[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH v2 6/8] ppc: simplify cpu model lookup by PVR
From: |
Igor Mammedov |
Subject: |
[Qemu-ppc] [PATCH v2 6/8] ppc: simplify cpu model lookup by PVR |
Date: |
Wed, 30 Aug 2017 15:24:33 +0200 |
Signed-off-by: Igor Mammedov <address@hidden>
---
v2:
- if going PVR lookup routem check that cpu_model string consumed
completely, as PVR number shouldn't have any stray symbol in it.
---
target/ppc/translate_init.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index cf0d795..a803a7f 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
@@ -10203,22 +10204,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));
}
}
--
2.7.4
- [Qemu-ppc] [PATCH v2 0/8] ppc: cpu_model handling cleanups, Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 6/8] ppc: simplify cpu model lookup by PVR,
Igor Mammedov <=
- [Qemu-ppc] [PATCH v2 4/8] ppc: make cpu alias point only to real cpu models, Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 5/8] ppc: replace inter-function cyclic dependency/recurssion with 2 simple lookups, Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 2/8] ppc: use macros to make cpu type name from string literal, Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 1/8] ppc: replace cpu_ppc_init() with cpu_generic_init(), Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 7/8] ppc: drop caching ObjectClass from PowerPCCPUAlias, Igor Mammedov, 2017/08/30
- [Qemu-ppc] [PATCH v2 8/8] ppc: remove non implemented cpu models, Igor Mammedov, 2017/08/30