]> git.saurik.com Git - apple/libc.git/blame - i386/sys/spinlocks_asm.s
Libc-825.40.1.tar.gz
[apple/libc.git] / i386 / sys / spinlocks_asm.s
CommitLineData
1f2f436a
A
1/*
2 * Copyright (c) 2003-2009 Apple, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#include <sys/appleapiopts.h>
30#include <machine/cpu_capabilities.h>
31#include <platfunc.h>
32#include <mach/i386/syscall_sw.h>
33
34
35PLATFUNC_FUNCTION_START(OSSpinLockTry, up, 32, 4)
36PLATFUNC_FUNCTION_START(_spin_lock_try, up, 32, 4)
37 movl 4(%esp), %ecx
38 xorl %eax, %eax
39 orl $-1, %edx
40 cmpxchgl %edx, (%ecx)
41 setz %dl
42 movzbl %dl, %eax
43 ret
44PLATFUNC_DESCRIPTOR(OSSpinLockTry,up,kUP,0)
45PLATFUNC_DESCRIPTOR(_spin_lock_try,up,kUP,0)
46
47PLATFUNC_FUNCTION_START_GENERIC(OSSpinLockTry, mp, 32, 4)
48PLATFUNC_FUNCTION_START_GENERIC(_spin_lock_try, mp, 32, 4)
49 movl 4(%esp), %ecx
50 xorl %eax, %eax
51 orl $-1, %edx
52 lock
53 cmpxchgl %edx, (%ecx)
54 setz %dl
55 movzbl %dl, %eax
56 ret
57PLATFUNC_DESCRIPTOR(OSSpinLockTry,mp,0,kUP)
58PLATFUNC_DESCRIPTOR(_spin_lock_try,mp,0,kUP)
59
60
61PLATFUNC_FUNCTION_START(spin_lock, up, 32, 4)
62PLATFUNC_FUNCTION_START(OSSpinLockLock, up, 32, 4)
63PLATFUNC_FUNCTION_START(_spin_lock, up, 32, 4)
64Lspin_lock_up:
65 movl 4(%esp), %ecx
66 xorl %eax, %eax
67 orl $-1, %edx
68 cmpxchgl %edx, (%ecx)
69 jnz 1f
70 ret
711:
72 /* failed to get lock so relinquish the processor immediately on UP */
73 pushl $1 /* 1 ms */
74 pushl $1 /* SWITCH_OPTION_DEPRESS */
75 pushl $0 /* THREAD_NULL */
76 pushl $0 /* push dummy stack ret addr */
77 movl $-61,%eax /* SYSCALL_THREAD_SWITCH */
78 int $(MACH_INT)
79 addl $16, %esp /* adjust stack*/
80 jmp Lspin_lock_up
81PLATFUNC_DESCRIPTOR(spin_lock,up,kUP,0)
82PLATFUNC_DESCRIPTOR(OSSpinLockLock,up,kUP,0)
83PLATFUNC_DESCRIPTOR(_spin_lock,up,kUP,0)
84
85PLATFUNC_FUNCTION_START_GENERIC(spin_lock, mp, 32, 4)
86PLATFUNC_FUNCTION_START_GENERIC(OSSpinLockLock, mp, 32, 4)
87PLATFUNC_FUNCTION_START_GENERIC(_spin_lock, mp, 32, 4)
88Lspin_lock_mp:
89 movl 4(%esp), %ecx
90 xorl %eax, %eax
910:
92 orl $-1, %edx
93 lock
94 cmpxchgl %edx, (%ecx)
95 jnz 1f
96 ret
971:
98 xorl %eax, %eax
99 movl $(MP_SPIN_TRIES), %edx
1002:
101 pause
102 cmpl %eax, (%ecx)
103 jz 0b /* favor success and slow down spin loop */
104 decl %edx
105 jnz 2b
106 /* failed to get lock after spinning so relinquish */
107 pushl $1 /* 1 ms */
108 pushl $1 /* SWITCH_OPTION_DEPRESS */
109 pushl $0 /* THREAD_NULL */
110 pushl $0 /* push dummy stack ret addr */
111 movl $-61,%eax /* SYSCALL_THREAD_SWITCH */
112 int $(MACH_INT)
113 addl $16, %esp /* adjust stack*/
114 jmp Lspin_lock_mp
115PLATFUNC_DESCRIPTOR(spin_lock,mp,0,kUP)
116PLATFUNC_DESCRIPTOR(OSSpinLockLock,mp,0,kUP)
117PLATFUNC_DESCRIPTOR(_spin_lock,mp,0,kUP)
118
119 .align 2, 0x90
120 .globl _OSSpinLockUnlock
121 .globl _spin_unlock
122 .globl __spin_unlock
123_OSSpinLockUnlock:
124_spin_unlock:
125__spin_unlock:
126 movl 4(%esp), %eax
127 movl $0, (%eax)
128 ret
129