qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] Support for cpudef files placed in the share/ d


From: Amit Shah
Subject: [Qemu-devel] [PATCH 4/4] Support for cpudef files placed in the share/ directory
Date: Wed, 11 Feb 2009 18:45:14 +0530

This patch adds support to use cpudefs placed in the
$(PREFIX)/share/qemu/cpudefs directory.

The various cpu definitions in the code can now be placed there, making
things simpler.

Signed-off-by: Amit Shah <address@hidden>
---
 qemu/target-i386/helper.c |  172 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 129 insertions(+), 43 deletions(-)

diff --git a/qemu/target-i386/helper.c b/qemu/target-i386/helper.c
index 7152dc4..ececb32 100644
--- a/qemu/target-i386/helper.c
+++ b/qemu/target-i386/helper.c
@@ -28,6 +28,7 @@
 #include "cpu.h"
 #include "exec-all.h"
 #include "qemu-common.h"
+#include "sysemu.h"
 #include "kvm.h"
 
 //#define DEBUG_MMU
@@ -164,27 +165,6 @@ static x86_def_t x86_defs[] = {
         .xlevel = 0x8000001A,
         .model_id = "AMD Phenom(tm) 9550 Quad-Core Processor"
     },
-    {
-        .name = "core2duo",
-        .level = 10,
-        .family = 6,
-        .model = 15,
-        .stepping = 11,
-       /* The original CPU also implements these features:
-               CPUID_VME, CPUID_DTS, CPUID_ACPI, CPUID_SS, CPUID_HT,
-               CPUID_TM, CPUID_PBE */
-        .features = PPRO_FEATURES |
-            CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
-            CPUID_PSE36,
-       /* The original CPU also implements these ext features:
-               CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_EST,
-               CPUID_EXT_TM2, CPUID_EXT_CX16, CPUID_EXT_XTPR, CPUID_EXT_PDCM */
-        .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3,
-        .ext2_features = CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
-        /* Missing: .ext3_features = CPUID_EXT3_LAHF_LM */
-        .xlevel = 0x80000008,
-        .model_id = "Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz",
-    },
 #endif
     {
         .name = "qemu32",
@@ -198,25 +178,6 @@ static x86_def_t x86_defs[] = {
         .model_id = "QEMU Virtual CPU version " QEMU_VERSION,
     },
     {
-        .name = "coreduo",
-        .level = 10,
-        .family = 6,
-        .model = 14,
-        .stepping = 8,
-        /* The original CPU also implements these features:
-               CPUID_DTS, CPUID_ACPI, CPUID_SS, CPUID_HT,
-               CPUID_TM, CPUID_PBE */
-        .features = PPRO_FEATURES | CPUID_VME |
-            CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA,
-        /* The original CPU also implements these ext features:
-               CPUID_EXT_VMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_XTPR,
-               CPUID_EXT_PDCM */
-        .ext_features = CPUID_EXT_SSE3 | CPUID_EXT_MONITOR,
-        .ext2_features = CPUID_EXT2_NX,
-        .xlevel = 0x80000008,
-        .model_id = "Genuine Intel(R) CPU           T2600  @ 2.16GHz",
-    },
-    {
         .name = "486",
         .level = 0,
         .family = 4,
@@ -290,6 +251,127 @@ static x86_def_t x86_defs[] = {
     },
 };
 
+static long get_cpudef_value(char *line, int base)
+{
+    char *string;
+
+    string = strchr(line, ' ');
+    if (!string)
+        return -1;
+    return strtol(string, NULL, base);
+}
+
+static int get_cpudef_from_file(x86_def_t *x86_cpu_def, const char *cpu_model)
+{
+    char cpudef_path[1024], line[1024];
+    FILE *fp;
+
+    snprintf(cpudef_path, sizeof(cpudef_path), "%s/cpudefs/%s",
+             get_datafile_dir(), cpu_model);
+
+    fp = fopen(cpudef_path, "r");
+    if (!fp)
+        return -1;
+
+    x86_cpu_def->features = x86_cpu_def->ext_features = 0;
+    x86_cpu_def->ext2_features = x86_cpu_def->ext3_features = 0;
+
+    for(;;) {
+        if (fgets(line, 1024, fp) == NULL)
+            break;
+        if (line[0] == '#')
+            continue;
+        if (!strncmp(line, "level ", 6)) {
+            x86_cpu_def->level = get_cpudef_value(line, 10);
+            continue;
+        }
+        if (!strncmp(line, "family ", 7)) {
+            x86_cpu_def->family = get_cpudef_value(line, 10);
+            continue;
+        }
+        if (!strncmp(line, "model ", 6)) {
+            x86_cpu_def->model = get_cpudef_value(line, 10);
+            continue;
+        }
+        if (!strncmp(line, "stepping ", 9)) {
+            x86_cpu_def->stepping = get_cpudef_value(line, 10);
+            continue;
+        }
+        if (!strncmp(line, "xlevel ", 7)) {
+            x86_cpu_def->xlevel = get_cpudef_value(line, 16);
+            continue;
+        }
+        if (!strncmp(line, "model_id ", 9)) {
+            char *substr = strchr(line, ' ');
+            int i = 0;
+
+            while (*substr) {
+                if (*substr == '\n')
+                    break;
+
+                /* Skip to first quote mark */
+                if (*substr != '\"') {
+                    substr++;
+                    continue;
+                }
+                substr++;
+                while (i < 48 && *substr && *substr != '\"'
+                       && *substr != '\n')
+                    x86_cpu_def->model_id[i++] = *substr++;
+
+                break;
+            }
+            continue;
+        }
+        if (!strncmp(line, "features ", 9)) {
+            char *substr = strchr(line, ' ');
+            char feat[20];
+
+            while (*substr) {
+                int i;
+
+                if (*substr == '\n')
+                    break;
+                /* Skip to next feature string */
+                else if (!isalnum(*substr)) {
+                    substr++;
+                    continue;
+                }
+
+                i = 0;
+                /*
+                 * Features only have alphanumeric values (and
+                 * underscores, in some cases).  Only allow these
+                 * values.
+                 */
+                while (*substr && (isalnum(*substr) || *substr == '_'))
+                    feat[i++] = *substr++;
+                feat[i] = 0;
+
+                if (!strncmp(feat, "i486_features", 13))
+                    x86_cpu_def->features |= I486_FEATURES;
+                else if (!strncmp(feat, "pentium_features", 16))
+                    x86_cpu_def->features |= PENTIUM_FEATURES;
+                else if (!strncmp(feat, "pentium2_features", 17))
+                    x86_cpu_def->features |= PENTIUM2_FEATURES;
+                else if (!strncmp(feat, "pentium3_features", 18))
+                    x86_cpu_def->features |= PENTIUM3_FEATURES;
+                else if (!strncmp(feat, "ppro_features", 13)) {
+                    x86_cpu_def->features |= PPRO_FEATURES;
+                    x86_cpu_def->ext_features |=
+                        PPRO_FEATURES & 0x0183F3FF;
+                } else
+                    add_flagname_to_bitmaps(feat, &x86_cpu_def->features,
+                                            &x86_cpu_def->ext_features,
+                                            &x86_cpu_def->ext2_features,
+                                            &x86_cpu_def->ext3_features);
+            }
+        }
+        continue;
+    }
+    return 0;
+}
+
 static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
 {
     unsigned int i;
@@ -308,9 +390,13 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, 
const char *cpu_model)
             break;
         }
     }
-    if (!def)
-        goto error;
-    memcpy(x86_cpu_def, def, sizeof(*def));
+    if (!def) {
+        int r;
+        r = get_cpudef_from_file(x86_cpu_def, cpu_model);
+        if (r < 0)
+            goto error;
+    } else
+        memcpy(x86_cpu_def, def, sizeof(*def));
 
     featurestr = strtok(NULL, ",");
 
-- 
1.6.0.6





reply via email to

[Prev in Thread] Current Thread [Next in Thread]