]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/main.cpp
d6292789e77cd36ec0439b6fa2d56e251a773b64
[l4.git] / kernel / fiasco / src / kern / arm / main.cpp
1 INTERFACE [arm]:
2 #include <cstddef>
3
4 //---------------------------------------------------------------------------
5 IMPLEMENTATION [arm]:
6
7 #include <cstdlib>
8 #include <cstdio>
9 #include <cstring>
10
11 #include "config.h"
12 #include "globals.h"
13 #include "initcalls.h"
14 #include "kmem_alloc.h"
15 #include "kip_init.h"
16 #include "pagetable.h"
17 #include "kdb_ke.h"
18 #include "kernel_thread.h"
19 #include "kernel_task.h"
20 #include "kernel_console.h"
21 #include "reset.h"
22 #include "space.h"
23 #include "terminate.h"
24
25 #include "processor.h"
26
27 static int exit_question_active = 0;
28
29 extern "C" void __attribute__ ((noreturn))
30 _exit(int)
31 {
32   if(exit_question_active)
33     pc_reset();
34   else
35     while(1) { Proc::halt(); Proc::pause(); }
36 }
37
38
39 static void exit_question()
40 {
41   exit_question_active = 1;
42
43   while (1)
44     {
45       puts("\nReturn reboots, \"k\" enters L4 kernel debugger...");
46
47       char c = Kconsole::console()->getchar();
48
49       if (c == 'k' || c == 'K')
50         {
51           kdb_ke("_exit");
52         }
53       else
54         {
55           // it may be better to not call all the destruction stuff
56           // because of unresolved static destructor dependency
57           // problems.
58           // SO just do the reset at this point.
59           puts("\033[1mRebooting...\033[0m");
60           pc_reset();
61           break;
62         }
63     }
64 }
65
66 void
67 kernel_main()
68 {
69   // caution: no stack variables in this function because we're going
70   // to change the stack pointer!
71
72   // make some basic initializations, then create and run the kernel
73   // thread
74   set_exit_question(&exit_question);
75
76   printf("%s\n", Kip::k()->version_string());
77
78   // disallow all interrupts before we selectively enable them
79   //  pic_disable_all();
80
81   // create kernel thread
82   static Kernel_thread *kernel = new (Ram_quota::root) Kernel_thread;
83   nil_thread = kernel;
84   Space *const ktask = Kernel_task::kernel_task();
85   check(kernel->bind(ktask, 0));
86
87   // switch to stack of kernel thread and bootstrap the kernel
88   asm volatile
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"
93      :  "=m" (boot_stack)
94      :  "r" (kernel->init_stack()), "r" (kernel));
95 }
96
97 //------------------------------------------------------------------------
98 IMPLEMENTATION[arm && mp]:
99
100 #include <cstdio>
101 #include "config.h"
102 #include "cpu.h"
103 #include "globals.h"
104 #include "app_cpu_thread.h"
105 #include "per_cpu_data_alloc.h"
106 #include "perf_cnt.h"
107 #include "pic.h"
108 #include "spin_lock.h"
109 #include "utcb_init.h"
110
111
112 int boot_ap_cpu(unsigned cpu) __asm__("BOOT_AP_CPU");
113
114 int boot_ap_cpu(unsigned _cpu)
115 {
116   if (!Per_cpu_data_alloc::alloc(_cpu))
117     {
118       extern Spin_lock _tramp_mp_spinlock;
119       printf("CPU allocation failed for CPU%u, disabling CPU.\n", _cpu);
120       _tramp_mp_spinlock.clear();
121       while (1)
122         Proc::halt();
123     }
124   Per_cpu_data::run_ctors(_cpu);
125   Cpu &cpu = Cpu::cpus.cpu(_cpu);
126   cpu.init();
127
128   Utcb_init::init_ap(cpu);
129   Pic::init_ap();
130   Ipi::cpu(_cpu).init();
131   Timer::init();
132   Perf_cnt::init_ap();
133
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));
138
139   // switch to stack of kernel thread and bootstrap the kernel
140   asm volatile
141     ("  mov sp,%0               \n"     // switch stack
142      "  mov r0,%1               \n"     // push "this" pointer
143      "  bl call_ap_bootstrap    \n"
144      :
145      :  "r" (kernel->init_stack()), "r" (kernel));
146   return 0;
147 }
148