Page 2 of 2

Re: Memory Heap Value Seems Incorrect

Posted: Tue Jan 19, 2021 6:40 pm
by foliagecanine
TheGameMaker90 wrote:And employer?? I believe I mentioned "my company." I'm the CEO and this is (until it gets into a usable state) a personal project.
"My company" could be interpreted two different ways: You owning the company, or your employer being the company. It is possible iansjack interpreted it as your employer being the company or simply did not read the previous forum posts thoroughly.
TheGameMaker90 wrote:Sort of makes sense, but how can you have 64 bits on a 32 bit OS?
A 32-bit computer has a 32-bit address bus. This means that memory (or MMIO) cannot be addressed past 0xFFFFFFFF.
However, the C compiler DOES support doing 64-bit MATH on 32-bit computers. Technically, you can go further than 64 bits if you write custom code for handling the math, but the C compiler's support stops at 64-bit.

When Octocontrabass talked about virtual addresses having 64-bits, they were referring to when a 64-bit computer is in long mode. Since BIOS-based machines boot up in 16-bit mode, they must switch to protected mode to use a 32-bit address, and long-mode to use a 64-bit address.
A 32-bit OS simply means that you require a 32-bit computer at minimum, you at some point switch to protected mode, and you never use long-mode.

However, you CAN use more than 4GB (0xFFFFFFFF+1) of memory on a 32-bit computer with PAE (Physical Address Extension). You are still limited to using 4GB of memory at a time, but you can map memory beyond 4GB into the 4GB address space in the page tables.

Sorry, this next quote is kinda old. Hopefully it is of use to you.
TheGameMaker90 wrote:Perhaps it's the way large numbers are being represented in hexadecimal. Maybe indeed...
I just tried something:

Code: Select all

printf("%d\n", 0xFFFFFFFF);
And it prints: -1...
Hmm. That can't be normal...
Actually, the way binary math works, it does.
%d is the formatting specifier to print SIGNED integers;
The number you are entering in the form 0xFFFFFFFF is an UNSIGNED integer.
When converting from unsigned to signed, the last bit (bit 31) is the sign bit. That means 0xFFFFFFFF is equal to -1 to the computer.
If you want to learn more about unsigned/signed and how that works, you should research Two's Compliment or watch this video: https://www.youtube.com/watch?v=4qH4unVtJkE

To print 0xFFFFFFFF correctly, you need to use the %u formatting specifier.


Good luck with your project!

Re: Memory Heap Value Seems Incorrect

Posted: Wed Jan 20, 2021 12:38 am
by iansjack
If this a personal project then I can't see why you won't show the source repository when asking for help. This would make it far easier for people to help you.

Personal or not, you really need to read the documentation, which answers most of your questions. For example, the mechanism of PAE and the GRUB specification are very well documented. The necessity to know C fairly thoroughly should be obvious.