Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LWYOy-0005Mc-OJ for qemu-devel@nongnu.org; Mon, 09 Feb 2009 10:50:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LWYOy-0005MI-1n for qemu-devel@nongnu.org; Mon, 09 Feb 2009 10:50:28 -0500 Received: from [199.232.76.173] (port=56396 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LWYOx-0005MB-SI for qemu-devel@nongnu.org; Mon, 09 Feb 2009 10:50:27 -0500 Received: from savannah.gnu.org ([199.232.41.3]:58964 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LWYOx-00054f-Ey for qemu-devel@nongnu.org; Mon, 09 Feb 2009 10:50:27 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LWYOw-00077O-QT for qemu-devel@nongnu.org; Mon, 09 Feb 2009 15:50:26 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LWYOt-00077G-G1 for qemu-devel@nongnu.org; Mon, 09 Feb 2009 15:50:25 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Mon, 09 Feb 2009 15:50:23 +0000 Subject: [Qemu-devel] [6565] KVM: CPUID takes ecx as input value for some functions (Amit Shah) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6565 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6565 Author: aliguori Date: 2009-02-09 15:50:08 +0000 (Mon, 09 Feb 2009) Log Message: ----------- KVM: CPUID takes ecx as input value for some functions (Amit Shah) The CPUID instruction takes the value of ECX as an input parameter in addition to the value of EAX as the count for functions 4, 0xb and 0xd. Make sure we pass the value to the instruction. Also convert to the qemu-style whitespace for the surrounding code. Signed-off-by: Amit Shah Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/target-i386/cpu.h trunk/target-i386/helper.c trunk/target-i386/kvm.c trunk/target-i386/op_helper.c Modified: trunk/target-i386/cpu.h =================================================================== --- trunk/target-i386/cpu.h 2009-02-08 17:17:52 UTC (rev 6564) +++ trunk/target-i386/cpu.h 2009-02-09 15:50:08 UTC (rev 6565) @@ -772,7 +772,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr, int is_write, int mmu_idx, int is_softmmu); void cpu_x86_set_a20(CPUX86State *env, int a20_state); -void cpu_x86_cpuid(CPUX86State *env, uint32_t index, +void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); Modified: trunk/target-i386/helper.c =================================================================== --- trunk/target-i386/helper.c 2009-02-08 17:17:52 UTC (rev 6564) +++ trunk/target-i386/helper.c 2009-02-09 15:50:08 UTC (rev 6565) @@ -1403,7 +1403,8 @@ } #endif /* !CONFIG_USER_ONLY */ -static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx, +static void host_cpuid(uint32_t function, uint32_t count, + uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { #if defined(CONFIG_KVM) @@ -1411,19 +1412,19 @@ #ifdef __x86_64__ asm volatile("cpuid" - : "=a"(vec[0]), "=b"(vec[1]), - "=c"(vec[2]), "=d"(vec[3]) - : "0"(function) : "cc"); + : "=a"(vec[0]), "=b"(vec[1]), + "=c"(vec[2]), "=d"(vec[3]) + : "0"(function), "c"(count) : "cc"); #else asm volatile("pusha \n\t" - "cpuid \n\t" - "mov %%eax, 0(%1) \n\t" - "mov %%ebx, 4(%1) \n\t" - "mov %%ecx, 8(%1) \n\t" - "mov %%edx, 12(%1) \n\t" - "popa" - : : "a"(function), "S"(vec) - : "memory", "cc"); + "cpuid \n\t" + "mov %%eax, 0(%1) \n\t" + "mov %%ebx, 4(%1) \n\t" + "mov %%ecx, 8(%1) \n\t" + "mov %%edx, 12(%1) \n\t" + "popa" + : : "a"(function), "c"(count), "S"(vec) + : "memory", "cc"); #endif if (eax) @@ -1437,7 +1438,7 @@ #endif } -void cpu_x86_cpuid(CPUX86State *env, uint32_t index, +void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { @@ -1462,7 +1463,7 @@ * actuall cpu, and say goodbye to migration between different vendors * is you use compatibility mode. */ if (kvm_enabled()) - host_cpuid(0, NULL, ebx, ecx, edx); + host_cpuid(0, 0, NULL, ebx, ecx, edx); break; case 1: *eax = env->cpuid_version; @@ -1483,7 +1484,7 @@ break; case 4: /* cache info: needed for Core compatibility */ - switch (*ecx) { + switch (count) { case 0: /* L1 dcache info */ *eax = 0x0000121; *ebx = 0x1c0003f; @@ -1509,7 +1510,6 @@ *edx = 0; break; } - break; case 5: /* mwait info: needed for Core compatibility */ @@ -1554,7 +1554,7 @@ if (kvm_enabled()) { uint32_t h_eax, h_edx; - host_cpuid(0x80000001, &h_eax, NULL, NULL, &h_edx); + host_cpuid(index, 0, &h_eax, NULL, NULL, &h_edx); /* disable CPU features that the host does not support */ Modified: trunk/target-i386/kvm.c =================================================================== --- trunk/target-i386/kvm.c 2009-02-08 17:17:52 UTC (rev 6564) +++ trunk/target-i386/kvm.c 2009-02-09 15:50:08 UTC (rev 6565) @@ -44,13 +44,13 @@ cpuid_i = 0; - cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx); + cpu_x86_cpuid(env, 0, 0, &eax, &ebx, &ecx, &edx); limit = eax; for (i = 0; i <= limit; i++) { struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; - cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); + cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function = i; c->eax = eax; c->ebx = ebx; @@ -58,13 +58,13 @@ c->edx = edx; } - cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx); + cpu_x86_cpuid(env, 0x80000000, 0, &eax, &ebx, &ecx, &edx); limit = eax; for (i = 0x80000000; i <= limit; i++) { struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; - cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); + cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function = i; c->eax = eax; c->ebx = ebx; Modified: trunk/target-i386/op_helper.c =================================================================== --- trunk/target-i386/op_helper.c 2009-02-08 17:17:52 UTC (rev 6564) +++ trunk/target-i386/op_helper.c 2009-02-09 15:50:08 UTC (rev 6565) @@ -1913,7 +1913,7 @@ helper_svm_check_intercept_param(SVM_EXIT_CPUID, 0); - cpu_x86_cpuid(env, (uint32_t)EAX, &eax, &ebx, &ecx, &edx); + cpu_x86_cpuid(env, (uint32_t)EAX, (uint32_t)ECX, &eax, &ebx, &ecx, &edx); EAX = eax; EBX = ebx; ECX = ecx;