This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM46L430: Using floating point registers in IRQ and FIQ (RM46)

Part Number: RM46L430

Hi,

if I am using FP calculations in FIQ and IRQ and the FIQ interrupts the IRQ, I get wrong comparisons.
Say I have the following instructions in IRQ:

VCMPE.F32	s16,s17
VMRS		APSR_nzcv,FPSCR

Do I only have to save the registers s0-s31 or do I have to save the register FPSCR, too?

I would use this code to get around my problem:

;start of FIQ routine
VPUSH	{s0-s15}
VPUSH	{s16-s31}

;FP calculations in FIQ

VPOP	{s16-s31}
VPOP	{s0-s15}
;end of FIQ routine

Will this work?

Thanks!

  • Hi Falk,

    If you don't save those registers, you may get error after back to main code from the IRQ/FIQ ISR if the previous value in those registers are needed. I don't understand why you get error (FPSCR flag) in the ISR?

  • Hi!

    I managed to fix the problem with this asm file:

    	AREA SVC_Area, CODE, READONLY
        PRESERVE8
    
    	export	_saveVfp
    	export	_loadVfp
    		
    _saveVfp
    
    	VMRS    r0, FPSCR
    	PUSH	{r0}
    	VPUSH	{s0-s15}
    	VPUSH	{s16-s31}
    	
    	bx    	lr
    	
    _loadVfp
    
    	VPOP	{s16-s31}
    	VPOP	{s0-s15}
    	POP		{r0}
    	VMSR    FPSCR, r0
    	
    	bx    lr
    	
    	END

    Inside an interrupt, which uses float, I call "_saveVfp()" at the beginning and "_loadVfp()" at the end.
    It works, but is there a more simple solution?

    Regards,

    Falk

  • Hello Falk,

    Thanks for posting your solution. They look good.

    IF the VFP is enabled and floating point is used, the calling function should save S0~S15 of the VFP registers when it calls the ISR and restore them when the program exits the ISR. The other registers (S16~S31, and FPSCR ) are not preserved before the ISR call, the calling function must save them if their values need to be preserved.

    I just did a test with RTI compare 0 ISR (IRQ) which contains floating operation. I didn't see the ISR preserve the VFP registers.