Page 1 of 1

Pic32 Code generation error

Posted: 11 Jul 2022 21:32
by mlanesmith
In this ISR pre-amble, the compiler does not move the stack pointer far enough, and ends up corrupting the TOS word with a word from the FPU, causing a crash in the interrupted program where TOS often holds a return address:

;dyn_serial.c, 329 :: void DYNRX_ISR_Handler() iv DYN_IVT_RX ilevel DYN_IRQ_PRIO ics ICS_SRS {
0x9D01791C 0x415DE800 RDPGPR SP, SP
0x9D017920 0x27BDFFE8 ADDIU SP, SP, -24
0x9D017924 0x401E7000 MFC0 R30, 14, 0
0x9D017928 0xAFBE0004 SW R30, 4(SP)
0x9D01792C 0x401E6000 MFC0 R30, 12, 0
0x9D017930 0xAFBE0000 SW R30, 0(SP)
0x9D017934 0x7C1E7844 INS R30, R0, 1, 15
0x9D017938 0x37DE1400 ORI R30, R30, 5120
0x9D01793C 0x409E6000 MTC0 R30, 12, 0
0x9D017940 0xE7A0000C SWC1 S0, 12(SP)
0x9D017944 0x447E0000 MFHC1 R30, S0
0x9D017948 0xAFBE0010 SW R30, 16(SP)
0x9D01794C 0xE7A10014 SWC1 S1, 20(SP)
0x9D017950 0x447E0800 MFHC1 R30, S1
0x9D017954 0xAFBE0018 SW R30, 24(SP)
0x9D017958 0x27BDFFF8 ADDIU SP, SP, -8

I have other ISRs where this error does not occur. Typically, the second line is ADDIU SP, SP, -32

Re: Pic32 Code generation error

Posted: 12 Jul 2022 14:18
by filip
Hi,

Can you please attach minimal project that demonstrates this issue ?

Regards,
Filip.