revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / compiler / arossupport / include / system.h
blob71f20069a4e6d3edb0648a08cd86613b95344350
1 #ifndef AROS_SYSTEM_H
2 #define AROS_SYSTEM_H
4 /*
5 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Analyse the current kind of system and compiler.
9 Lang: english
12 #ifndef AROS_CPU_H
13 # include <aros/cpu.h>
14 #endif
16 /**************************************
17 Defines
18 **************************************/
19 /* 1. Analyze system: Specify a definitive define for each system */
20 #if defined(_AMIGA) || defined(AMIGA)
21 # ifndef _AMIGA
22 # define _AMIGA
23 # endif
24 # ifndef AMIGA
25 # define AMIGA
26 # endif
27 #endif
29 #if defined __GNUC__ && defined __GNUC_MINOR__
30 # define __GNUC_PREREQ(maj, min) \
31 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
32 #else
33 # define __GNUC_PREREQ(maj, min) 0
34 #endif
35 #define __GNUC_PREREQ__ __GNUC_PREREQ
39 * 2. Analyze compiler for STD C/C++.
41 * We test for the following:
42 * a. extern "C" linkage required for programs.
43 * b. inline, const, volatile, restrict keywords defined in
44 * newer C/C++ standards.
45 * c. throw() being available, which lets the compiler better
46 * optimize stuff
49 #if defined(__cplusplus)
50 # define __EXTERN extern "C"
51 # define __BEGIN_DECLS extern "C" {
52 # define __BEGIN_EXTERN extern "C" {
53 # define __END_DECLS };
54 # define __END_EXTERN };
55 #else
56 # define __EXTERN extern
57 # define __BEGIN_DECLS
58 # define __BEGIN_EXTERN
59 # define __END_DECLS
60 # define __END_EXTERN
61 #endif
63 #if defined(__STDC__) || defined(__cplusplus)
64 # if !defined(__GNUC__)
65 # define __const__ const
66 # define __inline__ inline
67 # define __volatile__ volatile
68 # endif
71 * C99 defines a new keyword restrict that can help do optimisation where
72 * pointers are used in programs. We'd like to support optimisation :-)
74 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
75 # define __restrict__ restrict
76 # else
77 # define __restrict__
78 # define restrict
79 # endif
81 #else
82 # define __const__
83 # define const
84 # define __inline__
85 # define inline
86 # define __volatile__
87 # define volatile
88 # define __restrict__
89 # define restrict
90 #endif
92 #if defined(__GNUC__) && !defined(__THROW)
93 # if defined __cplusplus && __GNUC_PREREQ (2,8)
94 # define __THROW throw ()
95 # else
96 # define __THROW
97 # endif
98 #endif
100 /* 3. Macros for making things more efficient */
101 #ifndef __packed
102 #if __GNUC_PREREQ(2,5)
103 # define __packed __attribute__((__packed__))
104 #else
105 # error Define __packed appropriately for your compiler!
106 #endif
107 #endif
109 #ifndef __noreturn
110 #if __GNUC_PREREQ(2,5)
111 # define __noreturn __attribute__((__noreturn__))
112 #else
113 # define __noreturn
114 #endif
115 #endif
117 #ifndef __noeffect
118 #if __GNUC_PREREQ(2,5) && !(__GNUC_PREREQ(2,6) && defined __cplusplus)
119 # define __noeffect __attribute__((__const__))
120 #else
121 # define __noeffect
122 #endif
123 #endif
125 #ifndef __unused
126 # if __GNUC_PREREQ(2,7)
127 # define __unused __attribute__((__unused__))
128 # else
129 # define __unused
130 # endif
131 #endif
133 #ifndef __used
134 # if __GNUC_PREREQ(3,3)
135 # define __used __attribute__((__used__))
136 # else
137 # define __used __unused
138 # endif
139 #endif
141 #ifndef __pure
142 #if __GNUC_PREREQ(2,96)
143 # define __pure __attribute__((__pure__))
144 #else
145 # define __pure
146 #endif
147 #endif
149 #ifndef __const
150 #if __GNUC_PREREQ(2,5)
151 # define __const __attribute__((__const__))
152 #else
153 # define __const
154 #endif
155 #endif
157 #ifndef __mayalias
158 #if __GNUC_PREREQ(3,3)
159 # define __mayalias __attribute__((__may_alias__))
160 #else
161 # define __mayalias
162 #endif
163 #endif
165 #define __pure2 __const
167 /* 4. Macros for debugging and development */
168 #if defined(__GNUC__) || defined(__INTEL_COMPILER) || (defined(__STDC__) && __STDC_VERSION__ >= 199901L)
169 #if !defined(AROS_64BIT_TYPE)
170 # define AROS_64BIT_TYPE long long
171 #endif
172 # define AROS_HAVE_LONG_LONG
173 #endif
175 #if defined(__INTEL_COMPILER)
176 # ifdef inline
177 # undef inline
178 # endif
179 # define inline
180 #endif
182 #if __GNUC__ <= 2
183 # define __deprecated
184 # define __section(x)
185 #endif
186 #if __GNUC__ > 2
187 # define __deprecated __attribute__((__deprecated__))
188 # define __section(x) __attribute__((__section__(x)))
189 #endif
191 #if __GNUC_PREREQ(3,3)
192 #define __startup __section(".aros.startup") __used
193 #else
194 #define __startup __used
195 #endif
197 /* 5. Calculated #defines */
198 #if !AROS_STACK_GROWS_DOWNWARDS
199 # define AROS_SLOWSTACKTAGS
200 # define AROS_SLOWSTACKMETHODS
201 #endif /* !AROS_STACK_GROWS_DOWNWARDS */
203 #if !defined(__CONCAT)
204 # if defined(__STDC__) || defined(__cplusplus)
205 # define __CONCAT1(a,b) a ## b
206 # define __CONCAT(a,b) __CONCAT1(a,b)
207 # else
208 # define __CONCAT(a,b) a/**/b
209 # endif
210 #endif
212 #ifndef AROS_ASMSYMNAME
213 # define AROS_ASMSYMNAME(n) n
214 #endif
216 #ifndef AROS_CSYM_FROM_ASM_NAME
217 # if defined(__ELF__) || defined(__MACH__) || defined(_WIN32) || defined(__CYGWIN__)
218 # define AROS_CSYM_FROM_ASM_NAME(n) n
219 # else
220 # error define AROS_CSYM_FROM_ASM_NAME for your architecture
221 # endif
222 #endif
224 #define ___AROS_STR(x) #x
225 #define __AROS_STR(x) ___AROS_STR(x)
228 /* Makes a 'new' symbol which occupies the same memory location as the 'old' symbol */
229 #if !defined AROS_MAKE_ALIAS
230 # define AROS_MAKE_ALIAS(old, new) \
231 AROS_MAKE_ASM_SYM(typeof(old), new, AROS_CSYM_FROM_ASM_NAME(new), AROS_CSYM_FROM_ASM_NAME(old)); \
232 AROS_EXPORT_ASM_SYM(AROS_CSYM_FROM_ASM_NAME(new))
233 #endif
235 /* define an asm symbol 'asym' with a C name 'csym', type 'type' and with value 'value'.
236 'value' has to be an asm constant, thus either an address number or an asm symbol name, */
237 #if !defined AROS_MAKE_ASM_SYM
238 # define AROS_MAKE_ASM_SYM(type, csym, asym, value) \
239 extern type csym asm(__AROS_STR(asym)); \
240 typedef int __CONCAT(__you_must_first_make_asym_, asym); \
241 asm(".set " __AROS_STR(asym) ", " __AROS_STR(value) "\n")
242 #endif
244 /* Makes an ASM symbol 'asym' available for use in the compilation unit this
245 macro is used, with a C name 'csym'. This has also the side effect of
246 triggering the inclusion, by the linker, of all code and data present in the
247 module where the ASM symbol is actually defined. */
248 #if !defined AROS_IMPORT_ASM_SYM
249 # define AROS_IMPORT_ASM_SYM(type, csym, asym) \
250 extern type csym asm(__AROS_STR(asym)); \
251 asm("\n.globl " __AROS_STR(asym) "\n")
252 #endif
254 /* Make sure other compilation units can see the symbol 'asym' created with AROS_MAKE_ASM_SYM.
255 This macro results in a compile-time error in case it's used BEFORE the symbol has been
256 made with AROS_MAKE_ASM_SYM. */
257 #if !defined AROS_EXPORT_ASM_SYM
258 # define AROS_EXPORT_ASM_SYM(asym) \
259 struct __CONCAT(___you_must_first_make_asym_, asym) \
261 int a[sizeof(__CONCAT(__you_must_first_make_asym_, asym))]; \
262 }; \
263 asm("\n.globl " __AROS_STR(asym) "\n")
264 #endif
266 #endif /* AROS_SYSTEM_H */