feat: print memory map

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-02 10:32:11 +02:00
parent 16d9802872
commit 4a63e27d4b
6 changed files with 91 additions and 25 deletions

71
boot/common/bootinfo.inc Normal file
View file

@ -0,0 +1,71 @@
struc BootInfoRange {
.base dd ?
.legth dd ?
}
struc BootInfo {
.mmap dd 4*2*40 dup(0)
}
BOOTINFO_MEMORY_LIMIT = 0xFFFFF000
;; Function: boot_info_add_memmap
;;
;; In:
;; EAX - base
;; EDX - length
;;
boot_info_add_memmap:
cmp eax, BOOTINFO_MEMORY_LIMIT
jbe @f
ret
@@:
mov ecx, BOOTINFO_MEMORY_LIMIT
sub ecx, edx
cmp eax, ecx
jbe @f
ret
@@:
push ebx
xor ecx, ecx
.loop:
mov ebx, [boot_structure.mmap + ecx * 8 + 4]
or ebx, ebx
jnz @f
mov [boot_structure.mmap + ecx * 8], eax
mov [boot_structure.mmap + ecx * 8 + 4], edx
jmp .end
@@:
inc ecx
cmp ecx, 40
jne .loop
.end:
pop ebx
ret
;; Function: boot_info_print_mmap
boot_info_print_mmap:
xchg bx, bx
xor ecx, ecx
.loop:
mov eax, [boot_structure.mmap + ecx * 8 + 4]
or eax, eax
jz @f
push ecx
push dword [boot_structure.mmap + ecx * 8 + 4]
push dword [boot_structure.mmap + ecx * 8]
mov si, szMsgMemMap
call bios_log
pop ecx
xchg bx, bx
@@:
inc ecx
cmp ecx, 40
jbe .loop
ret
szMsgMemMap db 'Address: %x - Length: %x'

View file

@ -96,7 +96,7 @@ aSearchPaths du '\\', 0, \
'\\boot', 0, \
'\\boot\\efi', 0, 0
szKernelFile du 'vmstupid.sys', 0
szConfigFile du 'stpdboot.cfg', 0
szConfigFile du 'stpdboot.ini', 0
hImage dd ?
pSystemTable dd ?

View file

@ -50,4 +50,3 @@ Section: UEFI (IA32)
> | BOOTIA32.EFI |----->| vmstupid.sys |
> +--------------+ +--------------+
>

View file

@ -99,6 +99,10 @@ _start:
call memory_get_map
jc .error_memory
xchg bx, bx
call boot_info_print_mmap
; video information
call video_setup
@ -142,6 +146,7 @@ _start:
include 'memory.inc'
include 'video.inc'
include 'gdt.inc'
include '../common/bootinfo.inc'
uDrive rb 1
bDriveLBA db FALSE
@ -199,7 +204,7 @@ hang:
_edata:
boot_structure:
boot_structure BootInfo
align 4096
boot_page_directory:

View file

@ -76,11 +76,15 @@ memory_get_for_large_conf:
mov ax, 0xE801
int 0x15
jc @f
xor ecx, ecx
push ax
push bx
mov si, szMsgLarge
call bios_log
movzx edx, ax
mov eax, 0x100000 ; 1MB
call boot_info_add_memmap
mov eax, 0x1000000 ; 16MB
movzx edx, bx
shl edx, 16 ; * 64KB
call boot_info_add_memmap
@@:
ret
@ -104,22 +108,10 @@ memory_get_map:
jc .end
xor ebx, ebx
mov bx, ax
push ebx
mov si, szMsgMaxMemKB
call bios_log
shr ebx, 2
push ebx
mov si, szMsgMaxPage
call bios_log
movzx edx, ax
mov eax, 0x100000
call boot_info_add_memmap
.end:
ret
szMsgMaxMemKB db "%x KB above 1MB", 0
szMsgMaxPage db "%x pages", 0
szMsgLarge db "%d KB above 1MB - %d * 64 KB above 16MB", 0

View file

@ -60,7 +60,6 @@ video_setup:
mov si, szMsgDetectVideo
call bios_log
clc
xchg bx, bx
xor ax, ax
mov es, ax
mov di, vesa_block_buffer
@ -109,5 +108,5 @@ vesa_info_block_buffer VesaModeInfo
szMsgVesaInfo db "Version: %x", CR, LF, "OEM Name: %s", CR, LF, "Total Memory: %d", CR, LF, "Vendor name: %s", CR, LF, "Product name: %s", 0
szMsgDetectVideo db "Fetch video information.", 0
szMsgFramebuffer db "Fb: 0x%x", 0
szMsgFramebuffer db "Fb: %x", 0
szMsgErrorVesa db "Failed to detect VBE mode", 0