2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
5 * Copyright (C) 1990, NeXT, Inc.
7 * File: next/kern_machdep.c
10 * Machine-specific kernel routines.
13 #include <sys/types.h>
14 #include <mach/machine.h>
15 #include <kern/cpu_number.h>
16 #include <libkern/libkern.h>
17 #include <machine/exec.h>
18 #include <pexpert/arm64/board_config.h>
21 static cpu_subtype_t
cpu_subtype32(void);
22 #endif /* __arm64__ */
26 * When an arm64 CPU is executing an arm32 binary, we need to map from the
27 * host's 64-bit subtype to the appropriate 32-bit subtype.
32 switch (cpu_subtype()) {
33 case CPU_SUBTYPE_ARM64_V8
:
34 return CPU_SUBTYPE_ARM_V8
;
41 grade_arm64e_binary(cpu_subtype_t execfeatures
)
45 * iOS 13 toolchains produced unversioned arm64e slices which are not
46 * ABI compatible with this release.
48 if ((execfeatures
& CPU_SUBTYPE_PTRAUTH_ABI
) == 0) {
49 #if DEBUG || DEVELOPMENT
50 printf("%s: arm64e prerelease ABI cannot be used with this kernel\n", __func__
);
51 #endif /* DEBUG || DEVELOPMENT */
54 #endif /* XNU_TARGET_OS_IOS */
56 /* The current ABI version is preferred over arm64 */
57 if (CPU_SUBTYPE_ARM64_PTR_AUTH_VERSION(execfeatures
) ==
58 CPU_SUBTYPE_ARM64_PTR_AUTH_CURRENT_VERSION
) {
62 /* Future ABIs are allowed, but exec_mach_imgact will treat it like an arm64 slice */
65 #endif /* __arm64__ */
67 /**********************************************************************
68 * Routine: grade_binary()
70 * Function: Return a relative preference for exectypes and
71 * execsubtypes in fat executable files. The higher the
72 * grade, the higher the preference. A grade of 0 means
74 **********************************************************************/
76 grade_binary(cpu_type_t exectype
, cpu_subtype_t execsubtype
, cpu_subtype_t execfeatures __unused
, bool allow_simulator_binary __unused
)
79 cpu_subtype_t hostsubtype
=
80 (exectype
& CPU_ARCH_ABI64
) ? cpu_subtype() : cpu_subtype32();
82 cpu_subtype_t hostsubtype
= cpu_subtype();
83 #endif /* __arm64__ */
88 switch (hostsubtype
) {
89 case CPU_SUBTYPE_ARM64_V8
:
90 switch (execsubtype
) {
91 case CPU_SUBTYPE_ARM64_V8
:
93 case CPU_SUBTYPE_ARM64_ALL
:
98 case CPU_SUBTYPE_ARM64E
:
99 switch (execsubtype
) {
100 case CPU_SUBTYPE_ARM64E
:
101 return grade_arm64e_binary(execfeatures
);
102 case CPU_SUBTYPE_ARM64_V8
:
104 case CPU_SUBTYPE_ARM64_ALL
:
107 } /* switch (hostsubtype) */
110 #else /* __arm64__ */
113 switch (hostsubtype
) {
115 * For 32-bit ARMv8, try the ARMv8 slice before falling back to Swift.
117 case CPU_SUBTYPE_ARM_V8
:
118 switch (execsubtype
) {
119 case CPU_SUBTYPE_ARM_V8
:
125 * For Swift and later, we prefer to run a swift slice, but fall back
126 * to v7 as Cortex A9 errata should not apply
129 case CPU_SUBTYPE_ARM_V7S
:
130 switch (execsubtype
) {
131 case CPU_SUBTYPE_ARM_V7S
:
137 * For Cortex A7, accept v7k only due to differing ABI
139 case CPU_SUBTYPE_ARM_V7K
:
140 switch (execsubtype
) {
141 case CPU_SUBTYPE_ARM_V7K
:
147 * For Cortex A9, we prefer the A9 slice, but will run v7 albeit
148 * under the risk of hitting the NEON load/store errata
150 case CPU_SUBTYPE_ARM_V7F
:
151 switch (execsubtype
) {
152 case CPU_SUBTYPE_ARM_V7F
:
158 case CPU_SUBTYPE_ARM_V7
:
159 switch (execsubtype
) {
160 case CPU_SUBTYPE_ARM_V7
:
165 case CPU_SUBTYPE_ARM_V6
:
166 switch (execsubtype
) {
167 case CPU_SUBTYPE_ARM_V6
:
172 case CPU_SUBTYPE_ARM_V5TEJ
:
173 switch (execsubtype
) {
174 case CPU_SUBTYPE_ARM_V5TEJ
:
179 case CPU_SUBTYPE_ARM_V4T
:
180 switch (execsubtype
) {
181 case CPU_SUBTYPE_ARM_V4T
:
183 case CPU_SUBTYPE_ARM_ALL
:
188 case CPU_SUBTYPE_ARM_XSCALE
:
189 switch (execsubtype
) {
190 case CPU_SUBTYPE_ARM_XSCALE
:
192 case CPU_SUBTYPE_ARM_V5TEJ
:
194 case CPU_SUBTYPE_ARM_V4T
:
196 case CPU_SUBTYPE_ARM_ALL
:
201 #endif /* __arm64__ */