[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 6/6] target/loongarch: Dump all generic CSR registers
From: |
Bibo Mao |
Subject: |
[PATCH v2 6/6] target/loongarch: Dump all generic CSR registers |
Date: |
Thu, 16 Jan 2025 19:30:32 +0800 |
CSR registers is import system control registers, it had better
dump all CSR registers when VM is running in system mode.
Here is dump output example of CSR registers:
CSR000: CRMD b4 PRMD 4 EUEN 0
MISC 0
CSR004: ECFG 71c1c ESTAT 0 ERA 9000000002901300
BADV 12022c0e0
CSR008: BADI 2b0000
CSR012: EENTRY 9000000100250000
CSR016: TLBIDX ffffffff8e000228 TLBEHI 120228000 TLBELO0
400000016f0a001f TLBELO1 400000016f0b401f
CSR024: ASID a0003 PGDL 900000010432c000 PGDH 9000000004350000
PGD 0
CSR028: PWCL 5e56e PWCH 2e4 STLBPS e
RVACFG 0
CSR032: CPUID 3 PRCFG1 72f8 PRCFG2 3ffff000
PRCFG3 8073f2
CSR048: SAVE0 0 SAVE1 171c SAVE2 12010c3b8
SAVE3 8e30000
CSR052: SAVE4 0 SAVE5 0 SAVE6 0
SAVE7 0
CSR064: TID 1 TCFG 60670 TVAL 60670
CNTC fffffffffe6002cb
CSR068: TICLR 0
CSR096: LLBCTL 0
CSR136: TLBRENTRY 10025a000 TLBRBADV 139ef6708 TLBRERA 120113d98
TLBRSAVE d901
CSR140: TLBRELO0 0 TLBRELO1 0 TLBREHI 139ef600e
TLBRPRMD 7
CSR384: DMW0 8000000000000001 DMW1 9000000000000011 DMW2 0
DMW3 0
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 62 +++++++++++++++++++++++++++++++-----------
target/loongarch/csr.c | 2 ++
target/loongarch/csr.h | 1 +
3 files changed, 49 insertions(+), 16 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index a744010332..502258d54e 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -793,6 +793,50 @@ static ObjectClass *loongarch_cpu_class_by_name(const char
*cpu_model)
return oc;
}
+static void loongarch_cpu_dump_csr(CPUState *cs, FILE *f)
+{
+#ifndef CONFIG_USER_ONLY
+ CPULoongArchState *env = cpu_env(cs);
+ CSRInfo *csr_info;
+ int64_t *addr;
+ int i, j, len, col = 0;
+
+ qemu_fprintf(f, "\n");
+
+ /* Dump all generic CSR register */
+ for (i = 0; i < LOONGARCH_CSR_DBG; i++) {
+ csr_info = get_csr(i);
+ if (!csr_info || (csr_info->flags & CSRFL_UNUSED)) {
+ if (i == (col + 3)) {
+ qemu_fprintf(f, "\n");
+ }
+
+ continue;
+ }
+
+ if ((i > (col + 3)) || (i == col)) {
+ col = i & ~3;
+ qemu_fprintf(f, " CSR%03d:", col);
+ }
+
+ addr = (void *)env + csr_info->offset;
+ qemu_fprintf(f, " %s %" PRIx64, csr_info->name, *addr);
+ len = find_last_bit((void *)addr, BITS_PER_LONG) & (BITS_PER_LONG - 1);
+ len = strlen(csr_info->name) + len / 4 + 1;
+ if (len < 22) {
+ for (j = 0; j < (22 - len); j++) {
+ qemu_fprintf(f, " ");
+ }
+ }
+
+ if (i == (col + 3)) {
+ qemu_fprintf(f, "\n");
+ }
+ }
+ qemu_fprintf(f, "\n");
+#endif
+}
+
static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)
{
CPULoongArchState *env = cpu_env(cs);
@@ -812,22 +856,8 @@ static 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_PRCFG2, 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);
- qemu_fprintf(f, "TCFG=%016" PRIx64 "\n", env->CSR_TCFG);
- qemu_fprintf(f, "TVAL=%016" PRIx64 "\n", env->CSR_TVAL);
+ /* csr */
+ loongarch_cpu_dump_csr(cs, f);
/* fpr */
if (flags & CPU_DUMP_FPU) {
diff --git a/target/loongarch/csr.c b/target/loongarch/csr.c
index 87bd24e8cd..7ea0a30450 100644
--- a/target/loongarch/csr.c
+++ b/target/loongarch/csr.c
@@ -9,12 +9,14 @@
#define CSR_OFF_FUNCS(NAME, FL, RD, WR) \
[LOONGARCH_CSR_##NAME] = { \
+ .name = (stringify(NAME)), \
.offset = offsetof(CPULoongArchState, CSR_##NAME), \
.flags = FL, .readfn = RD, .writefn = WR \
}
#define CSR_OFF_ARRAY(NAME, N) \
[LOONGARCH_CSR_##NAME(N)] = { \
+ .name = (stringify(NAME##N)), \
.offset = offsetof(CPULoongArchState, CSR_##NAME[N]), \
.flags = 0, .readfn = NULL, .writefn = NULL \
}
diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h
index deb1aacc33..81a656baae 100644
--- a/target/loongarch/csr.h
+++ b/target/loongarch/csr.h
@@ -17,6 +17,7 @@ enum {
};
typedef struct {
+ const char *name;
int offset;
int flags;
GenCSRFunc readfn;
--
2.39.3
- [PATCH v2 0/6] Dump all generic CSR registers, Bibo Mao, 2025/01/16
- [PATCH v2 2/6] target/loongarch: Remove static CSR function setting, Bibo Mao, 2025/01/16
- [PATCH v2 1/6] target/loongarch: Add dynamic function access with CSR register, Bibo Mao, 2025/01/16
- [PATCH v2 4/6] target/loongarch: Add common source file for CSR register, Bibo Mao, 2025/01/16
- [PATCH v2 6/6] target/loongarch: Dump all generic CSR registers,
Bibo Mao <=
- [PATCH v2 3/6] target/loongarch: Add common header file for CSR register, Bibo Mao, 2025/01/16
- [PATCH v2 5/6] target/loongarch: Set unused flag with CSR registers, Bibo Mao, 2025/01/16