inlined ClusterToLBA into ReadFATCluster

fixed a bug where fat32_state wasn't being updated...
This commit is contained in:
2024-12-20 10:10:12 -05:00
parent ce73226eee
commit ddd3f35a8b

View File

@@ -41,19 +41,17 @@ InitFATDriver:
.calc_active_part: .calc_active_part:
mov ax, word [partition_offset] mov ax, word [partition_offset]
mov di, fat32_state
mov dx, partition_table mov dx, partition_table
add dx, ax ; dx points to the partition that was booted from add dx, ax ; dx points to the partition that was booted from
mov bx, dx ; set bx, should point at our partition mov bx, dx ; set bx, should point at our partition
mov eax, dword [bx + PartEntry_t.lba_start] mov eax, dword [bx + PartEntry_t.lba_start]
mov dword [fat32_state + FAT32_State_t.curr_drive_lba_32], eax mov dword [di + FAT32_State_t.curr_drive_lba_32], eax
mov ax, fat32_bpb mov si, fat32_bpb
mov si, ax mov bx, fat32_ebpb
mov ax, fat32_ebpb
mov bx, ax
.calc_first_fat: .calc_first_fat:
movzx eax, word [si + FAT32_bpb_t.reserved_sectors_word] ; first fat from start of partition movzx eax, word [si + FAT32_bpb_t.reserved_sectors_word] ; first fat from start of partition
add eax, dword [di + FAT32_State_t.curr_drive_lba_32] ; calculate offset from start of drive add eax, dword [di + FAT32_State_t.curr_drive_lba_32] ; calculate offset from start of drive
@@ -275,26 +273,6 @@ NextCluster:
.error_cfdivz: .error_cfdivz:
ERROR STAGE2_FAT32_NCLUS_CFDIVZ ERROR STAGE2_FAT32_NCLUS_CFDIVZ
; __fastcall16 uint32_t ClusterToLBA(uint32_t cluster)
; input = dword cluster in eax
ALIGN 4, db 0x90
ClusterToLBA:
__FASTCALL16_ENTRY
.func:
sub eax, 2
movzx edx, byte [fat32_bpb + FAT32_bpb_t.sectors_per_cluster_byte]
mul edx ; result in eax, error on carry
jc ClusterToLBA.error
add eax, dword [fat32_state + FAT32_State_t.first_data_sector_32]
jc ClusterToLBA.error
; eax contains the LBA now
.endp:
__FASTCALL16_EXIT
ret
.error:
ERROR STAGE2_FAT32_CLS2LBA_CF
; bp - 2 - byte boot_drive
; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster) ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
ALIGN 4, db 0x90 ALIGN 4, db 0x90
ReadFATCluster: ReadFATCluster:
@@ -302,6 +280,9 @@ ReadFATCluster:
.func: .func:
print_string ReadFATCluster_info print_string ReadFATCluster_info
mov bx, fat32_bpb
mov si, fat32_ebpb
xor ax, ax xor ax, ax
mov al, byte [boot_drive] mov al, byte [boot_drive]
push ax push ax
@@ -309,8 +290,14 @@ ReadFATCluster:
mov ax, 0x1 ; count = 1 mov ax, 0x1 ; count = 1
push ax push ax
mov eax, dword [bp + 8] mov eax, dword [bp + 8] ; cluster
call ClusterToLBA ; __fastcall16 uint32_t ClusterToLBA(uint32_t cluster) sub eax, 2
movzx edx, byte [bx + FAT32_bpb_t.sectors_per_cluster_byte]
mul edx ; result in eax, error on carry
jc ReadFATCluster.error
add eax, dword [si + FAT32_State_t.first_data_sector_32]
jc ReadFATCluster.error
; eax contains the LBA now
push dword eax ; lba = ClusterToLBA(..) push dword eax ; lba = ClusterToLBA(..)
mov ax, word [bp + 6] ; offset mov ax, word [bp + 6] ; offset
@@ -326,6 +313,8 @@ ReadFATCluster:
.endp: .endp:
__CDECL16_EXIT __CDECL16_EXIT
ret ret
.error:
ERROR STAGE2_FAT32_CLS2LBA_CF
%endif %endif
%define __INC_FAT32_SYS %define __INC_FAT32_SYS