]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/app_cpu_thread.cpp
update
[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 "task.h"
24 #include "thread.h"
25 #include "thread_state.h"
26 #include "timer.h"
27 #include "spin_lock.h"
28
29
30 PUBLIC inline
31 Mword *
32 App_cpu_thread::init_stack()
33 { return _kernel_sp; }
34
35 // the kernel bootstrap routine
36 IMPLEMENT
37 void
38 App_cpu_thread::bootstrap()
39 {
40   extern Spin_lock<Mword> _tramp_mp_spinlock;
41
42   state_change_dirty(0, Thread_ready);          // Set myself ready
43
44   // Setup initial timeslice
45   set_current_sched(sched());
46
47   Fpu::init(cpu());
48
49   // initialize the current_mem_space function to point to the kernel space
50   Kernel_task::kernel_task()->mem_space()->make_current();
51
52   Mem_unit::tlb_flush();
53
54   Cpu::cpus.cpu(current_cpu()).set_online(1);
55
56   _tramp_mp_spinlock.set(1);
57
58   kernel_context(cpu(), this);
59   Sched_context::rq(cpu()).set_idle(this->sched());
60
61   Timer::enable();
62
63   Per_cpu_data::run_late_ctors(cpu());
64
65   cpu_lock.clear();
66
67   printf("CPU[%u]: goes to idle loop\n", cpu());
68
69   do_app_idle();
70 }
71
72 // ------------------------------------------------------------------------
73 IMPLEMENTATION [mp && !kernel_can_exit]:
74
75 PRIVATE inline
76 void
77 App_cpu_thread::do_app_idle()
78 {
79   while (1)
80     idle_op();
81 }
82
83 // ------------------------------------------------------------------------
84 IMPLEMENTATION [mp && kernel_can_exit]:
85
86 PRIVATE inline
87 void
88 App_cpu_thread::do_app_idle()
89 {
90   while (running)
91     {
92       Mem::rmb();
93       idle_op();
94     }
95
96   // Boost this thread's priority to the maximum. Since this thread tears down
97   // all other threads, we want it to run whenever possible to advance as fast
98   // as we can.
99   ready_dequeue();
100   sched()->set_prio(255);
101   ready_enqueue();
102   Proc::cli();
103   while(1)
104     Proc::halt();
105 }