OSDev.org https://forum.osdev.org/ |
|
cast to pointer from integer of different size https://forum.osdev.org/viewtopic.php?f=13&t=56339 |
Page 1 of 1 |
Author: | viruss33 [ Mon Jun 27, 2022 12:40 pm ] |
Post subject: | cast to pointer from integer of different size |
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. |
Author: | iansjack [ Mon Jun 27, 2022 1:00 pm ] |
Post subject: | Re: cast to pointer from integer of different size |
Your code is 64-bit? |
Author: | Octocontrabass [ Mon Jun 27, 2022 1:04 pm ] |
Post subject: | 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. |
Author: | viruss33 [ Mon Jun 27, 2022 2:00 pm ] |
Post subject: | 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? |
Author: | eekee [ Mon Jun 27, 2022 2:19 pm ] |
Post subject: | Re: cast to pointer from integer of different size |
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 |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |