]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/architecture.h
Merge pull request #4844 from hadess/sensor-quirks
[thirdparty/systemd.git] / src / basic / architecture.h
CommitLineData
099524d7
LP
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
6017365a
LP
22#include <endian.h>
23
a8fbdf54 24#include "macro.h"
099524d7
LP
25#include "util.h"
26
579af519
LP
27/* A cleaned up architecture definition. We don't want to get lost in
28 * processor features, models, generations or even ABIs. Hence we
45afd519 29 * focus on general family, and distinguish word width and
06b643e7 30 * endianness. */
9a00f57a 31
592fd144 32enum {
099524d7
LP
33 ARCHITECTURE_X86 = 0,
34 ARCHITECTURE_X86_64,
35 ARCHITECTURE_PPC,
ae0e60fb 36 ARCHITECTURE_PPC_LE,
099524d7 37 ARCHITECTURE_PPC64,
ae0e60fb 38 ARCHITECTURE_PPC64_LE,
099524d7
LP
39 ARCHITECTURE_IA64,
40 ARCHITECTURE_PARISC,
41 ARCHITECTURE_PARISC64,
42 ARCHITECTURE_S390,
43 ARCHITECTURE_S390X,
44 ARCHITECTURE_SPARC,
45 ARCHITECTURE_SPARC64,
46 ARCHITECTURE_MIPS,
9a00f57a 47 ARCHITECTURE_MIPS_LE,
099524d7 48 ARCHITECTURE_MIPS64,
9a00f57a 49 ARCHITECTURE_MIPS64_LE,
099524d7
LP
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,
46eea341 58 ARCHITECTURE_TILEGX,
86bafac9 59 ARCHITECTURE_CRIS,
b79660e6 60 ARCHITECTURE_NIOS2,
171b5338
RJ
61 ARCHITECTURE_RISCV32,
62 ARCHITECTURE_RISCV64,
099524d7
LP
63 _ARCHITECTURE_MAX,
64 _ARCHITECTURE_INVALID = -1
592fd144 65};
099524d7 66
592fd144 67int uname_architecture(void);
099524d7 68
9a00f57a 69/*
613e3a26
LP
70 * LIB_ARCH_TUPLE should resolve to the local library path
71 * architecture tuple systemd is built for, according to the Debian
72 * tuple list:
9a00f57a
LP
73 *
74 * https://wiki.debian.org/Multiarch/Tuples
75 *
613e3a26
LP
76 * This is used in library search paths that should understand
77 * Debian's paths on all distributions.
9a00f57a
LP
78 */
79
099524d7
LP
80#if defined(__x86_64__)
81# define native_architecture() ARCHITECTURE_X86_64
613e3a26 82# define LIB_ARCH_TUPLE "x86_64-linux-gnu"
0c0fea07 83# define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
099524d7
LP
84#elif defined(__i386__)
85# define native_architecture() ARCHITECTURE_X86
613e3a26 86# define LIB_ARCH_TUPLE "i386-linux-gnu"
099524d7 87#elif defined(__powerpc64__)
4f4b92ba 88# if __BYTE_ORDER == __BIG_ENDIAN
ae0e60fb 89# define native_architecture() ARCHITECTURE_PPC64
613e3a26 90# define LIB_ARCH_TUPLE "ppc64-linux-gnu"
0c0fea07 91# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
ae0e60fb
LP
92# else
93# define native_architecture() ARCHITECTURE_PPC64_LE
37d6781b 94# define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
0c0fea07 95# define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
ae0e60fb 96# endif
099524d7 97#elif defined(__powerpc__)
4f4b92ba 98# if __BYTE_ORDER == __BIG_ENDIAN
ae0e60fb 99# define native_architecture() ARCHITECTURE_PPC
613e3a26 100# define LIB_ARCH_TUPLE "powerpc-linux-gnu"
ae0e60fb
LP
101# else
102# define native_architecture() ARCHITECTURE_PPC_LE
613e3a26 103# error "Missing LIB_ARCH_TUPLE for PPCLE"
ae0e60fb 104# endif
099524d7
LP
105#elif defined(__ia64__)
106# define native_architecture() ARCHITECTURE_IA64
613e3a26 107# define LIB_ARCH_TUPLE "ia64-linux-gnu"
099524d7
LP
108#elif defined(__hppa64__)
109# define native_architecture() ARCHITECTURE_PARISC64
613e3a26 110# error "Missing LIB_ARCH_TUPLE for HPPA64"
099524d7
LP
111#elif defined(__hppa__)
112# define native_architecture() ARCHITECTURE_PARISC
613e3a26 113# define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
099524d7
LP
114#elif defined(__s390x__)
115# define native_architecture() ARCHITECTURE_S390X
613e3a26 116# define LIB_ARCH_TUPLE "s390x-linux-gnu"
0c0fea07 117# define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
099524d7
LP
118#elif defined(__s390__)
119# define native_architecture() ARCHITECTURE_S390
613e3a26 120# define LIB_ARCH_TUPLE "s390-linux-gnu"
cd042078 121#elif defined(__sparc__) && defined (__arch64__)
099524d7 122# define native_architecture() ARCHITECTURE_SPARC64
613e3a26 123# define LIB_ARCH_TUPLE "sparc64-linux-gnu"
099524d7
LP
124#elif defined(__sparc__)
125# define native_architecture() ARCHITECTURE_SPARC
613e3a26 126# define LIB_ARCH_TUPLE "sparc-linux-gnu"
099524d7 127#elif defined(__mips64__)
4f4b92ba 128# if __BYTE_ORDER == __BIG_ENDIAN
9a00f57a 129# define native_architecture() ARCHITECTURE_MIPS64
613e3a26 130# error "Missing LIB_ARCH_TUPLE for MIPS64"
9a00f57a
LP
131# else
132# define native_architecture() ARCHITECTURE_MIPS64_LE
613e3a26 133# error "Missing LIB_ARCH_TUPLE for MIPS64_LE"
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"
099524d7
LP
153# endif
154#elif defined(__arm__)
4f4b92ba 155# if __BYTE_ORDER == __BIG_ENDIAN
099524d7 156# define native_architecture() ARCHITECTURE_ARM_BE
579af519
LP
157# if defined(__ARM_EABI__)
158# if defined(__ARM_PCS_VFP)
159# define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
160# else
161# define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
162# endif
0881d7af 163# else
579af519 164# define LIB_ARCH_TUPLE "armeb-linux-gnu"
0881d7af 165# endif
099524d7 166# else
0881d7af 167# define native_architecture() ARCHITECTURE_ARM
2a9899d8
ZJS
168# if defined(__ARM_EABI__)
169# if defined(__ARM_PCS_VFP)
170# define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
171# else
172# define LIB_ARCH_TUPLE "arm-linux-gnueabi"
173# endif
fd3b401e 174# else
2a9899d8 175# define LIB_ARCH_TUPLE "arm-linux-gnu"
fd3b401e 176# endif
099524d7
LP
177# endif
178#elif defined(__sh64__)
179# define native_architecture() ARCHITECTURE_SH64
613e3a26 180# error "Missing LIB_ARCH_TUPLE for SH64"
099524d7
LP
181#elif defined(__sh__)
182# define native_architecture() ARCHITECTURE_SH
613e3a26 183# define LIB_ARCH_TUPLE "sh4-linux-gnu"
099524d7
LP
184#elif defined(__m68k__)
185# define native_architecture() ARCHITECTURE_M68K
613e3a26 186# define LIB_ARCH_TUPLE "m68k-linux-gnu"
46eea341
HGB
187#elif defined(__tilegx__)
188# define native_architecture() ARCHITECTURE_TILEGX
613e3a26 189# error "Missing LIB_ARCH_TUPLE for TILEGX"
86bafac9
UTL
190#elif defined(__cris__)
191# define native_architecture() ARCHITECTURE_CRIS
613e3a26 192# error "Missing LIB_ARCH_TUPLE for CRIS"
b79660e6
ZJS
193#elif defined(__nios2__)
194# define native_architecture() ARCHITECTURE_NIOS2
195# define LIB_ARCH_TUPLE "nios2-linux-gnu"
171b5338
RJ
196#elif defined(__riscv__)
197# if __SIZEOF_POINTER__ == 4
198# define native_architecture() ARCHITECTURE_RISCV32
199# define LIB_ARCH_TUPLE "riscv32-linux-gnu"
200# elif __SIZEOF_POINTER__ == 8
201# define native_architecture() ARCHITECTURE_RISCV64
202# define LIB_ARCH_TUPLE "riscv64-linux-gnu"
203# else
204# error "Unrecognized riscv architecture variant"
205# endif
099524d7 206#else
568981d2 207# error "Please register your architecture here!"
099524d7
LP
208#endif
209
592fd144
LP
210const char *architecture_to_string(int a) _const_;
211int architecture_from_string(const char *s) _pure_;