Code: Select all
;; Method: read_sectors
;;--------------------------------------
;; cx = num sectors to read
;; eax = disk offset
;; es:bx => buffer to read to
;;--------------------------------------
;; Reads the number of sectors in cx from the disk offset in eax to the location es:bx.
;; Uses BIOS int 0x13. May not work if you have an old BIOS. The boot sector checks this.
;; Destroys values in eax, edx, esi, ecx
eoemsg db "Error in read_sectors, please reboot", 13, 10, 0
read_sectors:
;; Make a disk address packet
mov byte [diskaddr], 0x10 ;; packet size
mov byte [diskaddr+1], 0x00 ;; reserved byte
mov word [diskaddr+2], cx ;; num sectors
mov word [diskaddr+4], es ;; offset to write to
mov word [diskaddr+6], bx
mov dword [diskaddr+8], eax ;; disk address (LBA)
mov dword [diskaddr+0x0b], 0x00
xor ecx, ecx
mov cx, 5 ;; try 5 times, then exit on error
try_again:
mov si, diskaddr ;; address of disk packet
mov ah, 0x42 ;; instruction code
mov dl, 0x80 ;; disk to read (hard disk)
int 0x13
jnc rs_done
loop try_again ;; try again on error
jmp exit_on_error ;; after 5 tries, exit
rs_done:
ret
exit_on_error:
mov si, eoemsg
call print
jmp $
Code: Select all
int13_harddisk: function 42. LBA out of range
Code: Select all
eax: 0x00000013 19
ecx: 0x0000000e 14
edx: 0x00000000 0
ebx: 0x00000200 512
esp: 0x0000fffd 65533
ebp: 0x00000000 0
esi: 0x000e7c58 949336
edi: 0x0000ffac 65452
eip: 0x00007db3
eflags 0x00000246
id vip vif ac vm rf nt IOPL=0 of df IF tf sf ZF af PF cf