Add LoongArch softmmu support
v3 cover Add LoongArch softmmu support
Hi All,
As this series only supports running binary files in ELF format, and does not depend on BIOS and kernel file. so this series are changed from RFC to patch v1.
The manual:
- https://github.com/loongson/LoongArch-Documentation/releases/tag/2022.03.17
Old series:
- https://patchew.org/QEMU/[email protected]/
- https://patchew.org/QEMU/[email protected]/
Thanks.
Xiaojuan
-----
v3:
- Add Check csr_names.
- Drop CSR_CPUID, use cpu->cpu_index.
- Fixed loongarch extioi device emulation. ipmap and coremap register change to 32bits.
- Check_iocsr() function moved to loongarch_ipi_writel().
- Pch_pic/msi use qdev_init_gpio_out() to init irq, and use qdev_connect_gpio_out() to connect irq.
- Load elf function moved to hw/loongarch/loongson.c
v2:
- Improvents to CSR/IOCSR instructions translation.
- Fixed extioi device emulation. It is represented by only one memory region.
- Fixed IPI device emulation. The registers are represented with uint64_t.
- Use do_cpu_reset() and cpu_set_pc() to specify the load address.
v2: https://patchew.org/QEMU/[email protected]/
v1: https://patchew.org/QEMU/[email protected]/
Song Gao (18):
target/loongarch: Add README
target/loongarch: Add core definition
target/loongarch: Add main translation routines target/loongarch: Add fixed point arithmetic instruction translation target/loongarch: Add fixed point shift instruction translation target/loongarch: Add fixed point bit instruction translation target/loongarch: Add fixed point load/store instruction translation target/loongarch: Add fixed point atomic instruction translation target/loongarch: Add fixed point extra instruction translation target/loongarch: Add floating point arithmetic instruction
translation
target/loongarch: Add floating point comparison instruction
translation
target/loongarch: Add floating point conversion instruction
translation
target/loongarch: Add floating point move instruction translation target/loongarch: Add floating point load/store instruction
translation
target/loongarch: Add branch instruction translation target/loongarch: Add disassembler
target/loongarch: Add target build suport target/loongarch: 'make check-tcg' support
Xiaojuan Yang (25):
target/loongarch: Add system emulation introduction target/loongarch: Add CSRs definition
target/loongarch: Add basic vmstate description of CPU. target/loongarch: Implement qmp_query_cpu_definitions() target/loongarch: Add MMU support for LoongArch CPU. target/loongarch: Add LoongArch interrupt and exception handle target/loongarch: Add constant timer support target/loongarch: Add LoongArch CSR instruction target/loongarch: Add LoongArch IOCSR instruction target/loongarch: Add TLB instruction support target/loongarch: Add other core instructions support target/loongarch: Add timer related instructions support. hw/loongarch: Add support loongson3 virt machine type. hw/loongarch: Add LoongArch ipi interrupt support(IPI) hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC) hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI) hw/intc: Add LoongArch extioi interrupt controller(EIOINTC) hw/loongarch: Add irq hierarchy for the system
Enable common virtio pci support for LoongArch hw/loongarch: Add some devices support for 3A5000. hw/loongarch: Add LoongArch ls7a rtc device support hw/loongarch: Add LoongArch load elf function. hw/loongarch: Add LoongArch ls7a acpi device support target/loongarch: Add gdb support.
tests/tcg/loongarch64: Add hello/memory test in loongarch64 system
MAINTAINERS | 26 + .../devices/loongarch64-softmmu/default.mak | 3 + configs/targets/loongarch64-softmmu.mak | 4 + docs/system/loongarch/loongson3.rst | 41 + gdb-xml/loongarch-base64.xml | 44 + gdb-xml/loongarch-fpu64.xml | 57 ++ hw/Kconfig | 1 + hw/acpi/Kconfig | 4 + hw/acpi/ls7a.c | 374 ++++++++ hw/acpi/meson.build | 1 + hw/intc/Kconfig | 15 + hw/intc/loongarch_extioi.c | 248 +++++ hw/intc/loongarch_ipi.c | 242 +++++ hw/intc/loongarch_pch_msi.c | 73 ++ hw/intc/loongarch_pch_pic.c | 431 +++++++++ hw/intc/meson.build | 4 + hw/intc/trace-events | 21 + hw/loongarch/Kconfig | 18 + hw/loongarch/loongson3.c | 361 ++++++++ hw/loongarch/meson.build | 4 + hw/meson.build | 1 + hw/rtc/Kconfig | 3 + hw/rtc/ls7a_rtc.c | 322 +++++++ hw/rtc/meson.build | 1 + include/disas/dis-asm.h | 2 + include/exec/poison.h | 2 + include/hw/acpi/ls7a.h | 53 ++ include/hw/intc/loongarch_extioi.h | 58 ++ include/hw/intc/loongarch_ipi.h | 52 ++ include/hw/intc/loongarch_pch_msi.h | 20 + include/hw/intc/loongarch_pch_pic.h | 69 ++ include/hw/loongarch/virt.h | 42 + include/hw/pci-host/ls7a.h | 48 + include/sysemu/arch_init.h | 1 + meson.build | 1 + qapi/machine-target.json | 6 +- qapi/machine.json | 2 +- softmmu/qdev-monitor.c | 3 +- target/Kconfig | 1 + target/loongarch/Kconfig | 2 + target/loongarch/README | 64 ++ target/loongarch/constant_timer.c | 64 ++ target/loongarch/cpu-csr.h | 208 +++++ target/loongarch/cpu-param.h | 18 + target/loongarch/cpu.c | 698 ++++++++++++++ target/loongarch/cpu.h | 391 ++++++++ target/loongarch/csr_helper.c | 92 ++ target/loongarch/disas.c | 757 +++++++++++++++ target/loongarch/fpu_helper.c | 862 ++++++++++++++++++ target/loongarch/gdbstub.c | 81 ++ target/loongarch/helper.h | 131 +++ target/loongarch/insn_trans/trans_arith.c.inc | 304 ++++++ .../loongarch/insn_trans/trans_atomic.c.inc | 113 +++ target/loongarch/insn_trans/trans_bit.c.inc | 212 +++++ .../loongarch/insn_trans/trans_branch.c.inc | 83 ++ target/loongarch/insn_trans/trans_extra.c.inc | 101 ++ .../loongarch/insn_trans/trans_farith.c.inc | 105 +++ target/loongarch/insn_trans/trans_fcmp.c.inc | 56 ++ target/loongarch/insn_trans/trans_fcnv.c.inc | 33 + .../loongarch/insn_trans/trans_fmemory.c.inc | 153 ++++ target/loongarch/insn_trans/trans_fmov.c.inc | 157 ++++ .../loongarch/insn_trans/trans_memory.c.inc | 229 +++++ .../insn_trans/trans_privileged.c.inc | 465 ++++++++++ target/loongarch/insn_trans/trans_shift.c.inc | 106 +++ target/loongarch/insns.decode | 486 ++++++++++ target/loongarch/internals.h | 56 ++ target/loongarch/iocsr_helper.c | 67 ++ target/loongarch/machine.c | 102 +++ target/loongarch/meson.build | 30 + target/loongarch/op_helper.c | 132 +++ target/loongarch/tlb_helper.c | 763 ++++++++++++++++ target/loongarch/translate.c | 280 ++++++ target/loongarch/translate.h | 45 + target/meson.build | 1 + tests/tcg/configure.sh | 1 + tests/tcg/loongarch64/Makefile.softmmu-target | 33 + tests/tcg/loongarch64/system/boot.S | 56 ++ tests/tcg/loongarch64/system/kernel.ld | 30 + tests/tcg/loongarch64/system/regdef.h | 86 ++ 79 files changed, 10308 insertions(+), 4 deletions(-) create mode 100644 configs/devices/loongarch64-softmmu/default.mak create mode 100644 configs/targets/loongarch64-softmmu.mak create mode 100644 docs/system/loongarch/loongson3.rst create mode 100644 gdb-xml/loongarch-base64.xml create mode 100644 gdb-xml/loongarch-fpu64.xml create mode 100644 hw/acpi/ls7a.c create mode 100644 hw/intc/loongarch_extioi.c create mode 100644 hw/intc/loongarch_ipi.c create mode 100644 hw/intc/loongarch_pch_msi.c create mode 100644 hw/intc/loongarch_pch_pic.c create mode 100644 hw/loongarch/Kconfig create mode 100644 hw/loongarch/loongson3.c create mode 100644 hw/loongarch/meson.build create mode 100644 hw/rtc/ls7a_rtc.c create mode 100644 include/hw/acpi/ls7a.h create mode 100644 include/hw/intc/loongarch_extioi.h create mode 100644 include/hw/intc/loongarch_ipi.h create mode 100644 include/hw/intc/loongarch_pch_msi.h create mode 100644 include/hw/intc/loongarch_pch_pic.h create mode 100644 include/hw/loongarch/virt.h create mode 100644 include/hw/pci-host/ls7a.h create mode 100644 target/loongarch/Kconfig create mode 100644 target/loongarch/README create mode 100644 target/loongarch/constant_timer.c create mode 100644 target/loongarch/cpu-csr.h create mode 100644 target/loongarch/cpu-param.h create mode 100644 target/loongarch/cpu.c create mode 100644 target/loongarch/cpu.h create mode 100644 target/loongarch/csr_helper.c create mode 100644 target/loongarch/disas.c create mode 100644 target/loongarch/fpu_helper.c create mode 100644 target/loongarch/gdbstub.c create mode 100644 target/loongarch/helper.h create mode 100644 target/loongarch/insn_trans/trans_arith.c.inc create mode 100644 target/loongarch/insn_trans/trans_atomic.c.inc create mode 100644 target/loongarch/insn_trans/trans_bit.c.inc create mode 100644 target/loongarch/insn_trans/trans_branch.c.inc create mode 100644 target/loongarch/insn_trans/trans_extra.c.inc create mode 100644 target/loongarch/insn_trans/trans_farith.c.inc create mode 100644 target/loongarch/insn_trans/trans_fcmp.c.inc create mode 100644 target/loongarch/insn_trans/trans_fcnv.c.inc create mode 100644 target/loongarch/insn_trans/trans_fmemory.c.inc create mode 100644 target/loongarch/insn_trans/trans_fmov.c.inc create mode 100644 target/loongarch/insn_trans/trans_memory.c.inc create mode 100644 target/loongarch/insn_trans/trans_privileged.c.inc create mode 100644 target/loongarch/insn_trans/trans_shift.c.inc create mode 100644 target/loongarch/insns.decode create mode 100644 target/loongarch/internals.h create mode 100644 target/loongarch/iocsr_helper.c create mode 100644 target/loongarch/machine.c create mode 100644 target/loongarch/meson.build create mode 100644 target/loongarch/op_helper.c create mode 100644 target/loongarch/tlb_helper.c create mode 100644 target/loongarch/translate.c create mode 100644 target/loongarch/translate.h create mode 100644 tests/tcg/loongarch64/Makefile.softmmu-target create mode 100644 tests/tcg/loongarch64/system/boot.S create mode 100644 tests/tcg/loongarch64/system/kernel.ld create mode 100644 tests/tcg/loongarch64/system/regdef.h
Signature · 1 line
2.31.1
PATCH v3 1/43 target/loongarch: Add README
From: Song Gao <[email protected]>
This patch gives an introduction to the LoongArch target.
--- MAINTAINERS | 6 ++++++ target/loongarch/README | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 target/loongarch/README
MAINTAINERS +6 -0
@@ -213,6 +213,12 @@ S: Maintained F: target/hppa/ F: disas/hppa.c +LoongArch TCG CPUs +M: Song Gao <[email protected]> +M: Xiaojuan Yang <[email protected]> +S: Maintained +F: target/loongarch/ + M68K TCG CPUs M: Laurent Vivier <[email protected]> S: Maintained
target/loongarch/README new file +10 -0
@@ -0,0 +1,10 @@ +- Introduction + + LoongArch is the general processor architecture of Loongson. + + The following versions of the LoongArch core are supported + core: 3A5000 + https://github.com/loongson/LoongArch-Documentation/releases/download/2021.08.17/LoongArch-Vol1-v1.00-EN.pdf + + We can get the latest loongarch documents at https://github.com/loongson/LoongArch-Documentation/tags. +
Signature · 1 line
2.31.1
PATCH v3 2/43 target/loongarch: Add core definition
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This patch adds target state header, target definitions and initialization routines.
--- target/loongarch/cpu-param.h | 18 ++ target/loongarch/cpu.c | 324 +++++++++++++++++++++++++++++++++++ target/loongarch/cpu.h | 243 ++++++++++++++++++++++++++ target/loongarch/internals.h | 21 +++ 4 files changed, 606 insertions(+) create mode 100644 target/loongarch/cpu-param.h create mode 100644 target/loongarch/cpu.c create mode 100644 target/loongarch/cpu.h create mode 100644 target/loongarch/internals.h
target/loongarch/cpu-param.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch CPU parameters for QEMU. +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef LOONGARCH_CPU_PARAM_H +#define LOONGARCH_CPU_PARAM_H + +#define TARGET_LONG_BITS 64 +#define TARGET_PHYS_ADDR_SPACE_BITS 48 +#define TARGET_VIRT_ADDR_SPACE_BITS 48 + +#define TARGET_PAGE_BITS 14 +#define NB_MMU_MODES 4 + +#endif
target/loongarch/cpu.c new file +324 -0
324 lines not on this page · raw message
target/loongarch/cpu.h new file +243 -0
243 lines not on this page · raw message
target/loongarch/internals.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QEMU LoongArch CPU -- internal functions and types +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef LOONGARCH_INTERNALS_H +#define LOONGARCH_INTERNALS_H + +void loongarch_translate_init (void ); + +void loongarch_cpu_dump_state (CPUState *cpu,FILE *f,int flags); + +void G_NORETURN do_raise_exception(CPULoongArchState *env, +uint32_t exception, +uintptr_t pc); + +const char *loongarch_exception_name (int32_t exception); + +#endif
Signature · 1 line
2.31.1
Re: [PATCH v3 02/43] target/loongarch: Add core definition
Quoted 1 line · Xiaojuan Yang
+
DEFINE_LOONGARCH_CPU_TYPE("Loongson-3A5000", loongarch_3a5000_initfn),
Follow up on the comments against patch 34, and reading the 3A5000 manual, I see
# On-chip integration of four 64-bit quad-launch superscalar GS464v processor cores.
Therefore it would seem that the cpu core here in target/loongarch/ should be named "gs464v", and the 3A5000 name should be reserved for the cpu package over in hw/loongarch/.
r~
Re: [PATCH v3 02/43] target/loongarch: Add core definition
Quoted 9 lines · Richard Henderson
Quoted 1 line · Xiaojuan Yang
+
DEFINE_LOONGARCH_CPU_TYPE("Loongson-3A5000", loongarch_3a5000_initfn),Follow up on the comments against patch 34, and reading the 3A5000 manual, I see
# On-chip integration of four 64-bit quad-launch superscalar GS464v processor cores.
Therefore it would seem that the cpu core here in target/loongarch/ should be named "gs464v", and the 3A5000 name should be reserved for the cpu package over in hw/loongarch/.
OK, the lastest manual [1] the cpu core named ' LA464', I will correct it on v4.
[1] : https://loongson.github.io/LoongArch-Documentation/Loongson-3A5000-usermanual-EN.pdf
Thanks.
Xiaojuan
PATCH v3 3/43 target/loongarch: Add main translation routines
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This patch adds main translation routines and
basic functions for translation.
--- target/loongarch/helper.h | 6 ++ target/loongarch/op_helper.c | 21 +++++ target/loongarch/translate.c | 160 +++++++++++++++++++++++++++++++++++ target/loongarch/translate.h | 26 ++++++ 4 files changed, 213 insertions(+) create mode 100644 target/loongarch/helper.h create mode 100644 target/loongarch/op_helper.c create mode 100644 target/loongarch/translate.c create mode 100644 target/loongarch/translate.h
target/loongarch/helper.h new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +DEF_HELPER_2 (raise_exception, noreturn, env, i32)
target/loongarch/op_helper.c new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch emulation helpers for QEMU. +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "cpu.h" +#include "qemu/host-utils.h" +#include "exec/helper-proto.h" +#include "exec/exec-all.h" +#include "exec/cpu_ldst.h" +#include "internals.h" + +/* Exceptions helpers */ +void helper_raise_exception (CPULoongArchState *env,uint32_t exception) +{ +do_raise_exception (env, exception,GETPC ()); +}
target/loongarch/translate.c new file +160 -0
160 lines not on this page · raw message
target/loongarch/translate.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch translation routines. +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef TARGET_LOONGARCH_TRANSLATE_H +#define TARGET_LOONGARCH_TRANSLATE_H + +#include "exec/translator.h" + +typedef struct DisasContext { +DisasContextBase base; +target_ulong page_start; +uint32_t opcode; +int mem_idx; +}DisasContext ; + +void generate_exception (DisasContext *ctx,int excp); + +extern TCGv cpu_gpr[32 ], cpu_pc; +extern TCGv_i32 cpu_fscr0; +extern TCGv_i64 cpu_fpr[32 ]; + +#endif
Signature · 1 line
2.31.1
PATCH v3 4/43 target/loongarch: Add fixed point arithmetic instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- ADD.{W/D}, SUB.{W/D}
- ADDI.{W/D}, ADDU16ID
- ALSL.{W[U]/D}
- LU12I.W, LU32I.D LU52I.D
- SLT[U], SLT[U]I
- PCADDI, PCADDU12I, PCADDU18I, PCALAU12I
- AND, OR, NOR, XOR, ANDN, ORN
- MUL.{W/D}, MULH.{W[U]/D[U]}
- MULW.D.W[U]
- DIV.{W[U]/D[U]}, MOD.{W[U]/D[U]}
- ANDI, ORI, XORI
--- target/loongarch/insn_trans/trans_arith.c.inc | 304 ++++++++++++++++++ target/loongarch/insns.decode | 79 +++++ target/loongarch/translate.c | 83 +++++ target/loongarch/translate.h | 19 ++ 4 files changed, 485 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_arith.c.inc create mode 100644 target/loongarch/insns.decode
target/loongarch/insn_trans/trans_arith.c.inc new file +304 -0
@@ -0,0 +1,304 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +static bool gen_rrr(DisasContext *ctx, arg_rrr *a, + DisasExtend src1_ext, DisasExtend src2_ext, + DisasExtend dst_ext, void (*func)(TCGv, TCGv, TCGv)) +{ + TCGv dest = gpr_dst(ctx, a->rd, dst_ext); + TCGv src1 = gpr_src(ctx, a->rj, src1_ext); + TCGv src2 = gpr_src(ctx, a->rk, src2_ext); + + func(dest, src1, src2); + gen_set_gpr(a->rd, dest, dst_ext); + + return true; +} + +static bool gen_rri_v(DisasContext *ctx, arg_rr_i *a, + DisasExtend src_ext, DisasExtend dst_ext, + void (*func)(TCGv, TCGv, TCGv)) +{ + TCGv dest = gpr_dst(ctx, a->rd, dst_ext); + TCGv src1 = gpr_src(ctx, a->rj, src_ext); + TCGv src2 = tcg_constant_tl(a->imm); + + func(dest, src1, src2); + gen_set_gpr(a->rd, dest, dst_ext); + + return true; +} + +static bool gen_rri_c(DisasContext *ctx, arg_rr_i *a, + DisasExtend src_ext, DisasExtend dst_ext, + void (*func)(TCGv, TCGv, target_long)) +{ + TCGv dest = gpr_dst(ctx, a->rd, dst_ext); + TCGv src1 = gpr_src(ctx, a->rj, src_ext); + + func(dest, src1, a->imm); + gen_set_gpr(a->rd, dest, dst_ext); + + return true; +} + +static bool gen_rrr_sa(DisasContext *ctx, arg_rrr_sa *a, + DisasExtend src_ext, DisasExtend dst_ext, + void (*func)(TCGv, TCGv, TCGv, target_long)) +{ + TCGv dest = gpr_dst(ctx, a->rd, dst_ext); + TCGv src1 = gpr_src(ctx, a->rj, src_ext); + TCGv src2 = gpr_src(ctx, a->rk, src_ext); + + func(dest, src1, src2, a->sa); + gen_set_gpr(a->rd, dest, dst_ext); + + return true; +} + +static bool trans_lu12i_w(DisasContext *ctx, arg_lu12i_w *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + + tcg_gen_movi_tl(dest, a->imm << 12); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +static bool gen_pc(DisasContext *ctx, arg_r_i *a, + target_ulong (*func)(target_ulong, int)) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + target_ulong addr = func(ctx->base.pc_next, a->imm); + + tcg_gen_movi_tl(dest, addr); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +static void gen_slt(TCGv dest, TCGv src1, TCGv src2) +{ + tcg_gen_setcond_tl(TCG_COND_LT, dest, src1, src2); +} + +static void gen_sltu(TCGv dest, TCGv src1, TCGv src2) +{ + tcg_gen_setcond_tl(TCG_COND_LTU, dest, src1, src2); +} + +static void gen_mulh_w(TCGv dest, TCGv src1, TCGv src2) +{ + tcg_gen_mul_i64(dest, src1, src2); + tcg_gen_sari_i64(dest, dest, 32); +} + +static void gen_mulh_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv discard = tcg_temp_new(); + tcg_gen_muls2_tl(discard, dest, src1, src2); + tcg_temp_free(discard); +} + +static void gen_mulh_du(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv discard = tcg_temp_new(); + tcg_gen_mulu2_tl(discard, dest, src1, src2); + tcg_temp_free(discard); +} + +static void prep_divisor_d(TCGv ret, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + TCGv t1 = tcg_temp_new(); + TCGv zero = tcg_constant_tl(0); + + /* + * If min / -1, set the divisor to 1. + * This avoids potential host overflow trap and produces min. + * If x / 0, set the divisor to 1. + * This avoids potential host overflow trap; + * the required result is undefined. + */ + tcg_gen_setcondi_tl(TCG_COND_EQ, ret, src1, INT64_MIN); + tcg_gen_setcondi_tl(TCG_COND_EQ, t0, src2, -1); + tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src2, 0); + tcg_gen_and_tl(ret, ret, t0); + tcg_gen_or_tl(ret, ret, t1); + tcg_gen_movcond_tl(TCG_COND_NE, ret, ret, zero, ret, src2); + + tcg_temp_free(t0); + tcg_temp_free(t1); +} + +static void prep_divisor_du(TCGv ret, TCGv src2) +{ + TCGv zero = tcg_constant_tl(0); + TCGv one = tcg_constant_tl(1); + + /* + * If x / 0, set the divisor to 1. + * This avoids potential host overflow trap; + * the required result is undefined. + */ + tcg_gen_movcond_tl(TCG_COND_EQ, ret, src2, zero, one, src2); +} + +static void gen_div_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + prep_divisor_d(t0, src1, src2); + tcg_gen_div_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_rem_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + prep_divisor_d(t0, src1, src2); + tcg_gen_rem_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_div_du(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + prep_divisor_du(t0, src2); + tcg_gen_divu_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_rem_du(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + prep_divisor_du(t0, src2); + tcg_gen_remu_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_div_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + /* We need not check for integer overflow for div_w. */ + prep_divisor_du(t0, src2); + tcg_gen_div_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_rem_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + /* We need not check for integer overflow for rem_w. */ + prep_divisor_du(t0, src2); + tcg_gen_rem_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_alsl(TCGv dest, TCGv src1, TCGv src2, target_long sa) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_shli_tl(t0, src1, sa); + tcg_gen_add_tl(dest, t0, src2); + tcg_temp_free(t0); +} + +static bool trans_lu32i_d(DisasContext *ctx, arg_lu32i_d *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rd, EXT_NONE); + TCGv src2 = tcg_constant_tl(a->imm); + + tcg_gen_deposit_tl(dest, src1, src2, 32, 32); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +static bool trans_lu52i_d(DisasContext *ctx, arg_lu52i_d *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = tcg_constant_tl(a->imm); + + tcg_gen_deposit_tl(dest, src1, src2, 52, 12); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +static target_ulong gen_pcaddi(target_ulong pc, int imm) +{ + return pc + (imm << 2); +} + +static target_ulong gen_pcalau12i(target_ulong pc, int imm) +{ + return (pc + (imm << 12)) & ~0xfff; +} + +static target_ulong gen_pcaddu12i(target_ulong pc, int imm) +{ + return pc + (imm << 12); +} + +static target_ulong gen_pcaddu18i(target_ulong pc, int imm) +{ + return pc + ((target_ulong)(imm) << 18); +} + +static bool trans_addu16i_d(DisasContext *ctx, arg_addu16i_d *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + + tcg_gen_addi_tl(dest, src1, a->imm << 16); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +TRANS(add_w, gen_rrr, EXT_NONE, EXT_NONE, EXT_SIGN, tcg_gen_add_tl) +TRANS(add_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_add_tl) +TRANS(sub_w, gen_rrr, EXT_NONE, EXT_NONE, EXT_SIGN, tcg_gen_sub_tl) +TRANS(sub_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_sub_tl) +TRANS(and, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_and_tl) +TRANS(or, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_or_tl) +TRANS(xor, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_xor_tl) +TRANS(nor, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_nor_tl) +TRANS(andn, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_andc_tl) +TRANS(orn, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_orc_tl) +TRANS(slt, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_slt) +TRANS(sltu, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_sltu) +TRANS(mul_w, gen_rrr, EXT_SIGN, EXT_SIGN, EXT_SIGN, tcg_gen_mul_tl) +TRANS(mul_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, tcg_gen_mul_tl) +TRANS(mulh_w, gen_rrr, EXT_SIGN, EXT_SIGN, EXT_NONE, gen_mulh_w) +TRANS(mulh_wu, gen_rrr, EXT_ZERO, EXT_ZERO, EXT_NONE, gen_mulh_w) +TRANS(mulh_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_mulh_d) +TRANS(mulh_du, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_mulh_du) +TRANS(mulw_d_w, gen_rrr, EXT_SIGN, EXT_SIGN, EXT_NONE, tcg_gen_mul_tl) +TRANS(mulw_d_wu, gen_rrr, EXT_ZERO, EXT_ZERO, EXT_NONE, tcg_gen_mul_tl) +TRANS(div_w, gen_rrr, EXT_SIGN, EXT_SIGN, EXT_SIGN, gen_div_w) +TRANS(mod_w, gen_rrr, EXT_SIGN, EXT_SIGN, EXT_SIGN, gen_rem_w) +TRANS(div_wu, gen_rrr, EXT_ZERO, EXT_ZERO, EXT_SIGN, gen_div_du) +TRANS(mod_wu, gen_rrr, EXT_ZERO, EXT_ZERO, EXT_SIGN, gen_rem_du) +TRANS(div_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_div_d) +TRANS(mod_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_rem_d) +TRANS(div_du, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_div_du) +TRANS(mod_du, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_rem_du) +TRANS(slti, gen_rri_v, EXT_NONE, EXT_NONE, gen_slt) +TRANS(sltui, gen_rri_v, EXT_NONE, EXT_NONE, gen_sltu) +TRANS(addi_w, gen_rri_c, EXT_NONE, EXT_SIGN, tcg_gen_addi_tl) +TRANS(addi_d, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_addi_tl) +TRANS(alsl_w, gen_rrr_sa, EXT_NONE, EXT_SIGN, gen_alsl) +TRANS(alsl_wu, gen_rrr_sa, EXT_NONE, EXT_ZERO, gen_alsl) +TRANS(alsl_d, gen_rrr_sa, EXT_NONE, EXT_NONE, gen_alsl) +TRANS(pcaddi, gen_pc, gen_pcaddi) +TRANS(pcalau12i, gen_pc, gen_pcalau12i) +TRANS(pcaddu12i, gen_pc, gen_pcaddu12i) +TRANS(pcaddu18i, gen_pc, gen_pcaddu18i) +TRANS(andi, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_andi_tl) +TRANS(ori, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_ori_tl) +TRANS(xori, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_xori_tl)
target/loongarch/insns.decode new file +79 -0
79 lines not on this page · raw message
target/loongarch/translate.c +83 -0
107 lines not on this page · raw message
target/loongarch/translate.h +19 -0
@@ -10,11 +10,30 @@#include "exec/translator.h" +#define TRANS (NAME ,FUNC , ...) \ + static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \ + { return FUNC(ctx, a, __VA_ARGS__); } + +/* +* If an operation is being performed on less than TARGET_LONG_BITS, +* it may require the inputs to be sign- or zero-extended; which will +* depend on the exact operation being performed. +*/ +typedef enum { +EXT_NONE , +EXT_SIGN , +EXT_ZERO , +}DisasExtend ; +typedef struct DisasContext {DisasContextBase base;target_ulong page_start;uint32_t opcode;int mem_idx; +TCGv zero; +/* Space for 3 operands plus 1 extra for address computation. */ +TCGv temp[4 ]; +uint8_t ntemp; }DisasContext ;void generate_exception (DisasContext *ctx,int excp);
Signature · 1 line
2.31.1
PATCH v3 5/43 target/loongarch: Add fixed point shift instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- SLL.W, SRL.W, SRA.W, ROTR.W
- SLLI.W, SRLI.W, SRAI.W, ROTRI.W
- SLL.D, SRL.D, SRA.D, ROTR.D
- SLLI.D, SRLI.D, SRAI.D, ROTRI.D
--- target/loongarch/insn_trans/trans_shift.c.inc | 106 ++++++++++++++++++ target/loongarch/insns.decode | 22 ++++ target/loongarch/translate.c | 1 + 3 files changed, 129 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_shift.c.inc
target/loongarch/insn_trans/trans_shift.c.inc new file +106 -0
@@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +static void gen_sll_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x1f); + tcg_gen_shl_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_srl_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x1f); + tcg_gen_shr_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_sra_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x1f); + tcg_gen_sar_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_sll_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x3f); + tcg_gen_shl_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_srl_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x3f); + tcg_gen_shr_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_sra_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x3f); + tcg_gen_sar_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static void gen_rotr_w(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv_i32 t1 = tcg_temp_new_i32(); + TCGv_i32 t2 = tcg_temp_new_i32(); + TCGv t0 = tcg_temp_new(); + + tcg_gen_andi_tl(t0, src2, 0x1f); + + tcg_gen_trunc_tl_i32(t1, src1); + tcg_gen_trunc_tl_i32(t2, t0); + + tcg_gen_rotr_i32(t1, t1, t2); + tcg_gen_ext_i32_tl(dest, t1); + + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t2); + tcg_temp_free(t0); +} + +static void gen_rotr_d(TCGv dest, TCGv src1, TCGv src2) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_andi_tl(t0, src2, 0x3f); + tcg_gen_rotr_tl(dest, src1, t0); + tcg_temp_free(t0); +} + +static bool trans_srai_w(DisasContext *ctx, arg_srai_w *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_ZERO); + + tcg_gen_sextract_tl(dest, src1, a->imm, 32 - a->imm); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +TRANS(sll_w, gen_rrr, EXT_ZERO, EXT_NONE, EXT_SIGN, gen_sll_w) +TRANS(srl_w, gen_rrr, EXT_ZERO, EXT_NONE, EXT_SIGN, gen_srl_w) +TRANS(sra_w, gen_rrr, EXT_SIGN, EXT_NONE, EXT_SIGN, gen_sra_w) +TRANS(sll_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_sll_d) +TRANS(srl_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_srl_d) +TRANS(sra_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_sra_d) +TRANS(rotr_w, gen_rrr, EXT_ZERO, EXT_NONE, EXT_SIGN, gen_rotr_w) +TRANS(rotr_d, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_rotr_d) +TRANS(slli_w, gen_rri_c, EXT_NONE, EXT_SIGN, tcg_gen_shli_tl) +TRANS(slli_d, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_shli_tl) +TRANS(srli_w, gen_rri_c, EXT_ZERO, EXT_SIGN, tcg_gen_shri_tl) +TRANS(srli_d, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_shri_tl) +TRANS(srai_d, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_sari_tl) +TRANS(rotri_w, gen_rri_v, EXT_NONE, EXT_NONE, gen_rotr_w) +TRANS(rotri_d, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_rotri_tl)
target/loongarch/insns.decode +22 -0
@@ -23,6 +23,8 @@ # @rrr .... ........ ..... rk:5 rj:5 rd:5 &rrr @r_i20 .... ... imm:s20 rd:5 &r_i +@rr_ui5 .... ........ ..... imm:5 rj:5 rd:5 &rr_i +@rr_ui6 .... ........ .... imm:6 rj:5 rd:5 &rr_i @rr_i12 .... ...... imm:s12 rj:5 rd:5 &rr_i @rr_ui12 .... ...... imm:12 rj:5 rd:5 &rr_i @rr_i16 .... .. imm:s16 rj:5 rd:5 &rr_i
@@ -77,3 +79,23 @@ addu16i_d 0001 00 ................ ..... ..... @rr_i16 andi 0000 001101 ............ ..... ..... @rr_ui12 ori 0000 001110 ............ ..... ..... @rr_ui12 xori 0000 001111 ............ ..... ..... @rr_ui12 + +# +# Fixed point shift operation instruction +# +sll_w 0000 00000001 01110 ..... ..... ..... @rrr +srl_w 0000 00000001 01111 ..... ..... ..... @rrr +sra_w 0000 00000001 10000 ..... ..... ..... @rrr +sll_d 0000 00000001 10001 ..... ..... ..... @rrr +srl_d 0000 00000001 10010 ..... ..... ..... @rrr +sra_d 0000 00000001 10011 ..... ..... ..... @rrr +rotr_w 0000 00000001 10110 ..... ..... ..... @rrr +rotr_d 0000 00000001 10111 ..... ..... ..... @rrr +slli_w 0000 00000100 00001 ..... ..... ..... @rr_ui5 +slli_d 0000 00000100 0001 ...... ..... ..... @rr_ui6 +srli_w 0000 00000100 01001 ..... ..... ..... @rr_ui5 +srli_d 0000 00000100 0101 ...... ..... ..... @rr_ui6 +srai_w 0000 00000100 10001 ..... ..... ..... @rr_ui5 +srai_d 0000 00000100 1001 ...... ..... ..... @rr_ui6 +rotri_w 0000 00000100 11001 ..... ..... ..... @rr_ui5 +rotri_d 0000 00000100 1101 ...... ..... ..... @rr_ui6
target/loongarch/translate.c +1 -0
@@ -146,6 +146,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "decode-insns.c.inc" #include "insn_trans/trans_arith.c.inc" +#include "insn_trans/trans_shift.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 6/43 target/loongarch: Add fixed point bit instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- EXT.W.{B/H}
- CL{O/Z}.{W/D}, CT{O/Z}.{W/D}
- BYTEPICK.{W/D}
- REVB.{2H/4H/2W/D}
- REVH.{2W/D}
- BITREV.{4B/8B}, BITREV.{W/D}
- BSTRINS.{W/D}, BSTRPICK.{W/D}
- MASKEQZ, MASKNEZ
--- target/loongarch/helper.h | 4 + target/loongarch/insn_trans/trans_bit.c.inc | 212 ++++++++++++++++++++ target/loongarch/insns.decode | 39 ++++ target/loongarch/op_helper.c | 21 ++ target/loongarch/translate.c | 1 + 5 files changed, 277 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_bit.c.inc
target/loongarch/helper.h +4 -0
@@ -4,3 +4,7 @@*/ DEF_HELPER_2(raise_exception, noreturn, env, i32) + +DEF_HELPER_FLAGS_1(bitrev_w, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(bitrev_d, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1 (bitswap,TCG_CALL_NO_RWG_SE , tl, tl)
target/loongarch/insn_trans/trans_bit.c.inc new file +212 -0
212 lines not on this page · raw message
target/loongarch/insns.decode +39 -0
@@ -14,13 +14,16 @@ # Argument sets # &r_i rd imm +&rr rd rj &rrr rd rj rk &rr_i rd rj imm &rrr_sa rd rj rk sa +&rr_ms_ls rd rj ms ls # # Formats # +@rr .... ........ ..... ..... rj:5 rd:5 &rr @rrr .... ........ ..... rk:5 rj:5 rd:5 &rrr @r_i20 .... ... imm:s20 rd:5 &r_i @rr_ui5 .... ........ ..... imm:5 rj:5 rd:5 &rr_i
@@ -29,6 +32,10 @@ @rr_ui12 .... ...... imm:12 rj:5 rd:5 &rr_i @rr_i16 .... .. imm:s16 rj:5 rd:5 &rr_i @rrr_sa2p1 .... ........ ... .. rk:5 rj:5 rd:5 &rrr_sa sa=%sa2p1 +@rrr_sa2 .... ........ ... sa:2 rk:5 rj:5 rd:5 &rrr_sa +@rrr_sa3 .... ........ .. sa:3 rk:5 rj:5 rd:5 &rrr_sa +@rr_2bw .... ....... ms:5 . ls:5 rj:5 rd:5 &rr_ms_ls +@rr_2bd .... ...... ms:6 ls:6 rj:5 rd:5 &rr_ms_ls # # Fixed point arithmetic operation instruction
@@ -99,3 +106,35 @@ srai_w 0000 00000100 10001 ..... ..... ..... @rr_ui5 srai_d 0000 00000100 1001 ...... ..... ..... @rr_ui6 rotri_w 0000 00000100 11001 ..... ..... ..... @rr_ui5 rotri_d 0000 00000100 1101 ...... ..... ..... @rr_ui6 + +# +# Fixed point bit operation instruction +# +ext_w_h 0000 00000000 00000 10110 ..... ..... @rr +ext_w_b 0000 00000000 00000 10111 ..... ..... @rr +clo_w 0000 00000000 00000 00100 ..... ..... @rr +clz_w 0000 00000000 00000 00101 ..... ..... @rr +cto_w 0000 00000000 00000 00110 ..... ..... @rr +ctz_w 0000 00000000 00000 00111 ..... ..... @rr +clo_d 0000 00000000 00000 01000 ..... ..... @rr +clz_d 0000 00000000 00000 01001 ..... ..... @rr +cto_d 0000 00000000 00000 01010 ..... ..... @rr +ctz_d 0000 00000000 00000 01011 ..... ..... @rr +revb_2h 0000 00000000 00000 01100 ..... ..... @rr +revb_4h 0000 00000000 00000 01101 ..... ..... @rr +revb_2w 0000 00000000 00000 01110 ..... ..... @rr +revb_d 0000 00000000 00000 01111 ..... ..... @rr +revh_2w 0000 00000000 00000 10000 ..... ..... @rr +revh_d 0000 00000000 00000 10001 ..... ..... @rr +bitrev_4b 0000 00000000 00000 10010 ..... ..... @rr +bitrev_8b 0000 00000000 00000 10011 ..... ..... @rr +bitrev_w 0000 00000000 00000 10100 ..... ..... @rr +bitrev_d 0000 00000000 00000 10101 ..... ..... @rr +bytepick_w 0000 00000000 100 .. ..... ..... ..... @rrr_sa2 +bytepick_d 0000 00000000 11 ... ..... ..... ..... @rrr_sa3 +maskeqz 0000 00000001 00110 ..... ..... ..... @rrr +masknez 0000 00000001 00111 ..... ..... ..... @rrr +bstrins_w 0000 0000011 ..... 0 ..... ..... ..... @rr_2bw +bstrpick_w 0000 0000011 ..... 1 ..... ..... ..... @rr_2bw +bstrins_d 0000 000010 ...... ...... ..... ..... @rr_2bd +bstrpick_d 0000 000011 ...... ...... ..... ..... @rr_2bd
target/loongarch/op_helper.c +21 -0
@@ -19,3 +19,24 @@ void helper_raise_exception(CPULoongArchState *env, uint32_t exception) {do_raise_exception (env, exception,GETPC ()); } + +target_ulong helper_bitrev_w (target_ulong rj) +{ +return (int32_t )revbit32 (rj); +} + +target_ulong helper_bitrev_d (target_ulong rj) +{ +return revbit64 (rj); +} + +target_ulong helper_bitswap (target_ulong v) +{ + v = ((v >>1 ) & (target_ulong )0x5555555555555555ULL ) | + ((v & (target_ulong )0x5555555555555555ULL ) <<1 ); + v = ((v >>2 ) & (target_ulong )0x3333333333333333ULL ) | + ((v & (target_ulong )0x3333333333333333ULL ) <<2 ); + v = ((v >>4 ) & (target_ulong )0x0F0F0F0F0F0F0F0FULL ) | + ((v & (target_ulong )0x0F0F0F0F0F0F0F0FULL ) <<4 ); +return v; +}
target/loongarch/translate.c +1 -0
@@ -147,6 +147,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "decode-insns.c.inc" #include "insn_trans/trans_arith.c.inc" #include "insn_trans/trans_shift.c.inc" +#include "insn_trans/trans_bit.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 7/43 target/loongarch: Add fixed point load/store instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- LD.{B[U]/H[U]/W[U]/D}, ST.{B/H/W/D}
- LDX.{B[U]/H[U]/W[U]/D}, STX.{B/H/W/D}
- LDPTR.{W/D}, STPTR.{W/D}
- PRELD
- LD{GT/LE}.{B/H/W/D}, ST{GT/LE}.{B/H/W/D}
- DBAR, IBAR
--- target/loongarch/helper.h | 3 + .../loongarch/insn_trans/trans_memory.c.inc | 229 ++++++++++++++++++ target/loongarch/insns.decode | 55 +++++ target/loongarch/op_helper.c | 15 ++ target/loongarch/translate.c | 6 + 5 files changed, 308 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_memory.c.inc
target/loongarch/helper.h +3 -0
@@ -8,3 +8,6 @@ DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_FLAGS_1(bitrev_w, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(bitrev_d, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl) + +DEF_HELPER_FLAGS_3(asrtle_d, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3 (asrtgt_d,TCG_CALL_NO_WG , void, env, tl, tl)
target/loongarch/insn_trans/trans_memory.c.inc new file +229 -0
229 lines not on this page · raw message
target/loongarch/insns.decode +55 -0
86 lines not on this page · raw message
target/loongarch/op_helper.c +15 -0
@@ -40,3 +40,18 @@ target_ulong helper_bitswap(target_ulong v) ((v & (target_ulong )0x0F0F0F0F0F0F0F0FULL ) <<4 );return v; } + +/* loongarch assert op */ +void helper_asrtle_d (CPULoongArchState *env,target_ulong rj,target_ulong rk) +{ +if (rj > rk) { +do_raise_exception (env,EXCCODE_ADEM ,GETPC ()); + } +} + +void helper_asrtgt_d (CPULoongArchState *env,target_ulong rj,target_ulong rk) +{ +if (rj <= rk) { +do_raise_exception (env,EXCCODE_ADEM ,GETPC ()); + } +}
target/loongarch/translate.c +6 -0
@@ -31,6 +31,11 @@ static inline int plus_1(DisasContext *ctx, int x)return x +1 ; } +static inline int shl_2 (DisasContext *ctx,int x) +{ +return x <<2 ; +} +void generate_exception (DisasContext *ctx,int excp) {tcg_gen_movi_tl (cpu_pc, ctx->base.pc_next);
@@ -148,6 +153,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_arith.c.inc" #include "insn_trans/trans_shift.c.inc" #include "insn_trans/trans_bit.c.inc" +#include "insn_trans/trans_memory.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 8/43 target/loongarch: Add fixed point atomic instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- LL.{W/D}, SC.{W/D}
- AM{SWAP/ADD/AND/OR/XOR/MAX/MIN}[_DB].{W/D}
- AM{MAX/MIN}[_DB].{WU/DU}
--- .../loongarch/insn_trans/trans_atomic.c.inc | 113 ++++++++++++++++++ .../loongarch/insn_trans/trans_memory.c.inc | 2 +- target/loongarch/insns.decode | 44 +++++++ target/loongarch/translate.c | 1 + 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 target/loongarch/insn_trans/trans_atomic.c.inc
target/loongarch/insn_trans/trans_atomic.c.inc new file +113 -0
@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +static bool gen_ll(DisasContext *ctx, arg_rr_i *a, MemOp mop) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv t0 = tcg_temp_new(); + + tcg_gen_addi_tl(t0, src1, a->imm); + tcg_gen_qemu_ld_i64(dest, t0, ctx->mem_idx, mop); + tcg_gen_st_tl(t0, cpu_env, offsetof(CPULoongArchState, lladdr)); + tcg_gen_st_tl(dest, cpu_env, offsetof(CPULoongArchState, llval)); + gen_set_gpr(a->rd, dest, EXT_NONE); + tcg_temp_free(t0); + + return true; +} + +static bool gen_sc(DisasContext *ctx, arg_rr_i *a, MemOp mop) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rd, EXT_NONE); + TCGv t0 = tcg_temp_new(); + TCGv val = tcg_temp_new(); + + TCGLabel *l1 = gen_new_label(); + TCGLabel *done = gen_new_label(); + + tcg_gen_addi_tl(t0, src1, a->imm); + tcg_gen_brcond_tl(TCG_COND_EQ, t0, cpu_lladdr, l1); + tcg_gen_movi_tl(dest, 0); + tcg_gen_br(done); + + gen_set_label(l1); + tcg_gen_mov_tl(val, src2); + /* generate cmpxchg */ + tcg_gen_atomic_cmpxchg_tl(t0, cpu_lladdr, cpu_llval, + val, ctx->mem_idx, mop); + tcg_gen_setcond_tl(TCG_COND_EQ, dest, t0, cpu_llval); + gen_set_label(done); + gen_set_gpr(a->rd, dest, EXT_NONE); + tcg_temp_free(t0); + tcg_temp_free(val); + + return true; +} + +static bool gen_am(DisasContext *ctx, arg_rrr *a, + void (*func)(TCGv, TCGv, TCGv, TCGArg, MemOp), + MemOp mop) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); + TCGv val = gpr_src(ctx, a->rk, EXT_NONE); + + if (a->rd != 0 && (a->rj == a->rd || a->rk == a->rd)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Warning: source register overlaps destination register" + "in atomic insn at pc=0x" TARGET_FMT_lx "\n", + ctx->base.pc_next - 4); + return false; + } + + func(dest, addr, val, ctx->mem_idx, mop); + gen_set_gpr(a->rd, dest, EXT_NONE); + + return true; +} + +TRANS(ll_w, gen_ll, MO_TESL) +TRANS(sc_w, gen_sc, MO_TESL) +TRANS(ll_d, gen_ll, MO_TEUQ) +TRANS(sc_d, gen_sc, MO_TEUQ) +TRANS(amswap_w, gen_am, tcg_gen_atomic_xchg_tl, MO_TESL) +TRANS(amswap_d, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ) +TRANS(amadd_w, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TESL) +TRANS(amadd_d, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ) +TRANS(amand_w, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TESL) +TRANS(amand_d, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ) +TRANS(amor_w, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TESL) +TRANS(amor_d, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ) +TRANS(amxor_w, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TESL) +TRANS(amxor_d, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ) +TRANS(ammax_w, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TESL) +TRANS(ammax_d, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ) +TRANS(ammin_w, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TESL) +TRANS(ammin_d, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ) +TRANS(ammax_wu, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TESL) +TRANS(ammax_du, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ) +TRANS(ammin_wu, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TESL) +TRANS(ammin_du, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ) +TRANS(amswap_db_w, gen_am, tcg_gen_atomic_xchg_tl, MO_TESL) +TRANS(amswap_db_d, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ) +TRANS(amadd_db_w, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TESL) +TRANS(amadd_db_d, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ) +TRANS(amand_db_w, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TESL) +TRANS(amand_db_d, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ) +TRANS(amor_db_w, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TESL) +TRANS(amor_db_d, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ) +TRANS(amxor_db_w, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TESL) +TRANS(amxor_db_d, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ) +TRANS(ammax_db_w, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TESL) +TRANS(ammax_db_d, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ) +TRANS(ammin_db_w, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TESL) +TRANS(ammin_db_d, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ) +TRANS(ammax_db_wu, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TESL) +TRANS(ammax_db_du, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ) +TRANS(ammin_db_wu, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TESL) +TRANS(ammin_db_du, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ)
target/loongarch/insn_trans/trans_memory.c.inc +1 -1
@@ -172,7 +172,7 @@ static bool gen_stptr(DisasContext *ctx, arg_rr_i *a, MemOp mop) if (a->imm) { temp = tcg_temp_new(); - tcg_gen_addi_tl(temp, addr, a->im); + tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; }
target/loongarch/insns.decode +44 -0
47 lines not on this page · raw message
target/loongarch/translate.c +1 -0
@@ -154,6 +154,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_shift.c.inc" #include "insn_trans/trans_bit.c.inc" #include "insn_trans/trans_memory.c.inc" +#include "insn_trans/trans_atomic.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 9/43 target/loongarch: Add fixed point extra instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- CRC[C].W.{B/H/W/D}.W
- SYSCALL
- BREAK
- ASRT{LE/GT}.D
- RDTIME{L/H}.W, RDTIME.D
- CPUCFG
--- target/loongarch/helper.h | 4 ++ target/loongarch/insn_trans/trans_extra.c.inc | 68 +++++++++++++++++++ target/loongarch/insns.decode | 19 ++++++ target/loongarch/op_helper.c | 26 +++++++ target/loongarch/translate.c | 1 + 5 files changed, 118 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_extra.c.inc
target/loongarch/helper.h +4 -0
@@ -11,3 +11,7 @@ DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_3(asrtle_d, TCG_CALL_NO_WG, void, env, tl, tl) DEF_HELPER_FLAGS_3(asrtgt_d, TCG_CALL_NO_WG, void, env, tl, tl) + +DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_2 (cpucfg,TCG_CALL_NO_RWG_SE , tl, env, tl)
target/loongarch/insn_trans/trans_extra.c.inc new file +68 -0
68 lines not on this page · raw message
target/loongarch/insns.decode +19 -0
@@ -17,6 +17,7 @@ &i imm &r_i rd imm &rr rd rj +&rr_jk rj rk &rrr rd rj rk &rr_i rd rj imm &hint_r_i hint rj imm
@@ -28,6 +29,7 @@ # @i15 .... ........ ..... imm:15 &i @rr .... ........ ..... ..... rj:5 rd:5 &rr +@rr_jk .... ........ ..... rk:5 rj:5 ..... &rr_jk @rrr .... ........ ..... rk:5 rj:5 rd:5 &rrr @r_i20 .... ... imm:s20 rd:5 &r_i @rr_ui5 .... ........ ..... imm:5 rj:5 rd:5 &rr_i
@@ -237,3 +239,20 @@ ammax_db_wu 0011 10000111 00000 ..... ..... ..... @rrr ammax_db_du 0011 10000111 00001 ..... ..... ..... @rrr ammin_db_wu 0011 10000111 00010 ..... ..... ..... @rrr ammin_db_du 0011 10000111 00011 ..... ..... ..... @rrr + +# +# Fixed point extra instruction +# +crc_w_b_w 0000 00000010 01000 ..... ..... ..... @rrr +crc_w_h_w 0000 00000010 01001 ..... ..... ..... @rrr +crc_w_w_w 0000 00000010 01010 ..... ..... ..... @rrr +crc_w_d_w 0000 00000010 01011 ..... ..... ..... @rrr +crcc_w_b_w 0000 00000010 01100 ..... ..... ..... @rrr +crcc_w_h_w 0000 00000010 01101 ..... ..... ..... @rrr +crcc_w_w_w 0000 00000010 01110 ..... ..... ..... @rrr +crcc_w_d_w 0000 00000010 01111 ..... ..... ..... @rrr +break 0000 00000010 10100 ............... @i15 +syscall 0000 00000010 10110 ............... @i15 +asrtle_d 0000 00000000 00010 ..... ..... 00000 @rr_jk +asrtgt_d 0000 00000000 00011 ..... ..... 00000 @rr_jk +cpucfg 0000 00000000 00000 11011 ..... ..... @rr
target/loongarch/op_helper.c +26 -0
@@ -13,6 +13,8 @@#include "exec/exec-all.h" #include "exec/cpu_ldst.h" #include "internals.h" +#include "qemu/crc32c.h" +#include <zlib.h> /* Exceptions helpers */ void helper_raise_exception (CPULoongArchState *env,uint32_t exception)
@@ -55,3 +57,27 @@ void helper_asrtgt_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)do_raise_exception (env,EXCCODE_ADEM ,GETPC ()); } } + +target_ulong helper_crc32 (target_ulong val,target_ulong m,uint64_t sz) +{ +uint8_t buf[8 ]; +target_ulong mask = ((sz *8 ) ==64 ) ?-1ULL : ((1ULL << (sz *8 )) -1 ); + + m &= mask; +stq_le_p (buf, m); +return (int32_t ) (crc32 (val ^0xffffffff , buf, sz) ^0xffffffff ); +} + +target_ulong helper_crc32c (target_ulong val,target_ulong m,uint64_t sz) +{ +uint8_t buf[8 ]; +target_ulong mask = ((sz *8 ) ==64 ) ?-1ULL : ((1ULL << (sz *8 )) -1 ); + m &= mask; +stq_le_p (buf, m); +return (int32_t ) (crc32c (val, buf, sz) ^0xffffffff ); +} + +target_ulong helper_cpucfg (CPULoongArchState *env,target_ulong rj) +{ +return rj >21 ?0 : env->cpucfg[rj]; +}
target/loongarch/translate.c +1 -0
@@ -155,6 +155,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_bit.c.inc" #include "insn_trans/trans_memory.c.inc" #include "insn_trans/trans_atomic.c.inc" +#include "insn_trans/trans_extra.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 10/43 target/loongarch: Add floating point arithmetic instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- F{ADD/SUB/MUL/DIV}.{S/D}
- F{MADD/MSUB/NMADD/NMSUB}.{S/D}
- F{MAX/MIN}.{S/D}
- F{MAXA/MINA}.{S/D}
- F{ABS/NEG}.{S/D}
- F{SQRT/RECIP/RSQRT}.{S/D}
- F{SCALEB/LOGB/COPYSIGN}.{S/D}
- FCLASS.{S/D}
--- target/loongarch/cpu.c | 1 + target/loongarch/fpu_helper.c | 403 ++++++++++++++++++ target/loongarch/helper.h | 37 ++ .../loongarch/insn_trans/trans_farith.c.inc | 105 +++++ target/loongarch/insns.decode | 52 +++ target/loongarch/internals.h | 2 + target/loongarch/translate.c | 11 + 7 files changed, 611 insertions(+) create mode 100644 target/loongarch/fpu_helper.c create mode 100644 target/loongarch/insn_trans/trans_farith.c.inc
target/loongarch/cpu.c +1 -0
@@ -196,6 +196,7 @@ static void loongarch_cpu_reset(DeviceState *dev) env->fcsr0_mask =FCSR0_M1 |FCSR0_M2 |FCSR0_M3 ; env->fcsr0 =0x0 ; +restore_fp_status (env); cs->exception_index =-1 ; }
target/loongarch/fpu_helper.c new file +403 -0
403 lines not on this page · raw message
target/loongarch/helper.h +37 -0
@@ -15,3 +15,40 @@ DEF_HELPER_FLAGS_3(asrtgt_d, TCG_CALL_NO_WG, void, env, tl, tl) DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl)DEF_HELPER_FLAGS_2 (cpucfg,TCG_CALL_NO_RWG_SE , tl, env, tl) + +/* Floating-point helper */ +DEF_HELPER_FLAGS_3(fadd_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fadd_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fsub_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fsub_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmul_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmul_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fdiv_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fdiv_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmax_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmax_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmin_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmin_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmaxa_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmaxa_d, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmina_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fmina_d, TCG_CALL_NO_WG, i64, env, i64, i64) + +DEF_HELPER_FLAGS_5(fmuladd_s, TCG_CALL_NO_WG, i64, env, i64, i64, i64, i32) +DEF_HELPER_FLAGS_5(fmuladd_d, TCG_CALL_NO_WG, i64, env, i64, i64, i64, i32) + +DEF_HELPER_FLAGS_3(fscaleb_s, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(fscaleb_d, TCG_CALL_NO_WG, i64, env, i64, i64) + +DEF_HELPER_FLAGS_2(flogb_s, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(flogb_d, TCG_CALL_NO_WG, i64, env, i64) + +DEF_HELPER_FLAGS_2(fsqrt_s, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(fsqrt_d, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(frsqrt_s, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(frsqrt_d, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(frecip_s, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(frecip_d, TCG_CALL_NO_WG, i64, env, i64) + +DEF_HELPER_FLAGS_2(fclass_s, TCG_CALL_NO_RWG_SE, i64, env, i64) +DEF_HELPER_FLAGS_2 (fclass_d,TCG_CALL_NO_RWG_SE , i64, env, i64)
target/loongarch/insn_trans/trans_farith.c.inc new file +105 -0
105 lines not on this page · raw message
target/loongarch/insns.decode +52 -0
67 lines not on this page · raw message
target/loongarch/internals.h +2 -0
@@ -18,4 +18,6 @@ void G_NORETURN do_raise_exception(CPULoongArchState *env,const char *loongarch_exception_name (int32_t exception); +void restore_fp_status (CPULoongArchState *env); +#endif
target/loongarch/translate.c +11 -0
@@ -15,6 +15,7 @@#include "exec/translator.h" #include "exec/log.h" #include "qemu/qemu-print.h" +#include "fpu/softfloat.h" #include "translate.h" #include "internals.h"
@@ -36,6 +37,15 @@ static inline int shl_2(DisasContext *ctx, int x)return x <<2 ; } +/* +* LoongArch the upper 32 bits are undefined ("can be any value"). +* QEMU chooses to nanbox, because it is most likely to show guest bugs early. +*/ +static void gen_nanbox_s (TCGv_i64 out,TCGv_i64 in) +{ +tcg_gen_ori_i64 (out, in,MAKE_64BIT_MASK (32 ,32 )); +} +void generate_exception (DisasContext *ctx,int excp) {tcg_gen_movi_tl (cpu_pc, ctx->base.pc_next);
@@ -156,6 +166,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_memory.c.inc" #include "insn_trans/trans_atomic.c.inc" #include "insn_trans/trans_extra.c.inc" +#include "insn_trans/trans_farith.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 11/43 target/loongarch: Add floating point comparison instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- FCMP.cond.{S/D}
--- target/loongarch/fpu_helper.c | 60 ++++++++++++++++++++ target/loongarch/helper.h | 9 +++ target/loongarch/insn_trans/trans_fcmp.c.inc | 56 ++++++++++++++++++ target/loongarch/insns.decode | 8 +++ target/loongarch/internals.h | 5 ++ target/loongarch/translate.c | 1 + 6 files changed, 139 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_fcmp.c.inc
target/loongarch/fpu_helper.c +60 -0
@@ -401,3 +401,63 @@ uint64_t helper_fmuladd_d(CPULoongArchState *env, uint64_t fj,update_fcsr0 (env,GETPC ());return fd; } + +static uint64_t fcmp_common (CPULoongArchState *env,FloatRelation cmp, +uint32_t flags) +{ +bool ret; + +switch (cmp) { +case float_relation_less: + ret = (flags &FCMP_LT ); +break ; +case float_relation_equal: + ret = (flags &FCMP_EQ ); +break ; +case float_relation_greater: + ret = (flags &FCMP_GT ); +break ; +case float_relation_unordered: + ret = (flags &FCMP_UN ); +break ; +default : +g_assert_not_reached (); + } +update_fcsr0 (env,GETPC ()); + +return ret; +} + +/* fcmp_cXXX_s */ +uint64_t helper_fcmp_c_s (CPULoongArchState *env,uint64_t fj, +uint64_t fk,uint32_t flags) +{ +FloatRelation cmp =float32_compare_quiet ((uint32_t )fj, + (uint32_t )fk, &env->fp_status); +return fcmp_common (env, cmp, flags); +} + +/* fcmp_sXXX_s */ +uint64_t helper_fcmp_s_s (CPULoongArchState *env,uint64_t fj, +uint64_t fk,uint32_t flags) +{ +FloatRelation cmp =float32_compare ((uint32_t )fj, + (uint32_t )fk, &env->fp_status); +return fcmp_common (env, cmp, flags); +} + +/* fcmp_cXXX_d */ +uint64_t helper_fcmp_c_d (CPULoongArchState *env,uint64_t fj, +uint64_t fk,uint32_t flags) +{ +FloatRelation cmp =float64_compare_quiet (fj, fk, &env->fp_status); +return fcmp_common (env, cmp, flags); +} + +/* fcmp_sXXX_d */ +uint64_t helper_fcmp_s_d (CPULoongArchState *env,uint64_t fj, +uint64_t fk,uint32_t flags) +{ +FloatRelation cmp =float64_compare (fj, fk, &env->fp_status); +return fcmp_common (env, cmp, flags); +}
target/loongarch/helper.h +9 -0
@@ -52,3 +52,12 @@ DEF_HELPER_FLAGS_2(frecip_d, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_2(fclass_s, TCG_CALL_NO_RWG_SE, i64, env, i64)DEF_HELPER_FLAGS_2 (fclass_d,TCG_CALL_NO_RWG_SE , i64, env, i64) + +/* fcmp.cXXX.s */ +DEF_HELPER_4 (fcmp_c_s, i64, env, i64, i64, i32) +/* fcmp.sXXX.s */ +DEF_HELPER_4 (fcmp_s_s, i64, env, i64, i64, i32) +/* fcmp.cXXX.d */ +DEF_HELPER_4 (fcmp_c_d, i64, env, i64, i64, i32) +/* fcmp.sXXX.d */ +DEF_HELPER_4 (fcmp_s_d, i64, env, i64, i64, i32)
target/loongarch/insn_trans/trans_fcmp.c.inc new file +56 -0
56 lines not on this page · raw message
target/loongarch/insns.decode +8 -0
@@ -26,6 +26,7 @@ &ff fd fj &fff fd fj fk &ffff fd fj fk fa +&cff_fcond cd fj fk fcond # # Formats
@@ -50,6 +51,7 @@ @ff .... ........ ..... ..... fj:5 fd:5 &ff @fff .... ........ ..... fk:5 fj:5 fd:5 &fff @ffff .... ........ fa:5 fk:5 fj:5 fd:5 &ffff +@cff_fcond .... ........ fcond:5 fk:5 fj:5 .. cd:3 &cff_fcond # # Fixed point arithmetic operation instruction
@@ -308,3 +310,9 @@ fcopysign_s 0000 00010001 00101 ..... ..... ..... @fff fcopysign_d 0000 00010001 00110 ..... ..... ..... @fff fclass_s 0000 00010001 01000 01101 ..... ..... @ff fclass_d 0000 00010001 01000 01110 ..... ..... @ff + +# +# Floating point compare instruction +# +fcmp_cond_s 0000 11000001 ..... ..... ..... 00 ... @cff_fcond +fcmp_cond_d 0000 11000010 ..... ..... ..... 00 ... @cff_fcond
target/loongarch/internals.h +5 -0
@@ -8,6 +8,11 @@#ifndef LOONGARCH_INTERNALS_H #define LOONGARCH_INTERNALS_H +#define FCMP_LT 0b0001/* fp0 < fp1 */ +#define FCMP_EQ 0b0010/* fp0 = fp1 */ +#define FCMP_UN 0b0100/* unordered */ +#define FCMP_GT 0b1000/* fp0 > fp1 */ +void loongarch_translate_init (void );void loongarch_cpu_dump_state (CPUState *cpu,FILE *f,int flags);
target/loongarch/translate.c +1 -0
@@ -167,6 +167,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_atomic.c.inc" #include "insn_trans/trans_extra.c.inc" #include "insn_trans/trans_farith.c.inc" +#include "insn_trans/trans_fcmp.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 12/43 target/loongarch: Add floating point conversion instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- FCVT.S.D, FCVT.D.S
- FFINT.{S/D}.{W/L}, FTINT.{W/L}.{S/D}
- FTINT{RM/RP/RZ/RNE}.{W/L}.{S/D}
- FRINT.{S/D}
--- target/loongarch/fpu_helper.c | 393 +++++++++++++++++++ target/loongarch/helper.h | 29 ++ target/loongarch/insn_trans/trans_fcnv.c.inc | 33 ++ target/loongarch/insns.decode | 32 ++ target/loongarch/translate.c | 1 + 5 files changed, 488 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_fcnv.c.inc
target/loongarch/fpu_helper.c +393 -0
@@ -461,3 +461,396 @@ uint64_t helper_fcmp_s_d(CPULoongArchState *env, uint64_t fj,FloatRelation cmp =float64_compare (fj, fk, &env->fp_status);return fcmp_common (env, cmp, flags); } + +/* floating point conversion */ +uint64_t helper_fcvt_s_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =nanbox_s (float64_to_float32 (fj, &env->fp_status)); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_fcvt_d_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =float32_to_float64 ((uint32_t )fj, &env->fp_status); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ffint_s_w (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =nanbox_s (int32_to_float32 ((int32_t )fj, &env->fp_status)); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ffint_s_l (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =nanbox_s (int64_to_float32 (fj, &env->fp_status)); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ffint_d_w (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =int32_to_float64 ((int32_t )fj, &env->fp_status); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ffint_d_l (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =int64_to_float64 (fj, &env->fp_status); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_frint_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd = (uint64_t )(float32_round_to_int ((uint32_t )fj, &env->fp_status)); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_frint_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =float64_round_to_int (fj, &env->fp_status); +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrm_l_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_down, &env->fp_status); + fd =float64_to_int64 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrm_l_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_down, &env->fp_status); + fd =float32_to_int64 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrm_w_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_down, &env->fp_status); + fd = (uint64_t )float64_to_int32 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrm_w_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_down, &env->fp_status); + fd = (uint64_t )float32_to_int32 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrp_l_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_up, &env->fp_status); + fd =float64_to_int64 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrp_l_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_up, &env->fp_status); + fd =float32_to_int64 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrp_w_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_up, &env->fp_status); + fd = (uint64_t )float64_to_int32 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrp_w_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_up, &env->fp_status); + fd = (uint64_t )float32_to_int32 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrz_l_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + + fd =float64_to_int64_round_to_zero (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrz_l_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + + fd =float32_to_int64_round_to_zero ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrz_w_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + + fd = (uint64_t )float64_to_int32_round_to_zero (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrz_w_s (CPULoongArchState *env,uint64_t fj) +{ +uint32_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + + fd =float32_to_int32_round_to_zero ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return (uint64_t )fd; +} + +uint64_t helper_ftintrne_l_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_nearest_even, &env->fp_status); + fd =float64_to_int64 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrne_l_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_nearest_even, &env->fp_status); + fd =float32_to_int64 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrne_w_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_nearest_even, &env->fp_status); + fd = (uint64_t )float64_to_int32 (fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftintrne_w_s (CPULoongArchState *env,uint64_t fj) +{ +uint32_t fd; +FloatRoundMode old_mode =get_float_rounding_mode (&env->fp_status); + +set_float_rounding_mode (float_round_nearest_even, &env->fp_status); + fd =float32_to_int32 ((uint32_t )fj, &env->fp_status); +set_float_rounding_mode (old_mode, &env->fp_status); + +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return (uint64_t )fd; +} + +uint64_t helper_ftint_l_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =float64_to_int64 (fj, &env->fp_status); +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftint_l_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd =float32_to_int64 ((uint32_t )fj, &env->fp_status); +if (get_float_exception_flags (&env->fp_status) & + (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT64_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftint_w_s (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd = (uint64_t )float32_to_int32 ((uint32_t )fj, &env->fp_status); +if (get_float_exception_flags (&env->fp_status) + & (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +} + +uint64_t helper_ftint_w_d (CPULoongArchState *env,uint64_t fj) +{ +uint64_t fd; + + fd = (uint64_t )float64_to_int32 (fj, &env->fp_status); +if (get_float_exception_flags (&env->fp_status) + & (float_flag_invalid | float_flag_overflow)) { + fd =FLOAT_TO_INT32_OVERFLOW ; + } +update_fcsr0 (env,GETPC ()); +return fd; +}
target/loongarch/helper.h +29 -0
@@ -61,3 +61,32 @@ DEF_HELPER_4(fcmp_s_s, i64, env, i64, i64, i32)DEF_HELPER_4 (fcmp_c_d, i64, env, i64, i64, i32) /* fcmp.sXXX.d */ DEF_HELPER_4(fcmp_s_d, i64, env, i64, i64, i32) + +DEF_HELPER_2(fcvt_d_s, i64, env, i64) +DEF_HELPER_2(fcvt_s_d, i64, env, i64) +DEF_HELPER_2(ffint_d_w, i64, env, i64) +DEF_HELPER_2(ffint_d_l, i64, env, i64) +DEF_HELPER_2(ffint_s_w, i64, env, i64) +DEF_HELPER_2(ffint_s_l, i64, env, i64) +DEF_HELPER_2(ftintrm_l_s, i64, env, i64) +DEF_HELPER_2(ftintrm_l_d, i64, env, i64) +DEF_HELPER_2(ftintrm_w_s, i64, env, i64) +DEF_HELPER_2(ftintrm_w_d, i64, env, i64) +DEF_HELPER_2(ftintrp_l_s, i64, env, i64) +DEF_HELPER_2(ftintrp_l_d, i64, env, i64) +DEF_HELPER_2(ftintrp_w_s, i64, env, i64) +DEF_HELPER_2(ftintrp_w_d, i64, env, i64) +DEF_HELPER_2(ftintrz_l_s, i64, env, i64) +DEF_HELPER_2(ftintrz_l_d, i64, env, i64) +DEF_HELPER_2(ftintrz_w_s, i64, env, i64) +DEF_HELPER_2(ftintrz_w_d, i64, env, i64) +DEF_HELPER_2(ftintrne_l_s, i64, env, i64) +DEF_HELPER_2(ftintrne_l_d, i64, env, i64) +DEF_HELPER_2(ftintrne_w_s, i64, env, i64) +DEF_HELPER_2(ftintrne_w_d, i64, env, i64) +DEF_HELPER_2(ftint_l_s, i64, env, i64) +DEF_HELPER_2(ftint_l_d, i64, env, i64) +DEF_HELPER_2(ftint_w_s, i64, env, i64) +DEF_HELPER_2(ftint_w_d, i64, env, i64) +DEF_HELPER_2(frint_s, i64, env, i64) +DEF_HELPER_2 (frint_d, i64, env, i64)
target/loongarch/insn_trans/trans_fcnv.c.inc new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +TRANS(fcvt_s_d, gen_ff, gen_helper_fcvt_s_d) +TRANS(fcvt_d_s, gen_ff, gen_helper_fcvt_d_s) +TRANS(ftintrm_w_s, gen_ff, gen_helper_ftintrm_w_s) +TRANS(ftintrm_w_d, gen_ff, gen_helper_ftintrm_w_d) +TRANS(ftintrm_l_s, gen_ff, gen_helper_ftintrm_l_s) +TRANS(ftintrm_l_d, gen_ff, gen_helper_ftintrm_l_d) +TRANS(ftintrp_w_s, gen_ff, gen_helper_ftintrp_w_s) +TRANS(ftintrp_w_d, gen_ff, gen_helper_ftintrp_w_d) +TRANS(ftintrp_l_s, gen_ff, gen_helper_ftintrp_l_s) +TRANS(ftintrp_l_d, gen_ff, gen_helper_ftintrp_l_d) +TRANS(ftintrz_w_s, gen_ff, gen_helper_ftintrz_w_s) +TRANS(ftintrz_w_d, gen_ff, gen_helper_ftintrz_w_d) +TRANS(ftintrz_l_s, gen_ff, gen_helper_ftintrz_l_s) +TRANS(ftintrz_l_d, gen_ff, gen_helper_ftintrz_l_d) +TRANS(ftintrne_w_s, gen_ff, gen_helper_ftintrne_w_s) +TRANS(ftintrne_w_d, gen_ff, gen_helper_ftintrne_w_d) +TRANS(ftintrne_l_s, gen_ff, gen_helper_ftintrne_l_s) +TRANS(ftintrne_l_d, gen_ff, gen_helper_ftintrne_l_d) +TRANS(ftint_w_s, gen_ff, gen_helper_ftint_w_s) +TRANS(ftint_w_d, gen_ff, gen_helper_ftint_w_d) +TRANS(ftint_l_s, gen_ff, gen_helper_ftint_l_s) +TRANS(ftint_l_d, gen_ff, gen_helper_ftint_l_d) +TRANS(ffint_s_w, gen_ff, gen_helper_ffint_s_w) +TRANS(ffint_s_l, gen_ff, gen_helper_ffint_s_l) +TRANS(ffint_d_w, gen_ff, gen_helper_ffint_d_w) +TRANS(ffint_d_l, gen_ff, gen_helper_ffint_d_l) +TRANS(frint_s, gen_ff, gen_helper_frint_s) +TRANS(frint_d, gen_ff, gen_helper_frint_d)
target/loongarch/insns.decode +32 -0
@@ -316,3 +316,35 @@ fclass_d 0000 00010001 01000 01110 ..... ..... @ff # fcmp_cond_s 0000 11000001 ..... ..... ..... 00 ... @cff_fcond fcmp_cond_d 0000 11000010 ..... ..... ..... 00 ... @cff_fcond + +# +# Floating point conversion instruction +# +fcvt_s_d 0000 00010001 10010 00110 ..... ..... @ff +fcvt_d_s 0000 00010001 10010 01001 ..... ..... @ff +ftintrm_w_s 0000 00010001 10100 00001 ..... ..... @ff +ftintrm_w_d 0000 00010001 10100 00010 ..... ..... @ff +ftintrm_l_s 0000 00010001 10100 01001 ..... ..... @ff +ftintrm_l_d 0000 00010001 10100 01010 ..... ..... @ff +ftintrp_w_s 0000 00010001 10100 10001 ..... ..... @ff +ftintrp_w_d 0000 00010001 10100 10010 ..... ..... @ff +ftintrp_l_s 0000 00010001 10100 11001 ..... ..... @ff +ftintrp_l_d 0000 00010001 10100 11010 ..... ..... @ff +ftintrz_w_s 0000 00010001 10101 00001 ..... ..... @ff +ftintrz_w_d 0000 00010001 10101 00010 ..... ..... @ff +ftintrz_l_s 0000 00010001 10101 01001 ..... ..... @ff +ftintrz_l_d 0000 00010001 10101 01010 ..... ..... @ff +ftintrne_w_s 0000 00010001 10101 10001 ..... ..... @ff +ftintrne_w_d 0000 00010001 10101 10010 ..... ..... @ff +ftintrne_l_s 0000 00010001 10101 11001 ..... ..... @ff +ftintrne_l_d 0000 00010001 10101 11010 ..... ..... @ff +ftint_w_s 0000 00010001 10110 00001 ..... ..... @ff +ftint_w_d 0000 00010001 10110 00010 ..... ..... @ff +ftint_l_s 0000 00010001 10110 01001 ..... ..... @ff +ftint_l_d 0000 00010001 10110 01010 ..... ..... @ff +ffint_s_w 0000 00010001 11010 00100 ..... ..... @ff +ffint_s_l 0000 00010001 11010 00110 ..... ..... @ff +ffint_d_w 0000 00010001 11010 01000 ..... ..... @ff +ffint_d_l 0000 00010001 11010 01010 ..... ..... @ff +frint_s 0000 00010001 11100 10001 ..... ..... @ff +frint_d 0000 00010001 11100 10010 ..... ..... @ff
target/loongarch/translate.c +1 -0
@@ -168,6 +168,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_extra.c.inc" #include "insn_trans/trans_farith.c.inc" #include "insn_trans/trans_fcmp.c.inc" +#include "insn_trans/trans_fcnv.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 13/43 target/loongarch: Add floating point move instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- FMOV.{S/D}
- FSEL
- MOVGR2FR.{W/D}, MOVGR2FRH.W
- MOVFR2GR.{S/D}, MOVFRH2GR.S
- MOVGR2FCSR, MOVFCSR2GR
- MOVFR2CF, MOVCF2FR
- MOVGR2CF, MOVCF2GR
--- target/loongarch/fpu_helper.c | 6 + target/loongarch/helper.h | 2 + target/loongarch/insn_trans/trans_fmov.c.inc | 157 +++++++++++++++++++ target/loongarch/insns.decode | 37 +++++ target/loongarch/translate.c | 1 + 5 files changed, 203 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_fmov.c.inc
target/loongarch/fpu_helper.c +6 -0
@@ -854,3 +854,9 @@ uint64_t helper_ftint_w_d(CPULoongArchState *env, uint64_t fj)update_fcsr0 (env,GETPC ());return fd; } + +void helper_set_rounding_mode (CPULoongArchState *env,uint32_t fcsr0) +{ +set_float_rounding_mode (ieee_rm[(fcsr0 >>FCSR0_RM ) &0x3 ], + &env->fp_status); +}
target/loongarch/helper.h +2 -0
@@ -90,3 +90,5 @@ DEF_HELPER_2(ftint_w_s, i64, env, i64) DEF_HELPER_2(ftint_w_d, i64, env, i64) DEF_HELPER_2(frint_s, i64, env, i64) DEF_HELPER_2(frint_d, i64, env, i64) + +DEF_HELPER_FLAGS_2 (set_rounding_mode,TCG_CALL_NO_RWG , void, env, i32)
target/loongarch/insn_trans/trans_fmov.c.inc new file +157 -0
157 lines not on this page · raw message
target/loongarch/insns.decode +37 -0
@@ -27,6 +27,15 @@ &fff fd fj fk &ffff fd fj fk fa &cff_fcond cd fj fk fcond +&fffc fd fj fk ca +&fr fd rj +&rf rd fj +&fcsrd_r fcsrd rj +&r_fcsrs rd fcsrs +&cf cd fj +&fc fd cj +&cr cd rj +&rc rd cj # # Formats
@@ -52,6 +61,15 @@ @fff .... ........ ..... fk:5 fj:5 fd:5 &fff @ffff .... ........ fa:5 fk:5 fj:5 fd:5 &ffff @cff_fcond .... ........ fcond:5 fk:5 fj:5 .. cd:3 &cff_fcond +@fffc .... ........ .. ca:3 fk:5 fj:5 fd:5 &fffc +@fr .... ........ ..... ..... rj:5 fd:5 &fr +@rf .... ........ ..... ..... fj:5 rd:5 &rf +@fcsrd_r .... ........ ..... ..... rj:5 fcsrd:5 &fcsrd_r +@r_fcsrs .... ........ ..... ..... fcsrs:5 rd:5 &r_fcsrs +@cf .... ........ ..... ..... fj:5 .. cd:3 &cf +@fc .... ........ ..... ..... .. cj:3 fd:5 &fc +@cr .... ........ ..... ..... rj:5 .. cd:3 &cr +@rc .... ........ ..... ..... .. cj:3 rd:5 &rc # # Fixed point arithmetic operation instruction
@@ -348,3 +366,22 @@ ffint_d_w 0000 00010001 11010 01000 ..... ..... @ff ffint_d_l 0000 00010001 11010 01010 ..... ..... @ff frint_s 0000 00010001 11100 10001 ..... ..... @ff frint_d 0000 00010001 11100 10010 ..... ..... @ff + +# +# Floating point move instruction +# +fmov_s 0000 00010001 01001 00101 ..... ..... @ff +fmov_d 0000 00010001 01001 00110 ..... ..... @ff +fsel 0000 11010000 00 ... ..... ..... ..... @fffc +movgr2fr_w 0000 00010001 01001 01001 ..... ..... @fr +movgr2fr_d 0000 00010001 01001 01010 ..... ..... @fr +movgr2frh_w 0000 00010001 01001 01011 ..... ..... @fr +movfr2gr_s 0000 00010001 01001 01101 ..... ..... @rf +movfr2gr_d 0000 00010001 01001 01110 ..... ..... @rf +movfrh2gr_s 0000 00010001 01001 01111 ..... ..... @rf +movgr2fcsr 0000 00010001 01001 10000 ..... ..... @fcsrd_r +movfcsr2gr 0000 00010001 01001 10010 ..... ..... @r_fcsrs +movfr2cf 0000 00010001 01001 10100 ..... 00 ... @cf +movcf2fr 0000 00010001 01001 10101 00 ... ..... @fc +movgr2cf 0000 00010001 01001 10110 ..... 00 ... @cr +movcf2gr 0000 00010001 01001 10111 00 ... ..... @rc
target/loongarch/translate.c +1 -0
@@ -169,6 +169,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_farith.c.inc" #include "insn_trans/trans_fcmp.c.inc" #include "insn_trans/trans_fcnv.c.inc" +#include "insn_trans/trans_fmov.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 14/43 target/loongarch: Add floating point load/store instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- FLD.{S/D}, FST.{S/D}
- FLDX.{S/D}, FSTX.{S/D}
- FLD{GT/LE}.{S/D}, FST{GT/LE}.{S/D}
--- .../loongarch/insn_trans/trans_fmemory.c.inc | 153 ++++++++++++++++++ target/loongarch/insns.decode | 24 +++ target/loongarch/translate.c | 1 + 3 files changed, 178 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_fmemory.c.inc
target/loongarch/insn_trans/trans_fmemory.c.inc new file +153 -0
@@ -0,0 +1,153 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +static void maybe_nanbox_load(TCGv freg, MemOp mop) +{ + if ((mop & MO_SIZE) == MO_32) { + gen_nanbox_s(freg, freg); + } +} + +static bool gen_fload_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) +{ + TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); + TCGv temp = NULL; + + if (a->imm) { + temp = tcg_temp_new(); + tcg_gen_addi_tl(temp, addr, a->imm); + addr = temp; + } + + tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + maybe_nanbox_load(cpu_fpr[a->fd], mop); + + if (temp) { + tcg_temp_free(temp); + } + + return true; +} + +static bool gen_fstore_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) +{ + TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); + TCGv temp = NULL; + + if (a->imm) { + temp = tcg_temp_new(); + tcg_gen_addi_tl(temp, addr, a->imm); + addr = temp; + } + + tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + + if (temp) { + tcg_temp_free(temp); + } + return true; +} + +static bool gen_floadx(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + maybe_nanbox_load(cpu_fpr[a->fd], mop); + tcg_temp_free(addr); + + return true; +} + +static bool gen_fstorex(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + tcg_temp_free(addr); + + return true; +} + +static bool gen_fload_gt(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + gen_helper_asrtgt_d(cpu_env, src1, src2); + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + maybe_nanbox_load(cpu_fpr[a->fd], mop); + tcg_temp_free(addr); + + return true; +} + +static bool gen_fstore_gt(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + gen_helper_asrtgt_d(cpu_env, src1, src2); + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + tcg_temp_free(addr); + + return true; +} + +static bool gen_fload_le(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + gen_helper_asrtle_d(cpu_env, src1, src2); + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + maybe_nanbox_load(cpu_fpr[a->fd], mop); + tcg_temp_free(addr); + + return true; +} + +static bool gen_fstore_le(DisasContext *ctx, arg_frr *a, MemOp mop) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); + TCGv addr = tcg_temp_new(); + + gen_helper_asrtle_d(cpu_env, src1, src2); + tcg_gen_add_tl(addr, src1, src2); + tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); + tcg_temp_free(addr); + + return true; +} + +TRANS(fld_s, gen_fload_i, MO_TEUL) +TRANS(fst_s, gen_fstore_i, MO_TEUL) +TRANS(fld_d, gen_fload_i, MO_TEUQ) +TRANS(fst_d, gen_fstore_i, MO_TEUQ) +TRANS(fldx_s, gen_floadx, MO_TEUL) +TRANS(fldx_d, gen_floadx, MO_TEUQ) +TRANS(fstx_s, gen_fstorex, MO_TEUL) +TRANS(fstx_d, gen_fstorex, MO_TEUQ) +TRANS(fldgt_s, gen_fload_gt, MO_TEUL) +TRANS(fldgt_d, gen_fload_gt, MO_TEUQ) +TRANS(fldle_s, gen_fload_le, MO_TEUL) +TRANS(fldle_d, gen_fload_le, MO_TEUQ) +TRANS(fstgt_s, gen_fstore_gt, MO_TEUL) +TRANS(fstgt_d, gen_fstore_gt, MO_TEUQ) +TRANS(fstle_s, gen_fstore_le, MO_TEUL) +TRANS(fstle_d, gen_fstore_le, MO_TEUQ)
target/loongarch/insns.decode +24 -0
@@ -36,6 +36,8 @@ &fc fd cj &cr cd rj &rc rd cj +&frr fd rj rk +&fr_i fd rj imm # # Formats
@@ -70,6 +72,8 @@ @fc .... ........ ..... ..... .. cj:3 fd:5 &fc @cr .... ........ ..... ..... rj:5 .. cd:3 &cr @rc .... ........ ..... ..... .. cj:3 rd:5 &rc +@frr .... ........ ..... rk:5 rj:5 fd:5 &frr +@fr_i12 .... ...... imm:s12 rj:5 fd:5 &fr_i # # Fixed point arithmetic operation instruction
@@ -385,3 +389,23 @@ movfr2cf 0000 00010001 01001 10100 ..... 00 ... @cf movcf2fr 0000 00010001 01001 10101 00 ... ..... @fc movgr2cf 0000 00010001 01001 10110 ..... 00 ... @cr movcf2gr 0000 00010001 01001 10111 00 ... ..... @rc + +# +# Floating point load/store instruction +# +fld_s 0010 101100 ............ ..... ..... @fr_i12 +fst_s 0010 101101 ............ ..... ..... @fr_i12 +fld_d 0010 101110 ............ ..... ..... @fr_i12 +fst_d 0010 101111 ............ ..... ..... @fr_i12 +fldx_s 0011 10000011 00000 ..... ..... ..... @frr +fldx_d 0011 10000011 01000 ..... ..... ..... @frr +fstx_s 0011 10000011 10000 ..... ..... ..... @frr +fstx_d 0011 10000011 11000 ..... ..... ..... @frr +fldgt_s 0011 10000111 01000 ..... ..... ..... @frr +fldgt_d 0011 10000111 01001 ..... ..... ..... @frr +fldle_s 0011 10000111 01010 ..... ..... ..... @frr +fldle_d 0011 10000111 01011 ..... ..... ..... @frr +fstgt_s 0011 10000111 01100 ..... ..... ..... @frr +fstgt_d 0011 10000111 01101 ..... ..... ..... @frr +fstle_s 0011 10000111 01110 ..... ..... ..... @frr +fstle_d 0011 10000111 01111 ..... ..... ..... @frr
target/loongarch/translate.c +1 -0
@@ -170,6 +170,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_fcmp.c.inc" #include "insn_trans/trans_fcnv.c.inc" #include "insn_trans/trans_fmov.c.inc" +#include "insn_trans/trans_fmemory.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 15/43 target/loongarch: Add branch instruction translation
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This includes:
- BEQ, BNE, BLT[U], BGE[U]
- BEQZ, BNEZ
- B
- BL
- JIRL
- BCEQZ, BCNEZ
--- .../loongarch/insn_trans/trans_branch.c.inc | 83 +++++++++++++++++++ target/loongarch/insns.decode | 28 +++++++ target/loongarch/translate.c | 1 + 3 files changed, 112 insertions(+) create mode 100644 target/loongarch/insn_trans/trans_branch.c.inc
target/loongarch/insn_trans/trans_branch.c.inc new file +83 -0
@@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Loongson Technology Corporation Limited + */ + +static bool trans_b(DisasContext *ctx, arg_b *a) +{ + gen_goto_tb(ctx, 0, ctx->base.pc_next + a->offs); + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} + +static bool trans_bl(DisasContext *ctx, arg_bl *a) +{ + tcg_gen_movi_tl(cpu_gpr[1], ctx->base.pc_next + 4); + gen_goto_tb(ctx, 0, ctx->base.pc_next + a->offs); + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} + +static bool trans_jirl(DisasContext *ctx, arg_jirl *a) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + + tcg_gen_addi_tl(cpu_pc, src1, a->offs); + tcg_gen_movi_tl(dest, ctx->base.pc_next + 4); + gen_set_gpr(a->rd, dest, EXT_NONE); + tcg_gen_lookup_and_goto_ptr(); + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} + +static void gen_bc(DisasContext *ctx, TCGv src1, TCGv src2, + target_long offs, TCGCond cond) +{ + TCGLabel *l = gen_new_label(); + tcg_gen_brcond_tl(cond, src1, src2, l); + gen_goto_tb(ctx, 1, ctx->base.pc_next + 4); + gen_set_label(l); + gen_goto_tb(ctx, 0, ctx->base.pc_next + offs); + ctx->base.is_jmp = DISAS_NORETURN; +} + +static bool gen_rr_bc(DisasContext *ctx, arg_rr_offs *a, TCGCond cond) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = gpr_src(ctx, a->rd, EXT_NONE); + + gen_bc(ctx, src1, src2, a->offs, cond); + return true; +} + +static bool gen_rz_bc(DisasContext *ctx, arg_r_offs *a, TCGCond cond) +{ + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + TCGv src2 = tcg_constant_tl(0); + + gen_bc(ctx, src1, src2, a->offs, cond); + return true; +} + +static bool gen_cz_bc(DisasContext *ctx, arg_c_offs *a, TCGCond cond) +{ + TCGv src1 = tcg_temp_new(); + TCGv src2 = tcg_constant_tl(0); + + tcg_gen_ld8u_tl(src1, cpu_env, + offsetof(CPULoongArchState, cf[a->cj])); + gen_bc(ctx, src1, src2, a->offs, cond); + return true; +} + +TRANS(beq, gen_rr_bc, TCG_COND_EQ) +TRANS(bne, gen_rr_bc, TCG_COND_NE) +TRANS(blt, gen_rr_bc, TCG_COND_LT) +TRANS(bge, gen_rr_bc, TCG_COND_GE) +TRANS(bltu, gen_rr_bc, TCG_COND_LTU) +TRANS(bgeu, gen_rr_bc, TCG_COND_GEU) +TRANS(beqz, gen_rz_bc, TCG_COND_EQ) +TRANS(bnez, gen_rz_bc, TCG_COND_NE) +TRANS(bceqz, gen_cz_bc, TCG_COND_EQ) +TRANS(bcnez, gen_cz_bc, TCG_COND_NE)
target/loongarch/insns.decode +28 -0
@@ -10,6 +10,9 @@ # %i14s2 10:s14 !function=shl_2 %sa2p1 15:2 !function=plus_1 +%offs21 0:s5 10:16 !function=shl_2 +%offs16 10:s16 !function=shl_2 +%offs26 0:s10 10:16 !function=shl_2 # # Argument sets
@@ -38,6 +41,10 @@ &rc rd cj &frr fd rj rk &fr_i fd rj imm +&r_offs rj offs +&c_offs cj offs +&offs offs +&rr_offs rj rd offs # # Formats
@@ -74,6 +81,10 @@ @rc .... ........ ..... ..... .. cj:3 rd:5 &rc @frr .... ........ ..... rk:5 rj:5 fd:5 &frr @fr_i12 .... ...... imm:s12 rj:5 fd:5 &fr_i +@r_offs21 .... .. ................ rj:5 ..... &r_offs offs=%offs21 +@c_offs21 .... .. ................ .. cj:3 ..... &c_offs offs=%offs21 +@offs26 .... .. .......................... &offs offs=%offs26 +@rr_offs16 .... .. ................ rj:5 rd:5 &rr_offs offs=%offs16 # # Fixed point arithmetic operation instruction
@@ -409,3 +420,20 @@ fstgt_s 0011 10000111 01100 ..... ..... ..... @frr fstgt_d 0011 10000111 01101 ..... ..... ..... @frr fstle_s 0011 10000111 01110 ..... ..... ..... @frr fstle_d 0011 10000111 01111 ..... ..... ..... @frr + +# +# Branch instructions +# +beqz 0100 00 ................ ..... ..... @r_offs21 +bnez 0100 01 ................ ..... ..... @r_offs21 +bceqz 0100 10 ................ 00 ... ..... @c_offs21 +bcnez 0100 10 ................ 01 ... ..... @c_offs21 +jirl 0100 11 ................ ..... ..... @rr_offs16 +b 0101 00 .......................... @offs26 +bl 0101 01 .......................... @offs26 +beq 0101 10 ................ ..... ..... @rr_offs16 +bne 0101 11 ................ ..... ..... @rr_offs16 +blt 0110 00 ................ ..... ..... @rr_offs16 +bge 0110 01 ................ ..... ..... @rr_offs16 +bltu 0110 10 ................ ..... ..... @rr_offs16 +bgeu 0110 11 ................ ..... ..... @rr_offs16
target/loongarch/translate.c +1 -0
@@ -171,6 +171,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_fcnv.c.inc" #include "insn_trans/trans_fmov.c.inc" #include "insn_trans/trans_fmemory.c.inc" +#include "insn_trans/trans_branch.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
Signature · 1 line
2.31.1
PATCH v3 16/43 target/loongarch: Add disassembler
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
This patch adds support for disassembling via option '-d in_asm'.
--- include/disas/dis-asm.h | 2 + meson.build | 1 + target/loongarch/disas.c | 610 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 613 insertions(+) create mode 100644 target/loongarch/disas.c
include/disas/dis-asm.h +2 -0
@@ -253,6 +253,7 @@ enum bfd_architecture#define bfd_mach_rx 0x75#define bfd_mach_rx_v2 0x76#define bfd_mach_rx_v3 0x77 + bfd_arch_loongarch, bfd_arch_last };#define bfd_mach_s390_31 31
@@ -462,6 +463,7 @@ int print_insn_riscv64 (bfd_vma, disassemble_info*);int print_insn_riscv128 (bfd_vma ,disassemble_info *);int print_insn_rx (bfd_vma ,disassemble_info *);int print_insn_hexagon (bfd_vma ,disassemble_info *); +int print_insn_loongarch (bfd_vma ,disassemble_info *);#ifdef CONFIG_CAPSTONE bool cap_disas_target (disassemble_info *info,uint64_t pc,size_t size);
meson.build +1 -0
@@ -2181,6 +2181,7 @@ disassemblers = { 'sh4' : ['CONFIG_SH4_DIS'], 'sparc' : ['CONFIG_SPARC_DIS'], 'xtensa' : ['CONFIG_XTENSA_DIS'], + 'loongarch' : ['CONFIG_LOONGARCH_DIS'], } if link_language == 'cpp' disassemblers += {
target/loongarch/disas.c new file +610 -0
610 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 17/43 target/loongarch: Add target build suport
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
--- target/loongarch/meson.build | 19 +++++++++++++++++++ target/meson.build | 1 + 2 files changed, 20 insertions(+) create mode 100644 target/loongarch/meson.build
target/loongarch/meson.build new file +19 -0
@@ -0,0 +1,19 @@ +gen = decodetree.process('insns.decode') + +loongarch_ss = ss.source_set() +loongarch_ss.add(files( + 'cpu.c', + 'disas.c', +)) +loongarch_tcg_ss = ss.source_set() +loongarch_tcg_ss.add(gen) +loongarch_tcg_ss.add(files( + 'fpu_helper.c', + 'op_helper.c', + 'translate.c', +)) +loongarch_tcg_ss.add(zlib) + +loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss]) + +target_arch += {'loongarch': loongarch_ss}
target/meson.build +1 -0
@@ -5,6 +5,7 @@ subdir('cris') subdir('hexagon') subdir('hppa') subdir('i386') +subdir('loongarch') subdir('m68k') subdir('microblaze') subdir('mips')
Signature · 1 line
2.31.1
PATCH v3 18/43 target/loongarch: Add system emulation introduction
In reply to Xiaojuan Yang--- MAINTAINERS | 8 +++++ docs/system/loongarch/loongson3.rst | 41 ++++++++++++++++++++++ target/loongarch/README | 54 +++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 docs/system/loongarch/loongson3.rst
MAINTAINERS +8 -0
@@ -1123,6 +1123,14 @@ F: hw/net/*i82596* F: include/hw/net/lasi_82596.h F: pc-bios/hppa-firmware.img +LoongArch Machines +------------------ +Virt +M: Xiaojuan Yang <[email protected]> +M: Song Gao <[email protected]> +S: Maintained +F: docs/system/loongarch/loongson3.rst + M68K Machines ------------- an5206
docs/system/loongarch/loongson3.rst new file +41 -0
41 lines not on this page · raw message
target/loongarch/README +54 -0
57 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 19/43 target/loongarch: Add CSRs definition
In reply to Xiaojuan Yang--- target/loongarch/cpu-csr.h | 208 +++++++++++++++++++++++++++++++++++++ target/loongarch/cpu.c | 36 +++++++ target/loongarch/cpu.h | 64 ++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 target/loongarch/cpu-csr.h
target/loongarch/cpu-csr.h new file +208 -0
@@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QEMU LoongArch CSRs +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef LOONGARCH_CPU_CSR_H +#define LOONGARCH_CPU_CSR_H + +#include "hw/registerfields.h" + +/* Base on kernal definitions: arch/loongarch/include/asm/loongarch.h */ + +/* Basic CSRs */ +#define LOONGARCH_CSR_CRMD 0x0/* Current mode info */ + +#define LOONGARCH_CSR_PRMD 0x1/* Prev-exception mode info */ +FIELD(CSR_PRMD, PPLV, 0, 2) +FIELD(CSR_PRMD, PIE, 2, 1) +FIELD(CSR_PRMD, PWE, 3, 1) + +#define LOONGARCH_CSR_EUEN 0x2/* Extended unit enable */ +FIELD(CSR_EUEN, FPE, 0, 1) +FIELD(CSR_EUEN, SXE, 1, 1) +FIELD(CSR_EUEN, ASXE, 2, 1) +FIELD(CSR_EUEN, BTE, 3, 1) + +#define LOONGARCH_CSR_MISC 0x3/* Misc config */ +FIELD(CSR_MISC, VA32, 0, 4) +FIELD(CSR_MISC, DRDTL, 4, 4) +FIELD(CSR_MISC, RPCNTL, 8, 4) +FIELD(CSR_MISC, ALCL, 12, 4) +FIELD(CSR_MISC, DWPL, 16, 3) + +#define LOONGARCH_CSR_ECFG 0x4/* Exception config */ +FIELD(CSR_ECFG, LIE, 0, 13) +FIELD(CSR_ECFG, VS, 16, 3) + +#define LOONGARCH_CSR_ESTAT 0x5/* Exception status */ +FIELD(CSR_ESTAT, IS, 0, 13) +FIELD(CSR_ESTAT, ECODE, 16, 6) +FIELD(CSR_ESTAT, ESUBCODE, 22, 9) + +#define LOONGARCH_CSR_ERA 0x6/* Exception return address */ + +#define LOONGARCH_CSR_BADV 0x7/* Bad virtual address */ + +#define LOONGARCH_CSR_BADI 0x8/* Bad instruction */ + +#define LOONGARCH_CSR_EENTRY 0xc/* Exception entry address */ + +/* TLB related CSRs */ +#define LOONGARCH_CSR_TLBIDX 0x10/* TLB Index, EHINV, PageSize, NP */ +FIELD(CSR_TLBIDX, INDEX, 0, 12) +FIELD(CSR_TLBIDX, PS, 24, 6) +FIELD(CSR_TLBIDX, NE, 31, 1) + +#define LOONGARCH_CSR_TLBEHI 0x11/* TLB EntryHi */ +FIELD(CSR_TLBEHI, VPPN, 13, 35) + +#define LOONGARCH_CSR_TLBELO0 0x12/* TLB EntryLo0 */ +#define LOONGARCH_CSR_TLBELO1 0x13/* TLB EntryLo1 */ +FIELD(TLBENTRY, V, 0, 1) +FIELD(TLBENTRY, D, 1, 1) +FIELD(TLBENTRY, PLV, 2, 2) +FIELD(TLBENTRY, MAT, 4, 2) +FIELD(TLBENTRY, G, 6, 1) +FIELD(TLBENTRY, PPN, 12, 36) +FIELD(TLBENTRY, NR, 61, 1) +FIELD(TLBENTRY, NX, 62, 1) +FIELD(TLBENTRY, RPLV, 63, 1) + +#define LOONGARCH_CSR_ASID 0x18/* Address space identifier */ +FIELD(CSR_ASID, ASID, 0, 10) +FIELD (CSR_ASID ,ASIDBITS ,16 ,8 ) + +/* Page table base address when badv[47] = 0 */ +#define LOONGARCH_CSR_PGDL 0x19 +/* Page table base address when badv[47] = 1 */ +#define LOONGARCH_CSR_PGDH 0x1a + +#define LOONGARCH_CSR_PGD 0x1b/* Page table base address */ + +/* Page walk controller's low addr */ +#define LOONGARCH_CSR_PWCL 0x1c +FIELD(CSR_PWCL, PTBASE, 0, 5) +FIELD(CSR_PWCL, PTWIDTH, 5, 5) +FIELD(CSR_PWCL, DIR1_BASE, 10, 5) +FIELD(CSR_PWCL, DIR1_WIDTH, 15, 5) +FIELD(CSR_PWCL, DIR2_BASE, 20, 5) +FIELD(CSR_PWCL, DIR2_WIDTH, 25, 5) +FIELD (CSR_PWCL ,PTEWIDTH ,30 ,2 ) + +/* Page walk controller's high addr */ +#define LOONGARCH_CSR_PWCH 0x1d +FIELD(CSR_PWCH, DIR3_BASE, 0, 6) +FIELD(CSR_PWCH, DIR3_WIDTH, 6, 6) +FIELD(CSR_PWCH, DIR4_BASE, 12, 6) +FIELD(CSR_PWCH, DIR4_WIDTH, 18, 6) + +#define LOONGARCH_CSR_STLBPS 0x1e/* Stlb page size */ +FIELD(CSR_STLBPS, PS, 0, 5) + +#define LOONGARCH_CSR_RVACFG 0x1f/* Reduced virtual address config */ +FIELD (CSR_RVACFG ,RBITS ,0 ,4 ) + +/* Config CSRs */ +#define LOONGARCH_CSR_CPUID 0x20/* CPU core id */ + +#define LOONGARCH_CSR_PRCFG1 0x21/* Config1 */ +FIELD(CSR_PRCFG1, SAVE_NUM, 0, 4) +FIELD(CSR_PRCFG1, TIMER_BITS, 4, 8) +FIELD(CSR_PRCFG1, VSMAX, 12, 3) + +#define LOONGARCH_CSR_PRCFG2 0x22/* Config2 */ + +#define LOONGARCH_CSR_PRCFG3 0x23/* Config3 */ +FIELD(CSR_PRCFG3, TLB_TYPE, 0, 4) +FIELD(CSR_PRCFG3, MTLB_ENTRY, 4, 8) +FIELD(CSR_PRCFG3, STLB_WAYS, 12, 8) +FIELD (CSR_PRCFG3 ,STLB_SETS ,20 ,8 ) + +/* +* Save registers count can read from PRCFG1.SAVE_NUM +* The Min count is 1. Max count is 15. + */ +#define LOONGARCH_CSR_SAVE (N ) (0x30 + N) + +/* Timer CSRs */ +#define LOONGARCH_CSR_TID 0x40/* Timer ID */ + +#define LOONGARCH_CSR_TCFG 0x41/* Timer config */ +FIELD(CSR_TCFG, EN, 0, 1) +FIELD(CSR_TCFG, PERIODIC, 1, 1) +FIELD(CSR_TCFG, INIT_VAL, 2, 46) + +#define LOONGARCH_CSR_TVAL 0x42/* Timer ticks remain */ + +#define LOONGARCH_CSR_CNTC 0x43/* Timer offset */ + +#define LOONGARCH_CSR_TICLR 0x44/* Timer interrupt clear */ + +/* LLBCTL CSRs */ +#define LOONGARCH_CSR_LLBCTL 0x60/* LLBit control */ +FIELD(CSR_LLBCTL, ROLLB, 0, 1) +FIELD(CSR_LLBCTL, WCLLB, 1, 1) +FIELD (CSR_LLBCTL ,KLO ,2 ,1 ) + +/* Implement dependent */ +#define LOONGARCH_CSR_IMPCTL1 0x80/* LoongArch config1 */ + +#define LOONGARCH_CSR_IMPCTL2 0x81/* LoongArch config2*/ + +/* TLB Refill CSRs */ +#define LOONGARCH_CSR_TLBRENTRY 0x88/* TLB refill exception address */ +#define LOONGARCH_CSR_TLBRBADV 0x89/* TLB refill badvaddr */ +#define LOONGARCH_CSR_TLBRERA 0x8a/* TLB refill ERA */ +#define LOONGARCH_CSR_TLBRSAVE 0x8b/* KScratch for TLB refill */ +FIELD(CSR_TLBRERA, ISTLBR, 0, 1) +FIELD(CSR_TLBRERA, PC, 2, 62) +#define LOONGARCH_CSR_TLBRELO0 0x8c/* TLB refill entrylo0 */ +#define LOONGARCH_CSR_TLBRELO1 0x8d/* TLB refill entrylo1 */ +#define LOONGARCH_CSR_TLBREHI 0x8e/* TLB refill entryhi */ +FIELD(CSR_TLBREHI, PS, 0, 6) +FIELD(CSR_TLBREHI, VPPN, 13, 35) +#define LOONGARCH_CSR_TLBRPRMD 0x8f/* TLB refill mode info */ +FIELD(CSR_TLBRPRMD, PPLV, 0, 2) +FIELD(CSR_TLBRPRMD, PIE, 2, 1) +FIELD (CSR_TLBRPRMD ,PWE ,4 ,1 ) + +/* Machine Error CSRs */ +#define LOONGARCH_CSR_MERRCTL 0x90/* ERRCTL */ +FIELD(CSR_MERRCTL, ISMERR, 0, 1) +#define LOONGARCH_CSR_MERRINFO1 0x91 +#define LOONGARCH_CSR_MERRINFO2 0x92 +#define LOONGARCH_CSR_MERRENTRY 0x93/* MError exception base */ +#define LOONGARCH_CSR_MERRERA 0x94/* MError exception PC */ +#define LOONGARCH_CSR_MERRSAVE 0x95/* KScratch for error exception */ + +#define LOONGARCH_CSR_CTAG 0x98/* TagLo + TagHi */ + +/* Direct map windows CSRs*/ +#define LOONGARCH_CSR_DMW (N ) (0x180 + N) +FIELD(CSR_DMW, PLV0, 0, 1) +FIELD(CSR_DMW, PLV1, 1, 1) +FIELD(CSR_DMW, PLV2, 2, 1) +FIELD(CSR_DMW, PLV3, 3, 1) +FIELD(CSR_DMW, MAT, 4, 2) +FIELD(CSR_DMW, VSEG, 60, 4) + +#define dmw_va2pa (va) \ + (va & MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS)) + +/* Debug CSRs */ +#define LOONGARCH_CSR_DBG 0x500/* debug config */ +FIELD(CSR_DBG, DST, 0, 1) +FIELD(CSR_DBG, DREV, 1, 7) +FIELD(CSR_DBG, DEI, 8, 1) +FIELD(CSR_DBG, DCL, 9, 1) +FIELD(CSR_DBG, DFW, 10, 1) +FIELD(CSR_DBG, DMW, 11, 1) +FIELD(CSR_DBG, ECODE, 16, 6) + +#define LOONGARCH_CSR_DERA 0x501/* Debug era */ +#define LOONGARCH_CSR_DSAVE 0x502/* Debug save */ + +#endif /* LOONGARCH_CPU_CSR_H */
target/loongarch/cpu.c +36 -0
@@ -16,6 +16,7 @@#include "cpu.h" #include "internals.h" #include "fpu/softfloat-helpers.h" +#include "cpu-csr.h" const char *const regnames[32 ] = {"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" ,
@@ -167,6 +168,8 @@ static void loongarch_3a5000_initfn(Object *obj) data =FIELD_DP32 (data,CPUCFG20 ,L3IU_SETS ,14 ); data =FIELD_DP32 (data,CPUCFG20 ,L3IU_SETS ,6 ); env->cpucfg[20 ] = data; + + env->CSR_ASID =FIELD_DP64 (0 ,CSR_ASID ,ASIDBITS ,0xa ); }static void loongarch_cpu_list_entry (gpointer data,gpointer user_data)
@@ -196,6 +199,39 @@ static void loongarch_cpu_reset(DeviceState *dev) env->fcsr0_mask =FCSR0_M1 |FCSR0_M2 |FCSR0_M3 ; env->fcsr0 =0x0 ; +int n; +/* Set csr registers value after reset */ + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PLV ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,IE ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,DA ,1 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PG ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,DATF ,1 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,DATM ,1 ); + + env->CSR_EUEN =FIELD_DP64 (env->CSR_EUEN,CSR_EUEN ,FPE ,0 ); + env->CSR_EUEN =FIELD_DP64 (env->CSR_EUEN,CSR_EUEN ,SXE ,0 ); + env->CSR_EUEN =FIELD_DP64 (env->CSR_EUEN,CSR_EUEN ,ASXE ,0 ); + env->CSR_EUEN =FIELD_DP64 (env->CSR_EUEN,CSR_EUEN ,BTE ,0 ); + + env->CSR_MISC =0 ; + + env->CSR_ECFG =FIELD_DP64 (env->CSR_ECFG,CSR_ECFG ,VS ,0 ); + env->CSR_ECFG =FIELD_DP64 (env->CSR_ECFG,CSR_ECFG ,LIE ,0 ); + + env->CSR_ESTAT = env->CSR_ESTAT & (~MAKE_64BIT_MASK (0 ,2 )); + env->CSR_RVACFG =FIELD_DP64 (env->CSR_RVACFG,CSR_RVACFG ,RBITS ,0 ); + env->CSR_TCFG =FIELD_DP64 (env->CSR_TCFG,CSR_TCFG ,EN ,0 ); + env->CSR_LLBCTL =FIELD_DP64 (env->CSR_LLBCTL,CSR_LLBCTL ,KLO ,0 ); + env->CSR_TLBRERA =FIELD_DP64 (env->CSR_TLBRERA,CSR_TLBRERA ,ISTLBR ,0 ); + env->CSR_MERRCTL =FIELD_DP64 (env->CSR_MERRCTL,CSR_MERRCTL ,ISMERR ,0 ); + +for (n =0 ; n <4 ; n++) { + env->CSR_DMW[n] =FIELD_DP64 (env->CSR_DMW[n],CSR_DMW ,PLV0 ,0 ); + env->CSR_DMW[n] =FIELD_DP64 (env->CSR_DMW[n],CSR_DMW ,PLV1 ,0 ); + env->CSR_DMW[n] =FIELD_DP64 (env->CSR_DMW[n],CSR_DMW ,PLV2 ,0 ); + env->CSR_DMW[n] =FIELD_DP64 (env->CSR_DMW[n],CSR_DMW ,PLV3 ,0 ); + } +restore_fp_status (env); cs->exception_index =-1 ; }
target/loongarch/cpu.h +64 -0
76 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 20/43 target/loongarch: Add basic vmstate description of CPU.
In reply to Xiaojuan Yang--- target/loongarch/cpu.c | 1 + target/loongarch/internals.h | 2 + target/loongarch/machine.c | 85 ++++++++++++++++++++++++++++++++++++ target/loongarch/meson.build | 6 +++ 4 files changed, 94 insertions(+) create mode 100644 target/loongarch/machine.c
target/loongarch/cpu.c +1 -0
@@ -331,6 +331,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->class_by_name = loongarch_cpu_class_by_name; cc->dump_state = loongarch_cpu_dump_state; cc->set_pc = loongarch_cpu_set_pc; + dc->vmsd = &vmstate_loongarch_cpu; cc->disas_set_info = loongarch_cpu_disas_set_info;#ifdef CONFIG_TCG cc->tcg_ops = &loongarch_tcg_ops;
target/loongarch/internals.h +2 -0
@@ -25,4 +25,6 @@ const char *loongarch_exception_name(int32_t exception);void restore_fp_status (CPULoongArchState *env); +extern const VMStateDescription vmstate_loongarch_cpu; +#endif
target/loongarch/machine.c new file +85 -0
85 lines not on this page · raw message
target/loongarch/meson.build +6 -0
@@ -14,6 +14,12 @@ loongarch_tcg_ss.add(files( )) loongarch_tcg_ss.add(zlib) +loongarch_softmmu_ss = ss.source_set() +loongarch_softmmu_ss.add(files( + 'machine.c', +)) + loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss]) target_arch += {'loongarch': loongarch_ss} +target_softmmu_arch += {'loongarch': loongarch_softmmu_ss}
Signature · 1 line
2.31.1
PATCH v3 21/43 target/loongarch: Implement qmp_query_cpu_definitions()
In reply to Xiaojuan Yang--- qapi/machine-target.json | 6 ++++-- target/loongarch/cpu.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)
qapi/machine-target.json +4 -2
@@ -324,7 +324,8 @@ 'TARGET_ARM', 'TARGET_I386', 'TARGET_S390X', - 'TARGET_MIPS' ] } } + 'TARGET_MIPS', + 'TARGET_LOONGARCH64' ] } } ## # @query-cpu-definitions:
@@ -340,4 +341,5 @@ 'TARGET_ARM', 'TARGET_I386', 'TARGET_S390X', - 'TARGET_MIPS' ] } } + 'TARGET_MIPS', + 'TARGET_LOONGARCH64' ] } }
target/loongarch/cpu.c +26 -0
@@ -360,3 +360,29 @@ static const TypeInfo loongarch_cpu_type_infos[] = { };DEFINE_TYPES (loongarch_cpu_type_infos) + +static void loongarch_cpu_add_definition(gpointer data, gpointer user_data) +{ +ObjectClass *oc = data; +CpuDefinitionInfoList **cpu_list = user_data; +CpuDefinitionInfo *info =g_new0 (CpuDefinitionInfo,1 ); +const char *typename =object_class_get_name (oc); + + info->name =g_strndup (typename, +strlen (typename) -strlen ("-" TYPE_LOONGARCH_CPU )); + info->q_typename =g_strdup (typename); + +QAPI_LIST_PREPEND (*cpu_list, info); +} + +CpuDefinitionInfoList *qmp_query_cpu_definitions (Error **errp) +{ +CpuDefinitionInfoList *cpu_list =NULL ; +GSList *list; + + list =object_class_get_list (TYPE_LOONGARCH_CPU , false); +g_slist_foreach (list, loongarch_cpu_add_definition, &cpu_list); +g_slist_free (list); + +return cpu_list; +}
Signature · 1 line
2.31.1
PATCH v3 22/43 target/loongarch: Add MMU support for LoongArch CPU.
In reply to Xiaojuan Yang--- target/loongarch/cpu-param.h | 2 +- target/loongarch/cpu.c | 24 +++ target/loongarch/cpu.h | 51 ++++++ target/loongarch/internals.h | 9 + target/loongarch/machine.c | 17 ++ target/loongarch/meson.build | 1 + target/loongarch/tlb_helper.c | 315 ++++++++++++++++++++++++++++++++++ 7 files changed, 418 insertions(+), 1 deletion(-) create mode 100644 target/loongarch/tlb_helper.c
target/loongarch/cpu-param.h +1 -1
@@ -13,6 +13,6 @@#define TARGET_VIRT_ADDR_SPACE_BITS 48#define TARGET_PAGE_BITS 14 -#define NB_MMU_MODES 4 +#define NB_MMU_MODES 5#endif
target/loongarch/cpu.c +24 -0
@@ -298,6 +298,21 @@ void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) } } +qemu_fprintf (f,"CRMD=%016" PRIx64"\n" , env->CSR_CRMD); +qemu_fprintf (f,"PRMD=%016" PRIx64"\n" , env->CSR_PRMD); +qemu_fprintf (f,"EUEN=%016" PRIx64"\n" , env->CSR_EUEN); +qemu_fprintf (f,"ESTAT=%016" PRIx64"\n" , env->CSR_ESTAT); +qemu_fprintf (f,"ERA=%016" PRIx64"\n" , env->CSR_ERA); +qemu_fprintf (f,"BADV=%016" PRIx64"\n" , env->CSR_BADV); +qemu_fprintf (f,"BADI=%016" PRIx64"\n" , env->CSR_BADI); +qemu_fprintf (f,"EENTRY=%016" PRIx64"\n" , env->CSR_EENTRY); +qemu_fprintf (f,"PRCFG1=%016" PRIx64", PRCFG2=%016" PRIx64"," +" PRCFG3=%016" PRIx64"\n" , + env->CSR_PRCFG1, env->CSR_PRCFG3, env->CSR_PRCFG3); +qemu_fprintf (f,"TLBRENTRY=%016" PRIx64"\n" , env->CSR_TLBRENTRY); +qemu_fprintf (f,"TLBRBADV=%016" PRIx64"\n" , env->CSR_TLBRBADV); +qemu_fprintf (f,"TLBRERA=%016" PRIx64"\n" , env->CSR_TLBRERA); +/* fpr */ if (flags &CPU_DUMP_FPU ) {for (i =0 ; i <32 ; i++) {
@@ -315,9 +330,17 @@ void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)static struct TCGCPUOps loongarch_tcg_ops = { .initialize = loongarch_translate_init, .synchronize_from_tb = loongarch_cpu_synchronize_from_tb, + + .tlb_fill = loongarch_cpu_tlb_fill, };#endif /* CONFIG_TCG */ +#include "hw/core/sysemu-cpu-ops.h" + +static const struct SysemuCPUOps loongarch_sysemu_ops = { + .get_phys_page_debug = loongarch_cpu_get_phys_page_debug, +}; +static void loongarch_cpu_class_init (ObjectClass *c,void *data) {LoongArchCPUClass *lacc =LOONGARCH_CPU_CLASS (c);
@@ -332,6 +355,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) cc->dump_state = loongarch_cpu_dump_state; cc->set_pc = loongarch_cpu_set_pc; dc->vmsd = &vmstate_loongarch_cpu; + cc->sysemu_ops = &loongarch_sysemu_ops; cc->disas_set_info = loongarch_cpu_disas_set_info;#ifdef CONFIG_TCG cc->tcg_ops = &loongarch_tcg_ops;
target/loongarch/cpu.h +51 -0
69 lines not on this page · raw message
target/loongarch/internals.h +9 -0
@@ -13,6 +13,9 @@#define FCMP_UN 0b0100/* unordered */ #define FCMP_GT 0b1000/* fp0 > fp1 */ +#define TARGET_PHYS_MASK MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS) +#define TARGET_VIRT_MASK MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS) +void loongarch_translate_init (void );void loongarch_cpu_dump_state (CPUState *cpu,FILE *f,int flags);
@@ -27,4 +30,10 @@ void restore_fp_status(CPULoongArchState *env);extern const VMStateDescription vmstate_loongarch_cpu; +bool loongarch_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); + +hwaddr loongarch_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); +#endif
target/loongarch/machine.c +17 -0
@@ -8,6 +8,20 @@#include "qemu/osdep.h" #include "cpu.h" #include "migration/cpu.h" +#include "internals.h" + +/* TLB state */ +const VMStateDescription vmstate_tlb = { + .name ="cpu/tlb" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (tlb_misc, LoongArchTLB), +VMSTATE_UINT64 (tlb_entry0, LoongArchTLB), +VMSTATE_UINT64 (tlb_entry1, LoongArchTLB), +VMSTATE_END_OF_LIST () + } +};/* LoongArch CPU state */
@@ -79,6 +93,9 @@ const VMStateDescription vmstate_loongarch_cpu = {VMSTATE_UINT64 (env.CSR_DBG, LoongArchCPU),VMSTATE_UINT64 (env.CSR_DERA, LoongArchCPU),VMSTATE_UINT64 (env.CSR_DSAVE, LoongArchCPU), +/* TLB */ +VMSTATE_STRUCT_ARRAY (env.tlb, LoongArchCPU,LOONGARCH_TLB_MAX , +0 , vmstate_tlb, LoongArchTLB),VMSTATE_END_OF_LIST () },
target/loongarch/meson.build +1 -0
@@ -17,6 +17,7 @@ loongarch_tcg_ss.add(zlib) loongarch_softmmu_ss = ss.source_set() loongarch_softmmu_ss.add(files( 'machine.c', + 'tlb_helper.c', )) loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss])
target/loongarch/tlb_helper.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 23/43 target/loongarch: Add LoongArch interrupt and exception handle
In reply to Xiaojuan Yang--- target/loongarch/cpu.c | 229 +++++++++++++++++++++++++++++++++++ target/loongarch/cpu.h | 2 + target/loongarch/internals.h | 2 + 3 files changed, 233 insertions(+)
target/loongarch/cpu.c +229 -0
@@ -80,6 +80,214 @@ static void loongarch_cpu_set_pc(CPUState *cs, vaddr value) env->pc = value; } +void loongarch_cpu_set_irq (void *opaque,int irq,int level) +{ +LoongArchCPU *cpu = opaque; +CPULoongArchState *env = &cpu->env; +CPUState *cs =CPU (cpu); + +if (irq <0 || irq >=N_IRQS ) { +return ; + } + + env->CSR_ESTAT =deposit64 (env->CSR_ESTAT, irq,1 , level !=0 ); + +if (FIELD_EX64 (env->CSR_ESTAT,CSR_ESTAT ,IS )) { +cpu_interrupt (cs,CPU_INTERRUPT_HARD ); + }else { +cpu_reset_interrupt (cs,CPU_INTERRUPT_HARD ); + } +} + +static inline bool cpu_loongarch_hw_interrupts_enabled (CPULoongArchState *env) +{ +bool ret =0 ; + + ret = (FIELD_EX64 (env->CSR_CRMD,CSR_CRMD ,IE ) && + !(FIELD_EX64 (env->CSR_DBG,CSR_DBG ,DST ))); + +return ret; +} + +/* Check if there is pending and not masked out interrupt */ +static inline bool cpu_loongarch_hw_interrupts_pending (CPULoongArchState *env) +{ +uint32_t pending; +uint32_t status; +bool r; + + pending =FIELD_EX64 (env->CSR_ESTAT,CSR_ESTAT ,IS ); + status =FIELD_EX64 (env->CSR_ECFG,CSR_ECFG ,LIE ); + + r = (pending & status) !=0 ; +return r; +} + +static void loongarch_cpu_do_interrupt (CPUState *cs) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; +bool update_badinstr =1 ; +int cause =-1 ; +const char *name; +bool tlbfill =FIELD_EX64 (env->CSR_TLBRERA,CSR_TLBRERA ,ISTLBR ); +uint32_t vec_size =FIELD_EX64 (env->CSR_ECFG,CSR_ECFG ,VS ); + +if (cs->exception_index !=EXCCODE_INT ) { +if (cs->exception_index <0 || + cs->exception_index >ARRAY_SIZE (excp_names)) { + name ="unknown" ; + }else { + name = excp_names[cs->exception_index]; + } + +qemu_log_mask (CPU_LOG_INT , +"%s enter: pc " TARGET_FMT_lx" ERA " TARGET_FMT_lx +" TLBRERA " TARGET_FMT_lx" %s exception\n" , __func__, + env->pc, env->CSR_ERA, env->CSR_TLBRERA, name); + } + +switch (cs->exception_index) { +case EXCCODE_DBP : + env->CSR_DBG =FIELD_DP64 (env->CSR_DBG,CSR_DBG ,DCL ,1 ); + env->CSR_DBG =FIELD_DP64 (env->CSR_DBG,CSR_DBG ,ECODE ,0xC ); + goto set_DERA; + set_DERA: + env->CSR_DERA = env->pc; + env->CSR_DBG =FIELD_DP64 (env->CSR_DBG,CSR_DBG ,DST ,1 ); + env->pc = env->CSR_EENTRY +0x480 ; +break ; +case EXCCODE_INT : +if (FIELD_EX64 (env->CSR_DBG,CSR_DBG ,DST )) { + env->CSR_DBG =FIELD_DP64 (env->CSR_DBG,CSR_DBG ,DEI ,1 ); + goto set_DERA; + } +QEMU_FALLTHROUGH ; +case EXCCODE_PIF : + cause = cs->exception_index; + update_badinstr =0 ; +break ; +case EXCCODE_ADEM : +case EXCCODE_SYS : +case EXCCODE_BRK : +case EXCCODE_PIL : +case EXCCODE_PIS : +case EXCCODE_PME : +case EXCCODE_PNR : +case EXCCODE_PNX : +case EXCCODE_PPI : +case EXCCODE_INE : +case EXCCODE_IPE : +case EXCCODE_FPE : + cause = cs->exception_index; +break ; +default : +qemu_log ("Error: exception(%d) '%s' has not been supported\n" , + cs->exception_index, excp_names[cs->exception_index]); +abort (); + } + +if (update_badinstr) { + env->CSR_BADI =cpu_ldl_code (env, env->pc); + } + +/* Save PLV and IE */ +if (tlbfill) { + env->CSR_TLBRPRMD =FIELD_DP64 (env->CSR_TLBRPRMD,CSR_TLBRPRMD ,PPLV , +FIELD_EX64 (env->CSR_CRMD, +CSR_CRMD ,PLV )); + env->CSR_TLBRPRMD =FIELD_DP64 (env->CSR_TLBRPRMD,CSR_TLBRPRMD ,PIE , +FIELD_EX64 (env->CSR_CRMD,CSR_CRMD ,IE )); +/* set the DA mode */ + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,DA ,1 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PG ,0 ); + env->CSR_TLBRERA =FIELD_DP64 (env->CSR_TLBRERA,CSR_TLBRERA , +PC , (env->pc >>2 )); + }else { + env->CSR_ESTAT =FIELD_DP64 (env->CSR_ESTAT,CSR_ESTAT ,ECODE , cause); + env->CSR_PRMD =FIELD_DP64 (env->CSR_PRMD,CSR_PRMD ,PPLV , +FIELD_EX64 (env->CSR_CRMD,CSR_CRMD ,PLV )); + env->CSR_PRMD =FIELD_DP64 (env->CSR_PRMD,CSR_PRMD ,PIE , +FIELD_EX64 (env->CSR_CRMD,CSR_CRMD ,IE )); + env->CSR_ERA = env->pc; + } + + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PLV ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,IE ,0 ); + +if (cs->exception_index ==EXCCODE_INT ) { +/* Interrupt */ +uint32_t vector =0 ; +uint32_t pending =FIELD_EX64 (env->CSR_ESTAT,CSR_ESTAT ,IS ); + pending &=FIELD_EX64 (env->CSR_ECFG,CSR_ECFG ,LIE ); + +/* Find the highest-priority interrupt. */ + vector =31 -clz32 (pending); + env->pc = env->CSR_EENTRY + (EXCCODE_EXTERNAL_INT + vector) * vec_size; +qemu_log_mask (CPU_LOG_INT , +"%s: PC " TARGET_FMT_lx" ERA " TARGET_FMT_lx +" cause %d\n" " A " TARGET_FMT_lx" D " + TARGET_FMT_lx" vector = %d ExC %08lx ExS %08lx\n" , + __func__, env->pc, env->CSR_ERA, + cause, env->CSR_BADV, env->CSR_DERA, vector, + env->CSR_ECFG, env->CSR_ESTAT); + }else { +if (tlbfill) { + env->pc = env->CSR_TLBRENTRY; + }else { + env->pc = env->CSR_EENTRY; + env->pc += cause * vec_size; + } +qemu_log_mask (CPU_LOG_INT , +"%s: PC " TARGET_FMT_lx" ERA " TARGET_FMT_lx +" cause %d%s\n, ESTAT " TARGET_FMT_lx +" EXCFG " TARGET_FMT_lx" BADVA " TARGET_FMT_lx +"BADI " TARGET_FMT_lx" SYS_NUM " TARGET_FMT_lu +" cpu %d asid 0x%lx" "\n" , __func__, env->pc, + tlbfill ? env->CSR_TLBRERA : env->CSR_ERA, + cause, tlbfill ?"(refill)" :"" , env->CSR_ESTAT, + env->CSR_ECFG, + tlbfill ? env->CSR_TLBRBADV : env->CSR_BADV, + env->CSR_BADI, env->gpr[11 ], cs->cpu_index, + env->CSR_ASID); + } + cs->exception_index =-1 ; +} + +static void loongarch_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr addr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response, +uintptr_t retaddr) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; + +if (access_type ==MMU_INST_FETCH ) { +do_raise_exception (env,EXCCODE_ADEF , retaddr); + }else { +do_raise_exception (env,EXCCODE_ADEM , retaddr); + } +} + +static bool loongarch_cpu_exec_interrupt (CPUState *cs,int interrupt_request) +{ +if (interrupt_request &CPU_INTERRUPT_HARD ) { +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; + +if (cpu_loongarch_hw_interrupts_enabled (env) && +cpu_loongarch_hw_interrupts_pending (env)) { +/* Raise it */ + cs->exception_index =EXCCODE_INT ; +loongarch_cpu_do_interrupt (cs); +return true; + } + } +return false; +} +#ifdef CONFIG_TCG static void loongarch_cpu_synchronize_from_tb (CPUState *cs,const TranslationBlock *tb)
@@ -91,6 +299,20 @@ static void loongarch_cpu_synchronize_from_tb(CPUState *cs, }#endif /* CONFIG_TCG */ +static bool loongarch_cpu_has_work (CPUState *cs) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; +bool has_work = false; + +if ((cs->interrupt_request &CPU_INTERRUPT_HARD ) && +cpu_loongarch_hw_interrupts_pending (env)) { + has_work = true; + } + +return has_work; +} +static void loongarch_3a5000_initfn (Object *obj) {LoongArchCPU *cpu =LOONGARCH_CPU (obj);
@@ -232,6 +454,8 @@ static void loongarch_cpu_reset(DeviceState *dev) env->CSR_DMW[n] =FIELD_DP64 (env->CSR_DMW[n],CSR_DMW ,PLV3 ,0 ); } + env->pc =0x1c000000 ; +restore_fp_status (env); cs->exception_index =-1 ; }
@@ -264,6 +488,7 @@ static void loongarch_cpu_init(Object *obj)LoongArchCPU *cpu =LOONGARCH_CPU (obj);cpu_set_cpustate_pointers (cpu); +qdev_init_gpio_in (DEVICE (cpu), loongarch_cpu_set_irq,N_IRQS ); }static ObjectClass *loongarch_cpu_class_by_name (const char *cpu_model)
@@ -332,6 +557,9 @@ static struct TCGCPUOps loongarch_tcg_ops = { .synchronize_from_tb = loongarch_cpu_synchronize_from_tb, .tlb_fill = loongarch_cpu_tlb_fill, + .cpu_exec_interrupt = loongarch_cpu_exec_interrupt, + .do_interrupt = loongarch_cpu_do_interrupt, + .do_transaction_failed = loongarch_cpu_do_transaction_failed, };#endif /* CONFIG_TCG */
@@ -352,6 +580,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)device_class_set_parent_reset (dc, loongarch_cpu_reset, &lacc->parent_reset); cc->class_by_name = loongarch_cpu_class_by_name; + cc->has_work = loongarch_cpu_has_work; cc->dump_state = loongarch_cpu_dump_state; cc->set_pc = loongarch_cpu_set_pc; dc->vmsd = &vmstate_loongarch_cpu;
target/loongarch/cpu.h +2 -0
@@ -184,6 +184,8 @@ FIELD(CSR_CRMD, WE, 9, 1)extern const char *const regnames[32 ];extern const char *const fregnames[32 ]; +#define N_IRQS 13 +#define LOONGARCH_STLB 2048/* 2048 STLB */ #define LOONGARCH_MTLB 64/* 64 MTLB */ #define LOONGARCH_TLB_MAX (LOONGARCH_STLB + LOONGARCH_MTLB)
target/loongarch/internals.h +2 -0
@@ -30,6 +30,8 @@ void restore_fp_status(CPULoongArchState *env);extern const VMStateDescription vmstate_loongarch_cpu; +void loongarch_cpu_set_irq (void *opaque,int irq,int level); +bool loongarch_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr);
Signature · 1 line
2.31.1
PATCH v3 24/43 target/loongarch: Add constant timer support
In reply to Xiaojuan Yang--- target/loongarch/constant_timer.c | 64 +++++++++++++++++++++++++++++++ target/loongarch/cpu.c | 2 + target/loongarch/cpu.h | 4 ++ target/loongarch/internals.h | 6 +++ target/loongarch/meson.build | 1 + 5 files changed, 77 insertions(+) create mode 100644 target/loongarch/constant_timer.c
target/loongarch/constant_timer.c new file +64 -0
@@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QEMU LoongArch constant timer support +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#include "qemu/osdep.h" +#include "qemu/timer.h" +#include "cpu.h" +#include "internals.h" +#include "cpu-csr.h" + +#define TIMER_PERIOD 10/* 10 ns period for 100 MHz frequency */ +#define CONSTANT_TIMER_TICK_MASK 0xfffffffffffcUL +#define CONSTANT_TIMER_ENABLE 0x1UL + +uint64_t cpu_loongarch_get_constant_timer_counter (LoongArchCPU *cpu) +{ +return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /TIMER_PERIOD ; +} + +uint64_t cpu_loongarch_get_constant_timer_ticks (LoongArchCPU *cpu) +{ +uint64_t now, expire; + + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + expire =timer_expire_time_ns (&cpu->timer); + +return (expire - now) /TIMER_PERIOD ; +} + +void cpu_loongarch_store_constant_timer_config (LoongArchCPU *cpu, +uint64_t value) +{ +CPULoongArchState *env = &cpu->env; +uint64_t now, next; + + env->CSR_TCFG = value; +if (value &CONSTANT_TIMER_ENABLE ) { + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + next = now + (value &CONSTANT_TIMER_TICK_MASK ) *TIMER_PERIOD ; +timer_mod (&cpu->timer, next); + }else { +timer_del (&cpu->timer); + } +} + +void loongarch_constant_timer_cb (void *opaque) +{ +LoongArchCPU *cpu = opaque; +CPULoongArchState *env = &cpu->env; +uint64_t now, next; + +if (FIELD_EX64 (env->CSR_TCFG,CSR_TCFG ,PERIODIC )) { + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + next = now + (env->CSR_TCFG &CONSTANT_TIMER_TICK_MASK ) *TIMER_PERIOD ; +timer_mod (&cpu->timer, next); + }else { + env->CSR_TCFG =FIELD_DP64 (env->CSR_TCFG,CSR_TCFG ,EN ,0 ); + } + +loongarch_cpu_set_irq (opaque,IRQ_TIMER ,1 ); +}
target/loongarch/cpu.c +2 -0
@@ -489,6 +489,8 @@ static void loongarch_cpu_init(Object *obj)cpu_set_cpustate_pointers (cpu);qdev_init_gpio_in (DEVICE (cpu), loongarch_cpu_set_irq,N_IRQS ); +timer_init_ns (&cpu->timer,QEMU_CLOCK_VIRTUAL , + &loongarch_constant_timer_cb, cpu); }static ObjectClass *loongarch_cpu_class_by_name (const char *cpu_model)
target/loongarch/cpu.h +4 -0
@@ -11,6 +11,7 @@#include "exec/cpu-defs.h" #include "fpu/softfloat-types.h" #include "hw/registerfields.h" +#include "qemu/timer.h" #define TCG_GUEST_DEFAULT_MO (0)
@@ -185,6 +186,8 @@ extern const char * const regnames[32];extern const char *const fregnames[32 ];#define N_IRQS 13 +#define IRQ_TIMER 11 +#define IRQ_IPI 12#define LOONGARCH_STLB 2048/* 2048 STLB */ #define LOONGARCH_MTLB 64/* 64 MTLB */
@@ -295,6 +298,7 @@ struct ArchCPU {CPUNegativeOffsetState neg;CPULoongArchState env; +QEMUTimer timer; };#define TYPE_LOONGARCH_CPU "loongarch-cpu"
target/loongarch/internals.h +6 -0
@@ -32,6 +32,12 @@ extern const VMStateDescription vmstate_loongarch_cpu;void loongarch_cpu_set_irq (void *opaque,int irq,int level); +void loongarch_constant_timer_cb (void *opaque); +uint64_t cpu_loongarch_get_constant_timer_counter (LoongArchCPU *cpu); +uint64_t cpu_loongarch_get_constant_timer_ticks (LoongArchCPU *cpu); +void cpu_loongarch_store_constant_timer_config (LoongArchCPU *cpu, +uint64_t value); +bool loongarch_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr);
target/loongarch/meson.build +1 -0
@@ -18,6 +18,7 @@ loongarch_softmmu_ss = ss.source_set() loongarch_softmmu_ss.add(files( 'machine.c', 'tlb_helper.c', + 'constant_timer.c', )) loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss])
Signature · 1 line
2.31.1
PATCH v3 25/43 target/loongarch: Add LoongArch CSR instruction
In reply to Xiaojuan YangThis includes:
- CSRRD
- CSRWR
- CSRXCHG
--- target/loongarch/csr_helper.c | 92 ++++++ target/loongarch/disas.c | 101 +++++++ target/loongarch/helper.h | 9 + .../insn_trans/trans_privileged.c.inc | 263 ++++++++++++++++++ target/loongarch/insns.decode | 13 + target/loongarch/meson.build | 1 + target/loongarch/translate.c | 11 +- 7 files changed, 489 insertions(+), 1 deletion(-) create mode 100644 target/loongarch/csr_helper.c create mode 100644 target/loongarch/insn_trans/trans_privileged.c.inc
target/loongarch/csr_helper.c new file +92 -0
@@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch emulation helpers for CSRs +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "cpu.h" +#include "internals.h" +#include "qemu/host-utils.h" +#include "exec/helper-proto.h" +#include "exec/exec-all.h" +#include "exec/cpu_ldst.h" +#include "hw/irq.h" +#include "cpu-csr.h" +#include "tcg/tcg-ldst.h" + +target_ulong helper_csrrd_pgd (CPULoongArchState *env) +{ +int64_t v; + +if (env->CSR_TLBRERA &0x1 ) { + v = env->CSR_TLBRBADV; + }else { + v = env->CSR_BADV; + } + +if ((v >>63 ) &0x1 ) { + v = env->CSR_PGDH; + }else { + v = env->CSR_PGDL; + } + +return v; +} + +target_ulong helper_csrrd_cpuid (CPULoongArchState *env) +{ +return (env_cpu (env))->cpu_index; +} + +target_ulong helper_csrrd_tval (CPULoongArchState *env) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (env_cpu (env)); + +return cpu_loongarch_get_constant_timer_ticks (cpu); +} + +target_ulong helper_csrwr_estat (CPULoongArchState *env,target_ulong val) +{ +int64_t old_v = env->CSR_ESTAT; + +/* Only IS[1:0] can be written */ + env->CSR_ESTAT =deposit64 (env->CSR_ESTAT,0 ,2 , val); + +return old_v; +} + +target_ulong helper_csrwr_asid (CPULoongArchState *env,target_ulong val) +{ +int64_t old_v = env->CSR_ASID; + +/* Only ASID filed of CSR_ASID can be written */ + env->CSR_ASID =deposit64 (env->CSR_ASID,0 ,10 , val); +if (old_v != env->CSR_ASID) { +tlb_flush (env_cpu (env)); + } +return old_v; +} + +target_ulong helper_csrwr_tcfg (CPULoongArchState *env,target_ulong val) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (env_cpu (env)); +int64_t old_v = env->CSR_TCFG; + +cpu_loongarch_store_constant_timer_config (cpu, val); + +return old_v; +} + +target_ulong helper_csrwr_ticlr (CPULoongArchState *env,target_ulong val) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (env_cpu (env)); +int64_t old_v =0 ; + +if (val &0x1 ) { +loongarch_cpu_set_irq (cpu,IRQ_TIMER ,0 ); + } +return old_v; +}
target/loongarch/disas.c +101 -0
125 lines not on this page · raw message
target/loongarch/helper.h +9 -0
@@ -92,3 +92,12 @@ DEF_HELPER_2(frint_s, i64, env, i64) DEF_HELPER_2(frint_d, i64, env, i64)DEF_HELPER_FLAGS_2 (set_rounding_mode,TCG_CALL_NO_RWG , void, env, i32) + +/* CSRs helper */ +DEF_HELPER_1(csrrd_pgd, i64, env) +DEF_HELPER_1(csrrd_cpuid, i64, env) +DEF_HELPER_1(csrrd_tval, i64, env) +DEF_HELPER_2(csrwr_estat, i64, env, tl) +DEF_HELPER_2(csrwr_asid, i64, env, tl) +DEF_HELPER_2(csrwr_tcfg, i64, env, tl) +DEF_HELPER_2 (csrwr_ticlr, i64, env, tl)
target/loongarch/insn_trans/trans_privileged.c.inc new file +263 -0
263 lines not on this page · raw message
target/loongarch/insns.decode +13 -0
@@ -45,6 +45,8 @@ &c_offs cj offs &offs offs &rr_offs rj rd offs +&r_csr rd csr +&rr_csr rd rj csr # # Formats
@@ -85,6 +87,8 @@ @c_offs21 .... .. ................ .. cj:3 ..... &c_offs offs=%offs21 @offs26 .... .. .......................... &offs offs=%offs26 @rr_offs16 .... .. ................ rj:5 rd:5 &rr_offs offs=%offs16 +@r_csr .... .... csr:14 ..... rd:5 &r_csr +@rr_csr .... .... csr:14 rj:5 rd:5 &rr_csr # # Fixed point arithmetic operation instruction
@@ -437,3 +441,12 @@ blt 0110 00 ................ ..... ..... @rr_offs16 bge 0110 01 ................ ..... ..... @rr_offs16 bltu 0110 10 ................ ..... ..... @rr_offs16 bgeu 0110 11 ................ ..... ..... @rr_offs16 + +# +# Core instructions +# +{ + csrrd 0000 0100 .............. 00000 ..... @r_csr + csrwr 0000 0100 .............. 00001 ..... @r_csr + csrxchg 0000 0100 .............. ..... ..... @rr_csr +}
target/loongarch/meson.build +1 -0
@@ -19,6 +19,7 @@ loongarch_softmmu_ss.add(files( 'machine.c', 'tlb_helper.c', 'constant_timer.c', + 'csr_helper.c', )) loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss])
target/loongarch/translate.c +10 -1
@@ -25,7 +25,9 @@ static TCGv cpu_lladdr, cpu_llval;TCGv_i32 cpu_fcsr0;TCGv_i64 cpu_fpr[32 ]; -#define DISAS_STOP DISAS_TARGET_0 +#define DISAS_STOP DISAS_TARGET_0 +#define DISAS_EXIT DISAS_TARGET_1 +#define DISAS_EXIT_UPDATE DISAS_TARGET_2static inline int plus_1 (DisasContext *ctx,int x) {
@@ -172,6 +174,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)#include "insn_trans/trans_fmov.c.inc" #include "insn_trans/trans_fmemory.c.inc" #include "insn_trans/trans_branch.c.inc" +#include "insn_trans/trans_privileged.c.inc" static void loongarch_tr_translate_insn (DisasContextBase *dcbase,CPUState *cs) {
@@ -209,6 +212,12 @@ static void loongarch_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)break ;case DISAS_NORETURN :break ; +case DISAS_EXIT_UPDATE : +tcg_gen_movi_tl (cpu_pc, ctx->base.pc_next); +QEMU_FALLTHROUGH ; +case DISAS_EXIT : +tcg_gen_exit_tb (NULL ,0 ); +break ;default :g_assert_not_reached (); }
Signature · 1 line
2.31.1
Re: [PATCH v3 25/43] target/loongarch: Add LoongArch CSR instruction
target/loongarch/insn_trans/trans_privileged.c.inc line 72
Quoted 6 lines · Xiaojuan Yang
target/loongarch/insn_trans/trans_privileged.c.inc new file +6
-0+ [LOONGARCH_CSR_CPUID] = { + .offset = -1, + .flags = CSRFL_READONLY, + .readfn = gen_helper_csrrd_cpuid, + .writefn = NULL + },
The offset should be
(int)offsetof(CPUState, cpu_index) - (int)offsetof(LoongArchCPU, env)
at which point you don't need the readfn.
target/loongarch/csr_helper.c line 46
Quoted 3 lines
target/loongarch/csr_helper.c new file +3
-0+target_ulong helper_csrrd_tval (CPULoongArchState *env) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (env_cpu (env));
cpu = env_archcpu(env).
Several other instances in the file.
Otherwise it looks good.
r~
Re: [PATCH v3 25/43] target/loongarch: Add LoongArch CSR instruction
Hi Richard,
Quoted 20 lines · Richard Henderson
Quoted 6 lines · Xiaojuan Yang
+ [
LOONGARCH_CSR_CPUID] = {
+ .offset = -1,
+ .flags =CSRFL_READONLY,
+ .readfn =gen_helper_csrrd_cpuid,
+ .writefn = NULL
+ },The offset should be
(int)offsetof(CPUState,
cpu_index) - (int)offsetof(LoongArchCPU, env)at which point you don't need the readfn.
target/loongarch/csr_helper.c line 46
Quoted 3 lines
target/loongarch/csr_helper.c new file +3
-0+target_ulong helper_csrrd_tval (CPULoongArchState *env) +{ + LoongArchCPU *cpu = LOONGARCH_CPU(env_cpu(env));cpu =
env_archcpu(env).
Quoted 6 lines
Several other instances in the file.
Otherwise it looks good.
r~ \
Sorry for the late reply, I will correct it on v4,
Thanks.
Xiaojuan
PATCH v3 26/43 target/loongarch: Add LoongArch IOCSR instruction
In reply to Xiaojuan YangThis includes:
- IOCSR{RD/WR}.{B/H/W/D}
--- target/loongarch/cpu.c | 44 ++++++++++++ target/loongarch/cpu.h | 25 +++++++ target/loongarch/disas.c | 8 +++ target/loongarch/helper.h | 8 +++ .../insn_trans/trans_privileged.c.inc | 35 ++++++++++ target/loongarch/insns.decode | 9 +++ target/loongarch/iocsr_helper.c | 67 +++++++++++++++++++ target/loongarch/meson.build | 1 + 8 files changed, 197 insertions(+) create mode 100644 target/loongarch/iocsr_helper.c
target/loongarch/cpu.c +44 -0
@@ -17,6 +17,8 @@#include "internals.h" #include "fpu/softfloat-helpers.h" #include "cpu-csr.h" +#include "sysemu/reset.h" +#include "hw/loader.h" const char *const regnames[32 ] = {"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" ,
@@ -483,14 +485,56 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) lacc->parent_realize (dev, errp); } +static void loongarch_qemu_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +} + +static uint64_t loongarch_qemu_read (void *opaque,hwaddr addr,unsigned size) +{ +switch (addr) { +case FEATURE_REG : +return 1UL <<IOCSRF_MSI |1UL <<IOCSRF_EXTIOI | +1UL <<IOCSRF_CSRIPI ; +case VENDOR_REG : +return 0x6e6f73676e6f6f4c ;/* "Loongson" */ +case CPUNAME_REG : +return 0x303030354133 ;/* "3A5000" */ +case MISC_FUNC_REG : +return 1UL <<IOCSRM_EXTIOI_EN ; + } +return 0 ; +} + +static const MemoryRegionOps loongarch_qemu_ops = { + .read = loongarch_qemu_read, + .write = loongarch_qemu_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; +static void loongarch_cpu_init (Object *obj) {LoongArchCPU *cpu =LOONGARCH_CPU (obj); +CPULoongArchState *env = &cpu->env;cpu_set_cpustate_pointers (cpu);qdev_init_gpio_in (DEVICE (cpu), loongarch_cpu_set_irq,N_IRQS );timer_init_ns (&cpu->timer,QEMU_CLOCK_VIRTUAL , &loongarch_constant_timer_cb, cpu); +memory_region_init_io (&env->system_iocsr,OBJECT (cpu),NULL , + env,"iocsr" ,UINT64_MAX ); +address_space_init (&env->address_space_iocsr, &env->system_iocsr,"IOCSR" ); +memory_region_init_io (&env->iocsr_mem,OBJECT (cpu), &loongarch_qemu_ops, +NULL ,"iocsr_misc" ,0x428 ); +memory_region_add_subregion (&env->system_iocsr,0 , &env->iocsr_mem); }static ObjectClass *loongarch_cpu_class_by_name (const char *cpu_model)
target/loongarch/cpu.h +25 -0
@@ -12,6 +12,27 @@#include "fpu/softfloat-types.h" #include "hw/registerfields.h" #include "qemu/timer.h" +#include "exec/memory.h" +#include "hw/sysbus.h" + +#define IOCSRF_TEMP 0 +#define IOCSRF_NODECNT 1 +#define IOCSRF_MSI 2 +#define IOCSRF_EXTIOI 3 +#define IOCSRF_CSRIPI 4 +#define IOCSRF_FREQCSR 5 +#define IOCSRF_FREQSCALE 6 +#define IOCSRF_DVFSV1 7 +#define IOCSRF_GMOD 9 +#define IOCSRF_VM 11 + +#define FEATURE_REG 0x8 +#define VENDOR_REG 0x10 +#define CPUNAME_REG 0x20 +#define MISC_FUNC_REG 0x420 +#define IOCSRM_EXTIOI_EN 48 + +#define IOCSR_MEM_SIZE 0x428#define TCG_GUEST_DEFAULT_MO (0)
@@ -283,6 +304,10 @@ typedef struct CPUArchState {uint64_t CSR_DSAVE ;LoongArchTLB tlb[LOONGARCH_TLB_MAX ]; + +AddressSpace address_space_iocsr; +MemoryRegion system_iocsr; +MemoryRegion iocsr_mem; } CPULoongArchState;/**
target/loongarch/disas.c +8 -0
@@ -615,6 +615,14 @@ INSN(bgeu, rr_offs) INSN(csrrd, r_csr) INSN(csrwr, r_csr) INSN(csrxchg, rr_csr) +INSN(iocsrrd_b, rr) +INSN(iocsrrd_h, rr) +INSN(iocsrrd_w, rr) +INSN(iocsrrd_d, rr) +INSN(iocsrwr_b, rr) +INSN(iocsrwr_h, rr) +INSN(iocsrwr_w, rr) +INSN(iocsrwr_d, rr)#define output_fcmp (C ,PREFIX ,SUFFIX ) \ { \
target/loongarch/helper.h +8 -0
@@ -101,3 +101,11 @@ DEF_HELPER_2(csrwr_estat, i64, env, tl) DEF_HELPER_2(csrwr_asid, i64, env, tl) DEF_HELPER_2(csrwr_tcfg, i64, env, tl) DEF_HELPER_2(csrwr_ticlr, i64, env, tl) +DEF_HELPER_2(iocsrrd_b, i64, env, tl) +DEF_HELPER_2(iocsrrd_h, i64, env, tl) +DEF_HELPER_2(iocsrrd_w, i64, env, tl) +DEF_HELPER_2(iocsrrd_d, i64, env, tl) +DEF_HELPER_3(iocsrwr_b, void, env, tl, tl) +DEF_HELPER_3(iocsrwr_h, void, env, tl, tl) +DEF_HELPER_3(iocsrwr_w, void, env, tl, tl) +DEF_HELPER_3 (iocsrwr_d, void, env, tl, tl)
target/loongarch/insn_trans/trans_privileged.c.inc +35 -0
@@ -261,3 +261,38 @@ static bool trans_csrxchg(DisasContext *ctx, arg_csrxchg *a) tcg_temp_free(oldv); return true; } + +static bool gen_iocsrrd(DisasContext *ctx, arg_rr *a, + void (*func)(TCGv, TCGv_ptr, TCGv)) +{ + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); + + if (check_plv(ctx)) { + return false; + } + func(dest, cpu_env, src1); + return true; +} + +static bool gen_iocsrwr(DisasContext *ctx, arg_rr *a, + void (*func)(TCGv_ptr, TCGv, TCGv)) +{ + TCGv val = gpr_src(ctx, a->rd, EXT_NONE); + TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); + + if (check_plv(ctx)) { + return false; + } + func(cpu_env, addr, val); + return true; +} + +TRANS(iocsrrd_b, gen_iocsrrd, gen_helper_iocsrrd_b) +TRANS(iocsrrd_h, gen_iocsrrd, gen_helper_iocsrrd_h) +TRANS(iocsrrd_w, gen_iocsrrd, gen_helper_iocsrrd_w) +TRANS(iocsrrd_d, gen_iocsrrd, gen_helper_iocsrrd_d) +TRANS(iocsrwr_b, gen_iocsrwr, gen_helper_iocsrwr_b) +TRANS(iocsrwr_h, gen_iocsrwr, gen_helper_iocsrwr_h) +TRANS(iocsrwr_w, gen_iocsrwr, gen_helper_iocsrwr_w) +TRANS(iocsrwr_d, gen_iocsrwr, gen_helper_iocsrwr_d)
target/loongarch/insns.decode +9 -0
@@ -450,3 +450,12 @@ bgeu 0110 11 ................ ..... ..... @rr_offs16 csrwr 0000 0100 .............. 00001 ..... @r_csr csrxchg 0000 0100 .............. ..... ..... @rr_csr } + +iocsrrd_b 0000 01100100 10000 00000 ..... ..... @rr +iocsrrd_h 0000 01100100 10000 00001 ..... ..... @rr +iocsrrd_w 0000 01100100 10000 00010 ..... ..... @rr +iocsrrd_d 0000 01100100 10000 00011 ..... ..... @rr +iocsrwr_b 0000 01100100 10000 00100 ..... ..... @rr +iocsrwr_h 0000 01100100 10000 00101 ..... ..... @rr +iocsrwr_w 0000 01100100 10000 00110 ..... ..... @rr +iocsrwr_d 0000 01100100 10000 00111 ..... ..... @rr
target/loongarch/iocsr_helper.c new file +67 -0
67 lines not on this page · raw message
target/loongarch/meson.build +1 -0
@@ -20,6 +20,7 @@ loongarch_softmmu_ss.add(files( 'tlb_helper.c', 'constant_timer.c', 'csr_helper.c', + 'iocsr_helper.c', )) loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss])
Signature · 1 line
2.31.1
Re: [PATCH v3 26/43] target/loongarch: Add LoongArch IOCSR instruction
Quoted 15 lines · Xiaojuan Yang
This includes:
- IOCSR{RD/WR}.{B/H/W/D}Signed-off-by Xiaojuan Yang<[email protected]>Signed-off-by Song Gao<[email protected]>--- target/loongarch/cpu.c | 44 ++++++++++++ target/loongarch/cpu.h | 25 +++++++ target/loongarch/disas.c | 8 +++ target/loongarch/helper.h | 8 +++ .../insn_trans/trans_privileged.c.inc | 35 ++++++++++ target/loongarch/insns.decode | 9 +++ target/loongarch/iocsr_helper.c | 67 +++++++++++++++++++ target/loongarch/meson.build | 1 + 8 files changed, 197 insertions(+)
Quoted 1 line
create mode 100644
target/loongarch/iocsr_helper.c
r~
PATCH v3 27/43 target/loongarch: Add TLB instruction support
In reply to Xiaojuan YangThis includes:
- TLBSRCH
- TLBRD
- TLBWR
- TLBFILL
- TLBCLR
- TLBFLUSH
- INVTLB
--- target/loongarch/disas.c | 18 + target/loongarch/helper.h | 13 + .../insn_trans/trans_privileged.c.inc | 102 +++++ target/loongarch/insns.decode | 11 + target/loongarch/tlb_helper.c | 355 ++++++++++++++++++ 5 files changed, 499 insertions(+)
target/loongarch/disas.c +18 -0
@@ -303,6 +303,17 @@ static void output_rr_csr(DisasContext *ctx, arg_rr_csr *a, a->rd, a->rj, a->csr, get_csr_name(a->csr)); } +static void output_empty (DisasContext *ctx,arg_empty *a, +const char *mnemonic) +{ +output (ctx, mnemonic,"" ); +} + +static void output_i_rr (DisasContext *ctx,arg_i_rr *a,const char *mnemonic) +{ +output (ctx, mnemonic,"%d, r%d, r%d" , a->imm, a->rj, a->rk); +} +#define INSN (insn, type) \ static bool trans_##insn(DisasContext *ctx, arg_##type * a) \ { \
@@ -623,6 +634,13 @@ INSN(iocsrwr_b, rr) INSN(iocsrwr_h, rr) INSN(iocsrwr_w, rr) INSN(iocsrwr_d, rr) +INSN(tlbsrch, empty) +INSN(tlbrd, empty) +INSN(tlbwr, empty) +INSN(tlbfill, empty) +INSN(tlbclr, empty) +INSN(tlbflush, empty) +INSN(invtlb, i_rr)#define output_fcmp (C ,PREFIX ,SUFFIX ) \ { \
target/loongarch/helper.h +13 -0
@@ -109,3 +109,16 @@ DEF_HELPER_3(iocsrwr_b, void, env, tl, tl) DEF_HELPER_3(iocsrwr_h, void, env, tl, tl) DEF_HELPER_3(iocsrwr_w, void, env, tl, tl)DEF_HELPER_3 (iocsrwr_d, void, env, tl, tl) + +/* TLB helper */ +DEF_HELPER_1(tlbwr, void, env) +DEF_HELPER_1(tlbfill, void, env) +DEF_HELPER_1(tlbsrch, void, env) +DEF_HELPER_1(tlbrd, void, env) +DEF_HELPER_1(tlbclr, void, env) +DEF_HELPER_1(tlbflush, void, env) +DEF_HELPER_1(invtlb_all, void, env) +DEF_HELPER_2(invtlb_all_g, void, env, i32) +DEF_HELPER_2(invtlb_all_asid, void, env, tl) +DEF_HELPER_3(invtlb_page_asid, void, env, tl, tl) +DEF_HELPER_3 (invtlb_page_asid_or_g, void, env, tl, tl)
target/loongarch/insn_trans/trans_privileged.c.inc +102 -0
105 lines not on this page · raw message
target/loongarch/insns.decode +11 -0
@@ -47,6 +47,8 @@ &rr_offs rj rd offs &r_csr rd csr &rr_csr rd rj csr +&empty +&i_rr imm rj rk # # Formats
@@ -89,6 +91,8 @@ @rr_offs16 .... .. ................ rj:5 rd:5 &rr_offs offs=%offs16 @r_csr .... .... csr:14 ..... rd:5 &r_csr @rr_csr .... .... csr:14 rj:5 rd:5 &rr_csr +@empty .... ........ ..... ..... ..... ..... &empty +@i_rr ...... ...... ..... rk:5 rj:5 imm:5 &i_rr # # Fixed point arithmetic operation instruction
@@ -459,3 +463,10 @@ iocsrwr_b 0000 01100100 10000 00100 ..... ..... @rr iocsrwr_h 0000 01100100 10000 00101 ..... ..... @rr iocsrwr_w 0000 01100100 10000 00110 ..... ..... @rr iocsrwr_d 0000 01100100 10000 00111 ..... ..... @rr +tlbsrch 0000 01100100 10000 01010 00000 00000 @empty +tlbrd 0000 01100100 10000 01011 00000 00000 @empty +tlbwr 0000 01100100 10000 01100 00000 00000 @empty +tlbfill 0000 01100100 10000 01101 00000 00000 @empty +tlbclr 0000 01100100 10000 01000 00000 00000 @empty +tlbflush 0000 01100100 10000 01001 00000 00000 @empty +invtlb 0000 01100100 10011 ..... ..... ..... @i_rr
target/loongarch/tlb_helper.c +355 -0
370 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 28/43 target/loongarch: Add other core instructions support
In reply to Xiaojuan YangThis includes:
-CACOP
-LDDIR
-LDPTE-ERTN
-DBCL
-IDLE
--- target/loongarch/disas.c | 17 ++++ target/loongarch/helper.h | 5 + .../insn_trans/trans_privileged.c.inc | 65 +++++++++++++ target/loongarch/insns.decode | 11 +++ target/loongarch/internals.h | 5 + target/loongarch/op_helper.c | 36 +++++++ target/loongarch/tlb_helper.c | 93 +++++++++++++++++++ 7 files changed, 232 insertions(+)
target/loongarch/disas.c +17 -0
@@ -314,6 +314,17 @@ static void output_i_rr(DisasContext *ctx, arg_i_rr *a, const char *mnemonic)output (ctx, mnemonic,"%d, r%d, r%d" , a->imm, a->rj, a->rk); } +static void output_cop_r_i (DisasContext *ctx,arg_cop_r_i *a, +const char *mnemonic) +{ +output (ctx, mnemonic,"%d, r%d, %d" , a->cop, a->rj, a->imm); +} + +static void output_j_i (DisasContext *ctx,arg_j_i *a,const char *mnemonic) +{ +output (ctx, mnemonic,"r%d, %d" , a->rj, a->imm); +} +#define INSN (insn, type) \ static bool trans_##insn(DisasContext *ctx, arg_##type * a) \ { \
@@ -641,6 +652,12 @@ INSN(tlbfill, empty) INSN(tlbclr, empty) INSN(tlbflush, empty) INSN(invtlb, i_rr) +INSN(cacop, cop_r_i) +INSN(lddir, rr_i) +INSN(ldpte, j_i) +INSN(ertn, empty) +INSN(idle, i) +INSN(dbcl, i)#define output_fcmp (C ,PREFIX ,SUFFIX ) \ { \
target/loongarch/helper.h +5 -0
@@ -122,3 +122,8 @@ DEF_HELPER_2(invtlb_all_g, void, env, i32) DEF_HELPER_2(invtlb_all_asid, void, env, tl) DEF_HELPER_3(invtlb_page_asid, void, env, tl, tl) DEF_HELPER_3(invtlb_page_asid_or_g, void, env, tl, tl) + +DEF_HELPER_4(lddir, tl, env, tl, tl, i32) +DEF_HELPER_4(ldpte, void, env, tl, tl, i32) +DEF_HELPER_1(ertn, void, env) +DEF_HELPER_1 (idle, void, env)
target/loongarch/insn_trans/trans_privileged.c.inc +65 -0
68 lines not on this page · raw message
target/loongarch/insns.decode +11 -0
@@ -49,6 +49,8 @@ &rr_csr rd rj csr &empty &i_rr imm rj rk +&cop_r_i cop rj imm +&j_i rj imm # # Formats
@@ -60,6 +62,7 @@ @r_i20 .... ... imm:s20 rd:5 &r_i @rr_ui5 .... ........ ..... imm:5 rj:5 rd:5 &rr_i @rr_ui6 .... ........ .... imm:6 rj:5 rd:5 &rr_i +@rr_ui8 .. ........ .... imm:8 rj:5 rd:5 &rr_i @rr_i12 .... ...... imm:s12 rj:5 rd:5 &rr_i @rr_ui12 .... ...... imm:12 rj:5 rd:5 &rr_i @rr_i14s2 .... .... .............. rj:5 rd:5 &rr_i imm=%i14s2
@@ -93,6 +96,8 @@ @rr_csr .... .... csr:14 rj:5 rd:5 &rr_csr @empty .... ........ ..... ..... ..... ..... &empty @i_rr ...... ...... ..... rk:5 rj:5 imm:5 &i_rr +@cop_r_i .... ...... imm:s12 rj:5 cop:5 &cop_r_i +@j_i .... ........ .. imm:8 rj:5 ..... &j_i # # Fixed point arithmetic operation instruction
@@ -470,3 +475,9 @@ tlbfill 0000 01100100 10000 01101 00000 00000 @empty tlbclr 0000 01100100 10000 01000 00000 00000 @empty tlbflush 0000 01100100 10000 01001 00000 00000 @empty invtlb 0000 01100100 10011 ..... ..... ..... @i_rr +cacop 0000 011000 ............ ..... ..... @cop_r_i +lddir 0000 01100100 00 ........ ..... ..... @rr_ui8 +ldpte 0000 01100100 01 ........ ..... 00000 @j_i +ertn 0000 01100100 10000 01110 00000 00000 @empty +idle 0000 01100100 10001 ............... @i15 +dbcl 0000 00000010 10101 ............... @i15
target/loongarch/internals.h +5 -0
@@ -16,6 +16,11 @@#define TARGET_PHYS_MASK MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS)#define TARGET_VIRT_MASK MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS) +/* Global bit used for lddir/ldpte */ +#define LOONGARCH_PAGE_HUGE_SHIFT 6 +/* Global bit for huge page */ +#define LOONGARCH_HGLOBAL_SHIFT 12 +void loongarch_translate_init (void );void loongarch_cpu_dump_state (CPUState *cpu,FILE *f,int flags);
target/loongarch/op_helper.c +36 -0
@@ -6,6 +6,7 @@*/ #include "qemu/osdep.h" +#include "qemu/log.h" #include "qemu/main-loop.h" #include "cpu.h" #include "qemu/host-utils.h"
@@ -15,6 +16,7 @@#include "internals.h" #include "qemu/crc32c.h" #include <zlib.h> +#include "cpu-csr.h" /* Exceptions helpers */ void helper_raise_exception (CPULoongArchState *env,uint32_t exception)
@@ -81,3 +83,37 @@ target_ulong helper_cpucfg(CPULoongArchState *env, target_ulong rj) {return rj >21 ?0 : env->cpucfg[rj]; } + +void helper_ertn (CPULoongArchState *env) +{ +uint64_t csr_pplv, csr_pie; +if (FIELD_EX64 (env->CSR_TLBRERA,CSR_TLBRERA ,ISTLBR )) { + csr_pplv =FIELD_EX64 (env->CSR_TLBRPRMD,CSR_TLBRPRMD ,PPLV ); + csr_pie =FIELD_EX64 (env->CSR_TLBRPRMD,CSR_TLBRPRMD ,PIE ); + + env->CSR_TLBRERA =FIELD_DP64 (env->CSR_TLBRERA,CSR_TLBRERA ,ISTLBR ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,DA ,0 ); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PG ,1 ); + env->pc = env->CSR_TLBRERA; +qemu_log_mask (CPU_LOG_INT ,"%s: TLBRERA 0x%lx\n" , + __func__, env->CSR_TLBRERA); + }else { + csr_pplv =FIELD_EX64 (env->CSR_PRMD,CSR_PRMD ,PPLV ); + csr_pie =FIELD_EX64 (env->CSR_PRMD,CSR_PRMD ,PIE ); + + env->pc = env->CSR_ERA; +qemu_log_mask (CPU_LOG_INT ,"%s: ERA 0x%lx\n" , __func__, env->CSR_ERA); + } + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,PLV , csr_pplv); + env->CSR_CRMD =FIELD_DP64 (env->CSR_CRMD,CSR_CRMD ,IE , csr_pie); + + env->lladdr =1 ; +} + +void helper_idle (CPULoongArchState *env) +{ +CPUState *cs =env_cpu (env); + + cs->halted =1 ; +do_raise_exception (env,EXCP_HLT ,0 ); +}
target/loongarch/tlb_helper.c +93 -0
96 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 29/43 target/loongarch: Add timer related instructions support.
In reply to Xiaojuan YangThis includes:
-RDTIME{L/H}.W
-RDTIME.D
--- target/loongarch/disas.c | 3 ++ target/loongarch/helper.h | 2 ++ target/loongarch/insn_trans/trans_extra.c.inc | 33 +++++++++++++++++++ target/loongarch/insns.decode | 3 ++ target/loongarch/op_helper.c | 13 ++++++++ target/loongarch/translate.c | 2 ++ 6 files changed, 56 insertions(+)
target/loongarch/disas.c +3 -0
@@ -352,6 +352,9 @@ INSN(bitrev_w, rr) INSN(bitrev_d, rr) INSN(ext_w_h, rr) INSN(ext_w_b, rr) +INSN(rdtimel_w, rr) +INSN(rdtimeh_w, rr) +INSN(rdtime_d, rr) INSN(cpucfg, rr) INSN(asrtle_d, rr_jk)INSN (asrtgt_d, rr_jk)
target/loongarch/helper.h +2 -0
@@ -93,6 +93,8 @@ DEF_HELPER_2(frint_d, i64, env, i64) DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_RWG, void, env, i32) +DEF_HELPER_1 (rdtime_d, i64, env) + /* CSRs helper */ DEF_HELPER_1(csrrd_pgd, i64, env)DEF_HELPER_1 (csrrd_cpuid, i64, env)
target/loongarch/insn_trans/trans_extra.c.inc +33 -0
@@ -33,6 +33,39 @@ static bool trans_asrtgt_d(DisasContext *ctx, arg_asrtgt_d * a) return true; } +static bool gen_rdtime(DisasContext *ctx, arg_rr *a, + bool word, bool high) +{ + TCGv dst1 = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv dst2 = gpr_dst(ctx, a->rj, EXT_NONE); + + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); + } + gen_helper_rdtime_d(dst1, cpu_env); + if (word) { + tcg_gen_sextract_tl(dst1, dst1, high ? 32 : 0, 32); + } + tcg_gen_ld_i64(dst2, cpu_env, offsetof(CPULoongArchState, CSR_TID)); + + return true; +} + +static bool trans_rdtimel_w(DisasContext *ctx, arg_rdtimel_w *a) +{ + return gen_rdtime(ctx, a, 1, 0); +} + +static bool trans_rdtimeh_w(DisasContext *ctx, arg_rdtimeh_w *a) +{ + return gen_rdtime(ctx, a, 1, 1); +} + +static bool trans_rdtime_d(DisasContext *ctx, arg_rdtime_d *a) +{ + return gen_rdtime(ctx, a, 0, 0); +} + static bool trans_cpucfg(DisasContext *ctx, arg_cpucfg *a) { TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
target/loongarch/insns.decode +3 -0
@@ -309,6 +309,9 @@ break 0000 00000010 10100 ............... @i15 syscall 0000 00000010 10110 ............... @i15 asrtle_d 0000 00000000 00010 ..... ..... 00000 @rr_jk asrtgt_d 0000 00000000 00011 ..... ..... 00000 @rr_jk +rdtimel_w 0000 00000000 00000 11000 ..... ..... @rr +rdtimeh_w 0000 00000000 00000 11001 ..... ..... @rr +rdtime_d 0000 00000000 00000 11010 ..... ..... @rr cpucfg 0000 00000000 00000 11011 ..... ..... @rr #
target/loongarch/op_helper.c +13 -0
@@ -84,6 +84,19 @@ target_ulong helper_cpucfg(CPULoongArchState *env, target_ulong rj)return rj >21 ?0 : env->cpucfg[rj]; } +uint64_t helper_rdtime_d (CPULoongArchState *env) +{ +uint64_t plv; +LoongArchCPU *cpu =LOONGARCH_CPU (env_cpu (env)); + + plv =FIELD_EX64 (env->CSR_CRMD,CSR_CRMD ,PLV ); +if (extract64 (env->CSR_MISC,R_CSR_MISC_DRDTL_SHIFT + plv,1 )) { +do_raise_exception (env,EXCCODE_IPE ,GETPC ()); + } + +return cpu_loongarch_get_constant_timer_counter (cpu); +} +void helper_ertn (CPULoongArchState *env) {uint64_t csr_pplv, csr_pie;
target/loongarch/translate.c +2 -0
@@ -25,6 +25,8 @@ static TCGv cpu_lladdr, cpu_llval;TCGv_i32 cpu_fcsr0;TCGv_i64 cpu_fpr[32 ]; +#include "exec/gen-icount.h" +#define DISAS_STOP DISAS_TARGET_0#define DISAS_EXIT DISAS_TARGET_1#define DISAS_EXIT_UPDATE DISAS_TARGET_2
Signature · 1 line
2.31.1
PATCH v3 30/43 hw/loongarch: Add support loongson3 virt machine type.
In reply to Xiaojuan YangEmulate a 3A5000 board use the new loongarch instruction. 3A5000 belongs to the Loongson3 series processors. The board consists of a 3A5000 cpu model and the virt bridge. The host 3A5000 board is really complicated and contains many functions.Now for the tcg softmmu mode only part functions are emulated.
More detailed info you can see
https://github.com/loongson/LoongArch-Documentation
--- MAINTAINERS | 4 + .../devices/loongarch64-softmmu/default.mak | 3 + configs/targets/loongarch64-softmmu.mak | 3 + hw/Kconfig | 1 + hw/loongarch/Kconfig | 4 + hw/loongarch/loongson3.c | 89 +++++++++++++++++++ hw/loongarch/meson.build | 4 + hw/meson.build | 1 + include/exec/poison.h | 2 + include/hw/loongarch/virt.h | 31 +++++++ include/sysemu/arch_init.h | 1 + qapi/machine.json | 2 +- target/Kconfig | 1 + target/loongarch/Kconfig | 2 + target/loongarch/cpu.c | 2 + 15 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 configs/devices/loongarch64-softmmu/default.mak create mode 100644 configs/targets/loongarch64-softmmu.mak create mode 100644 hw/loongarch/Kconfig create mode 100644 hw/loongarch/loongson3.c create mode 100644 hw/loongarch/meson.build create mode 100644 include/hw/loongarch/virt.h create mode 100644 target/loongarch/Kconfig
MAINTAINERS +4 -0
@@ -1130,6 +1130,10 @@ M: Xiaojuan Yang <[email protected]> M: Song Gao <[email protected]> S: Maintained F: docs/system/loongarch/loongson3.rst +F: configs/targets/loongarch64-softmmu.mak +F: configs/devices/loongarch64-softmmu/default.mak +F: hw/loongarch/ +F: include/hw/loongarch/virt.h M68K Machines -------------
configs/devices/loongarch64-softmmu/default.mak new file +3 -0
@@ -0,0 +1,3 @@ +# Default configuration for loongarch64-softmmu + +CONFIG_LOONGARCH_VIRT=y
configs/targets/loongarch64-softmmu.mak new file +3 -0
@@ -0,0 +1,3 @@ +TARGET_ARCH=loongarch64 +TARGET_BASE_ARCH=loongarch +TARGET_SUPPORTS_MTTCG=y
hw/Kconfig +1 -0
@@ -49,6 +49,7 @@ source avr/Kconfig source cris/Kconfig source hppa/Kconfig source i386/Kconfig +source loongarch/Kconfig source m68k/Kconfig source microblaze/Kconfig source mips/Kconfig
hw/loongarch/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +config LOONGARCH_VIRT + bool + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE
hw/loongarch/loongson3.c new file +89 -0
89 lines not on this page · raw message
hw/loongarch/meson.build new file +4 -0
@@ -0,0 +1,4 @@ +loongarch_ss = ss.source_set() +loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: files('loongson3.c')) + +hw_arch += {'loongarch': loongarch_ss}
hw/meson.build +1 -0
@@ -49,6 +49,7 @@ subdir('avr') subdir('cris') subdir('hppa') subdir('i386') +subdir('loongarch') subdir('m68k') subdir('microblaze') subdir('mips')
include/exec/poison.h +2 -0
@@ -14,6 +14,7 @@#pragma GCC poison TARGET_CRIS#pragma GCC poison TARGET_HEXAGON#pragma GCC poison TARGET_HPPA +#pragma GCC poison TARGET_LOONGARCH64#pragma GCC poison TARGET_M68K#pragma GCC poison TARGET_MICROBLAZE#pragma GCC poison TARGET_MIPS
@@ -71,6 +72,7 @@#pragma GCC poison CONFIG_HPPA_DIS#pragma GCC poison CONFIG_I386_DIS#pragma GCC poison CONFIG_HEXAGON_DIS +#pragma GCC poison CONFIG_LOONGARCH_DIS#pragma GCC poison CONFIG_M68K_DIS#pragma GCC poison CONFIG_MICROBLAZE_DIS#pragma GCC poison CONFIG_MIPS_DIS
include/hw/loongarch/virt.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Definitions for loongarch board emulation. +* +* Copyright (C) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef HW_LOONGARCH_H +#define HW_LOONGARCH_H + +#include "target/loongarch/cpu.h" +#include "hw/boards.h" +#include "qemu/queue.h" + +#define LOONGARCH_MAX_VCPUS 4 + +#define LOONGARCH_ISA_IO_BASE 0x18000000UL +#define LOONGARCH_ISA_IO_SIZE 0x0004000 + +struct LoongArchMachineState { +/*< private >*/ +MachineState parent_obj; + +MemoryRegion lowmem; +MemoryRegion highmem; +MemoryRegion isa_io; +}; + +#define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt") +OBJECT_DECLARE_SIMPLE_TYPE(LoongArchMachineState, LOONGARCH_MACHINE) +#endif
include/sysemu/arch_init.h +1 -0
@@ -24,6 +24,7 @@ enum {QEMU_ARCH_RX = (1 <<20 ),QEMU_ARCH_AVR = (1 <<21 ),QEMU_ARCH_HEXAGON = (1 <<22 ), + QEMU_ARCH_LOONGARCH = (1 << 23), };extern const uint32_t arch_type;
qapi/machine.json +1 -1
@@ -30,7 +30,7 @@ ## { 'enum' : 'SysEmuTarget', 'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'cris', 'hppa', 'i386', - 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64', + 'loongarch64', 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel', 'nios2', 'or1k', 'ppc', 'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4', 'sh4eb', 'sparc', 'sparc64', 'tricore',
target/Kconfig +1 -0
@@ -4,6 +4,7 @@ source avr/Kconfig source cris/Kconfig source hppa/Kconfig source i386/Kconfig +source loongarch/Kconfig source m68k/Kconfig source microblaze/Kconfig source mips/Kconfig
target/loongarch/Kconfig new file +2 -0
@@ -0,0 +1,2 @@ +config LOONGARCH64 + bool
target/loongarch/cpu.c +2 -0
@@ -82,6 +82,8 @@ static void loongarch_cpu_set_pc(CPUState *cs, vaddr value) env->pc = value; } +#include "hw/loongarch/virt.h" +void loongarch_cpu_set_irq (void *opaque,int irq,int level) {LoongArchCPU *cpu = opaque;
Signature · 1 line
2.31.1
PATCH v3 31/43 hw/loongarch: Add LoongArch ipi interrupt support(IPI)
In reply to Xiaojuan YangThis patch realize the IPI interrupt controller.
--- MAINTAINERS | 2 + hw/intc/Kconfig | 3 + hw/intc/loongarch_ipi.c | 242 ++++++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + hw/intc/trace-events | 4 + hw/loongarch/Kconfig | 1 + include/hw/intc/loongarch_ipi.h | 52 +++++++ include/hw/loongarch/virt.h | 2 + 8 files changed, 307 insertions(+) create mode 100644 hw/intc/loongarch_ipi.c create mode 100644 include/hw/intc/loongarch_ipi.h
MAINTAINERS +2 -0
@@ -1134,6 +1134,8 @@ F: configs/targets/loongarch64-softmmu.mak F: configs/devices/loongarch64-softmmu/default.mak F: hw/loongarch/ F: include/hw/loongarch/virt.h +F: include/hw/intc/loongarch_*.h +F: hw/intc/loongarch_*.c M68K Machines -------------
hw/intc/Kconfig +3 -0
@@ -87,3 +87,6 @@ config M68K_IRQC config NIOS2_VIC bool + +config LOONGARCH_IPI + bool
hw/intc/loongarch_ipi.c new file +242 -0
242 lines not on this page · raw message
hw/intc/meson.build +1 -0
@@ -63,3 +63,4 @@ specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XIVE'], specific_ss.add(when: 'CONFIG_GOLDFISH_PIC', if_true: files('goldfish_pic.c')) specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) specific_ss.add(when: 'CONFIG_NIOS2_VIC', if_true: files('nios2_vic.c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c'))
hw/intc/trace-events +4 -0
@@ -287,3 +287,7 @@ sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %u - sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " -> 0x%lx" sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " <- 0x%lx" sh_intc_set(int id, int enable) "setting interrupt group %d to %d" + +# loongarch_ipi.c +loongarch_ipi_read(unsigned size, uint64_t addr, unsigned long val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64 +loongarch_ipi_write(unsigned size, uint64_t addr, unsigned long val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64
hw/loongarch/Kconfig +1 -0
@@ -2,3 +2,4 @@ config LOONGARCH_VIRT bool select PCI select PCI_EXPRESS_GENERIC_BRIDGE + select LOONGARCH_IPI
include/hw/intc/loongarch_ipi.h new file +52 -0
52 lines not on this page · raw message
include/hw/loongarch/virt.h +2 -0
@@ -11,6 +11,7 @@#include "target/loongarch/cpu.h" #include "hw/boards.h" #include "qemu/queue.h" +#include "hw/intc/loongarch_ipi.h" #define LOONGARCH_MAX_VCPUS 4
@@ -21,6 +22,7 @@ struct LoongArchMachineState {/*< private >*/ MachineState parent_obj; +IPICore ipi_core[MAX_IPI_CORE_NUM ];MemoryRegion lowmem;MemoryRegion highmem;MemoryRegion isa_io;
Signature · 1 line
2.31.1
PATCH v3 32/43 hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC)
In reply to Xiaojuan YangThis patch realize the PCH-PIC interrupt controller.
--- MAINTAINERS | 1 + hw/intc/Kconfig | 4 + hw/intc/loongarch_pch_pic.c | 431 ++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + hw/intc/trace-events | 9 + hw/loongarch/Kconfig | 1 + include/hw/intc/loongarch_pch_pic.h | 69 +++++ include/hw/pci-host/ls7a.h | 30 ++ 8 files changed, 546 insertions(+) create mode 100644 hw/intc/loongarch_pch_pic.c create mode 100644 include/hw/intc/loongarch_pch_pic.h create mode 100644 include/hw/pci-host/ls7a.h
MAINTAINERS +1 -0
@@ -1136,6 +1136,7 @@ F: hw/loongarch/ F: include/hw/loongarch/virt.h F: include/hw/intc/loongarch_*.h F: hw/intc/loongarch_*.c +F: include/hw/pci-host/ls7a.h M68K Machines -------------
hw/intc/Kconfig +4 -0
@@ -90,3 +90,7 @@ config NIOS2_VIC config LOONGARCH_IPI bool + +config LOONGARCH_PCH_PIC + bool + select UNIMP
hw/intc/loongarch_pch_pic.c new file +431 -0
431 lines not on this page · raw message
hw/intc/meson.build +1 -0
@@ -64,3 +64,4 @@ specific_ss.add(when: 'CONFIG_GOLDFISH_PIC', if_true: files('goldfish_pic.c')) specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) specific_ss.add(when: 'CONFIG_NIOS2_VIC', if_true: files('nios2_vic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c'))
hw/intc/trace-events +9 -0
@@ -291,3 +291,12 @@ sh_intc_set(int id, int enable) "setting interrupt group %d to %d" # loongarch_ipi.c loongarch_ipi_read(unsigned size, uint64_t addr, unsigned long val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64 loongarch_ipi_write(unsigned size, uint64_t addr, unsigned long val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64 + +# loongarch_pch_pic.c +loongarch_pch_pic_irq_handler(int irq, int level) "irq %d level %d" +loongarch_pch_pic_low_readw(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 +loongarch_pch_pic_low_writew(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 +loongarch_pch_pic_high_readw(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 +loongarch_pch_pic_high_writew(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 +loongarch_pch_pic_readb(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 +loongarch_pch_pic_writeb(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64
hw/loongarch/Kconfig +1 -0
@@ -3,3 +3,4 @@ config LOONGARCH_VIRT select PCI select PCI_EXPRESS_GENERIC_BRIDGE select LOONGARCH_IPI + select LOONGARCH_PCH_PIC
include/hw/intc/loongarch_pch_pic.h new file +69 -0
69 lines not on this page · raw message
include/hw/pci-host/ls7a.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QEMU LoongArch CPU +* +* Copyright (c) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef HW_LS7A_H +#define HW_LS7A_H + +#include "hw/pci/pci.h" +#include "hw/pci/pcie_host.h" +#include "hw/pci-host/pam.h" +#include "qemu/units.h" +#include "qemu/range.h" +#include "qom/object.h" + +#define LS7A_PCH_REG_BASE 0x10000000UL +#define LS7A_IOAPIC_REG_BASE (LS7A_PCH_REG_BASE) +#define LS7A_PCH_MSI_ADDR_LOW 0x2FF00000UL + +/* +* According to the kernel pch irq start from 64 offset +* 0 ~ 16 irqs used for non-pci device while 16 ~ 64 irqs +* used for pci device. +*/ +#define PCH_PIC_IRQ_OFFSET 64 +#define LS7A_DEVICE_IRQS 16 +#define LS7A_PCI_IRQS 48 +#endif
Signature · 1 line
2.31.1
Re: [PATCH v3 32/43] hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC)
Quoted 14 lines · Xiaojuan Yang
This patch realize the PCH-PIC interrupt controller.
Signed-off-by Xiaojuan Yang<[email protected]>Signed-off-by Song Gao<[email protected]>--- MAINTAINERS | 1 + hw/intc/Kconfig | 4 + hw/intc/loongarch_pch_pic.c | 431 ++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + hw/intc/trace-events | 9 + hw/loongarch/Kconfig | 1 + include/hw/intc/loongarch_pch_pic.h | 69 +++++ include/hw/pci-host/ls7a.h | 30 ++ 8 files changed, 546 insertions(+)
Quoted 3 lines
create mode 100644
hw/intc/loongarch_pch_pic.ccreate mode 100644include/hw/intc/loongarch_pch_pic.hcreate mode 100644include/hw/pci-host/ls7a.h
r~
PATCH v3 33/43 hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI)
In reply to Xiaojuan YangThis patch realize PCH-MSI interrupt controller.
--- hw/intc/Kconfig | 5 ++ hw/intc/loongarch_pch_msi.c | 73 +++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + hw/intc/trace-events | 3 ++ hw/loongarch/Kconfig | 1 + include/hw/intc/loongarch_pch_msi.h | 20 ++++++++ 6 files changed, 103 insertions(+) create mode 100644 hw/intc/loongarch_pch_msi.c create mode 100644 include/hw/intc/loongarch_pch_msi.h
hw/intc/Kconfig +5 -0
@@ -94,3 +94,8 @@ config LOONGARCH_IPI config LOONGARCH_PCH_PIC bool select UNIMP + +config LOONGARCH_PCH_MSI + select MSI_NONBROKEN + bool + select UNIMP
hw/intc/loongarch_pch_msi.c new file +73 -0
73 lines not on this page · raw message
hw/intc/meson.build +1 -0
@@ -65,3 +65,4 @@ specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) specific_ss.add(when: 'CONFIG_NIOS2_VIC', if_true: files('nios2_vic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c'))
hw/intc/trace-events +3 -0
@@ -300,3 +300,6 @@ loongarch_pch_pic_high_readw(unsigned size, uint32_t addr, unsigned long val) "s loongarch_pch_pic_high_writew(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 loongarch_pch_pic_readb(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 loongarch_pch_pic_writeb(unsigned size, uint32_t addr, unsigned long val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx64 + +# loongarch_pch_msi.c +loongarch_msi_set_irq(int irq_num) "set msi irq %d"
hw/loongarch/Kconfig +1 -0
@@ -4,3 +4,4 @@ config LOONGARCH_VIRT select PCI_EXPRESS_GENERIC_BRIDGE select LOONGARCH_IPI select LOONGARCH_PCH_PIC + select LOONGARCH_PCH_MSI
include/hw/intc/loongarch_pch_msi.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch 7A1000 I/O interrupt controller definitions +* +* Copyright (C) 2021 Loongson Technology Corporation Limited +*/ + +#define TYPE_LOONGARCH_PCH_MSI "loongarch_pch_msi" +OBJECT_DECLARE_SIMPLE_TYPE (LoongArchPCHMSI,LOONGARCH_PCH_MSI ) + +/* Msi irq start start from 64 to 255 */ +#define PCH_MSI_IRQ_START 64 +#define PCH_MSI_IRQ_END 255 +#define PCH_MSI_IRQ_NUM 192 + +struct LoongArchPCHMSI { +SysBusDevice parent_obj; +qemu_irq pch_msi_irq[PCH_MSI_IRQ_NUM ]; +MemoryRegion msi_mmio; +};
Signature · 1 line
2.31.1
PATCH v3 34/43 hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
In reply to Xiaojuan YangThis patch realize the EIOINTC interrupt controller.
--- hw/intc/Kconfig | 3 + hw/intc/loongarch_extioi.c | 248 +++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + hw/intc/trace-events | 5 + hw/loongarch/Kconfig | 1 + include/hw/intc/loongarch_extioi.h | 58 +++++++ 6 files changed, 316 insertions(+) create mode 100644 hw/intc/loongarch_extioi.c create mode 100644 include/hw/intc/loongarch_extioi.h
hw/intc/Kconfig +3 -0
@@ -99,3 +99,6 @@ config LOONGARCH_PCH_MSI select MSI_NONBROKEN bool select UNIMP + +config LOONGARCH_EXTIOI + bool
hw/intc/loongarch_extioi.c new file +248 -0
248 lines not on this page · raw message
hw/intc/meson.build +1 -0
@@ -66,3 +66,4 @@ specific_ss.add(when: 'CONFIG_NIOS2_VIC', if_true: files('nios2_vic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c'))
hw/intc/trace-events +5 -0
@@ -303,3 +303,8 @@ loongarch_pch_pic_writeb(unsigned size, uint32_t addr, unsigned long val) "size: # loongarch_pch_msi.c loongarch_msi_set_irq(int irq_num) "set msi irq %d" + +# loongarch_extioi.c +loongarch_extioi_setirq(int irq, int level) "set extirq irq %d level %d" +loongarch_extioi_readw(uint32_t addr, uint32_t val) "addr: 0x%"PRIx32 "val: 0x%" PRIx32 +loongarch_extioi_writew(unsigned size, uint32_t addr, uint32_t val) "size: %u addr: 0x%"PRIx32 "val: 0x%" PRIx32
hw/loongarch/Kconfig +1 -0
@@ -5,3 +5,4 @@ config LOONGARCH_VIRT select LOONGARCH_IPI select LOONGARCH_PCH_PIC select LOONGARCH_PCH_MSI + select LOONGARCH_EXTIOI
include/hw/intc/loongarch_extioi.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 1 line · Xiaojuan Yang
+ int
ipmap_mask=0xff<<ipmap_offset;
...
Quoted 1 line
+ int
cpu_mask=0xff<<ipmap_offset;
These two masks are redundant with
Quoted 1 line
+ ipnum = ((s->ipmap[ipmap_index] &
ipmap_mask) >>ipmap_offset) &0xf;
...
Quoted 1 line
+ cpu = ((s->coremap[cpu_index] &
cpu_mask) >>cpu_offset) &0xf;
the 0xf masking here.
hw/intc/loongarch_extioi.c line 49
Quoted 2 lines
hw/intc/loongarch_extioi.c new file +2
-0+ cpu =ctz32 (cpu); + cpu = (cpu >=4 ) ?0 : cpu;
You are not considering CSR[0x420][49], which changes the format of this mapping.
I think this function is wrong because you maintain an unmapped enable bitmap, but you do not maintain an unmapped status bitmap, which *should* be readable from EXTIOI_ISR_{START,END}, but is not present in extioi_readw.
I think that only extioi_setirq should actually change the unmapped status bitmap, and that extioi_update_irq should only evaluate the mapping to apply changes to the cpus.
hw/intc/loongarch_extioi.c line 61
Quoted 11 lines
hw/intc/loongarch_extioi.c new file +11
-0+if (level) { +/* if not enable return false */ +if (((s->enable[enable_index]) & (1 << enable_mask)) ==0 ) { +return ; + } + s->coreisr[cpu][coreisr_index] |= (1 << coreisr_mask); +qemu_set_irq (s->parent_irq[cpu][ipnum], level); + }else { + s->coreisr[cpu][coreisr_index] &= ~(1 << coreisr_mask); +qemu_set_irq (s->parent_irq[cpu][ipnum], level); + }
This final bit, updating the cpu irq is also wrong, in that it should be unconditional. This is the only way that it will work for the usage in updating the enable mask.
I think you are not considering when the MAP registers overlap outputs. For instance, if all 256 bits of EXT_IOIMap contain 0, then all of EXT_IOI[n*32+31 : n*32] overlap. When that happens, you cannot lower the level of the cpu pin until all of the matching ioi interrupts are low.
Or, perhaps I don't understand how this is supposed to work? The documentation is very weak.
Quoted 9 lines
hw/intc/loongarch_extioi.c new file +9
-0+static void extioi_writew (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +LoongArchExtIOI *s =LOONGARCH_EXTIOI (opaque); +int cpu, index, old_data, data_offset; +uint32_t offset; +trace_loongarch_extioi_writew (size, (uint32_t )addr, val); + + offset = addr &0xffff ;
hw/intc/loongarch_extioi.c line 129
Quoted 10 lines
hw/intc/loongarch_extioi.c new file +10
-0+ +switch (offset) { + case EXTIOI_NODETYPE_START ... EXTIOI_NODETYPE_END - 1: + index = (offset -EXTIOI_NODETYPE_START ) >>2 ; + s->nodetype[index] = val; +break ; + case EXTIOI_IPMAP_START ... EXTIOI_IPMAP_END - 1: + index = (offset -EXTIOI_IPMAP_START ) >>2 ; + s->ipmap[index] = val; +break ;
Do you need to recompute the entire interrupt map when ipmap changes?
hw/intc/loongarch_extioi.c line 139
Quoted 10 lines
hw/intc/loongarch_extioi.c new file +10
-0+ case EXTIOI_ENABLE_START ... EXTIOI_ENABLE_END - 1: + index = (offset -EXTIOI_ENABLE_START ) >>2 ; + old_data = s->enable[index]; +if (old_data != (int )val) { + s->enable[index] = val; + old_data = old_data ^ val; + data_offset =ctz32 (old_data); +while (data_offset !=32 ) { +if (!(val & (1 << data_offset))) { +extioi_update_irq (s, data_offset + index *32 ,0 );
This is not correct -- you're unconditionally setting level=0, corrupting the old value of coreisr[cpu][index]. You need to recompute *without* changning those levels.
hw/intc/loongarch_extioi.c line 169
Quoted 4 lines
hw/intc/loongarch_extioi.c new file +4
-0+ case EXTIOI_COREMAP_START ... EXTIOI_COREMAP_END - 1: + index = (offset -EXTIOI_COREMAP_START ) >>2 ; + s->coremap[index] = val; +break ;
Recompute the entire interrupt map?
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Hi Richard,
Quoted 10 lines · Richard Henderson
Quoted 1 line · Xiaojuan Yang
+ int
ipmap_mask=0xff<<ipmap_offset;...
Quoted 1 line
+ int
cpu_mask=0xff<<ipmap_offset;These two masks are redundant with
Quoted 2 lines
+ ipnum = ((s->ipmap[ipmap_index] &
ipmap_mask) >>ipmap_offset) &0xf;...
Quoted 9 lines
Quoted 1 line
+ cpu = ((s->coremap[cpu_index] &
cpu_mask) >>cpu_offset) &0xf;the
0xfmasking here.Quoted 2 lines
+ cpu = ctz32(cpu);
+ cpu = (cpu >= 4) ? 0 : cpu;You are not considering CSR[0x420][49], which changes the format of this mapping.
Thanks very much, I will consider the mapping format by read iocsr[0x420][49] like this:
static uint64_t map_format(void)
{
LoongArchCPU *cpu;
CPULoongArchState *env;
uint64_t val;
cpu = LOONGARCH_CPU(current_cpu);
env = &(cpu->env);
val = address_space_ldq(&env->address_space_iocsr, 0x420, MEMTXATTRS_UNSPECIFIED, NULL); val &= 1 << 49;
return val;
}
...
if (!map_format()) {
cpu = ctz32(cpu);
cpu = (cpu >= 4) ? 0 : cpu;
}
...
Quoted 4 lines
I think this function is wrong because you maintain an unmapped enable bitmap, but you do not maintain an unmapped status bitmap, which *should* be readable from EXTIOI_ISR_{START,END}, but is not present in
extioi_readw.I think that only
extioi_setirqshould actually change the unmapped status bitmap, and thatextioi_update_irqshould only evaluate the mapping to apply changes to the cpus.
Ok, there should be ISR registers(the status bitmap), i will add it to the LoongArchExtIOI, like this:
struct LoongArchExtIOI {
...
+ uint32_t isr[EXTIOI_IRQS / 32]
...
}
when extioi_setirq, update the isr filed.
static void extioi_setirq(void *opaque, int irq, int level) {
LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); trace_loongarch_extioi_setirq(irq, level); s->isr[irq / 32] |= 1 << irq % 32; extioi_update_irq(s, irq, level);
}
and add ISR_START ... ISR_END to extioi_readw, like this
...
case EXTIOI_ISR_START ... EXTIOI_ISR_END - 1:
index = ((offset - EXTIOI_ISR_START) >> 2; ret = s->isr[index];
break;
...
Quoted 22 lines
This final bit, updating the cpu irq is also wrong, in that it should be unconditional. This is the only way that it will work for the usage in updating the enable mask.
I think you are not considering when the MAP registers overlap outputs. For instance, if all 256 bits of
EXT_IOIMapcontain 0, then all of EXT_IOI[n*32+31 : n*32] overlap. When that happens, you cannot lower the level of the cpu pin until all of the matching ioi interrupts are low.Or, perhaps I don't understand how this is supposed to work? The documentation is very weak.
Quoted 13 lines
hw/intc/loongarch_extioi.c new file +13
-0+static void extioi_writew (void *opaque,hwaddr addr, + uint64_t val, unsigned size) +{ + LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); + int cpu, index, old_data, data_offset; + uint32_t offset; + trace_loongarch_extioi_writew(size, (uint32_t)addr, val); + + offset = addr & 0xffff; + + switch (offset) { + case EXTIOI_NODETYPE_START ... EXTIOI_NODETYPE_END - 1: + index = (offset - EXTIOI_NODETYPE_START) >> 2;
Quoted 9 lines
Quoted 6 lines
+ s->nodetype[index] = val;
+ break;
+ caseEXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'? we only have ipmap and coremap registers in the LoongArchExtIOI, should we add an entire interrupt map?
Quoted 11 lines
Quoted 10 lines
+ case
EXTIOI_ENABLE_START...EXTIOI_ENABLE_END- 1:
+ index = (offset -EXTIOI_ENABLE_START) >> 2;
+old_data= s->enable[index];
+ if (old_data!= (int)val) {
+ s->enable[index] = val;
+old_data=old_data^ val;
+data_offset=ctz32(old_data);
+ while (data_offset!= 32) {
+ if (!(val & (1 <<data_offset))) {
+extioi_update_irq(s, data_offset + index * 32, 0);
Quoted 2 lines
This is not correct -- you're unconditionally setting level=0, corrupting the old value of coreisr[cpu][index]. You need to recompute *without* changning those levels.
Thanks, i will add a condition to judge coreisr[cpu][index], excute extioi_update_irq when the coreisr val is 1, like this:
static int get_coremap(int irq_num)
{
int cpu;
int cpu_index = irq_num / 4;
int cpu_offset = irq_num & 0x3;
int cpu_mask = 0xf << cpu_offset;
cpu = (s->coremap[cpu_index] & cpu_mask) >> cpu_offset; if (!map_format()) {
cpu = ctz32(cpu);
cpu = (cpu >= 4) ? 0 : cpu;
}
return cpu;
}
static int coreisr_level(LoongArchExtIOI *s, int irq_num) {
int cpu = get_coremap(irq_num);
return s->coreisr[cpu][irq_num / 32];
}
...
while (data_offset != 32) {
if (!(val & (1 << data_offset))) {
if (coreisr_level(s, data_offset + index * 32)) { extioi_update_irq(s, data_offset + index * 32, 0); }
}
...
BTW, Could you help us to review the patch [1] or add some other reviewers ?
[1] :
[PATCH v3 40/43] hw/loongarch: Add LoongArch ls7a acpi device support
Thanks.
Xiaojuan
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 9 lines · yangxiaojuan
Quoted 2 lines
You are not considering CSR[0x420][49], which changes the format of this mapping.
Thanks very much, I will consider the mapping format by read iocsr[0x420][49] like this:
staticuint64_tmap_format(void)
{
LoongArchCPU *cpu;
CPULoongArchState *env;
uint64_tval;
Quoted 8 lines
cpu =
LOONGARCH_CPU(current_cpu);
env = &(cpu->env);val =
address_space_ldq(&env->address_space_iocsr, 0x420, MEMTXATTRS_UNSPECIFIED, NULL); val &= 1 << 49;
return val;
}
I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
I see you're putting control of this register into loongarch_qemu_read in target/loongarch/cpu.c. Which, I suppose is fair, because this is documented as part of the 3A5000 cpu documentation. But then you split out all of the devices which are *also* documented as part of the cpu into the board configuration.
This reminds me of the memory-mapped interface that the armv7m cpu has with its own registers. I believe that you need to model this similarly, where you will have a device that represents the cpu, and then instantiates all of the devices that are listed in the Loongson 3A5000 TRM -- call this ls3a to match the ls7a name you have for the 7A1000 bridge device.
When there is a write to the ls3a "Other function configuration register", the ls3a will need to communicate the changes to the various bits to its various sub-devices. I do not think it unreasonable to have direct function calls between the components.
Peter, do you have any advice from the armv7m side?
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
+ case
EXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'?
I mean, ipmap[*] and coremap[*] controls how isr[*] maps to the various cpus, as coreisr[*]. If either ipmap or coremap changes, do you need to re-compute coreisr[*] from the input isr[*]?
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 14 lines · Richard Henderson
I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
I see you're putting control of this register into
loongarch_qemu_readintarget/loongarch/cpu.c. Which, I suppose is fair, because this is documented as part of the 3A5000 cpu documentation. But then you split out all of the devices which are *also* documented as part of the cpu into the board configuration.This reminds me of the memory-mapped interface that the armv7m cpu has with its own registers. I believe that you need to model this similarly, where you will have a device that represents the cpu, and then instantiates all of the devices that are listed in the Loongson 3A5000 TRM -- call this ls3a to match the ls7a name you have for the 7A1000 bridge device.
Quoted 5 lines
When there is a write to the ls3a "Other function configuration register", the ls3a will need to communicate the changes to the various bits to its various sub-devices. I do not think it unreasonable to have direct function calls between the components.
Peter, do you have any advice from the armv7m side?
Nothing concrete. I'm not sure that we'd structure the armv7m stuff the way we have now if we were writing it from scratch, but it's functional enough. (In particular, if MMIO regions were part of Device rather than SysBusDevice then I'd be tempted to suggest that CPUs with MMIO-mapped registers should directly own their MemoryRegions for them. But they aren't, so we can't do that.)
-- PMM
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Richard Henderson
I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
I see you're putting control of this register into
loongarch_qemu_readintarget/loongarch/cpu.c. Which, I suppose is fair, because this is documented as part of the 3A5000 cpu documentation. But then you split out all of the devices which are *also* documented as part of the cpu into the board configuration.This reminds me of the memory-mapped interface that the armv7m cpu has with its own registers. I believe that you need to model this similarly, where you will have a device that represents the cpu, and then instantiates all of the devices that are listed in the Loongson 3A5000 TRM -- call this ls3a to match the ls7a name you have for the 7A1000 bridge device.
When there is a write to the ls3a "Other function configuration register", the ls3a will need to communicate the changes to the various bits to its various sub-devices. I do not think it unreasonable to have direct function calls between the components.
Quoted 8 lines
Quoted 1 line
Peter, do you have any advice from the armv7m side?
Nothing concrete. I'm not sure that we'd structure the armv7m stuff the way we have now if we were writing it from scratch, but it's functional enough. (In particular, if MMIO regions were part of Device rather than SysBusDevice then I'd be tempted to suggest that CPUs with MMIO-mapped registers should directly own their MemoryRegions for them. But they aren't, so we can't do that.)
Having thought about this a little more, I believe that these registers are part of the "cpu package", because they are shared between the 4 cpu cores within the package. Thus their current placement attached to LoongArchCPU -- as well as the current placement of address_space_iocsr -- is incorrect.
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 23 lines · Richard Henderson
Quoted 22 lines · Peter Maydell
Quoted 19 lines · Richard Henderson
I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
I see you're putting control of this register into
loongarch_qemu_readin target/loongarch/cpu.c. Which, I suppose is fair, because this is documented as part of the 3A5000 cpu documentation. But then you split out all of the devices which are *also* documented as part of the cpu into the board configuration.This reminds me of the memory-mapped interface that the armv7m cpu has with its own registers. I believe that you need to model this similarly, where you will have a device that represents the cpu, and then instantiates all of the devices that are listed in the Loongson 3A5000 TRM -- call this ls3a to match the ls7a name you have for the 7A1000 bridge device.
When there is a write to the ls3a "Other function configuration register", the ls3a will need to communicate the changes to the various bits to its various sub-devices. I do not think it unreasonable to have direct function calls between the components.
Peter, do you have any advice from the armv7m side?
Quoted 8 lines
Quoted 6 lines
Nothing concrete. I'm not sure that we'd structure the armv7m stuff the way we have now if we were writing it from scratch, but it's functional enough. (In particular, if MMIO regions were part of Device rather than SysBusDevice then I'd be tempted to suggest that CPUs with MMIO-mapped registers should directly own their MemoryRegions for them. But they aren't, so we can't do that.)
Having thought about this a little more, I believe that these registers are part of the "cpu package", because they are shared between the 4 cpu cores within the package. Thus their current placement attached to LoongArchCPU -- as well as the current placement of
address_space_iocsr-- is incorrect.
The extioi hardware design is not friend to software developer, local cpu INTC is mixed with board INTC with extioi/iocsr. Local cpu INTC registers should be banked, address space is space for local cpu review point.
how about put address_space_iocsr as board rather than percpu since there is no concept of "cpu package".
regards
bibo, mao
Quoted 3 lines
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 33 lines · maobibo
Quoted 30 lines · Richard Henderson
Quoted 28 lines · Peter Maydell
Quoted 14 lines · Richard Henderson
I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
I see you're putting control of this register into
loongarch_qemu_readin target/loongarch/cpu.c. Which, I suppose is fair, because this is documented as part of the 3A5000 cpu documentation. But then you split out all of the devices which are *also* documented as part of the cpu into the board configuration.This reminds me of the memory-mapped interface that the armv7m cpu has with its own registers. I believe that you need to model this similarly, where you will have a device that represents the cpu, and then instantiates all of the devices that are listed in the Loongson 3A5000 TRM -- call this ls3a to match the ls7a name you have for the 7A1000 bridge device.
Quoted 5 lines
When there is a write to the ls3a "Other function configuration register", the ls3a will need to communicate the changes to the various bits to its various sub-devices. I do not think it unreasonable to have direct function calls between the components.
Peter, do you have any advice from the armv7m side?
Nothing concrete. I'm not sure that we'd structure the armv7m stuff the way we have now if we were writing it from scratch, but it's functional enough. (In particular, if MMIO regions were part of Device rather than SysBusDevice then I'd be tempted to suggest that CPUs with MMIO-mapped registers should directly own their MemoryRegions for them. But they aren't, so we can't do that.)
Quoted 5 lines
Quoted 1 line
Having thought about this a little more, I believe that these registers are part of the "cpu package", because they are shared between the 4 cpu cores within the package. Thus their current placement attached to LoongArchCPU -- as well as the current placement of
address_space_iocsr-- is incorrect.The extioi hardware design is not friend to software developer, local cpu INTC is mixed with board INTC with extioi/iocsr. Local cpu INTC registers should be banked, address space is space for local cpu review point.
address space of local cpu INTC should be the same from cpu viewpoint.
Quoted 10 lines
how about put
address_space_iocsras board rather than percpu since there is no concept of "cpu package".regards
bibo, maoQuoted 3 lines
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
In reply to maobiboQuoted 2 lines · maobibo
how about put
address_space_iocsras board rather than percpu since there is no concept of "cpu package".
"cpu package" works ok as a device on the board.
I don't know if it's possible to have the iocsr address space controlled by the device, especially since it appears that the iocsr address space is *also* available -- or at least partially available -- in the main address space at base 0x1fe00000?
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 7 lines · Richard Henderson
Quoted 2 lines · maobibo
how about put
address_space_iocsras board rather than percpu since there is no concept of "cpu package"."cpu package" works ok as a device on the board.
I don't know if it's possible to have the iocsr address space controlled by the device, especially since it appears that the iocsr address space is *also* available -- or at least partially available -- in the main address space at base
0x1fe00000?
In the current hw implementation, iocsr/mmio address space can both be used for IPI/EXTIOI, in future mmio address space will be deprecated and removed, only iocsr will be used since it is easy for hw to abstract the interface.
In the next patch, main address space at base 0x1fe00000 for IPI/EXTIOI will be removed and only iocsr address space will be used. And iocsr address space can controlled by device also.
Quoted 3 lines
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
In reply to Richard HendersonQuoted 11 lines · Richard Henderson
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
+ case
EXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'?
I mean, ipmap[*] and coremap[*] controls how isr[*] maps to the various cpus, as coreisr[*]. If either ipmap or coremap changes, do you need to re-compute coreisr[*] from the input isr[*]?
I think the interrupt has been handled by the core before set coremap or ipmap, and coreisr[*] also has been set and cleard by original core. So, the new mapped core need not to update the coreisr[*].
Thanks.
Xiaojuan
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 8 lines · yangxiaojuan
Quoted 6 lines · Richard Henderson
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
+ case
EXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'?
I mean, ipmap[*] and coremap[*] controls how isr[*] maps to the various cpus, as coreisr[*]. If either ipmap or coremap changes, do you need to re-compute coreisr[*] from the input isr[*]?
I think the interrupt has been handled by the core before set coremap or ipmap, and coreisr[*] also has been set and cleard by original core. So, the new mapped core need not to update the coreisr[*].
Why do you believe that the core to which the interrupt is directed has interrupts enabled? Why do you believe the core to which the interrupt is directed is the one that is changing the interrupt mapping?
I think your assumption is not correct.
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 13 lines · Richard Henderson
Quoted 12 lines · yangxiaojuan
Quoted 10 lines · Richard Henderson
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
+ case
EXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I mean, ipmap[*] and coremap[*] controls how isr[*] maps to the various cpus, as coreisr[*]. If either ipmap or coremap changes, do you need to re-compute coreisr[*] from the input isr[*]?
I think the interrupt has been handled by the core before set coremap or ipmap, and coreisr[*] also has been set and cleard by original core. So, the new mapped core need not to update the coreisr[*].
Why do you believe that the core to which the interrupt is directed has interrupts enabled? Why do you believe the core to which the interrupt is directed is the one that is changing the interrupt mapping?
By my understanding, irq bit of coreisr will be set even if the interrupt is disabled on the core, interrupt has been posted to core already, only that it is not serviced by the core. After irq affinity is changed, new interrupt may arrived to new core, one interrupt will be serviced by old core and new core at the same time. However it is the problem of guest kernel, guest kernel system should disable the irq and wait until irq finishes to be serviced on the old core when irq affinity is changing.
Quoted 5 lines
I think your assumption is not correct.
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
Quoted 8 lines · maobibo
Quoted 6 lines · Richard Henderson
Quoted 5 lines · yangxiaojuan
Quoted 4 lines · Richard Henderson
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ case
EXTIOI_IPMAP_START...EXTIOI_IPMAP_END- 1:
+ index = (offset -EXTIOI_IPMAP_START) >> 2; + s->ipmap[index] = val;
+ break;
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Do you need to recompute the entire interrupt map when ipmap changes?
Sorry, could you explain it in more detail? i can not understand the meanning of 'the entire interrupt map'?
I mean, ipmap[*] and coremap[*] controls how isr[*] maps to the various cpus, as coreisr[*]. If either ipmap or coremap changes, do you need to re-compute coreisr[*] from the input isr[*]?
I think the interrupt has been handled by the core before set coremap or ipmap, and coreisr[*] also has been set and cleard by original core. So, the new mapped core need not to update the coreisr[*].
Why do you believe that the core to which the interrupt is directed has interrupts enabled? Why do you believe the core to which the interrupt is directed is the one that is changing the interrupt mapping?
I think there is no interrupt enable registers of percpu in extioi device. So, i think we need not to consider the core to which the interrupt is directed if has interrupts enabled. If the core to which the interrupt is directed is diffrent from the core that is changing the mapping, Should we copy the status value of coreisr[old_core][irq_num] to coreisr[new_core][irq_num]? Ip mapping could not affect coreisr[cpu][irq_num], Should we still need to update the interrupt?
Thanks.
xiaojuan
Quoted 6 lines
By my understanding, irq bit of coreisr will be set even if the interrupt is disabled on the core, interrupt has been posted to core already, only that it is not serviced by the core. After irq affinity is changed, new interrupt may arrived to new core, one interrupt will be serviced by old core and new core at the same time. However it is the problem of guest kernel, guest kernel system should disable the irq and wait until irq finishes to be serviced on the old core when irq affinity is changing.
Quoted 4 lines
I think your assumption is not correct.
r~
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
In reply to Richard HendersonQuoted 13 lines · Richard Henderson
Quoted 12 lines · yangxiaojuan
Quoted 2 lines
You are not considering CSR[0x420][49], which changes the format of this mapping.
Thanks very much, I will consider the mapping format by read iocsr[0x420][49] like this:
staticuint64_tmap_format(void)
{
LoongArchCPU *cpu;
CPULoongArchState *env;
uint64_tval;cpu =
LOONGARCH_CPU(current_cpu);
env = &(cpu->env);
Quoted 7 lines
Quoted 5 lines
val =
address_space_ldq(&env->address_space_iocsr, 0x420, MEMTXATTRS_UNSPECIFIED, NULL); val &= 1 << 49;
return val;
}I'm not 100% sure how this "Other configuration control register" should be handled, but definitely not like this.
Could we use the bitmapping as the default cpu or ip map format? Becaue we emulate iocsr[0x420] as a default value, and it does not support to write. We will add 'TOOD' logs and continue to modify them when using other routing methods later. What do you think of this idea?
Thanks.
Xiaojuan
Re: [PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC)
In reply to Richard HendersonQuoted 12 lines · Richard Henderson
Quoted 11 lines
+ if (level) {
+ /* if not enable return false */
+ if (((s->enable[enable_index]) & (1 <<enable_mask)) == 0) { + return;
+ }
+ s->coreisr[cpu][coreisr_index] |= (1 <<coreisr_mask); +qemu_set_irq(s->parent_irq[cpu][ipnum], level);
+ } else {
+ s->coreisr[cpu][coreisr_index] &= ~(1 <<coreisr_mask); +qemu_set_irq(s->parent_irq[cpu][ipnum], level);
+ }
Quoted 4 lines
This final bit, updating the cpu irq is also wrong, in that it should be unconditional. This is the only way that it will work for the usage in updating the enable mask.
I think you are not considering when the MAP registers overlap outputs. For instance, if all 256 bits of
EXT_IOIMapcontain 0, then all of EXT_IOI[n*32+31 : n*32] overlap. When that happens, you cannot lower the level of the cpu pin until all of the matching ioi interrupts are low.
Thanks, i should consider the MAP registers overlap outputs.
And i want to add 'uint32_t sw_isr_group[256 / 32]', when each bit of sw_isr_group[n*32+31 : n*32] is 0, then lower the level of the cpu pin.
Thanks.
Xiaojuan
PATCH v3 35/43 hw/loongarch: Add irq hierarchy for the system
In reply to Xiaojuan YangThis patch add the irq hierarchy for the virt board.
--- hw/loongarch/loongson3.c | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)
hw/loongarch/loongson3.c +116 -0
@@ -16,8 +16,122 @@#include "sysemu/rtc.h" #include "hw/loongarch/virt.h" #include "exec/address-spaces.h" +#include "hw/intc/loongarch_ipi.h" +#include "hw/intc/loongarch_extioi.h" +#include "hw/intc/loongarch_pch_pic.h" +#include "hw/intc/loongarch_pch_msi.h" +#include "hw/pci-host/ls7a.h" +#include "target/loongarch/cpu.h" +static void loongarch_irq_init (LoongArchMachineState *lams) +{ +MachineState *ms =MACHINE (lams); +DeviceState *pch_pic, *pch_msi, *cpudev; +DeviceState *ipi, *extioi; +SysBusDevice *d; +LoongArchCPU *lacpu; +CPULoongArchState *env; +CPUState *cpu_state; + +int cpu, pin, i; +unsigned long ipi_addr; + + ipi =qdev_new (TYPE_LOONGARCH_IPI ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (ipi), &error_fatal); + + extioi =qdev_new (TYPE_LOONGARCH_EXTIOI ); +sysbus_realize_and_unref (SYS_BUS_DEVICE (extioi), &error_fatal); + +/* +* The connection of interrupts: +* +-----+ +---------+ +-------+ +* | IPI |--> | CPUINTC | <-- | Timer | +* +-----+ +---------+ +-------+ +* ^ +* | +* +---------+ +* | EIOINTC | +* +---------+ +* ^ ^ +* | | +* +---------+ +---------+ +* | PCH-PIC | | PCH-MSI | +* +---------+ +---------+ +* ^ ^ ^ +* | | | +* +--------+ +---------+ +---------+ +* | UARTs | | Devices | | Devices | +* +--------+ +---------+ +---------+ +*/ +for (cpu =0 ; cpu < ms->smp.cpus; cpu++) { + cpu_state =qemu_get_cpu (cpu); + cpudev =DEVICE (cpu_state); + lacpu =LOONGARCH_CPU (cpu_state); + env = &(lacpu->env); + +/* connect ipi irq to cpu irq */ +qdev_connect_gpio_out (ipi, cpu,qdev_get_gpio_in (cpudev,IRQ_IPI )); +/* IPI iocsr memory region */ +memory_region_add_subregion (&env->system_iocsr,SMP_IPI_MAILBOX , +sysbus_mmio_get_region (SYS_BUS_DEVICE (ipi), + cpu *2 )); +/* IPI system memory region */ + ipi_addr =IPI_SYSTEM_MEM + cpu *0x100 ; +memory_region_add_subregion (get_system_memory (), ipi_addr, +sysbus_mmio_get_region (SYS_BUS_DEVICE (ipi), + cpu *2 +1 )); +/* extioi iocsr memory region */ +memory_region_add_subregion (&env->system_iocsr,APIC_BASE , +sysbus_mmio_get_region (SYS_BUS_DEVICE (extioi), + cpu)); + } + +/* extioi memory region */ +memory_region_add_subregion (get_system_memory (),EXTIOI_SYSTEM_MEM , +sysbus_mmio_get_region (SYS_BUS_DEVICE (extioi), + cpu)); + +/* +* connect ext irq to the cpu irq +* cpu_pin[9:2] <= intc_pin[7:0] +*/ +for (cpu =0 ; cpu < ms->smp.cpus; cpu++) { + cpudev =DEVICE (qemu_get_cpu (cpu)); +for (pin =0 ; pin <LS3A_INTC_IP ; pin++) { +qdev_connect_gpio_out (extioi, (cpu *8 + pin), +qdev_get_gpio_in (cpudev, pin +2 )); + } + } + + pch_pic =qdev_new (TYPE_LOONGARCH_PCH_PIC ); + d =SYS_BUS_DEVICE (pch_pic); +sysbus_realize_and_unref (d, &error_fatal); +memory_region_add_subregion (get_system_memory (),LS7A_IOAPIC_REG_BASE , +sysbus_mmio_get_region (d,0 )); +memory_region_add_subregion (get_system_memory (), +LS7A_IOAPIC_REG_BASE +PCH_PIC_ROUTE_ENTRY_OFFSET , +sysbus_mmio_get_region (d,1 )); +memory_region_add_subregion (get_system_memory (), +LS7A_IOAPIC_REG_BASE +PCH_PIC_INT_STATUS_LO , +sysbus_mmio_get_region (d,2 )); + +/* Connect 64 pch_pic irqs to extioi */ +for (int i =0 ; i <PCH_PIC_IRQ_NUM ; i++) { +qdev_connect_gpio_out (DEVICE (d), i,qdev_get_gpio_in (extioi, i)); + } + + pch_msi =qdev_new (TYPE_LOONGARCH_PCH_MSI ); + d =SYS_BUS_DEVICE (pch_msi); +sysbus_realize_and_unref (d, &error_fatal); +sysbus_mmio_map (d,0 ,LS7A_PCH_MSI_ADDR_LOW ); +for (i =0 ; i <PCH_MSI_IRQ_NUM ; i++) { +/* Connect 192 pch_msi irqs to extioi */ +qdev_connect_gpio_out (DEVICE (d), i, +qdev_get_gpio_in (extioi, i +PCH_MSI_IRQ_START )); + } +} +static void loongarch_init (MachineState *machine) {const char *cpu_model = machine->cpu_type;
@@ -58,6 +172,8 @@ static void loongarch_init(MachineState *machine) get_system_io(), 0, LOONGARCH_ISA_IO_SIZE);memory_region_add_subregion (address_space_mem,LOONGARCH_ISA_IO_BASE , &lams->isa_io); +/* Initialize the IO interrupt subsystem */ +loongarch_irq_init (lams); }static void loongarch_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.31.1
PATCH v3 36/43 Enable common virtio pci support for LoongArch
In reply to Xiaojuan Yang--- softmmu/qdev-monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
softmmu/qdev-monitor.c +2 -1
@@ -60,7 +60,8 @@ typedef struct QDevAlias QEMU_ARCH_HPPA | QEMU_ARCH_I386 | \ QEMU_ARCH_MIPS | QEMU_ARCH_PPC | \ QEMU_ARCH_RISCV | QEMU_ARCH_SH4 | \ - QEMU_ARCH_SPARC | QEMU_ARCH_XTENSA) + QEMU_ARCH_SPARC | QEMU_ARCH_XTENSA | \ + QEMU_ARCH_LOONGARCH)#define QEMU_ARCH_VIRTIO_CCW (QEMU_ARCH_S390X)#define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K)
Signature · 1 line
2.31.1
PATCH v3 37/43 hw/loongarch: Add some devices support for 3A5000.
In reply to Xiaojuan Yang1.Add uart,virtio-net,vga and usb for 3A5000. 2.Add irq set and map for the pci host. Non pci device use irq 0-16, pci device use 16-64.
3.Add some unimplented device to emulate guest unused memory space.
--- hw/loongarch/Kconfig | 7 ++++ hw/loongarch/loongson3.c | 77 ++++++++++++++++++++++++++++++++++++++ include/hw/pci-host/ls7a.h | 8 ++++ 3 files changed, 92 insertions(+)
hw/loongarch/Kconfig +7 -0
@@ -2,6 +2,13 @@ config LOONGARCH_VIRT bool select PCI select PCI_EXPRESS_GENERIC_BRIDGE + imply VGA_PCI + imply VIRTIO_VGA + imply PCI_DEVICES + select ISA_BUS + select SERIAL + select SERIAL_ISA + select VIRTIO_PCI select LOONGARCH_IPI select LOONGARCH_PCH_PIC select LOONGARCH_PCH_MSI
hw/loongarch/loongson3.c +77 -0
103 lines not on this page · raw message
include/hw/pci-host/ls7a.h +8 -0
@@ -15,6 +15,12 @@#include "qemu/range.h" #include "qom/object.h" +#define LS7A_PCI_IO_OFFSET 0x4000 +#define LS_PCIECFG_BASE 0x20000000 +#define LS_PCIECFG_SIZE 0x08000000 +#define LS7A_PCI_IO_BASE 0x18004000UL +#define LS7A_PCI_IO_SIZE 0xC000 +#define LS7A_PCH_REG_BASE 0x10000000UL#define LS7A_IOAPIC_REG_BASE (LS7A_PCH_REG_BASE)#define LS7A_PCH_MSI_ADDR_LOW 0x2FF00000UL
@@ -27,4 +33,6 @@#define PCH_PIC_IRQ_OFFSET 64#define LS7A_DEVICE_IRQS 16#define LS7A_PCI_IRQS 48 +#define LS7A_UART_IRQ (PCH_PIC_IRQ_OFFSET + 2) +#define LS7A_UART_BASE 0x1fe001e0#endif
Signature · 1 line
2.31.1
PATCH v3 38/43 hw/loongarch: Add LoongArch ls7a rtc device support
In reply to Xiaojuan YangThis patch add ls7a rtc device support.
--- MAINTAINERS | 1 + hw/loongarch/Kconfig | 1 + hw/loongarch/loongson3.c | 4 + hw/rtc/Kconfig | 3 + hw/rtc/ls7a_rtc.c | 322 +++++++++++++++++++++++++++++++++++++ hw/rtc/meson.build | 1 + include/hw/pci-host/ls7a.h | 4 + 7 files changed, 336 insertions(+) create mode 100644 hw/rtc/ls7a_rtc.c
MAINTAINERS +1 -0
@@ -1137,6 +1137,7 @@ F: include/hw/loongarch/virt.h F: include/hw/intc/loongarch_*.h F: hw/intc/loongarch_*.c F: include/hw/pci-host/ls7a.h +F: hw/rtc/ls7a_rtc.c M68K Machines -------------
hw/loongarch/Kconfig +1 -0
@@ -13,3 +13,4 @@ config LOONGARCH_VIRT select LOONGARCH_PCH_PIC select LOONGARCH_PCH_MSI select LOONGARCH_EXTIOI + select LS7A_RTC
hw/loongarch/loongson3.c +4 -0
@@ -97,6 +97,10 @@ static void loongarch_devices_init(DeviceState *pch_pic)* Create some unimplemented devices to emulate this. */ create_unimplemented_device ("pci-dma-cfg" ,0x1001041c ,0x4 ); + +sysbus_create_simple ("ls7a_rtc" ,LS7A_RTC_REG_BASE , +qdev_get_gpio_in (pch_pic, +LS7A_RTC_IRQ -PCH_PIC_IRQ_OFFSET )); }static void loongarch_irq_init (LoongArchMachineState *lams)
hw/rtc/Kconfig +3 -0
@@ -27,3 +27,6 @@ config SUN4V_RTC config GOLDFISH_RTC bool + +config LS7A_RTC + bool
hw/rtc/ls7a_rtc.c new file +322 -0
322 lines not on this page · raw message
hw/rtc/meson.build +1 -0
@@ -11,6 +11,7 @@ softmmu_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_rtc.c')) softmmu_ss.add(when: 'CONFIG_SUN4V_RTC', if_true: files('sun4v-rtc.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_rtc.c')) softmmu_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c')) +softmmu_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c')) softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.c')) specific_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
include/hw/pci-host/ls7a.h +4 -0
@@ -35,4 +35,8 @@#define LS7A_PCI_IRQS 48#define LS7A_UART_IRQ (PCH_PIC_IRQ_OFFSET + 2)#define LS7A_UART_BASE 0x1fe001e0 +#define LS7A_RTC_IRQ (PCH_PIC_IRQ_OFFSET + 3) +#define LS7A_MISC_REG_BASE (LS7A_PCH_REG_BASE + 0x00080000) +#define LS7A_RTC_REG_BASE (LS7A_MISC_REG_BASE + 0x00050100) +#define LS7A_RTC_LEN 0x100#endif
Signature · 1 line
2.31.1
Re: [PATCH v3 38/43] hw/loongarch: Add LoongArch ls7a rtc device support
Quoted 20 lines · Xiaojuan Yang
hw/rtc/ls7a_rtc.c new file +20
-0+/* +* Shift bits and filed mask +*/ +#define TOY_MON_MASK 0x3f +#define TOY_DAY_MASK 0x1f +#define TOY_HOUR_MASK 0x1f +#define TOY_MIN_MASK 0x3f +#define TOY_SEC_MASK 0x3f +#define TOY_MSEC_MASK 0xf + +#define TOY_MON_SHIFT 26 +#define TOY_DAY_SHIFT 21 +#define TOY_HOUR_SHIFT 16 +#define TOY_MIN_SHIFT 10 +#define TOY_SEC_SHIFT 4 +#define TOY_MSEC_SHIFT 0 + +#define TOY_MATCH_YEAR_MASK 0x3f +#define TOY_MATCH_MON_MASK 0xf +#define TOY_MATCH_DAY_MASK 0x1f
hw/rtc/ls7a_rtc.c line 65
Quoted 10 lines
hw/rtc/ls7a_rtc.c new file +10
-0+#define TOY_MATCH_HOUR_MASK 0x1f +#define TOY_MATCH_MIN_MASK 0x3f +#define TOY_MATCH_SEC_MASK 0x3f + +#define TOY_MATCH_YEAR_SHIFT 26 +#define TOY_MATCH_MON_SHIFT 22 +#define TOY_MATCH_DAY_SHIFT 17 +#define TOY_MATCH_HOUR_SHIFT 12 +#define TOY_MATCH_MIN_SHIFT 6 +#define TOY_MATCH_SEC_SHIFT 0
While this is ok, it would be better to use <hw/registerfields.h> This becomes
FIELD(TOY, MON, 26, 6)FIELD(TOY, DAY, 21, 5)FIELD(TOY, HOUR, 16, 5)
You then extract with FIELD_EX32(val, TOY, MON), etc.
I will also mention that "millisec" is misnamed in the documentation. Since it represents units of 0.1 seconds, the prefix should be "deci".
Quoted 1 line
+#define
TOY_ENABLE_BIT(1U << 11)
...
hw/rtc/ls7a_rtc.c line 98
Quoted 4 lines
hw/rtc/ls7a_rtc.c new file +4
-0+enum { +TOYEN =1UL <<11 , +RTCEN =1UL <<13 , +};
You have two copies of the same bit. It would be best to fill in the rest of the bits in RTCCTRL, using FIELD().
hw/rtc/ls7a_rtc.c line 135
Quoted 3 lines
hw/rtc/ls7a_rtc.c new file +3
-0+case SYS_RTCREAD0 : + val = s->rtccount; +break ;
Surely this needs to examine qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) and scale the offset back to 32kHz.
Quoted 15 lines
hw/rtc/ls7a_rtc.c new file +15
-0+case SYS_TOYMATCH0 : + s->toymatch[0 ] = val; +qemu_get_timedate (&tm, s->offset); + tm.tm_sec = (val >>TOY_MATCH_SEC_SHIFT ) &TOY_MATCH_SEC_MASK ; + tm.tm_min = (val >>TOY_MATCH_MIN_SHIFT ) &TOY_MATCH_MIN_MASK ; + tm.tm_hour = ((val >>TOY_MATCH_HOUR_SHIFT ) &TOY_MATCH_HOUR_MASK ); + tm.tm_mday = ((val >>TOY_MATCH_DAY_SHIFT ) &TOY_MATCH_DAY_MASK ); + tm.tm_mon = ((val >>TOY_MATCH_MON_SHIFT ) &TOY_MATCH_MON_MASK ) -1 ; + year_diff = ((val >>TOY_MATCH_YEAR_SHIFT ) &TOY_MATCH_YEAR_MASK ); + year_diff = year_diff - (tm.tm_year &TOY_MATCH_YEAR_MASK ); + tm.tm_year = tm.tm_year + year_diff; + alarm_offset =qemu_timedate_diff (&tm) - s->offset; +if ((alarm_offset <0 ) && (alarm_offset >-5 )) { + alarm_offset =0 ; + }
hw/rtc/ls7a_rtc.c line 198
Quoted 10 lines
hw/rtc/ls7a_rtc.c new file +10
-0+ expire_time =qemu_clock_get_ms (rtc_clock); + expire_time += ((alarm_offset *1000 ) +100 ); +timer_mod (s->timer, expire_time); +break ; +case SYS_TOYMATCH1 : + s->toymatch[1 ] = val; +break ; +case SYS_TOYMATCH2 : + s->toymatch[2 ] = val; +break ;
Why does only register 0 affect expire time, and not all 3 registers?
hw/rtc/ls7a_rtc.c line 201
Quoted 3 lines
hw/rtc/ls7a_rtc.c new file +3
-0+case SYS_RTCCTRL : + s->cntrctl = val; +break ;
Need to check REN, TEN, and EO fields.
hw/rtc/ls7a_rtc.c line 204
Quoted 3 lines
hw/rtc/ls7a_rtc.c new file +3
-0+case SYS_RTCWRTIE0 : + s->rtccount = val; +break ;
Need to compute a new rtc_offset from QEMU_CLOCK_VIRTUAL, to match RTCREAD0 above.
hw/rtc/ls7a_rtc.c line 213
Quoted 9 lines
hw/rtc/ls7a_rtc.c new file +9
-0+case SYS_RTCMATCH0 : + s->rtcmatch[0 ] = val; +break ; +case SYS_RTCMATCH1 : + val = s->rtcmatch[1 ]; +break ; +case SYS_RTCMATCH2 : + val = s->rtcmatch[2 ]; +break ;
Why do these not affect expire time?
hw/rtc/ls7a_rtc.c line 249
Quoted 2 lines
hw/rtc/ls7a_rtc.c new file +2
-0+ d->timer =timer_new_ms (rtc_clock, toy_timer, d); +timer_mod (d->timer,qemu_clock_get_ms (rtc_clock) +100 );
Where does this number come from? In any case, after reset I would expect (1) the rtc and toy to be disabled (documentation says must initialize rtcctrl bits) and (2) I would expect all of the comparison registers to be 0 and thus no timer enabled.
I guess this 100 milliseconds thing is trying to match 1 decisecond from TOYMATCH0?
r~
Re: [PATCH v3 38/43] hw/loongarch: Add LoongArch ls7a rtc device support
Quoted 35 lines · Richard Henderson
Quoted 20 lines · Xiaojuan Yang
hw/rtc/ls7a_rtc.c new file +20
-0+/* +* Shift bits and filed mask +*/ +#define TOY_MON_MASK 0x3f +#define TOY_DAY_MASK 0x1f +#define TOY_HOUR_MASK 0x1f +#define TOY_MIN_MASK 0x3f +#define TOY_SEC_MASK 0x3f +#define TOY_MSEC_MASK 0xf + +#define TOY_MON_SHIFT 26 +#define TOY_DAY_SHIFT 21 +#define TOY_HOUR_SHIFT 16 +#define TOY_MIN_SHIFT 10 +#define TOY_SEC_SHIFT 4 +#define TOY_MSEC_SHIFT 0 + +#define TOY_MATCH_YEAR_MASK 0x3f +#define TOY_MATCH_MON_MASK 0xf +#define TOY_MATCH_DAY_MASK 0x1fhw/rtc/ls7a_rtc.c line 65
Quoted 10 lines
hw/rtc/ls7a_rtc.c new file +10
-0+#define TOY_MATCH_HOUR_MASK 0x1f +#define TOY_MATCH_MIN_MASK 0x3f +#define TOY_MATCH_SEC_MASK 0x3f + +#define TOY_MATCH_YEAR_SHIFT 26 +#define TOY_MATCH_MON_SHIFT 22 +#define TOY_MATCH_DAY_SHIFT 17 +#define TOY_MATCH_HOUR_SHIFT 12 +#define TOY_MATCH_MIN_SHIFT 6 +#define TOY_MATCH_SEC_SHIFT 0While this is ok, it would be better to use <
hw/registerfields.h> This becomes
Quoted 8 lines
FIELD(TOY, MON, 26, 6)FIELD(TOY, DAY, 21, 5)FIELD(TOY, HOUR, 16, 5)You then extract with
FIELD_EX32(val, TOY, MON), etc.I will also mention that "millisec" is misnamed in the documentation. Since it represents units of 0.1 seconds, the prefix should be "deci".
Thanks very much, i changed it to this format:
+FIELD(TOY, MON, 26, 6)
+FIELD(TOY, DAY, 21, 5)
+FIELD(TOY, HOUR, 16, 5)
+FIELD(TOY, MIN, 10, 6)
+FIELD(TOY, SEC, 4, 6)
+FIELD(TOY, MSEC, 0, 4)
+
+FIELD(TOY_MATCH, YEAR, 26, 6)
+FIELD(TOY_MATCH, MON, 22, 4)
+FIELD(TOY_MATCH, DAY, 17, 5)
+FIELD(TOY_MATCH, HOUR, 12, 5)
+FIELD(TOY_MATCH, MIN, 6, 6)
+FIELD(TOY_MATCH, SEC, 0, 6)
+
+FIELD(RTC_CTRL, RTCEN, 13, 1)
+FIELD(RTC_CTRL, TOYEN, 11, 1)
+FIELD(RTC_CTRL, EO, 8, 1)
get time from the value, like this:
...
case SYS_TOYWRITE0:
qemu_get_timedate(&tm, s->offset); + tm.tm_sec = FIELD_EX32(val, TOY, SEC); + tm.tm_min = FIELD_EX32(val, TOY, MIN); + tm.tm_hour = FIELD_EX32(val, TOY, HOUR); + tm.tm_mday = FIELD_EX32(val, TOY, DAY); + tm.tm_mon = FIELD_EX32(val, TOY, MON) - 1;
...
Quoted 45 lines
Quoted 1 line
+#define
TOY_ENABLE_BIT(1U << 11)...
hw/rtc/ls7a_rtc.c line 98
Quoted 4 lines
hw/rtc/ls7a_rtc.c new file +4
-0+enum { + TOYEN = 1UL << 11, + RTCEN = 1UL << 13, +};You have two copies of the same bit. It would be best to fill in the rest of the bits in RTCCTRL, using
FIELD().Quoted 3 lines
+ case
SYS_RTCREAD0:
+ val =s->rtccount;
+ break;Surely this needs to examine
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)and scale the offset back to 32kHz.Quoted 21 lines
+ case
SYS_TOYMATCH0:
+ s->toymatch[0] = val;
+qemu_get_timedate(&tm, s->offset);
+ tm.tm_sec = (val >>TOY_MATCH_SEC_SHIFT) &TOY_MATCH_SEC_MASK; + tm.tm_min = (val >>TOY_MATCH_MIN_SHIFT) &TOY_MATCH_MIN_MASK; + tm.tm_hour = ((val >>TOY_MATCH_HOUR_SHIFT) &TOY_MATCH_HOUR_MASK);
+ tm.tm_mday = ((val >>TOY_MATCH_DAY_SHIFT) &TOY_MATCH_DAY_MASK);
+ tm.tm_mon = ((val >>TOY_MATCH_MON_SHIFT) &TOY_MATCH_MON_MASK) - 1;
+year_diff= ((val >>TOY_MATCH_YEAR_SHIFT) &TOY_MATCH_YEAR_MASK);
+year_diff=year_diff- (tm.tm_year &TOY_MATCH_YEAR_MASK); + tm.tm_year = tm.tm_year +year_diff;
+alarm_offset=qemu_timedate_diff(&tm)-s->offset; + if ((alarm_offset< 0) && (alarm_offset> -5)) {
+alarm_offset= 0;
+ }
+expire_time=qemu_clock_get_ms(rtc_clock);
+expire_time+= ((alarm_offset* 1000) + 100);Quoted 8 lines
+
timer_mod(s->timer, expire_time);
+ break;
+ caseSYS_TOYMATCH1:
+ s->toymatch[1] = val;
+ break;
+ caseSYS_TOYMATCH2:
+ s->toymatch[2] = val;
+ break;
Quoted 2 lines
Why does only register 0 affect expire time, and not all 3 registers?
Thanks, the toymatch[1]/[2] should also affect expire time. I fixed it like this:
+static void rtc_toymatch_write(LS7ARtcState *s, struct tm *tm, uint64_t val) +{
+ int64_t alarm_offset, year_diff, expire_time;
+
+ qemu_get_timedate(tm, s->offset);
+ tm->tm_sec = FIELD_EX32(val, TOY_MATCH, SEC);
+ tm->tm_min = FIELD_EX32(val, TOY_MATCH, MIN);
+ tm->tm_hour = FIELD_EX32(val, TOY_MATCH, HOUR);
+ tm->tm_mday = FIELD_EX32(val, TOY_MATCH, DAY);
+ tm->tm_mon = FIELD_EX32(val, TOY_MATCH, MON) - 1;
+ year_diff = FIELD_EX32(val, TOY_MATCH, MON);
+ year_diff = year_diff - (tm->tm_year & TOY_MATCH_YEAR_MASK); + tm->tm_year = tm->tm_year + year_diff;
+ alarm_offset = qemu_timedate_diff(tm) - s->offset;
+ if ((alarm_offset < 0) && (alarm_offset > -5)) {
+ alarm_offset = 0;
+ }
+ expire_time = qemu_clock_get_ms(rtc_clock);
+ expire_time += ((alarm_offset * 1000) + 100);
+ timer_mod(s->timer, expire_time);
+}
...
case SYS_TOYMATCH0:
s->toymatch[0] = val;
+ rtc_toymatch_write(s, &tm, val);
break;
case SYS_TOYMATCH1:
s->toymatch[1] = val;
+ rtc_toymatch_write(s, &tm, val);
break;
case SYS_TOYMATCH2:
s->toymatch[2] = val;
+ rtc_toymatch_write(s, &tm, val);
break;
...
Quoted 6 lines
Quoted 3 lines
+ case
SYS_RTCCTRL:
+s->cntrctl= val;
+ break;Need to check REN, TEN, and EO fields.
Thanks, i fixed the rtc_ctrl writing function like this:
...
case SYS_RTCCTRL:
- s->cntrctl = val;
+ if (FIELD_EX32(val, RTC_CTRL, RTCEN) && + FIELD_EX32(val, RTC_CTRL, TOYEN) && + FIELD_EX32(val, RTC_CTRL, EO)) {
+ s->cntrctl = val;
+ }
...
Quoted 16 lines
Quoted 3 lines
+ case
SYS_RTCWRTIE0:
+s->rtccount= val;
+ break;Need to compute a new
rtc_offsetfromQEMU_CLOCK_VIRTUAL, to match RTCREAD0 above.Quoted 9 lines
+ case
SYS_RTCMATCH0:
+ s->rtcmatch[0] = val;
+ break;
+ caseSYS_RTCMATCH1:
+ val = s->rtcmatch[1];
+ break;
+ caseSYS_RTCMATCH2:
+ val = s->rtcmatch[2];
+ break;
Quoted 2 lines
Why do these not affect expire time?
Sorry, i could not understand this very clearly, could you please explain it in more detail? Thanks very much.
Quoted 6 lines
Quoted 2 lines
+
d->timer=timer_new_ms(rtc_clock, toy_timer, d); +timer_mod(d->timer, qemu_clock_get_ms(rtc_clock) + 100);Where does this number come from? In any case, after reset I would expect (1) the rtc and toy to be disabled (documentation says must initialize rtcctrl bits) and (2) I would expect all of the comparison registers to be 0 and thus no timer enabled. I guess this 100 milliseconds thing is trying to match 1 decisecond from TOYMATCH0?
Thanks, I think i should delete the it.
Thanks.
Xiaojuan
Re: [PATCH v3 38/43] hw/loongarch: Add LoongArch ls7a rtc device support
Quoted 31 lines · yangxiaojuan
Quoted 2 lines
Why does only register 0 affect expire time, and not all 3 registers?
Thanks, the toymatch[1]/[2] should also affect expire time. I fixed it like this:
(quoted diff) +21
-0+static void rtc_toymatch_write(LS7ARtcState *s, struct tm *tm, uint64_t val) +{ + int64_t alarm_offset, year_diff, expire_time; + + qemu_get_timedate(tm, s->offset); + tm->tm_sec = FIELD_EX32(val, TOY_MATCH, SEC); + tm->tm_min = FIELD_EX32(val, TOY_MATCH, MIN); + tm->tm_hour = FIELD_EX32(val, TOY_MATCH, HOUR); + tm->tm_mday = FIELD_EX32(val, TOY_MATCH, DAY); + tm->tm_mon = FIELD_EX32(val, TOY_MATCH, MON) - 1; + year_diff = FIELD_EX32(val, TOY_MATCH, MON); + year_diff = year_diff - (tm->tm_year & TOY_MATCH_YEAR_MASK); + tm->tm_year = tm->tm_year + year_diff; + alarm_offset = qemu_timedate_diff(tm) - s->offset; + if ((alarm_offset < 0) && (alarm_offset > -5)) { + alarm_offset = 0; + } + expire_time = qemu_clock_get_ms(rtc_clock); + expire_time += ((alarm_offset * 1000) + 100); + timer_mod(s->timer, expire_time); +}case
SYS_TOYMATCH0:
s->toymatch[0] = val;
+rtc_toymatch_write(s, &tm, val);
break;
Quoted 8 lines
case
SYS_TOYMATCH1:
s->toymatch[1] = val;
+rtc_toymatch_write(s, &tm, val);
break;
caseSYS_TOYMATCH2:
s->toymatch[2] = val;
+rtc_toymatch_write(s, &tm, val);
break;
You either have to have 6 timer objects, or you have to pick the minimum expire time between the 3 toymatch and the 3 rtcmatch values.
Quoted 7 lines
...
Quoted 6 lines
Quoted 3 lines
+ case
SYS_RTCCTRL:
+s->cntrctl= val;
+ break;Need to check REN, TEN, and EO fields.
Quoted 9 lines
Thanks, i fixed the
rtc_ctrlwriting function like this:
...
caseSYS_RTCCTRL:
-s->cntrctl= val;
+ if (FIELD_EX32(val, RTC_CTRL, RTCEN)&& +FIELD_EX32(val, RTC_CTRL, TOYEN)&& +FIELD_EX32(val, RTC_CTRL, EO)) {
+s->cntrctl= val;
+ }
Uh, no, that's not what I meant by "check".
If TOYEN is off, then the toymatch timers must stop, at minimum; it might also mean that the time of day should not advance -- the documentation isn't clear.
If RTCEN is off, then similarly rtcmatch timers must stop and the rtcread value must not advance.
If EO is off, I would expect all of the above to stop, because the clock source is stopped.
You'd always record the store to s->cntrctl.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ case
SYS_RTCMATCH0:
+ s->rtcmatch[0] = val;
+ break;
+ caseSYS_RTCMATCH1:
+ val = s->rtcmatch[1];
+ break;
+ caseSYS_RTCMATCH2:
+ val = s->rtcmatch[2];
+ break;
Quoted 3 lines
Quoted 2 lines
Why do these not affect expire time?
Sorry, i could not understand this very clearly, could you please explain it in more detail? Thanks very much.
You're not raising an interrupt for any rtcmatch, as you did from toymatch0.
r~
PATCH v3 39/43 hw/loongarch: Add LoongArch load elf function.
In reply to Xiaojuan Yang--- hw/loongarch/loongson3.c | 66 +++++++++++++++++++++++++++++++++++-- include/hw/loongarch/virt.h | 9 +++++ target/loongarch/cpu.h | 2 ++ 3 files changed, 75 insertions(+), 2 deletions(-)
hw/loongarch/loongson3.c +64 -2
@@ -19,6 +19,8 @@#include "exec/address-spaces.h" #include "hw/irq.h" #include "net/net.h" +#include "hw/loader.h" +#include "elf.h" #include "hw/intc/loongarch_ipi.h" #include "hw/intc/loongarch_extioi.h" #include "hw/intc/loongarch_pch_pic.h"
@@ -29,6 +31,36 @@#include "target/loongarch/cpu.h" +static struct _loaderparams { +unsigned long ram_size; +const char *kernel_filename; +} loaderparams; + +static uint64_t cpu_loongarch_virt_to_phys (void *opaque,uint64_t addr) +{ +return addr &0x1fffffffll ; +} + +static int64_t load_kernel_info (void ) +{ +int64_t kernel_entry, kernel_low, kernel_high; +long kernel_size; + + kernel_size =load_elf (loaderparams.kernel_filename,NULL , + cpu_loongarch_virt_to_phys,NULL , + (uint64_t *)&kernel_entry, (uint64_t *)&kernel_low, + (uint64_t *)&kernel_high,NULL ,0 , +EM_LOONGARCH ,1 ,0 ); + +if (kernel_size <0 ) { +error_report ("could not load kernel '%s': %s" , + loaderparams.kernel_filename, +load_elf_strerror (kernel_size)); +exit (1 ); + } +return kernel_entry; +} +static void loongarch_devices_init (DeviceState *pch_pic) {DeviceState *gpex_dev;
@@ -213,15 +245,29 @@ static void loongarch_irq_init(LoongArchMachineState *lams)loongarch_devices_init (pch_pic); } +static void reset_load_elf (void *opaque) +{ +LoongArchCPU *cpu = opaque; +CPULoongArchState *env = &cpu->env; + +cpu_reset (CPU (cpu)); +if (env->load_elf) { +cpu_set_pc (CPU (cpu), env->elf_address); + } +} +static void loongarch_init (MachineState *machine) {const char *cpu_model = machine->cpu_type; +const char *kernel_filename = machine->kernel_filename;ram_addr_t offset =0 ;ram_addr_t ram_size = machine->ram_size;uint64_t highram_size =0 ;MemoryRegion *address_space_mem =get_system_memory ();LoongArchMachineState *lams =LOONGARCH_MACHINE (machine); +LoongArchCPU *lacpu;int i; +int64_t kernel_addr =0 ;if (!cpu_model) { cpu_model =LOONGARCH_CPU_TYPE_NAME ("Loongson-3A5000" );
@@ -237,22 +283,38 @@ static void loongarch_init(MachineState *machine)cpu_create (machine->cpu_type); } +if (ram_size <1 * GiB) { +error_report ("ram_size must be greater than 1G." ); +exit (1 ); + } +/* Add memory region */ memory_region_init_alias (&lams->lowmem,NULL ,"loongarch.lowram" , machine->ram,0 ,256 * MiB);memory_region_add_subregion (address_space_mem, offset, &lams->lowmem); offset +=256 * MiB; - highram_size = ram_size -256 * MiB;memory_region_init_alias (&lams->highmem,NULL ,"loongarch.highmem" , machine->ram, offset, highram_size);memory_region_add_subregion (address_space_mem,0x90000000 , &lams->highmem); -/* Add isa io region */ memory_region_init_alias (&lams->isa_io,NULL ,"isa-io" ,get_system_io (),0 ,LOONGARCH_ISA_IO_SIZE );memory_region_add_subregion (address_space_mem,LOONGARCH_ISA_IO_BASE , &lams->isa_io); +if (kernel_filename) { + loaderparams.ram_size = ram_size; + loaderparams.kernel_filename = kernel_filename; + kernel_addr =load_kernel_info (); +if (!machine->firmware) { +for (i =0 ; i < machine->smp.cpus; i++) { + lacpu =LOONGARCH_CPU (qemu_get_cpu (i)); + lacpu->env.load_elf = true; + lacpu->env.elf_address = kernel_addr; +qemu_register_reset (reset_load_elf, lacpu); + } + } + }/* Initialize the IO interrupt subsystem */ loongarch_irq_init (lams); }
include/hw/loongarch/virt.h +9 -0
@@ -12,12 +12,17 @@#include "hw/boards.h" #include "qemu/queue.h" #include "hw/intc/loongarch_ipi.h" +#include "qemu/units.h" #define LOONGARCH_MAX_VCPUS 4#define LOONGARCH_ISA_IO_BASE 0x18000000UL#define LOONGARCH_ISA_IO_SIZE 0x0004000 +#define FW_CFG_ADDR 0x1e020000 +#define LA_BIOS_BASE 0x1c000000 +#define LA_BIOS_SIZE (4 * MiB) +struct LoongArchMachineState {/*< private >*/ MachineState parent_obj;
@@ -26,6 +31,10 @@ struct LoongArchMachineState {MemoryRegion lowmem;MemoryRegion highmem;MemoryRegion isa_io; +MemoryRegion bios; + +/* State for other subsystems/APIs: */ +FWCfgState *fw_cfg; };#define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt")
target/loongarch/cpu.h +2 -0
@@ -308,6 +308,8 @@ typedef struct CPUArchState {AddressSpace address_space_iocsr;MemoryRegion system_iocsr;MemoryRegion iocsr_mem; +bool load_elf; +uint64_t elf_address; } CPULoongArchState;/**
Signature · 1 line
2.31.1
Re: [PATCH v3 39/43] hw/loongarch: Add LoongArch load elf function.
Quoted 22 lines · Xiaojuan Yang
Signed-off-by Xiaojuan Yang <[email protected]>Signed-off-by Song Gao <[email protected]>--- hw/loongarch/loongson3.c | 66 +++++++++++++++++++++++++++++++++++-- include/hw/loongarch/virt.h | 9 +++++ target/loongarch/cpu.h | 2 ++ 3 files changed, 75 insertions(+), 2 deletions(-)hw/loongarch/loongson3.c +2
-0@@ -19,6 +19,8 @@#include "exec/address-spaces.h" #include "hw/irq.h" #include "net/net.h" +#include "hw/loader.h" +#include "elf.h" #include "hw/intc/loongarch_ipi.h" #include "hw/intc/loongarch_extioi.h" #include "hw/intc/loongarch_pch_pic.h"
hw/loongarch/loongson3.c line 37
Quoted 7 lines
hw/loongarch/loongson3.c +4
-0@@ -29,6 +31,36 @@#include "target/loongarch/cpu.h" +static struct _loaderparams { +unsigned long ram_size; +const char *kernel_filename; +} loaderparams;
Never use "unsigned long", only "uint{32,64}_t" or "size_t". Otherwise you don't know what the host is going to give you.
hw/loongarch/loongson3.c line 46
Quoted 3 lines
hw/loongarch/loongson3.c +3
-0+static int64_t load_kernel_info (void ) +{ +int64_t kernel_entry, kernel_low, kernel_high;
Why are you using signed values here,
hw/loongarch/loongson3.c line 52
Quoted 6 lines
hw/loongarch/loongson3.c +6
-0+long kernel_size; + + kernel_size = load_elf(loaderparams.kernel_filename, NULL, + cpu_loongarch_virt_to_phys, NULL, + (uint64_t *)&kernel_entry, (uint64_t *)&kernel_low, + (uint64_t *)&kernel_high, NULL, 0,
and casting them? Oh, and kernel_size must be ssize_t.
hw/loongarch/loongson3.c static void loongarch_init(MachineState *machine) · line 289
Quoted 8 lines
hw/loongarch/loongson3.c +4
-0@@ -237,22 +283,38 @@ static void loongarch_init(MachineState *machine)cpu_create (machine->cpu_type); } +if (ram_size <1 * GiB) { +error_report ("ram_size must be greater than 1G." ); +exit (1 ); + }
Why is this here? It's certainly not related to load_elf.
r~
PATCH v3 40/43 hw/loongarch: Add LoongArch ls7a acpi device support
In reply to Xiaojuan Yang--- MAINTAINERS | 2 + hw/acpi/Kconfig | 4 + hw/acpi/ls7a.c | 374 +++++++++++++++++++++++++++++++++++++ hw/acpi/meson.build | 1 + hw/loongarch/Kconfig | 2 + hw/loongarch/loongson3.c | 19 +- include/hw/acpi/ls7a.h | 53 ++++++ include/hw/pci-host/ls7a.h | 6 + 8 files changed, 458 insertions(+), 3 deletions(-) create mode 100644 hw/acpi/ls7a.c create mode 100644 include/hw/acpi/ls7a.h
MAINTAINERS +2 -0
@@ -1138,6 +1138,8 @@ F: include/hw/intc/loongarch_*.h F: hw/intc/loongarch_*.c F: include/hw/pci-host/ls7a.h F: hw/rtc/ls7a_rtc.c +F: include/hw/acpi/ls7a.h +F: hw/acpi/ls7a.c M68K Machines -------------
hw/acpi/Kconfig +4 -0
@@ -12,6 +12,10 @@ config ACPI_X86 select ACPI_PCIHP select ACPI_ERST +config ACPI_LOONGARCH + bool + select ACPI + config ACPI_X86_ICH bool select ACPI_X86
hw/acpi/ls7a.c new file +374 -0
374 lines not on this page · raw message
hw/acpi/meson.build +1 -0
@@ -25,6 +25,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c')) acpi_ss.add(when: 'CONFIG_ACPI_ERST', if_true: files('erst.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c')) acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c')) +acpi_ss.add(when: 'CONFIG_ACPI_LOONGARCH', if_true: files('ls7a.c')) if have_tpm acpi_ss.add(files('tpm.c')) endif
hw/loongarch/Kconfig +2 -0
@@ -14,3 +14,5 @@ config LOONGARCH_VIRT select LOONGARCH_PCH_MSI select LOONGARCH_EXTIOI select LS7A_RTC + select ACPI_LOONGARCH + select ACPI_PCI
hw/loongarch/loongson3.c +16 -3
@@ -28,7 +28,8 @@#include "hw/pci-host/ls7a.h" #include "hw/pci-host/gpex.h" #include "hw/misc/unimp.h" - +#include "hw/acpi/aml-build.h" +#include "qapi/qapi-visit-common.h" #include "target/loongarch/cpu.h" static struct _loaderparams {
@@ -63,11 +64,11 @@ static int64_t load_kernel_info(void)static void loongarch_devices_init (DeviceState *pch_pic) { -DeviceState *gpex_dev; +DeviceState *gpex_dev, *ls7a_pm;SysBusDevice *d;PCIBus *pci_bus;MemoryRegion *ecam_alias, *ecam_reg, *pio_alias, *pio_reg; -MemoryRegion *mmio_alias, *mmio_reg; +MemoryRegion *mmio_alias, *mmio_reg, *pm_reg;int i; gpex_dev =qdev_new (TYPE_GPEX_HOST );
@@ -133,6 +134,18 @@ static void loongarch_devices_init(DeviceState *pch_pic)sysbus_create_simple ("ls7a_rtc" ,LS7A_RTC_REG_BASE ,qdev_get_gpio_in (pch_pic,LS7A_RTC_IRQ -PCH_PIC_IRQ_OFFSET )); +/* Init pm */ + ls7a_pm =qdev_new (TYPE_LS7A_PM ); + d =SYS_BUS_DEVICE (ls7a_pm); +sysbus_realize_and_unref (d, &error_fatal); +ls7a_pm_init (ls7a_pm,qdev_get_gpio_in (pch_pic, +ACPI_SCI_IRQ -PCH_PIC_IRQ_OFFSET )); + pm_reg =sysbus_mmio_get_region (d,0 ); +memory_region_add_subregion (get_system_memory (),ACPI_IO_BASE , pm_reg); +memory_region_add_subregion (pm_reg,LS7A_GPE0_STS_REG , +sysbus_mmio_get_region (d,1 )); +memory_region_add_subregion (pm_reg,LS7A_GPE0_RESET_REG , +sysbus_mmio_get_region (d,2 )); }static void loongarch_irq_init (LoongArchMachineState *lams)
include/hw/acpi/ls7a.h new file +53 -0
53 lines not on this page · raw message
include/hw/pci-host/ls7a.h +6 -0
@@ -11,6 +11,7 @@#include "hw/pci/pci.h" #include "hw/pci/pcie_host.h" #include "hw/pci-host/pam.h" +#include "hw/acpi/ls7a.h" #include "qemu/units.h" #include "qemu/range.h" #include "qom/object.h"
@@ -21,6 +22,9 @@#define LS7A_PCI_IO_BASE 0x18004000UL#define LS7A_PCI_IO_SIZE 0xC000 +#define LS7A_PCI_MEM_BASE 0x40000000UL +#define LS7A_PCI_MEM_SIZE 0x40000000UL +#define LS7A_PCH_REG_BASE 0x10000000UL#define LS7A_IOAPIC_REG_BASE (LS7A_PCH_REG_BASE)#define LS7A_PCH_MSI_ADDR_LOW 0x2FF00000UL
@@ -39,4 +43,6 @@#define LS7A_MISC_REG_BASE (LS7A_PCH_REG_BASE + 0x00080000)#define LS7A_RTC_REG_BASE (LS7A_MISC_REG_BASE + 0x00050100)#define LS7A_RTC_LEN 0x100 +#define LS7A_ACPI_REG_BASE (LS7A_MISC_REG_BASE + 0x00050000) +#define LS7A_SCI_IRQ (PCH_PIC_IRQ_OFFSET + 4)#endif
Signature · 1 line
2.31.1
Re: [PATCH v3 40/43] hw/loongarch: Add LoongArch ls7a acpi device support
I know nothing about ACPI, could one of you help out here?
r~
Quoted 580 lines · Xiaojuan Yang
Signed-off-by Xiaojuan Yang <[email protected]>Signed-off-by Song Gao <[email protected]>--- MAINTAINERS | 2 + hw/acpi/Kconfig | 4 + hw/acpi/ls7a.c | 374 +++++++++++++++++++++++++++++++++++++ hw/acpi/meson.build | 1 + hw/loongarch/Kconfig | 2 + hw/loongarch/loongson3.c | 19 +- include/hw/acpi/ls7a.h | 53 ++++++ include/hw/pci-host/ls7a.h | 6 + 8 files changed, 458 insertions(+), 3 deletions(-)create mode 100644
hw/acpi/ls7a.c
create mode 100644include/hw/acpi/ls7a.hMAINTAINERS +2
-0@@ -1138,6 +1138,8 @@ F: include/hw/intc/loongarch_*.h F: hw/intc/loongarch_*.c F: include/hw/pci-host/ls7a.h F: hw/rtc/ls7a_rtc.c +F: include/hw/acpi/ls7a.h +F: hw/acpi/ls7a.c M68K Machines -------------hw/acpi/Kconfig +4
-0@@ -12,6 +12,10 @@ config ACPI_X86 select ACPI_PCIHP select ACPI_ERST +config ACPI_LOONGARCH + bool + select ACPI + config ACPI_X86_ICH bool select ACPI_X86hw/acpi/ls7a.c new file +374
-0@@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* LoongArch ACPI implementation +* +* Copyright (C) 2021 Loongson Technology Corporation Limited +*/ + +#include "qemu/osdep.h" +#include "sysemu/sysemu.h" +#include "hw/hw.h" +#include "hw/irq.h" +#include "sysemu/reset.h" +#include "sysemu/runstate.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/ls7a.h" +#include "hw/nvram/fw_cfg.h" +#include "qemu/config-file.h" +#include "qapi/opts-visitor.h" +#include "qapi/qapi-events-run-state.h" +#include "qapi/error.h" +#include "hw/pci-host/ls7a.h" +#include "hw/mem/pc-dimm.h" +#include "hw/mem/nvdimm.h" +#include "migration/vmstate.h" + +static void ls7a_pm_update_sci_fn (ACPIREGS *regs) +{ +LS7APMState *pm =container_of (regs, LS7APMState, acpi_regs); +acpi_update_sci (&pm->acpi_regs, pm->irq); +} + +static uint64_t ls7a_gpe_readb (void *opaque,hwaddr addr,unsigned width) +{ +LS7APMState *pm = opaque; +return acpi_gpe_ioport_readb (&pm->acpi_regs, addr); +} + +static void ls7a_gpe_writeb (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +LS7APMState *pm = opaque; +acpi_gpe_ioport_writeb (&pm->acpi_regs, addr, val); +acpi_update_sci (&pm->acpi_regs, pm->irq); +} + +static const MemoryRegionOps ls7a_gpe_ops = { + .read = ls7a_gpe_readb, + .write = ls7a_gpe_writeb, + .valid.min_access_size =1 , + .valid.max_access_size =8 , + .impl.min_access_size =1 , + .impl.max_access_size =1 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +#define VMSTATE_GPE_ARRAY (_field, _state) \ + { \ + .name = (stringify(_field)), \ + .version_id = 0, \ + .num = ACPI_GPE0_LEN, \ + .info = &vmstate_info_uint8, \ + .size = sizeof(uint8_t), \ + .flags = VMS_ARRAY | VMS_POINTER, \ + .offset = vmstate_offset_pointer(_state, _field, uint8_t), \ + } + +static uint64_t ls7a_reset_readw (void *opaque,hwaddr addr,unsigned width) +{ +return 0 ; +} + +static void ls7a_reset_writew (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +if (val &1 ) { +qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); +return ; + } +} + +static const MemoryRegionOps ls7a_reset_ops = { + .read = ls7a_reset_readw, + .write = ls7a_reset_writew, + .valid.min_access_size =4 , + .valid.max_access_size =4 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +const VMStateDescription vmstate_ls7a_pm = { + .name ="ls7a_pm" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT16 (acpi_regs.pm1.evt.sts, LS7APMState), +VMSTATE_UINT16 (acpi_regs.pm1.evt.en, LS7APMState), +VMSTATE_UINT16 (acpi_regs.pm1.cnt.cnt, LS7APMState), +VMSTATE_TIMER_PTR (acpi_regs.tmr.timer, LS7APMState), +VMSTATE_INT64 (acpi_regs.tmr.overflow_time, LS7APMState), +VMSTATE_GPE_ARRAY (acpi_regs.gpe.sts, LS7APMState), +VMSTATE_GPE_ARRAY (acpi_regs.gpe.en, LS7APMState), +VMSTATE_END_OF_LIST () + }, +}; + +static inline int64_t acpi_pm_tmr_get_clock (void ) +{ +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ),PM_TIMER_FREQUENCY , +NANOSECONDS_PER_SECOND ); +} + +static uint32_t acpi_pm_tmr_get (ACPIREGS *ar) +{ +uint32_t d =acpi_pm_tmr_get_clock (); +return d &0xffffff ; +} + +static void acpi_pm_tmr_timer (void *opaque) +{ +ACPIREGS *ar = opaque; +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_PMTIMER ,NULL ); + ar->tmr.update_sci (ar); +} + +static uint64_t acpi_pm_tmr_read (void *opaque,hwaddr addr,unsigned width) +{ +return acpi_pm_tmr_get (opaque); +} + +static void acpi_pm_tmr_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +} + +static const MemoryRegionOps acpi_pm_tmr_ops = { + .read = acpi_pm_tmr_read, + .write = acpi_pm_tmr_write, + .valid.min_access_size =4 , + .valid.max_access_size =4 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static void ls7a_pm_tmr_init (ACPIREGS *ar,acpi_update_sci_fn update_sci, +MemoryRegion *parent,uint64_t offset) +{ + ar->tmr.update_sci = update_sci; + ar->tmr.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , acpi_pm_tmr_timer, ar); +memory_region_init_io (&ar->tmr.io,memory_region_owner (parent), + &acpi_pm_tmr_ops, ar,"acpi-tmr" ,4 ); +memory_region_add_subregion (parent, offset, &ar->tmr.io); +} + +static void acpi_pm1_evt_write_sts (ACPIREGS *ar,uint16_t val) +{ +uint16_t pm1_sts =acpi_pm1_evt_get_sts (ar); +if (pm1_sts & val &ACPI_BITMASK_TIMER_STATUS ) { +/* if TMRSTS is reset, then compute the new overflow time */ +acpi_pm_tmr_calc_overflow_time (ar); + } + ar->pm1.evt.sts &= ~val; +} + +static uint64_t acpi_pm_evt_read (void *opaque,hwaddr addr,unsigned width) +{ +ACPIREGS *ar = opaque; +switch (addr) { +case 0 : +return acpi_pm1_evt_get_sts (ar); +case 4 : +return ar->pm1.evt.en; +default : +return 0 ; + } +} + +static void acpi_pm1_evt_write_en (ACPIREGS *ar,uint16_t val) +{ + ar->pm1.evt.en = val; +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC , + val &ACPI_BITMASK_RT_CLOCK_ENABLE ); +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_PMTIMER , + val &ACPI_BITMASK_TIMER_ENABLE ); +} + +static void acpi_pm_evt_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ACPIREGS *ar = opaque; +switch (addr) { +case 0 : +acpi_pm1_evt_write_sts (ar, val); + ar->pm1.evt.update_sci (ar); +break ; +case 4 : +acpi_pm1_evt_write_en (ar, val); + ar->pm1.evt.update_sci (ar); +break ; + } +} + +static const MemoryRegionOps acpi_pm_evt_ops = { + .read = acpi_pm_evt_read, + .write = acpi_pm_evt_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static void ls7a_pm1_evt_init (ACPIREGS *ar,acpi_update_sci_fn update_sci, +MemoryRegion *parent,uint64_t offset) +{ + ar->pm1.evt.update_sci = update_sci; +memory_region_init_io (&ar->pm1.evt.io,memory_region_owner (parent), + &acpi_pm_evt_ops, ar,"acpi-evt" ,8 ); +memory_region_add_subregion (parent, offset, &ar->pm1.evt.io); +} + +static uint64_t acpi_pm_cnt_read (void *opaque,hwaddr addr,unsigned width) +{ +ACPIREGS *ar = opaque; +return ar->pm1.cnt.cnt; +} + +/* ACPI PM1aCNT */ +static void acpi_pm1_cnt_write (ACPIREGS *ar,uint16_t val) +{ + ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE ); + +if (val &ACPI_BITMASK_SLEEP_ENABLE ) { +/* Change suspend type */ +uint16_t sus_typ = (val >>10 ) &7 ; +switch (sus_typ) { +/* Not support s3 s4 yet */ +case 7 :/* Soft power off */ +qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_SHUTDOWN ); +break ; +default : +break ; + } + } +} + +static void acpi_pm_cnt_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +acpi_pm1_cnt_write (opaque, val); +} + +static const MemoryRegionOps acpi_pm_cnt_ops = { + .read = acpi_pm_cnt_read, + .write = acpi_pm_cnt_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; + +static void acpi_notify_wakeup (Notifier *notifier,void *data) +{ +ACPIREGS *ar =container_of (notifier,ACPIREGS , wakeup); +WakeupReason *reason = data; + +switch (*reason) { +case QEMU_WAKEUP_REASON_RTC : + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_RT_CLOCK_STATUS ); +break ; +case QEMU_WAKEUP_REASON_PMTIMER : + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_TIMER_STATUS ); +break ; +case QEMU_WAKEUP_REASON_OTHER : +/* +* ACPI_BITMASK_WAKE_STATUS should be set on resume. +* Pretend that resume was caused by power button +*/ + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_POWER_BUTTON_STATUS ); +break ; +default : +break ; + } +} + +static void ls7a_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, +uint64_t offset) +{ + ar->wakeup.notify = acpi_notify_wakeup; +qemu_register_wakeup_notifier (&ar->wakeup); +memory_region_init_io (&ar->pm1.cnt.io,memory_region_owner (parent), + &acpi_pm_cnt_ops, ar,"acpi-cnt" ,4 ); +memory_region_add_subregion (parent, offset, &ar->pm1.cnt.io); +} + +static void ls7a_pm_reset (DeviceState *d) +{ +LS7APMState *pm =LS7A_PM (d); + +acpi_pm1_evt_reset (&pm->acpi_regs); +acpi_pm1_cnt_reset (&pm->acpi_regs); +acpi_pm_tmr_reset (&pm->acpi_regs); +acpi_gpe_reset (&pm->acpi_regs); + +acpi_update_sci (&pm->acpi_regs, pm->irq); +} + +static void pm_powerdown_req (Notifier *n,void *opaque) +{ +LS7APMState *pm =container_of (n, LS7APMState, powerdown_notifier); + +acpi_pm1_evt_power_down (&pm->acpi_regs); +} + +void ls7a_pm_init (DeviceState *ls7a_pm,qemu_irq pm_irq) +{ +LS7APMState *pm =LS7A_PM (ls7a_pm); + pm->irq = pm_irq; +} + +static void ls7a_pm_realize (DeviceState *dev,Error **errp) +{ +LS7APMState *pm =LS7A_PM (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + +/* +* ls7a board acpi hardware info, including +* acpi system io base address +* acpi gpe length +* acpi sci irq number +*/ + +memory_region_init (&pm->iomem,OBJECT (pm),"ls7a_pm" ,ACPI_IO_SIZE ); +sysbus_init_mmio (sbd, &pm->iomem); + +ls7a_pm_tmr_init (&pm->acpi_regs, ls7a_pm_update_sci_fn, + &pm->iomem,LS7A_PM_TMR_BLK ); +ls7a_pm1_evt_init (&pm->acpi_regs, ls7a_pm_update_sci_fn, + &pm->iomem,LS7A_PM_EVT_BLK ); +ls7a_pm1_cnt_init (&pm->acpi_regs, &pm->iomem,LS7A_PM_CNT_BLK ); + +acpi_gpe_init (&pm->acpi_regs,ACPI_GPE0_LEN ); +memory_region_init_io (&pm->iomem_gpe,OBJECT (pm), &ls7a_gpe_ops, pm, +"acpi-gpe0" ,ACPI_GPE0_LEN ); +sysbus_init_mmio (sbd, &pm->iomem_gpe); + +memory_region_init_io (&pm->iomem_reset,OBJECT (pm), + &ls7a_reset_ops, pm,"acpi-reset" ,4 ); +sysbus_init_mmio (sbd, &pm->iomem_reset); + + pm->powerdown_notifier.notify = pm_powerdown_req; +qemu_register_powerdown_notifier (&pm->powerdown_notifier); +} + +static void ls7a_pm_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = ls7a_pm_realize; + dc->reset = ls7a_pm_reset; + dc->desc ="PM" ; + dc->vmsd = &vmstate_ls7a_pm; +} + +static const TypeInfo ls7a_pm_info = { + .name =TYPE_LS7A_PM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (LS7APMState), + .class_init = ls7a_pm_class_init, +}; + +static void ls7a_pm_register_types (void ) +{ +type_register_static (&ls7a_pm_info); +} + +type_init (ls7a_pm_register_types)hw/acpi/meson.build +1
-0@@ -25,6 +25,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c')) acpi_ss.add(when: 'CONFIG_ACPI_ERST', if_true: files('erst.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c')) acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c')) +acpi_ss.add(when: 'CONFIG_ACPI_LOONGARCH', if_true: files('ls7a.c')) if have_tpm acpi_ss.add(files('tpm.c')) endifhw/loongarch/Kconfig +2
-0@@ -14,3 +14,5 @@ config LOONGARCH_VIRT select LOONGARCH_PCH_MSI select LOONGARCH_EXTIOI select LS7A_RTC + select ACPI_LOONGARCH + select ACPI_PCIhw/loongarch/loongson3.c +16
-3@@ -28,7 +28,8 @@#include "hw/pci-host/ls7a.h" #include "hw/pci-host/gpex.h" #include "hw/misc/unimp.h" - +#include "hw/acpi/aml-build.h" +#include "qapi/qapi-visit-common.h" #include "target/loongarch/cpu.h" static struct _loaderparams {@@ -63,11 +64,11 @@ static int64_t load_kernel_info(void)static void loongarch_devices_init (DeviceState *pch_pic) { -DeviceState *gpex_dev; +DeviceState *gpex_dev, *ls7a_pm;SysBusDevice *d;PCIBus *pci_bus;MemoryRegion *ecam_alias, *ecam_reg, *pio_alias, *pio_reg; -MemoryRegion *mmio_alias, *mmio_reg; +MemoryRegion *mmio_alias, *mmio_reg, *pm_reg;int i; gpex_dev =qdev_new (TYPE_GPEX_HOST );@@ -133,6 +134,18 @@ static void loongarch_devices_init(DeviceState *pch_pic)sysbus_create_simple ("ls7a_rtc" ,LS7A_RTC_REG_BASE ,qdev_get_gpio_in (pch_pic,LS7A_RTC_IRQ -PCH_PIC_IRQ_OFFSET )); +/* Init pm */ + ls7a_pm =qdev_new (TYPE_LS7A_PM ); + d =SYS_BUS_DEVICE (ls7a_pm); +sysbus_realize_and_unref (d, &error_fatal); +ls7a_pm_init (ls7a_pm,qdev_get_gpio_in (pch_pic, +ACPI_SCI_IRQ -PCH_PIC_IRQ_OFFSET )); + pm_reg =sysbus_mmio_get_region (d,0 ); +memory_region_add_subregion (get_system_memory (),ACPI_IO_BASE , pm_reg); +memory_region_add_subregion (pm_reg,LS7A_GPE0_STS_REG , +sysbus_mmio_get_region (d,1 )); +memory_region_add_subregion (pm_reg,LS7A_GPE0_RESET_REG , +sysbus_mmio_get_region (d,2 )); }static void loongarch_irq_init (LoongArchMachineState *lams)include/hw/acpi/ls7a.h new file +53
-0@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QEMU GMCH/LS7A PCI PM Emulation +* +* Copyright (C) 2021 Loongson Technology Corporation Limited +*/ + +#ifndef HW_ACPI_LS7A_H +#define HW_ACPI_LS7A_H + +#include "hw/acpi/acpi.h" +#include "hw/sysbus.h" + +#define LS7A_ACPI_IO_BASE 0x800 +#define LS7A_ACPI_IO_SIZE 0x100 +#define LS7A_PM_EVT_BLK (0x0C)/* 4 bytes */ +#define LS7A_PM_CNT_BLK (0x14)/* 2 bytes */ +#define LS7A_GPE0_STS_REG (0x28)/* 4 bytes */ +#define LS7A_GPE0_ENA_REG (0x2C)/* 4 bytes */ +#define LS7A_GPE0_RESET_REG (0x30)/* 4 bytes */ +#define LS7A_PM_TMR_BLK (0x18)/* 4 bytes */ +#define LS7A_GPE0_LEN (8) +#define ACPI_IO_BASE (LS7A_ACPI_REG_BASE) +#define ACPI_GPE0_LEN (LS7A_GPE0_LEN) +#define ACPI_IO_SIZE (LS7A_ACPI_IO_SIZE) +#define ACPI_SCI_IRQ (LS7A_SCI_IRQ) + +typedef struct LS7APMState { +SysBusDevice parent_obj; +/* +* In ls7a spec says that pm1_cnt register is 32bit width and +* that the upper 16bits are reserved and unused. +* PM1a_CNT_BLK = 2 in FADT so it is defined as uint16_t. +*/ +ACPIREGS acpi_regs; + +MemoryRegion iomem; +MemoryRegion iomem_gpe; +MemoryRegion iomem_reset; + +qemu_irq irq;/* SCI */ + +uint32_t pm_io_base; +Notifier powerdown_notifier; +}LS7APMState ; + +#define TYPE_LS7A_PM "ls7a_pm" +DECLARE_INSTANCE_CHECKER(struct LS7APMState, LS7A_PM, TYPE_LS7A_PM) + +void ls7a_pm_init (DeviceState *ls7a_pm,qemu_irq irq); + +extern const VMStateDescription vmstate_ls7a_pm; +#endif /* HW_ACPI_LS7A_H */ include/hw/pci-host/ls7a.h +6
-0@@ -11,6 +11,7 @@#include "hw/pci/pci.h" #include "hw/pci/pcie_host.h" #include "hw/pci-host/pam.h" +#include "hw/acpi/ls7a.h" #include "qemu/units.h" #include "qemu/range.h" #include "qom/object.h" @@ -21,6 +22,9 @@#define LS7A_PCI_IO_BASE 0x18004000UL#define LS7A_PCI_IO_SIZE 0xC000 +#define LS7A_PCI_MEM_BASE 0x40000000UL +#define LS7A_PCI_MEM_SIZE 0x40000000UL +#define LS7A_PCH_REG_BASE 0x10000000UL#define LS7A_IOAPIC_REG_BASE (LS7A_PCH_REG_BASE)#define LS7A_PCH_MSI_ADDR_LOW 0x2FF00000UL@@ -39,4 +43,6 @@#define LS7A_MISC_REG_BASE (LS7A_PCH_REG_BASE + 0x00080000)#define LS7A_RTC_REG_BASE (LS7A_MISC_REG_BASE + 0x00050100)#define LS7A_RTC_LEN 0x100 +#define LS7A_ACPI_REG_BASE (LS7A_MISC_REG_BASE + 0x00050000) +#define LS7A_SCI_IRQ (PCH_PIC_IRQ_OFFSET + 4)#endif
PATCH v3 41/43 target/loongarch: Add gdb support.
In reply to Xiaojuan Yang--- MAINTAINERS | 1 + configs/targets/loongarch64-softmmu.mak | 1 + gdb-xml/loongarch-base64.xml | 44 ++++++++++++++ gdb-xml/loongarch-fpu64.xml | 57 +++++++++++++++++ target/loongarch/cpu.c | 9 +++ target/loongarch/gdbstub.c | 81 +++++++++++++++++++++++++ target/loongarch/internals.h | 4 ++ target/loongarch/meson.build | 1 + 8 files changed, 198 insertions(+) create mode 100644 gdb-xml/loongarch-base64.xml create mode 100644 gdb-xml/loongarch-fpu64.xml create mode 100644 target/loongarch/gdbstub.c
MAINTAINERS +1 -0
@@ -1140,6 +1140,7 @@ F: include/hw/pci-host/ls7a.h F: hw/rtc/ls7a_rtc.c F: include/hw/acpi/ls7a.h F: hw/acpi/ls7a.c +F: gdb-xml/loongarch*.xml M68K Machines -------------
configs/targets/loongarch64-softmmu.mak +1 -0
@@ -1,3 +1,4 @@ TARGET_ARCH=loongarch64 TARGET_BASE_ARCH=loongarch TARGET_SUPPORTS_MTTCG=y +TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu64.xml
gdb-xml/loongarch-base64.xml new file +44 -0
44 lines not on this page · raw message
gdb-xml/loongarch-fpu64.xml new file +57 -0
57 lines not on this page · raw message
target/loongarch/cpu.c +9 -0
@@ -481,6 +481,8 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)return ; } +loongarch_cpu_register_gdb_regs_for_features (cs); +cpu_reset (cs);qemu_init_vcpu (cs);
@@ -634,6 +636,13 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data) dc->vmsd = &vmstate_loongarch_cpu; cc->sysemu_ops = &loongarch_sysemu_ops; 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 =34 ; + cc->gdb_core_xml_file ="loongarch-base64.xml" ; + cc->gdb_stop_before_watchpoint = true; +#ifdef CONFIG_TCG cc->tcg_ops = &loongarch_tcg_ops;#endif
target/loongarch/gdbstub.c new file +81 -0
81 lines not on this page · raw message
target/loongarch/internals.h +4 -0
@@ -49,4 +49,8 @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size,hwaddr loongarch_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); +int loongarch_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n); +int loongarch_cpu_gdb_write_register (CPUState *cs,uint8_t *mem_buf,int n); +void loongarch_cpu_register_gdb_regs_for_features (CPUState *cs); +#endif
target/loongarch/meson.build +1 -0
@@ -11,6 +11,7 @@ loongarch_tcg_ss.add(files( 'fpu_helper.c', 'op_helper.c', 'translate.c', + 'gdbstub.c', )) loongarch_tcg_ss.add(zlib)
Signature · 1 line
2.31.1
PATCH v3 42/43 tests/tcg/loongarch64: Add hello/memory test in loongarch64 system
In reply to Xiaojuan Yang- We write a very minimal softmmu harness.
- This is a very simple smoke test with no need to run a full Linux/kernel.
- The Makefile.softmmu-target record the rule to run.
--- MAINTAINERS | 1 + tests/tcg/loongarch64/Makefile.softmmu-target | 33 +++++++ tests/tcg/loongarch64/system/boot.S | 56 ++++++++++++ tests/tcg/loongarch64/system/kernel.ld | 30 +++++++ tests/tcg/loongarch64/system/regdef.h | 86 +++++++++++++++++++ 5 files changed, 206 insertions(+) create mode 100644 tests/tcg/loongarch64/Makefile.softmmu-target create mode 100644 tests/tcg/loongarch64/system/boot.S create mode 100644 tests/tcg/loongarch64/system/kernel.ld create mode 100644 tests/tcg/loongarch64/system/regdef.h
MAINTAINERS +1 -0
@@ -218,6 +218,7 @@ M: Song Gao <[email protected]> M: Xiaojuan Yang <[email protected]> S: Maintained F: target/loongarch/ +F: tests/tcg/loongarch64/ M68K TCG CPUs M: Laurent Vivier <[email protected]>
tests/tcg/loongarch64/Makefile.softmmu-target new file +33 -0
@@ -0,0 +1,33 @@ +# +# Loongarch64 system tests +# + +LOONGARCH64_SYSTEM_SRC=$(SRC_PATH)/tests/tcg/loongarch64/system +VPATH+=$(LOONGARCH64_SYSTEM_SRC) + +# These objects provide the basic boot code and helper functions for all tests +CRT_OBJS=boot.o + +LOONGARCH64_TEST_SRCS=$(wildcard $(LOONGARCH64_SYSTEM_SRC)/*.c) +LOONGARCH64_TESTS = $(patsubst $(LOONGARCH64_SYSTEM_SRC)/%.c, %, $(LOONGARCH64_TEST_SRCS)) + +CRT_PATH=$(LOONGARCH64_SYSTEM_SRC) +LINK_SCRIPT=$(LOONGARCH64_SYSTEM_SRC)/kernel.ld +LDFLAGS=-Wl,-T$(LINK_SCRIPT) +TESTS+=$(LOONGARCH64_TESTS) $(MULTIARCH_TESTS) +CFLAGS+=-nostdlib -g -O1 -march=loongarch64 -mabi=lp64d $(MINILIB_INC) +LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc + +# building head blobs +.PRECIOUS: $(CRT_OBJS) + +%.o: $(CRT_PATH)/%.S + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@ + +# Build and link the tests +%: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + +memory: CFLAGS+=-DCHECK_UNALIGNED=0 +# Running +QEMU_OPTS+=-serial chardev:output -kernel
tests/tcg/loongarch64/system/boot.S new file +56 -0
56 lines not on this page · raw message
tests/tcg/loongarch64/system/kernel.ld new file +30 -0
@@ -0,0 +1,30 @@ +ENTRY(_start) + +SECTIONS +{ + /* Linux kernel legacy start address. */ + . = 0x9000000000200000; + _text = .; + .text : { + *(.text) + } + .rodata : { + *(.rodata) + } + _etext = .; + + . = ALIGN(8192); + _data = .; + .got : { + *(.got) + } + .data : { + *(.sdata) + *(.data) + } + _edata = .; + .bss : { + *(.bss) + } + _end = .; +}
tests/tcg/loongarch64/system/regdef.h new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 43/43 target/loongarch: 'make check-tcg' support
In reply to Xiaojuan YangFrom: Song Gao <[email protected]>
--- tests/tcg/configure.sh | 1 + 1 file changed, 1 insertion(+)
tests/tcg/configure.sh +1 -0
@@ -51,6 +51,7 @@ fi : ${cross_cc_cflags_armeb="-mbig-endian"} : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"} : ${cross_cc_cflags_hexagon="-mv67 -O2 -static"} +: ${cross_cc_loongarch64="loongarch64-unknown-linux-gnu-gcc"} : ${cross_cc_hppa="hppa-linux-gnu-gcc"} : ${cross_cc_i386="i686-linux-gnu-gcc"} : ${cross_cc_cflags_i386="-m32"}
Signature · 1 line
2.31.1
Hi Richard and Mark,
Could you help us review the patch [1] ?
[1] :
[PATCH v3 34/43] hw/intc: Add LoongArch extioi interrupt [PATCH v3 38/43] hw/loongarch: Add LoongArch ls7a rtc device support [PATCH v3 39/43] hw/loongarch: Add LoongArch load elf function. [PATCH v3 40/43] hw/loongarch: Add LoongArch ls7a acpi device support
Thanks.
Xiaojuan
Quoted 227 lines · Xiaojuan Yang
Hi All,
As this series only supports running binary files in ELF format, and does not depend on BIOS and kernel file. so this series are changed from RFC to patch v1.
The manual:
- https://github.com/loongson/LoongArch-Documentation/releases/tag/2022.03.17Old series:
- https://patchew.org/QEMU/[email protected]/
- https://patchew.org/QEMU/[email protected]/Thanks.
Xiaojuan-----
v3:- Add Check
csr_names.
- DropCSR_CPUID, usecpu->cpu_index.
- Fixed loongarch extioi device emulation. ipmap and coremap register change to 32bits.
-Check_iocsr()function moved toloongarch_ipi_writel().
- Pch_pic/msi useqdev_init_gpio_out()to init irq, and useqdev_connect_gpio_out()to connect irq.
- Load elf function moved tohw/loongarch/loongson.cv2:
- Improvents to CSR/IOCSR instructions translation.
- Fixed extioi device emulation. It is represented by only one memory region.
- Fixed IPI device emulation. The registers are represented withuint64_t.
- Usedo_cpu_reset()andcpu_set_pc()to specify the load address.v2: https://patchew.org/QEMU/[email protected]/
v1: https://patchew.org/QEMU/[email protected]/Song Gao (18):
target/loongarch: Add README
target/loongarch: Add core definition
target/loongarch: Add main translation routines target/loongarch: Add fixed point arithmetic instruction translation target/loongarch: Add fixed point shift instruction translation target/loongarch: Add fixed point bit instruction translation target/loongarch: Add fixed point load/store instruction translation target/loongarch: Add fixed point atomic instruction translation target/loongarch: Add fixed point extra instruction translation target/loongarch: Add floating point arithmetic instruction
translation
target/loongarch: Add floating point comparison instruction
translation
target/loongarch: Add floating point conversion instruction
translation
target/loongarch: Add floating point move instruction translation target/loongarch: Add floating point load/store instruction
translation
target/loongarch: Add branch instruction translation target/loongarch: Add disassembler
target/loongarch: Add target build suport target/loongarch: 'make check-tcg' supportXiaojuan Yang (25):
target/loongarch: Add system emulation introduction target/loongarch: Add CSRs definition
target/loongarch: Add basic vmstate description of CPU. target/loongarch: Implementqmp_query_cpu_definitions()target/loongarch: Add MMU support for LoongArch CPU. target/loongarch: Add LoongArch interrupt and exception handle target/loongarch: Add constant timer support target/loongarch: Add LoongArch CSR instruction target/loongarch: Add LoongArch IOCSR instruction target/loongarch: Add TLB instruction support target/loongarch: Add other core instructions support target/loongarch: Add timer related instructions support. hw/loongarch: Add support loongson3 virt machine type. hw/loongarch: Add LoongArch ipi interrupt support(IPI) hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC) hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI) hw/intc: Add LoongArch extioi interrupt controller(EIOINTC) hw/loongarch: Add irq hierarchy for the system
Enable common virtio pci support for LoongArch hw/loongarch: Add some devices support for 3A5000. hw/loongarch: Add LoongArch ls7a rtc device support hw/loongarch: Add LoongArch load elf function. hw/loongarch: Add LoongArch ls7a acpi device support target/loongarch: Add gdb support.
tests/tcg/loongarch64: Add hello/memory test in loongarch64 systemMAINTAINERS | 26 + .../devices/loongarch64-softmmu/default.mak | 3 + configs/targets/loongarch64-softmmu.mak | 4 + docs/system/loongarch/loongson3.rst | 41 + gdb-xml/loongarch-base64.xml | 44 + gdb-xml/loongarch-fpu64.xml | 57 ++ hw/Kconfig | 1 + hw/acpi/Kconfig | 4 + hw/acpi/ls7a.c | 374 ++++++++ hw/acpi/meson.build | 1 + hw/intc/Kconfig | 15 + hw/intc/loongarch_extioi.c | 248 +++++ hw/intc/loongarch_ipi.c | 242 +++++ hw/intc/loongarch_pch_msi.c | 73 ++ hw/intc/loongarch_pch_pic.c | 431 +++++++++ hw/intc/meson.build | 4 + hw/intc/trace-events | 21 + hw/loongarch/Kconfig | 18 + hw/loongarch/loongson3.c | 361 ++++++++ hw/loongarch/meson.build | 4 + hw/meson.build | 1 + hw/rtc/Kconfig | 3 + hw/rtc/ls7a_rtc.c | 322 +++++++ hw/rtc/meson.build | 1 + include/disas/dis-asm.h | 2 + include/exec/poison.h | 2 + include/hw/acpi/ls7a.h | 53 ++ include/hw/intc/loongarch_extioi.h | 58 ++ include/hw/intc/loongarch_ipi.h | 52 ++ include/hw/intc/loongarch_pch_msi.h | 20 + include/hw/intc/loongarch_pch_pic.h | 69 ++ include/hw/loongarch/virt.h | 42 + include/hw/pci-host/ls7a.h | 48 + include/sysemu/arch_init.h | 1 + meson.build | 1 + qapi/machine-target.json | 6 +- qapi/machine.json | 2 +- softmmu/qdev-monitor.c | 3 +- target/Kconfig | 1 + target/loongarch/Kconfig | 2 + target/loongarch/README | 64 ++ target/loongarch/constant_timer.c | 64 ++ target/loongarch/cpu-csr.h | 208 +++++ target/loongarch/cpu-param.h | 18 + target/loongarch/cpu.c | 698 ++++++++++++++ target/loongarch/cpu.h | 391 ++++++++ target/loongarch/csr_helper.c | 92 ++ target/loongarch/disas.c | 757 +++++++++++++++ target/loongarch/fpu_helper.c | 862 ++++++++++++++++++ target/loongarch/gdbstub.c | 81 ++ target/loongarch/helper.h | 131 +++ target/loongarch/insn_trans/trans_arith.c.inc | 304 ++++++ .../loongarch/insn_trans/trans_atomic.c.inc | 113 +++ target/loongarch/insn_trans/trans_bit.c.inc | 212 +++++ .../loongarch/insn_trans/trans_branch.c.inc | 83 ++ target/loongarch/insn_trans/trans_extra.c.inc | 101 ++ .../loongarch/insn_trans/trans_farith.c.inc | 105 +++ target/loongarch/insn_trans/trans_fcmp.c.inc | 56 ++ target/loongarch/insn_trans/trans_fcnv.c.inc | 33 + .../loongarch/insn_trans/trans_fmemory.c.inc | 153 ++++ target/loongarch/insn_trans/trans_fmov.c.inc | 157 ++++ .../loongarch/insn_trans/trans_memory.c.inc | 229 +++++ .../insn_trans/trans_privileged.c.inc | 465 ++++++++++ target/loongarch/insn_trans/trans_shift.c.inc | 106 +++ target/loongarch/insns.decode | 486 ++++++++++ target/loongarch/internals.h | 56 ++ target/loongarch/iocsr_helper.c | 67 ++ target/loongarch/machine.c | 102 +++ target/loongarch/meson.build | 30 + target/loongarch/op_helper.c | 132 +++ target/loongarch/tlb_helper.c | 763 ++++++++++++++++ target/loongarch/translate.c | 280 ++++++ target/loongarch/translate.h | 45 + target/meson.build | 1 + tests/tcg/configure.sh | 1 + tests/tcg/loongarch64/Makefile.softmmu-target | 33 + tests/tcg/loongarch64/system/boot.S | 56 ++ tests/tcg/loongarch64/system/kernel.ld | 30 + tests/tcg/loongarch64/system/regdef.h | 86 ++ 79 files changed, 10308 insertions(+), 4 deletions(-)create mode 100644 configs/devices/loongarch64-softmmu/default.mak create mode 100644 configs/targets/loongarch64-softmmu.mak create mode 100644
docs/system/loongarch/loongson3.rstcreate mode 100644gdb-xml/loongarch-base64.xml
create mode 100644gdb-xml/loongarch-fpu64.xml
create mode 100644hw/acpi/ls7a.c
create mode 100644hw/intc/loongarch_extioi.c
create mode 100644hw/intc/loongarch_ipi.c
create mode 100644hw/intc/loongarch_pch_msi.c
create mode 100644hw/intc/loongarch_pch_pic.c
create mode 100644 hw/loongarch/Kconfig
create mode 100644hw/loongarch/loongson3.c
create mode 100644 hw/loongarch/meson.build
create mode 100644hw/rtc/ls7a_rtc.c
create mode 100644include/hw/acpi/ls7a.h
create mode 100644include/hw/intc/loongarch_extioi.hcreate mode 100644include/hw/intc/loongarch_ipi.h
create mode 100644include/hw/intc/loongarch_pch_msi.hcreate mode 100644include/hw/intc/loongarch_pch_pic.hcreate mode 100644include/hw/loongarch/virt.h
create mode 100644include/hw/pci-host/ls7a.h
create mode 100644 target/loongarch/Kconfig
create mode 100644 target/loongarch/README
create mode 100644target/loongarch/constant_timer.ccreate mode 100644target/loongarch/cpu-csr.h
create mode 100644target/loongarch/cpu-param.h
create mode 100644target/loongarch/cpu.c
create mode 100644target/loongarch/cpu.h
create mode 100644target/loongarch/csr_helper.c
create mode 100644target/loongarch/disas.c
create mode 100644target/loongarch/fpu_helper.c
create mode 100644target/loongarch/gdbstub.c
create mode 100644target/loongarch/helper.h
create mode 100644 target/loongarch/insn_trans/trans_arith.c.inc create mode 100644 target/loongarch/insn_trans/trans_atomic.c.inc create mode 100644 target/loongarch/insn_trans/trans_bit.c.inc create mode 100644 target/loongarch/insn_trans/trans_branch.c.inc create mode 100644 target/loongarch/insn_trans/trans_extra.c.inc create mode 100644 target/loongarch/insn_trans/trans_farith.c.inc create mode 100644 target/loongarch/insn_trans/trans_fcmp.c.inc create mode 100644 target/loongarch/insn_trans/trans_fcnv.c.inc create mode 100644 target/loongarch/insn_trans/trans_fmemory.c.inc create mode 100644 target/loongarch/insn_trans/trans_fmov.c.inc create mode 100644 target/loongarch/insn_trans/trans_memory.c.inc create mode 100644 target/loongarch/insn_trans/trans_privileged.c.inc create mode 100644 target/loongarch/insn_trans/trans_shift.c.inc create mode 100644 target/loongarch/insns.decode
create mode 100644target/loongarch/internals.h
create mode 100644target/loongarch/iocsr_helper.c
create mode 100644target/loongarch/machine.c
create mode 100644 target/loongarch/meson.build
create mode 100644target/loongarch/op_helper.c
create mode 100644target/loongarch/tlb_helper.c
create mode 100644target/loongarch/translate.c
create mode 100644target/loongarch/translate.h
create mode 100644 tests/tcg/loongarch64/Makefile.softmmu-target create mode 100644tests/tcg/loongarch64/system/boot.Screate mode 100644 tests/tcg/loongarch64/system/kernel.ld create mode 100644tests/tcg/loongarch64/system/regdef.h