[kernel] mod some file before function main have some error


Some like the title.
Demo link https://github.com/duncup/dissOS/blob/master/src/main.rs#L22
If this code move to somewhere before fn main, then can’t get the hello world.


Yikes! First things first, we have a major problem in this department:

$(RUSTC) -O --target i686-unknown-linux-gnu --crate-type lib -o $@ --emit obj -C relocation-model=static $<

By using a target of i686-unknown-linux-gnu, rustc thinks it’s compiling a userspace Linux program. This will have all sorts of ramifications in the future which may lead to some fairly unpleasant bugs. I strongly suggest reading up on custom target definitions (here’s a great introduction) before continuing (watch out though, that page is defining a target suitable for x86_64, which is not the architecture you’re trying to compile for).

Secondly, you aren’t placing your sections in the right place. Where do you think that string "Hello world!" is being placed? You need to update your linker file:

    . = 0x7e00;

    .text : {
    } >ram

    // Hint: some more sections should appear here, at least a `.rodata` (plus its `.rodata.*` friends) and `.data`

    /DISCARD/ : {

For example, these are the sections I include for generating code for x86_64

Edit: just as a sanity check, I’d also check the size of your binary in total, since you’re only loading 24 sectors in your bootloader


Thanks for your time, i’ll try this.