]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/architecture.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / architecture.h
CommitLineData
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
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
6017365a
LP
23#include <endian.h>
24
a8fbdf54 25#include "macro.h"
099524d7
LP
26#include "util.h"
27
579af519
LP
28/* A cleaned up architecture definition. We don't want to get lost in
29 * processor features, models, generations or even ABIs. Hence we
45afd519 30 * focus on general family, and distinguish word width and
06b643e7 31 * endianness. */
9a00f57a 32
592fd144 33enum {
099524d7
LP
34 ARCHITECTURE_X86 = 0,
35 ARCHITECTURE_X86_64,
36 ARCHITECTURE_PPC,
ae0e60fb 37 ARCHITECTURE_PPC_LE,
099524d7 38 ARCHITECTURE_PPC64,
ae0e60fb 39 ARCHITECTURE_PPC64_LE,
099524d7
LP
40 ARCHITECTURE_IA64,
41 ARCHITECTURE_PARISC,
42 ARCHITECTURE_PARISC64,
43 ARCHITECTURE_S390,
44 ARCHITECTURE_S390X,
45 ARCHITECTURE_SPARC,
46 ARCHITECTURE_SPARC64,
47 ARCHITECTURE_MIPS,
9a00f57a 48 ARCHITECTURE_MIPS_LE,
099524d7 49 ARCHITECTURE_MIPS64,
9a00f57a 50 ARCHITECTURE_MIPS64_LE,
099524d7
LP
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,
46eea341 59 ARCHITECTURE_TILEGX,
86bafac9 60 ARCHITECTURE_CRIS,
b79660e6 61 ARCHITECTURE_NIOS2,
171b5338
RJ
62 ARCHITECTURE_RISCV32,
63 ARCHITECTURE_RISCV64,
27b09f1f
AB
64 ARCHITECTURE_ARC,
65 ARCHITECTURE_ARC_BE,
099524d7
LP
66 _ARCHITECTURE_MAX,
67 _ARCHITECTURE_INVALID = -1
592fd144 68};
099524d7 69
592fd144 70int uname_architecture(void);
099524d7 71
9a00f57a 72/*
613e3a26
LP
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:
9a00f57a
LP
76 *
77 * https://wiki.debian.org/Multiarch/Tuples
78 *
613e3a26
LP
79 * This is used in library search paths that should understand
80 * Debian's paths on all distributions.
9a00f57a
LP
81 */
82
099524d7
LP
83#if defined(__x86_64__)
84# define native_architecture() ARCHITECTURE_X86_64
4c7c70c7
JPAG
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
0c0fea07 90# define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
099524d7
LP
91#elif defined(__i386__)
92# define native_architecture() ARCHITECTURE_X86
613e3a26 93# define LIB_ARCH_TUPLE "i386-linux-gnu"
099524d7 94#elif defined(__powerpc64__)
4f4b92ba 95# if __BYTE_ORDER == __BIG_ENDIAN
ae0e60fb 96# define native_architecture() ARCHITECTURE_PPC64
613e3a26 97# define LIB_ARCH_TUPLE "ppc64-linux-gnu"
0c0fea07 98# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
ae0e60fb
LP
99# else
100# define native_architecture() ARCHITECTURE_PPC64_LE
37d6781b 101# define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
0c0fea07 102# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
ae0e60fb 103# endif
099524d7 104#elif defined(__powerpc__)
4f4b92ba 105# if __BYTE_ORDER == __BIG_ENDIAN
ae0e60fb 106# define native_architecture() ARCHITECTURE_PPC
202145c0
JPAG
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
ae0e60fb
LP
112# else
113# define native_architecture() ARCHITECTURE_PPC_LE
613e3a26 114# error "Missing LIB_ARCH_TUPLE for PPCLE"
ae0e60fb 115# endif
099524d7
LP
116#elif defined(__ia64__)
117# define native_architecture() ARCHITECTURE_IA64
613e3a26 118# define LIB_ARCH_TUPLE "ia64-linux-gnu"
099524d7
LP
119#elif defined(__hppa64__)
120# define native_architecture() ARCHITECTURE_PARISC64
613e3a26 121# error "Missing LIB_ARCH_TUPLE for HPPA64"
099524d7
LP
122#elif defined(__hppa__)
123# define native_architecture() ARCHITECTURE_PARISC
613e3a26 124# define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
099524d7
LP
125#elif defined(__s390x__)
126# define native_architecture() ARCHITECTURE_S390X
613e3a26 127# define LIB_ARCH_TUPLE "s390x-linux-gnu"
0c0fea07 128# define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
099524d7
LP
129#elif defined(__s390__)
130# define native_architecture() ARCHITECTURE_S390
613e3a26 131# define LIB_ARCH_TUPLE "s390-linux-gnu"
cd042078 132#elif defined(__sparc__) && defined (__arch64__)
099524d7 133# define native_architecture() ARCHITECTURE_SPARC64
613e3a26 134# define LIB_ARCH_TUPLE "sparc64-linux-gnu"
099524d7
LP
135#elif defined(__sparc__)
136# define native_architecture() ARCHITECTURE_SPARC
613e3a26 137# define LIB_ARCH_TUPLE "sparc-linux-gnu"
caf49b95 138#elif defined(__mips64) && defined(__LP64__)
4f4b92ba 139# if __BYTE_ORDER == __BIG_ENDIAN
9a00f57a 140# define native_architecture() ARCHITECTURE_MIPS64
caf49b95 141# define LIB_ARCH_TUPLE "mips64-linux-gnuabi64"
9a00f57a
LP
142# else
143# define native_architecture() ARCHITECTURE_MIPS64_LE
caf49b95
YS
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"
9a00f57a 153# endif
099524d7 154#elif defined(__mips__)
4f4b92ba 155# if __BYTE_ORDER == __BIG_ENDIAN
9a00f57a 156# define native_architecture() ARCHITECTURE_MIPS
613e3a26 157# define LIB_ARCH_TUPLE "mips-linux-gnu"
9a00f57a
LP
158# else
159# define native_architecture() ARCHITECTURE_MIPS_LE
613e3a26 160# define LIB_ARCH_TUPLE "mipsel-linux-gnu"
568981d2 161# endif
099524d7
LP
162#elif defined(__alpha__)
163# define native_architecture() ARCHITECTURE_ALPHA
613e3a26 164# define LIB_ARCH_TUPLE "alpha-linux-gnu"
099524d7 165#elif defined(__aarch64__)
4f4b92ba 166# if __BYTE_ORDER == __BIG_ENDIAN
099524d7 167# define native_architecture() ARCHITECTURE_ARM64_BE
613e3a26 168# define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
099524d7
LP
169# else
170# define native_architecture() ARCHITECTURE_ARM64
613e3a26 171# define LIB_ARCH_TUPLE "aarch64-linux-gnu"
b7cac527 172# define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM
099524d7
LP
173# endif
174#elif defined(__arm__)
4f4b92ba 175# if __BYTE_ORDER == __BIG_ENDIAN
099524d7 176# define native_architecture() ARCHITECTURE_ARM_BE
579af519
LP
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
0881d7af 183# else
579af519 184# define LIB_ARCH_TUPLE "armeb-linux-gnu"
0881d7af 185# endif
099524d7 186# else
0881d7af 187# define native_architecture() ARCHITECTURE_ARM
2a9899d8
ZJS
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
fd3b401e 194# else
2a9899d8 195# define LIB_ARCH_TUPLE "arm-linux-gnu"
fd3b401e 196# endif
099524d7
LP
197# endif
198#elif defined(__sh64__)
199# define native_architecture() ARCHITECTURE_SH64
613e3a26 200# error "Missing LIB_ARCH_TUPLE for SH64"
099524d7
LP
201#elif defined(__sh__)
202# define native_architecture() ARCHITECTURE_SH
9da2a0ac
JPAG
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
099524d7
LP
220#elif defined(__m68k__)
221# define native_architecture() ARCHITECTURE_M68K
613e3a26 222# define LIB_ARCH_TUPLE "m68k-linux-gnu"
46eea341
HGB
223#elif defined(__tilegx__)
224# define native_architecture() ARCHITECTURE_TILEGX
b1caafb2 225# define LIB_ARCH_TUPLE "tilegx-linux-gnu"
86bafac9
UTL
226#elif defined(__cris__)
227# define native_architecture() ARCHITECTURE_CRIS
613e3a26 228# error "Missing LIB_ARCH_TUPLE for CRIS"
b79660e6
ZJS
229#elif defined(__nios2__)
230# define native_architecture() ARCHITECTURE_NIOS2
231# define LIB_ARCH_TUPLE "nios2-linux-gnu"
680a752c
ZJS
232#elif defined(__riscv__) || defined(__riscv)
233 /* __riscv__ is obsolete, remove in 2018 */
171b5338
RJ
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
27b09f1f
AB
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
099524d7 251#else
568981d2 252# error "Please register your architecture here!"
099524d7
LP
253#endif
254
592fd144
LP
255const char *architecture_to_string(int a) _const_;
256int architecture_from_string(const char *s) _pure_;