From 2a8cc7397ef9a7f6791e0cd605af096aee61bba7 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Tue, 14 May 2024 16:26:02 +0200 Subject: [PATCH] Implement ArGetCpuFlags() routine --- xtoskrnl/ar/amd64/cpufunc.c | 24 ++++++++++++++++++++++++ xtoskrnl/ar/i686/cpufunc.c | 24 ++++++++++++++++++++++++ xtoskrnl/includes/amd64/ari.h | 4 ++++ xtoskrnl/includes/i686/ari.h | 4 ++++ 4 files changed, 56 insertions(+) diff --git a/xtoskrnl/ar/amd64/cpufunc.c b/xtoskrnl/ar/amd64/cpufunc.c index 2db1e56..b65b041 100644 --- a/xtoskrnl/ar/amd64/cpufunc.c +++ b/xtoskrnl/ar/amd64/cpufunc.c @@ -82,6 +82,30 @@ ArFlushTlb(VOID) ArWriteControlRegister(3, ArReadControlRegister(3)); } +/** + * Gets the RFLAGS register. + * + * @return This routine returns the RFLAGS register. + * + * @since XT 1.0 + */ +XTCDECL +ULONG +ArGetCpuFlags(VOID) +{ + ULONG Flags; + + /* Get RFLAGS register */ + asm volatile("pushf\n" + "pop %0\n" + : "=rm" (Flags) + : + : "memory"); + + /* Return flags */ + return Flags; +} + /** * Gets the address of the current stack register. * diff --git a/xtoskrnl/ar/i686/cpufunc.c b/xtoskrnl/ar/i686/cpufunc.c index 8da2efa..2072a36 100644 --- a/xtoskrnl/ar/i686/cpufunc.c +++ b/xtoskrnl/ar/i686/cpufunc.c @@ -82,6 +82,30 @@ ArFlushTlb(VOID) ArWriteControlRegister(3, ArReadControlRegister(3)); } +/** + * Gets the EFLAGS register. + * + * @return This routine returns the EFLAGS register. + * + * @since XT 1.0 + */ +XTCDECL +ULONG +ArGetCpuFlags(VOID) +{ + ULONG Flags; + + /* Get EFLAGS register */ + asm volatile("pushf\n" + "pop %0\n" + : "=rm" (Flags) + : + : "memory"); + + /* Return flags */ + return Flags; +} + /** * Gets the address of the current stack register. * diff --git a/xtoskrnl/includes/amd64/ari.h b/xtoskrnl/includes/amd64/ari.h index b4da180..54c702a 100644 --- a/xtoskrnl/includes/amd64/ari.h +++ b/xtoskrnl/includes/amd64/ari.h @@ -25,6 +25,10 @@ XTCDECL VOID ArFlushTlb(VOID); +XTCDECL +ULONG +ArGetCpuFlags(VOID); + XTASSEMBLY XTCDECL ULONG_PTR diff --git a/xtoskrnl/includes/i686/ari.h b/xtoskrnl/includes/i686/ari.h index 199fcb1..d61a0bd 100644 --- a/xtoskrnl/includes/i686/ari.h +++ b/xtoskrnl/includes/i686/ari.h @@ -25,6 +25,10 @@ XTCDECL VOID ArFlushTlb(VOID); +XTCDECL +ULONG +ArGetCpuFlags(VOID); + XTASSEMBLY XTCDECL ULONG_PTR