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)