rename __CDECL16_ENTRY and EXIT

This commit is contained in:
2025-09-07 13:29:24 -04:00
parent 6f2fc627be
commit 9493aefa68
11 changed files with 75 additions and 70 deletions

View File

@@ -35,7 +35,7 @@ endstruc
ALIGN 4, db 0x90 ALIGN 4, db 0x90
GetMemoryMap: GetMemoryMap:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
push es ; save segment register push es ; save segment register
.func: .func:
mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], 0 mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], 0
@@ -83,11 +83,11 @@ GetMemoryMap:
ERROR STAGE2_MM_E820_NO_SMAP ERROR STAGE2_MM_E820_NO_SMAP
.endp: .endp:
pop es pop es
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
PrintMemoryMap: PrintMemoryMap:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov eax, dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries] mov eax, dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries]
cmp eax, 0 cmp eax, 0
@@ -106,15 +106,15 @@ PrintMemoryMap:
; print_string strformat_buffer ; print_string strformat_buffer
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
FormatMemoryMapEntry: FormatMemoryMapEntry:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
; create a string buffer somewhere and return address to result string in ax ; create a string buffer somewhere and return address to result string in ax
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret

View File

@@ -64,7 +64,7 @@
; Bits 6-7 - 00: HDD activity LED off; any other value is "on" ; Bits 6-7 - 00: HDD activity LED off; any other value is "on"
ALIGN 4, db 0x90 ALIGN 4, db 0x90
EnableA20: EnableA20:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
push ds push ds
push es push es
.a20_check: .a20_check:
@@ -134,7 +134,7 @@ EnableA20:
.endp: .endp:
pop es pop es
pop ds pop ds
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif

View File

@@ -76,7 +76,7 @@ endstruc
; uint16_t count, uint8_t drive_num) ; uint16_t count, uint8_t drive_num)
ALIGN 4, db 0x90 ALIGN 4, db 0x90
read_disk_raw: read_disk_raw:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov ax, LBAPkt_t_size mov ax, LBAPkt_t_size
push ax ; len push ax ; len
@@ -123,7 +123,7 @@ read_disk_raw:
ERROR STAGE2_MBR_DISK_READ_ERROR ERROR STAGE2_MBR_DISK_READ_ERROR
%endif %endif
.endf: .endf:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif

View File

@@ -20,7 +20,7 @@
ALIGN 4, db 0x90 ALIGN 4, db 0x90
SetTextMode: SetTextMode:
.prolog: .prolog:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
pushf pushf
.func: .func:
xor ah, ah ; Set Video mode BIOS function xor ah, ah ; Set Video mode BIOS function
@@ -33,14 +33,14 @@ SetTextMode:
int 0x10 ; call video interrupt int 0x10 ; call video interrupt
.endp: .endp:
popf popf
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; disables blinking text mode cursor via crtc pokes ; disables blinking text mode cursor via crtc pokes
; 0x3D4/0x3D5 for color, mono at 0x3B4/0x3B5 ; 0x3D4/0x3D5 for color, mono at 0x3B4/0x3B5
ALIGN 4, db 0x90 ALIGN 4, db 0x90
disable_cursor_crtc: disable_cursor_crtc:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov dx, 0x3D4 mov dx, 0x3D4
mov al, 0xA ; low cursor shape register mov al, 0xA ; low cursor shape register
@@ -50,13 +50,13 @@ disable_cursor_crtc:
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
out dx, al out dx, al
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; disables blinking text mode cursor via BIOS int 10h, ah = 01 ; disables blinking text mode cursor via BIOS int 10h, ah = 01
ALIGN 4, db 0x90 ALIGN 4, db 0x90
disable_cursor_bios: disable_cursor_bios:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
push bx push bx
mov ah, 03h ; read cursor pos & shape mov ah, 03h ; read cursor pos & shape
@@ -68,14 +68,14 @@ disable_cursor_bios:
int 10h int 10h
pop bx pop bx
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; Prints a C-Style string (null terminated) using BIOS vga teletype call ; Prints a C-Style string (null terminated) using BIOS vga teletype call
; void PrintString(char* buf) ; void PrintString(char* buf)
ALIGN 4, db 0x90 ALIGN 4, db 0x90
PrintString: PrintString:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
mov di, [bp + 4] ; first arg is char[] mov di, [bp + 4] ; first arg is char[]
.str_len: .str_len:
xor cx, cx ; ECX = 0 xor cx, cx ; ECX = 0
@@ -101,14 +101,14 @@ PrintString:
jcxz PrintString.endp jcxz PrintString.endp
jmp PrintString.print_L0 ; Fetch next character from string jmp PrintString.print_L0 ; Fetch next character from string
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ; Return from procedure ret ; Return from procedure
; Prints a single character ; Prints a single character
; void PrintCharacter(char c); ; void PrintCharacter(char c);
ALIGN 4, db 0x90 ALIGN 4, db 0x90
PrintCharacter: PrintCharacter:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov al, byte [bp + 4] ; AL = character c mov al, byte [bp + 4] ; AL = character c
mov ah, 0x0E ; INT 0x10, AH=0x0E call mov ah, 0x0E ; INT 0x10, AH=0x0E call
@@ -116,7 +116,7 @@ PrintCharacter:
int 0x10 ; call video interrupt int 0x10 ; call video interrupt
; TODO: check for carry and clear carry before call ; TODO: check for carry and clear carry before call
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
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
@@ -124,7 +124,7 @@ PrintCharacter:
; void PrintDWORD(uint32_t val); ; void PrintDWORD(uint32_t val);
ALIGN 4, db 0x90 ALIGN 4, db 0x90
PrintDWORD: PrintDWORD:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov si, IntToHex_table mov si, IntToHex_table
mov ebx, 16 ; base-16 mov ebx, 16 ; base-16
@@ -166,7 +166,7 @@ PrintDWORD:
jmp PrintDWORD.print_stack jmp PrintDWORD.print_stack
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif
%define __INC_VIDEO %define __INC_VIDEO

View File

@@ -13,8 +13,8 @@
; You should have received a copy of the GNU General Public License ; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>. ; along with this program. If not, see <https://www.gnu.org/licenses/>.
%ifnmacro __CDECL16_ENTRY %ifnmacro __CDECL16_PROC_ENTRY
%macro __CDECL16_ENTRY 0-1 %macro __CDECL16_PROC_ENTRY 0-1
push bp push bp
mov bp, sp mov bp, sp
@@ -28,8 +28,8 @@
%endmacro %endmacro
%endif %endif
%ifnmacro __CDECL16_EXIT %ifnmacro __CDECL16_PROC_EXIT
%macro __CDECL16_EXIT 0 %macro __CDECL16_PROC_EXIT 0
pop bx pop bx
pop di pop di
pop si pop si
@@ -42,7 +42,6 @@
; __CDECL16_ARGS nargs ; __CDECL16_ARGS nargs
; Creates %$arg1 .. %$argN as [bp+4], [bp+6], ... ; Creates %$arg1 .. %$argN as [bp+4], [bp+6], ...
; for use inside of function bodies ; for use inside of function bodies
;
%ifnmacro __CDECL16_ARGS %ifnmacro __CDECL16_ARGS
%macro __CDECL16_ARGS 1 %macro __CDECL16_ARGS 1
%assign %$__i 1 %assign %$__i 1
@@ -112,20 +111,26 @@
%endmacro %endmacro
%endif %endif
%ifnmacro CLOB
%ifnmacro __CDECL16_CALLER_SAVE ; e.g CLOB ax dx ... inside func entry, then UNCLOB ax dx at all exits
%macro __CDECL16_CALLER_SAVE 0 ; ordering is already taken care of
push ax ; i.e if you CLOB ax cx dx then UNCLOB ax cx dx, the unclob is reversed
push cx %macro __CDECL16_CLOB 1-*
push dx %assign %$i 1
%rep %0
push %[%$i]
%assign %$i %$i+1
%endrep
%endmacro %endmacro
%endif %endif
%ifnmacro __CDECL16_CALLER_RESTORE %ifnmacro __CDECL16_UNCLOB
%macro __CDECL16_CALLER_RESTORE 0 %macro UNCLOB 1-*
pop dx %assign %$i %0
pop cx %rep %0
pop ax pop %[%$i]
%assign %$i %$i-1
%endrep
%endmacro %endmacro
%endif %endif

View File

@@ -23,7 +23,7 @@
; returns: none ; returns: none
ALIGN 4, db 0x90 ALIGN 4, db 0x90
InitFATDriver: InitFATDriver:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov ax, FAT32_State_t_size mov ax, FAT32_State_t_size
push ax ; length of fat32_state structure push ax ; length of fat32_state structure
@@ -70,14 +70,14 @@ InitFATDriver:
mov eax, dword [bx + FAT32_ebpb_t.root_clus_dword] mov eax, dword [bx + FAT32_ebpb_t.root_clus_dword]
mov dword [di + FAT32_State_t.curr_dir_cluster_32], eax mov dword [di + FAT32_State_t.curr_dir_cluster_32], eax
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
.error: .error:
ERROR STAGE2_FAT32_INIT_CF ERROR STAGE2_FAT32_INIT_CF
ALIGN 4, db 0x90 ALIGN 4, db 0x90
FSInfoPrinter: FSInfoPrinter:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
;info we want to print to validate we are loading stuff from the disk correctly ;info we want to print to validate we are loading stuff from the disk correctly
; boot_drive # (i.e 0x80) ; boot_drive # (i.e 0x80)
@@ -88,7 +88,7 @@ FSInfoPrinter:
; print entire FAT32 state ; print entire FAT32 state
; ;
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
.error: .error:
ERROR STAGE2_ERROR_INFOPRINTER ERROR STAGE2_ERROR_INFOPRINTER
@@ -104,7 +104,7 @@ FSInfoPrinter:
; uint32_t SearchFATDIR(uint8_t* SFN); ; uint32_t SearchFATDIR(uint8_t* SFN);
ALIGN 4, db 0x90 ALIGN 4, db 0x90
SearchFATDIR: SearchFATDIR:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.file_lookup: .file_lookup:
print_string SearchFATDIR_info print_string SearchFATDIR_info
mov bx, fat32_state mov bx, fat32_state
@@ -201,7 +201,7 @@ SearchFATDIR:
mov ax, [si + FAT32_SFN_t.cluster_16_low] mov ax, [si + FAT32_SFN_t.cluster_16_low]
; eax == first cluster of file ; eax == first cluster of file
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; BUG: this function needs review ; BUG: this function needs review
@@ -210,7 +210,7 @@ SearchFATDIR:
; 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
ALIGN 4, db 0x90 ALIGN 4, db 0x90
NextCluster: NextCluster:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
print_string NextFATCluster_info print_string NextFATCluster_info
@@ -275,7 +275,7 @@ NextCluster:
mov si, fat_buffer mov si, fat_buffer
mov eax, dword [bx+si+0] mov eax, dword [bx+si+0]
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
.error_cfdivz: .error_cfdivz:
ERROR STAGE2_FAT32_NCLUS_CFDIVZ ERROR STAGE2_FAT32_NCLUS_CFDIVZ
@@ -283,7 +283,7 @@ NextCluster:
; 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:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
print_string ReadFATCluster_info print_string ReadFATCluster_info
@@ -318,7 +318,7 @@ ReadFATCluster:
call read_disk_raw call read_disk_raw
add sp, 0xC add sp, 0xC
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
.error: .error:
ERROR STAGE2_FAT32_CLS2LBA_CF ERROR STAGE2_FAT32_CLS2LBA_CF

View File

@@ -12,7 +12,7 @@ endstruc
; void arena_init(ArenaState *a) ; void arena_init(ArenaState *a)
; ;
arena_init: arena_init:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov ax, word [bp + 4] ; ptr to state structure mov ax, word [bp + 4] ; ptr to state structure
mov di, ax mov di, ax
@@ -35,7 +35,7 @@ arena_init:
add sp, 0x6 add sp, 0x6
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; size_t align_up(size_t x, size_t a) ; size_t align_up(size_t x, size_t a)
@@ -44,7 +44,7 @@ arena_init:
; (x + (a-1)) & ~(a-1) ; (x + (a-1)) & ~(a-1)
; return value in ax ; return value in ax
arena_align_up: arena_align_up:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
; if a == 0 return x ; if a == 0 return x
mov ax, [bp + 4] ; x mov ax, [bp + 4] ; x
@@ -81,7 +81,7 @@ arena_align_up:
mov ax, cx ; move to ax and return mov ax, cx ; move to ax and return
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; void* arena_alloc(size_t bytes, size_t align) ; void* arena_alloc(size_t bytes, size_t align)
@@ -89,7 +89,7 @@ arena_align_up:
; bp-4 - aligned_ptr ; bp-4 - aligned_ptr
; bp-6 - new_end ; bp-6 - new_end
arena_alloc: arena_alloc:
__CDECL16_ENTRY 0x10 __CDECL16_PROC_ENTRY 0x10
.func: .func:
; remove bytes from pool and increment mark to the new cursor location ; remove bytes from pool and increment mark to the new cursor location
; return a pointer to the begining of allocated segment ; return a pointer to the begining of allocated segment
@@ -133,36 +133,36 @@ arena_alloc:
; return aligned_ptr ; return aligned_ptr
mov ax, word [bp - 4] mov ax, word [bp - 4]
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
.error: .error:
ERROR STEVIA_DEBUG_ERR ERROR STEVIA_DEBUG_ERR
arena_mark: arena_mark:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
; return the current location of the 'cursor' in the allocator ; return the current location of the 'cursor' in the allocator
ERROR STEVIA_DEBUG_UNIMPLEMENTED ERROR STEVIA_DEBUG_UNIMPLEMENTED
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
arena_reset_to: arena_reset_to:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
; rewind the arena to a previously marked point ; rewind the arena to a previously marked point
ERROR STEVIA_DEBUG_UNIMPLEMENTED ERROR STEVIA_DEBUG_UNIMPLEMENTED
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
arena_reset: arena_reset:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
; reset the entire heap to a fresh state ; reset the entire heap to a fresh state
ERROR STEVIA_DEBUG_UNIMPLEMENTED ERROR STEVIA_DEBUG_UNIMPLEMENTED
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif

View File

@@ -19,7 +19,7 @@
; void* kmemset_byte(void* dst, uint8_t val, uint16_t len); ; void* kmemset_byte(void* dst, uint8_t val, uint16_t len);
ALIGN 4, db 0x90 ALIGN 4, db 0x90
kmemset: kmemset:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov cx, [bp + 8] ; uint16_t len mov cx, [bp + 8] ; uint16_t len
mov al, byte [bp + 6] ; uint8_t val mov al, byte [bp + 6] ; uint8_t val
@@ -29,14 +29,14 @@ kmemset:
rep stosb rep stosb
mov ax, di ; return pointer to dest + len (last elem of dest) mov ax, di ; return pointer to dest + len (last elem of dest)
.endp: .endp:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
; uint8_t* kmemset(uint16_t* dest, uint16_t* src, uint16_t len); ; uint8_t* kmemset(uint16_t* dest, uint16_t* src, uint16_t len);
; not overlap safe ; not overlap safe
ALIGN 4, db 0x90 ALIGN 4, db 0x90
kmemcpy: kmemcpy:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov cx, [bp + 8] ; len mov cx, [bp + 8] ; len
mov si, [bp + 6] ; src mov si, [bp + 6] ; src
@@ -46,7 +46,7 @@ kmemcpy:
rep movsb rep movsb
mov ax, di ; return pointer to dest mov ax, di ; return pointer to dest
.endf: .endf:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif

View File

@@ -20,7 +20,7 @@
; not overlap safe, only for ; not overlap safe, only for
ALIGN 4, db 0x90 ALIGN 4, db 0x90
kmemcpy5: kmemcpy5:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
push ds push ds
push es push es
.setup_segments: .setup_segments:
@@ -41,7 +41,7 @@ kmemcpy5:
pop es pop es
pop ds pop ds
.endf: .endf:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%define __INC_KMEMCPY5_FUNC %define __INC_KMEMCPY5_FUNC

View File

@@ -19,7 +19,7 @@
; word kmemset_byte(word segment, word dst, byte val, word len); ; word kmemset_byte(word segment, word dst, byte val, word len);
ALIGN 4, db 0x90 ALIGN 4, db 0x90
kmemset4: kmemset4:
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
.setup_segment: .setup_segment:
push es push es
mov ax, [bp + 4] mov ax, [bp + 4]
@@ -35,7 +35,7 @@ kmemset4:
.restore_segments: .restore_segments:
pop es pop es
.endf: .endf:
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
%endif %endif

View File

@@ -264,7 +264,7 @@ hcf:
ALIGN 4, db 0x90 ALIGN 4, db 0x90
EnterUnrealMode: EnterUnrealMode:
__BOCHS_MAGIC_DEBUG __BOCHS_MAGIC_DEBUG
__CDECL16_ENTRY __CDECL16_PROC_ENTRY
cli ; no interrupts cli ; no interrupts
.func: .func:
lgdt [((__STAGE2_SEGMENT << 4) + unreal_gdt_info)] ; load unreal gdt lgdt [((__STAGE2_SEGMENT << 4) + unreal_gdt_info)] ; load unreal gdt
@@ -301,7 +301,7 @@ EnterUnrealMode:
; to easily access data outside of 64KiB boundries using ds/es addressing ; to easily access data outside of 64KiB boundries using ds/es addressing
__TINY_DS_ES __TINY_DS_ES
__CDECL16_EXIT __CDECL16_PROC_EXIT
ret ret
end_text: end_text: