3 * Copyright (c) 2003, David H. Hovemeyer <daveho@cs.umd.edu>
6 * This is free software. You are permitted to use,
7 * redistribute, and modify it as specified in the file "COPYING".
10 #ifndef GEEKOS_RANGE_H
11 #define GEEKOS_RANGE_H
13 #include <geekos/ktypes.h>
16 * TODO: think about these, make sure they're correct
20 * Check that given range is "proper".
21 * @param start the start of the range
22 * @param size the size of the range
23 * @return true if range is properly within the space
24 * 0(inclusive)..ULONG_MAX(inclusive)
26 static __inline__ bool
27 Check_Range_Proper(ulong_t start, ulong_t size)
30 * Wrap around is only permitted if the sum is zero.
31 * E.g., start=ULONG_MAX, size==1 is a valid range.
33 ulong_t sum = start + size;
34 return start <= sum || (sum == 0);
38 * Check that given range lies entirely under the
39 * maximum value specified (exclusive).
40 * @param start the start of the range
41 * @param size the size of the range
42 * @param max the lowest address NOT allowed to be in the range
43 * @return true if range falls entirely within the range
44 * 0(inclusive)..max(exclusive)
46 static __inline__ bool
47 Check_Range_Under(ulong_t start, ulong_t size, ulong_t max)
49 if (!Check_Range_Proper(start, size))
52 return start < max && (start + size) <= max;
55 #endif /* GEEKOS_RANGE_H */