Add support for hard disks

This commit is contained in:
Nero 2020-12-26 17:44:48 +00:00
parent b8b56e1f45
commit c75b323d31
2 changed files with 82 additions and 11 deletions

View File

@ -29,17 +29,21 @@ init: cli
sub dl, (0x80-2)
.k: mov [defdrv], dl
call logdrv.force
call logdrv
xor ax, ax
xor dx, dx
call maprd
inc word [dskbuf+0x82]
push word [dskbuf+0x82]
call dirty
call flush
call printf
db "Current run: ",2,0x0A,0x0D,0
hlt: hlt
jmp hlt

View File

@ -65,15 +65,33 @@ int13: ; debug output
stc
ret
; restore DPT to default values if possible
; IN dl bios drive number
rstdpt: mov ah, 8
; get drive parameters
; read BIOS int13h/AH=8 values
; DPT data gets copied over our dpt
; CHS data gets inserted into our bpb
getprm: mov ah, 8
mov dl, [biosnum]
call int13
jc .ret
mov ax, es
; bail out if error
jc .nodpt
; get and store sector number
and cx, 0x3F
mov word [bpb+BPBSPT], cx
; get and store number of heads
xchg dl, dh
and dx, 0xFF
inc dx
mov [bpb+BPBNOS], dx
; print geometry
push dx
push cx
call printf
db "getprm: ",2," sectors, ",2," heads",0x0A,0x0D,0
; test if DPT ptr is non-zero
.nochs: mov ax, es
or ax, di
test ax, ax
jz .ret
jz .nodpt
; DS:SI = ES:DI
mov ax, es
mov ds, ax
@ -85,9 +103,10 @@ rstdpt: mov ah, 8
; do the copy
mov cx, 11
rep movsb
.ret: ; restore DS to 0
.nodpt: ; restore segment registers
xor ax, ax
mov ds, ax
mov es, ax
ret
; log in drive
@ -95,7 +114,7 @@ rstdpt: mov ah, 8
; IN dl drive number
logdrv: ; dont do anything if drive already selected
cmp dl, [dsknum]
je .ret
je logfdd.ret
; clear out current contents
push dx
call flush
@ -106,10 +125,14 @@ logdrv: ; dont do anything if drive already selected
pop dx
; set current drive number
mov [dsknum], dl
; save info for bios
; fork off if hdd
cmp dl, 2
jnc loghdd
logfdd: ; save info for bios
mov [biosnum], dl
; reset dpt to defaults
call rstdpt
call getprm
; set default geometry (1.44 MB floppy)
mov word [bpb+BPBNOS], 2
mov word [bpb+BPBSPT], 18
@ -132,6 +155,50 @@ logdrv: ; dont do anything if drive already selected
mov [bpb+BPBHS+2], ax
.ret: ret
loghdd: sub dl, 2
cmp dl, 4
jnc logerr
push dx
mov byte [biosnum], 0x80
; get chs data (needed or we cant load vbr)
call getprm
; read mbr
xor ax, ax
xor dx, dx
call mapabs
; get partition number
pop bx
xor bh, bh
mov cl, 4
sal bx, cl
; bail out if no partition
cmp byte [dskbuf+0x1be+bx+4], 0
je logerr
; load partition offset
mov ax, [dskbuf+0x1be+bx+8]
mov dx, [dskbuf+0x1be+bx+8+2]
; save to to stack
push dx
push ax
; load vbr
call mapabs
; copy bpb
mov si, dskbuf+BPBOFF
mov di, bpb
mov cx, BPBSIZ4
rep movsb
; fix CHS data
call getprm
; fix partition offset
pop ax
pop dx
mov [bpb+BPBHS], ax
mov [bpb+BPBHS+2], dx
ret
logerr: stc
ret
mapclu: ; counting from begin of cluster area
mov bx, [bpb+BPBRDE]
mov cl, 4