L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
15 */
16#ifndef L4_SYS_KIP_H__
17#define L4_SYS_KIP_H__
18
19#include <l4/cxx/static_vector>
20
21/* C++ version of memory descriptors */
22
32namespace L4
33{
34 namespace Kip
35 {
43 {
44 public:
49 {
50 Undefined = 0x0,
52 Reserved = 0x2,
53 Dedicated = 0x3,
54 Shared = 0x4,
55
56 Info = 0xd,
57 Bootloader = 0xe,
58 Arch = 0xf
59 };
60
65 {
67 };
68
77
78 private:
79 unsigned long _l, _h;
80
81 static unsigned long &memory_info(void *kip) noexcept
82 { return *(reinterpret_cast<unsigned long *>(kip) + 21); }
83
84 static unsigned long memory_info(void const *kip) noexcept
85 { return *(reinterpret_cast<unsigned long const *>(kip) + 21); }
86
87 public:
95 static Mem_desc *first(void *kip) noexcept
96 {
97 return reinterpret_cast<Mem_desc *>(reinterpret_cast<char *>(kip)
98 + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8)));
99 }
100
101 static Mem_desc const *first(void const *kip) noexcept
102 {
103 char const *addr = reinterpret_cast<char const *>(kip)
104 + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8));
105 return reinterpret_cast<Mem_desc const *>(addr);
106 }
107
115 static unsigned long count(void const *kip) noexcept
116 {
117 return memory_info(kip)
118 & ((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1);
119 }
120
127 static void count(void *kip, unsigned count) noexcept
128 {
129 unsigned long &mi = memory_info(kip);
130 mi = (mi & ~((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1)) | count;
131 }
132
138 static inline cxx::static_vector<Mem_desc const> all(void const *kip)
139 {
141 Mem_desc::count(kip));
142 }
143
149 static inline cxx::static_vector<Mem_desc> all(void *kip)
150 {
152 Mem_desc::count(kip));
153 }
154
168 Mem_desc(unsigned long start, unsigned long end,
169 Mem_type t, unsigned char st = 0, bool virt = false,
170 bool eager = false) noexcept
171 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
172 | (virt ? 0x0200 : 0x0) | (eager ? 0x100 : 0x0)), _h(end | 0x3ffUL)
173 {}
174
180 unsigned long start() const noexcept { return _l & ~0x3ffUL; }
181
187 unsigned long end() const noexcept { return _h | 0x3ffUL; }
188
194 unsigned long size() const noexcept { return end() + 1 - start(); }
195
201 Mem_type type() const noexcept
202 {
203 return static_cast<Mem_type>(_l & 0x0f);
204 }
205
211 unsigned char sub_type() const noexcept { return (_l >> 4) & 0x0f; }
212
219 unsigned is_virtual() const noexcept { return _l & 0x200; }
220
225 unsigned eager_map() const noexcept { return _l & 0x100; }
226
239 void set(unsigned long start, unsigned long end,
240 Mem_type t, unsigned char st = 0, bool virt = false,
241 bool eager = false) noexcept
242 {
243 _l = (start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
244 | (virt?0x0200:0x0) | (eager ? 0x0100 : 0x0);
245
246 _h = end | 0x3ffUL;
247 }
248
249 };
250 };
251};
252
253#endif
Memory descriptors stored in the kernel interface page.
Definition kip:43
Mem_type type() const noexcept
Return type of the memory descriptor.
Definition kip:201
static void count(void *kip, unsigned count) noexcept
Set number of memory descriptors.
Definition kip:127
unsigned long end() const noexcept
Return end address of memory descriptor.
Definition kip:187
unsigned long start() const noexcept
Return start address of memory descriptor.
Definition kip:180
Arch_sub_type_common
Common sub types across all architectures for the Mem_type::Arch type.
Definition kip:73
@ Arch_acpi_tables
Firmware ACPI tables.
Definition kip:74
@ Arch_acpi_nvs
Firmware reserved address space.
Definition kip:75
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:239
static cxx::static_vector< Mem_desc const > all(void const *kip)
Return enumerable list of memory descriptors.
Definition kip:138
unsigned is_virtual() const noexcept
Return whether the memory descriptor describes a virtual or physical region.
Definition kip:219
Info_sub_type
Memory sub types for the Mem_type::Info type.
Definition kip:65
@ Info_acpi_rsdp
Physical address of the ACPI root pointer.
Definition kip:66
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:168
unsigned eager_map() const noexcept
Return whether the region shall be eligible for eager mapping in sigma0 or the root task.
Definition kip:225
static cxx::static_vector< Mem_desc > all(void *kip)
Return enumerable list of memory descriptors.
Definition kip:149
Mem_type
Memory types.
Definition kip:49
@ Reserved
Reserved region, do not use this memory.
Definition kip:52
@ Shared
Shared.
Definition kip:54
@ Dedicated
Dedicated.
Definition kip:53
@ Conventional
Conventional memory.
Definition kip:51
@ Info
Info by boot loader.
Definition kip:56
@ Undefined
Undefined memory.
Definition kip:50
@ Arch
Architecture specific memory.
Definition kip:58
@ Bootloader
Memory belongs to the boot loader.
Definition kip:57
unsigned long size() const noexcept
Return size of region described by the memory descriptor.
Definition kip:194
static unsigned long count(void const *kip) noexcept
Return number of memory descriptors stored in the kernel info page.
Definition kip:115
static Mem_desc * first(void *kip) noexcept
Get first memory descriptor.
Definition kip:95
unsigned char sub_type() const noexcept
Return sub-type of the memory descriptor.
Definition kip:211
Simple encapsulation for a dynamically allocated array.
Definition static_vector:17
L4 low-level kernel interface.