bootloader

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
praveen
Posts:2
Joined:Mon Nov 08, 2010 5:12 am
bootloader

Post by praveen » Thu Nov 11, 2010 5:22 am

Hi
This post is regarding
"How to use C in a boot loader " in the post http://www.brokenthorn.com/Resources/OSDev0.html.

It is said in the first part that we can have C code along with a stub of assembly in a single file.
But my question is, when the above C code (in the single file along with the stub of assembly) is compiled it will generate object code in elf format (gcc), but we want a flat binary file for bootloader.
In that case how our objective is fullfilled.
Can the author throw more light on this?

I have seen a bootloader (from utexas cs395t course) with two files one an assembly file and other a C file. The assembly file starts and calls the C code. I am not understanding how one get flat binary in this case while compiling the above two files(in linux gcc environment).

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: bootloader

Post by Andyhhp » Thu Nov 11, 2010 10:37 pm

For gcc, you need to:

1) compile the c file to an object file (.o)
2) assemble the asm file to an object file (.o)
3) use ld to link the two object files into a single binary.

In your linker script, specify that the output format should be binary rather than elf.

see http://wiki.osdev.org/Bare_bones for a tutorial on how to set this up

~Andrew
Image

praveen
Posts:2
Joined:Mon Nov 08, 2010 5:12 am

Re: bootloader

Post by praveen » Fri Nov 12, 2010 6:24 am

praveen wrote:Hi
This post is regarding
"How to use C in a boot loader " in the post http://www.brokenthorn.com/Resources/OSDev0.html.

I have seen a bootloader (from utexas cs395t course) with two files one an assembly file and other a C file. The assembly file starts and calls the C code. I am not understanding how one get flat binary in this case while compiling the above two files(in linux gcc environment).



When the above two bootloader files are compiled and linked, it said that the bootloader size is 414 bytes. But none of those files took care of boot signature to be placed at bytes 511 and 512.

Is it that there are other means of putting the bootsignature at those bytes using loader/linker instead of taking care of it in the bootloader code (the assembly file and the c file)?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: bootloader

Post by Andyhhp » Fri Nov 12, 2010 11:24 am

You can get the linker script to put in arbitrary values at arbitrary locations.
Image

Post Reply