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 // switch to stack of kernel thread and bootstrap the kernel
89 (" str sp,%0 \n" // save stack pointer in safe register
90 " mov sp,%1 \n" // switch stack
91 " mov r0,%2 \n" // push "this" pointer
92 " bl call_bootstrap \n"
94 : "r" (kernel->init_stack()), "r" (kernel));
97 //------------------------------------------------------------------------
98 IMPLEMENTATION[arm && mp]:
104 #include "app_cpu_thread.h"
105 #include "per_cpu_data_alloc.h"
106 #include "perf_cnt.h"
108 #include "spin_lock.h"
109 #include "utcb_init.h"
112 int boot_ap_cpu(unsigned cpu) __asm__("BOOT_AP_CPU");
114 int boot_ap_cpu(unsigned _cpu)
116 if (!Per_cpu_data_alloc::alloc(_cpu))
118 extern Spin_lock _tramp_mp_spinlock;
119 printf("CPU allocation failed for CPU%u, disabling CPU.\n", _cpu);
120 _tramp_mp_spinlock.clear();
124 Per_cpu_data::run_ctors(_cpu);
125 Cpu &cpu = Cpu::cpus.cpu(_cpu);
128 Utcb_init::init_ap(cpu);
130 Ipi::cpu(_cpu).init();
134 // create kernel thread
135 App_cpu_thread *kernel = new (Ram_quota::root) App_cpu_thread();
136 set_cpu_of(kernel, _cpu);
137 check(kernel->bind(Kernel_task::kernel_task(), 0));
139 // switch to stack of kernel thread and bootstrap the kernel
141 (" mov sp,%0 \n" // switch stack
142 " mov r0,%1 \n" // push "this" pointer
143 " bl call_ap_bootstrap \n"
145 : "r" (kernel->init_stack()), "r" (kernel));