2024-04-14 05:35:43 +00:00
|
|
|
;; File: memory.inc
|
|
|
|
;; Detect available memory
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Constants: Address type
|
|
|
|
;;
|
|
|
|
;; See <AddressRange.Type>
|
|
|
|
;;
|
|
|
|
;; ADDRESS_RANGE_MEMORY - Available and usable RAM.
|
|
|
|
;; ADDRESS_RANGE_RESERVED - Reserved or in use.
|
|
|
|
ADDRESS_RANGE_MEMORY = 1
|
|
|
|
ADDRESS_RANGE_RESERVED = 2
|
|
|
|
|
|
|
|
;; Struct: AddressRange
|
2024-07-02 09:33:44 +00:00
|
|
|
struc E820AddressRange
|
2024-04-14 05:35:43 +00:00
|
|
|
{
|
|
|
|
;; Variable: BaseAddrLow
|
|
|
|
;; Low 32 Bits of Base Address
|
|
|
|
.BaseAddrLow dd ?
|
|
|
|
;; Variable: BaseAddrHigh
|
|
|
|
;; High 32 Bits of Base Address
|
|
|
|
.BaseAddrHigh dd ?
|
|
|
|
;; Variable: LengthLow
|
|
|
|
;; Low 32 Bits of Length in Bytes
|
|
|
|
.LengthLow dd ?
|
|
|
|
;; Variable: LengthHigh
|
|
|
|
;; High 32 Bits of Length in Bytes
|
|
|
|
.LengthHigh dd ?
|
|
|
|
;; Variable: Type
|
|
|
|
;; Address type of this range. <Address type>
|
2024-07-02 09:33:44 +00:00
|
|
|
.Type dd ?
|
|
|
|
|
2024-04-14 05:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
;; Function: memory_e820_get_mmap_entry
|
|
|
|
;;
|
|
|
|
;; In:
|
|
|
|
;; EAX - Function code
|
|
|
|
;; EBX - Continuation
|
|
|
|
;; ES:DI - Buffer Pointer
|
|
|
|
;; ECX - Buffer size
|
|
|
|
;; EDX - Signature 'SMAP'
|
|
|
|
;;
|
|
|
|
;; Out:
|
|
|
|
;; CF - Carry Flag
|
|
|
|
;; EAX - Signature 'SMAP'
|
|
|
|
;; ES:DI - Buffer Pointer
|
|
|
|
;; ECX - Buffer Size
|
|
|
|
;; EBX - Continuation
|
|
|
|
memory_e820_get_map:
|
2024-07-02 09:33:44 +00:00
|
|
|
xor ebx, ebx
|
|
|
|
@@:
|
2024-06-29 14:29:15 +00:00
|
|
|
clc
|
2024-07-02 09:33:44 +00:00
|
|
|
xor eax, eax
|
|
|
|
mov es, ax
|
|
|
|
mov di, pE280AddrRange
|
|
|
|
mov ecx, 20
|
2024-04-14 05:35:43 +00:00
|
|
|
mov eax, 0xE820
|
2024-07-06 13:19:35 +00:00
|
|
|
mov edx, 'PAMS'
|
2024-07-02 09:33:44 +00:00
|
|
|
int 0x15
|
|
|
|
jc .error
|
2024-07-06 13:19:35 +00:00
|
|
|
cmp eax, 'PAMS'
|
2024-07-02 09:33:44 +00:00
|
|
|
jne .error
|
|
|
|
or ebx, ebx
|
|
|
|
jz .end
|
|
|
|
|
|
|
|
cmp [pE280AddrRange.Type], 0x1
|
|
|
|
jne @b
|
2024-04-14 05:35:43 +00:00
|
|
|
|
2024-07-02 09:33:44 +00:00
|
|
|
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:
|
2024-04-14 05:35:43 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
;; Function: memory_get_for_large_conf
|
|
|
|
;;
|
|
|
|
;; In:
|
|
|
|
;; AX - Function code E801h
|
|
|
|
;;
|
|
|
|
;; Out:
|
|
|
|
;; CF - Non-Carry - indicates no error
|
|
|
|
;; AX - Extended 1
|
|
|
|
;; BX - Extended 2
|
|
|
|
;; CX - Configured 1
|
|
|
|
;; DX - Configured 2
|
2024-04-28 06:41:36 +00:00
|
|
|
memory_get_for_large_conf:
|
2024-06-11 09:53:34 +00:00
|
|
|
clc
|
2024-04-28 06:41:36 +00:00
|
|
|
mov ax, 0xE801
|
|
|
|
int 0x15
|
2024-06-11 09:53:34 +00:00
|
|
|
jc @f
|
2024-07-02 08:32:11 +00:00
|
|
|
|
|
|
|
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
|
2024-06-11 09:53:34 +00:00
|
|
|
@@:
|
|
|
|
ret
|
2024-04-14 05:35:43 +00:00
|
|
|
|
|
|
|
;; Function: memory_get_extended_memory_size
|
|
|
|
;;
|
|
|
|
;; In:
|
|
|
|
;; AH - Function code 88h
|
|
|
|
;;
|
|
|
|
;; Out:
|
|
|
|
;; CF - Non-Carry - indicates no error
|
|
|
|
;; AX - Number of contiguous KB above 1MB
|
|
|
|
memory_get_map:
|
2024-06-29 14:29:15 +00:00
|
|
|
call memory_e820_get_map
|
|
|
|
jnc .end
|
|
|
|
|
2024-06-11 09:53:34 +00:00
|
|
|
call memory_get_for_large_conf
|
|
|
|
jnc .end
|
2024-04-28 06:41:36 +00:00
|
|
|
clc
|
2024-06-11 09:53:34 +00:00
|
|
|
mov ah, 0x88
|
|
|
|
int 0x15
|
|
|
|
|
|
|
|
jc .end
|
|
|
|
|
2024-07-02 08:32:11 +00:00
|
|
|
movzx edx, ax
|
|
|
|
mov eax, 0x100000
|
|
|
|
call boot_info_add_memmap
|
2024-06-11 09:53:34 +00:00
|
|
|
|
|
|
|
.end:
|
2024-04-14 05:35:43 +00:00
|
|
|
ret
|
2024-06-11 09:53:34 +00:00
|
|
|
|
2024-07-02 09:33:44 +00:00
|
|
|
|
|
|
|
pE280AddrRange E820AddressRange
|