]> 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_object.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_object *sigma0_thread = new (Ram_quota::root) Thread_object();
99
100   assert_kdb(sigma0_thread);
101   check (map(sigma0_thread, sigma0_task->obj_space(), sigma0_task, C_thread, 0));
102
103   Address sp = init_workload_s0_stack();
104   check (sigma0_thread->control(Thread_ptr(false), Thread_ptr(false),
105                                 sigma0_task,
106                                 (void*)Mem_layout::Utcb_addr) == 0);
107
108   check (sigma0_thread->ex_regs(Kip::k()->sigma0_ip, sp));
109
110   //sigma0_thread->thread_lock()->clear();
111
112   //
113   // create the boot task
114   //
115
116   boot_task = Task::create(Space::Default_factory(), Ram_quota::root,
117       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT+2));
118   assert(boot_task);
119
120   check (boot_task->initialize());
121
122   Thread_object *boot_thread = new (Ram_quota::root) Thread_object();
123
124   assert_kdb (boot_thread);
125
126   check (map(boot_task,   boot_task->obj_space(), boot_task, C_task, 0));
127   check (map(boot_thread, boot_task->obj_space(), boot_task, C_thread, 0));
128
129   check (boot_thread->control(Thread_ptr(C_pager), Thread_ptr(~0UL),
130                               boot_task,
131                               (void*)Mem_layout::Utcb_addr) == 0);
132   check (boot_thread->ex_regs(Kip::k()->root_ip, Kip::k()->root_sp));
133
134   Ipc_gate *s0_b_gate = Ipc_gate::create(Ram_quota::root, sigma0_thread, 4 << 4);
135
136   check (s0_b_gate);
137   check (map(s0_b_gate, boot_task->obj_space(), boot_task, C_pager, 0));
138
139   set_cpu_of(sigma0_thread, 0);
140   set_cpu_of(boot_thread, 0);
141   sigma0_thread->state_del_dirty(Thread_suspended);
142   boot_thread->state_del_dirty(Thread_suspended);
143
144   sigma0_thread->activate();
145   check (obj_map(sigma0_task, C_factory,   1, boot_task, C_factory, 0).error() == 0);
146   for (unsigned c = Initial_kobjects::First_cap; c < Initial_kobjects::End_cap; ++c)
147     {
148       Kobject_iface *o = initial_kobjects.obj(c);
149       if (o)
150         check(obj_map(sigma0_task, c, 1, boot_task, c, 0).error() == 0);
151     }
152
153   boot_thread->activate();
154 }
155
156 IMPLEMENTATION [ia32,amd64]:
157
158 PRIVATE inline
159 Address
160 Kernel_thread::init_workload_s0_stack()
161 {
162   // push address of kernel info page to sigma0's stack
163   Address sp = Kip::k()->sigma0_sp - sizeof(Mword);
164   // assume we run in kdir 1:1 mapping
165   *reinterpret_cast<Address*>(sp) = Kmem::virt_to_phys(Kip::k());
166   return sp;
167 }
168
169 IMPLEMENTATION [ux,arm,ppc32]:
170
171 PRIVATE inline
172 Address
173 Kernel_thread::init_workload_s0_stack()
174 { return Kip::k()->sigma0_sp; }
175
176
177 // ---------------------------------------------------------------------------
178 IMPLEMENTATION [io]:
179
180 #include "io_space_sigma0.h"
181
182 PUBLIC
183 static
184 void
185 Sigma0_space_factory::create(Io_space *v)
186 { new (v) Io_space_sigma0<Space>(); }