L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 while (start <= end)
58 {
59 long retval;
60 int len2 = l4util_splitlog2_size(start, end);
61 l4_addr_t len = 1UL << len2;
62 if ((retval = handler(start, start + len - 1, len2)))
63 return retval;
64 start += len;
65 }
66 return 0;
67}
68
71{
72 int start_bits = l4util_bsf(start);
73 int len_bits = l4util_bsr(end - start + 1);
74 if (start_bits != -1 && len_bits > start_bits)
75 len_bits = start_bits;
76
77 return len_bits;
78}
79
80#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:46
#define __END_DECLS
End section with C types and functions.
Definition compiler.h:167
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define __BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:164
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:70
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