[BACK]Return to mutex.S CVS log [TXT][DIR] Up to [local] / sys / arch / m88k / m88k

Annotation of sys/arch/m88k/m88k/mutex.S, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: mutex.S,v 1.4 2007/05/18 16:34:31 miod Exp $  */
                      2:
                      3: /*
                      4:  * Copyright (c) 2005, Miodrag Vallat.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     18:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
                     19:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     20:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     21:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     23:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                     24:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     25:  * POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
                     28: #include "assym.h"
                     29: #if MTX_LOCK != 0
                     30: #error Lack of Humppa in mutex code
                     31: #endif
                     32:
                     33: #include <machine/asm.h>
                     34:
                     35: /*
                     36:  * void mtx_init(struct mutex *mtx, int ipl)
                     37:  */
                     38: ENTRY(mtx_init)
                     39:        st      r0, r2, MTX_LOCK        /* mtx->mtx_lock = 0 */
                     40:        st      r0, r2, MTX_OLDIPL      /* mtx->mtx_oldipl = IPL_NONE */
                     41:        st      r3, r2, MTX_WANTIPL     /* mtx->mtx_wantipl = ipl */
                     42:        jmp.n   r1
                     43:         st     r0, r2, MTX_CPU         /* mtx->mtx_cpu = NULL */
                     44:
                     45: /*
                     46:  * void mtx_enter(struct mutex *mtx)
                     47:  */
                     48: ENTRY(mtx_enter)
                     49:        subu    r31, r31, 8
                     50:        st      r1,  r31, 4             /* save return address */
                     51:
                     52: #ifdef MULTIPROCESSOR
                     53:
                     54:        st      r2,  r31, 0             /* save mtx */
                     55: enter_again:
                     56:        ld      r2,  r2,  MTX_WANTIPL
                     57:        bcnd    eq0, r2,  1f
                     58:        bsr     _C_LABEL(raiseipl)      /* raiseipl(mtx->mtx_wantipl) */
                     59: 1:
                     60:        ld      r4,  r31, 0
                     61:        or      r3,  r0,  1
                     62:        xmem    r3,  r4,  r0            /* attempt to claim the lock, old */
                     63:        bcnd    ne0, r3,  enter_failed  /* mtx->mtx_lock is 0 if successful */
                     64:
                     65:        ldcr    r3,  CPU
                     66:        st      r2,  r4,  MTX_OLDIPL    /* save into mtx_oldipl */
                     67:        st      r3,  r4,  MTX_CPU       /* mtx->mtx_cpu = curcpu() */
                     68:
                     69:        ld      r1,  r31, 4
                     70:        jmp.n   r1
                     71:         addu   r31, r31, 8
                     72:
                     73: enter_failed:  /* the lock is not ours... */
                     74:        ld      r3,  r4,  MTX_WANTIPL
                     75:        bcnd    eq0, r4,  2f
                     76:        bcnd    ne0, r2,  1f            /* splx(oldipl) */
                     77:        bsr.n   _C_LABEL(spl0)
                     78:         addu   r1,  r1,  2f - . - 4
                     79: 1:
                     80:        bsr     _C_LABEL(setipl)
                     81: 2:
                     82:        ld      r2,  r31, 0             /* restore mtx */
                     83: enter_spin:
                     84: #ifdef DIAGNOSTIC
                     85:        ldcr    r3,  CPU
                     86:        ld      r4,  r2,  MTX_CPU
                     87:        cmp     r5,  r3,  r4
                     88:        bcnd    eq0, r5,  enter_panic
                     89: #endif
                     90:        ld      r3,  r2,  MTX_LOCK
                     91:        bcnd    eq0, r3,  enter_again
                     92:        br      enter_spin
                     93:
                     94: #ifdef DIAGNOSTIC
                     95: enter_panic:
                     96:        or.u    r2,  r0,  hi16(9f)
                     97:        bsr.n   _C_LABEL(panic)
                     98:         or     r2,  r2,  lo16(9f)
                     99:
                    100:        data
                    101: 9:
                    102:        string  "mtx_enter: humpaan itsekseni"
                    103: #endif
                    104:
                    105: #else  /* MULTIPROCESSOR */
                    106:
                    107:        st      r2,  r31, 0             /* save mtx */
                    108:        ld      r2,  r2,  MTX_WANTIPL
                    109:        bcnd    eq0, r2,  1f
                    110:        bsr     _C_LABEL(raiseipl)      /* raiseipl(mtx->mtx_wantipl) */
                    111: 1:
                    112:        ld      r4,  r31, 0
                    113:        ldcr    r3,  CPU
                    114:        st      r3,  r4,  MTX_LOCK      /* locked! */
                    115:
                    116:        st      r2,  r4,  MTX_OLDIPL    /* save into mtx_oldipl */
                    117:
                    118: #ifdef DIAGNOSTIC      /* necessary for MUTEX_ASSERT_LOCKED */
                    119:        st      r3,  r4,  MTX_CPU       /* mtx->mtx_cpu = curcpu() */
                    120: #endif
                    121:
                    122:        ld      r1,  r31, 4
                    123:        jmp.n   r1
                    124:         addu   r31, r31, 8
                    125:
                    126: #endif /* MULTIPROCESSOR */
                    127:
                    128: /*
                    129:  * void mtx_leave(struct mutex *mtx)
                    130:  */
                    131: ENTRY(mtx_leave)
                    132:        ld      r3,  r2,  MTX_OLDIPL
                    133:        ld      r4,  r2,  MTX_WANTIPL
                    134:        st      r0,  r2,  MTX_CPU               /* mtx->mtx_cpu = NULL */
                    135:        bcnd.n  eq0, r4,  2f
                    136:         st     r0,  r2,  MTX_LOCK              /* mtx->mtx_lock = 0 */
                    137:
                    138:        bcnd    ne0, r3,  1f                    /* splx(mtx->mtx_oldipl) */
                    139:        br      _C_LABEL(spl0)
                    140: 1:
                    141:        br.n    _C_LABEL(setipl)
                    142:         or     r2,  r3,  r0
                    143: 2:
                    144:        jmp     r1

CVSweb