]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/boot/bootstrap.cc
9ce820f19cb73402abc9d9937fc49eb35b460728
[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 "checksum.h"
14 #include "config.h"
15 #include "globalconfig.h"
16 #include "kip.h"
17 #include "kmem_alloc.h"
18 #include "mem_layout.h"
19 #include "mem_region.h"
20 #include "multiboot.h"
21 #include "panic.h"
22 #include "processor.h"
23 #include "reset.h"
24
25 struct check_sum
26 {
27   char delimiter[16];
28   Unsigned32 checksum_ro;
29   Unsigned32 checksum_rw;
30 } check_sum = {"FIASCOCHECKSUM=", 0, 0};
31
32 extern "C" char _start[];
33 extern "C" char _end[];
34
35 extern "C" void exit(int rc) __attribute__((noreturn));
36
37 void
38 exit(int)
39 {
40   for (;;)
41     Proc::pause();
42 }
43
44 // test if [start1..end1-1] overlaps [start2..end2-1]
45 static
46 void
47 check_overlap (const char *str,
48                Address start1, Address end1, Address start2, Address end2)
49 {
50   if ((start1 >= start2 && start1 < end2) || (end1 > start2 && end1 <= end2))
51     panic("Kernel [0x%014lx,0x%014lx) overlaps %s [0x%014lx,0x%014lx).",
52           start1, end1, str, start2, end2);
53 }
54
55 typedef void (*Start)(Multiboot_info *, unsigned, unsigned) FIASCO_FASTCALL;
56
57 extern "C" FIASCO_FASTCALL
58 void
59 bootstrap (Multiboot_info *mbi, unsigned int flag)
60 {
61   extern Kip my_kernel_info_page;
62   Start start;
63
64   assert(flag == Multiboot_header::Valid);
65
66   // setup stuff for base_paging_init() 
67   base_cpu_setup();
68   // now do base_paging_init(): sets up paging with one-to-one mapping
69   base_paging_init();
70
71   asm volatile ("" ::: "memory");
72
73   Kip::init_global_kip(&my_kernel_info_page);
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   start = (Start)_start;
96
97   Address phys_start = (Address)_start - Mem_layout::Kernel_image;
98   Address phys_end   = (Address)_end   - Mem_layout::Kernel_image;
99   check_overlap ("VGA/IO", phys_start, phys_end, 0xa0000, 0x100000);
100
101   if (Checksum::get_checksum_ro() != check_sum.checksum_ro)
102     panic("Read-only (text) checksum does not match.");
103
104   if (Checksum::get_checksum_rw() != check_sum.checksum_rw)
105     panic("Read-write (data) checksum does not match.");
106
107   start (mbi, flag, check_sum.checksum_ro);
108 }