]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/arm/kern_machdep.c
xnu-6153.141.1.tar.gz
[apple/xnu.git] / bsd / dev / arm / kern_machdep.c
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 */
4 /*
5 * Copyright (C) 1990, NeXT, Inc.
6 *
7 * File: next/kern_machdep.c
8 * Author: John Seamons
9 *
10 * Machine-specific kernel routines.
11 */
12
13 #include <sys/types.h>
14 #include <mach/machine.h>
15 #include <kern/cpu_number.h>
16 #include <machine/exec.h>
17 #include <pexpert/arm64/board_config.h>
18
19 #if __arm64__
20 static cpu_subtype_t cpu_subtype32(void);
21 #endif /* __arm64__ */
22
23 #if __arm64__
24 /*
25 * When an arm64 CPU is executing an arm32 binary, we need to map from the
26 * host's 64-bit subtype to the appropriate 32-bit subtype.
27 */
28 static cpu_subtype_t
29 cpu_subtype32()
30 {
31 switch (cpu_subtype()) {
32 case CPU_SUBTYPE_ARM64_V8:
33 return CPU_SUBTYPE_ARM_V8;
34 default:
35 return 0;
36 }
37 }
38 #endif /* __arm64__*/
39
40 /**********************************************************************
41 * Routine: grade_binary()
42 *
43 * Function: Return a relative preference for exectypes and
44 * execsubtypes in fat executable files. The higher the
45 * grade, the higher the preference. A grade of 0 means
46 * not acceptable.
47 **********************************************************************/
48 int
49 grade_binary(cpu_type_t exectype, cpu_subtype_t execsubtype, bool allow_simulator_binary __unused)
50 {
51 #if __arm64__
52 cpu_subtype_t hostsubtype =
53 (exectype & CPU_ARCH_ABI64) ? cpu_subtype() : cpu_subtype32();
54 #else
55 cpu_subtype_t hostsubtype = cpu_subtype();
56 #endif /* __arm64__ */
57
58 switch (exectype) {
59 #if __arm64__
60 case CPU_TYPE_ARM64:
61 switch (hostsubtype) {
62 case CPU_SUBTYPE_ARM64_V8:
63 switch (execsubtype) {
64 case CPU_SUBTYPE_ARM64_V8:
65 return 10;
66 case CPU_SUBTYPE_ARM64_ALL:
67 return 9;
68 }
69 break;
70
71 } /* switch (hostsubtype) */
72
73 #else /* __arm64__ */
74
75 case CPU_TYPE_ARM:
76 switch (hostsubtype) {
77 /*
78 * For 32-bit ARMv8, try the ARMv8 slice before falling back to Swift.
79 */
80 case CPU_SUBTYPE_ARM_V8:
81 switch (execsubtype) {
82 case CPU_SUBTYPE_ARM_V8:
83 return 7;
84 }
85 goto v7s;
86
87 /*
88 * For Swift and later, we prefer to run a swift slice, but fall back
89 * to v7 as Cortex A9 errata should not apply
90 */
91 v7s:
92 case CPU_SUBTYPE_ARM_V7S:
93 switch (execsubtype) {
94 case CPU_SUBTYPE_ARM_V7S:
95 return 6;
96 }
97 goto v7;
98
99 /*
100 * For Cortex A7, accept v7k only due to differing ABI
101 */
102 case CPU_SUBTYPE_ARM_V7K:
103 switch (execsubtype) {
104 case CPU_SUBTYPE_ARM_V7K:
105 return 6;
106 }
107 break;
108
109 /*
110 * For Cortex A9, we prefer the A9 slice, but will run v7 albeit
111 * under the risk of hitting the NEON load/store errata
112 */
113 case CPU_SUBTYPE_ARM_V7F:
114 switch (execsubtype) {
115 case CPU_SUBTYPE_ARM_V7F:
116 return 6;
117 }
118 goto v7;
119
120 v7:
121 case CPU_SUBTYPE_ARM_V7:
122 switch (execsubtype) {
123 case CPU_SUBTYPE_ARM_V7:
124 return 5;
125 }
126 // fall through...
127
128 case CPU_SUBTYPE_ARM_V6:
129 switch (execsubtype) {
130 case CPU_SUBTYPE_ARM_V6:
131 return 4;
132 }
133 // fall through...
134
135 case CPU_SUBTYPE_ARM_V5TEJ:
136 switch (execsubtype) {
137 case CPU_SUBTYPE_ARM_V5TEJ:
138 return 3;
139 }
140 // fall through
141
142 case CPU_SUBTYPE_ARM_V4T:
143 switch (execsubtype) {
144 case CPU_SUBTYPE_ARM_V4T:
145 return 2;
146 case CPU_SUBTYPE_ARM_ALL:
147 return 1;
148 }
149 break;
150
151 case CPU_SUBTYPE_ARM_XSCALE:
152 switch (execsubtype) {
153 case CPU_SUBTYPE_ARM_XSCALE:
154 return 4;
155 case CPU_SUBTYPE_ARM_V5TEJ:
156 return 3;
157 case CPU_SUBTYPE_ARM_V4T:
158 return 2;
159 case CPU_SUBTYPE_ARM_ALL:
160 return 1;
161 }
162 break;
163 }
164 #endif /* __arm64__ */
165 }
166
167 return 0;
168 }
169
170 boolean_t
171 pie_required(cpu_type_t exectype, cpu_subtype_t execsubtype)
172 {
173 switch (exectype) {
174 #if __arm64__
175 case CPU_TYPE_ARM64:
176 return TRUE;
177 #endif /* __arm64__ */
178
179 case CPU_TYPE_ARM:
180 switch (execsubtype) {
181 case CPU_SUBTYPE_ARM_V7K:
182 return TRUE;
183 }
184 break;
185 }
186 return FALSE;
187 }