]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/abi/kip.cpp
update
[l4.git] / kernel / fiasco / src / abi / kip.cpp
1 INTERFACE:
2
3 class Mem_desc
4 {
5 public:
6   enum Mem_type
7   {
8     Undefined    = 0x0,
9     Conventional = 0x1,
10     Reserved     = 0x2,
11     Dedicated    = 0x3,
12     Shared       = 0x4,
13     Kernel_tmp   = 0x7,
14
15     Bootloader   = 0xe,
16     Arch         = 0xf,
17   };
18
19 private:
20   Mword _l, _h;
21 };
22
23 //----------------------------------------------------------------------------
24 INTERFACE [ia32]:
25
26 /* Empty class for VHW descriptor in KIP for native ia32 */
27 class Vhw_descriptor {};
28
29 //----------------------------------------------------------------------------
30 INTERFACE:
31
32 #include "mem_region.h"
33 #include "types.h"
34
35 class Kip
36 {
37 public:
38   void print() const;
39
40   char const *version_string() const;
41
42   // returns the 1st address beyond all available physical memory
43   Address main_memory_high() const;
44
45 private:
46   static Kip *global_kip asm ("GLOBAL_KIP");
47 };
48
49 #define L4_KERNEL_INFO_MAGIC (0x4BE6344CL) /* "L4µK" */
50
51 //============================================================================
52 IMPLEMENTATION:
53
54 #include "assert.h"
55 #include "config.h"
56 #include "panic.h"
57 #include "static_assert.h"
58 #include "version.h"
59
60 PUBLIC inline
61 Mem_desc::Mem_desc(Address start, Address end, Mem_type t, bool v = false,
62                    unsigned st = 0)
63 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
64      | (v?0x0200:0x0)),
65   _h(end)
66 {}
67
68 PUBLIC inline
69 Address Mem_desc::start() const
70 { return _l & ~0x3ffUL; }
71
72 PUBLIC inline
73 Address Mem_desc::end() const
74 { return _h | 0x3ffUL; }
75
76 PUBLIC inline
77 void
78 Mem_desc::type(Mem_type t)
79 { _l = (_l & ~0x0f) | (t & 0x0f); }
80
81 PUBLIC inline
82 Mem_desc::Mem_type Mem_desc::type() const
83 { return (Mem_type)(_l & 0x0f); }
84
85 PUBLIC inline
86 unsigned Mem_desc::ext_type() const
87 { return _l & 0x0f0; }
88
89 PUBLIC inline
90 unsigned Mem_desc::is_virtual() const
91 { return _l & 0x200; }
92
93 PUBLIC inline
94 bool Mem_desc::contains(unsigned long addr)
95 {
96   return start() <= addr && end() >= addr;
97 }
98
99 PUBLIC inline
100 bool Mem_desc::valid() const
101 { return type() && start() < end(); }
102
103 PUBLIC inline
104 Mem_desc *Kip::mem_descs()
105 { return (Mem_desc*)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
106
107 PUBLIC inline
108 Mem_desc const *Kip::mem_descs() const
109 { return (Mem_desc const *)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
110
111 PUBLIC inline
112 unsigned Kip::num_mem_descs() const
113 { return _mem_info & ((1UL << (MWORD_BITS/2))-1); }
114
115 PUBLIC inline
116 void Kip::num_mem_descs (unsigned n)
117 {
118   _mem_info = (_mem_info & ~((1UL << (MWORD_BITS/2))-1)
119                | (n & ((1UL << (MWORD_BITS/2))-1)));
120 }
121
122 PUBLIC
123 Mem_desc *Kip::add_mem_region(Mem_desc const &md)
124 {
125   Mem_desc *m = mem_descs();
126   Mem_desc *end = m + num_mem_descs();
127   for (;m<end;++m)
128     {
129       if (m->type() == Mem_desc::Undefined)
130         {
131           *m = md;
132           return m;
133         }
134     }
135
136   // Add mem region failed -- must be a Fiasco startup problem.  Bail out.
137   panic("Too few memory descriptors in KIP");
138
139   return 0;
140 }
141
142 Kip *Kip::global_kip;
143
144 PUBLIC static
145 void Kip::init_global_kip(Kip *kip)
146 {
147   global_kip = kip;
148
149   kip->platform_info.is_mp = Config::Max_num_cpus > 1;
150
151   // check that the KIP has actually been set up
152   //assert(kip->sigma0_ip && kip->root_ip && kip->user_ptr);
153 }
154
155 PUBLIC static inline Kip *Kip::k() { return global_kip; }
156
157 IMPLEMENT
158 char const *Kip::version_string() const
159 {
160   static_assert((sizeof(Kip) & 0xf) == 0, "Invalid KIP structure size");
161
162   return reinterpret_cast <char const *> (this) + (offset_version_strings << 4);
163 }
164
165 asm(".section .initkip.version, \"a\", %progbits        \n"     \
166     ".string \"" CONFIG_KERNEL_VERSION_STRING "\"       \n"     \
167     ".previous                                          \n");
168
169 asm(".section .initkip.features.fini, \"a\", %progbits  \n"     \
170     ".string \"\"                                       \n"     \
171     ".previous                                          \n");