ClusterToLBA to fastcall
cleanup of NextCluster
This commit is contained in:
@@ -40,8 +40,7 @@ InitFATDriver:
|
|||||||
sub sp, 0x6
|
sub sp, 0x6
|
||||||
|
|
||||||
.calc_active_part:
|
.calc_active_part:
|
||||||
mov bx, [partition_offset_ptr]
|
mov bx, [partition_offset]
|
||||||
mov cx, word [ds:bx]
|
|
||||||
mov ax, partition_table
|
mov ax, partition_table
|
||||||
add ax, cx
|
add ax, cx
|
||||||
mov si, ax ; si = offset to active partition
|
mov si, ax ; si = offset to active partition
|
||||||
@@ -222,44 +221,29 @@ NextCluster:
|
|||||||
mov edx, dword [bp + 4]
|
mov edx, dword [bp + 4]
|
||||||
mov si, fat32_nc_data ; instead of push/pop and moving the data back
|
mov si, fat32_nc_data ; instead of push/pop and moving the data back
|
||||||
mov di, fat32_bpb ; load si & di then use xchg
|
mov di, fat32_bpb ; load si & di then use xchg
|
||||||
|
mov bx, fat32_state
|
||||||
.calc_offset:
|
.calc_offset:
|
||||||
; fat_offset = active_cluster * 4
|
; fat_offset = active_cluster * 4
|
||||||
mov eax, 4
|
mov eax, 4
|
||||||
mul edx
|
mul edx
|
||||||
jc NextCluster.error_cfdivz
|
jc NextCluster.error_cfdivz
|
||||||
mov dword [si + FAT32_NextClusterData_t.fat_offset], eax ; move lower 32 bits to fat offset
|
mov dword [si + FAT32_NextClusterData_t.fat_offset], eax ; move lower 32 bits to fat offset
|
||||||
|
|
||||||
.calc_fat_sector:
|
.calc_fat_sector:
|
||||||
; fat_sector = first_fat_sector + (fat_offset / sector_size)
|
; fat_sector = first_fat_sector + (fat_offset / sector_size)
|
||||||
; entry_offset = fat_offset % sector_size
|
; entry_offset = fat_offset % sector_size
|
||||||
mov edx, 0xffff_0000
|
xor edx, edx
|
||||||
and edx, eax
|
movzx ecx, word [di + FAT32_bpb_t.bytes_per_sector_word]
|
||||||
shr edx, 16
|
cmp eax, 0
|
||||||
|
|
||||||
xchg si, di ; switch to fat32_bpb in si
|
|
||||||
mov cx, word [si + FAT32_bpb_t.bytes_per_sector_word]
|
|
||||||
xchg si, di
|
|
||||||
|
|
||||||
cmp edx, 0
|
|
||||||
je NextCluster.error_cfdivz
|
je NextCluster.error_cfdivz
|
||||||
div cx ; DX:AX / cx = fat_sector - first_fat_sector in AX
|
div ecx ; eDX:eAX / eCX = fat_sector - first_fat_sector in eAX
|
||||||
; DX = remainder (fat_offset mod sector_size)
|
; eDX = remainder (fat_offset mod sector_size)
|
||||||
|
|
||||||
mov ecx, 0x0000_ffff
|
|
||||||
and edx, ecx
|
|
||||||
mov dword [si + FAT32_NextClusterData_t.entry_offset], edx
|
mov dword [si + FAT32_NextClusterData_t.entry_offset], edx
|
||||||
|
mov ecx, dword [bx + FAT32_State_t.first_fat_sector_32]
|
||||||
xchg si, di ; switch to fat32_bpb in si
|
|
||||||
mov ecx, dword [si + FAT32_State_t.first_fat_sector_32]
|
|
||||||
xchg si, di
|
|
||||||
|
|
||||||
mov edx, 0x0000ffff
|
|
||||||
and eax, edx
|
|
||||||
add eax, ecx ; fat_sector + first_fat_sector
|
add eax, ecx ; fat_sector + first_fat_sector
|
||||||
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
||||||
.load_fat_table:
|
.load_fat_table:
|
||||||
mov bx, word [boot_drive_ptr]
|
mov ax, word [boot_drive]
|
||||||
movzx ax, byte [ds:bx]
|
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
mov ax, 0x1
|
mov ax, 0x1
|
||||||
@@ -304,20 +288,21 @@ NextCluster:
|
|||||||
.error_cfdivz:
|
.error_cfdivz:
|
||||||
ERROR STAGE2_FAT32_NCLUS_CFDIVZ
|
ERROR STAGE2_FAT32_NCLUS_CFDIVZ
|
||||||
|
|
||||||
; uint32_t ClusterToLBA(uint32_t cluster)
|
; __fastcall16 uint32_t ClusterToLBA(uint32_t cluster)
|
||||||
|
; input = dword cluster in eax
|
||||||
ALIGN 4, db 0x90
|
ALIGN 4, db 0x90
|
||||||
ClusterToLBA:
|
ClusterToLBA:
|
||||||
__CDECL16_ENTRY
|
__FASTCALL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
mov dword eax, [bp + 4]
|
|
||||||
sub eax, 2
|
sub eax, 2
|
||||||
movzx edx, byte [fat32_bpb + FAT32_bpb_t.sectors_per_cluster_byte]
|
movzx edx, byte [fat32_bpb + FAT32_bpb_t.sectors_per_cluster_byte]
|
||||||
mul edx
|
mul edx ; result in eax, error on carry
|
||||||
jc ClusterToLBA.error
|
jc ClusterToLBA.error
|
||||||
add eax, dword [fat32_state + FAT32_State_t.first_data_sector_32]
|
add eax, dword [fat32_state + FAT32_State_t.first_data_sector_32]
|
||||||
|
jc ClusterToLBA.error
|
||||||
; eax contains the LBA now
|
; eax contains the LBA now
|
||||||
.endp:
|
.endp:
|
||||||
__CDECL16_EXIT
|
__FASTCALL16_EXIT
|
||||||
ret
|
ret
|
||||||
.error:
|
.error:
|
||||||
ERROR STAGE2_FAT32_CLS2LBA_CF
|
ERROR STAGE2_FAT32_CLS2LBA_CF
|
||||||
@@ -330,24 +315,21 @@ ReadFATCluster:
|
|||||||
.func:
|
.func:
|
||||||
print_string ReadFATCluster_info
|
print_string ReadFATCluster_info
|
||||||
|
|
||||||
mov bx, word [boot_drive_ptr]
|
mov ax, word [boot_drive]
|
||||||
movzx ax, byte [ds:bx]
|
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
mov ax, 0x1 ; count = 1
|
mov ax, 0x1 ; count = 1
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
mov eax, dword [bp + 8]
|
mov eax, dword [bp + 8]
|
||||||
push dword eax
|
call ClusterToLBA ; __fastcall16 uint32_t ClusterToLBA(uint32_t cluster)
|
||||||
call ClusterToLBA
|
|
||||||
add sp, 0x4
|
|
||||||
; eax contains the LBA now
|
; eax contains the LBA now
|
||||||
push dword eax ; lba = ClusterToLBA(..)
|
push dword eax ; lba = ClusterToLBA(..)
|
||||||
|
|
||||||
mov ax, fat_buffer ; offset = fat_buffer (in mem.inc)
|
mov ax, word [bp + 6] ; offset
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
xor ax, ax ; segment = 0x0000, our buffer is in the first 64 KiB
|
mov ax, word [bp + 4]
|
||||||
push ax
|
push ax
|
||||||
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||||
; uint32_t lba,
|
; uint32_t lba,
|
||||||
|
|||||||
Reference in New Issue
Block a user