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