remove the dword stack macros and just use the 32bit override
This commit is contained in:
@@ -207,50 +207,6 @@ struc AddressRangeDescStruct_t
|
|||||||
.ExtType resd 1
|
.ExtType resd 1
|
||||||
endstruc
|
endstruc
|
||||||
|
|
||||||
; moves argument into eax then pushes lower 16bits then upper 16 bits of of argument to stack
|
|
||||||
; eax is clobbered
|
|
||||||
%macro PUSH_DWORD 1
|
|
||||||
mov eax, %1
|
|
||||||
push ax
|
|
||||||
shr eax, 16
|
|
||||||
push ax
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; same as PUSH_DWORD except no arguments, pushes EAX directly
|
|
||||||
%macro PUSH_DWORD_EAX 0
|
|
||||||
push ax
|
|
||||||
shr eax, 16
|
|
||||||
push ax
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; pops upper 16bits then lower 16bits into eax
|
|
||||||
; eax is clobbered
|
|
||||||
%macro POP_DWORD_EAX 0
|
|
||||||
xor eax, eax
|
|
||||||
pop ax
|
|
||||||
shl eax, 16
|
|
||||||
pop ax
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; moves data on stack referenced by bp to eax
|
|
||||||
; stack must be organized as follows (tl;dr push lower 16bits first ie. PUSH_DWORD macro)
|
|
||||||
; MOV_DWORD_EAX 2
|
|
||||||
; STACK TOP (0x0)
|
|
||||||
; upper_uint16 [bp-4]
|
|
||||||
; lower_uint16 [bp-2]
|
|
||||||
; --- [bp] ---
|
|
||||||
; ...
|
|
||||||
; STACK BOTTOM
|
|
||||||
;
|
|
||||||
; first argument == starting offset from bp for lower 16bits
|
|
||||||
; BUG: needs fixed for cdecl16
|
|
||||||
%macro MOV_DWORD_EAX 1
|
|
||||||
mov ax, [bp+(%1+2)]
|
|
||||||
shl eax, 16
|
|
||||||
mov ax, [bp+%1]
|
|
||||||
; eax contains dword from stack
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
%macro DEBUG_HCF 0
|
%macro DEBUG_HCF 0
|
||||||
DEBUG_LOOP:
|
DEBUG_LOOP:
|
||||||
hlt
|
hlt
|
||||||
|
|||||||
@@ -110,15 +110,17 @@ main:
|
|||||||
; Find first cluster of bootable file
|
; Find first cluster of bootable file
|
||||||
;
|
;
|
||||||
call SearchFATDIR
|
call SearchFATDIR
|
||||||
PUSH_DWORD_EAX ; save return value of function as a 32-bit value on a 16-bit aligned stack
|
push dword eax
|
||||||
|
|
||||||
lea ax, [FileFound_OK_cstr]
|
lea ax, [FileFound_OK_cstr]
|
||||||
push ax
|
push ax
|
||||||
call PrintString
|
call PrintString
|
||||||
add sp, 0x2
|
add sp, 0x2
|
||||||
|
|
||||||
call PrintDWORD ; print 32bit value void PrintDWORD(uint32_t dword)
|
push dword eax
|
||||||
|
call PrintDWORD ; void PrintDWORD(uint32_t dword)
|
||||||
|
add sp, 0x4
|
||||||
|
|
||||||
lea ax, [NewLine_cstr]
|
lea ax, [NewLine_cstr]
|
||||||
push ax
|
push ax
|
||||||
call PrintString
|
call PrintString
|
||||||
@@ -194,12 +196,11 @@ InitFATDriver:
|
|||||||
SearchFATDIR:
|
SearchFATDIR:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.file_lookup:
|
.file_lookup:
|
||||||
xor ecx, ecx
|
|
||||||
xor edx, edx
|
|
||||||
.load_first_dir:
|
.load_first_dir:
|
||||||
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
|
||||||
PUSH_DWORD_EAX
|
|
||||||
|
push dword eax ; cluster
|
||||||
lea ax, [dir_buffer]
|
lea ax, [dir_buffer]
|
||||||
push ax ; offset
|
push ax ; offset
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
@@ -211,12 +212,11 @@ SearchFATDIR:
|
|||||||
jmp SearchFATDIR.empty_dir_entry
|
jmp SearchFATDIR.empty_dir_entry
|
||||||
|
|
||||||
.load_next_dir:
|
.load_next_dir:
|
||||||
; 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
|
||||||
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
|
call NextCluster ; uint32_t NextCluster(uint32_t active_cluster);
|
||||||
add sp, 0x4
|
add sp, 0x4
|
||||||
|
|
||||||
cmp eax, 0x0fff_fff7
|
cmp eax, 0x0fff_fff7
|
||||||
@@ -226,12 +226,12 @@ 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
|
||||||
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
|
|
||||||
lea ax, [dir_buffer]
|
push dword eax
|
||||||
|
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
|
||||||
|
|
||||||
@@ -297,8 +297,7 @@ SearchFATDIR:
|
|||||||
NextCluster:
|
NextCluster:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
MOV_DWORD_EAX 2
|
mov dword edx, [bp + 4]
|
||||||
mov edx, eax
|
|
||||||
mov si, fat32_nc_data
|
mov si, fat32_nc_data
|
||||||
.calc_offset:
|
.calc_offset:
|
||||||
; fat_offset = active_cluster * 4
|
; fat_offset = active_cluster * 4
|
||||||
@@ -336,19 +335,15 @@ NextCluster:
|
|||||||
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
||||||
.load_fat_table:
|
.load_fat_table:
|
||||||
; load correct fat
|
; load correct fat
|
||||||
ror eax, 16
|
push dword eax
|
||||||
push ax
|
|
||||||
ror eax, 16
|
|
||||||
push ax
|
|
||||||
|
|
||||||
mov ax, fat_buffer
|
mov ax, fat_buffer
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
||||||
call read_disk_raw ; read_disk_raw(0, fat_buffer, 31:16 fat_sector, 15:0 fat_sector)
|
call read_disk_raw ; read_disk_raw(0, fat_buffer, fat_sector)
|
||||||
add sp, 0x8
|
add sp, 0x8
|
||||||
|
|
||||||
.read_cluster:
|
.read_cluster:
|
||||||
@@ -364,7 +359,7 @@ NextCluster:
|
|||||||
ClusterToLBA:
|
ClusterToLBA:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
MOV_DWORD_EAX 2
|
mov dword eax, [bp + 4]
|
||||||
sub eax, 2
|
sub eax, 2
|
||||||
movzx edx, byte [fat32_bpb + FAT32_bpb_t.sectors_per_cluster_8]
|
movzx edx, byte [fat32_bpb + FAT32_bpb_t.sectors_per_cluster_8]
|
||||||
mul edx
|
mul edx
|
||||||
@@ -378,26 +373,21 @@ ClusterToLBA:
|
|||||||
ReadFATCluster:
|
ReadFATCluster:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
MOV_DWORD_EAX 8
|
mov dword eax, [bp + 8]
|
||||||
PUSH_DWORD_EAX
|
push dword eax
|
||||||
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 dx, [bp + 4] ; seg
|
push dword eax ;uint32_t lba
|
||||||
shl edx, 16
|
|
||||||
mov dx, [bp + 6] ; offset
|
|
||||||
|
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
|
||||||
ror eax, 16
|
|
||||||
push ax
|
|
||||||
ror eax, 16
|
|
||||||
push ax ; uint32 cluster split to two (2) uint16_t's (lower and upper LBA)
|
|
||||||
|
|
||||||
|
mov dx, [bp + 4] ; seg
|
||||||
push dx ; uint16_t buf_offset
|
push dx ; uint16_t buf_offset
|
||||||
ror edx, 16
|
|
||||||
|
mov dx, [bp + 6] ; offset
|
||||||
push dx ; unit16_t segment
|
push dx ; unit16_t segment
|
||||||
|
|
||||||
call read_disk_raw
|
call read_disk_raw ; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint32_t lba)
|
||||||
add sp, 0x8
|
add sp, 0x8
|
||||||
.endp:
|
.endp:
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
@@ -426,13 +416,7 @@ ReadFATCluster:
|
|||||||
; successfully transferred
|
; successfully transferred
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint32_t lba)
|
||||||
; bp-0 = call frame
|
|
||||||
; bp-2 = upper_lower_lba
|
|
||||||
; bp-4 = lower_lower_lba
|
|
||||||
; bp-6 = offset
|
|
||||||
; bp-8 = segment
|
|
||||||
; bp-10 = ret ptr
|
|
||||||
; TODO: this needs validation
|
; TODO: this needs validation
|
||||||
read_disk_raw:
|
read_disk_raw:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
@@ -450,15 +434,13 @@ read_disk_raw:
|
|||||||
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
||||||
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
||||||
|
|
||||||
mov ax, [bp + 4]
|
mov dword eax, [bp + 8]
|
||||||
shl eax, 16
|
|
||||||
mov ax, [bp + 6]
|
|
||||||
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
||||||
|
|
||||||
mov ax, [bp + 8]
|
mov ax, [bp + 6]
|
||||||
mov word [lba_packet + LBAPkt_t.offset], ax
|
mov word [lba_packet + LBAPkt_t.offset], ax
|
||||||
|
|
||||||
mov ax, [bp + 10]
|
mov ax, [bp + 4]
|
||||||
mov word [lba_packet + LBAPkt_t.segment], ax
|
mov word [lba_packet + LBAPkt_t.segment], ax
|
||||||
|
|
||||||
mov si, lba_packet
|
mov si, lba_packet
|
||||||
@@ -520,17 +502,15 @@ PrintCharacter:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; TODO: fix the prolog, epilog and stack usage to confirm with cdecl16
|
; TODO: fix the prolog, epilog and stack usage to confirm with cdecl16
|
||||||
; prints the hex representation of of val_upper:val_lower (4 byte value)
|
; prints the hex representation of of val
|
||||||
; void PrintDWORD(uint16_t val_upper, uint16_t val_lower);
|
; void PrintDWORD(uint32_t val);
|
||||||
PrintDWORD:
|
PrintDWORD:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
lea si, [IntToHex_table]
|
lea si, [IntToHex_table]
|
||||||
mov ebx, 16 ; base-16
|
mov ebx, 16 ; base-16
|
||||||
|
|
||||||
mov ax, [bp + 6] ; val_upper
|
mov dword eax, [bp + 4] ;val
|
||||||
shl eax, 16
|
|
||||||
mov ax, [bp + 2] ; val_lower
|
|
||||||
|
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
xor cx, cx
|
xor cx, cx
|
||||||
|
|||||||
Reference in New Issue
Block a user