From 7a3a2f0a56a1a3de3c0423084c16dc6fd2183d7d Mon Sep 17 00:00:00 2001 From: Tyler True <944067+sirocyl@users.noreply.github.com> Date: Sun, 2 Jul 2023 05:28:50 -0400 Subject: [PATCH 1/3] uefix.s: add CHS mode This should enable booting a sector payload from an FDD, and so enabling `-D FLOPPY` on the yasm line will switch to CHS drive logic. --- uefix.s | 61 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/uefix.s b/uefix.s index 6e1edb5..8c583aa 100644 --- a/uefix.s +++ b/uefix.s @@ -16,21 +16,46 @@ rep movsb jmp 0:start start: - mov ah, 0x42 - mov si, packet +; Both CHS and LBA code is present in the loader, as we have the free space +; and switching between the two manually is a single-byte edit. +%ifdef FLOPPY + jmp load.chs +%else + jmp load.lba +%endif + +load: +.chs: + mov ah, 0x02 ; function, chs load sector + mov al, 1 ; count sectors + + mov dl, 0 ; drive (0 = floppy A:, 1 = floppy B:, 8 = HDD C:) + mov dh, 0 ; head + mov cl, 1 ; sector + mov ch, 0 ; cylinder + mov bx, 0x7c00 ; buffer int 0x13 - jc error + jc error.chs + jmp 0x7c00 +.lba: + mov ah, 0x42 ; function, lba extended load + mov si, lbapacket ; location of int13h/AH=42h arguments packet + int 0x13 + jc error.lba jmp 0x7c00 -packet: - db 0x10 - db 0 - dw 1 ; count - dw 0x7c00, 0 ; buffer - dq 1 ; LBA error: - mov si, errmsg +.lba: + mov si, errmsg.lba + jmp error.loop +.chs: +; TODO: some FDDs may be slow to start, and need to reset and reread +; the sector, while the disk spins up. Implement code here to do so +; three or four times, then go ahead and print the error message. + mov si, errmsg.chs + jmp error.loop .loop: +; TODO: Read error numbers from BIOS return regs, and print them with errmsg. lodsb or al, al jz .done @@ -43,13 +68,25 @@ error: jmp .done errmsg: - db "Disk error :(", 0 +.lba: + db "Forth: BIOS returns an LBA loader error.", 0 +.chs: + db "Forth: BIOS returns a CHS loader error.", 0 + +lbapacket: + db 0x10 + db 0 + dw 1 ; count + dw 0x7c00, 0 ; buffer + dq 1 ; LBA +blank: times 446 - ($ - $$) db 0 +mbrinfo: db 0 ; not active db 0, 1, 0 ; start CHS - db 0x42 ; type + db 0x7f ; partition type (0x7f: experimental) db 0, 1, 0 ; end CHS dd 1 ; start LBA dd 1 ; length From 19df4025e2cfb6e168648703a1551df0045be5a6 Mon Sep 17 00:00:00 2001 From: Tyler True <944067+sirocyl@users.noreply.github.com> Date: Sun, 2 Jul 2023 05:52:35 -0400 Subject: [PATCH 2/3] off by one error Load the sector after the first one. --- uefix.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uefix.s b/uefix.s index 8c583aa..d54705f 100644 --- a/uefix.s +++ b/uefix.s @@ -31,7 +31,7 @@ load: mov dl, 0 ; drive (0 = floppy A:, 1 = floppy B:, 8 = HDD C:) mov dh, 0 ; head - mov cl, 1 ; sector + mov cl, 2 ; sector mov ch, 0 ; cylinder mov bx, 0x7c00 ; buffer int 0x13 From 5cf052708ce203384a981325d1788830e6c3fbdb Mon Sep 17 00:00:00 2001 From: Tyler True <944067+sirocyl@users.noreply.github.com> Date: Wed, 5 Jul 2023 06:40:27 -0400 Subject: [PATCH 3/3] uefix.s: fix comment on drive numbers --- uefix.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uefix.s b/uefix.s index d54705f..73c1406 100644 --- a/uefix.s +++ b/uefix.s @@ -29,7 +29,7 @@ load: mov ah, 0x02 ; function, chs load sector mov al, 1 ; count sectors - mov dl, 0 ; drive (0 = floppy A:, 1 = floppy B:, 8 = HDD C:) + mov dl, 0 ; drive (0 = floppy A:, 1 = floppy B:, 80 = HDD C:) mov dh, 0 ; head mov cl, 2 ; sector mov ch, 0 ; cylinder