The size 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
Peter_Vigren

The size of RAM...

Post by Peter_Vigren »

Hi, is there any way to get the size of the total RAM without using a BIOS interrupt??
pete.piper

Re:The size of RAM...

Post by pete.piper »

I've read some stuff on USENET but they all preach against determining RAM size yourself. For instance, direct probing is the act of writing a magic number at every 1 MB (arbitrary) intervals, reading it back, and concluding that it's usable RAM if it has maintained the data you wrote. I've heard of many instances of computer's locking up, memory holes at 16 MB, yada, yada, yada. Just go to http://groups.google.com and search for "RAM direct probing" or something of that nature and you'll get all that you want and more. (:

So the logical question is... how the heck does the BIOS do it? I'm not completely sure, to be honest. Any experts care to share? I've heard that it's still not stable to use similar methods to the BIOS because it needs to be done during system initialization (or something of that nature).

Pete
crazybuddha

Re:The size of RAM...

Post by crazybuddha »

Peter_Vigren

Re:The size of RAM...

Post by Peter_Vigren »

I need a way that circumvent BIOS... but thanks anyway.
crazybuddha

Re:The size of RAM...

Post by crazybuddha »

Oops. Didn't read to the end.



mov edi, 0x00100000
mov ebx, edi
probe:
mov eax, [edi]
xor [edi], edi
cmp [edi], eax
jz end
add edi, ebx
jmp probe
end:
sub edi, ebx ; EDI = bytes > 1 meg
.bdjames

Re:The size of RAM...

Post by .bdjames »

MemSize:
push ebx
push ecx
mov eax, 100000h
mov ebx, 100000h
jmp ProbeMemory
MemoryLoop:
add eax,ebx
ProbeMemory:
mov ecx, [eax]
xor [eax], eax
cmp [eax], ecx
jnz MemoryLoop
sub eax, ebx
pop ecx
pop ebx
ret
Tim

Re:The size of RAM...

Post by Tim »

Peter_Vigren wrote:I need a way that circumvent BIOS... but thanks anyway.
Don't want to use the BIOS? Then program the motherboard chipset manually. You'll need different code for every model of motherboard, and you'll have to talk to the chipset manufacturers yourself, because they almost certainly don't document the direct hardware interfaces.

Don't use direct probing of memory locations, because a lot of machines with memory-mapped devices will crash if you write to some sensitive area.

If you don't want to program the motherboard manually, use the handy built-in motherboard driver called "BIOS". Seriously -- get the memory size using the BIOS interrupts before you switch to protected mode. It's the only reliable way of doing it.
crazybuddha

Re:The size of RAM...

Post by crazybuddha »

Tim Robinson wrote:
Peter_Vigren wrote:I need a way that circumvent BIOS... but thanks anyway.
, because a lot of machines with memory-mapped devices will crash if you write to some sensitive area.
I've wondered about this. Does this mean there are devices which are mapped to memory locations above 1 Meg??
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:The size of RAM...

Post by Pype.Clicker »

well, at least the VBE framebuffer lies in high addresses, but there is (usually) a gap between it and RAM...
.bdjames

Re:The size of RAM...

Post by .bdjames »

Well,

It would be a pretty crapy os, if you did not know
where the holes are, so instead of depending on the
magical bios, why not determine the holes first then
probe. :-*

For your startup code the bios is fine (<16meg). So what are
the devices mapped above 16megs?

advanced interrupt control, ...
crazybuddha

Re:The size of RAM...

Post by crazybuddha »

.bdjames wrote:
advanced interrupt control, ...
Is this the APIC? I've never dealt with it.

And regarding the VBE framebuffer, you have to set this up early anyway, so you know you might not want to clobber it if you plan to support it. True?

Any others??
pete.piper

Re:The size of RAM...

Post by pete.piper »

Check out this thread that does a decent job of tackling many issues that arise in direct probing:

http://groups.google.com/groups?hl=en&l ... fd5&rnum=3

Here's another good one:

http://groups.google.com/groups?hl=en&l ... 394&rnum=5

Heck, and:

http://groups.google.com/groups?hl=en&l ... 865&rnum=7

Pete
Tim

Re:The size of RAM...

Post by Tim »

Is this the APIC? I've never dealt with it.
Yes, the APICs map to physical addresses fairly high up (I think around FEE00000). If your memory probing function is hitting these, something's gone wrong... :)
And regarding the VBE framebuffer, you have to set this up early anyway, so you know you might not want to clobber it if you plan to support it. True?
On a PCI card that supports a linear framebuffer (i.e. any modern one), the framebuffer will be mapped as a big chunk of memory high up in the address space. For example, my 32MB card is at 4GB - 32MB.
Any others??
Memory hole between 15MB and 16MB? Some BIOSes enforce that. ISA adapters between A0000 and E0000 (e.g. SCSI card). Some other weird memory-mapped device (a lot of PCI cards have the option to map their registers as memory locations rather than I/O ports).
Peter_Vigren

Re:The size of RAM...

Post by Peter_Vigren »

There is a way that I can get the memory size (limit lies at 64 Mb) without an interrupt... By reading the CMOS... First telling port 70h which register I want to access and the read port 71h...

Mov Al,Register
Out 70h,Al
;Jmp $+2   ; Windows doesn't like this one, that's why it is commented out
In Al,71h

Registers   Meaning
---------   -------
15h      Low word of base memory (kb)
16h      High word of base memory (kb)
17h      Low word of expanded memory (kb)
18h      High word of expanded memory (kb)

But as I wrote... that's the 64 Mb-limit...
K.J.

Re:The size of RAM...

Post by K.J. »

Do be warned, some of the BIOS functions for memory probing don't work in Bochs.

K.J.
Post Reply