Skip to content

Commit b5b13eb

Browse files
committed
target/loongarch: Set unused flag with CSR registers
On LA464, some CSR registers are not used such as CSR_SAVE8 - CSR_SAVE15, also CSR registers relative with MCE is not used now. Flag CSRFL_UNUSED is added for these registers, so that it will not dumped. In order to keep compatiblity, these CSR registers are not removed since it is used in vmstate already. Signed-off-by: Bibo Mao <maobibo@loongson.cn>
1 parent cb6fa41 commit b5b13eb

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

target/loongarch/cpu.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "cpu.h"
2020
#include "internals.h"
2121
#include "fpu/softfloat-helpers.h"
22-
#include "cpu-csr.h"
22+
#include "csr.h"
2323
#ifndef CONFIG_USER_ONLY
2424
#include "system/reset.h"
2525
#endif
@@ -375,6 +375,33 @@ static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch)
375375
return MMU_DA_IDX;
376376
}
377377

378+
static void loongarch_la464_init_csr(Object *obj)
379+
{
380+
#ifndef CONFIG_USER_ONLY
381+
static bool initialized;
382+
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
383+
CPULoongArchState *env = &cpu->env;
384+
int i, num;
385+
386+
if (!initialized) {
387+
initialized = true;
388+
num = FIELD_EX64(env->CSR_PRCFG1, CSR_PRCFG1, SAVE_NUM);
389+
for (i = num; i < 16; i++) {
390+
set_csr_flag(LOONGARCH_CSR_SAVE(i), CSRFL_UNUSED);
391+
}
392+
set_csr_flag(LOONGARCH_CSR_IMPCTL1, CSRFL_UNUSED);
393+
set_csr_flag(LOONGARCH_CSR_IMPCTL2, CSRFL_UNUSED);
394+
set_csr_flag(LOONGARCH_CSR_MERRCTL, CSRFL_UNUSED);
395+
set_csr_flag(LOONGARCH_CSR_MERRINFO1, CSRFL_UNUSED);
396+
set_csr_flag(LOONGARCH_CSR_MERRINFO2, CSRFL_UNUSED);
397+
set_csr_flag(LOONGARCH_CSR_MERRENTRY, CSRFL_UNUSED);
398+
set_csr_flag(LOONGARCH_CSR_MERRERA, CSRFL_UNUSED);
399+
set_csr_flag(LOONGARCH_CSR_MERRSAVE, CSRFL_UNUSED);
400+
set_csr_flag(LOONGARCH_CSR_CTAG, CSRFL_UNUSED);
401+
}
402+
#endif
403+
}
404+
378405
static void loongarch_la464_initfn(Object *obj)
379406
{
380407
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
@@ -470,6 +497,7 @@ static void loongarch_la464_initfn(Object *obj)
470497
env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, STLB_WAYS, 7);
471498
env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, STLB_SETS, 8);
472499

500+
loongarch_la464_init_csr(obj);
473501
loongarch_cpu_post_init(obj);
474502
}
475503

target/loongarch/csr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ CSRInfo *get_csr(unsigned int csr_num)
112112

113113
return csr;
114114
}
115+
116+
bool set_csr_flag(unsigned int csr_num, int flag)
117+
{
118+
CSRInfo *csr;
119+
120+
csr = get_csr(csr_num);
121+
if (!csr) {
122+
return false;
123+
}
124+
125+
csr->flags |= flag;
126+
return true;
127+
}

target/loongarch/csr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum {
1313
CSRFL_READONLY = (1 << 0),
1414
CSRFL_EXITTB = (1 << 1),
1515
CSRFL_IO = (1 << 2),
16+
CSRFL_UNUSED = (1 << 3),
1617
};
1718

1819
typedef struct {
@@ -23,4 +24,5 @@ typedef struct {
2324
} CSRInfo;
2425

2526
CSRInfo *get_csr(unsigned int csr_num);
27+
bool set_csr_flag(unsigned int csr_num, int flag);
2628
#endif /* TARGET_LOONGARCH_CSR_H */

0 commit comments

Comments
 (0)