Initial bit maps support
All checks were successful
Builds / ExectOS (i686) (push) Successful in 34s
Builds / ExectOS (amd64) (push) Successful in 37s

This commit is contained in:
Rafal Kupiec 2024-03-12 19:15:02 +01:00
parent 3a86ab1424
commit c3831f82e7
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
5 changed files with 204 additions and 0 deletions

View File

@ -69,6 +69,13 @@ typedef enum _RTL_VARIABLE_TYPE
WideString
} RTL_VARIABLE_TYPE, *PRTL_VARIABLE_TYPE;
/* Bit Map structure definition */
typedef struct _RTL_BITMAP
{
ULONG Size;
PULONG_PTR Buffer;
} RTL_BITMAP, *PRTL_BITMAP;
/* Runtime Library print context structure definition */
typedef struct _RTL_PRINT_CONTEXT
{

View File

@ -41,6 +41,14 @@
#define MAXLONG 0x7FFFFFFF
#define MAXULONG 0xFFFFFFFF
/* Pointer limits */
#define MININT_PTR (~MAXINT_PTR)
#define MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1))
#define MAXUINT_PTR (~((UINT_PTR)0))
#define MINLONG_PTR (~MAXLONG_PTR)
#define MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1))
#define MAXULONG_PTR (~((ULONG_PTR)0))
/* Number of bits per byte */
#define BITS_PER_BYTE 8

View File

@ -22,6 +22,7 @@
#define _ARCH_NAME "32-bit x86"
#define _ARCH_IMAGE_MACHINE_TYPE 0x014C
#define _XT32 1
#define BITS_PER_LONG 32
#define CACHE_ALIGNMENT 64
#define EFI_ERROR_MASK 0x80000000
#define MAXIMUM_PROCESSORS 32
@ -35,6 +36,7 @@
#define _ARCH_NAME "64-bit x86"
#define _ARCH_IMAGE_MACHINE_TYPE 0x8664
#define _XT64 1
#define BITS_PER_LONG 64
#define CACHE_ALIGNMENT 64
#define EFI_ERROR_MASK 0x8000000000000000
#define MAXIMUM_PROCESSORS 256

View File

@ -40,6 +40,7 @@ list(APPEND XTOSKRNL_SOURCE
${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pages.c
${XTOSKRNL_SOURCE_DIR}/po/idle.c
${XTOSKRNL_SOURCE_DIR}/rtl/atomic.c
${XTOSKRNL_SOURCE_DIR}/rtl/bitmap.c
${XTOSKRNL_SOURCE_DIR}/rtl/byteswap.c
${XTOSKRNL_SOURCE_DIR}/rtl/globals.c
${XTOSKRNL_SOURCE_DIR}/rtl/guid.c

186
xtoskrnl/rtl/bitmap.c Normal file
View File

@ -0,0 +1,186 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/rtl/bitmap.c
* DESCRIPTION: Bit maps support related routines
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtos.h>
/**
* Clears all bits in the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @return This routine does not return any value.
*
* @since NT 3.5
*/
XTAPI
VOID
RtlClearAllBits(IN PRTL_BITMAP BitMap)
{
/* Clear all bits */
RtlSetMemory(BitMap->Buffer, 0, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR));
}
/**
* Clears a single bit in the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @param Bit
* Specifies the number of the bit to be cleared.
*
* @return This routine does not return any value.
*
* @since NT 5.1
*/
XTAPI
VOID
RtlClearBit(IN PRTL_BITMAP BitMap,
IN ULONG_PTR Bit)
{
/* Check if bit is in range */
if(Bit >= BitMap->Size)
{
/* Supplied bit exceeds bit map size */
return;
}
/* Clear specified bit */
BitMap->Buffer[Bit / BITS_PER_LONG] &= ~(1 << (Bit & (BITS_PER_LONG - 1)));
}
/**
* Dumps the contents of the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
RtlDumpBitMap(IN PRTL_BITMAP BitMap)
{
ULONG_PTR Index;
/* Dump bit map buffer information */
DebugPrint(L"BitMap Buffer: 0x%zX (%lu bytes)\n", BitMap->Buffer, BitMap->Size);
/* Dump bit map buffer content */
for(Index = 0; Index < (BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG; Index++)
{
DebugPrint(L" %8zu: %08lx\n", Index, BitMap->Buffer[Index]);
}
}
/**
* Initializes a bit map.
*
* @param BitMap
* Supplies a pointer to the bit map to initialize.
*
* @param Buffer
* Supplies a pointer to the buffer that will be used as a bit map.
*
* @param Size
* Supplies a size of the bit map.
*
* @return This routine does not return any value.
*
* @since NT 3.5
*/
XTAPI
VOID
RtlInitializeBitMap(IN PRTL_BITMAP BitMap,
IN PULONG_PTR Buffer,
IN ULONG Size)
{
/* Initialize bit map */
BitMap->Buffer = Buffer;
BitMap->Size = Size;
}
/**
* Sets all bits in the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @return This routine does not return any value.
*
* @since NT 3.5
*/
XTAPI
VOID
RtlSetAllBits(IN PRTL_BITMAP BitMap)
{
/* Set all bits */
RtlSetMemory(BitMap->Buffer, 0xFF, ((BitMap->Size + BITS_PER_LONG - 1) / BITS_PER_LONG) * sizeof(ULONG_PTR));
}
/**
* Sets a single bit in the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @param Bit
* Specifies the number of the bit to be set.
*
* @return This routine does not return any value.
*
* @since NT 5.1
*/
XTAPI
VOID
RtlSetBit(IN PRTL_BITMAP BitMap,
IN ULONG_PTR Bit)
{
/* Check if bit is in range */
if(Bit >= BitMap->Size)
{
/* Supplied bit exceeds bit map size */
return;
}
/* Set specified bit */
BitMap->Buffer[Bit / BITS_PER_LONG] |= 1 << (Bit & (BITS_PER_LONG - 1));
}
/**
* Tests a state of a single bit in the bit map.
*
* @param BitMap
* Supplies a pointer to the bit map.
*
* @param Bit
* Specifies the number of the bit to be tested.
*
* @return This routine returns TRUE when bit is set, or FALSE otherwise.
*
* @since NT 5.1
*/
XTAPI
BOOLEAN
RtlTestBit(IN PRTL_BITMAP BitMap,
IN ULONG_PTR Bit)
{
/* Check if bit is in range */
if(Bit >= BitMap->Size)
{
/* Supplied bit exceeds bit map size, return FALSE */
return FALSE;
}
/* Test specified bit and return result */
return ((BitMap->Buffer[Bit / BITS_PER_LONG] >> (Bit & (BITS_PER_LONG - 1))) & 1) ? TRUE : FALSE;
}