开发者

Error in bootloader: Help in assembly

I am trying to create a simple operating system, yet when I compile the bootloader, I get the error:

error: binary output format does not support external references

I know what this error means, but is it possible to make external references when compiling to binary format? Here is my complete code:

;Bootloader.s
[BITS 16]     
[ORG 0x7C00]
global loader
extern kmain

loader:
call kmain
times 510-($-$$) db 0
dw 0xAA55 

And my kernel:

/*kernel.c*/
void kmain()
{
    unsigned char *vidmem = (u开发者_JAVA百科nsigned char *) 0xb8000;
    int i
    for(i=1;i<=11;i+=2)
    {
        vidmem[i]=0x07;
    }
    vidmem[0]='H';
    vidmem[2]='e';
    vidmem[4],vidmem[6]='l';
    vidmem[8]='o';
    videmem[10]='!';
}

How I compiled:

nasm -o '/home/myusername/Cubed OS/Bootloader.o' '/home/myusername/Cubed OS/Bootloader.s'


You can only have external references in object file formats that are linkable. A bare binary is not, so you can't do that directly.

(And you need to set up a stack before you can call a C function AFAIK.)

I see three ways of going about this:

  • Use a bootloader that has Multiboot, and write your kernel as an ELF image. See the OSDev Bare bones for an example of that.
  • Write the whole thing in assembly. See for example How to write a simple operating system.
  • Write it all in C and use linker tricks to get things aligned where they need to be. An example of this with the GCC toolchain can be found here: Real mode in C with gcc : writing a bootloader
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜