boot kernel without grub?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
eddie23
Posts: 1
Joined: Sat Jun 13, 2009 8:34 pm

boot kernel without grub?

Post by eddie23 »

Hi everyone,
I have currently written my own bootloader. My current bootloader can load an image at 0x100000 but of course the simple kernel I currently load is written in asm and is assembled in pure binary making it easy to load at the 1 meg. I was trying to figure out how I could load a simple kernel (that just puts text to the monitor) I wrote in c to compile and link so it would run at 0x100000. Any tutorial I have seen says to use grub to load the image. I would like to use my own bootloader to load the image. I guess I am looking for a better explanation on what format I should compile and link in, like pe or elf, and how I would have to load that image.

Thanks,
I hope I have explained what I am looking for good enough.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: boot kernel without grub?

Post by earlz »

It's somewhere in the wiki. Look for stuff about flat binary formats... and everything(almost) for linker scripts applies to both ELF/PE and flat binary.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: boot kernel without grub?

Post by 01000101 »

Out of personal preference, I'd compile and link your C/assembly files into a static ELF file. Then you need to load that file, parse the ELF file header and extract the relevant sections into memory. From there, you will know (from the ELF header) where to jump too to start executing your kernel.
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Re: boot kernel without grub?

Post by mathematician »

You would need to write a stub in asm. From within that stub call a routine called _kernel, or kernel (depending upon the compiler/linker), and then within your C source file you would have a function called kernel(), instead of the usual main(). How you compile and link the stub with the C kernel, to get a flat binary, would depend upon the linker options available to you.

If you have no other work for it to do, the stub needs to do no more than set up the stack, maybe the gdt, and call kernel().

Another thing I've just thought of: The stub would need to have an org 100000h in it.
The continuous image of a connected set is connected.
Post Reply