OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Aug 13, 2022 9:16 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: cast to pointer from integer of different size
PostPosted: Mon Jun 27, 2022 12:40 pm 
Offline

Joined: Sun Apr 23, 2017 4:28 am
Posts: 14
Currently I'm working on physical memory manager and I have a code that assigns address to a pointer variable, and I got this warning which I don't know how to fix. I have a uint32_t* bitmap = (uint32_t*)address, where address is taken from grub structure and is uint64_t.
Similarly, I have a code
memory_region* memory_regions = (memory_region*) address; where address uint64_t.


Top
 Profile  
 
 Post subject: Re: cast to pointer from integer of different size
PostPosted: Mon Jun 27, 2022 1:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4389
Location: Chichester, UK
Your code is 64-bit?


Top
 Profile  
 
 Post subject: Re: cast to pointer from integer of different size
PostPosted: Mon Jun 27, 2022 1:04 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4006
The warning means exactly what it says. The physical addresses in the Multiboot structures are 64 bits. You're writing 32-bit code, so your virtual addresses (pointers) have 32 bits.

If you haven't enabled paging, or you've set up paging for identity mapping only, you need to check to make sure the address is below 4GB before assigning it to a pointer.

If you have enabled paging and you're not using identity mapping, you can't use a physical address as a pointer. You need to assign a virtual address to that physical address in your page tables and assign the virtual address to a pointer. If the physical address is above 4GB, you must use PAE to access it.


Top
 Profile  
 
 Post subject: Re: cast to pointer from integer of different size
PostPosted: Mon Jun 27, 2022 2:00 pm 
Offline

Joined: Sun Apr 23, 2017 4:28 am
Posts: 14
Thanks, checking for addresses <4gb and casting address to uint32_t fixes the problem. Paging is not yet enabled, that's what im working now. I'm wondering how the compiler knows that the code I'm writing is 32-bit. Is it the target architecture that we pass to it?


Top
 Profile  
 
 Post subject: Re: cast to pointer from integer of different size
PostPosted: Mon Jun 27, 2022 2:19 pm 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 636
Location: Oscillating between two different potentials
viruss33 wrote:
Thanks, checking for addresses <4gb and casting address to uint32_t fixes the problem. Paging is not yet enabled, that's what im working now. I'm wondering how the compiler knows that the code I'm writing is 32-bit. Is it the target architecture that we pass to it?

With gcc, the executable is different for each... what to call it? major architecture version, and for some other details about the target. For instance, the full name of gcc on my old Knoppix disk is "i686-linux-gnu-gcc-8". (It's the only gcc install I have handy.) There's a bunch of symlinks in /usr/bin:

gcc -> gcc-8
gcc-8 -> i686-linux-gnu-gcc-8
i586-linux-gnu-gcc -> gcc-8
i686-linux-gnu-gcc -> gcc-8
i686-linux-gnu-gcc-8

_________________
Crunchy Kaph — An experimental Forth environment for certain PPC Macs.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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