Memory Detecting Routine
Memory Detecting Routine
How could it be?? I want to know the size of my RAM memory ( without using BIOS interrupts or GRUB ). Theorically, I need to write to an address and read from it. (OK). But I should handle fault when data is written into not present memory address. ( HOW ? )
This is my code for detecting memory size.
E820H bios function will help you to get the size of memory.
Code: Select all
; {{{ Now, try to get the size of memory
E820H:
; NOTICE
; we assume that the maximum index of MRD structure is 128
; if the MRD entry count is bigger than 128, it can makes problem..
; but most system didn't uses more than 128.. I believe that...
; just believing...
; If this makes some problem. try fix it.
; and I will check this and tell it to the KERNEL, to handle it.. :)
and BYTE [CPUTYPE], MEM_BIT_CLEAR
or BYTE [CPUTYPE], E820_USED
xor ebx, ebx
mov [MRD_CNT], BYTE 0
mov di, MRD
e_mem_info:
mov eax, 0x0000E820 ; function
mov edx, SMAP ; signature
mov ecx, 0x14 ; size of record
push ds
pop es ; set es to zero, di -> MemoryRangeDescriptor
int 0x15 ; interrupt
jc E820H_error ; no-carry = success
cmp eax, SMAP
jne E801H ; check signature
cmp ecx, 0x14
jne E801H ; check the size
add di, 0x14 ; add 20 to DI
cmp ebx, 0
je mem_ok ; check EOF (ebx == 0)
cmp BYTE [MRD_CNT], MRD_MAX_CNT
jae E820H_over_cnt
inc BYTE [MRD_CNT]
jmp e_mem_info ; LOOP
E820H_over_cnt:
and BYTE [CPUTYPE], MEM_BIT_CLEAR
or BYTE [CPUTYPE], E820_OVER
jmp mem_ok
E820H_error:
E801H:
mov di, MRD
and BYTE [CPUTYPE], MEM_BIT_CLEAR
or BYTE [CPUTYPE], E801_USED
stc
xor cx, cx
xor dx, dx
mov ax, 0xe801
int 0x15
jc E801H_error
cmp cx, 0
jne E801_USE_CX_DX
cmp dx, 0
jne E801_USE_CX_DX
mov ax, cx
mov bx, dx
E801_USE_CX_DX:
and edx, 0xffff
shl edx, 6
mov DWORD [di], edx
and ecx, 0xffff
add DWORD [di], ecx
add di, 4
jmp mem_ok
E801H_error:
E88H: ; real value of function is '88h'
mov di, MRD
and BYTE [CPUTYPE], MEM_BIT_CLEAR
or BYTE [CPUTYPE], E88_USED
mov ah, 0x88
int 0x15
mov WORD [di], ax
add di, 2
mem_ok:
int 0x12
mov WORD [di], ax
; }}}
http://nicesj.com
With the software, What You Think Is What You Get.(WYTIWYG)
With the software, What You Think Is What You Get.(WYTIWYG)
@sjpark: He doesn't want BIOS.
In that case you need to get memory from CMOS and that works clearly only with RAM < 64 MB. If I would be you, I get that value before switching to protected mode through BIOS like sjpark's example and store the value somewhere. Then, you switch to protected mode and you have the size of RAM in yer kernel
BIOS is legacy and slow, but useful sometimes
inflater
In that case you need to get memory from CMOS and that works clearly only with RAM < 64 MB. If I would be you, I get that value before switching to protected mode through BIOS like sjpark's example and store the value somewhere. Then, you switch to protected mode and you have the size of RAM in yer kernel
BIOS is legacy and slow, but useful sometimes
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Derrick operating system: http://derrick.xf.cz (Slovak and English )
ah, sorry I forgot what he said...inflater wrote:@sjpark: He doesn't want BIOS.
In that case you need to get memory from CMOS and that works clearly only with RAM < 64 MB. If I would be you, I get that value before switching to protected mode through BIOS like sjpark's example and store the value somewhere. Then, you switch to protected mode and you have the size of RAM in yer kernel
BIOS is legacy and slow, but useful sometimes
inflater
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Well, asking the bios or grub are the common (and the only politically correct) approaches. You should really use one of those. If you so want, you can try to use v8086 mode and call the bios from protected mode.
If you are really desparate, there's a page in the wiki on (alternative) methods of detecting memory with the appropriate warnings
If you are really desparate, there's a page in the wiki on (alternative) methods of detecting memory with the appropriate warnings