diff --git a/sdk/xtdk/amd64/hlfuncs.h b/sdk/xtdk/amd64/hlfuncs.h index 0fd872c..443623b 100644 --- a/sdk/xtdk/amd64/hlfuncs.h +++ b/sdk/xtdk/amd64/hlfuncs.h @@ -69,6 +69,10 @@ XTCDECL ULONGLONG HlReadModelSpecificRegister(IN ULONG Register); +XTCDECL +ULONGLONG +HlReadTimeStampCounter(); + XTCDECL VOID HlSetInterruptFlag(); diff --git a/sdk/xtdk/i686/hlfuncs.h b/sdk/xtdk/i686/hlfuncs.h index cf6137d..00ba7ae 100644 --- a/sdk/xtdk/i686/hlfuncs.h +++ b/sdk/xtdk/i686/hlfuncs.h @@ -69,6 +69,10 @@ XTCDECL ULONGLONG HlReadModelSpecificRegister(IN ULONG Register); +XTCDECL +ULONGLONG +HlReadTimeStampCounter(); + XTCDECL VOID HlSetInterruptFlag(); diff --git a/xtoskrnl/hl/amd64/cpufunc.c b/xtoskrnl/hl/amd64/cpufunc.c index 1197ebc..fd11ef8 100644 --- a/xtoskrnl/hl/amd64/cpufunc.c +++ b/xtoskrnl/hl/amd64/cpufunc.c @@ -321,6 +321,26 @@ HlReadModelSpecificRegister(IN ULONG Register) return ((ULONGLONG)High << 32) | Low; } +/** + * Reads the current value of the CPU's time-stamp counter. + * + * @return This routine returns the current instruction cycle count since the processor was started. + * + * @since XT 1.0 + */ +XTCDECL +ULONGLONG +HlReadTimeStampCounter() +{ + ULONGLONG Low, High; + + asm volatile("rdtsc" + :"=a"(Low), + "=d"(High)); + + return ((ULONGLONG)High << 32) | Low; +} + /** * Instructs the processor to set the interrupt flag. * diff --git a/xtoskrnl/hl/i686/cpufunc.c b/xtoskrnl/hl/i686/cpufunc.c index 4f45ee8..2320f42 100644 --- a/xtoskrnl/hl/i686/cpufunc.c +++ b/xtoskrnl/hl/i686/cpufunc.c @@ -313,6 +313,25 @@ HlReadModelSpecificRegister(IN ULONG Register) return Value; } +/** + * Reads the current value of the CPU's time-stamp counter. + * + * @return This routine returns the current instruction cycle count since the processor was started. + * + * @since XT 1.0 + */ +XTCDECL +ULONGLONG +HlReadTimeStampCounter() +{ + ULONGLONG Value; + + asm volatile("rdtsc" + : "=A"(Value)); + + return Value; +} + /** * Instructs the processor to set the interrupt flag. *