2019-05-30 16:59:25 +03:00
|
|
|
; ***********************************************
|
|
|
|
; Reads a disk sector with an LBA address
|
|
|
|
; ***********************************************
|
|
|
|
|
|
|
|
; IN:
|
|
|
|
; EAX = LBA sector to load
|
|
|
|
; DL = Drive number
|
|
|
|
; ES = Buffer segment
|
|
|
|
; BX = Buffer offset
|
|
|
|
|
|
|
|
; OUT:
|
|
|
|
; Carry if error
|
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
read_sector:
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
push es
|
|
|
|
pop word [.target_segment]
|
|
|
|
mov word [.target_offset], bx
|
|
|
|
mov dword [.lba_address_low], eax
|
|
|
|
|
|
|
|
xor esi, esi
|
|
|
|
mov si, .da_struct
|
|
|
|
mov ah, 0x42
|
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
clc
|
|
|
|
int 0x13
|
2020-01-22 06:12:55 +03:00
|
|
|
|
|
|
|
.done:
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
2020-01-22 07:02:12 +03:00
|
|
|
ret
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
align 4
|
|
|
|
.da_struct:
|
|
|
|
.packet_size db 16
|
|
|
|
.unused db 0
|
|
|
|
.count dw 1
|
|
|
|
.target_offset dw 0
|
|
|
|
.target_segment dw 0
|
|
|
|
.lba_address_low dd 0
|
|
|
|
.lba_address_high dd 0
|
|
|
|
|
|
|
|
; ********************************************
|
|
|
|
; Reads multiple LBA addressed sectors
|
|
|
|
; ********************************************
|
|
|
|
|
|
|
|
; IN:
|
|
|
|
; EAX = LBA starting sector
|
|
|
|
; DL = Drive number
|
|
|
|
; ES = Buffer segment
|
|
|
|
; EBX = Buffer offset
|
2020-01-22 06:12:55 +03:00
|
|
|
; ECX = Sectors count
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
; OUT:
|
|
|
|
; Carry if error
|
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
%define TEMP_BUFFER_SEG 0x7000
|
|
|
|
%define BYTES_PER_SECT 512
|
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
read_sectors:
|
|
|
|
push eax ; Save GPRs
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
push esi
|
|
|
|
push edi
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
.loop:
|
|
|
|
push es
|
|
|
|
push ebx
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
mov bx, TEMP_BUFFER_SEG
|
2020-01-22 06:12:55 +03:00
|
|
|
mov es, bx
|
|
|
|
xor bx, bx
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
call read_sector
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
pop ebx
|
|
|
|
pop es
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
jc .done
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
push ds
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
mov si, TEMP_BUFFER_SEG
|
2020-01-22 06:12:55 +03:00
|
|
|
mov ds, si
|
|
|
|
mov edi, ebx
|
|
|
|
xor esi, esi
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
push ecx
|
2020-01-22 07:02:12 +03:00
|
|
|
mov ecx, BYTES_PER_SECT
|
2020-01-22 06:12:55 +03:00
|
|
|
a32 o32 rep movsb
|
|
|
|
pop ecx
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
pop ds
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
inc eax
|
|
|
|
add ebx, BYTES_PER_SECT
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 07:02:12 +03:00
|
|
|
loop .loop
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
.done:
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop edx
|
2020-01-22 07:02:12 +03:00
|
|
|
pop ecx
|
2020-01-22 06:12:55 +03:00
|
|
|
pop ebx
|
|
|
|
pop eax
|
2020-01-22 07:02:12 +03:00
|
|
|
ret
|