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
;
40 #endif /* __arm64__ */
42 /**********************************************************************
43 * Routine: grade_binary()
45 * Function: Return a relative preference for exectypes and
46 * execsubtypes in fat executable files. The higher the
47 * grade, the higher the preference. A grade of 0 means
49 **********************************************************************/
51 grade_binary(cpu_type_t exectype
, cpu_subtype_t execsubtype
, cpu_subtype_t execfeatures __unused
, bool allow_simulator_binary __unused
)
54 cpu_subtype_t hostsubtype
=
55 (exectype
& CPU_ARCH_ABI64
) ? cpu_subtype() : cpu_subtype32();
57 cpu_subtype_t hostsubtype
= cpu_subtype();
58 #endif /* __arm64__ */
63 switch (hostsubtype
) {
64 case CPU_SUBTYPE_ARM64_V8
:
65 switch (execsubtype
) {
66 case CPU_SUBTYPE_ARM64_V8
:
68 case CPU_SUBTYPE_ARM64_ALL
:
73 } /* switch (hostsubtype) */
79 switch (hostsubtype
) {
81 * For 32-bit ARMv8, try the ARMv8 slice before falling back to Swift.
83 case CPU_SUBTYPE_ARM_V8
:
84 switch (execsubtype
) {
85 case CPU_SUBTYPE_ARM_V8
:
91 * For Swift and later, we prefer to run a swift slice, but fall back
92 * to v7 as Cortex A9 errata should not apply
95 case CPU_SUBTYPE_ARM_V7S
:
96 switch (execsubtype
) {
97 case CPU_SUBTYPE_ARM_V7S
:
103 * For Cortex A7, accept v7k only due to differing ABI
105 case CPU_SUBTYPE_ARM_V7K
:
106 switch (execsubtype
) {
107 case CPU_SUBTYPE_ARM_V7K
:
113 * For Cortex A9, we prefer the A9 slice, but will run v7 albeit
114 * under the risk of hitting the NEON load/store errata
116 case CPU_SUBTYPE_ARM_V7F
:
117 switch (execsubtype
) {
118 case CPU_SUBTYPE_ARM_V7F
:
124 case CPU_SUBTYPE_ARM_V7
:
125 switch (execsubtype
) {
126 case CPU_SUBTYPE_ARM_V7
:
131 case CPU_SUBTYPE_ARM_V6
:
132 switch (execsubtype
) {
133 case CPU_SUBTYPE_ARM_V6
:
138 case CPU_SUBTYPE_ARM_V5TEJ
:
139 switch (execsubtype
) {
140 case CPU_SUBTYPE_ARM_V5TEJ
:
145 case CPU_SUBTYPE_ARM_V4T
:
146 switch (execsubtype
) {
147 case CPU_SUBTYPE_ARM_V4T
:
149 case CPU_SUBTYPE_ARM_ALL
:
154 case CPU_SUBTYPE_ARM_XSCALE
:
155 switch (execsubtype
) {
156 case CPU_SUBTYPE_ARM_XSCALE
:
158 case CPU_SUBTYPE_ARM_V5TEJ
:
160 case CPU_SUBTYPE_ARM_V4T
:
162 case CPU_SUBTYPE_ARM_ALL
:
167 #endif /* __arm64__ */