In my Acer laptop with 16GB memory, OS detects only 2GB, and In Samsung laptop with 8GB memory, OS detects only 3GB.
Until now, operating system checks physical memory by manually writing to
memory. However, this way is discouraged unless it is really necessary.
Before OS is loaded to memory, some region of memory is already reserved by
hardware. Because result of accessing and writing at the region is
unpredictable, it is recommended to use BIOS service. Among various ways
to get the memory map, I used a BIOS service called int 0x15, eax=0xE820
.
-
Sometimes accessing reserved area is allowed, but writing does not work. Or even accessing does not work
-
Sometimes, accessing or writing at reserved area causes reboot
-
Sometimes, accessing or writing at reserved area causes page fault or other exceptions
-
In Mint64OS,
memory map
is stored at0x20004
and number of entries is at0x20000
kCheckTotalRamSize function in Utility.c accesses the memory map entries and gets the total available memory size which does not include reserved regions
-
test
is likecmp
. The difference is thattest
is logical comparison andcmp
is arithmetic comparison. Also there is some performance and size difference-
result of
test eax, eax
is equal to the result ofcmp eax, 0
except the size and internal implementation -
test
does bitwise-and operation and discards result -
cmp
does subtraction operation and discards result
-
-
int 0x15 EAX=0xE820
is complicated service. I recommend to read osdev wiki to use the service -
jc short .failed
,jne short .failed
,jmp short .jmpin
-
j* short
is short jump. If the relative jump is less than 124 in address, short jump should be used because the size of instruction is only2 bytes
. Otherwise, use near jump or far jump -
far jump additionally includes segment selector
-
near jump works in the same segment (does not include selector in operand)
-
-
jcxz
,jecxz
,jrcxz
is jump if cx or ecx or rcx is zero -
jbe
is for unsigned number comparison -
clc
means clear CF flag in EFLAGS -
stc
means set CF flag in EFLAGS -
and
andtest
both does the bitwise-and operation and set some flags-
test instruction
discards
result -
and instruction does not discard result
-