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