diff mbox

KVM: qemu: CPUID takes ecx as input value for some functions

Message ID 1231670495-17916-1-git-send-email-amit.shah@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amit Shah Jan. 11, 2009, 10:41 a.m. UTC
The CPUID instruction takes the value of ECX as an input parameter
in addition to the value of EAX for function 4. Make sure we pass
the value to the instruction.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 qemu/target-i386/helper.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

Comments

Avi Kivity Jan. 11, 2009, 10:46 a.m. UTC | #1
Amit Shah wrote:
> The CPUID instruction takes the value of ECX as an input parameter
> in addition to the value of EAX for function 4. Make sure we pass
> the value to the instruction.
>
>   

This needs to go to upstream qemu.  I'd suggest adding a new parameter 
rather than making ecx an in/out parameter.

I'd expect a loop when we use this...
Amit Shah Jan. 11, 2009, 10:57 a.m. UTC | #2
On Sun, Jan 11, 2009 at 12:46:49PM +0200, Avi Kivity wrote:
> Amit Shah wrote:
>> The CPUID instruction takes the value of ECX as an input parameter
>> in addition to the value of EAX for function 4. Make sure we pass
>> the value to the instruction.
>>
>>   
>
> This needs to go to upstream qemu.  I'd suggest adding a new parameter  
> rather than making ecx an in/out parameter.

You mean something like

host_cpuid(index, subindex, eax, ebx, ecx, edx);

?

>
> I'd expect a loop when we use this...

Why a loop? We'll only return the values true for a particular EAX:ECX
combination. The requestor (kernel) will loop.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Avi Kivity Jan. 11, 2009, 11:23 a.m. UTC | #3
Amit Shah wrote:
> On Sun, Jan 11, 2009 at 12:46:49PM +0200, Avi Kivity wrote:
>   
>> Amit Shah wrote:
>>     
>>> The CPUID instruction takes the value of ECX as an input parameter
>>> in addition to the value of EAX for function 4. Make sure we pass
>>> the value to the instruction.
>>>
>>>   
>>>       
>> This needs to go to upstream qemu.  I'd suggest adding a new parameter  
>> rather than making ecx an in/out parameter.
>>     
>
> You mean something like
>
> host_cpuid(index, subindex, eax, ebx, ecx, edx);
>
> ?
>
>   

Yes.

>> I'd expect a loop when we use this...
>>     
>
> Why a loop? We'll only return the values true for a particular EAX:ECX
> combination. The requestor (kernel) will loop.
>   

The kernel doesn't call host_cpuid().  We preload all possible 
combinations of eax and ecx in advance.
diff mbox

Patch

diff --git a/qemu/target-i386/helper.c b/qemu/target-i386/helper.c
index cda0390..e468366 100644
--- a/qemu/target-i386/helper.c
+++ b/qemu/target-i386/helper.c
@@ -1387,7 +1387,7 @@  static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx,
     asm volatile("cpuid"
 		 : "=a"(vec[0]), "=b"(vec[1]),
 		   "=c"(vec[2]), "=d"(vec[3])
-		 : "0"(function) : "cc");
+		 : "0"(function), "c"(*ecx) : "cc");
 #else
     asm volatile("pusha \n\t"
 		 "cpuid \n\t"
@@ -1396,7 +1396,7 @@  static void host_cpuid(uint32_t function, uint32_t *eax, uint32_t *ebx,
 		 "mov %%ecx, 8(%1) \n\t"
 		 "mov %%edx, 12(%1) \n\t"
 		 "popa"
-		 : : "a"(function), "S"(vec)
+		 : : "a"(function), "c"(*ecx), "S"(vec)
 		 : "memory", "cc");
 #endif
 
@@ -1483,7 +1483,6 @@  void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
                 *edx = 0;
                 break;
         }
-
         break;
     case 5:
         /* mwait info: needed for Core compatibility */
@@ -1526,9 +1525,9 @@  void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
         *edx = env->cpuid_ext2_features;
 
         if (kvm_enabled()) {
-            uint32_t h_eax, h_edx;
+            uint32_t h_eax, h_edx, h_ecx;
 
-            host_cpuid(0x80000001, &h_eax, NULL, NULL, &h_edx);
+            host_cpuid(0x80000001, &h_eax, NULL, &h_ecx, &h_edx);
 
             /* disable CPU features that the host does not support */