|
|
|
|
@ -247,8 +247,14 @@ main:
|
|
|
|
|
mov ax, msg_a20_enabled
|
|
|
|
|
call vga_println
|
|
|
|
|
|
|
|
|
|
call mem_detect
|
|
|
|
|
jc .mem_detect_fail
|
|
|
|
|
|
|
|
|
|
hlt
|
|
|
|
|
|
|
|
|
|
.mem_detect_fail:
|
|
|
|
|
panic PANIC_TYPE_MEM_DETECT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Print a panic message then terminate.
|
|
|
|
|
; Arguments:
|
|
|
|
|
@ -704,6 +710,74 @@ enable_a20_intel_8042:
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mem_detect:
|
|
|
|
|
%if MEMMAP_CAP < 1
|
|
|
|
|
%error "memmap buffer too small"
|
|
|
|
|
%endif
|
|
|
|
|
|
|
|
|
|
fnstart
|
|
|
|
|
push es
|
|
|
|
|
|
|
|
|
|
mov word [GLOBALS + MEMMAP_ENTRIES], 0
|
|
|
|
|
|
|
|
|
|
; Memset the memmap buffer to 0.
|
|
|
|
|
xor ax, ax
|
|
|
|
|
mov es, ax
|
|
|
|
|
mov di, MEMMAP
|
|
|
|
|
mov cx, (MEMMAP_END - MEMMAP)
|
|
|
|
|
rep stosb
|
|
|
|
|
|
|
|
|
|
; Entry number (will be incremented for us)
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
; Buffer (es:di)
|
|
|
|
|
mov di, MEMMAP
|
|
|
|
|
mov dword [di + 0x20], 0x1
|
|
|
|
|
; Entry size
|
|
|
|
|
mov ecx, MEMMAP_ENT_SIZE
|
|
|
|
|
; Magic number
|
|
|
|
|
mov edx, E820_MAGIC
|
|
|
|
|
; Detect memory
|
|
|
|
|
mov eax, 0xe820
|
|
|
|
|
clc
|
|
|
|
|
int 0x15
|
|
|
|
|
jc .fail
|
|
|
|
|
cmp eax, E820_MAGIC
|
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
|
|
inc word [GLOBALS + MEMMAP_ENTRIES]
|
|
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
|
cmp word [GLOBALS + MEMMAP_ENTRIES], MEMMAP_CAP
|
|
|
|
|
jae .done
|
|
|
|
|
|
|
|
|
|
add di, MEMMAP_ENT_SIZE
|
|
|
|
|
mov dword [di + 0x20], 0x1
|
|
|
|
|
mov ecx, MEMMAP_ENT_SIZE
|
|
|
|
|
mov eax, 0xe820
|
|
|
|
|
clc
|
|
|
|
|
int 0x15
|
|
|
|
|
; Carry flag will be set if we'd already reached the end of the entries.
|
|
|
|
|
jc .done
|
|
|
|
|
|
|
|
|
|
inc word [GLOBALS + MEMMAP_ENTRIES]
|
|
|
|
|
|
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .done
|
|
|
|
|
|
|
|
|
|
jmp .loop
|
|
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
|
stc
|
|
|
|
|
jmp .return
|
|
|
|
|
|
|
|
|
|
.done:
|
|
|
|
|
clc
|
|
|
|
|
|
|
|
|
|
.return:
|
|
|
|
|
pop es
|
|
|
|
|
fnret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg_boot1_loaded db "boot1 loaded. hello!", 0
|
|
|
|
|
msg_a20_enabled db "a20 enabled", 0
|
|
|
|
|
msg_a20_disabled db "a20 not enabled", 0
|
|
|
|
|
@ -746,15 +820,18 @@ table_reg_msgs:
|
|
|
|
|
dw msg_reg_flags
|
|
|
|
|
dw 0
|
|
|
|
|
|
|
|
|
|
msg_panic_generic db "generic panic", 0
|
|
|
|
|
msg_panic_a20 db "failed to enable a20 line", 0
|
|
|
|
|
msg_panic_generic db "generic panic", 0
|
|
|
|
|
msg_panic_a20 db "failed to enable a20 line", 0
|
|
|
|
|
msg_panic_mem_detect db "failed to detect available memory", 0
|
|
|
|
|
|
|
|
|
|
panic_type_msgs:
|
|
|
|
|
PANIC_TYPE_GENERIC equ ($ - panic_type_msgs) / 2
|
|
|
|
|
PANIC_TYPE_GENERIC equ ($ - panic_type_msgs) / 2
|
|
|
|
|
dw msg_panic_generic
|
|
|
|
|
PANIC_TYPE_A20 equ ($ - panic_type_msgs) / 2
|
|
|
|
|
PANIC_TYPE_A20 equ ($ - panic_type_msgs) / 2
|
|
|
|
|
dw msg_panic_a20
|
|
|
|
|
PANIC_TYPE_MAX equ ($ - panic_type_msgs) / 2
|
|
|
|
|
PANIC_TYPE_MEM_DETECT equ ($ - panic_type_msgs) / 2
|
|
|
|
|
dw msg_panic_mem_detect
|
|
|
|
|
PANIC_TYPE_MAX equ ($ - panic_type_msgs) / 2
|
|
|
|
|
dw 0
|
|
|
|
|
|
|
|
|
|
boot1_magic dd BOOT1_MAGIC
|
|
|
|
|
|