Page 1 of 1

getting the amount of avilable memory

Posted: Thu Apr 28, 2005 11:00 pm
by aymanmadkour
Hi...
I am working on a memory manger. I am trying to get the amount of available memory FROM PROTECTED MODE. Any ideas?[/b]

Re: getting the amount of avilable memory

Posted: Thu Apr 28, 2005 11:00 pm
by bubach
Best ways to get RAM size is with the BIOS:
http://my.execpc.com/~geezer/osd/boot/biosmem.asm

Otherwise you can get it from CMOS, will only report up to 64mb, or by directly probing for memory.
When probing you simply write something at memroy positions like 0xdeadbeef at every megabyte, and then you read it and compare, if it's the same then the memory position exists.

Directly probing for memory won't work on machines where you might write your little test thing ( for ex. 0xdeadbeef) onto a "bad area" like memory mapped IO devices or hitting a memory hole.

/ Christoffer

Re: getting the amount of avilable memory

Posted: Thu Apr 28, 2005 11:00 pm
by aymanmadkour
I used the direct memory probing solution... It is not the best one, but it worked.
Thanks :)

Re: getting the amount of avilable memory

Posted: Sun May 01, 2005 11:00 pm
by beppe85
I dunno if there's a easy(and safe) way to do that in protected mode...because the usual way is to do BIOS calls. If you cannot get memory size while still in real mode and store in a variable, write a virtual-8086 monitor to call the BIOS services from protected mode.

This handles getting memory size from real mode. Works for me.

Code: Select all

mov     ax, 0xe801
int     15h
shl     eax, 10
shl     ebx, 16
add     eax, 1 * BytesPerMega
add     eax, ebx
mov     [TotalMemory], eax
This is my code, so it may not work in other machines.