i have tried in vain for a while to get grub to load a module for my os.
the process seems very easy: get grub to load it, get the starting address from multiboot, relocate elf etc.
it seems to load it fine, and multiboot says theres one module loaded, and has a starting offset. when i try to relocate this, my driver gives all sorts of errors, saying its not an elf etc etc
i checked thru my code, and wrote a debugging function which printed everything remotly to do with modules onto the screen and found that the contents of the module where that of my gets() function...
i will post code as soon as i get home for you to look at, but i was wondering why the f*** this would happen, i havnt done anything remotly like each other in the code, and i certainly dont cross over the variables :S
grub module problem
i think i may haved missed something, i have been over my code countless times and cannot see whats wrong with it.
heres what it looks like debugging:
![Image](http://img214.imageshack.us/img214/5741/40362949av1.jpg)
heres my code:
so you can see what goes on in main ![Smile :)](./images/smilies/icon_smile.gif)
thats my module/elf relocation code (duh :p)
if anybody has 5 minutes and feels like reading through my code (:roll:) i would very much appreciate it!
Luke
edit: ignore the random curses in my code.. its when things (drivers) im testing don't do as they're told lol
heres what it looks like debugging:
![Image](http://img214.imageshack.us/img214/5741/40362949av1.jpg)
heres my code:
Code: Select all
module_t* mods = (module_t*) mbd->mods_addr;
printf("Balls... multiboot doesn't seem to be working. Lets do some checks:\n");
printf("\n++++++++++++++DEBUG++++++++++++++\n");
printf("mods_count: %d\n", mbd->mods_count);
printf("mods_addr: 0x%x\n", mbd->mods_addr);
printf("mod_start: 0x%x\n",mods->mod_start);
printf("+++++++++++++++++++++++++++++++++\n\n");
openModule_elf("Shell.bin",mods->mod_start); /* mods[1].mod_start */
printf("hmm...\n");
![Smile :)](./images/smilies/icon_smile.gif)
Code: Select all
int openModule_elf(char* name, int offset)
{
elfHeader* header;
/* Put header information into header struct */
header = (elfHeader*) offset;
/* DEBUGING STUFF */
printf("Opening %s from 0x%x!\n",name,offset);
printf("Magic Bits: 0x%x %s%s%s\n",header->ident[0],header->ident[1],header->ident[2],header->ident[3]);
/* !DEBUGING STUFF */
/* Check for any errors */
if(header->ident[0] != 0x7f/* || header->ident[1] != 'E' || header->ident[2] != 'L' || header->ident[3] != 'F'*/)
{
printf("Error opening %s! %s is not ELF\n",name,name);
return -1;
}
if(header->ident[4] != 1)
{
printf("Error opening %s! ELF not designed for x86-32 architecture!\n",name);
return -1;
}
if(header->ident[5] != 1)
{
printf("Error opening %s! ELF uses wrong encoding type. LSB ONLY supported!\n",name);
return -1;
}
if(header->machine != 7)
{
printf("Error opening %s! ELF designed for a different architecture!\n",name);
return -1;
}
if(header->flags)
{
printf("Error opening %s! ELF must not contain flags in header!\n",name);
return -1;
}
if(relocModule_elf(header, header->entry) != 1)
{
printf("Error opening %s! Cannot relocate ELF image!\n",name);
return -1;
}
/* Call the program */
__asm__ __volatile("call %0" : : "a" (header->entry));
return 1;
}
int relocModule_elf(elfHeader* header, int start_addr)
{
int i;
programHeader* pHeader = (programHeader*) (header->phoff + start_addr);
for(i = 0; i < header->phnum; i++)
{
/* Check if its loadable */
if( pHeader[i].type == 1 ) /* PT_LOAD == 1 */
{
if(!malloc(pHeader->memSize))
return -1;
}
}
/* We rule! */
return 1;
}
Code: Select all
void gets(char *string)
{
shell_bit = 1; /* Tell kbd handler to gather input */
while(shell_bit)
printf("");
for(int i=0; i<= kb_count; i++)
{
string[i] = shell_data_buffer[i];
}
kb_count = 0;
shell_bit = 0;
shell_data_buffer = "";
}
void keyboard_handler(struct regs *r)
{
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
if(getch_flag)
getch_bit++;
else
getch_bit=0;
/* Special Keys */
switch (scancode)
{
case KRCAPS_LOCK:
if(caps)
caps = 0;
else
caps = 1;
toggle_caps();
break;
case KRNUM_LOCK:
toggle_num();
break;
case KRSCROLL_LOCK:
toggle_scroll();
break;
case 88: /* F12 */
reboot();
break;
default:
break;
}
if (scancode & 0x80)
{
/* Held Keys */
}
else
{
if( shell_bit )
{
/* Was it enter? */
if(kbduk[scancode]=='\n')
{
/* Yes.. Clear all buffers */
shell_data_buffer[kb_count] = '\0';
putch('\n');
shell_bit = 0;
kb_count = 0;
} else {
/* No... so we append this key to our string */
if(caps)
shell_data_buffer[kb_count] = kbduk_shift[scancode];
else
shell_data_buffer[kb_count] = kbduk[scancode];
putch(shell_data_buffer[kb_count]);
kb_count++;
}
}
}
}
Luke
edit: ignore the random curses in my code.. its when things (drivers) im testing don't do as they're told lol
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Your code appears to be alright.
I'd suggest loading up your final binary in a hex editor to find out exactly what's in it - and also load up a file that you know is a valid ELF binary and find out what's different.
It might also be that your kernel overwrites the module (I avoid this in my kernel by marking the pages that each module takes as "allocated").
I'd suggest loading up your final binary in a hex editor to find out exactly what's in it - and also load up a file that you know is a valid ELF binary and find out what's different.
It might also be that your kernel overwrites the module (I avoid this in my kernel by marking the pages that each module takes as "allocated").
i dont think its been overwritten, because i too have a malloc system which marks used chunks as such...
ill have a little look when i get access to it again, maybe fiddle with my gets...![Sad :(](./images/smilies/icon_sad.gif)
BTW: i typed hello[enter] in my gets function, before i tried to load the module, and the magic bits apear as you can see in the image :S
if i dont use a gets function the magic bits dont show elf either... maybe it is the reloc code..
ill have a little look when i get access to it again, maybe fiddle with my gets...
![Sad :(](./images/smilies/icon_sad.gif)
BTW: i typed hello[enter] in my gets function, before i tried to load the module, and the magic bits apear as you can see in the image :S
if i dont use a gets function the magic bits dont show elf either... maybe it is the reloc code..
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Code: Select all
printf("Magic Bits: 0x%x %s%s%s\n",header->ident[0],header->ident[1],header->ident[2],header->ident[3]);
Code: Select all
printf("Magic Bits: 0x%x %c%c%c\n",header->ident[0],header->ident[1],header->ident[2],header->ident[3]);