chiark / gitweb /
always check for __BYTE_ORDER == __BIG_ENDIAN when checking for endianess
[elogind.git] / src / shared / architecture.h
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
24 #include "util.h"
25
26 /* A cleaned up architecture definition. We don't want to get lost in
27  * processor features, models, generations or even ABIs. Hence we
28  * focus on general family, and distuignish word width and
29  * endianess. */
30
31 typedef enum Architecture {
32         ARCHITECTURE_X86 = 0,
33         ARCHITECTURE_X86_64,
34         ARCHITECTURE_PPC,
35         ARCHITECTURE_PPC_LE,
36         ARCHITECTURE_PPC64,
37         ARCHITECTURE_PPC64_LE,
38         ARCHITECTURE_IA64,
39         ARCHITECTURE_PARISC,
40         ARCHITECTURE_PARISC64,
41         ARCHITECTURE_S390,
42         ARCHITECTURE_S390X,
43         ARCHITECTURE_SPARC,
44         ARCHITECTURE_SPARC64,
45         ARCHITECTURE_MIPS,
46         ARCHITECTURE_MIPS_LE,
47         ARCHITECTURE_MIPS64,
48         ARCHITECTURE_MIPS64_LE,
49         ARCHITECTURE_ALPHA,
50         ARCHITECTURE_ARM,
51         ARCHITECTURE_ARM_BE,
52         ARCHITECTURE_ARM64,
53         ARCHITECTURE_ARM64_BE,
54         ARCHITECTURE_SH,
55         ARCHITECTURE_SH64,
56         ARCHITECTURE_M68K,
57         ARCHITECTURE_TILEGX,
58         ARCHITECTURE_CRIS,
59         _ARCHITECTURE_MAX,
60         _ARCHITECTURE_INVALID = -1
61 } Architecture;
62
63 Architecture uname_architecture(void);
64
65 /*
66  * LIB_ARCH_TUPLE should resolve to the local library path
67  * architecture tuple systemd is built for, according to the Debian
68  * tuple list:
69  *
70  * https://wiki.debian.org/Multiarch/Tuples
71  *
72  * This is used in library search paths that should understand
73  * Debian's paths on all distributions.
74  */
75
76 #if defined(__x86_64__)
77 #  define native_architecture() ARCHITECTURE_X86_64
78 #  define LIB_ARCH_TUPLE "x86_64-linux-gnu"
79 #elif defined(__i386__)
80 #  define native_architecture() ARCHITECTURE_X86
81 #  define LIB_ARCH_TUPLE "i386-linux-gnu"
82 #elif defined(__powerpc64__)
83 #  if __BYTE_ORDER == __BIG_ENDIAN
84 #    define native_architecture() ARCHITECTURE_PPC64
85 #    define LIB_ARCH_TUPLE "ppc64-linux-gnu"
86 #  else
87 #    define native_architecture() ARCHITECTURE_PPC64_LE
88 #    error "Missing LIB_ARCH_TUPLE for PPC64LE"
89 #  endif
90 #elif defined(__powerpc__)
91 #  if __BYTE_ORDER == __BIG_ENDIAN
92 #    define native_architecture() ARCHITECTURE_PPC
93 #    define LIB_ARCH_TUPLE "powerpc-linux-gnu"
94 #  else
95 #    define native_architecture() ARCHITECTURE_PPC_LE
96 #    error "Missing LIB_ARCH_TUPLE for PPCLE"
97 #  endif
98 #elif defined(__ia64__)
99 #  define native_architecture() ARCHITECTURE_IA64
100 #  define LIB_ARCH_TUPLE "ia64-linux-gnu"
101 #elif defined(__hppa64__)
102 #  define native_architecture() ARCHITECTURE_PARISC64
103 #  error "Missing LIB_ARCH_TUPLE for HPPA64"
104 #elif defined(__hppa__)
105 #  define native_architecture() ARCHITECTURE_PARISC
106 #  define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
107 #elif defined(__s390x__)
108 #  define native_architecture() ARCHITECTURE_S390X
109 #  define LIB_ARCH_TUPLE "s390x-linux-gnu"
110 #elif defined(__s390__)
111 #  define native_architecture() ARCHITECTURE_S390
112 #  define LIB_ARCH_TUPLE "s390-linux-gnu"
113 #elif defined(__sparc64__)
114 #  define native_architecture() ARCHITECTURE_SPARC64
115 #  define LIB_ARCH_TUPLE "sparc64-linux-gnu"
116 #elif defined(__sparc__)
117 #  define native_architecture() ARCHITECTURE_SPARC
118 #  define LIB_ARCH_TUPLE "sparc-linux-gnu"
119 #elif defined(__mips64__)
120 #  if __BYTE_ORDER == __BIG_ENDIAN
121 #    define native_architecture() ARCHITECTURE_MIPS64
122 #    error "Missing LIB_ARCH_TUPLE for MIPS64"
123 #  else
124 #    define native_architecture() ARCHITECTURE_MIPS64_LE
125 #    error "Missing LIB_ARCH_TUPLE for MIPS64_LE"
126 #  endif
127 #elif defined(__mips__)
128 #  if __BYTE_ORDER == __BIG_ENDIAN
129 #    define native_architecture() ARCHITECTURE_MIPS
130 #    define LIB_ARCH_TUPLE "mips-linux-gnu"
131 #  else
132 #    define native_architecture() ARCHITECTURE_MIPS_LE
133 #    define LIB_ARCH_TUPLE "mipsel-linux-gnu"
134 #endif
135 #elif defined(__alpha__)
136 #  define native_architecture() ARCHITECTURE_ALPHA
137 #  define LIB_ARCH_TUPLE "alpha-linux-gnu"
138 #elif defined(__aarch64__)
139 #  if __BYTE_ORDER == __BIG_ENDIAN
140 #    define native_architecture() ARCHITECTURE_ARM64_BE
141 #    define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
142 #  else
143 #    define native_architecture() ARCHITECTURE_ARM64
144 #    define LIB_ARCH_TUPLE "aarch64-linux-gnu"
145 #  endif
146 #elif defined(__arm__)
147 #  if __BYTE_ORDER == __BIG_ENDIAN
148 #    define native_architecture() ARCHITECTURE_ARM_BE
149 #    if defined(__ARM_EABI__)
150 #      if defined(__ARM_PCS_VFP)
151 #        define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
152 #      else
153 #        define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
154 #      endif
155 #    else
156 #      define LIB_ARCH_TUPLE "armeb-linux-gnu"
157 #    endif
158 #  else
159 #    define native_architecture() ARCHITECTURE_ARM
160 #    if defined(__ARM_EABI__)
161 #      if defined(__ARM_PCS_VFP)
162 #        define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
163 #      else
164 #        define LIB_ARCH_TUPLE "arm-linux-gnueabi"
165 #      endif
166 #    else
167 #      define LIB_ARCH_TUPLE "arm-linux-gnu"
168 #    endif
169 #  endif
170 #elif defined(__sh64__)
171 #  define native_architecture() ARCHITECTURE_SH64
172 #  error "Missing LIB_ARCH_TUPLE for SH64"
173 #elif defined(__sh__)
174 #  define native_architecture() ARCHITECTURE_SH
175 #  define LIB_ARCH_TUPLE "sh4-linux-gnu"
176 #elif defined(__m68k__)
177 #  define native_architecture() ARCHITECTURE_M68K
178 #  define LIB_ARCH_TUPLE "m68k-linux-gnu"
179 #elif defined(__tilegx__)
180 #  define native_architecture() ARCHITECTURE_TILEGX
181 #  error "Missing LIB_ARCH_TUPLE for TILEGX"
182 #elif defined(__cris__)
183 #  define native_architecture() ARCHITECTURE_CRIS
184 #  error "Missing LIB_ARCH_TUPLE for CRIS"
185 #else
186 #error "Please register your architecture here!"
187 #endif
188
189 const char *architecture_to_string(Architecture a) _const_;
190 Architecture architecture_from_string(const char *s) _pure_;