How to Detect the Amount of RAM on Your PC
Posted: Tue Mar 13, 2007 2:41 pm
================================================
How to Detect the Amount of RAM?:
I want to give a short description on how to detect the amount of RAM: (This description I collected from the forums (mainly from Brendan and Smiddy) and from my experience).
1).
Use those BIOS calls:
INT 0x15, eax = 0xE820
INT 0x15, ax = 0xE881
INT 0x15, ax = 0xE801
INT 0x15, ah = 0xC7
INT 0x15, ah = 0x88
Use the CMOS:
Locations 0x17 and 0x18
All this can only give you information how much RAM is there below 64MB, but you would not get any information about ROM or any reserved areas, except for 0xE820, 0xE881, 0xE801 functions that are only present on new PCs.
================================================
2). Get RAM & ROM Information from the PnP BIOS.
(Some times the PnP Bios causes the OS to crash, so make sure you have a good exception handling and not to only display some blue screen of death, make sure that your OS can continue after a PnP Bios crash, and after crash only skip the PnP Information).
(Maybe is better getting the PnP Information by using the special I/O address, I have not yet tried it out but maybe it would work).
Fix me if I'm wrong.
================================================
3). Get the memory information from the PCI headers.
(This means go over all the valid PCI headers, and get the RAM and ROM locations and sizes).
================================================
4). Get ROM & RAM information from the SM BIOS.
(I didn't yet get good information about the RAM from the SM (Maybe because I'm not interpreting it right, but you can get from it the BIOS version, location, size, CPU, PCI slots etc).
It seems that you can't get any voluble information about the installed RAM from the SM BIOS, Fix me if I'm wrong.
================================================
From all what you have collected from the BIOS, CMOS, PnP, PCI, and SM BIOS, make a list and get ready for the last part >> Probing <<.
================================================
5). Probe every 1MB block of memory if it is valid.
(This is done by writing to the beginning block 0xAA55AA55 and reading it, if the value redden = 0xAA55AA55 do the test again but this time by writing 0x55AA55AA, if the test past you know that this RAM block is valid, before you start you must be in PM, and disable paging, and cashing).
Note:
Probing memory-mapped PCI devices may have unpredictable results and possibly damage your system, so once again we discourage its use. (From: http://www.osdev.org\osfaq2).
It seems that Brendan claims that you don't really have to be worried about this.
He wrote:
For older machines (80486 and older IIRC) there can be a problem with bus capacitance, where you write a value out to the system bus and read the same value back in when nothing is at that address. To solve this problem it's best to write to a dummy address in RAM between the write and the read.
(Brendan, tell me if I understood right what you write).
Another reason why not to be worried from probing, is because you first got all the information form the PCI headers, so you know were not to probe.
(Brendan, tell me if I'm right).
================================================
Another note (from Brendan):
If the computer has 15/16 MB of RAM and something (e.g. an old ISA SVGA card) mapped in the area from 15 MB to 16 MB, then your code will think that's an extra 1 MB of RAM. I guess you could provide warnings but be careful with your wording - there's a difference between not supporting the cards (e.g. OS works but card doesn't) and not supporting any computer that contains these cards (e.g. OS crashes).
================================================
Conclusion:
In conclusion it seems that to get the RAM amount and reserved areas use the PnP BIOS, PCI Headers, and probing, all the rest would not really help you a lot (this includes the BIOS functions, CMOS, and SM BIOS).
Fix me if I'm wrong.
Another thing to make sure that when you load your OS kernel and drivers, check their checksums to make sure that the files were loaded successfully, and not to invalid RAM, etc.
Have a successful RAM detection!
How to Detect the Amount of RAM?:
I want to give a short description on how to detect the amount of RAM: (This description I collected from the forums (mainly from Brendan and Smiddy) and from my experience).
1).
Use those BIOS calls:
INT 0x15, eax = 0xE820
INT 0x15, ax = 0xE881
INT 0x15, ax = 0xE801
INT 0x15, ah = 0xC7
INT 0x15, ah = 0x88
Use the CMOS:
Locations 0x17 and 0x18
All this can only give you information how much RAM is there below 64MB, but you would not get any information about ROM or any reserved areas, except for 0xE820, 0xE881, 0xE801 functions that are only present on new PCs.
================================================
2). Get RAM & ROM Information from the PnP BIOS.
(Some times the PnP Bios causes the OS to crash, so make sure you have a good exception handling and not to only display some blue screen of death, make sure that your OS can continue after a PnP Bios crash, and after crash only skip the PnP Information).
(Maybe is better getting the PnP Information by using the special I/O address, I have not yet tried it out but maybe it would work).
Fix me if I'm wrong.
================================================
3). Get the memory information from the PCI headers.
(This means go over all the valid PCI headers, and get the RAM and ROM locations and sizes).
================================================
4). Get ROM & RAM information from the SM BIOS.
(I didn't yet get good information about the RAM from the SM (Maybe because I'm not interpreting it right, but you can get from it the BIOS version, location, size, CPU, PCI slots etc).
It seems that you can't get any voluble information about the installed RAM from the SM BIOS, Fix me if I'm wrong.
================================================
From all what you have collected from the BIOS, CMOS, PnP, PCI, and SM BIOS, make a list and get ready for the last part >> Probing <<.
================================================
5). Probe every 1MB block of memory if it is valid.
(This is done by writing to the beginning block 0xAA55AA55 and reading it, if the value redden = 0xAA55AA55 do the test again but this time by writing 0x55AA55AA, if the test past you know that this RAM block is valid, before you start you must be in PM, and disable paging, and cashing).
Note:
Probing memory-mapped PCI devices may have unpredictable results and possibly damage your system, so once again we discourage its use. (From: http://www.osdev.org\osfaq2).
It seems that Brendan claims that you don't really have to be worried about this.
He wrote:
For older machines (80486 and older IIRC) there can be a problem with bus capacitance, where you write a value out to the system bus and read the same value back in when nothing is at that address. To solve this problem it's best to write to a dummy address in RAM between the write and the read.
(Brendan, tell me if I understood right what you write).
Another reason why not to be worried from probing, is because you first got all the information form the PCI headers, so you know were not to probe.
(Brendan, tell me if I'm right).
================================================
Another note (from Brendan):
If the computer has 15/16 MB of RAM and something (e.g. an old ISA SVGA card) mapped in the area from 15 MB to 16 MB, then your code will think that's an extra 1 MB of RAM. I guess you could provide warnings but be careful with your wording - there's a difference between not supporting the cards (e.g. OS works but card doesn't) and not supporting any computer that contains these cards (e.g. OS crashes).
================================================
Conclusion:
In conclusion it seems that to get the RAM amount and reserved areas use the PnP BIOS, PCI Headers, and probing, all the rest would not really help you a lot (this includes the BIOS functions, CMOS, and SM BIOS).
Fix me if I'm wrong.
Another thing to make sure that when you load your OS kernel and drivers, check their checksums to make sure that the files were loaded successfully, and not to invalid RAM, etc.
Have a successful RAM detection!