From 2cb39a4ff1ae6396914a2d42c50f0dbf0ab0ce10 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Fri, 8 May 2020 20:48:23 +0000 Subject: [PATCH] Implement lba read --- kernel/diskio.asm | 56 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/kernel/diskio.asm b/kernel/diskio.asm index 1ff7504..3f344a4 100644 --- a/kernel/diskio.asm +++ b/kernel/diskio.asm @@ -9,27 +9,28 @@ disk_current: lba_supported: resb 1 + ; Seek state and geometry info for CHS access disk_chs: ; DL, DH, CL, CH for int 13h CHS functions resb 4 -disk_dap: ; disk access packet for int 13h EBIOS functions - resb 0x10 - disk_spc: ; sectors per cylinder = heads * spt resw 1 disk_spt: resb 1 + ; Partition conf from MBR or dummy for floppies part_offset: resd 1 part_size: resd 1 - ; Disk access packet for EBIOS extensions -dapps: equ 0 ; byte packet size -dapnum: equ 2 ; word number of sectors to transfer -dapbuf: equ 4 ; dword transfer buffer -dapsec: equ 8 ; qword absolute sector number -dapsiz: equ 16 +dap: ; Disk access packet for EBIOS extensions + resw 1 +dap_sectors: + resw 1 +dap_buffer: + resd 1 +dap_sector: + resq 1 section .text @@ -46,14 +47,15 @@ dncl: rcl dl, 1 ret ; Select a drive for I/O + ; This leave the first sector of the partition in the buffer ; IN dl 0=A, 1=B, 2=C, 3=D select: mov byte [disk_current], 0xFF mov byte [lba_supported], 0 - cmp dl, 0x02 - jc select_floppy - ; detect EBIOS/LBA extensions call dnconv mov byte [disk_chs], dl + cmp dl, 0x80 + jc select_floppy + ; detect EBIOS/LBA extensions mov ah, 0x41 mov bx, 0x55AA int 0x13 @@ -123,6 +125,9 @@ seek: push ax pop ax jz seek_zero + test byte [lba_supported], 1 + jnz seek_lba + ; dx:ax = lba div word [disk_spc] xchg ax, dx @@ -147,14 +152,26 @@ seek_zero: mov byte [disk_chs+1], 0 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 + xor dx, dx +seek_lba: + mov word [dap], 0x10 + mov word [dap_sectors], 1 + mov word [dap_buffer], disk_buffer + mov [dap_buffer+2], cs + lea di, [dap_sector] + stosw + mov ax, dx + stosw + xor ax, ax + stosw + stosw ret ; Read a sector into buffer -read: mov ax, 0x0201 +read: test byte [lba_supported], 1 + jnz read_lba + mov ax, 0x0201 mov dx, [disk_chs] mov cx, [disk_chs+2] lea bx, [disk_buffer] @@ -163,6 +180,13 @@ read: mov ax, 0x0201 int 0x13 ret +read_lba: + mov ah, 0x42 + mov dl, [disk_chs] + lea si, [dap] + int 0x13 + ret + ; Write a sector into buffer write: stc ret