3 #include <cxx/static_vector>
31 //----------------------------------------------------------------------------
34 /* Empty class for VHW descriptor in KIP for native ia32 */
35 class Vhw_descriptor {};
37 //----------------------------------------------------------------------------
40 #include "mem_region.h"
48 char const *version_string() const;
51 static Kip *global_kip asm ("GLOBAL_KIP");
54 #define L4_KERNEL_INFO_MAGIC (0x4BE6344CL) /* "L4µK" */
56 //============================================================================
62 #include "static_assert.h"
66 Mem_desc::Mem_desc(Address start, Address end, Mem_type t, bool v = false,
68 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
73 PUBLIC inline ALWAYS_INLINE
74 Address Mem_desc::start() const
75 { return _l & ~0x3ffUL; }
77 PUBLIC inline ALWAYS_INLINE
78 Address Mem_desc::end() const
79 { return _h | 0x3ffUL; }
81 PUBLIC inline ALWAYS_INLINE
83 Mem_desc::type(Mem_type t)
84 { _l = (_l & ~0x0f) | (t & 0x0f); }
86 PUBLIC inline ALWAYS_INLINE
87 Mem_desc::Mem_type Mem_desc::type() const
88 { return (Mem_type)(_l & 0x0f); }
91 unsigned Mem_desc::ext_type() const
92 { return (_l >> 4) & 0x0f; }
94 PUBLIC inline ALWAYS_INLINE
95 unsigned Mem_desc::is_virtual() const
96 { return _l & 0x200; }
99 bool Mem_desc::contains(unsigned long addr)
101 return start() <= addr && end() >= addr;
104 PUBLIC inline ALWAYS_INLINE
105 bool Mem_desc::valid() const
106 { return type() && start() < end(); }
108 PRIVATE inline ALWAYS_INLINE
109 Mem_desc *Kip::mem_descs()
110 { return (Mem_desc*)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
113 Mem_desc const *Kip::mem_descs() const
114 { return (Mem_desc const *)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
116 PUBLIC inline ALWAYS_INLINE
117 unsigned Kip::num_mem_descs() const
118 { return _mem_info & ((1UL << (MWORD_BITS/2))-1); }
120 PUBLIC inline NEEDS[Kip::num_mem_descs, Kip::mem_descs] ALWAYS_INLINE
121 cxx::static_vector<Mem_desc>
123 { return cxx::static_vector<Mem_desc>(mem_descs(), num_mem_descs()); }
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()); }
132 void Kip::num_mem_descs(unsigned n)
134 _mem_info = (_mem_info & ~((1UL << (MWORD_BITS/2))-1)
135 | (n & ((1UL << (MWORD_BITS/2))-1)));
139 Mem_desc *Kip::add_mem_region(Mem_desc const &md)
141 for (auto &m: mem_descs_a())
142 if (m.type() == Mem_desc::Undefined)
148 // Add mem region failed -- must be a Fiasco startup problem. Bail out.
149 panic("Too few memory descriptors in KIP");
154 Kip *Kip::global_kip;
156 PUBLIC static inline ALWAYS_INLINE NEEDS["config.h"]
158 Kip::init_global_kip(Kip *kip)
162 kip->platform_info.is_mp = Config::Max_num_cpus > 1;
164 // check that the KIP has actually been set up
165 //assert(kip->sigma0_ip && kip->root_ip && kip->user_ptr);
168 PUBLIC static inline Kip *Kip::k() { return global_kip; }
171 char const *Kip::version_string() const
173 static_assert((sizeof(Kip) & 0xf) == 0, "Invalid KIP structure size");
175 return reinterpret_cast <char const *> (this) + (offset_version_strings << 4);
178 asm(".section .initkip.version, \"a\", %progbits \n"
179 ".string \"" CONFIG_KERNEL_VERSION_STRING "\" \n"
182 asm(".section .initkip.features.end, \"a\", %progbits \n"