UEFI GetMemoryMap() incorrectly showing low memory as free

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Tyyrus
Posts: 9
Joined: Tue May 26, 2020 8:44 pm

UEFI GetMemoryMap() incorrectly showing low memory as free

Post by Tyyrus »

Hello all,

I was working on my physical memory manager; more specifically I was working on getting a few memory bitmaps in place. I noticed some very strange performance behavior, and after a ton of debugging, came to realize that my bitmap was actually bring printed as pixels across the top of my screen, and it looks like the performance issues occurred whenever the screen was bring printed too.

The memory area I was in was nowhere near the graphics buffer. Very long story short, my system was allocating the first available large enough space in "free" memory (according to UEFI's getMemoryMap) to store my bitmap. I put the memory map in another post a couple days ago, here it is:

Code: Select all

Type Start Addr   Num Pages
7     0            160
7     1048576      768
2     4194304      2
7     4202496      7172
4     33579008     1
7     33583104     25
4     33685504     2272
7     42991616     9984
2     83886080     1
7     83890176     389055
1     1677459456   10
7     1677500416   491574
4     3690987520   32
7     3691118592   11827
2     3739561984   3
7     3739574272   775
4     3742748672   202
7     3743576064   27
4     3743686656   2836
7     3755302912   18
3     3755376640   366
5     3756875776   48
6     3757072384   36
0     3757219840   4
9     3757236224   8
10    3757268992   4
4     3757285376   134
6     3757834240   32
7     3757965312   16
7     4294967296  1179648
You might already be able to tell what happened, by the title and the table, but the memory bitmap was being stored in very low memory, the first table entry. It appears that the display was changing (and performance issues had) when the bitmap was writing to 0x000A0000, a.k.a. the video display memory. Some other system magic behind the scenes replicated this into my graphics buffer, but that's really besides the point.

I had assumed (silly me) that if UEFI told me that the first 160 pages of memory were "conventional memory" (Type 7, free to use how you want), that I could use it. I thought those low memory addresses just weren't reserved if you were using UEFI. Clearly that's not correct, so what memory addresses should I "black out"? Everything below 1mb? Why doesn't UEFI mark these important sections as reserved anyway? Is it a quirk of using VirtualBox? Are there other important parts of memory I should be marking as reserved?

Thanks ahead of time!
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: UEFI GetMemoryMap() incorrectly showing low memory as fr

Post by Octocontrabass »

The memory map is correct, you must be interpreting it wrong somewhere. If you have 160 4kiB pages starting at 0, they cover addresses from 0 to 0x9FFFF and 0xA0000 is not included.
Tyyrus
Posts: 9
Joined: Tue May 26, 2020 8:44 pm

Re: UEFI GetMemoryMap() incorrectly showing low memory as fr

Post by Tyyrus »

Wow, that's embarrassing lol.. You're right, and my 4am sleep-deprived brain didn't catch that.. I think I should take a break for a day or two lol. There's a problem with the function that translated the free space from the memory map, but I had moved on past that part. Thanks for the help again, I'll try to double-check the obvious things next time before I post :)
Post Reply