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