OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 1:41 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Answered] GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 6:54 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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?

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Last edited by Octacone on Sat Apr 15, 2017 6:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 7:35 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
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

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject: Re: GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 7:45 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


Top
 Profile  
 
 Post subject: Re: GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 8:42 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 9:49 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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?
Attachment:
MemoryMapGRUB.png
MemoryMapGRUB.png [ 12.99 KiB | Viewed 2133 times ]

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 9:54 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
What's 0xF(x8)1 ?? Other than that looks ok.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: [Answered] GRUB Memory Map Stealing 513KB
PostPosted: Fri Apr 14, 2017 10:02 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 606 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