]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/main-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / main-ia32.cpp
1 /*
2  * Fiasco-IA32/AMD64
3  * Architecture specific main startup/shutdown code
4  */
5
6 IMPLEMENTATION[ia32,amd64]:
7
8 #include <cstdio>
9 #include <cstring>
10 #include <cstdlib>
11 #include "config.h"
12 #include "io.h"
13 #include "idt.h"
14 #include "kdb_ke.h"
15 #include "kernel_console.h"
16 #include "koptions.h"
17 #include "pic.h"
18 #include "processor.h"
19 #include "reset.h"
20 #include "timer.h"
21 #include "terminate.h"
22
23 int exit_question_active;
24
25
26 extern "C" void __attribute__ ((noreturn))
27 _exit(int)
28 {
29   if (exit_question_active)
30     pc_reset();
31
32   while(1)
33     { 
34       Proc::halt(); 
35       Proc::pause();
36     }
37 }
38
39
40 static
41 void
42 exit_question()
43 {
44   Proc::cli();
45   exit_question_active = 1;
46
47   Pic::Status irqs = Pic::disable_all_save();
48   if (Config::getchar_does_hlt && Config::getchar_does_hlt_works_ok)
49     {
50       Idt::set_vectors_stop();
51       Timer::enable();
52       Proc::sti();
53     }
54
55   // make sure that we don't acknowledg the exit question automatically
56   Kconsole::console()->change_state(Console::PUSH, 0, ~Console::INENABLED, 0);
57   puts("\nReturn reboots, \"k\" enters L4 kernel debugger...");
58
59   char c = Kconsole::console()->getchar();
60
61   if (c == 'k' || c == 'K') 
62     {
63       Pic::restore_all(irqs);
64       kdb_ke("_exit");
65     }
66   else
67     {
68       // It may be better to not call all the destruction stuff because of
69       // unresolved static destructor dependency problems. So just do the
70       // reset at this point.
71       puts("\033[1mRebooting.\033[m");
72     }
73 }
74
75 void
76 main_arch()
77 {
78   // console initialization
79   set_exit_question(&exit_question);
80
81   //Pic::disable_all_save();
82 }
83
84
85 //------------------------------------------------------------------------
86 IMPLEMENTATION[(ia32,amd64) && mp]:
87
88 #include <cstdio>
89 #include "apic.h"
90 #include "app_cpu_thread.h"
91 #include "config.h"
92 #include "cpu.h"
93 #include "div32.h"
94 #include "fpu.h"
95 #include "globals.h"
96 #include "ipi.h"
97 #include "kernel_task.h"
98 #include "processor.h"
99 #include "per_cpu_data_alloc.h"
100 #include "perf_cnt.h"
101 #include "spin_lock.h"
102 #include "utcb_init.h"
103
104 int FIASCO_FASTCALL boot_ap_cpu(unsigned _cpu) __asm__("BOOT_AP_CPU");
105
106 int boot_ap_cpu(unsigned _cpu)
107 {
108   if (!Per_cpu_data_alloc::alloc(_cpu))
109     {
110       extern Spin_lock<Mword> _tramp_mp_spinlock;
111       printf("CPU allocation failed for CPU%u, disabling CPU.\n", _cpu);
112       _tramp_mp_spinlock.clear();
113       while (1)
114         Proc::halt();
115     }
116   Per_cpu_data::run_ctors(_cpu);
117   Cpu &cpu = Cpu::cpus.cpu(_cpu);
118
119   Kmem::init_cpu(cpu);
120   Idt::load();
121   Utcb_init::init_ap(cpu);
122
123   Apic::init_ap();
124   Ipi::cpu(_cpu).init();
125   Timer::init();
126   Apic::check_still_getting_interrupts();
127
128
129   // caution: no stack variables in this function because we're going
130   // to change the stack pointer!
131   cpu.print();
132   cpu.show_cache_tlb_info("");
133
134   if (Koptions::o()->opt(Koptions::F_loadcnt))
135     Perf_cnt::init_ap();
136
137   puts("");
138
139   // create kernel thread
140   App_cpu_thread *kernel = new (Ram_quota::root) App_cpu_thread();
141   set_cpu_of(kernel, _cpu);
142   check(kernel->bind(Kernel_task::kernel_task(), User<Utcb>::Ptr(0)));
143
144   main_switch_ap_cpu_stack(kernel);
145   return 0;
146 }