Sources of information: x86 architecture: Appendix A of https://pdos.csail.mit.edu/6.828/2016/xv6/book-rev9.pdf boot process xv6: Appendix B of that files in xv6 : bootasm.S, bootmain.c, Makefile, .h files boot process in general: https://en.wikibooks.org/wiki/X86_Assembly/Bootloaders OS development : http://wiki.osdev.org/Main_Page BIOS interrupts : https://en.wikipedia.org/wiki/BIOS_interrupt_call int 10h video : https://courses.engr.illinois.edu/ece390/books/labmanual/graphics-int10h.html x86 assembly (GAS) : https://en.wikibooks.org/wiki/X86_Assembly BIOS keyboard : https://en.wikipedia.org/wiki/INT_16H Things of note in the Makefile: dd for file copying - putting bootblock, then kernel, then up to 10k zeroes Commands for the demo: make qemu-nox-gdb gdb -x .gdbinit kernel debugger commands: b *0x7c00 display/i $pc stepi x/i 0x7c00 dd if=bootblock of=/dev/sd_SOMETHING x86 registers of note: (e is for extended, x is also for extended) pc - program counter (memory address of next instruction to run) eax - accumulator (used for temporary things). Note ax is 16 bits, al and ah are 8 bits each from ax. ds, ss, cs - data segment, stack segment, code segment registers (offsets) x86 instructions of note: cli clear interrupts xor jnz jumps if not zero (checks z flag in some register) mov transfers data between registers and memory out in Boot sequence rules from the BIOS standard stuff: * Loads first 512 sector of disk, checks that last 2 bytes are 0x55aa. If so, assumes that 512 bytes is a boot loader. Reads that 512 bytes to memory address 0x7c00, and starts running there. * Note - since we only have 512 bytes to work with, written in assembly to be efficient. Also, bootasm.S is assembly because doing CPU-ish stuff. * When we start running, are in "real 8086 mode". That uses 20 bit memory addresses formed from an offset and segment start. Set segment starts to 0. Also, need to enable the A20 bit by messing with the keyboard controller ports. And put CPU into "protected" mode, which allows us to access more than 1M of memory. * The normal boot process would have the boot loader read from the disk for the rest of the stuff to load the OS, etc. This is in bootmain.c