I am new to operating system programming and I am reading a book which gives a simple example of kernel as follows:
main() {
char *video_memory = 0xb8000;
The first thing you'll need to is change the name of you function. If you call it main
the MinGW version of GCC will insert a call to __main
to do initialization. For example:
start() {
char *video_memory = 0xb8000;
*video_memory = 'X';
}
This means you'll also have to edit kernel_entry.asm
accordingly:
[bits 32]
[extern _start]
call _start
jmp $
Next compile and assemble the two files as you did before, and link it with these commands:
ld -T NUL -o kernel.tmp -Ttext 0x1000 kernel_entry.o kernel.o
objcopy -O binary -j .text kernel.tmp kernel.bin
The first command links the objects as a PECOFF executable, and then the second command converts it to a binary. Now combine the binary with the boot loader:
copy /b boot_sect.bin+kernel.bin os-image