From cf8449ce13341b4250e1b125a0ea0f4f33c2e8e0 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Tue, 2 Jul 2024 11:33:44 +0200 Subject: [PATCH] feat(boot/loader): fetch memory map from e820 bios call --- boot/common/bootinfo.inc | 3 --- boot/loader/Makefile | 1 + boot/loader/memory.inc | 49 ++++++++++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/boot/common/bootinfo.inc b/boot/common/bootinfo.inc index 5739f00..9533cd8 100644 --- a/boot/common/bootinfo.inc +++ b/boot/common/bootinfo.inc @@ -46,10 +46,8 @@ boot_info_add_memmap: 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] @@ -61,7 +59,6 @@ boot_info_print_mmap: mov si, szMsgMemMap call bios_log pop ecx - xchg bx, bx @@: inc ecx cmp ecx, 40 diff --git a/boot/loader/Makefile b/boot/loader/Makefile index 1874150..ed8597d 100644 --- a/boot/loader/Makefile +++ b/boot/loader/Makefile @@ -2,6 +2,7 @@ TARGET = stpdldr.sys LOADER_SRCS = loader.asm \ ../common/const.inc \ + ../common/bootinfo.inc \ video.inc \ memory.inc \ logger.inc \ diff --git a/boot/loader/memory.inc b/boot/loader/memory.inc index 8d10f1e..81f0364 100644 --- a/boot/loader/memory.inc +++ b/boot/loader/memory.inc @@ -12,7 +12,7 @@ ADDRESS_RANGE_MEMORY = 1 ADDRESS_RANGE_RESERVED = 2 ;; Struct: AddressRange -struc AddressRange +struc E820AddressRange { ;; Variable: BaseAddrLow ;; Low 32 Bits of Base Address @@ -28,9 +28,9 @@ struc AddressRange .LengthHigh dd ? ;; Variable: Type ;; Address type of this range.
- .Type db ? + .Type dd ? + } -defn AddressRange ;; Function: memory_e820_get_mmap_entry ;; @@ -48,16 +48,43 @@ defn AddressRange ;; ECX - Buffer Size ;; EBX - Continuation memory_e820_get_map: + xor ebx, ebx +@@: clc -@@: + xchg bx, bx + xor eax, eax + mov es, ax + mov di, pE280AddrRange + mov ecx, 20 mov eax, 0xE820 - mov ebx, 0x0 - mov edx, 'SMAP' - jc @f - cmp eax, 'SMAP' - jne @f -@@: + mov edx, 0x534D4150 + int 0x15 + xchg bx, bx + jc .error + cmp eax, 0x534D4150 + jne .error + or ebx, ebx + jz .end + cmp [pE280AddrRange.Type], 0x1 + jne @b + + mov ecx, [pE280AddrRange.BaseAddrHigh] + or ecx, ecx + jnz @b + + mov ecx, [pE280AddrRange.LengthHigh] + or ecx, ecx + jnz @b + + mov edx, [pE280AddrRange.LengthLow] + mov eax, [pE280AddrRange.BaseAddrLow] + call boot_info_add_memmap + + jmp @b +.error: + stc +.end: ret ;; Function: memory_get_for_large_conf @@ -115,3 +142,5 @@ memory_get_map: .end: ret + +pE280AddrRange E820AddressRange