L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
splitlog2.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7 * economic rights: Technische Universität Dresden (Germany)
8 * License: see LICENSE.spdx (in this directory or the directories above)
9 */
10#ifndef __L4UTIL__INCLUDE__SPLITLOG2_H__
11#define __L4UTIL__INCLUDE__SPLITLOG2_H__
12
13#include <l4/sys/linkage.h>
14#include <l4/sys/err.h>
15#include <l4/util/bitops.h>
16
18
31L4_INLINE long
33 long (*handler)(l4_addr_t s, l4_addr_t e, int log2size));
34
45
47
48/* Implementation */
49
50L4_INLINE long
52 long (*handler)(l4_addr_t s, l4_addr_t e, int log2size))
53{
54 if (end < start)
55 return -L4_EINVAL;
56
57 for (;;)
58 {
59 long retval;
60 int len2 = l4util_splitlog2_size(start, end);
61 l4_addr_t len = 1UL << len2;
62 l4_addr_t chunk_end = start + len - 1;
63 if ((retval = handler(start, chunk_end, len2)))
64 return retval;
65 if (chunk_end >= end)
66 return 0;
67 start = chunk_end + 1;
68 }
69}
70
73{
74 int start_bits = l4util_bsf(start);
75 l4_addr_t len = end - start + 1; // == 0 for entire address space
76 int len_bits = len ? l4util_bsr(len) : (int)(sizeof(l4_addr_t) * 8 - 1);
77 if (start_bits != -1 && len_bits > start_bits)
78 len_bits = start_bits;
79
80 return len_bits;
81}
82
83#endif /* ! __L4UTIL__INCLUDE__SPLITLOG2_H__ */
bit manipulation functions
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
@ L4_EINVAL
Invalid argument.
Definition err.h:47
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:171
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:172
l4_addr_t l4util_splitlog2_size(l4_addr_t start, l4_addr_t end)
Return log2 base and size aligned length of a range.
Definition splitlog2.h:72
L4_BEGIN_DECLS long l4util_splitlog2_hdl(l4_addr_t start, l4_addr_t end, long(*handler)(l4_addr_t s, l4_addr_t e, int log2size))
Split a range into log2 base and size aligned chunks.
Definition splitlog2.h:51