OSDev.org
https://forum.osdev.org/

Why the undeclared gap in the QEMU memory layout and how...
https://forum.osdev.org/viewtopic.php?f=1&t=33464
Page 1 of 1

Author:  scippie [ Sun Jan 27, 2019 9:08 am ]
Post subject:  Why the undeclared gap in the QEMU memory layout and how...

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?

Author:  BenLunt [ Sun Jan 27, 2019 11:27 am ]
Post subject:  Re: Why the undeclared gap in the QEMU memory layout and how

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

Author:  scippie [ Sun Jan 27, 2019 12:24 pm ]
Post subject:  Re: Why the undeclared gap in the QEMU memory layout and how

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.

Author:  Korona [ Sun Jan 27, 2019 12:39 pm ]
Post subject:  Re: Why the undeclared gap in the QEMU memory layout and how

"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.

Author:  omarrx024 [ Mon Jan 28, 2019 1:40 pm ]
Post subject:  Re: Why the undeclared gap in the QEMU memory layout and how

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/