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.
cast to pointer from integer of different size
Re: cast to pointer from integer of different size
Your code is 64-bit?
-
- Member
- Posts: 5512
- Joined: Mon Mar 25, 2013 7:01 pm
Re: cast to pointer from integer of different size
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.
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.
Re: cast to pointer from integer of different size
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?
Re: cast to pointer from integer of different size
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: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?
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
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie