target/loongarch: Cleanups in preparation of loongarch32 support
PATCH v2 1/8 target/loongarch: Log I/O write accesses to CSR registers
In reply to Philippe Mathieu-DaudéVarious CSR registers have Read/Write fields. We might want to see guest trying to change such registers.
--- target/loongarch/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/loongarch/cpu.c +2 -0
@@ -544,6 +544,8 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)static void loongarch_qemu_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) { +qemu_log_mask (LOG_UNIMP ,"[%s]: Unimplemented reg 0x%" HWADDR_PRIx"\n" , + __func__, addr); }static uint64_t loongarch_qemu_read (void *opaque,hwaddr addr,unsigned size)
Signature · 1 line
2.41.0
v2 cover target/loongarch: Cleanups in preparation of loongarch32 support
v2:
- Do no rename loongarch_cpu_get/set_pc (rth)
- Rebased Jiajie's patches for convenience
- Added rth's R-b
Jiajie, this series contains few notes I took while reviewing your series adding loongarch32 support [*].
If your series isn't merged, consider rebasing it on this one.
Regards,
Phil.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Jiajie Chen (3):
target/loongarch: Add function to check current arch target/loongarch: Add new object class for loongarch32 cpus target/loongarch: Add GDB support for loongarch32 mode
Philippe Mathieu-Daudé (4):
target/loongarch: Log I/O write accesses to CSR registers target/loongarch: Remove duplicated disas_set_info assignment target/loongarch: Introduce abstract TYPE_LOONGARCH64_CPU target/loongarch: Extract 64-bit specifics to
loongarch64_cpu_class_init
Song Gao (1):
target/loongarch: Fix loongarch_la464_initfn() misses setting LSPW
configs/targets/loongarch64-softmmu.mak | 2 +- target/loongarch/cpu.h | 12 +++++ target/loongarch/cpu.c | 62 +++++++++++++++++++------ target/loongarch/gdbstub.c | 32 ++++++++++--- gdb-xml/loongarch-base32.xml | 45 ++++++++++++++++++ 5 files changed, 132 insertions(+), 21 deletions(-) create mode 100644 gdb-xml/loongarch-base32.xml
Signature · 1 line
2.41.0
PATCH v2 2/8 target/loongarch: Remove duplicated disas_set_info assignment
Commit 228021f05e ("target/loongarch: Add core definition") sets disas_set_info to loongarch_cpu_disas_set_info. Probably due to a failed git-rebase, commit ca61e75071 ("target/loongarch: Add gdb support") also sets it to the same value. Remove the duplication.
--- target/loongarch/cpu.c | 1 - 1 file changed, 1 deletion(-)
target/loongarch/cpu.c +0 -1
@@ -723,7 +723,6 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->disas_set_info = loongarch_cpu_disas_set_info; cc->gdb_read_register = loongarch_cpu_gdb_read_register; cc->gdb_write_register = loongarch_cpu_gdb_write_register; - cc->disas_set_info = loongarch_cpu_disas_set_info; cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="loongarch-base64.xml" ; cc->gdb_stop_before_watchpoint = true;
Signature · 1 line
2.41.0
PATCH v2 5/8 target/loongarch: Extract 64-bit specifics to loongarch64_cpu_class_init
In reply to Philippe Mathieu-DaudéExtract loongarch64 specific code from loongarch_cpu_class_init() to a new loongarch64_cpu_class_init().
In preparation of supporting loongarch32 cores, rename these functions using the '64' suffix.
--- target/loongarch/cpu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
target/loongarch/cpu.c +17 -10
@@ -356,7 +356,7 @@ static bool loongarch_cpu_has_work(CPUState *cs)#endif } -static void loongarch_la464_initfn (Object *obj) +static void loongarch64_la464_initfn (Object *obj) {LoongArchCPU *cpu =LOONGARCH_CPU (obj);CPULoongArchState *env = &cpu->env;
@@ -695,11 +695,6 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = { };#endif -static gchar *loongarch_gdb_arch_name (CPUState *cs) -{ -return g_strdup ("loongarch64" ); -} -static void loongarch_cpu_class_init (ObjectClass *c,void *data) {LoongArchCPUClass *lacc =LOONGARCH_CPU_CLASS (c);
@@ -724,16 +719,27 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->disas_set_info = loongarch_cpu_disas_set_info; cc->gdb_read_register = loongarch_cpu_gdb_read_register; cc->gdb_write_register = loongarch_cpu_gdb_write_register; - cc->gdb_num_core_regs =35 ; - cc->gdb_core_xml_file ="loongarch-base64.xml" ; cc->gdb_stop_before_watchpoint = true; - cc->gdb_arch_name = loongarch_gdb_arch_name;#ifdef CONFIG_TCG cc->tcg_ops = &loongarch_tcg_ops;#endif } +static gchar *loongarch64_gdb_arch_name (CPUState *cs) +{ +return g_strdup ("loongarch64" ); +} + +static void loongarch64_cpu_class_init (ObjectClass *c,void *data) +{ +CPUClass *cc =CPU_CLASS (c); + + cc->gdb_num_core_regs =35 ; + cc->gdb_core_xml_file ="loongarch-base64.xml" ; + cc->gdb_arch_name = loongarch64_gdb_arch_name; +} +#define DEFINE_LOONGARCH_CPU_TYPE (size, model, initfn) \ { \ .parent = TYPE_LOONGARCH##size##_CPU, \
@@ -757,8 +763,9 @@ static const TypeInfo loongarch_cpu_type_infos[] = { .parent = TYPE_LOONGARCH_CPU, .abstract = true, + .class_init = loongarch64_cpu_class_init, }, - DEFINE_LOONGARCH_CPU_TYPE(64, "la464", loongarch_la464_initfn), + DEFINE_LOONGARCH_CPU_TYPE(64, "la464", loongarch64_la464_initfn), };DEFINE_TYPES (loongarch_cpu_type_infos)
Signature · 1 line
2.41.0
PATCH v2 4/8 target/loongarch: Introduce abstract TYPE_LOONGARCH64_CPU
In reply to Philippe Mathieu-DaudéIn preparation of introducing TYPE_LOONGARCH32_CPU, introduce an abstract TYPE_LOONGARCH64_CPU.
--- target/loongarch/cpu.h | 1 + target/loongarch/cpu.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
target/loongarch/cpu.h +1 -0
@@ -377,6 +377,7 @@ struct ArchCPU { };#define TYPE_LOONGARCH_CPU "loongarch-cpu" +#define TYPE_LOONGARCH64_CPU "loongarch64-cpu"OBJECT_DECLARE_CPU_TYPE (LoongArchCPU, LoongArchCPUClass,LOONGARCH_CPU )
target/loongarch/cpu.c +9 -3
@@ -734,9 +734,9 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)#endif } -#define DEFINE_LOONGARCH_CPU_TYPE (model, initfn) \ +#define DEFINE_LOONGARCH_CPU_TYPE (size, model, initfn) \ { \ - .parent = TYPE_LOONGARCH_CPU, \ + .parent = TYPE_LOONGARCH##size##_CPU, \ .instance_init = initfn, \ .name = LOONGARCH_CPU_TYPE_NAME(model), \ }
@@ -752,7 +752,13 @@ static const TypeInfo loongarch_cpu_type_infos[] = { .class_size = sizeof(LoongArchCPUClass), .class_init = loongarch_cpu_class_init, }, - DEFINE_LOONGARCH_CPU_TYPE("la464", loongarch_la464_initfn), + { + .name = TYPE_LOONGARCH64_CPU, + .parent = TYPE_LOONGARCH_CPU, + + .abstract = true, + }, + DEFINE_LOONGARCH_CPU_TYPE(64, "la464", loongarch_la464_initfn), };DEFINE_TYPES (loongarch_cpu_type_infos)
Signature · 1 line
2.41.0
PATCH v2 6/8 target/loongarch: Add function to check current arch
In reply to Philippe Mathieu-DaudéFrom: Jiajie Chen <[email protected]>
Add is_la64 function to check if the current cpucfg[1].arch equals to 2(LA64).
Message-ID: <[email protected]>
--- target/loongarch/cpu.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
target/loongarch/cpu.h +10 -0
@@ -132,6 +132,11 @@ FIELD(CPUCFG1, HP, 24, 1) FIELD(CPUCFG1, IOCSR_BRD, 25, 1)FIELD (CPUCFG1 ,MSG_INT ,26 ,1 ) +/* cpucfg[1].arch */ +#define CPUCFG1_ARCH_LA32R 0 +#define CPUCFG1_ARCH_LA32 1 +#define CPUCFG1_ARCH_LA64 2 +/* cpucfg[2] bits */ FIELD(CPUCFG2, FP, 0, 1)FIELD (CPUCFG2 ,FP_SP ,1 ,1 )
@@ -421,6 +426,11 @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch)#endif } +static inline bool is_la64 (CPULoongArchState *env) +{ +return FIELD_EX32 (env->cpucfg[1 ],CPUCFG1 ,ARCH ) ==CPUCFG1_ARCH_LA64 ; +} +/* * LoongArch CPUs hardware flags. */
Signature · 1 line
2.41.0
PATCH v2 7/8 target/loongarch: Add new object class for loongarch32 cpus
In reply to Philippe Mathieu-DaudéFrom: Jiajie Chen <[email protected]>
Add object class stub for future loongarch32 cpus.
Message-ID: <[email protected]>
--- target/loongarch/cpu.h | 1 + target/loongarch/cpu.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
target/loongarch/cpu.h +1 -0
@@ -382,6 +382,7 @@ struct ArchCPU { };#define TYPE_LOONGARCH_CPU "loongarch-cpu" +#define TYPE_LOONGARCH32_CPU "loongarch32-cpu"#define TYPE_LOONGARCH64_CPU "loongarch64-cpu" OBJECT_DECLARE_CPU_TYPE(LoongArchCPU, LoongArchCPUClass,
target/loongarch/cpu.c +11 -0
@@ -726,6 +726,10 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)#endif } +static void loongarch32_cpu_class_init (ObjectClass *c,void *data) +{ +} +static gchar *loongarch64_gdb_arch_name (CPUState *cs) {return g_strdup ("loongarch64" );
@@ -758,6 +762,13 @@ static const TypeInfo loongarch_cpu_type_infos[] = { .class_size = sizeof(LoongArchCPUClass), .class_init = loongarch_cpu_class_init, }, + { + .name = TYPE_LOONGARCH32_CPU, + .parent = TYPE_LOONGARCH_CPU, + + .abstract = true, + .class_init = loongarch32_cpu_class_init, + }, { .name = TYPE_LOONGARCH64_CPU, .parent = TYPE_LOONGARCH_CPU,
Signature · 1 line
2.41.0
PATCH v2 3/8 target/loongarch: Fix loongarch_la464_initfn() misses setting LSPW
In reply to Philippe Mathieu-DaudéFrom: Song Gao <[email protected]>
Message-ID: <[email protected]>
--- target/loongarch/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/loongarch/cpu.c +1 -0
@@ -391,6 +391,7 @@ static void loongarch_la464_initfn(Object *obj) data =FIELD_DP32 (data,CPUCFG2 ,LSX ,1 ), data =FIELD_DP32 (data,CPUCFG2 ,LLFTP ,1 ); data =FIELD_DP32 (data,CPUCFG2 ,LLFTP_VER ,1 ); + data =FIELD_DP32 (data,CPUCFG2 ,LSPW ,1 ); data =FIELD_DP32 (data,CPUCFG2 ,LAM ,1 ); env->cpucfg[2 ] = data;
Signature · 1 line
2.41.0
PATCH v2 8/8 target/loongarch: Add GDB support for loongarch32 mode
In reply to Philippe Mathieu-DaudéFrom: Jiajie Chen <[email protected]>
GPRs and PC are 32-bit wide in loongarch32 mode.
Message-ID: <[email protected]>
--- configs/targets/loongarch64-softmmu.mak | 2 +- target/loongarch/cpu.c | 10 ++++++ target/loongarch/gdbstub.c | 32 ++++++++++++++---- gdb-xml/loongarch-base32.xml | 45 +++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 gdb-xml/loongarch-base32.xml
configs/targets/loongarch64-softmmu.mak +1 -1
@@ -1,5 +1,5 @@ TARGET_ARCH=loongarch64 TARGET_BASE_ARCH=loongarch TARGET_SUPPORTS_MTTCG=y -TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml +TARGET_XML_FILES= gdb-xml/loongarch-base32.xml gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml TARGET_NEED_FDT=y
target/loongarch/cpu.c +10 -0
@@ -726,8 +726,18 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)#endif } +static gchar *loongarch32_gdb_arch_name (CPUState *cs) +{ +return g_strdup ("loongarch32" ); +} +static void loongarch32_cpu_class_init (ObjectClass *c,void *data) { +CPUClass *cc =CPU_CLASS (c); + + cc->gdb_num_core_regs =35 ; + cc->gdb_core_xml_file ="loongarch-base32.xml" ; + cc->gdb_arch_name = loongarch32_gdb_arch_name; }static gchar *loongarch64_gdb_arch_name (CPUState *cs)
target/loongarch/gdbstub.c +25 -7
@@ -34,16 +34,25 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) {LoongArchCPU *cpu =LOONGARCH_CPU (cs);CPULoongArchState *env = &cpu->env; +uint64_t val;if (0 <= n && n <32 ) { -return gdb_get_regl (mem_buf, env->gpr[n]); + val = env->gpr[n]; }else if (n ==32 ) {/* orig_a0 */ -return gdb_get_regl (mem_buf,0 ); + val =0 ; }else if (n ==33 ) { -return gdb_get_regl (mem_buf, env->pc); + val = env->pc; }else if (n ==34 ) { -return gdb_get_regl (mem_buf, env->CSR_BADV); + val = env->CSR_BADV; + } + +if (0 <= n && n <=34 ) { +if (is_la64 (env)) { +return gdb_get_reg64 (mem_buf, val); + }else { +return gdb_get_reg32 (mem_buf, val); + } }return 0 ; }
@@ -52,15 +61,24 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) {LoongArchCPU *cpu =LOONGARCH_CPU (cs);CPULoongArchState *env = &cpu->env; -target_ulong tmp =ldtul_p (mem_buf); +target_ulong tmp; +int read_length;int length =0 ; +if (is_la64 (env)) { + tmp =ldq_p (mem_buf); + read_length =8 ; + }else { + tmp =ldl_p (mem_buf); + read_length =4 ; + } +if (0 <= n && n <32 ) { env->gpr[n] = tmp; - length =sizeof (target_ulong); + length = read_length; }else if (n ==33 ) { env->pc = tmp; - length =sizeof (target_ulong); + length = read_length; }return length; }
gdb-xml/loongarch-base32.xml new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v2 5/8] target/loongarch: Extract 64-bit specifics to loongarch64_cpu_class_init
In reply to Philippe Mathieu-DaudéQuoted 16 lines · Philippe Mathieu-Daudé
Extract loongarch64 specific code from
loongarch_cpu_class_init()to a newloongarch64_cpu_class_init().In preparation of supporting loongarch32 cores, rename these functions using the '64' suffix.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/loongarch/cpu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)target/loongarch/cpu.c +0
-0
target/loongarch/cpu.c static bool loongarch_cpu_has_work(CPUState *cs) · line 359
Quoted 5 lines
target/loongarch/cpu.c +1
-1@@ -356,7 +356,7 @@ static bool loongarch_cpu_has_work(CPUState *cs)#endif } -static void loongarch_la464_initfn (Object *obj) +static void loongarch64_la464_initfn (Object *obj)
This rename is not relevant to populating the abstract loongarch64 class.
Otherwise,
r~
Re: [PATCH v2 4/8] target/loongarch: Introduce abstract TYPE_LOONGARCH64_CPU
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
In preparation of introducing
TYPE_LOONGARCH32_CPU, introduce an abstractTYPE_LOONGARCH64_CPU.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/loongarch/cpu.h | 1 + target/loongarch/cpu.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
r~
Re: [PATCH v2 1/8] target/loongarch: Log I/O write accesses to CSR registers
In reply to Philippe Mathieu-DaudéQuoted 14 lines · Philippe Mathieu-Daudé
Various CSR registers have Read/Write fields. We might want to see guest trying to change such registers.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/loongarch/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/loongarch/cpu.c +0
-0
target/loongarch/cpu.c static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) · line 551
Quoted 8 lines
target/loongarch/cpu.c +2
-0@@ -544,6 +544,8 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)static void loongarch_qemu_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) { +qemu_log_mask (LOG_UNIMP ,"[%s]: Unimplemented reg 0x%" HWADDR_PRIx"\n" , + __func__, addr); }static uint64_t loongarch_qemu_read (void *opaque,hwaddr addr,unsigned size)
Thanks.
Song Gao
Re: [PATCH v2 2/8] target/loongarch: Remove duplicated disas_set_info assignment
In reply to Philippe Mathieu-DaudéQuoted 17 lines · Philippe Mathieu-Daudé
Commit
228021f05e("target/loongarch: Add core definition") setsdisas_set_infotoloongarch_cpu_disas_set_info. Probably due to a failed git-rebase, commitca61e75071("target/loongarch: Add gdb support") also sets it to the same value. Remove the duplication.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/loongarch/cpu.c | 1 - 1 file changed, 1 deletion(-)target/loongarch/cpu.c +0
-0
target/loongarch/cpu.c static void loongarch_cpu_class_init(ObjectClass *c, void *data) · line 728
Quoted 7 lines
target/loongarch/cpu.c +0
-1@@ -723,7 +723,6 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->disas_set_info = loongarch_cpu_disas_set_info; cc->gdb_read_register = loongarch_cpu_gdb_read_register; cc->gdb_write_register = loongarch_cpu_gdb_write_register; - cc->disas_set_info = loongarch_cpu_disas_set_info; cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="loongarch-base64.xml" ; cc->gdb_stop_before_watchpoint = true;
Thanks.
Song Gao