1
The following changes since commit 15106f7dc3290ff3254611f265849a314a93eb0e:
1
The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946:
2
2
3
Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-hex-20210502' into staging (2021-05-02 16:23:05 +0100)
3
Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210504-2
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528
8
8
9
for you to fetch changes up to 7a98eab3a704139020bdad35bfae0356d2a31fa0:
9
for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393:
10
10
11
target/riscv: Fix the RV64H decode comment (2021-05-04 08:03:43 +1000)
11
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
A large collection of RISC-V fixes, improvements and features
14
RISC-V PR for 9.1
15
15
16
- Clenaup some left over v1.9 code
16
* APLICs add child earlier than realize
17
- Documentation improvements
17
* Fix exposure of Zkr
18
- Support for the shakti_c machine
18
* Raise exceptions on wrs.nto
19
- Internal cleanup of the CSR accesses
19
* Implement SBI debug console (DBCN) calls for KVM
20
- Updates to the OpenTitan platform
20
* Support 64-bit addresses for initrd
21
- Support for the virtio-vga
21
* Change RISCV_EXCP_SEMIHOST exception number to 63
22
- Fix for the saturate subtract in vector extensions
22
* Tolerate KVM disable ext errors
23
- Experimental support for the ePMP spec
23
* Set tval in breakpoints
24
- A range of other internal code cleanups and bug fixes
24
* Add support for Zve32x extension
25
* Add support for Zve64x extension
26
* Relax vector register check in RISCV gdbstub
27
* Fix the element agnostic Vector function problem
28
* Fix Zvkb extension config
29
* Implement dynamic establishment of custom decoder
30
* Add th.sxstatus CSR emulation
31
* Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
32
* Check single width operator for vector fp widen instructions
33
* Check single width operator for vfncvt.rod.f.f.w
34
* Remove redudant SEW checking for vector fp narrow/widen instructions
35
* Prioritize pmp errors in raise_mmu_exception()
36
* Do not set mtval2 for non guest-page faults
37
* Remove experimental prefix from "B" extension
38
* Fixup CBO extension register calculation
39
* Fix the hart bit setting of AIA
40
* Fix reg_width in ricsv_gen_dynamic_vector_feature()
41
* Decode all of the pmpcfg and pmpaddr CSRs
42
* Raise an exception when CSRRS/CSRRC writes a read-only CSR
25
43
26
----------------------------------------------------------------
44
----------------------------------------------------------------
27
Alexander Wagner (1):
45
Alexei Filippov (1):
28
hw/riscv: Fix OT IBEX reset vector
46
target/riscv: do not set mtval2 for non guest-page faults
29
47
30
Alistair Francis (22):
48
Alistair Francis (2):
31
target/riscv: Convert the RISC-V exceptions to an enum
49
target/riscv: rvzicbo: Fixup CBO extension register calculation
32
target/riscv: Use the RISCVException enum for CSR predicates
50
disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs
33
target/riscv: Fix 32-bit HS mode access permissions
34
target/riscv: Use the RISCVException enum for CSR operations
35
target/riscv: Use RISCVException enum for CSR access
36
MAINTAINERS: Update the RISC-V CPU Maintainers
37
hw/opentitan: Update the interrupt layout
38
hw/riscv: Enable VIRTIO_VGA for RISC-V virt machine
39
target/riscv: Fix the PMP is locked check when using TOR
40
target/riscv: Add the ePMP feature
41
target/riscv/pmp: Remove outdated comment
42
target/riscv: Add ePMP support for the Ibex CPU
43
target/riscv: Remove the hardcoded RVXLEN macro
44
target/riscv: Remove the hardcoded SSTATUS_SD macro
45
target/riscv: Remove the hardcoded HGATP_MODE macro
46
target/riscv: Remove the hardcoded MSTATUS_SD macro
47
target/riscv: Remove the hardcoded SATP_MODE macro
48
target/riscv: Remove the unused HSTATUS_WPRI macro
49
target/riscv: Remove an unused CASE_OP_32_64 macro
50
target/riscv: Consolidate RV32/64 32-bit instructions
51
target/riscv: Consolidate RV32/64 16-bit instructions
52
target/riscv: Fix the RV64H decode comment
53
51
54
Atish Patra (1):
52
Andrew Jones (2):
55
target/riscv: Remove privilege v1.9 specific CSR related code
53
target/riscv/kvm: Fix exposure of Zkr
54
target/riscv: Raise exceptions on wrs.nto
56
55
57
Axel Heider (1):
56
Cheng Yang (1):
58
docs/system/generic-loader.rst: Fix style
57
hw/riscv/boot.c: Support 64-bit address for initrd
59
58
60
Bin Meng (1):
59
Christoph Müllner (1):
61
hw/riscv: sifive_e: Add 'const' to sifive_e_memmap[]
60
riscv: thead: Add th.sxstatus CSR emulation
62
61
63
Dylan Jhong (1):
62
Clément Léger (1):
64
target/riscv: Align the data type of reset vector address
63
target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63
65
64
66
Emmanuel Blot (2):
65
Daniel Henrique Barboza (6):
67
target/riscv: fix exception index on instruction access fault
66
target/riscv/kvm: implement SBI debug console (DBCN) calls
68
target/riscv: fix a typo with interrupt names
67
target/riscv/kvm: tolerate KVM disable ext errors
68
target/riscv/debug: set tval=pc in breakpoint exceptions
69
trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint
70
target/riscv: prioritize pmp errors in raise_mmu_exception()
71
riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature()
69
72
70
Frank Chang (2):
73
Huang Tao (2):
71
target/riscv: fix vrgather macro index variable type bug
74
target/riscv: Fix the element agnostic function problem
72
fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
75
target/riscv: Implement dynamic establishment of custom decoder
73
76
74
Hou Weiying (4):
77
Jason Chien (3):
75
target/riscv: Define ePMP mseccfg
78
target/riscv: Add support for Zve32x extension
76
target/riscv: Add ePMP CSR access functions
79
target/riscv: Add support for Zve64x extension
77
target/riscv: Implementation of enhanced PMP (ePMP)
80
target/riscv: Relax vector register check in RISCV gdbstub
78
target/riscv: Add a config option for ePMP
79
81
80
Jade Fink (1):
82
Max Chou (4):
81
riscv: don't look at SUM when accessing memory from a debugger context
83
target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
84
target/riscv: rvv: Check single width operator for vector fp widen instructions
85
target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w
86
target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions
82
87
83
LIU Zhiwei (1):
88
Rob Bradford (1):
84
target/riscv: Fixup saturate subtract function
89
target/riscv: Remove experimental prefix from "B" extension
85
90
86
Vijai Kumar K (5):
91
Yangyu Chen (1):
87
target/riscv: Add Shakti C class CPU
92
target/riscv/cpu.c: fix Zvkb extension config
88
riscv: Add initial support for Shakti C machine
89
hw/char: Add Shakti UART emulation
90
hw/riscv: Connect Shakti UART to Shakti platform
91
docs: Add documentation for shakti_c machine
92
93
93
docs/system/generic-loader.rst | 9 +-
94
Yong-Xuan Wang (1):
94
docs/system/riscv/shakti-c.rst | 82 +++
95
target/riscv/kvm.c: Fix the hart bit setting of AIA
95
default-configs/devices/riscv64-softmmu.mak | 1 +
96
include/hw/char/shakti_uart.h | 74 +++
97
include/hw/riscv/opentitan.h | 16 +-
98
include/hw/riscv/shakti_c.h | 75 +++
99
target/riscv/cpu.h | 42 +-
100
target/riscv/cpu_bits.h | 114 +---
101
target/riscv/helper.h | 18 +-
102
target/riscv/pmp.h | 14 +
103
target/riscv/insn16-32.decode | 28 -
104
target/riscv/insn16-64.decode | 36 --
105
target/riscv/insn16.decode | 30 +
106
target/riscv/insn32-64.decode | 88 ---
107
target/riscv/insn32.decode | 67 ++-
108
hw/char/shakti_uart.c | 185 +++++++
109
hw/intc/ibex_plic.c | 20 +-
110
hw/riscv/opentitan.c | 10 +-
111
hw/riscv/shakti_c.c | 178 ++++++
112
hw/riscv/sifive_e.c | 2 +-
113
target/riscv/cpu.c | 26 +-
114
target/riscv/cpu_helper.c | 88 ++-
115
target/riscv/csr.c | 824 +++++++++++++++++-----------
116
target/riscv/fpu_helper.c | 16 +-
117
target/riscv/gdbstub.c | 8 +-
118
target/riscv/machine.c | 8 +-
119
target/riscv/monitor.c | 22 +-
120
target/riscv/op_helper.c | 18 +-
121
target/riscv/pmp.c | 218 +++++++-
122
target/riscv/translate.c | 38 +-
123
target/riscv/vector_helper.c | 18 +-
124
fpu/softfloat-specialize.c.inc | 6 +
125
target/riscv/insn_trans/trans_rva.c.inc | 14 +-
126
target/riscv/insn_trans/trans_rvd.c.inc | 17 +-
127
target/riscv/insn_trans/trans_rvf.c.inc | 6 +-
128
target/riscv/insn_trans/trans_rvh.c.inc | 8 +-
129
target/riscv/insn_trans/trans_rvi.c.inc | 22 +-
130
target/riscv/insn_trans/trans_rvm.c.inc | 12 +-
131
target/riscv/insn_trans/trans_rvv.c.inc | 39 +-
132
MAINTAINERS | 14 +-
133
hw/char/meson.build | 1 +
134
hw/char/trace-events | 4 +
135
hw/riscv/Kconfig | 11 +
136
hw/riscv/meson.build | 1 +
137
target/riscv/meson.build | 13 +-
138
target/riscv/trace-events | 3 +
139
46 files changed, 1755 insertions(+), 789 deletions(-)
140
create mode 100644 docs/system/riscv/shakti-c.rst
141
create mode 100644 include/hw/char/shakti_uart.h
142
create mode 100644 include/hw/riscv/shakti_c.h
143
delete mode 100644 target/riscv/insn16-32.decode
144
delete mode 100644 target/riscv/insn16-64.decode
145
delete mode 100644 target/riscv/insn32-64.decode
146
create mode 100644 hw/char/shakti_uart.c
147
create mode 100644 hw/riscv/shakti_c.c
148
96
97
Yu-Ming Chang (1):
98
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR
99
100
yang.zhang (1):
101
hw/intc/riscv_aplic: APLICs should add child earlier than realize
102
103
MAINTAINERS | 1 +
104
target/riscv/cpu.h | 11 ++
105
target/riscv/cpu_bits.h | 2 +-
106
target/riscv/cpu_cfg.h | 2 +
107
target/riscv/helper.h | 1 +
108
target/riscv/sbi_ecall_interface.h | 17 +++
109
target/riscv/tcg/tcg-cpu.h | 15 +++
110
disas/riscv.c | 65 +++++++++-
111
hw/intc/riscv_aplic.c | 8 +-
112
hw/riscv/boot.c | 4 +-
113
target/riscv/cpu.c | 10 +-
114
target/riscv/cpu_helper.c | 37 +++---
115
target/riscv/csr.c | 71 +++++++++--
116
target/riscv/debug.c | 3 +
117
target/riscv/gdbstub.c | 8 +-
118
target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++-
119
target/riscv/op_helper.c | 17 ++-
120
target/riscv/tcg/tcg-cpu.c | 50 +++++---
121
target/riscv/th_csr.c | 79 +++++++++++++
122
target/riscv/translate.c | 31 +++--
123
target/riscv/vector_internals.c | 22 ++++
124
target/riscv/insn_trans/trans_privileged.c.inc | 2 +
125
target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++---
126
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++--
127
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++-
128
target/riscv/meson.build | 1 +
129
26 files changed, 596 insertions(+), 109 deletions(-)
130
create mode 100644 target/riscv/th_csr.c
131
diff view generated by jsdifflib
1
The RISC-V spec says:
1
From: "yang.zhang" <yang.zhang@hexintek.com>
2
if PMP entry i is locked and pmpicfg.A is set to TOR, writes to
3
pmpaddri-1 are ignored.
4
2
5
The current QEMU code ignores accesses to pmpaddri-1 and pmpcfgi-1 which
3
Since only root APLICs can have hw IRQ lines, aplic->parent should
6
is incorrect.
4
be initialized first.
7
5
8
Update the pmp_is_locked() function to not check the supporting fields
6
Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation")
9
and instead enforce the lock functionality in the pmpaddr write operation.
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Message-ID: <20240409014445.278-1-gaoshanliukou@163.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
hw/intc/riscv_aplic.c | 8 ++++----
14
1 file changed, 4 insertions(+), 4 deletions(-)
10
15
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
12
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
13
Message-id: 2831241458163f445a89bd59c59990247265b0c6.1618812899.git.alistair.francis@wdc.com
14
---
15
target/riscv/pmp.c | 26 ++++++++++++++++----------
16
1 file changed, 16 insertions(+), 10 deletions(-)
17
18
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/pmp.c
18
--- a/hw/intc/riscv_aplic.c
21
+++ b/target/riscv/pmp.c
19
+++ b/hw/intc/riscv_aplic.c
22
@@ -XXX,XX +XXX,XX @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index)
20
@@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
23
return 0;
21
qdev_prop_set_bit(dev, "msimode", msimode);
22
qdev_prop_set_bit(dev, "mmode", mmode);
23
24
+ if (parent) {
25
+ riscv_aplic_add_child(parent, dev);
26
+ }
27
+
28
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
29
30
if (!is_kvm_aia(msimode)) {
31
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
24
}
32
}
25
33
26
- /* In TOR mode, need to check the lock bit of the next pmp
34
- if (parent) {
27
- * (if there is a next)
35
- riscv_aplic_add_child(parent, dev);
28
- */
29
- const uint8_t a_field =
30
- pmp_get_a_field(env->pmp_state.pmp[pmp_index + 1].cfg_reg);
31
- if ((env->pmp_state.pmp[pmp_index + 1u].cfg_reg & PMP_LOCK) &&
32
- (PMP_AMATCH_TOR == a_field)) {
33
- return 1;
34
- }
36
- }
35
-
37
-
36
return 0;
38
if (!msimode) {
37
}
39
for (i = 0; i < num_harts; i++) {
38
40
CPUState *cpu = cpu_by_arch_id(hartid_base + i);
39
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
40
target_ulong val)
41
{
42
trace_pmpaddr_csr_write(env->mhartid, addr_index, val);
43
+
44
if (addr_index < MAX_RISCV_PMPS) {
45
+ /*
46
+ * In TOR mode, need to check the lock bit of the next pmp
47
+ * (if there is a next).
48
+ */
49
+ if (addr_index + 1 < MAX_RISCV_PMPS) {
50
+ uint8_t pmp_cfg = env->pmp_state.pmp[addr_index + 1].cfg_reg;
51
+
52
+ if (pmp_cfg & PMP_LOCK &&
53
+ PMP_AMATCH_TOR == pmp_get_a_field(pmp_cfg)) {
54
+ qemu_log_mask(LOG_GUEST_ERROR,
55
+ "ignoring pmpaddr write - pmpcfg + 1 locked\n");
56
+ return;
57
+ }
58
+ }
59
+
60
if (!pmp_is_locked(env, addr_index)) {
61
env->pmp_state.pmp[addr_index].addr_reg = val;
62
pmp_update_rule(env, addr_index);
63
--
41
--
64
2.31.1
42
2.45.1
65
66
diff view generated by jsdifflib
1
From: Hou Weiying <weiying_hou@outlook.com>
1
From: Andrew Jones <ajones@ventanamicro.com>
2
2
3
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
3
The Zkr extension may only be exposed to KVM guests if the VMM
4
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
4
implements the SEED CSR. Use the same implementation as TCG.
5
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
5
6
Without this patch, running with a KVM which does not forward the
7
SEED CSR access to QEMU will result in an ILL exception being
8
injected into the guest (this results in Linux guests crashing on
9
boot). And, when running with a KVM which does forward the access,
10
QEMU will crash, since QEMU doesn't know what to do with the exit.
11
12
Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8")
13
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Cc: qemu-stable <qemu-stable@nongnu.org>
16
Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 270762cb2507fba6a9eeb99a774cf49f7da9cc32.1618812899.git.alistair.francis@wdc.com
9
[ Changes by AF:
10
- Rebase on master
11
- Fix build errors
12
- Fix some style issues
13
]
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
16
---
18
---
17
target/riscv/cpu.h | 1 +
19
target/riscv/cpu.h | 3 +++
18
target/riscv/pmp.h | 14 ++++++++++++++
20
target/riscv/csr.c | 18 ++++++++++++++----
19
target/riscv/csr.c | 24 ++++++++++++++++++++++++
21
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++
20
target/riscv/pmp.c | 34 ++++++++++++++++++++++++++++++++++
22
3 files changed, 42 insertions(+), 4 deletions(-)
21
target/riscv/trace-events | 3 +++
22
5 files changed, 76 insertions(+)
23
23
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
25
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.h
26
--- a/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
29
29
30
/* physical memory protection */
30
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
31
pmp_table_t pmp_state;
31
32
+ target_ulong mseccfg;
32
+target_ulong riscv_new_csr_seed(target_ulong new_value,
33
33
+ target_ulong write_mask);
34
/* machine specific rdtime callback */
35
uint64_t (*rdtime_fn)(uint32_t);
36
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/pmp.h
39
+++ b/target/riscv/pmp.h
40
@@ -XXX,XX +XXX,XX @@ typedef enum {
41
PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */
42
} pmp_am_t;
43
44
+typedef enum {
45
+ MSECCFG_MML = 1 << 0,
46
+ MSECCFG_MMWP = 1 << 1,
47
+ MSECCFG_RLB = 1 << 2
48
+} mseccfg_field_t;
49
+
34
+
50
typedef struct {
35
uint8_t satp_mode_max_from_map(uint32_t map);
51
target_ulong addr_reg;
36
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
52
uint8_t cfg_reg;
37
53
@@ -XXX,XX +XXX,XX @@ typedef struct {
54
void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
55
target_ulong val);
56
target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index);
57
+
58
+void mseccfg_csr_write(CPURISCVState *env, target_ulong val);
59
+target_ulong mseccfg_csr_read(CPURISCVState *env);
60
+
61
void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
62
target_ulong val);
63
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
64
@@ -XXX,XX +XXX,XX @@ void pmp_update_rule_nums(CPURISCVState *env);
65
uint32_t pmp_get_num_rules(CPURISCVState *env);
66
int pmp_priv_to_page_prot(pmp_priv_t pmp_priv);
67
68
+#define MSECCFG_MML_ISSET(env) get_field(env->mseccfg, MSECCFG_MML)
69
+#define MSECCFG_MMWP_ISSET(env) get_field(env->mseccfg, MSECCFG_MMWP)
70
+#define MSECCFG_RLB_ISSET(env) get_field(env->mseccfg, MSECCFG_RLB)
71
+
72
#endif
73
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
38
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
74
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
75
--- a/target/riscv/csr.c
40
--- a/target/riscv/csr.c
76
+++ b/target/riscv/csr.c
41
+++ b/target/riscv/csr.c
77
@@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno)
42
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
78
43
#endif
79
return RISCV_EXCP_ILLEGAL_INST;
44
45
/* Crypto Extension */
46
-static RISCVException rmw_seed(CPURISCVState *env, int csrno,
47
- target_ulong *ret_value,
48
- target_ulong new_value,
49
- target_ulong write_mask)
50
+target_ulong riscv_new_csr_seed(target_ulong new_value,
51
+ target_ulong write_mask)
52
{
53
uint16_t random_v;
54
Error *random_e = NULL;
55
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
56
rval = random_v | SEED_OPST_ES16;
57
}
58
59
+ return rval;
60
+}
61
+
62
+static RISCVException rmw_seed(CPURISCVState *env, int csrno,
63
+ target_ulong *ret_value,
64
+ target_ulong new_value,
65
+ target_ulong write_mask)
66
+{
67
+ target_ulong rval;
68
+
69
+ rval = riscv_new_csr_seed(new_value, write_mask);
70
+
71
if (ret_value) {
72
*ret_value = rval;
73
}
74
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
75
index XXXXXXX..XXXXXXX 100644
76
--- a/target/riscv/kvm/kvm-cpu.c
77
+++ b/target/riscv/kvm/kvm-cpu.c
78
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
79
return ret;
80
}
80
}
81
82
+static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run)
83
+{
84
+ target_ulong csr_num = run->riscv_csr.csr_num;
85
+ target_ulong new_value = run->riscv_csr.new_value;
86
+ target_ulong write_mask = run->riscv_csr.write_mask;
87
+ int ret = 0;
81
+
88
+
82
+static RISCVException epmp(CPURISCVState *env, int csrno)
89
+ switch (csr_num) {
83
+{
90
+ case CSR_SEED:
84
+ if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) {
91
+ run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask);
85
+ return RISCV_EXCP_NONE;
92
+ break;
93
+ default:
94
+ qemu_log_mask(LOG_UNIMP,
95
+ "%s: un-handled CSR EXIT for CSR %lx\n",
96
+ __func__, csr_num);
97
+ ret = -1;
98
+ break;
86
+ }
99
+ }
87
+
100
+
88
+ return RISCV_EXCP_ILLEGAL_INST;
101
+ return ret;
89
+}
90
#endif
91
92
/* User Floating-Point CSRs */
93
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mtinst(CPURISCVState *env, int csrno,
94
}
95
96
/* Physical Memory Protection */
97
+static RISCVException read_mseccfg(CPURISCVState *env, int csrno,
98
+ target_ulong *val)
99
+{
100
+ *val = mseccfg_csr_read(env);
101
+ return RISCV_EXCP_NONE;
102
+}
102
+}
103
+
103
+
104
+static RISCVException write_mseccfg(CPURISCVState *env, int csrno,
104
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
105
+ target_ulong val)
106
+{
107
+ mseccfg_csr_write(env, val);
108
+ return RISCV_EXCP_NONE;
109
+}
110
+
111
static RISCVException read_pmpcfg(CPURISCVState *env, int csrno,
112
target_ulong *val)
113
{
105
{
114
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
106
int ret = 0;
115
[CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst },
107
@@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
116
108
case KVM_EXIT_RISCV_SBI:
117
/* Physical Memory Protection */
109
ret = kvm_riscv_handle_sbi(cs, run);
118
+ [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg },
110
break;
119
[CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg },
111
+ case KVM_EXIT_RISCV_CSR:
120
[CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },
112
+ ret = kvm_riscv_handle_csr(cs, run);
121
[CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg },
113
+ break;
122
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
114
default:
123
index XXXXXXX..XXXXXXX 100644
115
qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
124
--- a/target/riscv/pmp.c
116
__func__, run->exit_reason);
125
+++ b/target/riscv/pmp.c
126
@@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index)
127
return val;
128
}
129
130
+/*
131
+ * Handle a write to a mseccfg CSR
132
+ */
133
+void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
134
+{
135
+ int i;
136
+
137
+ trace_mseccfg_csr_write(env->mhartid, val);
138
+
139
+ /* RLB cannot be enabled if it's already 0 and if any regions are locked */
140
+ if (!MSECCFG_RLB_ISSET(env)) {
141
+ for (i = 0; i < MAX_RISCV_PMPS; i++) {
142
+ if (pmp_is_locked(env, i)) {
143
+ val &= ~MSECCFG_RLB;
144
+ break;
145
+ }
146
+ }
147
+ }
148
+
149
+ /* Sticky bits */
150
+ val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML));
151
+
152
+ env->mseccfg = val;
153
+}
154
+
155
+/*
156
+ * Handle a read from a mseccfg CSR
157
+ */
158
+target_ulong mseccfg_csr_read(CPURISCVState *env)
159
+{
160
+ trace_mseccfg_csr_read(env->mhartid, env->mseccfg);
161
+ return env->mseccfg;
162
+}
163
+
164
/*
165
* Calculate the TLB size if the start address or the end address of
166
* PMP entry is presented in thie TLB page.
167
diff --git a/target/riscv/trace-events b/target/riscv/trace-events
168
index XXXXXXX..XXXXXXX 100644
169
--- a/target/riscv/trace-events
170
+++ b/target/riscv/trace-events
171
@@ -XXX,XX +XXX,XX @@ pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRI
172
pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64
173
pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64
174
pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64
175
+
176
+mseccfg_csr_read(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": read mseccfg, val: 0x%" PRIx64
177
+mseccfg_csr_write(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": write mseccfg, val: 0x%" PRIx64
178
--
117
--
179
2.31.1
118
2.45.1
180
181
diff view generated by jsdifflib
1
This patch removes the insn16-32.decode and insn16-64.decode decode
1
From: Andrew Jones <ajones@ventanamicro.com>
2
files and consolidates the instructions into the general RISC-V
3
insn16.decode decode tree.
4
2
5
This means that all of the instructions are avaliable in both the 32-bit
3
Implementing wrs.nto to always just return is consistent with the
6
and 64-bit builds. This also means that we run a check to ensure we are
4
specification, as the instruction is permitted to terminate the
7
running a 64-bit softmmu before we execute the 64-bit only instructions.
5
stall for any reason, but it's not useful for virtualization, where
8
This allows us to include the 32-bit instructions in the 64-bit build,
6
we'd like the guest to trap to the hypervisor in order to allow
9
while also ensuring that 32-bit only software can not execute the
7
scheduling of the lock holding VCPU. Change to always immediately
10
instructions.
8
raise exceptions when the appropriate conditions are present,
9
otherwise continue to just return. Note, immediately raising
10
exceptions is also consistent with the specification since the
11
time limit that should expire prior to the exception is
12
implementation-specific.
11
13
14
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
15
Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 01e2b0efeae311adc7ebf133c2cde6a7a37224d7.1619234854.git.alistair.francis@wdc.com
15
---
20
---
16
target/riscv/insn16-32.decode | 28 -------------------
21
target/riscv/helper.h | 1 +
17
target/riscv/insn16-64.decode | 36 -------------------------
22
target/riscv/op_helper.c | 11 ++++++++
18
target/riscv/insn16.decode | 30 +++++++++++++++++++++
23
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++-------
19
target/riscv/insn_trans/trans_rvi.c.inc | 6 +++++
24
3 files changed, 32 insertions(+), 9 deletions(-)
20
target/riscv/meson.build | 11 +++-----
21
5 files changed, 39 insertions(+), 72 deletions(-)
22
delete mode 100644 target/riscv/insn16-32.decode
23
delete mode 100644 target/riscv/insn16-64.decode
24
25
25
diff --git a/target/riscv/insn16-32.decode b/target/riscv/insn16-32.decode
26
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
26
deleted file mode 100644
27
index XXXXXXX..XXXXXXX
28
--- a/target/riscv/insn16-32.decode
29
+++ /dev/null
30
@@ -XXX,XX +XXX,XX @@
31
-#
32
-# RISC-V translation routines for the RVXI Base Integer Instruction Set.
33
-#
34
-# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
35
-# Bastian Koppelmann, kbastian@mail.uni-paderborn.de
36
-#
37
-# This program is free software; you can redistribute it and/or modify it
38
-# under the terms and conditions of the GNU General Public License,
39
-# version 2 or later, as published by the Free Software Foundation.
40
-#
41
-# This program is distributed in the hope it will be useful, but WITHOUT
42
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
44
-# more details.
45
-#
46
-# You should have received a copy of the GNU General Public License along with
47
-# this program. If not, see <http://www.gnu.org/licenses/>.
48
-
49
-# *** RV32C Standard Extension (Quadrant 0) ***
50
-flw 011 ... ... .. ... 00 @cl_w
51
-fsw 111 ... ... .. ... 00 @cs_w
52
-
53
-# *** RV32C Standard Extension (Quadrant 1) ***
54
-jal 001 ........... 01 @cj rd=1 # C.JAL
55
-
56
-# *** RV32C Standard Extension (Quadrant 2) ***
57
-flw 011 . ..... ..... 10 @c_lwsp
58
-fsw 111 . ..... ..... 10 @c_swsp
59
diff --git a/target/riscv/insn16-64.decode b/target/riscv/insn16-64.decode
60
deleted file mode 100644
61
index XXXXXXX..XXXXXXX
62
--- a/target/riscv/insn16-64.decode
63
+++ /dev/null
64
@@ -XXX,XX +XXX,XX @@
65
-#
66
-# RISC-V translation routines for the RVXI Base Integer Instruction Set.
67
-#
68
-# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
69
-# Bastian Koppelmann, kbastian@mail.uni-paderborn.de
70
-#
71
-# This program is free software; you can redistribute it and/or modify it
72
-# under the terms and conditions of the GNU General Public License,
73
-# version 2 or later, as published by the Free Software Foundation.
74
-#
75
-# This program is distributed in the hope it will be useful, but WITHOUT
76
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
78
-# more details.
79
-#
80
-# You should have received a copy of the GNU General Public License along with
81
-# this program. If not, see <http://www.gnu.org/licenses/>.
82
-
83
-# *** RV64C Standard Extension (Quadrant 0) ***
84
-ld 011 ... ... .. ... 00 @cl_d
85
-sd 111 ... ... .. ... 00 @cs_d
86
-
87
-# *** RV64C Standard Extension (Quadrant 1) ***
88
-{
89
- illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0
90
- addiw 001 . ..... ..... 01 @ci
91
-}
92
-subw 100 1 11 ... 00 ... 01 @cs_2
93
-addw 100 1 11 ... 01 ... 01 @cs_2
94
-
95
-# *** RV64C Standard Extension (Quadrant 2) ***
96
-{
97
- illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0
98
- ld 011 . ..... ..... 10 @c_ldsp
99
-}
100
-sd 111 . ..... ..... 10 @c_sdsp
101
diff --git a/target/riscv/insn16.decode b/target/riscv/insn16.decode
102
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
103
--- a/target/riscv/insn16.decode
28
--- a/target/riscv/helper.h
104
+++ b/target/riscv/insn16.decode
29
+++ b/target/riscv/helper.h
105
@@ -XXX,XX +XXX,XX @@ lw 010 ... ... .. ... 00 @cl_w
30
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
106
fsd 101 ... ... .. ... 00 @cs_d
31
DEF_HELPER_1(sret, tl, env)
107
sw 110 ... ... .. ... 00 @cs_w
32
DEF_HELPER_1(mret, tl, env)
108
33
DEF_HELPER_1(wfi, void, env)
109
+# *** RV32C and RV64C specific Standard Extension (Quadrant 0) ***
34
+DEF_HELPER_1(wrs_nto, void, env)
35
DEF_HELPER_1(tlb_flush, void, env)
36
DEF_HELPER_1(tlb_flush_all, void, env)
37
/* Native Debug */
38
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/op_helper.c
41
+++ b/target/riscv/op_helper.c
42
@@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env)
43
}
44
}
45
46
+void helper_wrs_nto(CPURISCVState *env)
110
+{
47
+{
111
+ ld 011 ... ... .. ... 00 @cl_d
48
+ if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) &&
112
+ flw 011 ... ... .. ... 00 @cl_w
49
+ get_field(env->hstatus, HSTATUS_VTW) &&
113
+}
50
+ !get_field(env->mstatus, MSTATUS_TW)) {
114
+{
51
+ riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC());
115
+ sd 111 ... ... .. ... 00 @cs_d
52
+ } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) {
116
+ fsw 111 ... ... .. ... 00 @cs_w
53
+ riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
54
+ }
117
+}
55
+}
118
+
56
+
119
# *** RV32/64C Standard Extension (Quadrant 1) ***
57
void helper_tlb_flush(CPURISCVState *env)
120
addi 000 . ..... ..... 01 @ci
58
{
121
addi 010 . ..... ..... 01 @c_li
59
CPUState *cs = env_cpu(env);
122
@@ -XXX,XX +XXX,XX @@ jal 101 ........... 01 @cj rd=0 # C.J
60
diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc
123
beq 110 ... ... ..... 01 @cb_z
124
bne 111 ... ... ..... 01 @cb_z
125
126
+# *** RV64C and RV32C specific Standard Extension (Quadrant 1) ***
127
+{
128
+ c64_illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0
129
+ addiw 001 . ..... ..... 01 @ci
130
+ jal 001 ........... 01 @cj rd=1 # C.JAL
131
+}
132
+subw 100 1 11 ... 00 ... 01 @cs_2
133
+addw 100 1 11 ... 01 ... 01 @cs_2
134
+
135
# *** RV32/64C Standard Extension (Quadrant 2) ***
136
slli 000 . ..... ..... 10 @c_shift2
137
fld 001 . ..... ..... 10 @c_ldsp
138
@@ -XXX,XX +XXX,XX @@ fld 001 . ..... ..... 10 @c_ldsp
139
}
140
fsd 101 ...... ..... 10 @c_sdsp
141
sw 110 . ..... ..... 10 @c_swsp
142
+
143
+# *** RV32C and RV64C specific Standard Extension (Quadrant 2) ***
144
+{
145
+ c64_illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0
146
+ ld 011 . ..... ..... 10 @c_ldsp
147
+ flw 011 . ..... ..... 10 @c_lwsp
148
+}
149
+{
150
+ sd 111 . ..... ..... 10 @c_sdsp
151
+ fsw 111 . ..... ..... 10 @c_swsp
152
+}
153
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
154
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
155
--- a/target/riscv/insn_trans/trans_rvi.c.inc
62
--- a/target/riscv/insn_trans/trans_rvzawrs.c.inc
156
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
63
+++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc
157
@@ -XXX,XX +XXX,XX @@ static bool trans_illegal(DisasContext *ctx, arg_empty *a)
64
@@ -XXX,XX +XXX,XX @@
65
* this program. If not, see <http://www.gnu.org/licenses/>.
66
*/
67
68
-static bool trans_wrs(DisasContext *ctx)
69
+static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a)
70
{
71
if (!ctx->cfg_ptr->ext_zawrs) {
72
return false;
73
@@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx)
158
return true;
74
return true;
159
}
75
}
160
76
161
+static bool trans_c64_illegal(DisasContext *ctx, arg_empty *a)
77
-#define GEN_TRANS_WRS(insn) \
78
-static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \
79
-{ \
80
- (void)a; \
81
- return trans_wrs(ctx); \
82
-}
83
+static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a)
162
+{
84
+{
163
+ REQUIRE_64BIT(ctx);
85
+ if (!ctx->cfg_ptr->ext_zawrs) {
164
+ return trans_illegal(ctx, a);
86
+ return false;
87
+ }
88
89
-GEN_TRANS_WRS(wrs_nto)
90
-GEN_TRANS_WRS(wrs_sto)
91
+ /*
92
+ * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto
93
+ * should raise an exception when the implementation-specific bounded time
94
+ * limit has expired. Our time limit is zero, so we either return
95
+ * immediately, as does our implementation of wrs.sto, or raise an
96
+ * exception, as handled by the wrs.nto helper.
97
+ */
98
+#ifndef CONFIG_USER_ONLY
99
+ gen_helper_wrs_nto(tcg_env);
100
+#endif
101
+
102
+ /* We only get here when helper_wrs_nto() doesn't raise an exception. */
103
+ return trans_wrs_sto(ctx, NULL);
165
+}
104
+}
166
+
167
static bool trans_lui(DisasContext *ctx, arg_lui *a)
168
{
169
if (a->rd != 0) {
170
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
171
index XXXXXXX..XXXXXXX 100644
172
--- a/target/riscv/meson.build
173
+++ b/target/riscv/meson.build
174
@@ -XXX,XX +XXX,XX @@
175
# FIXME extra_args should accept files()
176
dir = meson.current_source_dir()
177
-gen32 = [
178
- decodetree.process('insn16.decode', extra_args: [dir / 'insn16-32.decode', '--static-decode=decode_insn16', '--insnwidth=16']),
179
- decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'),
180
-]
181
182
-gen64 = [
183
- decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']),
184
+gen = [
185
+ decodetree.process('insn16.decode', extra_args: ['--static-decode=decode_insn16', '--insnwidth=16']),
186
decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'),
187
]
188
189
riscv_ss = ss.source_set()
190
-riscv_ss.add(when: 'TARGET_RISCV32', if_true: gen32)
191
-riscv_ss.add(when: 'TARGET_RISCV64', if_true: gen64)
192
+riscv_ss.add(gen)
193
riscv_ss.add(files(
194
'cpu.c',
195
'cpu_helper.c',
196
--
105
--
197
2.31.1
106
2.45.1
198
107
199
108
diff view generated by jsdifflib
1
From: Vijai Kumar K <vijai@behindbytes.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
This is the initial implementation of Shakti UART.
3
SBI defines a Debug Console extension "DBCN" that will, in time, replace
4
4
the legacy console putchar and getchar SBI extensions.
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
5
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
The appeal of the DBCN extension is that it allows multiple bytes to be
7
Message-id: 20210401181457.73039-4-vijai@behindbytes.com
7
read/written in the SBI console in a single SBI call.
8
9
As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM
10
module to userspace. But this will only happens if the KVM module
11
actually supports this SBI extension and we activate it.
12
13
We'll check for DBCN support during init time, checking if get-reg-list
14
is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via
15
kvm_set_one_reg() during kvm_arch_init_vcpu().
16
17
Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for
18
SBI_EXT_DBCN, reading and writing as required.
19
20
A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V
21
host, takes around 20 seconds to boot without using DBCN. With this
22
patch we're taking around 14 seconds to boot due to the speed-up in the
23
terminal output. There's no change in boot time if the guest isn't
24
using earlycon.
25
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
28
Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
30
---
10
include/hw/char/shakti_uart.h | 74 ++++++++++++++
31
target/riscv/sbi_ecall_interface.h | 17 +++++
11
hw/char/shakti_uart.c | 185 ++++++++++++++++++++++++++++++++++
32
target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++
12
MAINTAINERS | 2 +
33
2 files changed, 128 insertions(+)
13
hw/char/meson.build | 1 +
34
14
hw/char/trace-events | 4 +
35
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
15
5 files changed, 266 insertions(+)
36
index XXXXXXX..XXXXXXX 100644
16
create mode 100644 include/hw/char/shakti_uart.h
37
--- a/target/riscv/sbi_ecall_interface.h
17
create mode 100644 hw/char/shakti_uart.c
38
+++ b/target/riscv/sbi_ecall_interface.h
18
19
diff --git a/include/hw/char/shakti_uart.h b/include/hw/char/shakti_uart.h
20
new file mode 100644
21
index XXXXXXX..XXXXXXX
22
--- /dev/null
23
+++ b/include/hw/char/shakti_uart.h
24
@@ -XXX,XX +XXX,XX @@
39
@@ -XXX,XX +XXX,XX @@
25
+/*
40
26
+ * SHAKTI UART
41
/* clang-format off */
27
+ *
42
28
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
43
+#define SBI_SUCCESS 0
29
+ *
44
+#define SBI_ERR_FAILED -1
30
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
45
+#define SBI_ERR_NOT_SUPPORTED -2
31
+ * of this software and associated documentation files (the "Software"), to deal
46
+#define SBI_ERR_INVALID_PARAM -3
32
+ * in the Software without restriction, including without limitation the rights
47
+#define SBI_ERR_DENIED -4
33
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+#define SBI_ERR_INVALID_ADDRESS -5
34
+ * copies of the Software, and to permit persons to whom the Software is
49
+#define SBI_ERR_ALREADY_AVAILABLE -6
35
+ * furnished to do so, subject to the following conditions:
50
+#define SBI_ERR_ALREADY_STARTED -7
36
+ *
51
+#define SBI_ERR_ALREADY_STOPPED -8
37
+ * The above copyright notice and this permission notice shall be included in
52
+#define SBI_ERR_NO_SHMEM -9
38
+ * all copies or substantial portions of the Software.
53
+
39
+ *
54
/* SBI Extension IDs */
40
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
#define SBI_EXT_0_1_SET_TIMER 0x0
41
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
42
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46
+ * THE SOFTWARE.
47
+ */
48
+
49
+#ifndef HW_SHAKTI_UART_H
50
+#define HW_SHAKTI_UART_H
51
+
52
+#include "hw/sysbus.h"
53
+#include "chardev/char-fe.h"
54
+
55
+#define SHAKTI_UART_BAUD 0x00
56
+#define SHAKTI_UART_TX 0x04
57
+#define SHAKTI_UART_RX 0x08
58
+#define SHAKTI_UART_STATUS 0x0C
59
+#define SHAKTI_UART_DELAY 0x10
60
+#define SHAKTI_UART_CONTROL 0x14
61
+#define SHAKTI_UART_INT_EN 0x18
62
+#define SHAKTI_UART_IQ_CYCLES 0x1C
63
+#define SHAKTI_UART_RX_THRES 0x20
64
+
65
+#define SHAKTI_UART_STATUS_TX_EMPTY (1 << 0)
66
+#define SHAKTI_UART_STATUS_TX_FULL (1 << 1)
67
+#define SHAKTI_UART_STATUS_RX_NOT_EMPTY (1 << 2)
68
+#define SHAKTI_UART_STATUS_RX_FULL (1 << 3)
69
+/* 9600 8N1 is the default setting */
70
+/* Reg value = (50000000 Hz)/(16 * 9600)*/
71
+#define SHAKTI_UART_BAUD_DEFAULT 0x0145
72
+#define SHAKTI_UART_CONTROL_DEFAULT 0x0100
73
+
74
+#define TYPE_SHAKTI_UART "shakti-uart"
75
+#define SHAKTI_UART(obj) \
76
+ OBJECT_CHECK(ShaktiUartState, (obj), TYPE_SHAKTI_UART)
77
+
78
+typedef struct {
79
+ /* <private> */
80
+ SysBusDevice parent_obj;
81
+
82
+ /* <public> */
83
+ MemoryRegion mmio;
84
+
85
+ uint32_t uart_baud;
86
+ uint32_t uart_tx;
87
+ uint32_t uart_rx;
88
+ uint32_t uart_status;
89
+ uint32_t uart_delay;
90
+ uint32_t uart_control;
91
+ uint32_t uart_interrupt;
92
+ uint32_t uart_iq_cycles;
93
+ uint32_t uart_rx_threshold;
94
+
95
+ CharBackend chr;
96
+} ShaktiUartState;
97
+
98
+#endif /* HW_SHAKTI_UART_H */
99
diff --git a/hw/char/shakti_uart.c b/hw/char/shakti_uart.c
100
new file mode 100644
101
index XXXXXXX..XXXXXXX
102
--- /dev/null
103
+++ b/hw/char/shakti_uart.c
104
@@ -XXX,XX +XXX,XX @@
57
@@ -XXX,XX +XXX,XX @@
105
+/*
58
#define SBI_EXT_IPI 0x735049
106
+ * SHAKTI UART
59
#define SBI_EXT_RFENCE 0x52464E43
107
+ *
60
#define SBI_EXT_HSM 0x48534D
108
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
61
+#define SBI_EXT_DBCN 0x4442434E
109
+ *
62
110
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
63
/* SBI function IDs for BASE extension */
111
+ * of this software and associated documentation files (the "Software"), to deal
64
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
112
+ * in the Software without restriction, including without limitation the rights
65
@@ -XXX,XX +XXX,XX @@
113
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66
#define SBI_EXT_HSM_HART_STOP 0x1
114
+ * copies of the Software, and to permit persons to whom the Software is
67
#define SBI_EXT_HSM_HART_GET_STATUS 0x2
115
+ * furnished to do so, subject to the following conditions:
68
116
+ *
69
+/* SBI function IDs for DBCN extension */
117
+ * The above copyright notice and this permission notice shall be included in
70
+#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0
118
+ * all copies or substantial portions of the Software.
71
+#define SBI_EXT_DBCN_CONSOLE_READ 0x1
119
+ *
72
+#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2
120
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73
+
121
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74
#define SBI_HSM_HART_STATUS_STARTED 0x0
122
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
75
#define SBI_HSM_HART_STATUS_STOPPED 0x1
123
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76
#define SBI_HSM_HART_STATUS_START_PENDING 0x2
124
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
125
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
78
index XXXXXXX..XXXXXXX 100644
126
+ * THE SOFTWARE.
79
--- a/target/riscv/kvm/kvm-cpu.c
127
+ */
80
+++ b/target/riscv/kvm/kvm-cpu.c
128
+
81
@@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = {
129
+#include "qemu/osdep.h"
82
KVM_REG_RISCV_VECTOR_CSR_REG(vlenb)
130
+#include "hw/char/shakti_uart.h"
83
};
131
+#include "hw/qdev-properties.h"
84
132
+#include "hw/qdev-properties-system.h"
85
+static KVMCPUConfig kvm_sbi_dbcn = {
133
+#include "qemu/log.h"
86
+ .name = "sbi_dbcn",
134
+
87
+ .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 |
135
+static uint64_t shakti_uart_read(void *opaque, hwaddr addr, unsigned size)
88
+ KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN
89
+};
90
+
91
static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
92
{
93
CPURISCVState *env = &cpu->env;
94
@@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b)
95
return 0;
96
}
97
98
+static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu,
99
+ KVMScratchCPU *kvmcpu,
100
+ struct kvm_reg_list *reglist)
136
+{
101
+{
137
+ ShaktiUartState *s = opaque;
102
+ struct kvm_reg_list *reg_search;
138
+
103
+
139
+ switch (addr) {
104
+ reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n,
140
+ case SHAKTI_UART_BAUD:
105
+ sizeof(uint64_t), uint64_cmp);
141
+ return s->uart_baud;
106
+
142
+ case SHAKTI_UART_RX:
107
+ if (reg_search) {
143
+ qemu_chr_fe_accept_input(&s->chr);
108
+ kvm_sbi_dbcn.supported = true;
144
+ s->uart_status &= ~SHAKTI_UART_STATUS_RX_NOT_EMPTY;
145
+ return s->uart_rx;
146
+ case SHAKTI_UART_STATUS:
147
+ return s->uart_status;
148
+ case SHAKTI_UART_DELAY:
149
+ return s->uart_delay;
150
+ case SHAKTI_UART_CONTROL:
151
+ return s->uart_control;
152
+ case SHAKTI_UART_INT_EN:
153
+ return s->uart_interrupt;
154
+ case SHAKTI_UART_IQ_CYCLES:
155
+ return s->uart_iq_cycles;
156
+ case SHAKTI_UART_RX_THRES:
157
+ return s->uart_rx_threshold;
158
+ default:
159
+ /* Also handles TX REG which is write only */
160
+ qemu_log_mask(LOG_GUEST_ERROR,
161
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
162
+ }
109
+ }
163
+
164
+ return 0;
165
+}
110
+}
166
+
111
+
167
+static void shakti_uart_write(void *opaque, hwaddr addr,
112
static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
168
+ uint64_t data, unsigned size)
113
struct kvm_reg_list *reglist)
114
{
115
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
116
if (riscv_has_ext(&cpu->env, RVV)) {
117
kvm_riscv_read_vlenb(cpu, kvmcpu, reglist);
118
}
119
+
120
+ kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist);
121
}
122
123
static void riscv_init_kvm_registers(Object *cpu_obj)
124
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
125
return ret;
126
}
127
128
+static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs)
169
+{
129
+{
170
+ ShaktiUartState *s = opaque;
130
+ target_ulong reg = 1;
171
+ uint32_t value = data;
131
+
172
+ uint8_t ch;
132
+ if (!kvm_sbi_dbcn.supported) {
173
+
133
+ return 0;
174
+ switch (addr) {
134
+ }
175
+ case SHAKTI_UART_BAUD:
135
+
176
+ s->uart_baud = value;
136
+ return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, &reg);
137
+}
138
+
139
int kvm_arch_init_vcpu(CPUState *cs)
140
{
141
int ret = 0;
142
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
143
kvm_riscv_update_cpu_misa_ext(cpu, cs);
144
kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs);
145
146
+ ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs);
147
+
148
return ret;
149
}
150
151
@@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
152
return true;
153
}
154
155
+static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run)
156
+{
157
+ g_autofree uint8_t *buf = NULL;
158
+ RISCVCPU *cpu = RISCV_CPU(cs);
159
+ target_ulong num_bytes;
160
+ uint64_t addr;
161
+ unsigned char ch;
162
+ int ret;
163
+
164
+ switch (run->riscv_sbi.function_id) {
165
+ case SBI_EXT_DBCN_CONSOLE_READ:
166
+ case SBI_EXT_DBCN_CONSOLE_WRITE:
167
+ num_bytes = run->riscv_sbi.args[0];
168
+
169
+ if (num_bytes == 0) {
170
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
171
+ run->riscv_sbi.ret[1] = 0;
172
+ break;
173
+ }
174
+
175
+ addr = run->riscv_sbi.args[1];
176
+
177
+ /*
178
+ * Handle the case where a 32 bit CPU is running in a
179
+ * 64 bit addressing env.
180
+ */
181
+ if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) {
182
+ addr |= (uint64_t)run->riscv_sbi.args[2] << 32;
183
+ }
184
+
185
+ buf = g_malloc0(num_bytes);
186
+
187
+ if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) {
188
+ ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes);
189
+ if (ret < 0) {
190
+ error_report("SBI_EXT_DBCN_CONSOLE_READ: error when "
191
+ "reading chardev");
192
+ exit(1);
193
+ }
194
+
195
+ cpu_physical_memory_write(addr, buf, ret);
196
+ } else {
197
+ cpu_physical_memory_read(addr, buf, num_bytes);
198
+
199
+ ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes);
200
+ if (ret < 0) {
201
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when "
202
+ "writing chardev");
203
+ exit(1);
204
+ }
205
+ }
206
+
207
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
208
+ run->riscv_sbi.ret[1] = ret;
177
+ break;
209
+ break;
178
+ case SHAKTI_UART_TX:
210
+ case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
179
+ ch = value;
211
+ ch = run->riscv_sbi.args[0];
180
+ qemu_chr_fe_write_all(&s->chr, &ch, 1);
212
+ ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch));
181
+ s->uart_status &= ~SHAKTI_UART_STATUS_TX_FULL;
213
+
182
+ break;
214
+ if (ret < 0) {
183
+ case SHAKTI_UART_STATUS:
215
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when "
184
+ s->uart_status = value;
216
+ "writing chardev");
185
+ break;
217
+ exit(1);
186
+ case SHAKTI_UART_DELAY:
218
+ }
187
+ s->uart_delay = value;
219
+
188
+ break;
220
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
189
+ case SHAKTI_UART_CONTROL:
221
+ run->riscv_sbi.ret[1] = 0;
190
+ s->uart_control = value;
191
+ break;
192
+ case SHAKTI_UART_INT_EN:
193
+ s->uart_interrupt = value;
194
+ break;
195
+ case SHAKTI_UART_IQ_CYCLES:
196
+ s->uart_iq_cycles = value;
197
+ break;
198
+ case SHAKTI_UART_RX_THRES:
199
+ s->uart_rx_threshold = value;
200
+ break;
222
+ break;
201
+ default:
223
+ default:
202
+ qemu_log_mask(LOG_GUEST_ERROR,
224
+ run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
203
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
204
+ }
225
+ }
205
+}
226
+}
206
+
227
+
207
+static const MemoryRegionOps shakti_uart_ops = {
228
static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
208
+ .read = shakti_uart_read,
229
{
209
+ .write = shakti_uart_write,
230
int ret = 0;
210
+ .endianness = DEVICE_NATIVE_ENDIAN,
231
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
211
+ .impl = {.min_access_size = 1, .max_access_size = 4},
232
}
212
+ .valid = {.min_access_size = 1, .max_access_size = 4},
233
ret = 0;
213
+};
234
break;
214
+
235
+ case SBI_EXT_DBCN:
215
+static void shakti_uart_reset(DeviceState *dev)
236
+ kvm_riscv_handle_sbi_dbcn(cs, run);
216
+{
237
+ break;
217
+ ShaktiUartState *s = SHAKTI_UART(dev);
238
default:
218
+
239
qemu_log_mask(LOG_UNIMP,
219
+ s->uart_baud = SHAKTI_UART_BAUD_DEFAULT;
240
"%s: un-handled SBI EXIT, specific reasons is %lu\n",
220
+ s->uart_tx = 0x0;
221
+ s->uart_rx = 0x0;
222
+ s->uart_status = 0x0000;
223
+ s->uart_delay = 0x0000;
224
+ s->uart_control = SHAKTI_UART_CONTROL_DEFAULT;
225
+ s->uart_interrupt = 0x0000;
226
+ s->uart_iq_cycles = 0x00;
227
+ s->uart_rx_threshold = 0x00;
228
+}
229
+
230
+static int shakti_uart_can_receive(void *opaque)
231
+{
232
+ ShaktiUartState *s = opaque;
233
+
234
+ return !(s->uart_status & SHAKTI_UART_STATUS_RX_NOT_EMPTY);
235
+}
236
+
237
+static void shakti_uart_receive(void *opaque, const uint8_t *buf, int size)
238
+{
239
+ ShaktiUartState *s = opaque;
240
+
241
+ s->uart_rx = *buf;
242
+ s->uart_status |= SHAKTI_UART_STATUS_RX_NOT_EMPTY;
243
+}
244
+
245
+static void shakti_uart_realize(DeviceState *dev, Error **errp)
246
+{
247
+ ShaktiUartState *sus = SHAKTI_UART(dev);
248
+ qemu_chr_fe_set_handlers(&sus->chr, shakti_uart_can_receive,
249
+ shakti_uart_receive, NULL, NULL, sus, NULL, true);
250
+}
251
+
252
+static void shakti_uart_instance_init(Object *obj)
253
+{
254
+ ShaktiUartState *sus = SHAKTI_UART(obj);
255
+ memory_region_init_io(&sus->mmio,
256
+ obj,
257
+ &shakti_uart_ops,
258
+ sus,
259
+ TYPE_SHAKTI_UART,
260
+ 0x1000);
261
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &sus->mmio);
262
+}
263
+
264
+static Property shakti_uart_properties[] = {
265
+ DEFINE_PROP_CHR("chardev", ShaktiUartState, chr),
266
+ DEFINE_PROP_END_OF_LIST(),
267
+};
268
+
269
+static void shakti_uart_class_init(ObjectClass *klass, void *data)
270
+{
271
+ DeviceClass *dc = DEVICE_CLASS(klass);
272
+ dc->reset = shakti_uart_reset;
273
+ dc->realize = shakti_uart_realize;
274
+ device_class_set_props(dc, shakti_uart_properties);
275
+}
276
+
277
+static const TypeInfo shakti_uart_info = {
278
+ .name = TYPE_SHAKTI_UART,
279
+ .parent = TYPE_SYS_BUS_DEVICE,
280
+ .instance_size = sizeof(ShaktiUartState),
281
+ .class_init = shakti_uart_class_init,
282
+ .instance_init = shakti_uart_instance_init,
283
+};
284
+
285
+static void shakti_uart_register_types(void)
286
+{
287
+ type_register_static(&shakti_uart_info);
288
+}
289
+type_init(shakti_uart_register_types)
290
diff --git a/MAINTAINERS b/MAINTAINERS
291
index XXXXXXX..XXXXXXX 100644
292
--- a/MAINTAINERS
293
+++ b/MAINTAINERS
294
@@ -XXX,XX +XXX,XX @@ M: Vijai Kumar K <vijai@behindbytes.com>
295
L: qemu-riscv@nongnu.org
296
S: Supported
297
F: hw/riscv/shakti_c.c
298
+F: hw/char/shakti_uart.c
299
F: include/hw/riscv/shakti_c.h
300
+F: include/hw/char/shakti_uart.h
301
302
SiFive Machines
303
M: Alistair Francis <Alistair.Francis@wdc.com>
304
diff --git a/hw/char/meson.build b/hw/char/meson.build
305
index XXXXXXX..XXXXXXX 100644
306
--- a/hw/char/meson.build
307
+++ b/hw/char/meson.build
308
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SERIAL', if_true: files('serial.c'))
309
softmmu_ss.add(when: 'CONFIG_SERIAL_ISA', if_true: files('serial-isa.c'))
310
softmmu_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c'))
311
softmmu_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c'))
312
+softmmu_ss.add(when: 'CONFIG_SHAKTI', if_true: files('shakti_uart.c'))
313
softmmu_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-console.c'))
314
softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen_console.c'))
315
softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_uartlite.c'))
316
diff --git a/hw/char/trace-events b/hw/char/trace-events
317
index XXXXXXX..XXXXXXX 100644
318
--- a/hw/char/trace-events
319
+++ b/hw/char/trace-events
320
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1"
321
nrf51_uart_read(uint64_t addr, uint64_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
322
nrf51_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
323
324
+# shakti_uart.c
325
+shakti_uart_read(uint64_t addr, uint16_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx16 " size %u"
326
+shakti_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
327
+
328
# exynos4210_uart.c
329
exynos_uart_dmabusy(uint32_t channel) "UART%d: DMA busy (Rx buffer empty)"
330
exynos_uart_dmaready(uint32_t channel) "UART%d: DMA ready"
331
--
241
--
332
2.31.1
242
2.45.1
333
334
diff view generated by jsdifflib
1
From: Cheng Yang <yangcheng.work@foxmail.com>
2
3
Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell()
4
to set the address of initrd in FDT to support 64-bit address.
5
6
Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Message-id: fcc125d96da941b56c817c9dd6068dc36478fc53.1619234854.git.alistair.francis@wdc.com
4
---
10
---
5
target/riscv/cpu_bits.h | 10 ----------
11
hw/riscv/boot.c | 4 ++--
6
target/riscv/csr.c | 12 ++++++++++--
12
1 file changed, 2 insertions(+), 2 deletions(-)
7
target/riscv/translate.c | 19 +++++++++++++++++--
8
3 files changed, 27 insertions(+), 14 deletions(-)
9
13
10
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
14
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
11
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/cpu_bits.h
16
--- a/hw/riscv/boot.c
13
+++ b/target/riscv/cpu_bits.h
17
+++ b/hw/riscv/boot.c
14
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
15
#define MXL_RV64 2
19
/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
16
#define MXL_RV128 3
20
if (fdt) {
17
21
end = start + size;
18
-#if defined(TARGET_RISCV32)
22
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start);
19
-#define MSTATUS_SD MSTATUS32_SD
23
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end);
20
-#define MISA_MXL MISA32_MXL
24
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start);
21
-#define MXL_VAL MXL_RV32
25
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end);
22
-#elif defined(TARGET_RISCV64)
23
-#define MSTATUS_SD MSTATUS64_SD
24
-#define MISA_MXL MISA64_MXL
25
-#define MXL_VAL MXL_RV64
26
-#endif
27
-
28
/* sstatus CSR bits */
29
#define SSTATUS_UIE 0x00000001
30
#define SSTATUS_SIE 0x00000002
31
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/csr.c
34
+++ b/target/riscv/csr.c
35
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
36
37
dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) |
38
((mstatus & MSTATUS_XS) == MSTATUS_XS);
39
- mstatus = set_field(mstatus, MSTATUS_SD, dirty);
40
+ if (riscv_cpu_is_32bit(env)) {
41
+ mstatus = set_field(mstatus, MSTATUS32_SD, dirty);
42
+ } else {
43
+ mstatus = set_field(mstatus, MSTATUS64_SD, dirty);
44
+ }
45
env->mstatus = mstatus;
46
47
return RISCV_EXCP_NONE;
48
@@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno,
49
}
26
}
50
51
/* misa.MXL writes are not supported by QEMU */
52
- val = (env->misa & MISA_MXL) | (val & ~MISA_MXL);
53
+ if (riscv_cpu_is_32bit(env)) {
54
+ val = (env->misa & MISA32_MXL) | (val & ~MISA32_MXL);
55
+ } else {
56
+ val = (env->misa & MISA64_MXL) | (val & ~MISA64_MXL);
57
+ }
58
59
/* flush translation cache */
60
if (val != env->misa) {
61
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
62
index XXXXXXX..XXXXXXX 100644
63
--- a/target/riscv/translate.c
64
+++ b/target/riscv/translate.c
65
@@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
66
return ctx->misa & ext;
67
}
27
}
68
28
69
+#ifdef TARGET_RISCV32
70
+# define is_32bit(ctx) true
71
+#elif defined(CONFIG_USER_ONLY)
72
+# define is_32bit(ctx) false
73
+#else
74
+static inline bool is_32bit(DisasContext *ctx)
75
+{
76
+ return (ctx->misa & RV32) == RV32;
77
+}
78
+#endif
79
+
80
/*
81
* RISC-V requires NaN-boxing of narrower width floating point values.
82
* This applies when a 32-bit value is assigned to a 64-bit FP register.
83
@@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
84
static void mark_fs_dirty(DisasContext *ctx)
85
{
86
TCGv tmp;
87
+ target_ulong sd;
88
+
89
if (ctx->mstatus_fs == MSTATUS_FS) {
90
return;
91
}
92
@@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx)
93
ctx->mstatus_fs = MSTATUS_FS;
94
95
tmp = tcg_temp_new();
96
+ sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD;
97
+
98
tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
99
- tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD);
100
+ tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
101
tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
102
103
if (ctx->virt_enabled) {
104
tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
105
- tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD);
106
+ tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
107
tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
108
}
109
tcg_temp_free(tmp);
110
--
29
--
111
2.31.1
30
2.45.1
112
113
diff view generated by jsdifflib
1
From: Clément Léger <cleger@rivosinc.com>
2
3
The current semihost exception number (16) is a reserved number (range
4
[16-17]). The upcoming double trap specification uses that number for
5
the double trap exception. Since the privileged spec (Table 22) defines
6
ranges for custom uses change the semihosting exception number to 63
7
which belongs to the range [48-63] in order to avoid any future
8
collisions with reserved exception.
9
10
Signed-off-by: Clément Léger <cleger@rivosinc.com>
11
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
4
Message-id: f191dcf08bf413a822e743a7c7f824d68879a527.1617290165.git.alistair.francis@wdc.com
5
---
15
---
6
target/riscv/cpu_bits.h | 44 ++++++++++++++++++++-------------------
16
target/riscv/cpu_bits.h | 2 +-
7
target/riscv/cpu.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
8
target/riscv/cpu_helper.c | 4 ++--
9
3 files changed, 26 insertions(+), 24 deletions(-)
10
18
11
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
19
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
12
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/cpu_bits.h
21
--- a/target/riscv/cpu_bits.h
14
+++ b/target/riscv/cpu_bits.h
22
+++ b/target/riscv/cpu_bits.h
15
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
16
#define DEFAULT_RSTVEC 0x1000
24
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
17
25
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
18
/* Exception causes */
26
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
19
-#define EXCP_NONE -1 /* sentinel value */
27
- RISCV_EXCP_SEMIHOST = 0x10,
20
-#define RISCV_EXCP_INST_ADDR_MIS 0x0
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
21
-#define RISCV_EXCP_INST_ACCESS_FAULT 0x1
29
RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
22
-#define RISCV_EXCP_ILLEGAL_INST 0x2
30
RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
23
-#define RISCV_EXCP_BREAKPOINT 0x3
31
RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
24
-#define RISCV_EXCP_LOAD_ADDR_MIS 0x4
32
+ RISCV_EXCP_SEMIHOST = 0x3f,
25
-#define RISCV_EXCP_LOAD_ACCESS_FAULT 0x5
33
} RISCVException;
26
-#define RISCV_EXCP_STORE_AMO_ADDR_MIS 0x6
27
-#define RISCV_EXCP_STORE_AMO_ACCESS_FAULT 0x7
28
-#define RISCV_EXCP_U_ECALL 0x8
29
-#define RISCV_EXCP_S_ECALL 0x9
30
-#define RISCV_EXCP_VS_ECALL 0xa
31
-#define RISCV_EXCP_M_ECALL 0xb
32
-#define RISCV_EXCP_INST_PAGE_FAULT 0xc /* since: priv-1.10.0 */
33
-#define RISCV_EXCP_LOAD_PAGE_FAULT 0xd /* since: priv-1.10.0 */
34
-#define RISCV_EXCP_STORE_PAGE_FAULT 0xf /* since: priv-1.10.0 */
35
-#define RISCV_EXCP_SEMIHOST 0x10
36
-#define RISCV_EXCP_INST_GUEST_PAGE_FAULT 0x14
37
-#define RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT 0x15
38
-#define RISCV_EXCP_VIRT_INSTRUCTION_FAULT 0x16
39
-#define RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT 0x17
40
+typedef enum RISCVException {
41
+ RISCV_EXCP_NONE = -1, /* sentinel value */
42
+ RISCV_EXCP_INST_ADDR_MIS = 0x0,
43
+ RISCV_EXCP_INST_ACCESS_FAULT = 0x1,
44
+ RISCV_EXCP_ILLEGAL_INST = 0x2,
45
+ RISCV_EXCP_BREAKPOINT = 0x3,
46
+ RISCV_EXCP_LOAD_ADDR_MIS = 0x4,
47
+ RISCV_EXCP_LOAD_ACCESS_FAULT = 0x5,
48
+ RISCV_EXCP_STORE_AMO_ADDR_MIS = 0x6,
49
+ RISCV_EXCP_STORE_AMO_ACCESS_FAULT = 0x7,
50
+ RISCV_EXCP_U_ECALL = 0x8,
51
+ RISCV_EXCP_S_ECALL = 0x9,
52
+ RISCV_EXCP_VS_ECALL = 0xa,
53
+ RISCV_EXCP_M_ECALL = 0xb,
54
+ RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
55
+ RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
56
+ RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
57
+ RISCV_EXCP_SEMIHOST = 0x10,
58
+ RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
59
+ RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
60
+ RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
61
+ RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
62
+} RISCVException;
63
34
64
#define RISCV_EXCP_INT_FLAG 0x80000000
35
#define RISCV_EXCP_INT_FLAG 0x80000000
65
#define RISCV_EXCP_INT_MASK 0x7fffffff
66
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/cpu.c
69
+++ b/target/riscv/cpu.c
70
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
71
env->pc = env->resetvec;
72
env->two_stage_lookup = false;
73
#endif
74
- cs->exception_index = EXCP_NONE;
75
+ cs->exception_index = RISCV_EXCP_NONE;
76
env->load_res = -1;
77
set_default_nan_mode(1, &env->fp_status);
78
}
79
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/target/riscv/cpu_helper.c
82
+++ b/target/riscv/cpu_helper.c
83
@@ -XXX,XX +XXX,XX @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env)
84
if (irqs) {
85
return ctz64(irqs); /* since non-zero */
86
} else {
87
- return EXCP_NONE; /* indicates no pending interrupt */
88
+ return RISCV_EXCP_NONE; /* indicates no pending interrupt */
89
}
90
}
91
#endif
92
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
93
94
env->two_stage_lookup = false;
95
#endif
96
- cs->exception_index = EXCP_NONE; /* mark handled to qemu */
97
+ cs->exception_index = RISCV_EXCP_NONE; /* mark handled to qemu */
98
}
99
--
36
--
100
2.31.1
37
2.45.1
101
38
102
39
diff view generated by jsdifflib
1
From: LIU Zhiwei <zhiwei_liu@c-sky.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right.
3
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr
4
However, when the predication is ture and a is 0, it should return maximum.
4
enabled, will fail with a kernel oops SIGILL right at the start. The
5
reason is that we can't expose zkr without implementing the SEED CSR.
6
Disabling zkr in the guest would be a workaround, but if the KVM doesn't
7
allow it we'll error out and never boot.
5
8
6
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
9
In hindsight this is too strict. If we keep proceeding, despite not
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
disabling the extension in the KVM vcpu, we'll not add the extension in
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
the riscv,isa. The guest kernel will be unaware of the extension, i.e.
9
Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com
12
it doesn't matter if the KVM vcpu has it enabled underneath or not. So
13
it's ok to keep booting in this case.
14
15
Change our current logic to not error out if we fail to disable an
16
extension in kvm_set_one_reg(), but show a warning and keep booting. It
17
is important to throw a warning because we must make the user aware that
18
the extension is still available in the vcpu, meaning that an
19
ill-behaved guest can ignore the riscv,isa settings and use the
20
extension.
21
22
The case we're handling happens with an EINVAL error code. If we fail to
23
disable the extension in KVM for any other reason, error out.
24
25
We'll also keep erroring out when we fail to enable an extension in KVM,
26
since adding the extension in riscv,isa at this point will cause a guest
27
malfunction because the extension isn't enabled in the vcpu.
28
29
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
33
Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
35
---
12
target/riscv/vector_helper.c | 8 ++++----
36
target/riscv/kvm/kvm-cpu.c | 12 ++++++++----
13
1 file changed, 4 insertions(+), 4 deletions(-)
37
1 file changed, 8 insertions(+), 4 deletions(-)
14
38
15
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
39
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
16
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/vector_helper.c
41
--- a/target/riscv/kvm/kvm-cpu.c
18
+++ b/target/riscv/vector_helper.c
42
+++ b/target/riscv/kvm/kvm-cpu.c
19
@@ -XXX,XX +XXX,XX @@ static inline int8_t ssub8(CPURISCVState *env, int vxrm, int8_t a, int8_t b)
43
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
20
{
44
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
21
int8_t res = a - b;
45
ret = kvm_set_one_reg(cs, id, &reg);
22
if ((res ^ a) & (a ^ b) & INT8_MIN) {
46
if (ret != 0) {
23
- res = a > 0 ? INT8_MAX : INT8_MIN;
47
- error_report("Unable to %s extension %s in KVM, error %d",
24
+ res = a >= 0 ? INT8_MAX : INT8_MIN;
48
- reg ? "enable" : "disable",
25
env->vxsat = 0x1;
49
- multi_ext_cfg->name, ret);
50
- exit(EXIT_FAILURE);
51
+ if (!reg && ret == -EINVAL) {
52
+ warn_report("KVM cannot disable extension %s",
53
+ multi_ext_cfg->name);
54
+ } else {
55
+ error_report("Unable to enable extension %s in KVM, error %d",
56
+ multi_ext_cfg->name, ret);
57
+ exit(EXIT_FAILURE);
58
+ }
59
}
26
}
60
}
27
return res;
61
}
28
@@ -XXX,XX +XXX,XX @@ static inline int16_t ssub16(CPURISCVState *env, int vxrm, int16_t a, int16_t b)
29
{
30
int16_t res = a - b;
31
if ((res ^ a) & (a ^ b) & INT16_MIN) {
32
- res = a > 0 ? INT16_MAX : INT16_MIN;
33
+ res = a >= 0 ? INT16_MAX : INT16_MIN;
34
env->vxsat = 0x1;
35
}
36
return res;
37
@@ -XXX,XX +XXX,XX @@ static inline int32_t ssub32(CPURISCVState *env, int vxrm, int32_t a, int32_t b)
38
{
39
int32_t res = a - b;
40
if ((res ^ a) & (a ^ b) & INT32_MIN) {
41
- res = a > 0 ? INT32_MAX : INT32_MIN;
42
+ res = a >= 0 ? INT32_MAX : INT32_MIN;
43
env->vxsat = 0x1;
44
}
45
return res;
46
@@ -XXX,XX +XXX,XX @@ static inline int64_t ssub64(CPURISCVState *env, int vxrm, int64_t a, int64_t b)
47
{
48
int64_t res = a - b;
49
if ((res ^ a) & (a ^ b) & INT64_MIN) {
50
- res = a > 0 ? INT64_MAX : INT64_MIN;
51
+ res = a >= 0 ? INT64_MAX : INT64_MIN;
52
env->vxsat = 0x1;
53
}
54
return res;
55
--
62
--
56
2.31.1
63
2.45.1
57
58
diff view generated by jsdifflib
1
From: Jade Fink <qemu@jade.fyi>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Previously the qemu monitor and gdbstub looked at SUM and refused to
3
We're not setting (s/m)tval when triggering breakpoints of type 2
4
perform accesses to user memory if it is off, which was an impediment to
4
(mcontrol) and 6 (mcontrol6). According to the debug spec section
5
debugging.
5
5.7.12, "Match Control Type 6":
6
6
7
Signed-off-by: Jade Fink <qemu@jade.fyi>
7
"The Privileged Spec says that breakpoint exceptions that occur on
8
instruction fetches, loads, or stores update the tval CSR with either
9
zero or the faulting virtual address. The faulting virtual address for
10
an mcontrol6 trigger with action = 0 is the address being accessed and
11
which caused that trigger to fire."
12
13
A similar text is also found in the Debug spec section 5.7.11 w.r.t.
14
mcontrol.
15
16
Note that what we're doing ATM is not violating the spec, but it's
17
simple enough to set mtval/stval and it makes life easier for any
18
software that relies on this info.
19
20
Given that we always use action = 0, save the faulting address for the
21
mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is
22
used as as scratch area for traps with address information. 'tval' is
23
then set during riscv_cpu_do_interrupt().
24
25
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210406113109.1031033-1-qemu@jade.fyi
27
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
28
Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
30
---
12
target/riscv/cpu_helper.c | 20 ++++++++++++--------
31
target/riscv/cpu_helper.c | 1 +
13
1 file changed, 12 insertions(+), 8 deletions(-)
32
target/riscv/debug.c | 3 +++
33
2 files changed, 4 insertions(+)
14
34
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
35
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
16
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
37
--- a/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
38
+++ b/target/riscv/cpu_helper.c
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
39
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
20
* @first_stage: Are we in first stage translation?
40
tval = env->bins;
21
* Second stage is used for hypervisor guest translation
41
break;
22
* @two_stage: Are we going to perform two stage translation
42
case RISCV_EXCP_BREAKPOINT:
23
+ * @is_debug: Is this access from a debugger or the monitor?
43
+ tval = env->badaddr;
24
*/
44
if (cs->watchpoint_hit) {
25
static int get_physical_address(CPURISCVState *env, hwaddr *physical,
45
tval = cs->watchpoint_hit->hitaddr;
26
int *prot, target_ulong addr,
46
cs->watchpoint_hit = NULL;
27
target_ulong *fault_pte_addr,
47
diff --git a/target/riscv/debug.c b/target/riscv/debug.c
28
int access_type, int mmu_idx,
48
index XXXXXXX..XXXXXXX 100644
29
- bool first_stage, bool two_stage)
49
--- a/target/riscv/debug.c
30
+ bool first_stage, bool two_stage,
50
+++ b/target/riscv/debug.c
31
+ bool is_debug)
51
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
32
{
52
if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) {
33
/* NOTE: the env->pc value visible here will not be
53
/* check U/S/M bit against current privilege level */
34
* correct, but the value visible to the exception handler
54
if ((ctrl >> 3) & BIT(env->priv)) {
35
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
55
+ env->badaddr = pc;
36
widened = 2;
56
return true;
37
}
57
}
38
/* status.SUM will be ignored if execute on background */
58
}
39
- sum = get_field(env->mstatus, MSTATUS_SUM) || use_background;
59
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
40
+ sum = get_field(env->mstatus, MSTATUS_SUM) || use_background || is_debug;
60
if (env->virt_enabled) {
41
switch (vm) {
61
/* check VU/VS bit against current privilege level */
42
case VM_1_10_SV32:
62
if ((ctrl >> 23) & BIT(env->priv)) {
43
levels = 2; ptidxbits = 10; ptesize = 4; break;
63
+ env->badaddr = pc;
44
@@ -XXX,XX +XXX,XX @@ restart:
64
return true;
45
/* Do the second stage translation on the base PTE address. */
65
}
46
int vbase_ret = get_physical_address(env, &vbase, &vbase_prot,
66
} else {
47
base, NULL, MMU_DATA_LOAD,
67
/* check U/S/M bit against current privilege level */
48
- mmu_idx, false, true);
68
if ((ctrl >> 3) & BIT(env->priv)) {
49
+ mmu_idx, false, true,
69
+ env->badaddr = pc;
50
+ is_debug);
70
return true;
51
71
}
52
if (vbase_ret != TRANSLATE_SUCCESS) {
72
}
53
if (fault_pte_addr) {
54
@@ -XXX,XX +XXX,XX @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
55
int mmu_idx = cpu_mmu_index(&cpu->env, false);
56
57
if (get_physical_address(env, &phys_addr, &prot, addr, NULL, 0, mmu_idx,
58
- true, riscv_cpu_virt_enabled(env))) {
59
+ true, riscv_cpu_virt_enabled(env), true)) {
60
return -1;
61
}
62
63
if (riscv_cpu_virt_enabled(env)) {
64
if (get_physical_address(env, &phys_addr, &prot, phys_addr, NULL,
65
- 0, mmu_idx, false, true)) {
66
+ 0, mmu_idx, false, true, true)) {
67
return -1;
68
}
69
}
70
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
71
/* Two stage lookup */
72
ret = get_physical_address(env, &pa, &prot, address,
73
&env->guest_phys_fault_addr, access_type,
74
- mmu_idx, true, true);
75
+ mmu_idx, true, true, false);
76
77
/*
78
* A G-stage exception may be triggered during two state lookup.
79
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
80
im_address = pa;
81
82
ret = get_physical_address(env, &pa, &prot2, im_address, NULL,
83
- access_type, mmu_idx, false, true);
84
+ access_type, mmu_idx, false, true,
85
+ false);
86
87
qemu_log_mask(CPU_LOG_MMU,
88
"%s 2nd-stage address=%" VADDR_PRIx " ret %d physical "
89
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
90
} else {
91
/* Single stage lookup */
92
ret = get_physical_address(env, &pa, &prot, address, NULL,
93
- access_type, mmu_idx, true, false);
94
+ access_type, mmu_idx, true, false, false);
95
96
qemu_log_mask(CPU_LOG_MMU,
97
"%s address=%" VADDR_PRIx " ret %d physical "
98
--
73
--
99
2.31.1
74
2.45.1
100
101
diff view generated by jsdifflib
1
From: Frank Chang <frank.chang@sifive.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
In IEEE 754-2008 spec:
3
Privileged spec section 4.1.9 mentions:
4
Invalid operation exception is signaled when doing:
5
fusedMultiplyAdd(0, Inf, c) or fusedMultiplyAdd(Inf, 0, c)
6
unless c is a quiet NaN; if c is a quiet NaN then it is
7
implementation defined whether the invalid operation exception
8
is signaled.
9
4
10
In RISC-V Unprivileged ISA spec:
5
"When a trap is taken into S-mode, stval is written with
11
The fused multiply-add instructions must set the invalid
6
exception-specific information to assist software in handling the trap.
12
operation exception flag when the multiplicands are Inf and
7
(...)
13
zero, even when the addend is a quiet NaN.
14
8
15
This commit set invalid operation execption flag for RISC-V when
9
If stval is written with a nonzero value when a breakpoint,
16
multiplicands of muladd instructions are Inf and zero.
10
address-misaligned, access-fault, or page-fault exception occurs on an
11
instruction fetch, load, or store, then stval will contain the faulting
12
virtual address."
17
13
18
Signed-off-by: Frank Chang <frank.chang@sifive.com>
14
A similar text is found for mtval in section 3.1.16.
15
16
Setting mtval/stval in this scenario is optional, but some softwares read
17
these regs when handling ebreaks.
18
19
Write 'badaddr' in all ebreak breakpoints to write the appropriate
20
'tval' during riscv_do_cpu_interrrupt().
21
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Message-id: 20210420013150.21992-1-frank.chang@sifive.com
26
Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
28
---
23
fpu/softfloat-specialize.c.inc | 6 ++++++
29
target/riscv/insn_trans/trans_privileged.c.inc | 2 ++
24
1 file changed, 6 insertions(+)
30
1 file changed, 2 insertions(+)
25
31
26
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
32
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
27
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
28
--- a/fpu/softfloat-specialize.c.inc
34
--- a/target/riscv/insn_trans/trans_privileged.c.inc
29
+++ b/fpu/softfloat-specialize.c.inc
35
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
30
@@ -XXX,XX +XXX,XX @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
36
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
37
if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
38
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
31
} else {
39
} else {
32
return 1;
40
+ tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env,
41
+ offsetof(CPURISCVState, badaddr));
42
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
33
}
43
}
34
+#elif defined(TARGET_RISCV)
44
return true;
35
+ /* For RISC-V, InvalidOp is set when multiplicands are Inf and zero */
36
+ if (infzero) {
37
+ float_raise(float_flag_invalid, status);
38
+ }
39
+ return 3; /* default NaN */
40
#elif defined(TARGET_XTENSA)
41
/*
42
* For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns
43
--
45
--
44
2.31.1
46
2.45.1
45
46
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
2
3
Add support for Zve32x extension and replace some checks for Zve32f with
4
Zve32x, since Zve32f depends on Zve32x.
5
6
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
Reviewed-by: Max Chou <max.chou@sifive.com>
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Message-ID: <20240328022343.6871-2-jason.chien@sifive.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Message-id: 6b701769d6621f45ba1739334198e36a64fe04df.1619234854.git.alistair.francis@wdc.com
4
---
12
---
5
target/riscv/cpu_bits.h | 11 -----------
13
target/riscv/cpu_cfg.h | 1 +
6
target/riscv/cpu_helper.c | 32 ++++++++++++++++++++++++--------
14
target/riscv/cpu.c | 2 ++
7
target/riscv/csr.c | 19 +++++++++++++++----
15
target/riscv/cpu_helper.c | 2 +-
8
target/riscv/monitor.c | 22 +++++++++++++++++-----
16
target/riscv/csr.c | 2 +-
9
4 files changed, 56 insertions(+), 28 deletions(-)
17
target/riscv/tcg/tcg-cpu.c | 16 ++++++++--------
18
target/riscv/insn_trans/trans_rvv.c.inc | 4 ++--
19
6 files changed, 15 insertions(+), 12 deletions(-)
10
20
11
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
21
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
12
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/cpu_bits.h
23
--- a/target/riscv/cpu_cfg.h
14
+++ b/target/riscv/cpu_bits.h
24
+++ b/target/riscv/cpu_cfg.h
15
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
16
#define SATP64_ASID 0x0FFFF00000000000ULL
26
bool ext_zhinx;
17
#define SATP64_PPN 0x00000FFFFFFFFFFFULL
27
bool ext_zhinxmin;
18
28
bool ext_zve32f;
19
-#if defined(TARGET_RISCV32)
29
+ bool ext_zve32x;
20
-#define SATP_MODE SATP32_MODE
30
bool ext_zve64f;
21
-#define SATP_ASID SATP32_ASID
31
bool ext_zve64d;
22
-#define SATP_PPN SATP32_PPN
32
bool ext_zvbb;
23
-#endif
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
24
-#if defined(TARGET_RISCV64)
34
index XXXXXXX..XXXXXXX 100644
25
-#define SATP_MODE SATP64_MODE
35
--- a/target/riscv/cpu.c
26
-#define SATP_ASID SATP64_ASID
36
+++ b/target/riscv/cpu.c
27
-#define SATP_PPN SATP64_PPN
37
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
28
-#endif
38
ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb),
29
-
39
ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc),
30
/* VM modes (mstatus.vm) privileged ISA 1.9.1 */
40
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
31
#define VM_1_09_MBARE 0
41
+ ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
32
#define VM_1_09_MBB 1
42
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
43
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
44
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
45
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
46
MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false),
47
MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false),
48
MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false),
49
+ MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
50
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
51
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
52
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
33
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
53
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
34
index XXXXXXX..XXXXXXX 100644
54
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/cpu_helper.c
55
--- a/target/riscv/cpu_helper.c
36
+++ b/target/riscv/cpu_helper.c
56
+++ b/target/riscv/cpu_helper.c
37
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
57
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
38
58
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
39
if (first_stage == true) {
59
*cs_base = 0;
40
if (use_background) {
60
41
- base = (hwaddr)get_field(env->vsatp, SATP_PPN) << PGSHIFT;
61
- if (cpu->cfg.ext_zve32f) {
42
- vm = get_field(env->vsatp, SATP_MODE);
62
+ if (cpu->cfg.ext_zve32x) {
43
+ if (riscv_cpu_is_32bit(env)) {
63
/*
44
+ base = (hwaddr)get_field(env->vsatp, SATP32_PPN) << PGSHIFT;
64
* If env->vl equals to VLMAX, we can use generic vector operation
45
+ vm = get_field(env->vsatp, SATP32_MODE);
65
* expanders (GVEC) to accerlate the vector operations.
46
+ } else {
47
+ base = (hwaddr)get_field(env->vsatp, SATP64_PPN) << PGSHIFT;
48
+ vm = get_field(env->vsatp, SATP64_MODE);
49
+ }
50
} else {
51
- base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT;
52
- vm = get_field(env->satp, SATP_MODE);
53
+ if (riscv_cpu_is_32bit(env)) {
54
+ base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT;
55
+ vm = get_field(env->satp, SATP32_MODE);
56
+ } else {
57
+ base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT;
58
+ vm = get_field(env->satp, SATP64_MODE);
59
+ }
60
}
61
widened = 0;
62
} else {
63
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
64
{
65
CPUState *cs = env_cpu(env);
66
int page_fault_exceptions, vm;
67
+ uint64_t stap_mode;
68
+
69
+ if (riscv_cpu_is_32bit(env)) {
70
+ stap_mode = SATP32_MODE;
71
+ } else {
72
+ stap_mode = SATP64_MODE;
73
+ }
74
75
if (first_stage) {
76
- vm = get_field(env->satp, SATP_MODE);
77
- } else if (riscv_cpu_is_32bit(env)) {
78
- vm = get_field(env->hgatp, SATP32_MODE);
79
+ vm = get_field(env->satp, stap_mode);
80
} else {
81
- vm = get_field(env->hgatp, SATP64_MODE);
82
+ vm = get_field(env->hgatp, stap_mode);
83
}
84
+
85
page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation;
86
87
switch (access_type) {
88
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
66
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
89
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
90
--- a/target/riscv/csr.c
68
--- a/target/riscv/csr.c
91
+++ b/target/riscv/csr.c
69
+++ b/target/riscv/csr.c
92
@@ -XXX,XX +XXX,XX @@ static RISCVException read_satp(CPURISCVState *env, int csrno,
70
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
93
static RISCVException write_satp(CPURISCVState *env, int csrno,
71
94
target_ulong val)
72
static RISCVException vs(CPURISCVState *env, int csrno)
95
{
73
{
96
+ int vm, mask, asid;
74
- if (riscv_cpu_cfg(env)->ext_zve32f) {
97
+
75
+ if (riscv_cpu_cfg(env)->ext_zve32x) {
98
if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
76
#if !defined(CONFIG_USER_ONLY)
99
return RISCV_EXCP_NONE;
77
if (!env->debugger && !riscv_cpu_vector_enabled(env)) {
100
}
101
- if (validate_vm(env, get_field(val, SATP_MODE)) &&
102
- ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN)))
103
- {
104
+
105
+ if (riscv_cpu_is_32bit(env)) {
106
+ vm = validate_vm(env, get_field(val, SATP32_MODE));
107
+ mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN);
108
+ asid = (val ^ env->satp) & SATP32_ASID;
109
+ } else {
110
+ vm = validate_vm(env, get_field(val, SATP64_MODE));
111
+ mask = (val ^ env->satp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN);
112
+ asid = (val ^ env->satp) & SATP64_ASID;
113
+ }
114
+
115
+ if (vm && mask) {
116
if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
117
return RISCV_EXCP_ILLEGAL_INST;
78
return RISCV_EXCP_ILLEGAL_INST;
118
} else {
79
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
119
- if ((val ^ env->satp) & SATP_ASID) {
120
+ if (asid) {
121
tlb_flush(env_cpu(env));
122
}
123
env->satp = val;
124
diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c
125
index XXXXXXX..XXXXXXX 100644
80
index XXXXXXX..XXXXXXX 100644
126
--- a/target/riscv/monitor.c
81
--- a/target/riscv/tcg/tcg-cpu.c
127
+++ b/target/riscv/monitor.c
82
+++ b/target/riscv/tcg/tcg-cpu.c
128
@@ -XXX,XX +XXX,XX @@ static void mem_info_svxx(Monitor *mon, CPUArchState *env)
83
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
129
target_ulong last_size;
130
int last_attr;
131
132
- base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT;
133
+ if (riscv_cpu_is_32bit(env)) {
134
+ base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT;
135
+ vm = get_field(env->satp, SATP32_MODE);
136
+ } else {
137
+ base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT;
138
+ vm = get_field(env->satp, SATP64_MODE);
139
+ }
140
141
- vm = get_field(env->satp, SATP_MODE);
142
switch (vm) {
143
case VM_1_10_SV32:
144
levels = 2;
145
@@ -XXX,XX +XXX,XX @@ void hmp_info_mem(Monitor *mon, const QDict *qdict)
146
return;
84
return;
147
}
85
}
148
86
149
- if (!(env->satp & SATP_MODE)) {
87
- if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) {
150
- monitor_printf(mon, "No translation or protection\n");
88
- error_setg(errp, "Zve32f/Zve64f extensions require F extension");
151
- return;
89
- return;
152
+ if (riscv_cpu_is_32bit(env)) {
90
+ /* The Zve32f extension depends on the Zve32x extension */
153
+ if (!(env->satp & SATP32_MODE)) {
91
+ if (cpu->cfg.ext_zve32f) {
154
+ monitor_printf(mon, "No translation or protection\n");
92
+ if (!riscv_has_ext(env, RVF)) {
93
+ error_setg(errp, "Zve32f/Zve64f extensions require F extension");
155
+ return;
94
+ return;
156
+ }
95
+ }
157
+ } else {
96
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
158
+ if (!(env->satp & SATP64_MODE)) {
159
+ monitor_printf(mon, "No translation or protection\n");
160
+ return;
161
+ }
162
}
97
}
163
98
164
mem_info_svxx(mon, env);
99
if (cpu->cfg.ext_zvfh) {
100
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
101
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true);
102
}
103
104
- /*
105
- * In principle Zve*x would also suffice here, were they supported
106
- * in qemu
107
- */
108
if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg ||
109
cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed ||
110
- cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) {
111
+ cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) {
112
error_setg(errp,
113
"Vector crypto extensions require V or Zve* extensions");
114
return;
115
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
116
index XXXXXXX..XXXXXXX 100644
117
--- a/target/riscv/insn_trans/trans_rvv.c.inc
118
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
119
@@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
120
{
121
TCGv s1, dst;
122
123
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
124
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
125
return false;
126
}
127
128
@@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
129
{
130
TCGv dst;
131
132
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
133
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
134
return false;
135
}
136
165
--
137
--
166
2.31.1
138
2.45.1
167
168
diff view generated by jsdifflib
1
From: Vijai Kumar K <vijai@behindbytes.com>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
C-Class is a member of the SHAKTI family of processors from IIT-M.
3
Add support for Zve64x extension. Enabling Zve64f enables Zve64x and
4
enabling Zve64x enables Zve32x according to their dependency.
4
5
5
It is an extremely configurable and commercial-grade 5-stage in-order
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107
6
core supporting the standard RV64GCSUN ISA extensions.
7
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
9
Reviewed-by: Max Chou <max.chou@sifive.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Message-id: 20210401181457.73039-2-vijai@behindbytes.com
11
Message-ID: <20240328022343.6871-3-jason.chien@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
---
13
target/riscv/cpu.h | 1 +
14
target/riscv/cpu_cfg.h | 1 +
14
target/riscv/cpu.c | 1 +
15
target/riscv/cpu.c | 2 ++
15
2 files changed, 2 insertions(+)
16
target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------
17
3 files changed, 14 insertions(+), 6 deletions(-)
16
18
17
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
19
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
18
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu.h
21
--- a/target/riscv/cpu_cfg.h
20
+++ b/target/riscv/cpu.h
22
+++ b/target/riscv/cpu_cfg.h
21
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
22
#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")
24
bool ext_zve32x;
23
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
25
bool ext_zve64f;
24
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
26
bool ext_zve64d;
25
+#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
27
+ bool ext_zve64x;
26
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
28
bool ext_zvbb;
27
#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34")
29
bool ext_zvbc;
28
#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51")
30
bool ext_zvkb;
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
30
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu.c
33
--- a/target/riscv/cpu.c
32
+++ b/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
33
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
35
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
34
DEFINE_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init),
36
ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
35
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init),
37
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
36
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),
38
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
37
+ DEFINE_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init),
39
+ ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x),
38
#endif
40
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
39
};
41
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
42
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
43
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
44
MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
45
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
46
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
47
+ MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false),
48
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
49
MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false),
50
MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
51
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/tcg/tcg-cpu.c
54
+++ b/target/riscv/tcg/tcg-cpu.c
55
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
56
57
/* The Zve64d extension depends on the Zve64f extension */
58
if (cpu->cfg.ext_zve64d) {
59
+ if (!riscv_has_ext(env, RVD)) {
60
+ error_setg(errp, "Zve64d/V extensions require D extension");
61
+ return;
62
+ }
63
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true);
64
}
65
66
- /* The Zve64f extension depends on the Zve32f extension */
67
+ /* The Zve64f extension depends on the Zve64x and Zve32f extensions */
68
if (cpu->cfg.ext_zve64f) {
69
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true);
70
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true);
71
}
72
73
- if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) {
74
- error_setg(errp, "Zve64d/V extensions require D extension");
75
- return;
76
+ /* The Zve64x extension depends on the Zve32x extension */
77
+ if (cpu->cfg.ext_zve64x) {
78
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
79
}
80
81
/* The Zve32f extension depends on the Zve32x extension */
82
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
83
return;
84
}
85
86
- if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) {
87
+ if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) {
88
error_setg(
89
errp,
90
- "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions");
91
+ "Zvbc and Zvknhb extensions require V or Zve64x extensions");
92
return;
93
}
40
94
41
--
95
--
42
2.31.1
96
2.45.1
43
44
diff view generated by jsdifflib
1
From: Alexander Wagner <alexander.wagner@ulal.de>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
The IBEX documentation [1] specifies the reset vector to be "the most
3
In current implementation, the gdbstub allows reading vector registers
4
significant 3 bytes of the boot address and the reset value (0x80) as
4
only if V extension is supported. However, all vector extensions and
5
the least significant byte".
5
vector crypto extensions have the vector registers and they all depend
6
on Zve32x. The gdbstub should check for Zve32x instead.
6
7
7
[1] https://github.com/lowRISC/ibex/blob/master/doc/03_reference/exception_interrupts.rst
8
Signed-off-by: Jason Chien <jason.chien@sifive.com>
8
9
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20240328022343.6871-4-jason.chien@sifive.com>
11
Message-id: 20210420080008.119798-1-alexander.wagner@ulal.de
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
13
---
14
hw/riscv/opentitan.c | 2 +-
14
target/riscv/gdbstub.c | 2 +-
15
1 file changed, 1 insertion(+), 1 deletion(-)
15
1 file changed, 1 insertion(+), 1 deletion(-)
16
16
17
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/riscv/opentitan.c
19
--- a/target/riscv/gdbstub.c
20
+++ b/hw/riscv/opentitan.c
20
+++ b/target/riscv/gdbstub.c
21
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
22
&error_abort);
22
gdb_find_static_feature("riscv-32bit-fpu.xml"),
23
object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
23
0);
24
&error_abort);
24
}
25
- object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort);
25
- if (env->misa_ext & RVV) {
26
+ object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort);
26
+ if (cpu->cfg.ext_zve32x) {
27
sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
27
gdb_register_coprocessor(cs, riscv_gdb_get_vector,
28
28
riscv_gdb_set_vector,
29
/* Boot ROM */
29
ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs),
30
--
30
--
31
2.31.1
31
2.45.1
32
33
diff view generated by jsdifflib
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
3
In RVV and vcrypto instructions, the masked and tail elements are set to 1s
4
using vext_set_elems_1s function if the vma/vta bit is set. It is the element
5
agnostic policy.
6
7
However, this function can't deal the big endian situation. This patch fixes
8
the problem by adding handling of such case.
9
10
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
11
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: a07bc0c6dc4958681b4f93cbc5d0acc31ed3344a.1619234854.git.alistair.francis@wdc.com
5
---
16
---
6
target/riscv/cpu.h | 6 ------
17
target/riscv/vector_internals.c | 22 ++++++++++++++++++++++
7
target/riscv/cpu.c | 6 +++++-
18
1 file changed, 22 insertions(+)
8
2 files changed, 5 insertions(+), 7 deletions(-)
9
19
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c
11
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/cpu.h
22
--- a/target/riscv/vector_internals.c
13
+++ b/target/riscv/cpu.h
23
+++ b/target/riscv/vector_internals.c
14
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
15
#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))
25
if (tot - cnt == 0) {
16
#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
26
return ;
17
27
}
18
-#if defined(TARGET_RISCV32)
28
+
19
-#define RVXLEN RV32
29
+ if (HOST_BIG_ENDIAN) {
20
-#elif defined(TARGET_RISCV64)
30
+ /*
21
-#define RVXLEN RV64
31
+ * Deal the situation when the elements are insdie
22
-#endif
32
+ * only one uint64 block including setting the
23
-
33
+ * masked-off element.
24
#define RV(x) ((target_ulong)1 << (x - 'A'))
34
+ */
25
35
+ if (((tot - 1) ^ cnt) < 8) {
26
#define RVI RV('I')
36
+ memset(base + H1(tot - 1), -1, tot - cnt);
27
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
37
+ return;
28
index XXXXXXX..XXXXXXX 100644
38
+ }
29
--- a/target/riscv/cpu.c
39
+ /*
30
+++ b/target/riscv/cpu.c
40
+ * Otherwise, at least cross two uint64_t blocks.
31
@@ -XXX,XX +XXX,XX @@ static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
41
+ * Set first unaligned block.
32
static void riscv_any_cpu_init(Object *obj)
42
+ */
33
{
43
+ if (cnt % 8 != 0) {
34
CPURISCVState *env = &RISCV_CPU(obj)->env;
44
+ uint32_t j = ROUND_UP(cnt, 8);
35
- set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
45
+ memset(base + H1(j - 1), -1, j - cnt);
36
+#if defined(TARGET_RISCV32)
46
+ cnt = j;
37
+ set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
47
+ }
38
+#elif defined(TARGET_RISCV64)
48
+ /* Set other 64bit aligend blocks */
39
+ set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
49
+ }
40
+#endif
50
memset(base + cnt, -1, tot - cnt);
41
set_priv_version(env, PRIV_VERSION_1_11_0);
42
}
51
}
43
52
44
--
53
--
45
2.31.1
54
2.45.1
46
47
diff view generated by jsdifflib
1
From: Emmanuel Blot <emmanuel.blot@sifive.com>
1
From: Yangyu Chen <cyy@cyyself.name>
2
2
3
Interrupt names have been swapped in 205377f8 and do not follow
3
This code has a typo that writes zvkb to zvkg, causing users can't
4
IRQ_*_EXT definition order.
4
enable zvkb through the config. This patch gets this fixed.
5
5
6
Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
6
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
7
Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions")
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210421133236.11323-1-emmanuel.blot@sifive.com
10
Reviewed-by: Max Chou <max.chou@sifive.com>
11
Reviewed-by:  Weiwei Li <liwei1518@gmail.com>
12
Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
15
---
11
target/riscv/cpu.c | 2 +-
16
target/riscv/cpu.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
13
18
14
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu.c
21
--- a/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
18
@@ -XXX,XX +XXX,XX @@ const char * const riscv_intr_names[] = {
23
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
19
"vs_timer",
24
/* Vector cryptography extensions */
20
"m_timer",
25
MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
21
"u_external",
26
MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false),
22
+ "s_external",
27
- MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false),
23
"vs_external",
28
+ MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false),
24
- "h_external",
29
MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false),
25
"m_external",
30
MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false),
26
"reserved",
31
MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false),
27
"reserved",
28
--
32
--
29
2.31.1
33
2.45.1
30
34
31
35
diff view generated by jsdifflib
1
From: Atish Patra <atish.patra@wdc.com>
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
2
3
Qemu doesn't support RISC-V privilege specification v1.9. Remove the
3
In this patch, we modify the decoder to be a freely composable data
4
remaining v1.9 specific references from the implementation.
4
structure instead of a hardcoded one. It can be dynamically builded up
5
according to the extensions.
6
This approach has several benefits:
7
1. Provides support for heterogeneous cpu architectures. As we add decoder in
8
RISCVCPU, each cpu can have their own decoder, and the decoders can be
9
different due to cpu's features.
10
2. Improve the decoding efficiency. We run the guard_func to see if the decoder
11
can be added to the dynamic_decoder when building up the decoder. Therefore,
12
there is no need to run the guard_func when decoding each instruction. It can
13
improve the decoding efficiency
14
3. For vendor or dynamic cpus, it allows them to customize their own decoder
15
functions to improve decoding efficiency, especially when vendor-defined
16
instruction sets increase. Because of dynamic building up, it can skip the other
17
decoder guard functions when decoding.
18
4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal
19
overhead for users that don't need this particular vendor decoder.
5
20
6
Signed-off-by: Atish Patra <atish.patra@wdc.com>
21
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
22
Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu>
23
Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-Id: <20210319194534.2082397-2-atish.patra@wdc.com>
26
Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com>
9
[Changes by AF:
10
- Rebase on latest patches
11
- Bump the vmstate_riscv_cpu version_id and minimum_version_id
12
]
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
28
---
15
target/riscv/cpu.h | 4 +---
29
target/riscv/cpu.h | 1 +
16
target/riscv/cpu_bits.h | 23 ---------------------
30
target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++
17
target/riscv/cpu.c | 2 +-
31
target/riscv/cpu.c | 1 +
18
target/riscv/cpu_helper.c | 12 +++++------
32
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
19
target/riscv/csr.c | 42 ++++++++++-----------------------------
33
target/riscv/translate.c | 31 +++++++++++++++----------------
20
target/riscv/machine.c | 8 +++-----
34
5 files changed, 47 insertions(+), 16 deletions(-)
21
target/riscv/translate.c | 4 ++--
22
7 files changed, 23 insertions(+), 72 deletions(-)
23
35
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
36
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
25
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.h
38
--- a/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
39
+++ b/target/riscv/cpu.h
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
40
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
29
target_ulong mie;
41
uint32_t pmu_avail_ctrs;
30
target_ulong mideleg;
42
/* Mapping of events to counters */
31
43
GHashTable *pmu_event_ctr_map;
32
- target_ulong sptbr; /* until: priv-1.9.1 */
44
+ const GPtrArray *decoders;
33
target_ulong satp; /* since: priv-1.10.0 */
45
};
34
- target_ulong sbadaddr;
46
35
- target_ulong mbadaddr;
47
/**
36
+ target_ulong stval;
48
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
37
target_ulong medeleg;
38
39
target_ulong stvec;
40
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
41
index XXXXXXX..XXXXXXX 100644
49
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/cpu_bits.h
50
--- a/target/riscv/tcg/tcg-cpu.h
43
+++ b/target/riscv/cpu_bits.h
51
+++ b/target/riscv/tcg/tcg-cpu.h
44
@@ -XXX,XX +XXX,XX @@
52
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
45
/* 32-bit only */
53
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
46
#define CSR_MSTATUSH 0x310
54
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu);
47
55
48
-/* Legacy Counter Setup (priv v1.9.1) */
56
+struct DisasContext;
49
-/* Update to #define CSR_MCOUNTINHIBIT 0x320 for 1.11.0 */
57
+struct RISCVCPUConfig;
50
-#define CSR_MUCOUNTEREN 0x320
58
+typedef struct RISCVDecoder {
51
-#define CSR_MSCOUNTEREN 0x321
59
+ bool (*guard_func)(const struct RISCVCPUConfig *);
52
-#define CSR_MHCOUNTEREN 0x322
60
+ bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
53
-
61
+} RISCVDecoder;
54
/* Machine Trap Handling */
62
+
55
#define CSR_MSCRATCH 0x340
63
+typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
56
#define CSR_MEPC 0x341
64
+
57
@@ -XXX,XX +XXX,XX @@
65
+extern const size_t decoder_table_size;
58
#define CSR_MTVAL 0x343
66
+
59
#define CSR_MIP 0x344
67
+extern const RISCVDecoder decoder_table[];
60
68
+
61
-/* Legacy Machine Trap Handling (priv v1.9.1) */
69
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu);
62
-#define CSR_MBADADDR 0x343
70
+
63
-
71
#endif
64
/* Supervisor Trap Setup */
65
#define CSR_SSTATUS 0x100
66
#define CSR_SEDELEG 0x102
67
@@ -XXX,XX +XXX,XX @@
68
#define CSR_STVAL 0x143
69
#define CSR_SIP 0x144
70
71
-/* Legacy Supervisor Trap Handling (priv v1.9.1) */
72
-#define CSR_SBADADDR 0x143
73
-
74
/* Supervisor Protection and Translation */
75
#define CSR_SPTBR 0x180
76
#define CSR_SATP 0x180
77
@@ -XXX,XX +XXX,XX @@
78
#define CSR_MHPMCOUNTER30H 0xb9e
79
#define CSR_MHPMCOUNTER31H 0xb9f
80
81
-/* Legacy Machine Protection and Translation (priv v1.9.1) */
82
-#define CSR_MBASE 0x380
83
-#define CSR_MBOUND 0x381
84
-#define CSR_MIBASE 0x382
85
-#define CSR_MIBOUND 0x383
86
-#define CSR_MDBASE 0x384
87
-#define CSR_MDBOUND 0x385
88
-
89
/* mstatus CSR bits */
90
#define MSTATUS_UIE 0x00000001
91
#define MSTATUS_SIE 0x00000002
92
@@ -XXX,XX +XXX,XX @@
93
#define MSTATUS_FS 0x00006000
94
#define MSTATUS_XS 0x00018000
95
#define MSTATUS_MPRV 0x00020000
96
-#define MSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */
97
#define MSTATUS_SUM 0x00040000 /* since: priv-1.10 */
98
#define MSTATUS_MXR 0x00080000
99
-#define MSTATUS_VM 0x1F000000 /* until: priv-1.9.1 */
100
#define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */
101
#define MSTATUS_TW 0x00200000 /* since: priv-1.10 */
102
#define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */
103
@@ -XXX,XX +XXX,XX @@
104
#define SSTATUS_SPP 0x00000100
105
#define SSTATUS_FS 0x00006000
106
#define SSTATUS_XS 0x00018000
107
-#define SSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */
108
#define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */
109
#define SSTATUS_MXR 0x00080000
110
111
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
72
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
112
index XXXXXXX..XXXXXXX 100644
73
index XXXXXXX..XXXXXXX 100644
113
--- a/target/riscv/cpu.c
74
--- a/target/riscv/cpu.c
114
+++ b/target/riscv/cpu.c
75
+++ b/target/riscv/cpu.c
115
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
116
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause);
77
error_propagate(errp, local_err);
78
return;
79
}
80
+ riscv_tcg_cpu_finalize_dynamic_decoder(cpu);
81
} else if (kvm_enabled()) {
82
riscv_kvm_cpu_finalize_features(cpu, &local_err);
83
if (local_err != NULL) {
84
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/tcg/tcg-cpu.c
87
+++ b/target/riscv/tcg/tcg-cpu.c
88
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
117
}
89
}
118
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval);
119
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->sbadaddr);
120
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval);
121
if (riscv_has_ext(env, RVH)) {
122
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
123
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
124
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
125
index XXXXXXX..XXXXXXX 100644
126
--- a/target/riscv/cpu_helper.c
127
+++ b/target/riscv/cpu_helper.c
128
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
129
env->vscause = env->scause;
130
env->scause = env->scause_hs;
131
132
- env->vstval = env->sbadaddr;
133
- env->sbadaddr = env->stval_hs;
134
+ env->vstval = env->stval;
135
+ env->stval = env->stval_hs;
136
137
env->vsatp = env->satp;
138
env->satp = env->satp_hs;
139
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
140
env->scause_hs = env->scause;
141
env->scause = env->vscause;
142
143
- env->stval_hs = env->sbadaddr;
144
- env->sbadaddr = env->vstval;
145
+ env->stval_hs = env->stval;
146
+ env->stval = env->vstval;
147
148
env->satp_hs = env->satp;
149
env->satp = env->vsatp;
150
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
151
env->mstatus = s;
152
env->scause = cause | ((target_ulong)async << (TARGET_LONG_BITS - 1));
153
env->sepc = env->pc;
154
- env->sbadaddr = tval;
155
+ env->stval = tval;
156
env->htval = htval;
157
env->pc = (env->stvec >> 2 << 2) +
158
((async && (env->stvec & 3) == 1) ? cause * 4 : 0);
159
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
160
env->mstatus = s;
161
env->mcause = cause | ~(((target_ulong)-1) >> async);
162
env->mepc = env->pc;
163
- env->mbadaddr = tval;
164
+ env->mtval = tval;
165
env->mtval2 = mtval2;
166
env->pc = (env->mtvec >> 2 << 2) +
167
((async && (env->mtvec & 3) == 1) ? cause * 4 : 0);
168
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
169
index XXXXXXX..XXXXXXX 100644
170
--- a/target/riscv/csr.c
171
+++ b/target/riscv/csr.c
172
@@ -XXX,XX +XXX,XX @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)
173
return 0;
174
}
90
}
175
91
176
-/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */
92
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
177
-static int read_mscounteren(CPURISCVState *env, int csrno, target_ulong *val)
93
+{
178
-{
94
+ GPtrArray *dynamic_decoders;
179
- if (env->priv_ver < PRIV_VERSION_1_11_0) {
95
+ dynamic_decoders = g_ptr_array_sized_new(decoder_table_size);
180
- return -RISCV_EXCP_ILLEGAL_INST;
96
+ for (size_t i = 0; i < decoder_table_size; ++i) {
181
- }
97
+ if (decoder_table[i].guard_func &&
182
- *val = env->mcounteren;
98
+ decoder_table[i].guard_func(&cpu->cfg)) {
183
- return 0;
99
+ g_ptr_array_add(dynamic_decoders,
184
-}
100
+ (gpointer)decoder_table[i].riscv_cpu_decode_fn);
185
-
101
+ }
186
-/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */
102
+ }
187
-static int write_mscounteren(CPURISCVState *env, int csrno, target_ulong val)
103
+
188
-{
104
+ cpu->decoders = dynamic_decoders;
189
- if (env->priv_ver < PRIV_VERSION_1_11_0) {
105
+}
190
- return -RISCV_EXCP_ILLEGAL_INST;
106
+
191
- }
107
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu)
192
- env->mcounteren = val;
193
- return 0;
194
-}
195
-
196
/* Machine Trap Handling */
197
static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val)
198
{
108
{
199
@@ -XXX,XX +XXX,XX @@ static int write_mcause(CPURISCVState *env, int csrno, target_ulong val)
109
return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL;
200
return 0;
201
}
202
203
-static int read_mbadaddr(CPURISCVState *env, int csrno, target_ulong *val)
204
+static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val)
205
{
206
- *val = env->mbadaddr;
207
+ *val = env->mtval;
208
return 0;
209
}
210
211
-static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val)
212
+static int write_mtval(CPURISCVState *env, int csrno, target_ulong val)
213
{
214
- env->mbadaddr = val;
215
+ env->mtval = val;
216
return 0;
217
}
218
219
@@ -XXX,XX +XXX,XX @@ static int write_scause(CPURISCVState *env, int csrno, target_ulong val)
220
return 0;
221
}
222
223
-static int read_sbadaddr(CPURISCVState *env, int csrno, target_ulong *val)
224
+static int read_stval(CPURISCVState *env, int csrno, target_ulong *val)
225
{
226
- *val = env->sbadaddr;
227
+ *val = env->stval;
228
return 0;
229
}
230
231
-static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val)
232
+static int write_stval(CPURISCVState *env, int csrno, target_ulong val)
233
{
234
- env->sbadaddr = val;
235
+ env->stval = val;
236
return 0;
237
}
238
239
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
240
241
[CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush },
242
243
- [CSR_MSCOUNTEREN] = { "msounteren", any, read_mscounteren, write_mscounteren },
244
-
245
/* Machine Trap Handling */
246
[CSR_MSCRATCH] = { "mscratch", any, read_mscratch, write_mscratch },
247
[CSR_MEPC] = { "mepc", any, read_mepc, write_mepc },
248
[CSR_MCAUSE] = { "mcause", any, read_mcause, write_mcause },
249
- [CSR_MBADADDR] = { "mbadaddr", any, read_mbadaddr, write_mbadaddr },
250
+ [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval },
251
[CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip },
252
253
/* Supervisor Trap Setup */
254
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
255
[CSR_SSCRATCH] = { "sscratch", smode, read_sscratch, write_sscratch },
256
[CSR_SEPC] = { "sepc", smode, read_sepc, write_sepc },
257
[CSR_SCAUSE] = { "scause", smode, read_scause, write_scause },
258
- [CSR_SBADADDR] = { "sbadaddr", smode, read_sbadaddr, write_sbadaddr },
259
+ [CSR_STVAL] = { "stval", smode, read_stval, write_stval },
260
[CSR_SIP] = { "sip", smode, NULL, NULL, rmw_sip },
261
262
/* Supervisor Protection and Translation */
263
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
264
index XXXXXXX..XXXXXXX 100644
265
--- a/target/riscv/machine.c
266
+++ b/target/riscv/machine.c
267
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_hyper = {
268
269
const VMStateDescription vmstate_riscv_cpu = {
270
.name = "cpu",
271
- .version_id = 1,
272
- .minimum_version_id = 1,
273
+ .version_id = 2,
274
+ .minimum_version_id = 2,
275
.fields = (VMStateField[]) {
276
VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32),
277
VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32),
278
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
279
VMSTATE_UINT32(env.miclaim, RISCVCPU),
280
VMSTATE_UINTTL(env.mie, RISCVCPU),
281
VMSTATE_UINTTL(env.mideleg, RISCVCPU),
282
- VMSTATE_UINTTL(env.sptbr, RISCVCPU),
283
VMSTATE_UINTTL(env.satp, RISCVCPU),
284
- VMSTATE_UINTTL(env.sbadaddr, RISCVCPU),
285
- VMSTATE_UINTTL(env.mbadaddr, RISCVCPU),
286
+ VMSTATE_UINTTL(env.stval, RISCVCPU),
287
VMSTATE_UINTTL(env.medeleg, RISCVCPU),
288
VMSTATE_UINTTL(env.stvec, RISCVCPU),
289
VMSTATE_UINTTL(env.sepc, RISCVCPU),
290
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
110
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
291
index XXXXXXX..XXXXXXX 100644
111
index XXXXXXX..XXXXXXX 100644
292
--- a/target/riscv/translate.c
112
--- a/target/riscv/translate.c
293
+++ b/target/riscv/translate.c
113
+++ b/target/riscv/translate.c
294
@@ -XXX,XX +XXX,XX @@ static void generate_exception(DisasContext *ctx, int excp)
114
@@ -XXX,XX +XXX,XX @@
295
ctx->base.is_jmp = DISAS_NORETURN;
115
#include "exec/helper-info.c.inc"
116
#undef HELPER_H
117
118
+#include "tcg/tcg-cpu.h"
119
+
120
/* global register indices */
121
static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart;
122
static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
123
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
124
/* FRM is known to contain a valid value. */
125
bool frm_valid;
126
bool insn_start_updated;
127
+ const GPtrArray *decoders;
128
} DisasContext;
129
130
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
131
@@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word)
132
return (first_word & 3) == 3 ? 4 : 2;
296
}
133
}
297
134
298
-static void generate_exception_mbadaddr(DisasContext *ctx, int excp)
135
+const RISCVDecoder decoder_table[] = {
299
+static void generate_exception_mtval(DisasContext *ctx, int excp)
136
+ { always_true_p, decode_insn32 },
137
+ { has_xthead_p, decode_xthead},
138
+ { has_XVentanaCondOps_p, decode_XVentanaCodeOps},
139
+};
140
+
141
+const size_t decoder_table_size = ARRAY_SIZE(decoder_table);
142
+
143
static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
300
{
144
{
301
tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
145
- /*
302
tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr));
146
- * A table with predicate (i.e., guard) functions and decoder functions
303
@@ -XXX,XX +XXX,XX @@ static void gen_exception_illegal(DisasContext *ctx)
147
- * that are tested in-order until a decoder matches onto the opcode.
304
148
- */
305
static void gen_exception_inst_addr_mis(DisasContext *ctx)
149
- static const struct {
306
{
150
- bool (*guard_func)(const RISCVCPUConfig *);
307
- generate_exception_mbadaddr(ctx, RISCV_EXCP_INST_ADDR_MIS);
151
- bool (*decode_func)(DisasContext *, uint32_t);
308
+ generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS);
152
- } decoders[] = {
153
- { always_true_p, decode_insn32 },
154
- { has_xthead_p, decode_xthead },
155
- { has_XVentanaCondOps_p, decode_XVentanaCodeOps },
156
- };
157
-
158
ctx->virt_inst_excp = false;
159
ctx->cur_insn_len = insn_len(opcode);
160
/* Check for compressed insn */
161
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
162
ctx->base.pc_next + 2));
163
ctx->opcode = opcode32;
164
165
- for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) {
166
- if (decoders[i].guard_func(ctx->cfg_ptr) &&
167
- decoders[i].decode_func(ctx, opcode32)) {
168
+ for (guint i = 0; i < ctx->decoders->len; ++i) {
169
+ riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i);
170
+ if (func(ctx, opcode32)) {
171
return;
172
}
173
}
174
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
175
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
176
ctx->zero = tcg_constant_tl(0);
177
ctx->virt_inst_excp = false;
178
+ ctx->decoders = cpu->decoders;
309
}
179
}
310
180
311
static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
181
static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
312
--
182
--
313
2.31.1
183
2.45.1
314
315
diff view generated by jsdifflib
Deleted patch
1
From: Axel Heider <axelheider@gmx.de>
2
1
3
Fix style to have a proper description of the parameter 'force-raw'.
4
5
Signed-off-by: Axel Heider <axelheider@gmx.de>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Message-id: a7e50a64-1c7c-2d41-96d3-d8a417a659ac@gmx.de
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
10
docs/system/generic-loader.rst | 9 ++++++---
11
1 file changed, 6 insertions(+), 3 deletions(-)
12
13
diff --git a/docs/system/generic-loader.rst b/docs/system/generic-loader.rst
14
index XXXXXXX..XXXXXXX 100644
15
--- a/docs/system/generic-loader.rst
16
+++ b/docs/system/generic-loader.rst
17
@@ -XXX,XX +XXX,XX @@ shown below:
18
specified in the executable format header. This option should only
19
be used for the boot image. This will also cause the image to be
20
written to the specified CPU's address space. If not specified, the
21
- default is CPU 0. <force-raw> - Setting force-raw=on forces the file
22
- to be treated as a raw image. This can be used to load supported
23
- executable formats as if they were raw.
24
+ default is CPU 0.
25
+
26
+``<force-raw>``
27
+ Setting 'force-raw=on' forces the file to be treated as a raw image.
28
+ This can be used to load supported executable formats as if they
29
+ were raw.
30
31
All values are parsed using the standard QemuOpts parsing. This allows the user
32
to specify any values in any format supported. By default the values
33
--
34
2.31.1
35
36
diff view generated by jsdifflib
1
From: Vijai Kumar K <vijai@behindbytes.com>
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
2
3
Add support for emulating Shakti reference platform based on C-class
3
The th.sxstatus CSR can be used to identify available custom extension
4
running on arty-100T board.
4
on T-Head CPUs. The CSR is documented here:
5
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc
5
6
6
https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/README.rst
7
An important property of this patch is, that the th.sxstatus MAEE field
8
is not set (indicating that XTheadMae is not available).
9
XTheadMae is a memory attribute extension (similar to Svpbmt) which is
10
implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits
11
in PTEs that are marked as reserved. QEMU maintainers prefer to not
12
implement XTheadMae, so we need give kernels a mechanism to identify
13
if XTheadMae is available in a system or not. And this patch introduces
14
this mechanism in QEMU in a way that's compatible with real HW
15
(i.e., probing the th.sxstatus.MAEE bit).
7
16
8
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
17
Further context can be found on the list:
18
https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html
19
20
Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210401181457.73039-3-vijai@behindbytes.com
22
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
23
Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
25
---
13
default-configs/devices/riscv64-softmmu.mak | 1 +
26
MAINTAINERS | 1 +
14
include/hw/riscv/shakti_c.h | 73 +++++++++
27
target/riscv/cpu.h | 3 ++
15
hw/riscv/shakti_c.c | 170 ++++++++++++++++++++
28
target/riscv/cpu.c | 1 +
16
MAINTAINERS | 7 +
29
target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++
17
hw/riscv/Kconfig | 10 ++
30
target/riscv/meson.build | 1 +
18
hw/riscv/meson.build | 1 +
31
5 files changed, 85 insertions(+)
19
6 files changed, 262 insertions(+)
32
create mode 100644 target/riscv/th_csr.c
20
create mode 100644 include/hw/riscv/shakti_c.h
21
create mode 100644 hw/riscv/shakti_c.c
22
33
23
diff --git a/default-configs/devices/riscv64-softmmu.mak b/default-configs/devices/riscv64-softmmu.mak
34
diff --git a/MAINTAINERS b/MAINTAINERS
24
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
25
--- a/default-configs/devices/riscv64-softmmu.mak
36
--- a/MAINTAINERS
26
+++ b/default-configs/devices/riscv64-softmmu.mak
37
+++ b/MAINTAINERS
27
@@ -XXX,XX +XXX,XX @@ CONFIG_SIFIVE_E=y
38
@@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org
28
CONFIG_SIFIVE_U=y
39
S: Supported
29
CONFIG_RISCV_VIRT=y
40
F: target/riscv/insn_trans/trans_xthead.c.inc
30
CONFIG_MICROCHIP_PFSOC=y
41
F: target/riscv/xthead*.decode
31
+CONFIG_SHAKTI_C=y
42
+F: target/riscv/th_*
32
diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h
43
F: disas/riscv-xthead*
44
45
RISC-V XVentanaCondOps extension
46
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/cpu.h
49
+++ b/target/riscv/cpu.h
50
@@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value,
51
uint8_t satp_mode_max_from_map(uint32_t map);
52
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
53
54
+/* Implemented in th_csr.c */
55
+void th_register_custom_csrs(RISCVCPU *cpu);
56
+
57
#endif /* RISCV_CPU_H */
58
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/target/riscv/cpu.c
61
+++ b/target/riscv/cpu.c
62
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
63
cpu->cfg.mvendorid = THEAD_VENDOR_ID;
64
#ifndef CONFIG_USER_ONLY
65
set_satp_mode_max_supported(cpu, VM_1_10_SV39);
66
+ th_register_custom_csrs(cpu);
67
#endif
68
69
/* inherited from parent obj via riscv_cpu_init() */
70
diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c
33
new file mode 100644
71
new file mode 100644
34
index XXXXXXX..XXXXXXX
72
index XXXXXXX..XXXXXXX
35
--- /dev/null
73
--- /dev/null
36
+++ b/include/hw/riscv/shakti_c.h
74
+++ b/target/riscv/th_csr.c
37
@@ -XXX,XX +XXX,XX @@
75
@@ -XXX,XX +XXX,XX @@
38
+/*
76
+/*
39
+ * Shakti C-class SoC emulation
77
+ * T-Head-specific CSRs.
40
+ *
78
+ *
41
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
79
+ * Copyright (c) 2024 VRULL GmbH
42
+ *
43
+ * This program is free software; you can redistribute it and/or modify it
44
+ * under the terms and conditions of the GNU General Public License,
45
+ * version 2 or later, as published by the Free Software Foundation.
46
+ *
47
+ * This program is distributed in the hope it will be useful, but WITHOUT
48
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
50
+ * more details.
51
+ *
52
+ * You should have received a copy of the GNU General Public License along with
53
+ * this program. If not, see <http://www.gnu.org/licenses/>.
54
+ */
55
+
56
+#ifndef HW_SHAKTI_H
57
+#define HW_SHAKTI_H
58
+
59
+#include "hw/riscv/riscv_hart.h"
60
+#include "hw/boards.h"
61
+
62
+#define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc"
63
+#define RISCV_SHAKTI_SOC(obj) \
64
+ OBJECT_CHECK(ShaktiCSoCState, (obj), TYPE_RISCV_SHAKTI_SOC)
65
+
66
+typedef struct ShaktiCSoCState {
67
+ /*< private >*/
68
+ DeviceState parent_obj;
69
+
70
+ /*< public >*/
71
+ RISCVHartArrayState cpus;
72
+ DeviceState *plic;
73
+ MemoryRegion rom;
74
+
75
+} ShaktiCSoCState;
76
+
77
+#define TYPE_RISCV_SHAKTI_MACHINE MACHINE_TYPE_NAME("shakti_c")
78
+#define RISCV_SHAKTI_MACHINE(obj) \
79
+ OBJECT_CHECK(ShaktiCMachineState, (obj), TYPE_RISCV_SHAKTI_MACHINE)
80
+typedef struct ShaktiCMachineState {
81
+ /*< private >*/
82
+ MachineState parent_obj;
83
+
84
+ /*< public >*/
85
+ ShaktiCSoCState soc;
86
+} ShaktiCMachineState;
87
+
88
+enum {
89
+ SHAKTI_C_ROM,
90
+ SHAKTI_C_RAM,
91
+ SHAKTI_C_UART,
92
+ SHAKTI_C_GPIO,
93
+ SHAKTI_C_PLIC,
94
+ SHAKTI_C_CLINT,
95
+ SHAKTI_C_I2C,
96
+};
97
+
98
+#define SHAKTI_C_PLIC_HART_CONFIG "MS"
99
+/* Including Interrupt ID 0 (no interrupt)*/
100
+#define SHAKTI_C_PLIC_NUM_SOURCES 28
101
+/* Excluding Priority 0 */
102
+#define SHAKTI_C_PLIC_NUM_PRIORITIES 2
103
+#define SHAKTI_C_PLIC_PRIORITY_BASE 0x04
104
+#define SHAKTI_C_PLIC_PENDING_BASE 0x1000
105
+#define SHAKTI_C_PLIC_ENABLE_BASE 0x2000
106
+#define SHAKTI_C_PLIC_ENABLE_STRIDE 0x80
107
+#define SHAKTI_C_PLIC_CONTEXT_BASE 0x200000
108
+#define SHAKTI_C_PLIC_CONTEXT_STRIDE 0x1000
109
+
110
+#endif
111
diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c
112
new file mode 100644
113
index XXXXXXX..XXXXXXX
114
--- /dev/null
115
+++ b/hw/riscv/shakti_c.c
116
@@ -XXX,XX +XXX,XX @@
117
+/*
118
+ * Shakti C-class SoC emulation
119
+ *
120
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
121
+ *
80
+ *
122
+ * This program is free software; you can redistribute it and/or modify it
81
+ * This program is free software; you can redistribute it and/or modify it
123
+ * under the terms and conditions of the GNU General Public License,
82
+ * under the terms and conditions of the GNU General Public License,
124
+ * version 2 or later, as published by the Free Software Foundation.
83
+ * version 2 or later, as published by the Free Software Foundation.
125
+ *
84
+ *
...
...
131
+ * You should have received a copy of the GNU General Public License along with
90
+ * You should have received a copy of the GNU General Public License along with
132
+ * this program. If not, see <http://www.gnu.org/licenses/>.
91
+ * this program. If not, see <http://www.gnu.org/licenses/>.
133
+ */
92
+ */
134
+
93
+
135
+#include "qemu/osdep.h"
94
+#include "qemu/osdep.h"
136
+#include "hw/boards.h"
95
+#include "cpu.h"
137
+#include "hw/riscv/shakti_c.h"
96
+#include "cpu_vendorid.h"
138
+#include "qapi/error.h"
139
+#include "hw/intc/sifive_plic.h"
140
+#include "hw/intc/sifive_clint.h"
141
+#include "sysemu/sysemu.h"
142
+#include "hw/qdev-properties.h"
143
+#include "exec/address-spaces.h"
144
+#include "hw/riscv/boot.h"
145
+
97
+
98
+#define CSR_TH_SXSTATUS 0x5c0
146
+
99
+
147
+static const struct MemmapEntry {
100
+/* TH_SXSTATUS bits */
148
+ hwaddr base;
101
+#define TH_SXSTATUS_UCME BIT(16)
149
+ hwaddr size;
102
+#define TH_SXSTATUS_MAEE BIT(21)
150
+} shakti_c_memmap[] = {
103
+#define TH_SXSTATUS_THEADISAEE BIT(22)
151
+ [SHAKTI_C_ROM] = { 0x00001000, 0x2000 },
104
+
152
+ [SHAKTI_C_RAM] = { 0x80000000, 0x0 },
105
+typedef struct {
153
+ [SHAKTI_C_UART] = { 0x00011300, 0x00040 },
106
+ int csrno;
154
+ [SHAKTI_C_GPIO] = { 0x020d0000, 0x00100 },
107
+ int (*insertion_test)(RISCVCPU *cpu);
155
+ [SHAKTI_C_PLIC] = { 0x0c000000, 0x20000 },
108
+ riscv_csr_operations csr_ops;
156
+ [SHAKTI_C_CLINT] = { 0x02000000, 0xc0000 },
109
+} riscv_csr;
157
+ [SHAKTI_C_I2C] = { 0x20c00000, 0x00100 },
110
+
111
+static RISCVException smode(CPURISCVState *env, int csrno)
112
+{
113
+ if (riscv_has_ext(env, RVS)) {
114
+ return RISCV_EXCP_NONE;
115
+ }
116
+
117
+ return RISCV_EXCP_ILLEGAL_INST;
118
+}
119
+
120
+static int test_thead_mvendorid(RISCVCPU *cpu)
121
+{
122
+ if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) {
123
+ return -1;
124
+ }
125
+
126
+ return 0;
127
+}
128
+
129
+static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno,
130
+ target_ulong *val)
131
+{
132
+ /* We don't set MAEE here, because QEMU does not implement MAEE. */
133
+ *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE;
134
+ return RISCV_EXCP_NONE;
135
+}
136
+
137
+static riscv_csr th_csr_list[] = {
138
+ {
139
+ .csrno = CSR_TH_SXSTATUS,
140
+ .insertion_test = test_thead_mvendorid,
141
+ .csr_ops = { "th.sxstatus", smode, read_th_sxstatus }
142
+ }
158
+};
143
+};
159
+
144
+
160
+static void shakti_c_machine_state_init(MachineState *mstate)
145
+void th_register_custom_csrs(RISCVCPU *cpu)
161
+{
146
+{
162
+ ShaktiCMachineState *sms = RISCV_SHAKTI_MACHINE(mstate);
147
+ for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) {
163
+ MemoryRegion *system_memory = get_system_memory();
148
+ int csrno = th_csr_list[i].csrno;
164
+ MemoryRegion *main_mem = g_new(MemoryRegion, 1);
149
+ riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops;
165
+
150
+ if (!th_csr_list[i].insertion_test(cpu)) {
166
+ /* Allow only Shakti C CPU for this platform */
151
+ riscv_set_csr_ops(csrno, csr_ops);
167
+ if (strcmp(mstate->cpu_type, TYPE_RISCV_CPU_SHAKTI_C) != 0) {
152
+ }
168
+ error_report("This board can only be used with Shakti C CPU");
169
+ exit(1);
170
+ }
153
+ }
171
+
172
+ /* Initialize SoC */
173
+ object_initialize_child(OBJECT(mstate), "soc", &sms->soc,
174
+ TYPE_RISCV_SHAKTI_SOC);
175
+ qdev_realize(DEVICE(&sms->soc), NULL, &error_abort);
176
+
177
+ /* register RAM */
178
+ memory_region_init_ram(main_mem, NULL, "riscv.shakti.c.ram",
179
+ mstate->ram_size, &error_fatal);
180
+ memory_region_add_subregion(system_memory,
181
+ shakti_c_memmap[SHAKTI_C_RAM].base,
182
+ main_mem);
183
+
184
+ /* ROM reset vector */
185
+ riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus,
186
+ shakti_c_memmap[SHAKTI_C_RAM].base,
187
+ shakti_c_memmap[SHAKTI_C_ROM].base,
188
+ shakti_c_memmap[SHAKTI_C_ROM].size, 0, 0,
189
+ NULL);
190
+ riscv_load_firmware(mstate->firmware, shakti_c_memmap[SHAKTI_C_RAM].base,
191
+ NULL);
192
+}
154
+}
193
+
155
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
194
+static void shakti_c_machine_instance_init(Object *obj)
195
+{
196
+}
197
+
198
+static void shakti_c_machine_class_init(ObjectClass *klass, void *data)
199
+{
200
+ MachineClass *mc = MACHINE_CLASS(klass);
201
+ mc->desc = "RISC-V Board compatible with Shakti SDK";
202
+ mc->init = shakti_c_machine_state_init;
203
+ mc->default_cpu_type = TYPE_RISCV_CPU_SHAKTI_C;
204
+}
205
+
206
+static const TypeInfo shakti_c_machine_type_info = {
207
+ .name = TYPE_RISCV_SHAKTI_MACHINE,
208
+ .parent = TYPE_MACHINE,
209
+ .class_init = shakti_c_machine_class_init,
210
+ .instance_init = shakti_c_machine_instance_init,
211
+ .instance_size = sizeof(ShaktiCMachineState),
212
+};
213
+
214
+static void shakti_c_machine_type_info_register(void)
215
+{
216
+ type_register_static(&shakti_c_machine_type_info);
217
+}
218
+type_init(shakti_c_machine_type_info_register)
219
+
220
+static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)
221
+{
222
+ ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(dev);
223
+ MemoryRegion *system_memory = get_system_memory();
224
+
225
+ sysbus_realize(SYS_BUS_DEVICE(&sss->cpus), &error_abort);
226
+
227
+ sss->plic = sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base,
228
+ (char *)SHAKTI_C_PLIC_HART_CONFIG, 0,
229
+ SHAKTI_C_PLIC_NUM_SOURCES,
230
+ SHAKTI_C_PLIC_NUM_PRIORITIES,
231
+ SHAKTI_C_PLIC_PRIORITY_BASE,
232
+ SHAKTI_C_PLIC_PENDING_BASE,
233
+ SHAKTI_C_PLIC_ENABLE_BASE,
234
+ SHAKTI_C_PLIC_ENABLE_STRIDE,
235
+ SHAKTI_C_PLIC_CONTEXT_BASE,
236
+ SHAKTI_C_PLIC_CONTEXT_STRIDE,
237
+ shakti_c_memmap[SHAKTI_C_PLIC].size);
238
+
239
+ sifive_clint_create(shakti_c_memmap[SHAKTI_C_CLINT].base,
240
+ shakti_c_memmap[SHAKTI_C_CLINT].size, 0, 1,
241
+ SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
242
+ SIFIVE_CLINT_TIMEBASE_FREQ, false);
243
+
244
+ /* ROM */
245
+ memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom",
246
+ shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal);
247
+ memory_region_add_subregion(system_memory,
248
+ shakti_c_memmap[SHAKTI_C_ROM].base, &sss->rom);
249
+}
250
+
251
+static void shakti_c_soc_class_init(ObjectClass *klass, void *data)
252
+{
253
+ DeviceClass *dc = DEVICE_CLASS(klass);
254
+ dc->realize = shakti_c_soc_state_realize;
255
+}
256
+
257
+static void shakti_c_soc_instance_init(Object *obj)
258
+{
259
+ ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj);
260
+
261
+ object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY);
262
+
263
+ /*
264
+ * CPU type is fixed and we are not supporting passing from commandline yet.
265
+ * So let it be in instance_init. When supported should use ms->cpu_type
266
+ * instead of TYPE_RISCV_CPU_SHAKTI_C
267
+ */
268
+ object_property_set_str(OBJECT(&sss->cpus), "cpu-type",
269
+ TYPE_RISCV_CPU_SHAKTI_C, &error_abort);
270
+ object_property_set_int(OBJECT(&sss->cpus), "num-harts", 1,
271
+ &error_abort);
272
+}
273
+
274
+static const TypeInfo shakti_c_type_info = {
275
+ .name = TYPE_RISCV_SHAKTI_SOC,
276
+ .parent = TYPE_DEVICE,
277
+ .class_init = shakti_c_soc_class_init,
278
+ .instance_init = shakti_c_soc_instance_init,
279
+ .instance_size = sizeof(ShaktiCSoCState),
280
+};
281
+
282
+static void shakti_c_type_info_register(void)
283
+{
284
+ type_register_static(&shakti_c_type_info);
285
+}
286
+type_init(shakti_c_type_info_register)
287
diff --git a/MAINTAINERS b/MAINTAINERS
288
index XXXXXXX..XXXXXXX 100644
156
index XXXXXXX..XXXXXXX 100644
289
--- a/MAINTAINERS
157
--- a/target/riscv/meson.build
290
+++ b/MAINTAINERS
158
+++ b/target/riscv/meson.build
291
@@ -XXX,XX +XXX,XX @@ F: include/hw/misc/mchp_pfsoc_dmc.h
159
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
292
F: include/hw/misc/mchp_pfsoc_ioscb.h
160
'monitor.c',
293
F: include/hw/misc/mchp_pfsoc_sysreg.h
161
'machine.c',
294
162
'pmu.c',
295
+Shakti C class SoC
163
+ 'th_csr.c',
296
+M: Vijai Kumar K <vijai@behindbytes.com>
164
'time_helper.c',
297
+L: qemu-riscv@nongnu.org
165
'riscv-qmp-cmds.c',
298
+S: Supported
166
))
299
+F: hw/riscv/shakti_c.c
300
+F: include/hw/riscv/shakti_c.h
301
+
302
SiFive Machines
303
M: Alistair Francis <Alistair.Francis@wdc.com>
304
M: Bin Meng <bin.meng@windriver.com>
305
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
306
index XXXXXXX..XXXXXXX 100644
307
--- a/hw/riscv/Kconfig
308
+++ b/hw/riscv/Kconfig
309
@@ -XXX,XX +XXX,XX @@ config OPENTITAN
310
select IBEX
311
select UNIMP
312
313
+config SHAKTI
314
+ bool
315
+
316
+config SHAKTI_C
317
+ bool
318
+ select UNIMP
319
+ select SHAKTI
320
+ select SIFIVE_CLINT
321
+ select SIFIVE_PLIC
322
+
323
config RISCV_VIRT
324
bool
325
imply PCI_DEVICES
326
diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build
327
index XXXXXXX..XXXXXXX 100644
328
--- a/hw/riscv/meson.build
329
+++ b/hw/riscv/meson.build
330
@@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c'))
331
riscv_ss.add(files('riscv_hart.c'))
332
riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c'))
333
riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c'))
334
+riscv_ss.add(when: 'CONFIG_SHAKTI_C', if_true: files('shakti_c.c'))
335
riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c'))
336
riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c'))
337
riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c'))
338
--
167
--
339
2.31.1
168
2.45.1
340
169
341
170
diff view generated by jsdifflib
1
This also ensures that the SD bit is not writable.
1
From: Max Chou <max.chou@sifive.com>
2
2
3
According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w
4
instructions will be affected by Zvfhmin extension.
5
And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the
6
conversions of
7
8
* From 1*SEW(16/32) to 2*SEW(32/64)
9
* From 2*SEW(32/64) to 1*SEW(16/32)
10
11
Signed-off-by: Max Chou <max.chou@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-2-max.chou@sifive.com>
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
6
Message-id: 9ea842309f0fd7adff172790f5b5fc058b40f2f1.1619234854.git.alistair.francis@wdc.com
7
---
16
---
8
target/riscv/cpu_bits.h | 6 ------
17
target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++--
9
target/riscv/csr.c | 9 ++++++++-
18
1 file changed, 18 insertions(+), 2 deletions(-)
10
2 files changed, 8 insertions(+), 7 deletions(-)
11
19
12
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
13
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
14
--- a/target/riscv/cpu_bits.h
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
15
+++ b/target/riscv/cpu_bits.h
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
16
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s)
17
#define SSTATUS32_SD 0x80000000
25
}
18
#define SSTATUS64_SD 0x8000000000000000ULL
26
}
19
27
20
-#if defined(TARGET_RISCV32)
28
+static bool require_rvfmin(DisasContext *s)
21
-#define SSTATUS_SD SSTATUS32_SD
29
+{
22
-#elif defined(TARGET_RISCV64)
30
+ if (s->mstatus_fs == EXT_STATUS_DISABLED) {
23
-#define SSTATUS_SD SSTATUS64_SD
31
+ return false;
24
-#endif
25
-
26
/* hstatus CSR bits */
27
#define HSTATUS_VSBE 0x00000020
28
#define HSTATUS_GVA 0x00000040
29
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/csr.c
32
+++ b/target/riscv/csr.c
33
@@ -XXX,XX +XXX,XX @@ static const target_ulong delegable_excps =
34
(1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT));
35
static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
36
SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
37
- SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD;
38
+ SSTATUS_SUM | SSTATUS_MXR;
39
static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP;
40
static const target_ulong hip_writable_mask = MIP_VSSIP;
41
static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
42
@@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno,
43
target_ulong *val)
44
{
45
target_ulong mask = (sstatus_v1_10_mask);
46
+
47
+ if (riscv_cpu_is_32bit(env)) {
48
+ mask |= SSTATUS32_SD;
49
+ } else {
50
+ mask |= SSTATUS64_SD;
51
+ }
32
+ }
52
+
33
+
53
*val = env->mstatus & mask;
34
+ switch (s->sew) {
54
return RISCV_EXCP_NONE;
35
+ case MO_16:
36
+ return s->cfg_ptr->ext_zvfhmin;
37
+ case MO_32:
38
+ return s->cfg_ptr->ext_zve32f;
39
+ default:
40
+ return false;
41
+ }
42
+}
43
+
44
static bool require_scale_rvf(DisasContext *s)
45
{
46
if (s->mstatus_fs == EXT_STATUS_DISABLED) {
47
@@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s)
48
}
49
50
switch (s->sew) {
51
- case MO_8:
52
- return s->cfg_ptr->ext_zvfhmin;
53
case MO_16:
54
return s->cfg_ptr->ext_zve32f;
55
case MO_32:
56
@@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a)
57
static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
58
{
59
return opfv_widen_check(s, a) &&
60
+ require_rvfmin(s) &&
61
require_scale_rvfmin(s) &&
62
(s->sew != MO_8);
63
}
64
@@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a)
65
static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
66
{
67
return opfv_narrow_check(s, a) &&
68
+ require_rvfmin(s) &&
69
require_scale_rvfmin(s) &&
70
(s->sew != MO_8);
55
}
71
}
56
--
72
--
57
2.31.1
73
2.45.1
58
59
diff view generated by jsdifflib
1
From: Frank Chang <frank.chang@sifive.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
ETYPE may be type of uint64_t, thus index variable has to be declared as
3
The require_scale_rvf function only checks the double width operator for
4
type of uint64_t, too. Otherwise the value read from vs1 register may be
4
the vector floating point widen instructions, so most of the widen
5
truncated to type of uint32_t.
5
checking functions need to add require_rvf for single width operator.
6
6
7
Signed-off-by: Frank Chang <frank.chang@sifive.com>
7
The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
integer to double width float, so the opfxv_widen_check function doesn’t
9
Message-id: 20210419060302.14075-1-frank.chang@sifive.com
9
need require_rvf for the single width operator(integer).
10
11
Signed-off-by: Max Chou <max.chou@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-3-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
16
---
12
target/riscv/vector_helper.c | 6 ++++--
17
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++
13
1 file changed, 4 insertions(+), 2 deletions(-)
18
1 file changed, 5 insertions(+)
14
19
15
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/vector_helper.c
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/vector_helper.c
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
@@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \
24
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check)
20
uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \
25
static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
21
uint32_t vm = vext_vm(desc); \
26
{
22
uint32_t vl = env->vl; \
27
return require_rvv(s) &&
23
- uint32_t index, i; \
28
+ require_rvf(s) &&
24
+ uint64_t index; \
29
require_scale_rvf(s) &&
25
+ uint32_t i; \
30
(s->sew != MO_8) &&
26
\
31
vext_check_isa_ill(s) &&
27
for (i = 0; i < vl; i++) { \
32
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check)
28
if (!vm && !vext_elem_mask(v0, mlen, i)) { \
33
static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
29
@@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \
34
{
30
uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \
35
return require_rvv(s) &&
31
uint32_t vm = vext_vm(desc); \
36
+ require_rvf(s) &&
32
uint32_t vl = env->vl; \
37
require_scale_rvf(s) &&
33
- uint32_t index = s1, i; \
38
(s->sew != MO_8) &&
34
+ uint64_t index = s1; \
39
vext_check_isa_ill(s) &&
35
+ uint32_t i; \
40
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf)
36
\
41
static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
37
for (i = 0; i < vl; i++) { \
42
{
38
if (!vm && !vext_elem_mask(v0, mlen, i)) { \
43
return require_rvv(s) &&
44
+ require_rvf(s) &&
45
require_scale_rvf(s) &&
46
(s->sew != MO_8) &&
47
vext_check_isa_ill(s) &&
48
@@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv)
49
static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
50
{
51
return require_rvv(s) &&
52
+ require_rvf(s) &&
53
require_scale_rvf(s) &&
54
(s->sew != MO_8) &&
55
vext_check_isa_ill(s) &&
56
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check)
57
static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
58
{
59
return reduction_widen_check(s, a) &&
60
+ require_rvf(s) &&
61
require_scale_rvf(s) &&
62
(s->sew != MO_8);
63
}
39
--
64
--
40
2.31.1
65
2.45.1
41
66
42
67
diff view generated by jsdifflib
1
The physical Ibex CPU has ePMP support and it's enabled for the
1
From: Max Chou <max.chou@sifive.com>
2
OpenTitan machine so let's enable ePMP support for the Ibex CPU in QEMU.
3
2
3
The opfv_narrow_check needs to check the single width float operator by
4
require_rvf.
5
6
Signed-off-by: Max Chou <max.chou@sifive.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Message-ID: <20240322092600.1198921-4-max.chou@sifive.com>
4
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
6
Message-id: d426baabab0c9361ed2e989dbe416e417a551fd1.1618812899.git.alistair.francis@wdc.com
7
---
11
---
8
target/riscv/cpu.c | 1 +
12
target/riscv/insn_trans/trans_rvv.c.inc | 1 +
9
1 file changed, 1 insertion(+)
13
1 file changed, 1 insertion(+)
10
14
11
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
12
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/cpu.c
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
14
+++ b/target/riscv/cpu.c
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
15
@@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj)
19
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
16
set_misa(env, RV32 | RVI | RVM | RVC | RVU);
20
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
17
set_priv_version(env, PRIV_VERSION_1_10_0);
21
{
18
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
22
return opfv_narrow_check(s, a) &&
19
+ qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
23
+ require_rvf(s) &&
24
require_scale_rvf(s) &&
25
(s->sew != MO_8);
20
}
26
}
21
22
static void rv32_imafcu_nommu_cpu_init(Object *obj)
23
--
27
--
24
2.31.1
28
2.45.1
25
26
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
2
3
If the checking functions check both the single and double width
4
operators at the same time, then the single width operator checking
5
functions (require_rvf[min]) will check whether the SEW is 8.
6
7
Signed-off-by: Max Chou <max.chou@sifive.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Message-ID: <20240322092600.1198921-5-max.chou@sifive.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: 8566c4c271723f27f3ae8fc2429f906a459f17ce.1617290165.git.alistair.francis@wdc.com
5
---
12
---
6
target/riscv/cpu.h | 14 +-
13
target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------
7
target/riscv/csr.c | 629 +++++++++++++++++++++++++++------------------
14
1 file changed, 4 insertions(+), 12 deletions(-)
8
2 files changed, 382 insertions(+), 261 deletions(-)
9
15
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
11
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/cpu.h
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
13
+++ b/target/riscv/cpu.h
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
14
@@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
20
@@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
15
21
return require_rvv(s) &&
16
typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
22
require_rvf(s) &&
17
int csrno);
23
require_scale_rvf(s) &&
18
-typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
24
- (s->sew != MO_8) &&
19
- target_ulong *ret_value);
25
vext_check_isa_ill(s) &&
20
-typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
26
vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm);
21
- target_ulong new_value);
27
}
22
-typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
28
@@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
23
- target_ulong *ret_value, target_ulong new_value, target_ulong write_mask);
29
return require_rvv(s) &&
24
+typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
30
require_rvf(s) &&
25
+ target_ulong *ret_value);
31
require_scale_rvf(s) &&
26
+typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
32
- (s->sew != MO_8) &&
27
+ target_ulong new_value);
33
vext_check_isa_ill(s) &&
28
+typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
34
vext_check_ds(s, a->rd, a->rs2, a->vm);
29
+ target_ulong *ret_value,
35
}
30
+ target_ulong new_value,
36
@@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
31
+ target_ulong write_mask);
37
return require_rvv(s) &&
32
38
require_rvf(s) &&
33
typedef struct {
39
require_scale_rvf(s) &&
34
const char *name;
40
- (s->sew != MO_8) &&
35
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
41
vext_check_isa_ill(s) &&
36
index XXXXXXX..XXXXXXX 100644
42
vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm);
37
--- a/target/riscv/csr.c
43
}
38
+++ b/target/riscv/csr.c
44
@@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
39
@@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno)
45
return require_rvv(s) &&
40
#endif
46
require_rvf(s) &&
41
47
require_scale_rvf(s) &&
42
/* User Floating-Point CSRs */
48
- (s->sew != MO_8) &&
43
-static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val)
49
vext_check_isa_ill(s) &&
44
+static RISCVException read_fflags(CPURISCVState *env, int csrno,
50
vext_check_dd(s, a->rd, a->rs2, a->vm);
45
+ target_ulong *val)
51
}
52
@@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
46
{
53
{
47
#if !defined(CONFIG_USER_ONLY)
54
return opfv_widen_check(s, a) &&
48
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
55
require_rvfmin(s) &&
49
- return -RISCV_EXCP_ILLEGAL_INST;
56
- require_scale_rvfmin(s) &&
50
+ return RISCV_EXCP_ILLEGAL_INST;
57
- (s->sew != MO_8);
51
}
58
+ require_scale_rvfmin(s);
52
#endif
53
*val = riscv_cpu_get_fflags(env);
54
- return 0;
55
+ return RISCV_EXCP_NONE;
56
}
59
}
57
60
58
-static int write_fflags(CPURISCVState *env, int csrno, target_ulong val)
61
#define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
59
+static RISCVException write_fflags(CPURISCVState *env, int csrno,
62
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
60
+ target_ulong val)
61
{
63
{
62
#if !defined(CONFIG_USER_ONLY)
64
return opfv_narrow_check(s, a) &&
63
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
65
require_rvfmin(s) &&
64
- return -RISCV_EXCP_ILLEGAL_INST;
66
- require_scale_rvfmin(s) &&
65
+ return RISCV_EXCP_ILLEGAL_INST;
67
- (s->sew != MO_8);
66
}
68
+ require_scale_rvfmin(s);
67
env->mstatus |= MSTATUS_FS;
68
#endif
69
riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT));
70
- return 0;
71
+ return RISCV_EXCP_NONE;
72
}
69
}
73
70
74
-static int read_frm(CPURISCVState *env, int csrno, target_ulong *val)
71
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
75
+static RISCVException read_frm(CPURISCVState *env, int csrno,
76
+ target_ulong *val)
77
{
72
{
78
#if !defined(CONFIG_USER_ONLY)
73
return opfv_narrow_check(s, a) &&
79
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
74
require_rvf(s) &&
80
- return -RISCV_EXCP_ILLEGAL_INST;
75
- require_scale_rvf(s) &&
81
+ return RISCV_EXCP_ILLEGAL_INST;
76
- (s->sew != MO_8);
82
}
77
+ require_scale_rvf(s);
83
#endif
84
*val = env->frm;
85
- return 0;
86
+ return RISCV_EXCP_NONE;
87
}
78
}
88
79
89
-static int write_frm(CPURISCVState *env, int csrno, target_ulong val)
80
#define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \
90
+static RISCVException write_frm(CPURISCVState *env, int csrno,
81
@@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
91
+ target_ulong val)
92
{
82
{
93
#if !defined(CONFIG_USER_ONLY)
83
return reduction_widen_check(s, a) &&
94
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
84
require_rvf(s) &&
95
- return -RISCV_EXCP_ILLEGAL_INST;
85
- require_scale_rvf(s) &&
96
+ return RISCV_EXCP_ILLEGAL_INST;
86
- (s->sew != MO_8);
97
}
87
+ require_scale_rvf(s);
98
env->mstatus |= MSTATUS_FS;
99
#endif
100
env->frm = val & (FSR_RD >> FSR_RD_SHIFT);
101
- return 0;
102
+ return RISCV_EXCP_NONE;
103
}
88
}
104
89
105
-static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val)
90
GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check)
106
+static RISCVException read_fcsr(CPURISCVState *env, int csrno,
107
+ target_ulong *val)
108
{
109
#if !defined(CONFIG_USER_ONLY)
110
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
111
- return -RISCV_EXCP_ILLEGAL_INST;
112
+ return RISCV_EXCP_ILLEGAL_INST;
113
}
114
#endif
115
*val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT)
116
@@ -XXX,XX +XXX,XX @@ static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val)
117
*val |= (env->vxrm << FSR_VXRM_SHIFT)
118
| (env->vxsat << FSR_VXSAT_SHIFT);
119
}
120
- return 0;
121
+ return RISCV_EXCP_NONE;
122
}
123
124
-static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val)
125
+static RISCVException write_fcsr(CPURISCVState *env, int csrno,
126
+ target_ulong val)
127
{
128
#if !defined(CONFIG_USER_ONLY)
129
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
130
- return -RISCV_EXCP_ILLEGAL_INST;
131
+ return RISCV_EXCP_ILLEGAL_INST;
132
}
133
env->mstatus |= MSTATUS_FS;
134
#endif
135
@@ -XXX,XX +XXX,XX @@ static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val)
136
env->vxsat = (val & FSR_VXSAT) >> FSR_VXSAT_SHIFT;
137
}
138
riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT);
139
- return 0;
140
+ return RISCV_EXCP_NONE;
141
}
142
143
-static int read_vtype(CPURISCVState *env, int csrno, target_ulong *val)
144
+static RISCVException read_vtype(CPURISCVState *env, int csrno,
145
+ target_ulong *val)
146
{
147
*val = env->vtype;
148
- return 0;
149
+ return RISCV_EXCP_NONE;
150
}
151
152
-static int read_vl(CPURISCVState *env, int csrno, target_ulong *val)
153
+static RISCVException read_vl(CPURISCVState *env, int csrno,
154
+ target_ulong *val)
155
{
156
*val = env->vl;
157
- return 0;
158
+ return RISCV_EXCP_NONE;
159
}
160
161
-static int read_vxrm(CPURISCVState *env, int csrno, target_ulong *val)
162
+static RISCVException read_vxrm(CPURISCVState *env, int csrno,
163
+ target_ulong *val)
164
{
165
*val = env->vxrm;
166
- return 0;
167
+ return RISCV_EXCP_NONE;
168
}
169
170
-static int write_vxrm(CPURISCVState *env, int csrno, target_ulong val)
171
+static RISCVException write_vxrm(CPURISCVState *env, int csrno,
172
+ target_ulong val)
173
{
174
env->vxrm = val;
175
- return 0;
176
+ return RISCV_EXCP_NONE;
177
}
178
179
-static int read_vxsat(CPURISCVState *env, int csrno, target_ulong *val)
180
+static RISCVException read_vxsat(CPURISCVState *env, int csrno,
181
+ target_ulong *val)
182
{
183
*val = env->vxsat;
184
- return 0;
185
+ return RISCV_EXCP_NONE;
186
}
187
188
-static int write_vxsat(CPURISCVState *env, int csrno, target_ulong val)
189
+static RISCVException write_vxsat(CPURISCVState *env, int csrno,
190
+ target_ulong val)
191
{
192
env->vxsat = val;
193
- return 0;
194
+ return RISCV_EXCP_NONE;
195
}
196
197
-static int read_vstart(CPURISCVState *env, int csrno, target_ulong *val)
198
+static RISCVException read_vstart(CPURISCVState *env, int csrno,
199
+ target_ulong *val)
200
{
201
*val = env->vstart;
202
- return 0;
203
+ return RISCV_EXCP_NONE;
204
}
205
206
-static int write_vstart(CPURISCVState *env, int csrno, target_ulong val)
207
+static RISCVException write_vstart(CPURISCVState *env, int csrno,
208
+ target_ulong val)
209
{
210
env->vstart = val;
211
- return 0;
212
+ return RISCV_EXCP_NONE;
213
}
214
215
/* User Timers and Counters */
216
-static int read_instret(CPURISCVState *env, int csrno, target_ulong *val)
217
+static RISCVException read_instret(CPURISCVState *env, int csrno,
218
+ target_ulong *val)
219
{
220
#if !defined(CONFIG_USER_ONLY)
221
if (icount_enabled()) {
222
@@ -XXX,XX +XXX,XX @@ static int read_instret(CPURISCVState *env, int csrno, target_ulong *val)
223
#else
224
*val = cpu_get_host_ticks();
225
#endif
226
- return 0;
227
+ return RISCV_EXCP_NONE;
228
}
229
230
-static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val)
231
+static RISCVException read_instreth(CPURISCVState *env, int csrno,
232
+ target_ulong *val)
233
{
234
#if !defined(CONFIG_USER_ONLY)
235
if (icount_enabled()) {
236
@@ -XXX,XX +XXX,XX @@ static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val)
237
#else
238
*val = cpu_get_host_ticks() >> 32;
239
#endif
240
- return 0;
241
+ return RISCV_EXCP_NONE;
242
}
243
244
#if defined(CONFIG_USER_ONLY)
245
-static int read_time(CPURISCVState *env, int csrno, target_ulong *val)
246
+static RISCVException read_time(CPURISCVState *env, int csrno,
247
+ target_ulong *val)
248
{
249
*val = cpu_get_host_ticks();
250
- return 0;
251
+ return RISCV_EXCP_NONE;
252
}
253
254
-static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val)
255
+static RISCVException read_timeh(CPURISCVState *env, int csrno,
256
+ target_ulong *val)
257
{
258
*val = cpu_get_host_ticks() >> 32;
259
- return 0;
260
+ return RISCV_EXCP_NONE;
261
}
262
263
#else /* CONFIG_USER_ONLY */
264
265
-static int read_time(CPURISCVState *env, int csrno, target_ulong *val)
266
+static RISCVException read_time(CPURISCVState *env, int csrno,
267
+ target_ulong *val)
268
{
269
uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0;
270
271
if (!env->rdtime_fn) {
272
- return -RISCV_EXCP_ILLEGAL_INST;
273
+ return RISCV_EXCP_ILLEGAL_INST;
274
}
275
276
*val = env->rdtime_fn(env->rdtime_fn_arg) + delta;
277
- return 0;
278
+ return RISCV_EXCP_NONE;
279
}
280
281
-static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val)
282
+static RISCVException read_timeh(CPURISCVState *env, int csrno,
283
+ target_ulong *val)
284
{
285
uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0;
286
287
if (!env->rdtime_fn) {
288
- return -RISCV_EXCP_ILLEGAL_INST;
289
+ return RISCV_EXCP_ILLEGAL_INST;
290
}
291
292
*val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32;
293
- return 0;
294
+ return RISCV_EXCP_NONE;
295
}
296
297
/* Machine constants */
298
@@ -XXX,XX +XXX,XX @@ static const char valid_vm_1_10_64[16] = {
299
};
300
301
/* Machine Information Registers */
302
-static int read_zero(CPURISCVState *env, int csrno, target_ulong *val)
303
+static RISCVException read_zero(CPURISCVState *env, int csrno,
304
+ target_ulong *val)
305
{
306
- return *val = 0;
307
+ *val = 0;
308
+ return RISCV_EXCP_NONE;
309
}
310
311
-static int read_mhartid(CPURISCVState *env, int csrno, target_ulong *val)
312
+static RISCVException read_mhartid(CPURISCVState *env, int csrno,
313
+ target_ulong *val)
314
{
315
*val = env->mhartid;
316
- return 0;
317
+ return RISCV_EXCP_NONE;
318
}
319
320
/* Machine Trap Setup */
321
-static int read_mstatus(CPURISCVState *env, int csrno, target_ulong *val)
322
+static RISCVException read_mstatus(CPURISCVState *env, int csrno,
323
+ target_ulong *val)
324
{
325
*val = env->mstatus;
326
- return 0;
327
+ return RISCV_EXCP_NONE;
328
}
329
330
static int validate_vm(CPURISCVState *env, target_ulong vm)
331
@@ -XXX,XX +XXX,XX @@ static int validate_vm(CPURISCVState *env, target_ulong vm)
332
}
333
}
334
335
-static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
336
+static RISCVException write_mstatus(CPURISCVState *env, int csrno,
337
+ target_ulong val)
338
{
339
uint64_t mstatus = env->mstatus;
340
uint64_t mask = 0;
341
@@ -XXX,XX +XXX,XX @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
342
mstatus = set_field(mstatus, MSTATUS_SD, dirty);
343
env->mstatus = mstatus;
344
345
- return 0;
346
+ return RISCV_EXCP_NONE;
347
}
348
349
-static int read_mstatush(CPURISCVState *env, int csrno, target_ulong *val)
350
+static RISCVException read_mstatush(CPURISCVState *env, int csrno,
351
+ target_ulong *val)
352
{
353
*val = env->mstatus >> 32;
354
- return 0;
355
+ return RISCV_EXCP_NONE;
356
}
357
358
-static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val)
359
+static RISCVException write_mstatush(CPURISCVState *env, int csrno,
360
+ target_ulong val)
361
{
362
uint64_t valh = (uint64_t)val << 32;
363
uint64_t mask = MSTATUS_MPV | MSTATUS_GVA;
364
@@ -XXX,XX +XXX,XX @@ static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val)
365
366
env->mstatus = (env->mstatus & ~mask) | (valh & mask);
367
368
- return 0;
369
+ return RISCV_EXCP_NONE;
370
}
371
372
-static int read_misa(CPURISCVState *env, int csrno, target_ulong *val)
373
+static RISCVException read_misa(CPURISCVState *env, int csrno,
374
+ target_ulong *val)
375
{
376
*val = env->misa;
377
- return 0;
378
+ return RISCV_EXCP_NONE;
379
}
380
381
-static int write_misa(CPURISCVState *env, int csrno, target_ulong val)
382
+static RISCVException write_misa(CPURISCVState *env, int csrno,
383
+ target_ulong val)
384
{
385
if (!riscv_feature(env, RISCV_FEATURE_MISA)) {
386
/* drop write to misa */
387
- return 0;
388
+ return RISCV_EXCP_NONE;
389
}
390
391
/* 'I' or 'E' must be present */
392
if (!(val & (RVI | RVE))) {
393
/* It is not, drop write to misa */
394
- return 0;
395
+ return RISCV_EXCP_NONE;
396
}
397
398
/* 'E' excludes all other extensions */
399
@@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val)
400
/* when we support 'E' we can do "val = RVE;" however
401
* for now we just drop writes if 'E' is present.
402
*/
403
- return 0;
404
+ return RISCV_EXCP_NONE;
405
}
406
407
/* Mask extensions that are not supported by this hart */
408
@@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val)
409
410
env->misa = val;
411
412
- return 0;
413
+ return RISCV_EXCP_NONE;
414
}
415
416
-static int read_medeleg(CPURISCVState *env, int csrno, target_ulong *val)
417
+static RISCVException read_medeleg(CPURISCVState *env, int csrno,
418
+ target_ulong *val)
419
{
420
*val = env->medeleg;
421
- return 0;
422
+ return RISCV_EXCP_NONE;
423
}
424
425
-static int write_medeleg(CPURISCVState *env, int csrno, target_ulong val)
426
+static RISCVException write_medeleg(CPURISCVState *env, int csrno,
427
+ target_ulong val)
428
{
429
env->medeleg = (env->medeleg & ~delegable_excps) | (val & delegable_excps);
430
- return 0;
431
+ return RISCV_EXCP_NONE;
432
}
433
434
-static int read_mideleg(CPURISCVState *env, int csrno, target_ulong *val)
435
+static RISCVException read_mideleg(CPURISCVState *env, int csrno,
436
+ target_ulong *val)
437
{
438
*val = env->mideleg;
439
- return 0;
440
+ return RISCV_EXCP_NONE;
441
}
442
443
-static int write_mideleg(CPURISCVState *env, int csrno, target_ulong val)
444
+static RISCVException write_mideleg(CPURISCVState *env, int csrno,
445
+ target_ulong val)
446
{
447
env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints);
448
if (riscv_has_ext(env, RVH)) {
449
env->mideleg |= VS_MODE_INTERRUPTS;
450
}
451
- return 0;
452
+ return RISCV_EXCP_NONE;
453
}
454
455
-static int read_mie(CPURISCVState *env, int csrno, target_ulong *val)
456
+static RISCVException read_mie(CPURISCVState *env, int csrno,
457
+ target_ulong *val)
458
{
459
*val = env->mie;
460
- return 0;
461
+ return RISCV_EXCP_NONE;
462
}
463
464
-static int write_mie(CPURISCVState *env, int csrno, target_ulong val)
465
+static RISCVException write_mie(CPURISCVState *env, int csrno,
466
+ target_ulong val)
467
{
468
env->mie = (env->mie & ~all_ints) | (val & all_ints);
469
- return 0;
470
+ return RISCV_EXCP_NONE;
471
}
472
473
-static int read_mtvec(CPURISCVState *env, int csrno, target_ulong *val)
474
+static RISCVException read_mtvec(CPURISCVState *env, int csrno,
475
+ target_ulong *val)
476
{
477
*val = env->mtvec;
478
- return 0;
479
+ return RISCV_EXCP_NONE;
480
}
481
482
-static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val)
483
+static RISCVException write_mtvec(CPURISCVState *env, int csrno,
484
+ target_ulong val)
485
{
486
/* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
487
if ((val & 3) < 2) {
488
@@ -XXX,XX +XXX,XX @@ static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val)
489
} else {
490
qemu_log_mask(LOG_UNIMP, "CSR_MTVEC: reserved mode not supported\n");
491
}
492
- return 0;
493
+ return RISCV_EXCP_NONE;
494
}
495
496
-static int read_mcounteren(CPURISCVState *env, int csrno, target_ulong *val)
497
+static RISCVException read_mcounteren(CPURISCVState *env, int csrno,
498
+ target_ulong *val)
499
{
500
*val = env->mcounteren;
501
- return 0;
502
+ return RISCV_EXCP_NONE;
503
}
504
505
-static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)
506
+static RISCVException write_mcounteren(CPURISCVState *env, int csrno,
507
+ target_ulong val)
508
{
509
env->mcounteren = val;
510
- return 0;
511
+ return RISCV_EXCP_NONE;
512
}
513
514
/* Machine Trap Handling */
515
-static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val)
516
+static RISCVException read_mscratch(CPURISCVState *env, int csrno,
517
+ target_ulong *val)
518
{
519
*val = env->mscratch;
520
- return 0;
521
+ return RISCV_EXCP_NONE;
522
}
523
524
-static int write_mscratch(CPURISCVState *env, int csrno, target_ulong val)
525
+static RISCVException write_mscratch(CPURISCVState *env, int csrno,
526
+ target_ulong val)
527
{
528
env->mscratch = val;
529
- return 0;
530
+ return RISCV_EXCP_NONE;
531
}
532
533
-static int read_mepc(CPURISCVState *env, int csrno, target_ulong *val)
534
+static RISCVException read_mepc(CPURISCVState *env, int csrno,
535
+ target_ulong *val)
536
{
537
*val = env->mepc;
538
- return 0;
539
+ return RISCV_EXCP_NONE;
540
}
541
542
-static int write_mepc(CPURISCVState *env, int csrno, target_ulong val)
543
+static RISCVException write_mepc(CPURISCVState *env, int csrno,
544
+ target_ulong val)
545
{
546
env->mepc = val;
547
- return 0;
548
+ return RISCV_EXCP_NONE;
549
}
550
551
-static int read_mcause(CPURISCVState *env, int csrno, target_ulong *val)
552
+static RISCVException read_mcause(CPURISCVState *env, int csrno,
553
+ target_ulong *val)
554
{
555
*val = env->mcause;
556
- return 0;
557
+ return RISCV_EXCP_NONE;
558
}
559
560
-static int write_mcause(CPURISCVState *env, int csrno, target_ulong val)
561
+static RISCVException write_mcause(CPURISCVState *env, int csrno,
562
+ target_ulong val)
563
{
564
env->mcause = val;
565
- return 0;
566
+ return RISCV_EXCP_NONE;
567
}
568
569
-static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val)
570
+static RISCVException read_mtval(CPURISCVState *env, int csrno,
571
+ target_ulong *val)
572
{
573
*val = env->mtval;
574
- return 0;
575
+ return RISCV_EXCP_NONE;
576
}
577
578
-static int write_mtval(CPURISCVState *env, int csrno, target_ulong val)
579
+static RISCVException write_mtval(CPURISCVState *env, int csrno,
580
+ target_ulong val)
581
{
582
env->mtval = val;
583
- return 0;
584
+ return RISCV_EXCP_NONE;
585
}
586
587
-static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value,
588
- target_ulong new_value, target_ulong write_mask)
589
+static RISCVException rmw_mip(CPURISCVState *env, int csrno,
590
+ target_ulong *ret_value,
591
+ target_ulong new_value, target_ulong write_mask)
592
{
593
RISCVCPU *cpu = env_archcpu(env);
594
/* Allow software control of delegable interrupts not claimed by hardware */
595
@@ -XXX,XX +XXX,XX @@ static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value,
596
*ret_value = old_mip;
597
}
598
599
- return 0;
600
+ return RISCV_EXCP_NONE;
601
}
602
603
/* Supervisor Trap Setup */
604
-static int read_sstatus(CPURISCVState *env, int csrno, target_ulong *val)
605
+static RISCVException read_sstatus(CPURISCVState *env, int csrno,
606
+ target_ulong *val)
607
{
608
target_ulong mask = (sstatus_v1_10_mask);
609
*val = env->mstatus & mask;
610
- return 0;
611
+ return RISCV_EXCP_NONE;
612
}
613
614
-static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val)
615
+static RISCVException write_sstatus(CPURISCVState *env, int csrno,
616
+ target_ulong val)
617
{
618
target_ulong mask = (sstatus_v1_10_mask);
619
target_ulong newval = (env->mstatus & ~mask) | (val & mask);
620
return write_mstatus(env, CSR_MSTATUS, newval);
621
}
622
623
-static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val)
624
+static RISCVException read_vsie(CPURISCVState *env, int csrno,
625
+ target_ulong *val)
626
{
627
/* Shift the VS bits to their S bit location in vsie */
628
*val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1;
629
- return 0;
630
+ return RISCV_EXCP_NONE;
631
}
632
633
-static int read_sie(CPURISCVState *env, int csrno, target_ulong *val)
634
+static RISCVException read_sie(CPURISCVState *env, int csrno,
635
+ target_ulong *val)
636
{
637
if (riscv_cpu_virt_enabled(env)) {
638
read_vsie(env, CSR_VSIE, val);
639
} else {
640
*val = env->mie & env->mideleg;
641
}
642
- return 0;
643
+ return RISCV_EXCP_NONE;
644
}
645
646
-static int write_vsie(CPURISCVState *env, int csrno, target_ulong val)
647
+static RISCVException write_vsie(CPURISCVState *env, int csrno,
648
+ target_ulong val)
649
{
650
/* Shift the S bits to their VS bit location in mie */
651
target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) |
652
@@ -XXX,XX +XXX,XX @@ static int write_sie(CPURISCVState *env, int csrno, target_ulong val)
653
write_mie(env, CSR_MIE, newval);
654
}
655
656
- return 0;
657
+ return RISCV_EXCP_NONE;
658
}
659
660
-static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val)
661
+static RISCVException read_stvec(CPURISCVState *env, int csrno,
662
+ target_ulong *val)
663
{
664
*val = env->stvec;
665
- return 0;
666
+ return RISCV_EXCP_NONE;
667
}
668
669
-static int write_stvec(CPURISCVState *env, int csrno, target_ulong val)
670
+static RISCVException write_stvec(CPURISCVState *env, int csrno,
671
+ target_ulong val)
672
{
673
/* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
674
if ((val & 3) < 2) {
675
@@ -XXX,XX +XXX,XX @@ static int write_stvec(CPURISCVState *env, int csrno, target_ulong val)
676
} else {
677
qemu_log_mask(LOG_UNIMP, "CSR_STVEC: reserved mode not supported\n");
678
}
679
- return 0;
680
+ return RISCV_EXCP_NONE;
681
}
682
683
-static int read_scounteren(CPURISCVState *env, int csrno, target_ulong *val)
684
+static RISCVException read_scounteren(CPURISCVState *env, int csrno,
685
+ target_ulong *val)
686
{
687
*val = env->scounteren;
688
- return 0;
689
+ return RISCV_EXCP_NONE;
690
}
691
692
-static int write_scounteren(CPURISCVState *env, int csrno, target_ulong val)
693
+static RISCVException write_scounteren(CPURISCVState *env, int csrno,
694
+ target_ulong val)
695
{
696
env->scounteren = val;
697
- return 0;
698
+ return RISCV_EXCP_NONE;
699
}
700
701
/* Supervisor Trap Handling */
702
-static int read_sscratch(CPURISCVState *env, int csrno, target_ulong *val)
703
+static RISCVException read_sscratch(CPURISCVState *env, int csrno,
704
+ target_ulong *val)
705
{
706
*val = env->sscratch;
707
- return 0;
708
+ return RISCV_EXCP_NONE;
709
}
710
711
-static int write_sscratch(CPURISCVState *env, int csrno, target_ulong val)
712
+static RISCVException write_sscratch(CPURISCVState *env, int csrno,
713
+ target_ulong val)
714
{
715
env->sscratch = val;
716
- return 0;
717
+ return RISCV_EXCP_NONE;
718
}
719
720
-static int read_sepc(CPURISCVState *env, int csrno, target_ulong *val)
721
+static RISCVException read_sepc(CPURISCVState *env, int csrno,
722
+ target_ulong *val)
723
{
724
*val = env->sepc;
725
- return 0;
726
+ return RISCV_EXCP_NONE;
727
}
728
729
-static int write_sepc(CPURISCVState *env, int csrno, target_ulong val)
730
+static RISCVException write_sepc(CPURISCVState *env, int csrno,
731
+ target_ulong val)
732
{
733
env->sepc = val;
734
- return 0;
735
+ return RISCV_EXCP_NONE;
736
}
737
738
-static int read_scause(CPURISCVState *env, int csrno, target_ulong *val)
739
+static RISCVException read_scause(CPURISCVState *env, int csrno,
740
+ target_ulong *val)
741
{
742
*val = env->scause;
743
- return 0;
744
+ return RISCV_EXCP_NONE;
745
}
746
747
-static int write_scause(CPURISCVState *env, int csrno, target_ulong val)
748
+static RISCVException write_scause(CPURISCVState *env, int csrno,
749
+ target_ulong val)
750
{
751
env->scause = val;
752
- return 0;
753
+ return RISCV_EXCP_NONE;
754
}
755
756
-static int read_stval(CPURISCVState *env, int csrno, target_ulong *val)
757
+static RISCVException read_stval(CPURISCVState *env, int csrno,
758
+ target_ulong *val)
759
{
760
*val = env->stval;
761
- return 0;
762
+ return RISCV_EXCP_NONE;
763
}
764
765
-static int write_stval(CPURISCVState *env, int csrno, target_ulong val)
766
+static RISCVException write_stval(CPURISCVState *env, int csrno,
767
+ target_ulong val)
768
{
769
env->stval = val;
770
- return 0;
771
+ return RISCV_EXCP_NONE;
772
}
773
774
-static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value,
775
- target_ulong new_value, target_ulong write_mask)
776
+static RISCVException rmw_vsip(CPURISCVState *env, int csrno,
777
+ target_ulong *ret_value,
778
+ target_ulong new_value, target_ulong write_mask)
779
{
780
/* Shift the S bits to their VS bit location in mip */
781
int ret = rmw_mip(env, 0, ret_value, new_value << 1,
782
@@ -XXX,XX +XXX,XX @@ static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value,
783
return ret;
784
}
785
786
-static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
787
- target_ulong new_value, target_ulong write_mask)
788
+static RISCVException rmw_sip(CPURISCVState *env, int csrno,
789
+ target_ulong *ret_value,
790
+ target_ulong new_value, target_ulong write_mask)
791
{
792
int ret;
793
794
@@ -XXX,XX +XXX,XX @@ static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
795
}
796
797
/* Supervisor Protection and Translation */
798
-static int read_satp(CPURISCVState *env, int csrno, target_ulong *val)
799
+static RISCVException read_satp(CPURISCVState *env, int csrno,
800
+ target_ulong *val)
801
{
802
if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
803
*val = 0;
804
- return 0;
805
+ return RISCV_EXCP_NONE;
806
}
807
808
if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
809
- return -RISCV_EXCP_ILLEGAL_INST;
810
+ return RISCV_EXCP_ILLEGAL_INST;
811
} else {
812
*val = env->satp;
813
}
814
815
- return 0;
816
+ return RISCV_EXCP_NONE;
817
}
818
819
-static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
820
+static RISCVException write_satp(CPURISCVState *env, int csrno,
821
+ target_ulong val)
822
{
823
if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
824
- return 0;
825
+ return RISCV_EXCP_NONE;
826
}
827
if (validate_vm(env, get_field(val, SATP_MODE)) &&
828
((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN)))
829
{
830
if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
831
- return -RISCV_EXCP_ILLEGAL_INST;
832
+ return RISCV_EXCP_ILLEGAL_INST;
833
} else {
834
if ((val ^ env->satp) & SATP_ASID) {
835
tlb_flush(env_cpu(env));
836
@@ -XXX,XX +XXX,XX @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
837
env->satp = val;
838
}
839
}
840
- return 0;
841
+ return RISCV_EXCP_NONE;
842
}
843
844
/* Hypervisor Extensions */
845
-static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val)
846
+static RISCVException read_hstatus(CPURISCVState *env, int csrno,
847
+ target_ulong *val)
848
{
849
*val = env->hstatus;
850
if (!riscv_cpu_is_32bit(env)) {
851
@@ -XXX,XX +XXX,XX @@ static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val)
852
}
853
/* We only support little endian */
854
*val = set_field(*val, HSTATUS_VSBE, 0);
855
- return 0;
856
+ return RISCV_EXCP_NONE;
857
}
858
859
-static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val)
860
+static RISCVException write_hstatus(CPURISCVState *env, int csrno,
861
+ target_ulong val)
862
{
863
env->hstatus = val;
864
if (!riscv_cpu_is_32bit(env) && get_field(val, HSTATUS_VSXL) != 2) {
865
@@ -XXX,XX +XXX,XX @@ static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val)
866
if (get_field(val, HSTATUS_VSBE) != 0) {
867
qemu_log_mask(LOG_UNIMP, "QEMU does not support big endian guests.");
868
}
869
- return 0;
870
+ return RISCV_EXCP_NONE;
871
}
872
873
-static int read_hedeleg(CPURISCVState *env, int csrno, target_ulong *val)
874
+static RISCVException read_hedeleg(CPURISCVState *env, int csrno,
875
+ target_ulong *val)
876
{
877
*val = env->hedeleg;
878
- return 0;
879
+ return RISCV_EXCP_NONE;
880
}
881
882
-static int write_hedeleg(CPURISCVState *env, int csrno, target_ulong val)
883
+static RISCVException write_hedeleg(CPURISCVState *env, int csrno,
884
+ target_ulong val)
885
{
886
env->hedeleg = val;
887
- return 0;
888
+ return RISCV_EXCP_NONE;
889
}
890
891
-static int read_hideleg(CPURISCVState *env, int csrno, target_ulong *val)
892
+static RISCVException read_hideleg(CPURISCVState *env, int csrno,
893
+ target_ulong *val)
894
{
895
*val = env->hideleg;
896
- return 0;
897
+ return RISCV_EXCP_NONE;
898
}
899
900
-static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val)
901
+static RISCVException write_hideleg(CPURISCVState *env, int csrno,
902
+ target_ulong val)
903
{
904
env->hideleg = val;
905
- return 0;
906
+ return RISCV_EXCP_NONE;
907
}
908
909
-static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value,
910
- target_ulong new_value, target_ulong write_mask)
911
+static RISCVException rmw_hvip(CPURISCVState *env, int csrno,
912
+ target_ulong *ret_value,
913
+ target_ulong new_value, target_ulong write_mask)
914
{
915
int ret = rmw_mip(env, 0, ret_value, new_value,
916
write_mask & hvip_writable_mask);
917
@@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value,
918
return ret;
919
}
920
921
-static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value,
922
- target_ulong new_value, target_ulong write_mask)
923
+static RISCVException rmw_hip(CPURISCVState *env, int csrno,
924
+ target_ulong *ret_value,
925
+ target_ulong new_value, target_ulong write_mask)
926
{
927
int ret = rmw_mip(env, 0, ret_value, new_value,
928
write_mask & hip_writable_mask);
929
@@ -XXX,XX +XXX,XX @@ static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value,
930
return ret;
931
}
932
933
-static int read_hie(CPURISCVState *env, int csrno, target_ulong *val)
934
+static RISCVException read_hie(CPURISCVState *env, int csrno,
935
+ target_ulong *val)
936
{
937
*val = env->mie & VS_MODE_INTERRUPTS;
938
- return 0;
939
+ return RISCV_EXCP_NONE;
940
}
941
942
-static int write_hie(CPURISCVState *env, int csrno, target_ulong val)
943
+static RISCVException write_hie(CPURISCVState *env, int csrno,
944
+ target_ulong val)
945
{
946
target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS);
947
return write_mie(env, CSR_MIE, newval);
948
}
949
950
-static int read_hcounteren(CPURISCVState *env, int csrno, target_ulong *val)
951
+static RISCVException read_hcounteren(CPURISCVState *env, int csrno,
952
+ target_ulong *val)
953
{
954
*val = env->hcounteren;
955
- return 0;
956
+ return RISCV_EXCP_NONE;
957
}
958
959
-static int write_hcounteren(CPURISCVState *env, int csrno, target_ulong val)
960
+static RISCVException write_hcounteren(CPURISCVState *env, int csrno,
961
+ target_ulong val)
962
{
963
env->hcounteren = val;
964
- return 0;
965
+ return RISCV_EXCP_NONE;
966
}
967
968
-static int read_hgeie(CPURISCVState *env, int csrno, target_ulong *val)
969
+static RISCVException read_hgeie(CPURISCVState *env, int csrno,
970
+ target_ulong *val)
971
{
972
qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
973
- return 0;
974
+ return RISCV_EXCP_NONE;
975
}
976
977
-static int write_hgeie(CPURISCVState *env, int csrno, target_ulong val)
978
+static RISCVException write_hgeie(CPURISCVState *env, int csrno,
979
+ target_ulong val)
980
{
981
qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
982
- return 0;
983
+ return RISCV_EXCP_NONE;
984
}
985
986
-static int read_htval(CPURISCVState *env, int csrno, target_ulong *val)
987
+static RISCVException read_htval(CPURISCVState *env, int csrno,
988
+ target_ulong *val)
989
{
990
*val = env->htval;
991
- return 0;
992
+ return RISCV_EXCP_NONE;
993
}
994
995
-static int write_htval(CPURISCVState *env, int csrno, target_ulong val)
996
+static RISCVException write_htval(CPURISCVState *env, int csrno,
997
+ target_ulong val)
998
{
999
env->htval = val;
1000
- return 0;
1001
+ return RISCV_EXCP_NONE;
1002
}
1003
1004
-static int read_htinst(CPURISCVState *env, int csrno, target_ulong *val)
1005
+static RISCVException read_htinst(CPURISCVState *env, int csrno,
1006
+ target_ulong *val)
1007
{
1008
*val = env->htinst;
1009
- return 0;
1010
+ return RISCV_EXCP_NONE;
1011
}
1012
1013
-static int write_htinst(CPURISCVState *env, int csrno, target_ulong val)
1014
+static RISCVException write_htinst(CPURISCVState *env, int csrno,
1015
+ target_ulong val)
1016
{
1017
- return 0;
1018
+ return RISCV_EXCP_NONE;
1019
}
1020
1021
-static int read_hgeip(CPURISCVState *env, int csrno, target_ulong *val)
1022
+static RISCVException read_hgeip(CPURISCVState *env, int csrno,
1023
+ target_ulong *val)
1024
{
1025
qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
1026
- return 0;
1027
+ return RISCV_EXCP_NONE;
1028
}
1029
1030
-static int write_hgeip(CPURISCVState *env, int csrno, target_ulong val)
1031
+static RISCVException write_hgeip(CPURISCVState *env, int csrno,
1032
+ target_ulong val)
1033
{
1034
qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN.");
1035
- return 0;
1036
+ return RISCV_EXCP_NONE;
1037
}
1038
1039
-static int read_hgatp(CPURISCVState *env, int csrno, target_ulong *val)
1040
+static RISCVException read_hgatp(CPURISCVState *env, int csrno,
1041
+ target_ulong *val)
1042
{
1043
*val = env->hgatp;
1044
- return 0;
1045
+ return RISCV_EXCP_NONE;
1046
}
1047
1048
-static int write_hgatp(CPURISCVState *env, int csrno, target_ulong val)
1049
+static RISCVException write_hgatp(CPURISCVState *env, int csrno,
1050
+ target_ulong val)
1051
{
1052
env->hgatp = val;
1053
- return 0;
1054
+ return RISCV_EXCP_NONE;
1055
}
1056
1057
-static int read_htimedelta(CPURISCVState *env, int csrno, target_ulong *val)
1058
+static RISCVException read_htimedelta(CPURISCVState *env, int csrno,
1059
+ target_ulong *val)
1060
{
1061
if (!env->rdtime_fn) {
1062
- return -RISCV_EXCP_ILLEGAL_INST;
1063
+ return RISCV_EXCP_ILLEGAL_INST;
1064
}
1065
1066
*val = env->htimedelta;
1067
- return 0;
1068
+ return RISCV_EXCP_NONE;
1069
}
1070
1071
-static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val)
1072
+static RISCVException write_htimedelta(CPURISCVState *env, int csrno,
1073
+ target_ulong val)
1074
{
1075
if (!env->rdtime_fn) {
1076
- return -RISCV_EXCP_ILLEGAL_INST;
1077
+ return RISCV_EXCP_ILLEGAL_INST;
1078
}
1079
1080
if (riscv_cpu_is_32bit(env)) {
1081
@@ -XXX,XX +XXX,XX @@ static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val)
1082
} else {
1083
env->htimedelta = val;
1084
}
1085
- return 0;
1086
+ return RISCV_EXCP_NONE;
1087
}
1088
1089
-static int read_htimedeltah(CPURISCVState *env, int csrno, target_ulong *val)
1090
+static RISCVException read_htimedeltah(CPURISCVState *env, int csrno,
1091
+ target_ulong *val)
1092
{
1093
if (!env->rdtime_fn) {
1094
- return -RISCV_EXCP_ILLEGAL_INST;
1095
+ return RISCV_EXCP_ILLEGAL_INST;
1096
}
1097
1098
*val = env->htimedelta >> 32;
1099
- return 0;
1100
+ return RISCV_EXCP_NONE;
1101
}
1102
1103
-static int write_htimedeltah(CPURISCVState *env, int csrno, target_ulong val)
1104
+static RISCVException write_htimedeltah(CPURISCVState *env, int csrno,
1105
+ target_ulong val)
1106
{
1107
if (!env->rdtime_fn) {
1108
- return -RISCV_EXCP_ILLEGAL_INST;
1109
+ return RISCV_EXCP_ILLEGAL_INST;
1110
}
1111
1112
env->htimedelta = deposit64(env->htimedelta, 32, 32, (uint64_t)val);
1113
- return 0;
1114
+ return RISCV_EXCP_NONE;
1115
}
1116
1117
/* Virtual CSR Registers */
1118
-static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val)
1119
+static RISCVException read_vsstatus(CPURISCVState *env, int csrno,
1120
+ target_ulong *val)
1121
{
1122
*val = env->vsstatus;
1123
- return 0;
1124
+ return RISCV_EXCP_NONE;
1125
}
1126
1127
-static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val)
1128
+static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
1129
+ target_ulong val)
1130
{
1131
uint64_t mask = (target_ulong)-1;
1132
env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val;
1133
- return 0;
1134
+ return RISCV_EXCP_NONE;
1135
}
1136
1137
static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val)
1138
{
1139
*val = env->vstvec;
1140
- return 0;
1141
+ return RISCV_EXCP_NONE;
1142
}
1143
1144
-static int write_vstvec(CPURISCVState *env, int csrno, target_ulong val)
1145
+static RISCVException write_vstvec(CPURISCVState *env, int csrno,
1146
+ target_ulong val)
1147
{
1148
env->vstvec = val;
1149
- return 0;
1150
+ return RISCV_EXCP_NONE;
1151
}
1152
1153
-static int read_vsscratch(CPURISCVState *env, int csrno, target_ulong *val)
1154
+static RISCVException read_vsscratch(CPURISCVState *env, int csrno,
1155
+ target_ulong *val)
1156
{
1157
*val = env->vsscratch;
1158
- return 0;
1159
+ return RISCV_EXCP_NONE;
1160
}
1161
1162
-static int write_vsscratch(CPURISCVState *env, int csrno, target_ulong val)
1163
+static RISCVException write_vsscratch(CPURISCVState *env, int csrno,
1164
+ target_ulong val)
1165
{
1166
env->vsscratch = val;
1167
- return 0;
1168
+ return RISCV_EXCP_NONE;
1169
}
1170
1171
-static int read_vsepc(CPURISCVState *env, int csrno, target_ulong *val)
1172
+static RISCVException read_vsepc(CPURISCVState *env, int csrno,
1173
+ target_ulong *val)
1174
{
1175
*val = env->vsepc;
1176
- return 0;
1177
+ return RISCV_EXCP_NONE;
1178
}
1179
1180
-static int write_vsepc(CPURISCVState *env, int csrno, target_ulong val)
1181
+static RISCVException write_vsepc(CPURISCVState *env, int csrno,
1182
+ target_ulong val)
1183
{
1184
env->vsepc = val;
1185
- return 0;
1186
+ return RISCV_EXCP_NONE;
1187
}
1188
1189
-static int read_vscause(CPURISCVState *env, int csrno, target_ulong *val)
1190
+static RISCVException read_vscause(CPURISCVState *env, int csrno,
1191
+ target_ulong *val)
1192
{
1193
*val = env->vscause;
1194
- return 0;
1195
+ return RISCV_EXCP_NONE;
1196
}
1197
1198
-static int write_vscause(CPURISCVState *env, int csrno, target_ulong val)
1199
+static RISCVException write_vscause(CPURISCVState *env, int csrno,
1200
+ target_ulong val)
1201
{
1202
env->vscause = val;
1203
- return 0;
1204
+ return RISCV_EXCP_NONE;
1205
}
1206
1207
-static int read_vstval(CPURISCVState *env, int csrno, target_ulong *val)
1208
+static RISCVException read_vstval(CPURISCVState *env, int csrno,
1209
+ target_ulong *val)
1210
{
1211
*val = env->vstval;
1212
- return 0;
1213
+ return RISCV_EXCP_NONE;
1214
}
1215
1216
-static int write_vstval(CPURISCVState *env, int csrno, target_ulong val)
1217
+static RISCVException write_vstval(CPURISCVState *env, int csrno,
1218
+ target_ulong val)
1219
{
1220
env->vstval = val;
1221
- return 0;
1222
+ return RISCV_EXCP_NONE;
1223
}
1224
1225
-static int read_vsatp(CPURISCVState *env, int csrno, target_ulong *val)
1226
+static RISCVException read_vsatp(CPURISCVState *env, int csrno,
1227
+ target_ulong *val)
1228
{
1229
*val = env->vsatp;
1230
- return 0;
1231
+ return RISCV_EXCP_NONE;
1232
}
1233
1234
-static int write_vsatp(CPURISCVState *env, int csrno, target_ulong val)
1235
+static RISCVException write_vsatp(CPURISCVState *env, int csrno,
1236
+ target_ulong val)
1237
{
1238
env->vsatp = val;
1239
- return 0;
1240
+ return RISCV_EXCP_NONE;
1241
}
1242
1243
-static int read_mtval2(CPURISCVState *env, int csrno, target_ulong *val)
1244
+static RISCVException read_mtval2(CPURISCVState *env, int csrno,
1245
+ target_ulong *val)
1246
{
1247
*val = env->mtval2;
1248
- return 0;
1249
+ return RISCV_EXCP_NONE;
1250
}
1251
1252
-static int write_mtval2(CPURISCVState *env, int csrno, target_ulong val)
1253
+static RISCVException write_mtval2(CPURISCVState *env, int csrno,
1254
+ target_ulong val)
1255
{
1256
env->mtval2 = val;
1257
- return 0;
1258
+ return RISCV_EXCP_NONE;
1259
}
1260
1261
-static int read_mtinst(CPURISCVState *env, int csrno, target_ulong *val)
1262
+static RISCVException read_mtinst(CPURISCVState *env, int csrno,
1263
+ target_ulong *val)
1264
{
1265
*val = env->mtinst;
1266
- return 0;
1267
+ return RISCV_EXCP_NONE;
1268
}
1269
1270
-static int write_mtinst(CPURISCVState *env, int csrno, target_ulong val)
1271
+static RISCVException write_mtinst(CPURISCVState *env, int csrno,
1272
+ target_ulong val)
1273
{
1274
env->mtinst = val;
1275
- return 0;
1276
+ return RISCV_EXCP_NONE;
1277
}
1278
1279
/* Physical Memory Protection */
1280
-static int read_pmpcfg(CPURISCVState *env, int csrno, target_ulong *val)
1281
+static RISCVException read_pmpcfg(CPURISCVState *env, int csrno,
1282
+ target_ulong *val)
1283
{
1284
*val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0);
1285
- return 0;
1286
+ return RISCV_EXCP_NONE;
1287
}
1288
1289
-static int write_pmpcfg(CPURISCVState *env, int csrno, target_ulong val)
1290
+static RISCVException write_pmpcfg(CPURISCVState *env, int csrno,
1291
+ target_ulong val)
1292
{
1293
pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val);
1294
- return 0;
1295
+ return RISCV_EXCP_NONE;
1296
}
1297
1298
-static int read_pmpaddr(CPURISCVState *env, int csrno, target_ulong *val)
1299
+static RISCVException read_pmpaddr(CPURISCVState *env, int csrno,
1300
+ target_ulong *val)
1301
{
1302
*val = pmpaddr_csr_read(env, csrno - CSR_PMPADDR0);
1303
- return 0;
1304
+ return RISCV_EXCP_NONE;
1305
}
1306
1307
-static int write_pmpaddr(CPURISCVState *env, int csrno, target_ulong val)
1308
+static RISCVException write_pmpaddr(CPURISCVState *env, int csrno,
1309
+ target_ulong val)
1310
{
1311
pmpaddr_csr_write(env, csrno - CSR_PMPADDR0, val);
1312
- return 0;
1313
+ return RISCV_EXCP_NONE;
1314
}
1315
1316
#endif
1317
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
1318
1319
/* execute combined read/write operation if it exists */
1320
if (csr_ops[csrno].op) {
1321
- return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask);
1322
+ ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask);
1323
+ if (ret != RISCV_EXCP_NONE) {
1324
+ return -ret;
1325
+ }
1326
+ return 0;
1327
}
1328
1329
/* if no accessor exists then return failure */
1330
if (!csr_ops[csrno].read) {
1331
return -RISCV_EXCP_ILLEGAL_INST;
1332
}
1333
-
1334
/* read old value */
1335
ret = csr_ops[csrno].read(env, csrno, &old_value);
1336
- if (ret < 0) {
1337
- return ret;
1338
+ if (ret != RISCV_EXCP_NONE) {
1339
+ return -ret;
1340
}
1341
1342
/* write value if writable and write mask set, otherwise drop writes */
1343
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
1344
new_value = (old_value & ~write_mask) | (new_value & write_mask);
1345
if (csr_ops[csrno].write) {
1346
ret = csr_ops[csrno].write(env, csrno, new_value);
1347
- if (ret < 0) {
1348
- return ret;
1349
+ if (ret != RISCV_EXCP_NONE) {
1350
+ return -ret;
1351
}
1352
}
1353
}
1354
--
91
--
1355
2.31.1
92
2.45.1
1356
1357
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
raise_mmu_exception(), as is today, is prioritizing guest page faults by
4
checking first if virt_enabled && !first_stage, and then considering the
5
regular inst/load/store faults.
6
7
There's no mention in the spec about guest page fault being a higher
8
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
9
10
"Attempting to fetch an instruction from a PMP region that does not have
11
execute permissions raises an instruction access-fault exception.
12
Attempting to execute a load or load-reserved instruction which accesses
13
a physical address within a PMP region without read permissions raises a
14
load access-fault exception. Attempting to execute a store,
15
store-conditional, or AMO instruction which accesses a physical address
16
within a PMP region without write permissions raises a store
17
access-fault exception."
18
19
So, in fact, we're doing it wrong - PMP faults should always be thrown,
20
regardless of also being a first or second stage fault.
21
22
The way riscv_cpu_tlb_fill() and get_physical_address() work is
23
adequate: a TRANSLATE_PMP_FAIL error is immediately reported and
24
reflected in the 'pmp_violation' flag. What we need is to change
25
raise_mmu_exception() to prioritize it.
26
27
Reported-by: Joseph Chan <jchan@ventanamicro.com>
28
Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage")
29
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
30
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
31
Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: 665f624bfdc2e3ca64265004b07de7489c77a766.1619234854.git.alistair.francis@wdc.com
5
---
34
---
6
target/riscv/cpu_bits.h | 11 -----------
35
target/riscv/cpu_helper.c | 22 ++++++++++++----------
7
target/riscv/cpu_helper.c | 24 +++++++++++++++---------
36
1 file changed, 12 insertions(+), 10 deletions(-)
8
2 files changed, 15 insertions(+), 20 deletions(-)
9
37
10
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
11
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/cpu_bits.h
13
+++ b/target/riscv/cpu_bits.h
14
@@ -XXX,XX +XXX,XX @@
15
#define CSR_HTIMEDELTA 0x605
16
#define CSR_HTIMEDELTAH 0x615
17
18
-#if defined(TARGET_RISCV32)
19
-#define HGATP_MODE SATP32_MODE
20
-#define HGATP_VMID SATP32_ASID
21
-#define HGATP_PPN SATP32_PPN
22
-#endif
23
-#if defined(TARGET_RISCV64)
24
-#define HGATP_MODE SATP64_MODE
25
-#define HGATP_VMID SATP64_ASID
26
-#define HGATP_PPN SATP64_PPN
27
-#endif
28
-
29
/* Virtual CSRs */
30
#define CSR_VSSTATUS 0x200
31
#define CSR_VSIE 0x204
32
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
38
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
33
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/cpu_helper.c
40
--- a/target/riscv/cpu_helper.c
35
+++ b/target/riscv/cpu_helper.c
41
+++ b/target/riscv/cpu_helper.c
36
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
37
}
38
widened = 0;
39
} else {
40
- base = (hwaddr)get_field(env->hgatp, HGATP_PPN) << PGSHIFT;
41
- vm = get_field(env->hgatp, HGATP_MODE);
42
+ if (riscv_cpu_is_32bit(env)) {
43
+ base = (hwaddr)get_field(env->hgatp, SATP32_PPN) << PGSHIFT;
44
+ vm = get_field(env->hgatp, SATP32_MODE);
45
+ } else {
46
+ base = (hwaddr)get_field(env->hgatp, SATP64_PPN) << PGSHIFT;
47
+ vm = get_field(env->hgatp, SATP64_MODE);
48
+ }
49
widened = 2;
50
}
51
/* status.SUM will be ignored if execute on background */
52
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
42
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
53
bool first_stage, bool two_stage)
43
54
{
55
CPUState *cs = env_cpu(env);
56
- int page_fault_exceptions;
57
+ int page_fault_exceptions, vm;
58
+
59
if (first_stage) {
60
- page_fault_exceptions =
61
- get_field(env->satp, SATP_MODE) != VM_1_10_MBARE &&
62
- !pmp_violation;
63
+ vm = get_field(env->satp, SATP_MODE);
64
+ } else if (riscv_cpu_is_32bit(env)) {
65
+ vm = get_field(env->hgatp, SATP32_MODE);
66
} else {
67
- page_fault_exceptions =
68
- get_field(env->hgatp, HGATP_MODE) != VM_1_10_MBARE &&
69
- !pmp_violation;
70
+ vm = get_field(env->hgatp, SATP64_MODE);
71
}
72
+ page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation;
73
+
74
switch (access_type) {
44
switch (access_type) {
75
case MMU_INST_FETCH:
45
case MMU_INST_FETCH:
76
if (riscv_cpu_virt_enabled(env) && !first_stage) {
46
- if (env->virt_enabled && !first_stage) {
47
+ if (pmp_violation) {
48
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
49
+ } else if (env->virt_enabled && !first_stage) {
50
cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
51
} else {
52
- cs->exception_index = pmp_violation ?
53
- RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
54
+ cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
55
}
56
break;
57
case MMU_DATA_LOAD:
58
- if (two_stage && !first_stage) {
59
+ if (pmp_violation) {
60
+ cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
61
+ } else if (two_stage && !first_stage) {
62
cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
63
} else {
64
- cs->exception_index = pmp_violation ?
65
- RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
66
+ cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT;
67
}
68
break;
69
case MMU_DATA_STORE:
70
- if (two_stage && !first_stage) {
71
+ if (pmp_violation) {
72
+ cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
73
+ } else if (two_stage && !first_stage) {
74
cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
75
} else {
76
- cs->exception_index = pmp_violation ?
77
- RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
78
- RISCV_EXCP_STORE_PAGE_FAULT;
79
+ cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
80
}
81
break;
82
default:
77
--
83
--
78
2.31.1
84
2.45.1
79
80
diff view generated by jsdifflib
1
From: Emmanuel Blot <emmanuel.blot@sifive.com>
1
From: Alexei Filippov <alexei.filippov@syntacore.com>
2
2
3
When no MMU is used and the guest code attempts to fetch an instruction
3
Previous patch fixed the PMP priority in raise_mmu_exception() but we're still
4
from an invalid memory location, the exception index defaults to a data
4
setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage
5
load access fault, rather an instruction access fault.
5
translation part, mtval2 will be set in case of successes 2 stage translation but
6
failed pmp check.
6
7
7
Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
8
In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of
9
riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2
10
should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest
11
page-fault is taken into M-mode, mtval2 is written with either zero or guest
12
physical address that faulted, shifted by 2 bits. *For other traps, mtval2
13
is set to zero...*
14
15
Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: FB9EA197-B018-4879-AB0F-922C2047A08B@sifive.com
18
Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com>
19
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
21
---
12
target/riscv/cpu_helper.c | 4 +++-
22
target/riscv/cpu_helper.c | 12 ++++++------
13
1 file changed, 3 insertions(+), 1 deletion(-)
23
1 file changed, 6 insertions(+), 6 deletions(-)
14
24
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
25
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
16
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
27
--- a/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
28
+++ b/target/riscv/cpu_helper.c
19
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
29
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
20
30
__func__, pa, ret, prot_pmp, tlb_size);
21
if (access_type == MMU_DATA_STORE) {
31
22
cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
32
prot &= prot_pmp;
23
- } else {
33
- }
24
+ } else if (access_type == MMU_DATA_LOAD) {
34
-
25
cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
35
- if (ret != TRANSLATE_SUCCESS) {
26
+ } else {
36
+ } else {
27
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
37
/*
28
}
38
* Guest physical address translation failed, this is a HS
29
39
* level exception
30
env->badaddr = addr;
40
*/
41
first_stage_error = false;
42
- env->guest_phys_fault_addr = (im_address |
43
- (address &
44
- (TARGET_PAGE_SIZE - 1))) >> 2;
45
+ if (ret != TRANSLATE_PMP_FAIL) {
46
+ env->guest_phys_fault_addr = (im_address |
47
+ (address &
48
+ (TARGET_PAGE_SIZE - 1))) >> 2;
49
+ }
50
}
51
}
52
} else {
31
--
53
--
32
2.31.1
54
2.45.1
33
34
diff view generated by jsdifflib
1
From: Dylan Jhong <dylan@andestech.com>
1
From: Rob Bradford <rbradford@rivosinc.com>
2
2
3
Use target_ulong to instead of uint64_t on reset vector address
3
This extension has now been ratified:
4
to adapt on both 32/64 machine.
4
https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be
5
removed.
5
6
6
Signed-off-by: Dylan Jhong <dylan@andestech.com>
7
Since this is now a ratified extension add it to the list of extensions
7
Signed-off-by: Ruinland ChuanTzu Tsai <ruinland@andestech.com>
8
included in the "max" CPU variant.
8
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
9
10
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210329034801.22667-1-dylan@andestech.com
13
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
14
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
15
Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
17
---
13
target/riscv/cpu.c | 2 +-
18
target/riscv/cpu.c | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
19
target/riscv/tcg/tcg-cpu.c | 2 +-
20
2 files changed, 2 insertions(+), 2 deletions(-)
15
21
16
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
22
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
17
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/cpu.c
24
--- a/target/riscv/cpu.c
19
+++ b/target/riscv/cpu.c
25
+++ b/target/riscv/cpu.c
20
@@ -XXX,XX +XXX,XX @@ static void set_feature(CPURISCVState *env, int feature)
26
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
21
env->features |= (1ULL << feature);
27
MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
22
}
28
MISA_EXT_INFO(RVV, "v", "Vector operations"),
23
29
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
24
-static void set_resetvec(CPURISCVState *env, int resetvec)
30
- MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)")
25
+static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
31
+ MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
26
{
32
};
27
#ifndef CONFIG_USER_ONLY
33
28
env->resetvec = resetvec;
34
static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc)
35
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
36
index XXXXXXX..XXXXXXX 100644
37
--- a/target/riscv/tcg/tcg-cpu.c
38
+++ b/target/riscv/tcg/tcg-cpu.c
39
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
40
const RISCVCPUMultiExtConfig *prop;
41
42
/* Enable RVG, RVJ and RVV that are disabled by default */
43
- riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV);
44
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV);
45
46
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
47
isa_ext_update_enabled(cpu, prop->offset, true);
29
--
48
--
30
2.31.1
49
2.45.1
31
32
diff view generated by jsdifflib
Deleted patch
1
From: Bin Meng <bmeng.cn@gmail.com>
2
1
3
This was accidentally dropped before. Add it back.
4
5
Fixes: 732612856a8 ("hw/riscv: Drop 'struct MemmapEntry'")
6
Reported-by: Emmanuel Blot <eblot.ml@gmail.com>
7
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210331103612.654261-1-bmeng.cn@gmail.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
hw/riscv/sifive_e.c | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
15
16
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/riscv/sifive_e.c
19
+++ b/hw/riscv/sifive_e.c
20
@@ -XXX,XX +XXX,XX @@
21
#include "sysemu/sysemu.h"
22
#include "exec/address-spaces.h"
23
24
-static MemMapEntry sifive_e_memmap[] = {
25
+static const MemMapEntry sifive_e_memmap[] = {
26
[SIFIVE_E_DEV_DEBUG] = { 0x0, 0x1000 },
27
[SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 },
28
[SIFIVE_E_DEV_OTP] = { 0x20000, 0x2000 },
29
--
30
2.31.1
31
32
diff view generated by jsdifflib
Deleted patch
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
1
3
Connect one shakti uart to the shakti_c machine.
4
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Message-id: 20210401181457.73039-5-vijai@behindbytes.com
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
10
include/hw/riscv/shakti_c.h | 2 ++
11
hw/riscv/shakti_c.c | 8 ++++++++
12
2 files changed, 10 insertions(+)
13
14
diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/riscv/shakti_c.h
17
+++ b/include/hw/riscv/shakti_c.h
18
@@ -XXX,XX +XXX,XX @@
19
20
#include "hw/riscv/riscv_hart.h"
21
#include "hw/boards.h"
22
+#include "hw/char/shakti_uart.h"
23
24
#define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc"
25
#define RISCV_SHAKTI_SOC(obj) \
26
@@ -XXX,XX +XXX,XX @@ typedef struct ShaktiCSoCState {
27
/*< public >*/
28
RISCVHartArrayState cpus;
29
DeviceState *plic;
30
+ ShaktiUartState uart;
31
MemoryRegion rom;
32
33
} ShaktiCSoCState;
34
diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/riscv/shakti_c.c
37
+++ b/hw/riscv/shakti_c.c
38
@@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)
39
SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
40
SIFIVE_CLINT_TIMEBASE_FREQ, false);
41
42
+ qdev_prop_set_chr(DEVICE(&(sss->uart)), "chardev", serial_hd(0));
43
+ if (!sysbus_realize(SYS_BUS_DEVICE(&sss->uart), errp)) {
44
+ return;
45
+ }
46
+ sysbus_mmio_map(SYS_BUS_DEVICE(&sss->uart), 0,
47
+ shakti_c_memmap[SHAKTI_C_UART].base);
48
+
49
/* ROM */
50
memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom",
51
shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal);
52
@@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_instance_init(Object *obj)
53
ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj);
54
55
object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY);
56
+ object_initialize_child(obj, "uart", &sss->uart, TYPE_SHAKTI_UART);
57
58
/*
59
* CPU type is fixed and we are not supporting passing from commandline yet.
60
--
61
2.31.1
62
63
diff view generated by jsdifflib
1
This patch removes the insn32-64.decode decode file and consolidates the
1
From: Alistair Francis <alistair23@gmail.com>
2
instructions into the general RISC-V insn32.decode decode tree.
3
2
4
This means that all of the instructions are avaliable in both the 32-bit
3
When running the instruction
5
and 64-bit builds. This also means that we run a check to ensure we are
4
6
running a 64-bit softmmu before we execute the 64-bit only instructions.
5
```
7
This allows us to include the 32-bit instructions in the 64-bit build,
6
cbo.flush 0(x0)
8
while also ensuring that 32-bit only software can not execute the
7
```
9
instructions.
8
9
QEMU would segfault.
10
11
The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0]
12
allocated.
13
14
In order to fix this let's use the existing get_address()
15
helper. This also has the benefit of performing pointer mask
16
calculations on the address specified in rs1.
17
18
The pointer masking specificiation specifically states:
19
20
"""
21
Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz
22
"""
23
24
So this is the correct behaviour and we previously have been incorrectly
25
not masking the address.
10
26
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
Reported-by: Fabian Thomas <fabian.thomas@cispa.de>
29
Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension")
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
30
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: db709360e2be47d2f9c6483ab973fe4791aefa77.1619234854.git.alistair.francis@wdc.com
31
Cc: qemu-stable <qemu-stable@nongnu.org>
32
Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
34
---
15
target/riscv/helper.h | 18 +++--
35
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++----
16
target/riscv/insn32-64.decode | 88 -------------------------
36
1 file changed, 12 insertions(+), 4 deletions(-)
17
target/riscv/insn32.decode | 67 ++++++++++++++++++-
18
target/riscv/fpu_helper.c | 16 ++---
19
target/riscv/translate.c | 9 ++-
20
target/riscv/vector_helper.c | 4 --
21
target/riscv/insn_trans/trans_rva.c.inc | 14 +++-
22
target/riscv/insn_trans/trans_rvd.c.inc | 17 ++++-
23
target/riscv/insn_trans/trans_rvf.c.inc | 6 +-
24
target/riscv/insn_trans/trans_rvh.c.inc | 8 ++-
25
target/riscv/insn_trans/trans_rvi.c.inc | 16 +++--
26
target/riscv/insn_trans/trans_rvm.c.inc | 12 +++-
27
target/riscv/insn_trans/trans_rvv.c.inc | 39 +++++------
28
target/riscv/meson.build | 2 +-
29
14 files changed, 166 insertions(+), 150 deletions(-)
30
delete mode 100644 target/riscv/insn32-64.decode
31
37
32
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
38
diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc
33
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/helper.h
40
--- a/target/riscv/insn_trans/trans_rvzicbo.c.inc
35
+++ b/target/riscv/helper.h
41
+++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc
36
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
37
DEF_HELPER_FLAGS_3(feq_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
38
DEF_HELPER_FLAGS_2(fcvt_w_s, TCG_CALL_NO_RWG, tl, env, i64)
39
DEF_HELPER_FLAGS_2(fcvt_wu_s, TCG_CALL_NO_RWG, tl, env, i64)
40
-DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, i64, env, i64)
41
-DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, i64, env, i64)
42
+DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, tl, env, i64)
43
+DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, tl, env, i64)
44
DEF_HELPER_FLAGS_2(fcvt_s_w, TCG_CALL_NO_RWG, i64, env, tl)
45
DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl)
46
-DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, i64)
47
-DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, i64)
48
+DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl)
49
+DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl)
50
DEF_HELPER_FLAGS_1(fclass_s, TCG_CALL_NO_RWG_SE, tl, i64)
51
52
/* Floating Point - Double Precision */
53
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
54
DEF_HELPER_FLAGS_3(feq_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
55
DEF_HELPER_FLAGS_2(fcvt_w_d, TCG_CALL_NO_RWG, tl, env, i64)
56
DEF_HELPER_FLAGS_2(fcvt_wu_d, TCG_CALL_NO_RWG, tl, env, i64)
57
-DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, i64, env, i64)
58
-DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, i64, env, i64)
59
+DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, tl, env, i64)
60
+DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, tl, env, i64)
61
DEF_HELPER_FLAGS_2(fcvt_d_w, TCG_CALL_NO_RWG, i64, env, tl)
62
DEF_HELPER_FLAGS_2(fcvt_d_wu, TCG_CALL_NO_RWG, i64, env, tl)
63
-DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, i64)
64
-DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, i64)
65
+DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, tl)
66
+DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl)
67
DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64)
68
69
/* Special functions */
70
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vlhuff_v_w, void, ptr, ptr, tl, env, i32)
71
DEF_HELPER_5(vlhuff_v_d, void, ptr, ptr, tl, env, i32)
72
DEF_HELPER_5(vlwuff_v_w, void, ptr, ptr, tl, env, i32)
73
DEF_HELPER_5(vlwuff_v_d, void, ptr, ptr, tl, env, i32)
74
-#ifdef TARGET_RISCV64
75
DEF_HELPER_6(vamoswapw_v_d, void, ptr, ptr, tl, ptr, env, i32)
76
DEF_HELPER_6(vamoswapd_v_d, void, ptr, ptr, tl, ptr, env, i32)
77
DEF_HELPER_6(vamoaddw_v_d, void, ptr, ptr, tl, ptr, env, i32)
78
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vamominuw_v_d, void, ptr, ptr, tl, ptr, env, i32)
79
DEF_HELPER_6(vamominud_v_d, void, ptr, ptr, tl, ptr, env, i32)
80
DEF_HELPER_6(vamomaxuw_v_d, void, ptr, ptr, tl, ptr, env, i32)
81
DEF_HELPER_6(vamomaxud_v_d, void, ptr, ptr, tl, ptr, env, i32)
82
-#endif
83
DEF_HELPER_6(vamoswapw_v_w, void, ptr, ptr, tl, ptr, env, i32)
84
DEF_HELPER_6(vamoaddw_v_w, void, ptr, ptr, tl, ptr, env, i32)
85
DEF_HELPER_6(vamoxorw_v_w, void, ptr, ptr, tl, ptr, env, i32)
86
diff --git a/target/riscv/insn32-64.decode b/target/riscv/insn32-64.decode
87
deleted file mode 100644
88
index XXXXXXX..XXXXXXX
89
--- a/target/riscv/insn32-64.decode
90
+++ /dev/null
91
@@ -XXX,XX +XXX,XX @@
42
@@ -XXX,XX +XXX,XX @@
92
-#
43
static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a)
93
-# RISC-V translation routines for the RV Instruction Set.
44
{
94
-#
45
REQUIRE_ZICBOM(ctx);
95
-# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
46
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
96
-# Bastian Koppelmann, kbastian@mail.uni-paderborn.de
47
+ TCGv src = get_address(ctx, a->rs1, 0);
97
-#
98
-# This program is free software; you can redistribute it and/or modify it
99
-# under the terms and conditions of the GNU General Public License,
100
-# version 2 or later, as published by the Free Software Foundation.
101
-#
102
-# This program is distributed in the hope it will be useful, but WITHOUT
103
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
104
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
105
-# more details.
106
-#
107
-# You should have received a copy of the GNU General Public License along with
108
-# this program. If not, see <http://www.gnu.org/licenses/>.
109
-
110
-# This is concatenated with insn32.decode for risc64 targets.
111
-# Most of the fields and formats are there.
112
-
113
-%sh5 20:5
114
-
115
-@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd
116
-
117
-# *** RV64I Base Instruction Set (in addition to RV32I) ***
118
-lwu ............ ..... 110 ..... 0000011 @i
119
-ld ............ ..... 011 ..... 0000011 @i
120
-sd ....... ..... ..... 011 ..... 0100011 @s
121
-addiw ............ ..... 000 ..... 0011011 @i
122
-slliw 0000000 ..... ..... 001 ..... 0011011 @sh5
123
-srliw 0000000 ..... ..... 101 ..... 0011011 @sh5
124
-sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5
125
-addw 0000000 ..... ..... 000 ..... 0111011 @r
126
-subw 0100000 ..... ..... 000 ..... 0111011 @r
127
-sllw 0000000 ..... ..... 001 ..... 0111011 @r
128
-srlw 0000000 ..... ..... 101 ..... 0111011 @r
129
-sraw 0100000 ..... ..... 101 ..... 0111011 @r
130
-
131
-# *** RV64M Standard Extension (in addition to RV32M) ***
132
-mulw 0000001 ..... ..... 000 ..... 0111011 @r
133
-divw 0000001 ..... ..... 100 ..... 0111011 @r
134
-divuw 0000001 ..... ..... 101 ..... 0111011 @r
135
-remw 0000001 ..... ..... 110 ..... 0111011 @r
136
-remuw 0000001 ..... ..... 111 ..... 0111011 @r
137
-
138
-# *** RV64A Standard Extension (in addition to RV32A) ***
139
-lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld
140
-sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st
141
-amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st
142
-amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st
143
-amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st
144
-amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st
145
-amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st
146
-amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st
147
-amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st
148
-amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st
149
-amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st
150
-
151
-#*** Vector AMO operations (in addition to Zvamo) ***
152
-vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm
153
-vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm
154
-vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm
155
-vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm
156
-vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm
157
-vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm
158
-vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm
159
-vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm
160
-vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm
161
-
162
-# *** RV64F Standard Extension (in addition to RV32F) ***
163
-fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm
164
-fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm
165
-fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm
166
-fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm
167
-
168
-# *** RV64D Standard Extension (in addition to RV32D) ***
169
-fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm
170
-fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm
171
-fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2
172
-fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm
173
-fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm
174
-fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2
175
-
176
-# *** RV32H Base Instruction Set ***
177
-hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2
178
-hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2
179
-hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s
180
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
181
index XXXXXXX..XXXXXXX 100644
182
--- a/target/riscv/insn32.decode
183
+++ b/target/riscv/insn32.decode
184
@@ -XXX,XX +XXX,XX @@
185
%rs2 20:5
186
%rs1 15:5
187
%rd 7:5
188
+%sh5 20:5
189
190
%sh10 20:10
191
%csr 20:12
192
@@ -XXX,XX +XXX,XX @@
193
@sfence_vma ....... ..... ..... ... ..... ....... %rs2 %rs1
194
@sfence_vm ....... ..... ..... ... ..... ....... %rs1
195
196
+# Formats 64:
197
+@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd
198
199
# *** Privileged Instructions ***
200
ecall 000000000000 00000 000 00000 1110011
201
@@ -XXX,XX +XXX,XX @@ csrrwi ............ ..... 101 ..... 1110011 @csr
202
csrrsi ............ ..... 110 ..... 1110011 @csr
203
csrrci ............ ..... 111 ..... 1110011 @csr
204
205
+# *** RV64I Base Instruction Set (in addition to RV32I) ***
206
+lwu ............ ..... 110 ..... 0000011 @i
207
+ld ............ ..... 011 ..... 0000011 @i
208
+sd ....... ..... ..... 011 ..... 0100011 @s
209
+addiw ............ ..... 000 ..... 0011011 @i
210
+slliw 0000000 ..... ..... 001 ..... 0011011 @sh5
211
+srliw 0000000 ..... ..... 101 ..... 0011011 @sh5
212
+sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5
213
+addw 0000000 ..... ..... 000 ..... 0111011 @r
214
+subw 0100000 ..... ..... 000 ..... 0111011 @r
215
+sllw 0000000 ..... ..... 001 ..... 0111011 @r
216
+srlw 0000000 ..... ..... 101 ..... 0111011 @r
217
+sraw 0100000 ..... ..... 101 ..... 0111011 @r
218
+
48
+
219
# *** RV32M Standard Extension ***
49
+ gen_helper_cbo_clean_flush(tcg_env, src);
220
mul 0000001 ..... ..... 000 ..... 0110011 @r
221
mulh 0000001 ..... ..... 001 ..... 0110011 @r
222
@@ -XXX,XX +XXX,XX @@ divu 0000001 ..... ..... 101 ..... 0110011 @r
223
rem 0000001 ..... ..... 110 ..... 0110011 @r
224
remu 0000001 ..... ..... 111 ..... 0110011 @r
225
226
+# *** RV64M Standard Extension (in addition to RV32M) ***
227
+mulw 0000001 ..... ..... 000 ..... 0111011 @r
228
+divw 0000001 ..... ..... 100 ..... 0111011 @r
229
+divuw 0000001 ..... ..... 101 ..... 0111011 @r
230
+remw 0000001 ..... ..... 110 ..... 0111011 @r
231
+remuw 0000001 ..... ..... 111 ..... 0111011 @r
232
+
233
# *** RV32A Standard Extension ***
234
lr_w 00010 . . 00000 ..... 010 ..... 0101111 @atom_ld
235
sc_w 00011 . . ..... ..... 010 ..... 0101111 @atom_st
236
@@ -XXX,XX +XXX,XX @@ amomax_w 10100 . . ..... ..... 010 ..... 0101111 @atom_st
237
amominu_w 11000 . . ..... ..... 010 ..... 0101111 @atom_st
238
amomaxu_w 11100 . . ..... ..... 010 ..... 0101111 @atom_st
239
240
+# *** RV64A Standard Extension (in addition to RV32A) ***
241
+lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld
242
+sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st
243
+amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st
244
+amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st
245
+amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st
246
+amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st
247
+amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st
248
+amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st
249
+amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st
250
+amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st
251
+amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st
252
+
253
# *** RV32F Standard Extension ***
254
flw ............ ..... 010 ..... 0000111 @i
255
fsw ....... ..... ..... 010 ..... 0100111 @s
256
@@ -XXX,XX +XXX,XX @@ fcvt_s_w 1101000 00000 ..... ... ..... 1010011 @r2_rm
257
fcvt_s_wu 1101000 00001 ..... ... ..... 1010011 @r2_rm
258
fmv_w_x 1111000 00000 ..... 000 ..... 1010011 @r2
259
260
+# *** RV64F Standard Extension (in addition to RV32F) ***
261
+fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm
262
+fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm
263
+fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm
264
+fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm
265
+
266
# *** RV32D Standard Extension ***
267
fld ............ ..... 011 ..... 0000111 @i
268
fsd ....... ..... ..... 011 ..... 0100111 @s
269
@@ -XXX,XX +XXX,XX @@ fcvt_wu_d 1100001 00001 ..... ... ..... 1010011 @r2_rm
270
fcvt_d_w 1101001 00000 ..... ... ..... 1010011 @r2_rm
271
fcvt_d_wu 1101001 00001 ..... ... ..... 1010011 @r2_rm
272
273
+# *** RV64D Standard Extension (in addition to RV32D) ***
274
+fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm
275
+fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm
276
+fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2
277
+fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm
278
+fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm
279
+fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2
280
+
281
# *** RV32H Base Instruction Set ***
282
hlv_b 0110000 00000 ..... 100 ..... 1110011 @r2
283
hlv_bu 0110000 00001 ..... 100 ..... 1110011 @r2
284
@@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s
285
hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma
286
hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma
287
288
-# *** RV32V Extension ***
289
+# *** RV32H Base Instruction Set ***
290
+hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2
291
+hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2
292
+hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s
293
294
# *** Vector loads and stores are encoded within LOADFP/STORE-FP ***
295
vlb_v ... 100 . 00000 ..... 000 ..... 0000111 @r2_nfvm
296
@@ -XXX,XX +XXX,XX @@ vcompress_vm 010111 - ..... ..... 010 ..... 1010111 @r
297
298
vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm
299
vsetvl 1000000 ..... ..... 111 ..... 1010111 @r
300
+
301
+#*** Vector AMO operations (in addition to Zvamo) ***
302
+vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm
303
+vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm
304
+vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm
305
+vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm
306
+vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm
307
+vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm
308
+vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm
309
+vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm
310
+vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm
311
diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c
312
index XXXXXXX..XXXXXXX 100644
313
--- a/target/riscv/fpu_helper.c
314
+++ b/target/riscv/fpu_helper.c
315
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_s(CPURISCVState *env, uint64_t rs1)
316
return (int32_t)float32_to_uint32(frs1, &env->fp_status);
317
}
318
319
-uint64_t helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1)
320
+target_ulong helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1)
321
{
322
float32 frs1 = check_nanbox_s(rs1);
323
return float32_to_int64(frs1, &env->fp_status);
324
}
325
326
-uint64_t helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1)
327
+target_ulong helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1)
328
{
329
float32 frs1 = check_nanbox_s(rs1);
330
return float32_to_uint64(frs1, &env->fp_status);
331
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1)
332
return nanbox_s(uint32_to_float32((uint32_t)rs1, &env->fp_status));
333
}
334
335
-uint64_t helper_fcvt_s_l(CPURISCVState *env, uint64_t rs1)
336
+uint64_t helper_fcvt_s_l(CPURISCVState *env, target_ulong rs1)
337
{
338
return nanbox_s(int64_to_float32(rs1, &env->fp_status));
339
}
340
341
-uint64_t helper_fcvt_s_lu(CPURISCVState *env, uint64_t rs1)
342
+uint64_t helper_fcvt_s_lu(CPURISCVState *env, target_ulong rs1)
343
{
344
return nanbox_s(uint64_to_float32(rs1, &env->fp_status));
345
}
346
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1)
347
return (int32_t)float64_to_uint32(frs1, &env->fp_status);
348
}
349
350
-uint64_t helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1)
351
+target_ulong helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1)
352
{
353
return float64_to_int64(frs1, &env->fp_status);
354
}
355
356
-uint64_t helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1)
357
+target_ulong helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1)
358
{
359
return float64_to_uint64(frs1, &env->fp_status);
360
}
361
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_d_wu(CPURISCVState *env, target_ulong rs1)
362
return uint32_to_float64((uint32_t)rs1, &env->fp_status);
363
}
364
365
-uint64_t helper_fcvt_d_l(CPURISCVState *env, uint64_t rs1)
366
+uint64_t helper_fcvt_d_l(CPURISCVState *env, target_ulong rs1)
367
{
368
return int64_to_float64(rs1, &env->fp_status);
369
}
370
371
-uint64_t helper_fcvt_d_lu(CPURISCVState *env, uint64_t rs1)
372
+uint64_t helper_fcvt_d_lu(CPURISCVState *env, target_ulong rs1)
373
{
374
return uint64_to_float64(rs1, &env->fp_status);
375
}
376
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
377
index XXXXXXX..XXXXXXX 100644
378
--- a/target/riscv/translate.c
379
+++ b/target/riscv/translate.c
380
@@ -XXX,XX +XXX,XX @@ EX_SH(12)
381
} \
382
} while (0)
383
384
+#define REQUIRE_64BIT(ctx) do { \
385
+ if (is_32bit(ctx)) { \
386
+ return false; \
387
+ } \
388
+} while (0)
389
+
390
static int ex_rvc_register(DisasContext *ctx, int reg)
391
{
392
return 8 + reg;
393
@@ -XXX,XX +XXX,XX @@ static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a,
394
return true;
50
return true;
395
}
51
}
396
52
397
-#ifdef TARGET_RISCV64
53
static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
398
static void gen_addw(TCGv ret, TCGv arg1, TCGv arg2)
399
{
54
{
400
tcg_gen_add_tl(ret, arg1, arg2);
55
REQUIRE_ZICBOM(ctx);
401
@@ -XXX,XX +XXX,XX @@ static bool gen_arith_div_uw(DisasContext *ctx, arg_r *a,
56
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
57
+ TCGv src = get_address(ctx, a->rs1, 0);
58
+
59
+ gen_helper_cbo_clean_flush(tcg_env, src);
402
return true;
60
return true;
403
}
61
}
404
62
405
-#endif
63
static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
406
-
407
static bool gen_arith(DisasContext *ctx, arg_r *a,
408
void(*func)(TCGv, TCGv, TCGv))
409
{
64
{
410
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
65
REQUIRE_ZICBOM(ctx);
411
index XXXXXXX..XXXXXXX 100644
66
- gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]);
412
--- a/target/riscv/vector_helper.c
67
+ TCGv src = get_address(ctx, a->rs1, 0);
413
+++ b/target/riscv/vector_helper.c
68
+
414
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominw_v_w, 32, 32, H4, DO_MIN, l)
69
+ gen_helper_cbo_inval(tcg_env, src);
415
GEN_VEXT_AMO_NOATOMIC_OP(vamomaxw_v_w, 32, 32, H4, DO_MAX, l)
416
GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_w, 32, 32, H4, DO_MINU, l)
417
GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_w, 32, 32, H4, DO_MAXU, l)
418
-#ifdef TARGET_RISCV64
419
GEN_VEXT_AMO_NOATOMIC_OP(vamoswapw_v_d, 64, 32, H8, DO_SWAP, l)
420
GEN_VEXT_AMO_NOATOMIC_OP(vamoswapd_v_d, 64, 64, H8, DO_SWAP, q)
421
GEN_VEXT_AMO_NOATOMIC_OP(vamoaddw_v_d, 64, 32, H8, DO_ADD, l)
422
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_d, 64, 32, H8, DO_MINU, l)
423
GEN_VEXT_AMO_NOATOMIC_OP(vamominud_v_d, 64, 64, H8, DO_MINU, q)
424
GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_d, 64, 32, H8, DO_MAXU, l)
425
GEN_VEXT_AMO_NOATOMIC_OP(vamomaxud_v_d, 64, 64, H8, DO_MAXU, q)
426
-#endif
427
428
static inline void
429
vext_amo_noatomic(void *vs3, void *v0, target_ulong base,
430
@@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vs3, void *v0, target_ulong base, \
431
GETPC()); \
432
}
433
434
-#ifdef TARGET_RISCV64
435
GEN_VEXT_AMO(vamoswapw_v_d, int32_t, int64_t, idx_d, clearq)
436
GEN_VEXT_AMO(vamoswapd_v_d, int64_t, int64_t, idx_d, clearq)
437
GEN_VEXT_AMO(vamoaddw_v_d, int32_t, int64_t, idx_d, clearq)
438
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO(vamominuw_v_d, uint32_t, uint64_t, idx_d, clearq)
439
GEN_VEXT_AMO(vamominud_v_d, uint64_t, uint64_t, idx_d, clearq)
440
GEN_VEXT_AMO(vamomaxuw_v_d, uint32_t, uint64_t, idx_d, clearq)
441
GEN_VEXT_AMO(vamomaxud_v_d, uint64_t, uint64_t, idx_d, clearq)
442
-#endif
443
GEN_VEXT_AMO(vamoswapw_v_w, int32_t, int32_t, idx_w, clearl)
444
GEN_VEXT_AMO(vamoaddw_v_w, int32_t, int32_t, idx_w, clearl)
445
GEN_VEXT_AMO(vamoxorw_v_w, int32_t, int32_t, idx_w, clearl)
446
diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc
447
index XXXXXXX..XXXXXXX 100644
448
--- a/target/riscv/insn_trans/trans_rva.c.inc
449
+++ b/target/riscv/insn_trans/trans_rva.c.inc
450
@@ -XXX,XX +XXX,XX @@ static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a)
451
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL));
452
}
453
454
-#ifdef TARGET_RISCV64
455
-
456
static bool trans_lr_d(DisasContext *ctx, arg_lr_d *a)
457
{
458
+ REQUIRE_64BIT(ctx);
459
return gen_lr(ctx, a, MO_ALIGN | MO_TEQ);
460
}
461
462
static bool trans_sc_d(DisasContext *ctx, arg_sc_d *a)
463
{
464
+ REQUIRE_64BIT(ctx);
465
return gen_sc(ctx, a, (MO_ALIGN | MO_TEQ));
466
}
467
468
static bool trans_amoswap_d(DisasContext *ctx, arg_amoswap_d *a)
469
{
470
+ REQUIRE_64BIT(ctx);
471
return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TEQ));
472
}
473
474
static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a)
475
{
476
+ REQUIRE_64BIT(ctx);
477
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TEQ));
478
}
479
480
static bool trans_amoxor_d(DisasContext *ctx, arg_amoxor_d *a)
481
{
482
+ REQUIRE_64BIT(ctx);
483
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TEQ));
484
}
485
486
static bool trans_amoand_d(DisasContext *ctx, arg_amoand_d *a)
487
{
488
+ REQUIRE_64BIT(ctx);
489
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TEQ));
490
}
491
492
static bool trans_amoor_d(DisasContext *ctx, arg_amoor_d *a)
493
{
494
+ REQUIRE_64BIT(ctx);
495
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TEQ));
496
}
497
498
static bool trans_amomin_d(DisasContext *ctx, arg_amomin_d *a)
499
{
500
+ REQUIRE_64BIT(ctx);
501
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TEQ));
502
}
503
504
static bool trans_amomax_d(DisasContext *ctx, arg_amomax_d *a)
505
{
506
+ REQUIRE_64BIT(ctx);
507
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TEQ));
508
}
509
510
static bool trans_amominu_d(DisasContext *ctx, arg_amominu_d *a)
511
{
512
+ REQUIRE_64BIT(ctx);
513
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TEQ));
514
}
515
516
static bool trans_amomaxu_d(DisasContext *ctx, arg_amomaxu_d *a)
517
{
518
+ REQUIRE_64BIT(ctx);
519
return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TEQ));
520
}
521
-#endif
522
diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc
523
index XXXXXXX..XXXXXXX 100644
524
--- a/target/riscv/insn_trans/trans_rvd.c.inc
525
+++ b/target/riscv/insn_trans/trans_rvd.c.inc
526
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a)
527
return true;
70
return true;
528
}
71
}
529
72
530
-#ifdef TARGET_RISCV64
73
static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
531
-
532
static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
533
{
74
{
534
+ REQUIRE_64BIT(ctx);
75
REQUIRE_ZICBOZ(ctx);
535
REQUIRE_FPU;
76
- gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]);
536
REQUIRE_EXT(ctx, RVD);
77
+ TCGv src = get_address(ctx, a->rs1, 0);
537
78
+
538
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
79
+ gen_helper_cbo_zero(tcg_env, src);
539
540
static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
541
{
542
+ REQUIRE_64BIT(ctx);
543
REQUIRE_FPU;
544
REQUIRE_EXT(ctx, RVD);
545
546
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
547
548
static bool trans_fmv_x_d(DisasContext *ctx, arg_fmv_x_d *a)
549
{
550
+ REQUIRE_64BIT(ctx);
551
REQUIRE_FPU;
552
REQUIRE_EXT(ctx, RVD);
553
554
+#ifdef TARGET_RISCV64
555
gen_set_gpr(a->rd, cpu_fpr[a->rs1]);
556
return true;
557
+#else
558
+ qemu_build_not_reached();
559
+#endif
560
}
561
562
static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
563
{
564
+ REQUIRE_64BIT(ctx);
565
REQUIRE_FPU;
566
REQUIRE_EXT(ctx, RVD);
567
568
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
569
570
static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
571
{
572
+ REQUIRE_64BIT(ctx);
573
REQUIRE_FPU;
574
REQUIRE_EXT(ctx, RVD);
575
576
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
577
578
static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
579
{
580
+ REQUIRE_64BIT(ctx);
581
REQUIRE_FPU;
582
REQUIRE_EXT(ctx, RVD);
583
584
+#ifdef TARGET_RISCV64
585
TCGv t0 = tcg_temp_new();
586
gen_get_gpr(t0, a->rs1);
587
588
@@ -XXX,XX +XXX,XX @@ static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
589
tcg_temp_free(t0);
590
mark_fs_dirty(ctx);
591
return true;
592
-}
593
+#else
594
+ qemu_build_not_reached();
595
#endif
596
+}
597
diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc
598
index XXXXXXX..XXXXXXX 100644
599
--- a/target/riscv/insn_trans/trans_rvf.c.inc
600
+++ b/target/riscv/insn_trans/trans_rvf.c.inc
601
@@ -XXX,XX +XXX,XX @@ static bool trans_fmv_w_x(DisasContext *ctx, arg_fmv_w_x *a)
602
return true;
80
return true;
603
}
81
}
604
605
-#ifdef TARGET_RISCV64
606
static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
607
{
608
+ REQUIRE_64BIT(ctx);
609
REQUIRE_FPU;
610
REQUIRE_EXT(ctx, RVF);
611
612
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
613
614
static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
615
{
616
+ REQUIRE_64BIT(ctx);
617
REQUIRE_FPU;
618
REQUIRE_EXT(ctx, RVF);
619
620
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
621
622
static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
623
{
624
+ REQUIRE_64BIT(ctx);
625
REQUIRE_FPU;
626
REQUIRE_EXT(ctx, RVF);
627
628
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
629
630
static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
631
{
632
+ REQUIRE_64BIT(ctx);
633
REQUIRE_FPU;
634
REQUIRE_EXT(ctx, RVF);
635
636
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
637
tcg_temp_free(t0);
638
return true;
639
}
640
-#endif
641
diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc
642
index XXXXXXX..XXXXXXX 100644
643
--- a/target/riscv/insn_trans/trans_rvh.c.inc
644
+++ b/target/riscv/insn_trans/trans_rvh.c.inc
645
@@ -XXX,XX +XXX,XX @@ static bool trans_hsv_w(DisasContext *ctx, arg_hsv_w *a)
646
#endif
647
}
648
649
-#ifdef TARGET_RISCV64
650
static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a)
651
{
652
+ REQUIRE_64BIT(ctx);
653
REQUIRE_EXT(ctx, RVH);
654
+
655
#ifndef CONFIG_USER_ONLY
656
TCGv t0 = tcg_temp_new();
657
TCGv t1 = tcg_temp_new();
658
@@ -XXX,XX +XXX,XX @@ static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a)
659
660
static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a)
661
{
662
+ REQUIRE_64BIT(ctx);
663
REQUIRE_EXT(ctx, RVH);
664
+
665
#ifndef CONFIG_USER_ONLY
666
TCGv t0 = tcg_temp_new();
667
TCGv t1 = tcg_temp_new();
668
@@ -XXX,XX +XXX,XX @@ static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a)
669
670
static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a)
671
{
672
+ REQUIRE_64BIT(ctx);
673
REQUIRE_EXT(ctx, RVH);
674
+
675
#ifndef CONFIG_USER_ONLY
676
TCGv t0 = tcg_temp_new();
677
TCGv dat = tcg_temp_new();
678
@@ -XXX,XX +XXX,XX @@ static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a)
679
return false;
680
#endif
681
}
682
-#endif
683
684
static bool trans_hlvx_hu(DisasContext *ctx, arg_hlvx_hu *a)
685
{
686
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
687
index XXXXXXX..XXXXXXX 100644
688
--- a/target/riscv/insn_trans/trans_rvi.c.inc
689
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
690
@@ -XXX,XX +XXX,XX @@ static bool trans_sw(DisasContext *ctx, arg_sw *a)
691
return gen_store(ctx, a, MO_TESL);
692
}
693
694
-#ifdef TARGET_RISCV64
695
static bool trans_lwu(DisasContext *ctx, arg_lwu *a)
696
{
697
+ REQUIRE_64BIT(ctx);
698
return gen_load(ctx, a, MO_TEUL);
699
}
700
701
static bool trans_ld(DisasContext *ctx, arg_ld *a)
702
{
703
+ REQUIRE_64BIT(ctx);
704
return gen_load(ctx, a, MO_TEQ);
705
}
706
707
static bool trans_sd(DisasContext *ctx, arg_sd *a)
708
{
709
+ REQUIRE_64BIT(ctx);
710
return gen_store(ctx, a, MO_TEQ);
711
}
712
-#endif
713
714
static bool trans_addi(DisasContext *ctx, arg_addi *a)
715
{
716
@@ -XXX,XX +XXX,XX @@ static bool trans_and(DisasContext *ctx, arg_and *a)
717
return gen_arith(ctx, a, &tcg_gen_and_tl);
718
}
719
720
-#ifdef TARGET_RISCV64
721
static bool trans_addiw(DisasContext *ctx, arg_addiw *a)
722
{
723
+ REQUIRE_64BIT(ctx);
724
return gen_arith_imm_tl(ctx, a, &gen_addw);
725
}
726
727
static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
728
{
729
+ REQUIRE_64BIT(ctx);
730
TCGv source1;
731
source1 = tcg_temp_new();
732
gen_get_gpr(source1, a->rs1);
733
@@ -XXX,XX +XXX,XX @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
734
735
static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
736
{
737
+ REQUIRE_64BIT(ctx);
738
TCGv t = tcg_temp_new();
739
gen_get_gpr(t, a->rs1);
740
tcg_gen_extract_tl(t, t, a->shamt, 32 - a->shamt);
741
@@ -XXX,XX +XXX,XX @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
742
743
static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
744
{
745
+ REQUIRE_64BIT(ctx);
746
TCGv t = tcg_temp_new();
747
gen_get_gpr(t, a->rs1);
748
tcg_gen_sextract_tl(t, t, a->shamt, 32 - a->shamt);
749
@@ -XXX,XX +XXX,XX @@ static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
750
751
static bool trans_addw(DisasContext *ctx, arg_addw *a)
752
{
753
+ REQUIRE_64BIT(ctx);
754
return gen_arith(ctx, a, &gen_addw);
755
}
756
757
static bool trans_subw(DisasContext *ctx, arg_subw *a)
758
{
759
+ REQUIRE_64BIT(ctx);
760
return gen_arith(ctx, a, &gen_subw);
761
}
762
763
static bool trans_sllw(DisasContext *ctx, arg_sllw *a)
764
{
765
+ REQUIRE_64BIT(ctx);
766
TCGv source1 = tcg_temp_new();
767
TCGv source2 = tcg_temp_new();
768
769
@@ -XXX,XX +XXX,XX @@ static bool trans_sllw(DisasContext *ctx, arg_sllw *a)
770
771
static bool trans_srlw(DisasContext *ctx, arg_srlw *a)
772
{
773
+ REQUIRE_64BIT(ctx);
774
TCGv source1 = tcg_temp_new();
775
TCGv source2 = tcg_temp_new();
776
777
@@ -XXX,XX +XXX,XX @@ static bool trans_srlw(DisasContext *ctx, arg_srlw *a)
778
779
static bool trans_sraw(DisasContext *ctx, arg_sraw *a)
780
{
781
+ REQUIRE_64BIT(ctx);
782
TCGv source1 = tcg_temp_new();
783
TCGv source2 = tcg_temp_new();
784
785
@@ -XXX,XX +XXX,XX @@ static bool trans_sraw(DisasContext *ctx, arg_sraw *a)
786
787
return true;
788
}
789
-#endif
790
791
static bool trans_fence(DisasContext *ctx, arg_fence *a)
792
{
793
diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc
794
index XXXXXXX..XXXXXXX 100644
795
--- a/target/riscv/insn_trans/trans_rvm.c.inc
796
+++ b/target/riscv/insn_trans/trans_rvm.c.inc
797
@@ -XXX,XX +XXX,XX @@ static bool trans_remu(DisasContext *ctx, arg_remu *a)
798
return gen_arith(ctx, a, &gen_remu);
799
}
800
801
-#ifdef TARGET_RISCV64
802
static bool trans_mulw(DisasContext *ctx, arg_mulw *a)
803
{
804
+ REQUIRE_64BIT(ctx);
805
REQUIRE_EXT(ctx, RVM);
806
+
807
return gen_arith(ctx, a, &gen_mulw);
808
}
809
810
static bool trans_divw(DisasContext *ctx, arg_divw *a)
811
{
812
+ REQUIRE_64BIT(ctx);
813
REQUIRE_EXT(ctx, RVM);
814
+
815
return gen_arith_div_w(ctx, a, &gen_div);
816
}
817
818
static bool trans_divuw(DisasContext *ctx, arg_divuw *a)
819
{
820
+ REQUIRE_64BIT(ctx);
821
REQUIRE_EXT(ctx, RVM);
822
+
823
return gen_arith_div_uw(ctx, a, &gen_divu);
824
}
825
826
static bool trans_remw(DisasContext *ctx, arg_remw *a)
827
{
828
+ REQUIRE_64BIT(ctx);
829
REQUIRE_EXT(ctx, RVM);
830
+
831
return gen_arith_div_w(ctx, a, &gen_rem);
832
}
833
834
static bool trans_remuw(DisasContext *ctx, arg_remuw *a)
835
{
836
+ REQUIRE_64BIT(ctx);
837
REQUIRE_EXT(ctx, RVM);
838
+
839
return gen_arith_div_uw(ctx, a, &gen_remu);
840
}
841
-#endif
842
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
843
index XXXXXXX..XXXXXXX 100644
844
--- a/target/riscv/insn_trans/trans_rvv.c.inc
845
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
846
@@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq)
847
gen_helper_vamominuw_v_w,
848
gen_helper_vamomaxuw_v_w
849
};
850
-#ifdef TARGET_RISCV64
851
static gen_helper_amo *const fnsd[18] = {
852
gen_helper_vamoswapw_v_d,
853
gen_helper_vamoaddw_v_d,
854
@@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq)
855
gen_helper_vamominud_v_d,
856
gen_helper_vamomaxud_v_d
857
};
858
-#endif
859
860
if (tb_cflags(s->base.tb) & CF_PARALLEL) {
861
gen_helper_exit_atomic(cpu_env);
862
@@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq)
863
return true;
864
} else {
865
if (s->sew == 3) {
866
-#ifdef TARGET_RISCV64
867
- fn = fnsd[seq];
868
-#else
869
- /* Check done in amo_check(). */
870
- g_assert_not_reached();
871
-#endif
872
+ if (!is_32bit(s)) {
873
+ fn = fnsd[seq];
874
+ } else {
875
+ /* Check done in amo_check(). */
876
+ g_assert_not_reached();
877
+ }
878
} else {
879
assert(seq < ARRAY_SIZE(fnsw));
880
fn = fnsw[seq];
881
@@ -XXX,XX +XXX,XX @@ static bool amo_check(DisasContext *s, arg_rwdvm* a)
882
((1 << s->sew) >= 4));
883
}
884
885
+static bool amo_check64(DisasContext *s, arg_rwdvm* a)
886
+{
887
+ return !is_32bit(s) && amo_check(s, a);
888
+}
889
+
890
GEN_VEXT_TRANS(vamoswapw_v, 0, rwdvm, amo_op, amo_check)
891
GEN_VEXT_TRANS(vamoaddw_v, 1, rwdvm, amo_op, amo_check)
892
GEN_VEXT_TRANS(vamoxorw_v, 2, rwdvm, amo_op, amo_check)
893
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_TRANS(vamominw_v, 5, rwdvm, amo_op, amo_check)
894
GEN_VEXT_TRANS(vamomaxw_v, 6, rwdvm, amo_op, amo_check)
895
GEN_VEXT_TRANS(vamominuw_v, 7, rwdvm, amo_op, amo_check)
896
GEN_VEXT_TRANS(vamomaxuw_v, 8, rwdvm, amo_op, amo_check)
897
-#ifdef TARGET_RISCV64
898
-GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check)
899
-GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check)
900
-GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check)
901
-GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check)
902
-GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check)
903
-GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check)
904
-GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check)
905
-GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check)
906
-GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check)
907
-#endif
908
+GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check64)
909
+GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check64)
910
+GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check64)
911
+GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check64)
912
+GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check64)
913
+GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check64)
914
+GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check64)
915
+GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check64)
916
+GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check64)
917
918
/*
919
*** Vector Integer Arithmetic Instructions
920
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
921
index XXXXXXX..XXXXXXX 100644
922
--- a/target/riscv/meson.build
923
+++ b/target/riscv/meson.build
924
@@ -XXX,XX +XXX,XX @@ gen32 = [
925
926
gen64 = [
927
decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']),
928
- decodetree.process('insn32.decode', extra_args: [dir / 'insn32-64.decode', '--static-decode=decode_insn32']),
929
+ decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'),
930
]
931
932
riscv_ss = ss.source_set()
933
--
82
--
934
2.31.1
83
2.45.1
935
936
diff view generated by jsdifflib
1
From: Hou Weiying <weiying_hou@outlook.com>
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
2
2
3
This commit adds support for ePMP v0.9.1.
3
In AIA spec, each hart (or each hart within a group) has a unique hart
4
number to locate the memory pages of interrupt files in the address
5
space. The number of bits required to represent any hart number is equal
6
to ceil(log2(hmax + 1)), where hmax is the largest hart number among
7
groups.
4
8
5
The ePMP spec can be found in:
9
However, if the largest hart number among groups is a power of 2, QEMU
6
https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8
10
will pass an inaccurate hart-index-bit setting to Linux. For example, when
11
the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient
12
to represent 4 harts, but we passes 3 to Linux. The code needs to be
13
updated to ensure accurate hart-index-bit settings.
7
14
8
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
15
Additionally, a Linux patch[1] is necessary to correctly recover the hart
9
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
16
index when the guest OS has only 1 hart, where the hart-index-bit is 0.
10
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
17
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
[1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/
12
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
19
13
Message-id: fef23b885f9649a4d54e7c98b168bdec5d297bb1.1618812899.git.alistair.francis@wdc.com
20
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
14
[ Changes by AF:
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
15
- Rebase on master
22
Cc: qemu-stable <qemu-stable@nongnu.org>
16
- Update to latest spec
23
Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com>
17
- Use a switch case to handle ePMP MML permissions
18
- Fix a few bugs
19
]
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
21
---
25
---
22
target/riscv/pmp.c | 154 ++++++++++++++++++++++++++++++++++++++++++---
26
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
23
1 file changed, 146 insertions(+), 8 deletions(-)
27
1 file changed, 8 insertions(+), 1 deletion(-)
24
28
25
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
26
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
27
--- a/target/riscv/pmp.c
31
--- a/target/riscv/kvm/kvm-cpu.c
28
+++ b/target/riscv/pmp.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
29
@@ -XXX,XX +XXX,XX @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index)
33
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
30
static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
34
}
31
{
35
}
32
if (pmp_index < MAX_RISCV_PMPS) {
36
33
- if (!pmp_is_locked(env, pmp_index)) {
37
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
34
- env->pmp_state.pmp[pmp_index].cfg_reg = val;
35
- pmp_update_rule(env, pmp_index);
36
+ bool locked = true;
37
+
38
+
38
+ if (riscv_feature(env, RISCV_FEATURE_EPMP)) {
39
+ if (max_hart_per_socket > 1) {
39
+ /* mseccfg.RLB is set */
40
+ max_hart_per_socket--;
40
+ if (MSECCFG_RLB_ISSET(env)) {
41
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
41
+ locked = false;
42
+ } else {
42
+ }
43
+ hart_bits = 0;
43
+
44
+ /* mseccfg.MML is not set */
45
+ if (!MSECCFG_MML_ISSET(env) && !pmp_is_locked(env, pmp_index)) {
46
+ locked = false;
47
+ }
48
+
49
+ /* mseccfg.MML is set */
50
+ if (MSECCFG_MML_ISSET(env)) {
51
+ /* not adding execute bit */
52
+ if ((val & PMP_LOCK) != 0 && (val & PMP_EXEC) != PMP_EXEC) {
53
+ locked = false;
54
+ }
55
+ /* shared region and not adding X bit */
56
+ if ((val & PMP_LOCK) != PMP_LOCK &&
57
+ (val & 0x7) != (PMP_WRITE | PMP_EXEC)) {
58
+ locked = false;
59
+ }
60
+ }
61
} else {
62
+ if (!pmp_is_locked(env, pmp_index)) {
63
+ locked = false;
64
+ }
65
+ }
66
+
67
+ if (locked) {
68
qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n");
69
+ } else {
70
+ env->pmp_state.pmp[pmp_index].cfg_reg = val;
71
+ pmp_update_rule(env, pmp_index);
72
}
73
} else {
74
qemu_log_mask(LOG_GUEST_ERROR,
75
@@ -XXX,XX +XXX,XX @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr,
76
{
77
bool ret;
78
79
+ if (riscv_feature(env, RISCV_FEATURE_EPMP)) {
80
+ if (MSECCFG_MMWP_ISSET(env)) {
81
+ /*
82
+ * The Machine Mode Whitelist Policy (mseccfg.MMWP) is set
83
+ * so we default to deny all, even for M-mode.
84
+ */
85
+ *allowed_privs = 0;
86
+ return false;
87
+ } else if (MSECCFG_MML_ISSET(env)) {
88
+ /*
89
+ * The Machine Mode Lockdown (mseccfg.MML) bit is set
90
+ * so we can only execute code in M-mode with an applicable
91
+ * rule. Other modes are disabled.
92
+ */
93
+ if (mode == PRV_M && !(privs & PMP_EXEC)) {
94
+ ret = true;
95
+ *allowed_privs = PMP_READ | PMP_WRITE;
96
+ } else {
97
+ ret = false;
98
+ *allowed_privs = 0;
99
+ }
100
+
101
+ return ret;
102
+ }
103
+ }
44
+ }
104
+
45
+
105
if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) {
46
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
106
/*
47
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
107
* Privileged spec v1.10 states if HW doesn't implement any PMP entry
48
&hart_bits, true, NULL);
108
@@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
109
pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg);
110
111
/*
112
- * If the PMP entry is not off and the address is in range, do the priv
113
- * check
114
+ * Convert the PMP permissions to match the truth table in the
115
+ * ePMP spec.
116
*/
117
+ const uint8_t epmp_operation =
118
+ ((env->pmp_state.pmp[i].cfg_reg & PMP_LOCK) >> 4) |
119
+ ((env->pmp_state.pmp[i].cfg_reg & PMP_READ) << 2) |
120
+ (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |
121
+ ((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2);
122
+
123
if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) {
124
- *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
125
- if ((mode != PRV_M) || pmp_is_locked(env, i)) {
126
- *allowed_privs &= env->pmp_state.pmp[i].cfg_reg;
127
+ /*
128
+ * If the PMP entry is not off and the address is in range,
129
+ * do the priv check
130
+ */
131
+ if (!MSECCFG_MML_ISSET(env)) {
132
+ /*
133
+ * If mseccfg.MML Bit is not set, do pmp priv check
134
+ * This will always apply to regular PMP.
135
+ */
136
+ *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
137
+ if ((mode != PRV_M) || pmp_is_locked(env, i)) {
138
+ *allowed_privs &= env->pmp_state.pmp[i].cfg_reg;
139
+ }
140
+ } else {
141
+ /*
142
+ * If mseccfg.MML Bit set, do the enhanced pmp priv check
143
+ */
144
+ if (mode == PRV_M) {
145
+ switch (epmp_operation) {
146
+ case 0:
147
+ case 1:
148
+ case 4:
149
+ case 5:
150
+ case 6:
151
+ case 7:
152
+ case 8:
153
+ *allowed_privs = 0;
154
+ break;
155
+ case 2:
156
+ case 3:
157
+ case 14:
158
+ *allowed_privs = PMP_READ | PMP_WRITE;
159
+ break;
160
+ case 9:
161
+ case 10:
162
+ *allowed_privs = PMP_EXEC;
163
+ break;
164
+ case 11:
165
+ case 13:
166
+ *allowed_privs = PMP_READ | PMP_EXEC;
167
+ break;
168
+ case 12:
169
+ case 15:
170
+ *allowed_privs = PMP_READ;
171
+ break;
172
+ }
173
+ } else {
174
+ switch (epmp_operation) {
175
+ case 0:
176
+ case 8:
177
+ case 9:
178
+ case 12:
179
+ case 13:
180
+ case 14:
181
+ *allowed_privs = 0;
182
+ break;
183
+ case 1:
184
+ case 10:
185
+ case 11:
186
+ *allowed_privs = PMP_EXEC;
187
+ break;
188
+ case 2:
189
+ case 4:
190
+ case 15:
191
+ *allowed_privs = PMP_READ;
192
+ break;
193
+ case 3:
194
+ case 6:
195
+ *allowed_privs = PMP_READ | PMP_WRITE;
196
+ break;
197
+ case 5:
198
+ *allowed_privs = PMP_READ | PMP_EXEC;
199
+ break;
200
+ case 7:
201
+ *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
202
+ break;
203
+ }
204
+ }
205
}
206
207
ret = ((privs & *allowed_privs) == privs);
208
--
49
--
209
2.31.1
50
2.45.1
210
211
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length
4
in bytes, when in this context we want 'reg_width' as the length in
5
bits.
6
7
Fix 'reg_width' back to the value in bits like 7cb59921c05a
8
("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set
9
beforehand.
10
11
While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more
12
clarity about what the variable represents. 'bitsize' is also used in
13
riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to
14
gdb_feature_builder_append_reg().
15
16
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
17
Cc: Alex Bennée <alex.bennee@linaro.org>
18
Reported-by: Robin Dapp <rdapp.gcc@gmail.com>
19
Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML")
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
22
Acked-by: Alex Bennée <alex.bennee@linaro.org>
23
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Cc: qemu-stable <qemu-stable@nongnu.org>
26
Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: 302b208f40373557fa11b351b5c9f43039ca8ea3.1617290165.git.alistair.francis@wdc.com
5
---
28
---
6
target/riscv/cpu.h | 11 +++++++----
29
target/riscv/gdbstub.c | 6 +++---
7
target/riscv/csr.c | 37 ++++++++++++++++++-------------------
30
1 file changed, 3 insertions(+), 3 deletions(-)
8
target/riscv/gdbstub.c | 8 ++++----
9
target/riscv/op_helper.c | 18 +++++++++---------
10
4 files changed, 38 insertions(+), 36 deletions(-)
11
31
12
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/target/riscv/cpu.h
15
+++ b/target/riscv/cpu.h
16
@@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
17
*pflags = flags;
18
}
19
20
-int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
21
- target_ulong new_value, target_ulong write_mask);
22
-int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value,
23
- target_ulong new_value, target_ulong write_mask);
24
+RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
25
+ target_ulong *ret_value,
26
+ target_ulong new_value, target_ulong write_mask);
27
+RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno,
28
+ target_ulong *ret_value,
29
+ target_ulong new_value,
30
+ target_ulong write_mask);
31
32
static inline void riscv_csr_write(CPURISCVState *env, int csrno,
33
target_ulong val)
34
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/csr.c
37
+++ b/target/riscv/csr.c
38
@@ -XXX,XX +XXX,XX @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno,
39
* csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value);
40
*/
41
42
-int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
43
- target_ulong new_value, target_ulong write_mask)
44
+RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
45
+ target_ulong *ret_value,
46
+ target_ulong new_value, target_ulong write_mask)
47
{
48
- int ret;
49
+ RISCVException ret;
50
target_ulong old_value;
51
RISCVCPU *cpu = env_archcpu(env);
52
53
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
54
55
if ((write_mask && read_only) ||
56
(!env->debugger && (effective_priv < get_field(csrno, 0x300)))) {
57
- return -RISCV_EXCP_ILLEGAL_INST;
58
+ return RISCV_EXCP_ILLEGAL_INST;
59
}
60
#endif
61
62
/* ensure the CSR extension is enabled. */
63
if (!cpu->cfg.ext_icsr) {
64
- return -RISCV_EXCP_ILLEGAL_INST;
65
+ return RISCV_EXCP_ILLEGAL_INST;
66
}
67
68
/* check predicate */
69
if (!csr_ops[csrno].predicate) {
70
- return -RISCV_EXCP_ILLEGAL_INST;
71
+ return RISCV_EXCP_ILLEGAL_INST;
72
}
73
ret = csr_ops[csrno].predicate(env, csrno);
74
if (ret != RISCV_EXCP_NONE) {
75
- return -ret;
76
+ return ret;
77
}
78
79
/* execute combined read/write operation if it exists */
80
if (csr_ops[csrno].op) {
81
- ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask);
82
- if (ret != RISCV_EXCP_NONE) {
83
- return -ret;
84
- }
85
- return 0;
86
+ return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask);
87
}
88
89
/* if no accessor exists then return failure */
90
if (!csr_ops[csrno].read) {
91
- return -RISCV_EXCP_ILLEGAL_INST;
92
+ return RISCV_EXCP_ILLEGAL_INST;
93
}
94
/* read old value */
95
ret = csr_ops[csrno].read(env, csrno, &old_value);
96
if (ret != RISCV_EXCP_NONE) {
97
- return -ret;
98
+ return ret;
99
}
100
101
/* write value if writable and write mask set, otherwise drop writes */
102
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
103
if (csr_ops[csrno].write) {
104
ret = csr_ops[csrno].write(env, csrno, new_value);
105
if (ret != RISCV_EXCP_NONE) {
106
- return -ret;
107
+ return ret;
108
}
109
}
110
}
111
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
112
*ret_value = old_value;
113
}
114
115
- return 0;
116
+ return RISCV_EXCP_NONE;
117
}
118
119
/*
120
* Debugger support. If not in user mode, set env->debugger before the
121
* riscv_csrrw call and clear it after the call.
122
*/
123
-int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value,
124
- target_ulong new_value, target_ulong write_mask)
125
+RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno,
126
+ target_ulong *ret_value,
127
+ target_ulong new_value,
128
+ target_ulong write_mask)
129
{
130
- int ret;
131
+ RISCVException ret;
132
#if !defined(CONFIG_USER_ONLY)
133
env->debugger = true;
134
#endif
135
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
32
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
136
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
137
--- a/target/riscv/gdbstub.c
34
--- a/target/riscv/gdbstub.c
138
+++ b/target/riscv/gdbstub.c
35
+++ b/target/riscv/gdbstub.c
139
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n)
36
@@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg)
140
*/
37
static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
141
result = riscv_csrrw_debug(env, n - 32, &val,
38
{
142
0, 0);
39
RISCVCPU *cpu = RISCV_CPU(cs);
143
- if (result == 0) {
40
- int reg_width = cpu->cfg.vlenb;
144
+ if (result == RISCV_EXCP_NONE) {
41
+ int bitsize = cpu->cfg.vlenb << 3;
145
return gdb_get_regl(buf, val);
42
GDBFeatureBuilder builder;
146
}
43
int i;
44
45
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
46
47
/* First define types and totals in a whole VL */
48
for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) {
49
- int count = reg_width / vec_lanes[i].size;
50
+ int count = bitsize / vec_lanes[i].size;
51
gdb_feature_builder_append_tag(
52
&builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
53
vec_lanes[i].id, vec_lanes[i].gdb_type, count);
54
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
55
/* Define vector registers */
56
for (i = 0; i < 32; i++) {
57
gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i),
58
- reg_width, i, "riscv_vector", "vector");
59
+ bitsize, i, "riscv_vector", "vector");
147
}
60
}
148
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n)
61
149
*/
62
gdb_feature_builder_end(&builder);
150
result = riscv_csrrw_debug(env, n - 32, NULL,
151
val, -1);
152
- if (result == 0) {
153
+ if (result == RISCV_EXCP_NONE) {
154
return sizeof(target_ulong);
155
}
156
}
157
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n)
158
int result;
159
160
result = riscv_csrrw_debug(env, n, &val, 0, 0);
161
- if (result == 0) {
162
+ if (result == RISCV_EXCP_NONE) {
163
return gdb_get_regl(buf, val);
164
}
165
}
166
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n)
167
int result;
168
169
result = riscv_csrrw_debug(env, n, NULL, val, -1);
170
- if (result == 0) {
171
+ if (result == RISCV_EXCP_NONE) {
172
return sizeof(target_ulong);
173
}
174
}
175
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
176
index XXXXXXX..XXXXXXX 100644
177
--- a/target/riscv/op_helper.c
178
+++ b/target/riscv/op_helper.c
179
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, target_ulong src,
180
target_ulong csr)
181
{
182
target_ulong val = 0;
183
- int ret = riscv_csrrw(env, csr, &val, src, -1);
184
+ RISCVException ret = riscv_csrrw(env, csr, &val, src, -1);
185
186
- if (ret < 0) {
187
- riscv_raise_exception(env, -ret, GETPC());
188
+ if (ret != RISCV_EXCP_NONE) {
189
+ riscv_raise_exception(env, ret, GETPC());
190
}
191
return val;
192
}
193
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrs(CPURISCVState *env, target_ulong src,
194
target_ulong csr, target_ulong rs1_pass)
195
{
196
target_ulong val = 0;
197
- int ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0);
198
+ RISCVException ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0);
199
200
- if (ret < 0) {
201
- riscv_raise_exception(env, -ret, GETPC());
202
+ if (ret != RISCV_EXCP_NONE) {
203
+ riscv_raise_exception(env, ret, GETPC());
204
}
205
return val;
206
}
207
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src,
208
target_ulong csr, target_ulong rs1_pass)
209
{
210
target_ulong val = 0;
211
- int ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0);
212
+ RISCVException ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0);
213
214
- if (ret < 0) {
215
- riscv_raise_exception(env, -ret, GETPC());
216
+ if (ret != RISCV_EXCP_NONE) {
217
+ riscv_raise_exception(env, ret, GETPC());
218
}
219
return val;
220
}
221
--
63
--
222
2.31.1
64
2.45.1
223
65
224
66
diff view generated by jsdifflib
1
From: Vijai Kumar K <vijai@behindbytes.com>
1
From: Alistair Francis <alistair23@gmail.com>
2
2
3
Add documentation for Shakti C reference platform.
3
Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr
4
CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr
5
CSRs are part of the disassembly.
4
6
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
7
Reported-by: Eric DeVolder <eric_devolder@yahoo.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Message-id: 20210412174248.8668-1-vijai@behindbytes.com
9
Fixes: ea10325917 ("RISC-V Disassembler")
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Cc: qemu-stable <qemu-stable@nongnu.org>
12
Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
14
---
10
docs/system/riscv/shakti-c.rst | 82 ++++++++++++++++++++++++++++++++++
15
disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
11
1 file changed, 82 insertions(+)
16
1 file changed, 64 insertions(+), 1 deletion(-)
12
create mode 100644 docs/system/riscv/shakti-c.rst
13
17
14
diff --git a/docs/system/riscv/shakti-c.rst b/docs/system/riscv/shakti-c.rst
18
diff --git a/disas/riscv.c b/disas/riscv.c
15
new file mode 100644
19
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX
20
--- a/disas/riscv.c
17
--- /dev/null
21
+++ b/disas/riscv.c
18
+++ b/docs/system/riscv/shakti-c.rst
22
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
19
@@ -XXX,XX +XXX,XX @@
23
case 0x0383: return "mibound";
20
+Shakti C Reference Platform (``shakti_c``)
24
case 0x0384: return "mdbase";
21
+==========================================
25
case 0x0385: return "mdbound";
22
+
26
- case 0x03a0: return "pmpcfg3";
23
+Shakti C Reference Platform is a reference platform based on arty a7 100t
27
+ case 0x03a0: return "pmpcfg0";
24
+for the Shakti SoC.
28
+ case 0x03a1: return "pmpcfg1";
25
+
29
+ case 0x03a2: return "pmpcfg2";
26
+Shakti SoC is a SoC based on the Shakti C-class processor core. Shakti C
30
+ case 0x03a3: return "pmpcfg3";
27
+is a 64bit RV64GCSUN processor core.
31
+ case 0x03a4: return "pmpcfg4";
28
+
32
+ case 0x03a5: return "pmpcfg5";
29
+For more details on Shakti SoC, please see:
33
+ case 0x03a6: return "pmpcfg6";
30
+https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/fpga/boards/artya7-100t/c-class/README.rst
34
+ case 0x03a7: return "pmpcfg7";
31
+
35
+ case 0x03a8: return "pmpcfg8";
32
+For more info on the Shakti C-class core, please see:
36
+ case 0x03a9: return "pmpcfg9";
33
+https://c-class.readthedocs.io/en/latest/
37
+ case 0x03aa: return "pmpcfg10";
34
+
38
+ case 0x03ab: return "pmpcfg11";
35
+Supported devices
39
+ case 0x03ac: return "pmpcfg12";
36
+-----------------
40
+ case 0x03ad: return "pmpcfg13";
37
+
41
+ case 0x03ae: return "pmpcfg14";
38
+The ``shakti_c`` machine supports the following devices:
42
+ case 0x03af: return "pmpcfg15";
39
+
43
case 0x03b0: return "pmpaddr0";
40
+ * 1 C-class core
44
case 0x03b1: return "pmpaddr1";
41
+ * Core Level Interruptor (CLINT)
45
case 0x03b2: return "pmpaddr2";
42
+ * Platform-Level Interrupt Controller (PLIC)
46
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
43
+ * 1 UART
47
case 0x03bd: return "pmpaddr13";
44
+
48
case 0x03be: return "pmpaddr14";
45
+Boot options
49
case 0x03bf: return "pmpaddr15";
46
+------------
50
+ case 0x03c0: return "pmpaddr16";
47
+
51
+ case 0x03c1: return "pmpaddr17";
48
+The ``shakti_c`` machine can start using the standard -bios
52
+ case 0x03c2: return "pmpaddr18";
49
+functionality for loading the baremetal application or opensbi.
53
+ case 0x03c3: return "pmpaddr19";
50
+
54
+ case 0x03c4: return "pmpaddr20";
51
+Boot the machine
55
+ case 0x03c5: return "pmpaddr21";
52
+----------------
56
+ case 0x03c6: return "pmpaddr22";
53
+
57
+ case 0x03c7: return "pmpaddr23";
54
+Shakti SDK
58
+ case 0x03c8: return "pmpaddr24";
55
+~~~~~~~~~~
59
+ case 0x03c9: return "pmpaddr25";
56
+Shakti SDK can be used to generate the baremetal example UART applications.
60
+ case 0x03ca: return "pmpaddr26";
57
+
61
+ case 0x03cb: return "pmpaddr27";
58
+.. code-block:: bash
62
+ case 0x03cc: return "pmpaddr28";
59
+
63
+ case 0x03cd: return "pmpaddr29";
60
+ $ git clone https://gitlab.com/behindbytes/shakti-sdk.git
64
+ case 0x03ce: return "pmpaddr30";
61
+ $ cd shakti-sdk
65
+ case 0x03cf: return "pmpaddr31";
62
+ $ make software PROGRAM=loopback TARGET=artix7_100t
66
+ case 0x03d0: return "pmpaddr32";
63
+
67
+ case 0x03d1: return "pmpaddr33";
64
+Binary would be generated in:
68
+ case 0x03d2: return "pmpaddr34";
65
+ software/examples/uart_applns/loopback/output/loopback.shakti
69
+ case 0x03d3: return "pmpaddr35";
66
+
70
+ case 0x03d4: return "pmpaddr36";
67
+You could also download the precompiled example applicatons using below
71
+ case 0x03d5: return "pmpaddr37";
68
+commands.
72
+ case 0x03d6: return "pmpaddr38";
69
+
73
+ case 0x03d7: return "pmpaddr39";
70
+.. code-block:: bash
74
+ case 0x03d8: return "pmpaddr40";
71
+
75
+ case 0x03d9: return "pmpaddr41";
72
+ $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/sdk/shakti_sdk_qemu.zip
76
+ case 0x03da: return "pmpaddr42";
73
+ $ unzip shakti_sdk_qemu.zip
77
+ case 0x03db: return "pmpaddr43";
74
+
78
+ case 0x03dc: return "pmpaddr44";
75
+Then we can run the UART example using:
79
+ case 0x03dd: return "pmpaddr45";
76
+
80
+ case 0x03de: return "pmpaddr46";
77
+.. code-block:: bash
81
+ case 0x03df: return "pmpaddr47";
78
+
82
+ case 0x03e0: return "pmpaddr48";
79
+ $ qemu-system-riscv64 -M shakti_c -nographic \
83
+ case 0x03e1: return "pmpaddr49";
80
+ -bios path/to/shakti_sdk_qemu/loopback.shakti
84
+ case 0x03e2: return "pmpaddr50";
81
+
85
+ case 0x03e3: return "pmpaddr51";
82
+OpenSBI
86
+ case 0x03e4: return "pmpaddr52";
83
+~~~~~~~
87
+ case 0x03e5: return "pmpaddr53";
84
+We can also run OpenSBI with Test Payload.
88
+ case 0x03e6: return "pmpaddr54";
85
+
89
+ case 0x03e7: return "pmpaddr55";
86
+.. code-block:: bash
90
+ case 0x03e8: return "pmpaddr56";
87
+
91
+ case 0x03e9: return "pmpaddr57";
88
+ $ git clone https://github.com/riscv/opensbi.git -b v0.9
92
+ case 0x03ea: return "pmpaddr58";
89
+ $ cd opensbi
93
+ case 0x03eb: return "pmpaddr59";
90
+ $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/dts/shakti.dtb
94
+ case 0x03ec: return "pmpaddr60";
91
+ $ export CROSS_COMPILE=riscv64-unknown-elf-
95
+ case 0x03ed: return "pmpaddr61";
92
+ $ export FW_FDT_PATH=./shakti.dtb
96
+ case 0x03ee: return "pmpaddr62";
93
+ $ make PLATFORM=generic
97
+ case 0x03ef: return "pmpaddr63";
94
+
98
case 0x0780: return "mtohost";
95
+fw_payload.elf would be generated in build/platform/generic/firmware/fw_payload.elf.
99
case 0x0781: return "mfromhost";
96
+Boot it using the below qemu command.
100
case 0x0782: return "mreset";
97
+
98
+.. code-block:: bash
99
+
100
+ $ qemu-system-riscv64 -M shakti_c -nographic \
101
+ -bios path/to/fw_payload.elf
102
--
101
--
103
2.31.1
102
2.45.1
104
105
diff view generated by jsdifflib
1
From: Yu-Ming Chang <yumin686@andestech.com>
2
3
Both CSRRS and CSRRC always read the addressed CSR and cause any read side
4
effects regardless of rs1 and rd fields. Note that if rs1 specifies a register
5
holding a zero value other than x0, the instruction will still attempt to write
6
the unmodified value back to the CSR and will cause any attendant side effects.
7
8
So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies
9
a register holding a zero value, an illegal instruction exception should be
10
raised.
11
12
Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-ID: <20240403070823.80897-1-yumin686@andestech.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: 187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com
5
---
16
---
6
target/riscv/cpu.h | 3 +-
17
target/riscv/cpu.h | 4 ++++
7
target/riscv/csr.c | 80 +++++++++++++++++++++++++---------------------
18
target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++----
8
2 files changed, 46 insertions(+), 37 deletions(-)
19
target/riscv/op_helper.c | 6 ++---
20
3 files changed, 53 insertions(+), 8 deletions(-)
9
21
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
11
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/cpu.h
24
--- a/target/riscv/cpu.h
13
+++ b/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
14
@@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
15
return val;
27
void riscv_cpu_update_mask(CPURISCVState *env);
16
}
28
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
17
29
18
-typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno);
30
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
19
+typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
31
+ target_ulong *ret_value);
20
+ int csrno);
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
21
typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
33
target_ulong *ret_value,
22
target_ulong *ret_value);
34
target_ulong new_value, target_ulong write_mask);
23
typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
35
@@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
36
target_ulong new_value,
37
target_ulong write_mask);
38
39
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
40
+ Int128 *ret_value);
41
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
42
Int128 *ret_value,
43
Int128 new_value, Int128 write_mask);
24
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
44
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
25
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/csr.c
46
--- a/target/riscv/csr.c
27
+++ b/target/riscv/csr.c
47
+++ b/target/riscv/csr.c
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops)
48
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
49
50
static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
51
int csrno,
52
- bool write_mask)
53
+ bool write)
54
{
55
/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
56
bool read_only = get_field(csrno, 0xC00) == 3;
57
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
58
}
59
60
/* read / write check */
61
- if (write_mask && read_only) {
62
+ if (write && read_only) {
63
return RISCV_EXCP_ILLEGAL_INST;
64
}
65
66
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno,
67
return RISCV_EXCP_NONE;
29
}
68
}
30
69
31
/* Predicates */
70
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
32
-static int fs(CPURISCVState *env, int csrno)
71
+ target_ulong *ret_value)
33
+static RISCVException fs(CPURISCVState *env, int csrno)
72
+{
34
{
73
+ RISCVException ret = riscv_csrrw_check(env, csrno, false);
35
#if !defined(CONFIG_USER_ONLY)
74
+ if (ret != RISCV_EXCP_NONE) {
36
/* loose check condition for fcsr in vector extension */
75
+ return ret;
37
if ((csrno == CSR_FCSR) && (env->misa & RVV)) {
38
- return 0;
39
+ return RISCV_EXCP_NONE;
40
}
41
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
42
- return -RISCV_EXCP_ILLEGAL_INST;
43
+ return RISCV_EXCP_ILLEGAL_INST;
44
}
45
#endif
46
- return 0;
47
+ return RISCV_EXCP_NONE;
48
}
49
50
-static int vs(CPURISCVState *env, int csrno)
51
+static RISCVException vs(CPURISCVState *env, int csrno)
52
{
53
if (env->misa & RVV) {
54
- return 0;
55
+ return RISCV_EXCP_NONE;
56
}
57
- return -RISCV_EXCP_ILLEGAL_INST;
58
+ return RISCV_EXCP_ILLEGAL_INST;
59
}
60
61
-static int ctr(CPURISCVState *env, int csrno)
62
+static RISCVException ctr(CPURISCVState *env, int csrno)
63
{
64
#if !defined(CONFIG_USER_ONLY)
65
CPUState *cs = env_cpu(env);
66
@@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno)
67
68
if (!cpu->cfg.ext_counters) {
69
/* The Counters extensions is not enabled */
70
- return -RISCV_EXCP_ILLEGAL_INST;
71
+ return RISCV_EXCP_ILLEGAL_INST;
72
}
73
74
if (riscv_cpu_virt_enabled(env)) {
75
@@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno)
76
case CSR_CYCLE:
77
if (!get_field(env->hcounteren, HCOUNTEREN_CY) &&
78
get_field(env->mcounteren, HCOUNTEREN_CY)) {
79
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
80
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
81
}
82
break;
83
case CSR_TIME:
84
if (!get_field(env->hcounteren, HCOUNTEREN_TM) &&
85
get_field(env->mcounteren, HCOUNTEREN_TM)) {
86
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
87
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
88
}
89
break;
90
case CSR_INSTRET:
91
if (!get_field(env->hcounteren, HCOUNTEREN_IR) &&
92
get_field(env->mcounteren, HCOUNTEREN_IR)) {
93
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
94
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
95
}
96
break;
97
case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31:
98
if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)) &&
99
get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))) {
100
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
101
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
102
}
103
break;
104
}
105
@@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno)
106
case CSR_CYCLEH:
107
if (!get_field(env->hcounteren, HCOUNTEREN_CY) &&
108
get_field(env->mcounteren, HCOUNTEREN_CY)) {
109
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
110
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
111
}
112
break;
113
case CSR_TIMEH:
114
if (!get_field(env->hcounteren, HCOUNTEREN_TM) &&
115
get_field(env->mcounteren, HCOUNTEREN_TM)) {
116
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
117
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
118
}
119
break;
120
case CSR_INSTRETH:
121
if (!get_field(env->hcounteren, HCOUNTEREN_IR) &&
122
get_field(env->mcounteren, HCOUNTEREN_IR)) {
123
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
124
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
125
}
126
break;
127
case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H:
128
if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3H)) &&
129
get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3H))) {
130
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
131
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
132
}
133
break;
134
}
135
}
136
}
137
#endif
138
- return 0;
139
+ return RISCV_EXCP_NONE;
140
}
141
142
-static int ctr32(CPURISCVState *env, int csrno)
143
+static RISCVException ctr32(CPURISCVState *env, int csrno)
144
{
145
if (!riscv_cpu_is_32bit(env)) {
146
- return -RISCV_EXCP_ILLEGAL_INST;
147
+ return RISCV_EXCP_ILLEGAL_INST;
148
}
149
150
return ctr(env, csrno);
151
}
152
153
#if !defined(CONFIG_USER_ONLY)
154
-static int any(CPURISCVState *env, int csrno)
155
+static RISCVException any(CPURISCVState *env, int csrno)
156
{
157
- return 0;
158
+ return RISCV_EXCP_NONE;
159
}
160
161
-static int any32(CPURISCVState *env, int csrno)
162
+static RISCVException any32(CPURISCVState *env, int csrno)
163
{
164
if (!riscv_cpu_is_32bit(env)) {
165
- return -RISCV_EXCP_ILLEGAL_INST;
166
+ return RISCV_EXCP_ILLEGAL_INST;
167
}
168
169
return any(env, csrno);
170
171
}
172
173
-static int smode(CPURISCVState *env, int csrno)
174
+static RISCVException smode(CPURISCVState *env, int csrno)
175
{
176
- return -!riscv_has_ext(env, RVS);
177
+ if (riscv_has_ext(env, RVS)) {
178
+ return RISCV_EXCP_NONE;
179
+ }
76
+ }
180
+
77
+
181
+ return RISCV_EXCP_ILLEGAL_INST;
78
+ return riscv_csrrw_do64(env, csrno, ret_value, 0, 0);
79
+}
80
+
81
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
82
target_ulong *ret_value,
83
target_ulong new_value, target_ulong write_mask)
84
{
85
- RISCVException ret = riscv_csrrw_check(env, csrno, write_mask);
86
+ RISCVException ret = riscv_csrrw_check(env, csrno, true);
87
if (ret != RISCV_EXCP_NONE) {
88
return ret;
89
}
90
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno,
91
return RISCV_EXCP_NONE;
182
}
92
}
183
93
184
-static int hmode(CPURISCVState *env, int csrno)
94
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
185
+static RISCVException hmode(CPURISCVState *env, int csrno)
95
+ Int128 *ret_value)
186
{
96
+{
187
if (riscv_has_ext(env, RVS) &&
97
+ RISCVException ret;
188
riscv_has_ext(env, RVH)) {
98
+
189
/* Hypervisor extension is supported */
99
+ ret = riscv_csrrw_check(env, csrno, false);
190
if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
100
+ if (ret != RISCV_EXCP_NONE) {
191
env->priv == PRV_M) {
101
+ return ret;
192
- return 0;
193
+ return RISCV_EXCP_NONE;
194
} else {
195
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
196
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
197
}
198
}
199
200
- return -RISCV_EXCP_ILLEGAL_INST;
201
+ return RISCV_EXCP_ILLEGAL_INST;
202
}
203
204
-static int hmode32(CPURISCVState *env, int csrno)
205
+static RISCVException hmode32(CPURISCVState *env, int csrno)
206
{
207
if (!riscv_cpu_is_32bit(env)) {
208
- return 0;
209
+ return RISCV_EXCP_NONE;
210
}
211
212
return hmode(env, csrno);
213
214
}
215
216
-static int pmp(CPURISCVState *env, int csrno)
217
+static RISCVException pmp(CPURISCVState *env, int csrno)
218
{
219
- return -!riscv_feature(env, RISCV_FEATURE_PMP);
220
+ if (riscv_feature(env, RISCV_FEATURE_PMP)) {
221
+ return RISCV_EXCP_NONE;
222
+ }
102
+ }
223
+
103
+
224
+ return RISCV_EXCP_ILLEGAL_INST;
104
+ if (csr_ops[csrno].read128) {
225
}
105
+ return riscv_csrrw_do128(env, csrno, ret_value,
226
#endif
106
+ int128_zero(), int128_zero());
227
107
+ }
228
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
108
+
229
return -RISCV_EXCP_ILLEGAL_INST;
109
+ /*
110
+ * Fall back to 64-bit version for now, if the 128-bit alternative isn't
111
+ * at all defined.
112
+ * Note, some CSRs don't need to extend to MXLEN (64 upper bits non
113
+ * significant), for those, this fallback is correctly handling the
114
+ * accesses
115
+ */
116
+ target_ulong old_value;
117
+ ret = riscv_csrrw_do64(env, csrno, &old_value,
118
+ (target_ulong)0,
119
+ (target_ulong)0);
120
+ if (ret == RISCV_EXCP_NONE && ret_value) {
121
+ *ret_value = int128_make64(old_value);
122
+ }
123
+ return ret;
124
+}
125
+
126
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
127
Int128 *ret_value,
128
Int128 new_value, Int128 write_mask)
129
{
130
RISCVException ret;
131
132
- ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask));
133
+ ret = riscv_csrrw_check(env, csrno, true);
134
if (ret != RISCV_EXCP_NONE) {
135
return ret;
230
}
136
}
231
ret = csr_ops[csrno].predicate(env, csrno);
137
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
232
- if (ret < 0) {
138
index XXXXXXX..XXXXXXX 100644
233
- return ret;
139
--- a/target/riscv/op_helper.c
234
+ if (ret != RISCV_EXCP_NONE) {
140
+++ b/target/riscv/op_helper.c
235
+ return -ret;
141
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr)
236
}
142
}
237
143
238
/* execute combined read/write operation if it exists */
144
target_ulong val = 0;
145
- RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0);
146
+ RISCVException ret = riscv_csrr(env, csr, &val);
147
148
if (ret != RISCV_EXCP_NONE) {
149
riscv_raise_exception(env, ret, GETPC());
150
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr,
151
target_ulong helper_csrr_i128(CPURISCVState *env, int csr)
152
{
153
Int128 rv = int128_zero();
154
- RISCVException ret = riscv_csrrw_i128(env, csr, &rv,
155
- int128_zero(),
156
- int128_zero());
157
+ RISCVException ret = riscv_csrr_i128(env, csr, &rv);
158
159
if (ret != RISCV_EXCP_NONE) {
160
riscv_raise_exception(env, ret, GETPC());
239
--
161
--
240
2.31.1
162
2.45.1
241
242
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: cb1ef2061547dc9028ce3cf4f6622588f9c09149.1617290165.git.alistair.francis@wdc.com
5
---
6
target/riscv/csr.c | 6 +++++-
7
1 file changed, 5 insertions(+), 1 deletion(-)
8
1
9
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/target/riscv/csr.c
12
+++ b/target/riscv/csr.c
13
@@ -XXX,XX +XXX,XX @@ static RISCVException hmode(CPURISCVState *env, int csrno)
14
static RISCVException hmode32(CPURISCVState *env, int csrno)
15
{
16
if (!riscv_cpu_is_32bit(env)) {
17
- return RISCV_EXCP_NONE;
18
+ if (riscv_cpu_virt_enabled(env)) {
19
+ return RISCV_EXCP_ILLEGAL_INST;
20
+ } else {
21
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
22
+ }
23
}
24
25
return hmode(env, csrno);
26
--
27
2.31.1
28
29
diff view generated by jsdifflib
Deleted patch
1
Update the RISC-V maintainers by removing Sagar and Bastian who haven't
2
been involved recently.
3
1
4
Also add Bin who has been helping with reviews.
5
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Acked-by: Bin Meng <bin.meng@windriver.com>
8
Acked-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 6564ba829c40ad9aa7d28f43be69d8eb5cf4b56b.1617749142.git.alistair.francis@wdc.com
11
---
12
MAINTAINERS | 5 ++---
13
1 file changed, 2 insertions(+), 3 deletions(-)
14
15
diff --git a/MAINTAINERS b/MAINTAINERS
16
index XXXXXXX..XXXXXXX 100644
17
--- a/MAINTAINERS
18
+++ b/MAINTAINERS
19
@@ -XXX,XX +XXX,XX @@ F: tests/acceptance/machine_ppc.py
20
21
RISC-V TCG CPUs
22
M: Palmer Dabbelt <palmer@dabbelt.com>
23
-M: Alistair Francis <Alistair.Francis@wdc.com>
24
-M: Sagar Karandikar <sagark@eecs.berkeley.edu>
25
-M: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
26
+M: Alistair Francis <alistair.francis@wdc.com>
27
+M: Bin Meng <bin.meng@windriver.com>
28
L: qemu-riscv@nongnu.org
29
S: Supported
30
F: target/riscv/
31
--
32
2.31.1
33
34
diff view generated by jsdifflib
Deleted patch
1
Update the OpenTitan interrupt layout to match the latest OpenTitan
2
bitstreams. This involves changing the Ibex PLIC memory layout and the
3
UART interrupts.
4
1
5
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
6
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
7
Message-id: e92b696f1809c9fa4410da2e9f23c414db5a6960.1617202791.git.alistair.francis@wdc.com
8
---
9
include/hw/riscv/opentitan.h | 16 ++++++++--------
10
hw/intc/ibex_plic.c | 20 ++++++++++----------
11
hw/riscv/opentitan.c | 8 ++++----
12
3 files changed, 22 insertions(+), 22 deletions(-)
13
14
diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/riscv/opentitan.h
17
+++ b/include/hw/riscv/opentitan.h
18
@@ -XXX,XX +XXX,XX @@ enum {
19
};
20
21
enum {
22
- IBEX_UART_RX_PARITY_ERR_IRQ = 0x28,
23
- IBEX_UART_RX_TIMEOUT_IRQ = 0x27,
24
- IBEX_UART_RX_BREAK_ERR_IRQ = 0x26,
25
- IBEX_UART_RX_FRAME_ERR_IRQ = 0x25,
26
- IBEX_UART_RX_OVERFLOW_IRQ = 0x24,
27
- IBEX_UART_TX_EMPTY_IRQ = 0x23,
28
- IBEX_UART_RX_WATERMARK_IRQ = 0x22,
29
- IBEX_UART_TX_WATERMARK_IRQ = 0x21,
30
+ IBEX_UART0_RX_PARITY_ERR_IRQ = 8,
31
+ IBEX_UART0_RX_TIMEOUT_IRQ = 7,
32
+ IBEX_UART0_RX_BREAK_ERR_IRQ = 6,
33
+ IBEX_UART0_RX_FRAME_ERR_IRQ = 5,
34
+ IBEX_UART0_RX_OVERFLOW_IRQ = 4,
35
+ IBEX_UART0_TX_EMPTY_IRQ = 3,
36
+ IBEX_UART0_RX_WATERMARK_IRQ = 2,
37
+ IBEX_UART0_TX_WATERMARK_IRQ = 1,
38
};
39
40
#endif
41
diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/intc/ibex_plic.c
44
+++ b/hw/intc/ibex_plic.c
45
@@ -XXX,XX +XXX,XX @@ static void ibex_plic_irq_request(void *opaque, int irq, int level)
46
47
static Property ibex_plic_properties[] = {
48
DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1),
49
- DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 80),
50
+ DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 176),
51
52
DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0),
53
- DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 3),
54
+ DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 6),
55
56
- DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x0c),
57
- DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 3),
58
+ DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x18),
59
+ DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 6),
60
61
- DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x18),
62
- DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 80),
63
+ DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x30),
64
+ DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 177),
65
66
- DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x200),
67
- DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 3),
68
+ DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x300),
69
+ DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 6),
70
71
- DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x20c),
72
+ DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x318),
73
74
- DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x210),
75
+ DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x31c),
76
DEFINE_PROP_END_OF_LIST(),
77
};
78
79
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/hw/riscv/opentitan.c
82
+++ b/hw/riscv/opentitan.c
83
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
84
sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart), 0, memmap[IBEX_DEV_UART].base);
85
sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart),
86
0, qdev_get_gpio_in(DEVICE(&s->plic),
87
- IBEX_UART_TX_WATERMARK_IRQ));
88
+ IBEX_UART0_TX_WATERMARK_IRQ));
89
sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart),
90
1, qdev_get_gpio_in(DEVICE(&s->plic),
91
- IBEX_UART_RX_WATERMARK_IRQ));
92
+ IBEX_UART0_RX_WATERMARK_IRQ));
93
sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart),
94
2, qdev_get_gpio_in(DEVICE(&s->plic),
95
- IBEX_UART_TX_EMPTY_IRQ));
96
+ IBEX_UART0_TX_EMPTY_IRQ));
97
sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart),
98
3, qdev_get_gpio_in(DEVICE(&s->plic),
99
- IBEX_UART_RX_OVERFLOW_IRQ));
100
+ IBEX_UART0_RX_OVERFLOW_IRQ));
101
102
create_unimplemented_device("riscv.lowrisc.ibex.gpio",
103
memmap[IBEX_DEV_GPIO].base, memmap[IBEX_DEV_GPIO].size);
104
--
105
2.31.1
106
107
diff view generated by jsdifflib
Deleted patch
1
imply VIRTIO_VGA for the virt machine, this fixes the following error
2
when specifying `-vga virtio` as a command line argument:
3
1
4
qemu-system-riscv64: Virtio VGA not available
5
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 7ac26fafee8bd59d2a0640f3233f8ad1ab270e1e.1617367317.git.alistair.francis@wdc.com
9
---
10
hw/riscv/Kconfig | 1 +
11
1 file changed, 1 insertion(+)
12
13
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/riscv/Kconfig
16
+++ b/hw/riscv/Kconfig
17
@@ -XXX,XX +XXX,XX @@ config SHAKTI_C
18
config RISCV_VIRT
19
bool
20
imply PCI_DEVICES
21
+ imply VIRTIO_VGA
22
imply TEST_DEVICES
23
select GOLDFISH_RTC
24
select MSI_NONBROKEN
25
--
26
2.31.1
27
28
diff view generated by jsdifflib
Deleted patch
1
From: Hou Weiying <weiying_hou@outlook.com>
2
1
3
Use address 0x390 and 0x391 for the ePMP CSRs.
4
5
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
6
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
7
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
11
Message-id: 63245b559f477a9ce6d4f930136d2d7fd7f99c78.1618812899.git.alistair.francis@wdc.com
12
[ Changes by AF:
13
- Tidy up commit message
14
]
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
17
---
18
target/riscv/cpu_bits.h | 3 +++
19
1 file changed, 3 insertions(+)
20
21
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu_bits.h
24
+++ b/target/riscv/cpu_bits.h
25
@@ -XXX,XX +XXX,XX @@
26
#define CSR_MTINST 0x34a
27
#define CSR_MTVAL2 0x34b
28
29
+/* Enhanced Physical Memory Protection (ePMP) */
30
+#define CSR_MSECCFG 0x390
31
+#define CSR_MSECCFGH 0x391
32
/* Physical Memory Protection */
33
#define CSR_PMPCFG0 0x3a0
34
#define CSR_PMPCFG1 0x3a1
35
--
36
2.31.1
37
38
diff view generated by jsdifflib
Deleted patch
1
The spec is avaliable at:
2
https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8
3
1
4
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
6
Message-id: 28c8855c80b0388a08c3ae009f5467e2b3960ce0.1618812899.git.alistair.francis@wdc.com
7
---
8
target/riscv/cpu.h | 1 +
9
1 file changed, 1 insertion(+)
10
11
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/cpu.h
14
+++ b/target/riscv/cpu.h
15
@@ -XXX,XX +XXX,XX @@
16
enum {
17
RISCV_FEATURE_MMU,
18
RISCV_FEATURE_PMP,
19
+ RISCV_FEATURE_EPMP,
20
RISCV_FEATURE_MISA
21
};
22
23
--
24
2.31.1
25
26
diff view generated by jsdifflib
Deleted patch
1
From: Hou Weiying <weiying_hou@outlook.com>
2
1
3
Add a config option to enable experimental support for ePMP. This
4
is disabled by default and can be enabled with 'x-epmp=true'.
5
6
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
7
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
8
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
11
Message-id: a22ccdaf9314078bc735d3b323f966623f8af020.1618812899.git.alistair.francis@wdc.com
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
14
---
15
target/riscv/cpu.h | 1 +
16
target/riscv/cpu.c | 10 ++++++++++
17
2 files changed, 11 insertions(+)
18
19
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPU {
24
uint16_t elen;
25
bool mmu;
26
bool pmp;
27
+ bool epmp;
28
uint64_t resetvec;
29
} cfg;
30
};
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
36
37
if (cpu->cfg.pmp) {
38
set_feature(env, RISCV_FEATURE_PMP);
39
+
40
+ /*
41
+ * Enhanced PMP should only be available
42
+ * on harts with PMP support
43
+ */
44
+ if (cpu->cfg.epmp) {
45
+ set_feature(env, RISCV_FEATURE_EPMP);
46
+ }
47
}
48
49
set_resetvec(env, cpu->cfg.resetvec);
50
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
51
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
52
DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
53
DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
54
+ DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false),
55
+
56
DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
57
DEFINE_PROP_END_OF_LIST(),
58
};
59
--
60
2.31.1
61
62
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3
Message-id: 10387eec21d2f17c499a78fdba85280cab4dd27f.1618812899.git.alistair.francis@wdc.com
4
---
5
target/riscv/pmp.c | 4 ----
6
1 file changed, 4 deletions(-)
7
1
8
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
9
index XXXXXXX..XXXXXXX 100644
10
--- a/target/riscv/pmp.c
11
+++ b/target/riscv/pmp.c
12
@@ -XXX,XX +XXX,XX @@
13
* this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
-/*
17
- * PMP (Physical Memory Protection) is as-of-yet unused and needs testing.
18
- */
19
-
20
#include "qemu/osdep.h"
21
#include "qemu/log.h"
22
#include "qapi/error.h"
23
--
24
2.31.1
25
26
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: e095b57af0d419c8ed822958f04dfc732d7beb7e.1619234854.git.alistair.francis@wdc.com
5
---
6
target/riscv/cpu_bits.h | 6 ------
7
1 file changed, 6 deletions(-)
8
1
9
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
10
index XXXXXXX..XXXXXXX 100644
11
--- a/target/riscv/cpu_bits.h
12
+++ b/target/riscv/cpu_bits.h
13
@@ -XXX,XX +XXX,XX @@
14
#define HSTATUS32_WPRI 0xFF8FF87E
15
#define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL
16
17
-#if defined(TARGET_RISCV32)
18
-#define HSTATUS_WPRI HSTATUS32_WPRI
19
-#elif defined(TARGET_RISCV64)
20
-#define HSTATUS_WPRI HSTATUS64_WPRI
21
-#endif
22
-
23
#define HCOUNTEREN_CY (1 << 0)
24
#define HCOUNTEREN_TM (1 << 1)
25
#define HCOUNTEREN_IR (1 << 2)
26
--
27
2.31.1
28
29
diff view generated by jsdifflib
Deleted patch
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
3
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4
Message-id: 4853459564af35a6690120c74ad892f60cec35ff.1619234854.git.alistair.francis@wdc.com
5
---
6
target/riscv/translate.c | 6 ------
7
1 file changed, 6 deletions(-)
8
1
9
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/target/riscv/translate.c
12
+++ b/target/riscv/translate.c
13
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
14
CPUState *cs;
15
} DisasContext;
16
17
-#ifdef TARGET_RISCV64
18
-#define CASE_OP_32_64(X) case X: case glue(X, W)
19
-#else
20
-#define CASE_OP_32_64(X) case X
21
-#endif
22
-
23
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
24
{
25
return ctx->misa & ext;
26
--
27
2.31.1
28
29
diff view generated by jsdifflib
Deleted patch
1
BugLink: https://gitlab.com/qemu-project/qemu/-/issues/47
2
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
3
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
4
Message-id: 024ce841221c1d15c74b253512428c4baca7e4ba.1619234854.git.alistair.francis@wdc.com
5
---
6
target/riscv/insn32.decode | 2 +-
7
1 file changed, 1 insertion(+), 1 deletion(-)
8
1
9
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
10
index XXXXXXX..XXXXXXX 100644
11
--- a/target/riscv/insn32.decode
12
+++ b/target/riscv/insn32.decode
13
@@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s
14
hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma
15
hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma
16
17
-# *** RV32H Base Instruction Set ***
18
+# *** RV64H Base Instruction Set ***
19
hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2
20
hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2
21
hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s
22
--
23
2.31.1
24
25
diff view generated by jsdifflib