]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/static_init.h
15f9bab87ed5ba3bb34f720635294fee85e7422d
[l4.git] / kernel / fiasco / src / kern / static_init.h
1 /* -*- c++ -*- */
2
3 #include "initcalls.h"
4
5 /**
6  * definitions for static, pre-main initialization stuff
7  */
8 #ifndef STATIC_INIT_H
9 #define STATIC_INIT_H
10
11 /// Priorities for ordered static initialization
12 //@{
13
14 #define DEPENDS_ON(SUBSYS)      ((SUBSYS) + 2)
15
16 #define LINKER_INTERNAL          100            // linker internal use
17 #define UX_STARTUP1_INIT_PRIO    DEPENDS_ON(LINKER_INTERNAL)
18 #define EARLY_INIT_PRIO          DEPENDS_ON(UX_STARTUP1_INIT_PRIO)
19 #define STARTUP1_INIT_PRIO       DEPENDS_ON(EARLY_INIT_PRIO)
20 // at this stage spinlocks must be working
21 #define ROOT_FACTORY_INIT_PRIO   DEPENDS_ON(STARTUP1_INIT_PRIO)
22 #define BOOT_CONSOLE_INIT_PRIO   DEPENDS_ON(ROOT_FACTORY_INIT_PRIO)
23 #define GDB_INIT_PRIO            DEPENDS_ON(BOOT_CONSOLE_INIT_PRIO)
24 #define UART_INIT_PRIO           DEPENDS_ON(BOOT_CONSOLE_INIT_PRIO)
25 #define STARTUP_INIT_PRIO        DEPENDS_ON(GDB_INIT_PRIO)
26 #define CPU_LOCAL_BASE_INIT_PRIO DEPENDS_ON(STARTUP_INIT_PRIO)
27 #define CPU_LOCAL_INIT_PRIO      DEPENDS_ON(CPU_LOCAL_BASE_INIT_PRIO)
28 #define POST_CPU_LOCAL_INIT_PRIO DEPENDS_ON(CPU_LOCAL_INIT_PRIO)
29 #define PERF_CNT_INIT_PRIO       DEPENDS_ON(POST_CPU_LOCAL_INIT_PRIO)
30 #define JDB_CATEGORY_INIT_PRIO   DEPENDS_ON(POST_CPU_LOCAL_INIT_PRIO)
31 #define JDB_MODULE_INIT_PRIO     DEPENDS_ON(JDB_CATEGORY_INIT_PRIO)
32
33 #define WATCHDOG_INIT            DEPENDS_ON(PERF_CNT_INIT_PRIO)
34 #define KDB_INIT_PRIO            DEPENDS_ON(JDB_MODULE_INIT_PRIO)
35 #define JDB_INIT_PRIO            DEPENDS_ON(KDB_INIT_PRIO)
36
37 #define INIT_PRIORITY(a) __attribute__((init_priority(a)))
38
39 //@}
40
41
42
43 /* ATTENTION: WARNING: DON'T READ ANY FURTHER !!! */
44 /*  The following definitions are likely to cause */
45 /*  extreme and irreparable BRAIN DAMAGE.         */
46 /*  (I already tested this on my unsuspecting    */
47 /*   colleagues)                                  */
48
49 /**
50  * \defgroup Magic static initializer macros
51  */
52 //@{
53 #define __STATIC_INITIALIZER(_func, va) \
54 class static_init_##va { \
55 public: \
56   static_init_##va() FIASCO_INIT; \
57 };\
58 static_init_##va::static_init_##va() { \
59   _func(); \
60 } \
61 static static_init_##va __static_construction_of_##va##__
62
63 #define __STATIC_INITIALIZER_P(_func, va, prio) \
64 class static_init_##va { \
65 public: \
66   static_init_##va() FIASCO_INIT; \
67 };\
68 static_init_##va::static_init_##va() { \
69   _func(); \
70 } \
71 static static_init_##va __static_construction_of_##va##__ \
72   __attribute__((init_priority(prio)))
73 //@}
74
75
76
77 /**
78  * \defgroup Macros to define static init functions
79  */
80 //@{
81
82 /// mark f as static initializer with priority p
83 #define STATIC_INITIALIZER_P(f, p) \
84   __STATIC_INITIALIZER_P(f,func_##f,p)
85
86 /// mark f as static initailizer
87 #define STATIC_INITIALIZER(f) \
88   __STATIC_INITIALIZER(f,func_##f)
89 //@}
90
91
92 /// static initialization of singleton (static) classes
93 /**
94  * The classes that should be initialized must provide
95  * a init() member function that takes no arguments.
96  */
97 //@{
98
99 /** mark class c to be statically initialized via its init
100  *  function and with priority p
101  */
102 #define STATIC_INITIALIZE_P(c,p) \
103   __STATIC_INITIALIZER_P(c::init, class_##c,p)
104
105 /// mark class c to be statically initialized via its init function
106 #define STATIC_INITIALIZE(c) \
107   __STATIC_INITIALIZER(c::init, class_##c)
108
109 /** mark class c to be statically initialized via its init
110  *  function and with priority p
111  */
112 #define STATIC_INITIALIZEX_P(c,func,p) \
113   __STATIC_INITIALIZER_P(c::func, class_##c##_##func,p)
114
115 /// mark class c to be statically initialized via its init function
116 #define STATIC_INITIALIZEX(c,func) \
117   __STATIC_INITIALIZER(c::func, class_##c##_##func)
118 //@}
119
120
121
122 #endif // __STATIC_INIT_H__