]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/architecture.h
basic/architecture: Properly set LIB_ARCH_TUPLE for powerpcspe
[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 # if defined(__ILP32__)
83 # define LIB_ARCH_TUPLE "x86_64-linux-gnux32"
84 # else
85 # define LIB_ARCH_TUPLE "x86_64-linux-gnu"
86 # endif
87 # define SECONDARY_ARCHITECTURE ARCHITECTURE_X86
88 #elif defined(__i386__)
89 # define native_architecture() ARCHITECTURE_X86
90 # define LIB_ARCH_TUPLE "i386-linux-gnu"
91 #elif defined(__powerpc64__)
92 # if __BYTE_ORDER == __BIG_ENDIAN
93 # define native_architecture() ARCHITECTURE_PPC64
94 # define LIB_ARCH_TUPLE "ppc64-linux-gnu"
95 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC
96 # else
97 # define native_architecture() ARCHITECTURE_PPC64_LE
98 # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu"
99 # define SECONDARY_ARCHITECTURE ARCHITECTURE_PPC_LE
100 # endif
101 #elif defined(__powerpc__)
102 # if __BYTE_ORDER == __BIG_ENDIAN
103 # define native_architecture() ARCHITECTURE_PPC
104 # if defined(__NO_FPRS__)
105 # define LIB_ARCH_TUPLE "powerpc-linux-gnuspe"
106 # else
107 # define LIB_ARCH_TUPLE "powerpc-linux-gnu"
108 # endif
109 # else
110 # define native_architecture() ARCHITECTURE_PPC_LE
111 # error "Missing LIB_ARCH_TUPLE for PPCLE"
112 # endif
113 #elif defined(__ia64__)
114 # define native_architecture() ARCHITECTURE_IA64
115 # define LIB_ARCH_TUPLE "ia64-linux-gnu"
116 #elif defined(__hppa64__)
117 # define native_architecture() ARCHITECTURE_PARISC64
118 # error "Missing LIB_ARCH_TUPLE for HPPA64"
119 #elif defined(__hppa__)
120 # define native_architecture() ARCHITECTURE_PARISC
121 # define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
122 #elif defined(__s390x__)
123 # define native_architecture() ARCHITECTURE_S390X
124 # define LIB_ARCH_TUPLE "s390x-linux-gnu"
125 # define SECONDARY_ARCHITECTURE ARCHITECTURE_S390
126 #elif defined(__s390__)
127 # define native_architecture() ARCHITECTURE_S390
128 # define LIB_ARCH_TUPLE "s390-linux-gnu"
129 #elif defined(__sparc__) && defined (__arch64__)
130 # define native_architecture() ARCHITECTURE_SPARC64
131 # define LIB_ARCH_TUPLE "sparc64-linux-gnu"
132 #elif defined(__sparc__)
133 # define native_architecture() ARCHITECTURE_SPARC
134 # define LIB_ARCH_TUPLE "sparc-linux-gnu"
135 #elif defined(__mips64) && defined(__LP64__)
136 # if __BYTE_ORDER == __BIG_ENDIAN
137 # define native_architecture() ARCHITECTURE_MIPS64
138 # define LIB_ARCH_TUPLE "mips64-linux-gnuabi64"
139 # else
140 # define native_architecture() ARCHITECTURE_MIPS64_LE
141 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabi64"
142 # endif
143 #elif defined(__mips64)
144 # if __BYTE_ORDER == __BIG_ENDIAN
145 # define native_architecture() ARCHITECTURE_MIPS64
146 # define LIB_ARCH_TUPLE "mips64-linux-gnuabin32"
147 # else
148 # define native_architecture() ARCHITECTURE_MIPS64_LE
149 # define LIB_ARCH_TUPLE "mips64el-linux-gnuabin32"
150 # endif
151 #elif defined(__mips__)
152 # if __BYTE_ORDER == __BIG_ENDIAN
153 # define native_architecture() ARCHITECTURE_MIPS
154 # define LIB_ARCH_TUPLE "mips-linux-gnu"
155 # else
156 # define native_architecture() ARCHITECTURE_MIPS_LE
157 # define LIB_ARCH_TUPLE "mipsel-linux-gnu"
158 # endif
159 #elif defined(__alpha__)
160 # define native_architecture() ARCHITECTURE_ALPHA
161 # define LIB_ARCH_TUPLE "alpha-linux-gnu"
162 #elif defined(__aarch64__)
163 # if __BYTE_ORDER == __BIG_ENDIAN
164 # define native_architecture() ARCHITECTURE_ARM64_BE
165 # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
166 # else
167 # define native_architecture() ARCHITECTURE_ARM64
168 # define LIB_ARCH_TUPLE "aarch64-linux-gnu"
169 # define SECONDARY_ARCHITECTURE ARCHITECTURE_ARM
170 # endif
171 #elif defined(__arm__)
172 # if __BYTE_ORDER == __BIG_ENDIAN
173 # define native_architecture() ARCHITECTURE_ARM_BE
174 # if defined(__ARM_EABI__)
175 # if defined(__ARM_PCS_VFP)
176 # define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
177 # else
178 # define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
179 # endif
180 # else
181 # define LIB_ARCH_TUPLE "armeb-linux-gnu"
182 # endif
183 # else
184 # define native_architecture() ARCHITECTURE_ARM
185 # if defined(__ARM_EABI__)
186 # if defined(__ARM_PCS_VFP)
187 # define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
188 # else
189 # define LIB_ARCH_TUPLE "arm-linux-gnueabi"
190 # endif
191 # else
192 # define LIB_ARCH_TUPLE "arm-linux-gnu"
193 # endif
194 # endif
195 #elif defined(__sh64__)
196 # define native_architecture() ARCHITECTURE_SH64
197 # error "Missing LIB_ARCH_TUPLE for SH64"
198 #elif defined(__sh__)
199 # define native_architecture() ARCHITECTURE_SH
200 # define LIB_ARCH_TUPLE "sh4-linux-gnu"
201 #elif defined(__m68k__)
202 # define native_architecture() ARCHITECTURE_M68K
203 # define LIB_ARCH_TUPLE "m68k-linux-gnu"
204 #elif defined(__tilegx__)
205 # define native_architecture() ARCHITECTURE_TILEGX
206 # define LIB_ARCH_TUPLE "tilegx-linux-gnu"
207 #elif defined(__cris__)
208 # define native_architecture() ARCHITECTURE_CRIS
209 # error "Missing LIB_ARCH_TUPLE for CRIS"
210 #elif defined(__nios2__)
211 # define native_architecture() ARCHITECTURE_NIOS2
212 # define LIB_ARCH_TUPLE "nios2-linux-gnu"
213 #elif defined(__riscv__) || defined(__riscv)
214 /* __riscv__ is obsolete, remove in 2018 */
215 # if __SIZEOF_POINTER__ == 4
216 # define native_architecture() ARCHITECTURE_RISCV32
217 # define LIB_ARCH_TUPLE "riscv32-linux-gnu"
218 # elif __SIZEOF_POINTER__ == 8
219 # define native_architecture() ARCHITECTURE_RISCV64
220 # define LIB_ARCH_TUPLE "riscv64-linux-gnu"
221 # else
222 # error "Unrecognized riscv architecture variant"
223 # endif
224 #else
225 # error "Please register your architecture here!"
226 #endif
227
228 const char *architecture_to_string(int a) _const_;
229 int architecture_from_string(const char *s) _pure_;