Skip to contentSkip to conversation

target-sh4: SuperHCPU subclasses

RFC In review Andreas Färber 1 participant 4 messages Jan 21, 2013

lore
Share & tools
lore
#0 lore raw

v2 cover target-sh4: SuperHCPU subclasses

Hello,

This series introduces SuperH CPU subclasses.
The first conversion to QOM patch had used a declarative approach reusing sh4_def_t as SuperHCPUInfo. This approach now uses imperative instance_init functions. To preserve -cpu ? output and case-insensitivity, distinct name and type name are used, but allowing use of the type name as done for alpha.

TODO: guard against abstract types (may apply to other targets as well)
TODO: move class -> name lookup to cpu.c?

This series in context:
+ qom-cpu cleanups and bugfixes being queued for 1.4
+ CPUState QOM realizefn and initfn RFC for 1.5 / qom-cpu-next ~ SuperHCPU subclasses (this series)
- SH7750 QOM'ification (to be rebased)
- cross-target refactoring of cpu_init() and "realized" behavior (TBD)

Available for testing at:
git://github.com/afaerber/qemu-cpu.git qom-cpu-sh4-classes.v2
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-sh4-classes.v2

Regards,
Andreas

v2:
* Fixed bug in class name comparison, spotted by Igor.
* Refactored name -> ObjectClass mapping into new function.
* Moved realizefn patch into CPUState series, rebased.

v1 -> preview on GitHub:
* Redone, using combination of initfn and class_init instead of SuperHCPUInfo.
* Adopted naming scheme suggested by Eduardo.
* Split out SuperHCPUClass field movements into separate patch.

Cc Aurélien Jarno <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Eduardo Habkost <[email protected]>

Andreas Färber (2):
target-sh4: Introduce SuperHCPU subclasses
target-sh4: Move PVR/PRR/CVR into SuperHCPUClass

 hw/sh7750.c            |   10 ++--
 target-sh4/cpu-qom.h   |   13 +++++
 target-sh4/cpu.c       |  124 +++++++++++++++++++++++++++++++++++++++++++++++-
 target-sh4/cpu.h       |    3 --
 target-sh4/translate.c |   94 +++++++++++++-----------------------

5 Dateien geändert, 175 Zeilen hinzugefügt(+), 69 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#1 lore raw

RFC v2 1/2 target-sh4: Introduce SuperHCPU subclasses

Store legacy name in SuperHCPUClass for -cpu ? and for case-insensitive class lookup.

List CPUs by iterating over TYPE_SUPERH_CPU subclasses.

---
 target-sh4/cpu-qom.h   |    7 +++
 target-sh4/cpu.c       |  124 +++++++++++++++++++++++++++++++++++++++++++++++-
 target-sh4/translate.c |   94 +++++++++++++-----------------------

3 Dateien geändert, 162 Zeilen hinzugefügt(+), 63 Zeilen entfernt(-)

target-sh4/cpu-qom.h +7 -0
index d368db1..8326ceb 100644
@@ -24,6 +24,10 @@
 
 #define TYPE_SUPERH_CPU "superh-cpu"
 
+#define TYPE_SH7750R_CPU "sh7750r-" TYPE_SUPERH_CPU
+#define TYPE_SH7751R_CPU "sh7751r-" TYPE_SUPERH_CPU
+#define TYPE_SH7785_CPU "sh7785-" TYPE_SUPERH_CPU
+
 #define SUPERH_CPU_CLASS(klass) \
     OBJECT_CLASS_CHECK(SuperHCPUClass, (klass), TYPE_SUPERH_CPU)
 #define SUPERH_CPU(obj) \
@@ -35,6 +39,7 @@
  * SuperHCPUClass:
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
+ * @name: The name.
  *
  * A SuperH CPU model.
  */
@@ -45,6 +50,8 @@ typedef struct SuperHCPUClass {
 
     DeviceRealize parent_realize;
     void (*parent_reset)(CPUState *cpu);
+
+    const char *name;
 } SuperHCPUClass;
 
 /**
target-sh4/cpu.c +123 -1

142 lines not on this page · raw message

target-sh4/translate.c +32 -62

116 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

RFC v2 2/2 target-sh4: Move PVR/PRR/CVR into SuperHCPUClass

In reply to Andreas Färber

They are never changed once initialized, and moving them to the class will allow to inspect them before instantiating.

---
 hw/sh7750.c          |   10 +++++++---
 target-sh4/cpu-qom.h |    6 ++++++
 target-sh4/cpu.c     |   18 +++++++++---------
 target-sh4/cpu.h     |    3 ---

4 Dateien geändert, 22 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)

hw/sh7750.c +7 -3
index 666f865..2259b59 100644
@@ -255,6 +255,7 @@ static uint32_t sh7750_mem_readw(void *opaque, hwaddr addr)
 static uint32_t sh7750_mem_readl(void *opaque, hwaddr addr)
 {
     SH7750State *s = opaque;
+    SuperHCPUClass *scc;
 
     switch (addr) {
     case SH7750_BCR1_A7:
@@ -288,11 +289,14 @@ static uint32_t sh7750_mem_readl(void *opaque, hwaddr addr)
     case SH7750_CCR_A7:
 	return s->ccr;
     case 0x1f000030:		/* Processor version */
-	return s->cpu->pvr;
+        scc = SUPERH_CPU_GET_CLASS(s->cpu);
+        return scc->pvr;
     case 0x1f000040:		/* Cache version */
-	return s->cpu->cvr;
+        scc = SUPERH_CPU_GET_CLASS(s->cpu);
+        return scc->cvr;
     case 0x1f000044:		/* Processor revision */
-	return s->cpu->prr;
+        scc = SUPERH_CPU_GET_CLASS(s->cpu);
+        return scc->prr;
     default:
 	error_access("long read", addr);
         abort();
target-sh4/cpu-qom.h +6 -0
index 8326ceb..b264be7 100644
@@ -40,6 +40,9 @@
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
  * @name: The name.
+ * @pvr: Processor Version Register
+ * @prr: Processor Revision Register
+ * @cvr: Cache Version Register
  *
  * A SuperH CPU model.
  */
@@ -52,6 +55,9 @@ typedef struct SuperHCPUClass {
     void (*parent_reset)(CPUState *cpu);
 
     const char *name;
+    uint32_t pvr;
+    uint32_t prr;
+    uint32_t cvr;
 } SuperHCPUClass;
 
 /**
target-sh4/cpu.c +9 -9
index 80804ef..d4ba957 100644
@@ -100,9 +100,6 @@ static void sh7750r_cpu_initfn(Object *obj)
     CPUSH4State *env = &cpu->env;
 
     env->id = SH_CPU_SH7750R;
-    env->pvr = 0x00050000;
-    env->prr = 0x00000100;
-    env->cvr = 0x00110000;
     env->features = SH_FEATURE_BCR3_AND_BCR4;
 }
 
@@ -111,6 +108,9 @@ static void sh7750r_class_init(ObjectClass *oc, void *data)
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
     scc->name = "SH7750R";
+    scc->pvr = 0x00050000;
+    scc->prr = 0x00000100;
+    scc->cvr = 0x00110000;
 }
 
 static const TypeInfo sh7750r_type_info = {
@@ -126,9 +126,6 @@ static void sh7751r_cpu_initfn(Object *obj)
     CPUSH4State *env = &cpu->env;
 
     env->id = SH_CPU_SH7751R;
-    env->pvr = 0x04050005;
-    env->prr = 0x00000113;
-    env->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
     env->features = SH_FEATURE_BCR3_AND_BCR4;
 }
 
@@ -137,6 +134,9 @@ static void sh7751r_class_init(ObjectClass *oc, void *data)
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
     scc->name = "SH7751R";
+    scc->pvr = 0x04050005;
+    scc->prr = 0x00000113;
+    scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
 }
 
 static const TypeInfo sh7751r_type_info = {
@@ -152,9 +152,6 @@ static void sh7785_cpu_initfn(Object *obj)
     CPUSH4State *env = &cpu->env;
 
     env->id = SH_CPU_SH7785;
-    env->pvr = 0x10300700;
-    env->prr = 0x00000200;
-    env->cvr = 0x71440211;
     env->features = SH_FEATURE_SH4A;
 }
 
@@ -163,6 +160,9 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
     SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
 
     scc->name = "SH7785";
+    scc->pvr = 0x10300700;
+    scc->prr = 0x00000200;
+    scc->cvr = 0x71440211;
 }
 
 static const TypeInfo sh7785_type_info = {
target-sh4/cpu.h +0 -3
index 49dcd9e..f805778 100644
@@ -179,9 +179,6 @@ typedef struct CPUSH4State {
     CPU_COMMON
 
     int id;			/* CPU model */
-    uint32_t pvr;		/* Processor Version Register */
-    uint32_t prr;		/* Processor Revision Register */
-    uint32_t cvr;		/* Cache Version Register */
 
     void *intc_handle;
     int in_sleep;		/* SR_BL ignored during sleep */
Signature · 1 line
1.7.10.4
#3 lore raw
In reply to Andreas Färber

Am 21.01.2013 04:28, schrieb Andreas Färber:

Quoted 18 lines

Hello,

This series introduces SuperH CPU subclasses.
The first conversion to QOM patch had used a declarative approach reusing sh4_def_t as SuperHCPUInfo. This approach now uses imperative instance_init functions. To preserve -cpu ? output and case-insensitivity, distinct name and type name are used, but allowing use of the type name as done for alpha.

TODO: guard against abstract types (may apply to other targets as well)
TODO: move class -> name lookup to cpu.c?

This series in context:
+ qom-cpu cleanups and bugfixes being queued for 1.4
+ CPUState QOM realizefn and initfn RFC for 1.5 / qom-cpu-next ~ SuperHCPU subclasses (this series)
- SH7750 QOM'ification (to be rebased)
- cross-target refactoring of cpu_init() and "realized" behavior (TBD)

Quoted 3 lines

Available for testing at:
git://github.com/afaerber/qemu-cpu.git qom-cpu-sh4-classes.v2
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-sh4-classes.v2

Note that the default sh4 machine shix does not check the return value of cpu_init() and silently continues even without CPU. I've used -M r2d for testing and will try to post a fix for 1.4.

Andreas

Quoted 25 lines

v2:
* Fixed bug in class name comparison, spotted by Igor.
* Refactored name -> ObjectClass mapping into new function.
* Moved realizefn patch into CPUState series, rebased.

v1 -> preview on GitHub:
* Redone, using combination of initfn and class_init instead of SuperHCPUInfo.
* Adopted naming scheme suggested by Eduardo.
* Split out SuperHCPUClass field movements into separate patch.

Cc Aurélien Jarno <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Eduardo Habkost <[email protected]>

Andreas Färber (2):
target-sh4: Introduce SuperHCPU subclasses
target-sh4: Move PVR/PRR/CVR into SuperHCPUClass

 hw/sh7750.c            |   10 ++--
 target-sh4/cpu-qom.h   |   13 +++++
 target-sh4/cpu.c       |  124 +++++++++++++++++++++++++++++++++++++++++++++++-
 target-sh4/cpu.h       |    3 --
 target-sh4/translate.c |   94 +++++++++++++-----------------------

5 Dateien geändert, 175 Zeilen hinzugefügt(+), 69 Zeilen entfernt(-)

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg