1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * LoongArch emulation helpers for CSRs
5 * Copyright (c) 2021 Loongson Technology Corporation Limited
8 #include "qemu/osdep.h"
9 #include "qemu/main-loop.h"
11 #include "internals.h"
12 #include "qemu/host-utils.h"
13 #include "exec/helper-proto.h"
14 #include "exec/exec-all.h"
15 #include "exec/cpu_ldst.h"
18 #include "tcg/tcg-ldst.h"
20 target_ulong
helper_csrrd_pgd(CPULoongArchState
*env
)
24 if (env
->CSR_TLBRERA
& 0x1) {
25 v
= env
->CSR_TLBRBADV
;
30 if ((v
>> 63) & 0x1) {
39 target_ulong
helper_csrrd_tval(CPULoongArchState
*env
)
41 LoongArchCPU
*cpu
= env_archcpu(env
);
43 return cpu_loongarch_get_constant_timer_ticks(cpu
);
46 target_ulong
helper_csrwr_estat(CPULoongArchState
*env
, target_ulong val
)
48 int64_t old_v
= env
->CSR_ESTAT
;
50 /* Only IS[1:0] can be written */
51 env
->CSR_ESTAT
= deposit64(env
->CSR_ESTAT
, 0, 2, val
);
56 target_ulong
helper_csrwr_asid(CPULoongArchState
*env
, target_ulong val
)
58 int64_t old_v
= env
->CSR_ASID
;
60 /* Only ASID filed of CSR_ASID can be written */
61 env
->CSR_ASID
= deposit64(env
->CSR_ASID
, 0, 10, val
);
62 if (old_v
!= env
->CSR_ASID
) {
63 tlb_flush(env_cpu(env
));
68 target_ulong
helper_csrwr_tcfg(CPULoongArchState
*env
, target_ulong val
)
70 LoongArchCPU
*cpu
= env_archcpu(env
);
71 int64_t old_v
= env
->CSR_TCFG
;
73 cpu_loongarch_store_constant_timer_config(cpu
, val
);
78 target_ulong
helper_csrwr_ticlr(CPULoongArchState
*env
, target_ulong val
)
80 LoongArchCPU
*cpu
= env_archcpu(env
);
84 qemu_mutex_lock_iothread();
85 loongarch_cpu_set_irq(cpu
, IRQ_TIMER
, 0);
86 qemu_mutex_unlock_iothread();