You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.0 KiB
ArmAsm

; MEMORY LAYOUT
; 0x0000 - 0x7000: stack
; 0x7000 - 0x7c00: globals
; 0x7000 - 0x7001: boot drive number
; 0x7001 - 0x7002: number of hard disk drives
; 0x7002 - 0x7003:
; 0x7c00 - 0x7e00: boot sector
; BIOS puts our boot sector at 0000:7c00
org 0x7c00
; We're (probably) in real mode
bits 16
; Disable interrupts
cli
xor ax, ax
mov ds, ax
mov es, ax
; Put stack base at 0x7000. Stack grows high->low, so we'll grow away from our program text at
; 0x7c00. We reserve the range [0x7000,0x7c00) for globals.
mov ss, ax
mov sp, 0x7000
; Segment for VGA (0xb800 * 16 = 0xb8000)
mov ax, 0xb800
mov fs, ax
mov di, 0x7000
; Store boot drive number
mov ds:[di], dl
; Get drive geometry
mov di, 0x00
mov ah, 0x08
int 0x13
jb panic
mov ds:[di + 1], dl
; Set VGA mode
; https://mendelson.org/wpdos/videomodes.txt
mov ax, 0x0003
int 0x10
mov word fs:[0x0000], 0xc048
mov word fs:[0x0002], 0xc069
mov word fs:[0x0004], 0xc021
hlt
panic:
mov ax, 0x0003
int 0x10
mov word fs:[0x0000], 0x4f46
mov word fs:[0x0002], 0x4f41
mov word fs:[0x0004], 0x4f49
mov word fs:[0x0006], 0x4f4c
hlt
; TODO: enable A20
; TODO: load a second stage
; TODO: grab all the info we can from bios interrupts and deliver it to ths OS nicely
; e.g. in a fixed memory location
; TODO:
; - Generate GPT in justfile
; - Parse global parition table
; - Load second stage from GPT partition with a particular UUID / name like GRUB does
; (it's Hah!IdontNeedEFI in GRUB)
; - https://en.wikipedia.org/wiki/BIOS_boot_partition
; - Future work:
; - Boot from UEFI
; - Boot on non-GPT partitioned disk
; MBR bootstrap field is 440 bytes long
%if ($ - $$) > 440
%error "exceeded mbr bootstrap field size"
%endif
; Pad to the end of the MBR bootstrap field
times 440 - ($ - $$) db 0
; Unique disk ID
dd 0x00000000
; Reserved
dw 0x0000
; Zero the partition fields
; TODO: fill in the field pointing to the GPT table
times 510 - ($ - $$) db 0
; Boot signature
db 0x55
db 0xaa