Received: from eggs.gnu.org ([2001:4830:134:3::10]:40455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVHGl-0000ZT-Ry for qemu-devel@nongnu.org; Mon, 15 Feb 2016 06:24:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVHGj-000328-9y for qemu-devel@nongnu.org; Mon, 15 Feb 2016 06:24:43 -0500 Received: from mail-qg0-x22d.google.com ([2607:f8b0:400d:c04::22d]:35559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVHGj-000323-4u for qemu-devel@nongnu.org; Mon, 15 Feb 2016 06:24:41 -0500 Received: by mail-qg0-x22d.google.com with SMTP id y89so108105873qge.2 for ; Mon, 15 Feb 2016 03:24:41 -0800 (PST) Sender: Richard Henderson From: Richard Henderson Date: Mon, 15 Feb 2016 22:23:27 +1100 Message-Id: <1455535408-26566-16-git-send-email-rth@twiddle.net> In-Reply-To: <1455535408-26566-1-git-send-email-rth@twiddle.net> References: <1455535408-26566-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PULL 15/16] target-i386: Enable CR4/XCR0 features for user-mode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com Signed-off-by: Richard Henderson --- target-i386/cpu.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 4682166..063c8fb 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2643,6 +2643,8 @@ static void x86_cpu_reset(CPUState *s) X86CPU *cpu = X86_CPU(s); X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu); CPUX86State *env = &cpu->env; + target_ulong cr4; + uint64_t xcr0; int i; xcc->parent_reset(s); @@ -2702,7 +2704,8 @@ static void x86_cpu_reset(CPUState *s) cpu_set_fpuc(env, 0x37f); env->mxcsr = 0x1f80; - env->xstate_bv = XSTATE_FP | XSTATE_SSE; + /* All units are in INIT state. */ + env->xstate_bv = 0; env->pat = 0x0007040600070406ULL; env->msr_ia32_misc_enable = MSR_IA32_MISC_ENABLE_DEFAULT; @@ -2713,7 +2716,24 @@ static void x86_cpu_reset(CPUState *s) cpu_breakpoint_remove_all(s, BP_CPU); cpu_watchpoint_remove_all(s, BP_CPU); - env->xcr0 = 1; + cr4 = 0; + xcr0 = XSTATE_FP; + +#ifdef CONFIG_USER_ONLY + /* Enable all the features for user-mode. */ + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + xcr0 |= XSTATE_SSE; + } + if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_MPX) { + xcr0 |= XSTATE_BNDREGS | XSTATE_BNDCSR; + } + if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { + cr4 |= CR4_OSFXSR_MASK | CR4_OSXSAVE_MASK; + } +#endif + + env->xcr0 = xcr0; + cpu_x86_update_cr4(env, cr4); /* * SDM 11.11.5 requires: -- 2.5.0