]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/architecture.h
Merge pull request #4867 from keszybz/catalog-messages
[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_MAX,
64 _ARCHITECTURE_INVALID = -1
65 };
66
67 int uname_architecture(void);
68
69 /*
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:
73 *
74 * https://wiki.debian.org/Multiarch/Tuples
75 *
76 * This is used in library search paths that should understand
77 * Debian's paths on all distributions.
78 */
79
80 #if defined(__x86_64__)
81 # define native_architecture() ARCHITECTURE_X86_64
82 # define LIB_ARCH_TUPLE "x86_64-linux-gnu"
83 # define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
84 #elif defined(__i386__)
85 # define native_architecture() ARCHITECTURE_X86
86 # define LIB_ARCH_TUPLE "i386-linux-gnu"
87 #elif defined(__powerpc64__)
88 # if __BYTE_ORDER == __BIG_ENDIAN
89 # define native_architecture() ARCHITECTURE_PPC64
90 # define LIB_ARCH_TUPLE "ppc64-linux-gnu"
91 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
92 # else
93 # define native_architecture() ARCHITECTURE_PPC64_LE
94 # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
95 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
96 # endif
97 #elif defined(__powerpc__)
98 # if __BYTE_ORDER == __BIG_ENDIAN
99 # define native_architecture() ARCHITECTURE_PPC
100 # define LIB_ARCH_TUPLE "powerpc-linux-gnu"
101 # else
102 # define native_architecture() ARCHITECTURE_PPC_LE
103 # error "Missing LIB_ARCH_TUPLE for PPCLE"
104 # endif
105 #elif defined(__ia64__)
106 # define native_architecture() ARCHITECTURE_IA64
107 # define LIB_ARCH_TUPLE "ia64-linux-gnu"
108 #elif defined(__hppa64__)
109 # define native_architecture() ARCHITECTURE_PARISC64
110 # error "Missing LIB_ARCH_TUPLE for HPPA64"
111 #elif defined(__hppa__)
112 # define native_architecture() ARCHITECTURE_PARISC
113 # define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
114 #elif defined(__s390x__)
115 # define native_architecture() ARCHITECTURE_S390X
116 # define LIB_ARCH_TUPLE "s390x-linux-gnu"
117 # define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
118 #elif defined(__s390__)
119 # define native_architecture() ARCHITECTURE_S390
120 # define LIB_ARCH_TUPLE "s390-linux-gnu"
121 #elif defined(__sparc__) && defined (__arch64__)
122 # define native_architecture() ARCHITECTURE_SPARC64
123 # define LIB_ARCH_TUPLE "sparc64-linux-gnu"
124 #elif defined(__sparc__)
125 # define native_architecture() ARCHITECTURE_SPARC
126 # define LIB_ARCH_TUPLE "sparc-linux-gnu"
127 #elif defined(__mips64__)
128 # if __BYTE_ORDER == __BIG_ENDIAN
129 # define native_architecture() ARCHITECTURE_MIPS64
130 # error "Missing LIB_ARCH_TUPLE for MIPS64"
131 # else
132 # define native_architecture() ARCHITECTURE_MIPS64_LE
133 # error "Missing LIB_ARCH_TUPLE for MIPS64_LE"
134 # endif
135 #elif defined(__mips__)
136 # if __BYTE_ORDER == __BIG_ENDIAN
137 # define native_architecture() ARCHITECTURE_MIPS
138 # define LIB_ARCH_TUPLE "mips-linux-gnu"
139 # else
140 # define native_architecture() ARCHITECTURE_MIPS_LE
141 # define LIB_ARCH_TUPLE "mipsel-linux-gnu"
142 # endif
143 #elif defined(__alpha__)
144 # define native_architecture() ARCHITECTURE_ALPHA
145 # define LIB_ARCH_TUPLE "alpha-linux-gnu"
146 #elif defined(__aarch64__)
147 # if __BYTE_ORDER == __BIG_ENDIAN
148 # define native_architecture() ARCHITECTURE_ARM64_BE
149 # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
150 # else
151 # define native_architecture() ARCHITECTURE_ARM64
152 # define LIB_ARCH_TUPLE "aarch64-linux-gnu"
153 # define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM
154 # endif
155 #elif defined(__arm__)
156 # if __BYTE_ORDER == __BIG_ENDIAN
157 # define native_architecture() ARCHITECTURE_ARM_BE
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
164 # else
165 # define LIB_ARCH_TUPLE "armeb-linux-gnu"
166 # endif
167 # else
168 # define native_architecture() ARCHITECTURE_ARM
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
175 # else
176 # define LIB_ARCH_TUPLE "arm-linux-gnu"
177 # endif
178 # endif
179 #elif defined(__sh64__)
180 # define native_architecture() ARCHITECTURE_SH64
181 # error "Missing LIB_ARCH_TUPLE for SH64"
182 #elif defined(__sh__)
183 # define native_architecture() ARCHITECTURE_SH
184 # define LIB_ARCH_TUPLE "sh4-linux-gnu"
185 #elif defined(__m68k__)
186 # define native_architecture() ARCHITECTURE_M68K
187 # define LIB_ARCH_TUPLE "m68k-linux-gnu"
188 #elif defined(__tilegx__)
189 # define native_architecture() ARCHITECTURE_TILEGX
190 # error "Missing LIB_ARCH_TUPLE for TILEGX"
191 #elif defined(__cris__)
192 # define native_architecture() ARCHITECTURE_CRIS
193 # error "Missing LIB_ARCH_TUPLE for CRIS"
194 #elif defined(__nios2__)
195 # define native_architecture() ARCHITECTURE_NIOS2
196 # define LIB_ARCH_TUPLE "nios2-linux-gnu"
197 #elif defined(__riscv__)
198 # if __SIZEOF_POINTER__ == 4
199 # define native_architecture() ARCHITECTURE_RISCV32
200 # define LIB_ARCH_TUPLE "riscv32-linux-gnu"
201 # elif __SIZEOF_POINTER__ == 8
202 # define native_architecture() ARCHITECTURE_RISCV64
203 # define LIB_ARCH_TUPLE "riscv64-linux-gnu"
204 # else
205 # error "Unrecognized riscv architecture variant"
206 # endif
207 #else
208 # error "Please register your architecture here!"
209 #endif
210
211 const char *architecture_to_string(int a) _const_;
212 int architecture_from_string(const char *s) _pure_;