I have a very basic working kernel written in C that can print stuff.
I noticed that I cannot declare global variables without the kernel not running. I find this very odd. I thought this might be related, so I link into an ELF, and then use objcopy. The kernel still works, but as soon as I declare a global variable, it doesn't.
Here's my compilation:
Code: Select all
nasm -f elf32 MOSS/kernel/jump.asm -o jump.o
gcc -c -Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -nostdinc -ffreestanding MOSS/kernel/kernel.c -o kernel.o
ld --entry jump jump.o kernel.o -o jump_kernel.elf
objcopy -O binary jump_kernel.elf kernel.bin
Code: Select all
;jump.asm
[BITS 32]
[global jump]
[extern kernel_main]
jump:
call kernel_main
Code: Select all
//kernel.c
//static unsigned char* video = (unsigned char*)(0x00B8000); //uncomment this to see problem
void kernel_main(void) {
unsigned char* video2 = (unsigned char*)(0x00B8000);
video2[0] = 'H';
video2[1] = 0x07;
video2[2] = 'i';
video2[3] = 0x07;
HANG: goto HANG;
}
Thanks,