]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_thread-std.cpp
89c5e9ba8e56f2c4e0890496c5d027c12f388715
[l4.git] / kernel / fiasco / src / kern / kernel_thread-std.cpp
1 IMPLEMENTATION:
2
3 #include "config.h"
4 #include "cmdline.h"
5 #include "scheduler.h"
6 #include "factory.h"
7 #include "initcalls.h"
8 #include "ipc_gate.h"
9 #include "irq.h"
10 #include "map_util.h"
11 #include "mem_layout.h"
12 #include "mem_space_sigma0.h"
13 #include "task.h"
14 #include "thread.h"
15 #include "types.h"
16 #include "ram_quota.h"
17 #include "vlog.h"
18 #include "irq_controller.h"
19
20 static Vlog vlog;
21 static Scheduler scheduler;
22 static Icu icu;
23
24 enum Default_base_caps
25 {
26   C_task      = 1,
27   C_factory   = 2,
28   C_thread    = 3,
29   C_pager     = 4,
30   C_log       = 5,
31   C_icu       = 6,
32   C_scheduler = 7,
33   C_log_irq,
34
35 };
36
37 struct Sigma0_space_factory
38 {
39   static void create(Mem_space *v, Ram_quota *q)
40   { new (v) Mem_space_sigma0(q); }
41
42
43   template< typename S >
44   static void create(S *v)
45   { new (v) S(); }
46
47 };
48
49
50 IMPLEMENT
51 void
52 Kernel_thread::init_workload()
53 {
54   Lock_guard<Cpu_lock> g(&cpu_lock);
55   //
56   // create sigma0
57   //
58
59   char const *s;
60   if (Config::Jdb &&
61       (!strstr (Cmdline::cmdline(), " -nojdb")) &&
62       ((s = strstr (Cmdline::cmdline(), " -jdb_cmd="))))
63     {
64       // extract the control sequence from the command line
65       char ctrl[128];
66       char *d;
67
68       for (s=s+10, d=ctrl;
69            d < ctrl+sizeof(ctrl)-1 && *s && *s != ' '; *d++ = *s++)
70         ;
71       *d = '\0';
72       printf("JDB: exec cmd '%s'\n", ctrl);
73       kdb_ke_sequence(ctrl);
74     }
75
76   // kernel debugger rendezvous
77   if (strstr (Cmdline::cmdline(), " -wait"))
78     kdb_ke("Wait");
79
80 #if 0
81     {
82       Lock_guard<Cpu_lock> g(&cpu_lock);
83       kdb_ke("Wait");
84     }
85 #endif
86
87
88   Task *sigma0 = Task::create(Sigma0_space_factory(), Ram_quota::root,
89       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT));
90   sigma0_task = sigma0;
91   assert(sigma0_task);
92
93   check (sigma0->initialize());
94   check (map(sigma0,          sigma0_task->obj_space(), sigma0_task, C_task, 0));
95   check (map(Factory::root(), sigma0_task->obj_space(), sigma0_task, C_factory, 0));
96   check (map(&scheduler,      sigma0_task->obj_space(), sigma0_task, C_scheduler, 0));
97   check (map(&vlog,           sigma0_task->obj_space(), sigma0_task, C_log, 0));
98   check (map(&icu,            sigma0_task->obj_space(), sigma0_task, C_icu, 0));
99
100   sigma0_space = sigma0_task->mem_space();
101
102   Thread *sigma0_thread = new (Ram_quota::root) Thread();
103   // Config::sigma0_prio
104
105   assert_kdb(sigma0_thread);
106   check (map(sigma0_thread, sigma0_task->obj_space(), sigma0_task, C_thread, 0));
107
108   Address sp = init_workload_s0_stack();
109   check (sigma0_thread->control(Thread_ptr(false), Thread_ptr(false),
110                                 sigma0_task,
111                                 (void*)Mem_layout::Utcb_addr) == 0);
112
113   check (sigma0_thread->ex_regs(Kip::k()->sigma0_ip, sp));
114
115   //sigma0_thread->thread_lock()->clear();
116
117   //
118   // create the boot task
119   //
120
121   boot_task = Task::create(Space::Default_factory(), Ram_quota::root,
122       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT+2));
123   assert(boot_task);
124
125   check (boot_task->initialize());
126
127   Thread *boot_thread = new (Ram_quota::root) Thread();
128   // Config::boot_prio
129
130   assert_kdb (boot_thread);
131
132   check (map(boot_task,   boot_task->obj_space(), boot_task, C_task, 0));
133   check (map(boot_thread, boot_task->obj_space(), boot_task, C_thread, 0));
134
135   check (boot_thread->control(Thread_ptr(C_pager), Thread_ptr(~0UL),
136                               boot_task,
137                               (void*)Mem_layout::Utcb_addr) == 0);
138   check (boot_thread->ex_regs(Kip::k()->root_ip, Kip::k()->root_sp));
139
140   Ipc_gate *s0_b_gate = Ipc_gate::create(Ram_quota::root, sigma0_thread, 4 << 4);
141
142   check (s0_b_gate);
143   check (map(s0_b_gate, boot_task->obj_space(), boot_task, C_pager, 0));
144
145   //Cpu::cpus.cpu(0).tz_switch_to_ns();
146   set_cpu_of(sigma0_thread, 0);
147   set_cpu_of(boot_thread, 0);
148   sigma0_thread->state_del_dirty(Thread_suspended);
149   boot_thread->state_del_dirty(Thread_suspended);
150
151   sigma0_thread->activate();
152   check (obj_map(sigma0_task, C_factory,   1, boot_task, C_factory, 0).error() == 0);
153   check (obj_map(sigma0_task, C_scheduler, 1, boot_task, C_scheduler, 0).error() == 0);
154   check (obj_map(sigma0_task, C_log,       1, boot_task, C_log, 0).error() == 0);
155   check (obj_map(sigma0_task, C_icu,       1, boot_task, C_icu, 0).error() == 0);
156
157   boot_thread->activate();
158 }
159
160 IMPLEMENTATION [ia32,amd64]:
161
162 PRIVATE inline
163 Address
164 Kernel_thread::init_workload_s0_stack()
165 {
166   // push address of kernel info page to sigma0's stack
167   Address sp = Kip::k()->sigma0_sp - sizeof(Mword);
168   // assume we run in kdir 1:1 mapping
169   *reinterpret_cast<Address*>(sp) = Kmem::virt_to_phys(Kip::k());
170   return sp;
171 }
172
173 IMPLEMENTATION [ux,arm,ppc32]:
174
175 PRIVATE inline
176 Address
177 Kernel_thread::init_workload_s0_stack()
178 { return Kip::k()->sigma0_sp; }
179
180
181 // ---------------------------------------------------------------------------
182 IMPLEMENTATION [io]:
183
184 #include "io_space_sigma0.h"
185
186 PUBLIC
187 static
188 void
189 Sigma0_space_factory::create(Io_space *v)
190 { new (v) Io_space_sigma0<Space>(); }