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.
I need help with an ELF Parser. now i have a Grub module that is at a random address (due to the initrd i made is variable) and i dont know how to run the console i added as a grub module and call its entry function. i have in a stored variable the start and end addresses of the elf program and just need to figure out how to call the entry level.
The structure of an ELF binary is actually quite simple, and a loader is usually only about 50 lines of C or so. Here are the ELF specs: http://www.skyfree.org/linux/references/ELF_Format.pdf. You only need to care about the loading section - all linking information can be ignored. For you, the beginning of the file will really be the offset from that start pointer you have.
ok i implemented some code but it pagefaults and i dont know why. and my elf verifier is pulling invalid data as well saying its not an ELF executable but i did a printf of the memory area and got this (the (triangle)ELF is me printing that address of memory as string)
so obviously the ELF Header is there, just my parser isnt correctly reading it
Sources in question Includes/Kernel/ELF.h and Kernel/ELF.cpp
yeah that fixed that issue so obviously i need to correct them as other then unsigned long (which is for some reason what i set things up to in structs)
(which is for some reason what i set things up to in structs)
Read the spec - it tells you exactly how wide each element of the struct should be. Assuming you have at least a basic knowledge of your types, you should be able to make the structs with ease.
Ok all is fixed it was the headers and i figured out by reading the spec more thuroughly what the types were. jeeze i sometimes get lazy and thats not good in programming oses
now it executes the ELF Module thanks for all your help
i forgot i commented out paging so when i reenabled paging this happened
and also it seems when the ELF got copied it rewritten over data because those are not the strings how can i run the elf from where its already preexisting into memory like a in place execution without copying or am i thinking this wrong.
ELF describes a layout as it is intended to be, then packs all the data bits together. That means that in the normal case you will have to copy ELF sections to their intended locations, since the sections are not page aligned in the input file.
If you want to execute an ELF in place, you should know link it to exact that location. Since I don't know of ld being able to pull such a thing off, your best bet is to do relocation during load, but doing so is more complicated than a simple map_memory and copy.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]