From e8fb22c826a84008654b6ce78ec6641cb6fc4e5b Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Fri, 11 Oct 2024 14:25:01 -0400 Subject: [PATCH] somewhat of a cludge, but added a macro to save all caller saved regs --- include/cdecl16.inc | 16 ++++++++++++++++ include/fat32/FAT32_SYS.inc | 24 +++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/cdecl16.inc b/include/cdecl16.inc index 81477e8..60583ad 100644 --- a/include/cdecl16.inc +++ b/include/cdecl16.inc @@ -38,4 +38,20 @@ mov sp, bp pop bp %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 \ No newline at end of file diff --git a/include/fat32/FAT32_SYS.inc b/include/fat32/FAT32_SYS.inc index 70d91ac..902d887 100644 --- a/include/fat32/FAT32_SYS.inc +++ b/include/fat32/FAT32_SYS.inc @@ -91,6 +91,8 @@ SearchFATDIR: mov eax, [fat32_ebpb + FAT32_ebpb_t.root_dir_cluster_32] mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax + __CDECL16_CALLER_SAVE + push dword eax ; cluster lea ax, [dir_buffer] push ax ; offset @@ -99,16 +101,20 @@ SearchFATDIR: call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster) add sp, 0x8 + __CDECL16_CALLER_RESTORE + lea si, [dir_buffer] jmp SearchFATDIR.empty_dir_entry .load_next_dir: ; 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 + __CDECL16_CALLER_SAVE mov eax, dword [fat32_state + FAT32_State_t.active_dir_cluster_32] push dword eax call NextCluster ; uint32_t NextCluster(uint32_t active_cluster); add sp, 0x4 + __CDECL16_CALLER_RESTORE cmp eax, 0x0fff_fff7 jb SearchFATDIR.load_next_dir_next_OK @@ -116,15 +122,18 @@ SearchFATDIR: .load_next_dir_next_OK: ; load 512 bytes of directory entries from data sector + __CDECL16_CALLER_SAVE mov eax, [fat32_state + FAT32_State_t.active_dir_cluster_32] + push dword eax ; cluster - push dword eax - lea ax, [dir_buffer] ; cluster + lea ax, [dir_buffer] push ax ; offset + xor ax, ax push ax ; segment call ReadFATCluster ; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster) sub sp, 0x8 + __CDECL16_CALLER_RESTORE lea si, [dir_buffer] .empty_dir_entry: @@ -181,7 +190,7 @@ SearchFATDIR: .endp: __CDECL16_EXIT ret - +; BUG: this function needs review ; uint32_t NextCluster(uint32_t active_cluster); ; 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 @@ -232,6 +241,7 @@ NextCluster: add eax, ecx ; fat_sector + first_fat_sector mov dword [si + FAT32_NextClusterData_t.fat_sector], eax .load_fat_table: + __CDECL16_CALLER_SAVE movzx ax, [bp - 2] push ax @@ -249,6 +259,7 @@ NextCluster: push ax call read_disk_raw add sp, 0xC + __CDECL16_CALLER_RESTORE ; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset, ; uint32_t lba, ; uint16_t count, uint16_t drive_num) @@ -281,6 +292,7 @@ ALIGN 4, db 0x90 ReadFATCluster: __CDECL16_ENTRY .func: + __CDECL16_CALLER_SAVE mov bx, [boot_drive_ptr] mov ax, [bx + 0] 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) add sp, 0x4 ; eax == LBA mov dword [bp - 6], eax + __CDECL16_CALLER_RESTORE + __CDECL16_CALLER_SAVE movzx ax, [bp - 2] push ax @@ -305,8 +319,12 @@ ReadFATCluster: xor ax, 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 add sp, 0xC + __CDECL16_CALLER_RESTORE .endp: __CDECL16_EXIT ret