Code: Select all
;; Method: load_FAT_data
;;--------------------------------------
;; di => where to load
;;--------------------------------------
;; Loads the boot sector, FATs, and root directory
;; of the FAT filesystem on disk 0x80 to di. di must
;; point to enough space. Returns the number of sectors
;; read.
load_FAT_data:
push ebp
mov ebp, esp
sub esp, 4 ;; space for return value
pusha
push fs
lfd_read_bpb:
xor ecx, ecx
mov bx, di ;; offset to read to
xor eax, eax ;; reading the first sector
mov fs, ax ;; no segment variable
mov cx, 1 ;; only reading bpb sector
call read_sectors
add word [ebp - 4], cx ;; for return value
lfd_read_FATs:
mov ax, word [di + 22] ;; sectors per FAT
mul byte [di + 16] ;; number of FATs
mov cx, ax ;; that's how many sectors we need load
mov ax, word [di + 14] ;; FATs start right after the reserved sectors
add bx, 0x200 ;; read to sector after bpb
call read_sectors
add word [ebp - 4], cx ;; for return value
lfd_read_rootdir:
add ax, cx ;; rootdir is right after FATs, so add number just loaded
push ax ;; save ax so we can use it for calculations
mov cx, ax ;; num sectors loaded last
mov dx, 0x200 ;; size of a sector
mul dx ;; number of bytes loaded last
add bx, ax ;; add to memory index
mov ax, word [di + 17] ;; # of rootdir entries
mov dx, 0x20 ;; 32-byte entry
mul dx
mov edx, 0x200 ;; # of bytes per sector
div edx ;; <- this is the instruction that freezes it
mov cx, ax
pop ax
call read_sectors
add word [ebp - 4], cx ;; return value
pop fs
popa
mov ax, word [ebp - 4] ;; return value
mov esp, ebp
pop ebp
ret
Code: Select all
eax: 0x00004000 16384
ecx: 0x00000080 128
edx: 0x00000200 512
ebx: 0x00009e00 40448
esp: 0x00009be1 39905
ebp: 0x00009bf9 39929
esi: 0x00008ea5 36517
edi: 0x00009c00 39936
eip: 0x00008d95
eflags 0x00000206
id vip vif ac vm rf nt IOPL=0 of df IF tf sf zf af PF cf