2 * T-Head-specific CSRs.
4 * Copyright (c) 2024 VRULL GmbH
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
21 #include "cpu_vendorid.h"
23 #define CSR_TH_SXSTATUS 0x5c0
25 /* TH_SXSTATUS bits */
26 #define TH_SXSTATUS_UCME BIT(16)
27 #define TH_SXSTATUS_MAEE BIT(21)
28 #define TH_SXSTATUS_THEADISAEE BIT(22)
32 int (*insertion_test
)(RISCVCPU
*cpu
);
33 riscv_csr_operations csr_ops
;
36 static RISCVException
smode(CPURISCVState
*env
, int csrno
)
38 if (riscv_has_ext(env
, RVS
)) {
39 return RISCV_EXCP_NONE
;
42 return RISCV_EXCP_ILLEGAL_INST
;
45 static int test_thead_mvendorid(RISCVCPU
*cpu
)
47 if (cpu
->cfg
.mvendorid
!= THEAD_VENDOR_ID
) {
54 static RISCVException
read_th_sxstatus(CPURISCVState
*env
, int csrno
,
57 /* We don't set MAEE here, because QEMU does not implement MAEE. */
58 *val
= TH_SXSTATUS_UCME
| TH_SXSTATUS_THEADISAEE
;
59 return RISCV_EXCP_NONE
;
62 static riscv_csr th_csr_list
[] = {
64 .csrno
= CSR_TH_SXSTATUS
,
65 .insertion_test
= test_thead_mvendorid
,
66 .csr_ops
= { "th.sxstatus", smode
, read_th_sxstatus
}
70 void th_register_custom_csrs(RISCVCPU
*cpu
)
72 for (size_t i
= 0; i
< ARRAY_SIZE(th_csr_list
); i
++) {
73 int csrno
= th_csr_list
[i
].csrno
;
74 riscv_csr_operations
*csr_ops
= &th_csr_list
[i
].csr_ops
;
75 if (!th_csr_list
[i
].insertion_test(cpu
)) {
76 riscv_set_csr_ops(csrno
, csr_ops
);