1

I am porting some code from that originally compiles with a GCC 3 series compiler for the NIOS2 architecture. Porting it to GCC 4.8.2. I get errors: "error: matching constraint references invalid operand number" from a lot of inline asm code.

The errors are coming from the input-line of the inline asm (after second colon). I've tried searching and have not managed to find what kind of register 'D' refers to (does not seem to be a standard constraint, nor is it listed as an architecture specific one for NIOS2). The errors refer to the numbers but am even more confused about the numbers and what they refer to, I know they are called matching constraints and are related to matching the instruction operands but trap does not have any operands...? I can make the errors disappear if I change the number to range from 1-4 in this case but I need to understand what it does and what has changed in GCC. I read all the migration guides for all the intermediate versions and didn't see anything related.

Edit: Also not sure what the "callno" refers to.

#define POS_SYSCALL(R,N,P,A,B)                                          \
    __asm__ volatile ("trap\n"                                          \
                      : "=r"(R), "=r"(N), "=r"(P), "=r"(A), "=r"(B)     \
                      : [callno]"D04"(N), "D05"(P), "D06"(A), "D07"(B)  \
                      : "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "memory");

__inline__
int syscall(int callnr, int param, void * a, void * b)
{
    register int result __asm__("r2");
    register int arg0 __asm__("r5") = (int)param;
    register void * arga __asm__("r6") = a;
    register void * argb __asm__("r7") = b;
    POS_SYSCALL(result, callnr, arg0, arga, argb);
    return result;
}
Dago
  • 1,349
  • 1
  • 11
  • 19
  • Well, I can tell you what the `callno` thing refers to. Looking at the [docs](https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands), you can assign symbolic names to the operands. This would allow you to use `%[callno]` in the asm template instead of `%5`. In this case, it serves as little more than a comment. Looking thru the [machine constraints](https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html) for *Nios II family*, I don't see `D` listed as a valid constraint, so I'm not sure what this is doing. – David Wohlferd Oct 09 '17 at 06:53
  • Logically it must (somehow) be defining exactly which register to put the value into. The call number can't just go in 'any available' register. The `trap` is expecting it in a specific place. Looking at the docs for `trap` on nios may give you some clues here. – David Wohlferd Oct 09 '17 at 07:00
  • So at a guess, it's saying "on input: r4=N, r5=P r6=A r7=B" and "on output: R=r2, N=?, P=r5, A=r6, B=r7". N is probably some unknown (but potentially changed from input) value. But I know zero about NIOS, so take this with a lot of salt. – David Wohlferd Oct 09 '17 at 07:09

0 Answers0