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 mapis stored at0x20004and 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
-
testis likecmp. The difference is thattestis logical comparison andcmpis arithmetic comparison. Also there is some performance and size difference-
result of
test eax, eaxis equal to the result ofcmp eax, 0except the size and internal implementation -
testdoes bitwise-and operation and discards result -
cmpdoes subtraction operation and discards result
-
-
int 0x15 EAX=0xE820is complicated service. I recommend to read osdev wiki to use the service -
jc short .failed,jne short .failed,jmp short .jmpin-
j* shortis 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,jrcxzis jump if cx or ecx or rcx is zero -
jbeis for unsigned number comparison -
clcmeans clear CF flag in EFLAGS -
stcmeans set CF flag in EFLAGS -
andandtestboth does the bitwise-and operation and set some flags-
test instruction
discardsresult -
and instruction does not discard result
-