Fixed tasking SSE

This commit is contained in:
Alex
2022-12-29 02:05:07 +02:00
parent 5da3b3ae6c
commit e53bc14240
7 changed files with 88 additions and 57 deletions

View File

@ -5,11 +5,6 @@
#include <cstring>
extern "C" void _amd64_fxsave(char *Buffer);
extern "C" void _amd64_fxrstor(char *Buffer);
extern "C" void _i386_fxsave(char *Buffer);
extern "C" void _i386_fxrstor(char *Buffer);
#define x86_CPUID_VENDOR_OLDAMD "AMDisbetter!" /* Early engineering samples of AMD K5 processor */
#define x86_CPUID_VENDOR_AMD "AuthenticAMD"
#define x86_CPUID_VENDOR_INTEL "GenuineIntel"
@ -3404,31 +3399,29 @@ namespace CPU
#endif
}
SafeFunction static inline void fxsave(char *FXSaveArea)
SafeFunction static inline void fxsave(void *FXSaveArea)
{
#if defined(__amd64__)
if (!FXSaveArea || FXSaveArea >= (char *)0xfffffffffffff000)
return;
_amd64_fxsave(FXSaveArea);
// asmv("fxsaveq (%0)"
// :
// : "r"(FXSaveArea)
// : "memory");
asmv("fxsaveq (%0)"
:
: "r"(FXSaveArea)
: "memory");
#endif
}
SafeFunction static inline void fxrstor(char *FXRstorArea)
SafeFunction static inline void fxrstor(void *FXRstorArea)
{
#if defined(__amd64__)
if (!FXRstorArea || FXRstorArea >= (char *)0xfffffffffffff000)
return;
_amd64_fxrstor(FXRstorArea);
// asmv("fxrstorq (%0)"
// :
// : "r"(FXRstorArea)
// : "memory");
asmv("fxrstorq (%0)"
:
: "r"(FXRstorArea)
: "memory");
#endif
}

View File

@ -57,6 +57,32 @@ namespace Tasking
Terminated
};
struct FXState
{
/** @brief FPU control word */
uint16_t fcw;
/** @brief FPU status word */
uint16_t fsw;
/** @brief FPU tag words */
uint8_t ftw;
/** @brief Reserved (zero) */
uint8_t Reserved;
/** @brief FPU opcode */
uint16_t fop;
/** @brief PFU instruction pointer */
uint64_t rip;
/** @brief FPU data pointer */
uint64_t rdp;
/** @brief SSE control register */
uint32_t mxcsr;
/** @brief SSE control register mask */
uint32_t mxcsrmask;
/** @brief FPU registers (last 6 bytes reserved) */
uint8_t st[8][16];
/** @brief XMM registers */
uint8_t xmm[16][16];
} __attribute__((packed));
struct TaskSecurity
{
TaskTrustLevel TrustLevel;
@ -104,7 +130,7 @@ namespace Tasking
uintptr_t IPHistory[128];
TaskSecurity Security;
TaskInfo Info;
char FXRegion[512] __attribute__((aligned(16)));
FXState *FPU;
void Rename(const char *name)
{