Compare commits
2 Commits
69bd7d8f56
...
766c67c041
| Author | SHA1 | Date | |
|---|---|---|---|
| 766c67c041 | |||
| 49d82be0e8 |
@@ -44,11 +44,13 @@
|
|||||||
; for use inside of function bodies
|
; for use inside of function bodies
|
||||||
%ifnmacro __CDECL16_PROC_ARGS
|
%ifnmacro __CDECL16_PROC_ARGS
|
||||||
%macro __CDECL16_PROC_ARGS 1
|
%macro __CDECL16_PROC_ARGS 1
|
||||||
|
%push __CDECL16_PROC_ARGS
|
||||||
%assign %$__i 1
|
%assign %$__i 1
|
||||||
%rep %1
|
%rep %1
|
||||||
%xdefine %$arg%$__i [bp + 4 + 2*(%$__i-1)]
|
%xdefine %$arg%$__i [bp + 4 + 2*(%$__i-1)]
|
||||||
%assign %$__i %$__i + 1
|
%assign %$__i %$__i + 1
|
||||||
%endrep
|
%endrep
|
||||||
|
%pop
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
@@ -56,10 +58,9 @@
|
|||||||
; handles pushing values to the stack in the correct order
|
; handles pushing values to the stack in the correct order
|
||||||
%ifnmacro __CDECL16_CALL_ARGS
|
%ifnmacro __CDECL16_CALL_ARGS
|
||||||
%macro __CDECL16_CALL_ARGS 1-*
|
%macro __CDECL16_CALL_ARGS 1-*
|
||||||
%assign %$__i %0
|
|
||||||
%rep %0
|
%rep %0
|
||||||
push %[%$__i]
|
%rotate -1 ; move the last argument into %1
|
||||||
%assign %$__i %$__i - 1
|
push %1 ; push last, then next-to-last, ...
|
||||||
%endrep
|
%endrep
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
@@ -79,57 +80,68 @@
|
|||||||
; count the stack frame to restore later!
|
; count the stack frame to restore later!
|
||||||
%ifnmacro __CDECL16_CALL_ARGS_SIZED
|
%ifnmacro __CDECL16_CALL_ARGS_SIZED
|
||||||
%macro __CDECL16_CALL_ARGS_SIZED 2-*
|
%macro __CDECL16_CALL_ARGS_SIZED 2-*
|
||||||
|
%push __CDECL16_CALL_ARGS_SIZED
|
||||||
call %1
|
call %1
|
||||||
%assign %$__sum 0
|
%assign %$__sum 0
|
||||||
%assign %$__i 2
|
%assign %$__i 2
|
||||||
%rep %0-1
|
%rep %0-1
|
||||||
%assign %$__sum %$__sum + %[%$__i]
|
%assign %$__sum %$__sum + %[%$__i] ; sizes may be expressions
|
||||||
%assign %$__i %$__i + 1
|
%assign %$__i %$__i + 1
|
||||||
%endrep
|
%endrep
|
||||||
|
%if %$__sum & 1
|
||||||
|
%error "__CDECL16_CALL_ARGS_SIZED: total size is odd; pushes must sum to whole bytes actually pushed (usually even)."
|
||||||
|
%endif
|
||||||
add sp, %$__sum
|
add sp, %$__sum
|
||||||
|
%pop
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
|
||||||
; __CDECL16_INVOKE func, arg1[, arg2 ...]
|
; __CDECL16_INVOKE func, arg1[, arg2 ...]
|
||||||
; pushes args right-to-left, calls, then add sp by (#args)*2
|
; pushes args right-to-left, calls, then add sp by (#args)*2
|
||||||
; !!! warning for word sized args only !!!
|
; !!! warning for word sized args only !!!
|
||||||
%ifnmacro __CDECL16_INVOKE
|
%ifnmacro __CDECL16_INVOKE
|
||||||
%macro __CDECL16_INVOKE 1-*
|
%macro __CDECL16_INVOKE 1-*
|
||||||
%assign %$__argc %0-1
|
%push __CDECL16_INVOKE
|
||||||
%if %$__argc > 0
|
%define %$fn %1
|
||||||
; push args right-to-left
|
%assign %$argc %0-1
|
||||||
%assign %$__i %0
|
%rotate -1 ; drop function name; %1.. are args
|
||||||
%rep %$__argc
|
%rep %$argc
|
||||||
push %[%$__i]
|
%rotate -1
|
||||||
%assign %$__i %$__i - 1
|
push %1
|
||||||
%endrep
|
%endrep
|
||||||
call %1
|
call %$fn
|
||||||
add sp, %$__argc*2
|
%if %$argc
|
||||||
%else
|
add sp, %$argc*2
|
||||||
call %1
|
|
||||||
%endif
|
%endif
|
||||||
|
%pop
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%ifnmacro __CDECL16_CLOB
|
%ifnmacro __CDECL16_CLOB
|
||||||
; e.g CLOB ax dx ... inside func entry, then UNCLOB ax dx at all exits
|
; Save registers in the order listed. Supports "flags" as a pseudo-reg.
|
||||||
; ordering is already taken care of
|
|
||||||
; i.e if you CLOB ax cx dx then UNCLOB ax cx dx, the unclob is reversed
|
|
||||||
%macro __CDECL16_CLOB 1-*
|
%macro __CDECL16_CLOB 1-*
|
||||||
%assign %$i 1
|
|
||||||
%rep %0
|
%rep %0
|
||||||
push %[%$i]
|
%ifidni %1, flags
|
||||||
%assign %$i %$i+1
|
pushf
|
||||||
|
%else
|
||||||
|
push %1
|
||||||
|
%endif
|
||||||
|
%rotate 1
|
||||||
%endrep
|
%endrep
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%ifnmacro __CDECL16_UNCLOB
|
%ifnmacro __CDECL16_UNCLOB
|
||||||
|
; Restore in reverse order of CLOB. Supports "flags".
|
||||||
%macro __CDECL16_UNCLOB 1-*
|
%macro __CDECL16_UNCLOB 1-*
|
||||||
%assign %$i %0
|
|
||||||
%rep %0
|
%rep %0
|
||||||
pop %[%$i]
|
%rotate -1
|
||||||
%assign %$i %$i-1
|
%ifidni %1, flags
|
||||||
|
popf
|
||||||
|
%else
|
||||||
|
pop %1
|
||||||
|
%endif
|
||||||
%endrep
|
%endrep
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
|
|||||||
@@ -135,33 +135,21 @@ main:
|
|||||||
je main.stage2_main
|
je main.stage2_main
|
||||||
ERROR STAGE2_SIGNATURE_MISSING
|
ERROR STAGE2_SIGNATURE_MISSING
|
||||||
.stage2_main:
|
.stage2_main:
|
||||||
mov ax, PartTable_t_size
|
; copy partition table data to .data section in stage2
|
||||||
push ax ; len = PartTable_t_size
|
__CDECL16_CALL_ARGS partition_table, word [vbr_part_table_ptr], PartTable_t_size
|
||||||
mov ax, word [vbr_part_table_ptr] ; src = ptr to vbr partition_table
|
__CDECL16_CALL kmemcpy, 3
|
||||||
push ax
|
|
||||||
mov ax, partition_table ; dst
|
|
||||||
push ax
|
|
||||||
call kmemcpy ; copy partition table data to .data section in stage2
|
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
mov ax, (FAT32_bpb_t_size + FAT32_ebpb_t_size) ; len
|
; copy bpb & ebpb to memory
|
||||||
push ax
|
__CDECL16_CALL_ARGS fat32_bpb, word [vbr_fat32_bpb_ptr], (FAT32_bpb_t_size + FAT32_ebpb_t_size)
|
||||||
mov ax, word [vbr_fat32_bpb_ptr] ; src
|
__CDECL16_CALL kmemcpy, 3
|
||||||
push ax
|
|
||||||
mov ax, fat32_bpb ; dst
|
|
||||||
push ax
|
|
||||||
call kmemcpy ; copy bpb & ebpb to memory
|
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
call SetTextMode
|
call SetTextMode
|
||||||
call disable_cursor_bios
|
call disable_cursor_bios
|
||||||
print_string HelloPrompt_info
|
print_string HelloPrompt_info
|
||||||
|
|
||||||
; setup the early heap
|
; setup the early heap
|
||||||
mov ax, early_heap_state
|
__CDECL16_CALL_ARGS early_heap_state
|
||||||
push ax ; address in bss of state structure
|
__CDECL16_CALL arena_init, 1
|
||||||
call arena_init
|
|
||||||
add sp, 0x2
|
|
||||||
|
|
||||||
; enable A20 gate
|
; enable A20 gate
|
||||||
call EnableA20
|
call EnableA20
|
||||||
|
|||||||
Reference in New Issue
Block a user