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