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 *((unsigned long *)kip + 21); }
94
95 static unsigned long memory_info(void const *kip) noexcept
96 { return *((unsigned long const *)kip + 21); }
97
98 public:
106 static Mem_desc *first(void *kip) noexcept
107 {
108 return (Mem_desc *)((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 return (Mem_desc const *)((char const *)kip
115 + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8)));
116 }
117
125 static unsigned long count(void const *kip) noexcept
126 {
127 return memory_info(kip)
128 & ((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1);
129 }
130
137 static void count(void *kip, unsigned count) noexcept
138 {
139 unsigned long &mi = memory_info(kip);
140 mi = (mi & ~((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1)) | count;
141 }
142
148 static inline cxx::static_vector<Mem_desc const> all(void const *kip)
149 {
151 Mem_desc::count(kip));
152 }
153
159 static inline cxx::static_vector<Mem_desc> all(void *kip)
160 {
162 Mem_desc::count(kip));
163 }
164
175 Mem_desc(unsigned long start, unsigned long end,
176 Mem_type t, unsigned char st = 0, bool virt = false) noexcept
177 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
178 | (virt ? 0x0200 : 0x0)), _h(end | 0x3ffUL)
179 {}
180
186 unsigned long start() const noexcept { return _l & ~0x3ffUL; }
187
193 unsigned long end() const noexcept { return _h | 0x3ffUL; }
194
200 unsigned long size() const noexcept { return end() + 1 - start(); }
201
207 Mem_type type() const noexcept { return (Mem_type)(_l & 0x0f); }
208
214 unsigned char sub_type() const noexcept { return (_l >> 4) & 0x0f; }
215
222 unsigned is_virtual() const noexcept { return _l & 0x200; }
223
233 void set(unsigned long start, unsigned long end,
234 Mem_type t, unsigned char st = 0, bool virt = false) noexcept
235 {
236 _l = (start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
237 | (virt?0x0200:0x0);
238
239 _h = end | 0x3ffUL;
240 }
241
242 };
243 };
244};
245
246#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:207
static void count(void *kip, unsigned count) noexcept
Set number of memory descriptors.
Definition kip:137
void set(unsigned long start, unsigned long end, Mem_type t, unsigned char st=0, bool virt=false) noexcept
Set values of a memory descriptor.
Definition kip:233
unsigned long end() const noexcept
Return end address of memory descriptor.
Definition kip:193
unsigned long start() const noexcept
Return start address of memory descriptor.
Definition kip:186
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
static cxx::static_vector< Mem_desc const > all(void const *kip)
Return enumerable list of memory descriptors.
Definition kip:148
unsigned is_virtual() const noexcept
Return whether the memory descriptor describes a virtual or physical region.
Definition kip:222
Mem_desc(unsigned long start, unsigned long end, Mem_type t, unsigned char st=0, bool virt=false) noexcept
Initialize memory descriptor.
Definition kip:175
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
static cxx::static_vector< Mem_desc > all(void *kip)
Return enumerable list of memory descriptors.
Definition kip:159
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:200
static unsigned long count(void const *kip) noexcept
Return number of memory descriptors stored in the kernel info page.
Definition kip:125
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:214
Simple encapsulation for a dynamically allocated array.
Definition static_vector:17
L4 low-level kernel interface.