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