OLD | NEW |
1 // Copyright (c) 2012, Google Inc. | 1 // Copyright (c) 2012, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 12 matching lines...) Expand all Loading... |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 #include "common/mac/arch_utilities.h" | 30 #include "common/mac/arch_utilities.h" |
31 | 31 |
32 #include <mach-o/arch.h> | 32 #include <mach-o/arch.h> |
| 33 #include <mach-o/fat.h> |
33 #include <stdio.h> | 34 #include <stdio.h> |
34 #include <string.h> | 35 #include <string.h> |
35 | 36 |
36 #ifndef CPU_TYPE_ARM | |
37 #define CPU_TYPE_ARM (static_cast<cpu_type_t>(12)) | |
38 #endif // CPU_TYPE_ARM | |
39 | |
40 #ifndef CPU_SUBTYPE_ARM_V7 | |
41 #define CPU_SUBTYPE_ARM_V7 (static_cast<cpu_subtype_t>(9)) | |
42 #endif // CPU_SUBTYPE_ARM_V7 | |
43 | |
44 #ifndef CPU_SUBTYPE_ARM_V7S | 37 #ifndef CPU_SUBTYPE_ARM_V7S |
45 #define CPU_SUBTYPE_ARM_V7S (static_cast<cpu_subtype_t>(11)) | 38 #define CPU_SUBTYPE_ARM_V7S (static_cast<cpu_subtype_t>(11)) |
46 #endif // CPU_SUBTYPE_ARM_V7S | 39 #endif // CPU_SUBTYPE_ARM_V7S |
47 | 40 |
48 #ifndef CPU_TYPE_ARM64 | 41 #ifndef CPU_TYPE_ARM64 |
49 #define CPU_TYPE_ARM64 (static_cast<cpu_type_t>(16777228)) | 42 #define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64) |
50 #endif // CPU_TYPE_ARM64 | 43 #endif // CPU_TYPE_ARM64 |
51 | 44 |
52 #ifndef CPU_SUBTYPE_ARM64_ALL | 45 #ifndef CPU_SUBTYPE_ARM64_ALL |
53 #define CPU_SUBTYPE_ARM64_ALL (static_cast<cpu_type_t>(0)) | 46 #define CPU_SUBTYPE_ARM64_ALL (static_cast<cpu_subtype_t>(0)) |
54 #endif // CPU_SUBTYPE_ARM64_ALL | 47 #endif // CPU_SUBTYPE_ARM64_ALL |
55 | 48 |
56 namespace { | 49 namespace { |
57 | 50 |
58 const NXArchInfo* ArchInfo_arm64() { | 51 const NXArchInfo* ArchInfo_arm64() { |
59 NXArchInfo* arm64 = new NXArchInfo; | 52 NXArchInfo* arm64 = new NXArchInfo; |
60 *arm64 = *NXGetArchInfoFromCpuType(CPU_TYPE_ARM, | 53 *arm64 = *NXGetArchInfoFromCpuType(CPU_TYPE_ARM, |
61 CPU_SUBTYPE_ARM_V7); | 54 CPU_SUBTYPE_ARM_V7); |
62 arm64->name = "arm64"; | 55 arm64->name = "arm64"; |
63 arm64->cputype = CPU_TYPE_ARM64; | 56 arm64->cputype = CPU_TYPE_ARM64; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // TODO: Remove this when the OS knows about armv7s. | 97 // TODO: Remove this when the OS knows about armv7s. |
105 if (cpu_type == CPU_TYPE_ARM && cpu_subtype == CPU_SUBTYPE_ARM_V7S) { | 98 if (cpu_type == CPU_TYPE_ARM && cpu_subtype == CPU_SUBTYPE_ARM_V7S) { |
106 static const NXArchInfo* armv7s = ArchInfo_armv7s(); | 99 static const NXArchInfo* armv7s = ArchInfo_armv7s(); |
107 return armv7s; | 100 return armv7s; |
108 } | 101 } |
109 | 102 |
110 return NXGetArchInfoFromCpuType(cpu_type, cpu_subtype); | 103 return NXGetArchInfoFromCpuType(cpu_type, cpu_subtype); |
111 } | 104 } |
112 | 105 |
113 } // namespace google_breakpad | 106 } // namespace google_breakpad |
| 107 |
| 108 #ifndef __APPLE__ |
| 109 namespace { |
| 110 |
| 111 enum Architecture { |
| 112 kArch_i386 = 0, |
| 113 kArch_x86_64, |
| 114 kArch_arm, |
| 115 kArch_arm64, |
| 116 kArch_ppc, |
| 117 // This must be last. |
| 118 kNumArchitectures |
| 119 }; |
| 120 |
| 121 // enum Architecture above and kKnownArchitectures below |
| 122 // must be kept in sync. |
| 123 const NXArchInfo kKnownArchitectures[] = { |
| 124 { |
| 125 "i386", |
| 126 CPU_TYPE_I386, |
| 127 CPU_SUBTYPE_I386_ALL, |
| 128 NX_LittleEndian, |
| 129 "Intel 80x86" |
| 130 }, |
| 131 { |
| 132 "x86_64", |
| 133 CPU_TYPE_X86_64, |
| 134 CPU_SUBTYPE_X86_64_ALL, |
| 135 NX_LittleEndian, |
| 136 "Intel x86-64" |
| 137 }, |
| 138 { |
| 139 "arm", |
| 140 CPU_TYPE_ARM, |
| 141 CPU_SUBTYPE_ARM_ALL, |
| 142 NX_LittleEndian, |
| 143 "ARM" |
| 144 }, |
| 145 { |
| 146 "arm64", |
| 147 CPU_TYPE_ARM64, |
| 148 CPU_SUBTYPE_ARM64_ALL, |
| 149 NX_LittleEndian, |
| 150 "ARM64" |
| 151 }, |
| 152 { |
| 153 "ppc", |
| 154 CPU_TYPE_POWERPC, |
| 155 CPU_SUBTYPE_POWERPC_ALL, |
| 156 NX_BigEndian, |
| 157 "PowerPC" |
| 158 } |
| 159 }; |
| 160 |
| 161 } // namespace |
| 162 |
| 163 const NXArchInfo *NXGetLocalArchInfo(void) { |
| 164 Architecture arch; |
| 165 #if defined(__i386__) |
| 166 arch = kArch_i386; |
| 167 #elif defined(__x86_64__) |
| 168 arch = kArch_x86_64; |
| 169 #elif defined(__arm64) |
| 170 arch = kArch_arm64; |
| 171 #elif defined(__arm__) |
| 172 arch = kArch_arm; |
| 173 #elif defined(__powerpc__) |
| 174 arch = kArch_ppc; |
| 175 #else |
| 176 #error "Unsupported CPU architecture" |
| 177 #endif |
| 178 return &kKnownArchitectures[arch]; |
| 179 } |
| 180 |
| 181 const NXArchInfo *NXGetArchInfoFromName(const char *name) { |
| 182 for (int arch = 0; arch < kNumArchitectures; ++arch) { |
| 183 if (strcmp(name, kKnownArchitectures[arch].name)) { |
| 184 return &kKnownArchitectures[arch]; |
| 185 } |
| 186 } |
| 187 return NULL; |
| 188 } |
| 189 |
| 190 const NXArchInfo *NXGetArchInfoFromCpuType(cpu_type_t cputype, |
| 191 cpu_subtype_t cpusubtype) { |
| 192 for (int arch = 0; arch < kNumArchitectures; ++arch) { |
| 193 if (kKnownArchitectures[arch].cputype == cputype) { |
| 194 return &kKnownArchitectures[arch]; |
| 195 } |
| 196 } |
| 197 return NULL; |
| 198 } |
| 199 |
| 200 struct fat_arch *NXFindBestFatArch(cpu_type_t cputype, |
| 201 cpu_subtype_t cpusubtype, |
| 202 struct fat_arch *fat_archs, |
| 203 uint32_t nfat_archs) { |
| 204 for (uint32_t f = 0; f < nfat_archs; ++f) { |
| 205 if (fat_archs[f].cputype == cputype) { |
| 206 return &fat_archs[f]; |
| 207 } |
| 208 } |
| 209 return NULL; |
| 210 } |
| 211 #endif // !__APPLE__ |
OLD | NEW |