]> 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 "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   Mem_unit::tlb_flush();
56
57   Cpu::cpus.cpu(current_cpu()).set_online(1);
58
59   _tramp_mp_spinlock.set(1);
60
61   kernel_context(cpu(), this);
62   Sched_context::rq(cpu()).set_idle(this->sched());
63
64   Timer::enable();
65
66   Per_cpu_data::run_late_ctors(cpu());
67
68   cpu_lock.clear();
69
70   printf("CPU[%u]: goes to idle loop\n", cpu());
71
72   do_app_idle();
73 }
74
75 // ------------------------------------------------------------------------
76 IMPLEMENTATION [mp && !kernel_can_exit]:
77
78 PRIVATE inline
79 void
80 App_cpu_thread::do_app_idle()
81 {
82   while (1)
83     idle_op();
84 }
85
86 // ------------------------------------------------------------------------
87 IMPLEMENTATION [mp && kernel_can_exit]:
88
89 PRIVATE inline
90 void
91 App_cpu_thread::do_app_idle()
92 {
93   while (running)
94     {
95       Mem::rmb();
96       idle_op();
97     }
98
99   // Boost this thread's priority to the maximum. Since this thread tears down
100   // all other threads, we want it to run whenever possible to advance as fast
101   // as we can.
102   ready_dequeue();
103   sched()->set_prio(255);
104   ready_enqueue();
105   Proc::cli();
106   while(1)
107     Proc::halt();
108 }