Here is my setup:
Windows
nasm
gcc
virtual box
What I am doing:
Compile boot loader and kernel where the boot loader will load the kernel into memory and then jump to it. (Depending on kernel maybe in protected mode)
I am using nasm to compile my boot loader directly into a binary flat file and then gcc to compile my kernel from C. To compile my kernel I use these commands:
gcc -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs -o kernel.o -c kernel.c
C:\MinGW\mingw32\bin\ld.exe kernel.o -o kernel.bin
objcopy -O binary kernel.tmp kernel.bin
My code for my kernel is this:
Code: Select all
void kmain( )
{
asm("cli");
char* buffer = "Hello, world!",
* vmem = (char*)0xB8000;
while (*buffer) {
*vmem++ = *buffer++;
*vmem++ = 0x07;
}
for (;;)
asm("hlt");
}
the linker blows it up to 3.7k and objcopy then makes it 8k.
I have a nagging feeling that this is probably not correct and my linking skills are almost non-existent. I
have seen where some people have compiled the boot loader and kernel to objects then link the too together
but I am not really comfortable with that idea.
Is anyone aware if the size is correct? As a test I read somewhere that I can compile it straight to assembly with
these commands:
gcc -c kernel.c
objcopy -O binary kernel.o kernel.bin
however if I do that then the first line in the assembly is "Hello, Word!" which is not a instruction. I could try to jump
past it but I want to be consistent because the kernel will change and I don't want to have to keep modifying my
boot loader each time.