20 #ifndef KERNEL_UTILITY_H 21 #define KERNEL_UTILITY_H 23 #include "pedigree/kernel/compiler.h" 24 #include "pedigree/kernel/processor/types.h" 27 #include "pedigree/kernel/utilities/cpp.h" 28 #include "pedigree/kernel/utilities/lib.h" 30 #if defined(HOSTED) && !defined(UTILITY_LINUX) 40 #define BS16(x) (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) 42 (((x & 0xFF000000) >> 24) | ((x & 0x00FF0000) >> 8) | \ 43 ((x & 0x0000FF00) << 8) | ((x & 0x000000FF) << 24)) 46 #ifdef TARGET_IS_LITTLE_ENDIAN 48 #define LITTLE_TO_HOST8(x) (x) 49 #define LITTLE_TO_HOST16(x) (x) 50 #define LITTLE_TO_HOST32(x) (x) 51 #define LITTLE_TO_HOST64(x) (x) 53 #define HOST_TO_LITTLE8(x) (x) 54 #define HOST_TO_LITTLE16(x) (x) 55 #define HOST_TO_LITTLE32(x) (x) 56 #define HOST_TO_LITTLE64(x) (x) 58 #define BIG_TO_HOST8(x) BS8((x)) 59 #define BIG_TO_HOST16(x) BS16((x)) 60 #define BIG_TO_HOST32(x) BS32((x)) 61 #define BIG_TO_HOST64(x) BS64((x)) 63 #define HOST_TO_BIG8(x) BS8((x)) 64 #define HOST_TO_BIG16(x) BS16((x)) 65 #define HOST_TO_BIG32(x) BS32((x)) 66 #define HOST_TO_BIG64(x) BS64((x)) 68 #else // else Big endian 70 #define BIG_TO_HOST8(x) (x) 71 #define BIG_TO_HOST16(x) (x) 72 #define BIG_TO_HOST32(x) (x) 73 #define BIG_TO_HOST64(x) (x) 75 #define HOST_TO_BIG8(x) (x) 76 #define HOST_TO_BIG16(x) (x) 77 #define HOST_TO_BIG32(x) (x) 78 #define HOST_TO_BIG64(x) (x) 80 #define LITTLE_TO_HOST8(x) BS8((x)) 81 #define LITTLE_TO_HOST16(x) BS16((x)) 82 #define LITTLE_TO_HOST32(x) BS32((x)) 83 #define LITTLE_TO_HOST64(x) BS64((x)) 85 #define HOST_TO_LITTLE8(x) BS8((x)) 86 #define HOST_TO_LITTLE16(x) BS16((x)) 87 #define HOST_TO_LITTLE32(x) BS32((x)) 88 #define HOST_TO_LITTLE64(x) BS64((x)) 92 #define MAX_FUNCTION_NAME 128 94 #define MAX_PARAM_LENGTH 64 104 template <
typename T>
105 inline T *adjust_pointer(T *pointer, ssize_t offset)
107 return reinterpret_cast<T *
>(
reinterpret_cast<intptr_t
>(pointer) + offset);
110 template <
typename T>
111 inline void swap(T a, T b)
119 template <
typename T1,
typename T2>
120 inline intptr_t pointer_diff(
const T1 *a,
const T2 *b)
122 return reinterpret_cast<uintptr_t
>(b) - reinterpret_cast<uintptr_t>(a);
125 template <
typename T1,
typename T2>
126 constexpr intptr_t pointer_diff_const(T1 *a, T2 *b)
128 return reinterpret_cast<uintptr_t
>(b) - reinterpret_cast<uintptr_t>(a);
132 template <
typename T1,
typename T2>
133 inline uintptr_t abs_difference(T1 a, T2 b)
135 intptr_t value = b - a;
EXPORTED_PUBLIC void * page_align(void *p) PURE