somewhat of a cludge, but added a macro to save all caller saved regs

This commit is contained in:
2024-10-11 14:25:01 -04:00
parent 802d47fbf7
commit 71f13fd6b5
2 changed files with 37 additions and 3 deletions

View File

@@ -38,4 +38,20 @@
mov sp, bp mov sp, bp
pop bp pop bp
%endmacro %endmacro
%endif
%ifnmacro __CDECL16_CALLER_SAVE
%macro __CDECL16_CALLER_SAVE 0
push ax
push cx
push dx
%endmacro
%endif
%ifnmacro __CDECL16_CALLER_RESTORE
%macro __CDECL16_CALLER_RESTORE 0
pop dx
pop cx
pop ax
%endmacro
%endif %endif

View File

@@ -91,6 +91,8 @@ SearchFATDIR:
mov eax, [fat32_ebpb + FAT32_ebpb_t.root_dir_cluster_32] mov eax, [fat32_ebpb + FAT32_ebpb_t.root_dir_cluster_32]
mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax
__CDECL16_CALLER_SAVE
push dword eax ; cluster push dword eax ; cluster
lea ax, [dir_buffer] lea ax, [dir_buffer]
push ax ; offset push ax ; offset
@@ -99,16 +101,20 @@ SearchFATDIR:
call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster) call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
add sp, 0x8 add sp, 0x8
__CDECL16_CALLER_RESTORE
lea si, [dir_buffer] lea si, [dir_buffer]
jmp SearchFATDIR.empty_dir_entry jmp SearchFATDIR.empty_dir_entry
.load_next_dir: .load_next_dir:
; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain) ; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain)
; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad ; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad
__CDECL16_CALLER_SAVE
mov eax, dword [fat32_state + FAT32_State_t.active_dir_cluster_32] mov eax, dword [fat32_state + FAT32_State_t.active_dir_cluster_32]
push dword eax push dword eax
call NextCluster ; uint32_t NextCluster(uint32_t active_cluster); call NextCluster ; uint32_t NextCluster(uint32_t active_cluster);
add sp, 0x4 add sp, 0x4
__CDECL16_CALLER_RESTORE
cmp eax, 0x0fff_fff7 cmp eax, 0x0fff_fff7
jb SearchFATDIR.load_next_dir_next_OK jb SearchFATDIR.load_next_dir_next_OK
@@ -116,15 +122,18 @@ SearchFATDIR:
.load_next_dir_next_OK: .load_next_dir_next_OK:
; load 512 bytes of directory entries from data sector ; load 512 bytes of directory entries from data sector
__CDECL16_CALLER_SAVE
mov eax, [fat32_state + FAT32_State_t.active_dir_cluster_32] mov eax, [fat32_state + FAT32_State_t.active_dir_cluster_32]
push dword eax ; cluster
push dword eax lea ax, [dir_buffer]
lea ax, [dir_buffer] ; cluster
push ax ; offset push ax ; offset
xor ax, ax xor ax, ax
push ax ; segment push ax ; segment
call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster) call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
sub sp, 0x8 sub sp, 0x8
__CDECL16_CALLER_RESTORE
lea si, [dir_buffer] lea si, [dir_buffer]
.empty_dir_entry: .empty_dir_entry:
@@ -181,7 +190,7 @@ SearchFATDIR:
.endp: .endp:
__CDECL16_EXIT __CDECL16_EXIT
ret ret
; BUG: this function needs review
; uint32_t NextCluster(uint32_t active_cluster); ; uint32_t NextCluster(uint32_t active_cluster);
; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain) ; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain)
; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad ; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad
@@ -232,6 +241,7 @@ NextCluster:
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:
__CDECL16_CALLER_SAVE
movzx ax, [bp - 2] movzx ax, [bp - 2]
push ax push ax
@@ -249,6 +259,7 @@ NextCluster:
push ax push ax
call read_disk_raw call read_disk_raw
add sp, 0xC add sp, 0xC
__CDECL16_CALLER_RESTORE
; 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,
; uint16_t count, uint16_t drive_num) ; uint16_t count, uint16_t drive_num)
@@ -281,6 +292,7 @@ ALIGN 4, db 0x90
ReadFATCluster: ReadFATCluster:
__CDECL16_ENTRY __CDECL16_ENTRY
.func: .func:
__CDECL16_CALLER_SAVE
mov bx, [boot_drive_ptr] mov bx, [boot_drive_ptr]
mov ax, [bx + 0] mov ax, [bx + 0]
mov byte [bp - 2], al ; save boot drive as a local for easy access mov byte [bp - 2], al ; save boot drive as a local for easy access
@@ -290,7 +302,9 @@ ReadFATCluster:
call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster) call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster)
add sp, 0x4 ; eax == LBA add sp, 0x4 ; eax == LBA
mov dword [bp - 6], eax mov dword [bp - 6], eax
__CDECL16_CALLER_RESTORE
__CDECL16_CALLER_SAVE
movzx ax, [bp - 2] movzx ax, [bp - 2]
push ax push ax
@@ -305,8 +319,12 @@ ReadFATCluster:
xor ax, ax xor ax, ax
push ax push ax
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
; uint32_t lba,
; uint16_t count, uint16_t drive_num)
call read_disk_raw call read_disk_raw
add sp, 0xC add sp, 0xC
__CDECL16_CALLER_RESTORE
.endp: .endp:
__CDECL16_EXIT __CDECL16_EXIT
ret ret