From c81b85875734d5c84809309e3c1c3bcd1457eb8c Mon Sep 17 00:00:00 2001 From: belliash Date: Mon, 23 Jan 2023 19:59:54 +0100 Subject: [PATCH] Implement HlReadGSQuadWord() intrinsic --- sdk/xtdk/amd64/hlfuncs.h | 4 ++++ xtoskrnl/hl/amd64/cpufunc.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sdk/xtdk/amd64/hlfuncs.h b/sdk/xtdk/amd64/hlfuncs.h index c980ee2..947382a 100644 --- a/sdk/xtdk/amd64/hlfuncs.h +++ b/sdk/xtdk/amd64/hlfuncs.h @@ -67,6 +67,10 @@ XTCDECL ULONG_PTR HlReadControlRegister(IN USHORT ControlRegister); +XTCDECL +ULONGLONG +HlReadGSQuadWord(ULONG Offset); + XTCDECL ULONGLONG HlReadModelSpecificRegister(IN ULONG Register); diff --git a/xtoskrnl/hl/amd64/cpufunc.c b/xtoskrnl/hl/amd64/cpufunc.c index 8c4cf78..ae68d3a 100644 --- a/xtoskrnl/hl/amd64/cpufunc.c +++ b/xtoskrnl/hl/amd64/cpufunc.c @@ -318,6 +318,27 @@ HlReadControlRegister(IN USHORT ControlRegister) return Value; } +/** + * Reads quadword from a memory location specified by an offset relative to the beginning of the GS segment. + * + * @param Offset + * Specifies the offset from the beginning of GS segment. + * + * @return Returns the value read from the specified memory location relative to GS segment. + * + * @since XT 1.0 + */ +XTCDECL +ULONGLONG +HlReadGSQuadWord(ULONG Offset) +{ + ULONGLONG Value; + + /* Read quadword from GS segment */ + asm volatile("movq %%gs:%a[Offset], %q[Value]" : [Value] "=r" (Value) : [Offset] "ir" (Offset)); + return Value; +} + /** * Reads a 64-bit value from the requested Model Specific Register (MSR). *