]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap/server/src/init_kip_v4.cc
update
[l4.git] / l4 / pkg / bootstrap / server / src / init_kip_v4.cc
1 /**
2  * \file
3  */
4 /*
5  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
6  *               Alexander Warg <warg@os.inf.tu-dresden.de>,
7  *               Frank Mehnert <fm3@os.inf.tu-dresden.de>
8  *     economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  */
14
15 #include "init_kip.h"
16 #include "startup.h"
17 #include "region.h"
18 #include <l4/sys/kip>
19 #include <l4/sys/l4int.h>
20
21 using L4::Kip::Mem_desc;
22
23 /* XXX not possible to include kip.h from L4Ka::Pistachio here */
24
25 #if L4_MWORD_BITS == 32
26 #define V4KIP_SIGMA0_SP         0x20
27 #define V4KIP_SIGMA0_IP         0x24
28 #define V4KIP_SIGMA0_LOW        0x28
29 #define V4KIP_SIGMA0_HIGH       0x2C
30 #define V4KIP_ROOT_SP           0x40
31 #define V4KIP_ROOT_IP           0x44
32 #define V4KIP_ROOT_LOW          0x48
33 #define V4KIP_ROOT_HIGH         0x4C
34 #define V4KIP_MEM_INFO          0x54
35 #define V4KIP_BOOT_INFO         0xB8
36 #elif L4_MWORD_BITS == 64
37 #define V4KIP_SIGMA0_SP         0x40
38 #define V4KIP_SIGMA0_IP         0x48
39 #define V4KIP_SIGMA0_LOW        0x50
40 #define V4KIP_SIGMA0_HIGH       0x58
41 #define V4KIP_ROOT_SP           0x80
42 #define V4KIP_ROOT_IP           0x88
43 #define V4KIP_ROOT_LOW          0x90
44 #define V4KIP_ROOT_HIGH         0x98
45 #define V4KIP_MEM_INFO          0xA8
46 #define V4KIP_BOOT_INFO         0x170
47 #else
48 #error unknown architecture
49 #endif
50
51 #define V4KIP_WORD(kip,offset)  ((l4_umword_t*)(((char*)(kip))+(offset)))
52
53 /**
54  * @brief Initialize KIP prototype for Fiasco/v4.
55  */
56 void
57 init_kip_v4 (void *l4i, boot_info_t *bi, l4util_mb_info_t *mbi, 
58     Region_list *ram, Region_list *regions)
59 {
60   Mem_desc *md = Mem_desc::first(l4i);
61   for (Region const* c = ram->begin(); c != ram->end(); ++c)
62     (md++)->set(c->begin(), c->end(), Mem_desc::Conventional);
63
64 #if 0
65   // 1: all memory is accessible for users
66   *p++ = 0 | 4;
67   *p++ = ~0UL;
68   num_info++;
69
70   // 4: (additional) 20MB kernel memory
71   if (mem_end > (240 << 20))
72       mem_end = 240 << 20;
73   *p++ = (mem_end - (20 << 20)) | 2;
74   *p++ = mem_end;
75   num_info++;
76 #endif
77
78   // VGA
79   (md++)->set(0xA0000, 0xBFFFF, Mem_desc::Shared);
80   // 6: BIOS
81   (md++)->set(0xC0000, 0xEFFFF, Mem_desc::Shared);
82
83   unsigned long s0_low = ~0UL, s0_high = 0;
84   unsigned long root_low = ~0UL, root_high = 0;
85   
86   for (Region const *c = regions->begin(); c != regions->end(); ++c)
87     {
88       Mem_desc::Mem_type type = Mem_desc::Reserved;
89       unsigned char sub_type = 0;
90       switch (c->type())
91         {
92         case Region::No_mem:
93         case Region::Ram:
94         case Region::Boot:
95           continue;
96         case Region::Kernel:
97           type = Mem_desc::Reserved;
98           break;
99         case Region::Sigma0:
100           type = Mem_desc::Dedicated;
101           if (s0_low > c->begin())
102             s0_low = c->begin();
103           if (s0_high < c->end())
104             s0_high = c->end();
105           break;
106         case Region::Root:
107           type = Mem_desc::Bootloader;
108           if (root_low > c->begin())
109             root_low = c->begin();
110           if (root_high < c->end())
111             root_high = c->end();
112           break;
113         case Region::Arch:
114           type = Mem_desc::Arch;
115           sub_type = c->sub_type();
116           break;
117         }
118       (md++)->set(c->begin(), c->end() - 1, type, sub_type);
119     }
120
121   *V4KIP_WORD(l4i,V4KIP_SIGMA0_LOW)  = s0_low;
122   *V4KIP_WORD(l4i,V4KIP_SIGMA0_HIGH) = s0_high+1;
123   *V4KIP_WORD(l4i,V4KIP_SIGMA0_IP)   = bi->sigma0_start;
124
125   *V4KIP_WORD(l4i,V4KIP_ROOT_LOW)  = root_low;
126   *V4KIP_WORD(l4i,V4KIP_ROOT_HIGH) = root_high+1;
127   *V4KIP_WORD(l4i,V4KIP_ROOT_IP)   = bi->roottask_start;
128   *V4KIP_WORD(l4i,V4KIP_ROOT_SP)   = bi->roottask_stack;
129
130   *V4KIP_WORD(l4i,V4KIP_BOOT_INFO) = (unsigned long)mbi;
131
132   // set the mem_info variable: count of mem descriptors
133   Mem_desc::count(l4i, md - Mem_desc::first(l4i));
134 }