From 06e34ab57f74e1c53b91f819e40d8d4a8d1b4383 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 13 May 2023 07:40:05 +0300 Subject: [PATCH] Remove EFER from x32 --- Core/Crash/UserHandler.cpp | 8 ++---- Core/Crash/chfcts.hpp | 1 - include/cpu.hpp | 57 +++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/Core/Crash/UserHandler.cpp b/Core/Crash/UserHandler.cpp index 009c79c..3b7519d 100644 --- a/Core/Crash/UserHandler.cpp +++ b/Core/Crash/UserHandler.cpp @@ -70,8 +70,6 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) CPU::x32::CR3 cr3 = CPU::x32::readcr3(); CPU::x32::CR4 cr4 = CPU::x32::readcr4(); CPU::x32::CR8 cr8 = CPU::x32::readcr8(); - CPU::x32::EFER efer; - efer.raw = CPU::x32::rdmsr(CPU::x32::MSR_EFER); error("Technical Informations on CPU %lld:", CurCPU->ID); uintptr_t ds; @@ -95,7 +93,7 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) Frame->ss, Frame->cs, ds); error("EAX=%#llx EBX=%#llx ECX=%#llx EDX=%#llx", Frame->eax, Frame->ebx, Frame->ecx, Frame->edx); error("ESI=%#llx EDI=%#llx EBP=%#llx ESP=%#llx", Frame->esi, Frame->edi, Frame->ebp, Frame->esp); - error("EIP=%#llx EFL=%#llx INT=%#llx ERR=%#llx EFER=%#llx", Frame->eip, Frame->eflags.raw, Frame->InterruptNumber, Frame->ErrorCode, efer.raw); + error("EIP=%#llx EFL=%#llx INT=%#llx ERR=%#llx", Frame->eip, Frame->eflags.raw, Frame->InterruptNumber, Frame->ErrorCode); #elif defined(aa64) #endif @@ -156,12 +154,12 @@ SafeFunction void UserModeExceptionHandler(CHArchTrapFrame *Frame) #elif defined(aa64) #endif -#if defined(a86) +#if defined(a64) error("EFER: SCE:%s LME:%s LMA:%s NXE:%s SVME:%s LMSLE:%s FFXSR:%s TCE:%s R0:%#x R1:%#x R2:%#x", efer.SCE ? "True " : "False", efer.LME ? "True " : "False", efer.LMA ? "True " : "False", efer.NXE ? "True " : "False", efer.SVME ? "True " : "False", efer.LMSLE ? "True " : "False", efer.FFXSR ? "True " : "False", efer.TCE ? "True " : "False", efer.Reserved0, efer.Reserved1, efer.Reserved2); -#endif // a64 || a32 +#endif } switch (Frame->InterruptNumber) diff --git a/Core/Crash/chfcts.hpp b/Core/Crash/chfcts.hpp index 41a7a70..f5b0302 100644 --- a/Core/Crash/chfcts.hpp +++ b/Core/Crash/chfcts.hpp @@ -58,7 +58,6 @@ struct CRData CPU::x32::CR3 cr3; CPU::x32::CR4 cr4; CPU::x32::CR8 cr8; - CPU::x32::EFER efer; uintptr_t dr0, dr1, dr2, dr3, dr6; CPU::x32::DR7 dr7; diff --git a/include/cpu.hpp b/include/cpu.hpp index 1cdcaf5..9b6b9a2 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -279,37 +279,6 @@ namespace CPU uint32_t ss; // Stack Segment } TrapFrame; - /* TODO: Does EFER exists in x32? */ - typedef union EFER - { - struct - { - /** @brief Enable syscall & sysret instructions in 64-bit mode. */ - uint32_t SCE : 1; - /** @brief Reserved */ - uint32_t Reserved0 : 7; - /** @brief Enable long mode. */ - uint32_t LME : 1; - /** @brief Reserved */ - uint32_t Reserved1 : 1; - /** @brief Indicates long. */ - uint32_t LMA : 1; - /** @brief Enable No-Execute Bit */ - uint32_t NXE : 1; - /** @brief Enable Secure Virtual Machine */ - uint32_t SVME : 1; - /** @brief Enable Long Mode Segment Limit */ - uint32_t LMSLE : 1; - /** @brief Enable Fast FXSAVE/FXRSTOR */ - uint32_t FFXSR : 1; - /** @brief Enable Translation Cache Extension */ - uint32_t TCE : 1; - /** @brief Reserved */ - uint32_t Reserved2 : 32; - }; - uint32_t raw; - } __packed EFER; - // ! TODO: UNTESTED! typedef union DR7 { @@ -412,6 +381,32 @@ namespace CPU : "memory"); #else UNUSED(Address); +#endif + } + + SafeFunction static inline void fxsave(void *FXSaveArea) + { +#if defined(a32) + if (!FXSaveArea) + return; + + asmv("fxsave (%0)" + : + : "r"(FXSaveArea) + : "memory"); +#endif + } + + SafeFunction static inline void fxrstor(void *FXRstorArea) + { +#if defined(a32) + if (!FXRstorArea) + return; + + asmv("fxrstor (%0)" + : + : "r"(FXRstorArea) + : "memory"); #endif } }