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.
Hello,
Currently I am working on an ELF loader for a POSIX compliant operating system named NexNix. I am loading the file as a module with GRUB. However, the e_ident member of the ELF header is 0 for some reason. This is also just a prototype loader and will be greatly improved on. Here is the code for the loader:
I believe bootinfo does not contain the address of the module but a pointer to an array of modules (pointer, size and name) triplets. But I'm not very fond of Grub, so maybe someone can correct me on this. From the spec:
/* Are mods_* valid? */
if (CHECK_FLAG (mbi->flags, 3))
{
multiboot_module_t *mod;
int i;
printf ("mods_count = %d, mods_addr = 0x%x\n",
(int) mbi->mods_count, (int) mbi->mods_addr);
for (i = 0, mod = (multiboot_module_t *) mbi->mods_addr;
i < mbi->mods_count;
i++, mod++)
printf (" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n",
(unsigned) mod->mod_start,
(unsigned) mod->mod_end,
(char *) mod->cmdline);
}
Second, why do you copy the module? Why don't you simply map the memory where it's already located? If it's aligned on frame boundary, I see no reason why to copy it.
2) There is no need to allocate memory and copy the modules. Assuming they are ELF files and each program segment is page-aligned, you can just map them directly (but you will have to allocate some extra pages if "memory size" > "file size" for some program headers. This typically happens for BSS data).
I have tried changing it to use a structure, and that structure is valid, but the entry point address is 0xF0F0F0F, when it should be 0x8048060 according to readelf. That part looks like