20#ifndef KERNEL_UTILITY_H
21#define KERNEL_UTILITY_H
22#include "pedigree/kernel/compiler.h"
23#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/cpp.h"
29#include "pedigree/kernel/utilities/lib.h"
39constexpr uint8_t BS8(uint8_t value)
noexcept {
43constexpr uint16_t BS16(uint16_t value)
noexcept {
44 return std::byteswap(value);
47constexpr uint32_t BS32(uint32_t value)
noexcept {
48 return std::byteswap(value);
51constexpr uint64_t BS64(uint64_t value)
noexcept {
52 return std::byteswap(value);
55#define BS8(x) ((uint8_t)(x))
56#define BS16(x) __builtin_bswap16((uint16_t)(x))
57#define BS32(x) __builtin_bswap32((uint32_t)(x))
58#define BS64(x) __builtin_bswap64((uint64_t)(x))
61#if TARGET_IS_LITTLE_ENDIAN
63#define LITTLE_TO_HOST8(x) (x)
64#define LITTLE_TO_HOST16(x) (x)
65#define LITTLE_TO_HOST32(x) (x)
66#define LITTLE_TO_HOST64(x) (x)
68#define HOST_TO_LITTLE8(x) (x)
69#define HOST_TO_LITTLE16(x) (x)
70#define HOST_TO_LITTLE32(x) (x)
71#define HOST_TO_LITTLE64(x) (x)
73#define BIG_TO_HOST8(x) BS8((x))
74#define BIG_TO_HOST16(x) BS16((x))
75#define BIG_TO_HOST32(x) BS32((x))
76#define BIG_TO_HOST64(x) BS64((x))
78#define HOST_TO_BIG8(x) BS8((x))
79#define HOST_TO_BIG16(x) BS16((x))
80#define HOST_TO_BIG32(x) BS32((x))
81#define HOST_TO_BIG64(x) BS64((x))
85#define BIG_TO_HOST8(x) (x)
86#define BIG_TO_HOST16(x) (x)
87#define BIG_TO_HOST32(x) (x)
88#define BIG_TO_HOST64(x) (x)
90#define HOST_TO_BIG8(x) (x)
91#define HOST_TO_BIG16(x) (x)
92#define HOST_TO_BIG32(x) (x)
93#define HOST_TO_BIG64(x) (x)
95#define LITTLE_TO_HOST8(x) BS8((x))
96#define LITTLE_TO_HOST16(x) BS16((x))
97#define LITTLE_TO_HOST32(x) BS32((x))
98#define LITTLE_TO_HOST64(x) BS64((x))
100#define HOST_TO_LITTLE8(x) BS8((x))
101#define HOST_TO_LITTLE16(x) BS16((x))
102#define HOST_TO_LITTLE32(x) BS32((x))
103#define HOST_TO_LITTLE64(x) BS64((x))
107#define MAX_FUNCTION_NAME 128
109#define MAX_PARAM_LENGTH 64
119template <
typename T1,
typename T2 = T1>
120T2* adjust_pointer(T1* pointer, ssize_t offset) {
121 return reinterpret_cast<T2*
>(
reinterpret_cast<intptr_t
>(pointer) + offset);
132template <
typename T1,
typename T2>
133intptr_t pointer_diff(
const T1* a,
const T2* b) {
134 return reinterpret_cast<uintptr_t
>(b) -
reinterpret_cast<uintptr_t
>(a);
137template <
typename T1,
typename T2>
138constexpr intptr_t pointer_diff_const(T1* a, T2* b) {
139 return reinterpret_cast<uintptr_t
>(b) -
reinterpret_cast<uintptr_t
>(a);
143template <
typename T1,
typename T2>
144uintptr_t abs_difference(T1 a, T2 b) {
145 intptr_t value = b - a;
EXPORTED_PUBLIC void * page_align(void *p) PURE