From 50353bafdd2a17aa02b5fa449acebe67309e448e Mon Sep 17 00:00:00 2001 From: pantonshire Date: Sun, 23 Jun 2024 21:07:00 +0100 Subject: [PATCH] little boot sector that writes hi to vga --- boot.s | 47 +++++++++++++++++++++++++++++++++++++++++++++++ justfile | 6 ++++++ 2 files changed, 53 insertions(+) create mode 100644 boot.s create mode 100644 justfile diff --git a/boot.s b/boot.s new file mode 100644 index 0000000..09e789c --- /dev/null +++ b/boot.s @@ -0,0 +1,47 @@ +; BIOS puts our boot sector at 0000:7c00 +org 0x7c00 +; We're (probably) in real mode +bits 16 + + ; Disable interrupts, fuck knows what an interrupt would do right now + cli + + xor ax, ax + + mov ds, ax + mov es, ax + + ; Put the stack base at the address of our program text (stack will grow high->low away from it). + ; We're not doing anything with a stack right now but who knows we might want to later + mov ss, ax + mov sp, 0x7c00 + + ; Segment for VGA (0xb800 * 16 = 0xb8000) + mov ax, 0xb800 + mov fs, ax + + mov ah, 0x00 + mov al, 0x03 + int 0x10 + + ; Hi! + mov word fs:[0x0000], 0xc048 + mov word fs:[0x0002], 0xc069 + mov word fs:[0x0004], 0xc021 + + hlt + + ; TODO: grab all the info we can from bios interrupts and deliver it to ths OS nicely + ; e.g. in a fixed memory location + + ; Make sure we fit in a single 512-byte sector + %if ($ - $$) > 510 + %error "exceeded boot sector size" + %endif + + ; Pad to the boot signature offset + times 510 - ($ - $$) db 0 + ; Boot signature + db 0x55 + db 0xaa + diff --git a/justfile b/justfile new file mode 100644 index 0000000..55b1ba0 --- /dev/null +++ b/justfile @@ -0,0 +1,6 @@ +run: + qemu-system-x86_64 -drive format=raw,file=boot.bin + +build: + nasm -f bin -o boot.bin boot.s +