* [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c
@ 2025-09-22 7:33 Bibo Mao
2025-09-22 7:33 ` [PATCH 1/5] " Bibo Mao
` (4 more replies)
0 siblings, 5 replies; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:33 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
Some functions defined in file target/loongarch/cpu.c are TCG specified,
new file target/loongarch/tcg/tcg_cpu.c is created here and move TCG
specified functions to new file.
Bibo Mao (5):
target/loongarch: Move TCG specified functions to tcg_cpu.c
target/loongarch: Set function loongarch_cpu_has_work() as public
target/loongarch: Set file tcg_cpu.c separate from cpu.c
target/loongarch: Move function do_raise_exception() to tcg_cpu.c
target/loongarch: Define loongarch_exception_name() as static
target/loongarch/cpu.c | 318 +-------------------------
target/loongarch/cpu.h | 3 +
target/loongarch/internals.h | 2 -
target/loongarch/tcg/meson.build | 1 +
target/loongarch/tcg/tcg_cpu.c | 322 +++++++++++++++++++++++++++
target/loongarch/tcg/tcg_loongarch.h | 1 +
6 files changed, 329 insertions(+), 318 deletions(-)
create mode 100644 target/loongarch/tcg/tcg_cpu.c
base-commit: ab8008b231e758e03c87c1c483c03afdd9c02e19
--
2.39.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/5] target/loongarch: Move TCG specified functions to tcg_cpu.c
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
@ 2025-09-22 7:33 ` Bibo Mao
2025-09-22 7:33 ` [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public Bibo Mao
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:33 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
New file target/loongarch/tcg/tcg_cpu.c is created, and move TCG
specified functions to here from file target/loongarch/cpu.c
It is only code movement and there is no any function change.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 251 +-------------------------------
target/loongarch/tcg/tcg_cpu.c | 255 +++++++++++++++++++++++++++++++++
2 files changed, 256 insertions(+), 250 deletions(-)
create mode 100644 target/loongarch/tcg/tcg_cpu.c
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 55ee317bf2..20ef221fb2 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -140,16 +140,6 @@ void loongarch_cpu_set_irq(void *opaque, int irq, int level)
}
}
-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)
{
@@ -163,215 +153,6 @@ static inline bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env)
}
#endif
-#ifdef CONFIG_TCG
-#ifndef CONFIG_USER_ONLY
-static void loongarch_cpu_do_interrupt(CPUState *cs)
-{
- CPULoongArchState *env = cpu_env(cs);
- bool update_badinstr = 1;
- int cause = -1;
- 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) {
- qemu_log_mask(CPU_LOG_INT,
- "%s enter: pc " TARGET_FMT_lx " ERA " TARGET_FMT_lx
- " TLBRERA " TARGET_FMT_lx " exception: %d (%s)\n",
- __func__, env->pc, env->CSR_ERA, env->CSR_TLBRERA,
- cs->exception_index,
- loongarch_exception_name(cs->exception_index));
- }
-
- 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);
- set_pc(env, 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:
- case EXCCODE_ADEF:
- cause = cs->exception_index;
- update_badinstr = 0;
- break;
- case EXCCODE_SYS:
- case EXCCODE_BRK:
- case EXCCODE_INE:
- case EXCCODE_IPE:
- case EXCCODE_FPD:
- case EXCCODE_FPE:
- case EXCCODE_SXD:
- case EXCCODE_ASXD:
- env->CSR_BADV = env->pc;
- QEMU_FALLTHROUGH;
- case EXCCODE_BCE:
- case EXCCODE_ADEM:
- case EXCCODE_PIL:
- case EXCCODE_PIS:
- case EXCCODE_PME:
- case EXCCODE_PNR:
- case EXCCODE_PNX:
- case EXCCODE_PPI:
- cause = cs->exception_index;
- break;
- default:
- qemu_log("Error: exception(%d) has not been supported\n",
- 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,
- EXCODE_MCODE(cause));
- env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ESUBCODE,
- EXCODE_SUBCODE(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 (vec_size) {
- vec_size = (1 << vec_size) * 4;
- }
-
- 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);
- set_pc(env, 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 " TARGET_FMT_lx "ExS"
- TARGET_FMT_lx "\n",
- __func__, env->pc, env->CSR_ERA,
- cause, env->CSR_BADV, env->CSR_DERA, vector,
- env->CSR_ECFG, env->CSR_ESTAT);
- } else {
- if (tlbfill) {
- set_pc(env, env->CSR_TLBRENTRY);
- } else {
- set_pc(env, env->CSR_EENTRY + EXCODE_MCODE(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 " TARGET_FMT_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)
-{
- CPULoongArchState *env = cpu_env(cs);
-
- 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) {
- CPULoongArchState *env = cpu_env(cs);
-
- 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;
-}
-
-static vaddr loongarch_pointer_wrap(CPUState *cs, int mmu_idx,
- vaddr result, vaddr base)
-{
- return is_va32(cpu_env(cs)) ? (uint32_t)result : result;
-}
-#endif
-
-static TCGTBCPUState loongarch_get_tb_cpu_state(CPUState *cs)
-{
- CPULoongArchState *env = cpu_env(cs);
- uint32_t flags;
-
- flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK);
- flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, FPE) * HW_FLAGS_EUEN_FPE;
- flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, SXE) * HW_FLAGS_EUEN_SXE;
- flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, ASXE) * HW_FLAGS_EUEN_ASXE;
- flags |= is_va32(env) * HW_FLAGS_VA32;
-
- return (TCGTBCPUState){ .pc = env->pc, .flags = flags };
-}
-
-static void loongarch_cpu_synchronize_from_tb(CPUState *cs,
- const TranslationBlock *tb)
-{
- tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
- set_pc(cpu_env(cs), tb->pc);
-}
-
-static void loongarch_restore_state_to_opc(CPUState *cs,
- const TranslationBlock *tb,
- const uint64_t *data)
-{
- set_pc(cpu_env(cs), data[0]);
-}
-#endif /* CONFIG_TCG */
-
#ifndef CONFIG_USER_ONLY
static bool loongarch_cpu_has_work(CPUState *cs)
{
@@ -386,16 +167,6 @@ static bool loongarch_cpu_has_work(CPUState *cs)
}
#endif /* !CONFIG_USER_ONLY */
-static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch)
-{
- CPULoongArchState *env = cpu_env(cs);
-
- if (FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PG)) {
- return FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PLV);
- }
- return MMU_DA_IDX;
-}
-
static void loongarch_la464_init_csr(Object *obj)
{
#ifndef CONFIG_USER_ONLY
@@ -883,27 +654,7 @@ static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)
}
#ifdef CONFIG_TCG
-static const TCGCPUOps loongarch_tcg_ops = {
- .guest_default_memory_order = 0,
- .mttcg_supported = true,
-
- .initialize = loongarch_translate_init,
- .translate_code = loongarch_translate_code,
- .get_tb_cpu_state = loongarch_get_tb_cpu_state,
- .synchronize_from_tb = loongarch_cpu_synchronize_from_tb,
- .restore_state_to_opc = loongarch_restore_state_to_opc,
- .mmu_index = loongarch_cpu_mmu_index,
-
-#ifndef CONFIG_USER_ONLY
- .tlb_fill = loongarch_cpu_tlb_fill,
- .pointer_wrap = loongarch_pointer_wrap,
- .cpu_exec_interrupt = loongarch_cpu_exec_interrupt,
- .cpu_exec_halt = loongarch_cpu_has_work,
- .cpu_exec_reset = cpu_reset,
- .do_interrupt = loongarch_cpu_do_interrupt,
- .do_transaction_failed = loongarch_cpu_do_transaction_failed,
-#endif
-};
+#include "tcg/tcg_cpu.c"
#endif /* CONFIG_TCG */
#ifndef CONFIG_USER_ONLY
diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
new file mode 100644
index 0000000000..f09a695968
--- /dev/null
+++ b/target/loongarch/tcg/tcg_cpu.c
@@ -0,0 +1,255 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * LoongArch CPU parameters for QEMU.
+ *
+ * Copyright (c) 2025 Loongson Technology Corporation Limited
+ */
+
+#ifndef CONFIG_USER_ONLY
+static void loongarch_cpu_do_interrupt(CPUState *cs)
+{
+ CPULoongArchState *env = cpu_env(cs);
+ bool update_badinstr = 1;
+ int cause = -1;
+ 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) {
+ qemu_log_mask(CPU_LOG_INT,
+ "%s enter: pc " TARGET_FMT_lx " ERA " TARGET_FMT_lx
+ " TLBRERA " TARGET_FMT_lx " exception: %d (%s)\n",
+ __func__, env->pc, env->CSR_ERA, env->CSR_TLBRERA,
+ cs->exception_index,
+ loongarch_exception_name(cs->exception_index));
+ }
+
+ 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);
+ set_pc(env, 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:
+ case EXCCODE_ADEF:
+ cause = cs->exception_index;
+ update_badinstr = 0;
+ break;
+ case EXCCODE_SYS:
+ case EXCCODE_BRK:
+ case EXCCODE_INE:
+ case EXCCODE_IPE:
+ case EXCCODE_FPD:
+ case EXCCODE_FPE:
+ case EXCCODE_SXD:
+ case EXCCODE_ASXD:
+ env->CSR_BADV = env->pc;
+ QEMU_FALLTHROUGH;
+ case EXCCODE_BCE:
+ case EXCCODE_ADEM:
+ case EXCCODE_PIL:
+ case EXCCODE_PIS:
+ case EXCCODE_PME:
+ case EXCCODE_PNR:
+ case EXCCODE_PNX:
+ case EXCCODE_PPI:
+ cause = cs->exception_index;
+ break;
+ default:
+ qemu_log("Error: exception(%d) has not been supported\n",
+ 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,
+ EXCODE_MCODE(cause));
+ env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ESUBCODE,
+ EXCODE_SUBCODE(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 (vec_size) {
+ vec_size = (1 << vec_size) * 4;
+ }
+
+ 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);
+ set_pc(env, 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 " TARGET_FMT_lx "ExS"
+ TARGET_FMT_lx "\n",
+ __func__, env->pc, env->CSR_ERA,
+ cause, env->CSR_BADV, env->CSR_DERA, vector,
+ env->CSR_ECFG, env->CSR_ESTAT);
+ } else {
+ if (tlbfill) {
+ set_pc(env, env->CSR_TLBRENTRY);
+ } else {
+ set_pc(env, env->CSR_EENTRY + EXCODE_MCODE(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 " TARGET_FMT_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)
+{
+ CPULoongArchState *env = cpu_env(cs);
+
+ if (access_type == MMU_INST_FETCH) {
+ do_raise_exception(env, EXCCODE_ADEF, retaddr);
+ } else {
+ do_raise_exception(env, EXCCODE_ADEM, retaddr);
+ }
+}
+
+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;
+}
+
+static bool loongarch_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
+{
+ if (interrupt_request & CPU_INTERRUPT_HARD) {
+ CPULoongArchState *env = cpu_env(cs);
+
+ 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;
+}
+
+static vaddr loongarch_pointer_wrap(CPUState *cs, int mmu_idx,
+ vaddr result, vaddr base)
+{
+ return is_va32(cpu_env(cs)) ? (uint32_t)result : result;
+}
+#endif
+
+static TCGTBCPUState loongarch_get_tb_cpu_state(CPUState *cs)
+{
+ CPULoongArchState *env = cpu_env(cs);
+ uint32_t flags;
+
+ flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK);
+ flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, FPE) * HW_FLAGS_EUEN_FPE;
+ flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, SXE) * HW_FLAGS_EUEN_SXE;
+ flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, ASXE) * HW_FLAGS_EUEN_ASXE;
+ flags |= is_va32(env) * HW_FLAGS_VA32;
+
+ return (TCGTBCPUState){ .pc = env->pc, .flags = flags };
+}
+
+static void loongarch_cpu_synchronize_from_tb(CPUState *cs,
+ const TranslationBlock *tb)
+{
+ tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
+ set_pc(cpu_env(cs), tb->pc);
+}
+
+static void loongarch_restore_state_to_opc(CPUState *cs,
+ const TranslationBlock *tb,
+ const uint64_t *data)
+{
+ set_pc(cpu_env(cs), data[0]);
+}
+
+static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch)
+{
+ CPULoongArchState *env = cpu_env(cs);
+
+ if (FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PG)) {
+ return FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PLV);
+ }
+ return MMU_DA_IDX;
+}
+
+static const TCGCPUOps loongarch_tcg_ops = {
+ .guest_default_memory_order = 0,
+ .mttcg_supported = true,
+
+ .initialize = loongarch_translate_init,
+ .translate_code = loongarch_translate_code,
+ .get_tb_cpu_state = loongarch_get_tb_cpu_state,
+ .synchronize_from_tb = loongarch_cpu_synchronize_from_tb,
+ .restore_state_to_opc = loongarch_restore_state_to_opc,
+ .mmu_index = loongarch_cpu_mmu_index,
+
+#ifndef CONFIG_USER_ONLY
+ .tlb_fill = loongarch_cpu_tlb_fill,
+ .pointer_wrap = loongarch_pointer_wrap,
+ .cpu_exec_interrupt = loongarch_cpu_exec_interrupt,
+ .cpu_exec_halt = loongarch_cpu_has_work,
+ .cpu_exec_reset = cpu_reset,
+ .do_interrupt = loongarch_cpu_do_interrupt,
+ .do_transaction_failed = loongarch_cpu_do_transaction_failed,
+#endif
+};
--
2.39.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
2025-09-22 7:33 ` [PATCH 1/5] " Bibo Mao
@ 2025-09-22 7:33 ` Bibo Mao
2025-09-22 14:27 ` Richard Henderson
2025-09-22 7:33 ` [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c Bibo Mao
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:33 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
Function loongarch_cpu_has_work() is defined as static, it is used
by files target/loongarch/cpu.c and target/loongarch/tcg/tcg_cpu.c,
set it as public and declare it in header file target/loongarch/cpu.h
The same with function cpu_loongarch_hw_interrupts_pending().
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 4 ++--
target/loongarch/cpu.h | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 20ef221fb2..6eb8c3214a 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -141,7 +141,7 @@ void loongarch_cpu_set_irq(void *opaque, int irq, int level)
}
/* Check if there is pending and not masked out interrupt */
-static inline bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env)
+bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env)
{
uint32_t pending;
uint32_t status;
@@ -154,7 +154,7 @@ static inline bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env)
#endif
#ifndef CONFIG_USER_ONLY
-static bool loongarch_cpu_has_work(CPUState *cs)
+bool loongarch_cpu_has_work(CPUState *cs)
{
bool has_work = false;
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index c8b96f74dc..5475b6e44f 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -478,6 +478,9 @@ static inline void set_pc(CPULoongArchState *env, uint64_t value)
}
}
+bool loongarch_cpu_has_work(CPUState *cs);
+bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env);
+
/*
* LoongArch CPUs hardware flags.
*/
--
2.39.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
2025-09-22 7:33 ` [PATCH 1/5] " Bibo Mao
2025-09-22 7:33 ` [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public Bibo Mao
@ 2025-09-22 7:33 ` Bibo Mao
2025-09-22 14:29 ` Richard Henderson
2025-09-22 7:33 ` [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c Bibo Mao
2025-09-22 7:34 ` [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static Bibo Mao
4 siblings, 1 reply; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:33 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
Remove inline included with file tcg_cpu.c, and set it separate
with file target/loongarch/cpu.c
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 9 ---------
target/loongarch/tcg/meson.build | 1 +
target/loongarch/tcg/tcg_cpu.c | 13 ++++++++++++-
target/loongarch/tcg/tcg_loongarch.h | 1 +
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 6eb8c3214a..b449ede56d 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -28,11 +28,6 @@
#ifdef CONFIG_KVM
#include <linux/kvm.h>
#endif
-#ifdef CONFIG_TCG
-#include "accel/tcg/cpu-ldst.h"
-#include "accel/tcg/cpu-ops.h"
-#include "tcg/tcg.h"
-#endif
#include "tcg/tcg_loongarch.h"
const char * const regnames[32] = {
@@ -653,10 +648,6 @@ static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)
}
}
-#ifdef CONFIG_TCG
-#include "tcg/tcg_cpu.c"
-#endif /* CONFIG_TCG */
-
#ifndef CONFIG_USER_ONLY
#include "hw/core/sysemu-cpu-ops.h"
diff --git a/target/loongarch/tcg/meson.build b/target/loongarch/tcg/meson.build
index bdf34f9673..b7adfe46f1 100644
--- a/target/loongarch/tcg/meson.build
+++ b/target/loongarch/tcg/meson.build
@@ -7,6 +7,7 @@ loongarch_ss.add([zlib, gen])
loongarch_ss.add(files(
'fpu_helper.c',
'op_helper.c',
+ 'tcg_cpu.c',
'translate.c',
'vec_helper.c',
))
diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
index f09a695968..c7f49838e3 100644
--- a/target/loongarch/tcg/tcg_cpu.c
+++ b/target/loongarch/tcg/tcg_cpu.c
@@ -4,6 +4,17 @@
*
* Copyright (c) 2025 Loongson Technology Corporation Limited
*/
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "accel/accel-cpu-target.h"
+#include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-ops.h"
+#include "exec/translation-block.h"
+#include "exec/target_page.h"
+#include "tcg_loongarch.h"
+#include "internals.h"
#ifndef CONFIG_USER_ONLY
static void loongarch_cpu_do_interrupt(CPUState *cs)
@@ -232,7 +243,7 @@ static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch)
return MMU_DA_IDX;
}
-static const TCGCPUOps loongarch_tcg_ops = {
+const TCGCPUOps loongarch_tcg_ops = {
.guest_default_memory_order = 0,
.mttcg_supported = true,
diff --git a/target/loongarch/tcg/tcg_loongarch.h b/target/loongarch/tcg/tcg_loongarch.h
index 47702893e3..7fb627f2d6 100644
--- a/target/loongarch/tcg/tcg_loongarch.h
+++ b/target/loongarch/tcg/tcg_loongarch.h
@@ -9,6 +9,7 @@
#include "cpu.h"
#include "cpu-mmu.h"
+extern const TCGCPUOps loongarch_tcg_ops;
void loongarch_csr_translate_init(void);
bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
--
2.39.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
` (2 preceding siblings ...)
2025-09-22 7:33 ` [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c Bibo Mao
@ 2025-09-22 7:33 ` Bibo Mao
2025-09-22 14:32 ` Richard Henderson
2025-09-22 7:34 ` [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static Bibo Mao
4 siblings, 1 reply; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:33 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
Function do_raise_exception() is specified with TCG mode, so move
it to file target/loongarch/tcg/tcg_cpu.c
It is only code movement and there is no any function change.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 56 ----------------------------------
target/loongarch/tcg/tcg_cpu.c | 56 ++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index b449ede56d..5d4085fe7e 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -44,62 +44,6 @@ const char * const fregnames[32] = {
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
};
-struct TypeExcp {
- int32_t exccode;
- const char * const name;
-};
-
-static const struct TypeExcp excp_names[] = {
- {EXCCODE_INT, "Interrupt"},
- {EXCCODE_PIL, "Page invalid exception for load"},
- {EXCCODE_PIS, "Page invalid exception for store"},
- {EXCCODE_PIF, "Page invalid exception for fetch"},
- {EXCCODE_PME, "Page modified exception"},
- {EXCCODE_PNR, "Page Not Readable exception"},
- {EXCCODE_PNX, "Page Not Executable exception"},
- {EXCCODE_PPI, "Page Privilege error"},
- {EXCCODE_ADEF, "Address error for instruction fetch"},
- {EXCCODE_ADEM, "Address error for Memory access"},
- {EXCCODE_SYS, "Syscall"},
- {EXCCODE_BRK, "Break"},
- {EXCCODE_INE, "Instruction Non-Existent"},
- {EXCCODE_IPE, "Instruction privilege error"},
- {EXCCODE_FPD, "Floating Point Disabled"},
- {EXCCODE_FPE, "Floating Point Exception"},
- {EXCCODE_DBP, "Debug breakpoint"},
- {EXCCODE_BCE, "Bound Check Exception"},
- {EXCCODE_SXD, "128 bit vector instructions Disable exception"},
- {EXCCODE_ASXD, "256 bit vector instructions Disable exception"},
- {EXCP_HLT, "EXCP_HLT"},
-};
-
-const char *loongarch_exception_name(int32_t exception)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(excp_names); i++) {
- if (excp_names[i].exccode == exception) {
- return excp_names[i].name;
- }
- }
- return "Unknown";
-}
-
-void G_NORETURN do_raise_exception(CPULoongArchState *env,
- uint32_t exception,
- uintptr_t pc)
-{
- CPUState *cs = env_cpu(env);
-
- qemu_log_mask(CPU_LOG_INT, "%s: exception: %d (%s)\n",
- __func__,
- exception,
- loongarch_exception_name(exception));
- cs->exception_index = exception;
-
- cpu_loop_exit_restore(cs, pc);
-}
-
static void loongarch_cpu_set_pc(CPUState *cs, vaddr value)
{
set_pc(cpu_env(cs), value);
diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
index c7f49838e3..59b5800ecf 100644
--- a/target/loongarch/tcg/tcg_cpu.c
+++ b/target/loongarch/tcg/tcg_cpu.c
@@ -16,6 +16,62 @@
#include "tcg_loongarch.h"
#include "internals.h"
+struct TypeExcp {
+ int32_t exccode;
+ const char * const name;
+};
+
+static const struct TypeExcp excp_names[] = {
+ {EXCCODE_INT, "Interrupt"},
+ {EXCCODE_PIL, "Page invalid exception for load"},
+ {EXCCODE_PIS, "Page invalid exception for store"},
+ {EXCCODE_PIF, "Page invalid exception for fetch"},
+ {EXCCODE_PME, "Page modified exception"},
+ {EXCCODE_PNR, "Page Not Readable exception"},
+ {EXCCODE_PNX, "Page Not Executable exception"},
+ {EXCCODE_PPI, "Page Privilege error"},
+ {EXCCODE_ADEF, "Address error for instruction fetch"},
+ {EXCCODE_ADEM, "Address error for Memory access"},
+ {EXCCODE_SYS, "Syscall"},
+ {EXCCODE_BRK, "Break"},
+ {EXCCODE_INE, "Instruction Non-Existent"},
+ {EXCCODE_IPE, "Instruction privilege error"},
+ {EXCCODE_FPD, "Floating Point Disabled"},
+ {EXCCODE_FPE, "Floating Point Exception"},
+ {EXCCODE_DBP, "Debug breakpoint"},
+ {EXCCODE_BCE, "Bound Check Exception"},
+ {EXCCODE_SXD, "128 bit vector instructions Disable exception"},
+ {EXCCODE_ASXD, "256 bit vector instructions Disable exception"},
+ {EXCP_HLT, "EXCP_HLT"},
+};
+
+const char *loongarch_exception_name(int32_t exception)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(excp_names); i++) {
+ if (excp_names[i].exccode == exception) {
+ return excp_names[i].name;
+ }
+ }
+ return "Unknown";
+}
+
+void G_NORETURN do_raise_exception(CPULoongArchState *env,
+ uint32_t exception,
+ uintptr_t pc)
+{
+ CPUState *cs = env_cpu(env);
+
+ qemu_log_mask(CPU_LOG_INT, "%s: exception: %d (%s)\n",
+ __func__,
+ exception,
+ loongarch_exception_name(exception));
+ cs->exception_index = exception;
+
+ cpu_loop_exit_restore(cs, pc);
+}
+
#ifndef CONFIG_USER_ONLY
static void loongarch_cpu_do_interrupt(CPUState *cs)
{
--
2.39.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
` (3 preceding siblings ...)
2025-09-22 7:33 ` [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c Bibo Mao
@ 2025-09-22 7:34 ` Bibo Mao
2025-09-22 14:32 ` Richard Henderson
4 siblings, 1 reply; 11+ messages in thread
From: Bibo Mao @ 2025-09-22 7:34 UTC (permalink / raw)
To: Song Gao; +Cc: Jiaxun Yang, qemu-devel
Function loongarch_exception_name() is only called in defined file
target/loongarch/tcg/tcg_cpu.c, set this function as static.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/internals.h | 2 --
target/loongarch/tcg/tcg_cpu.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h
index e50d109767..29956f0fbe 100644
--- a/target/loongarch/internals.h
+++ b/target/loongarch/internals.h
@@ -24,8 +24,6 @@ void G_NORETURN do_raise_exception(CPULoongArchState *env,
uint32_t exception,
uintptr_t pc);
-const char *loongarch_exception_name(int32_t exception);
-
#ifdef CONFIG_TCG
int ieee_ex_to_loongarch(int xcpt);
void restore_fp_status(CPULoongArchState *env);
diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
index 59b5800ecf..82b54e6dc3 100644
--- a/target/loongarch/tcg/tcg_cpu.c
+++ b/target/loongarch/tcg/tcg_cpu.c
@@ -45,7 +45,7 @@ static const struct TypeExcp excp_names[] = {
{EXCP_HLT, "EXCP_HLT"},
};
-const char *loongarch_exception_name(int32_t exception)
+static const char *loongarch_exception_name(int32_t exception)
{
int i;
--
2.39.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public
2025-09-22 7:33 ` [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public Bibo Mao
@ 2025-09-22 14:27 ` Richard Henderson
0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2025-09-22 14:27 UTC (permalink / raw)
To: Bibo Mao, Song Gao; +Cc: Jiaxun Yang, qemu-devel
On 9/22/25 00:33, Bibo Mao wrote:
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -478,6 +478,9 @@ static inline void set_pc(CPULoongArchState *env, uint64_t value)
> }
> }
>
> +bool loongarch_cpu_has_work(CPUState *cs);
> +bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env);
> +
> /*
> * LoongArch CPUs hardware flags.
> */
Better to declare these in internals.h. Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c
2025-09-22 7:33 ` [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c Bibo Mao
@ 2025-09-22 14:29 ` Richard Henderson
2025-09-23 2:41 ` Bibo Mao
0 siblings, 1 reply; 11+ messages in thread
From: Richard Henderson @ 2025-09-22 14:29 UTC (permalink / raw)
To: Bibo Mao, Song Gao; +Cc: Jiaxun Yang, qemu-devel
On 9/22/25 00:33, Bibo Mao wrote:
> Remove inline included with file tcg_cpu.c, and set it separate
> with file target/loongarch/cpu.c
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> target/loongarch/cpu.c | 9 ---------
> target/loongarch/tcg/meson.build | 1 +
> target/loongarch/tcg/tcg_cpu.c | 13 ++++++++++++-
> target/loongarch/tcg/tcg_loongarch.h | 1 +
> 4 files changed, 14 insertions(+), 10 deletions(-)
I think this should be squashed with patch 1.
The intermediate #include of tcg/tcg_cpu.c was odd.
With that,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
>
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index 6eb8c3214a..b449ede56d 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -28,11 +28,6 @@
> #ifdef CONFIG_KVM
> #include <linux/kvm.h>
> #endif
> -#ifdef CONFIG_TCG
> -#include "accel/tcg/cpu-ldst.h"
> -#include "accel/tcg/cpu-ops.h"
> -#include "tcg/tcg.h"
> -#endif
> #include "tcg/tcg_loongarch.h"
>
> const char * const regnames[32] = {
> @@ -653,10 +648,6 @@ static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)
> }
> }
>
> -#ifdef CONFIG_TCG
> -#include "tcg/tcg_cpu.c"
> -#endif /* CONFIG_TCG */
> -
> #ifndef CONFIG_USER_ONLY
> #include "hw/core/sysemu-cpu-ops.h"
>
> diff --git a/target/loongarch/tcg/meson.build b/target/loongarch/tcg/meson.build
> index bdf34f9673..b7adfe46f1 100644
> --- a/target/loongarch/tcg/meson.build
> +++ b/target/loongarch/tcg/meson.build
> @@ -7,6 +7,7 @@ loongarch_ss.add([zlib, gen])
> loongarch_ss.add(files(
> 'fpu_helper.c',
> 'op_helper.c',
> + 'tcg_cpu.c',
> 'translate.c',
> 'vec_helper.c',
> ))
> diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
> index f09a695968..c7f49838e3 100644
> --- a/target/loongarch/tcg/tcg_cpu.c
> +++ b/target/loongarch/tcg/tcg_cpu.c
> @@ -4,6 +4,17 @@
> *
> * Copyright (c) 2025 Loongson Technology Corporation Limited
> */
> +#include "qemu/osdep.h"
> +#include "qemu/accel.h"
> +#include "qemu/error-report.h"
> +#include "qemu/log.h"
> +#include "accel/accel-cpu-target.h"
> +#include "accel/tcg/cpu-ldst.h"
> +#include "accel/tcg/cpu-ops.h"
> +#include "exec/translation-block.h"
> +#include "exec/target_page.h"
> +#include "tcg_loongarch.h"
> +#include "internals.h"
>
> #ifndef CONFIG_USER_ONLY
> static void loongarch_cpu_do_interrupt(CPUState *cs)
> @@ -232,7 +243,7 @@ static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch)
> return MMU_DA_IDX;
> }
>
> -static const TCGCPUOps loongarch_tcg_ops = {
> +const TCGCPUOps loongarch_tcg_ops = {
> .guest_default_memory_order = 0,
> .mttcg_supported = true,
>
> diff --git a/target/loongarch/tcg/tcg_loongarch.h b/target/loongarch/tcg/tcg_loongarch.h
> index 47702893e3..7fb627f2d6 100644
> --- a/target/loongarch/tcg/tcg_loongarch.h
> +++ b/target/loongarch/tcg/tcg_loongarch.h
> @@ -9,6 +9,7 @@
> #include "cpu.h"
> #include "cpu-mmu.h"
>
> +extern const TCGCPUOps loongarch_tcg_ops;
> void loongarch_csr_translate_init(void);
>
> bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c
2025-09-22 7:33 ` [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c Bibo Mao
@ 2025-09-22 14:32 ` Richard Henderson
0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2025-09-22 14:32 UTC (permalink / raw)
To: Bibo Mao, Song Gao; +Cc: Jiaxun Yang, qemu-devel
On 9/22/25 00:33, Bibo Mao wrote:
> Function do_raise_exception() is specified with TCG mode, so move
> it to file target/loongarch/tcg/tcg_cpu.c
>
> It is only code movement and there is no any function change.
>
> Signed-off-by: Bibo Mao<maobibo@loongson.cn>
> ---
> target/loongarch/cpu.c | 56 ----------------------------------
> target/loongarch/tcg/tcg_cpu.c | 56 ++++++++++++++++++++++++++++++++++
> 2 files changed, 56 insertions(+), 56 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
I'll note that loongarch_exception_name is now only used within tcg_cpu.c.
r~
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static
2025-09-22 7:34 ` [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static Bibo Mao
@ 2025-09-22 14:32 ` Richard Henderson
0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2025-09-22 14:32 UTC (permalink / raw)
To: Bibo Mao, Song Gao; +Cc: Jiaxun Yang, qemu-devel
On 9/22/25 00:34, Bibo Mao wrote:
> Function loongarch_exception_name() is only called in defined file
> target/loongarch/tcg/tcg_cpu.c, set this function as static.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> target/loongarch/internals.h | 2 --
> target/loongarch/tcg/tcg_cpu.c | 2 +-
> 2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h
> index e50d109767..29956f0fbe 100644
> --- a/target/loongarch/internals.h
> +++ b/target/loongarch/internals.h
> @@ -24,8 +24,6 @@ void G_NORETURN do_raise_exception(CPULoongArchState *env,
> uint32_t exception,
> uintptr_t pc);
>
> -const char *loongarch_exception_name(int32_t exception);
> -
> #ifdef CONFIG_TCG
> int ieee_ex_to_loongarch(int xcpt);
> void restore_fp_status(CPULoongArchState *env);
> diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
> index 59b5800ecf..82b54e6dc3 100644
> --- a/target/loongarch/tcg/tcg_cpu.c
> +++ b/target/loongarch/tcg/tcg_cpu.c
> @@ -45,7 +45,7 @@ static const struct TypeExcp excp_names[] = {
> {EXCP_HLT, "EXCP_HLT"},
> };
>
> -const char *loongarch_exception_name(int32_t exception)
> +static const char *loongarch_exception_name(int32_t exception)
> {
> int i;
>
Ha ha. My comment vs patch 4 was anticipated.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c
2025-09-22 14:29 ` Richard Henderson
@ 2025-09-23 2:41 ` Bibo Mao
0 siblings, 0 replies; 11+ messages in thread
From: Bibo Mao @ 2025-09-23 2:41 UTC (permalink / raw)
To: Richard Henderson, Song Gao; +Cc: Jiaxun Yang, qemu-devel
On 2025/9/22 下午10:29, Richard Henderson wrote:
> On 9/22/25 00:33, Bibo Mao wrote:
>> Remove inline included with file tcg_cpu.c, and set it separate
>> with file target/loongarch/cpu.c
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>> target/loongarch/cpu.c | 9 ---------
>> target/loongarch/tcg/meson.build | 1 +
>> target/loongarch/tcg/tcg_cpu.c | 13 ++++++++++++-
>> target/loongarch/tcg/tcg_loongarch.h | 1 +
>> 4 files changed, 14 insertions(+), 10 deletions(-)
>
> I think this should be squashed with patch 1.
> The intermediate #include of tcg/tcg_cpu.c was odd.
yes, it is actually odd. It is just for code review to do so.
Will squashed this with patch 1.
Regards
Bibo Mao
>
> With that,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
>
> r~
>
>>
>> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
>> index 6eb8c3214a..b449ede56d 100644
>> --- a/target/loongarch/cpu.c
>> +++ b/target/loongarch/cpu.c
>> @@ -28,11 +28,6 @@
>> #ifdef CONFIG_KVM
>> #include <linux/kvm.h>
>> #endif
>> -#ifdef CONFIG_TCG
>> -#include "accel/tcg/cpu-ldst.h"
>> -#include "accel/tcg/cpu-ops.h"
>> -#include "tcg/tcg.h"
>> -#endif
>> #include "tcg/tcg_loongarch.h"
>> const char * const regnames[32] = {
>> @@ -653,10 +648,6 @@ static void loongarch_cpu_dump_state(CPUState
>> *cs, FILE *f, int flags)
>> }
>> }
>> -#ifdef CONFIG_TCG
>> -#include "tcg/tcg_cpu.c"
>> -#endif /* CONFIG_TCG */
>> -
>> #ifndef CONFIG_USER_ONLY
>> #include "hw/core/sysemu-cpu-ops.h"
>> diff --git a/target/loongarch/tcg/meson.build
>> b/target/loongarch/tcg/meson.build
>> index bdf34f9673..b7adfe46f1 100644
>> --- a/target/loongarch/tcg/meson.build
>> +++ b/target/loongarch/tcg/meson.build
>> @@ -7,6 +7,7 @@ loongarch_ss.add([zlib, gen])
>> loongarch_ss.add(files(
>> 'fpu_helper.c',
>> 'op_helper.c',
>> + 'tcg_cpu.c',
>> 'translate.c',
>> 'vec_helper.c',
>> ))
>> diff --git a/target/loongarch/tcg/tcg_cpu.c
>> b/target/loongarch/tcg/tcg_cpu.c
>> index f09a695968..c7f49838e3 100644
>> --- a/target/loongarch/tcg/tcg_cpu.c
>> +++ b/target/loongarch/tcg/tcg_cpu.c
>> @@ -4,6 +4,17 @@
>> *
>> * Copyright (c) 2025 Loongson Technology Corporation Limited
>> */
>> +#include "qemu/osdep.h"
>> +#include "qemu/accel.h"
>> +#include "qemu/error-report.h"
>> +#include "qemu/log.h"
>> +#include "accel/accel-cpu-target.h"
>> +#include "accel/tcg/cpu-ldst.h"
>> +#include "accel/tcg/cpu-ops.h"
>> +#include "exec/translation-block.h"
>> +#include "exec/target_page.h"
>> +#include "tcg_loongarch.h"
>> +#include "internals.h"
>> #ifndef CONFIG_USER_ONLY
>> static void loongarch_cpu_do_interrupt(CPUState *cs)
>> @@ -232,7 +243,7 @@ static int loongarch_cpu_mmu_index(CPUState *cs,
>> bool ifetch)
>> return MMU_DA_IDX;
>> }
>> -static const TCGCPUOps loongarch_tcg_ops = {
>> +const TCGCPUOps loongarch_tcg_ops = {
>> .guest_default_memory_order = 0,
>> .mttcg_supported = true,
>> diff --git a/target/loongarch/tcg/tcg_loongarch.h
>> b/target/loongarch/tcg/tcg_loongarch.h
>> index 47702893e3..7fb627f2d6 100644
>> --- a/target/loongarch/tcg/tcg_loongarch.h
>> +++ b/target/loongarch/tcg/tcg_loongarch.h
>> @@ -9,6 +9,7 @@
>> #include "cpu.h"
>> #include "cpu-mmu.h"
>> +extern const TCGCPUOps loongarch_tcg_ops;
>> void loongarch_csr_translate_init(void);
>> bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-09-23 2:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 7:33 [PATCH 0/5] target/loongarch: Move TCG specified functions to tcg_cpu.c Bibo Mao
2025-09-22 7:33 ` [PATCH 1/5] " Bibo Mao
2025-09-22 7:33 ` [PATCH 2/5] target/loongarch: Set function loongarch_cpu_has_work() as public Bibo Mao
2025-09-22 14:27 ` Richard Henderson
2025-09-22 7:33 ` [PATCH 3/5] target/loongarch: Set file tcg_cpu.c separate from cpu.c Bibo Mao
2025-09-22 14:29 ` Richard Henderson
2025-09-23 2:41 ` Bibo Mao
2025-09-22 7:33 ` [PATCH 4/5] target/loongarch: Move function do_raise_exception() to tcg_cpu.c Bibo Mao
2025-09-22 14:32 ` Richard Henderson
2025-09-22 7:34 ` [PATCH 5/5] target/loongarch: Define loongarch_exception_name() as static Bibo Mao
2025-09-22 14:32 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).