Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM7TDMI does not support requested special purpose register

Tags:

gcc

assembly

arm

I need to convert some code compiled with ARMASM to gcc(code sourcery GCC-4.6.2 eabi). I use a ARM7TDMI and my compilations arguments are

arm-none-eabi-gcc -c -march=armv4t -mcpu=arm7tdmi -mlittle-endian -g -O1 

(I omitted the -I and -D arguments...)

In one of my files I have this code that won't compile :

extern inline void ngEnable( void)
{
    int tmp;
    asm volatile(
        "msr %[tmp], CPSR\n\t"
        "bic %[tmp], %[tmp], #0xC0\n\t"
        "msr CPSR_c, %[tmp]"
        : [tmp] "+r" (tmp)
    );
}

I get this error :

C:\DOCUME~1\MALLAR~1.ISC\LOCALS~1\Temp\ccA9cCgQ.s: Assembler messages:
C:\DOCUME~1\MALLAR~1.ISC\LOCALS~1\Temp\ccA9cCgQ.s:267: Error: selected processor does not support requested special purpose register -- `msr r3,CPSR'
make: *** [cdbini.o] Error 1

according to this post Re: trouble building linux-linaro-3.0-2011.08-0 (I build on windows, but the problem could be the same?) I'm already using the workaround of not using -march=all...

Any idea of what my problem is?

like image 373
Martin Allard Avatar asked Dec 15 '25 16:12

Martin Allard


1 Answers

To read a special purpose register, you should use the mrs instruction:

extern inline void ngEnable(void)
{
  int tmp;
  asm volatile(
    "mrs %[tmp], CPSR\n\t"
    "bic %[tmp], %[tmp], #0xC0\n\t"
    "msr CPSR_c, %[tmp]"
    : [tmp] "=r" (tmp)
  );
}

After this fix, the code works for me just fine.

Also, since you don't use the value of tmp, and you don't in fact even set it, you should use =r (output only) instead of +r (input-output).


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!