]> git.saurik.com Git - apple/libc.git/blob - arm/sys/OSAtomic_resolvers.c
28ad04fae96a6eb6776b3ff5138aefb230cfc43c
[apple/libc.git] / arm / sys / OSAtomic_resolvers.c
1 /*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * This holds the C versions of OSAtomic.s resolver functions, used by
26 * everyone except dyld.
27 */
28
29 #include <arm/arch.h>
30 #if defined(_ARM_ARCH_7)
31
32 #include <stdlib.h>
33 #include <machine/cpu_capabilities.h>
34 #include <mach/machine.h>
35
36 #if defined(VARIANT_DYLD)
37
38 #define _STRDEF(x) __STRING(x)
39
40 #define makeResolver_up_mp(name) \
41 void* name ## $VARIANT$up(void); \
42 void* name ## $VARIANT$mp(void); \
43 void* name ## Resolver(void) __asm__( "_" #name ); \
44 void* name ## Resolver(void) { \
45 __asm__ __volatile__ ( \
46 "ldr ip, L" #name "$commpage ;" \
47 "ldr ip, [ip] ;" \
48 "tst ip, $(" _STRDEF(kUP) ") ;" \
49 "bne 1f ; " \
50 "b _" __STRING(name) "$VARIANT$mp ;" \
51 "1: b _" __STRING(name) "$VARIANT$up ;" \
52 "L" #name "$commpage: .long " _STRDEF(_COMM_PAGE_CPU_CAPABILITIES) " ;" \
53 : : : ); \
54 }
55
56 #define makeResolver_up_mp_wfe(name) makeResolver_up_mp(name)
57
58 #else
59
60 #define makeResolver_up_mp(name) \
61 void name ## $VARIANT$up(void); \
62 void name ## $VARIANT$mp(void); \
63 void* name ## Resolver(void) __asm__( "_" #name ) ; \
64 void* name ## Resolver(void) { \
65 __asm__(".symbol_resolver _" #name); \
66 /* return MP variant functions on kNumCPUs > 1 */ \
67 if ((*(uint32_t*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES & kUP) == 0) { \
68 return name ## $VARIANT$mp; \
69 } \
70 return name ## $VARIANT$up; \
71 }
72
73 #define makeResolver_up_mp_wfe(name) \
74 void name ## $VARIANT$up(void); \
75 void name ## $VARIANT$mp(void); \
76 void name ## $VARIANT$wfe(void); \
77 void* name ## Resolver(void) __asm__( "_" #name ) ; \
78 void* name ## Resolver(void) { \
79 __asm__(".symbol_resolver _" #name); \
80 uint32_t caps = *(uint32_t*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES; \
81 /* return WFE variant if we will get woken up */ \
82 if ((caps & (kHasEvent | kUP)) == kHasEvent) { \
83 return name ## $VARIANT$wfe; \
84 } \
85 /* return MP variant functions on kNumCPUs > 1 */ \
86 else if ((caps & kUP) == 0) { \
87 return name ## $VARIANT$mp; \
88 } \
89 return name ## $VARIANT$up; \
90 }
91
92 #endif // defined VARIANT_DYLD
93
94 #include "OSAtomic_resolvers.h"
95
96 #else // defined _ARM_ARCH_7
97
98 typedef int emptyFilesArentCFiles;
99
100 #endif // defined _ARM_ARCH_7 && !defined VARIANT_DYLD