OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:33 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Unsigned addition really performs subtraction.
PostPosted: Thu Jul 29, 2021 8:29 pm 
Offline

Joined: Sun Apr 04, 2021 7:51 pm
Posts: 4
I am working on finding out the physical address range that I need to add to my page tables to access the provided framebuffer.

When I add the size of the framebuffer (Which I calculated as pitch * height) to the address of the framebuffer, the result appears to be a subtraction instead.

The calculated size of my framebuffer is 0x384000 bytes, and GRUB says that the start address is at 0x40000000. However, when I add these two numbers, I get 0x3fc7c000.

My first thought was that I was (somehow) getting a negative number for the size of my framebuffer (Or, at least the sign bit was set because of the multiplication result being large enough.) however, both my integers are `unsigned long long`and `unsigned long`, and I even checked with (x & (1 << 63)) and the sign bits are not set on either. Even if the sign bits are set, they should not be added as a signed integer.

What do you guys think is going on here? Am I doing something wrong?
This is the github repo: https://github.com/wireboy5/64bitOS

Thank's for your consideration!


Top
 Profile  
 
 Post subject: Re: Unsigned addition really performs subtraction.
PostPosted: Thu Jul 29, 2021 9:14 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You're converting the number to signed int before printing it.


Top
 Profile  
 
 Post subject: Re: Unsigned addition really performs subtraction.
PostPosted: Thu Jul 29, 2021 11:57 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
wireboy5 wrote:
1 << 63

Also, you likely want 1ULL << 63.


Top
 Profile  
 
 Post subject: Re: Unsigned addition really performs subtraction.
PostPosted: Fri Jul 30, 2021 12:22 pm 
Offline

Joined: Sun Apr 04, 2021 7:51 pm
Posts: 4
Thank you guys!

That was probably the silliest mistake I have made in a while. At least I have learned something though: Always check your debugging methods.

Thanks again!


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

All times are UTC - 6 hours


Who is online

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