From 4a63e27d4b692631fd60ace8cc5b61016459fd37 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Tue, 2 Jul 2024 10:32:11 +0200 Subject: [PATCH] feat: print memory map --- boot/common/bootinfo.inc | 71 ++++++++++++++++++++++++++++++++++++++++ boot/efi/bootia32.asm | 2 +- boot/intro.txt | 1 - boot/loader/loader.asm | 7 +++- boot/loader/memory.inc | 32 +++++++----------- boot/loader/video.inc | 3 +- 6 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 boot/common/bootinfo.inc diff --git a/boot/common/bootinfo.inc b/boot/common/bootinfo.inc new file mode 100644 index 0000000..5739f00 --- /dev/null +++ b/boot/common/bootinfo.inc @@ -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' diff --git a/boot/efi/bootia32.asm b/boot/efi/bootia32.asm index efab030..a1300e8 100644 --- a/boot/efi/bootia32.asm +++ b/boot/efi/bootia32.asm @@ -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 ? diff --git a/boot/intro.txt b/boot/intro.txt index 5643756..b3cba46 100644 --- a/boot/intro.txt +++ b/boot/intro.txt @@ -50,4 +50,3 @@ Section: UEFI (IA32) > | BOOTIA32.EFI |----->| vmstupid.sys | > +--------------+ +--------------+ > - diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index c9339d1..7e066cb 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -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: diff --git a/boot/loader/memory.inc b/boot/loader/memory.inc index b8b95d6..8d10f1e 100644 --- a/boot/loader/memory.inc +++ b/boot/loader/memory.inc @@ -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 diff --git a/boot/loader/video.inc b/boot/loader/video.inc index 4d91d78..c4f4b54 100644 --- a/boot/loader/video.inc +++ b/boot/loader/video.inc @@ -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