Add endian conversion routines

This commit is contained in:
Rafal Kupiec 2023-02-08 16:33:57 +01:00
parent a32e18b237
commit d8c68ed003
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 85 additions and 0 deletions

View File

@ -91,6 +91,18 @@ RtlStringToWideString(OUT PWCHAR Destination,
IN CONST PUCHAR *Source,
IN SIZE_T Length);
XTFASTCALL
ULONG
RtlUlongByteSwap(IN ULONG Source);
XTFASTCALL
ULONGLONG
RtlUlonglongByteSwap(IN ULONGLONG Source);
XTFASTCALL
USHORT
RtlUshortByteSwap(IN USHORT Source);
XTCDECL
INT
RtlWideStringCompare(IN CONST PWCHAR String1,

View File

@ -18,6 +18,7 @@ list(APPEND XTOSKRNL_SOURCE
${XTOSKRNL_SOURCE_DIR}/ke/globals.c
${XTOSKRNL_SOURCE_DIR}/ke/krnlinit.c
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/krnlinit.c
${XTOSKRNL_SOURCE_DIR}/rtl/byteswap.c
${XTOSKRNL_SOURCE_DIR}/rtl/memory.c
${XTOSKRNL_SOURCE_DIR}/rtl/plist.c
${XTOSKRNL_SOURCE_DIR}/rtl/string.c

72
xtoskrnl/rtl/byteswap.c Normal file
View File

@ -0,0 +1,72 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/rtl/byteswap.c
* DESCRIPTION: Endian conversion routines
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtos.h>
/**
* This routine converts endianness on 32bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 32bit value.
*
* @since NT 4.0
*/
XTFASTCALL
ULONG
RtlUlongByteSwap(IN ULONG Source)
{
return (ULONG)(((Source >> 24) & 0x000000FF) |
((Source >> 8) & 0x0000FF00) |
((Source << 8) & 0x00FF0000) |
((Source << 24) & 0xFF000000));
}
/**
* This routine converts endianness on 64bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 64bit value.
*
* @since NT 4.0
*/
XTFASTCALL
ULONGLONG
RtlUlonglongByteSwap(IN ULONGLONG Source)
{
return (ULONGLONG)(((Source >> 56) & 0x00000000000000FF) |
((Source >> 40) & 0x000000000000FF00) |
((Source >> 24) & 0x0000000000FF0000) |
((Source >> 8) & 0x00000000FF000000) |
((Source << 8) & 0x000000FF00000000) |
((Source << 24) & 0x0000FF0000000000) |
((Source << 40) & 0x00FF000000000000) |
((Source << 56) & 0xFF00000000000000));
}
/**
* This routine converts endianness on 16bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 16bit value.
*
* @since NT 4.0
*/
XTFASTCALL
USHORT
RtlUshortByteSwap(IN USHORT Source)
{
return (USHORT)(((Source >> 8) & 0x00FF) |
((Source << 8) & 0xFF00));
}