A haribote OS. Just run it by $ make run
.
- Start BIOS.
- BIOS reads the first 1 sector(2048 bytes), which is called IPL(initial boot loader), from a floppy disk into the memory 0x7c00.
- [ipl10.asm] IPL reads 10 cylinders from a floppy disk into the memory 0x8200.
- [nasmhead.asm] OS prepares boot(setting an image mode, enabling memory access more than 1MB, moving 32 bits mode, etc.)
- [nasmhead.asm] Execute the segment on bootpack.
- [bootpack.c and other c files] Execute haribote OS.
- 512 bytes binary assembled from ipl10.asm
- binary assembled from nasmhead.asm
- binary compiled from bootpack.c and other c files.
Place | Content |
---|---|
0 | The size of stack + data + heap (A multiple of 4KB) |
4 | Signature "Hari" |
8 | The size of mmarea (A multiple of 4KB) |
12 | Init value of stack & the destination of .data |
16 | The size of .data |
20 | The file place of init value of .data |
24 | 0xE9000000 |
28 | Entry address - 0x20 |
32 | Start address of heap area(malloc area) |
- 0x07C00ー0x07DFF: IPL. The first 1 sector(2048 bytes) of a floopy disk. This is the boot sector.
- 0x08200ー0x34FFF: The content of a floopy disk(10 cylinders. Except IPL.)
- 0x00000000ー0x000FFFFF: Use during startup phase, but becomes empty after that (1MB)
- 0x00100000ー0x00267FFF: Content storage for a floppy disk (1440KB)
- 0x00268000ー0x0026F7FF: Empty (30KB)
- 0x0026F800ー0x0026FFFF: IDT (2KB)
- 0x00270000ー0x0027FFFF: GDT (64KB)
- 0x00280000ー0x002FFFFF: bootpack.brb (512KB)
- 0x00300000ー0x003FFFFF: Stack etc. (1MB)
- 0x00400000ー: Empty
$ nasm -version
NASM version 2.11.08
$ qemu-system-i386 --version
QEMU emulator version 2.12.0
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
TODO: gdb-peda
$ make debug
gdb
(gdb) target remote localhost:10000
$ gdb --args qemu-system-i386 -m 32 -rtc base=localtime -vga std -fda os.img
Create a log file
$ qemu-system-i386 -monitor stdio -m 32 -rtc base=localtime -vga std -d cpu_reset -D ./a.log -fda os.img
Disassemble
$ objdump -D -m i386 -b binary os.img > os.txt
GDB
QEMU_ARGS = -L . -m 32 -localtime -vga std -fda fdimage0.bin -monitor stdio -s -S
$ make run
gdb -ex 'target remote localhost:1234'
$ gdb ./a.out
gpb> p <function_name>
OR
$ objdump -d a.out | grep -C 20 <function_name>
(gdb) b *0x7x00 // Create break point to the beginning of IPL
(gdb) c
(gdb) x/16bx $eip // Dump as a binary
(gdb) x/i $eip // Dump as a assembly
When initial boot loader. https://speakerdeck.com/yuyabu/gong-kai-yong