Skip to content

Commit

Permalink
feat(boot/loader): fetch memory map from e820 bios call
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Jul 2, 2024
1 parent 4a63e27 commit cf8449c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
3 changes: 0 additions & 3 deletions boot/common/bootinfo.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -61,7 +59,6 @@ boot_info_print_mmap:
mov si, szMsgMemMap
call bios_log
pop ecx
xchg bx, bx
@@:
inc ecx
cmp ecx, 40
Expand Down
1 change: 1 addition & 0 deletions boot/loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TARGET = stpdldr.sys

LOADER_SRCS = loader.asm \
../common/const.inc \
../common/bootinfo.inc \
video.inc \
memory.inc \
logger.inc \
Expand Down
49 changes: 39 additions & 10 deletions boot/loader/memory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,9 +28,9 @@ struc AddressRange
.LengthHigh dd ?
;; Variable: Type
;; Address type of this range. <Address type>
.Type db ?
.Type dd ?

}
defn AddressRange

;; Function: memory_e820_get_mmap_entry
;;
Expand All @@ -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
Expand Down Expand Up @@ -115,3 +142,5 @@ memory_get_map:
.end:
ret


pE280AddrRange E820AddressRange

0 comments on commit cf8449c

Please sign in to comment.