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