OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [macros.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __MACROS_H__
2
#define __MACROS_H__
3
#include "config.h"
4
 
5
#define __KERNELNAME__                  "code0"
6
 
7
/*
8
 * This file is automatically included before the first line of any
9
 * source file, using gcc's -imacro command line option.  Only macro
10
 * definitions will be extracted.
11
 */
12
#define INC_ARCH(x)             <l4/arch/__ARCH__/x>
13
#define INC_SUBARCH(x)          <l4/arch/__ARCH__/__SUBARCH__/x>
14
#define INC_CPU(x)              <l4/arch/__ARCH__/__SUBARCH__/__CPU__/x>
15
#define INC_PLAT(x)             <l4/platform/__PLATFORM__/x>
16
#define INC_API(x)              <l4/api/x>
17
#define INC_GLUE(x)             <l4/glue/__ARCH__/x>
18
 
19
#define __initdata      SECTION(".init.data")
20
 
21
/*
22
 * FIXME: Remove __CPP__
23
 * This is defined in kernel linker.lds.in,
24
 * find some better way.
25
 */
26
#if !defined(__CPP__)
27
/* use this to place code/data in a certain section */
28
#define SECTION(x) __attribute__((section(x)))
29
#define ALIGN(x) __attribute__((aligned (x)))
30
#endif
31
 
32
/* Functions for critical path optimizations */
33
#if (__GNUC__ >= 3)
34
#define unlikely(x)             __builtin_expect((x), false)
35
#define likely(x)               __builtin_expect((x), true)
36
#define likelyval(x,val)        __builtin_expect((x), (val))
37
#else /* __GNUC__ < 3 */
38
#define likely(x)               (x)
39
#define unlikely(x)             (x)
40
#define likelyval(x,val)        (x)
41
#endif /* __GNUC__ < 3 */
42
 
43
/* This guard is needed because tests use host C library and NULL is defined */
44
#ifndef NULL
45
#define NULL                    0
46
#endif
47
/* Convenience functions for memory sizes. */
48
#define SZ_1K                   1024
49
#define SZ_2K                   2048
50
#define SZ_4K                   0x1000
51
#define SZ_16K                  0x4000
52
#define SZ_32K                  0x8000
53
#define SZ_64K                  0x10000
54
#define SZ_1MB                  0x100000
55
#define SZ_2MB                  0x200000
56
#define SZ_4MB                  (4*SZ_1MB)
57
#define SZ_8MB                  (8*SZ_1MB)
58
#define SZ_16MB                 (16*SZ_1MB)
59
#define SZ_1K_BITS              10
60
#define SZ_4K_BITS              12
61
#define SZ_16K_BITS             14
62
#define SZ_1MB_BITS             20
63
 
64
/* Per-cpu variables */
65
 
66
#if defined CONFIG_SMP
67
#define DECLARE_PERCPU(type, name)      \
68
type name[CONFIG_NCPU]
69
 
70
#define per_cpu(val)    (val)[smp_get_cpuid()]
71
#define per_cpu_byid(val, cpu)  (val)[(cpu)]
72
 
73
#else /* Not CONFIG_SMP */
74
 
75
#define DECLARE_PERCPU(type, name)      \
76
type name
77
 
78
#define per_cpu(val)    (val)
79
#define per_cpu_byid(val, cpu)  val
80
 
81
#endif /* End of Not CONFIG_SMP */
82
 
83
#ifndef __ASSEMBLY__
84
#include <stddef.h>     /* offsetof macro, defined in the `standard' way. */
85
#endif
86
 
87
#define container_of(ptr, struct_type, field)                                   \
88
({                                                                              \
89
        const typeof(((struct_type *)0)->field) *field_ptr = (ptr);              \
90
        (struct_type *)((char *)field_ptr - offsetof(struct_type, field));      \
91
})
92
 
93
/* Prefetching is noop for now */
94
#define prefetch(x)             x
95
 
96
#if !defined(__KERNEL__)
97
#define printk                  printf
98
#endif
99
 
100
/* Converts an int-sized field offset in a struct into a bit offset in a word */
101
#define FIELD_TO_BIT(type, field)       (1 << (offsetof(type, field) >> 2))
102
 
103
/* Functions who may either return a pointer or an error code can use these: */
104
#define PTR_ERR(x)              ((void *)(x))
105
/* checks up to -1000, the rest might be valid pointers!!! E.g. 0xE0000000 */
106
// #define IS_ERR(x)            ((((int)(x)) < 0) && (((int)(x) > -1000)))
107
#if !defined(__ASSEMBLY__)
108
#define IS_ERR(x)       is_err((int)(x))
109
static inline int is_err(int x)
110
{
111
        return x < 0 && x > -0x1000;
112
}
113
#endif
114
 
115
/* TEST: Is this type of printk well tested? */
116
#define BUG()                   {do {                                                           \
117
                                        printk("BUG in file: %s function: %s line: %d\n",       \
118
                                                __FILE__, __FUNCTION__, __LINE__);              \
119
                                } while(0);                                                      \
120
                                while(1);}
121
 
122
#define BUG_ON(x)               {if (x) BUG();}
123
 
124
#define WARN_ON(x)      {if (x) printk("%s, %s, %s: Warning something is off here.\n", __FILE__, __FUNCTION__, __LINE__); }
125
 
126
#define BUG_ON_MSG(msg, x)      do {                            \
127
                                        printk(msg);            \
128
                                        BUG_ON(x)               \
129
                                } while(0)
130
 
131
#define BUG_MSG(msg...) do {                            \
132
                                        printk(msg);    \
133
                                        BUG();                  \
134
                                } while(0)
135
#endif /* __MACROS_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.