OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Jul 23, 2019 6:25 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Why the undeclared gap in the QEMU memory layout and how...
PostPosted: Sun Jan 27, 2019 9:08 am 
Offline
Member
Member

Joined: Wed Jun 27, 2012 3:57 am
Posts: 33
I am working on my memory management and I used int 15h, function E820 to retrieve a memory layout of the system (as explained on https://wiki.osdev.org/Detecting_Memory_(x86) and I don't think my question is explained in there unless I am missing it)

I receive a nice looking table with recognizable values:
0x0 (0x9FC00) (1)
0x9FC00 (0x400) (2)
0xF0000 (0x10000) (2)
0x100000 (0xBFEE0000) (1)
0xBFFE0000 (0x20000) (2)
0xFFFC0000 (0x40000) (2)
...

I just noticed that this table has gaps: 0x9FC00 + 0x400 = 0xA0000, but there is no definition in the table for 0xA0000-0xF0000. Of course I know that this is the video memory area for VGA, and as I ignore everything < 1MB and reserve it as kernel space, it's no worry.
But at 0xBFFE0000, there is a 0x20000 system reserved chunk, and only at 0xFFFC0000, there is a 0x40000 system reserved chunk.
0xBFFE0000 + 0x20000 = 0xBFFF0000, not 0xFFFC0000.

First I thought I had written a code bug, but then I saw someone else in another post getting the same values (https://forum.osdev.org/viewtopic.php?t=30318).

So, why the gaps? And how should I handle them?

Should I just ignore the sizes in the table and take the next memory address to know the size of the entry?
Would I have the same gaps on a typical real system?


Top
 Profile  
 
 Post subject: Re: Why the undeclared gap in the QEMU memory layout and how
PostPosted: Sun Jan 27, 2019 11:27 am 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 559
Location: USA
Hi,

To be completely safe, you should only use the memory area(s) the firmware returns to you as usable. Period.

As you stated, the area at 0x000A0000 is video memory. The memory at and above 0xBFFE0000 (as you stated) is usually mem-mapped devices and you will find these memory areas when you enumerate the PCI(e).

As long as you call the firmware and request a valid memory map, as you have done for the legacy BIOS, you need to trust the firmware and only use the memory it tells you that you can use. There will be a reason you shouldn't use the "gaps", whether the firmware returns a reason or not.

Ben
- http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: Why the undeclared gap in the QEMU memory layout and how
PostPosted: Sun Jan 27, 2019 12:24 pm 
Offline
Member
Member

Joined: Wed Jun 27, 2012 3:57 am
Posts: 33
BenLunt wrote:
As long as you call the firmware and request a valid memory map, as you have done for the legacy BIOS, you need to trust the firmware and only use the memory it tells you that you can use. There will be a reason you shouldn't use the "gaps", whether the firmware returns a reason or not.

That makes sense... the BIOS can't be aware of all the hardware.
Thanks.


Top
 Profile  
 
 Post subject: Re: Why the undeclared gap in the QEMU memory layout and how
PostPosted: Sun Jan 27, 2019 12:39 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 592
"Common" device regions in low memory are not report E820. Device memory in general is not necessarily reported.

The BIOS is actually aware of all device MMIO regions: As it was specifically compiled for a certain mainboard, it knows the devices present on that mainboard. All other devices are usually behind a PCI bridge that the BIOS configures. PCI bridges have specific memory regions attached to them (you can read about the bridge registers on the wiki) and all devices behind the bridge have to fall into those regions.

_________________
managarm: A microkernel-based OS that is capable of running a Wayland desktop


Top
 Profile  
 
 Post subject: Re: Why the undeclared gap in the QEMU memory layout and how
PostPosted: Mon Jan 28, 2019 1:40 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
The VGA memory area is considered part of a PCI device (the graphics card, obviously), and the ACPI specification explicitly says that the memory regions of PCI devices are not to be reported in the system memory map. On top of that, like Korona said, common well-defined memory areas aren't reported either.

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


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group