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
57 COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0)
69 COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP)
71 .set Lrelinquish_off, _COMM_PAGE_RELINQUISH - _COMM_PAGE_SPINLOCK_LOCK
77 .set Lretry, . - Lspin_lock_up
80 JNZ Lrelinquish_off - . + Lspin_lock_up - LEN
83 COMMPAGE_DESCRIPTOR(spin_lock_up,_COMM_PAGE_SPINLOCK_LOCK,kUP,0)
97 movl $(MP_SPIN_TRIES), %edx
106 JMP Lrelinquish_off - . + Lspin_lock_mp - LEN
108 COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP)
116 COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0)
119 Lrelinquish: /* relinquish the processor */
121 pushl $1 /* SWITCH_OPTION_DEPRESS */
122 pushl $0 /* THREAD_NULL */
123 movl $-61, %eax /* syscall_thread_switch */
125 popl %eax /* set %eax to 0 again */
126 popl %edx /* use %edx as scratch */
127 popl %edx /* reg to fixup stack */
128 JMP Lretry - Lrelinquish_off - . + Lrelinquish - LEN
130 COMMPAGE_DESCRIPTOR(relinquish,_COMM_PAGE_RELINQUISH,0,0)