Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;错误:不支持针对<;注册>&引用;.c文件中的内联PPC程序集代码出错_C_Gcc_Assembly_Powerpc - Fatal编程技术网

&引用;错误:不支持针对<;注册>&引用;.c文件中的内联PPC程序集代码出错

&引用;错误:不支持针对<;注册>&引用;.c文件中的内联PPC程序集代码出错,c,gcc,assembly,powerpc,C,Gcc,Assembly,Powerpc,我有以下内联汇编代码。但当我试图编译它时,它会抛出代码片段后面提到的错误 unsigned int func(void) { __asm__ ("mfspr r3, svr;"); } 下面是错误 {standard input}: Assembler messages: {standard input}:3349: Error: unsupported relocation against r3 {standard input}:3349: Error: unsupported relo

我有以下内联汇编代码。但当我试图编译它时,它会抛出代码片段后面提到的错误

unsigned int func(void)
{
  __asm__ ("mfspr r3, svr;");
}
下面是错误

{standard input}: Assembler messages:
{standard input}:3349: Error: unsupported relocation against r3
{standard input}:3349: Error: unsupported relocation against svr
{standard input}:3375: Error: unsupported relocation against r3
{standard input}:3375: Error: unsupported relocation against svr
{standard input}:3510: Error: unsupported relocation against r3
{standard input}:3510: Error: unsupported relocation against svr
{standard input}:3517: Error: unsupported relocation against r3
{standard input}:3517: Error: unsupported relocation against svr

有人能帮我修复这些吗?

显然gas没有内置的寄存器支持。为了使用它们,您应该自己定义它们,或者显式地使用它们的索引,如:

mfspr 3, <some_index_here>
mfspr 3,
或者,您可以包括:


如果你的核心是一个svr指数,那么svr指数将是1023

您应该明确指定输入和输出。如前所述,您的ASM块可能已优化

unsigned int func(void)
{
    unsigned x;
    __asm__("mfspr %0, svr" : "=b"(x));
    return x;
}
编译器足够聪明,可以计算出寄存器应该是
r3
。(这是编译器的主要工作之一:寄存器分配以最小化额外移动。)


如果您省略了输出规范,然后在启用优化的情况下编译,您可能会发现您的函数是空的,没有可找到的
mfspr
操作码。

这是gas在试图说它不知道“r3”和“svr”是寄存器名称时发出的有用错误消息。gas要求寄存器操作数使用数字而不是寄存器名称。如果您尝试,您会收到类似的错误消息

__asm__ ("mfspr foo, fum;");

换句话说,gas将寄存器名解释为任意符号。

如果您将
-mregnames
选项传递给汇编程序,至少一些错误会消失。(
-Wa,-mregnames
)。gas 2.19支持PPC的以下符号寄存器名称(来自binutils-2.19/gas/config/tc PPC.c):

/*预定义寄存器列表:
每个普通登记册都有预定义的表格名称:
1.r的值。
2.R这是有价值的。
每个浮点寄存器都有预定义的格式名称:
1.f的值。
2.F这是有价值的。
每个向量单位寄存器都有预定义的形式名称:
1.v的值。
2.v这是有价值的。
每个条件寄存器都有预定义的表单名称:
1.具有该值的cr。
2.有价值的。
还有单独的登记册:
sp或r.sp的值为1
rtoc或r.toc的值为2
fpscr的值为0
xer的值为1
lr的值为8
ctr的值为9
pmr的值为0
dar的值为19
dsisr的值为18
dec的值为22
sdr1的值为25
srr0的值为26
srr1的值为27
表格已排序。适合通过二进制搜索进行搜索*/

@vimalprathap:可能未定义
svr
。使用数字版本。@DietrichEpp我的构建中有一个类似的错误,尽管对于系统调用swapcontext,请也仔细检查一下@是的。请参阅e500mc参考手册:
/* List of registers that are pre-defined:

   Each general register has predefined names of the form:
   1. r<reg_num> which has the value <reg_num>.
   2. r.<reg_num> which has the value <reg_num>.

   Each floating point register has predefined names of the form:
   1. f<reg_num> which has the value <reg_num>.
   2. f.<reg_num> which has the value <reg_num>.

   Each vector unit register has predefined names of the form:
   1. v<reg_num> which has the value <reg_num>.
   2. v.<reg_num> which has the value <reg_num>.

   Each condition register has predefined names of the form:
   1. cr<reg_num> which has the value <reg_num>.
   2. cr.<reg_num> which has the value <reg_num>.

   There are individual registers as well:
   sp or r.sp     has the value 1
   rtoc or r.toc  has the value 2
   fpscr          has the value 0
   xer            has the value 1
   lr             has the value 8
   ctr            has the value 9
   pmr            has the value 0
   dar            has the value 19
   dsisr          has the value 18
   dec            has the value 22
   sdr1           has the value 25
   srr0           has the value 26
   srr1           has the value 27

   The table is sorted. Suitable for searching by a binary search.  */