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