2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 #include <sys/appleapiopts.h>
27 #include <machine/cpu_capabilities.h>
28 #include <machine/commpage.h>
31 * We need a relative branch within the comm page, and don't want the linker
32 * to relocate it, so we have to hand-code the instructions. LEN is to account
33 * for the length of a .long, since the jmp is relative to the next instruction.
36 #define JNZ .byte 0x0f, 0x85; .long
37 #define JMP .byte 0xe9; .long
41 * Branch prediction prefixes
44 #define LIKELY .byte 0x3e
45 #define UNLIKELY .byte 0x2e
47 #define MP_SPIN_TRIES 1024
60 COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0)
72 COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP)
74 .set Lrelinquish_off, _COMM_PAGE_RELINQUISH - _COMM_PAGE_SPINLOCK_LOCK
80 .set Lretry, . - Lspin_lock_up
83 JNZ Lrelinquish_off - . + Lspin_lock_up - LEN
86 COMMPAGE_DESCRIPTOR(spin_lock_up,_COMM_PAGE_SPINLOCK_LOCK,kUP,0)
100 movl $(MP_SPIN_TRIES), %edx
109 JMP Lrelinquish_off - . + Lspin_lock_mp - LEN
111 COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP)
119 COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0)
122 Lrelinquish: /* relinquish the processor */
124 pushl $1 /* SWITCH_OPTION_DEPRESS */
125 pushl $0 /* THREAD_NULL */
126 movl $-61, %eax /* syscall_thread_switch */
128 popl %eax /* set %eax to 0 again */
129 popl %edx /* use %edx as scratch */
130 popl %edx /* reg to fixup stack */
131 JMP Lretry - Lrelinquish_off - . + Lrelinquish - LEN
133 COMMPAGE_DESCRIPTOR(relinquish,_COMM_PAGE_RELINQUISH,0,0)