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