3

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 = (unsigned 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'
4

1 回答 1

3

您只能拥有可链接的目标文件格式的外部参考。裸二进制文件不是,所以你不能直接这样做。

(并且您需要在调用 C 函数 AFAIK 之前设置一个堆栈。)

我看到了三种解决方法:

于 2011-08-20T13:31:47.673 回答