aboutsummaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2017-08-30 15:24:33 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2017-09-08 09:30:55 +1000
commitb376db777563ec6f9fd57255506418b500151a3d (patch)
tree24232dbcc882e24794deb7c2aa633b82425dfa78 /target
parent03c9141d75eac39b7897c4a670eb71103da9986f (diff)
downloadqemu-b376db777563ec6f9fd57255506418b500151a3d.zip
qemu-b376db777563ec6f9fd57255506418b500151a3d.tar.gz
qemu-b376db777563ec6f9fd57255506418b500151a3d.tar.bz2
ppc: simplify cpu model lookup by PVR
Signed-off-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'target')
-rw-r--r--target/ppc/translate_init.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index 4092310..7c1d83b 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -34,6 +34,7 @@
#include "hw/ppc/ppc.h"
#include "mmu-book3s-v3.h"
#include "sysemu/qtest.h"
+#include "qemu/cutils.h"
//#define PPC_DUMP_CPU
//#define PPC_DEBUG_SPR
@@ -10279,22 +10280,16 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
char *cpu_model, *typename;
ObjectClass *oc;
const char *p;
- int i, len;
-
- /* Check if the given name is a PVR */
- len = strlen(name);
- if (len == 10 && name[0] == '0' && name[1] == 'x') {
- p = name + 2;
- goto check_pvr;
- } else if (len == 8) {
- p = name;
- check_pvr:
- for (i = 0; i < 8; i++) {
- if (!qemu_isxdigit(*p++))
- break;
- }
- if (i == 8) {
- return OBJECT_CLASS(ppc_cpu_class_by_pvr(strtoul(name, NULL, 16)));
+ unsigned long pvr;
+
+ /* Lookup by PVR if cpu_model is valid 8 digit hex number
+ * (excl: 0x prefix if present)
+ */
+ if (!qemu_strtoul(name, &p, 16, &pvr)) {
+ int len = p - name;
+ len = (len == 10) && (name[1] == 'x') ? len - 2 : len;
+ if ((len == 8) && (*p == '\0')) {
+ return OBJECT_CLASS(ppc_cpu_class_by_pvr(pvr));
}
}