]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/abi/kip.cpp
4bc8c34c07bad10c0a1d7d246380fe8076faf504
[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   enum Kernel_uart_info_type
46   {
47     Kernel_uart_info_invalid = 0,
48     Kernel_uart_info_ioport,
49     Kernel_uart_info_mmio,
50   };
51
52   struct Kernel_uart_info
53   {
54     Unsigned32 type;
55     Unsigned32 irqno;
56     Unsigned64 base;
57   };
58
59   struct Platform_info
60   {
61     char name[16];
62   };
63
64 private:
65   static Kip *global_kip asm ("GLOBAL_KIP");
66 };
67
68 #define L4_KERNEL_INFO_MAGIC (0x4BE6344CL) /* "L4µK" */
69
70 //============================================================================
71 IMPLEMENTATION:
72
73 #include "panic.h"
74
75 PUBLIC inline
76 Mem_desc::Mem_desc(Address start, Address end, Mem_type t, bool v = false,
77                    unsigned st = 0)
78 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
79      | (v?0x0200:0x0)),
80   _h(end)
81 {}
82
83 PUBLIC inline
84 Address Mem_desc::start() const
85 { return _l & ~0x3ffUL; }
86
87 PUBLIC inline
88 Address Mem_desc::end() const
89 { return _h | 0x3ffUL; }
90
91 PUBLIC inline
92 void
93 Mem_desc::type(Mem_type t)
94 { _l = (_l & ~0x0f) | (t & 0x0f); }
95
96 PUBLIC inline
97 Mem_desc::Mem_type Mem_desc::type() const
98 { return (Mem_type)(_l & 0x0f); }
99
100 PUBLIC inline
101 unsigned Mem_desc::ext_type() const
102 { return _l & 0x0f0; }
103
104 PUBLIC inline
105 unsigned Mem_desc::is_virtual() const
106 { return _l & 0x200; }
107
108 PUBLIC inline
109 bool Mem_desc::contains(unsigned long addr)
110 {
111   return start() <= addr && end() >= addr;
112 }
113
114 PUBLIC inline
115 bool Mem_desc::valid() const
116 { return type() && start() < end(); }
117
118 PUBLIC inline
119 Mem_desc *Kip::mem_descs()
120 { return (Mem_desc*)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
121
122 PUBLIC inline
123 Mem_desc const *Kip::mem_descs() const
124 { return (Mem_desc const *)(((Address)this) + (_mem_info >> (MWORD_BITS/2))); }
125
126 PUBLIC inline
127 unsigned Kip::num_mem_descs() const
128 { return _mem_info & ((1UL << (MWORD_BITS/2))-1); }
129
130 PUBLIC inline
131 void Kip::num_mem_descs (unsigned n)
132 {
133   _mem_info = (_mem_info & ~((1UL << (MWORD_BITS/2))-1)
134                | (n & ((1UL << (MWORD_BITS/2))-1)));
135 }
136
137 PUBLIC
138 Mem_desc *Kip::add_mem_region(Mem_desc const &md)
139 {
140   Mem_desc *m = mem_descs();
141   Mem_desc *end = m + num_mem_descs();
142   for (;m<end;++m)
143     {
144       if (m->type() == Mem_desc::Undefined)
145         {
146           *m = md;
147           return m;
148         }
149     }
150
151   // Add mem region failed -- must be a Fiasco startup problem.  Bail out.
152   panic("Too few memory descriptors in KIP");
153
154   return 0;
155 }
156
157 //----------------------------------------------------------------------------
158 IMPLEMENTATION [mp]:
159
160 PUBLIC static inline
161 unsigned
162 Kip::system_cpus()
163 { return (k()->processor_info & 0xffff) + 1; }
164
165 //----------------------------------------------------------------------------
166 IMPLEMENTATION [!mp]:
167
168 PUBLIC static inline
169 unsigned
170 Kip::system_cpus()
171 { return 1; }
172
173 //----------------------------------------------------------------------------
174 IMPLEMENTATION:
175
176 #include "config.h"
177 #include "version.h"
178
179 Kip *Kip::global_kip;
180 PUBLIC static inline void Kip::init_global_kip (Kip *kip) { global_kip = kip; }
181 PUBLIC static inline Kip *Kip::k() { return global_kip; }
182
183 IMPLEMENT
184 char const *Kip::version_string() const
185 {
186   return reinterpret_cast <char const *> (this) + (offset_version_strings << 4);
187 }
188
189 asm(".section .initkip.version, \"a\", %progbits        \n"     \
190     ".string \"" CONFIG_KERNEL_VERSION_STRING "\"       \n"     \
191     ".previous                                          \n");
192
193 asm(".section .initkip.features.fini, \"a\", %progbits  \n"     \
194     ".string \"\"                                       \n"     \
195     ".previous                                          \n");