kernel: implement diskio using drive table
This commit is contained in:
parent
4a294ee21c
commit
f0a000b7d1
5 changed files with 93 additions and 259 deletions
|
@ -16,6 +16,13 @@ drive_ptr: resw 1
|
|||
|
||||
drive_table: resb (drives * drive_size)
|
||||
|
||||
; DX and CX for int 13 CHS access
|
||||
chs_dx: resw 1
|
||||
chs_cx: resw 1
|
||||
|
||||
; disk buffer for I/O operations
|
||||
diskbuf: resb 1024
|
||||
|
||||
section .text
|
||||
|
||||
drives_init: ; CX = number of floppy drives in the system
|
||||
|
@ -32,6 +39,7 @@ drives_init: ; CX = number of floppy drives in the system
|
|||
.loop: push cx
|
||||
push dx
|
||||
mov [bx+drive.biosnum], dl
|
||||
mov byte [bx+drive.flag], 1 ; 1 = drive letter used
|
||||
; query bios for floppy format
|
||||
mov ah, 8
|
||||
push bx
|
||||
|
@ -82,3 +90,79 @@ drives_init: ; CX = number of floppy drives in the system
|
|||
add bx, drive_size
|
||||
loop .loop
|
||||
ret
|
||||
|
||||
; select drive
|
||||
; IN dl drive number
|
||||
drive_select: xor dh, dh
|
||||
mov ax, drive_size
|
||||
mul dx
|
||||
add ax, drive_table
|
||||
mov word [drive_ptr], ax
|
||||
ret
|
||||
|
||||
; reset currently selected drive
|
||||
drive_reset: mov bx, [drive_ptr]
|
||||
mov dl, [bx+drive.biosnum]
|
||||
; our ptr = CX:BX
|
||||
lea bx, [bx+drive.dpt]
|
||||
mov cx, ds
|
||||
; toggle in our ptr
|
||||
mov si, [0x1E*4]
|
||||
xchg bx, [si]
|
||||
xchg cx, [si+2]
|
||||
; do the call
|
||||
xor ax, ax
|
||||
int 0x13
|
||||
pushf
|
||||
; restore original ptr
|
||||
xchg bx, [si]
|
||||
xchg cx, [si+2]
|
||||
; pass int 13 flags
|
||||
popf
|
||||
ret
|
||||
|
||||
; query status of selected drive
|
||||
; OUT ah
|
||||
drive_status: mov bx, [drive_ptr]
|
||||
mov dl, [bx+drive.biosnum]
|
||||
mov ah, 1
|
||||
int 0x13
|
||||
ret
|
||||
|
||||
; set sector for read/write operation
|
||||
; IN dx:ax 32-bit sector number
|
||||
drive_seek: mov bx, [drive_ptr]
|
||||
div word [bx+drive.spc]
|
||||
xchg ax, dx
|
||||
; dx = cylinder, ax = head * spt + sector
|
||||
div byte [bx+drive.dpt+dpt.lastsector]
|
||||
; dx = cylinder, al = head, ah = sector
|
||||
xchg dl, dh
|
||||
ror dl, 1
|
||||
ror dl, 1
|
||||
or dl, ah
|
||||
inc dx
|
||||
; al: head number
|
||||
; dh bit 0-7: cylinder bits 0-7
|
||||
; dl bit 0-5: sector bits 0-5
|
||||
; dl bit 6-7: cylinder bits 8-9
|
||||
xchg al, ah
|
||||
mov al, [bx+drive.biosnum]
|
||||
; store
|
||||
mov word [chs_dx], ax
|
||||
mov word [chs_cx], dx
|
||||
ret
|
||||
|
||||
drive_read: mov ax, 0x0201
|
||||
mov cx, [chs_cx]
|
||||
mov dx, [chs_dx]
|
||||
mov bx, diskbuf
|
||||
int 0x13
|
||||
ret
|
||||
|
||||
drive_write: mov ah, 0x0301
|
||||
mov cx, [chs_cx]
|
||||
mov dx, [chs_dx]
|
||||
mov bx, diskbuf
|
||||
int 0x13
|
||||
ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue