target-i386: Use struct X86XSaveArea in fpu_helper.c
PATCH 1/1 target-i386: Use struct X86XSaveArea in fpu_helper.c
This avoids a double hand-full of magic numbers in the xsave and xrstor helper functions.
--- target-i386/cpu.c | 7 +++- target-i386/cpu.h | 7 ---- target-i386/fpu_helper.c | 99 +++++++++++++++++++++++++----------------------- 3 files changed, 58 insertions(+), 55 deletions(-)
target-i386/cpu.c +6 -1
@@ -472,7 +472,12 @@ static const X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = { };#undef REGISTER -const ExtSaveArea x86_ext_save_areas[] = { +typedef struct ExtSaveArea { +uint32_t feature, bits; +uint32_t offset, size; +}ExtSaveArea ; + +static const ExtSaveArea x86_ext_save_areas[] = { [XSTATE_YMM_BIT ] = { .feature =FEAT_1_ECX , .bits =CPUID_EXT_AVX , .offset = offsetof(X86XSaveArea , avx_state),
target-i386/cpu.h +0 -7
@@ -1345,13 +1345,6 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo, void *puc);/* cpu.c */ -typedef struct ExtSaveArea { -uint32_t feature, bits; -uint32_t offset, size; -}ExtSaveArea ; - -extern const ExtSaveArea x86_ext_save_areas[]; -void cpu_x86_cpuid (CPUX86State *env,uint32_t index,uint32_t count,uint32_t *eax,uint32_t *ebx,uint32_t *ecx,uint32_t *edx);
target-i386/fpu_helper.c +52 -47
245 lines not on this page · raw message
Signature · 1 line
2.5.5
On Sat, Jul 02, 2016 at 09:44:31AM -0700, Richard Henderson wrote:
[...]
target-i386/fpu_helper.c void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) · line 1414
Quoted 10 lines
target-i386/fpu_helper.c +2
-3@@ -1402,9 +1409,8 @@ void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) }/* The XCOMP field must be zero. */ - xcomp_bv0 =cpu_ldq_data_ra (env, ptr +520 , ra); - xcomp_bv1 =cpu_ldq_data_ra (env, ptr +528 , ra); -if (xcomp_bv0 || xcomp_bv1) { + xcomp_bv =cpu_ldq_data_ra (env, ptr +XO (header.xcomp_bv), ra); +if (xcomp_bv) {raise_exception_ra (env,EXCP0D_GPF , ra);
You are changing the code to not check bytes 528-535 (bytes 16:23 of the XSAVE header) anymore, but Intel SDM says XRSTOR raises #GP "If the standard form is executed and bytes 23:8 of the XSAVE header are not all zero."
Signature · 1 line
Eduardo
Quoted 5 lines · Eduardo Habkost
On Sat, Jul 02, 2016 at 09:44:31AM -0700, Richard Henderson wrote:
[...]Quoted 3 lines
(quoted diff) +0
-0@@ -1402,9 +1409,8 @@ void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) }
Quoted 12 lines
target-i386/fpu_helper.c void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) · line 1414
Quoted 7 lines
target-i386/fpu_helper.c +2
-3/* The XCOMP field must be zero. */ - xcomp_bv0 =cpu_ldq_data_ra (env, ptr +520 , ra); - xcomp_bv1 =cpu_ldq_data_ra (env, ptr +528 , ra); -if (xcomp_bv0 || xcomp_bv1) { + xcomp_bv =cpu_ldq_data_ra (env, ptr +XO (header.xcomp_bv), ra); +if (xcomp_bv) {raise_exception_ra (env,EXCP0D_GPF , ra);You are changing the code to not check bytes 528-535 (bytes 16:23 of the XSAVE header) anymore, but Intel SDM says XRSTOR raises #GP "If the standard form is executed and bytes 23:8 of the XSAVE header are not all zero."
Hmm. I must have an out-of-date version here, since mine just mentions the first 8 bytes, and I thought the current definition of X86XSaveHeader backed that up.
I can certainly modify the structure...
r~
Quoted 19 lines · Richard Henderson
Quoted 5 lines · Eduardo Habkost
On Sat, Jul 02, 2016 at 09:44:31AM -0700, Richard Henderson wrote:
[...]Quoted 3 lines
(quoted diff) +0
-0@@ -1402,9 +1409,8 @@ void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) }Quoted 12 lines
target-i386/fpu_helper.c void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) · line 1414
Quoted 7 lines
target-i386/fpu_helper.c +2
-3/* The XCOMP field must be zero. */ - xcomp_bv0 =cpu_ldq_data_ra (env, ptr +520 , ra); - xcomp_bv1 =cpu_ldq_data_ra (env, ptr +528 , ra); -if (xcomp_bv0 || xcomp_bv1) { + xcomp_bv =cpu_ldq_data_ra (env, ptr +XO (header.xcomp_bv), ra); +if (xcomp_bv) {raise_exception_ra (env,EXCP0D_GPF , ra);You are changing the code to not check bytes 528-535 (bytes 16:23 of the XSAVE header) anymore, but Intel SDM says XRSTOR raises #GP "If the standard form is executed and bytes 23:8 of the XSAVE header are not all zero."
Quoted 5 lines
Hmm. I must have an out-of-date version here, since mine just mentions the first 8 bytes, and I thought the current definition of X86XSaveHeader backed that up.
I can certainly modify the structure...
I was looking at a September 2015 version (Order Number 325462-056US). It is a bit confusing, because the header layout documentation (Section 13.4.2) just says bytes 63:16 are reserved, but the Instruction Set Reference for XRSTOR has the following:
Protected Mode Exceptions
#GP(0) [...]
If the standard form is executed and bytes 23:8 of the XSAVE header are not all zero.
Signature · 1 line
Eduardo