From 629fc3e8269577b1579b0b58b6eb4d6ed5143bea Mon Sep 17 00:00:00 2001 From: pantonshire Date: Sat, 29 Jun 2024 16:45:58 +0100 Subject: [PATCH] get drive geometry --- boot0.s | 60 +++++++++++++++++++++++++++++++--------------------- boot1.s | 23 ++++++++++++++++++++ resources.md | 2 ++ 3 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 boot1.s diff --git a/boot0.s b/boot0.s index 71f1f90..2e99481 100644 --- a/boot0.s +++ b/boot0.s @@ -1,9 +1,17 @@ +; 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, fuck knows what an interrupt would do right now + ; Disable interrupts cli xor ax, ax @@ -11,41 +19,45 @@ bits 16 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 + ; 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, 0x7c00 + 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 ah, 0x00 - mov al, 0x03 + mov ax, 0x0003 int 0x10 - ; Reveal the true nature of jen - xor bx, bx - mov ax, 17 -loop: - cmp ax, bx - jle done - lea si, [womble + bx] - mov dh, [si] - mov di, bx - shl di, 1 - mov byte fs:[di], dh - mov byte fs:[di + 1], 0x1f - inc bx - jmp loop - -done: + mov word fs:[0x0000], 0xc048 + mov word fs:[0x0002], 0xc069 + mov word fs:[0x0004], 0xc021 hlt -womble: - db "jen is a womble!" +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 diff --git a/boot1.s b/boot1.s new file mode 100644 index 0000000..85d3a2b --- /dev/null +++ b/boot1.s @@ -0,0 +1,23 @@ +org 0x7c00 +bits 16 + + ; Reveal the true nature of jen + xor bx, bx + mov ax, 17 +loop: + cmp bx, ax + jae done + lea si, [womble + bx] + mov dh, [si] + mov di, bx + shl di, 1 + mov byte fs:[di], dh + mov byte fs:[di + 0x01], 0x1f + inc bx + jmp loop +done: + hlt + +womble: + db "jen is a womble!" + diff --git a/resources.md b/resources.md index fda00db..59bcea9 100644 --- a/resources.md +++ b/resources.md @@ -3,6 +3,7 @@ - - - +- ## Boot sequence - @@ -18,4 +19,5 @@ ## VGA - - +-