1
The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946:
1
The following changes since commit d45a5270d075ea589f0b0ddcf963a5fea1f500ac:
2
2
3
Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700)
3
Merge remote-tracking branch 'remotes/vivier2/tags/trivial-branch-for-6.1-pull-request' into staging (2021-05-05 13:52:00 +0100)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210506
8
8
9
for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393:
9
for you to fetch changes up to d9e1a4683bc52ff218dcc133f73017bc4c496346:
10
10
11
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000)
11
target/riscv: Fix the RV64H decode comment (2021-05-06 08:59:59 +1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
RISC-V PR for 9.1
14
A large collection of RISC-V fixes, improvements and features
15
15
16
* APLICs add child earlier than realize
16
- Clenaup some left over v1.9 code
17
* Fix exposure of Zkr
17
- Documentation improvements
18
* Raise exceptions on wrs.nto
18
- Support for the shakti_c machine
19
* Implement SBI debug console (DBCN) calls for KVM
19
- Internal cleanup of the CSR accesses
20
* Support 64-bit addresses for initrd
20
- Updates to the OpenTitan platform
21
* Change RISCV_EXCP_SEMIHOST exception number to 63
21
- Support for the virtio-vga
22
* Tolerate KVM disable ext errors
22
- Fix for the saturate subtract in vector extensions
23
* Set tval in breakpoints
23
- Experimental support for the ePMP spec
24
* Add support for Zve32x extension
24
- A range of other internal code cleanups and bug fixes
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
43
25
44
----------------------------------------------------------------
26
----------------------------------------------------------------
45
Alexei Filippov (1):
27
Alexander Wagner (1):
46
target/riscv: do not set mtval2 for non guest-page faults
28
hw/riscv: Fix OT IBEX reset vector
47
29
48
Alistair Francis (2):
30
Alistair Francis (22):
49
target/riscv: rvzicbo: Fixup CBO extension register calculation
31
target/riscv: Convert the RISC-V exceptions to an enum
50
disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs
32
target/riscv: Use the RISCVException enum for CSR predicates
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
51
53
52
Andrew Jones (2):
54
Atish Patra (1):
53
target/riscv/kvm: Fix exposure of Zkr
55
target/riscv: Remove privilege v1.9 specific CSR related code
54
target/riscv: Raise exceptions on wrs.nto
55
56
56
Cheng Yang (1):
57
Axel Heider (1):
57
hw/riscv/boot.c: Support 64-bit address for initrd
58
docs/system/generic-loader.rst: Fix style
58
59
59
Christoph Müllner (1):
60
Bin Meng (1):
60
riscv: thead: Add th.sxstatus CSR emulation
61
hw/riscv: sifive_e: Add 'const' to sifive_e_memmap[]
61
62
62
Clément Léger (1):
63
Dylan Jhong (1):
63
target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63
64
target/riscv: Align the data type of reset vector address
64
65
65
Daniel Henrique Barboza (6):
66
Emmanuel Blot (2):
66
target/riscv/kvm: implement SBI debug console (DBCN) calls
67
target/riscv: fix exception index on instruction access fault
67
target/riscv/kvm: tolerate KVM disable ext errors
68
target/riscv: fix a typo with interrupt names
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()
72
69
73
Huang Tao (2):
70
Frank Chang (2):
74
target/riscv: Fix the element agnostic function problem
71
target/riscv: fix vrgather macro index variable type bug
75
target/riscv: Implement dynamic establishment of custom decoder
72
fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
76
73
77
Jason Chien (3):
74
Hou Weiying (4):
78
target/riscv: Add support for Zve32x extension
75
target/riscv: Define ePMP mseccfg
79
target/riscv: Add support for Zve64x extension
76
target/riscv: Add ePMP CSR access functions
80
target/riscv: Relax vector register check in RISCV gdbstub
77
target/riscv: Implementation of enhanced PMP (ePMP)
78
target/riscv: Add a config option for ePMP
81
79
82
Max Chou (4):
80
Jade Fink (1):
83
target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
81
riscv: don't look at SUM when accessing memory from a debugger context
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
87
82
88
Rob Bradford (1):
83
LIU Zhiwei (1):
89
target/riscv: Remove experimental prefix from "B" extension
84
target/riscv: Fixup saturate subtract function
90
85
91
Yangyu Chen (1):
86
Vijai Kumar K (5):
92
target/riscv/cpu.c: fix Zvkb extension config
87
target/riscv: Add Shakti C class CPU
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
93
92
94
Yong-Xuan Wang (1):
93
docs/system/generic-loader.rst | 9 +-
95
target/riscv/kvm.c: Fix the hart bit setting of AIA
94
docs/system/riscv/shakti-c.rst | 82 +++
95
docs/system/target-riscv.rst | 1 +
96
default-configs/devices/riscv64-softmmu.mak | 1 +
97
include/hw/char/shakti_uart.h | 74 +++
98
include/hw/riscv/opentitan.h | 16 +-
99
include/hw/riscv/shakti_c.h | 75 +++
100
target/riscv/cpu.h | 42 +-
101
target/riscv/cpu_bits.h | 114 +---
102
target/riscv/helper.h | 18 +-
103
target/riscv/pmp.h | 14 +
104
target/riscv/insn16-32.decode | 28 -
105
target/riscv/insn16-64.decode | 36 --
106
target/riscv/insn16.decode | 30 +
107
target/riscv/insn32-64.decode | 88 ---
108
target/riscv/insn32.decode | 67 ++-
109
hw/char/shakti_uart.c | 185 +++++++
110
hw/intc/ibex_plic.c | 20 +-
111
hw/riscv/opentitan.c | 10 +-
112
hw/riscv/shakti_c.c | 178 ++++++
113
hw/riscv/sifive_e.c | 2 +-
114
target/riscv/cpu.c | 26 +-
115
target/riscv/cpu_helper.c | 88 ++-
116
target/riscv/csr.c | 824 +++++++++++++++++-----------
117
target/riscv/fpu_helper.c | 16 +-
118
target/riscv/gdbstub.c | 8 +-
119
target/riscv/machine.c | 8 +-
120
target/riscv/monitor.c | 22 +-
121
target/riscv/op_helper.c | 18 +-
122
target/riscv/pmp.c | 218 +++++++-
123
target/riscv/translate.c | 38 +-
124
target/riscv/vector_helper.c | 18 +-
125
fpu/softfloat-specialize.c.inc | 6 +
126
target/riscv/insn_trans/trans_rva.c.inc | 14 +-
127
target/riscv/insn_trans/trans_rvd.c.inc | 17 +-
128
target/riscv/insn_trans/trans_rvf.c.inc | 6 +-
129
target/riscv/insn_trans/trans_rvh.c.inc | 8 +-
130
target/riscv/insn_trans/trans_rvi.c.inc | 22 +-
131
target/riscv/insn_trans/trans_rvm.c.inc | 12 +-
132
target/riscv/insn_trans/trans_rvv.c.inc | 39 +-
133
MAINTAINERS | 14 +-
134
hw/char/meson.build | 1 +
135
hw/char/trace-events | 4 +
136
hw/riscv/Kconfig | 11 +
137
hw/riscv/meson.build | 1 +
138
target/riscv/meson.build | 13 +-
139
target/riscv/trace-events | 3 +
140
47 files changed, 1756 insertions(+), 789 deletions(-)
141
create mode 100644 docs/system/riscv/shakti-c.rst
142
create mode 100644 include/hw/char/shakti_uart.h
143
create mode 100644 include/hw/riscv/shakti_c.h
144
delete mode 100644 target/riscv/insn16-32.decode
145
delete mode 100644 target/riscv/insn16-64.decode
146
delete mode 100644 target/riscv/insn32-64.decode
147
create mode 100644 hw/char/shakti_uart.c
148
create mode 100644 hw/riscv/shakti_c.c
96
149
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
From: Huang Tao <eric.huang@linux.alibaba.com>
1
From: Atish Patra <atish.patra@wdc.com>
2
2
3
In this patch, we modify the decoder to be a freely composable data
3
Qemu doesn't support RISC-V privilege specification v1.9. Remove the
4
structure instead of a hardcoded one. It can be dynamically builded up
4
remaining v1.9 specific references from the implementation.
5
according to the extensions.
5
6
This approach has several benefits:
6
Signed-off-by: Atish Patra <atish.patra@wdc.com>
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.
20
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>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com>
8
Message-Id: <20210319194534.2082397-2-atish.patra@wdc.com>
9
[Changes by AF:
10
- Rebase on latest patches
11
- Bump the vmstate_riscv_cpu version_id and minimum_version_id
12
]
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
14
---
29
target/riscv/cpu.h | 1 +
15
target/riscv/cpu.h | 4 +---
30
target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++
16
target/riscv/cpu_bits.h | 23 ---------------------
31
target/riscv/cpu.c | 1 +
17
target/riscv/cpu.c | 2 +-
32
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
18
target/riscv/cpu_helper.c | 12 +++++------
33
target/riscv/translate.c | 31 +++++++++++++++----------------
19
target/riscv/csr.c | 42 ++++++++++-----------------------------
34
5 files changed, 47 insertions(+), 16 deletions(-)
20
target/riscv/machine.c | 8 +++-----
21
target/riscv/translate.c | 4 ++--
22
7 files changed, 23 insertions(+), 72 deletions(-)
35
23
36
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
37
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu.h
26
--- a/target/riscv/cpu.h
39
+++ b/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
40
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
41
uint32_t pmu_avail_ctrs;
29
target_ulong mie;
42
/* Mapping of events to counters */
30
target_ulong mideleg;
43
GHashTable *pmu_event_ctr_map;
31
44
+ const GPtrArray *decoders;
32
- target_ulong sptbr; /* until: priv-1.9.1 */
45
};
33
target_ulong satp; /* since: priv-1.10.0 */
46
34
- target_ulong sbadaddr;
47
/**
35
- target_ulong mbadaddr;
48
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
36
+ target_ulong stval;
49
index XXXXXXX..XXXXXXX 100644
37
target_ulong medeleg;
50
--- a/target/riscv/tcg/tcg-cpu.h
38
51
+++ b/target/riscv/tcg/tcg-cpu.h
39
target_ulong stvec;
52
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
40
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
53
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
41
index XXXXXXX..XXXXXXX 100644
54
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu);
42
--- a/target/riscv/cpu_bits.h
55
43
+++ b/target/riscv/cpu_bits.h
56
+struct DisasContext;
44
@@ -XXX,XX +XXX,XX @@
57
+struct RISCVCPUConfig;
45
/* 32-bit only */
58
+typedef struct RISCVDecoder {
46
#define CSR_MSTATUSH 0x310
59
+ bool (*guard_func)(const struct RISCVCPUConfig *);
47
60
+ bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
48
-/* Legacy Counter Setup (priv v1.9.1) */
61
+} RISCVDecoder;
49
-/* Update to #define CSR_MCOUNTINHIBIT 0x320 for 1.11.0 */
62
+
50
-#define CSR_MUCOUNTEREN 0x320
63
+typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
51
-#define CSR_MSCOUNTEREN 0x321
64
+
52
-#define CSR_MHCOUNTEREN 0x322
65
+extern const size_t decoder_table_size;
53
-
66
+
54
/* Machine Trap Handling */
67
+extern const RISCVDecoder decoder_table[];
55
#define CSR_MSCRATCH 0x340
68
+
56
#define CSR_MEPC 0x341
69
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu);
57
@@ -XXX,XX +XXX,XX @@
70
+
58
#define CSR_MTVAL 0x343
71
#endif
59
#define CSR_MIP 0x344
60
61
-/* Legacy Machine Trap Handling (priv v1.9.1) */
62
-#define CSR_MBADADDR 0x343
63
-
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
72
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
111
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
73
index XXXXXXX..XXXXXXX 100644
112
index XXXXXXX..XXXXXXX 100644
74
--- a/target/riscv/cpu.c
113
--- a/target/riscv/cpu.c
75
+++ b/target/riscv/cpu.c
114
+++ b/target/riscv/cpu.c
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
115
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
77
error_propagate(errp, local_err);
116
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause);
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)
89
}
117
}
90
}
118
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval);
91
119
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->sbadaddr);
92
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
120
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval);
93
+{
121
if (riscv_has_ext(env, RVH)) {
94
+ GPtrArray *dynamic_decoders;
122
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
95
+ dynamic_decoders = g_ptr_array_sized_new(decoder_table_size);
123
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
96
+ for (size_t i = 0; i < decoder_table_size; ++i) {
124
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
97
+ if (decoder_table[i].guard_func &&
125
index XXXXXXX..XXXXXXX 100644
98
+ decoder_table[i].guard_func(&cpu->cfg)) {
126
--- a/target/riscv/cpu_helper.c
99
+ g_ptr_array_add(dynamic_decoders,
127
+++ b/target/riscv/cpu_helper.c
100
+ (gpointer)decoder_table[i].riscv_cpu_decode_fn);
128
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
101
+ }
129
env->vscause = env->scause;
102
+ }
130
env->scause = env->scause_hs;
103
+
131
104
+ cpu->decoders = dynamic_decoders;
132
- env->vstval = env->sbadaddr;
105
+}
133
- env->sbadaddr = env->stval_hs;
106
+
134
+ env->vstval = env->stval;
107
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu)
135
+ env->stval = env->stval_hs;
108
{
136
109
return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL;
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
}
175
176
-/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */
177
-static int read_mscounteren(CPURISCVState *env, int csrno, target_ulong *val)
178
-{
179
- if (env->priv_ver < PRIV_VERSION_1_11_0) {
180
- return -RISCV_EXCP_ILLEGAL_INST;
181
- }
182
- *val = env->mcounteren;
183
- return 0;
184
-}
185
-
186
-/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */
187
-static int write_mscounteren(CPURISCVState *env, int csrno, target_ulong val)
188
-{
189
- if (env->priv_ver < PRIV_VERSION_1_11_0) {
190
- return -RISCV_EXCP_ILLEGAL_INST;
191
- }
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
{
199
@@ -XXX,XX +XXX,XX @@ static int write_mcause(CPURISCVState *env, int csrno, target_ulong val)
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),
110
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
290
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
111
index XXXXXXX..XXXXXXX 100644
291
index XXXXXXX..XXXXXXX 100644
112
--- a/target/riscv/translate.c
292
--- a/target/riscv/translate.c
113
+++ b/target/riscv/translate.c
293
+++ b/target/riscv/translate.c
114
@@ -XXX,XX +XXX,XX @@
294
@@ -XXX,XX +XXX,XX @@ static void generate_exception(DisasContext *ctx, int excp)
115
#include "exec/helper-info.c.inc"
295
ctx->base.is_jmp = DISAS_NORETURN;
116
#undef HELPER_H
296
}
117
297
118
+#include "tcg/tcg-cpu.h"
298
-static void generate_exception_mbadaddr(DisasContext *ctx, int excp)
119
+
299
+static void generate_exception_mtval(DisasContext *ctx, int excp)
120
/* global register indices */
300
{
121
static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart;
301
tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
122
static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
302
tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr));
123
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
303
@@ -XXX,XX +XXX,XX @@ static void gen_exception_illegal(DisasContext *ctx)
124
/* FRM is known to contain a valid value. */
304
125
bool frm_valid;
305
static void gen_exception_inst_addr_mis(DisasContext *ctx)
126
bool insn_start_updated;
306
{
127
+ const GPtrArray *decoders;
307
- generate_exception_mbadaddr(ctx, RISCV_EXCP_INST_ADDR_MIS);
128
} DisasContext;
308
+ generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS);
129
309
}
130
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
310
131
@@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word)
311
static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
132
return (first_word & 3) == 3 ? 4 : 2;
133
}
134
135
+const RISCVDecoder decoder_table[] = {
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)
144
{
145
- /*
146
- * A table with predicate (i.e., guard) functions and decoder functions
147
- * that are tested in-order until a decoder matches onto the opcode.
148
- */
149
- static const struct {
150
- bool (*guard_func)(const RISCVCPUConfig *);
151
- bool (*decode_func)(DisasContext *, uint32_t);
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;
179
}
180
181
static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
182
--
312
--
183
2.45.1
313
2.31.1
314
315
diff view generated by jsdifflib
New patch
1
From: Axel Heider <axelheider@gmx.de>
1
2
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: Huang Tao <eric.huang@linux.alibaba.com>
1
From: Dylan Jhong <dylan@andestech.com>
2
2
3
In RVV and vcrypto instructions, the masked and tail elements are set to 1s
3
Use target_ulong to instead of uint64_t on reset vector address
4
using vext_set_elems_1s function if the vma/vta bit is set. It is the element
4
to adapt on both 32/64 machine.
5
agnostic policy.
6
5
7
However, this function can't deal the big endian situation. This patch fixes
6
Signed-off-by: Dylan Jhong <dylan@andestech.com>
8
the problem by adding handling of such case.
7
Signed-off-by: Ruinland ChuanTzu Tsai <ruinland@andestech.com>
9
8
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
10
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210329034801.22667-1-dylan@andestech.com
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>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
12
---
17
target/riscv/vector_internals.c | 22 ++++++++++++++++++++++
13
target/riscv/cpu.c | 2 +-
18
1 file changed, 22 insertions(+)
14
1 file changed, 1 insertion(+), 1 deletion(-)
19
15
20
diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c
16
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/vector_internals.c
18
--- a/target/riscv/cpu.c
23
+++ b/target/riscv/vector_internals.c
19
+++ b/target/riscv/cpu.c
24
@@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
20
@@ -XXX,XX +XXX,XX @@ static void set_feature(CPURISCVState *env, int feature)
25
if (tot - cnt == 0) {
21
env->features |= (1ULL << feature);
26
return ;
27
}
28
+
29
+ if (HOST_BIG_ENDIAN) {
30
+ /*
31
+ * Deal the situation when the elements are insdie
32
+ * only one uint64 block including setting the
33
+ * masked-off element.
34
+ */
35
+ if (((tot - 1) ^ cnt) < 8) {
36
+ memset(base + H1(tot - 1), -1, tot - cnt);
37
+ return;
38
+ }
39
+ /*
40
+ * Otherwise, at least cross two uint64_t blocks.
41
+ * Set first unaligned block.
42
+ */
43
+ if (cnt % 8 != 0) {
44
+ uint32_t j = ROUND_UP(cnt, 8);
45
+ memset(base + H1(j - 1), -1, j - cnt);
46
+ cnt = j;
47
+ }
48
+ /* Set other 64bit aligend blocks */
49
+ }
50
memset(base + cnt, -1, tot - cnt);
51
}
22
}
52
23
24
-static void set_resetvec(CPURISCVState *env, int resetvec)
25
+static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
26
{
27
#ifndef CONFIG_USER_ONLY
28
env->resetvec = resetvec;
53
--
29
--
54
2.45.1
30
2.31.1
31
32
diff view generated by jsdifflib
New patch
1
From: Bin Meng <bmeng.cn@gmail.com>
1
2
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/arch_init.h"
22
#include "sysemu/sysemu.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
1
From: Cheng Yang <yangcheng.work@foxmail.com>
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
2
3
Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell()
3
C-Class is a member of the SHAKTI family of processors from IIT-M.
4
to set the address of initrd in FDT to support 64-bit address.
5
4
6
Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
5
It is an extremely configurable and commercial-grade 5-stage in-order
6
core supporting the standard RV64GCSUN ISA extensions.
7
8
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com>
10
Message-id: 20210401181457.73039-2-vijai@behindbytes.com
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
12
---
11
hw/riscv/boot.c | 4 ++--
13
target/riscv/cpu.h | 1 +
12
1 file changed, 2 insertions(+), 2 deletions(-)
14
target/riscv/cpu.c | 1 +
15
2 files changed, 2 insertions(+)
13
16
14
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
17
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
15
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/riscv/boot.c
19
--- a/target/riscv/cpu.h
17
+++ b/hw/riscv/boot.c
20
+++ b/target/riscv/cpu.h
18
@@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
21
@@ -XXX,XX +XXX,XX @@
19
/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
22
#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")
20
if (fdt) {
23
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
21
end = start + size;
24
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
22
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start);
25
+#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
23
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end);
26
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
24
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start);
27
#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34")
25
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end);
28
#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51")
26
}
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
}
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu.c
32
+++ b/target/riscv/cpu.c
33
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
34
DEFINE_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init),
35
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init),
36
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),
37
+ DEFINE_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init),
38
#endif
39
};
28
40
29
--
41
--
30
2.45.1
42
2.31.1
43
44
diff view generated by jsdifflib
New patch
1
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
3
Add support for emulating Shakti reference platform based on C-class
4
running on arty-100T board.
5
6
https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/README.rst
7
8
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210401181457.73039-3-vijai@behindbytes.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
default-configs/devices/riscv64-softmmu.mak | 1 +
14
include/hw/riscv/shakti_c.h | 73 +++++++++
15
hw/riscv/shakti_c.c | 170 ++++++++++++++++++++
16
MAINTAINERS | 7 +
17
hw/riscv/Kconfig | 10 ++
18
hw/riscv/meson.build | 1 +
19
6 files changed, 262 insertions(+)
20
create mode 100644 include/hw/riscv/shakti_c.h
21
create mode 100644 hw/riscv/shakti_c.c
22
23
diff --git a/default-configs/devices/riscv64-softmmu.mak b/default-configs/devices/riscv64-softmmu.mak
24
index XXXXXXX..XXXXXXX 100644
25
--- a/default-configs/devices/riscv64-softmmu.mak
26
+++ b/default-configs/devices/riscv64-softmmu.mak
27
@@ -XXX,XX +XXX,XX @@ CONFIG_SIFIVE_E=y
28
CONFIG_SIFIVE_U=y
29
CONFIG_RISCV_VIRT=y
30
CONFIG_MICROCHIP_PFSOC=y
31
+CONFIG_SHAKTI_C=y
32
diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
36
+++ b/include/hw/riscv/shakti_c.h
37
@@ -XXX,XX +XXX,XX @@
38
+/*
39
+ * Shakti C-class SoC emulation
40
+ *
41
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
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
+ *
122
+ * 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,
124
+ * version 2 or later, as published by the Free Software Foundation.
125
+ *
126
+ * This program is distributed in the hope it will be useful, but WITHOUT
127
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
128
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
129
+ * more details.
130
+ *
131
+ * 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/>.
133
+ */
134
+
135
+#include "qemu/osdep.h"
136
+#include "hw/boards.h"
137
+#include "hw/riscv/shakti_c.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
+
146
+
147
+static const struct MemmapEntry {
148
+ hwaddr base;
149
+ hwaddr size;
150
+} shakti_c_memmap[] = {
151
+ [SHAKTI_C_ROM] = { 0x00001000, 0x2000 },
152
+ [SHAKTI_C_RAM] = { 0x80000000, 0x0 },
153
+ [SHAKTI_C_UART] = { 0x00011300, 0x00040 },
154
+ [SHAKTI_C_GPIO] = { 0x020d0000, 0x00100 },
155
+ [SHAKTI_C_PLIC] = { 0x0c000000, 0x20000 },
156
+ [SHAKTI_C_CLINT] = { 0x02000000, 0xc0000 },
157
+ [SHAKTI_C_I2C] = { 0x20c00000, 0x00100 },
158
+};
159
+
160
+static void shakti_c_machine_state_init(MachineState *mstate)
161
+{
162
+ ShaktiCMachineState *sms = RISCV_SHAKTI_MACHINE(mstate);
163
+ MemoryRegion *system_memory = get_system_memory();
164
+ MemoryRegion *main_mem = g_new(MemoryRegion, 1);
165
+
166
+ /* Allow only Shakti C CPU for this platform */
167
+ if (strcmp(mstate->cpu_type, TYPE_RISCV_CPU_SHAKTI_C) != 0) {
168
+ error_report("This board can only be used with Shakti C CPU");
169
+ exit(1);
170
+ }
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
+}
193
+
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
289
--- a/MAINTAINERS
290
+++ b/MAINTAINERS
291
@@ -XXX,XX +XXX,XX @@ F: include/hw/misc/mchp_pfsoc_dmc.h
292
F: include/hw/misc/mchp_pfsoc_ioscb.h
293
F: include/hw/misc/mchp_pfsoc_sysreg.h
294
295
+Shakti C class SoC
296
+M: Vijai Kumar K <vijai@behindbytes.com>
297
+L: qemu-riscv@nongnu.org
298
+S: Supported
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
--
339
2.31.1
340
341
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
2
3
Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr
3
This is the initial implementation of Shakti UART.
4
CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr
4
5
CSRs are part of the disassembly.
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
6
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reported-by: Eric DeVolder <eric_devolder@yahoo.com>
7
Message-id: 20210401181457.73039-4-vijai@behindbytes.com
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.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>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
9
---
15
disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
10
include/hw/char/shakti_uart.h | 74 ++++++++++++++
16
1 file changed, 64 insertions(+), 1 deletion(-)
11
hw/char/shakti_uart.c | 185 ++++++++++++++++++++++++++++++++++
17
12
MAINTAINERS | 2 +
18
diff --git a/disas/riscv.c b/disas/riscv.c
13
hw/char/meson.build | 1 +
14
hw/char/trace-events | 4 +
15
5 files changed, 266 insertions(+)
16
create mode 100644 include/hw/char/shakti_uart.h
17
create mode 100644 hw/char/shakti_uart.c
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 @@
25
+/*
26
+ * SHAKTI UART
27
+ *
28
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
29
+ *
30
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ * of this software and associated documentation files (the "Software"), to deal
32
+ * in the Software without restriction, including without limitation the rights
33
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ * copies of the Software, and to permit persons to whom the Software is
35
+ * furnished to do so, subject to the following conditions:
36
+ *
37
+ * The above copyright notice and this permission notice shall be included in
38
+ * all copies or substantial portions of the Software.
39
+ *
40
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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 @@
105
+/*
106
+ * SHAKTI UART
107
+ *
108
+ * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com>
109
+ *
110
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
111
+ * of this software and associated documentation files (the "Software"), to deal
112
+ * in the Software without restriction, including without limitation the rights
113
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114
+ * copies of the Software, and to permit persons to whom the Software is
115
+ * furnished to do so, subject to the following conditions:
116
+ *
117
+ * The above copyright notice and this permission notice shall be included in
118
+ * all copies or substantial portions of the Software.
119
+ *
120
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
121
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
122
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
123
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
124
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
125
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
126
+ * THE SOFTWARE.
127
+ */
128
+
129
+#include "qemu/osdep.h"
130
+#include "hw/char/shakti_uart.h"
131
+#include "hw/qdev-properties.h"
132
+#include "hw/qdev-properties-system.h"
133
+#include "qemu/log.h"
134
+
135
+static uint64_t shakti_uart_read(void *opaque, hwaddr addr, unsigned size)
136
+{
137
+ ShaktiUartState *s = opaque;
138
+
139
+ switch (addr) {
140
+ case SHAKTI_UART_BAUD:
141
+ return s->uart_baud;
142
+ case SHAKTI_UART_RX:
143
+ qemu_chr_fe_accept_input(&s->chr);
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
+ }
163
+
164
+ return 0;
165
+}
166
+
167
+static void shakti_uart_write(void *opaque, hwaddr addr,
168
+ uint64_t data, unsigned size)
169
+{
170
+ ShaktiUartState *s = opaque;
171
+ uint32_t value = data;
172
+ uint8_t ch;
173
+
174
+ switch (addr) {
175
+ case SHAKTI_UART_BAUD:
176
+ s->uart_baud = value;
177
+ break;
178
+ case SHAKTI_UART_TX:
179
+ ch = value;
180
+ qemu_chr_fe_write_all(&s->chr, &ch, 1);
181
+ s->uart_status &= ~SHAKTI_UART_STATUS_TX_FULL;
182
+ break;
183
+ case SHAKTI_UART_STATUS:
184
+ s->uart_status = value;
185
+ break;
186
+ case SHAKTI_UART_DELAY:
187
+ s->uart_delay = value;
188
+ break;
189
+ case SHAKTI_UART_CONTROL:
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;
201
+ default:
202
+ qemu_log_mask(LOG_GUEST_ERROR,
203
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
204
+ }
205
+}
206
+
207
+static const MemoryRegionOps shakti_uart_ops = {
208
+ .read = shakti_uart_read,
209
+ .write = shakti_uart_write,
210
+ .endianness = DEVICE_NATIVE_ENDIAN,
211
+ .impl = {.min_access_size = 1, .max_access_size = 4},
212
+ .valid = {.min_access_size = 1, .max_access_size = 4},
213
+};
214
+
215
+static void shakti_uart_reset(DeviceState *dev)
216
+{
217
+ ShaktiUartState *s = SHAKTI_UART(dev);
218
+
219
+ s->uart_baud = SHAKTI_UART_BAUD_DEFAULT;
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
19
index XXXXXXX..XXXXXXX 100644
291
index XXXXXXX..XXXXXXX 100644
20
--- a/disas/riscv.c
292
--- a/MAINTAINERS
21
+++ b/disas/riscv.c
293
+++ b/MAINTAINERS
22
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
294
@@ -XXX,XX +XXX,XX @@ M: Vijai Kumar K <vijai@behindbytes.com>
23
case 0x0383: return "mibound";
295
L: qemu-riscv@nongnu.org
24
case 0x0384: return "mdbase";
296
S: Supported
25
case 0x0385: return "mdbound";
297
F: hw/riscv/shakti_c.c
26
- case 0x03a0: return "pmpcfg3";
298
+F: hw/char/shakti_uart.c
27
+ case 0x03a0: return "pmpcfg0";
299
F: include/hw/riscv/shakti_c.h
28
+ case 0x03a1: return "pmpcfg1";
300
+F: include/hw/char/shakti_uart.h
29
+ case 0x03a2: return "pmpcfg2";
301
30
+ case 0x03a3: return "pmpcfg3";
302
SiFive Machines
31
+ case 0x03a4: return "pmpcfg4";
303
M: Alistair Francis <Alistair.Francis@wdc.com>
32
+ case 0x03a5: return "pmpcfg5";
304
diff --git a/hw/char/meson.build b/hw/char/meson.build
33
+ case 0x03a6: return "pmpcfg6";
305
index XXXXXXX..XXXXXXX 100644
34
+ case 0x03a7: return "pmpcfg7";
306
--- a/hw/char/meson.build
35
+ case 0x03a8: return "pmpcfg8";
307
+++ b/hw/char/meson.build
36
+ case 0x03a9: return "pmpcfg9";
308
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SERIAL', if_true: files('serial.c'))
37
+ case 0x03aa: return "pmpcfg10";
309
softmmu_ss.add(when: 'CONFIG_SERIAL_ISA', if_true: files('serial-isa.c'))
38
+ case 0x03ab: return "pmpcfg11";
310
softmmu_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c'))
39
+ case 0x03ac: return "pmpcfg12";
311
softmmu_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c'))
40
+ case 0x03ad: return "pmpcfg13";
312
+softmmu_ss.add(when: 'CONFIG_SHAKTI', if_true: files('shakti_uart.c'))
41
+ case 0x03ae: return "pmpcfg14";
313
softmmu_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-console.c'))
42
+ case 0x03af: return "pmpcfg15";
314
softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen_console.c'))
43
case 0x03b0: return "pmpaddr0";
315
softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_uartlite.c'))
44
case 0x03b1: return "pmpaddr1";
316
diff --git a/hw/char/trace-events b/hw/char/trace-events
45
case 0x03b2: return "pmpaddr2";
317
index XXXXXXX..XXXXXXX 100644
46
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
318
--- a/hw/char/trace-events
47
case 0x03bd: return "pmpaddr13";
319
+++ b/hw/char/trace-events
48
case 0x03be: return "pmpaddr14";
320
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1"
49
case 0x03bf: return "pmpaddr15";
321
nrf51_uart_read(uint64_t addr, uint64_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
50
+ case 0x03c0: return "pmpaddr16";
322
nrf51_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
51
+ case 0x03c1: return "pmpaddr17";
323
52
+ case 0x03c2: return "pmpaddr18";
324
+# shakti_uart.c
53
+ case 0x03c3: return "pmpaddr19";
325
+shakti_uart_read(uint64_t addr, uint16_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx16 " size %u"
54
+ case 0x03c4: return "pmpaddr20";
326
+shakti_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u"
55
+ case 0x03c5: return "pmpaddr21";
327
+
56
+ case 0x03c6: return "pmpaddr22";
328
# exynos4210_uart.c
57
+ case 0x03c7: return "pmpaddr23";
329
exynos_uart_dmabusy(uint32_t channel) "UART%d: DMA busy (Rx buffer empty)"
58
+ case 0x03c8: return "pmpaddr24";
330
exynos_uart_dmaready(uint32_t channel) "UART%d: DMA ready"
59
+ case 0x03c9: return "pmpaddr25";
60
+ case 0x03ca: return "pmpaddr26";
61
+ case 0x03cb: return "pmpaddr27";
62
+ case 0x03cc: return "pmpaddr28";
63
+ case 0x03cd: return "pmpaddr29";
64
+ case 0x03ce: return "pmpaddr30";
65
+ case 0x03cf: return "pmpaddr31";
66
+ case 0x03d0: return "pmpaddr32";
67
+ case 0x03d1: return "pmpaddr33";
68
+ case 0x03d2: return "pmpaddr34";
69
+ case 0x03d3: return "pmpaddr35";
70
+ case 0x03d4: return "pmpaddr36";
71
+ case 0x03d5: return "pmpaddr37";
72
+ case 0x03d6: return "pmpaddr38";
73
+ case 0x03d7: return "pmpaddr39";
74
+ case 0x03d8: return "pmpaddr40";
75
+ case 0x03d9: return "pmpaddr41";
76
+ case 0x03da: return "pmpaddr42";
77
+ case 0x03db: return "pmpaddr43";
78
+ case 0x03dc: return "pmpaddr44";
79
+ case 0x03dd: return "pmpaddr45";
80
+ case 0x03de: return "pmpaddr46";
81
+ case 0x03df: return "pmpaddr47";
82
+ case 0x03e0: return "pmpaddr48";
83
+ case 0x03e1: return "pmpaddr49";
84
+ case 0x03e2: return "pmpaddr50";
85
+ case 0x03e3: return "pmpaddr51";
86
+ case 0x03e4: return "pmpaddr52";
87
+ case 0x03e5: return "pmpaddr53";
88
+ case 0x03e6: return "pmpaddr54";
89
+ case 0x03e7: return "pmpaddr55";
90
+ case 0x03e8: return "pmpaddr56";
91
+ case 0x03e9: return "pmpaddr57";
92
+ case 0x03ea: return "pmpaddr58";
93
+ case 0x03eb: return "pmpaddr59";
94
+ case 0x03ec: return "pmpaddr60";
95
+ case 0x03ed: return "pmpaddr61";
96
+ case 0x03ee: return "pmpaddr62";
97
+ case 0x03ef: return "pmpaddr63";
98
case 0x0780: return "mtohost";
99
case 0x0781: return "mfromhost";
100
case 0x0782: return "mreset";
101
--
331
--
102
2.45.1
332
2.31.1
333
334
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
2
3
If the checking functions check both the single and double width
3
Connect one shakti uart to the shakti_c machine.
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
4
7
Signed-off-by: Max Chou <max.chou@sifive.com>
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
7
Message-id: 20210401181457.73039-5-vijai@behindbytes.com
10
Message-ID: <20240322092600.1198921-5-max.chou@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
9
---
13
target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------
10
include/hw/riscv/shakti_c.h | 2 ++
14
1 file changed, 4 insertions(+), 12 deletions(-)
11
hw/riscv/shakti_c.c | 8 ++++++++
12
2 files changed, 10 insertions(+)
15
13
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
14
diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h
17
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
16
--- a/include/hw/riscv/shakti_c.h
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
17
+++ b/include/hw/riscv/shakti_c.h
20
@@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
18
@@ -XXX,XX +XXX,XX @@
21
return require_rvv(s) &&
19
22
require_rvf(s) &&
20
#include "hw/riscv/riscv_hart.h"
23
require_scale_rvf(s) &&
21
#include "hw/boards.h"
24
- (s->sew != MO_8) &&
22
+#include "hw/char/shakti_uart.h"
25
vext_check_isa_ill(s) &&
23
26
vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm);
24
#define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc"
27
}
25
#define RISCV_SHAKTI_SOC(obj) \
28
@@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
26
@@ -XXX,XX +XXX,XX @@ typedef struct ShaktiCSoCState {
29
return require_rvv(s) &&
27
/*< public >*/
30
require_rvf(s) &&
28
RISCVHartArrayState cpus;
31
require_scale_rvf(s) &&
29
DeviceState *plic;
32
- (s->sew != MO_8) &&
30
+ ShaktiUartState uart;
33
vext_check_isa_ill(s) &&
31
MemoryRegion rom;
34
vext_check_ds(s, a->rd, a->rs2, a->vm);
32
35
}
33
} ShaktiCSoCState;
36
@@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
34
diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c
37
return require_rvv(s) &&
35
index XXXXXXX..XXXXXXX 100644
38
require_rvf(s) &&
36
--- a/hw/riscv/shakti_c.c
39
require_scale_rvf(s) &&
37
+++ b/hw/riscv/shakti_c.c
40
- (s->sew != MO_8) &&
38
@@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp)
41
vext_check_isa_ill(s) &&
39
SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
42
vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm);
40
SIFIVE_CLINT_TIMEBASE_FREQ, false);
43
}
41
44
@@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
42
+ qdev_prop_set_chr(DEVICE(&(sss->uart)), "chardev", serial_hd(0));
45
return require_rvv(s) &&
43
+ if (!sysbus_realize(SYS_BUS_DEVICE(&sss->uart), errp)) {
46
require_rvf(s) &&
44
+ return;
47
require_scale_rvf(s) &&
45
+ }
48
- (s->sew != MO_8) &&
46
+ sysbus_mmio_map(SYS_BUS_DEVICE(&sss->uart), 0,
49
vext_check_isa_ill(s) &&
47
+ shakti_c_memmap[SHAKTI_C_UART].base);
50
vext_check_dd(s, a->rd, a->rs2, a->vm);
48
+
51
}
49
/* ROM */
52
@@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
50
memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom",
53
{
51
shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal);
54
return opfv_widen_check(s, a) &&
52
@@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_instance_init(Object *obj)
55
require_rvfmin(s) &&
53
ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj);
56
- require_scale_rvfmin(s) &&
54
57
- (s->sew != MO_8);
55
object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY);
58
+ require_scale_rvfmin(s);
56
+ object_initialize_child(obj, "uart", &sss->uart, TYPE_SHAKTI_UART);
59
}
57
60
58
/*
61
#define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
59
* CPU type is fixed and we are not supporting passing from commandline yet.
62
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
63
{
64
return opfv_narrow_check(s, a) &&
65
require_rvfmin(s) &&
66
- require_scale_rvfmin(s) &&
67
- (s->sew != MO_8);
68
+ require_scale_rvfmin(s);
69
}
70
71
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
72
{
73
return opfv_narrow_check(s, a) &&
74
require_rvf(s) &&
75
- require_scale_rvf(s) &&
76
- (s->sew != MO_8);
77
+ require_scale_rvf(s);
78
}
79
80
#define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \
81
@@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
82
{
83
return reduction_widen_check(s, a) &&
84
require_rvf(s) &&
85
- require_scale_rvf(s) &&
86
- (s->sew != MO_8);
87
+ require_scale_rvf(s);
88
}
89
90
GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check)
91
--
60
--
92
2.45.1
61
2.31.1
62
63
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>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
1
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
15
---
5
---
16
target/riscv/cpu_bits.h | 2 +-
6
target/riscv/cpu_bits.h | 44 ++++++++++++++++++++-------------------
17
1 file changed, 1 insertion(+), 1 deletion(-)
7
target/riscv/cpu.c | 2 +-
8
target/riscv/cpu_helper.c | 4 ++--
9
3 files changed, 26 insertions(+), 24 deletions(-)
18
10
19
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
11
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
20
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu_bits.h
13
--- a/target/riscv/cpu_bits.h
22
+++ b/target/riscv/cpu_bits.h
14
+++ b/target/riscv/cpu_bits.h
23
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
15
@@ -XXX,XX +XXX,XX @@
24
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
16
#define DEFAULT_RSTVEC 0x1000
25
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
17
26
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
18
/* Exception causes */
27
- RISCV_EXCP_SEMIHOST = 0x10,
19
-#define EXCP_NONE -1 /* sentinel value */
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
20
-#define RISCV_EXCP_INST_ADDR_MIS 0x0
29
RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
21
-#define RISCV_EXCP_INST_ACCESS_FAULT 0x1
30
RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
22
-#define RISCV_EXCP_ILLEGAL_INST 0x2
31
RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
23
-#define RISCV_EXCP_BREAKPOINT 0x3
32
+ RISCV_EXCP_SEMIHOST = 0x3f,
24
-#define RISCV_EXCP_LOAD_ADDR_MIS 0x4
33
} RISCVException;
25
-#define RISCV_EXCP_LOAD_ACCESS_FAULT 0x5
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;
34
63
35
#define RISCV_EXCP_INT_FLAG 0x80000000
64
#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
}
36
--
99
--
37
2.45.1
100
2.31.1
38
101
39
102
diff view generated by jsdifflib
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
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: 187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com
5
---
6
target/riscv/cpu.h | 3 +-
7
target/riscv/csr.c | 80 +++++++++++++++++++++++++---------------------
8
2 files changed, 46 insertions(+), 37 deletions(-)
2
9
3
The th.sxstatus CSR can be used to identify available custom extension
4
on T-Head CPUs. The CSR is documented here:
5
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc
6
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).
16
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>
21
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
22
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
23
Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
26
MAINTAINERS | 1 +
27
target/riscv/cpu.h | 3 ++
28
target/riscv/cpu.c | 1 +
29
target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++
30
target/riscv/meson.build | 1 +
31
5 files changed, 85 insertions(+)
32
create mode 100644 target/riscv/th_csr.c
33
34
diff --git a/MAINTAINERS b/MAINTAINERS
35
index XXXXXXX..XXXXXXX 100644
36
--- a/MAINTAINERS
37
+++ b/MAINTAINERS
38
@@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org
39
S: Supported
40
F: target/riscv/insn_trans/trans_xthead.c.inc
41
F: target/riscv/xthead*.decode
42
+F: target/riscv/th_*
43
F: disas/riscv-xthead*
44
45
RISC-V XVentanaCondOps extension
46
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
47
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/cpu.h
12
--- a/target/riscv/cpu.h
49
+++ b/target/riscv/cpu.h
13
+++ b/target/riscv/cpu.h
50
@@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value,
14
@@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
51
uint8_t satp_mode_max_from_map(uint32_t map);
15
return val;
52
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
16
}
53
17
54
+/* Implemented in th_csr.c */
18
-typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno);
55
+void th_register_custom_csrs(RISCVCPU *cpu);
19
+typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
56
+
20
+ int csrno);
57
#endif /* RISCV_CPU_H */
21
typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
58
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
22
target_ulong *ret_value);
23
typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
24
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
59
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
60
--- a/target/riscv/cpu.c
26
--- a/target/riscv/csr.c
61
+++ b/target/riscv/cpu.c
27
+++ b/target/riscv/csr.c
62
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops)
63
cpu->cfg.mvendorid = THEAD_VENDOR_ID;
29
}
64
#ifndef CONFIG_USER_ONLY
30
65
set_satp_mode_max_supported(cpu, VM_1_10_SV39);
31
/* Predicates */
66
+ th_register_custom_csrs(cpu);
32
-static int fs(CPURISCVState *env, int csrno)
33
+static RISCVException fs(CPURISCVState *env, int csrno)
34
{
35
#if !defined(CONFIG_USER_ONLY)
36
/* loose check condition for fcsr in vector extension */
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
}
67
#endif
45
#endif
68
46
- return 0;
69
/* inherited from parent obj via riscv_cpu_init() */
47
+ return RISCV_EXCP_NONE;
70
diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c
48
}
71
new file mode 100644
49
72
index XXXXXXX..XXXXXXX
50
-static int vs(CPURISCVState *env, int csrno)
73
--- /dev/null
51
+static RISCVException vs(CPURISCVState *env, int csrno)
74
+++ b/target/riscv/th_csr.c
52
{
75
@@ -XXX,XX +XXX,XX @@
53
if (env->misa & RVV) {
76
+/*
54
- return 0;
77
+ * T-Head-specific CSRs.
55
+ return RISCV_EXCP_NONE;
78
+ *
56
}
79
+ * Copyright (c) 2024 VRULL GmbH
57
- return -RISCV_EXCP_ILLEGAL_INST;
80
+ *
58
+ return RISCV_EXCP_ILLEGAL_INST;
81
+ * This program is free software; you can redistribute it and/or modify it
59
}
82
+ * under the terms and conditions of the GNU General Public License,
60
83
+ * version 2 or later, as published by the Free Software Foundation.
61
-static int ctr(CPURISCVState *env, int csrno)
84
+ *
62
+static RISCVException ctr(CPURISCVState *env, int csrno)
85
+ * This program is distributed in the hope it will be useful, but WITHOUT
63
{
86
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64
#if !defined(CONFIG_USER_ONLY)
87
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
65
CPUState *cs = env_cpu(env);
88
+ * more details.
66
@@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno)
89
+ *
67
90
+ * You should have received a copy of the GNU General Public License along with
68
if (!cpu->cfg.ext_counters) {
91
+ * this program. If not, see <http://www.gnu.org/licenses/>.
69
/* The Counters extensions is not enabled */
92
+ */
70
- return -RISCV_EXCP_ILLEGAL_INST;
93
+
71
+ return RISCV_EXCP_ILLEGAL_INST;
94
+#include "qemu/osdep.h"
72
}
95
+#include "cpu.h"
73
96
+#include "cpu_vendorid.h"
74
if (riscv_cpu_virt_enabled(env)) {
97
+
75
@@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno)
98
+#define CSR_TH_SXSTATUS 0x5c0
76
case CSR_CYCLE:
99
+
77
if (!get_field(env->hcounteren, HCOUNTEREN_CY) &&
100
+/* TH_SXSTATUS bits */
78
get_field(env->mcounteren, HCOUNTEREN_CY)) {
101
+#define TH_SXSTATUS_UCME BIT(16)
79
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
102
+#define TH_SXSTATUS_MAEE BIT(21)
80
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
103
+#define TH_SXSTATUS_THEADISAEE BIT(22)
81
}
104
+
82
break;
105
+typedef struct {
83
case CSR_TIME:
106
+ int csrno;
84
if (!get_field(env->hcounteren, HCOUNTEREN_TM) &&
107
+ int (*insertion_test)(RISCVCPU *cpu);
85
get_field(env->mcounteren, HCOUNTEREN_TM)) {
108
+ riscv_csr_operations csr_ops;
86
- return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
109
+} riscv_csr;
87
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
110
+
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)
111
+static RISCVException smode(CPURISCVState *env, int csrno)
174
+static RISCVException smode(CPURISCVState *env, int csrno)
112
+{
175
{
176
- return -!riscv_has_ext(env, RVS);
113
+ if (riscv_has_ext(env, RVS)) {
177
+ if (riscv_has_ext(env, RVS)) {
114
+ return RISCV_EXCP_NONE;
178
+ return RISCV_EXCP_NONE;
115
+ }
179
+ }
116
+
180
+
117
+ return RISCV_EXCP_ILLEGAL_INST;
181
+ return RISCV_EXCP_ILLEGAL_INST;
118
+}
182
}
119
+
183
120
+static int test_thead_mvendorid(RISCVCPU *cpu)
184
-static int hmode(CPURISCVState *env, int csrno)
121
+{
185
+static RISCVException hmode(CPURISCVState *env, int csrno)
122
+ if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) {
186
{
123
+ return -1;
187
if (riscv_has_ext(env, RVS) &&
188
riscv_has_ext(env, RVH)) {
189
/* Hypervisor extension is supported */
190
if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
191
env->priv == PRV_M) {
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;
124
+ }
222
+ }
125
+
223
+
126
+ return 0;
224
+ return RISCV_EXCP_ILLEGAL_INST;
127
+}
225
}
128
+
226
#endif
129
+static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno,
227
130
+ target_ulong *val)
228
@@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
131
+{
229
return -RISCV_EXCP_ILLEGAL_INST;
132
+ /* We don't set MAEE here, because QEMU does not implement MAEE. */
230
}
133
+ *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE;
231
ret = csr_ops[csrno].predicate(env, csrno);
134
+ return RISCV_EXCP_NONE;
232
- if (ret < 0) {
135
+}
233
- return ret;
136
+
234
+ if (ret != RISCV_EXCP_NONE) {
137
+static riscv_csr th_csr_list[] = {
235
+ return -ret;
138
+ {
236
}
139
+ .csrno = CSR_TH_SXSTATUS,
237
140
+ .insertion_test = test_thead_mvendorid,
238
/* execute combined read/write operation if it exists */
141
+ .csr_ops = { "th.sxstatus", smode, read_th_sxstatus }
142
+ }
143
+};
144
+
145
+void th_register_custom_csrs(RISCVCPU *cpu)
146
+{
147
+ for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) {
148
+ int csrno = th_csr_list[i].csrno;
149
+ riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops;
150
+ if (!th_csr_list[i].insertion_test(cpu)) {
151
+ riscv_set_csr_ops(csrno, csr_ops);
152
+ }
153
+ }
154
+}
155
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
156
index XXXXXXX..XXXXXXX 100644
157
--- a/target/riscv/meson.build
158
+++ b/target/riscv/meson.build
159
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
160
'monitor.c',
161
'machine.c',
162
'pmu.c',
163
+ 'th_csr.c',
164
'time_helper.c',
165
'riscv-qmp-cmds.c',
166
))
167
--
239
--
168
2.45.1
240
2.31.1
169
241
170
242
diff view generated by jsdifflib
New 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(-)
1
8
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
1
From: Andrew Jones <ajones@ventanamicro.com>
2
3
The Zkr extension may only be exposed to KVM guests if the VMM
4
implements the SEED CSR. Use the same implementation as TCG.
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>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
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: 8566c4c271723f27f3ae8fc2429f906a459f17ce.1617290165.git.alistair.francis@wdc.com
18
---
5
---
19
target/riscv/cpu.h | 3 +++
6
target/riscv/cpu.h | 14 +-
20
target/riscv/csr.c | 18 ++++++++++++++----
7
target/riscv/csr.c | 629 +++++++++++++++++++++++++++------------------
21
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++
8
2 files changed, 382 insertions(+), 261 deletions(-)
22
3 files changed, 42 insertions(+), 4 deletions(-)
23
9
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
25
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.h
12
--- a/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
13
+++ b/target/riscv/cpu.h
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
14
@@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
29
15
30
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
16
typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
31
17
int csrno);
32
+target_ulong riscv_new_csr_seed(target_ulong new_value,
18
-typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
33
+ target_ulong write_mask);
19
- target_ulong *ret_value);
34
+
20
-typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
35
uint8_t satp_mode_max_from_map(uint32_t map);
21
- target_ulong new_value);
36
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
22
-typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
37
23
- target_ulong *ret_value, target_ulong new_value, target_ulong write_mask);
24
+typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
25
+ target_ulong *ret_value);
26
+typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
27
+ target_ulong new_value);
28
+typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
29
+ target_ulong *ret_value,
30
+ target_ulong new_value,
31
+ target_ulong write_mask);
32
33
typedef struct {
34
const char *name;
38
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
35
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
39
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/csr.c
37
--- a/target/riscv/csr.c
41
+++ b/target/riscv/csr.c
38
+++ b/target/riscv/csr.c
42
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
39
@@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno)
43
#endif
40
#endif
44
41
45
/* Crypto Extension */
42
/* User Floating-Point CSRs */
46
-static RISCVException rmw_seed(CPURISCVState *env, int csrno,
43
-static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val)
47
- target_ulong *ret_value,
44
+static RISCVException read_fflags(CPURISCVState *env, int csrno,
48
- target_ulong new_value,
45
+ target_ulong *val)
49
- target_ulong write_mask)
46
{
50
+target_ulong riscv_new_csr_seed(target_ulong new_value,
47
#if !defined(CONFIG_USER_ONLY)
51
+ target_ulong write_mask)
48
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
52
{
49
- return -RISCV_EXCP_ILLEGAL_INST;
53
uint16_t random_v;
50
+ return RISCV_EXCP_ILLEGAL_INST;
54
Error *random_e = NULL;
51
}
55
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
52
#endif
56
rval = random_v | SEED_OPST_ES16;
53
*val = riscv_cpu_get_fflags(env);
57
}
54
- return 0;
58
55
+ return RISCV_EXCP_NONE;
59
+ return rval;
56
}
60
+}
57
61
+
58
-static int write_fflags(CPURISCVState *env, int csrno, target_ulong val)
62
+static RISCVException rmw_seed(CPURISCVState *env, int csrno,
59
+static RISCVException write_fflags(CPURISCVState *env, int csrno,
60
+ target_ulong val)
61
{
62
#if !defined(CONFIG_USER_ONLY)
63
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
64
- return -RISCV_EXCP_ILLEGAL_INST;
65
+ return RISCV_EXCP_ILLEGAL_INST;
66
}
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
}
73
74
-static int read_frm(CPURISCVState *env, int csrno, target_ulong *val)
75
+static RISCVException read_frm(CPURISCVState *env, int csrno,
76
+ target_ulong *val)
77
{
78
#if !defined(CONFIG_USER_ONLY)
79
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
80
- return -RISCV_EXCP_ILLEGAL_INST;
81
+ return RISCV_EXCP_ILLEGAL_INST;
82
}
83
#endif
84
*val = env->frm;
85
- return 0;
86
+ return RISCV_EXCP_NONE;
87
}
88
89
-static int write_frm(CPURISCVState *env, int csrno, target_ulong val)
90
+static RISCVException write_frm(CPURISCVState *env, int csrno,
91
+ target_ulong val)
92
{
93
#if !defined(CONFIG_USER_ONLY)
94
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
95
- return -RISCV_EXCP_ILLEGAL_INST;
96
+ return RISCV_EXCP_ILLEGAL_INST;
97
}
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
}
104
105
-static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val)
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,
63
+ target_ulong *ret_value,
777
+ target_ulong *ret_value,
64
+ target_ulong new_value,
778
+ target_ulong new_value, target_ulong write_mask)
65
+ target_ulong write_mask)
779
{
66
+{
780
/* Shift the S bits to their VS bit location in mip */
67
+ target_ulong rval;
781
int ret = rmw_mip(env, 0, ret_value, new_value << 1,
68
+
782
@@ -XXX,XX +XXX,XX @@ static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value,
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;
783
return ret;
80
}
784
}
81
785
82
+static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run)
786
-static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
83
+{
787
- target_ulong new_value, target_ulong write_mask)
84
+ target_ulong csr_num = run->riscv_csr.csr_num;
788
+static RISCVException rmw_sip(CPURISCVState *env, int csrno,
85
+ target_ulong new_value = run->riscv_csr.new_value;
789
+ target_ulong *ret_value,
86
+ target_ulong write_mask = run->riscv_csr.write_mask;
790
+ target_ulong new_value, target_ulong write_mask)
87
+ int ret = 0;
791
{
88
+
792
int ret;
89
+ switch (csr_num) {
793
90
+ case CSR_SEED:
794
@@ -XXX,XX +XXX,XX @@ static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
91
+ run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask);
795
}
92
+ break;
796
93
+ default:
797
/* Supervisor Protection and Translation */
94
+ qemu_log_mask(LOG_UNIMP,
798
-static int read_satp(CPURISCVState *env, int csrno, target_ulong *val)
95
+ "%s: un-handled CSR EXIT for CSR %lx\n",
799
+static RISCVException read_satp(CPURISCVState *env, int csrno,
96
+ __func__, csr_num);
800
+ target_ulong *val)
97
+ ret = -1;
801
{
98
+ break;
802
if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
99
+ }
803
*val = 0;
100
+
804
- return 0;
101
+ return ret;
805
+ return RISCV_EXCP_NONE;
102
+}
806
}
103
+
807
104
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
808
if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
105
{
809
- return -RISCV_EXCP_ILLEGAL_INST;
106
int ret = 0;
810
+ return RISCV_EXCP_ILLEGAL_INST;
107
@@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
811
} else {
108
case KVM_EXIT_RISCV_SBI:
812
*val = env->satp;
109
ret = kvm_riscv_handle_sbi(cs, run);
813
}
110
break;
814
111
+ case KVM_EXIT_RISCV_CSR:
815
- return 0;
112
+ ret = kvm_riscv_handle_csr(cs, run);
816
+ return RISCV_EXCP_NONE;
113
+ break;
817
}
114
default:
818
115
qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
819
-static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
116
__func__, run->exit_reason);
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
}
117
--
1354
--
118
2.45.1
1355
2.31.1
1356
1357
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
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: 302b208f40373557fa11b351b5c9f43039ca8ea3.1617290165.git.alistair.francis@wdc.com
5
---
6
target/riscv/cpu.h | 11 +++++++----
7
target/riscv/csr.c | 37 ++++++++++++++++++-------------------
8
target/riscv/gdbstub.c | 8 ++++----
9
target/riscv/op_helper.c | 18 +++++++++---------
10
4 files changed, 38 insertions(+), 36 deletions(-)
2
11
3
Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length
12
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
4
in bytes, when in this context we want 'reg_width' as the length in
13
index XXXXXXX..XXXXXXX 100644
5
bits.
14
--- a/target/riscv/cpu.h
6
15
+++ b/target/riscv/cpu.h
7
Fix 'reg_width' back to the value in bits like 7cb59921c05a
16
@@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
8
("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set
17
*pflags = flags;
9
beforehand.
18
}
10
19
11
While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more
20
-int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
12
clarity about what the variable represents. 'bitsize' is also used in
21
- target_ulong new_value, target_ulong write_mask);
13
riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to
22
-int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value,
14
gdb_feature_builder_append_reg().
23
- target_ulong new_value, target_ulong write_mask);
15
24
+RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
16
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
25
+ target_ulong *ret_value,
17
Cc: Alex Bennée <alex.bennee@linaro.org>
26
+ target_ulong new_value, target_ulong write_mask);
18
Reported-by: Robin Dapp <rdapp.gcc@gmail.com>
27
+RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno,
19
Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML")
28
+ target_ulong *ret_value,
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
29
+ target_ulong new_value,
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
30
+ target_ulong write_mask);
22
Acked-by: Alex Bennée <alex.bennee@linaro.org>
31
23
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
32
static inline void riscv_csr_write(CPURISCVState *env, int csrno,
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
33
target_ulong val)
25
Cc: qemu-stable <qemu-stable@nongnu.org>
34
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
26
Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com>
35
index XXXXXXX..XXXXXXX 100644
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
36
--- a/target/riscv/csr.c
28
---
37
+++ b/target/riscv/csr.c
29
target/riscv/gdbstub.c | 6 +++---
38
@@ -XXX,XX +XXX,XX @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno,
30
1 file changed, 3 insertions(+), 3 deletions(-)
39
* csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value);
31
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
32
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
135
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
33
index XXXXXXX..XXXXXXX 100644
136
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/gdbstub.c
137
--- a/target/riscv/gdbstub.c
35
+++ b/target/riscv/gdbstub.c
138
+++ b/target/riscv/gdbstub.c
36
@@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg)
139
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n)
37
static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
140
*/
38
{
141
result = riscv_csrrw_debug(env, n - 32, &val,
39
RISCVCPU *cpu = RISCV_CPU(cs);
142
0, 0);
40
- int reg_width = cpu->cfg.vlenb;
143
- if (result == 0) {
41
+ int bitsize = cpu->cfg.vlenb << 3;
144
+ if (result == RISCV_EXCP_NONE) {
42
GDBFeatureBuilder builder;
145
return gdb_get_regl(buf, val);
43
int i;
146
}
44
147
}
45
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
148
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n)
46
149
*/
47
/* First define types and totals in a whole VL */
150
result = riscv_csrrw_debug(env, n - 32, NULL,
48
for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) {
151
val, -1);
49
- int count = reg_width / vec_lanes[i].size;
152
- if (result == 0) {
50
+ int count = bitsize / vec_lanes[i].size;
153
+ if (result == RISCV_EXCP_NONE) {
51
gdb_feature_builder_append_tag(
154
return sizeof(target_ulong);
52
&builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
155
}
53
vec_lanes[i].id, vec_lanes[i].gdb_type, count);
156
}
54
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
157
@@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n)
55
/* Define vector registers */
158
int result;
56
for (i = 0; i < 32; i++) {
159
57
gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i),
160
result = riscv_csrrw_debug(env, n, &val, 0, 0);
58
- reg_width, i, "riscv_vector", "vector");
161
- if (result == 0) {
59
+ bitsize, i, "riscv_vector", "vector");
162
+ if (result == RISCV_EXCP_NONE) {
60
}
163
return gdb_get_regl(buf, val);
61
164
}
62
gdb_feature_builder_end(&builder);
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
}
63
--
221
--
64
2.45.1
222
2.31.1
65
223
66
224
diff view generated by jsdifflib
New patch
1
Update the RISC-V maintainers by removing Sagar and Bastian who haven't
2
been involved recently.
1
3
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
New 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.
1
4
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
New patch
1
imply VIRTIO_VGA for the virt machine, this fixes the following error
2
when specifying `-vga virtio` as a command line argument:
1
3
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
1
From: Alexei Filippov <alexei.filippov@syntacore.com>
1
From: Jade Fink <qemu@jade.fyi>
2
2
3
Previous patch fixed the PMP priority in raise_mmu_exception() but we're still
3
Previously the qemu monitor and gdbstub looked at SUM and refused to
4
setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage
4
perform accesses to user memory if it is off, which was an impediment to
5
translation part, mtval2 will be set in case of successes 2 stage translation but
5
debugging.
6
failed pmp check.
7
6
8
In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of
7
Signed-off-by: Jade Fink <qemu@jade.fyi>
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>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com>
9
Message-id: 20210406113109.1031033-1-qemu@jade.fyi
19
Cc: qemu-stable <qemu-stable@nongnu.org>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
21
---
11
---
22
target/riscv/cpu_helper.c | 12 ++++++------
12
target/riscv/cpu_helper.c | 20 ++++++++++++--------
23
1 file changed, 6 insertions(+), 6 deletions(-)
13
1 file changed, 12 insertions(+), 8 deletions(-)
24
14
25
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
26
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
27
--- a/target/riscv/cpu_helper.c
17
--- a/target/riscv/cpu_helper.c
28
+++ b/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
20
* @first_stage: Are we in first stage translation?
21
* Second stage is used for hypervisor guest translation
22
* @two_stage: Are we going to perform two stage translation
23
+ * @is_debug: Is this access from a debugger or the monitor?
24
*/
25
static int get_physical_address(CPURISCVState *env, hwaddr *physical,
26
int *prot, target_ulong addr,
27
target_ulong *fault_pte_addr,
28
int access_type, int mmu_idx,
29
- bool first_stage, bool two_stage)
30
+ bool first_stage, bool two_stage,
31
+ bool is_debug)
32
{
33
/* NOTE: the env->pc value visible here will not be
34
* correct, but the value visible to the exception handler
35
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
36
widened = 2;
37
}
38
/* status.SUM will be ignored if execute on background */
39
- sum = get_field(env->mstatus, MSTATUS_SUM) || use_background;
40
+ sum = get_field(env->mstatus, MSTATUS_SUM) || use_background || is_debug;
41
switch (vm) {
42
case VM_1_10_SV32:
43
levels = 2; ptidxbits = 10; ptesize = 4; break;
44
@@ -XXX,XX +XXX,XX @@ restart:
45
/* Do the second stage translation on the base PTE address. */
46
int vbase_ret = get_physical_address(env, &vbase, &vbase_prot,
47
base, NULL, MMU_DATA_LOAD,
48
- mmu_idx, false, true);
49
+ mmu_idx, false, true,
50
+ is_debug);
51
52
if (vbase_ret != TRANSLATE_SUCCESS) {
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
}
29
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
70
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
30
__func__, pa, ret, prot_pmp, tlb_size);
71
/* Two stage lookup */
31
72
ret = get_physical_address(env, &pa, &prot, address,
32
prot &= prot_pmp;
73
&env->guest_phys_fault_addr, access_type,
33
- }
74
- mmu_idx, true, true);
34
-
75
+ mmu_idx, true, true, false);
35
- if (ret != TRANSLATE_SUCCESS) {
76
36
+ } else {
77
/*
37
/*
78
* A G-stage exception may be triggered during two state lookup.
38
* Guest physical address translation failed, this is a HS
79
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
39
* level exception
80
im_address = pa;
40
*/
81
41
first_stage_error = false;
82
ret = get_physical_address(env, &pa, &prot2, im_address, NULL,
42
- env->guest_phys_fault_addr = (im_address |
83
- access_type, mmu_idx, false, true);
43
- (address &
84
+ access_type, mmu_idx, false, true,
44
- (TARGET_PAGE_SIZE - 1))) >> 2;
85
+ false);
45
+ if (ret != TRANSLATE_PMP_FAIL) {
86
46
+ env->guest_phys_fault_addr = (im_address |
87
qemu_log_mask(CPU_LOG_MMU,
47
+ (address &
88
"%s 2nd-stage address=%" VADDR_PRIx " ret %d physical "
48
+ (TARGET_PAGE_SIZE - 1))) >> 2;
89
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
49
+ }
50
}
51
}
52
} else {
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 "
53
--
98
--
54
2.45.1
99
2.31.1
100
101
diff view generated by jsdifflib
1
From: "yang.zhang" <yang.zhang@hexintek.com>
1
From: LIU Zhiwei <zhiwei_liu@c-sky.com>
2
2
3
Since only root APLICs can have hw IRQ lines, aplic->parent should
3
The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right.
4
be initialized first.
4
However, when the predication is ture and a is 0, it should return maximum.
5
5
6
Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation")
6
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com
10
Message-ID: <20240409014445.278-1-gaoshanliukou@163.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
11
---
13
hw/intc/riscv_aplic.c | 8 ++++----
12
target/riscv/vector_helper.c | 8 ++++----
14
1 file changed, 4 insertions(+), 4 deletions(-)
13
1 file changed, 4 insertions(+), 4 deletions(-)
15
14
16
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
15
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/intc/riscv_aplic.c
17
--- a/target/riscv/vector_helper.c
19
+++ b/hw/intc/riscv_aplic.c
18
+++ b/target/riscv/vector_helper.c
20
@@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
19
@@ -XXX,XX +XXX,XX @@ static inline int8_t ssub8(CPURISCVState *env, int vxrm, int8_t a, int8_t b)
21
qdev_prop_set_bit(dev, "msimode", msimode);
20
{
22
qdev_prop_set_bit(dev, "mmode", mmode);
21
int8_t res = a - b;
23
22
if ((res ^ a) & (a ^ b) & INT8_MIN) {
24
+ if (parent) {
23
- res = a > 0 ? INT8_MAX : INT8_MIN;
25
+ riscv_aplic_add_child(parent, dev);
24
+ res = a >= 0 ? INT8_MAX : INT8_MIN;
26
+ }
25
env->vxsat = 0x1;
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);
32
}
26
}
33
27
return res;
34
- if (parent) {
28
@@ -XXX,XX +XXX,XX @@ static inline int16_t ssub16(CPURISCVState *env, int vxrm, int16_t a, int16_t b)
35
- riscv_aplic_add_child(parent, dev);
29
{
36
- }
30
int16_t res = a - b;
37
-
31
if ((res ^ a) & (a ^ b) & INT16_MIN) {
38
if (!msimode) {
32
- res = a > 0 ? INT16_MAX : INT16_MIN;
39
for (i = 0; i < num_harts; i++) {
33
+ res = a >= 0 ? INT16_MAX : INT16_MIN;
40
CPUState *cpu = cpu_by_arch_id(hartid_base + i);
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;
41
--
55
--
42
2.45.1
56
2.31.1
57
58
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Vijai Kumar K <vijai@behindbytes.com>
2
2
3
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr
3
Add documentation for Shakti C reference platform.
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.
8
4
9
In hindsight this is too strict. If we keep proceeding, despite not
5
Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
10
disabling the extension in the KVM vcpu, we'll not add the extension in
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
the riscv,isa. The guest kernel will be unaware of the extension, i.e.
7
Message-id: 20210412174248.8668-1-vijai@behindbytes.com
12
it doesn't matter if the KVM vcpu has it enabled underneath or not. So
8
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
13
it's ok to keep booting in this case.
9
[ Changes from Bin Meng:
14
10
- Add missing TOC
15
Change our current logic to not error out if we fail to disable an
11
Message-id: 20210430070534.1487242-1-bmeng.cn@gmail.com
16
extension in kvm_set_one_reg(), but show a warning and keep booting. It
12
]
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>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
35
---
14
---
36
target/riscv/kvm/kvm-cpu.c | 12 ++++++++----
15
docs/system/riscv/shakti-c.rst | 82 ++++++++++++++++++++++++++++++++++
37
1 file changed, 8 insertions(+), 4 deletions(-)
16
docs/system/target-riscv.rst | 1 +
17
2 files changed, 83 insertions(+)
18
create mode 100644 docs/system/riscv/shakti-c.rst
38
19
39
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
20
diff --git a/docs/system/riscv/shakti-c.rst b/docs/system/riscv/shakti-c.rst
21
new file mode 100644
22
index XXXXXXX..XXXXXXX
23
--- /dev/null
24
+++ b/docs/system/riscv/shakti-c.rst
25
@@ -XXX,XX +XXX,XX @@
26
+Shakti C Reference Platform (``shakti_c``)
27
+==========================================
28
+
29
+Shakti C Reference Platform is a reference platform based on arty a7 100t
30
+for the Shakti SoC.
31
+
32
+Shakti SoC is a SoC based on the Shakti C-class processor core. Shakti C
33
+is a 64bit RV64GCSUN processor core.
34
+
35
+For more details on Shakti SoC, please see:
36
+https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/fpga/boards/artya7-100t/c-class/README.rst
37
+
38
+For more info on the Shakti C-class core, please see:
39
+https://c-class.readthedocs.io/en/latest/
40
+
41
+Supported devices
42
+-----------------
43
+
44
+The ``shakti_c`` machine supports the following devices:
45
+
46
+ * 1 C-class core
47
+ * Core Level Interruptor (CLINT)
48
+ * Platform-Level Interrupt Controller (PLIC)
49
+ * 1 UART
50
+
51
+Boot options
52
+------------
53
+
54
+The ``shakti_c`` machine can start using the standard -bios
55
+functionality for loading the baremetal application or opensbi.
56
+
57
+Boot the machine
58
+----------------
59
+
60
+Shakti SDK
61
+~~~~~~~~~~
62
+Shakti SDK can be used to generate the baremetal example UART applications.
63
+
64
+.. code-block:: bash
65
+
66
+ $ git clone https://gitlab.com/behindbytes/shakti-sdk.git
67
+ $ cd shakti-sdk
68
+ $ make software PROGRAM=loopback TARGET=artix7_100t
69
+
70
+Binary would be generated in:
71
+ software/examples/uart_applns/loopback/output/loopback.shakti
72
+
73
+You could also download the precompiled example applicatons using below
74
+commands.
75
+
76
+.. code-block:: bash
77
+
78
+ $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/sdk/shakti_sdk_qemu.zip
79
+ $ unzip shakti_sdk_qemu.zip
80
+
81
+Then we can run the UART example using:
82
+
83
+.. code-block:: bash
84
+
85
+ $ qemu-system-riscv64 -M shakti_c -nographic \
86
+ -bios path/to/shakti_sdk_qemu/loopback.shakti
87
+
88
+OpenSBI
89
+~~~~~~~
90
+We can also run OpenSBI with Test Payload.
91
+
92
+.. code-block:: bash
93
+
94
+ $ git clone https://github.com/riscv/opensbi.git -b v0.9
95
+ $ cd opensbi
96
+ $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/dts/shakti.dtb
97
+ $ export CROSS_COMPILE=riscv64-unknown-elf-
98
+ $ export FW_FDT_PATH=./shakti.dtb
99
+ $ make PLATFORM=generic
100
+
101
+fw_payload.elf would be generated in build/platform/generic/firmware/fw_payload.elf.
102
+Boot it using the below qemu command.
103
+
104
+.. code-block:: bash
105
+
106
+ $ qemu-system-riscv64 -M shakti_c -nographic \
107
+ -bios path/to/fw_payload.elf
108
diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst
40
index XXXXXXX..XXXXXXX 100644
109
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/kvm/kvm-cpu.c
110
--- a/docs/system/target-riscv.rst
42
+++ b/target/riscv/kvm/kvm-cpu.c
111
+++ b/docs/system/target-riscv.rst
43
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
112
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
44
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
113
:maxdepth: 1
45
ret = kvm_set_one_reg(cs, id, &reg);
114
46
if (ret != 0) {
115
riscv/microchip-icicle-kit
47
- error_report("Unable to %s extension %s in KVM, error %d",
116
+ riscv/shakti-c
48
- reg ? "enable" : "disable",
117
riscv/sifive_u
49
- multi_ext_cfg->name, ret);
118
50
- exit(EXIT_FAILURE);
119
RISC-V CPU features
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
}
60
}
61
}
62
--
120
--
63
2.45.1
121
2.31.1
122
123
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
The RISC-V spec says:
2
if PMP entry i is locked and pmpicfg.A is set to TOR, writes to
3
pmpaddri-1 are ignored.
2
4
3
SBI defines a Debug Console extension "DBCN" that will, in time, replace
5
The current QEMU code ignores accesses to pmpaddri-1 and pmpcfgi-1 which
4
the legacy console putchar and getchar SBI extensions.
6
is incorrect.
5
7
6
The appeal of the DBCN extension is that it allows multiple bytes to be
8
Update the pmp_is_locked() function to not check the supporting fields
7
read/written in the SBI console in a single SBI call.
9
and instead enforce the lock functionality in the pmpaddr write operation.
8
10
9
As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
module to userspace. But this will only happens if the KVM module
12
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
11
actually supports this SBI extension and we activate it.
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(-)
12
17
13
We'll check for DBCN support during init time, checking if get-reg-list
18
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
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>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
30
---
31
target/riscv/sbi_ecall_interface.h | 17 +++++
32
target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++
33
2 files changed, 128 insertions(+)
34
35
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
36
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
37
--- a/target/riscv/sbi_ecall_interface.h
20
--- a/target/riscv/pmp.c
38
+++ b/target/riscv/sbi_ecall_interface.h
21
+++ b/target/riscv/pmp.c
39
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index)
40
23
return 0;
41
/* clang-format off */
24
}
42
25
43
+#define SBI_SUCCESS 0
26
- /* In TOR mode, need to check the lock bit of the next pmp
44
+#define SBI_ERR_FAILED -1
27
- * (if there is a next)
45
+#define SBI_ERR_NOT_SUPPORTED -2
28
- */
46
+#define SBI_ERR_INVALID_PARAM -3
29
- const uint8_t a_field =
47
+#define SBI_ERR_DENIED -4
30
- pmp_get_a_field(env->pmp_state.pmp[pmp_index + 1].cfg_reg);
48
+#define SBI_ERR_INVALID_ADDRESS -5
31
- if ((env->pmp_state.pmp[pmp_index + 1u].cfg_reg & PMP_LOCK) &&
49
+#define SBI_ERR_ALREADY_AVAILABLE -6
32
- (PMP_AMATCH_TOR == a_field)) {
50
+#define SBI_ERR_ALREADY_STARTED -7
33
- return 1;
51
+#define SBI_ERR_ALREADY_STOPPED -8
34
- }
52
+#define SBI_ERR_NO_SHMEM -9
35
-
53
+
54
/* SBI Extension IDs */
55
#define SBI_EXT_0_1_SET_TIMER 0x0
56
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
57
@@ -XXX,XX +XXX,XX @@
58
#define SBI_EXT_IPI 0x735049
59
#define SBI_EXT_RFENCE 0x52464E43
60
#define SBI_EXT_HSM 0x48534D
61
+#define SBI_EXT_DBCN 0x4442434E
62
63
/* SBI function IDs for BASE extension */
64
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
65
@@ -XXX,XX +XXX,XX @@
66
#define SBI_EXT_HSM_HART_STOP 0x1
67
#define SBI_EXT_HSM_HART_GET_STATUS 0x2
68
69
+/* SBI function IDs for DBCN extension */
70
+#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0
71
+#define SBI_EXT_DBCN_CONSOLE_READ 0x1
72
+#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2
73
+
74
#define SBI_HSM_HART_STATUS_STARTED 0x0
75
#define SBI_HSM_HART_STATUS_STOPPED 0x1
76
#define SBI_HSM_HART_STATUS_START_PENDING 0x2
77
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/target/riscv/kvm/kvm-cpu.c
80
+++ b/target/riscv/kvm/kvm-cpu.c
81
@@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = {
82
KVM_REG_RISCV_VECTOR_CSR_REG(vlenb)
83
};
84
85
+static KVMCPUConfig kvm_sbi_dbcn = {
86
+ .name = "sbi_dbcn",
87
+ .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 |
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;
36
return 0;
96
}
37
}
97
38
98
+static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu,
39
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
99
+ KVMScratchCPU *kvmcpu,
40
target_ulong val)
100
+ struct kvm_reg_list *reglist)
41
{
101
+{
42
trace_pmpaddr_csr_write(env->mhartid, addr_index, val);
102
+ struct kvm_reg_list *reg_search;
103
+
43
+
104
+ reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n,
44
if (addr_index < MAX_RISCV_PMPS) {
105
+ sizeof(uint64_t), uint64_cmp);
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;
106
+
51
+
107
+ if (reg_search) {
52
+ if (pmp_cfg & PMP_LOCK &&
108
+ kvm_sbi_dbcn.supported = true;
53
+ PMP_AMATCH_TOR == pmp_get_a_field(pmp_cfg)) {
109
+ }
54
+ qemu_log_mask(LOG_GUEST_ERROR,
110
+}
55
+ "ignoring pmpaddr write - pmpcfg + 1 locked\n");
111
+
56
+ return;
112
static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
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)
129
+{
130
+ target_ulong reg = 1;
131
+
132
+ if (!kvm_sbi_dbcn.supported) {
133
+ return 0;
134
+ }
135
+
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
+ }
57
+ }
205
+ }
58
+ }
206
+
59
+
207
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
60
if (!pmp_is_locked(env, addr_index)) {
208
+ run->riscv_sbi.ret[1] = ret;
61
env->pmp_state.pmp[addr_index].addr_reg = val;
209
+ break;
62
pmp_update_rule(env, addr_index);
210
+ case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
211
+ ch = run->riscv_sbi.args[0];
212
+ ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch));
213
+
214
+ if (ret < 0) {
215
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when "
216
+ "writing chardev");
217
+ exit(1);
218
+ }
219
+
220
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
221
+ run->riscv_sbi.ret[1] = 0;
222
+ break;
223
+ default:
224
+ run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
225
+ }
226
+}
227
+
228
static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
229
{
230
int ret = 0;
231
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
232
}
233
ret = 0;
234
break;
235
+ case SBI_EXT_DBCN:
236
+ kvm_riscv_handle_sbi_dbcn(cs, run);
237
+ break;
238
default:
239
qemu_log_mask(LOG_UNIMP,
240
"%s: un-handled SBI EXIT, specific reasons is %lu\n",
241
--
63
--
242
2.45.1
64
2.31.1
65
66
diff view generated by jsdifflib
New patch
1
From: Hou Weiying <weiying_hou@outlook.com>
1
2
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
1
From: Max Chou <max.chou@sifive.com>
1
The spec is avaliable at:
2
https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8
2
3
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>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
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
11
---
7
---
12
target/riscv/insn_trans/trans_rvv.c.inc | 1 +
8
target/riscv/cpu.h | 1 +
13
1 file changed, 1 insertion(+)
9
1 file changed, 1 insertion(+)
14
10
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
11
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
16
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
13
--- a/target/riscv/cpu.h
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
14
+++ b/target/riscv/cpu.h
19
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
15
@@ -XXX,XX +XXX,XX @@
20
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
16
enum {
21
{
17
RISCV_FEATURE_MMU,
22
return opfv_narrow_check(s, a) &&
18
RISCV_FEATURE_PMP,
23
+ require_rvf(s) &&
19
+ RISCV_FEATURE_EPMP,
24
require_scale_rvf(s) &&
20
RISCV_FEATURE_MISA
25
(s->sew != MO_8);
21
};
26
}
22
27
--
23
--
28
2.45.1
24
2.31.1
25
26
diff view generated by jsdifflib
1
From: Yu-Ming Chang <yumin686@andestech.com>
1
From: Hou Weiying <weiying_hou@outlook.com>
2
2
3
Both CSRRS and CSRRC always read the addressed CSR and cause any read side
3
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
4
effects regardless of rs1 and rd fields. Note that if rs1 specifies a register
4
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
5
holding a zero value other than x0, the instruction will still attempt to write
5
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
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>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
6
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
---
16
---
17
target/riscv/cpu.h | 4 ++++
17
target/riscv/cpu.h | 1 +
18
target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++----
18
target/riscv/pmp.h | 14 ++++++++++++++
19
target/riscv/op_helper.c | 6 ++---
19
target/riscv/csr.c | 24 ++++++++++++++++++++++++
20
3 files changed, 53 insertions(+), 8 deletions(-)
20
target/riscv/pmp.c | 34 ++++++++++++++++++++++++++++++++++
21
target/riscv/trace-events | 3 +++
22
5 files changed, 76 insertions(+)
21
23
22
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
23
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu.h
26
--- a/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
27
void riscv_cpu_update_mask(CPURISCVState *env);
29
28
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
30
/* physical memory protection */
29
31
pmp_table_t pmp_state;
30
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
32
+ target_ulong mseccfg;
31
+ target_ulong *ret_value);
33
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
34
/* machine specific rdtime callback */
33
target_ulong *ret_value,
35
uint64_t (*rdtime_fn)(uint32_t);
34
target_ulong new_value, target_ulong write_mask);
36
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
35
@@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
37
index XXXXXXX..XXXXXXX 100644
36
target_ulong new_value,
38
--- a/target/riscv/pmp.h
37
target_ulong write_mask);
39
+++ b/target/riscv/pmp.h
38
40
@@ -XXX,XX +XXX,XX @@ typedef enum {
39
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
41
PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */
40
+ Int128 *ret_value);
42
} pmp_am_t;
41
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
43
42
Int128 *ret_value,
44
+typedef enum {
43
Int128 new_value, Int128 write_mask);
45
+ MSECCFG_MML = 1 << 0,
46
+ MSECCFG_MMWP = 1 << 1,
47
+ MSECCFG_RLB = 1 << 2
48
+} mseccfg_field_t;
49
+
50
typedef struct {
51
target_ulong addr_reg;
52
uint8_t cfg_reg;
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
44
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
73
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
45
index XXXXXXX..XXXXXXX 100644
74
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/csr.c
75
--- a/target/riscv/csr.c
47
+++ b/target/riscv/csr.c
76
+++ b/target/riscv/csr.c
48
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
77
@@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno)
49
78
50
static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
79
return RISCV_EXCP_ILLEGAL_INST;
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;
68
}
80
}
69
81
+
70
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
82
+static RISCVException epmp(CPURISCVState *env, int csrno)
71
+ target_ulong *ret_value)
72
+{
83
+{
73
+ RISCVException ret = riscv_csrrw_check(env, csrno, false);
84
+ if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) {
74
+ if (ret != RISCV_EXCP_NONE) {
85
+ return RISCV_EXCP_NONE;
75
+ return ret;
76
+ }
86
+ }
77
+
87
+
78
+ return riscv_csrrw_do64(env, csrno, ret_value, 0, 0);
88
+ return RISCV_EXCP_ILLEGAL_INST;
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;
79
+}
102
+}
80
+
103
+
81
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
104
+static RISCVException write_mseccfg(CPURISCVState *env, int csrno,
82
target_ulong *ret_value,
105
+ target_ulong val)
83
target_ulong new_value, target_ulong write_mask)
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)
84
{
113
{
85
- RISCVException ret = riscv_csrrw_check(env, csrno, write_mask);
114
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
86
+ RISCVException ret = riscv_csrrw_check(env, csrno, true);
115
[CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst },
87
if (ret != RISCV_EXCP_NONE) {
116
88
return ret;
117
/* Physical Memory Protection */
89
}
118
+ [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg },
90
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno,
119
[CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg },
91
return RISCV_EXCP_NONE;
120
[CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },
121
[CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg },
122
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
123
index XXXXXXX..XXXXXXX 100644
124
--- a/target/riscv/pmp.c
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;
92
}
128
}
93
129
94
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
130
+/*
95
+ Int128 *ret_value)
131
+ * Handle a write to a mseccfg CSR
132
+ */
133
+void mseccfg_csr_write(CPURISCVState *env, target_ulong val)
96
+{
134
+{
97
+ RISCVException ret;
135
+ int i;
98
+
136
+
99
+ ret = riscv_csrrw_check(env, csrno, false);
137
+ trace_mseccfg_csr_write(env->mhartid, val);
100
+ if (ret != RISCV_EXCP_NONE) {
138
+
101
+ return ret;
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
+ }
102
+ }
147
+ }
103
+
148
+
104
+ if (csr_ops[csrno].read128) {
149
+ /* Sticky bits */
105
+ return riscv_csrrw_do128(env, csrno, ret_value,
150
+ val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML));
106
+ int128_zero(), int128_zero());
107
+ }
108
+
151
+
109
+ /*
152
+ env->mseccfg = val;
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
+}
153
+}
125
+
154
+
126
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
155
+/*
127
Int128 *ret_value,
156
+ * Handle a read from a mseccfg CSR
128
Int128 new_value, Int128 write_mask)
157
+ */
129
{
158
+target_ulong mseccfg_csr_read(CPURISCVState *env)
130
RISCVException ret;
159
+{
131
160
+ trace_mseccfg_csr_read(env->mhartid, env->mseccfg);
132
- ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask));
161
+ return env->mseccfg;
133
+ ret = riscv_csrrw_check(env, csrno, true);
162
+}
134
if (ret != RISCV_EXCP_NONE) {
163
+
135
return ret;
164
/*
136
}
165
* Calculate the TLB size if the start address or the end address of
137
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
166
* PMP entry is presented in thie TLB page.
167
diff --git a/target/riscv/trace-events b/target/riscv/trace-events
138
index XXXXXXX..XXXXXXX 100644
168
index XXXXXXX..XXXXXXX 100644
139
--- a/target/riscv/op_helper.c
169
--- a/target/riscv/trace-events
140
+++ b/target/riscv/op_helper.c
170
+++ b/target/riscv/trace-events
141
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr)
171
@@ -XXX,XX +XXX,XX @@ pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRI
142
}
172
pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64
143
173
pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64
144
target_ulong val = 0;
174
pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64
145
- RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0);
175
+
146
+ RISCVException ret = riscv_csrr(env, csr, &val);
176
+mseccfg_csr_read(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": read mseccfg, val: 0x%" PRIx64
147
177
+mseccfg_csr_write(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": write mseccfg, val: 0x%" PRIx64
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());
161
--
178
--
162
2.45.1
179
2.31.1
180
181
diff view generated by jsdifflib
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
1
From: Hou Weiying <weiying_hou@outlook.com>
2
2
3
In AIA spec, each hart (or each hart within a group) has a unique hart
3
This commit adds support for ePMP v0.9.1.
4
number to locate the memory pages of interrupt files in the address
4
5
space. The number of bits required to represent any hart number is equal
5
The ePMP spec can be found in:
6
to ceil(log2(hmax + 1)), where hmax is the largest hart number among
6
https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8
7
groups.
7
8
8
Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com>
9
However, if the largest hart number among groups is a power of 2, QEMU
9
Signed-off-by: Hou Weiying <weiying_hou@outlook.com>
10
will pass an inaccurate hart-index-bit setting to Linux. For example, when
10
Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com>
11
the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
to represent 4 harts, but we passes 3 to Linux. The code needs to be
12
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
13
updated to ensure accurate hart-index-bit settings.
13
Message-id: fef23b885f9649a4d54e7c98b168bdec5d297bb1.1618812899.git.alistair.francis@wdc.com
14
14
[ Changes by AF:
15
Additionally, a Linux patch[1] is necessary to correctly recover the hart
15
- Rebase on master
16
index when the guest OS has only 1 hart, where the hart-index-bit is 0.
16
- Update to latest spec
17
17
- Use a switch case to handle ePMP MML permissions
18
[1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/
18
- Fix a few bugs
19
19
]
20
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Cc: qemu-stable <qemu-stable@nongnu.org>
23
Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
21
---
26
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
22
target/riscv/pmp.c | 154 ++++++++++++++++++++++++++++++++++++++++++---
27
1 file changed, 8 insertions(+), 1 deletion(-)
23
1 file changed, 146 insertions(+), 8 deletions(-)
28
24
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
25
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
30
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/kvm/kvm-cpu.c
27
--- a/target/riscv/pmp.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
28
+++ b/target/riscv/pmp.c
33
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
29
@@ -XXX,XX +XXX,XX @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index)
30
static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
31
{
32
if (pmp_index < MAX_RISCV_PMPS) {
33
- if (!pmp_is_locked(env, pmp_index)) {
34
- env->pmp_state.pmp[pmp_index].cfg_reg = val;
35
- pmp_update_rule(env, pmp_index);
36
+ bool locked = true;
37
+
38
+ if (riscv_feature(env, RISCV_FEATURE_EPMP)) {
39
+ /* mseccfg.RLB is set */
40
+ if (MSECCFG_RLB_ISSET(env)) {
41
+ locked = false;
42
+ }
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);
34
}
72
}
35
}
73
} else {
36
74
qemu_log_mask(LOG_GUEST_ERROR,
37
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
75
@@ -XXX,XX +XXX,XX @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr,
38
+
76
{
39
+ if (max_hart_per_socket > 1) {
77
bool ret;
40
+ max_hart_per_socket--;
78
41
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
79
+ if (riscv_feature(env, RISCV_FEATURE_EPMP)) {
42
+ } else {
80
+ if (MSECCFG_MMWP_ISSET(env)) {
43
+ hart_bits = 0;
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
+ }
44
+ }
103
+ }
45
+
104
+
46
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
105
if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) {
47
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
106
/*
48
&hart_bits, true, NULL);
107
* Privileged spec v1.10 states if HW doesn't implement any PMP entry
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);
49
--
208
--
50
2.45.1
209
2.31.1
210
211
diff view generated by jsdifflib
New patch
1
From: Hou Weiying <weiying_hou@outlook.com>
1
2
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
New 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(-)
1
7
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
1
From: Rob Bradford <rbradford@rivosinc.com>
1
The physical Ibex CPU has ePMP support and it's enabled for the
2
OpenTitan machine so let's enable ePMP support for the Ibex CPU in QEMU.
2
3
3
This extension has now been ratified:
4
https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be
5
removed.
6
7
Since this is now a ratified extension add it to the list of extensions
8
included in the "max" CPU variant.
9
10
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.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>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
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
17
---
7
---
18
target/riscv/cpu.c | 2 +-
8
target/riscv/cpu.c | 1 +
19
target/riscv/tcg/tcg-cpu.c | 2 +-
9
1 file changed, 1 insertion(+)
20
2 files changed, 2 insertions(+), 2 deletions(-)
21
10
22
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
11
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
23
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu.c
13
--- a/target/riscv/cpu.c
25
+++ b/target/riscv/cpu.c
14
+++ b/target/riscv/cpu.c
26
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
15
@@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj)
27
MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
16
set_misa(env, RV32 | RVI | RVM | RVC | RVU);
28
MISA_EXT_INFO(RVV, "v", "Vector operations"),
17
set_priv_version(env, PRIV_VERSION_1_10_0);
29
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
18
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
30
- MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)")
19
+ qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
31
+ MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
20
}
32
};
21
33
22
static void rv32_imafcu_nommu_cpu_init(Object *obj)
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);
48
--
23
--
49
2.45.1
24
2.31.1
25
26
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
1
From: Frank Chang <frank.chang@sifive.com>
2
2
3
The require_scale_rvf function only checks the double width operator for
3
ETYPE may be type of uint64_t, thus index variable has to be declared as
4
the vector floating point widen instructions, so most of the widen
4
type of uint64_t, too. Otherwise the value read from vs1 register may be
5
checking functions need to add require_rvf for single width operator.
5
truncated to type of uint32_t.
6
6
7
The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width
7
Signed-off-by: Frank Chang <frank.chang@sifive.com>
8
integer to double width float, so the opfxv_widen_check function doesn’t
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
need require_rvf for the single width operator(integer).
9
Message-id: 20210419060302.14075-1-frank.chang@sifive.com
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>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
11
---
17
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++
12
target/riscv/vector_helper.c | 6 ++++--
18
1 file changed, 5 insertions(+)
13
1 file changed, 4 insertions(+), 2 deletions(-)
19
14
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
15
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
21
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
17
--- a/target/riscv/vector_helper.c
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/vector_helper.c
24
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check)
19
@@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \
25
static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
20
uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \
26
{
21
uint32_t vm = vext_vm(desc); \
27
return require_rvv(s) &&
22
uint32_t vl = env->vl; \
28
+ require_rvf(s) &&
23
- uint32_t index, i; \
29
require_scale_rvf(s) &&
24
+ uint64_t index; \
30
(s->sew != MO_8) &&
25
+ uint32_t i; \
31
vext_check_isa_ill(s) &&
26
\
32
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check)
27
for (i = 0; i < vl; i++) { \
33
static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
28
if (!vm && !vext_elem_mask(v0, mlen, i)) { \
34
{
29
@@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \
35
return require_rvv(s) &&
30
uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \
36
+ require_rvf(s) &&
31
uint32_t vm = vext_vm(desc); \
37
require_scale_rvf(s) &&
32
uint32_t vl = env->vl; \
38
(s->sew != MO_8) &&
33
- uint32_t index = s1, i; \
39
vext_check_isa_ill(s) &&
34
+ uint64_t index = s1; \
40
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf)
35
+ uint32_t i; \
41
static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
36
\
42
{
37
for (i = 0; i < vl; i++) { \
43
return require_rvv(s) &&
38
if (!vm && !vext_elem_mask(v0, mlen, i)) { \
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
}
64
--
39
--
65
2.45.1
40
2.31.1
66
41
67
42
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Emmanuel Blot <emmanuel.blot@sifive.com>
2
2
3
We're not setting (s/m)tval when triggering breakpoints of type 2
3
When no MMU is used and the guest code attempts to fetch an instruction
4
(mcontrol) and 6 (mcontrol6). According to the debug spec section
4
from an invalid memory location, the exception index defaults to a data
5
5.7.12, "Match Control Type 6":
5
load access fault, rather an instruction access fault.
6
6
7
"The Privileged Spec says that breakpoint exceptions that occur on
7
Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
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>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
27
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
9
Message-id: FB9EA197-B018-4879-AB0F-922C2047A08B@sifive.com
28
Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
30
---
11
---
31
target/riscv/cpu_helper.c | 1 +
12
target/riscv/cpu_helper.c | 4 +++-
32
target/riscv/debug.c | 3 +++
13
1 file changed, 3 insertions(+), 1 deletion(-)
33
2 files changed, 4 insertions(+)
34
14
35
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
36
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
37
--- a/target/riscv/cpu_helper.c
17
--- a/target/riscv/cpu_helper.c
38
+++ b/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
39
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
19
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
40
tval = env->bins;
20
41
break;
21
if (access_type == MMU_DATA_STORE) {
42
case RISCV_EXCP_BREAKPOINT:
22
cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
43
+ tval = env->badaddr;
23
- } else {
44
if (cs->watchpoint_hit) {
24
+ } else if (access_type == MMU_DATA_LOAD) {
45
tval = cs->watchpoint_hit->hitaddr;
25
cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
46
cs->watchpoint_hit = NULL;
26
+ } else {
47
diff --git a/target/riscv/debug.c b/target/riscv/debug.c
27
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
48
index XXXXXXX..XXXXXXX 100644
28
}
49
--- a/target/riscv/debug.c
29
50
+++ b/target/riscv/debug.c
30
env->badaddr = addr;
51
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
52
if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) {
53
/* check U/S/M bit against current privilege level */
54
if ((ctrl >> 3) & BIT(env->priv)) {
55
+ env->badaddr = pc;
56
return true;
57
}
58
}
59
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
60
if (env->virt_enabled) {
61
/* check VU/VS bit against current privilege level */
62
if ((ctrl >> 23) & BIT(env->priv)) {
63
+ env->badaddr = pc;
64
return true;
65
}
66
} else {
67
/* check U/S/M bit against current privilege level */
68
if ((ctrl >> 3) & BIT(env->priv)) {
69
+ env->badaddr = pc;
70
return true;
71
}
72
}
73
--
31
--
74
2.45.1
32
2.31.1
33
34
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
1
From: Alexander Wagner <alexander.wagner@ulal.de>
2
2
3
In current implementation, the gdbstub allows reading vector registers
3
The IBEX documentation [1] specifies the reset vector to be "the most
4
only if V extension is supported. However, all vector extensions and
4
significant 3 bytes of the boot address and the reset value (0x80) as
5
vector crypto extensions have the vector registers and they all depend
5
the least significant byte".
6
on Zve32x. The gdbstub should check for Zve32x instead.
7
6
8
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
[1] https://github.com/lowRISC/ibex/blob/master/doc/03_reference/exception_interrupts.rst
9
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
10
Reviewed-by: Max Chou <max.chou@sifive.com>
9
Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de>
11
Message-ID: <20240328022343.6871-4-jason.chien@sifive.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.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
target/riscv/gdbstub.c | 2 +-
14
hw/riscv/opentitan.c | 2 +-
15
1 file changed, 1 insertion(+), 1 deletion(-)
15
1 file changed, 1 insertion(+), 1 deletion(-)
16
16
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
17
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/gdbstub.c
19
--- a/hw/riscv/opentitan.c
20
+++ b/target/riscv/gdbstub.c
20
+++ b/hw/riscv/opentitan.c
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
21
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
22
gdb_find_static_feature("riscv-32bit-fpu.xml"),
22
&error_abort);
23
0);
23
object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
24
}
24
&error_abort);
25
- if (env->misa_ext & RVV) {
25
- object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort);
26
+ if (cpu->cfg.ext_zve32x) {
26
+ object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort);
27
gdb_register_coprocessor(cs, riscv_gdb_get_vector,
27
sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
28
riscv_gdb_set_vector,
28
29
ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs),
29
/* Boot ROM */
30
--
30
--
31
2.45.1
31
2.31.1
32
33
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Frank Chang <frank.chang@sifive.com>
2
2
3
Privileged spec section 4.1.9 mentions:
3
In IEEE 754-2008 spec:
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.
4
9
5
"When a trap is taken into S-mode, stval is written with
10
In RISC-V Unprivileged ISA spec:
6
exception-specific information to assist software in handling the trap.
11
The fused multiply-add instructions must set the invalid
7
(...)
12
operation exception flag when the multiplicands are Inf and
13
zero, even when the addend is a quiet NaN.
8
14
9
If stval is written with a nonzero value when a breakpoint,
15
This commit set invalid operation execption flag for RISC-V when
10
address-misaligned, access-fault, or page-fault exception occurs on an
16
multiplicands of muladd instructions are Inf and zero.
11
instruction fetch, load, or store, then stval will contain the faulting
12
virtual address."
13
17
14
A similar text is found for mtval in section 3.1.16.
18
Signed-off-by: Frank Chang <frank.chang@sifive.com>
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>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26
Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com>
20
Message-id: 20210420013150.21992-1-frank.chang@sifive.com
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
22
---
29
target/riscv/insn_trans/trans_privileged.c.inc | 2 ++
23
fpu/softfloat-specialize.c.inc | 6 ++++++
30
1 file changed, 2 insertions(+)
24
1 file changed, 6 insertions(+)
31
25
32
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
26
diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
33
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/insn_trans/trans_privileged.c.inc
28
--- a/fpu/softfloat-specialize.c.inc
35
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
29
+++ b/fpu/softfloat-specialize.c.inc
36
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
30
@@ -XXX,XX +XXX,XX @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
37
if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
38
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
39
} else {
31
} else {
40
+ tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env,
32
return 1;
41
+ offsetof(CPURISCVState, badaddr));
42
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
43
}
33
}
44
return true;
34
+#elif defined(TARGET_RISCV)
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
45
--
43
--
46
2.45.1
44
2.31.1
45
46
diff view generated by jsdifflib
1
From: Yangyu Chen <cyy@cyyself.name>
1
From: Emmanuel Blot <emmanuel.blot@sifive.com>
2
2
3
This code has a typo that writes zvkb to zvkg, causing users can't
3
Interrupt names have been swapped in 205377f8 and do not follow
4
enable zvkb through the config. This patch gets this fixed.
4
IRQ_*_EXT definition order.
5
5
6
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
6
Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com>
7
Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions")
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
8
Message-id: 20210421133236.11323-1-emmanuel.blot@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>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
10
---
16
target/riscv/cpu.c | 2 +-
11
target/riscv/cpu.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
12
1 file changed, 1 insertion(+), 1 deletion(-)
18
13
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
14
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.c
16
--- a/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
23
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
18
@@ -XXX,XX +XXX,XX @@ const char * const riscv_intr_names[] = {
24
/* Vector cryptography extensions */
19
"vs_timer",
25
MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
20
"m_timer",
26
MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false),
21
"u_external",
27
- MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false),
22
+ "s_external",
28
+ MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false),
23
"vs_external",
29
MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false),
24
- "h_external",
30
MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false),
25
"m_external",
31
MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false),
26
"reserved",
27
"reserved",
32
--
28
--
33
2.45.1
29
2.31.1
34
30
35
31
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
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: a07bc0c6dc4958681b4f93cbc5d0acc31ed3344a.1619234854.git.alistair.francis@wdc.com
5
---
6
target/riscv/cpu.h | 6 ------
7
target/riscv/cpu.c | 6 +++++-
8
2 files changed, 5 insertions(+), 7 deletions(-)
2
9
3
Add support for Zve64x extension. Enabling Zve64f enables Zve64x and
10
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
4
enabling Zve64x enables Zve32x according to their dependency.
5
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107
7
Signed-off-by: Jason Chien <jason.chien@sifive.com>
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Reviewed-by: Max Chou <max.chou@sifive.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Message-ID: <20240328022343.6871-3-jason.chien@sifive.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/cpu_cfg.h | 1 +
15
target/riscv/cpu.c | 2 ++
16
target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------
17
3 files changed, 14 insertions(+), 6 deletions(-)
18
19
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
20
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu_cfg.h
12
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu_cfg.h
13
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
14
@@ -XXX,XX +XXX,XX @@
24
bool ext_zve32x;
15
#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))
25
bool ext_zve64f;
16
#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
26
bool ext_zve64d;
17
27
+ bool ext_zve64x;
18
-#if defined(TARGET_RISCV32)
28
bool ext_zvbb;
19
-#define RVXLEN RV32
29
bool ext_zvbc;
20
-#elif defined(TARGET_RISCV64)
30
bool ext_zvkb;
21
-#define RVXLEN RV64
22
-#endif
23
-
24
#define RV(x) ((target_ulong)1 << (x - 'A'))
25
26
#define RVI RV('I')
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
29
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
30
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
31
@@ -XXX,XX +XXX,XX @@ static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
36
ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
32
static void riscv_any_cpu_init(Object *obj)
37
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
33
{
38
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
34
CPURISCVState *env = &RISCV_CPU(obj)->env;
39
+ ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x),
35
- set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
40
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
36
+#if defined(TARGET_RISCV32)
41
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
37
+ set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
42
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
38
+#elif defined(TARGET_RISCV64)
43
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
39
+ set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
44
MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
40
+#endif
45
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
41
set_priv_version(env, PRIV_VERSION_1_11_0);
46
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
42
}
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
}
94
43
95
--
44
--
96
2.45.1
45
2.31.1
46
47
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
1
This also ensures that the SD bit is not writable.
2
2
3
According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
instructions will be affected by Zvfhmin extension.
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
6
conversions of
6
Message-id: 9ea842309f0fd7adff172790f5b5fc058b40f2f1.1619234854.git.alistair.francis@wdc.com
7
---
8
target/riscv/cpu_bits.h | 6 ------
9
target/riscv/csr.c | 9 ++++++++-
10
2 files changed, 8 insertions(+), 7 deletions(-)
7
11
8
* From 1*SEW(16/32) to 2*SEW(32/64)
12
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
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>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
17
target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++--
18
1 file changed, 18 insertions(+), 2 deletions(-)
19
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
21
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
14
--- a/target/riscv/cpu_bits.h
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
15
+++ b/target/riscv/cpu_bits.h
24
@@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s)
16
@@ -XXX,XX +XXX,XX @@
25
}
17
#define SSTATUS32_SD 0x80000000
26
}
18
#define SSTATUS64_SD 0x8000000000000000ULL
27
19
28
+static bool require_rvfmin(DisasContext *s)
20
-#if defined(TARGET_RISCV32)
29
+{
21
-#define SSTATUS_SD SSTATUS32_SD
30
+ if (s->mstatus_fs == EXT_STATUS_DISABLED) {
22
-#elif defined(TARGET_RISCV64)
31
+ return false;
23
-#define SSTATUS_SD SSTATUS64_SD
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;
32
+ }
51
+ }
33
+
52
+
34
+ switch (s->sew) {
53
*val = env->mstatus & mask;
35
+ case MO_16:
54
return RISCV_EXCP_NONE;
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);
71
}
55
}
72
--
56
--
73
2.45.1
57
2.31.1
58
59
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
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: 665f624bfdc2e3ca64265004b07de7489c77a766.1619234854.git.alistair.francis@wdc.com
5
---
6
target/riscv/cpu_bits.h | 11 -----------
7
target/riscv/cpu_helper.c | 24 +++++++++++++++---------
8
2 files changed, 15 insertions(+), 20 deletions(-)
2
9
3
raise_mmu_exception(), as is today, is prioritizing guest page faults by
10
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
4
checking first if virt_enabled && !first_stage, and then considering the
11
index XXXXXXX..XXXXXXX 100644
5
regular inst/load/store faults.
12
--- a/target/riscv/cpu_bits.h
6
13
+++ b/target/riscv/cpu_bits.h
7
There's no mention in the spec about guest page fault being a higher
14
@@ -XXX,XX +XXX,XX @@
8
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
15
#define CSR_HTIMEDELTA 0x605
9
16
#define CSR_HTIMEDELTAH 0x615
10
"Attempting to fetch an instruction from a PMP region that does not have
17
11
execute permissions raises an instruction access-fault exception.
18
-#if defined(TARGET_RISCV32)
12
Attempting to execute a load or load-reserved instruction which accesses
19
-#define HGATP_MODE SATP32_MODE
13
a physical address within a PMP region without read permissions raises a
20
-#define HGATP_VMID SATP32_ASID
14
load access-fault exception. Attempting to execute a store,
21
-#define HGATP_PPN SATP32_PPN
15
store-conditional, or AMO instruction which accesses a physical address
22
-#endif
16
within a PMP region without write permissions raises a store
23
-#if defined(TARGET_RISCV64)
17
access-fault exception."
24
-#define HGATP_MODE SATP64_MODE
18
25
-#define HGATP_VMID SATP64_ASID
19
So, in fact, we're doing it wrong - PMP faults should always be thrown,
26
-#define HGATP_PPN SATP64_PPN
20
regardless of also being a first or second stage fault.
27
-#endif
21
28
-
22
The way riscv_cpu_tlb_fill() and get_physical_address() work is
29
/* Virtual CSRs */
23
adequate: a TRANSLATE_PMP_FAIL error is immediately reported and
30
#define CSR_VSSTATUS 0x200
24
reflected in the 'pmp_violation' flag. What we need is to change
31
#define CSR_VSIE 0x204
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>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
35
target/riscv/cpu_helper.c | 22 ++++++++++++----------
36
1 file changed, 12 insertions(+), 10 deletions(-)
37
38
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
32
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
39
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/cpu_helper.c
34
--- a/target/riscv/cpu_helper.c
41
+++ b/target/riscv/cpu_helper.c
35
+++ 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 */
42
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
52
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
43
53
bool first_stage, bool two_stage)
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
+
44
switch (access_type) {
74
switch (access_type) {
45
case MMU_INST_FETCH:
75
case MMU_INST_FETCH:
46
- if (env->virt_enabled && !first_stage) {
76
if (riscv_cpu_virt_enabled(env) && !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:
83
--
77
--
84
2.45.1
78
2.31.1
79
80
diff view generated by jsdifflib
New patch
1
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
---
5
target/riscv/cpu_bits.h | 10 ----------
6
target/riscv/csr.c | 12 ++++++++++--
7
target/riscv/translate.c | 19 +++++++++++++++++--
8
3 files changed, 27 insertions(+), 14 deletions(-)
1
9
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 MXL_RV64 2
16
#define MXL_RV128 3
17
18
-#if defined(TARGET_RISCV32)
19
-#define MSTATUS_SD MSTATUS32_SD
20
-#define MISA_MXL MISA32_MXL
21
-#define MXL_VAL MXL_RV32
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
}
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
}
68
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
--
111
2.31.1
112
113
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
1
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
---
5
target/riscv/cpu_bits.h | 11 -----------
6
target/riscv/cpu_helper.c | 32 ++++++++++++++++++++++++--------
7
target/riscv/csr.c | 19 +++++++++++++++----
8
target/riscv/monitor.c | 22 +++++++++++++++++-----
9
4 files changed, 56 insertions(+), 28 deletions(-)
2
10
3
Add support for Zve32x extension and replace some checks for Zve32f with
11
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
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>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/cpu_cfg.h | 1 +
14
target/riscv/cpu.c | 2 ++
15
target/riscv/cpu_helper.c | 2 +-
16
target/riscv/csr.c | 2 +-
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(-)
20
21
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
22
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu_cfg.h
13
--- a/target/riscv/cpu_bits.h
24
+++ b/target/riscv/cpu_cfg.h
14
+++ b/target/riscv/cpu_bits.h
25
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
15
@@ -XXX,XX +XXX,XX @@
26
bool ext_zhinx;
16
#define SATP64_ASID 0x0FFFF00000000000ULL
27
bool ext_zhinxmin;
17
#define SATP64_PPN 0x00000FFFFFFFFFFFULL
28
bool ext_zve32f;
18
29
+ bool ext_zve32x;
19
-#if defined(TARGET_RISCV32)
30
bool ext_zve64f;
20
-#define SATP_MODE SATP32_MODE
31
bool ext_zve64d;
21
-#define SATP_ASID SATP32_ASID
32
bool ext_zvbb;
22
-#define SATP_PPN SATP32_PPN
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
23
-#endif
34
index XXXXXXX..XXXXXXX 100644
24
-#if defined(TARGET_RISCV64)
35
--- a/target/riscv/cpu.c
25
-#define SATP_MODE SATP64_MODE
36
+++ b/target/riscv/cpu.c
26
-#define SATP_ASID SATP64_ASID
37
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
27
-#define SATP_PPN SATP64_PPN
38
ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb),
28
-#endif
39
ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc),
29
-
40
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
30
/* VM modes (mstatus.vm) privileged ISA 1.9.1 */
41
+ ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
31
#define VM_1_09_MBARE 0
42
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
32
#define VM_1_09_MBB 1
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),
53
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
33
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
54
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
55
--- a/target/riscv/cpu_helper.c
35
--- a/target/riscv/cpu_helper.c
56
+++ b/target/riscv/cpu_helper.c
36
+++ b/target/riscv/cpu_helper.c
57
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
37
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
58
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
38
59
*cs_base = 0;
39
if (first_stage == true) {
60
40
if (use_background) {
61
- if (cpu->cfg.ext_zve32f) {
41
- base = (hwaddr)get_field(env->vsatp, SATP_PPN) << PGSHIFT;
62
+ if (cpu->cfg.ext_zve32x) {
42
- vm = get_field(env->vsatp, SATP_MODE);
63
/*
43
+ if (riscv_cpu_is_32bit(env)) {
64
* If env->vl equals to VLMAX, we can use generic vector operation
44
+ base = (hwaddr)get_field(env->vsatp, SATP32_PPN) << PGSHIFT;
65
* expanders (GVEC) to accerlate the vector operations.
45
+ vm = get_field(env->vsatp, SATP32_MODE);
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) {
66
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
88
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
67
index XXXXXXX..XXXXXXX 100644
89
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/csr.c
90
--- a/target/riscv/csr.c
69
+++ b/target/riscv/csr.c
91
+++ b/target/riscv/csr.c
70
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
92
@@ -XXX,XX +XXX,XX @@ static RISCVException read_satp(CPURISCVState *env, int csrno,
71
93
static RISCVException write_satp(CPURISCVState *env, int csrno,
72
static RISCVException vs(CPURISCVState *env, int csrno)
94
target_ulong val)
73
{
95
{
74
- if (riscv_cpu_cfg(env)->ext_zve32f) {
96
+ int vm, mask, asid;
75
+ if (riscv_cpu_cfg(env)->ext_zve32x) {
97
+
76
#if !defined(CONFIG_USER_ONLY)
98
if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
77
if (!env->debugger && !riscv_cpu_vector_enabled(env)) {
99
return RISCV_EXCP_NONE;
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)) {
78
return RISCV_EXCP_ILLEGAL_INST;
117
return RISCV_EXCP_ILLEGAL_INST;
79
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
118
} else {
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
80
index XXXXXXX..XXXXXXX 100644
125
index XXXXXXX..XXXXXXX 100644
81
--- a/target/riscv/tcg/tcg-cpu.c
126
--- a/target/riscv/monitor.c
82
+++ b/target/riscv/tcg/tcg-cpu.c
127
+++ b/target/riscv/monitor.c
83
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
128
@@ -XXX,XX +XXX,XX @@ static void mem_info_svxx(Monitor *mon, CPUArchState *env)
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)
84
return;
146
return;
85
}
147
}
86
148
87
- if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) {
149
- if (!(env->satp & SATP_MODE)) {
88
- error_setg(errp, "Zve32f/Zve64f extensions require F extension");
150
- monitor_printf(mon, "No translation or protection\n");
89
- return;
151
- return;
90
+ /* The Zve32f extension depends on the Zve32x extension */
152
+ if (riscv_cpu_is_32bit(env)) {
91
+ if (cpu->cfg.ext_zve32f) {
153
+ if (!(env->satp & SATP32_MODE)) {
92
+ if (!riscv_has_ext(env, RVF)) {
154
+ monitor_printf(mon, "No translation or protection\n");
93
+ error_setg(errp, "Zve32f/Zve64f extensions require F extension");
94
+ return;
155
+ return;
95
+ }
156
+ }
96
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
157
+ } else {
158
+ if (!(env->satp & SATP64_MODE)) {
159
+ monitor_printf(mon, "No translation or protection\n");
160
+ return;
161
+ }
97
}
162
}
98
163
99
if (cpu->cfg.ext_zvfh) {
164
mem_info_svxx(mon, env);
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
137
--
165
--
138
2.45.1
166
2.31.1
167
168
diff view generated by jsdifflib
New 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(-)
1
8
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
New 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(-)
1
8
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
1
From: Alistair Francis <alistair23@gmail.com>
1
This patch removes the insn32-64.decode decode file and consolidates the
2
instructions into the general RISC-V insn32.decode decode tree.
2
3
3
When running the instruction
4
This means that all of the instructions are avaliable in both the 32-bit
4
5
and 64-bit builds. This also means that we run a check to ensure we are
5
```
6
running a 64-bit softmmu before we execute the 64-bit only instructions.
6
cbo.flush 0(x0)
7
This allows us to include the 32-bit instructions in the 64-bit build,
7
```
8
while also ensuring that 32-bit only software can not execute the
8
9
instructions.
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.
26
10
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
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")
30
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
31
Cc: qemu-stable <qemu-stable@nongnu.org>
13
Message-id: db709360e2be47d2f9c6483ab973fe4791aefa77.1619234854.git.alistair.francis@wdc.com
32
Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
14
---
35
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++----
15
target/riscv/helper.h | 18 +++--
36
1 file changed, 12 insertions(+), 4 deletions(-)
16
target/riscv/insn32-64.decode | 88 -------------------------
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
37
31
38
diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc
32
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
39
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/insn_trans/trans_rvzicbo.c.inc
34
--- a/target/riscv/helper.h
41
+++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc
35
+++ b/target/riscv/helper.h
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
42
@@ -XXX,XX +XXX,XX @@
91
@@ -XXX,XX +XXX,XX @@
43
static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a)
92
-#
44
{
93
-# RISC-V translation routines for the RV Instruction Set.
45
REQUIRE_ZICBOM(ctx);
94
-#
46
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
95
-# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
47
+ TCGv src = get_address(ctx, a->rs1, 0);
96
-# Bastian Koppelmann, kbastian@mail.uni-paderborn.de
48
+
97
-#
49
+ gen_helper_cbo_clean_flush(tcg_env, src);
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
+
219
# *** RV32M Standard Extension ***
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,
50
return true;
394
return true;
51
}
395
}
52
396
53
static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
397
-#ifdef TARGET_RISCV64
54
{
398
static void gen_addw(TCGv ret, TCGv arg1, TCGv arg2)
55
REQUIRE_ZICBOM(ctx);
399
{
56
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
400
tcg_gen_add_tl(ret, arg1, arg2);
57
+ TCGv src = get_address(ctx, a->rs1, 0);
401
@@ -XXX,XX +XXX,XX @@ static bool gen_arith_div_uw(DisasContext *ctx, arg_r *a,
58
+
59
+ gen_helper_cbo_clean_flush(tcg_env, src);
60
return true;
402
return true;
61
}
403
}
62
404
63
static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
405
-#endif
64
{
406
-
65
REQUIRE_ZICBOM(ctx);
407
static bool gen_arith(DisasContext *ctx, arg_r *a,
66
- gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]);
408
void(*func)(TCGv, TCGv, TCGv))
67
+ TCGv src = get_address(ctx, a->rs1, 0);
409
{
68
+
410
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
69
+ gen_helper_cbo_inval(tcg_env, src);
411
index XXXXXXX..XXXXXXX 100644
412
--- a/target/riscv/vector_helper.c
413
+++ b/target/riscv/vector_helper.c
414
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominw_v_w, 32, 32, H4, DO_MIN, l)
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)
70
return true;
527
return true;
71
}
528
}
72
529
73
static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
530
-#ifdef TARGET_RISCV64
74
{
531
-
75
REQUIRE_ZICBOZ(ctx);
532
static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
76
- gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]);
533
{
77
+ TCGv src = get_address(ctx, a->rs1, 0);
534
+ REQUIRE_64BIT(ctx);
78
+
535
REQUIRE_FPU;
79
+ gen_helper_cbo_zero(tcg_env, src);
536
REQUIRE_EXT(ctx, RVD);
537
538
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
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]);
80
return true;
556
return true;
81
}
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;
603
}
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()
82
--
933
--
83
2.45.1
934
2.31.1
935
936
diff view generated by jsdifflib
1
From: Andrew Jones <ajones@ventanamicro.com>
1
This patch removes the insn16-32.decode and insn16-64.decode decode
2
files and consolidates the instructions into the general RISC-V
3
insn16.decode decode tree.
2
4
3
Implementing wrs.nto to always just return is consistent with the
5
This means that all of the instructions are avaliable in both the 32-bit
4
specification, as the instruction is permitted to terminate the
6
and 64-bit builds. This also means that we run a check to ensure we are
5
stall for any reason, but it's not useful for virtualization, where
7
running a 64-bit softmmu before we execute the 64-bit only instructions.
6
we'd like the guest to trap to the hypervisor in order to allow
8
This allows us to include the 32-bit instructions in the 64-bit build,
7
scheduling of the lock holding VCPU. Change to always immediately
9
while also ensuring that 32-bit only software can not execute the
8
raise exceptions when the appropriate conditions are present,
10
instructions.
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.
13
11
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>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
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
20
---
15
---
21
target/riscv/helper.h | 1 +
16
target/riscv/insn16-32.decode | 28 -------------------
22
target/riscv/op_helper.c | 11 ++++++++
17
target/riscv/insn16-64.decode | 36 -------------------------
23
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++-------
18
target/riscv/insn16.decode | 30 +++++++++++++++++++++
24
3 files changed, 32 insertions(+), 9 deletions(-)
19
target/riscv/insn_trans/trans_rvi.c.inc | 6 +++++
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
25
24
26
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
25
diff --git a/target/riscv/insn16-32.decode b/target/riscv/insn16-32.decode
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
27
index XXXXXXX..XXXXXXX 100644
102
index XXXXXXX..XXXXXXX 100644
28
--- a/target/riscv/helper.h
103
--- a/target/riscv/insn16.decode
29
+++ b/target/riscv/helper.h
104
+++ b/target/riscv/insn16.decode
30
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
105
@@ -XXX,XX +XXX,XX @@ lw 010 ... ... .. ... 00 @cl_w
31
DEF_HELPER_1(sret, tl, env)
106
fsd 101 ... ... .. ... 00 @cs_d
32
DEF_HELPER_1(mret, tl, env)
107
sw 110 ... ... .. ... 00 @cs_w
33
DEF_HELPER_1(wfi, void, env)
108
34
+DEF_HELPER_1(wrs_nto, void, env)
109
+# *** RV32C and RV64C specific Standard Extension (Quadrant 0) ***
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)
47
+{
110
+{
48
+ if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) &&
111
+ ld 011 ... ... .. ... 00 @cl_d
49
+ get_field(env->hstatus, HSTATUS_VTW) &&
112
+ flw 011 ... ... .. ... 00 @cl_w
50
+ !get_field(env->mstatus, MSTATUS_TW)) {
113
+}
51
+ riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC());
114
+{
52
+ } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) {
115
+ sd 111 ... ... .. ... 00 @cs_d
53
+ riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
116
+ fsw 111 ... ... .. ... 00 @cs_w
54
+ }
55
+}
117
+}
56
+
118
+
57
void helper_tlb_flush(CPURISCVState *env)
119
# *** RV32/64C Standard Extension (Quadrant 1) ***
58
{
120
addi 000 . ..... ..... 01 @ci
59
CPUState *cs = env_cpu(env);
121
addi 010 . ..... ..... 01 @c_li
60
diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc
122
@@ -XXX,XX +XXX,XX @@ jal 101 ........... 01 @cj rd=0 # C.J
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
61
index XXXXXXX..XXXXXXX 100644
154
index XXXXXXX..XXXXXXX 100644
62
--- a/target/riscv/insn_trans/trans_rvzawrs.c.inc
155
--- a/target/riscv/insn_trans/trans_rvi.c.inc
63
+++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc
156
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
64
@@ -XXX,XX +XXX,XX @@
157
@@ -XXX,XX +XXX,XX @@ static bool trans_illegal(DisasContext *ctx, arg_empty *a)
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)
74
return true;
158
return true;
75
}
159
}
76
160
77
-#define GEN_TRANS_WRS(insn) \
161
+static bool trans_c64_illegal(DisasContext *ctx, arg_empty *a)
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)
84
+{
162
+{
85
+ if (!ctx->cfg_ptr->ext_zawrs) {
163
+ REQUIRE_64BIT(ctx);
86
+ return false;
164
+ return trans_illegal(ctx, a);
87
+ }
165
+}
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
+
166
+
102
+ /* We only get here when helper_wrs_nto() doesn't raise an exception. */
167
static bool trans_lui(DisasContext *ctx, arg_lui *a)
103
+ return trans_wrs_sto(ctx, NULL);
168
{
104
+}
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',
105
--
196
--
106
2.45.1
197
2.31.1
107
198
108
199
diff view generated by jsdifflib
New 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(-)
1
8
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