core.util¶
Portable data manipulation utilities with no architecture-specific dependencies.
Overview¶
core.util provides low-level helpers that operate on raw integers and memory without relying on any x86 assembly. It covers byte and nibble extraction, endian byte-order swapping, flat memory operations (memset/memcpy), BCD-to-integer conversion, hex character parsing, and a branchless absolute value. These primitives are used throughout the kernel wherever portable, assembly-free data manipulation is required.
Dependencies¶
None.
Functions and Procedures¶
hi¶
Returns the high nibble (bits 7–4) of a byte, shifted into the low four bits of the result. Exported with the aliasutil_hi.
lo¶
Returns the low nibble (bits 3–0) of a byte. Exported with the aliasutil_lo.
switchendian¶
Swaps the two nibbles of a byte (equivalent to a 4-bit rotate). Exported with the aliasutil_switchendian.
switchendian16¶
Reverses the byte order of a 16-bit value, converting between big-endian and little-endian representations.switchendian32¶
Reverses the byte order of a 32-bit value for endian conversion.getWord¶
Extracts the high or low 16-bit word from a 32-bit value. Returns bits 31–16 whenhi is true; bits 15–0 otherwise.
getByte¶
Extracts a single byte from a 32-bit value by zero-based byte index (0 = least significant byte).memset¶
Fillssize bytes starting at address location with the byte value. Does nothing if size is zero.
memcpy¶
Copiessize bytes from address source to address dest byte by byte. Behaviour is undefined if the regions overlap.
BCDToUint8¶
Converts a Binary-Coded Decimal byte to its unsigned integer equivalent. The high nibble is the tens digit; the low nibble is the units digit.HexCharToDecimal¶
Converts a single hexadecimal character (0–9, a–f, A–F) to its decimal value 0–15. Returns 0 for unrecognised characters.
abs¶
Returns the absolute value of a signed 32-bit integer using a branchless arithmetic technique based on sign-extension, XOR, and subtraction. The result type isuint32.
Notes¶
memcpy is a simple byte loop and does not handle overlapping source and destination regions correctly. Callers must ensure regions do not overlap, or copy in the appropriate direction manually.
The hi, lo, and switchendian functions carry stable C-compatible export aliases (util_hi, util_lo, util_switchendian) for use from assembly or interop stubs.