Skip to contentSkip to conversation

target/xtensa: Build system units in common source set

PATCH In review Philippe Mathieu-Daudé 3 participants 14 messages Jan 7 – Jan 13 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover target/xtensa: Build system units in common source set

Build all Xtensa system units as common objects.

Based-on: <[email protected]>
"meson: Allow system binaries to not have target-specific units"

Philippe Mathieu-Daudé (7):
target/xtensa: Convert XTENSA_DEFAULT_CPU_MODEL to runtime helper

    (MMU)

target/xtensa: Convert XTENSA_DEFAULT_CPU_MODEL to runtime (no MMU) target/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian() target/xtensa: Build system units in common source set target/xtensa: Build 'xtensa-isa.c' in common source set hw/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian() hw/xtensa: Build hw models in common source set

 target/xtensa/cpu-qom.h     |  3 +++
 target/xtensa/cpu.h         | 12 ----------
 hw/xtensa/sim.c             | 13 +++++++---
 hw/xtensa/virt.c            | 11 +++++++--
 hw/xtensa/xtfpga.c          | 48 +++++++++++++++++++++----------------
 linux-user/xtensa/elfload.c |  4 ++--
 target/xtensa/cpu.c         | 10 ++++++++
 target/xtensa/translate.c   |  5 ++--
 hw/xtensa/meson.build       |  2 +-
 target/xtensa/meson.build   |  7 +++++-
 10 files changed, 71 insertions(+), 44 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/7 target/xtensa: Convert XTENSA_DEFAULT_CPU_MODEL to runtime helper (MMU)

In order to remove the TARGET_BIG_ENDIAN use in "cpu.h", introduce the xtensa_default_cpu_model() helper which returns the current XTENSA_DEFAULT_CPU_MODEL but evaluating endianness at runtime. Update the machines using it.

---
 target/xtensa/cpu-qom.h     |  2 ++
 target/xtensa/cpu.h         |  4 ----
 hw/xtensa/sim.c             | 10 ++++++++--
 hw/xtensa/virt.c            | 11 +++++++++--
 hw/xtensa/xtfpga.c          | 17 +++++++++--------
 linux-user/xtensa/elfload.c |  4 ++--
 target/xtensa/cpu.c         |  5 +++++
 7 files changed, 35 insertions(+), 18 deletions(-)
target/xtensa/cpu-qom.h +2 -0
index d932346b5fe..66992d08c2e 100644
@@ -38,4 +38,6 @@ OBJECT_DECLARE_CPU_TYPE(XtensaCPU, XtensaCPUClass, XTENSA_CPU)
 #define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
 
+const char *xtensa_default_cpu_model(void);
+
 #endif
target/xtensa/cpu.h +0 -4
index 22192924841..fe2f25e527c 100644
@@ -606,14 +606,10 @@ G_NORETURN void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
 
 #if TARGET_BIG_ENDIAN
-#define XTENSA_DEFAULT_CPU_MODEL "fsf"
 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
 #else
-#define XTENSA_DEFAULT_CPU_MODEL "dc232b"
 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
 #endif
-#define XTENSA_DEFAULT_CPU_TYPE \
-    XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 #define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
     XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
 
hw/xtensa/sim.c +8 -2
index 994460d0414..03dbe69c2d4 100644
@@ -36,6 +36,7 @@
 #include "qemu/error-report.h"
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
+#include "target/xtensa/cpu-qom.h"
 
 static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
 {
@@ -119,12 +120,17 @@ static void xtensa_sim_init(MachineState *machine)
 
 static void xtensa_sim_machine_init(MachineClass *mc)
 {
-    mc->desc = "sim machine (" XTENSA_DEFAULT_CPU_MODEL ")";
+    if (target_big_endian()) {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("fsf");
+        mc->desc = "sim machine (fsf)";
+    } else {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("dc232b");
+        mc->desc = "sim machine (dc232b)";
+    }
     mc->is_default = true;
     mc->init = xtensa_sim_init;
     mc->max_cpus = 4;
     mc->no_serial = 1;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 DEFINE_MACHINE("sim", xtensa_sim_machine_init)
hw/xtensa/virt.c +9 -2
index 271f06e0953..2275953ce67 100644
@@ -35,8 +35,10 @@
 #include "elf.h"
 #include "system/memory.h"
 #include "qemu/error-report.h"
+#include "qemu/target-info.h"
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
+#include "target/xtensa/cpu-qom.h"
 
 static void create_pcie(MachineState *ms, CPUXtensaState *env, int irq_base,
                         hwaddr addr_base)
@@ -117,10 +119,15 @@ static void xtensa_virt_init(MachineState *machine)
 
 static void xtensa_virt_machine_init(MachineClass *mc)
 {
-    mc->desc = "virt machine (" XTENSA_DEFAULT_CPU_MODEL ")";
+    if (target_big_endian()) {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("fsf");
+        mc->desc = "virt machine (fsf)";
+    } else {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("dc232b");
+        mc->desc = "virt machine (dc232b)";
+    }
     mc->init = xtensa_virt_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
     mc->default_nic = "virtio-net-pci";
 }
 
hw/xtensa/xtfpga.c +9 -8
index d427d68e505..5fd4d655557 100644
@@ -51,6 +51,7 @@
 #include "hw/xtensa/mx_pic.h"
 #include "exec/cpu-common.h"
 #include "migration/vmstate.h"
+#include "target/xtensa/cpu-qom.h"
 
 typedef struct XtfpgaFlashDesc {
     hwaddr base;
@@ -591,10 +592,10 @@ static void xtfpga_lx60_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("lx60 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_lx60_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();
     mc->default_ram_size = 64 * MiB;
 }
 
@@ -625,10 +626,10 @@ static void xtfpga_lx200_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("lx200 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_lx200_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();
     mc->default_ram_size = 96 * MiB;
 }
 
@@ -659,10 +660,10 @@ static void xtfpga_ml605_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("ml605 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_ml605_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();
     mc->default_ram_size = 512 * MiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE;
 }
 
@@ -693,10 +694,10 @@ static void xtfpga_kc705_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("kc705 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_kc705_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();
     mc->default_ram_size = 1 * GiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE;
 }
 
linux-user/xtensa/elfload.c +2 -2
index 68aeed855f9..9bb740d357e 100644
@@ -4,11 +4,11 @@
 #include "qemu.h"
 #include "loader.h"
 #include "target_elf.h"
-
+#include "target/xtensa/cpu-qom.h"
 
 const char *get_elf_cpu_model(uint32_t eflags)
 {
-    return XTENSA_DEFAULT_CPU_MODEL;
+    return xtensa_default_cpu_model();
 }
 
 void elf_core_copy_regs(target_elf_gregset_t *r, const CPUXtensaState *env)
target/xtensa/cpu.c +5 -0
index ecc5e093a40..6220edda976 100644
@@ -29,6 +29,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "fpu/softfloat.h"
@@ -40,6 +41,10 @@
 #include "system/memory.h"
 #endif
 
+const char *xtensa_default_cpu_model(void)
+{
+    return target_big_endian() ? "fsf" : "dc232b";
+}
 
 static void xtensa_cpu_set_pc(CPUState *cs, vaddr value)
 {
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH 1/7] target/xtensa: Convert XTENSA_DEFAULT_CPU_MODEL to runtime helper (MMU)

Quoted 125 lines · Philippe Mathieu-Daudé

In order to remove the TARGET_BIG_ENDIAN use in "cpu.h", introduce the xtensa_default_cpu_model() helper which returns the current XTENSA_DEFAULT_CPU_MODEL but evaluating endianness at runtime. Update the machines using it.

---
 target/xtensa/cpu-qom.h     |  2 ++
 target/xtensa/cpu.h         |  4 ----
 hw/xtensa/sim.c             | 10 ++++++++--
 hw/xtensa/virt.c            | 11 +++++++++--
 hw/xtensa/xtfpga.c          | 17 +++++++++--------
 linux-user/xtensa/elfload.c |  4 ++--
 target/xtensa/cpu.c         |  5 +++++
 7 files changed, 35 insertions(+), 18 deletions(-)
target/xtensa/cpu-qom.h +2 -0
index d932346b5fe..66992d08c2e 100644
@@ -38,4 +38,6 @@ OBJECT_DECLARE_CPU_TYPE(XtensaCPU, XtensaCPUClass, XTENSA_CPU)
 #define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
 
+const char *xtensa_default_cpu_model(void);
+
 #endif
target/xtensa/cpu.h +0 -4
index 22192924841..fe2f25e527c 100644
@@ -606,14 +606,10 @@ G_NORETURN void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
 
 #if TARGET_BIG_ENDIAN
-#define XTENSA_DEFAULT_CPU_MODEL "fsf"
 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
 #else
-#define XTENSA_DEFAULT_CPU_MODEL "dc232b"
 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
 #endif
-#define XTENSA_DEFAULT_CPU_TYPE \
-    XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 #define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
     XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
 
hw/xtensa/sim.c +8 -2
index 994460d0414..03dbe69c2d4 100644
@@ -36,6 +36,7 @@
 #include "qemu/error-report.h"
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
+#include "target/xtensa/cpu-qom.h"
 
 static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
 {
@@ -119,12 +120,17 @@ static void xtensa_sim_init(MachineState *machine)
 
 static void xtensa_sim_machine_init(MachineClass *mc)
 {
-    mc->desc = "sim machine (" XTENSA_DEFAULT_CPU_MODEL ")";
+    if (target_big_endian()) {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("fsf");
+        mc->desc = "sim machine (fsf)";
+    } else {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("dc232b");
+        mc->desc = "sim machine (dc232b)";
+    }
     mc->is_default = true;
     mc->init = xtensa_sim_init;
     mc->max_cpus = 4;
     mc->no_serial = 1;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
 }
 
 DEFINE_MACHINE("sim", xtensa_sim_machine_init)
hw/xtensa/virt.c +9 -2
index 271f06e0953..2275953ce67 100644
@@ -35,8 +35,10 @@
 #include "elf.h"
 #include "system/memory.h"
 #include "qemu/error-report.h"
+#include "qemu/target-info.h"
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
+#include "target/xtensa/cpu-qom.h"
 
 static void create_pcie(MachineState *ms, CPUXtensaState *env, int irq_base,
                         hwaddr addr_base)
@@ -117,10 +119,15 @@ static void xtensa_virt_init(MachineState *machine)
 
 static void xtensa_virt_machine_init(MachineClass *mc)
 {
-    mc->desc = "virt machine (" XTENSA_DEFAULT_CPU_MODEL ")";
+    if (target_big_endian()) {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("fsf");
+        mc->desc = "virt machine (fsf)";
+    } else {
+        mc->default_cpu_type = XTENSA_CPU_TYPE_NAME("dc232b");
+        mc->desc = "virt machine (dc232b)";
+    }
     mc->init = xtensa_virt_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
     mc->default_nic = "virtio-net-pci";
 }
 
hw/xtensa/xtfpga.c +1 -0
index d427d68e505..5fd4d655557 100644
@@ -51,6 +51,7 @@
 #include "hw/xtensa/mx_pic.h"
 #include "exec/cpu-common.h"
 #include "migration/vmstate.h"
+#include "target/xtensa/cpu-qom.h"
 
 typedef struct XtfpgaFlashDesc {
     hwaddr base;

hw/xtensa/xtfpga.c static void xtfpga_lx60_class_init(ObjectClass *oc, const void *data) · line 598

Quoted 9 lines
hw/xtensa/xtfpga.c +2 -2
@@ -591,10 +592,10 @@ static void xtfpga_lx60_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("lx60 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_lx60_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();

Type was expected here, but model is supplied instead. I wonder why xtfpga and sim/virt are done differently?

hw/xtensa/xtfpga.c static void xtfpga_lx200_class_init(ObjectClass *oc, const void *data) · line 632

Quoted 13 lines
hw/xtensa/xtfpga.c +2 -2
     mc->default_ram_size = 64 * MiB;
 }
 
@@ -625,10 +626,10 @@ static void xtfpga_lx200_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("lx200 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_lx200_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();

Same here.

hw/xtensa/xtfpga.c static void xtfpga_ml605_class_init(ObjectClass *oc, const void *data) · line 666

Quoted 13 lines
hw/xtensa/xtfpga.c +2 -2
     mc->default_ram_size = 96 * MiB;
 }
 
@@ -659,10 +660,10 @@ static void xtfpga_ml605_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("ml605 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_ml605_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();

And here.

hw/xtensa/xtfpga.c static void xtfpga_kc705_class_init(ObjectClass *oc, const void *data) · line 700

Quoted 13 lines
hw/xtensa/xtfpga.c +2 -2
     mc->default_ram_size = 512 * MiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE;
 }
 
@@ -693,10 +694,10 @@ static void xtfpga_kc705_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
+    mc->desc = g_strdup_printf("kc705 EVB (%s)", xtensa_default_cpu_model());
     mc->init = xtfpga_kc705_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model();

And here.

Signature · 2 lines
Thanks.
-- Max
#3 lore raw

PATCH 2/7 target/xtensa: Convert XTENSA_DEFAULT_CPU_MODEL to runtime (no MMU)

In reply to Philippe Mathieu-Daudé

Similarly to the previous commit, now replace the
XTENSA_DEFAULT_CPU_NOMMU_MODEL definition by the
xtensa_default_cpu_model_nommu() helper which
evaluates endianness at runtime. Update xtfpga.c
machines.

---
 target/xtensa/cpu-qom.h |  1 +
 target/xtensa/cpu.h     |  8 --------
 hw/xtensa/xtfpga.c      | 20 ++++++++++++--------
 target/xtensa/cpu.c     |  5 +++++
 4 files changed, 18 insertions(+), 16 deletions(-)
target/xtensa/cpu-qom.h +1 -0
index 66992d08c2e..75b97632453 100644
@@ -39,5 +39,6 @@ OBJECT_DECLARE_CPU_TYPE(XtensaCPU, XtensaCPUClass, XTENSA_CPU)
 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
 
 const char *xtensa_default_cpu_model(void);
+const char *xtensa_default_cpu_model_nommu(void);
 
 #endif
target/xtensa/cpu.h +0 -8
index fe2f25e527c..85399390044 100644
@@ -605,14 +605,6 @@ G_NORETURN void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 
 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
 
-#if TARGET_BIG_ENDIAN
-#define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
-#else
-#define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
-#endif
-#define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
-    XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
-
 void xtensa_collect_sr_names(const XtensaConfig *config);
 void xtensa_translate_init(void);
 void xtensa_translate_code(CPUState *cs, TranslationBlock *tb,
hw/xtensa/xtfpga.c +12 -8
index 5fd4d655557..3d7afcad4cc 100644
@@ -609,10 +609,11 @@ static void xtfpga_lx60_nommu_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx60 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
+    mc->desc = g_strdup_printf("lx60 noMMU EVB (%s)",
+                               xtensa_default_cpu_model_nommu());
     mc->init = xtfpga_lx60_nommu_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model_nommu();
     mc->default_ram_size = 64 * MiB;
 }
 
@@ -643,10 +644,11 @@ static void xtfpga_lx200_nommu_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "lx200 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
+    mc->desc = g_strdup_printf("lx200 noMMU EVB (%s)",
+                               xtensa_default_cpu_model_nommu());
     mc->init = xtfpga_lx200_nommu_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model_nommu();
     mc->default_ram_size = 96 * MiB;
 }
 
@@ -677,10 +679,11 @@ static void xtfpga_ml605_nommu_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "ml605 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
+    mc->desc = g_strdup_printf("ml605 noMMU EVB (%s)",
+                               xtensa_default_cpu_model_nommu());
     mc->init = xtfpga_ml605_nommu_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model_nommu();
     mc->default_ram_size = 256 * MiB;
 }
 
@@ -711,10 +714,11 @@ static void xtfpga_kc705_nommu_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->desc = "kc705 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
+    mc->desc = g_strdup_printf("kc705 noMMU EVB (%s)",
+                               xtensa_default_cpu_model_nommu());
     mc->init = xtfpga_kc705_nommu_init;
     mc->max_cpus = 32;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
+    mc->default_cpu_type = xtensa_default_cpu_model_nommu();
     mc->default_ram_size = 256 * MiB;
 }
 
target/xtensa/cpu.c +5 -0
index 6220edda976..f09b93622c9 100644
@@ -46,6 +46,11 @@ const char *xtensa_default_cpu_model(void)
     return target_big_endian() ? "fsf" : "dc232b";
 }
 
+const char *xtensa_default_cpu_model_nommu(void)
+{
+    return target_big_endian() ? "fsf" : "de212";
+}
+
 static void xtensa_cpu_set_pc(CPUState *cs, vaddr value)
 {
     XtensaCPU *cpu = XTENSA_CPU(cs);
Signature · 1 line
2.52.0
#4 lore raw

PATCH 3/7 target/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian()

In reply to Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
 target/xtensa/translate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/xtensa/translate.c +3 -2
index bb8d2ed86cf..36f069d70ca 100644
@@ -34,6 +34,7 @@
 #include "tcg/tcg-op.h"
 #include "qemu/log.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target-info.h"
 #include "exec/translator.h"
 #include "exec/translation-block.h"
 #include "exec/target_page.h"
@@ -1381,7 +1382,7 @@ static void translate_bb(DisasContext *dc, const OpcodeArg arg[],
     TCGv_i32 tmp = tcg_temp_new_i32();
 
     tcg_gen_andi_i32(tmp, arg[1].in, 0x1f);
-    if (TARGET_BIG_ENDIAN) {
+    if (target_big_endian()) {
         tcg_gen_shr_i32(tmp, tcg_constant_i32(0x80000000u), tmp);
     } else {
         tcg_gen_shl_i32(tmp, tcg_constant_i32(0x00000001u), tmp);
@@ -1394,7 +1395,7 @@ static void translate_bbi(DisasContext *dc, const OpcodeArg arg[],
                           const uint32_t par[])
 {
     TCGv_i32 tmp = tcg_temp_new_i32();
-    if (TARGET_BIG_ENDIAN) {
+    if (target_big_endian()) {
         tcg_gen_andi_i32(tmp, arg[0].in, 0x80000000u >> arg[1].imm);
     } else {
         tcg_gen_andi_i32(tmp, arg[0].in, 0x00000001u << arg[1].imm);
Signature · 1 line
2.52.0
#5 lore raw

Re: [PATCH 3/7] target/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian()

Quoted 41 lines · Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
 target/xtensa/translate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/xtensa/translate.c +3 -2
index bb8d2ed86cf..36f069d70ca 100644
@@ -34,6 +34,7 @@
 #include "tcg/tcg-op.h"
 #include "qemu/log.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target-info.h"
 #include "exec/translator.h"
 #include "exec/translation-block.h"
 #include "exec/target_page.h"
@@ -1381,7 +1382,7 @@ static void translate_bb(DisasContext *dc, const OpcodeArg arg[],
     TCGv_i32 tmp = tcg_temp_new_i32();
 
     tcg_gen_andi_i32(tmp, arg[1].in, 0x1f);
-    if (TARGET_BIG_ENDIAN) {
+    if (target_big_endian()) {
         tcg_gen_shr_i32(tmp, tcg_constant_i32(0x80000000u), tmp);
     } else {
         tcg_gen_shl_i32(tmp, tcg_constant_i32(0x00000001u), tmp);
@@ -1394,7 +1395,7 @@ static void translate_bbi(DisasContext *dc, const OpcodeArg arg[],
                           const uint32_t par[])
 {
     TCGv_i32 tmp = tcg_temp_new_i32();
-    if (TARGET_BIG_ENDIAN) {
+    if (target_big_endian()) {
         tcg_gen_andi_i32(tmp, arg[0].in, 0x80000000u >> arg[1].imm);
     } else {
         tcg_gen_andi_i32(tmp, arg[0].in, 0x00000001u << arg[1].imm);
Signature · 1 line
2.52.0

What about the two remaining uses of TARGET_BIG_ENDIAN? The one in cpu.c is straight forward

  static void xtensa_cpu_disas_set_info(CPUState *cs, disassemble_info *info)
  {
      XtensaCPU *cpu = XTENSA_CPU(cs);
      info->private_data = cpu->env.config->isa;
      info->print_insn = print_insn_xtensa;
      info->endian = TARGET_BIG_ENDIAN ? BFD_ENDIAN_BIG
                                       : BFD_ENDIAN_LITTLE;

}

I guess for the one in overlay_tool.h we can register all cores unconditionally and filter for endianness mismatch with target_big_endian() later?

  #if TARGET_BIG_ENDIAN == (XCHAL_HAVE_BE != 0)
  #define REGISTER_CORE(core) \
      static void __attribute__((constructor)) register_core(void) \
      { \
          static XtensaConfigList node = { \
              .config = &core, \
          }; \
          xtensa_register_core(&node); \
      }
  #else
  #define REGISTER_CORE(core)
  #endif
#6 lore raw

PATCH 4/7 target/xtensa: Build system units in common source set

In reply to Philippe Mathieu-Daudé

These files are now free of target-specific symbols, build them as common files (thus forbidding further uses of such target-specific symbols).

---
 target/xtensa/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/xtensa/meson.build +1 -1
index f8d60101e3d..69c6946420a 100644
@@ -24,4 +24,4 @@ xtensa_system_ss.add(files(
 ))
 
 target_arch += {'xtensa': xtensa_ss}
-target_system_arch += {'xtensa': xtensa_system_ss}
+target_common_system_arch += {'xtensa': xtensa_system_ss}
Signature · 1 line
2.52.0
Reviewed-by Anton Johansson on v1 4/7
#7 lore raw
Quoted 23 lines · Philippe Mathieu-Daudé

These files are now free of target-specific symbols, build them as common files (thus forbidding further uses of such target-specific symbols).

---
 target/xtensa/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/xtensa/meson.build +1 -1
index f8d60101e3d..69c6946420a 100644
@@ -24,4 +24,4 @@ xtensa_system_ss.add(files(
 ))
 
 target_arch += {'xtensa': xtensa_ss}
-target_system_arch += {'xtensa': xtensa_system_ss}
+target_common_system_arch += {'xtensa': xtensa_system_ss}
Signature · 1 line
2.52.0

all of dbg_helper.c, mmu_helper.c, monitor.c, and xtensa-semi.c include cpu.h, change to target/xtensa/cpu.h.

Otherwise,

#8 lore raw

PATCH 5/7 target/xtensa: Build 'xtensa-isa.c' in common source set

In reply to Philippe Mathieu-Daudé

'xtensa-isa.c' is now free of target-specific symbols, build it as common files (thus forbidding further uses of such target-specific symbols).

---
 target/xtensa/meson.build | 5 +++++
 1 file changed, 5 insertions(+)
target/xtensa/meson.build +5 -0
index 69c6946420a..3fdb20db655 100644
@@ -12,6 +12,10 @@ xtensa_ss.add(files(
   'op_helper.c',
   'translate.c',
   'win_helper.c',
+))
+
+xtensa_common_ss = ss.source_set()
+xtensa_common_ss.add(files(
   'xtensa-isa.c',
 ))
 
@@ -24,4 +28,5 @@ xtensa_system_ss.add(files(
 ))
 
 target_arch += {'xtensa': xtensa_ss}
+target_common_arch += {'xtensa': xtensa_common_ss}
 target_common_system_arch += {'xtensa': xtensa_system_ss}
Signature · 1 line
2.52.0
Reviewed-by Anton Johansson on v1 5/7
#9 lore raw

Re: [PATCH 5/7] target/xtensa: Build 'xtensa-isa.c' in common source set

Quoted 33 lines · Philippe Mathieu-Daudé

'xtensa-isa.c' is now free of target-specific symbols, build it as common files (thus forbidding further uses of such target-specific symbols).

---
 target/xtensa/meson.build | 5 +++++
 1 file changed, 5 insertions(+)
target/xtensa/meson.build +5 -0
index 69c6946420a..3fdb20db655 100644
@@ -12,6 +12,10 @@ xtensa_ss.add(files(
   'op_helper.c',
   'translate.c',
   'win_helper.c',
+))
+
+xtensa_common_ss = ss.source_set()
+xtensa_common_ss.add(files(
   'xtensa-isa.c',
 ))
 
@@ -24,4 +28,5 @@ xtensa_system_ss.add(files(
 ))
 
 target_arch += {'xtensa': xtensa_ss}
+target_common_arch += {'xtensa': xtensa_common_ss}
 target_common_system_arch += {'xtensa': xtensa_system_ss}
Signature · 1 line
2.52.0

Mentioned this in the 7th patch, but xtensa-isa.h is strange to me, why not move hw/xtensa/xtensa-isa.h to target/ and drop the current one-line target/xtensa/xtensa-isa.h file? Also include with "target/".

Otherwise,

#10 lore raw

PATCH 6/7 hw/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian()

In reply to Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
 hw/xtensa/sim.c    |  3 ++-
 hw/xtensa/xtfpga.c | 11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
hw/xtensa/sim.c +2 -1
index 03dbe69c2d4..3a5ac8d67cd 100644
@@ -34,6 +34,7 @@
 #include "elf.h"
 #include "system/memory.h"
 #include "qemu/error-report.h"
+#include "qemu/target-info.h"
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
 #include "target/xtensa/cpu-qom.h"
@@ -102,7 +103,7 @@ void xtensa_sim_load_kernel(XtensaCPU *cpu, MachineState *machine)
         uint64_t elf_entry;
         int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
                                &elf_entry, NULL, NULL, NULL,
-                               TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
+                               target_big_endian() ? ELFDATA2MSB : ELFDATA2LSB,
                                EM_XTENSA, 0, 0);
 
         if (success > 0) {
hw/xtensa/xtfpga.c +6 -5
index 3d7afcad4cc..150fcd24f15 100644
@@ -27,6 +27,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "system/system.h"
@@ -313,7 +314,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
-        flash = xtfpga_flash_init(system_io, board, dinfo, TARGET_BIG_ENDIAN);
+        flash = xtfpga_flash_init(system_io, board, dinfo, target_big_endian());
     }
 
     /* Use presence of kernel file name as 'boot from SRAM' switch. */
@@ -402,7 +403,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         uint64_t elf_entry;
         int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
                                &elf_entry, NULL, NULL, NULL,
-                               TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
+                               target_big_endian() ? ELFDATA2MSB : ELFDATA2LSB,
                                EM_XTENSA, 0, 0);
         if (success > 0) {
             entry_point = elf_entry;
@@ -440,9 +441,9 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 0x21, 0xfe, 0xff,       /* l32r a2, entry_a2 */
                 0xa0, 0x00, 0x00,       /* jx   a0 */
             };
-            const size_t boot_sz = TARGET_BIG_ENDIAN ? sizeof(boot_be)
-                                                     : sizeof(boot_le);
-            uint8_t *boot = TARGET_BIG_ENDIAN ? boot_be : boot_le;
+            const size_t boot_sz = target_big_endian() ? sizeof(boot_be)
+                                                       : sizeof(boot_le);
+            uint8_t *boot = target_big_endian() ? boot_be : boot_le;
             uint32_t entry_pc = tswap32(entry_point);
             uint32_t entry_a2 = tswap32(tagptr);
 
Signature · 1 line
2.52.0
Reviewed-by Anton Johansson on v1 6/7
#11 lore raw

Re: [PATCH 6/7] hw/xtensa: Replace TARGET_BIG_ENDIAN -> target_big_endian()

Quoted 8 lines · Philippe Mathieu-Daudé

Check endianness at runtime to remove the target-specific TARGET_BIG_ENDIAN definition.

---
 hw/xtensa/sim.c    |  3 ++-
 hw/xtensa/xtfpga.c | 11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
#12 lore raw

PATCH 7/7 hw/xtensa: Build hw models in common source set

In reply to Philippe Mathieu-Daudé

These files are now free of target-specific symbols, build them as common files (thus forbidding further uses of such target-specific symbols).

---
 hw/xtensa/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xtensa/meson.build +1 -1
index 1d5835df4bf..fec22ef7d2f 100644
@@ -8,4 +8,4 @@ xtensa_ss.add(when: 'CONFIG_XTENSA_SIM', if_true: files('sim.c'))
 xtensa_ss.add(when: 'CONFIG_XTENSA_VIRT', if_true: files('virt.c'))
 xtensa_ss.add(when: 'CONFIG_XTENSA_XTFPGA', if_true: files('xtfpga.c'))
 
-hw_arch += {'xtensa': xtensa_ss}
+hw_common_arch += {'xtensa': xtensa_ss}
Signature · 1 line
2.52.0
Reviewed-by Anton Johansson on v1 7/7
#13 lore raw

Re: [PATCH 7/7] hw/xtensa: Build hw models in common source set

Quoted 22 lines · Philippe Mathieu-Daudé

These files are now free of target-specific symbols, build them as common files (thus forbidding further uses of such target-specific symbols).

---
 hw/xtensa/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xtensa/meson.build +1 -1
index 1d5835df4bf..fec22ef7d2f 100644
@@ -8,4 +8,4 @@ xtensa_ss.add(when: 'CONFIG_XTENSA_SIM', if_true: files('sim.c'))
 xtensa_ss.add(when: 'CONFIG_XTENSA_VIRT', if_true: files('virt.c'))
 xtensa_ss.add(when: 'CONFIG_XTENSA_XTFPGA', if_true: files('xtfpga.c'))
 
-hw_arch += {'xtensa': xtensa_ss}
+hw_common_arch += {'xtensa': xtensa_ss}
Signature · 1 line
2.52.0

nit about includes, in pic_cpu.c, xtensa_memory.h and xtfpga.c change

  #include "cpu.h" -> "target/xtensa/cpu.h"

and in cpu.h change

  #include "cpu-qom.h" -> "target/xtensa/cpu-qom.h"
  #include "qemu/cpu-float.h"
  #include "exec/cpu-common.h"
  #include "exec/cpu-defs.h"
  #include "exec/cpu-interrupt.h"
  #include "hw/core/clock.h"
  #include "xtensa-isa.h" -> "target/xtensa/xtensa-isa.h" or "hw/.."

About xtensa-isa.h, is there any reason for keeping it in hw/? Why not move it to target/ and get rid of the single line xtensa-isa.h file?

Anyway,