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'
0

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

1 Comment

What format can you have external references and use the "ORG" directive?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.