Detection of memory?

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
rup1033
Posts: 11
Joined: Thu May 26, 2005 11:00 pm

Detection of memory?

Post by rup1033 »

I am working on a memory manger for my os, and id like to implement paging allthough before i delve into that I need to figure out how to get the system memory amount im very unclear on how exactly to get the full system ram amount, i heard of a few things like probing(could cause issues), using the bios (only detects 64MB) , How does one get the value of extended memory in order to decide how many page bitmap entrys to put.
User avatar
smiddy
Member
Member
Posts: 127
Joined: Sun Oct 24, 2004 11:00 pm
Location: In my cube, like a good leming. ;-)

Re: Detection of memory?

Post by smiddy »

There are a lot of way to determine the amount of memory an x86 environment machine has. The most prefered way is using BIOS INT 15h AX=0E801h. You would also need to use INT 12h to determine the amount of conventional memory too. There is INT 15h AX=0E820 which is really comprehensive and gives you a mapping of all areas that are useable and non-useable. This one doesn't require you to use INT 12h as it does the conventional memory too. Then there is INT 15h AH=088h, though it has limitations in that it only detects up to 64MB. Then there is CMOS ports 17h & 18h for extended memory and ports 15h and 16h for conventional memory. CMOS is limited by the 64MB boundary too, and the conventional memory on most machines won't tell you if Extended BIOS Data Area (EBDA) is being used like INT 12h will. There there is probing. Probing is depedant on your routine to find everything...including where ROMs, PCI shares are etcetera. These areas are tricky to navigate and you run the risk of potentially harming your devices by poking those areas. There is another way too, that I am currently researching, there is PnP BIOS and SMBIOS. Apparently you can determine from the device IDs determine the amount of RAM on the motherboard, however, I haven't successfully done this yet. I expect to soon. Here is a screen shot of my machine with a DOS utility I wrote to get my RAM information:

Code: Select all

GETMEM - 0.16.0219 Attempt to see what memory is installed... -smiddy

BIOS:
   15h:
     E820:   Base Address   -  Memory Length    - Type
         : 0000000000000000 - 000000000009FC00h -  01 <<   Available to OS   >>
         : 000000000009FC00 - 0000000000000400h -  02 <<   Reserved Memory   >>
         : 00000000000F0000 - 0000000000010000h -  02 <<   Reserved Memory   >>
         : 0000000000100000 - 0000000027EF0000h -  01 <<   Available to OS   >>
         : 0000000027FF0000 - 0000000000008000h -  03 << ACPI Reclaim Memory >>
         : 0000000027FF8000 - 0000000000008000h -  04 <<   ACPI NVS Memory   >>
         : 00000000FEC00000 - 0000000000001000h -  02 <<   Reserved Memory   >>
         : 00000000FEE00000 - 0000000000001000h -  02 <<   Reserved Memory   >>
         : 00000000FFF80000 - 0000000000080000h -  02 <<   Reserved Memory   >>
         ----------------------------------------------------------------
         : Total Memory     :         27F8FC00h -    670,628,864 bytes.
         ----------------------------------------------------------------
   12h:
         : Lower Memory     :         0009FC00h -        654,336 bytes.
   15h:
     E801: 
         : Extended Memory  :         27EF0000h -    669,974,528 bytes.
         ----------------------------------------------------------------
         : Total Memory     :         27F8FC00h -    670,628,864 bytes.
         ----------------------------------------------------------------
   12h:
         : Lower Memory     :         0009FC00h -        654,336 bytes.
   15h:
     88  :   
         : Extended Memory  :         03FFFC00h -     67,107,840 bytes.
         ----------------------------------------------------------------
         : Total Memory     :         0409F800h -     67,762,176 bytes.
         ----------------------------------------------------------------
CMOS:
         : Lower Memory     :         000A0000h -        655,360 bytes.
         : Extended Memory  :         03FFFC00h -     67,107,840 bytes.
         ----------------------------------------------------------------
         : Total Memory     :         0409FC00h -     67,763,200 bytes.
         ----------------------------------------------------------------
PROBE:
         : Extended Memory  :         27F00000h -    670,040,064 bytes.
         ----------------------------------------------------------------
         : Total Memory     :         27F9FC00h -    670,694,400 bytes.
I am working on PnP BIOS now and will soon look into Systems Management BIOS in order to see what it can tell me for installed RAM.

I hope this has given you some thoughts and ideas for researching the avenues for checking the installed RAM on x86 environment PCs. ;)
-smiddy
rup1033
Posts: 11
Joined: Thu May 26, 2005 11:00 pm

Re: Detection of memory?

Post by rup1033 »

Cool, ill look into using the bios 15h, i wish you luck on the new style of memory detection you are attempting.
rup1033
Posts: 11
Joined: Thu May 26, 2005 11:00 pm

Re: Detection of memory?

Post by rup1033 »

I found a far easier way, just before your kernel in assembly (if booting using grub) push eax, ebx (the two arguments for your kernel)
download and include the multiboot.h header file

#include <multiboot.h>
void k_main(multiboot_info_t *mbd, unsigned int magic)
{
unsigned long base_memory=mbd->mem_lower;
unsigned long extended_memory=mbd->mem_upper;
// theese are in Killobytes

}

And create some kind of global value that has the system ram amount in it for other files to use to see the total ram installed. mbd is only accessable inside k_main.
User avatar
smiddy
Member
Member
Posts: 127
Joined: Sun Oct 24, 2004 11:00 pm
Location: In my cube, like a good leming. ;-)

Re: Detection of memory?

Post by smiddy »

Grub works too...

I did get my PnP check to work and recognize all installed memory that way too. Now I need to do SMBIOS and I should have covered all the basis for memory. Unless there is another machine way of doing it.

BTW, in case anyone is wondering why the heck I am using PnP or SMBIOS, it seems that they are both real decent at determining the devices installed on motherboards along with their specific ports et al. It takes the asumption out of coding an OS.
-smiddy
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: Detection of memory?

Post by blackcatcoder »

i 've done it with the e820 method and it works perfectly. It was a little work to sort the entrys but if it works it's great.
Post Reply