]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/globals.cpp
83f2e3ca81a5bd81186f430cc5b883ff4203d2c2
[l4.git] / kernel / fiasco / src / kern / globals.cpp
1 INTERFACE:
2
3 #include <cassert>
4
5 #include "mem_layout.h"
6 #include "panic.h"
7 #include "per_cpu_data.h"
8 #include "types.h"
9
10 class Context;
11 class Mem_space;
12 class Task;
13 class Space;
14 class Thread;
15 class Timeout;
16
17 extern Space *sigma0_task;
18 extern Task *boot_task;
19 extern Mem_space *sigma0_space;
20 extern Per_cpu<Timeout *> timeslice_timeout;
21 extern bool running;
22 extern unsigned boot_stack;
23
24 /* the check macro is like assert(), but it evaluates its argument
25    even if NDEBUG is defined */
26 #ifndef check
27 #ifdef NDEBUG
28 # define check(expression) ((void)(expression))
29 #else /* ! NDEBUG */
30 # ifdef ASSERT_KDB_KE
31 #  define check(expression) assert(expression)
32 # else
33 #  define check(expression) \
34           ((void)((expression) ? 0 : \
35                  (panic(__FILE__":%u: failed check `"#expression"'", \
36                          __LINE__), 0)))
37 # endif
38 #endif /* ! NDEBUG */
39 #endif /* check */
40
41 // nil_thread and kernel_thread might have different values on a SMP system
42 extern Thread *nil_thread;
43 static Thread *&kernel_thread = nil_thread;
44
45
46 class Global_context_data
47 {
48 public:
49   virtual ~Global_context_data() {}
50
51 protected:
52   Mword _state;
53 };
54
55
56 //---------------------------------------------------------------------------
57 INTERFACE [mp]:
58
59 EXTENSION class Global_context_data
60 {
61 protected:
62   friend unsigned &__cpu_of(const void *);
63   unsigned _cpu;
64 };
65
66 //---------------------------------------------------------------------------
67 IMPLEMENTATION:
68
69 #include "config.h"
70 #include "processor.h"
71
72 Space *sigma0_task;
73 Task *boot_task;
74 Mem_space *sigma0_space;
75 Thread *nil_thread;
76 bool running = true;
77 unsigned boot_stack;
78
79 inline NEEDS ["config.h"]
80 Context *context_of(const void *ptr)
81 {
82   return reinterpret_cast<Context *>
83     (reinterpret_cast<unsigned long>(ptr) & ~(Config::thread_block_size - 1));
84 }
85
86 inline NEEDS [context_of, "processor.h"]
87 Context *current()
88 { return context_of ((void *)Proc::stack_pointer()); }
89
90
91
92 IMPLEMENTATION [!mp]:
93
94 inline
95 void set_cpu_of(const void *ptr, unsigned cpu)
96 { (void)ptr; (void)cpu; }
97
98 inline
99 unsigned cpu_of(const void *)
100 { return 0; }
101
102 inline
103 unsigned current_cpu()
104 { return 0; }
105
106
107 IMPLEMENTATION [mp]:
108
109 inline NEEDS ["config.h"]
110 unsigned &__cpu_of(const void *ptr)
111 { return reinterpret_cast<Global_context_data*>(context_of(ptr))->_cpu; }
112
113 inline NEEDS [__cpu_of]
114 void set_cpu_of(const void *ptr, unsigned cpu)
115 { __cpu_of(ptr) = cpu; }
116
117
118 inline NEEDS [__cpu_of]
119 unsigned cpu_of(const void *ptr)
120 { return __cpu_of(ptr); }
121
122 inline NEEDS [current, cpu_of]
123 unsigned current_cpu()
124 { return cpu_of(current()); }
125