OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 9:26 am 
Offline

Joined: Fri Mar 17, 2017 9:37 pm
Posts: 22
I'm using int 15h eax=e820h to obtain a high memory map before switching to 32-bit protected mode. I'm staring at the map I've received here, and find it strange that smbios in qemu has given me a set of non-contiguous memory regions, as in there is 0xf7fc0000 byte gap between two memory regions with nothing to fill it. I've confirmed this with grub2 and the Linux kernel using the same qemu flags. I know launching the program that I only have 128MiB of memory and that memory range is accounted for, but there is a 0x40000 byte region that is "reserved" outside of the physical memory I have "installed". I'm just unsure how I should have my OS interpret a non-contiguous memory map. It seems pretty easy here, as the "lonely" memory region is "reserved", but on other systems could it be marked usable and would it really be usable? I'm also curious as to why (and a little bit how, though I have some idea) my memory isn't contiguous. This is what I see (sorry I haven't implemented a serial console left so it would be a pain to copy it as text):
Image


Last edited by Izzette on Thu Apr 13, 2017 10:50 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 9:39 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
If you're anything like me, and you just want to make life easy on yourself, you can ignore everything but "usable" areas, and just add those areas that are flagged as usable to your memory manager. You still have to worry a little about overlapping usable areas, but you can probably safely ignore that situation for a few years.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 10:48 am 
Offline

Joined: Fri Mar 17, 2017 9:37 pm
Posts: 22
Ok, if the BIOS says it's a usable memory region and it's non-overlapping it's actually a usable memory region, got it. As for the "why" part: that 0xfffc0000-0xffffffff region is memory mapped to hardware, right? And it actually is accessible, I could stick a pointer to it and read and/or write, it just might not be safe to do so, right?


Top
 Profile  
 
 Post subject: Re: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 10:55 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
This is not a phenomenon of QEMU. Real hardware has non-contiguous mapping as well. For example there is an architectural hole below 4 GiB that contains the MSI space and often the APIC and PCI BARs as well. Note that this range has to stay below 4 GiB in order to support non-64-bit aware OS.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 12:39 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
Izzette wrote:
Ok, if the BIOS says it's a usable memory region and it's non-overlapping it's actually a usable memory region, got it. As for the "why" part: that 0xfffc0000-0xffffffff region is memory mapped to hardware, right? And it actually is accessible, I could stick a pointer to it and read and/or write, it just might not be safe to do so, right?

Yes. A region should be marked as reserved if it is being used to communicate with physical hardware, or if it contains important system data, like 16-bit interrupt handlers, SMBios code or ACPI tables. Anything the Operating System should not touch.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: e820 non-contiguous memory map
PostPosted: Thu Apr 13, 2017 7:31 pm 
Offline

Joined: Fri Mar 17, 2017 9:37 pm
Posts: 22
Got it! Thanks, @SpyderTL and @Korona.


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: Bing [Bot], DotBot [Bot] and 65 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