L4Re - L4 Runtime Environment
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 
43 namespace L4
44 {
45  namespace Kip
46  {
53  class Mem_desc
54  {
55  public:
59  enum Mem_type
60  {
61  Undefined = 0x0,
62  Conventional = 0x1,
63  Reserved = 0x2,
64  Dedicated = 0x3,
65  Shared = 0x4,
66 
67  Info = 0xd,
68  Bootloader = 0xe,
69  Arch = 0xf
70  };
71 
76  {
78  };
79 
80  private:
81  unsigned long _l, _h;
82 
83  static unsigned long &memory_info(void *kip) throw()
84  { return *((unsigned long *)kip + 21); }
85 
86  static unsigned long memory_info(void const *kip) throw()
87  { return *((unsigned long const *)kip + 21); }
88 
89  public:
97  static Mem_desc *first(void *kip) throw()
98  {
99  return (Mem_desc *)((char *)kip
100  + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8)));
101  }
102 
103  static Mem_desc const *first(void const *kip) throw()
104  {
105  return (Mem_desc const *)((char const *)kip
106  + (memory_info(kip) >> ((sizeof(unsigned long) / 2) * 8)));
107  }
108 
116  static unsigned long count(void const *kip) throw()
117  {
118  return memory_info(kip)
119  & ((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1);
120  }
121 
128  static void count(void *kip, unsigned count) throw()
129  {
130  unsigned long &mi = memory_info(kip);
131  mi = (mi & ~((1UL << ((sizeof(unsigned long) / 2) * 8)) - 1)) | count;
132  }
133 
139  static inline cxx::static_vector<Mem_desc const> all(void const *kip)
140  {
142  Mem_desc::count(kip));
143  }
144 
150  static inline cxx::static_vector<Mem_desc> all(void *kip)
151  {
153  Mem_desc::count(kip));
154  }
155 
166  Mem_desc(unsigned long start, unsigned long end,
167  Mem_type t, unsigned char st = 0, bool virt = false) throw()
168  : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
169  | (virt ? 0x0200 : 0x0)), _h(end | 0x3ffUL)
170  {}
171 
177  unsigned long start() const throw() { return _l & ~0x3ffUL; }
178 
184  unsigned long end() const throw() { return _h | 0x3ffUL; }
185 
191  unsigned long size() const throw() { return end() + 1 - start(); }
192 
198  Mem_type type() const throw() { return (Mem_type)(_l & 0x0f); }
199 
205  unsigned char sub_type() const throw() { return (_l >> 4) & 0x0f; }
206 
213  unsigned is_virtual() const throw() { return _l & 0x200; }
214 
224  void set(unsigned long start, unsigned long end,
225  Mem_type t, unsigned char st = 0, bool virt = false) throw()
226  {
227  _l = (start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
228  | (virt?0x0200:0x0);
229 
230  _h = end | 0x3ffUL;
231  }
232 
233  };
234  };
235 };
236 
237 #endif
Mem_desc(unsigned long start, unsigned long end, Mem_type t, unsigned char st=0, bool virt=false)
Initialize memory descriptor.
Definition: kip:166
static cxx::static_vector< Mem_desc > all(void *kip)
Return enumerable list of memory descriptors.
Definition: kip:150
Simple encapsulation for a dynamically allocated array.
Definition: static_vector:16
Memory belongs to the boot loader.
Definition: kip:68
unsigned long end() const
Return end address of memory descriptor.
Definition: kip:184
Memory descriptors stored in the kernel interface page.
Definition: kip:53
static void count(void *kip, unsigned count)
Set number of memory descriptors.
Definition: kip:128
L4 low-level kernel interface.
unsigned long size() const
Return size of region described by the memory descriptor.
Definition: kip:191
Conventional memory.
Definition: kip:62
Undefined memory.
Definition: kip:61
static unsigned long count(void const *kip)
Return number of memory descriptors stored in the kernel info page.
Definition: kip:116
Dedicated.
Definition: kip:64
Mem_type type() const
Return type of the memory descriptor.
Definition: kip:198
Physical address of the ACPI root pointer.
Definition: kip:77
Architecture specific memory.
Definition: kip:69
unsigned long start() const
Return start address of memory descriptor.
Definition: kip:177
Info by boot loader.
Definition: kip:67
Reserved region, do not use this memory.
Definition: kip:63
static cxx::static_vector< Mem_desc const > all(void const *kip)
Return enumerable list of memory descriptors.
Definition: kip:139
Mem_type
Memory types.
Definition: kip:59
static Mem_desc * first(void *kip)
Get first memory descriptor.
Definition: kip:97
unsigned char sub_type() const
Return sub-type of the memory descriptor.
Definition: kip:205
unsigned is_virtual() const
Return whether the memory descriptor describes a virtual or physical region.
Definition: kip:213
Info_sub_type
Memory sub types for the Mem_type::Info type.
Definition: kip:75