00001
00002
00003 #ifndef globals_h
00004 #define globals_h
00005
00006 #include <cassert>
00007
00008 #include "mem_layout.h"
00009 #include "types.h"
00010
00011
00012
00013
00014
00015
00016 class Context;
00017 class Space;
00018 class Task;
00019 class Thread;
00020 class Timeout;
00021
00022 extern Task *sigma0_task;
00023 extern Space *sigma0_space;
00024 extern Thread *sigma0_thread;
00025 extern Timeout *timeslice_timeout;
00026 extern bool running;
00027 extern unsigned boot_stack;
00028
00029
00030
00031 #ifndef check
00032 #ifdef NDEBUG
00033 # define check(expression) ((void)(expression))
00034 #else
00035 # define check(expression) \
00036 ((void)((expression) ? 0 : \
00037 (panic(__FILE__":%u: failed check `"#expression"'", \
00038 __LINE__), 0)))
00039 #endif
00040 #endif
00041
00042
00043 static Thread * const nil_thread =
00044 reinterpret_cast<Thread*>(Mem_layout::Tcbs);
00045 static Thread * const kernel_thread =
00046 reinterpret_cast<Thread*>(Mem_layout::Tcbs);
00047
00048 inline Context *context_of(const void *ptr);
00049
00050 inline Context *current();
00051
00052
00053
00054
00055
00056
00057 #include "config.h"
00058
00059
00060
00061
00062
00063
00064
00065
00066 inline Context *context_of(const void *ptr)
00067 {
00068 return reinterpret_cast<Context *>
00069 (reinterpret_cast<unsigned long>(ptr) & ~(Config::thread_block_size - 1));
00070 }
00071
00072
00073
00074 inline Context *current()
00075 {
00076 void* esp;
00077 __asm__ __volatile__
00078 ("movl %%esp, %0" : "=q" (esp));
00079
00080 return context_of (esp);
00081 }
00082
00083 #endif // globals_h