直接内存映射GCC交叉编译

直接内存映射GCC交叉编译,c,memory,arm,cross-compiling,C,Memory,Arm,Cross Compiling,我正在windows机器上使用gcc交叉编译器,用于ARM CortexA9的裸机应用程序。对于直接内存映射,我需要访问地址0x8000\u 0000。我使用以下C代码: #define PORTBASE_A 0x80000000 unsigned int volatile * const portA = (unsigned int *) PORTBASE_A; #define PORTBASE_B 0x70000000 unsigned int volatile * const portB

我正在windows机器上使用gcc交叉编译器,用于ARM CortexA9的裸机应用程序。对于直接内存映射,我需要访问地址0x8000\u 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\u A%p\n”,(unsigned int*)portA导致输出
Portbase\u A 0xFFFFFFFF8000000

问题

尽管我的目标机器是32位机器,但为什么我会得到64位地址(0xFFFFFF8000000)。我意识到在0x8000_0000中,前导位是1,但为什么这会导致32个前导位的1填充?这是由于交叉编译而产生的人工制品吗

非常感谢您的回复

为了完整起见,这是我的分散文件的可视化。

从标准角度来看,根据
C99:6.3.2.3
引用:

5整数可以转换为任何指针类型。除非前面指定,否则结果是实现定义的,可能没有正确对齐,可能没有指向引用类型的实体,并且可能是陷阱表示。56)

由于结果是实现定义的,因此应该由实现来描述。编译程序。他说:

将指针转换为整数或将指针转换为整数的结果(C90 6.3.4、C99和C11 6.3.2.3)

从指针到整数的强制转换

如果指针表示小于整数类型,则从整数到指针的转换将丢弃最高有效位;如果指针表示大于整数类型,则根据整数类型的有符号性进行扩展,否则位将保持不变

我假设(读作:猜测)在您的平台上:

  • 两个补码用于表示数字和指针
  • int
    是4个字节
  • 所有指针都有8个字节

常量
0x8000000
0x7000000
的类型均为
int
。指针有8个字节。执行
(unsigned int*)PORTBASE\u A
时,编译器必须将
int
变量强制转换为8字节。您的编译器会生成这样的代码,即当从
int
转换到指针时,额外4字节中的所有额外位都会重复最高有效位。因此,结果值的额外位设置为1。

能否显示命令行?这太奇怪了。
printf(“%zu\n”,sizeof(unsigned int*))
说了什么?你到底是如何编译和链接代码的?
printf(“%zu\n”,sizeof(unsigned int*));//u
printf(“%d\n”,sizeof(unsigned int*)//4
4和u是上述调用的输出。为了编译和链接,我使用ARM DS-5 SDK.ook。
printf(“%d%d%d%d\n”、sizeof(int)、sizeof(long)、sizeof(long-long)、sizeof(uintpttr\t))的输出是什么
printf(“%ld%lx%lld%llx\n”,(长)-1,(长)-1,(长)-1,(长)-1,(长)-1)
printf(“%s\n”,新库版本)
?像
\u WANT\u IO\u C99\u FORMATS
\u WANT\u IO\u LONG\u LONG
\u NANO\u FORMATTED\u IO
这样的宏定义了吗?但OP说他的平台有32位指针。也: