Getting a negative amount of memory?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
oib111
Posts:38
Joined:Sat Aug 29, 2009 6:44 am
Getting a negative amount of memory?

Post by oib111 » Sun Sep 20, 2009 7:20 am

I'm using the code from the tutorials to get the amount of memory on the system, but it's returning a negative number:

Code: Select all

Memory Size: -268370093KB
Any idea on what's going on?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Getting a negative amount of memory?

Post by Andyhhp » Sun Sep 20, 2009 2:48 pm

This means you are interpreting an unsigned integer as a signed integer when converting it to a string to print.
Image

oib111
Posts:38
Joined:Sat Aug 29, 2009 6:44 am

Re: Getting a negative amount of memory?

Post by oib111 » Sun Sep 20, 2009 4:15 pm

Oh right, I remember I had a similar problem on hexadecimal numbers, thanks Andy. I still have some questions. Is the memory being returned in KB or bytes, because the amount seems too big to possibly be in KB. And also, how come in 14th demo (with the virtual memory manager) we initialize the physical memory manager with the size of RAM as bootinfo->m_memorySize when in demo11 we use 1024 + bootinfo->m_memoryLo + bootinfo->m_memoryHi*64?

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Getting a negative amount of memory?

Post by Mike » Mon Sep 21, 2009 1:59 am

Hello,

That memory size does not look right: It should be in KB. In demo 12 (Chapter 18), we passed the bootinfo struct containing two members: uint32_t m_memoryLo and uint32_t m_memoryHi In chapter 12, we combined them into one 64 bit memorySize member for simplicity.

They both initialize the memory size using the same basic method - just differently do to the above difference between the two tutorials. The basic formula is Memory Size in KB = 1024 + memLow + (memoryHi * 64) do to the interrupt that is used in the bootloader and what it returns.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

oib111
Posts:38
Joined:Sat Aug 29, 2009 6:44 am

Re: Getting a negative amount of memory?

Post by oib111 » Mon Sep 21, 2009 2:54 am

I see. Well for whatever reason I seem to be getting the amount of memory in bytes, no biggie lol.

EDIT:

Nevermind...I have no idea what I'm getting. I just realized Bochs default memory is 32MB, and Virtual Box's is 64MB, and it was reporting around 38MB of RAM...also noticed that the amount of available RAM (not total RAM, I mean available like the opposite of used) is always 1MB away from the correct amount of total RAM. Like in Bochs the available amount is 31MB (one less than 32MB) and in Virtual Box it is 63MB (one less than 64MB) :|

Post Reply