Implement reading of partition offset and size

This commit is contained in:
Nero 2020-05-06 20:28:30 +00:00
parent 9377924eab
commit 8d28dc9f85

View File

@ -14,11 +14,16 @@ disk_chs: ; DL, DH, CL, CH for int 13h CHS functions
disk_dap: ; disk access packet for int 13h EBIOS functions disk_dap: ; disk access packet for int 13h EBIOS functions
resb 0x10 resb 0x10
disk_tracks: ; heads * spt disk_spc: ; sectors per cylinder = heads * spt
resw 1 resw 1
disk_spt: disk_spt:
resb 1 resb 1
part_offset:
resd 1
part_size:
resd 1
; Disk access packet for EBIOS extensions ; Disk access packet for EBIOS extensions
dapps: equ 0 ; byte packet size dapps: equ 0 ; byte packet size
dapnum: equ 2 ; word number of sectors to transfer dapnum: equ 2 ; word number of sectors to transfer
@ -53,22 +58,42 @@ select: mov byte [disk_current], 0xFF
mov bx, 0x55AA mov bx, 0x55AA
int 0x13 int 0x13
test cx, 1 test cx, 1
jz .nolba jz select_hdd
cmp bx, 0xAA55 cmp bx, 0xAA55
jnz .nolba jnz select_hdd
mov byte [lba_supported], 1 mov byte [lba_supported], 1
.nolba: call seek_zero jmp select_hdd
ret
select_floppy: select_floppy:
xor dx, dx call seek_zero
xor ax, ax
call seek
call read call read
; load disk geometry
mov ax, [disk_buffer+0x0B+bpb_spt] mov ax, [disk_buffer+0x0B+bpb_spt]
mov [disk_spt], ax mov [disk_spt], ax
mul word [disk_buffer+0x0B+bpb_nos] mul word [disk_buffer+0x0B+bpb_nos]
mov [disk_tracks], ax mov [disk_spc], ax
; set partition size
; we dont rely on the 'total sectors' given in the BPB
; instead, we assume maximum cylinder
; 1023 is the maximum encodable for int 13h
mov di, 1023
mul di
mov [part_size], ax
mov [part_size+2], dx
; set partition offset to zero
xor ax, ax
mov [part_offset], ax
mov [part_offset+2], ax
ret
select_hdd:
call seek_zero
call read
mov bx, disk_buffer+0x1BE
lea si, [bx+8]
lea di, [part_offset]
mov cx, 4
rep movsw
ret ret
; Set absolute sector number ; Set absolute sector number
@ -79,7 +104,7 @@ seek: push ax
jz seek_zero jz seek_zero
; dx:ax = lba ; dx:ax = lba
div word [disk_tracks] div word [disk_spc]
xchg ax, dx xchg ax, dx
; dx = cylinder, ax = head * spt + sector ; dx = cylinder, ax = head * spt + sector
div byte [disk_spt] div byte [disk_spt]
@ -98,8 +123,14 @@ seek: push ax
ret ret
seek_zero: seek_zero:
; set chs data to first sector
mov byte [disk_chs+1], 0 mov byte [disk_chs+1], 0
mov word [disk_chs+2], 1 mov word [disk_chs+2], 1
; set lba data to first sector
lea di, [disk_dap+dapsec]
mov cx, 4
xor ax, ax
rep stosw
ret ret
; Read a sector into buffer ; Read a sector into buffer