简体   繁体   中英

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. 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. 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)

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

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.

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. 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. You are missing the goto .

  2. The label operands are numbered sequentially after the input operands (and of course there cannot be outputs). So failed is operand 4, and therefore you need to refer to it with bcc %l4 , not %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. Shouldn't you add "d1" and the rest along with "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. Do you have those variables defined register asm to tell the compiler about that, eg register int d0_fcode asm("d0"); ? Otherwise it could for instance choose d4 for the d0_fcode operand. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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