Hi,
I'd like to try to load an ELF binary without using GRUB but all docs I've read have about 1 page about program loading - any hints on this??? Most important would be: order of loaded sections and what sections are important to load and which are not. Maybe something on relocation?
Thanks
Darkening
ELF
Re: ELF
In ELF, there are sections and "segments". Sections denote logical parts of the executable (as code, data etc.) and segments describe what parts of the executable file are what (and, more importantly, which should be loaded). Basically, to run an ELF file, you have to do the following:
1. Read the ELF header and check that it is really an ELF file (and that it is built for your architecture).
2. Read the program headers (list of "segments"), location of which is specified in the ELF header.
3. Load every segment listed in the program headers that is marked loadable (type PT_LOAD).
4. If you load shared libraries along with the executable, remember the address of the dynamic section (the corresponding segment for which is marked PT_DYNAMIC).
If you use shared libraries, you also have to process all the relocations (I spent about two weeks firuring out everything about relocations, but that's not really difficult). Otherwise, there are no relocations.
BTW, are you loading the ELF kernel? If you want, I can mail you the source of my loader, which can load a kernel along with some modules and relocate everything (it is a bit complex, though).
1. Read the ELF header and check that it is really an ELF file (and that it is built for your architecture).
2. Read the program headers (list of "segments"), location of which is specified in the ELF header.
3. Load every segment listed in the program headers that is marked loadable (type PT_LOAD).
4. If you load shared libraries along with the executable, remember the address of the dynamic section (the corresponding segment for which is marked PT_DYNAMIC).
If you use shared libraries, you also have to process all the relocations (I spent about two weeks firuring out everything about relocations, but that's not really difficult). Otherwise, there are no relocations.
BTW, are you loading the ELF kernel? If you want, I can mail you the source of my loader, which can load a kernel along with some modules and relocate everything (it is a bit complex, though).
Re: ELF
BTW, this is the ELF specification. You may want to check it out: http://www.nondot.org/sabre/os/files/Ex ... es/ELF.pdf
Re: ELF
Sorry that I'm replying so late...
@Kernel Panic: Would be great to have a look at your source code! eMail address is [email protected]
Darkening
@Kernel Panic: Would be great to have a look at your source code! eMail address is [email protected]
Darkening