Hello all,
I have two modules for grub to load: one multiboot kernel module and an elf module. The first one is called with the "kernel" command and the second is called with the "module" command (in menu.lst).
Grub first boots the kernel with no problems. In this kernel, i have defined a global variable which stores the address (mbi->mods_addr)->mod_start which is the start address of the elf module. At the end of the kernel module i do a "jmp dest", where dest is the above global variable, because i want to jump to the entry point of the elf module and continue execution from there.
However, this doesn't work. The computer reboots when "jmp dest" is called.
Can anybody give me a helping hand? I would really appreciate it.
grub module question [answered]
-
- Posts: 13
- Joined: Sat Apr 28, 2007 1:57 am
grub module question [answered]
Last edited by 13postures on Fri May 25, 2007 8:35 am, edited 1 time in total.
-
- Posts: 13
- Joined: Sat Apr 28, 2007 1:57 am
Thank you for your reply Aali.
Do you mean i have to load the elf image manually into vm? I haven't created a vm system in order to back an operation like that. What do you mean with "relocate the module"?
Parsing the elf headers is easy. But i don't understand how can i find the elf image's entry point from searching the headers . There is a field called e_entry in Elf Header, but that's not it.
Do you mean i have to load the elf image manually into vm? I haven't created a vm system in order to back an operation like that. What do you mean with "relocate the module"?
Parsing the elf headers is easy. But i don't understand how can i find the elf image's entry point from searching the headers . There is a field called e_entry in Elf Header, but that's not it.
Read ELF and then run objdump -p filename on your module.
You'll get an output like
Each segment in the file expects to be loaded at the address specified by 'vaddr' but isn't really at that location in the file (or the file would be huge). Its actually at 'off', meaning offset, relative to the beginning of the file. Once you have loaded it to the correct location, then jumping to the location defined by e_entry should work.
Regards,
John.
You'll get an output like
Code: Select all
test/testa: file format elf32-i386
Program Header:
LOAD off 0x00001000 vaddr 0x40000000 paddr 0x40000000 align 2**12
filesz 0x0000605a memsz 0x0000605a flags r-x
LOAD off 0x00008000 vaddr 0x40007000 paddr 0x40007000 align 2**12
filesz 0x00000004 memsz 0x00001208 flags rw-
Regards,
John.
-
- Posts: 13
- Joined: Sat Apr 28, 2007 1:57 am
Jnc100, you have been very clear. Thank you for your answer. Just one thing though.
This means that i must have a virtual memory system set up in the kernel module so that i can load the elf file at the correct memory location, right? Or is there another way to load it at the correct location?jnc100 wrote: ...Once you have loaded it to the correct location, then jumping to the location defined by e_entry should work.
Generally yes, unless all the sections in the elf file are linked so that they exist within the physical memory of your system, in which case you can just copy them there. The executable sections and the kernel sections need to be mutually exclusive of course. This is generally a bad idea though, because 1) you don't know how much physical memory a user will have, whereas virtual memory is standard at 4GB in a 32-bit system and 2) all your user processes will need to be linked to run at different locations. With paging, you can use a separate address space for each process. No such luck if you're running with paging disabled.13postures wrote:This means that i must have a virtual memory system set up in the kernel module so that i can load the elf file at the correct memory location, right? Or is there another way to load it at the correct location?
Regards,
John.
-
- Posts: 13
- Joined: Sat Apr 28, 2007 1:57 am