OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 5:01 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [Solved] E820 Memory Results
PostPosted: Wed Mar 14, 2018 5:01 pm 
Offline

Joined: Fri Nov 17, 2017 6:07 pm
Posts: 16
I obtain information about the memory installed on my PC using the e820 mechanism provided by the BIOS. I have tried to attach an image showing my results (if the image is not displaying I will work on getting it up ASAP). However, my questions may be able to be answered with the image.

I believe I executed retrieved the data correctly, but am surprised by the results (see image below). Following is a list of questions and a screen shot of my results.

a) Regarding the status of the regions returned from the e820 function, the states are: Available and Reserved. However, some regions returned 4. Does anyone know what 4 means? Should this just be considered reserved?

b) I have 4 Gigabytes of memory installed. However, the maximum address returned is 0xBF77A000 + 0x7000 ( 0xBF781000 ). Why is this shown as the maximum amount of memory and not 0xFFFFFFFF? Further, if the only evidence of the memory installed is this map, how can I know for certain how much memory is installed?

c) Consider the last two regions in the picture below. Both are reserved. What is the reason that two reserved regions aren't merged into one large reserved region?

https://photos.app.goo.gl/sJ1VLmOKCRO4PZcF2

_________________
First time attempt at an OS: https://github.com/donsiuch/dinux/


Last edited by piscus on Wed Mar 14, 2018 8:34 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: E820 Memory Results
PostPosted: Wed Mar 14, 2018 6:10 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
piscus wrote:
a) Regarding the status of the regions returned from the e820 function, the states are: Available and Reserved. However, some regions returned 4. Does anyone know what 4 means? Should this just be considered reserved?

Yes. The ACPI spec says memory type 4 means ACPI non-volatile area. This is normally used for MMIO for stuff like batteries, laptop lids, etc. Treat it like reserved.

piscus wrote:
b) I have 4 Gigabytes of memory installed. However, the maximum address returned is 0xBF77A000 + 0x7000 ( 0xBF781000 ). Why is this shown as the maximum amount of memory and not 0xFFFFFFFF? Further, if the only evidence of the memory installed is this map, how can I know for certain how much memory is installed?

Somehow I doubt this, but I'll go for it. Are you assuming the size of the memory map entry to be 20 or 24? Because the spec really says it can be anything higher than 20.

piscus wrote:
c) Consider the last two regions in the picture below. Both are reserved. What is the reason that two reserved regions aren't merged into one large reserved region?

There isn't necessarily a real reason. The firmware can do almost anything as long as it complies with the specs.

Your memory map looks sane to me actually. Are you sure the PC has 4 GB of RAM? Normally when it has 4 GB of RAM, the first 3 GB are mapped normally, and the last GB is in the 64-bit address space (from 4 GB to 5 GB), to allow PCI MMIO and ACPI tables/MMIO and APICs/HPET/etc to be located between 3-4 GB, for compatibility with 32-bit software.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: E820 Memory Results
PostPosted: Wed Mar 14, 2018 7:17 pm 
Offline

Joined: Fri Nov 17, 2017 6:07 pm
Posts: 16
Omar, thanks for the response! That e820 map was produced on my Lenovo Thinkpad t410 (also a 64 Bit machine).

I am assuming the size of the memory map entry to be 20.

Regarding your question about the 4 Gigs, I double checked:

Since I have Linux installed on this PC, I did a 'cat /proc/meminfo' and got:

MemTotal: 3917488 kB
MemFree: 2108540 kB
MemAvailable: 2573120 kB
... etc.

3917488 kB --> 397488000 B --> 0xE9801F80 Bytes

This is pretty close to 4G which is where I am getting that number from.

_________________
First time attempt at an OS: https://github.com/donsiuch/dinux/


Last edited by piscus on Wed Mar 14, 2018 7:44 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: E820 Memory Results
PostPosted: Wed Mar 14, 2018 7:38 pm 
Offline

Joined: Fri Nov 17, 2017 6:07 pm
Posts: 16
I was able to find the e820 map Linux created on boot via 'dmesg'

The Linux map is identical to mine... only up until a certain point. The Linux version has several more entries beyond my own. Now I'm thinking that some sort of bug is cutting me off early. I am going to investigate and I will post back if I find what the issue is and mark this Resolved.

Thanks again for the response to my questions Omar

_________________
First time attempt at an OS: https://github.com/donsiuch/dinux/


Top
 Profile  
 
 Post subject: Re: E820 Memory Results
PostPosted: Wed Mar 14, 2018 7:55 pm 
Offline
Member
Member

Joined: Thu Jun 17, 2010 2:36 am
Posts: 141
piscus wrote:
I obtain information about the memory installed on my PC using the e820 mechanism provided by the BIOS. I have tried to attach an image showing my results (if the image is not displaying I will work on getting it up ASAP). However, my questions may be able to be answered with the image.

I believe I executed retrieved the data correctly, but am surprised by the results (see image below). Following is a list of questions and a screen shot of my results.

a) Regarding the status of the regions returned from the e820 function, the states are: Available and Reserved. However, some regions returned 4. Does anyone know what 4 means? Should this just be considered reserved?

b) I have 4 Gigabytes of memory installed. However, the maximum address returned is 0xBF77A000 + 0x7000 ( 0xBF781000 ). Why is this shown as the maximum amount of memory and not 0xFFFFFFFF? Further, if the only evidence of the memory installed is this map, how can I know for certain how much memory is installed?

c) Consider the last two regions in the picture below. Both are reserved. What is the reason that two reserved regions aren't merged into one large reserved region?

https://photos.app.goo.gl/sJ1VLmOKCRO4PZcF2


There are hardware devices that are mapped into the same address space as "regular RAM", so just because you have 4GB of RAM installed don't expect the maximum address to be 0xFFFFFFFF. The reason the BIOS returns two entries of the same type in adjacent regions is probably because the BIOS developers were lazy and didn't want to check to see if it was possible to merge a region before adding it. Either way its still a perfectly valid E820 map.

To know how much usable RAM is installed you just sum up the length of all the 'type 1' regions. This may differ slightly from what the user expects, e.g. it might not be exactly 16GB if they have 2x8GB sticks of RAM installed. The E820 function is the only way to get a reliable memory map that is useful enough to continue with. So long as the E820 function doesn't indicate an error the map it provides should be trusted but you have to account for weird things like overlapping regions, etc. If it returns an error or isn't available it really isn't worth trying to use other methods (IMHO, I'm sure others will disagree) to detect memory.

piscus wrote:
Omar, thanks for the response! That e820 map was produced on my Lenovo Thinkpad t410 (also a 64 Bit machine).

Regarding your question about the 4 Gigs, I double checked:

Since I have Linux installed on this PC, I did a 'cat /proc/meminfo' and got:

MemTotal: 3917488 kB
MemFree: 2108540 kB
MemAvailable: 2573120 kB
... etc.

3917488 kB --> 397488000 B --> 0xE9801F80 Bytes

This is pretty close to 4G which is where I am getting that number from.


Try:
Code:
dmesg | grep BIOS-e820


and see what it shows in Linux. Should be 100% identical to what the BIOS gave the kernel.

I suspect that you're somehow missing the last entry (or more) when you're printing your map. Can you post the code on how you call the E820 function? Is it possible you're incrementing the "entry count" after you check if EBX=0 so the last entry is missed?


Top
 Profile  
 
 Post subject: Re: E820 Memory Results
PostPosted: Wed Mar 14, 2018 8:33 pm 
Offline

Joined: Fri Nov 17, 2017 6:07 pm
Posts: 16
Thanks for the response Rudster. There was a silly error printing the memory map -- I was making a terrible assumption about the number of entries and cutting off the printing early. Turns out there are nearly 40 entries in my map and they do infact continue to increment up to the 4 gig mark.

I am happy with the help and responses to my questions. Thanks again all!

_________________
First time attempt at an OS: https://github.com/donsiuch/dinux/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: belliash, Bing [Bot] and 373 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group