Amount of RAM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Henry

Amount of RAM

Post by Henry »

I need to determine the amount of RAM that?s in my computer, and I need to know which areas that are available. How do I do that? I?ve read the FAQ but I didnt understand what was written there. I dont understand how you get a "map" from this code? Please help me!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Amount of RAM

Post by Candy »

Henry wrote: I need to determine the amount of RAM that?s in my computer, and I need to know which areas that are available. How do I do that? I?ve read the FAQ but I didnt understand what was written there. I dont understand how you get a "map" from this code? Please help me!

... sometimes I'm amazed by the incomprehensibility of others behaviour.

Try RBIL, int15/e820 plus links from there. Try int88. Try the GRUB map. Try probing. Try to work something out at least, before you come here that the explanation is too complex.

The FAQ is probably the easiest way to learn those things. If you don't understand the faq, do a step down and first learn the stuff below it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Amount of RAM

Post by Pype.Clicker »

Henry wrote: I?ve read the FAQ but I didnt understand what was written there. I dont understand how you get a "map" from this code? Please help me!
it would help us if you can better explain *what* you don't understand ... i.e. what question are still pending ...

I suggest you concentrate on "newer BIOSes - GET SYSTEM MEMORY MAP" as the first step. just call the INT with appropriated values in registers and you'll get an array of entry (e.g. the map) telling you the system configuration. An entry like

Code: Select all

0000-0000-0010-0000  0000-0000-00F0-0000 0000-0001 
for instance tells memory range 1MB-16MB is available for the OS
Henry

Re:Amount of RAM

Post by Henry »

Pype: I get the map using int 15, but my problem is to interpret it. I dont see how you get that MB 1-16 is available from that digits you wrote. That?s what I didnt understand
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Amount of RAM

Post by Brendan »

Hi,
Henry wrote: Pype: I get the map using int 15, but my problem is to interpret it. I dont see how you get that MB 1-16 is available from that digits you wrote. That?s what I didnt understand
Pype's digits are in hexidecimal:
0000-0000-0010-0000 0000-0000-00F0-0000 0000-0001

In decimal this is:
1048576 15728640 1

Which means, after the first 1 Mb (1048576 bytes) there's 15 Mb (or 15728640 bytes) of RAM (which is type 1).


Are you using NASM?

Code: Select all

;es:di = address of memory map data entry

   mov ebx,[es:di]
   mov ecx,[es:di+4]         ;ecx:ebx = base address of area in bytes
   mov edx,[es:di+8]
   mov esi,[es:di+12]         ;esi:edx = length of area in bytes
   mov eax,[es:di+16]         ;eax = memory area type (1 is RAM)

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Henry

Re:Amount of RAM

Post by Henry »

thank you brendan!
but what if ther? are gaps, so that the 1-2 mb is free, the 2-4 is in use, the 4-5 is free and so on?

And, do I only have to check the first 16 Mbytes? Is everything above "free to use"?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Amount of RAM

Post by Pype.Clicker »

Note that the 'QWORDs' are mainly there for compatibility with systems that will have more than 4GB of physical memory (which you can only use with the appropriate extension on some of the x86 processors)

As a first step, you can simply check that the 'highest' 32 bits of the region is made of zeroes and work with DWords everywhere:

Code: Select all

;; looking for a region where we can put data
;; assuming that the whole MAP table has been read into [Map]
;; assuming that ECX contains the amount of entries used in [Map]
ScanBiosMap:

mov edi,Map
.loop:
cmp [edi+16],1
  jne .nextEntry
cmp [edi+4],0
  jne .PaeSupportRequired
cmp [edi+12],0
  jne .PaeSupportRequired

;; we found a region that could interrest us ...
mov eax,[edi]      ;; eax is the start of the region
mov edx,[edi+8]
add edx, eax      ;; edx is the end of the region
call SetupFreeSpace

.nextEntry:
add edi,20
dec ecx
jne .loop
Hope That Helps
Post Reply