]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
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 | ||
1c79356b | 58 | switch (cpu_subtype) { |
55e303ae A |
59 | case CPU_SUBTYPE_POWERPC_970: |
60 | /* Do not allow a 970 binary to run on non-970 systems */ | |
61 | if (ms->cpu_subtype != CPU_SUBTYPE_POWERPC_970) | |
62 | break; | |
1c79356b A |
63 | case CPU_SUBTYPE_POWERPC_7450: |
64 | case CPU_SUBTYPE_POWERPC_7400: | |
65 | case CPU_SUBTYPE_POWERPC_750: | |
1c79356b A |
66 | case CPU_SUBTYPE_POWERPC_ALL: |
67 | return (TRUE); | |
68 | } | |
69 | ||
70 | return (FALSE); | |
71 | } | |
72 | ||
73 | /* | |
74 | * Routine: grade_cpu_subtype() | |
75 | * | |
76 | * Function: | |
77 | * Return a relative preference for cpu_subtypes in fat executable files. | |
78 | * The higher the grade, the higher the preference. | |
79 | * A grade of 0 means not acceptable. | |
80 | */ | |
81 | ||
82 | int | |
83 | grade_cpu_subtype(cpu_subtype_t cpu_subtype) | |
84 | { | |
85 | struct machine_slot *ms = &machine_slot[cpu_number()]; | |
86 | ||
87 | /* | |
88 | * This code should match cpusubtype_findbestarch() in best_arch.c in the | |
89 | * cctools project. As of 2/16/98 this is what has been agreed upon for | |
90 | * the PowerPC subtypes. If an exact match is not found the subtype will | |
91 | * be picked from the following order: | |
55e303ae | 92 | * 970(but only on 970), 7450, 7400, 750, ALL |
1c79356b A |
93 | * Note the 601 is NOT in the list above. It is only picked via an exact |
94 | * match. For details see Radar 2213821. | |
95 | * | |
96 | * To implement this function to follow what was agreed upon above, we use | |
55e303ae A |
97 | * the fact there are currently 4 different subtypes. Exact matches return |
98 | * the value 6, and the values 5 thru 1 are returned for the | |
99 | * subtypes listed in the order above. | |
1c79356b A |
100 | */ |
101 | if (ms->cpu_subtype == cpu_subtype) | |
55e303ae | 102 | return 6; |
1c79356b | 103 | switch (cpu_subtype) { |
55e303ae A |
104 | case CPU_SUBTYPE_POWERPC_970: |
105 | /* Do not allow a 970 binary to run on non-970 systems */ | |
106 | if (ms->cpu_subtype != CPU_SUBTYPE_POWERPC_970) | |
107 | break; | |
de355530 | 108 | return 5; |
55e303ae | 109 | case CPU_SUBTYPE_POWERPC_7450: |
de355530 | 110 | return 4; |
55e303ae | 111 | case CPU_SUBTYPE_POWERPC_7400: |
de355530 | 112 | return 3; |
55e303ae | 113 | case CPU_SUBTYPE_POWERPC_750: |
1c79356b A |
114 | return 2; |
115 | case CPU_SUBTYPE_POWERPC_ALL: | |
116 | return 1; | |
117 | } | |
118 | /* | |
55e303ae A |
119 | * If we get here it is because it is a cpusubtype we don't support |
120 | * or a new cpusubtype that was added since this code was written. Both | |
1c79356b A |
121 | * will be considered unacceptable. |
122 | */ | |
123 | return 0; | |
124 | } | |
125 | ||
126 | boolean_t | |
127 | kernacc( | |
128 | off_t start, | |
129 | size_t len | |
130 | ) | |
131 | { | |
132 | off_t base; | |
133 | off_t end; | |
134 | ||
55e303ae | 135 | base = trunc_page_64(start); |
1c79356b A |
136 | end = start + len; |
137 | ||
138 | while (base < end) { | |
139 | if(kvtophys((vm_offset_t)base) == NULL) | |
140 | return(FALSE); | |
141 | base += page_size; | |
142 | } | |
143 | ||
144 | return (TRUE); | |
145 | } |