]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/app_cpu_thread.cpp
384d1a595aed3867454d821038e9a022d7c565e5
[l4.git] / kernel / fiasco / src / kern / app_cpu_thread.cpp
1 INTERFACE [mp]:
2
3 #include "kernel_thread.h"
4
5 class App_cpu_thread : public Kernel_thread
6 {
7 private:
8   void bootstrap() asm ("call_ap_bootstrap") FIASCO_FASTCALL;
9 };
10
11 IMPLEMENTATION [mp]:
12
13 #include <cstdlib>
14 #include <cstdio>
15
16 #include "config.h"
17 #include "delayloop.h"
18 #include "fpu.h"
19 #include "globals.h"
20 #include "helping_lock.h"
21 #include "kernel_task.h"
22 #include "processor.h"
23 #include "scheduler.h"
24 #include "task.h"
25 #include "thread.h"
26 #include "thread_state.h"
27 #include "timer.h"
28 #include "timer_tick.h"
29 #include "spin_lock.h"
30
31 PUBLIC static
32 Kernel_thread *
33 App_cpu_thread::may_be_create(unsigned cpu, bool cpu_never_seen_before)
34 {
35   if (!cpu_never_seen_before)
36     return static_cast<Kernel_thread *>(kernel_context(cpu));
37
38   Kernel_thread *t = new (Ram_quota::root) App_cpu_thread;
39   assert (t);
40
41   set_cpu_of(t, cpu);
42   check(t->bind(Kernel_task::kernel_task(), User<Utcb>::Ptr(0)));
43   return t;
44 }
45
46
47 // the kernel bootstrap routine
48 IMPLEMENT
49 void
50 App_cpu_thread::bootstrap()
51 {
52   extern Spin_lock<Mword> _tramp_mp_spinlock;
53
54   state_change_dirty(0, Thread_ready);          // Set myself ready
55
56
57   Fpu::init(cpu(true));
58
59   // initialize the current_mem_space function to point to the kernel space
60   Kernel_task::kernel_task()->make_current();
61
62   Mem_unit::tlb_flush();
63
64   Cpu::cpus.current().set_online(1);
65
66   _tramp_mp_spinlock.set(1);
67
68   kernel_context(cpu(true), this);
69   Sched_context::rq.current().set_idle(this->sched());
70   Rcu::leave_idle(cpu(true));
71
72   Timer_tick::setup(cpu(true));
73   Timer_tick::enable(cpu(true));
74   enable_tlb(cpu(true));
75   // Setup initial timeslice
76   Sched_context::rq.current().set_current_sched(sched());
77
78   Per_cpu_data::run_late_ctors(cpu(true));
79
80   Scheduler::scheduler.trigger_hotplug_event();
81
82   cpu_lock.clear();
83
84   printf("CPU[%u]: goes to idle loop\n", cpu(true));
85
86   for (;;)
87     idle_op();
88 }