]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
099524d7 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2014 Lennart Poettering | |
099524d7 LP |
8 | ***/ |
9 | ||
6017365a LP |
10 | #include <endian.h> |
11 | ||
a8fbdf54 | 12 | #include "macro.h" |
099524d7 LP |
13 | #include "util.h" |
14 | ||
579af519 LP |
15 | /* A cleaned up architecture definition. We don't want to get lost in |
16 | * processor features, models, generations or even ABIs. Hence we | |
45afd519 | 17 | * focus on general family, and distinguish word width and |
06b643e7 | 18 | * endianness. */ |
9a00f57a | 19 | |
592fd144 | 20 | enum { |
099524d7 LP |
21 | ARCHITECTURE_X86 = 0, |
22 | ARCHITECTURE_X86_64, | |
23 | ARCHITECTURE_PPC, | |
ae0e60fb | 24 | ARCHITECTURE_PPC_LE, |
099524d7 | 25 | ARCHITECTURE_PPC64, |
ae0e60fb | 26 | ARCHITECTURE_PPC64_LE, |
099524d7 LP |
27 | ARCHITECTURE_IA64, |
28 | ARCHITECTURE_PARISC, | |
29 | ARCHITECTURE_PARISC64, | |
30 | ARCHITECTURE_S390, | |
31 | ARCHITECTURE_S390X, | |
32 | ARCHITECTURE_SPARC, | |
33 | ARCHITECTURE_SPARC64, | |
34 | ARCHITECTURE_MIPS, | |
9a00f57a | 35 | ARCHITECTURE_MIPS_LE, |
099524d7 | 36 | ARCHITECTURE_MIPS64, |
9a00f57a | 37 | ARCHITECTURE_MIPS64_LE, |
099524d7 LP |
38 | ARCHITECTURE_ALPHA, |
39 | ARCHITECTURE_ARM, | |
40 | ARCHITECTURE_ARM_BE, | |
41 | ARCHITECTURE_ARM64, | |
42 | ARCHITECTURE_ARM64_BE, | |
43 | ARCHITECTURE_SH, | |
44 | ARCHITECTURE_SH64, | |
45 | ARCHITECTURE_M68K, | |
46eea341 | 46 | ARCHITECTURE_TILEGX, |
86bafac9 | 47 | ARCHITECTURE_CRIS, |
b79660e6 | 48 | ARCHITECTURE_NIOS2, |
171b5338 RJ |
49 | ARCHITECTURE_RISCV32, |
50 | ARCHITECTURE_RISCV64, | |
27b09f1f AB |
51 | ARCHITECTURE_ARC, |
52 | ARCHITECTURE_ARC_BE, | |
099524d7 LP |
53 | _ARCHITECTURE_MAX, |
54 | _ARCHITECTURE_INVALID = -1 | |
592fd144 | 55 | }; |
099524d7 | 56 | |
592fd144 | 57 | int uname_architecture(void); |
099524d7 | 58 | |
9a00f57a | 59 | /* |
613e3a26 LP |
60 | * LIB_ARCH_TUPLE should resolve to the local library path |
61 | * architecture tuple systemd is built for, according to the Debian | |
62 | * tuple list: | |
9a00f57a LP |
63 | * |
64 | * https://wiki.debian.org/Multiarch/Tuples | |
65 | * | |
613e3a26 LP |
66 | * This is used in library search paths that should understand |
67 | * Debian's paths on all distributions. | |
9a00f57a LP |
68 | */ |
69 | ||
099524d7 LP |
70 | #if defined(__x86_64__) |
71 | # define native_architecture() ARCHITECTURE_X86_64 | |
4c7c70c7 JPAG |
72 | # if defined(__ILP32__) |
73 | # define LIB_ARCH_TUPLE "x86_64-linux-gnux32" | |
74 | # else | |
75 | # define LIB_ARCH_TUPLE "x86_64-linux-gnu" | |
76 | # endif | |
0c0fea07 | 77 | # define SECONDARY_ARCHITECTURE ARCHITECTURE_X86 |
099524d7 LP |
78 | #elif defined(__i386__) |
79 | # define native_architecture() ARCHITECTURE_X86 | |
613e3a26 | 80 | # define LIB_ARCH_TUPLE "i386-linux-gnu" |
099524d7 | 81 | #elif defined(__powerpc64__) |
4f4b92ba | 82 | # if __BYTE_ORDER == __BIG_ENDIAN |
ae0e60fb | 83 | # define native_architecture() ARCHITECTURE_PPC64 |
613e3a26 | 84 | # define LIB_ARCH_TUPLE "ppc64-linux-gnu" |
0c0fea07 | 85 | # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC |
ae0e60fb LP |
86 | # else |
87 | # define native_architecture() ARCHITECTURE_PPC64_LE | |
37d6781b | 88 | # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu" |
0c0fea07 | 89 | # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE |
ae0e60fb | 90 | # endif |
099524d7 | 91 | #elif defined(__powerpc__) |
4f4b92ba | 92 | # if __BYTE_ORDER == __BIG_ENDIAN |
ae0e60fb | 93 | # define native_architecture() ARCHITECTURE_PPC |
202145c0 JPAG |
94 | # if defined(__NO_FPRS__) |
95 | # define LIB_ARCH_TUPLE "powerpc-linux-gnuspe" | |
96 | # else | |
97 | # define LIB_ARCH_TUPLE "powerpc-linux-gnu" | |
98 | # endif | |
ae0e60fb LP |
99 | # else |
100 | # define native_architecture() ARCHITECTURE_PPC_LE | |
613e3a26 | 101 | # error "Missing LIB_ARCH_TUPLE for PPCLE" |
ae0e60fb | 102 | # endif |
099524d7 LP |
103 | #elif defined(__ia64__) |
104 | # define native_architecture() ARCHITECTURE_IA64 | |
613e3a26 | 105 | # define LIB_ARCH_TUPLE "ia64-linux-gnu" |
099524d7 LP |
106 | #elif defined(__hppa64__) |
107 | # define native_architecture() ARCHITECTURE_PARISC64 | |
613e3a26 | 108 | # error "Missing LIB_ARCH_TUPLE for HPPA64" |
099524d7 LP |
109 | #elif defined(__hppa__) |
110 | # define native_architecture() ARCHITECTURE_PARISC | |
613e3a26 | 111 | # define LIB_ARCH_TUPLE "hppa‑linux‑gnu" |
099524d7 LP |
112 | #elif defined(__s390x__) |
113 | # define native_architecture() ARCHITECTURE_S390X | |
613e3a26 | 114 | # define LIB_ARCH_TUPLE "s390x-linux-gnu" |
0c0fea07 | 115 | # define SECONDARY_ARCHITECTURE ARCHITECTURE_S390 |
099524d7 LP |
116 | #elif defined(__s390__) |
117 | # define native_architecture() ARCHITECTURE_S390 | |
613e3a26 | 118 | # define LIB_ARCH_TUPLE "s390-linux-gnu" |
cd042078 | 119 | #elif defined(__sparc__) && defined (__arch64__) |
099524d7 | 120 | # define native_architecture() ARCHITECTURE_SPARC64 |
613e3a26 | 121 | # define LIB_ARCH_TUPLE "sparc64-linux-gnu" |
099524d7 LP |
122 | #elif defined(__sparc__) |
123 | # define native_architecture() ARCHITECTURE_SPARC | |
613e3a26 | 124 | # define LIB_ARCH_TUPLE "sparc-linux-gnu" |
caf49b95 | 125 | #elif defined(__mips64) && defined(__LP64__) |
4f4b92ba | 126 | # if __BYTE_ORDER == __BIG_ENDIAN |
9a00f57a | 127 | # define native_architecture() ARCHITECTURE_MIPS64 |
caf49b95 | 128 | # define LIB_ARCH_TUPLE "mips64-linux-gnuabi64" |
9a00f57a LP |
129 | # else |
130 | # define native_architecture() ARCHITECTURE_MIPS64_LE | |
caf49b95 YS |
131 | # define LIB_ARCH_TUPLE "mips64el-linux-gnuabi64" |
132 | # endif | |
133 | #elif defined(__mips64) | |
134 | # if __BYTE_ORDER == __BIG_ENDIAN | |
135 | # define native_architecture() ARCHITECTURE_MIPS64 | |
136 | # define LIB_ARCH_TUPLE "mips64-linux-gnuabin32" | |
137 | # else | |
138 | # define native_architecture() ARCHITECTURE_MIPS64_LE | |
139 | # define LIB_ARCH_TUPLE "mips64el-linux-gnuabin32" | |
9a00f57a | 140 | # endif |
099524d7 | 141 | #elif defined(__mips__) |
4f4b92ba | 142 | # if __BYTE_ORDER == __BIG_ENDIAN |
9a00f57a | 143 | # define native_architecture() ARCHITECTURE_MIPS |
613e3a26 | 144 | # define LIB_ARCH_TUPLE "mips-linux-gnu" |
9a00f57a LP |
145 | # else |
146 | # define native_architecture() ARCHITECTURE_MIPS_LE | |
613e3a26 | 147 | # define LIB_ARCH_TUPLE "mipsel-linux-gnu" |
568981d2 | 148 | # endif |
099524d7 LP |
149 | #elif defined(__alpha__) |
150 | # define native_architecture() ARCHITECTURE_ALPHA | |
613e3a26 | 151 | # define LIB_ARCH_TUPLE "alpha-linux-gnu" |
099524d7 | 152 | #elif defined(__aarch64__) |
4f4b92ba | 153 | # if __BYTE_ORDER == __BIG_ENDIAN |
099524d7 | 154 | # define native_architecture() ARCHITECTURE_ARM64_BE |
613e3a26 | 155 | # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu" |
099524d7 LP |
156 | # else |
157 | # define native_architecture() ARCHITECTURE_ARM64 | |
613e3a26 | 158 | # define LIB_ARCH_TUPLE "aarch64-linux-gnu" |
b7cac527 | 159 | # define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM |
099524d7 LP |
160 | # endif |
161 | #elif defined(__arm__) | |
4f4b92ba | 162 | # if __BYTE_ORDER == __BIG_ENDIAN |
099524d7 | 163 | # define native_architecture() ARCHITECTURE_ARM_BE |
579af519 LP |
164 | # if defined(__ARM_EABI__) |
165 | # if defined(__ARM_PCS_VFP) | |
166 | # define LIB_ARCH_TUPLE "armeb-linux-gnueabihf" | |
167 | # else | |
168 | # define LIB_ARCH_TUPLE "armeb-linux-gnueabi" | |
169 | # endif | |
0881d7af | 170 | # else |
579af519 | 171 | # define LIB_ARCH_TUPLE "armeb-linux-gnu" |
0881d7af | 172 | # endif |
099524d7 | 173 | # else |
0881d7af | 174 | # define native_architecture() ARCHITECTURE_ARM |
2a9899d8 ZJS |
175 | # if defined(__ARM_EABI__) |
176 | # if defined(__ARM_PCS_VFP) | |
177 | # define LIB_ARCH_TUPLE "arm-linux-gnueabihf" | |
178 | # else | |
179 | # define LIB_ARCH_TUPLE "arm-linux-gnueabi" | |
180 | # endif | |
fd3b401e | 181 | # else |
2a9899d8 | 182 | # define LIB_ARCH_TUPLE "arm-linux-gnu" |
fd3b401e | 183 | # endif |
099524d7 LP |
184 | # endif |
185 | #elif defined(__sh64__) | |
186 | # define native_architecture() ARCHITECTURE_SH64 | |
613e3a26 | 187 | # error "Missing LIB_ARCH_TUPLE for SH64" |
099524d7 LP |
188 | #elif defined(__sh__) |
189 | # define native_architecture() ARCHITECTURE_SH | |
9da2a0ac JPAG |
190 | # if defined(__SH1__) |
191 | # define LIB_ARCH_TUPLE "sh1-linux-gnu" | |
192 | # elif defined(__SH2__) | |
193 | # define LIB_ARCH_TUPLE "sh2-linux-gnu" | |
194 | # elif defined(__SH2A__) | |
195 | # define LIB_ARCH_TUPLE "sh2a-linux-gnu" | |
196 | # elif defined(__SH2E__) | |
197 | # define LIB_ARCH_TUPLE "sh2e-linux-gnu" | |
198 | # elif defined(__SH3__) | |
199 | # define LIB_ARCH_TUPLE "sh3-linux-gnu" | |
200 | # elif defined(__SH3E__) | |
201 | # define LIB_ARCH_TUPLE "sh3e-linux-gnu" | |
202 | # elif defined(__SH4__) && !defined(__SH4A__) | |
203 | # define LIB_ARCH_TUPLE "sh4-linux-gnu" | |
204 | # elif defined(__SH4A__) | |
205 | # define LIB_ARCH_TUPLE "sh4a-linux-gnu" | |
206 | # endif | |
099524d7 LP |
207 | #elif defined(__m68k__) |
208 | # define native_architecture() ARCHITECTURE_M68K | |
613e3a26 | 209 | # define LIB_ARCH_TUPLE "m68k-linux-gnu" |
46eea341 HGB |
210 | #elif defined(__tilegx__) |
211 | # define native_architecture() ARCHITECTURE_TILEGX | |
b1caafb2 | 212 | # define LIB_ARCH_TUPLE "tilegx-linux-gnu" |
86bafac9 UTL |
213 | #elif defined(__cris__) |
214 | # define native_architecture() ARCHITECTURE_CRIS | |
613e3a26 | 215 | # error "Missing LIB_ARCH_TUPLE for CRIS" |
b79660e6 ZJS |
216 | #elif defined(__nios2__) |
217 | # define native_architecture() ARCHITECTURE_NIOS2 | |
218 | # define LIB_ARCH_TUPLE "nios2-linux-gnu" | |
680a752c ZJS |
219 | #elif defined(__riscv__) || defined(__riscv) |
220 | /* __riscv__ is obsolete, remove in 2018 */ | |
171b5338 RJ |
221 | # if __SIZEOF_POINTER__ == 4 |
222 | # define native_architecture() ARCHITECTURE_RISCV32 | |
223 | # define LIB_ARCH_TUPLE "riscv32-linux-gnu" | |
224 | # elif __SIZEOF_POINTER__ == 8 | |
225 | # define native_architecture() ARCHITECTURE_RISCV64 | |
226 | # define LIB_ARCH_TUPLE "riscv64-linux-gnu" | |
227 | # else | |
228 | # error "Unrecognized riscv architecture variant" | |
229 | # endif | |
27b09f1f AB |
230 | #elif defined(__arc__) |
231 | # if __BYTE_ORDER == __BIG_ENDIAN | |
232 | # define native_architecture() ARCHITECTURE_ARC_BE | |
233 | # define LIB_ARCH_TUPLE "arceb-linux" | |
234 | # else | |
235 | # define native_architecture() ARCHITECTURE_ARC | |
236 | # define LIB_ARCH_TUPLE "arc-linux" | |
237 | # endif | |
099524d7 | 238 | #else |
568981d2 | 239 | # error "Please register your architecture here!" |
099524d7 LP |
240 | #endif |
241 | ||
592fd144 LP |
242 | const char *architecture_to_string(int a) _const_; |
243 | int architecture_from_string(const char *s) _pure_; |