Compiler is C30 v3.12 (I know there are later versions, but this is the one I have to use)
Compiler options set in Build options->alternate settings. I am compiling with and without the psv_trap bit.
-g -Wall -O1 -c -save-temps -merrata=psv_trap
The build output window shows the option is correctly applied:
Make: The target "C:\Work\POWER_TILE\SourceToObject\SSPM - Without Compiler Options\PSV_Test.o" is out of date.
Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33FJ128GP206 -x c -c "source\PSV_Test.c" -o"PSV_Test.o" -g -Wall -O1 -c -save-temps -merrata=psv_trap
The assembler output is shown below. I don't get mov.d or a mov[--w0] or similar so I think the issue is my C code construction
.
int PSV_Test_Workaround(int x)
{
int result = 0;
CORCONbits.PSV = 1; // ensure that PSV is enabled
0: 00 40 a8 bset.b 0x0, #0x2
PSVPAG = __builtin_psvpage(&foo); // set the PSVPAG correctly
2: 01 00 20 mov.w #0x0, w1
4: 80 00 fd exch w0, w1
6: 00 e0 b7 mov.b WREG, 0x0
8: 80 00 fd exch w0, w1
// for accessing foo
if (foo[--x] == 9) // Access with pre-decrement
a: 00 00 40 add.w w0, w0, w0
c: 00 80 e9 dec2.w w0, w0
e: 01 00 20 mov.w #0x0, w1
10: 60 80 78 mov.w [w0+w1], w0
12: e9 0f 50 sub.w w0, #0x9, [w15]
14: 00 00 3a bra NZ, 0x16
{
result = bar; // we know bar is in the same
16: 00 00 80 mov.w 0x0, w0
18: 00 00 37 bra 0x1a <.L2>
0000001a <.L2>:
// PSV page as foo
}
else
{
result = (long)foo[0]; // Access with mov.d
1a: 00 00 80 mov.w 0x0, w0
0000001c <.L4>:
}
return(result);
} /* end PSV_Test_Workaround */