public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/50457] New: SH2A atomic functions
@ 2011-09-19 17:40 philip.stearns.andtr at gmail dot com
  2012-02-26 23:19 ` [Bug target/50457] " olegendo at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: philip.stearns.andtr at gmail dot com @ 2011-09-19 17:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50457

             Bug #: 50457
           Summary: SH2A atomic functions
    Classification: Unclassified
           Product: gcc
           Version: 4.3.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: philip.stearns.andtr@gmail.com


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:

#define ATOMIC_FETCH_AND_OP(OP,N,T) \
    .global    __sync_fetch_and_##OP##_##N; \
    HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
    .align    2; \
__sync_fetch_and_##OP##_##N:; \
    mova    1f, r0; \
    mov    r15, r1; \
    mov    #(0f-1f), r15; \ <<< SP modification
0:    mov.##T    @r4, r2; \
    OP    r2, r5; \
    mov.##T    r5, @r4; \
1:    mov    r1, r15; \ <<< SP modification
    rts; \
     mov    r2, r0; \
    ENDFUNC(__sync_fetch_and_##OP##_##N)

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. Replacing the SP modifying
code with direct interrupt disabling/enabling resolves the problem and the
application no longer crashes:

#define ATOMIC_FETCH_AND_OP(OP,N,T,EXT) \
    .global    __sync_fetch_and_##OP##_##N; \
    HIDDEN_FUNC(__sync_fetch_and_##OP##_##N); \
    .align    2; \
__sync_fetch_and_##OP##_##N:; \
    stc    sr, r0; \
    mov    r0, r1; \
    or    #0xf0, r0; \
    ldc    r0, sr; \ <<< interrupt disable
    mov.##T    @r4, r2; \
    OP    r2, r5; \
    mov.##T    r5, @r4; \
    ldc    r1, sr; \ <<< interrupt restore
    rts; \
     EXT    r2, r0; \
    ENDFUNC(__sync_fetch_and_##OP##_##N)


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-09-21  1:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-19 17:40 [Bug target/50457] New: SH2A atomic functions philip.stearns.andtr at gmail dot com
2012-02-26 23:19 ` [Bug target/50457] " olegendo at gcc dot gnu.org
2012-02-26 23:27 ` olegendo at gcc dot gnu.org
2012-09-24 14:20 ` olegendo at gcc dot gnu.org
2012-09-25  0:53 ` kkojima at gcc dot gnu.org
2012-09-25 10:54 ` olegendo at gcc dot gnu.org
2012-09-25 11:33 ` kkojima at gcc dot gnu.org
2012-10-01  8:34 ` olegendo at gcc dot gnu.org
2012-10-01 13:50 ` olegendo at gcc dot gnu.org
2012-10-01 23:30 ` kkojima at gcc dot gnu.org
2012-10-01 23:39 ` olegendo at gcc dot gnu.org
2012-10-02  0:55 ` olegendo at gcc dot gnu.org
2012-10-02  2:18 ` kkojima at gcc dot gnu.org
2012-10-02 10:58 ` olegendo at gcc dot gnu.org
2012-10-03 21:36 ` olegendo at gcc dot gnu.org
2012-10-08  0:21 ` olegendo at gcc dot gnu.org
2012-11-12 20:57 ` olegendo at gcc dot gnu.org
2015-09-21  1:54 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).