L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
kip.h
Go to the documentation of this file.
1
6/*
7 * (c) 2008-2013 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8 * Alexander Warg <warg@os.inf.tu-dresden.de>
9 * economic rights: Technische Universität Dresden (Germany)
10 *
11 * This file is part of TUD:OS and distributed under the terms of the
12 * GNU General Public License 2.
13 * Please see the COPYING-GPL-2 file for details.
14 *
15 * As a special exception, you may use this file as part of a free software
16 * library without restriction. Specifically, if other files instantiate
17 * templates or use macros or inline functions from this file, or you compile
18 * this file and link it with other files to produce an executable, this
19 * file does not by itself cause the resulting executable to be covered by
20 * the GNU General Public License. This exception does not however
21 * invalidate any other reasons why the executable file might be covered by
22 * the GNU General Public License.
23 */
24#pragma once
25
26#include <l4/sys/compiler.h>
27#include <l4/sys/l4int.h>
28
29#include <l4/sys/__kip-arch.h>
30
34struct l4_kip_platform_info
35{
36 char name[16];
37 l4_uint32_t is_mp;
38 struct l4_kip_platform_info_arch arch;
39};
40
41#if L4_MWORD_BITS == 32
42# include <l4/sys/__kip-32bit.h>
43#else
44# include <l4/sys/__kip-64bit.h>
45#endif
46
58enum l4_kernel_info_consts_t
59{
60 L4_KIP_VERSION_FIASCO = 0x87004444,
61 L4_KIP_VERSION_FIASCO_MASK = 0xff00ffff,
62};
63
64enum
65{
75
86};
87
91extern l4_kernel_info_t const *l4_global_kip;
92
96#define L4_KERNEL_INFO_MAGIC (0x4BE6344CL) /* "L4µK" */
97
98
105
106
115
124
133L4_INLINE int
135
155
168
184
187/*************************************************************************
188 * Implementations
189 *************************************************************************/
190
193{
194#ifdef __PIC__
195 return l4_global_kip;
196#else
197 extern char __L4_KIP_ADDR__[];
198 return (l4_kernel_info_t const *)__L4_KIP_ADDR__;
199#endif
200}
201
204{ return kip->version & L4_KIP_VERSION_FIASCO_MASK; }
205
206L4_INLINE const char*
209
210L4_INLINE int
212{ return kip->offset_version_strings << 4; }
213
216{
217 // Use kernel-provided code to determine the current clock.
218 typedef l4_uint64_t (*kip_time_fn_read_us)(void);
219 kip_time_fn_read_us read_us =
220 (kip_time_fn_read_us)((l4_uint8_t*)kip + L4_KIP_OFFS_READ_US);
221 return read_us();
222}
223
226{
227 typedef l4_uint64_t (*kip_time_fn_read_ns)(void);
228 kip_time_fn_read_ns read_ns =
229 (kip_time_fn_read_ns)((l4_uint8_t*)kip + L4_KIP_OFFS_READ_NS);
230 return read_ns();
231}
232
235{
236 union Clock_field
237 {
239 unsigned long l;
240 };
241 union Clock_field c = { kip->_clock_val };
242 l4_mb();
243 return c.l;
244}
245
252#define l4_kip_for_each_feature(s) \
253 for (s += __builtin_strlen(s) + 1; *s; s += __builtin_strlen(s) + 1)
254
265L4_INLINE int
266l4_kip_kernel_has_feature(l4_kernel_info_t const *kip, char const *str)
267{
268 const char *s = l4_kip_version_string(kip);
269 if (!s)
270 return 0;
271
273 {
274 if (__builtin_strcmp(s, str) == 0)
275 return 1;
276 }
277
278 return 0;
279}
L4 compiler related defines.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
l4_uint64_t l4_cpu_time_t
CPU clock type.
Definition l4int.h:58
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition l4int.h:36
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
int l4_kernel_info_version_offset(l4_kernel_info_t const *kip) L4_NOTHROW
Return offset in bytes of version_strings relative to the KIP base.
Definition kip.h:211
l4_umword_t l4_kip_clock_lw(l4_kernel_info_t const *kip) L4_NOTHROW
Return least significant machine word of clock value from the KIP.
Definition kip.h:234
l4_kernel_info_t const * l4_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition kip.h:192
const char * l4_kip_version_string(l4_kernel_info_t const *kip) L4_NOTHROW
Get the kernel version string.
Definition kip.h:207
l4_umword_t l4_kip_version(l4_kernel_info_t const *kip) L4_NOTHROW
Get the kernel version.
Definition kip.h:203
l4_cpu_time_t l4_kip_clock(l4_kernel_info_t const *kip) L4_NOTHROW
Return clock value from the KIP.
Definition kip.h:215
l4_uint64_t l4_kip_clock_ns(l4_kernel_info_t const *kip) L4_NOTHROW
Return current clock using the KIP in nanoseconds.
Definition kip.h:225
@ L4_KIP_OFFS_READ_NS
Offset of KIP code (provided by the kernel) for reading the time stamp counter and transforming this ...
Definition kip.h:85
@ L4_KIP_OFFS_READ_US
Offset of KIP code (provided by the kernel) for reading the KIP clock in microseconds.
Definition kip.h:74
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
void l4_mb(void)
Memory barrier.
Definition compiler.h:332
L4 Kernel Interface Page.
Definition __kip-32bit.h:39
l4_uint32_t version
Kernel version.
Definition __kip-32bit.h:44
int l4_kip_kernel_has_feature(l4_kernel_info_t const *kip, char const *str)
Check if kernel supports a feature.
Definition kip.h:266
#define l4_kip_for_each_feature(s)
Cycle through kernel features given in the KIP.
Definition kip.h:252