L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
compiler.h
Go to the documentation of this file.
1/*****************************************************************************/
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>,
10 * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
11 * Jork Löser <jork@os.inf.tu-dresden.de>,
12 * Ronald Aigner <ra3@os.inf.tu-dresden.de>
13 * economic rights: Technische Universität Dresden (Germany)
14 *
15 * This file is part of TUD:OS and distributed under the terms of the
16 * GNU General Public License 2.
17 * Please see the COPYING-GPL-2 file for details.
18 *
19 * As a special exception, you may use this file as part of a free software
20 * library without restriction. Specifically, if other files instantiate
21 * templates or use macros or inline functions from this file, or you compile
22 * this file and link it with other files to produce an executable, this
23 * file does not by itself cause the resulting executable to be covered by
24 * the GNU General Public License. This exception does not however
25 * invalidate any other reasons why the executable file might be covered by
26 * the GNU General Public License.
27 */
28/*****************************************************************************/
29#ifndef __L4_COMPILER_H__
30#define __L4_COMPILER_H__
31
32#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
33
45#ifndef L4_INLINE
46#ifndef __cplusplus
47# ifdef __OPTIMIZE__
48# define L4_INLINE_STATIC static __inline__
49# define L4_INLINE_EXTERN extern __inline__
50# ifdef __GNUC_STDC_INLINE__
51# define L4_INLINE L4_INLINE_STATIC
52# else
53# define L4_INLINE L4_INLINE_EXTERN
54# endif
55# else /* ! __OPTIMIZE__ */
56# define L4_INLINE static
57# endif /* ! __OPTIMIZE__ */
58#else /* __cplusplus */
59# define L4_INLINE inline
60#endif /* __cplusplus */
61#elif defined DOXYGEN
62# define L4_INLINE inline
63#endif /* L4_INLINE */
64
69#define L4_ALWAYS_INLINE L4_INLINE __attribute__((__always_inline__))
70
71
72#define L4_DECLARE_CONSTRUCTOR(func, prio) \
73 static inline __attribute__((constructor(prio))) void func ## _ctor_func(void) { func(); }
74
75
173#ifndef __cplusplus
174# define L4_NOTHROW__A __attribute__((nothrow))
175# define L4_NOTHROW
176# define EXTERN_C_BEGIN
177# define EXTERN_C_END
178# define EXTERN_C
179# ifndef __BEGIN_DECLS
180# define __BEGIN_DECLS
181# endif
182# ifndef __END_DECLS
183# define __END_DECLS
184# endif
185# define L4_DEFAULT_PARAM(x)
186#else /* __cplusplus */
187# if __cplusplus >= 201103L
188# define L4_NOTHROW noexcept
189# else /* C++ < 11 */
190# define L4_NOTHROW throw()
191# endif
192# define EXTERN_C_BEGIN extern "C" {
193# define EXTERN_C_END }
194# define EXTERN_C extern "C"
195# if !defined __BEGIN_DECLS || defined DOXYGEN
196# define __BEGIN_DECLS extern "C" {
197# endif
198# if !defined __END_DECLS || defined DOXYGEN
199# define __END_DECLS }
200# endif
201# define L4_DEFAULT_PARAM(x) = x
202#endif /* __cplusplus */
203
208#if defined __cplusplus && __cplusplus >= 201402L
209# define L4_CONSTEXPR constexpr
210#else
211# define L4_CONSTEXPR
212#endif
213
218#define L4_NORETURN __attribute__((noreturn))
219
220#define L4_PURE __attribute__((pure))
221
226#define L4_NOINSTRUMENT __attribute__((no_instrument_function))
227#ifndef L4_HIDDEN
228# define L4_HIDDEN __attribute__((visibility("hidden")))
229#endif
230#if !defined L4_EXPORT || defined DOXYGEN
231# define L4_EXPORT __attribute__((visibility("default")))
232#endif
233#ifndef L4_EXPORT_TYPE
234# ifdef __cplusplus
235# define L4_EXPORT_TYPE __attribute__((visibility("default")))
236# else
237# define L4_EXPORT_TYPE
238# endif
239#endif
240#define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
241#define L4__STRONG_ALIAS(name, aliasname) \
242 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
243
251#if defined(__i386__) || defined(__amd64__) || \
252 defined(__arm__) || defined(__aarch64__) || \
253 defined(__mips__) || defined(__riscv) || \
254 defined(__powerpc__) || defined(__sparc__)
255# define L4_STACK_ALIGN __BIGGEST_ALIGNMENT__
256#else
257# error Define L4_STACK_ALIGN for this target!
258#endif
259
277#if defined(__i386__) || defined(__amd64__)
278L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
279{
280 if ((stack & (L4_STACK_ALIGN - 1)) == (L4_STACK_ALIGN - sizeof(unsigned long)))
281 return stack;
282 return (stack & ~(L4_STACK_ALIGN)) - sizeof(unsigned long);
283}
284#else
285L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
286{
287 return stack & ~(L4_STACK_ALIGN);
288}
289#endif
290
291#endif /* !__ASSEMBLY__ */
292
293#include <l4/sys/linkage.h>
294
295#define L4_LIKELY(x) __builtin_expect((x),1)
296#define L4_UNLIKELY(x) __builtin_expect((x),0)
297
298/* Make sure that the function is not removed by optimization. Without the
299 * "used" attribute, unreferenced static functions are removed. */
300#define L4_STICKY(x) __attribute__((used)) x
301#define L4_DEPRECATED(s) __attribute__((deprecated(s)))
302
303#ifndef static_assert
304# if !defined(__cplusplus)
305# define static_assert(x, y) _Static_assert(x, y)
306# elif __cplusplus < 201103L
307# define static_assert(x, y) \
308 extern int l4_static_assert[-(!(x))] __attribute__((unused))
309# endif
310#endif
311
312#define L4_stringify_helper(x) #x
313#define L4_stringify(x) L4_stringify_helper(x)
314
315#ifdef __has_builtin
316#define L4_HAS_BUILTIN(def) __has_builtin(def)
317#else
318#define L4_HAS_BUILTIN(def) 0
319#endif
320
321#ifndef __ASSEMBLER__
325L4_INLINE void l4_barrier(void);
326
330L4_INLINE void l4_mb(void);
331
335L4_INLINE void l4_wmb(void);
336
341
342
343/* Implementations */
345{
346 __asm__ __volatile__ ("" : : : "memory");
347}
348
349L4_INLINE void l4_mb(void)
350{
351 __asm__ __volatile__ ("" : : : "memory");
352}
353
355{
356 __asm__ __volatile__ ("" : : : "memory");
357}
358
360{
361 while (1)
362 l4_barrier();
363}
364#endif
365
368#endif /* !__L4_COMPILER_H__ */
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:354
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
void l4_barrier(void)
Memory barrier.
Definition compiler.h:344
void l4_mb(void)
Memory barrier.
Definition compiler.h:349
unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
Specify the desired alignment of the stack pointer.
Definition compiler.h:285
L4_NORETURN void l4_infinite_loop(void)
Infinite loop.
Definition compiler.h:359
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:218