Annotation of src/sys/arch/vax/vax/lock_stubs.S, Revision 1.6.2.2
1.6.2.2 ! mjf 1: /* $NetBSD: lock_stubs.S,v 1.10 2008/02/13 18:42:36 matt Exp $ */
1.1 matt 2:
3: /*-
4: * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
8: * by Jason R. Thorpe and Andrew Doran.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the NetBSD
21: * Foundation, Inc. and its contributors.
22: * 4. Neither the name of The NetBSD Foundation nor the names of its
23: * contributors may be used to endorse or promote products derived
24: * from this software without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: * POSSIBILITY OF SUCH DAMAGE.
37: */
38:
1.3 matt 39: #include "opt_lockdebug.h"
1.1 matt 40: #include "opt_multiprocessor.h"
41: #include <machine/asm.h>
42: #include "assym.h"
43:
1.3 matt 44: #ifndef LOCKDEBUG
1.1 matt 45: /*
46: * void mutex_enter(kmutex_t *);
47: *
48: *
49: */
50: NENTRY(mutex_enter, 0)
51: movl 4(%ap), %r0 /* get mutex */
52: bbssi $31, (%r0), 1f /* is there an owner? */
53: mfpr $PR_SSP, %r1 /* Note, get curcpu */
54: movl CI_CURLWP(%r1),(%r0) /* set owner to curlwp */
55: ret /* and return */
56: 1:
57: callg (%ap), _C_LABEL(mutex_vector_enter)
58: /* there is an owner */
59: /* so go slow */
60: ret
61:
62:
63:
64: /*
65: * void mutex_exit(kmutex_t *);
66: */
67: NENTRY(mutex_exit, 0)
68: movl 4(%ap), %r0 /* get mutex */
1.6.2.1 mjf 69: blbs MTX_FLAGS(%r0), 1f /* go slow if this is SPIN */
1.1 matt 70: mfpr $PR_SSP, %r1 /* get curcpu */
71: cmpl (%r0),CI_CURLWP(%r1) /* is the owner still us and */
72: /* no waiters? */
1.3 matt 73: bneq 1f /* no, slow path */
1.2 matt 74: clrl (%r0) /* clear owner */
1.3 matt 75: ret
1.1 matt 76:
77: 1: callg (%ap), _C_LABEL(mutex_vector_exit)
78: ret
79:
80: /*
81: * void mutex_spin_enter(kmutex_t *);
82: */
83: NENTRY(mutex_spin_enter, 0)
84: movl 4(%ap), %r0 /* get spin mutex */
85: #ifdef DIAGNOSTIC
1.6.2.1 mjf 86: blbc MTX_FLAGS(%r0), 3f
1.1 matt 87: #endif
88: mfpr $PR_IPL, %r2 /* get current IPL */
1.3 matt 89: movzbl MTX_IPL(%r0), %r3
90: cmpl %r3, %r2 /* does mutex have > IPL? */
1.1 matt 91: bleq 1f /* no, leave IPL alone */
1.3 matt 92: mtpr %r3, $PR_IPL /* yes, raise IPL */
1.2 matt 93: 1: mfpr $PR_SSP, %r1 /* get curcpu */
1.3 matt 94: sobgeq CI_MTX_COUNT(%r1), 2f /* decr mutex count */
1.4 matt 95: brb 3f
96: 2: movl %r2, CI_MTX_OLDSPL(%r1) /* save was-current IPL */
1.5 yamt 97: 3:
1.1 matt 98: #if defined(DIAGNOSTIC) || defined(MULTIPROCESSOR)
1.4 matt 99: bbssi $0, (%r0), 4f /* take out mutex */
1.1 matt 100: ret
1.4 matt 101: 4: callg (%ap), _C_LABEL(mutex_spin_retry) /* slow path */
1.1 matt 102: #endif
103: ret
104:
105: /*
106: * void mutex_spin_exit(kmutex_t *);
107: */
108: NENTRY(mutex_spin_exit, 0)
109: movl 4(%ap), %r0 /* get spin mutex */
110: #ifdef DIAGNOSTIC
1.6.2.1 mjf 111: blbc MTX_FLAGS(%r0), 2f /* assert this is a spinlock */
1.1 matt 112: #endif
113: #if defined(DIAGNOSTIC) || defined(MULTIPROCESSOR)
114: bbcci $0, (%r0), 2f /* clear mutex */
115: #endif
116: mfpr $PR_SSP, %r1 /* get curcpu */
117: movl CI_MTX_OLDSPL(%r1), %r2 /* fetch oldspl */
1.3 matt 118: aoblss $MTX_COUNT_BIAS, CI_MTX_COUNT(%r1), 1f /* incr mtx count */
1.1 matt 119: mtpr %r2, $PR_IPL /* yes, restore saved ipl */
120: 1: ret
121:
122: #if defined(DIAGNOSTIC) || defined(MULTIPROCESSOR)
123: 2: callg (%ap), _C_LABEL(mutex_vector_exit) /* slow path */
124: ret
125: #endif
1.2 matt 126:
1.3 matt 127: #endif /* LOCKDEBUG */
128:
1.6.2.2 ! mjf 129: .section .bss
! 130: .p2align 2
! 131: .lcomm cashash,256
1.2 matt 132: /*
1.6.2.2 ! mjf 133: *
! 134: */
! 135: NENTRY(_atomic_cas_32, 0)
! 136: movq 4(%ap), %r1 /* cache ptr, old */
! 137: movl (%r1), %r0 /* get value */
! 138: cmpl %r0, %r2 /* does it equal old? */
! 139: bneq 4f /* nope, return */
! 140: /*
! 141: * Lock everyone out on this cpu.
! 142: */
! 143: mfpr $PR_IPL, %r5 /* save IPL */
! 144: mtpr $IPL_HIGH, $PR_IPL /* block everything */
! 145: #ifdef MULTIPROCESSOR
! 146: extzv $2,$11,%r1,%r4 /* gets bits 2-12 */
! 147: 1: bbssi %r4,cashash,1b /* is this pos in the hash table set */
! 148: #endif
! 149: movl (%r1), %r0 /* get value again */
! 150: cmpl %r0, %r2 /* does it still equal old? */
1.2 matt 151: bneq 2f /* nope, return */
152: movl 12(%ap),(%r1) /* update rw->rw_owner with new */
1.6.2.2 ! mjf 153: 2:
! 154: #ifdef MULTIPROCESSOR
! 155: bbcci %r4,cashash,3f /* clear this pos in the hash table */
! 156: 3:
! 157: #endif
! 158: mtpr %r5, $PR_IPL /* restore IPL */
! 159: 4:
! 160: ret /* return */
! 161: STRONG_ALIAS(atomic_cas_ptr,_atomic_cas_32)
! 162: STRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32)
! 163: STRONG_ALIAS(atomic_cas_uint,_atomic_cas_32)
! 164: STRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32)
! 165: STRONG_ALIAS(atomic_cas_ulong,_atomic_cas_32)
! 166: STRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32)
! 167: STRONG_ALIAS(atomic_cas_32,_atomic_cas_32)
! 168:
! 169: STRONG_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32)
! 170: STRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32)
! 171: STRONG_ALIAS(atomic_cas_uint_ni,_atomic_cas_32)
! 172: STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32)
! 173: STRONG_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32)
! 174: STRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32)
! 175: STRONG_ALIAS(atomic_cas_32_ni,_atomic_cas_32)
! 176: STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32)
CVSweb <webmaster@jp.NetBSD.org>