3 #include "thread_object.h"
5 class Kernel_thread : public Thread_object
9 * Frees the memory of the initcall sections.
11 * Virtually initcall sections are freed by not marking them
12 * reserved in the KIP. This method just invalidates the contents of
13 * the memory, by filling it with some invalid data and may be
16 void free_initcall_section();
17 void bootstrap() asm ("call_bootstrap") FIASCO_FASTCALL;
18 void bootstrap_arch();
20 void do_idle() __attribute__((noreturn));
26 INTERFACE [kernel_can_exit]:
28 EXTENSION class Kernel_thread
31 void arch_exit() __attribute__((noreturn));
41 #include "delayloop.h"
43 #include "helping_lock.h"
44 #include "kernel_task.h"
45 #include "processor.h"
48 #include "thread_state.h"
50 #include "vmem_alloc.h"
55 Kernel_thread::Kernel_thread() : Thread_object(Thread::Kernel)
60 Kernel_thread::init_stack()
65 // the kernel bootstrap routine
68 Kernel_thread::bootstrap()
70 // Initializations done -- Helping_lock can now use helping lock
71 Helping_lock::threading_system_active = true;
73 state_change_dirty (0, Thread_ready); // Set myself ready
75 set_cpu_of(this, Cpu::boot_cpu()->id());
76 Timer::init_system_clock();
77 Sched_context::rq(cpu()).set_idle(this->sched());
79 Kernel_task::kernel_task()->mem_space()->make_current();
81 // Setup initial timeslice
82 set_current_sched(sched());
88 Per_cpu_data::run_late_ctors(0);
91 printf("Calibrating timer loop... ");
92 // Init delay loop, needs working timer interrupt
102 * NEVER inline this function, because our caller is an initcall
104 IMPLEMENT FIASCO_NOINLINE FIASCO_NORETURN
108 free_initcall_section();
110 // No initcalls after this point!
112 kernel_context(cpu(), this);
114 // init_workload cannot be an initcall, because it fires up the userland
115 // applications which then have access to initcall frames as per kinfo page.
121 // ------------------------------------------------------------------------
122 IMPLEMENTATION [!arch_idle]:
124 PUBLIC inline NEEDS["processor.h"]
126 Kernel_thread::idle_op()
128 if (Config::hlt_works_ok)
129 Proc::halt(); // stop the CPU, waiting for an int
134 // ------------------------------------------------------------------------
135 IMPLEMENTATION [!kernel_can_exit]:
139 Kernel_thread::do_idle()
145 // ------------------------------------------------------------------------
146 IMPLEMENTATION [kernel_can_exit]:
150 Kernel_thread::do_idle()
158 puts ("\nExiting, wait...");
161 Task *sigma0 = static_cast<Task *>(sigma0_task);
165 boot_task->initiate_deletion(rl.list());
166 boot_task->destroy(rl.list());
168 delete boot_task; // Nuke everything else
170 Helping_lock::threading_system_active = false;