Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uefix.s: add CHS mode #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 49 additions & 12 deletions uefix.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +21 to +25
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps check whether the drive number provided by BIOS is less than 0x80, instead of hardcoding this at compile time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was quick and dirty, but honestly that's probably a better approach. I'll hop on this and the 8 = HDD comment when I get back from breakfast.

Register DL contains the disk number on boot, so test 0x80, dl and jnz load.lba seems correct here, right?


load:
.chs:
mov ah, 0x02 ; function, chs load sector
mov al, 1 ; count sectors

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
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
Expand All @@ -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
Expand Down