diff mbox series

[18/18] target/sparc: Make SPARC_CPU common to new SPARC32_CPU/SPARC64_CPU types

Message ID 20231010092901.99189-19-philmd@linaro.org
State New
Headers show
Series target: Make 'cpu-qom.h' really target agnostic | expand

Commit Message

Philippe Mathieu-Daudé Oct. 10, 2023, 9:29 a.m. UTC
"target/foo/cpu-qom.h" can not use any target specific definitions.

Currently "target/sparc/cpu-qom.h" defines TYPE_SPARC_CPU
depending on the sparc(32)/sparc64 build type. This doesn't
scale in a heterogeneous context where we need to access both
types concurrently.

In order to do that, introduce the new SPARC32_CPU / SPARC64_CPU
types, both inheriting a common TYPE_SPARC_CPU base type.

Keep the current CPU types registered in sparc_register_cpudef_type()
as 32 or 64-bit, depending on the binary built.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/sparc/cpu-qom.h |  9 ++++-----
 target/sparc/cpu.h     |  3 +++
 target/sparc/cpu.c     | 12 +++++++++++-
 3 files changed, 18 insertions(+), 6 deletions(-)

Comments

Mark Cave-Ayland Oct. 13, 2023, 6:28 p.m. UTC | #1
On 10/10/2023 10:29, Philippe Mathieu-Daudé wrote:

> "target/foo/cpu-qom.h" can not use any target specific definitions.
> 
> Currently "target/sparc/cpu-qom.h" defines TYPE_SPARC_CPU
> depending on the sparc(32)/sparc64 build type. This doesn't
> scale in a heterogeneous context where we need to access both
> types concurrently.
> 
> In order to do that, introduce the new SPARC32_CPU / SPARC64_CPU
> types, both inheriting a common TYPE_SPARC_CPU base type.
> 
> Keep the current CPU types registered in sparc_register_cpudef_type()
> as 32 or 64-bit, depending on the binary built.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/sparc/cpu-qom.h |  9 ++++-----
>   target/sparc/cpu.h     |  3 +++
>   target/sparc/cpu.c     | 12 +++++++++++-
>   3 files changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/target/sparc/cpu-qom.h b/target/sparc/cpu-qom.h
> index 86b24a254a..d08fbd4ddc 100644
> --- a/target/sparc/cpu-qom.h
> +++ b/target/sparc/cpu-qom.h
> @@ -23,13 +23,12 @@
>   #include "hw/core/cpu.h"
>   #include "qom/object.h"
>   
> -#ifdef TARGET_SPARC64
> -#define TYPE_SPARC_CPU "sparc64-cpu"
> -#else
>   #define TYPE_SPARC_CPU "sparc-cpu"
> -#endif
> +#define TYPE_SPARC32_CPU "sparc32-cpu"
> +#define TYPE_SPARC64_CPU "sparc64-cpu"
>   
> -OBJECT_DECLARE_CPU_TYPE(SPARCCPU, SPARCCPUClass, SPARC_CPU)
> +OBJECT_DECLARE_CPU_TYPE(SPARC32CPU, SPARCCPUClass, SPARC32_CPU)
> +OBJECT_DECLARE_CPU_TYPE(SPARC64CPU, SPARCCPUClass, SPARC64_CPU)
>   
>   #define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
>   #define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index 924e83b9ce..0f94e5a442 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -12,6 +12,9 @@
>   #define TARGET_DPREGS 32
>   #endif
>   
> +/* Abstract QOM SPARC CPU, not exposed to other targets */
> +OBJECT_DECLARE_CPU_TYPE(SPARCCPU, SPARCCPUClass, SPARC_CPU)
> +
>   /*#define EXCP_INTERRUPT 0x100*/
>   
>   /* Windowed register indexes.  */
> diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
> index 1e66413e94..7d060ba488 100644
> --- a/target/sparc/cpu.c
> +++ b/target/sparc/cpu.c
> @@ -934,6 +934,12 @@ static const TypeInfo sparc_cpu_types[] = {
>           .abstract       = true,
>           .class_size     = sizeof(SPARCCPUClass),
>           .class_init     = sparc_cpu_class_init,
> +    }, {
> +        .name           = TYPE_SPARC32_CPU,
> +        .parent         = TYPE_SPARC_CPU,
> +    }, {
> +        .name           = TYPE_SPARC64_CPU,
> +        .parent         = TYPE_SPARC_CPU,
>       }
>   };
>   
> @@ -950,7 +956,11 @@ static void sparc_register_cpudef_type(const struct sparc_def_t *def)
>       char *typename = sparc_cpu_type_name(def->name);
>       TypeInfo ti = {
>           .name = typename,
> -        .parent = TYPE_SPARC_CPU,
> +#ifdef TARGET_SPARC64
> +        .parent = TYPE_SPARC64_CPU,
> +#else
> +        .parent = TYPE_SPARC32_CPU,
> +#endif
>           .class_init = sparc_cpu_cpudef_class_init,
>           .class_data = (void *)def,
>       };

I do have a long-standing TODO which is to look at better separation between 32-bit 
and 64-bit SPARC, however for now:

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.
diff mbox series

Patch

diff --git a/target/sparc/cpu-qom.h b/target/sparc/cpu-qom.h
index 86b24a254a..d08fbd4ddc 100644
--- a/target/sparc/cpu-qom.h
+++ b/target/sparc/cpu-qom.h
@@ -23,13 +23,12 @@ 
 #include "hw/core/cpu.h"
 #include "qom/object.h"
 
-#ifdef TARGET_SPARC64
-#define TYPE_SPARC_CPU "sparc64-cpu"
-#else
 #define TYPE_SPARC_CPU "sparc-cpu"
-#endif
+#define TYPE_SPARC32_CPU "sparc32-cpu"
+#define TYPE_SPARC64_CPU "sparc64-cpu"
 
-OBJECT_DECLARE_CPU_TYPE(SPARCCPU, SPARCCPUClass, SPARC_CPU)
+OBJECT_DECLARE_CPU_TYPE(SPARC32CPU, SPARCCPUClass, SPARC32_CPU)
+OBJECT_DECLARE_CPU_TYPE(SPARC64CPU, SPARCCPUClass, SPARC64_CPU)
 
 #define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
 #define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 924e83b9ce..0f94e5a442 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -12,6 +12,9 @@ 
 #define TARGET_DPREGS 32
 #endif
 
+/* Abstract QOM SPARC CPU, not exposed to other targets */
+OBJECT_DECLARE_CPU_TYPE(SPARCCPU, SPARCCPUClass, SPARC_CPU)
+
 /*#define EXCP_INTERRUPT 0x100*/
 
 /* Windowed register indexes.  */
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 1e66413e94..7d060ba488 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -934,6 +934,12 @@  static const TypeInfo sparc_cpu_types[] = {
         .abstract       = true,
         .class_size     = sizeof(SPARCCPUClass),
         .class_init     = sparc_cpu_class_init,
+    }, {
+        .name           = TYPE_SPARC32_CPU,
+        .parent         = TYPE_SPARC_CPU,
+    }, {
+        .name           = TYPE_SPARC64_CPU,
+        .parent         = TYPE_SPARC_CPU,
     }
 };
 
@@ -950,7 +956,11 @@  static void sparc_register_cpudef_type(const struct sparc_def_t *def)
     char *typename = sparc_cpu_type_name(def->name);
     TypeInfo ti = {
         .name = typename,
-        .parent = TYPE_SPARC_CPU,
+#ifdef TARGET_SPARC64
+        .parent = TYPE_SPARC64_CPU,
+#else
+        .parent = TYPE_SPARC32_CPU,
+#endif
         .class_init = sparc_cpu_cpudef_class_init,
         .class_data = (void *)def,
     };