]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/main.cpp
update
[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   Mem_unit::tlb_flush();
88
89   // switch to stack of kernel thread and bootstrap the kernel
90   asm volatile
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"
95      :  "=m" (boot_stack)
96      :  "r" (kernel->init_stack()), "r" (kernel));
97 }
98
99 //------------------------------------------------------------------------
100 IMPLEMENTATION[arm && mp]:
101
102 #include <cstdio>
103 #include "config.h"
104 #include "cpu.h"
105 #include "globals.h"
106 #include "app_cpu_thread.h"
107 #include "per_cpu_data_alloc.h"
108 #include "perf_cnt.h"
109 #include "pic.h"
110 #include "spin_lock.h"
111 #include "utcb_init.h"
112
113
114 int boot_ap_cpu(unsigned cpu) __asm__("BOOT_AP_CPU");
115
116 int boot_ap_cpu(unsigned _cpu)
117 {
118   if (!Per_cpu_data_alloc::alloc(_cpu))
119     {
120       extern Spin_lock _tramp_mp_spinlock;
121       printf("CPU allocation failed for CPU%u, disabling CPU.\n", _cpu);
122       _tramp_mp_spinlock.clear();
123       while (1)
124         Proc::halt();
125     }
126   Per_cpu_data::run_ctors(_cpu);
127   Cpu &cpu = Cpu::cpus.cpu(_cpu);
128   cpu.init();
129
130   Utcb_init::init_ap(cpu);
131   Pic::init_ap();
132   Ipi::cpu(_cpu).init();
133   Timer::init();
134   Perf_cnt::init_ap();
135
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));
140
141   // switch to stack of kernel thread and bootstrap the kernel
142   asm volatile
143     ("  mov sp,%0               \n"     // switch stack
144      "  mov r0,%1               \n"     // push "this" pointer
145      "  bl call_ap_bootstrap    \n"
146      :
147      :  "r" (kernel->init_stack()), "r" (kernel));
148   return 0;
149 }
150