【发布时间】:2020-04-07 04:54:55
【问题描述】:
我在 Windows 机器上为 ARM CortexA9 使用 gcc 交叉编译器,用于裸机应用程序。对于直接内存映射,我需要访问地址 0x8000_0000。我使用以下 C 代码:
#define PORTBASE_A 0x80000000
unsigned int volatile * const portA = (unsigned int *) PORTBASE_A;
#define PORTBASE_B 0x70000000
unsigned int volatile * const portB = (unsigned int *) PORTBASE_B;
#define PORTBASE_C 0x080000000
unsigned int volatile * const portC = (unsigned int *) PORTBASE_C;
printf("Portbase_A %p \n",(unsigned int *) portA); // Portbase_A 0xffffffff80000000
printf("Portbase_B %p \n",(unsigned int *) portB); // Portbase_B 0x70000000
printf("Portbase_C %p \n",(unsigned int *) portC); // Portbase_C 0xffffffff80000000
printf("%d\n", sizeof(unsigned int *)); //4
使用printf("Portbase_A %p \n",(unsigned int *) portA); 导致输出
Portbase_A 0xffffffff80000000.
问题
尽管我的目标机器是 32 位机器,为什么我得到 64 位地址 (0xffffffff80000000)。我意识到在 0x8000_0000 中的前导位是一个,但是为什么这会导致 32 个前导位的 1 填充?这是由于交叉编译造成的某种人工制品吗?
非常感谢您的回复。
为了完整起见,这是我的分散文件的可视化。 scatter-file visualisation
【问题讨论】:
-
你能显示你的命令行吗?这很奇怪。
printf("%zu\n", sizeof(unsigned int *))说什么? -
你究竟是如何编译和链接代码的?
-
printf("%zu\n", sizeof(unsigned int *)); // uprintf("%d\n", sizeof(unsigned int *)); //44 和你是我提到的电话的输出 -
我使用 ARM DS-5 SDK 进行编译和链接。
-
哎呀。
printf("%d %d %d %d\n", sizeof(int), sizeof(long), sizeof(long long), sizeof(uintptr_t));和printf("%ld %lx %lld %llx\n", (long)-1, (long)-1, (long long)-1, (long long)-1);和printf("%s\n", _NEWLIB_VERSION )的输出是什么?_WANT_IO_C99_FORMATS、_WANT_IO_LONG_LONG和_NANO_FORMATTED_IO等宏是否已定义?
标签: c memory arm cross-compiling