Commit e00b6f80998a9974faf389b67adcc97db87f2bb3

Authored by aliguori
1 parent 4f396364

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 <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6565 c046a42c-6fe2-441c-8c8c-71466251a162
target-i386/cpu.h
@@ -772,7 +772,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo, @@ -772,7 +772,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
772 int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr, 772 int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
773 int is_write, int mmu_idx, int is_softmmu); 773 int is_write, int mmu_idx, int is_softmmu);
774 void cpu_x86_set_a20(CPUX86State *env, int a20_state); 774 void cpu_x86_set_a20(CPUX86State *env, int a20_state);
775 -void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 775 +void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
776 uint32_t *eax, uint32_t *ebx, 776 uint32_t *eax, uint32_t *ebx,
777 uint32_t *ecx, uint32_t *edx); 777 uint32_t *ecx, uint32_t *edx);
778 778
target-i386/helper.c
@@ -1403,7 +1403,8 @@ static void breakpoint_handler(CPUState *env) @@ -1403,7 +1403,8 @@ static void breakpoint_handler(CPUState *env)
1403 } 1403 }
1404 #endif /* !CONFIG_USER_ONLY */ 1404 #endif /* !CONFIG_USER_ONLY */
1405 1405
1406 -static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx, 1406 +static void host_cpuid(uint32_t function, uint32_t count,
  1407 + uint32_t *eax, uint32_t *ebx,
1407 uint32_t *ecx, uint32_t *edx) 1408 uint32_t *ecx, uint32_t *edx)
1408 { 1409 {
1409 #if defined(CONFIG_KVM) 1410 #if defined(CONFIG_KVM)
@@ -1411,19 +1412,19 @@ static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx, @@ -1411,19 +1412,19 @@ static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx,
1411 1412
1412 #ifdef __x86_64__ 1413 #ifdef __x86_64__
1413 asm volatile("cpuid" 1414 asm volatile("cpuid"
1414 - : "=a"(vec[0]), "=b"(vec[1]),  
1415 - "=c"(vec[2]), "=d"(vec[3])  
1416 - : "0"(function) : "cc"); 1415 + : "=a"(vec[0]), "=b"(vec[1]),
  1416 + "=c"(vec[2]), "=d"(vec[3])
  1417 + : "0"(function), "c"(count) : "cc");
1417 #else 1418 #else
1418 asm volatile("pusha \n\t" 1419 asm volatile("pusha \n\t"
1419 - "cpuid \n\t"  
1420 - "mov %%eax, 0(%1) \n\t"  
1421 - "mov %%ebx, 4(%1) \n\t"  
1422 - "mov %%ecx, 8(%1) \n\t"  
1423 - "mov %%edx, 12(%1) \n\t"  
1424 - "popa"  
1425 - : : "a"(function), "S"(vec)  
1426 - : "memory", "cc"); 1420 + "cpuid \n\t"
  1421 + "mov %%eax, 0(%1) \n\t"
  1422 + "mov %%ebx, 4(%1) \n\t"
  1423 + "mov %%ecx, 8(%1) \n\t"
  1424 + "mov %%edx, 12(%1) \n\t"
  1425 + "popa"
  1426 + : : "a"(function), "c"(count), "S"(vec)
  1427 + : "memory", "cc");
1427 #endif 1428 #endif
1428 1429
1429 if (eax) 1430 if (eax)
@@ -1437,7 +1438,7 @@ static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx, @@ -1437,7 +1438,7 @@ static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx,
1437 #endif 1438 #endif
1438 } 1439 }
1439 1440
1440 -void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 1441 +void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
1441 uint32_t *eax, uint32_t *ebx, 1442 uint32_t *eax, uint32_t *ebx,
1442 uint32_t *ecx, uint32_t *edx) 1443 uint32_t *ecx, uint32_t *edx)
1443 { 1444 {
@@ -1462,7 +1463,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, @@ -1462,7 +1463,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
1462 * actuall cpu, and say goodbye to migration between different vendors 1463 * actuall cpu, and say goodbye to migration between different vendors
1463 * is you use compatibility mode. */ 1464 * is you use compatibility mode. */
1464 if (kvm_enabled()) 1465 if (kvm_enabled())
1465 - host_cpuid(0, NULL, ebx, ecx, edx); 1466 + host_cpuid(0, 0, NULL, ebx, ecx, edx);
1466 break; 1467 break;
1467 case 1: 1468 case 1:
1468 *eax = env->cpuid_version; 1469 *eax = env->cpuid_version;
@@ -1483,7 +1484,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, @@ -1483,7 +1484,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
1483 break; 1484 break;
1484 case 4: 1485 case 4:
1485 /* cache info: needed for Core compatibility */ 1486 /* cache info: needed for Core compatibility */
1486 - switch (*ecx) { 1487 + switch (count) {
1487 case 0: /* L1 dcache info */ 1488 case 0: /* L1 dcache info */
1488 *eax = 0x0000121; 1489 *eax = 0x0000121;
1489 *ebx = 0x1c0003f; 1490 *ebx = 0x1c0003f;
@@ -1509,7 +1510,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, @@ -1509,7 +1510,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
1509 *edx = 0; 1510 *edx = 0;
1510 break; 1511 break;
1511 } 1512 }
1512 -  
1513 break; 1513 break;
1514 case 5: 1514 case 5:
1515 /* mwait info: needed for Core compatibility */ 1515 /* mwait info: needed for Core compatibility */
@@ -1554,7 +1554,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, @@ -1554,7 +1554,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
1554 if (kvm_enabled()) { 1554 if (kvm_enabled()) {
1555 uint32_t h_eax, h_edx; 1555 uint32_t h_eax, h_edx;
1556 1556
1557 - host_cpuid(0x80000001, &h_eax, NULL, NULL, &h_edx); 1557 + host_cpuid(index, 0, &h_eax, NULL, NULL, &h_edx);
1558 1558
1559 /* disable CPU features that the host does not support */ 1559 /* disable CPU features that the host does not support */
1560 1560
target-i386/kvm.c
@@ -44,13 +44,13 @@ int kvm_arch_init_vcpu(CPUState *env) @@ -44,13 +44,13 @@ int kvm_arch_init_vcpu(CPUState *env)
44 44
45 cpuid_i = 0; 45 cpuid_i = 0;
46 46
47 - cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx); 47 + cpu_x86_cpuid(env, 0, 0, &eax, &ebx, &ecx, &edx);
48 limit = eax; 48 limit = eax;
49 49
50 for (i = 0; i <= limit; i++) { 50 for (i = 0; i <= limit; i++) {
51 struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; 51 struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++];
52 52
53 - cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); 53 + cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx);
54 c->function = i; 54 c->function = i;
55 c->eax = eax; 55 c->eax = eax;
56 c->ebx = ebx; 56 c->ebx = ebx;
@@ -58,13 +58,13 @@ int kvm_arch_init_vcpu(CPUState *env) @@ -58,13 +58,13 @@ int kvm_arch_init_vcpu(CPUState *env)
58 c->edx = edx; 58 c->edx = edx;
59 } 59 }
60 60
61 - cpu_x86_cpuid(env, 0x80000000, &eax, &ebx, &ecx, &edx); 61 + cpu_x86_cpuid(env, 0x80000000, 0, &eax, &ebx, &ecx, &edx);
62 limit = eax; 62 limit = eax;
63 63
64 for (i = 0x80000000; i <= limit; i++) { 64 for (i = 0x80000000; i <= limit; i++) {
65 struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++]; 65 struct kvm_cpuid_entry *c = &cpuid_data.entries[cpuid_i++];
66 66
67 - cpu_x86_cpuid(env, i, &eax, &ebx, &ecx, &edx); 67 + cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx);
68 c->function = i; 68 c->function = i;
69 c->eax = eax; 69 c->eax = eax;
70 c->ebx = ebx; 70 c->ebx = ebx;
target-i386/op_helper.c
@@ -1913,7 +1913,7 @@ void helper_cpuid(void) @@ -1913,7 +1913,7 @@ void helper_cpuid(void)
1913 1913
1914 helper_svm_check_intercept_param(SVM_EXIT_CPUID, 0); 1914 helper_svm_check_intercept_param(SVM_EXIT_CPUID, 0);
1915 1915
1916 - cpu_x86_cpuid(env, (uint32_t)EAX, &eax, &ebx, &ecx, &edx); 1916 + cpu_x86_cpuid(env, (uint32_t)EAX, (uint32_t)ECX, &eax, &ebx, &ecx, &edx);
1917 EAX = eax; 1917 EAX = eax;
1918 EBX = ebx; 1918 EBX = ebx;
1919 ECX = ecx; 1919 ECX = ecx;