feat(boot/loader): fetch memory map from e820 bios call

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-02 11:33:44 +02:00
parent 4a63e27d4b
commit cf8449ce13
3 changed files with 40 additions and 13 deletions

View file

@ -46,10 +46,8 @@ boot_info_add_memmap:
pop ebx pop ebx
ret ret
;; Function: boot_info_print_mmap ;; Function: boot_info_print_mmap
boot_info_print_mmap: boot_info_print_mmap:
xchg bx, bx
xor ecx, ecx xor ecx, ecx
.loop: .loop:
mov eax, [boot_structure.mmap + ecx * 8 + 4] mov eax, [boot_structure.mmap + ecx * 8 + 4]
@ -61,7 +59,6 @@ boot_info_print_mmap:
mov si, szMsgMemMap mov si, szMsgMemMap
call bios_log call bios_log
pop ecx pop ecx
xchg bx, bx
@@: @@:
inc ecx inc ecx
cmp ecx, 40 cmp ecx, 40

View file

@ -2,6 +2,7 @@ TARGET = stpdldr.sys
LOADER_SRCS = loader.asm \ LOADER_SRCS = loader.asm \
../common/const.inc \ ../common/const.inc \
../common/bootinfo.inc \
video.inc \ video.inc \
memory.inc \ memory.inc \
logger.inc \ logger.inc \

View file

@ -12,7 +12,7 @@ ADDRESS_RANGE_MEMORY = 1
ADDRESS_RANGE_RESERVED = 2 ADDRESS_RANGE_RESERVED = 2
;; Struct: AddressRange ;; Struct: AddressRange
struc AddressRange struc E820AddressRange
{ {
;; Variable: BaseAddrLow ;; Variable: BaseAddrLow
;; Low 32 Bits of Base Address ;; Low 32 Bits of Base Address
@ -28,9 +28,9 @@ struc AddressRange
.LengthHigh dd ? .LengthHigh dd ?
;; Variable: Type ;; Variable: Type
;; Address type of this range. <Address type> ;; Address type of this range. <Address type>
.Type db ? .Type dd ?
} }
defn AddressRange
;; Function: memory_e820_get_mmap_entry ;; Function: memory_e820_get_mmap_entry
;; ;;
@ -48,16 +48,43 @@ defn AddressRange
;; ECX - Buffer Size ;; ECX - Buffer Size
;; EBX - Continuation ;; EBX - Continuation
memory_e820_get_map: memory_e820_get_map:
xor ebx, ebx
@@:
clc clc
@@: xchg bx, bx
xor eax, eax
mov es, ax
mov di, pE280AddrRange
mov ecx, 20
mov eax, 0xE820 mov eax, 0xE820
mov ebx, 0x0 mov edx, 0x534D4150
mov edx, 'SMAP' int 0x15
jc @f xchg bx, bx
cmp eax, 'SMAP' jc .error
jne @f 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 ret
;; Function: memory_get_for_large_conf ;; Function: memory_get_for_large_conf
@ -115,3 +142,5 @@ memory_get_map:
.end: .end:
ret ret
pE280AddrRange E820AddressRange