4 * \brief L4::Kip class, memory descriptors.
6 * \author Alexander Warg <alexander.warg@os.inf.tu-dresden.de>
11 * (c) 2008-2009 Author(s)
12 * economic rights: Technische Universität Dresden (Germany)
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.
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.
27 #ifndef L4_SYS_KIP_H__
28 #define L4_SYS_KIP_H__
30 /* C++ version of memory descriptors */
33 * \defgroup l4_kip_api Kernel Interface Page
35 * \brief Kernel Interface Page.
37 * C++ interface for the Kernel Interface Page:<br>
38 * <c>\#include <l4/sys/kip></c>
46 * \brief Memory descriptors stored in the kernel interface page.
49 * <c>\#include <l4/sys/kip></c>
55 * \brief Memory types.
59 Undefined = 0x0, //< Undefined memory
60 Conventional = 0x1, //< Conventional memory
61 Reserved = 0x2, //< Reserved region, do not use this memory
62 Dedicated = 0x3, //< Dedicated
63 Shared = 0x4, //< Shared
65 Bootloader = 0xe, //< Memory belongs to the boot loader
66 Arch = 0xf //< Architecture specific memory
71 static unsigned long &memory_info(void *kip) throw()
72 { return *((unsigned long *)kip + 21); }
74 static unsigned long memory_info(void const *kip) throw()
75 { return *((unsigned long const *)kip + 21); }
79 * \brief Get first memory descriptor.
80 * \param kip Pointer to the kernel info page
81 * \return First memory descriptor stored in the kernel info page
83 static Mem_desc *first(void *kip) throw()
85 return (Mem_desc*)((char *)kip
86 + (memory_info(kip) >> ((sizeof(unsigned long)/2)*8)));
89 static Mem_desc const *first(void const *kip) throw()
91 return (Mem_desc const*)((char const *)kip
92 + (memory_info(kip) >> ((sizeof(unsigned long)/2)*8)));
96 * \brief Return number of memory descriptors stored in the kernel info page.
97 * \param kip Pointer to the kernel info page
98 * \return Number of memory descriptors in the kernel info page.
100 static unsigned long count(void const *kip) throw()
102 return memory_info(kip) & ((1UL << ((sizeof(unsigned long)/2)*8)) - 1);
106 * \brief Set number of memory descriptors.
107 * \param kip Pointer to the kernel info page
108 * \param count Number of memory descriptors
110 static void count(void *kip, unsigned count) throw()
112 unsigned long &mi = memory_info(kip);
113 mi = (mi & ~((1UL << ((sizeof(unsigned long)/2)*8)) - 1)) | count;
117 * \brief Initialize memory descriptor.
118 * \param start Start address
119 * \param end End address
120 * \param t Memory type
121 * \param st Memory subtype, defaults to 0
122 * \param virt True for virtual memory, false for physical memory,
123 * defaults to physical
125 Mem_desc(unsigned long start, unsigned long end,
126 Mem_type t, unsigned char st = 0, bool virt = false) throw()
127 : _l((start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)
128 | (virt?0x0200:0x0)), _h(end | 0x3ffUL)
132 * \brief Return start address of memory descriptor.
133 * \return Start address of memory descriptor
135 unsigned long start() const throw() { return _l & ~0x3ffUL; }
138 * \brief Return end address of memory descriptor.
139 * \return End address of memory descriptor
141 unsigned long end() const throw() { return _h | 0x3ffUL; }
144 * \brief Return size of region described by the memory descriptor.
145 * \return Size of the region described by the memory descriptor
147 unsigned long size() const throw() { return end() + 1 - start(); }
150 * \brief Return type of the memory descriptor.
151 * \return Type of the memory descriptor
153 Mem_type type() const throw() { return (Mem_type)(_l & 0x0f); }
156 * \brief Return sub-type of the memory descriptor.
157 * \return Sub-type of the memory descriptor
159 unsigned char sub_type() const throw() { return (_l >> 4) & 0x0f; }
162 * \brief Return whether the memory descriptor describes a virtual or
164 * \return True for virtual region, false for physical region.
166 unsigned is_virtual() const throw() { return _l & 0x200; }
169 * \brief Set values of a memory descriptor.
170 * \param start Start address
171 * \param end End address
172 * \param t Memory type
173 * \param st Sub-type, defaults to 0
174 * \param virt Virtual or physical memory region, defaults to physical
176 void set(unsigned long start, unsigned long end,
177 Mem_type t, unsigned char st = 0, bool virt = false) throw()
179 _l = (start & ~0x3ffUL) | (t & 0x0f) | ((st << 4) & 0x0f0)