L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
kip
Go to the documentation of this file.
1// vim:set ft=cpp: -*- Mode: C++ -*-
10/*
11 * (c) 2008-2009 Author(s)
12 * economic rights: Technische Universität Dresden (Germany)
13 *
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU General Public License 2.
16 * Please see the COPYING-GPL-2 file for details.
17 *
18 * As a special exception, you may use this file as part of a free software
19 * library without restriction. Specifically, if other files instantiate
20 * templates or use macros or inline functions from this file, or you compile
21 * this file and link it with other files to produce an executable, this
22 * file does not by itself cause the resulting executable to be covered by
23 * the GNU General Public License. This exception does not however
24 * invalidate any other reasons why the executable file might be covered by
25 * the GNU General Public License.
26 */
27#ifndef L4_SYS_KIP_H__
28#define L4_SYS_KIP_H__
29
30#include <l4/cxx/static_vector>
31
32/* C++ version of memory descriptors */
33
43namespace L4
44{
45 namespace Kip
46 {
54 {
55 public:
60 {
61 Undefined = 0x0,
63 Reserved = 0x2,
64 Dedicated = 0x3,
65 Shared = 0x4,
66
67 Info = 0xd,
68 Bootloader = 0xe,
69 Arch = 0xf
70 };
71
76 {
78 };
79
88
89 private:
90 unsigned long _l, _h;
91
92 static unsigned long &memory_info(void *kip) noexcept
93 { return *(reinterpret_cast<unsigned long *>(kip) + 21); }
94
95 static unsigned long memory_info(void const *kip) noexcept
96 { return *(reinterpret_cast<unsigned long const *>(kip) + 21); }
97
98 public:
106 static Mem_desc *first(void *kip) noexcept
107 {
108 return reinterpret_cast<Mem_desc *>(reinterpret_cast<char *>(kip)
109 + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8)));
110 }
111
112 static Mem_desc const *first(void const *kip) noexcept
113 {
114 char const *addr = reinterpret_cast<char const *>(kip)
115 + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8));
116 return reinterpret_cast<Mem_desc const *>(addr);
117 }
118
126 static unsigned long count(void const *kip) noexcept
127 {
128 return memory_info(kip)
129 & ((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1);
130 }
131
138 static void count(void *kip, unsigned count) noexcept
139 {
140 unsigned long &mi = memory_info(kip);
141 mi = (mi & ~((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1)) | count;
142 }
143
149 static inline cxx::static_vector<Mem_desc const> all(void const *kip)
150 {
152 Mem_desc::count(kip));
153 }
154
160 static inline cxx::static_vector<Mem_desc> all(void *kip)
161 {
163 Mem_desc::count(kip));
164 }
165
179 Mem_desc(unsigned long start, unsigned long end,
180 Mem_type t, unsigned char st = 0, bool virt = false,
181 bool eager = false) noexcept
182 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
183 | (virt ? 0x0200 : 0x0) | (eager ? 0x100 : 0x0)), _h(end | 0x3ffUL)
184 {}
185
191 unsigned long start() const noexcept { return _l & ~0x3ffUL; }
192
198 unsigned long end() const noexcept { return _h | 0x3ffUL; }
199
205 unsigned long size() const noexcept { return end() + 1 - start(); }
206
212 Mem_type type() const noexcept
213 {
214 return static_cast<Mem_type>(_l & 0x0f);
215 }
216
222 unsigned char sub_type() const noexcept { return (_l >> 4) & 0x0f; }
223
230 unsigned is_virtual() const noexcept { return _l & 0x200; }
231
236 unsigned eager_map() const noexcept { return _l & 0x100; }
237
250 void set(unsigned long start, unsigned long end,
251 Mem_type t, unsigned char st = 0, bool virt = false,
252 bool eager = false) noexcept
253 {
254 _l = (start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
255 | (virt?0x0200:0x0) | (eager ? 0x0100 : 0x0);
256
257 _h = end | 0x3ffUL;
258 }
259
260 };
261 };
262};
263
264#endif
Memory descriptors stored in the kernel interface page.
Definition kip:54
Mem_type type() const noexcept
Return type of the memory descriptor.
Definition kip:212
static void count(void *kip, unsigned count) noexcept
Set number of memory descriptors.
Definition kip:138
unsigned long end() const noexcept
Return end address of memory descriptor.
Definition kip:198
unsigned long start() const noexcept
Return start address of memory descriptor.
Definition kip:191
Arch_sub_type_common
Common sub types across all architectures for the Mem_type::Arch type.
Definition kip:84
@ Arch_acpi_tables
Firmware ACPI tables.
Definition kip:85
@ Arch_acpi_nvs
Firmware reserved address space.
Definition kip:86
void set(unsigned long start, unsigned long end, Mem_type t, unsigned char st=0, bool virt=false, bool eager=false) noexcept
Set values of a memory descriptor.
Definition kip:250
static cxx::static_vector< Mem_desc const > all(void const *kip)
Return enumerable list of memory descriptors.
Definition kip:149
unsigned is_virtual() const noexcept
Return whether the memory descriptor describes a virtual or physical region.
Definition kip:230
Info_sub_type
Memory sub types for the Mem_type::Info type.
Definition kip:76
@ Info_acpi_rsdp
Physical address of the ACPI root pointer.
Definition kip:77
Mem_desc(unsigned long start, unsigned long end, Mem_type t, unsigned char st=0, bool virt=false, bool eager=false) noexcept
Initialize memory descriptor.
Definition kip:179
unsigned eager_map() const noexcept
Return whether the region shall be eligible for eager mapping in sigma0 or the root task.
Definition kip:236
static cxx::static_vector< Mem_desc > all(void *kip)
Return enumerable list of memory descriptors.
Definition kip:160
Mem_type
Memory types.
Definition kip:60
@ Reserved
Reserved region, do not use this memory.
Definition kip:63
@ Shared
Shared.
Definition kip:65
@ Dedicated
Dedicated.
Definition kip:64
@ Conventional
Conventional memory.
Definition kip:62
@ Info
Info by boot loader.
Definition kip:67
@ Undefined
Undefined memory.
Definition kip:61
@ Arch
Architecture specific memory.
Definition kip:69
@ Bootloader
Memory belongs to the boot loader.
Definition kip:68
unsigned long size() const noexcept
Return size of region described by the memory descriptor.
Definition kip:205
static unsigned long count(void const *kip) noexcept
Return number of memory descriptors stored in the kernel info page.
Definition kip:126
static Mem_desc * first(void *kip) noexcept
Get first memory descriptor.
Definition kip:106
unsigned char sub_type() const noexcept
Return sub-type of the memory descriptor.
Definition kip:222
Simple encapsulation for a dynamically allocated array.
Definition static_vector:17
L4 low-level kernel interface.
Definition io_regblock.h:19