]> Git Repo - qemu.git/blame - target/riscv/csr.c
target/riscv: rvv-1.0: add vcsr register
[qemu.git] / target / riscv / csr.c
CommitLineData
c7b95171
MC
1/*
2 * RISC-V Control and Status Registers.
3 *
4 * Copyright (c) 2016-2017 Sagar Karandikar, [email protected]
5 * Copyright (c) 2017-2018 SiFive, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2 or later, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "qemu/osdep.h"
21#include "qemu/log.h"
22#include "cpu.h"
23#include "qemu/main-loop.h"
24#include "exec/exec-all.h"
25
c7b95171
MC
26/* CSR function table public API */
27void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops)
28{
29 *ops = csr_ops[csrno & (CSR_TABLE_SIZE - 1)];
30}
31
32void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops)
33{
34 csr_ops[csrno & (CSR_TABLE_SIZE - 1)] = *ops;
35}
36
a88365c1 37/* Predicates */
0e62f92e 38static RISCVException fs(CPURISCVState *env, int csrno)
a88365c1
MC
39{
40#if !defined(CONFIG_USER_ONLY)
b345b480 41 if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
0e62f92e 42 return RISCV_EXCP_ILLEGAL_INST;
a88365c1
MC
43 }
44#endif
0e62f92e 45 return RISCV_EXCP_NONE;
a88365c1
MC
46}
47
0e62f92e 48static RISCVException vs(CPURISCVState *env, int csrno)
8e3a1f18 49{
e91a7227 50 if (env->misa_ext & RVV) {
0e62f92e 51 return RISCV_EXCP_NONE;
8e3a1f18 52 }
0e62f92e 53 return RISCV_EXCP_ILLEGAL_INST;
8e3a1f18
LZ
54}
55
0e62f92e 56static RISCVException ctr(CPURISCVState *env, int csrno)
a88365c1
MC
57{
58#if !defined(CONFIG_USER_ONLY)
0a13a5b8
AF
59 CPUState *cs = env_cpu(env);
60 RISCVCPU *cpu = RISCV_CPU(cs);
0a13a5b8
AF
61
62 if (!cpu->cfg.ext_counters) {
63 /* The Counters extensions is not enabled */
0e62f92e 64 return RISCV_EXCP_ILLEGAL_INST;
0a13a5b8 65 }
e39a8320
AF
66
67 if (riscv_cpu_virt_enabled(env)) {
68 switch (csrno) {
69 case CSR_CYCLE:
db70794e
BM
70 if (!get_field(env->hcounteren, COUNTEREN_CY) &&
71 get_field(env->mcounteren, COUNTEREN_CY)) {
0e62f92e 72 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
e39a8320
AF
73 }
74 break;
75 case CSR_TIME:
db70794e
BM
76 if (!get_field(env->hcounteren, COUNTEREN_TM) &&
77 get_field(env->mcounteren, COUNTEREN_TM)) {
0e62f92e 78 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
e39a8320
AF
79 }
80 break;
81 case CSR_INSTRET:
db70794e
BM
82 if (!get_field(env->hcounteren, COUNTEREN_IR) &&
83 get_field(env->mcounteren, COUNTEREN_IR)) {
0e62f92e 84 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
e39a8320
AF
85 }
86 break;
87 case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31:
88 if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)) &&
89 get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))) {
0e62f92e 90 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
e39a8320
AF
91 }
92 break;
8987cdc4 93 }
db23e5d9 94 if (riscv_cpu_mxl(env) == MXL_RV32) {
8987cdc4
AF
95 switch (csrno) {
96 case CSR_CYCLEH:
db70794e
BM
97 if (!get_field(env->hcounteren, COUNTEREN_CY) &&
98 get_field(env->mcounteren, COUNTEREN_CY)) {
0e62f92e 99 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
8987cdc4
AF
100 }
101 break;
102 case CSR_TIMEH:
db70794e
BM
103 if (!get_field(env->hcounteren, COUNTEREN_TM) &&
104 get_field(env->mcounteren, COUNTEREN_TM)) {
0e62f92e 105 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
8987cdc4
AF
106 }
107 break;
108 case CSR_INSTRETH:
db70794e
BM
109 if (!get_field(env->hcounteren, COUNTEREN_IR) &&
110 get_field(env->mcounteren, COUNTEREN_IR)) {
0e62f92e 111 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
8987cdc4
AF
112 }
113 break;
114 case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H:
115 if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3H)) &&
116 get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3H))) {
0e62f92e 117 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
8987cdc4
AF
118 }
119 break;
e39a8320 120 }
e39a8320
AF
121 }
122 }
a88365c1 123#endif
0e62f92e 124 return RISCV_EXCP_NONE;
a88365c1
MC
125}
126
0e62f92e 127static RISCVException ctr32(CPURISCVState *env, int csrno)
8987cdc4 128{
db23e5d9 129 if (riscv_cpu_mxl(env) != MXL_RV32) {
0e62f92e 130 return RISCV_EXCP_ILLEGAL_INST;
8987cdc4
AF
131 }
132
133 return ctr(env, csrno);
134}
135
a88365c1 136#if !defined(CONFIG_USER_ONLY)
0e62f92e 137static RISCVException any(CPURISCVState *env, int csrno)
a88365c1 138{
0e62f92e 139 return RISCV_EXCP_NONE;
a88365c1
MC
140}
141
0e62f92e 142static RISCVException any32(CPURISCVState *env, int csrno)
8987cdc4 143{
db23e5d9 144 if (riscv_cpu_mxl(env) != MXL_RV32) {
0e62f92e 145 return RISCV_EXCP_ILLEGAL_INST;
8987cdc4
AF
146 }
147
148 return any(env, csrno);
149
150}
151
0e62f92e 152static RISCVException smode(CPURISCVState *env, int csrno)
a88365c1 153{
0e62f92e
AF
154 if (riscv_has_ext(env, RVS)) {
155 return RISCV_EXCP_NONE;
156 }
157
158 return RISCV_EXCP_ILLEGAL_INST;
a88365c1
MC
159}
160
0e62f92e 161static RISCVException hmode(CPURISCVState *env, int csrno)
ff2cc129
AF
162{
163 if (riscv_has_ext(env, RVS) &&
164 riscv_has_ext(env, RVH)) {
165 /* Hypervisor extension is supported */
166 if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
167 env->priv == PRV_M) {
0e62f92e 168 return RISCV_EXCP_NONE;
e39a8320 169 } else {
0e62f92e 170 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
ff2cc129
AF
171 }
172 }
173
0e62f92e 174 return RISCV_EXCP_ILLEGAL_INST;
ff2cc129
AF
175}
176
0e62f92e 177static RISCVException hmode32(CPURISCVState *env, int csrno)
8987cdc4 178{
db23e5d9 179 if (riscv_cpu_mxl(env) != MXL_RV32) {
d6f20dac
AF
180 if (riscv_cpu_virt_enabled(env)) {
181 return RISCV_EXCP_ILLEGAL_INST;
182 } else {
183 return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
184 }
8987cdc4
AF
185 }
186
187 return hmode(env, csrno);
188
189}
190
4bbe8033
AB
191/* Checks if PointerMasking registers could be accessed */
192static RISCVException pointer_masking(CPURISCVState *env, int csrno)
193{
194 /* Check if j-ext is present */
195 if (riscv_has_ext(env, RVJ)) {
196 return RISCV_EXCP_NONE;
197 }
198 return RISCV_EXCP_ILLEGAL_INST;
199}
200
0e62f92e 201static RISCVException pmp(CPURISCVState *env, int csrno)
a88365c1 202{
0e62f92e
AF
203 if (riscv_feature(env, RISCV_FEATURE_PMP)) {
204 return RISCV_EXCP_NONE;
205 }
206
207 return RISCV_EXCP_ILLEGAL_INST;
a88365c1 208}
2582a95c
HW
209
210static RISCVException epmp(CPURISCVState *env, int csrno)
211{
212 if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) {
213 return RISCV_EXCP_NONE;
214 }
215
216 return RISCV_EXCP_ILLEGAL_INST;
217}
a88365c1
MC
218#endif
219
c7b95171 220/* User Floating-Point CSRs */
605def6e
AF
221static RISCVException read_fflags(CPURISCVState *env, int csrno,
222 target_ulong *val)
c7b95171 223{
fb738839 224 *val = riscv_cpu_get_fflags(env);
605def6e 225 return RISCV_EXCP_NONE;
c7b95171
MC
226}
227
605def6e
AF
228static RISCVException write_fflags(CPURISCVState *env, int csrno,
229 target_ulong val)
c7b95171
MC
230{
231#if !defined(CONFIG_USER_ONLY)
c7b95171
MC
232 env->mstatus |= MSTATUS_FS;
233#endif
fb738839 234 riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT));
605def6e 235 return RISCV_EXCP_NONE;
c7b95171
MC
236}
237
605def6e
AF
238static RISCVException read_frm(CPURISCVState *env, int csrno,
239 target_ulong *val)
c7b95171 240{
c7b95171 241 *val = env->frm;
605def6e 242 return RISCV_EXCP_NONE;
c7b95171
MC
243}
244
605def6e
AF
245static RISCVException write_frm(CPURISCVState *env, int csrno,
246 target_ulong val)
c7b95171
MC
247{
248#if !defined(CONFIG_USER_ONLY)
c7b95171
MC
249 env->mstatus |= MSTATUS_FS;
250#endif
251 env->frm = val & (FSR_RD >> FSR_RD_SHIFT);
605def6e 252 return RISCV_EXCP_NONE;
c7b95171
MC
253}
254
605def6e
AF
255static RISCVException read_fcsr(CPURISCVState *env, int csrno,
256 target_ulong *val)
c7b95171 257{
fb738839 258 *val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT)
c7b95171 259 | (env->frm << FSR_RD_SHIFT);
605def6e 260 return RISCV_EXCP_NONE;
c7b95171
MC
261}
262
605def6e
AF
263static RISCVException write_fcsr(CPURISCVState *env, int csrno,
264 target_ulong val)
c7b95171
MC
265{
266#if !defined(CONFIG_USER_ONLY)
c7b95171
MC
267 env->mstatus |= MSTATUS_FS;
268#endif
269 env->frm = (val & FSR_RD) >> FSR_RD_SHIFT;
fb738839 270 riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT);
605def6e 271 return RISCV_EXCP_NONE;
c7b95171
MC
272}
273
605def6e
AF
274static RISCVException read_vtype(CPURISCVState *env, int csrno,
275 target_ulong *val)
8e3a1f18
LZ
276{
277 *val = env->vtype;
605def6e 278 return RISCV_EXCP_NONE;
8e3a1f18
LZ
279}
280
605def6e
AF
281static RISCVException read_vl(CPURISCVState *env, int csrno,
282 target_ulong *val)
8e3a1f18
LZ
283{
284 *val = env->vl;
605def6e 285 return RISCV_EXCP_NONE;
8e3a1f18
LZ
286}
287
605def6e
AF
288static RISCVException read_vxrm(CPURISCVState *env, int csrno,
289 target_ulong *val)
8e3a1f18
LZ
290{
291 *val = env->vxrm;
605def6e 292 return RISCV_EXCP_NONE;
8e3a1f18
LZ
293}
294
605def6e
AF
295static RISCVException write_vxrm(CPURISCVState *env, int csrno,
296 target_ulong val)
8e3a1f18 297{
61b4b69d
LZ
298#if !defined(CONFIG_USER_ONLY)
299 env->mstatus |= MSTATUS_VS;
300#endif
8e3a1f18 301 env->vxrm = val;
605def6e 302 return RISCV_EXCP_NONE;
8e3a1f18
LZ
303}
304
605def6e
AF
305static RISCVException read_vxsat(CPURISCVState *env, int csrno,
306 target_ulong *val)
8e3a1f18
LZ
307{
308 *val = env->vxsat;
605def6e 309 return RISCV_EXCP_NONE;
8e3a1f18
LZ
310}
311
605def6e
AF
312static RISCVException write_vxsat(CPURISCVState *env, int csrno,
313 target_ulong val)
8e3a1f18 314{
61b4b69d
LZ
315#if !defined(CONFIG_USER_ONLY)
316 env->mstatus |= MSTATUS_VS;
317#endif
8e3a1f18 318 env->vxsat = val;
605def6e 319 return RISCV_EXCP_NONE;
8e3a1f18
LZ
320}
321
605def6e
AF
322static RISCVException read_vstart(CPURISCVState *env, int csrno,
323 target_ulong *val)
8e3a1f18
LZ
324{
325 *val = env->vstart;
605def6e 326 return RISCV_EXCP_NONE;
8e3a1f18
LZ
327}
328
605def6e
AF
329static RISCVException write_vstart(CPURISCVState *env, int csrno,
330 target_ulong val)
8e3a1f18 331{
61b4b69d
LZ
332#if !defined(CONFIG_USER_ONLY)
333 env->mstatus |= MSTATUS_VS;
334#endif
8e3a1f18 335 env->vstart = val;
605def6e 336 return RISCV_EXCP_NONE;
8e3a1f18
LZ
337}
338
4594fa5a
LZ
339static int read_vcsr(CPURISCVState *env, int csrno, target_ulong *val)
340{
341 *val = (env->vxrm << VCSR_VXRM_SHIFT) | (env->vxsat << VCSR_VXSAT_SHIFT);
342 return RISCV_EXCP_NONE;
343}
344
345static int write_vcsr(CPURISCVState *env, int csrno, target_ulong val)
346{
347#if !defined(CONFIG_USER_ONLY)
348 env->mstatus |= MSTATUS_VS;
349#endif
350 env->vxrm = (val & VCSR_VXRM) >> VCSR_VXRM_SHIFT;
351 env->vxsat = (val & VCSR_VXSAT) >> VCSR_VXSAT_SHIFT;
352 return RISCV_EXCP_NONE;
353}
354
c7b95171 355/* User Timers and Counters */
605def6e
AF
356static RISCVException read_instret(CPURISCVState *env, int csrno,
357 target_ulong *val)
c7b95171 358{
c7b95171 359#if !defined(CONFIG_USER_ONLY)
740b1759 360 if (icount_enabled()) {
8191d368 361 *val = icount_get();
c7b95171
MC
362 } else {
363 *val = cpu_get_host_ticks();
364 }
365#else
366 *val = cpu_get_host_ticks();
367#endif
605def6e 368 return RISCV_EXCP_NONE;
c7b95171
MC
369}
370
605def6e
AF
371static RISCVException read_instreth(CPURISCVState *env, int csrno,
372 target_ulong *val)
c7b95171 373{
c7b95171 374#if !defined(CONFIG_USER_ONLY)
740b1759 375 if (icount_enabled()) {
8191d368 376 *val = icount_get() >> 32;
c7b95171
MC
377 } else {
378 *val = cpu_get_host_ticks() >> 32;
379 }
380#else
381 *val = cpu_get_host_ticks() >> 32;
382#endif
605def6e 383 return RISCV_EXCP_NONE;
c7b95171 384}
c7b95171
MC
385
386#if defined(CONFIG_USER_ONLY)
605def6e
AF
387static RISCVException read_time(CPURISCVState *env, int csrno,
388 target_ulong *val)
c7b95171
MC
389{
390 *val = cpu_get_host_ticks();
605def6e 391 return RISCV_EXCP_NONE;
c7b95171
MC
392}
393
605def6e
AF
394static RISCVException read_timeh(CPURISCVState *env, int csrno,
395 target_ulong *val)
c7b95171
MC
396{
397 *val = cpu_get_host_ticks() >> 32;
605def6e 398 return RISCV_EXCP_NONE;
c7b95171 399}
c7b95171
MC
400
401#else /* CONFIG_USER_ONLY */
402
605def6e
AF
403static RISCVException read_time(CPURISCVState *env, int csrno,
404 target_ulong *val)
c6957248
AP
405{
406 uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0;
407
408 if (!env->rdtime_fn) {
605def6e 409 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
410 }
411
a47ef6e9 412 *val = env->rdtime_fn(env->rdtime_fn_arg) + delta;
605def6e 413 return RISCV_EXCP_NONE;
c6957248
AP
414}
415
605def6e
AF
416static RISCVException read_timeh(CPURISCVState *env, int csrno,
417 target_ulong *val)
c6957248
AP
418{
419 uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0;
420
421 if (!env->rdtime_fn) {
605def6e 422 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
423 }
424
a47ef6e9 425 *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32;
605def6e 426 return RISCV_EXCP_NONE;
c6957248 427}
c6957248 428
c7b95171
MC
429/* Machine constants */
430
ff2cc129
AF
431#define M_MODE_INTERRUPTS (MIP_MSIP | MIP_MTIP | MIP_MEIP)
432#define S_MODE_INTERRUPTS (MIP_SSIP | MIP_STIP | MIP_SEIP)
433#define VS_MODE_INTERRUPTS (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)
c7b95171 434
d0e53ce3
AF
435static const target_ulong delegable_ints = S_MODE_INTERRUPTS |
436 VS_MODE_INTERRUPTS;
bc083a51 437static const target_ulong vs_delegable_ints = VS_MODE_INTERRUPTS;
d0e53ce3
AF
438static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS |
439 VS_MODE_INTERRUPTS;
bc083a51
JM
440#define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \
441 (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \
442 (1ULL << (RISCV_EXCP_ILLEGAL_INST)) | \
443 (1ULL << (RISCV_EXCP_BREAKPOINT)) | \
444 (1ULL << (RISCV_EXCP_LOAD_ADDR_MIS)) | \
445 (1ULL << (RISCV_EXCP_LOAD_ACCESS_FAULT)) | \
446 (1ULL << (RISCV_EXCP_STORE_AMO_ADDR_MIS)) | \
447 (1ULL << (RISCV_EXCP_STORE_AMO_ACCESS_FAULT)) | \
448 (1ULL << (RISCV_EXCP_U_ECALL)) | \
449 (1ULL << (RISCV_EXCP_S_ECALL)) | \
450 (1ULL << (RISCV_EXCP_VS_ECALL)) | \
451 (1ULL << (RISCV_EXCP_M_ECALL)) | \
452 (1ULL << (RISCV_EXCP_INST_PAGE_FAULT)) | \
453 (1ULL << (RISCV_EXCP_LOAD_PAGE_FAULT)) | \
454 (1ULL << (RISCV_EXCP_STORE_PAGE_FAULT)) | \
455 (1ULL << (RISCV_EXCP_INST_GUEST_PAGE_FAULT)) | \
456 (1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) | \
457 (1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) | \
458 (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)))
459static const target_ulong vs_delegable_excps = DELEGABLE_EXCPS &
460 ~((1ULL << (RISCV_EXCP_S_ECALL)) |
461 (1ULL << (RISCV_EXCP_VS_ECALL)) |
462 (1ULL << (RISCV_EXCP_M_ECALL)) |
463 (1ULL << (RISCV_EXCP_INST_GUEST_PAGE_FAULT)) |
464 (1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) |
465 (1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) |
466 (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)));
c7b95171
MC
467static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
468 SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
89a81e37 469 SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS;
087b051a 470static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP;
e89b631c
GK
471static const target_ulong hip_writable_mask = MIP_VSSIP;
472static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
8747c9ee 473static const target_ulong vsip_writable_mask = MIP_VSSIP;
c7b95171 474
8987cdc4 475static const char valid_vm_1_10_32[16] = {
c7b95171
MC
476 [VM_1_10_MBARE] = 1,
477 [VM_1_10_SV32] = 1
478};
8987cdc4
AF
479
480static const char valid_vm_1_10_64[16] = {
c7b95171
MC
481 [VM_1_10_MBARE] = 1,
482 [VM_1_10_SV39] = 1,
483 [VM_1_10_SV48] = 1,
484 [VM_1_10_SV57] = 1
485};
c7b95171
MC
486
487/* Machine Information Registers */
605def6e
AF
488static RISCVException read_zero(CPURISCVState *env, int csrno,
489 target_ulong *val)
c7b95171 490{
605def6e
AF
491 *val = 0;
492 return RISCV_EXCP_NONE;
c7b95171
MC
493}
494
605def6e
AF
495static RISCVException read_mhartid(CPURISCVState *env, int csrno,
496 target_ulong *val)
c7b95171
MC
497{
498 *val = env->mhartid;
605def6e 499 return RISCV_EXCP_NONE;
c7b95171
MC
500}
501
502/* Machine Trap Setup */
b550f894
RH
503
504/* We do not store SD explicitly, only compute it on demand. */
505static uint64_t add_status_sd(RISCVMXL xl, uint64_t status)
506{
507 if ((status & MSTATUS_FS) == MSTATUS_FS ||
c36b2f1a 508 (status & MSTATUS_VS) == MSTATUS_VS ||
b550f894
RH
509 (status & MSTATUS_XS) == MSTATUS_XS) {
510 switch (xl) {
511 case MXL_RV32:
512 return status | MSTATUS32_SD;
513 case MXL_RV64:
514 return status | MSTATUS64_SD;
515 default:
516 g_assert_not_reached();
517 }
518 }
519 return status;
520}
521
605def6e
AF
522static RISCVException read_mstatus(CPURISCVState *env, int csrno,
523 target_ulong *val)
c7b95171 524{
b550f894 525 *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus);
605def6e 526 return RISCV_EXCP_NONE;
c7b95171
MC
527}
528
529static int validate_vm(CPURISCVState *env, target_ulong vm)
530{
db23e5d9 531 if (riscv_cpu_mxl(env) == MXL_RV32) {
8987cdc4
AF
532 return valid_vm_1_10_32[vm & 0xf];
533 } else {
534 return valid_vm_1_10_64[vm & 0xf];
535 }
c7b95171
MC
536}
537
605def6e
AF
538static RISCVException write_mstatus(CPURISCVState *env, int csrno,
539 target_ulong val)
c7b95171 540{
284d697c
YJ
541 uint64_t mstatus = env->mstatus;
542 uint64_t mask = 0;
c7b95171
MC
543
544 /* flush tlb on mstatus fields that affect VM */
1a9540d1
AF
545 if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV |
546 MSTATUS_MPRV | MSTATUS_SUM)) {
547 tlb_flush(env_cpu(env));
c7b95171 548 }
1a9540d1
AF
549 mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE |
550 MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM |
551 MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR |
61b4b69d 552 MSTATUS_TW | MSTATUS_VS;
8987cdc4 553
db23e5d9 554 if (riscv_cpu_mxl(env) != MXL_RV32) {
8987cdc4
AF
555 /*
556 * RV32: MPV and GVA are not in mstatus. The current plan is to
557 * add them to mstatush. For now, we just don't support it.
558 */
559 mask |= MSTATUS_MPV | MSTATUS_GVA;
560 }
c7b95171
MC
561
562 mstatus = (mstatus & ~mask) | (val & mask);
563
b550f894 564 if (riscv_cpu_mxl(env) == MXL_RV64) {
92371bd9
RH
565 /* SXL and UXL fields are for now read only */
566 mstatus = set_field(mstatus, MSTATUS64_SXL, MXL_RV64);
567 mstatus = set_field(mstatus, MSTATUS64_UXL, MXL_RV64);
4fd7455b 568 }
c7b95171
MC
569 env->mstatus = mstatus;
570
605def6e 571 return RISCV_EXCP_NONE;
c7b95171
MC
572}
573
605def6e
AF
574static RISCVException read_mstatush(CPURISCVState *env, int csrno,
575 target_ulong *val)
551fa7e8 576{
284d697c 577 *val = env->mstatus >> 32;
605def6e 578 return RISCV_EXCP_NONE;
551fa7e8
AF
579}
580
605def6e
AF
581static RISCVException write_mstatush(CPURISCVState *env, int csrno,
582 target_ulong val)
551fa7e8 583{
284d697c
YJ
584 uint64_t valh = (uint64_t)val << 32;
585 uint64_t mask = MSTATUS_MPV | MSTATUS_GVA;
586
587 if ((valh ^ env->mstatus) & (MSTATUS_MPV)) {
551fa7e8
AF
588 tlb_flush(env_cpu(env));
589 }
590
284d697c 591 env->mstatus = (env->mstatus & ~mask) | (valh & mask);
551fa7e8 592
605def6e 593 return RISCV_EXCP_NONE;
551fa7e8 594}
551fa7e8 595
605def6e
AF
596static RISCVException read_misa(CPURISCVState *env, int csrno,
597 target_ulong *val)
c7b95171 598{
e91a7227
RH
599 target_ulong misa;
600
601 switch (env->misa_mxl) {
602 case MXL_RV32:
603 misa = (target_ulong)MXL_RV32 << 30;
604 break;
605#ifdef TARGET_RISCV64
606 case MXL_RV64:
607 misa = (target_ulong)MXL_RV64 << 62;
608 break;
609#endif
610 default:
611 g_assert_not_reached();
612 }
613
614 *val = misa | env->misa_ext;
605def6e 615 return RISCV_EXCP_NONE;
c7b95171
MC
616}
617
605def6e
AF
618static RISCVException write_misa(CPURISCVState *env, int csrno,
619 target_ulong val)
f18637cd
MC
620{
621 if (!riscv_feature(env, RISCV_FEATURE_MISA)) {
622 /* drop write to misa */
605def6e 623 return RISCV_EXCP_NONE;
f18637cd
MC
624 }
625
626 /* 'I' or 'E' must be present */
627 if (!(val & (RVI | RVE))) {
628 /* It is not, drop write to misa */
605def6e 629 return RISCV_EXCP_NONE;
f18637cd
MC
630 }
631
632 /* 'E' excludes all other extensions */
633 if (val & RVE) {
634 /* when we support 'E' we can do "val = RVE;" however
635 * for now we just drop writes if 'E' is present.
636 */
605def6e 637 return RISCV_EXCP_NONE;
f18637cd
MC
638 }
639
e91a7227
RH
640 /*
641 * misa.MXL writes are not supported by QEMU.
642 * Drop writes to those bits.
643 */
644
f18637cd 645 /* Mask extensions that are not supported by this hart */
e91a7227 646 val &= env->misa_ext_mask;
f18637cd
MC
647
648 /* Mask extensions that are not supported by QEMU */
7b07a37c 649 val &= (RVI | RVE | RVM | RVA | RVF | RVD | RVC | RVS | RVU | RVV);
f18637cd
MC
650
651 /* 'D' depends on 'F', so clear 'D' if 'F' is not present */
652 if ((val & RVD) && !(val & RVF)) {
653 val &= ~RVD;
654 }
655
656 /* Suppress 'C' if next instruction is not aligned
657 * TODO: this should check next_pc
658 */
659 if ((val & RVC) && (GETPC() & ~3) != 0) {
660 val &= ~RVC;
661 }
662
e91a7227
RH
663 /* If nothing changed, do nothing. */
664 if (val == env->misa_ext) {
665 return RISCV_EXCP_NONE;
4fd7455b 666 }
f18637cd
MC
667
668 /* flush translation cache */
e91a7227
RH
669 tb_flush(env_cpu(env));
670 env->misa_ext = val;
605def6e 671 return RISCV_EXCP_NONE;
f18637cd
MC
672}
673
605def6e
AF
674static RISCVException read_medeleg(CPURISCVState *env, int csrno,
675 target_ulong *val)
c7b95171
MC
676{
677 *val = env->medeleg;
605def6e 678 return RISCV_EXCP_NONE;
c7b95171
MC
679}
680
605def6e
AF
681static RISCVException write_medeleg(CPURISCVState *env, int csrno,
682 target_ulong val)
c7b95171 683{
bc083a51 684 env->medeleg = (env->medeleg & ~DELEGABLE_EXCPS) | (val & DELEGABLE_EXCPS);
605def6e 685 return RISCV_EXCP_NONE;
c7b95171
MC
686}
687
605def6e
AF
688static RISCVException read_mideleg(CPURISCVState *env, int csrno,
689 target_ulong *val)
c7b95171
MC
690{
691 *val = env->mideleg;
605def6e 692 return RISCV_EXCP_NONE;
c7b95171
MC
693}
694
605def6e
AF
695static RISCVException write_mideleg(CPURISCVState *env, int csrno,
696 target_ulong val)
c7b95171
MC
697{
698 env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints);
713d8363
AF
699 if (riscv_has_ext(env, RVH)) {
700 env->mideleg |= VS_MODE_INTERRUPTS;
701 }
605def6e 702 return RISCV_EXCP_NONE;
c7b95171
MC
703}
704
605def6e
AF
705static RISCVException read_mie(CPURISCVState *env, int csrno,
706 target_ulong *val)
c7b95171
MC
707{
708 *val = env->mie;
605def6e 709 return RISCV_EXCP_NONE;
c7b95171
MC
710}
711
605def6e
AF
712static RISCVException write_mie(CPURISCVState *env, int csrno,
713 target_ulong val)
c7b95171
MC
714{
715 env->mie = (env->mie & ~all_ints) | (val & all_ints);
605def6e 716 return RISCV_EXCP_NONE;
c7b95171
MC
717}
718
605def6e
AF
719static RISCVException read_mtvec(CPURISCVState *env, int csrno,
720 target_ulong *val)
c7b95171
MC
721{
722 *val = env->mtvec;
605def6e 723 return RISCV_EXCP_NONE;
c7b95171
MC
724}
725
605def6e
AF
726static RISCVException write_mtvec(CPURISCVState *env, int csrno,
727 target_ulong val)
c7b95171
MC
728{
729 /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
acbbb94e
MC
730 if ((val & 3) < 2) {
731 env->mtvec = val;
c7b95171 732 } else {
acbbb94e 733 qemu_log_mask(LOG_UNIMP, "CSR_MTVEC: reserved mode not supported\n");
c7b95171 734 }
605def6e 735 return RISCV_EXCP_NONE;
c7b95171
MC
736}
737
605def6e
AF
738static RISCVException read_mcounteren(CPURISCVState *env, int csrno,
739 target_ulong *val)
c7b95171 740{
c7b95171 741 *val = env->mcounteren;
605def6e 742 return RISCV_EXCP_NONE;
c7b95171
MC
743}
744
605def6e
AF
745static RISCVException write_mcounteren(CPURISCVState *env, int csrno,
746 target_ulong val)
c7b95171 747{
c7b95171 748 env->mcounteren = val;
605def6e 749 return RISCV_EXCP_NONE;
c7b95171
MC
750}
751
c7b95171 752/* Machine Trap Handling */
605def6e
AF
753static RISCVException read_mscratch(CPURISCVState *env, int csrno,
754 target_ulong *val)
c7b95171
MC
755{
756 *val = env->mscratch;
605def6e 757 return RISCV_EXCP_NONE;
c7b95171
MC
758}
759
605def6e
AF
760static RISCVException write_mscratch(CPURISCVState *env, int csrno,
761 target_ulong val)
c7b95171
MC
762{
763 env->mscratch = val;
605def6e 764 return RISCV_EXCP_NONE;
c7b95171
MC
765}
766
605def6e
AF
767static RISCVException read_mepc(CPURISCVState *env, int csrno,
768 target_ulong *val)
c7b95171
MC
769{
770 *val = env->mepc;
605def6e 771 return RISCV_EXCP_NONE;
c7b95171
MC
772}
773
605def6e
AF
774static RISCVException write_mepc(CPURISCVState *env, int csrno,
775 target_ulong val)
c7b95171
MC
776{
777 env->mepc = val;
605def6e 778 return RISCV_EXCP_NONE;
c7b95171
MC
779}
780
605def6e
AF
781static RISCVException read_mcause(CPURISCVState *env, int csrno,
782 target_ulong *val)
c7b95171
MC
783{
784 *val = env->mcause;
605def6e 785 return RISCV_EXCP_NONE;
c7b95171
MC
786}
787
605def6e
AF
788static RISCVException write_mcause(CPURISCVState *env, int csrno,
789 target_ulong val)
c7b95171
MC
790{
791 env->mcause = val;
605def6e 792 return RISCV_EXCP_NONE;
c7b95171
MC
793}
794
605def6e
AF
795static RISCVException read_mtval(CPURISCVState *env, int csrno,
796 target_ulong *val)
c7b95171 797{
ac12b601 798 *val = env->mtval;
605def6e 799 return RISCV_EXCP_NONE;
c7b95171
MC
800}
801
605def6e
AF
802static RISCVException write_mtval(CPURISCVState *env, int csrno,
803 target_ulong val)
c7b95171 804{
ac12b601 805 env->mtval = val;
605def6e 806 return RISCV_EXCP_NONE;
c7b95171
MC
807}
808
605def6e
AF
809static RISCVException rmw_mip(CPURISCVState *env, int csrno,
810 target_ulong *ret_value,
811 target_ulong new_value, target_ulong write_mask)
c7b95171 812{
3109cd98 813 RISCVCPU *cpu = env_archcpu(env);
e3e7039c
MC
814 /* Allow software control of delegable interrupts not claimed by hardware */
815 target_ulong mask = write_mask & delegable_ints & ~env->miclaim;
71877e29
MC
816 uint32_t old_mip;
817
71877e29 818 if (mask) {
71877e29 819 old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask));
71877e29 820 } else {
7ec5d303 821 old_mip = env->mip;
71877e29 822 }
c7b95171 823
71877e29
MC
824 if (ret_value) {
825 *ret_value = old_mip;
826 }
c7b95171 827
605def6e 828 return RISCV_EXCP_NONE;
c7b95171
MC
829}
830
831/* Supervisor Trap Setup */
605def6e
AF
832static RISCVException read_sstatus(CPURISCVState *env, int csrno,
833 target_ulong *val)
c7b95171 834{
1a9540d1 835 target_ulong mask = (sstatus_v1_10_mask);
5f10e6d8 836
b550f894
RH
837 /* TODO: Use SXL not MXL. */
838 *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask);
605def6e 839 return RISCV_EXCP_NONE;
c7b95171
MC
840}
841
605def6e
AF
842static RISCVException write_sstatus(CPURISCVState *env, int csrno,
843 target_ulong val)
c7b95171 844{
1a9540d1 845 target_ulong mask = (sstatus_v1_10_mask);
c7b95171
MC
846 target_ulong newval = (env->mstatus & ~mask) | (val & mask);
847 return write_mstatus(env, CSR_MSTATUS, newval);
848}
849
605def6e
AF
850static RISCVException read_vsie(CPURISCVState *env, int csrno,
851 target_ulong *val)
9d5451e0
GK
852{
853 /* Shift the VS bits to their S bit location in vsie */
854 *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1;
605def6e 855 return RISCV_EXCP_NONE;
9d5451e0
GK
856}
857
605def6e
AF
858static RISCVException read_sie(CPURISCVState *env, int csrno,
859 target_ulong *val)
c7b95171 860{
d0e53ce3 861 if (riscv_cpu_virt_enabled(env)) {
9d5451e0 862 read_vsie(env, CSR_VSIE, val);
d0e53ce3
AF
863 } else {
864 *val = env->mie & env->mideleg;
865 }
605def6e 866 return RISCV_EXCP_NONE;
c7b95171
MC
867}
868
605def6e
AF
869static RISCVException write_vsie(CPURISCVState *env, int csrno,
870 target_ulong val)
c7b95171 871{
9d5451e0
GK
872 /* Shift the S bits to their VS bit location in mie */
873 target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) |
874 ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS);
875 return write_mie(env, CSR_MIE, newval);
876}
d0e53ce3 877
9d5451e0
GK
878static int write_sie(CPURISCVState *env, int csrno, target_ulong val)
879{
d0e53ce3 880 if (riscv_cpu_virt_enabled(env)) {
9d5451e0 881 write_vsie(env, CSR_VSIE, val);
d0e53ce3 882 } else {
9d5451e0
GK
883 target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) |
884 (val & S_MODE_INTERRUPTS);
885 write_mie(env, CSR_MIE, newval);
d0e53ce3
AF
886 }
887
605def6e 888 return RISCV_EXCP_NONE;
c7b95171
MC
889}
890
605def6e
AF
891static RISCVException read_stvec(CPURISCVState *env, int csrno,
892 target_ulong *val)
c7b95171
MC
893{
894 *val = env->stvec;
605def6e 895 return RISCV_EXCP_NONE;
c7b95171
MC
896}
897
605def6e
AF
898static RISCVException write_stvec(CPURISCVState *env, int csrno,
899 target_ulong val)
c7b95171
MC
900{
901 /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
acbbb94e
MC
902 if ((val & 3) < 2) {
903 env->stvec = val;
c7b95171 904 } else {
acbbb94e 905 qemu_log_mask(LOG_UNIMP, "CSR_STVEC: reserved mode not supported\n");
c7b95171 906 }
605def6e 907 return RISCV_EXCP_NONE;
c7b95171
MC
908}
909
605def6e
AF
910static RISCVException read_scounteren(CPURISCVState *env, int csrno,
911 target_ulong *val)
c7b95171 912{
c7b95171 913 *val = env->scounteren;
605def6e 914 return RISCV_EXCP_NONE;
c7b95171
MC
915}
916
605def6e
AF
917static RISCVException write_scounteren(CPURISCVState *env, int csrno,
918 target_ulong val)
c7b95171 919{
c7b95171 920 env->scounteren = val;
605def6e 921 return RISCV_EXCP_NONE;
c7b95171
MC
922}
923
924/* Supervisor Trap Handling */
605def6e
AF
925static RISCVException read_sscratch(CPURISCVState *env, int csrno,
926 target_ulong *val)
c7b95171
MC
927{
928 *val = env->sscratch;
605def6e 929 return RISCV_EXCP_NONE;
c7b95171
MC
930}
931
605def6e
AF
932static RISCVException write_sscratch(CPURISCVState *env, int csrno,
933 target_ulong val)
c7b95171
MC
934{
935 env->sscratch = val;
605def6e 936 return RISCV_EXCP_NONE;
c7b95171
MC
937}
938
605def6e
AF
939static RISCVException read_sepc(CPURISCVState *env, int csrno,
940 target_ulong *val)
c7b95171
MC
941{
942 *val = env->sepc;
605def6e 943 return RISCV_EXCP_NONE;
c7b95171
MC
944}
945
605def6e
AF
946static RISCVException write_sepc(CPURISCVState *env, int csrno,
947 target_ulong val)
c7b95171
MC
948{
949 env->sepc = val;
605def6e 950 return RISCV_EXCP_NONE;
c7b95171
MC
951}
952
605def6e
AF
953static RISCVException read_scause(CPURISCVState *env, int csrno,
954 target_ulong *val)
c7b95171
MC
955{
956 *val = env->scause;
605def6e 957 return RISCV_EXCP_NONE;
c7b95171
MC
958}
959
605def6e
AF
960static RISCVException write_scause(CPURISCVState *env, int csrno,
961 target_ulong val)
c7b95171
MC
962{
963 env->scause = val;
605def6e 964 return RISCV_EXCP_NONE;
c7b95171
MC
965}
966
605def6e
AF
967static RISCVException read_stval(CPURISCVState *env, int csrno,
968 target_ulong *val)
c7b95171 969{
ac12b601 970 *val = env->stval;
605def6e 971 return RISCV_EXCP_NONE;
c7b95171
MC
972}
973
605def6e
AF
974static RISCVException write_stval(CPURISCVState *env, int csrno,
975 target_ulong val)
c7b95171 976{
ac12b601 977 env->stval = val;
605def6e 978 return RISCV_EXCP_NONE;
c7b95171
MC
979}
980
605def6e
AF
981static RISCVException rmw_vsip(CPURISCVState *env, int csrno,
982 target_ulong *ret_value,
983 target_ulong new_value, target_ulong write_mask)
9d5451e0
GK
984{
985 /* Shift the S bits to their VS bit location in mip */
986 int ret = rmw_mip(env, 0, ret_value, new_value << 1,
987 (write_mask << 1) & vsip_writable_mask & env->hideleg);
33979526
RH
988
989 if (ret_value) {
990 *ret_value &= VS_MODE_INTERRUPTS;
991 /* Shift the VS bits to their S bit location in vsip */
992 *ret_value >>= 1;
993 }
9d5451e0
GK
994 return ret;
995}
996
605def6e
AF
997static RISCVException rmw_sip(CPURISCVState *env, int csrno,
998 target_ulong *ret_value,
999 target_ulong new_value, target_ulong write_mask)
c7b95171 1000{
a2e9f57d
AF
1001 int ret;
1002
1003 if (riscv_cpu_virt_enabled(env)) {
9d5451e0 1004 ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask);
a2e9f57d
AF
1005 } else {
1006 ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value,
087b051a 1007 write_mask & env->mideleg & sip_writable_mask);
a2e9f57d
AF
1008 }
1009
33979526
RH
1010 if (ret_value) {
1011 *ret_value &= env->mideleg;
1012 }
087b051a 1013 return ret;
c7b95171
MC
1014}
1015
1016/* Supervisor Protection and Translation */
605def6e
AF
1017static RISCVException read_satp(CPURISCVState *env, int csrno,
1018 target_ulong *val)
c7b95171
MC
1019{
1020 if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
1021 *val = 0;
605def6e 1022 return RISCV_EXCP_NONE;
1a9540d1
AF
1023 }
1024
1025 if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
605def6e 1026 return RISCV_EXCP_ILLEGAL_INST;
c7b95171 1027 } else {
1a9540d1 1028 *val = env->satp;
c7b95171 1029 }
1a9540d1 1030
605def6e 1031 return RISCV_EXCP_NONE;
c7b95171
MC
1032}
1033
605def6e
AF
1034static RISCVException write_satp(CPURISCVState *env, int csrno,
1035 target_ulong val)
c7b95171 1036{
15732b8e 1037 target_ulong vm, mask, asid;
419ddf00 1038
c7b95171 1039 if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
605def6e 1040 return RISCV_EXCP_NONE;
c7b95171 1041 }
419ddf00 1042
db23e5d9 1043 if (riscv_cpu_mxl(env) == MXL_RV32) {
419ddf00
AF
1044 vm = validate_vm(env, get_field(val, SATP32_MODE));
1045 mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN);
1046 asid = (val ^ env->satp) & SATP32_ASID;
1047 } else {
1048 vm = validate_vm(env, get_field(val, SATP64_MODE));
1049 mask = (val ^ env->satp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN);
1050 asid = (val ^ env->satp) & SATP64_ASID;
1051 }
1052
1053 if (vm && mask) {
7f2b5ff1 1054 if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
605def6e 1055 return RISCV_EXCP_ILLEGAL_INST;
7f2b5ff1 1056 } else {
419ddf00 1057 if (asid) {
3109cd98 1058 tlb_flush(env_cpu(env));
1e0d985f 1059 }
7f2b5ff1
MC
1060 env->satp = val;
1061 }
c7b95171 1062 }
605def6e 1063 return RISCV_EXCP_NONE;
c7b95171
MC
1064}
1065
ff2cc129 1066/* Hypervisor Extensions */
605def6e
AF
1067static RISCVException read_hstatus(CPURISCVState *env, int csrno,
1068 target_ulong *val)
ff2cc129
AF
1069{
1070 *val = env->hstatus;
db23e5d9 1071 if (riscv_cpu_mxl(env) != MXL_RV32) {
8987cdc4
AF
1072 /* We only support 64-bit VSXL */
1073 *val = set_field(*val, HSTATUS_VSXL, 2);
1074 }
30f663b1
AF
1075 /* We only support little endian */
1076 *val = set_field(*val, HSTATUS_VSBE, 0);
605def6e 1077 return RISCV_EXCP_NONE;
ff2cc129
AF
1078}
1079
605def6e
AF
1080static RISCVException write_hstatus(CPURISCVState *env, int csrno,
1081 target_ulong val)
ff2cc129
AF
1082{
1083 env->hstatus = val;
db23e5d9 1084 if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) {
f8dc878e
AF
1085 qemu_log_mask(LOG_UNIMP, "QEMU does not support mixed HSXLEN options.");
1086 }
30f663b1
AF
1087 if (get_field(val, HSTATUS_VSBE) != 0) {
1088 qemu_log_mask(LOG_UNIMP, "QEMU does not support big endian guests.");
1089 }
605def6e 1090 return RISCV_EXCP_NONE;
ff2cc129
AF
1091}
1092
605def6e
AF
1093static RISCVException read_hedeleg(CPURISCVState *env, int csrno,
1094 target_ulong *val)
ff2cc129
AF
1095{
1096 *val = env->hedeleg;
605def6e 1097 return RISCV_EXCP_NONE;
ff2cc129
AF
1098}
1099
605def6e
AF
1100static RISCVException write_hedeleg(CPURISCVState *env, int csrno,
1101 target_ulong val)
ff2cc129 1102{
bc083a51 1103 env->hedeleg = val & vs_delegable_excps;
605def6e 1104 return RISCV_EXCP_NONE;
ff2cc129
AF
1105}
1106
605def6e
AF
1107static RISCVException read_hideleg(CPURISCVState *env, int csrno,
1108 target_ulong *val)
ff2cc129
AF
1109{
1110 *val = env->hideleg;
605def6e 1111 return RISCV_EXCP_NONE;
ff2cc129
AF
1112}
1113
605def6e
AF
1114static RISCVException write_hideleg(CPURISCVState *env, int csrno,
1115 target_ulong val)
ff2cc129 1116{
bc083a51 1117 env->hideleg = val & vs_delegable_ints;
605def6e 1118 return RISCV_EXCP_NONE;
ff2cc129
AF
1119}
1120
605def6e
AF
1121static RISCVException rmw_hvip(CPURISCVState *env, int csrno,
1122 target_ulong *ret_value,
1123 target_ulong new_value, target_ulong write_mask)
83028098
AF
1124{
1125 int ret = rmw_mip(env, 0, ret_value, new_value,
e89b631c 1126 write_mask & hvip_writable_mask);
83028098 1127
33979526
RH
1128 if (ret_value) {
1129 *ret_value &= hvip_writable_mask;
1130 }
83028098
AF
1131 return ret;
1132}
1133
605def6e
AF
1134static RISCVException rmw_hip(CPURISCVState *env, int csrno,
1135 target_ulong *ret_value,
1136 target_ulong new_value, target_ulong write_mask)
ff2cc129
AF
1137{
1138 int ret = rmw_mip(env, 0, ret_value, new_value,
1139 write_mask & hip_writable_mask);
1140
33979526
RH
1141 if (ret_value) {
1142 *ret_value &= hip_writable_mask;
1143 }
ff2cc129
AF
1144 return ret;
1145}
1146
605def6e
AF
1147static RISCVException read_hie(CPURISCVState *env, int csrno,
1148 target_ulong *val)
ff2cc129
AF
1149{
1150 *val = env->mie & VS_MODE_INTERRUPTS;
605def6e 1151 return RISCV_EXCP_NONE;
ff2cc129
AF
1152}
1153
605def6e
AF
1154static RISCVException write_hie(CPURISCVState *env, int csrno,
1155 target_ulong val)
ff2cc129
AF
1156{
1157 target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS);
1158 return write_mie(env, CSR_MIE, newval);
1159}
1160
605def6e
AF
1161static RISCVException read_hcounteren(CPURISCVState *env, int csrno,
1162 target_ulong *val)
ff2cc129
AF
1163{
1164 *val = env->hcounteren;
605def6e 1165 return RISCV_EXCP_NONE;
ff2cc129
AF
1166}
1167
605def6e
AF
1168static RISCVException write_hcounteren(CPURISCVState *env, int csrno,
1169 target_ulong val)
ff2cc129
AF
1170{
1171 env->hcounteren = val;
605def6e 1172 return RISCV_EXCP_NONE;
ff2cc129
AF
1173}
1174
605def6e
AF
1175static RISCVException write_hgeie(CPURISCVState *env, int csrno,
1176 target_ulong val)
83028098 1177{
377cbb4b
RH
1178 if (val) {
1179 qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
1180 }
605def6e 1181 return RISCV_EXCP_NONE;
83028098
AF
1182}
1183
605def6e
AF
1184static RISCVException read_htval(CPURISCVState *env, int csrno,
1185 target_ulong *val)
ff2cc129
AF
1186{
1187 *val = env->htval;
605def6e 1188 return RISCV_EXCP_NONE;
ff2cc129
AF
1189}
1190
605def6e
AF
1191static RISCVException write_htval(CPURISCVState *env, int csrno,
1192 target_ulong val)
ff2cc129
AF
1193{
1194 env->htval = val;
605def6e 1195 return RISCV_EXCP_NONE;
ff2cc129
AF
1196}
1197
605def6e
AF
1198static RISCVException read_htinst(CPURISCVState *env, int csrno,
1199 target_ulong *val)
ff2cc129
AF
1200{
1201 *val = env->htinst;
605def6e 1202 return RISCV_EXCP_NONE;
ff2cc129
AF
1203}
1204
605def6e
AF
1205static RISCVException write_htinst(CPURISCVState *env, int csrno,
1206 target_ulong val)
ff2cc129 1207{
605def6e 1208 return RISCV_EXCP_NONE;
ff2cc129
AF
1209}
1210
605def6e
AF
1211static RISCVException write_hgeip(CPURISCVState *env, int csrno,
1212 target_ulong val)
83028098 1213{
377cbb4b
RH
1214 if (val) {
1215 qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
1216 }
605def6e 1217 return RISCV_EXCP_NONE;
83028098
AF
1218}
1219
605def6e
AF
1220static RISCVException read_hgatp(CPURISCVState *env, int csrno,
1221 target_ulong *val)
ff2cc129
AF
1222{
1223 *val = env->hgatp;
605def6e 1224 return RISCV_EXCP_NONE;
ff2cc129
AF
1225}
1226
605def6e
AF
1227static RISCVException write_hgatp(CPURISCVState *env, int csrno,
1228 target_ulong val)
ff2cc129
AF
1229{
1230 env->hgatp = val;
605def6e 1231 return RISCV_EXCP_NONE;
ff2cc129
AF
1232}
1233
605def6e
AF
1234static RISCVException read_htimedelta(CPURISCVState *env, int csrno,
1235 target_ulong *val)
c6957248
AP
1236{
1237 if (!env->rdtime_fn) {
605def6e 1238 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
1239 }
1240
c6957248 1241 *val = env->htimedelta;
605def6e 1242 return RISCV_EXCP_NONE;
c6957248
AP
1243}
1244
605def6e
AF
1245static RISCVException write_htimedelta(CPURISCVState *env, int csrno,
1246 target_ulong val)
c6957248
AP
1247{
1248 if (!env->rdtime_fn) {
605def6e 1249 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
1250 }
1251
db23e5d9 1252 if (riscv_cpu_mxl(env) == MXL_RV32) {
8987cdc4
AF
1253 env->htimedelta = deposit64(env->htimedelta, 0, 32, (uint64_t)val);
1254 } else {
1255 env->htimedelta = val;
1256 }
605def6e 1257 return RISCV_EXCP_NONE;
c6957248
AP
1258}
1259
605def6e
AF
1260static RISCVException read_htimedeltah(CPURISCVState *env, int csrno,
1261 target_ulong *val)
c6957248
AP
1262{
1263 if (!env->rdtime_fn) {
605def6e 1264 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
1265 }
1266
1267 *val = env->htimedelta >> 32;
605def6e 1268 return RISCV_EXCP_NONE;
c6957248
AP
1269}
1270
605def6e
AF
1271static RISCVException write_htimedeltah(CPURISCVState *env, int csrno,
1272 target_ulong val)
c6957248
AP
1273{
1274 if (!env->rdtime_fn) {
605def6e 1275 return RISCV_EXCP_ILLEGAL_INST;
c6957248
AP
1276 }
1277
1278 env->htimedelta = deposit64(env->htimedelta, 32, 32, (uint64_t)val);
605def6e 1279 return RISCV_EXCP_NONE;
c6957248 1280}
c6957248 1281
8747c9ee 1282/* Virtual CSR Registers */
605def6e
AF
1283static RISCVException read_vsstatus(CPURISCVState *env, int csrno,
1284 target_ulong *val)
8747c9ee
AF
1285{
1286 *val = env->vsstatus;
605def6e 1287 return RISCV_EXCP_NONE;
8747c9ee
AF
1288}
1289
605def6e
AF
1290static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
1291 target_ulong val)
8747c9ee 1292{
284d697c
YJ
1293 uint64_t mask = (target_ulong)-1;
1294 env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val;
605def6e 1295 return RISCV_EXCP_NONE;
8747c9ee
AF
1296}
1297
8747c9ee
AF
1298static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val)
1299{
1300 *val = env->vstvec;
605def6e 1301 return RISCV_EXCP_NONE;
8747c9ee
AF
1302}
1303
605def6e
AF
1304static RISCVException write_vstvec(CPURISCVState *env, int csrno,
1305 target_ulong val)
8747c9ee
AF
1306{
1307 env->vstvec = val;
605def6e 1308 return RISCV_EXCP_NONE;
8747c9ee
AF
1309}
1310
605def6e
AF
1311static RISCVException read_vsscratch(CPURISCVState *env, int csrno,
1312 target_ulong *val)
8747c9ee
AF
1313{
1314 *val = env->vsscratch;
605def6e 1315 return RISCV_EXCP_NONE;
8747c9ee
AF
1316}
1317
605def6e
AF
1318static RISCVException write_vsscratch(CPURISCVState *env, int csrno,
1319 target_ulong val)
8747c9ee
AF
1320{
1321 env->vsscratch = val;
605def6e 1322 return RISCV_EXCP_NONE;
8747c9ee
AF
1323}
1324
605def6e
AF
1325static RISCVException read_vsepc(CPURISCVState *env, int csrno,
1326 target_ulong *val)
8747c9ee
AF
1327{
1328 *val = env->vsepc;
605def6e 1329 return RISCV_EXCP_NONE;
8747c9ee
AF
1330}
1331
605def6e
AF
1332static RISCVException write_vsepc(CPURISCVState *env, int csrno,
1333 target_ulong val)
8747c9ee
AF
1334{
1335 env->vsepc = val;
605def6e 1336 return RISCV_EXCP_NONE;
8747c9ee
AF
1337}
1338
605def6e
AF
1339static RISCVException read_vscause(CPURISCVState *env, int csrno,
1340 target_ulong *val)
8747c9ee
AF
1341{
1342 *val = env->vscause;
605def6e 1343 return RISCV_EXCP_NONE;
8747c9ee
AF
1344}
1345
605def6e
AF
1346static RISCVException write_vscause(CPURISCVState *env, int csrno,
1347 target_ulong val)
8747c9ee
AF
1348{
1349 env->vscause = val;
605def6e 1350 return RISCV_EXCP_NONE;
8747c9ee
AF
1351}
1352
605def6e
AF
1353static RISCVException read_vstval(CPURISCVState *env, int csrno,
1354 target_ulong *val)
8747c9ee
AF
1355{
1356 *val = env->vstval;
605def6e 1357 return RISCV_EXCP_NONE;
8747c9ee
AF
1358}
1359
605def6e
AF
1360static RISCVException write_vstval(CPURISCVState *env, int csrno,
1361 target_ulong val)
8747c9ee
AF
1362{
1363 env->vstval = val;
605def6e 1364 return RISCV_EXCP_NONE;
8747c9ee
AF
1365}
1366
605def6e
AF
1367static RISCVException read_vsatp(CPURISCVState *env, int csrno,
1368 target_ulong *val)
8747c9ee
AF
1369{
1370 *val = env->vsatp;
605def6e 1371 return RISCV_EXCP_NONE;
8747c9ee
AF
1372}
1373
605def6e
AF
1374static RISCVException write_vsatp(CPURISCVState *env, int csrno,
1375 target_ulong val)
8747c9ee
AF
1376{
1377 env->vsatp = val;
605def6e 1378 return RISCV_EXCP_NONE;
8747c9ee
AF
1379}
1380
605def6e
AF
1381static RISCVException read_mtval2(CPURISCVState *env, int csrno,
1382 target_ulong *val)
34cfb5f6
AF
1383{
1384 *val = env->mtval2;
605def6e 1385 return RISCV_EXCP_NONE;
34cfb5f6
AF
1386}
1387
605def6e
AF
1388static RISCVException write_mtval2(CPURISCVState *env, int csrno,
1389 target_ulong val)
34cfb5f6
AF
1390{
1391 env->mtval2 = val;
605def6e 1392 return RISCV_EXCP_NONE;
34cfb5f6
AF
1393}
1394
605def6e
AF
1395static RISCVException read_mtinst(CPURISCVState *env, int csrno,
1396 target_ulong *val)
34cfb5f6
AF
1397{
1398 *val = env->mtinst;
605def6e 1399 return RISCV_EXCP_NONE;
34cfb5f6
AF
1400}
1401
605def6e
AF
1402static RISCVException write_mtinst(CPURISCVState *env, int csrno,
1403 target_ulong val)
34cfb5f6
AF
1404{
1405 env->mtinst = val;
605def6e 1406 return RISCV_EXCP_NONE;
34cfb5f6
AF
1407}
1408
c7b95171 1409/* Physical Memory Protection */
2582a95c
HW
1410static RISCVException read_mseccfg(CPURISCVState *env, int csrno,
1411 target_ulong *val)
1412{
1413 *val = mseccfg_csr_read(env);
1414 return RISCV_EXCP_NONE;
1415}
1416
1417static RISCVException write_mseccfg(CPURISCVState *env, int csrno,
1418 target_ulong val)
1419{
1420 mseccfg_csr_write(env, val);
1421 return RISCV_EXCP_NONE;
1422}
1423
605def6e
AF
1424static RISCVException read_pmpcfg(CPURISCVState *env, int csrno,
1425 target_ulong *val)
c7b95171
MC
1426{
1427 *val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0);
605def6e 1428 return RISCV_EXCP_NONE;
c7b95171
MC
1429}
1430
605def6e
AF
1431static RISCVException write_pmpcfg(CPURISCVState *env, int csrno,
1432 target_ulong val)
c7b95171
MC
1433{
1434 pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val);
605def6e 1435 return RISCV_EXCP_NONE;
c7b95171
MC
1436}
1437
605def6e
AF
1438static RISCVException read_pmpaddr(CPURISCVState *env, int csrno,
1439 target_ulong *val)
c7b95171
MC
1440{
1441 *val = pmpaddr_csr_read(env, csrno - CSR_PMPADDR0);
605def6e 1442 return RISCV_EXCP_NONE;
c7b95171
MC
1443}
1444
605def6e
AF
1445static RISCVException write_pmpaddr(CPURISCVState *env, int csrno,
1446 target_ulong val)
c7b95171
MC
1447{
1448 pmpaddr_csr_write(env, csrno - CSR_PMPADDR0, val);
605def6e 1449 return RISCV_EXCP_NONE;
c7b95171
MC
1450}
1451
4bbe8033
AB
1452/*
1453 * Functions to access Pointer Masking feature registers
1454 * We have to check if current priv lvl could modify
1455 * csr in given mode
1456 */
1457static bool check_pm_current_disabled(CPURISCVState *env, int csrno)
1458{
1459 int csr_priv = get_field(csrno, 0x300);
1460 int pm_current;
1461
1462 /*
1463 * If priv lvls differ that means we're accessing csr from higher priv lvl,
1464 * so allow the access
1465 */
1466 if (env->priv != csr_priv) {
1467 return false;
1468 }
1469 switch (env->priv) {
1470 case PRV_M:
1471 pm_current = get_field(env->mmte, M_PM_CURRENT);
1472 break;
1473 case PRV_S:
1474 pm_current = get_field(env->mmte, S_PM_CURRENT);
1475 break;
1476 case PRV_U:
1477 pm_current = get_field(env->mmte, U_PM_CURRENT);
1478 break;
1479 default:
1480 g_assert_not_reached();
1481 }
1482 /* It's same priv lvl, so we allow to modify csr only if pm.current==1 */
1483 return !pm_current;
1484}
1485
1486static RISCVException read_mmte(CPURISCVState *env, int csrno,
1487 target_ulong *val)
1488{
1489 *val = env->mmte & MMTE_MASK;
1490 return RISCV_EXCP_NONE;
1491}
1492
1493static RISCVException write_mmte(CPURISCVState *env, int csrno,
1494 target_ulong val)
1495{
1496 uint64_t mstatus;
1497 target_ulong wpri_val = val & MMTE_MASK;
1498
1499 if (val != wpri_val) {
1500 qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" TARGET_FMT_lx "\n",
1501 "MMTE: WPRI violation written 0x", val,
1502 "vs expected 0x", wpri_val);
1503 }
1504 /* for machine mode pm.current is hardwired to 1 */
1505 wpri_val |= MMTE_M_PM_CURRENT;
1506
1507 /* hardwiring pm.instruction bit to 0, since it's not supported yet */
1508 wpri_val &= ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN);
1509 env->mmte = wpri_val | PM_EXT_DIRTY;
1510
1511 /* Set XS and SD bits, since PM CSRs are dirty */
1512 mstatus = env->mstatus | MSTATUS_XS;
1513 write_mstatus(env, csrno, mstatus);
1514 return RISCV_EXCP_NONE;
1515}
1516
1517static RISCVException read_smte(CPURISCVState *env, int csrno,
1518 target_ulong *val)
1519{
1520 *val = env->mmte & SMTE_MASK;
1521 return RISCV_EXCP_NONE;
1522}
1523
1524static RISCVException write_smte(CPURISCVState *env, int csrno,
1525 target_ulong val)
1526{
1527 target_ulong wpri_val = val & SMTE_MASK;
1528
1529 if (val != wpri_val) {
1530 qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" TARGET_FMT_lx "\n",
1531 "SMTE: WPRI violation written 0x", val,
1532 "vs expected 0x", wpri_val);
1533 }
1534
1535 /* if pm.current==0 we can't modify current PM CSRs */
1536 if (check_pm_current_disabled(env, csrno)) {
1537 return RISCV_EXCP_NONE;
1538 }
1539
1540 wpri_val |= (env->mmte & ~SMTE_MASK);
1541 write_mmte(env, csrno, wpri_val);
1542 return RISCV_EXCP_NONE;
1543}
1544
1545static RISCVException read_umte(CPURISCVState *env, int csrno,
1546 target_ulong *val)
1547{
1548 *val = env->mmte & UMTE_MASK;
1549 return RISCV_EXCP_NONE;
1550}
1551
1552static RISCVException write_umte(CPURISCVState *env, int csrno,
1553 target_ulong val)
1554{
1555 target_ulong wpri_val = val & UMTE_MASK;
1556
1557 if (val != wpri_val) {
1558 qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" TARGET_FMT_lx "\n",
1559 "UMTE: WPRI violation written 0x", val,
1560 "vs expected 0x", wpri_val);
1561 }
1562
1563 if (check_pm_current_disabled(env, csrno)) {
1564 return RISCV_EXCP_NONE;
1565 }
1566
1567 wpri_val |= (env->mmte & ~UMTE_MASK);
1568 write_mmte(env, csrno, wpri_val);
1569 return RISCV_EXCP_NONE;
1570}
1571
1572static RISCVException read_mpmmask(CPURISCVState *env, int csrno,
1573 target_ulong *val)
1574{
1575 *val = env->mpmmask;
1576 return RISCV_EXCP_NONE;
1577}
1578
1579static RISCVException write_mpmmask(CPURISCVState *env, int csrno,
1580 target_ulong val)
1581{
1582 uint64_t mstatus;
1583
1584 env->mpmmask = val;
1585 env->mmte |= PM_EXT_DIRTY;
1586
1587 /* Set XS and SD bits, since PM CSRs are dirty */
1588 mstatus = env->mstatus | MSTATUS_XS;
1589 write_mstatus(env, csrno, mstatus);
1590 return RISCV_EXCP_NONE;
1591}
1592
1593static RISCVException read_spmmask(CPURISCVState *env, int csrno,
1594 target_ulong *val)
1595{
1596 *val = env->spmmask;
1597 return RISCV_EXCP_NONE;
1598}
1599
1600static RISCVException write_spmmask(CPURISCVState *env, int csrno,
1601 target_ulong val)
1602{
1603 uint64_t mstatus;
1604
1605 /* if pm.current==0 we can't modify current PM CSRs */
1606 if (check_pm_current_disabled(env, csrno)) {
1607 return RISCV_EXCP_NONE;
1608 }
1609 env->spmmask = val;
1610 env->mmte |= PM_EXT_DIRTY;
1611
1612 /* Set XS and SD bits, since PM CSRs are dirty */
1613 mstatus = env->mstatus | MSTATUS_XS;
1614 write_mstatus(env, csrno, mstatus);
1615 return RISCV_EXCP_NONE;
1616}
1617
1618static RISCVException read_upmmask(CPURISCVState *env, int csrno,
1619 target_ulong *val)
1620{
1621 *val = env->upmmask;
1622 return RISCV_EXCP_NONE;
1623}
1624
1625static RISCVException write_upmmask(CPURISCVState *env, int csrno,
1626 target_ulong val)
1627{
1628 uint64_t mstatus;
1629
1630 /* if pm.current==0 we can't modify current PM CSRs */
1631 if (check_pm_current_disabled(env, csrno)) {
1632 return RISCV_EXCP_NONE;
1633 }
1634 env->upmmask = val;
1635 env->mmte |= PM_EXT_DIRTY;
1636
1637 /* Set XS and SD bits, since PM CSRs are dirty */
1638 mstatus = env->mstatus | MSTATUS_XS;
1639 write_mstatus(env, csrno, mstatus);
1640 return RISCV_EXCP_NONE;
1641}
1642
1643static RISCVException read_mpmbase(CPURISCVState *env, int csrno,
1644 target_ulong *val)
1645{
1646 *val = env->mpmbase;
1647 return RISCV_EXCP_NONE;
1648}
1649
1650static RISCVException write_mpmbase(CPURISCVState *env, int csrno,
1651 target_ulong val)
1652{
1653 uint64_t mstatus;
1654
1655 env->mpmbase = val;
1656 env->mmte |= PM_EXT_DIRTY;
1657
1658 /* Set XS and SD bits, since PM CSRs are dirty */
1659 mstatus = env->mstatus | MSTATUS_XS;
1660 write_mstatus(env, csrno, mstatus);
1661 return RISCV_EXCP_NONE;
1662}
1663
1664static RISCVException read_spmbase(CPURISCVState *env, int csrno,
1665 target_ulong *val)
1666{
1667 *val = env->spmbase;
1668 return RISCV_EXCP_NONE;
1669}
1670
1671static RISCVException write_spmbase(CPURISCVState *env, int csrno,
1672 target_ulong val)
1673{
1674 uint64_t mstatus;
1675
1676 /* if pm.current==0 we can't modify current PM CSRs */
1677 if (check_pm_current_disabled(env, csrno)) {
1678 return RISCV_EXCP_NONE;
1679 }
1680 env->spmbase = val;
1681 env->mmte |= PM_EXT_DIRTY;
1682
1683 /* Set XS and SD bits, since PM CSRs are dirty */
1684 mstatus = env->mstatus | MSTATUS_XS;
1685 write_mstatus(env, csrno, mstatus);
1686 return RISCV_EXCP_NONE;
1687}
1688
1689static RISCVException read_upmbase(CPURISCVState *env, int csrno,
1690 target_ulong *val)
1691{
1692 *val = env->upmbase;
1693 return RISCV_EXCP_NONE;
1694}
1695
1696static RISCVException write_upmbase(CPURISCVState *env, int csrno,
1697 target_ulong val)
1698{
1699 uint64_t mstatus;
1700
1701 /* if pm.current==0 we can't modify current PM CSRs */
1702 if (check_pm_current_disabled(env, csrno)) {
1703 return RISCV_EXCP_NONE;
1704 }
1705 env->upmbase = val;
1706 env->mmte |= PM_EXT_DIRTY;
1707
1708 /* Set XS and SD bits, since PM CSRs are dirty */
1709 mstatus = env->mstatus | MSTATUS_XS;
1710 write_mstatus(env, csrno, mstatus);
1711 return RISCV_EXCP_NONE;
1712}
1713
c7b95171
MC
1714#endif
1715
1716/*
1717 * riscv_csrrw - read and/or update control and status register
1718 *
1719 * csrr <-> riscv_csrrw(env, csrno, ret_value, 0, 0);
1720 * csrrw <-> riscv_csrrw(env, csrno, ret_value, value, -1);
1721 * csrrs <-> riscv_csrrw(env, csrno, ret_value, -1, value);
1722 * csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value);
1723 */
1724
533c91e8
AF
1725RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
1726 target_ulong *ret_value,
1727 target_ulong new_value, target_ulong write_mask)
c7b95171 1728{
533c91e8 1729 RISCVException ret;
c7b95171 1730 target_ulong old_value;
591bddea 1731 RISCVCPU *cpu = env_archcpu(env);
42109837 1732 int read_only = get_field(csrno, 0xC00) == 3;
c7b95171 1733
65e728a2 1734 /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
c7b95171 1735#if !defined(CONFIG_USER_ONLY)
0a42f4c4 1736 int effective_priv = env->priv;
0a42f4c4
AF
1737
1738 if (riscv_has_ext(env, RVH) &&
1739 env->priv == PRV_S &&
1740 !riscv_cpu_virt_enabled(env)) {
1741 /*
1742 * We are in S mode without virtualisation, therefore we are in HS Mode.
1743 * Add 1 to the effective privledge level to allow us to access the
1744 * Hypervisor CSRs.
1745 */
1746 effective_priv++;
e6e03dcf 1747 }
0a42f4c4 1748
42109837 1749 if (!env->debugger && (effective_priv < get_field(csrno, 0x300))) {
533c91e8 1750 return RISCV_EXCP_ILLEGAL_INST;
c7b95171
MC
1751 }
1752#endif
42109837
LZ
1753 if (write_mask && read_only) {
1754 return RISCV_EXCP_ILLEGAL_INST;
1755 }
c7b95171 1756
591bddea
PD
1757 /* ensure the CSR extension is enabled. */
1758 if (!cpu->cfg.ext_icsr) {
533c91e8 1759 return RISCV_EXCP_ILLEGAL_INST;
591bddea
PD
1760 }
1761
a88365c1 1762 /* check predicate */
e39a8320 1763 if (!csr_ops[csrno].predicate) {
533c91e8 1764 return RISCV_EXCP_ILLEGAL_INST;
a88365c1 1765 }
e39a8320 1766 ret = csr_ops[csrno].predicate(env, csrno);
0e62f92e 1767 if (ret != RISCV_EXCP_NONE) {
533c91e8 1768 return ret;
e39a8320 1769 }
a88365c1 1770
c7b95171
MC
1771 /* execute combined read/write operation if it exists */
1772 if (csr_ops[csrno].op) {
533c91e8 1773 return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask);
c7b95171
MC
1774 }
1775
1776 /* if no accessor exists then return failure */
1777 if (!csr_ops[csrno].read) {
533c91e8 1778 return RISCV_EXCP_ILLEGAL_INST;
c7b95171 1779 }
c7b95171
MC
1780 /* read old value */
1781 ret = csr_ops[csrno].read(env, csrno, &old_value);
605def6e 1782 if (ret != RISCV_EXCP_NONE) {
533c91e8 1783 return ret;
c7b95171
MC
1784 }
1785
1786 /* write value if writable and write mask set, otherwise drop writes */
1787 if (write_mask) {
1788 new_value = (old_value & ~write_mask) | (new_value & write_mask);
1789 if (csr_ops[csrno].write) {
1790 ret = csr_ops[csrno].write(env, csrno, new_value);
605def6e 1791 if (ret != RISCV_EXCP_NONE) {
533c91e8 1792 return ret;
c7b95171
MC
1793 }
1794 }
1795 }
1796
1797 /* return old value */
1798 if (ret_value) {
1799 *ret_value = old_value;
1800 }
1801
533c91e8 1802 return RISCV_EXCP_NONE;
c7b95171
MC
1803}
1804
753e3fe2
JW
1805/*
1806 * Debugger support. If not in user mode, set env->debugger before the
1807 * riscv_csrrw call and clear it after the call.
1808 */
533c91e8
AF
1809RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno,
1810 target_ulong *ret_value,
1811 target_ulong new_value,
1812 target_ulong write_mask)
753e3fe2 1813{
533c91e8 1814 RISCVException ret;
753e3fe2
JW
1815#if !defined(CONFIG_USER_ONLY)
1816 env->debugger = true;
1817#endif
1818 ret = riscv_csrrw(env, csrno, ret_value, new_value, write_mask);
1819#if !defined(CONFIG_USER_ONLY)
1820 env->debugger = false;
1821#endif
1822 return ret;
1823}
1824
c7b95171 1825/* Control and Status Register function table */
56118ee8 1826riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
c7b95171 1827 /* User Floating-Point CSRs */
8ceac5dc
BM
1828 [CSR_FFLAGS] = { "fflags", fs, read_fflags, write_fflags },
1829 [CSR_FRM] = { "frm", fs, read_frm, write_frm },
1830 [CSR_FCSR] = { "fcsr", fs, read_fcsr, write_fcsr },
8e3a1f18 1831 /* Vector CSRs */
8ceac5dc
BM
1832 [CSR_VSTART] = { "vstart", vs, read_vstart, write_vstart },
1833 [CSR_VXSAT] = { "vxsat", vs, read_vxsat, write_vxsat },
1834 [CSR_VXRM] = { "vxrm", vs, read_vxrm, write_vxrm },
4594fa5a 1835 [CSR_VCSR] = { "vcsr", vs, read_vcsr, write_vcsr },
8ceac5dc
BM
1836 [CSR_VL] = { "vl", vs, read_vl },
1837 [CSR_VTYPE] = { "vtype", vs, read_vtype },
c7b95171 1838 /* User Timers and Counters */
8ceac5dc
BM
1839 [CSR_CYCLE] = { "cycle", ctr, read_instret },
1840 [CSR_INSTRET] = { "instret", ctr, read_instret },
1841 [CSR_CYCLEH] = { "cycleh", ctr32, read_instreth },
1842 [CSR_INSTRETH] = { "instreth", ctr32, read_instreth },
1843
1844 /*
1845 * In privileged mode, the monitor will have to emulate TIME CSRs only if
1846 * rdtime callback is not provided by machine/platform emulation.
1847 */
1848 [CSR_TIME] = { "time", ctr, read_time },
1849 [CSR_TIMEH] = { "timeh", ctr32, read_timeh },
c7b95171
MC
1850
1851#if !defined(CONFIG_USER_ONLY)
1852 /* Machine Timers and Counters */
8ceac5dc
BM
1853 [CSR_MCYCLE] = { "mcycle", any, read_instret },
1854 [CSR_MINSTRET] = { "minstret", any, read_instret },
1855 [CSR_MCYCLEH] = { "mcycleh", any32, read_instreth },
1856 [CSR_MINSTRETH] = { "minstreth", any32, read_instreth },
c7b95171
MC
1857
1858 /* Machine Information Registers */
8ceac5dc
BM
1859 [CSR_MVENDORID] = { "mvendorid", any, read_zero },
1860 [CSR_MARCHID] = { "marchid", any, read_zero },
1861 [CSR_MIMPID] = { "mimpid", any, read_zero },
1862 [CSR_MHARTID] = { "mhartid", any, read_mhartid },
c7b95171
MC
1863
1864 /* Machine Trap Setup */
8ceac5dc
BM
1865 [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus },
1866 [CSR_MISA] = { "misa", any, read_misa, write_misa },
1867 [CSR_MIDELEG] = { "mideleg", any, read_mideleg, write_mideleg },
1868 [CSR_MEDELEG] = { "medeleg", any, read_medeleg, write_medeleg },
1869 [CSR_MIE] = { "mie", any, read_mie, write_mie },
1870 [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec },
1871 [CSR_MCOUNTEREN] = { "mcounteren", any, read_mcounteren, write_mcounteren },
c7b95171 1872
8ceac5dc 1873 [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush },
551fa7e8 1874
c7b95171 1875 /* Machine Trap Handling */
8ceac5dc
BM
1876 [CSR_MSCRATCH] = { "mscratch", any, read_mscratch, write_mscratch },
1877 [CSR_MEPC] = { "mepc", any, read_mepc, write_mepc },
1878 [CSR_MCAUSE] = { "mcause", any, read_mcause, write_mcause },
ac12b601 1879 [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval },
8ceac5dc 1880 [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip },
c7b95171
MC
1881
1882 /* Supervisor Trap Setup */
8ceac5dc
BM
1883 [CSR_SSTATUS] = { "sstatus", smode, read_sstatus, write_sstatus },
1884 [CSR_SIE] = { "sie", smode, read_sie, write_sie },
1885 [CSR_STVEC] = { "stvec", smode, read_stvec, write_stvec },
1886 [CSR_SCOUNTEREN] = { "scounteren", smode, read_scounteren, write_scounteren },
c7b95171
MC
1887
1888 /* Supervisor Trap Handling */
8ceac5dc
BM
1889 [CSR_SSCRATCH] = { "sscratch", smode, read_sscratch, write_sscratch },
1890 [CSR_SEPC] = { "sepc", smode, read_sepc, write_sepc },
1891 [CSR_SCAUSE] = { "scause", smode, read_scause, write_scause },
ac12b601 1892 [CSR_STVAL] = { "stval", smode, read_stval, write_stval },
8ceac5dc 1893 [CSR_SIP] = { "sip", smode, NULL, NULL, rmw_sip },
c7b95171
MC
1894
1895 /* Supervisor Protection and Translation */
8ceac5dc
BM
1896 [CSR_SATP] = { "satp", smode, read_satp, write_satp },
1897
1898 [CSR_HSTATUS] = { "hstatus", hmode, read_hstatus, write_hstatus },
1899 [CSR_HEDELEG] = { "hedeleg", hmode, read_hedeleg, write_hedeleg },
1900 [CSR_HIDELEG] = { "hideleg", hmode, read_hideleg, write_hideleg },
1901 [CSR_HVIP] = { "hvip", hmode, NULL, NULL, rmw_hvip },
1902 [CSR_HIP] = { "hip", hmode, NULL, NULL, rmw_hip },
1903 [CSR_HIE] = { "hie", hmode, read_hie, write_hie },
1904 [CSR_HCOUNTEREN] = { "hcounteren", hmode, read_hcounteren, write_hcounteren },
377cbb4b 1905 [CSR_HGEIE] = { "hgeie", hmode, read_zero, write_hgeie },
8ceac5dc
BM
1906 [CSR_HTVAL] = { "htval", hmode, read_htval, write_htval },
1907 [CSR_HTINST] = { "htinst", hmode, read_htinst, write_htinst },
377cbb4b 1908 [CSR_HGEIP] = { "hgeip", hmode, read_zero, write_hgeip },
8ceac5dc
BM
1909 [CSR_HGATP] = { "hgatp", hmode, read_hgatp, write_hgatp },
1910 [CSR_HTIMEDELTA] = { "htimedelta", hmode, read_htimedelta, write_htimedelta },
1911 [CSR_HTIMEDELTAH] = { "htimedeltah", hmode32, read_htimedeltah, write_htimedeltah },
1912
1913 [CSR_VSSTATUS] = { "vsstatus", hmode, read_vsstatus, write_vsstatus },
1914 [CSR_VSIP] = { "vsip", hmode, NULL, NULL, rmw_vsip },
1915 [CSR_VSIE] = { "vsie", hmode, read_vsie, write_vsie },
1916 [CSR_VSTVEC] = { "vstvec", hmode, read_vstvec, write_vstvec },
1917 [CSR_VSSCRATCH] = { "vsscratch", hmode, read_vsscratch, write_vsscratch },
1918 [CSR_VSEPC] = { "vsepc", hmode, read_vsepc, write_vsepc },
1919 [CSR_VSCAUSE] = { "vscause", hmode, read_vscause, write_vscause },
1920 [CSR_VSTVAL] = { "vstval", hmode, read_vstval, write_vstval },
1921 [CSR_VSATP] = { "vsatp", hmode, read_vsatp, write_vsatp },
1922
1923 [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2 },
1924 [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst },
34cfb5f6 1925
c7b95171 1926 /* Physical Memory Protection */
2582a95c 1927 [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg },
8ceac5dc
BM
1928 [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg },
1929 [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },
1930 [CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg },
1931 [CSR_PMPCFG3] = { "pmpcfg3", pmp, read_pmpcfg, write_pmpcfg },
1932 [CSR_PMPADDR0] = { "pmpaddr0", pmp, read_pmpaddr, write_pmpaddr },
1933 [CSR_PMPADDR1] = { "pmpaddr1", pmp, read_pmpaddr, write_pmpaddr },
1934 [CSR_PMPADDR2] = { "pmpaddr2", pmp, read_pmpaddr, write_pmpaddr },
1935 [CSR_PMPADDR3] = { "pmpaddr3", pmp, read_pmpaddr, write_pmpaddr },
1936 [CSR_PMPADDR4] = { "pmpaddr4", pmp, read_pmpaddr, write_pmpaddr },
1937 [CSR_PMPADDR5] = { "pmpaddr5", pmp, read_pmpaddr, write_pmpaddr },
1938 [CSR_PMPADDR6] = { "pmpaddr6", pmp, read_pmpaddr, write_pmpaddr },
1939 [CSR_PMPADDR7] = { "pmpaddr7", pmp, read_pmpaddr, write_pmpaddr },
1940 [CSR_PMPADDR8] = { "pmpaddr8", pmp, read_pmpaddr, write_pmpaddr },
1941 [CSR_PMPADDR9] = { "pmpaddr9", pmp, read_pmpaddr, write_pmpaddr },
1942 [CSR_PMPADDR10] = { "pmpaddr10", pmp, read_pmpaddr, write_pmpaddr },
1943 [CSR_PMPADDR11] = { "pmpaddr11", pmp, read_pmpaddr, write_pmpaddr },
1944 [CSR_PMPADDR12] = { "pmpaddr12", pmp, read_pmpaddr, write_pmpaddr },
1945 [CSR_PMPADDR13] = { "pmpaddr13", pmp, read_pmpaddr, write_pmpaddr },
1946 [CSR_PMPADDR14] = { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr },
1947 [CSR_PMPADDR15] = { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr },
c7b95171 1948
4bbe8033
AB
1949 /* User Pointer Masking */
1950 [CSR_UMTE] = { "umte", pointer_masking, read_umte, write_umte },
1951 [CSR_UPMMASK] = { "upmmask", pointer_masking, read_upmmask, write_upmmask },
1952 [CSR_UPMBASE] = { "upmbase", pointer_masking, read_upmbase, write_upmbase },
1953 /* Machine Pointer Masking */
1954 [CSR_MMTE] = { "mmte", pointer_masking, read_mmte, write_mmte },
1955 [CSR_MPMMASK] = { "mpmmask", pointer_masking, read_mpmmask, write_mpmmask },
1956 [CSR_MPMBASE] = { "mpmbase", pointer_masking, read_mpmbase, write_mpmbase },
1957 /* Supervisor Pointer Masking */
1958 [CSR_SMTE] = { "smte", pointer_masking, read_smte, write_smte },
1959 [CSR_SPMMASK] = { "spmmask", pointer_masking, read_spmmask, write_spmmask },
1960 [CSR_SPMBASE] = { "spmbase", pointer_masking, read_spmbase, write_spmbase },
1961
c7b95171 1962 /* Performance Counters */
8ceac5dc
BM
1963 [CSR_HPMCOUNTER3] = { "hpmcounter3", ctr, read_zero },
1964 [CSR_HPMCOUNTER4] = { "hpmcounter4", ctr, read_zero },
1965 [CSR_HPMCOUNTER5] = { "hpmcounter5", ctr, read_zero },
1966 [CSR_HPMCOUNTER6] = { "hpmcounter6", ctr, read_zero },
1967 [CSR_HPMCOUNTER7] = { "hpmcounter7", ctr, read_zero },
1968 [CSR_HPMCOUNTER8] = { "hpmcounter8", ctr, read_zero },
1969 [CSR_HPMCOUNTER9] = { "hpmcounter9", ctr, read_zero },
1970 [CSR_HPMCOUNTER10] = { "hpmcounter10", ctr, read_zero },
1971 [CSR_HPMCOUNTER11] = { "hpmcounter11", ctr, read_zero },
1972 [CSR_HPMCOUNTER12] = { "hpmcounter12", ctr, read_zero },
1973 [CSR_HPMCOUNTER13] = { "hpmcounter13", ctr, read_zero },
1974 [CSR_HPMCOUNTER14] = { "hpmcounter14", ctr, read_zero },
1975 [CSR_HPMCOUNTER15] = { "hpmcounter15", ctr, read_zero },
1976 [CSR_HPMCOUNTER16] = { "hpmcounter16", ctr, read_zero },
1977 [CSR_HPMCOUNTER17] = { "hpmcounter17", ctr, read_zero },
1978 [CSR_HPMCOUNTER18] = { "hpmcounter18", ctr, read_zero },
1979 [CSR_HPMCOUNTER19] = { "hpmcounter19", ctr, read_zero },
1980 [CSR_HPMCOUNTER20] = { "hpmcounter20", ctr, read_zero },
1981 [CSR_HPMCOUNTER21] = { "hpmcounter21", ctr, read_zero },
1982 [CSR_HPMCOUNTER22] = { "hpmcounter22", ctr, read_zero },
1983 [CSR_HPMCOUNTER23] = { "hpmcounter23", ctr, read_zero },
1984 [CSR_HPMCOUNTER24] = { "hpmcounter24", ctr, read_zero },
1985 [CSR_HPMCOUNTER25] = { "hpmcounter25", ctr, read_zero },
1986 [CSR_HPMCOUNTER26] = { "hpmcounter26", ctr, read_zero },
1987 [CSR_HPMCOUNTER27] = { "hpmcounter27", ctr, read_zero },
1988 [CSR_HPMCOUNTER28] = { "hpmcounter28", ctr, read_zero },
1989 [CSR_HPMCOUNTER29] = { "hpmcounter29", ctr, read_zero },
1990 [CSR_HPMCOUNTER30] = { "hpmcounter30", ctr, read_zero },
1991 [CSR_HPMCOUNTER31] = { "hpmcounter31", ctr, read_zero },
1992
1993 [CSR_MHPMCOUNTER3] = { "mhpmcounter3", any, read_zero },
1994 [CSR_MHPMCOUNTER4] = { "mhpmcounter4", any, read_zero },
1995 [CSR_MHPMCOUNTER5] = { "mhpmcounter5", any, read_zero },
1996 [CSR_MHPMCOUNTER6] = { "mhpmcounter6", any, read_zero },
1997 [CSR_MHPMCOUNTER7] = { "mhpmcounter7", any, read_zero },
1998 [CSR_MHPMCOUNTER8] = { "mhpmcounter8", any, read_zero },
1999 [CSR_MHPMCOUNTER9] = { "mhpmcounter9", any, read_zero },
2000 [CSR_MHPMCOUNTER10] = { "mhpmcounter10", any, read_zero },
2001 [CSR_MHPMCOUNTER11] = { "mhpmcounter11", any, read_zero },
2002 [CSR_MHPMCOUNTER12] = { "mhpmcounter12", any, read_zero },
2003 [CSR_MHPMCOUNTER13] = { "mhpmcounter13", any, read_zero },
2004 [CSR_MHPMCOUNTER14] = { "mhpmcounter14", any, read_zero },
2005 [CSR_MHPMCOUNTER15] = { "mhpmcounter15", any, read_zero },
2006 [CSR_MHPMCOUNTER16] = { "mhpmcounter16", any, read_zero },
2007 [CSR_MHPMCOUNTER17] = { "mhpmcounter17", any, read_zero },
2008 [CSR_MHPMCOUNTER18] = { "mhpmcounter18", any, read_zero },
2009 [CSR_MHPMCOUNTER19] = { "mhpmcounter19", any, read_zero },
2010 [CSR_MHPMCOUNTER20] = { "mhpmcounter20", any, read_zero },
2011 [CSR_MHPMCOUNTER21] = { "mhpmcounter21", any, read_zero },
2012 [CSR_MHPMCOUNTER22] = { "mhpmcounter22", any, read_zero },
2013 [CSR_MHPMCOUNTER23] = { "mhpmcounter23", any, read_zero },
2014 [CSR_MHPMCOUNTER24] = { "mhpmcounter24", any, read_zero },
2015 [CSR_MHPMCOUNTER25] = { "mhpmcounter25", any, read_zero },
2016 [CSR_MHPMCOUNTER26] = { "mhpmcounter26", any, read_zero },
2017 [CSR_MHPMCOUNTER27] = { "mhpmcounter27", any, read_zero },
2018 [CSR_MHPMCOUNTER28] = { "mhpmcounter28", any, read_zero },
2019 [CSR_MHPMCOUNTER29] = { "mhpmcounter29", any, read_zero },
2020 [CSR_MHPMCOUNTER30] = { "mhpmcounter30", any, read_zero },
2021 [CSR_MHPMCOUNTER31] = { "mhpmcounter31", any, read_zero },
2022
2023 [CSR_MHPMEVENT3] = { "mhpmevent3", any, read_zero },
2024 [CSR_MHPMEVENT4] = { "mhpmevent4", any, read_zero },
2025 [CSR_MHPMEVENT5] = { "mhpmevent5", any, read_zero },
2026 [CSR_MHPMEVENT6] = { "mhpmevent6", any, read_zero },
2027 [CSR_MHPMEVENT7] = { "mhpmevent7", any, read_zero },
2028 [CSR_MHPMEVENT8] = { "mhpmevent8", any, read_zero },
2029 [CSR_MHPMEVENT9] = { "mhpmevent9", any, read_zero },
2030 [CSR_MHPMEVENT10] = { "mhpmevent10", any, read_zero },
2031 [CSR_MHPMEVENT11] = { "mhpmevent11", any, read_zero },
2032 [CSR_MHPMEVENT12] = { "mhpmevent12", any, read_zero },
2033 [CSR_MHPMEVENT13] = { "mhpmevent13", any, read_zero },
2034 [CSR_MHPMEVENT14] = { "mhpmevent14", any, read_zero },
2035 [CSR_MHPMEVENT15] = { "mhpmevent15", any, read_zero },
2036 [CSR_MHPMEVENT16] = { "mhpmevent16", any, read_zero },
2037 [CSR_MHPMEVENT17] = { "mhpmevent17", any, read_zero },
2038 [CSR_MHPMEVENT18] = { "mhpmevent18", any, read_zero },
2039 [CSR_MHPMEVENT19] = { "mhpmevent19", any, read_zero },
2040 [CSR_MHPMEVENT20] = { "mhpmevent20", any, read_zero },
2041 [CSR_MHPMEVENT21] = { "mhpmevent21", any, read_zero },
2042 [CSR_MHPMEVENT22] = { "mhpmevent22", any, read_zero },
2043 [CSR_MHPMEVENT23] = { "mhpmevent23", any, read_zero },
2044 [CSR_MHPMEVENT24] = { "mhpmevent24", any, read_zero },
2045 [CSR_MHPMEVENT25] = { "mhpmevent25", any, read_zero },
2046 [CSR_MHPMEVENT26] = { "mhpmevent26", any, read_zero },
2047 [CSR_MHPMEVENT27] = { "mhpmevent27", any, read_zero },
2048 [CSR_MHPMEVENT28] = { "mhpmevent28", any, read_zero },
2049 [CSR_MHPMEVENT29] = { "mhpmevent29", any, read_zero },
2050 [CSR_MHPMEVENT30] = { "mhpmevent30", any, read_zero },
2051 [CSR_MHPMEVENT31] = { "mhpmevent31", any, read_zero },
2052
2053 [CSR_HPMCOUNTER3H] = { "hpmcounter3h", ctr32, read_zero },
2054 [CSR_HPMCOUNTER4H] = { "hpmcounter4h", ctr32, read_zero },
2055 [CSR_HPMCOUNTER5H] = { "hpmcounter5h", ctr32, read_zero },
2056 [CSR_HPMCOUNTER6H] = { "hpmcounter6h", ctr32, read_zero },
2057 [CSR_HPMCOUNTER7H] = { "hpmcounter7h", ctr32, read_zero },
2058 [CSR_HPMCOUNTER8H] = { "hpmcounter8h", ctr32, read_zero },
2059 [CSR_HPMCOUNTER9H] = { "hpmcounter9h", ctr32, read_zero },
2060 [CSR_HPMCOUNTER10H] = { "hpmcounter10h", ctr32, read_zero },
2061 [CSR_HPMCOUNTER11H] = { "hpmcounter11h", ctr32, read_zero },
2062 [CSR_HPMCOUNTER12H] = { "hpmcounter12h", ctr32, read_zero },
2063 [CSR_HPMCOUNTER13H] = { "hpmcounter13h", ctr32, read_zero },
2064 [CSR_HPMCOUNTER14H] = { "hpmcounter14h", ctr32, read_zero },
2065 [CSR_HPMCOUNTER15H] = { "hpmcounter15h", ctr32, read_zero },
2066 [CSR_HPMCOUNTER16H] = { "hpmcounter16h", ctr32, read_zero },
2067 [CSR_HPMCOUNTER17H] = { "hpmcounter17h", ctr32, read_zero },
2068 [CSR_HPMCOUNTER18H] = { "hpmcounter18h", ctr32, read_zero },
2069 [CSR_HPMCOUNTER19H] = { "hpmcounter19h", ctr32, read_zero },
2070 [CSR_HPMCOUNTER20H] = { "hpmcounter20h", ctr32, read_zero },
2071 [CSR_HPMCOUNTER21H] = { "hpmcounter21h", ctr32, read_zero },
2072 [CSR_HPMCOUNTER22H] = { "hpmcounter22h", ctr32, read_zero },
2073 [CSR_HPMCOUNTER23H] = { "hpmcounter23h", ctr32, read_zero },
2074 [CSR_HPMCOUNTER24H] = { "hpmcounter24h", ctr32, read_zero },
2075 [CSR_HPMCOUNTER25H] = { "hpmcounter25h", ctr32, read_zero },
2076 [CSR_HPMCOUNTER26H] = { "hpmcounter26h", ctr32, read_zero },
2077 [CSR_HPMCOUNTER27H] = { "hpmcounter27h", ctr32, read_zero },
2078 [CSR_HPMCOUNTER28H] = { "hpmcounter28h", ctr32, read_zero },
2079 [CSR_HPMCOUNTER29H] = { "hpmcounter29h", ctr32, read_zero },
2080 [CSR_HPMCOUNTER30H] = { "hpmcounter30h", ctr32, read_zero },
2081 [CSR_HPMCOUNTER31H] = { "hpmcounter31h", ctr32, read_zero },
2082
2083 [CSR_MHPMCOUNTER3H] = { "mhpmcounter3h", any32, read_zero },
2084 [CSR_MHPMCOUNTER4H] = { "mhpmcounter4h", any32, read_zero },
2085 [CSR_MHPMCOUNTER5H] = { "mhpmcounter5h", any32, read_zero },
2086 [CSR_MHPMCOUNTER6H] = { "mhpmcounter6h", any32, read_zero },
2087 [CSR_MHPMCOUNTER7H] = { "mhpmcounter7h", any32, read_zero },
2088 [CSR_MHPMCOUNTER8H] = { "mhpmcounter8h", any32, read_zero },
2089 [CSR_MHPMCOUNTER9H] = { "mhpmcounter9h", any32, read_zero },
2090 [CSR_MHPMCOUNTER10H] = { "mhpmcounter10h", any32, read_zero },
2091 [CSR_MHPMCOUNTER11H] = { "mhpmcounter11h", any32, read_zero },
2092 [CSR_MHPMCOUNTER12H] = { "mhpmcounter12h", any32, read_zero },
2093 [CSR_MHPMCOUNTER13H] = { "mhpmcounter13h", any32, read_zero },
2094 [CSR_MHPMCOUNTER14H] = { "mhpmcounter14h", any32, read_zero },
2095 [CSR_MHPMCOUNTER15H] = { "mhpmcounter15h", any32, read_zero },
2096 [CSR_MHPMCOUNTER16H] = { "mhpmcounter16h", any32, read_zero },
2097 [CSR_MHPMCOUNTER17H] = { "mhpmcounter17h", any32, read_zero },
2098 [CSR_MHPMCOUNTER18H] = { "mhpmcounter18h", any32, read_zero },
2099 [CSR_MHPMCOUNTER19H] = { "mhpmcounter19h", any32, read_zero },
2100 [CSR_MHPMCOUNTER20H] = { "mhpmcounter20h", any32, read_zero },
2101 [CSR_MHPMCOUNTER21H] = { "mhpmcounter21h", any32, read_zero },
2102 [CSR_MHPMCOUNTER22H] = { "mhpmcounter22h", any32, read_zero },
2103 [CSR_MHPMCOUNTER23H] = { "mhpmcounter23h", any32, read_zero },
2104 [CSR_MHPMCOUNTER24H] = { "mhpmcounter24h", any32, read_zero },
2105 [CSR_MHPMCOUNTER25H] = { "mhpmcounter25h", any32, read_zero },
2106 [CSR_MHPMCOUNTER26H] = { "mhpmcounter26h", any32, read_zero },
2107 [CSR_MHPMCOUNTER27H] = { "mhpmcounter27h", any32, read_zero },
2108 [CSR_MHPMCOUNTER28H] = { "mhpmcounter28h", any32, read_zero },
2109 [CSR_MHPMCOUNTER29H] = { "mhpmcounter29h", any32, read_zero },
2110 [CSR_MHPMCOUNTER30H] = { "mhpmcounter30h", any32, read_zero },
2111 [CSR_MHPMCOUNTER31H] = { "mhpmcounter31h", any32, read_zero },
c7b95171
MC
2112#endif /* !CONFIG_USER_ONLY */
2113};
This page took 0.583438 seconds and 4 git commands to generate.