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 * This file is part of TUD:OS and distributed under the terms of the
9 * GNU Lesser General Public License 2.1.
10 * Please see the COPYING-LGPL-2.1 file for details.
11 */
12#ifndef __L4UTIL__INCLUDE__SPLITLOG2_H__
13#define __L4UTIL__INCLUDE__SPLITLOG2_H__
14
15#include <l4/sys/linkage.h>
16#include <l4/sys/err.h>
17#include <l4/util/bitops.h>
18
20
33L4_INLINE long
35 long (*handler)(l4_addr_t s, l4_addr_t e, int log2size));
36
47
49
50/* Implementation */
51
52L4_INLINE long
54 long (*handler)(l4_addr_t s, l4_addr_t e, int log2size))
55{
56 if (end < start)
57 return -L4_EINVAL;
58
59 while (start <= end)
60 {
61 long retval;
62 int len2 = l4util_splitlog2_size(start, end);
63 l4_addr_t len = 1UL << len2;
64 if ((retval = handler(start, start + len - 1, len2)))
65 return retval;
66 start += len;
67 }
68 return 0;
69}
70
73{
74 int start_bits = l4util_bsf(start);
75 int len_bits = l4util_bsr(end - start + 1);
76 if (start_bits != -1 && len_bits > start_bits)
77 len_bits = start_bits;
78
79 return len_bits;
80}
81
82#endif /* ! __L4UTIL__INCLUDE__SPLITLOG2_H__ */
bit manipulation functions
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
@ L4_EINVAL
Invalid argument.
Definition err.h:57
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition compiler.h:192
#define EXTERN_C_END
End section with C types and functions.
Definition compiler.h:193
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
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:53