Loading...
Searching...
No Matches
splitlog2.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#ifndef __L4UTIL__INCLUDE__SPLITLOG2_H__
#define __L4UTIL__INCLUDE__SPLITLOG2_H__
#include <l4/sys/linkage.h>
#include <l4/sys/err.h>
#include <l4/util/bitops.h>
L4_BEGIN_DECLS
L4_INLINE long
l4util_splitlog2_hdl(l4_addr_t start, l4_addr_t end,
long (*handler)(l4_addr_t s, l4_addr_t e, int log2size));
L4_INLINE l4_addr_t
l4util_splitlog2_size(l4_addr_t start, l4_addr_t end);
L4_END_DECLS
/* Implementation */
L4_INLINE long
l4util_splitlog2_hdl(l4_addr_t start, l4_addr_t end,
long (*handler)(l4_addr_t s, l4_addr_t e, int log2size))
{
if (end < start)
return -L4_EINVAL;
while (start <= end)
{
long retval;
int len2 = l4util_splitlog2_size(start, end);
l4_addr_t len = 1UL << len2;
if ((retval = handler(start, start + len - 1, len2)))
return retval;
start += len;
}
return 0;
}
L4_INLINE l4_addr_t
l4util_splitlog2_size(l4_addr_t start, l4_addr_t end)
{
int start_bits = l4util_bsf(start);
int len_bits = l4util_bsr(end - start + 1);
if (start_bits != -1 && len_bits > start_bits)
len_bits = start_bits;
return len_bits;
}
#endif /* ! __L4UTIL__INCLUDE__SPLITLOG2_H__ */
bitops.h
bit manipulation functions
err.h
Error codes.
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
L4_EINVAL
@ L4_EINVAL
Invalid argument.
Definition err.h:46
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_BEGIN_DECLS
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:165
L4_END_DECLS
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:166
l4util_splitlog2_size
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
l4util_splitlog2_hdl
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