2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <sys/appleapiopts.h>
32 #include <machine/cpu_capabilities.h>
33 #include <machine/commpage.h>
36 * We need a relative branch within the comm page, and don't want the linker
37 * to relocate it, so we have to hand-code the instructions. LEN is to account
38 * for the length of a .long, since the jmp is relative to the next instruction.
41 #define JNZ .byte 0x0f, 0x85; .long
42 #define JMP .byte 0xe9; .long
46 * Branch prediction prefixes
49 #define LIKELY .byte 0x3e
50 #define UNLIKELY .byte 0x2e
52 #define MP_SPIN_TRIES 1024
66 COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0)
79 COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP)
81 .set Lrelinquish_off, _COMM_PAGE_RELINQUISH - _COMM_PAGE_SPINLOCK_LOCK
87 .set Lretry, . - Lspin_lock_up
91 JNZ Lrelinquish_off - . + Lspin_lock_up - LEN
94 COMMPAGE_DESCRIPTOR(spin_lock_up,_COMM_PAGE_SPINLOCK_LOCK,kUP,0)
103 cmpxchgl %edx, (%ecx)
109 movl $(MP_SPIN_TRIES), %edx
118 JMP Lrelinquish_off - . + Lspin_lock_mp - LEN
120 COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP)
128 COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0)
131 Lrelinquish: /* relinquish the processor */
133 pushl $1 /* SWITCH_OPTION_DEPRESS */
134 pushl $0 /* THREAD_NULL */
135 pushl $0 /* push dummy stack ret addr */
136 movl $-61, %eax /* syscall_thread_switch */
138 addl $16, %esp /* adjust stack*/
139 xorl %eax, %eax /* set %eax to 0 again */
140 JMP Lretry - Lrelinquish_off - . + Lrelinquish - LEN
142 COMMPAGE_DESCRIPTOR(relinquish,_COMM_PAGE_RELINQUISH,0,0)