The goal is to try to understand the differents steps from switching your computer on until executing kernel. For this we will follow OSDev tutorials.
Steps to create a basic kernel in assembly are in Babysteps.
How to create a basic kernel in assembly:
- Babystep1 - Your first boot sector.
- Babystep2 - Writing a message using the BIOS.
- Babystep3 - A look at machine code
- Babystep4 - Printing to the screen without the BIOS
- Babystep5 - Interrupts
- Babystep6 - Entering protected mode
- Babystep7 - Unreal Mode
- Babystep8 - 32-bit printing
- Appendix A - Additional information
- To debug and check that everything is working as expected you can start qemu as follow:
qemu-system-i386 -s -S -fda boot.bin
- And in another terminal attach gdb:
gdb -ex 'target remote localhost:1234' -ex 'set disassembly-flavor intel'
(gdb) b *0x7c00
(gdb) c
Breakpoint 1, 0x00007c00 in ?? ()
(gdb) x/2i $pc
=> 0x7c00: cli
0x7c01: jmp 0x7c01
- As you see it is our code that it is running...
- Just run
qemu-system-i386 -hda boot.bin
and you should see the famous Hello, World!.-fda
is working as well.
- We use
hexdump
to see binary file:
# hexdump -C boot.bin
00000000 fa 31 c0 8e d8 be 16 7c fc ac 08 c0 74 06 b4 0e |.1.....|....t...|
00000010 cd 10 eb f5 eb fe 48 65 6c 6c 6f 2c 20 57 6f 72 |......Hello, Wor|
00000020 6c 64 21 00 00 00 00 00 00 00 00 00 00 00 00 00 |ld!.............|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
- We see for example fa that is the opcode for cli.
- Then 31 that is the opcode for xor register. To decode the instruction completely we need to check the instruction format.
Nothing really special.
Now you can press a key and you will see the value read from the keyboard... Cool no?
They are not really interesting. It is said that we need to setup the GDT to be able to jump to protected mode. We already wrote a blog about this and it is almost done in ZigOS.
YaK has been superseded by CrashTOS.
YaK was our first project that we did in parallel of babysteps. Then few weeks after starting it we found cool videos done by Queso Fuego and available on youtube: Amateur Makes an OS. After seeing these videos we started CrashTOS.
- The little book about OS development
- OSDev long mode
- Redox bootloader
- BIOS interrupt call
- OSDev bootloder wiki
- Multiboot headers
- A Blog related to these attempts to create a "kernel".