From 897d9d4099a52c817bccc7245fa9d797bf2bd13f Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sun, 10 May 2026 23:42:13 +0200 Subject: [PATCH] Expose timer performance counter and clock rate functions --- sdk/xtdk/hlfuncs.h | 10 ++++++++++ xtoskrnl/hl/exports.cc | 36 ++++++++++++++++++++++++++++++++++++ xtoskrnl/xtoskrnl.spec | 2 ++ 3 files changed, 48 insertions(+) diff --git a/sdk/xtdk/hlfuncs.h b/sdk/xtdk/hlfuncs.h index 6bb6a5f..34dbc99 100644 --- a/sdk/xtdk/hlfuncs.h +++ b/sdk/xtdk/hlfuncs.h @@ -18,6 +18,11 @@ #ifndef __XTOS_ASSEMBLER__ /* Hardware layer routines forward references */ +XTCLINK +XTAPI +LARGE_INTEGER +HlQueryPerformanceCounter(OUT PLARGE_INTEGER PerformanceFrequency); + XTCLINK XTAPI UCHAR @@ -33,6 +38,11 @@ XTAPI ULONG HlReadRegister32(IN PVOID Register); +XTCLINK +XTAPI +ULONG +HlSetClockRate(IN ULONG Rate); + XTCLINK XTAPI VOID diff --git a/xtoskrnl/hl/exports.cc b/xtoskrnl/hl/exports.cc index 0321cf1..0832ea4 100644 --- a/xtoskrnl/hl/exports.cc +++ b/xtoskrnl/hl/exports.cc @@ -9,6 +9,24 @@ #include +/** + * Retrieves the current value of the high-resolution performance counter. + * + * @param PerformanceFrequency + * Suplies an optional pointer to a variable that receives the performance counter frequency in Hz. + * + * @return This routine returns the current 64-bit monotonic tick count. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +LARGE_INTEGER +HlQueryPerformanceCounter(OUT PLARGE_INTEGER PerformanceFrequency) +{ + return HL::Timer::QueryPerformanceCounter(PerformanceFrequency); +} + /** * Reads the 8-bit data from the specified I/O port. * @@ -117,6 +135,24 @@ HlReadRegister32(IN PVOID Register) return HL::IoRegister::ReadRegister32(Register); } +/** + * Requests a dynamic adjustment of the system clock resolution. + * + * @param Rate + * The requested clock rate change in 100-nanosecond units. + * + * @return This routine returns the actual clock rate granted by the hardware. + * + * @since XT 1.0 + */ +XTCLINK +XTAPI +ULONG +HlSetClockRate(IN ULONG Rate) +{ + return HL::Timer::SetClockRate(Rate); +} + /** * Writes the 8-bit data to the specified I/O port. * diff --git a/xtoskrnl/xtoskrnl.spec b/xtoskrnl/xtoskrnl.spec index 17d6fa1..f5d47ff 100644 --- a/xtoskrnl/xtoskrnl.spec +++ b/xtoskrnl/xtoskrnl.spec @@ -6,12 +6,14 @@ @ fastcall ExReInitializeRundownProtection(ptr) @ fastcall ExReleaseRundownProtection(ptr) @ fastcall ExWaitForRundownProtectionRelease(ptr) +@ stdcall HlQueryPerformanceCounter(ptr) @ cdecl HlReadPort8(ptr) @ cdecl HlReadPort16(ptr) @ cdecl HlReadPort32(ptr) @ stdcall HlReadRegister8(ptr) @ stdcall HlReadRegister16(ptr) @ stdcall HlReadRegister32(ptr) +@ stdcall HlSetClockRate(long) @ cdecl HlWritePort8(ptr long) @ cdecl HlWritePort16(ptr long) @ cdecl HlWritePort32(ptr long)