]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap/server/src/ARCH-amd64/boot32/boot_kernel.c
f7b6e1492e70926ffb6aa93620d6771b23dbea73
[l4.git] / l4 / pkg / bootstrap / server / src / ARCH-amd64 / boot32 / boot_kernel.c
1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *          Alexander Warg <warg@os.inf.tu-dresden.de>,
4  *          Frank Mehnert <fm3@os.inf.tu-dresden.de>
5  *     economic rights: Technische Universität Dresden (Germany)
6  *
7  * This file is part of TUD:OS and distributed under the terms of the
8  * GNU General Public License 2.
9  * Please see the COPYING-GPL-2 file for details.
10  */
11 #include <stdio.h>
12 #include <l4/util/mb_info.h>
13 #include "boot_cpu.h"
14 #include "boot_paging.h"
15 #include "load_elf.h"
16
17 extern unsigned KERNEL_CS_64;
18 extern char _binary_bootstrap64_bin_start;
19
20 static l4_uint64_t find_upper_mem(l4util_mb_info_t *mbi)
21 {
22   l4_uint64_t max = 0;
23   l4util_mb_addr_range_t *mmap;
24   l4util_mb_for_each_mmap_entry(mmap, mbi)
25     {
26       if (max < mmap->addr + mmap->size)
27         max = mmap->addr + mmap->size;
28     }
29   return max;
30 }
31
32 void bootstrap (l4util_mb_info_t *mbi, unsigned int flag, char *rm_pointer);
33 void
34 bootstrap (l4util_mb_info_t *mbi, unsigned int flag, char *rm_pointer)
35 {
36   l4_uint32_t vma_start, vma_end;
37   struct
38   {
39     l4_uint32_t start;
40     l4_uint16_t cs __attribute__((packed));
41   } far_ptr;
42   l4_uint64_t mem_upper;
43
44   // setup stuff for base_paging_init() 
45   base_cpu_setup();
46
47 #ifdef REALMODE_LOADING
48   mem_upper = *(unsigned long*)(rm_pointer + 0x1e0);
49   mem_upper = 1024 * (1024 + mem_upper);
50 #else
51   mem_upper = find_upper_mem(mbi);
52   if (!mem_upper)
53     mem_upper = 1024 * (1024 + mbi->mem_upper);
54 #endif
55
56   printf("Highest physical memory address found: %llx\n", mem_upper);
57   // now do base_paging_init(): sets up paging with one-to-one mapping
58   base_paging_init(round_superpage(mem_upper));
59
60   printf("Loading 64bit part...\n");
61   // switch from 32 Bit compatibility mode to 64 Bit mode
62   far_ptr.cs    = KERNEL_CS_64;
63   far_ptr.start = load_elf(&_binary_bootstrap64_bin_start, 
64                            &vma_start, &vma_end);
65
66   asm volatile("ljmp *(%4)"
67                 :: "D"(mbi), "S"(flag), "d"(rm_pointer),
68                    "c"(&ptab64_mem_info),
69                    "r"(&far_ptr), "m"(far_ptr));
70 }