'Unsupported executable format' when doing loops
Posted: Sun Nov 23, 2008 2:00 pm
Hi,
Sorry for the title I wasn't sure what to put there. So here the case, I've just started looking at some kernel development this weekend and allready I am tearing my hair out. I've been following the Bran's Kernel Development tutorial but I ran into problems with my strlen function. I implemented it like this:
But whenever i called it in my main function the kernel whould not load in grub. (I got error 17 unsupported executable format). After playing around abit I was not able to figure out what caused this. But I did find something strange. The first code below runs fine, but when i change i < 2 to anything higher like i < 3 i get the same error 17 when loading my kernel.
I guess both of those problems are related but i really have no idea what may be causing them. If anyone has any clues as to what may help me please drop a comment.
P.S
I compile my code using the following commands (start.asm simply calls my kmain() function):
Runar
Sorry for the title I wasn't sure what to put there. So here the case, I've just started looking at some kernel development this weekend and allready I am tearing my hair out. I've been following the Bran's Kernel Development tutorial but I ran into problems with my strlen function. I implemented it like this:
Code: Select all
unsigned int strlen(const char *str)
{
unsigned int len;
for(len = 0; *str != '\0'; str++, len++);
return len;
}
Code: Select all
unsigned char* textmem = (unsigned char *) 0x0B8000;
char *str = "Hello world";
int i;
// Prints He, but if i change the condition to i > 3 or str[i] != '\0' for that matter
// grub whon't load my kernel image
for(i = 0; i < 2; i++) {
textmem[2*i] = str[i];
textmem[2*i+1] = str[i];
}
P.S
I compile my code using the following commands (start.asm simply calls my kmain() function):
Code: Select all
nasm -f aout -o start.o start.asm
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
ld -T link.ld -o kernel.bin start.o (Using the linker script at http://www.osdever.net/bkerndev/Docs/basickernel.htm)