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