]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/64/main-ia32-64.cpp
Inital import
[l4.git] / kernel / fiasco / src / kern / ia32 / 64 / main-ia32-64.cpp
1 /*
2  * Fiasco AMD64
3  * Shared main startup/shutdown code
4  */
5
6 INTERFACE[amd64]:
7
8 #include "initcalls.h"
9
10 class Kernel_thread;
11
12
13 IMPLEMENTATION[amd64]:
14
15 #include <cstdio>
16 #include "config.h"
17 #include "cpu.h"
18 #include "div32.h"
19 #include "globals.h"
20 #include "kernel_thread.h"
21 #include "kernel_task.h"
22
23 FIASCO_INIT
24 void
25 kernel_main (void)
26 {
27   unsigned dummy;
28
29   Cpu const &cpu = *Cpu::boot_cpu();
30
31   // caution: no stack variables in this function because we're going
32   // to change the stack pointer!
33
34   printf ("CPU[%u]: %s (%X:%X:%X:%X) Model: %s at %llu MHz\n\n",
35            cpu.id(),
36            cpu.vendor_str(), cpu.family(), cpu.model(),
37            cpu.stepping(), cpu.brand(), cpu.model_str(),
38            div32(cpu.frequency(), 1000000));
39
40   cpu.show_cache_tlb_info("");
41
42   printf ("\nFreeing init code/data: %lu bytes (%lu pages)\n\n",
43           (Address)(&Mem_layout::initcall_end - &Mem_layout::initcall_start),
44           (Address)(&Mem_layout::initcall_end - &Mem_layout::initcall_start 
45              >> Config::PAGE_SHIFT));
46
47   // Perform architecture specific initialization
48   main_arch();
49
50   // create kernel thread
51   static Kernel_thread *kernel = new (Ram_quota::root) Kernel_thread;
52   nil_thread = kernel;
53   Space *const ktask = Kernel_task::kernel_task();
54   check(kernel->bind(ktask, 0));
55
56   // switch to stack of kernel thread and bootstrap the kernel
57   asm volatile
58     ("  movq %%rax, %%cr3       \n\t"   // restore proper cr3 after running on the mp boot dir
59      "  movq %%rsp, %0          \n\t"   // save stack pointer in safe variable
60      "  movq %4, %%rsp          \n\t"   // switch stack
61      "  call call_bootstrap     \n\t"   // bootstrap kernel thread
62      :  "=m" (boot_stack), "=a" (dummy), "=c" (dummy), "=d" (dummy)
63      :  "S" (kernel->init_stack()), "D" (kernel),
64         "a" (Mem_layout::pmem_to_phys(Kmem::dir())));
65 }
66
67
68 //------------------------------------------------------------------------
69 IMPLEMENTATION[(amd64) && mp]:
70
71 #include "kernel_thread.h"
72
73 void
74 main_switch_ap_cpu_stack(Kernel_thread *kernel)
75 {
76   Mword dummy;
77
78   // switch to stack of kernel thread and bootstrap the kernel
79   asm volatile
80     ("  mov %%rsi, %%rsp        \n\t"   // switch stack
81      "  call call_ap_bootstrap  \n\t"   // bootstrap kernel thread
82      :  "=a" (dummy), "=c" (dummy), "=d" (dummy)
83      :  "a"(kernel), "S" (kernel->init_stack()));
84 }