Compare commits
3 Commits
14f6788a22
...
460165a8d1
| Author | SHA1 | Date | |
|---|---|---|---|
| 460165a8d1 | |||
| 935cbd1089 | |||
| 7f1b4fa632 |
@@ -11,9 +11,9 @@ endstruc
|
||||
|
||||
; void arena_init(ArenaState *a)
|
||||
;
|
||||
arena_init:
|
||||
ArenaInit:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
.proc:
|
||||
mov ax, word [bp + 4] ; ptr to state structure
|
||||
mov di, ax
|
||||
|
||||
@@ -25,15 +25,11 @@ arena_init:
|
||||
; zero out heap area on init
|
||||
; void* kmemset_byte(void* dst, uint8_t val, uint16_t len);
|
||||
; TODO: use word or qword spacing at least to speed this up
|
||||
mov ax, __ARENA_HEAP_SIZE
|
||||
push ax ; len
|
||||
xor ax, ax
|
||||
push ax ; val = 0
|
||||
mov ax, __ARENA_HEAP_START
|
||||
push ax ; dst
|
||||
push __ARENA_HEAP_SIZE ; len
|
||||
push 0x0 ; val = 0
|
||||
push __ARENA_HEAP_START ; dst
|
||||
call kmemset
|
||||
add sp, 0x6
|
||||
|
||||
.endp:
|
||||
__CDECL16_PROC_EXIT
|
||||
ret
|
||||
@@ -43,7 +39,7 @@ arena_init:
|
||||
; align x up to the nearest specified alignment (a), a should be a power of 2
|
||||
; (x + (a-1)) & ~(a-1)
|
||||
; return value in ax
|
||||
arena_align_up:
|
||||
ArenaAlignUp:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
; if a == 0 return x
|
||||
@@ -51,7 +47,7 @@ arena_align_up:
|
||||
mov bx, [bp + 6] ; a
|
||||
|
||||
test bx, bx
|
||||
jz .endp
|
||||
jz .endf
|
||||
|
||||
; enforce power-of-two for alignment, return x
|
||||
; for example...
|
||||
@@ -69,7 +65,7 @@ arena_align_up:
|
||||
mov cx, bx
|
||||
dec cx
|
||||
test bx, cx
|
||||
jnz .endp
|
||||
jnz .endf
|
||||
|
||||
dec bx ; a - 1
|
||||
|
||||
@@ -80,7 +76,7 @@ arena_align_up:
|
||||
and cx, bx ; and with the inverse
|
||||
|
||||
mov ax, cx ; move to ax and return
|
||||
.endp:
|
||||
.endf:
|
||||
__CDECL16_PROC_EXIT
|
||||
ret
|
||||
|
||||
@@ -88,9 +84,9 @@ arena_align_up:
|
||||
; bp-2 - current used arena (i.e 'highmark')
|
||||
; bp-4 - aligned_ptr
|
||||
; bp-6 - new_end
|
||||
arena_alloc:
|
||||
ArenaAlloc:
|
||||
__CDECL16_PROC_ENTRY 0x10
|
||||
.func:
|
||||
.proc:
|
||||
; remove bytes from pool and increment mark to the new cursor location
|
||||
; return a pointer to the begining of allocated segment
|
||||
mov bx, early_heap_state
|
||||
@@ -102,11 +98,10 @@ arena_alloc:
|
||||
|
||||
push bx ; save heap_state pointer
|
||||
|
||||
mov ax, word [bp + 6] ; requested next allocation alignment
|
||||
push ax
|
||||
mov ax, word [bp - 2] ; current arena 'highmark'
|
||||
push ax
|
||||
call arena_align_up
|
||||
|
||||
push word [bp + 6] ; requested next allocation alignment
|
||||
push word [bp - 2] ; current arena 'highmark'
|
||||
call ArenaAlignUp
|
||||
add sp, 0x4
|
||||
mov word [bp - 4], ax ; save return value
|
||||
|
||||
@@ -118,7 +113,7 @@ arena_alloc:
|
||||
|
||||
mov dx, word [bx + ArenaStateStruc_t.end]
|
||||
cmp ax, dx
|
||||
ja arena_alloc.error ; if our heap end is < the requested throw an error, heap is full
|
||||
ja .error ; if our heap end is < the requested throw an error, heap is full
|
||||
; else update the mark to the new value & return the aligned pointer
|
||||
|
||||
; mark_delta = new_end - curr_used
|
||||
@@ -140,7 +135,7 @@ arena_alloc:
|
||||
|
||||
arena_mark:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
.proc:
|
||||
; return the current location of the 'cursor' in the allocator
|
||||
ERROR STEVIA_DEBUG_UNIMPLEMENTED
|
||||
.endp:
|
||||
@@ -149,7 +144,7 @@ arena_mark:
|
||||
|
||||
arena_reset_to:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
.proc:
|
||||
; rewind the arena to a previously marked point
|
||||
ERROR STEVIA_DEBUG_UNIMPLEMENTED
|
||||
.endp:
|
||||
@@ -158,7 +153,7 @@ arena_reset_to:
|
||||
|
||||
arena_reset:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
.proc:
|
||||
; reset the entire heap to a fresh state
|
||||
ERROR STEVIA_DEBUG_UNIMPLEMENTED
|
||||
.endp:
|
||||
|
||||
@@ -126,29 +126,29 @@ main:
|
||||
|
||||
; setup the early heap
|
||||
__CDECL16_CALL_ARGS early_heap_state
|
||||
__CDECL16_CALL arena_init, 1
|
||||
__CDECL16_CALL ArenaInit, 1
|
||||
|
||||
__CDECL16_CALL_ARGS pszHelloPrompt
|
||||
__CDECL16_CALL PrintString, 1
|
||||
|
||||
; setup and store our vbr/mbr (e)bpb
|
||||
__CDECL16_CALL_ARGS 0x200, 0x10
|
||||
__CDECL16_CALL arena_alloc, 2
|
||||
__CDECL16_CALL ArenaAlloc, 2
|
||||
mov word [mbr_ptr], ax
|
||||
|
||||
push ax ; dst
|
||||
movzx ax, byte [u8_BootDrive]
|
||||
push ax ; boot_drive
|
||||
__CDECL16_CALL read_mbr, 2 ; fill mbr buffer
|
||||
__CDECL16_CALL ReadMbrData, 2 ; fill mbr buffer
|
||||
|
||||
__CDECL16_CALL_ARGS 0x200, 0x10
|
||||
__CDECL16_CALL arena_alloc, 2
|
||||
__CDECL16_CALL ArenaAlloc, 2
|
||||
mov word [vbr_ptr], ax
|
||||
|
||||
push ax ; dst
|
||||
movzx ax, byte [u8_BootDrive]
|
||||
push ax ; boot_drive
|
||||
__CDECL16_CALL read_vbr, 2 ; fill vbr buffer
|
||||
__CDECL16_CALL ReadVbrData, 2 ; fill vbr buffer
|
||||
|
||||
; enable A20 gate
|
||||
call EnableA20
|
||||
@@ -199,7 +199,7 @@ hcf:
|
||||
|
||||
; int read_mbr(int boot_drive, void* dst)
|
||||
; destination buffer needs 512 bytes of space
|
||||
read_mbr:
|
||||
ReadMbrData:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.proc:
|
||||
; read mbr on boot drive to memory (for the partition table)
|
||||
@@ -213,11 +213,10 @@ read_mbr:
|
||||
push __STAGE2_SEGMENT ; this segment
|
||||
call read_disk_raw
|
||||
add sp, 0xC
|
||||
|
||||
.check_sig:
|
||||
mov bx, [bp + 6]
|
||||
cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end
|
||||
jne read_mbr.error
|
||||
jne ReadMbrData.error
|
||||
; TODO: this needs error checking, zero checking, check the sig a bunch of stuff...
|
||||
.update_globals:
|
||||
mov ax, [bp + 6]
|
||||
@@ -230,22 +229,20 @@ read_mbr:
|
||||
ERROR STEVIA_DEBUG_ERR
|
||||
|
||||
; int read_vbr(int boot_drive, void* buf)
|
||||
read_vbr:
|
||||
; read vbr on boot partition to memory (for fat bpb/ebpb)
|
||||
ReadVbrData:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.proc:
|
||||
__BOCHS_MAGIC_DEBUG
|
||||
; read vbr on boot partition to memory (for fat bpb/ebpb)
|
||||
.calc_part_offset:
|
||||
mov bx, word [part_table_ptr] ; base pointer @ partition table
|
||||
mov bx, word [part_table_ptr] ; calculate offset; base pointer @ partition table
|
||||
mov cx, 4 ; only checking 4 entries
|
||||
mov si, PartEntry_t.attributes
|
||||
.find_active_L0:
|
||||
mov al, byte [bx + si]
|
||||
test al, 0x80 ; 0x80 == 1000_0000b
|
||||
je read_vbr.active_found
|
||||
je ReadVbrData.active_found
|
||||
add si, 0x10 ; add 16 bytes to offset (next part entry's attributes)
|
||||
loop read_vbr.find_active_L0
|
||||
jmp read_vbr.error
|
||||
loop ReadVbrData.find_active_L0
|
||||
jmp ReadVbrData.error
|
||||
.active_found:
|
||||
add bx, si ; update base to active part
|
||||
|
||||
@@ -264,10 +261,10 @@ read_vbr:
|
||||
.check_sig:
|
||||
mov bx, [bp + 6]
|
||||
cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end
|
||||
jne read_mbr.error
|
||||
jne ReadVbrData.error
|
||||
.check_FAT_size:
|
||||
test word [bx + FAT32_bpb_t.unused2_ZERO_word], 0 ; TotSectors16 will not be set if FAT32
|
||||
jnz read_vbr.error
|
||||
jnz ReadVbrData.error
|
||||
.update_globals:
|
||||
mov word [fat32_bpb_ptr], bx
|
||||
add bx, FAT32_bpb_t_size ; offset to ebpb
|
||||
@@ -338,7 +335,7 @@ ALIGN 4, db 0x90
|
||||
EnterUnrealMode:
|
||||
__CDECL16_PROC_ENTRY
|
||||
cli ; no interrupts
|
||||
.func:
|
||||
.proc:
|
||||
lgdt [((__STAGE2_SEGMENT << 4) + UnrealGdtInfo)] ; load unreal gdt
|
||||
|
||||
mov eax, cr0
|
||||
@@ -480,19 +477,19 @@ Gdt32Start:
|
||||
Gdt32End:
|
||||
|
||||
align 16,db 0
|
||||
BUILD_NASM_VER:
|
||||
BuildNasmVer:
|
||||
db "Stevia Stage2 built with NASM - ", __NASM_VER__, 00h
|
||||
|
||||
align 16,db 0
|
||||
BUILD_DATETIME:
|
||||
BuildDateTime:
|
||||
db 'Assembled - ', __DATE__, ' ', __TIME__, 00h
|
||||
|
||||
align 16,db 0
|
||||
BUILD_GIT_VER:
|
||||
BuildGitVer:
|
||||
db __GIT_VER__, 00h
|
||||
|
||||
align 16,db 0
|
||||
BUILD_GIT_HASH:
|
||||
BuildGitHash:
|
||||
db __GIT_HASH__, 00h
|
||||
end_data:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user