Goal: Write a basic, minimal, x86 bootloader and 32bit kernel to fulfill my curiosity about OS internals. (full time job is in no way related, it's full on python).
Code: https://github.com/eliaonceagain/edu-x8 ... der-kernel
Checkpoints
- Real mode 16bit bootloader
- load gdt
- setup video mode
- enable protected mode
- setup interrupts
- setup tss
- create processes
- scheduler to round robin created processes on every clock interrupt
- enable paging
All the above "works". And I'm writing "works" because I'm sure there are stuff that are misconfigured but are magically working.
Current problem:
Adding any new C code makes the kernel not load.
Stage 1 bootloader (src/bootloader.asm) makes far jump to stage 2 (src/kernel_init.asm) and it remains stuck there.
New code could be as simple as:
Code: Select all
echo "void helloworld(){}" > src/filler.c
Using bochs gui I've managed to pinpoint this to the instruction that loads the tss
src/kernel_init.asm -> setup_task_register -> ltr ax -> hang
Reproduction
Code: Select all
git clone https://github.com/EliaOnceAgain/edu-x86-bootloader-kernel.git
cd edu-x86-bootloader-kernel && echo "void helloworld(){}" > src/filler.c
make clean && make run
It seems that the core code is not stable enough but I'm missing a direction to follow.
Some questions in random order:
- Why is adding new code breaks loading the kernel?
- How to properly configure TSS? (tss segment defined in src/gdt.asm)
- Should I setup a stack in different way? (currently it's set in src/bootloader.asm as starting from 0x7C00 downwards)
Any tips / suggestions / changes related or unrelated to the above questions would be highly appreciated
Thanks,
Elia