4 //---------------------------------------------------------------------------
13 #include "initcalls.h"
14 #include "kmem_alloc.h"
16 #include "pagetable.h"
18 #include "kernel_thread.h"
19 #include "kernel_task.h"
20 #include "kernel_console.h"
23 #include "terminate.h"
25 #include "processor.h"
27 static int exit_question_active = 0;
29 extern "C" void __attribute__ ((noreturn))
32 if(exit_question_active)
35 while(1) { Proc::halt(); Proc::pause(); }
39 static void exit_question()
41 exit_question_active = 1;
45 puts("\nReturn reboots, \"k\" enters L4 kernel debugger...");
47 char c = Kconsole::console()->getchar();
49 if (c == 'k' || c == 'K')
55 // it may be better to not call all the destruction stuff
56 // because of unresolved static destructor dependency
58 // SO just do the reset at this point.
59 puts("\033[1mRebooting...\033[0m");
69 // caution: no stack variables in this function because we're going
70 // to change the stack pointer!
72 // make some basic initializations, then create and run the kernel
74 set_exit_question(&exit_question);
76 printf("%s\n", Kip::k()->version_string());
78 // disallow all interrupts before we selectively enable them
81 // create kernel thread
82 static Kernel_thread *kernel = new (Ram_quota::root) Kernel_thread;
84 Space *const ktask = Kernel_task::kernel_task();
85 check(kernel->bind(ktask, 0));
87 Mem_unit::tlb_flush();
89 // switch to stack of kernel thread and bootstrap the kernel
91 (" str sp,%0 \n" // save stack pointer in safe register
92 " mov sp,%1 \n" // switch stack
93 " mov r0,%2 \n" // push "this" pointer
94 " bl call_bootstrap \n"
96 : "r" (kernel->init_stack()), "r" (kernel));
99 //------------------------------------------------------------------------
100 IMPLEMENTATION[arm && mp]:
106 #include "app_cpu_thread.h"
107 #include "per_cpu_data_alloc.h"
108 #include "perf_cnt.h"
110 #include "spin_lock.h"
111 #include "utcb_init.h"
114 int boot_ap_cpu(unsigned cpu) __asm__("BOOT_AP_CPU");
116 int boot_ap_cpu(unsigned _cpu)
118 if (!Per_cpu_data_alloc::alloc(_cpu))
120 extern Spin_lock _tramp_mp_spinlock;
121 printf("CPU allocation failed for CPU%u, disabling CPU.\n", _cpu);
122 _tramp_mp_spinlock.clear();
126 Per_cpu_data::run_ctors(_cpu);
127 Cpu &cpu = Cpu::cpus.cpu(_cpu);
130 Utcb_init::init_ap(cpu);
132 Ipi::cpu(_cpu).init();
136 // create kernel thread
137 App_cpu_thread *kernel = new (Ram_quota::root) App_cpu_thread();
138 set_cpu_of(kernel, _cpu);
139 check(kernel->bind(Kernel_task::kernel_task(), 0));
141 // switch to stack of kernel thread and bootstrap the kernel
143 (" mov sp,%0 \n" // switch stack
144 " mov r0,%1 \n" // push "this" pointer
145 " bl call_ap_bootstrap \n"
147 : "r" (kernel->init_stack()), "r" (kernel));