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