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