]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_thread-std.cpp
2867ed06c0d5cc408bd64b8b8cb2cd8f323870db
[l4.git] / kernel / fiasco / src / kern / kernel_thread-std.cpp
1 IMPLEMENTATION:
2
3 #include "assert_opt.h"
4 #include "config.h"
5 #include "factory.h"
6 #include "initcalls.h"
7 #include "ipc_gate.h"
8 #include "irq.h"
9 #include "koptions.h"
10 #include "map_util.h"
11 #include "mem_layout.h"
12 #include "sigma0_task.h"
13 #include "task.h"
14 #include "thread_object.h"
15 #include "types.h"
16 #include "ram_quota.h"
17
18 enum Default_base_caps
19 {
20   C_task      = 1,
21   C_factory   = 2,
22   C_thread    = 3,
23   C_pager     = 4,
24   C_log       = 5,
25   C_icu       = 6,
26   C_scheduler = 7
27
28 };
29
30
31 IMPLEMENT
32 void
33 Kernel_thread::init_workload()
34 {
35   auto g = lock_guard(cpu_lock);
36
37   if (Config::Jdb &&
38       !Koptions::o()->opt(Koptions::F_nojdb) &&
39       Koptions::o()->opt(Koptions::F_jdb_cmd))
40     {
41       // extract the control sequence from the command line
42       char ctrl[128];
43       char const *s = Koptions::o()->jdb_cmd;
44       char *d;
45
46       for (d=ctrl; d < ctrl+sizeof(ctrl)-1 && *s && *s != ' '; *d++ = *s++)
47         ;
48       *d = '\0';
49
50       kdb_ke_sequence(ctrl);
51     }
52
53   // kernel debugger rendezvous
54   if (Koptions::o()->opt(Koptions::F_wait))
55     kdb_ke("Wait");
56
57   //
58   // create sigma0
59   //
60
61   Task *sigma0 = Task::create<Sigma0_task>(Ram_quota::root,
62       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT));
63
64   assert_opt (sigma0);
65   // prevent deletion of this thing
66   sigma0->inc_ref();
67
68   init_mapdb_mem(sigma0);
69   init_mapdb_io(sigma0);
70
71   check (map(sigma0,          sigma0, sigma0, C_task, 0));
72   check (map(Factory::root(), sigma0, sigma0, C_factory, 0));
73
74   for (unsigned c = Initial_kobjects::First_cap; c < Initial_kobjects::End_cap; ++c)
75     {
76       Kobject_iface *o = initial_kobjects.obj(c);
77       if (o)
78         check(map(o, sigma0, sigma0, c, 0));
79     }
80
81   Thread_object *sigma0_thread = new (Ram_quota::root) Thread_object();
82
83   assert_kdb(sigma0_thread);
84
85   // prevent deletion of this thing
86   sigma0_thread->inc_ref();
87   check (map(sigma0_thread, sigma0, sigma0, C_thread, 0));
88
89   Address sp = init_workload_s0_stack();
90   check (sigma0_thread->control(Thread_ptr(false), Thread_ptr(false)) == 0);
91   check (sigma0_thread->bind(sigma0, User<Utcb>::Ptr((Utcb*)Mem_layout::Utcb_addr)));
92   check (sigma0_thread->ex_regs(Kip::k()->sigma0_ip, sp));
93
94   //
95   // create the boot task
96   //
97
98   Task *boot_task = Task::create<Task>(Ram_quota::root,
99       L4_fpage::mem(Mem_layout::Utcb_addr, Config::PAGE_SHIFT+2));
100
101   assert_opt (boot_task);
102
103   // prevent deletion of this thing
104   boot_task->inc_ref();
105
106   Thread_object *boot_thread = new (Ram_quota::root) Thread_object();
107
108   assert_kdb (boot_thread);
109
110   // prevent deletion of this thing
111   boot_thread->inc_ref();
112
113   check (map(boot_task,   boot_task, boot_task, C_task, 0));
114   check (map(boot_thread, boot_task, boot_task, C_thread, 0));
115
116   check (boot_thread->control(Thread_ptr(C_pager), Thread_ptr(~0UL)) == 0);
117   check (boot_thread->bind(boot_task, User<Utcb>::Ptr((Utcb*)Mem_layout::Utcb_addr)));
118   check (boot_thread->ex_regs(Kip::k()->root_ip, Kip::k()->root_sp));
119
120   Ipc_gate *s0_b_gate = Ipc_gate::create(Ram_quota::root, sigma0_thread, 4 << 4);
121
122   check (s0_b_gate);
123   check (map(s0_b_gate, boot_task, boot_task, C_pager, 0));
124
125   set_cpu_of(sigma0_thread, 0);
126   set_cpu_of(boot_thread, 0);
127
128   sigma0_thread->activate();
129   check (obj_map(sigma0, C_factory,   1, boot_task, C_factory, 0).error() == 0);
130   for (unsigned c = Initial_kobjects::First_cap; c < Initial_kobjects::End_cap; ++c)
131     {
132       Kobject_iface *o = initial_kobjects.obj(c);
133       if (o)
134         check(obj_map(sigma0, c, 1, boot_task, c, 0).error() == 0);
135     }
136
137   boot_thread->activate();
138 }
139
140 IMPLEMENTATION [ia32,amd64]:
141
142 PRIVATE inline
143 Address
144 Kernel_thread::init_workload_s0_stack()
145 {
146   // push address of kernel info page to sigma0's stack
147   Address sp = Kip::k()->sigma0_sp - sizeof(Mword);
148   // assume we run in kdir 1:1 mapping
149   *reinterpret_cast<Address*>(sp) = Kmem::virt_to_phys(Kip::k());
150   return sp;
151 }
152
153 IMPLEMENTATION [ux,arm,ppc32,sparc]:
154
155 PRIVATE inline
156 Address
157 Kernel_thread::init_workload_s0_stack()
158 { return Kip::k()->sigma0_sp; }
159