2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/appleapiopts.h>
24 #include <machine/cpu_capabilities.h>
25 #include <machine/commpage.h>
28 * We need a relative branch within the comm page, and don't want the linker
29 * to relocate it, so we have to hand-code the instructions. LEN is to account
30 * for the length of a .long, since the jmp is relative to the next instruction.
33 #define JNZ .byte 0x0f, 0x85; .long
34 #define JMP .byte 0xe9; .long
38 * Branch prediction prefixes
41 #define LIKELY .byte 0x3e
42 #define UNLIKELY .byte 0x2e
44 #define MP_SPIN_TRIES 1024
58 COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0)
71 COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP)
73 .set Lrelinquish_off, _COMM_PAGE_RELINQUISH - _COMM_PAGE_SPINLOCK_LOCK
79 .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)
101 movl $(MP_SPIN_TRIES), %edx
110 JMP Lrelinquish_off - . + Lspin_lock_mp - LEN
112 COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP)
120 COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0)
123 Lrelinquish: /* relinquish the processor */
125 pushl $1 /* SWITCH_OPTION_DEPRESS */
126 pushl $0 /* THREAD_NULL */
127 pushl $0 /* push dummy stack ret addr */
128 movl $-61, %eax /* syscall_thread_switch */
130 addl $16, %esp /* adjust stack*/
131 xorl %eax, %eax /* set %eax to 0 again */
132 JMP Lretry - Lrelinquish_off - . + Lrelinquish - LEN
134 COMMPAGE_DESCRIPTOR(relinquish,_COMM_PAGE_RELINQUISH,0,0)