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