Kernel image format?

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
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Kernel image format?

Post by alethiophile »

I am currently in the process of writing my own bootloader. I do not want to have to do anything overly special with the kernel image; hence, I imagine the bootloader will need to be able to load ELF executables. I believe this is the format created by the instructions in the 'Bare bones' tutorial. How does a linker script like that included affect the output? How do I get the entry point? Is it sufficient to load the whole image as it is on disk and then jump to the entry point, or is some more elaborate system needed?
If I had an OS, there would be a link here.
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Kernel image format?

Post by Ferrarius »

This depends on whether or not you wish to support other kernels. Given the fact you stated you wish not to do it overly special even the ability to load ELF executable is not a necessity. I have written my bootloader to check a certain disk data structure for the location of a so called "Ultrablock" which encodes the location of the kernel and the size. The kernel itself is a flat binary, unlinked in any way. So Perhaps it is best to see what you really would like to load and then actually write the loading part of the loader;).
Modular Interface Kernel With a lot of bugs ;)
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Kernel image format?

Post by Love4Boobies »

alethiophile wrote:How does a linker script like that included affect the output? How do I get the entry point?
The entry point is noted in the header of the ELF executable. The linked puts it there based on your decision with the linker script.

If you want to provide Multiboot-compliance, you can use other formats as well (such as the flat binary Ferrarius talked about) by just reading the Multiboot header of the kernel. I'm telling you this because you mentioned the 'Bare Bones' tutorial.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: Kernel image format?

Post by alethiophile »

Thanks for the help. Will it work if I simply load the entire (ELF) kernel image into memory, parse its header to get the entry point, and jump to it? Also, in the 'Rolling your own bootloader' tutorial it stated that the kernel should be loaded to its compile-time-known entry point; how do I do that?
If I had an OS, there would be a link here.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Kernel image format?

Post by earlz »

alethiophile wrote:Thanks for the help. Will it work if I simply load the entire (ELF) kernel image into memory, parse its header to get the entry point, and jump to it? Also, in the 'Rolling your own bootloader' tutorial it stated that the kernel should be loaded to its compile-time-known entry point; how do I do that?
usually the entry point will be linked in so that it is at address 0 of the code segment(also the 0th segment) I'm not sure how this all goes in elf, but in flat binary, it means that the very first byte of the file is the beginning of the entry point function specified at link-time.

You can specify an entry function using ENTRY(_my_entry_function) inside of your linker script
Post Reply