Search code examples
arminline-assemblyneon

How to read/write FPSCR on Cortex-A9?


I'm working on a ARM Cortex-A9 based system running software that uses nested interrupts; however, the method for implementing nested interrupts seems to be flawed as floating-point values and operations can get corrupted.

To mitigate this I'm trying to save the states of the floating-point registers when entering an interrupting routine. The method I'm trying for FPSCR is this:

asm ("VMRS %0, FPSCR " : "=r" ( savedReg)); //Save

asm ("VMSR FPSCR, %0 " : "=r" ( savedReg)); //Restore

The read seems to work but not the write, it causes the A9 to reboot.

Is it possible to access the FPSCR in this way? What other method is recomended?


Solution

  • You are writing an undefined value to FPSCR and savedReg. You want:

    asm volatile ("VMSR FPSCR, %0 " : : "r" ( savedReg)); //Restore
    

    Also there is no guarantee that the floating point operations stay between the inline assembler (though volatile and "memory" may help), use standalone assembler.