[Answered] GRUB Memory Map Stealing 513KB

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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Answered] GRUB Memory Map Stealing 513KB

Post by Octacone »

I have a quick question? Does GRUB "steal" 513KB (449KB - other emulator) of memory?
Emulator memory: 2048MB (2097152KB). Lower Memory: 639KB. Upper Memory: 2096000KB. Total Memory: 2096639KB ==> 2047MB.
Where did the last megabyte go? Can I safely tell my memory manager that 2048MB are available?
Last edited by Octacone on Sat Apr 15, 2017 6:52 am, edited 1 time in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: GRUB Memory Map Stealing 513KB

Post by JAAman »

octacone wrote:I have a quick question? Does GRUB "steal" 513KB (449KB - other emulator) of memory?
Emulator memory: 2048MB (2097152KB). Lower Memory: 639KB. Upper Memory: 2096000KB. Total Memory: 2096639KB ==> 2047MB.
Where did the last megabyte go? Can I safely tell my memory manager that 2048MB are available?
you cannot safely tell your memory manager any amount of memory, actual RAM memory (especially on real hardware, though somewhat less common on emulators) is almost never contiguous -- always use the memory map, and instead of telling your memory manager how much memory exists, give your memory manager a list of available addresses

note: some of this missing memory might be in the area between the lower 639k and the upper 2096000k... the lower number is obviously already deducting some memory for firmware use (otherwise the number should be 640k rather than 639k) -- and if all the memory is laid out sequentially from address 0 (common on modern systems, though some older systems try to "remap" it to higher addresses) then about 384k of memory is hidden underneath the ROM region reserved for system and option ROMs between the lower and upper memory areas -- also the memory between 15MB and 16MB may not be usable (even if actual ram is located there, you will loose and be unable to use that memory on some systems which reserve that memory region for hardware use)

also note, some of that memory is used by the firmware for special tables and things that the OS cannot touch without destroying the computer (even after you take control of the system, the firmware continues to operate without your knowledge or intervention, and it might need some of that memory)

let me reiterate: if you are retrieving a total amount of memory instead of properly parsing the memory map, you can destroy the computer, this should never be done, it is dangerous to do, always always use the memory map
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GRUB Memory Map Stealing 513KB

Post by Octacone »

JAAman wrote:
octacone wrote:I have a quick question? Does GRUB "steal" 513KB (449KB - other emulator) of memory?
Emulator memory: 2048MB (2097152KB). Lower Memory: 639KB. Upper Memory: 2096000KB. Total Memory: 2096639KB ==> 2047MB.
Where did the last megabyte go? Can I safely tell my memory manager that 2048MB are available?
you cannot safely tell your memory manager any amount of memory, actual RAM memory (especially on real hardware, though somewhat less common on emulators) is almost never contiguous -- always use the memory map, and instead of telling your memory manager how much memory exists, give your memory manager a list of available addresses

note: some of this missing memory might be in the area between the lower 639k and the upper 2096000k... the lower number is obviously already deducting some memory for firmware use (otherwise the number should be 640k rather than 639k) -- and if all the memory is laid out sequentially from address 0 (common on modern systems, though some older systems try to "remap" it to higher addresses) then about 384k of memory is hidden underneath the ROM region reserved for system and option ROMs between the lower and upper memory areas -- also the memory between 15MB and 16MB may not be usable (even if actual ram is located there, you will loose and be unable to use that memory on some systems which reserve that memory region for hardware use)

also note, some of that memory is used by the firmware for special tables and things that the OS cannot touch without destroying the computer (even after you take control of the system, the firmware continues to operate without your knowledge or intervention, and it might need some of that memory)

let me reiterate: if you are retrieving a total amount of memory instead of properly parsing the memory map, you can destroy the computer, this should never be done, it is dangerous to do, always always use the memory map

Thanks for clarification. Actually I am trying to parse a memory map right now. C++ is making this hard for me (awful casting). I actually needed this information for display purposes. Then I guess I can tell the user he has 2048MB of RAM and tell the memory manager it can use 2047MB (memory map data of course).
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: GRUB Memory Map Stealing 513KB

Post by dozniak »

octacone wrote:Actually I am trying to parse a memory map right now. C++ is making this hard for me (awful casting).
Not too much, some casting may be necessary of course.

the actual parser has a few casts
Learn to read.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GRUB Memory Map Stealing 513KB

Post by Octacone »

dozniak wrote:
octacone wrote:Actually I am trying to parse a memory map right now. C++ is making this hard for me (awful casting).
Not too much, some casting may be necessary of course.

the actual parser has a few casts
Oh, I managed to get around it. That is not longer an issue. Thanks anyways.


Does this memory map look okay?
MemoryMapGRUB.png
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: GRUB Memory Map Stealing 513KB

Post by dozniak »

What's 0xF(x8)1 ?? Other than that looks ok.
Learn to read.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Answered] GRUB Memory Map Stealing 513KB

Post by Octacone »

dozniak wrote:What's 0xF(x8)1 ?? Other than that looks ok.
0xF(x8)1 = 0xFFFFFFFF + 1 = 0x100000000







Answered. :)
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Post Reply