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