]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/kern_machdep.c
ec816541367341aa0a91661216fc76a3f3224d90
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (C) 1990, 1993 NeXT, Inc.
27 * Copyright (C) 1997 Apple Computer, Inc.
28 *
29 * File: next/kern_machdep.c
30 * Author: John Seamons
31 *
32 * Machine-specific kernel routines.
33 *
34 * HISTORY
35 * 8-Dec-91 Peter King (king) at NeXT
36 * Added grade_cpu_subtype().
37 * FIXME: Do we want to merge this with check_cpu_subtype()?
38 *
39 * 5-Mar-90 John Seamons (jks) at NeXT
40 * Created.
41 */
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <mach/machine.h>
46 #include <mach/boolean.h>
47 #include <mach/vm_param.h>
48 #include <kern/cpu_number.h>
49
50 int
51 check_cpu_subtype(cpu_subtype_t cpu_subtype)
52 {
53 struct machine_slot *ms = &machine_slot[cpu_number()];
54
55 if (cpu_subtype == ms->cpu_subtype)
56 return (TRUE);
57
58 if (cpu_subtype == CPU_SUBTYPE_POWERPC_601)
59 return (FALSE);
60
61 switch (cpu_subtype) {
62 case CPU_SUBTYPE_POWERPC_7450:
63 case CPU_SUBTYPE_POWERPC_7400:
64 case CPU_SUBTYPE_POWERPC_750:
65 case CPU_SUBTYPE_POWERPC_604e:
66 case CPU_SUBTYPE_POWERPC_604:
67 case CPU_SUBTYPE_POWERPC_603ev:
68 case CPU_SUBTYPE_POWERPC_603e:
69 case CPU_SUBTYPE_POWERPC_603:
70 case CPU_SUBTYPE_POWERPC_ALL:
71 return (TRUE);
72 }
73
74 return (FALSE);
75 }
76
77 /*
78 * Routine: grade_cpu_subtype()
79 *
80 * Function:
81 * Return a relative preference for cpu_subtypes in fat executable files.
82 * The higher the grade, the higher the preference.
83 * A grade of 0 means not acceptable.
84 */
85
86 int
87 grade_cpu_subtype(cpu_subtype_t cpu_subtype)
88 {
89 struct machine_slot *ms = &machine_slot[cpu_number()];
90
91 /*
92 * This code should match cpusubtype_findbestarch() in best_arch.c in the
93 * cctools project. As of 2/16/98 this is what has been agreed upon for
94 * the PowerPC subtypes. If an exact match is not found the subtype will
95 * be picked from the following order:
96 * 7400, 750, 604e, 604, 603ev, 603e, 603, ALL
97 * Note the 601 is NOT in the list above. It is only picked via an exact
98 * match. For details see Radar 2213821.
99 *
100 * To implement this function to follow what was agreed upon above, we use
101 * the fact there are currently 10 different subtypes. Exact matches return
102 * the value 10, the value 0 is returned for 601 that is not an exact match,
103 * and the values 9 thru 1 are returned for the subtypes listed in the order
104 * above.
105 */
106 if (ms->cpu_subtype == cpu_subtype)
107 return 10;
108 if (cpu_subtype == CPU_SUBTYPE_POWERPC_601)
109 return 0;
110 switch (cpu_subtype) {
111 case CPU_SUBTYPE_POWERPC_7450:
112 return 9;
113 case CPU_SUBTYPE_POWERPC_7400:
114 return 8;
115 case CPU_SUBTYPE_POWERPC_750:
116 return 7;
117 case CPU_SUBTYPE_POWERPC_604e:
118 return 6;
119 case CPU_SUBTYPE_POWERPC_604:
120 return 5;
121 case CPU_SUBTYPE_POWERPC_603ev:
122 return 4;
123 case CPU_SUBTYPE_POWERPC_603e:
124 return 3;
125 case CPU_SUBTYPE_POWERPC_603:
126 return 2;
127 case CPU_SUBTYPE_POWERPC_ALL:
128 return 1;
129 }
130 /*
131 * If we get here it is because it is a cpusubtype we don't support (602 and
132 * 620) or new cpusubtype that was added since this code was written. Both
133 * will be considered unacceptable.
134 */
135 return 0;
136 }
137
138 boolean_t
139 kernacc(
140 off_t start,
141 size_t len
142 )
143 {
144 off_t base;
145 off_t end;
146
147 base = trunc_page(start);
148 end = start + len;
149
150 while (base < end) {
151 if(kvtophys((vm_offset_t)base) == NULL)
152 return(FALSE);
153 base += page_size;
154 }
155
156 return (TRUE);
157 }