Using codewarrior 6.3 professional edition on a PCF52235, I've noticed (in several cases) that the compiler generates asm for code similar to the example in the following manor:
MyClass::Alloc(int size)
{
if (size)
{
m_buffer = calloc1(size);
XXXXXXX1: 202E0014 move.l 20(a6),d0
XXXXXXX2: 2E80 move.l d0,(a7)
XXXXXXX3: 4EB90000DC1C jsr calloc1 (0xdc1c)
XXXXXXX4: 2D40FFFC move.l d0,-4(a6)
XXXXXXX5: 202EFFFC move.l -4(a6),d0
XXXXXXX6: 2D40FFF0 move.l d0,-16(a6)
XXXXXXX7: 206E0008 movea.l 8(a6),a0
XXXXXXX8: 202EFFF0 move.l -16(a6),d0
XXXXXXX9: 21400004 move.l d0,4(a0)
}
}
I'm not sure why I see the return from calloc1 being put into -4(a6) and -16(a6), and most of the time I wouldn't worry about it, but in some cases when this happens, there were less than 16 bytes alloced on the frame at the beginning of the method (link a6,#0; lea -8(a7),a7; ...). So, if an interrupt fires between 'move.l d0,-16(a6)' and 'move.l -16(a6),d0', -16(a6) gets corrupted and m_buffer ends up with an illegal address.
Additionally, I am running into another problem with these instructions. Even with interrupts disabled and more than 16 bytes alloced for the frame, -16(a6) is still corrupted in some cases (but repeatable) when the processor is allowed to execute the instuctions without breaks in between. For example, under the following scenario, -16(a6) is corrupted:
1. Set break points at lines 4 and 9 from above
2. Once the break point at 4 is hit, let the processor run
3. When the break point at 9 is hit, -4(a6) has the correct value for d0 in it, but -16(a6) does not (always ends up with the same incorrect value)
But if I step through each line between 4 and 9, when 9 is reached, both -4(a6) and -16(a6) have the correct value in them.
Any Ideas?