]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/app_cpu_thread.cpp
1c7a16ba60ad2518e6c681438ce3a7ebb152350b
[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   Per_cpu_data::run_late_ctors(cpu());
65
66   cpu_lock.clear();
67
68   printf("CPU[%u]: goes to idle loop\n", cpu());
69
70   do_app_idle();
71 }
72
73 // ------------------------------------------------------------------------
74 IMPLEMENTATION [mp && !kernel_can_exit]:
75
76 PRIVATE inline
77 void
78 App_cpu_thread::do_app_idle()
79 {
80   while (1)
81     idle_op();
82 }
83
84 // ------------------------------------------------------------------------
85 IMPLEMENTATION [mp && kernel_can_exit]:
86
87 PRIVATE inline
88 void
89 App_cpu_thread::do_app_idle()
90 {
91   while (running)
92     {
93       Mem::rmb();
94       idle_op();
95     }
96
97   // Boost this thread's priority to the maximum. Since this thread tears down
98   // all other threads, we want it to run whenever possible to advance as fast
99   // as we can.
100   ready_dequeue();
101   sched()->set_prio(255);
102   ready_enqueue();
103   Proc::cli();
104   while(1)
105     Proc::halt();
106 }