]> 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 "factory.h"
5 #include "initcalls.h"
6 #include "ipc_gate.h"
7 #include "irq.h"
8 #include "koptions.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   if (Config::Jdb &&
49       !Koptions::o()->opt(Koptions::F_nojdb) &&
50       Koptions::o()->opt(Koptions::F_jdb_cmd))
51     {
52       // extract the control sequence from the command line
53       char ctrl[128];
54       char const *s = Koptions::o()->jdb_cmd;
55       char *d;
56
57       for (d=ctrl; d < ctrl+sizeof(ctrl)-1 && *s && *s != ' '; *d++ = *s++)
58         ;
59       *d = '\0';
60
61       kdb_ke_sequence(ctrl);
62     }
63
64   // kernel debugger rendezvous
65   if (Koptions::o()->opt(Koptions::F_wait))
66     kdb_ke("Wait");
67
68   //
69   // create sigma0
70   //
71
72   Task *sigma0 = Task::create(Sigma0_space_factory(), Ram_quota::root,
73       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT));
74   sigma0_task = sigma0;
75   assert(sigma0_task);
76
77   // prevent deletion of this thing
78   sigma0->inc_ref();
79
80   check (sigma0->initialize());
81   check (map(sigma0,          sigma0->obj_space(), sigma0, C_task, 0));
82   check (map(Factory::root(), sigma0->obj_space(), sigma0, C_factory, 0));
83
84   for (unsigned c = Initial_kobjects::First_cap; c < Initial_kobjects::End_cap; ++c)
85     {
86       Kobject_iface *o = initial_kobjects.obj(c);
87       if (o)
88         check(map(o, sigma0->obj_space(), sigma0, c, 0));
89     }
90
91   sigma0_space = sigma0->mem_space();
92
93   Thread_object *sigma0_thread = new (Ram_quota::root) Thread_object();
94
95   assert_kdb(sigma0_thread);
96
97   // prevent deletion of this thing
98   sigma0_thread->inc_ref();
99   check (map(sigma0_thread, sigma0->obj_space(), sigma0, C_thread, 0));
100
101   Address sp = init_workload_s0_stack();
102   check (sigma0_thread->control(Thread_ptr(false), Thread_ptr(false)) == 0);
103   check (sigma0_thread->bind(sigma0, User<Utcb>::Ptr((Utcb*)Mem_layout::Utcb_addr)));
104   check (sigma0_thread->ex_regs(Kip::k()->sigma0_ip, sp));
105
106   //
107   // create the boot task
108   //
109
110   boot_task = Task::create(Space::Default_factory(), Ram_quota::root,
111       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT+2));
112   assert(boot_task);
113
114   check (boot_task->initialize());
115
116   // prevent deletion of this thing
117   boot_task->inc_ref();
118
119   Thread_object *boot_thread = new (Ram_quota::root) Thread_object();
120
121   assert_kdb (boot_thread);
122
123   // prevent deletion of this thing
124   boot_thread->inc_ref();
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)) == 0);
130   check (boot_thread->bind(boot_task, User<Utcb>::Ptr((Utcb*)Mem_layout::Utcb_addr)));
131   check (boot_thread->ex_regs(Kip::k()->root_ip, Kip::k()->root_sp));
132
133   Ipc_gate *s0_b_gate = Ipc_gate::create(Ram_quota::root, sigma0_thread, 4 << 4);
134
135   check (s0_b_gate);
136   check (map(s0_b_gate, boot_task->obj_space(), boot_task, C_pager, 0));
137
138   set_cpu_of(sigma0_thread, 0);
139   set_cpu_of(boot_thread, 0);
140   sigma0_thread->state_del_dirty(Thread_suspended);
141   boot_thread->state_del_dirty(Thread_suspended);
142
143   sigma0_thread->activate();
144   check (obj_map(sigma0, C_factory,   1, boot_task, C_factory, 0).error() == 0);
145   for (unsigned c = Initial_kobjects::First_cap; c < Initial_kobjects::End_cap; ++c)
146     {
147       Kobject_iface *o = initial_kobjects.obj(c);
148       if (o)
149         check(obj_map(sigma0, c, 1, boot_task, c, 0).error() == 0);
150     }
151
152   boot_thread->activate();
153 }
154
155 IMPLEMENTATION [ia32,amd64]:
156
157 PRIVATE inline
158 Address
159 Kernel_thread::init_workload_s0_stack()
160 {
161   // push address of kernel info page to sigma0's stack
162   Address sp = Kip::k()->sigma0_sp - sizeof(Mword);
163   // assume we run in kdir 1:1 mapping
164   *reinterpret_cast<Address*>(sp) = Kmem::virt_to_phys(Kip::k());
165   return sp;
166 }
167
168 IMPLEMENTATION [ux,arm,ppc32]:
169
170 PRIVATE inline
171 Address
172 Kernel_thread::init_workload_s0_stack()
173 { return Kip::k()->sigma0_sp; }
174
175
176 // ---------------------------------------------------------------------------
177 IMPLEMENTATION [io]:
178
179 #include "io_space_sigma0.h"
180
181 PUBLIC
182 static
183 void
184 Sigma0_space_factory::create(Io_space *v)
185 { new (v) Io_space_sigma0<Space>(); }