If I flush the branch cache in the kernel thread dispatcher, the problem seems to disappear (or happen so seldom
I cannot detect it, although I cannot detect it directly by stepping thru code, and I cannot get any bus error to detect this so I
cannot trace exactly what happens, it has taken almost two weeks to find this problem as I initially assumed that it was a code bug.)
from my disassembly I have this generated by gcc
loop:
jsr (a3)
jsr (a2)
addq.l #4,sp
bra loop
a3 points to the semaphore wait command
a2 points to something that executes every time I get a semaphore signal.
The pop is for the semaphore wait, but has been deferred.
When this code executes there seem to be a flexbus read at the address pointed to by a2 in another thread!
If I put just a trapf between the jsr instructions the problem goes away.
I have a memory mapped external peripheral (a DSP) and if a2 for some reason would point to its memory,
it would be really bad. 