All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Kenigsberg <danken@qumranet.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Allow setting the vendor and model_id strings with x86's -cpu option
Date: Thu, 20 Dec 2007 18:40:33 +0200	[thread overview]
Message-ID: <20071220164033.GA17722@karma.qumranet.com> (raw)
In-Reply-To: <20071125132334.GA9555@karma.qumranet.com>

Having AuthenticAMD hard-coded is nice, but allowing the user to impersonate
whatever CPU she wants is even nicer.

Hopefully it would now work on big endian host and with non-ASCII
characters.

Dan.


diff --git a/target-i386/helper2.c b/target-i386/helper2.c
index 6d40c64..b9b3093 100644
--- a/target-i386/helper2.c
+++ b/target-i386/helper2.c
@@ -120,6 +120,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
 typedef struct x86_def_t {
     const char *name;
     uint32_t vendor1, vendor2, vendor3;
+    char model_id[48];
     int family;
     int model;
     int stepping;
@@ -255,7 +256,21 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
                     goto error;
                 }
                 x86_cpu_def->stepping = stepping;
-            } else {
+            } else if (!strcmp(featurestr, "vendor")) {
+                if (strlen(val) != 12) {
+                    fprintf(stderr, "vendor string must be 12 chars long\n");
+                    x86_cpu_def = 0;
+                    goto error;
+                }
+                x86_cpu_def->vendor1 = x86_cpu_def->vendor2 = x86_cpu_def->vendor3 = 0;
+                for(i = 0; i < 4; i++) {
+                    x86_cpu_def->vendor1 |= ((unsigned char)val[i    ]) << (8 * i);
+                    x86_cpu_def->vendor2 |= ((unsigned char)val[i + 4]) << (8 * i);
+                    x86_cpu_def->vendor3 |= ((unsigned char)val[i + 8]) << (8 * i);
+                }
+            } else if (!strcmp(featurestr, "model_id"))
+                strncpy(x86_cpu_def->model_id, val, 48);
+            else {
                 fprintf(stderr, "unrecognized feature %s\n", featurestr);
                 x86_cpu_def = 0;
                 goto error;
@@ -316,13 +331,14 @@ static int cpu_x86_register (CPUX86State *env, const char *cpu_model)
     env->cpuid_ext3_features = def->ext3_features;
     {
         const char *model_id = "QEMU Virtual CPU version " QEMU_VERSION;
-        int c, len, i;
-        len = strlen(model_id);
+        int c = -1, i;
+	
+        if (def->model_id[0] != '\0')
+            model_id = def->model_id;
+
         for(i = 0; i < 48; i++) {
-            if (i >= len)
-                c = '\0';
-            else
-                c = model_id[i];
+            if (c != '\0')
+                c = (unsigned char)model_id[i];
             env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
         }
     }

      parent reply	other threads:[~2007-12-21 10:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-25 13:23 [Qemu-devel] [PATCH] Allow setting the vendor_id string with x86's -cpu option Dan Kenigsberg
2007-12-09  3:02 ` Thiemo Seufer
2007-12-09  9:27   ` Dan Kenigsberg
2007-12-09 11:36     ` Paul Brook
2007-12-09 13:52       ` Dan Kenigsberg
2007-12-09 18:29         ` Andreas Schwab
2007-12-09 18:58           ` Dan Kenigsberg
2007-12-09 20:00             ` Dan Kenigsberg
2007-12-20 16:40 ` Dan Kenigsberg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071220164033.GA17722@karma.qumranet.com \
    --to=danken@qumranet.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.