http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50457
--- Comment #1 from olegendo at gcc dot gnu.org 2012-02-26 23:07:41 UTC --- (In reply to comment #0) > The SH specific atomic functions don't seem to work properly with the SH2A > processor. An example function from the gcc/config/sh/linux-atomic.asm is as > follows: > > [...] > > Functions following this style cause the application to eventually crash. I > think this may be related to the locking mechanism around the instructions > making use of an on-board MMU, since the SP is loaded with a negative value. > As the SH2A does not have an MMU this poses a problem. This is the default GNU/Linux gUSA ABI, which signals the 'in atomic sequence' condition with a negative SP in the range somewhere between -128...-1. The interrupt/exception handling code must check for this condition before transferring control to some other execution context (other thread or direct interrupt handler). Please notice that starting with GCC 4.7 the atomic sequence implementation has changed and now has to be enabled with the -msoft-atomics option. For a slightly more detailed description of the machinery please see the comments in gcc/config/sh/sync.md. > Replacing the SP modifying > code with direct interrupt disabling/enabling resolves the problem and the > application no longer crashes: > > [...] While flipping interrupts on/off might fix the problem it is not recommended to do so because of performance reasons (slower code on average, increased interrupt latency etc). It is better and easier to fix the interrupt/exception handling code instead.