]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/boot/bootstrap.cc
update
[l4.git] / kernel / fiasco / src / boot / bootstrap.cc
1 /* this code is run directly from boot.S.  our task is to setup the
2    paging just enough so that L4 can run in its native address space 
3    at 0xf0001000, and then start up L4.  */
4
5 #include <cassert>
6 #include <cstring>
7 #include <cstdio>
8 #include <cstdlib>
9
10 #include "boot_cpu.h"
11 #include "boot_paging.h"
12 #include "boot_console.h"
13 #include "kernel_console.h"
14 #include "checksum.h"
15 #include "config.h"
16 #include "globalconfig.h"
17 #include "kip.h"
18 #include "kmem_alloc.h"
19 #include "mem_layout.h"
20 #include "mem_region.h"
21 #include "panic.h"
22 #include "processor.h"
23 #include "reset.h"
24 #include "mem_unit.h"
25
26 struct check_sum
27 {
28   char delimiter[16];
29   Unsigned32 checksum_ro;
30   Unsigned32 checksum_rw;
31 } check_sum = {"FIASCOCHECKSUM=", 0, 0};
32
33 extern "C" char _start[];
34 extern "C" char _end[];
35
36 extern "C" void exit(int rc) __attribute__((noreturn));
37
38 void
39 exit(int)
40 {
41   for (;;)
42     Proc::pause();
43 }
44
45 // test if [start1..end1-1] overlaps [start2..end2-1]
46 static
47 void
48 check_overlap (const char *str,
49                Address start1, Address end1, Address start2, Address end2)
50 {
51   if ((start1 >= start2 && start1 < end2) || (end1 > start2 && end1 <= end2))
52     panic("Kernel [0x%014lx,0x%014lx) overlaps %s [0x%014lx,0x%014lx).",
53           start1, end1, str, start2, end2);
54 }
55
56 typedef void (*Start)(unsigned) FIASCO_FASTCALL;
57
58 extern "C" FIASCO_FASTCALL
59 void
60 bootstrap()
61 {
62   extern Kip my_kernel_info_page;
63   Start start;
64
65   // setup stuff for base_paging_init()
66   base_cpu_setup();
67   // now do base_paging_init(): sets up paging with one-to-one mapping
68   base_paging_init();
69
70   asm volatile ("" ::: "memory");
71
72   Kip::init_global_kip(&my_kernel_info_page);
73   Kconsole::init();
74   Boot_console::init();
75   printf("Boot: KIP @ %p\n", Kip::k());
76
77   printf("Boot: Kmem_alloc::base_init();\n");
78   if (!Kmem_alloc::base_init())
79     {
80       panic("FATAL: Could not reserve kernel memory, halted\n");
81     }
82   printf("Boot: kernel memory reserved\n");
83
84   // make sure that we did not forgot to discard an unused header section
85   // (compare "objdump -p fiasco.image")
86   if ((Address)_start < Mem_layout::Kernel_image)
87     panic("Fiasco kernel occupies memory below %014lx",
88           (unsigned long)Mem_layout::Kernel_image);
89
90   if ((Address)&_end - Mem_layout::Kernel_image > 4<<20)
91     panic("Fiasco boot system occupies more than 4MB");
92
93   base_map_physical_memory_for_kernel();
94
95   Mem_unit::tlb_flush();
96
97   start = (Start)_start;
98
99   Address phys_start = (Address)_start - Mem_layout::Kernel_image + Mem_layout::Kernel_image_phys;
100   Address phys_end   = (Address)_end   - Mem_layout::Kernel_image + Mem_layout::Kernel_image_phys;
101   check_overlap ("VGA/IO", phys_start, phys_end, 0xa0000, 0x100000);
102
103   if (Checksum::get_checksum_ro() != check_sum.checksum_ro)
104     panic("Read-only (text) checksum does not match.");
105
106   if (Checksum::get_checksum_rw() != check_sum.checksum_rw)
107     panic("Read-write (data) checksum does not match.");
108
109   start(check_sum.checksum_ro);
110 }