Files
codezero/include/l4/macros.h
2008-01-22 13:26:19 +00:00

111 lines
3.0 KiB
C

#ifndef __MACROS_H__
#define __MACROS_H__
#include "config.h"
/*
* This file is automatically included before the first line of any
* source file, using gcc's -imacro command line option. Only macro
* definitions will be extracted.
*/
#define INC_ARCH(x) <l4/arch/__ARCH__/x>
#define INC_SUBARCH(x) <l4/arch/__ARCH__/__SUBARCH__/x>
#define INC_CPU(x) <l4/arch/__ARCH__/__SUBARCH__/__CPU__/x>
#define INC_PLAT(x) <l4/platform/__PLATFORM__/x>
#define INC_API(x) <l4/api/x>
#define INC_GLUE(x) <l4/glue/__ARCH__/x>
/* use this to place code/data in a certain section */
#define SECTION(x) __attribute__((section(x)))
#define UNIT(x) __attribute__((section(".data." x)))
/*
* use WEAK to specifiy a weak function which can be replaced
* by a architecture specific optimization
* example: void WEAK bla()
*/
#define WEAK __attribute__(( weak ))
/*
* Marks a function as noreturn.
*/
#define NORETURN __attribute__(( noreturn ))
/* Functions for critical path optimizations */
#if (__GNUC__ >= 3)
#define unlikely(x) __builtin_expect((x), false)
#define likely(x) __builtin_expect((x), true)
#define likelyval(x,val) __builtin_expect((x), (val))
#else /* __GNUC__ < 3 */
#define likely(x) (x)
#define unlikely(x) (x)
#define likelyval(x,val) (x)
#endif /* __GNUC__ < 3 */
/* This guard is needed because tests use host C library and NULL is defined */
#ifndef NULL
#define NULL 0
#endif
/* Convenience functions for memory sizes. */
#define SZ_1K 1024
#define SZ_4K 0x1000
#define SZ_16K 0x4000
#define SZ_64K 0x10000
#define SZ_1MB 0x100000
#define SZ_8MB (8*SZ_1MB)
#define SZ_16MB (16*SZ_1MB)
#define SZ_1K_BITS 10
#define SZ_4K_BITS 12
#define SZ_16K_BITS 14
#define SZ_1MB_BITS 20
#ifndef __ASSEMBLY__
#include <stddef.h> /* offsetof macro, defined in the `standard' way. */
#endif
/* Offset of struct fields. */
//#if (__GNUC__ >= 4)
//#define offsetof(type, field) __builtin_offsetof(type, field)
//#else
//#define offsetof(type, field) (u32)(&((type *)0)->field)
//#endif
/* LICENSE: Taken off Linux */
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
/* Prefetching is noop for now */
#define prefetch(x) x
#if !defined(__KERNEL__)
#define printk printf
#endif
/* TEST: Is this type of printk well tested? */
#define BUG() {do { \
printk("BUG in file: %s function: %s line: %d\n", \
__FILE__, __FUNCTION__, __LINE__); \
} while(0); \
while(1);}
#define BUG_ON(x) {if (x) BUG();}
#define BUG_ON_MSG(msg, x) do { \
printk(msg); \
BUG_ON(x) \
} while(0)
#define BUG_MSG(msg...) do { \
printk(msg); \
BUG(); \
} while(0)
#endif /* !__MACROS_H__ */