]>
Commit | Line | Data |
---|---|---|
099524d7 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | #pragma once | |
4 | ||
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2014 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
11 | under the terms of the GNU Lesser General Public License as published by | |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | Lesser General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU Lesser General Public License | |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
22 | ***/ | |
23 | ||
6017365a LP |
24 | #include <endian.h> |
25 | ||
099524d7 LP |
26 | #include "util.h" |
27 | ||
579af519 LP |
28 | /* A cleaned up architecture definition. We don't want to get lost in |
29 | * processor features, models, generations or even ABIs. Hence we | |
30 | * focus on general family, and distuignish word width and | |
06b643e7 | 31 | * endianness. */ |
9a00f57a | 32 | |
099524d7 LP |
33 | typedef enum Architecture { |
34 | ARCHITECTURE_X86 = 0, | |
35 | ARCHITECTURE_X86_64, | |
36 | ARCHITECTURE_PPC, | |
ae0e60fb | 37 | ARCHITECTURE_PPC_LE, |
099524d7 | 38 | ARCHITECTURE_PPC64, |
ae0e60fb | 39 | ARCHITECTURE_PPC64_LE, |
099524d7 LP |
40 | ARCHITECTURE_IA64, |
41 | ARCHITECTURE_PARISC, | |
42 | ARCHITECTURE_PARISC64, | |
43 | ARCHITECTURE_S390, | |
44 | ARCHITECTURE_S390X, | |
45 | ARCHITECTURE_SPARC, | |
46 | ARCHITECTURE_SPARC64, | |
47 | ARCHITECTURE_MIPS, | |
9a00f57a | 48 | ARCHITECTURE_MIPS_LE, |
099524d7 | 49 | ARCHITECTURE_MIPS64, |
9a00f57a | 50 | ARCHITECTURE_MIPS64_LE, |
099524d7 LP |
51 | ARCHITECTURE_ALPHA, |
52 | ARCHITECTURE_ARM, | |
53 | ARCHITECTURE_ARM_BE, | |
54 | ARCHITECTURE_ARM64, | |
55 | ARCHITECTURE_ARM64_BE, | |
56 | ARCHITECTURE_SH, | |
57 | ARCHITECTURE_SH64, | |
58 | ARCHITECTURE_M68K, | |
46eea341 | 59 | ARCHITECTURE_TILEGX, |
86bafac9 | 60 | ARCHITECTURE_CRIS, |
099524d7 LP |
61 | _ARCHITECTURE_MAX, |
62 | _ARCHITECTURE_INVALID = -1 | |
63 | } Architecture; | |
64 | ||
65 | Architecture uname_architecture(void); | |
66 | ||
9a00f57a | 67 | /* |
613e3a26 LP |
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: | |
9a00f57a LP |
71 | * |
72 | * https://wiki.debian.org/Multiarch/Tuples | |
73 | * | |
613e3a26 LP |
74 | * This is used in library search paths that should understand |
75 | * Debian's paths on all distributions. | |
9a00f57a LP |
76 | */ |
77 | ||
099524d7 LP |
78 | #if defined(__x86_64__) |
79 | # define native_architecture() ARCHITECTURE_X86_64 | |
613e3a26 | 80 | # define LIB_ARCH_TUPLE "x86_64-linux-gnu" |
099524d7 LP |
81 | #elif defined(__i386__) |
82 | # define native_architecture() ARCHITECTURE_X86 | |
613e3a26 | 83 | # define LIB_ARCH_TUPLE "i386-linux-gnu" |
099524d7 | 84 | #elif defined(__powerpc64__) |
4f4b92ba | 85 | # if __BYTE_ORDER == __BIG_ENDIAN |
ae0e60fb | 86 | # define native_architecture() ARCHITECTURE_PPC64 |
613e3a26 | 87 | # define LIB_ARCH_TUPLE "ppc64-linux-gnu" |
ae0e60fb LP |
88 | # else |
89 | # define native_architecture() ARCHITECTURE_PPC64_LE | |
37d6781b | 90 | # define LIB_ARCH_TUPLE "powerpc64le-linux-gnu" |
ae0e60fb | 91 | # endif |
099524d7 | 92 | #elif defined(__powerpc__) |
4f4b92ba | 93 | # if __BYTE_ORDER == __BIG_ENDIAN |
ae0e60fb | 94 | # define native_architecture() ARCHITECTURE_PPC |
613e3a26 | 95 | # define LIB_ARCH_TUPLE "powerpc-linux-gnu" |
ae0e60fb LP |
96 | # else |
97 | # define native_architecture() ARCHITECTURE_PPC_LE | |
613e3a26 | 98 | # error "Missing LIB_ARCH_TUPLE for PPCLE" |
ae0e60fb | 99 | # endif |
099524d7 LP |
100 | #elif defined(__ia64__) |
101 | # define native_architecture() ARCHITECTURE_IA64 | |
613e3a26 | 102 | # define LIB_ARCH_TUPLE "ia64-linux-gnu" |
099524d7 LP |
103 | #elif defined(__hppa64__) |
104 | # define native_architecture() ARCHITECTURE_PARISC64 | |
613e3a26 | 105 | # error "Missing LIB_ARCH_TUPLE for HPPA64" |
099524d7 LP |
106 | #elif defined(__hppa__) |
107 | # define native_architecture() ARCHITECTURE_PARISC | |
613e3a26 | 108 | # define LIB_ARCH_TUPLE "hppa‑linux‑gnu" |
099524d7 LP |
109 | #elif defined(__s390x__) |
110 | # define native_architecture() ARCHITECTURE_S390X | |
613e3a26 | 111 | # define LIB_ARCH_TUPLE "s390x-linux-gnu" |
099524d7 LP |
112 | #elif defined(__s390__) |
113 | # define native_architecture() ARCHITECTURE_S390 | |
613e3a26 | 114 | # define LIB_ARCH_TUPLE "s390-linux-gnu" |
099524d7 LP |
115 | #elif defined(__sparc64__) |
116 | # define native_architecture() ARCHITECTURE_SPARC64 | |
613e3a26 | 117 | # define LIB_ARCH_TUPLE "sparc64-linux-gnu" |
099524d7 LP |
118 | #elif defined(__sparc__) |
119 | # define native_architecture() ARCHITECTURE_SPARC | |
613e3a26 | 120 | # define LIB_ARCH_TUPLE "sparc-linux-gnu" |
099524d7 | 121 | #elif defined(__mips64__) |
4f4b92ba | 122 | # if __BYTE_ORDER == __BIG_ENDIAN |
9a00f57a | 123 | # define native_architecture() ARCHITECTURE_MIPS64 |
613e3a26 | 124 | # error "Missing LIB_ARCH_TUPLE for MIPS64" |
9a00f57a LP |
125 | # else |
126 | # define native_architecture() ARCHITECTURE_MIPS64_LE | |
613e3a26 | 127 | # error "Missing LIB_ARCH_TUPLE for MIPS64_LE" |
9a00f57a | 128 | # endif |
099524d7 | 129 | #elif defined(__mips__) |
4f4b92ba | 130 | # if __BYTE_ORDER == __BIG_ENDIAN |
9a00f57a | 131 | # define native_architecture() ARCHITECTURE_MIPS |
613e3a26 | 132 | # define LIB_ARCH_TUPLE "mips-linux-gnu" |
9a00f57a LP |
133 | # else |
134 | # define native_architecture() ARCHITECTURE_MIPS_LE | |
613e3a26 | 135 | # define LIB_ARCH_TUPLE "mipsel-linux-gnu" |
9a00f57a | 136 | #endif |
099524d7 LP |
137 | #elif defined(__alpha__) |
138 | # define native_architecture() ARCHITECTURE_ALPHA | |
613e3a26 | 139 | # define LIB_ARCH_TUPLE "alpha-linux-gnu" |
099524d7 | 140 | #elif defined(__aarch64__) |
4f4b92ba | 141 | # if __BYTE_ORDER == __BIG_ENDIAN |
099524d7 | 142 | # define native_architecture() ARCHITECTURE_ARM64_BE |
613e3a26 | 143 | # define LIB_ARCH_TUPLE "aarch64_be-linux-gnu" |
099524d7 LP |
144 | # else |
145 | # define native_architecture() ARCHITECTURE_ARM64 | |
613e3a26 | 146 | # define LIB_ARCH_TUPLE "aarch64-linux-gnu" |
099524d7 LP |
147 | # endif |
148 | #elif defined(__arm__) | |
4f4b92ba | 149 | # if __BYTE_ORDER == __BIG_ENDIAN |
099524d7 | 150 | # define native_architecture() ARCHITECTURE_ARM_BE |
579af519 LP |
151 | # if defined(__ARM_EABI__) |
152 | # if defined(__ARM_PCS_VFP) | |
153 | # define LIB_ARCH_TUPLE "armeb-linux-gnueabihf" | |
154 | # else | |
155 | # define LIB_ARCH_TUPLE "armeb-linux-gnueabi" | |
156 | # endif | |
0881d7af | 157 | # else |
579af519 | 158 | # define LIB_ARCH_TUPLE "armeb-linux-gnu" |
0881d7af | 159 | # endif |
099524d7 | 160 | # else |
0881d7af | 161 | # define native_architecture() ARCHITECTURE_ARM |
2a9899d8 ZJS |
162 | # if defined(__ARM_EABI__) |
163 | # if defined(__ARM_PCS_VFP) | |
164 | # define LIB_ARCH_TUPLE "arm-linux-gnueabihf" | |
165 | # else | |
166 | # define LIB_ARCH_TUPLE "arm-linux-gnueabi" | |
167 | # endif | |
fd3b401e | 168 | # else |
2a9899d8 | 169 | # define LIB_ARCH_TUPLE "arm-linux-gnu" |
fd3b401e | 170 | # endif |
099524d7 LP |
171 | # endif |
172 | #elif defined(__sh64__) | |
173 | # define native_architecture() ARCHITECTURE_SH64 | |
613e3a26 | 174 | # error "Missing LIB_ARCH_TUPLE for SH64" |
099524d7 LP |
175 | #elif defined(__sh__) |
176 | # define native_architecture() ARCHITECTURE_SH | |
613e3a26 | 177 | # define LIB_ARCH_TUPLE "sh4-linux-gnu" |
099524d7 LP |
178 | #elif defined(__m68k__) |
179 | # define native_architecture() ARCHITECTURE_M68K | |
613e3a26 | 180 | # define LIB_ARCH_TUPLE "m68k-linux-gnu" |
46eea341 HGB |
181 | #elif defined(__tilegx__) |
182 | # define native_architecture() ARCHITECTURE_TILEGX | |
613e3a26 | 183 | # error "Missing LIB_ARCH_TUPLE for TILEGX" |
86bafac9 UTL |
184 | #elif defined(__cris__) |
185 | # define native_architecture() ARCHITECTURE_CRIS | |
613e3a26 | 186 | # error "Missing LIB_ARCH_TUPLE for CRIS" |
099524d7 LP |
187 | #else |
188 | #error "Please register your architecture here!" | |
189 | #endif | |
190 | ||
191 | const char *architecture_to_string(Architecture a) _const_; | |
192 | Architecture architecture_from_string(const char *s) _pure_; |