1/* 2 * Copyright (c) 2006-2008 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_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. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include <mach/machine.h> 25 26#define I386_STRING "i386" 27#define X86_64_STRING "x86_64" 28#define ARM_STRING "arm" 29#define ARM64_STRING "arm64" 30#define ANY_CPU_STRING "any" 31 32static inline char* 33string_for_arch(cpu_type_t arch) 34{ 35 switch(arch) { 36 case CPU_TYPE_I386: 37 return I386_STRING; 38 case CPU_TYPE_X86_64: 39 return X86_64_STRING; 40 case CPU_TYPE_ARM: 41 return ARM_STRING; 42#if defined(CPU_TYPE_ARM64) && !defined(RC_HIDE_64) 43 case CPU_TYPE_ARM64: 44 return ARM64_STRING; 45#endif 46 case CPU_TYPE_ANY: 47 return ANY_CPU_STRING; 48 default: 49 return NULL; 50 } 51} 52 53static inline cpu_type_t 54arch_for_string(const char* string) 55{ 56 if(!strcmp(string, I386_STRING)) 57 return CPU_TYPE_I386; 58 else if(!strcmp(string, X86_64_STRING)) 59 return CPU_TYPE_X86_64; 60 else if(!strcmp(string, ARM_STRING)) 61 return CPU_TYPE_ARM; 62#if defined(CPU_TYPE_ARM64) && !defined(RC_HIDE_64) 63 else if(!strcmp(string, ARM64_STRING)) 64 return CPU_TYPE_ARM64; 65#endif 66 else if(!strcmp(string, ANY_CPU_STRING)) 67 return CPU_TYPE_ANY; 68 else 69 return (cpu_type_t)0; 70} 71 72static inline int needs_swapping(cpu_type_t a, cpu_type_t b) 73{ 74 switch(a) { 75 case CPU_TYPE_I386: 76 case CPU_TYPE_X86_64: 77 if(b == CPU_TYPE_POWERPC || b == CPU_TYPE_POWERPC64) 78 return 1; 79 else 80 return 0; 81 case CPU_TYPE_POWERPC: 82 case CPU_TYPE_POWERPC64: 83 if(b == CPU_TYPE_I386 || b == CPU_TYPE_X86_64) 84 return 1; 85 else 86 return 0; 87 } 88 89 return 0; 90} 91 92#if defined(__i386__) 93#define host_arch CPU_TYPE_I386 94#elif defined(__x86_64__) 95#define host_arch CPU_TYPE_X86_64 96#elif defined(__arm__) 97#define host_arch CPU_TYPE_ARM 98#elif defined(__arm64__) 99#define host_arch CPU_TYPE_ARM64 100#else 101#error Unsupported architecture 102#endif 103 104