Patchwork [09/20] target-i386: add x86cpu_vendor_words2str()

login
register
mail settings
Submitter Igor Mammedov
Date Dec. 28, 2012, 8:01 p.m.
Message ID <1356724895-24118-10-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/208576/
State New
Headers show

Comments

Igor Mammedov - Dec. 28, 2012, 8:01 p.m.
Make for() cycle reusable for the next patch

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d93bf5a..935bc42 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -847,6 +847,18 @@  static x86_def_t builtin_x86_defs[] = {
     },
 };
 
+static void x86cpu_vendor_words2str(char *dst, uint32_t ebx, uint32_t ecx,
+                                    uint32_t edx)
+{
+    int i;
+    for (i = 0; i < 4; i++) {
+        dst[i] = ebx >> (8 * i);
+        dst[i + 4] = edx >> (8 * i);
+        dst[i + 8] = ecx >> (8 * i);
+    }
+    dst[CPUID_VENDOR_SZ] = '\0';
+}
+
 #ifdef CONFIG_KVM
 static int cpu_x86_fill_model_id(char *str)
 {
@@ -1130,15 +1142,10 @@  static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
     X86CPU *cpu = X86_CPU(obj);
     CPUX86State *env = &cpu->env;
     char *value;
-    int i;
 
     value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
-    for (i = 0; i < 4; i++) {
-        value[i    ] = env->cpuid_vendor1 >> (8 * i);
-        value[i + 4] = env->cpuid_vendor2 >> (8 * i);
-        value[i + 8] = env->cpuid_vendor3 >> (8 * i);
-    }
-    value[CPUID_VENDOR_SZ] = '\0';
+    x86cpu_vendor_words2str(value, env->cpuid_vendor1, env->cpuid_vendor2,
+                            env->cpuid_vendor3);
     return value;
 }