StupidOS/boot/loader/disk.inc

79 lines
1.1 KiB
PHP
Raw Normal View History

2024-07-29 14:40:21 +00:00
;; File: disk.inc
2024-05-28 04:54:10 +00:00
2024-07-29 14:40:21 +00:00
;; Function: disk_read_sectors
;;
;; In:
;; AX - LBA starting sector
;; CX - Sector count
;; ES:BX - buffer
2024-05-28 04:54:10 +00:00
disk_read_sectors:
; test byte [bDriveLBA], TRUE
; je .lba_read
2024-05-28 04:54:10 +00:00
push ax
push bx
push cx
xor dx, dx
div word [sectors_per_track]
inc dx
mov [S], dx
xor dx, dx
div word [heads_per_cylinder]
mov [C], ax
mov [H], dx
mov ah, 0x2
mov al, 0x1
mov ch, byte [C]
mov cl, byte [S]
mov dh, byte [H]
2024-06-07 09:25:28 +00:00
mov dl, [uDrive]
2024-05-28 04:54:10 +00:00
int 0x13
jc @f
pop cx
pop bx
pop ax
add bx, word [bytes_per_sector]
inc ax
loop disk_read_sectors
ret
@@:
2024-06-07 09:25:28 +00:00
mov si, szMsgErrorSector
2024-05-28 04:54:10 +00:00
call bios_print
ret
.lba_read:
mov word [disk_packet.sectors], cx
mov word [disk_packet.segment], es
mov word [disk_packet.offset], bx
mov word [disk_packet.lba], ax
mov ds, [disk_packet]
2024-06-07 09:25:28 +00:00
mov dl, [uDrive]
2024-05-28 04:54:10 +00:00
mov ah, 0x42
int 0x13
ret
C dw 0x00
H dw 0x00
S dw 0x00
disk_packet:
db 0x10
db 0
.sectors:
dw 0
.segment:
dw 0
.offset:
dw 0
.lba:
dd 0
dd 0
sectors_per_track dw 18
heads_per_cylinder dw 2
bytes_per_sector dw 512
sectors_per_FAT dw 9
FAT_count db 2
reserved_sectors dw 1
root_dir_entries dw 224
sectors_per_cluster db 1