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