]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/kern_machdep.c
bdf477f7f676106ec83ab8f11309f78ff5f0e897
[apple/xnu.git] / bsd / dev / ppc / kern_machdep.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (C) 1990, 1993 NeXT, Inc.
24 * Copyright (C) 1997 Apple Computer, Inc.
25 *
26 * File: next/kern_machdep.c
27 * Author: John Seamons
28 *
29 * Machine-specific kernel routines.
30 */
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <mach/machine.h>
35 #include <mach/boolean.h>
36 #include <mach/vm_param.h>
37 #include <kern/cpu_number.h>
38 #include <machine/exec.h>
39
40 /*
41 * Routine: grade_binary()
42 *
43 * Function:
44 * Return a relative preference for exectypes and execsubtypes in fat
45 * executable files. The higher the grade, the higher the preference.
46 * A grade of 0 means not acceptable.
47 *
48 * Note: We really don't care about the real cpu_type() here,
49 * because machines can only have one type.
50 */
51 int
52 grade_binary(cpu_type_t exectype, cpu_subtype_t execsubtype)
53 {
54 int cpusubtype = cpu_subtype();
55
56 /*
57 * This code should match cpusubtype_findbestarch() in best_arch.c
58 * in the cctools project. As of 2/16/98 this is what has been
59 * agreed upon for the PowerPC subtypes. If an exact match is not
60 * found the subtype will be picked from the following order:
61 * 970(but only on 970), 7450, 7400, 750, ALL
62 * Note the 601 is NOT in the list above. It is only picked via
63 * an exact match. For details see Radar 2213821.
64 */
65
66 switch (cpusubtype) {
67 case CPU_SUBTYPE_POWERPC_970:
68 switch(exectype) {
69 case CPU_TYPE_POWERPC64: /* CPU_IS64BIT | CPU_POWERPC */
70 switch(execsubtype) {
71 /*
72 * Prefer 64 bit architecture specific binaries; note
73 * that this value does not mean the same thing here
74 * as it does below.
75 */
76 case CPU_SUBTYPE_POWERPC_970:
77 return 8;
78 /* Prefer generic binaries */
79 case CPU_SUBTYPE_POWERPC_ALL:
80 return 7;
81 default:
82 return 0;
83 }
84 /* NOTREACHED */
85
86 case CPU_TYPE_POWERPC:
87 switch(execsubtype) {
88 /*
89 * Prefer 32 bit binaries with 64 bit leaf functions;
90 * this is actually bogus use of the subtype to encode
91 * CPU feature bits.
92 */
93 case CPU_SUBTYPE_POWERPC_970:
94 return 6;
95 case CPU_SUBTYPE_POWERPC_7450:
96 return 4;
97 case CPU_SUBTYPE_POWERPC_7400:
98 return 3;
99 case CPU_SUBTYPE_POWERPC_750:
100 return 2;
101 case CPU_SUBTYPE_POWERPC_ALL:
102 return 1;
103 default:
104 return 0;
105 }
106 /* NOTREACHED */
107
108 default:
109 return 0;
110 }
111 /* NOTREACHED */
112
113 case CPU_SUBTYPE_POWERPC_7450:
114 switch(exectype) {
115 case CPU_TYPE_POWERPC64: /* CPU_IS64BIT | CPU_POWERPC */
116 return 0;
117
118 case CPU_TYPE_POWERPC:
119 switch(execsubtype) {
120 case CPU_SUBTYPE_POWERPC_7450:
121 return 6;
122 case CPU_SUBTYPE_POWERPC_7400:
123 return 4;
124 case CPU_SUBTYPE_POWERPC_750:
125 return 3;
126 case CPU_SUBTYPE_POWERPC_ALL:
127 return 1;
128 default:
129 return 0;
130 }
131 /* NOTREACHED */
132
133 default:
134 return 0;
135 }
136 /* NOTREACHED */
137
138 case CPU_SUBTYPE_POWERPC_7400:
139 switch(exectype) {
140 case CPU_TYPE_POWERPC64: /* CPU_IS64BIT | CPU_POWERPC */
141 return 0;
142
143 case CPU_TYPE_POWERPC:
144 switch(execsubtype) {
145 case CPU_SUBTYPE_POWERPC_7400:
146 return 6;
147 case CPU_SUBTYPE_POWERPC_7450:
148 return 4;
149 case CPU_SUBTYPE_POWERPC_750:
150 return 3;
151 case CPU_SUBTYPE_POWERPC_ALL:
152 return 1;
153 default:
154 return 0;
155 }
156 /* NOTREACHED */
157
158 default:
159 return 0;
160 }
161 /* NOTREACHED */
162
163 case CPU_SUBTYPE_POWERPC_750:
164 switch(exectype) {
165 case CPU_TYPE_POWERPC64: /* CPU_IS64BIT | CPU_POWERPC */
166 return 0;
167
168 case CPU_TYPE_POWERPC:
169 switch(execsubtype) {
170 case CPU_SUBTYPE_POWERPC_750:
171 return 6;
172 #ifndef ADDRESS_RADAR_2678019
173 /*
174 * Currently implemented because dropping this would
175 * turn the executable subtype into a "has Altivec"
176 * flag, which we do not want to permit. It could
177 * also break working third party applications
178 * already in use in the field.
179 */
180 case CPU_SUBTYPE_POWERPC_7400:
181 return 4;
182 case CPU_SUBTYPE_POWERPC_7450:
183 return 3;
184 #endif /* ADDRESS_RADAR_2678019 */
185 case CPU_SUBTYPE_POWERPC_ALL:
186 return 1;
187 default:
188 return 0;
189 }
190 /* NOTREACHED */
191
192 default:
193 return 0;
194 }
195 /* NOTREACHED */
196
197 default:
198 switch(exectype) {
199 case CPU_TYPE_POWERPC64: /* CPU_IS64BIT | CPU_POWERPC */
200 return 0;
201
202 case CPU_TYPE_POWERPC:
203 /* Special case for PPC601 */
204 if (cpusubtype == execsubtype)
205 return 6;
206 /*
207 * If we get here it is because it is a cpusubtype we
208 * don't support or a new cpusubtype that was added
209 * since this code was written. Both will be
210 * considered unacceptable.
211 */
212 return 0;
213 /* NOTREACHED */
214
215 default:
216 return 0;
217 }
218 /* NOTREACHED */
219 }
220 /* NOTREACHED */
221 }
222
223 boolean_t
224 kernacc(
225 off_t start,
226 size_t len
227 )
228 {
229 off_t base;
230 off_t end;
231
232 base = trunc_page_64(start);
233 end = start + len;
234
235 while (base < end) {
236 if(kvtophys((vm_offset_t)base) == NULL)
237 return(FALSE);
238 base += page_size;
239 }
240
241 return (TRUE);
242 }
243
244 void
245 md_prepare_for_shutdown(int paniced, int howto, char * command);
246
247 extern void IOSystemShutdownNotification(void);
248
249 void
250 md_prepare_for_shutdown(__unused int paniced, __unused int howto,
251 __unused char * command)
252 {
253
254 /*
255 * Temporary hack to notify the power management root domain
256 * that the system will shut down.
257 */
258 IOSystemShutdownNotification();
259 }