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.
boot kernel without grub?
Re: boot kernel without grub?
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.
Re: boot kernel without grub?
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.
Website: https://joscor.com
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
Re: boot kernel without grub?
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.
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.