]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/architecture.h
resolved: don't check conflicts for DNS-SD enumeration RRs
[thirdparty/systemd.git] / src / basic / architecture.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2014 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <endian.h>
24
25 #include "macro.h"
26 #include "util.h"
27
28 /* A cleaned up architecture definition. We don't want to get lost in
29 * processor features, models, generations or even ABIs. Hence we
30 * focus on general family, and distinguish word width and
31 * endianness. */
32
33 enum {
34 ARCHITECTURE_X86 = 0,
35 ARCHITECTURE_X86_64,
36 ARCHITECTURE_PPC,
37 ARCHITECTURE_PPC_LE,
38 ARCHITECTURE_PPC64,
39 ARCHITECTURE_PPC64_LE,
40 ARCHITECTURE_IA64,
41 ARCHITECTURE_PARISC,
42 ARCHITECTURE_PARISC64,
43 ARCHITECTURE_S390,
44 ARCHITECTURE_S390X,
45 ARCHITECTURE_SPARC,
46 ARCHITECTURE_SPARC64,
47 ARCHITECTURE_MIPS,
48 ARCHITECTURE_MIPS_LE,
49 ARCHITECTURE_MIPS64,
50 ARCHITECTURE_MIPS64_LE,
51 ARCHITECTURE_ALPHA,
52 ARCHITECTURE_ARM,
53 ARCHITECTURE_ARM_BE,
54 ARCHITECTURE_ARM64,
55 ARCHITECTURE_ARM64_BE,
56 ARCHITECTURE_SH,
57 ARCHITECTURE_SH64,
58 ARCHITECTURE_M68K,
59 ARCHITECTURE_TILEGX,
60 ARCHITECTURE_CRIS,
61 ARCHITECTURE_NIOS2,
62 ARCHITECTURE_RISCV32,
63 ARCHITECTURE_RISCV64,
64 ARCHITECTURE_ARC,
65 ARCHITECTURE_ARC_BE,
66 _ARCHITECTURE_MAX,
67 _ARCHITECTURE_INVALID = -1
68 };
69
70 int uname_architecture(void);
71
72 /*
73 * LIB_ARCH_TUPLE should resolve to the local library path
74 * architecture tuple systemd is built for, according to the Debian
75 * tuple list:
76 *
77 * https://wiki.debian.org/Multiarch/Tuples
78 *
79 * This is used in library search paths that should understand
80 * Debian's paths on all distributions.
81 */
82
83 #if defined(__x86_64__)
84 # define native_architecture() ARCHITECTURE_X86_64
85 # if defined(__ILP32__)
86 # define LIB_ARCH_TUPLE "x86_64-linux-gnux32"
87 # else
88 # define LIB_ARCH_TUPLE "x86_64-linux-gnu"
89 # endif
90 # define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
91 #elif defined(__i386__)
92 # define native_architecture() ARCHITECTURE_X86
93 # define LIB_ARCH_TUPLE "i386-linux-gnu"
94 #elif defined(__powerpc64__)
95 # if __BYTE_ORDER == __BIG_ENDIAN
96 # define native_architecture() ARCHITECTURE_PPC64
97 # define LIB_ARCH_TUPLE "ppc64-linux-gnu"
98 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
99 # else
100 # define native_architecture() ARCHITECTURE_PPC64_LE
101 # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
102 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
103 # endif
104 #elif defined(__powerpc__)
105 # if __BYTE_ORDER == __BIG_ENDIAN
106 # define native_architecture() ARCHITECTURE_PPC
107 # if defined(__NO_FPRS__)
108 # define LIB_ARCH_TUPLE "powerpc-linux-gnuspe"
109 # else
110 # define LIB_ARCH_TUPLE "powerpc-linux-gnu"
111 # endif
112 # else
113 # define native_architecture() ARCHITECTURE_PPC_LE
114 # error "Missing LIB_ARCH_TUPLE for PPCLE"
115 # endif
116 #elif defined(__ia64__)
117 # define native_architecture() ARCHITECTURE_IA64
118 # define LIB_ARCH_TUPLE "ia64-linux-gnu"
119 #elif defined(__hppa64__)
120 # define native_architecture() ARCHITECTURE_PARISC64
121 # error "Missing LIB_ARCH_TUPLE for HPPA64"
122 #elif defined(__hppa__)
123 # define native_architecture() ARCHITECTURE_PARISC
124 # define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
125 #elif defined(__s390x__)
126 # define native_architecture() ARCHITECTURE_S390X
127 # define LIB_ARCH_TUPLE "s390x-linux-gnu"
128 # define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
129 #elif defined(__s390__)
130 # define native_architecture() ARCHITECTURE_S390
131 # define LIB_ARCH_TUPLE "s390-linux-gnu"
132 #elif defined(__sparc__) && defined (__arch64__)
133 # define native_architecture() ARCHITECTURE_SPARC64
134 # define LIB_ARCH_TUPLE "sparc64-linux-gnu"
135 #elif defined(__sparc__)
136 # define native_architecture() ARCHITECTURE_SPARC
137 # define LIB_ARCH_TUPLE "sparc-linux-gnu"
138 #elif defined(__mips64) && defined(__LP64__)
139 # if __BYTE_ORDER == __BIG_ENDIAN
140 # define native_architecture() ARCHITECTURE_MIPS64
141 # define LIB_ARCH_TUPLE "mips64-linux-gnuabi64"
142 # else
143 # define native_architecture() ARCHITECTURE_MIPS64_LE
144 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabi64"
145 # endif
146 #elif defined(__mips64)
147 # if __BYTE_ORDER == __BIG_ENDIAN
148 # define native_architecture() ARCHITECTURE_MIPS64
149 # define LIB_ARCH_TUPLE "mips64-linux-gnuabin32"
150 # else
151 # define native_architecture() ARCHITECTURE_MIPS64_LE
152 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabin32"
153 # endif
154 #elif defined(__mips__)
155 # if __BYTE_ORDER == __BIG_ENDIAN
156 # define native_architecture() ARCHITECTURE_MIPS
157 # define LIB_ARCH_TUPLE "mips-linux-gnu"
158 # else
159 # define native_architecture() ARCHITECTURE_MIPS_LE
160 # define LIB_ARCH_TUPLE "mipsel-linux-gnu"
161 # endif
162 #elif defined(__alpha__)
163 # define native_architecture() ARCHITECTURE_ALPHA
164 # define LIB_ARCH_TUPLE "alpha-linux-gnu"
165 #elif defined(__aarch64__)
166 # if __BYTE_ORDER == __BIG_ENDIAN
167 # define native_architecture() ARCHITECTURE_ARM64_BE
168 # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
169 # else
170 # define native_architecture() ARCHITECTURE_ARM64
171 # define LIB_ARCH_TUPLE "aarch64-linux-gnu"
172 # define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM
173 # endif
174 #elif defined(__arm__)
175 # if __BYTE_ORDER == __BIG_ENDIAN
176 # define native_architecture() ARCHITECTURE_ARM_BE
177 # if defined(__ARM_EABI__)
178 # if defined(__ARM_PCS_VFP)
179 # define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
180 # else
181 # define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
182 # endif
183 # else
184 # define LIB_ARCH_TUPLE "armeb-linux-gnu"
185 # endif
186 # else
187 # define native_architecture() ARCHITECTURE_ARM
188 # if defined(__ARM_EABI__)
189 # if defined(__ARM_PCS_VFP)
190 # define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
191 # else
192 # define LIB_ARCH_TUPLE "arm-linux-gnueabi"
193 # endif
194 # else
195 # define LIB_ARCH_TUPLE "arm-linux-gnu"
196 # endif
197 # endif
198 #elif defined(__sh64__)
199 # define native_architecture() ARCHITECTURE_SH64
200 # error "Missing LIB_ARCH_TUPLE for SH64"
201 #elif defined(__sh__)
202 # define native_architecture() ARCHITECTURE_SH
203 # if defined(__SH1__)
204 # define LIB_ARCH_TUPLE "sh1-linux-gnu"
205 # elif defined(__SH2__)
206 # define LIB_ARCH_TUPLE "sh2-linux-gnu"
207 # elif defined(__SH2A__)
208 # define LIB_ARCH_TUPLE "sh2a-linux-gnu"
209 # elif defined(__SH2E__)
210 # define LIB_ARCH_TUPLE "sh2e-linux-gnu"
211 # elif defined(__SH3__)
212 # define LIB_ARCH_TUPLE "sh3-linux-gnu"
213 # elif defined(__SH3E__)
214 # define LIB_ARCH_TUPLE "sh3e-linux-gnu"
215 # elif defined(__SH4__) && !defined(__SH4A__)
216 # define LIB_ARCH_TUPLE "sh4-linux-gnu"
217 # elif defined(__SH4A__)
218 # define LIB_ARCH_TUPLE "sh4a-linux-gnu"
219 # endif
220 #elif defined(__m68k__)
221 # define native_architecture() ARCHITECTURE_M68K
222 # define LIB_ARCH_TUPLE "m68k-linux-gnu"
223 #elif defined(__tilegx__)
224 # define native_architecture() ARCHITECTURE_TILEGX
225 # define LIB_ARCH_TUPLE "tilegx-linux-gnu"
226 #elif defined(__cris__)
227 # define native_architecture() ARCHITECTURE_CRIS
228 # error "Missing LIB_ARCH_TUPLE for CRIS"
229 #elif defined(__nios2__)
230 # define native_architecture() ARCHITECTURE_NIOS2
231 # define LIB_ARCH_TUPLE "nios2-linux-gnu"
232 #elif defined(__riscv__) || defined(__riscv)
233 /* __riscv__ is obsolete, remove in 2018 */
234 # if __SIZEOF_POINTER__ == 4
235 # define native_architecture() ARCHITECTURE_RISCV32
236 # define LIB_ARCH_TUPLE "riscv32-linux-gnu"
237 # elif __SIZEOF_POINTER__ == 8
238 # define native_architecture() ARCHITECTURE_RISCV64
239 # define LIB_ARCH_TUPLE "riscv64-linux-gnu"
240 # else
241 # error "Unrecognized riscv architecture variant"
242 # endif
243 #elif defined(__arc__)
244 # if __BYTE_ORDER == __BIG_ENDIAN
245 # define native_architecture() ARCHITECTURE_ARC_BE
246 # define LIB_ARCH_TUPLE "arceb-linux"
247 # else
248 # define native_architecture() ARCHITECTURE_ARC
249 # define LIB_ARCH_TUPLE "arc-linux"
250 # endif
251 #else
252 # error "Please register your architecture here!"
253 #endif
254
255 const char *architecture_to_string(int a) _const_;
256 int architecture_from_string(const char *s) _pure_;