简体   繁体   English

m68k-elf 目标是否支持 GCC 内联 asm goto?

[英]Is GCC inline asm goto supported in the m68k-elf target?

I'm working on a project with lots of C wrappers around M68000 asm calls.我正在开发一个项目,其中包含许多围绕 M68000 asm 调用的 C 包装器。 A few of these calls return a success/fail status on the condition code register, so it would be ideal to 'goto' a C label depending on the status of CC.其中一些调用在条件代码寄存器上返回成功/失败状态,因此根据 CC 的状态“转到”C label 将是理想的。 However, no matter what permutations I try, I am constantly getting syntax errors from the compiler.然而,无论我尝试什么排列,我都会不断地从编译器中得到语法错误。

(This is gcc 10.2.0 --with-cpu=m68000) (这是 gcc 10.2.0 --with-cpu=m68000)

Example code:示例代码:

  asm(R"(
  moveq #0, d1
  jsr %p0
  bcc %l0
2:
    )":
        :
      "i"(_BURAM),
        "d"(d0_fcode),
        "a"(a0_info),
        "a"(a1_data)
        :
        "cc"
        : failed);

  return true;

  failed:
  return false;

The error this generates is:这产生的错误是:

/home/ryou/Projects/megadev/lib/sub/bram.h: In function 'bram_brmwrite':
/home/ryou/Projects/megadev/lib/sub/bram.h:156:7: error: expected ')' before ':' token
  156 |   "cc"
      |       ^
      |       )
  157 |   : failed);
      |   ~
/home/ryou/Projects/megadev/lib/sub/bram.h:144:5: note: to match this '('
  144 |  asm(R"(
      |     ^

I have attempted doing it with the simplest of examples, for testing:我尝试使用最简单的示例来进行测试:

asm("bra %l0" :::: failed);

And I still get:我仍然得到:

/home/ryou/Projects/megadev/lib/sub/bram.h:144:18: error: expected ')' before '::' token
  144 |  asm("bra %l0" :::: failed);

The only other somewhat relevant information I have found here is: Extended asm with goto, including an example from the gcc docs, fails to compile我在这里找到的唯一其他一些相关的信息是: Extended asm with goto,包括来自 gcc 文档的示例,无法编译

However, as you can see in both examples, I am not using any outputs.但是,正如您在两个示例中看到的那样,我没有使用任何输出。 I assume that the m68k-elf target does not support this in particular, but I really don't see why it wouldn't and I haven't found any documentation saying as much.我假设 m68k-elf 目标特别不支持这一点,但我真的不明白为什么它不支持,而且我没有找到任何文档说这么多。

There are ways around this (namely by checking the state of CC within the asm snippet itself and pushing the status to an output register), but if at all possible I'd like to use goto labels.有一些方法可以解决这个问题(即通过检查 asm 片段本身中 CC 的 state 并将状态推送到 output 寄存器),但如果可能的话,我想使用 goto 标签。 Any help with solving this would be much appreciated.任何解决此问题的帮助将不胜感激。

Yes, it is supported.是的,它受支持。 I think the problem is your code, which has a couple of errors:我认为问题在于您的代码,它有几个错误:

  1. To use the goto feature, you need to start the inline assembly statement with the asm goto keywords.要使用 goto 功能,您需要使用asm goto关键字启动内联汇编语句。 You are missing the goto .你错过了goto

  2. The label operands are numbered sequentially after the input operands (and of course there cannot be outputs). label 操作数在输入操作数之后按顺序编号(当然不能有输出)。 So failed is operand 4, and therefore you need to refer to it with bcc %l4 , not %l0 .所以failed是操作数 4,因此您需要使用bcc %l4而不是%l0来引用它。

With these changes I'm able to compile the code.通过这些更改,我能够编译代码。


By the way, I don't know much about m68k assembly, but it looks like you are clobbering register d1 , along with whatever the _BURAM subroutine clobbers, yet those have not been declared as clobbers.顺便说一句,我对 m68k 程序集不太了解,但看起来你正在破坏寄存器d1以及任何_BURAM子例程破坏器,但这些还没有被声明为破坏器。 Shouldn't you add "d1" and the rest along with "cc" ?您不应该将"d1"和 rest 与"cc"一起添加吗?

Also, it seems like maybe you are expecting the operands d0_fcode , a0_info , etc, to be put in those specific registers, presumably because _BURAM expects them there.此外,您似乎希望将操作数d0_fcodea0_info等放入那些特定的寄存器中,大概是因为_BURAM期望它们在那里。 Do you have those variables defined register asm to tell the compiler about that, eg register int d0_fcode asm("d0");你有那些变量定义register asm告诉编译器,例如register int d0_fcode asm("d0"); ? ? Otherwise it could for instance choose d4 for the d0_fcode operand.否则,它可以例如选择d4作为d0_fcode操作数。 In my test it happens by chance that they get put in the desired registers, without explicitly asking, but that is not safe to rely on.在我的测试中,碰巧将它们放入所需的寄存器中,而没有明确询问,但这并不安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM