Pass a struct by value on MAXQ30E
We have some code that looks basically like this:
typedef struct COMPLEX
{
int re;
int im;
} Complex;
Complex val1, val2;
int func(Complex x) {...}
value= func(val1) - func(val2);
The compiler appears to use a little scratchpad area of memory where it stores the input args, 8 bytes in size. Inside the function, DP[0] is used to reference this scratchpad. We have another variable, "pi", that happens to be located by the linker at the first addressable word in RAM.
Usually this works fine, but occasionally the value for pi is overwritten with the contents of the second word of the struct. If we protect the function call by disabling interrupts, the memory location is never overwritten.
So it seems that somehow DP is sometimes set to the wrong value by an interrupt handler, such that it's pointing to the wrong memory location. Yet the interrupt handlers all save and restore registers that can get changed, including DP. This overwriting happens whether register shadowing is enabled or not.
The documentation for the MAXQ30 says that function arguments are passed either in registers or on the stack, but they are not in this case.
So, is passing structs by value supported on the MAXQ30?
Please sign in to leave a comment.
Comments
0 comments