1
The following changes since commit fcb237e64f9d026c03d635579c7b288d0008a6e5:
1
The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946:
2
2
3
Merge tag 'pull-vfio-20230710' of https://github.com/legoater/qemu into staging (2023-07-10 09:17:06 +0100)
3
Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20230710-1
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528
8
8
9
for you to fetch changes up to a47842d16653b4f73b5d56ff0c252dd8a329481b:
9
for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393:
10
10
11
riscv: Add support for the Zfa extension (2023-07-10 22:29:20 +1000)
11
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Third RISC-V PR for 8.1
14
RISC-V PR for 9.1
15
15
16
* Use xl instead of mxl for disassemble
16
* APLICs add child earlier than realize
17
* Factor out extension tests to cpu_cfg.h
17
* Fix exposure of Zkr
18
* disas/riscv: Add vendor extension support
18
* Raise exceptions on wrs.nto
19
* disas/riscv: Add support for XVentanaCondOps
19
* Implement SBI debug console (DBCN) calls for KVM
20
* disas/riscv: Add support for XThead* instructions
20
* Support 64-bit addresses for initrd
21
* Fix mstatus related problems
21
* Change RISCV_EXCP_SEMIHOST exception number to 63
22
* Fix veyron-v1 CPU properties
22
* Tolerate KVM disable ext errors
23
* Fix the xlen for data address when MPRV=1
23
* Set tval in breakpoints
24
* opensbi: Upgrade from v1.2 to v1.3
24
* Add support for Zve32x extension
25
* Enable 32-bit Spike OpenSBI boot testing
25
* Add support for Zve64x extension
26
* Support the watchdog timer of HiFive 1 rev b
26
* Relax vector register check in RISCV gdbstub
27
* Only build qemu-system-riscv$$ on rv$$ host
27
* Fix the element agnostic Vector function problem
28
* Add RVV registers to log
28
* Fix Zvkb extension config
29
* Restrict ACLINT to TCG
29
* Implement dynamic establishment of custom decoder
30
* Add syscall riscv_hwprobe
30
* Add th.sxstatus CSR emulation
31
* Add support for BF16 extensions
31
* Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
32
* KVM_RISCV_SET_TIMER macro is not configured correctly
32
* Check single width operator for vector fp widen instructions
33
* Generate devicetree only after machine initialization is complete
33
* Check single width operator for vfncvt.rod.f.f.w
34
* virt: Convert fdt_load_addr to uint64_t
34
* Remove redudant SEW checking for vector fp narrow/widen instructions
35
* KVM: fixes and enhancements
35
* Prioritize pmp errors in raise_mmu_exception()
36
* Add support for the Zfa extension
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
37
43
38
----------------------------------------------------------------
44
----------------------------------------------------------------
39
Bin Meng (2):
45
Alexei Filippov (1):
40
roms/opensbi: Upgrade from v1.2 to v1.3
46
target/riscv: do not set mtval2 for non guest-page faults
41
tests/avocado: riscv: Enable 32-bit Spike OpenSBI boot testing
42
47
43
Christoph Müllner (8):
48
Alistair Francis (2):
44
target/riscv: Factor out extension tests to cpu_cfg.h
49
target/riscv: rvzicbo: Fixup CBO extension register calculation
45
disas/riscv: Move types/constants to new header file
50
disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs
46
disas/riscv: Make rv_op_illegal a shared enum value
47
disas/riscv: Encapsulate opcode_data into decode
48
disas/riscv: Provide infrastructure for vendor extensions
49
disas/riscv: Add support for XVentanaCondOps
50
disas/riscv: Add support for XThead* instructions
51
riscv: Add support for the Zfa extension
52
51
53
Daniel Henrique Barboza (20):
52
Andrew Jones (2):
54
target/riscv/cpu.c: fix veyron-v1 CPU properties
53
target/riscv/kvm: Fix exposure of Zkr
55
target/riscv: skip features setup for KVM CPUs
54
target/riscv: Raise exceptions on wrs.nto
56
hw/riscv/virt.c: skip 'mmu-type' FDT if satp mode not set
57
target/riscv/cpu.c: restrict 'mvendorid' value
58
target/riscv/cpu.c: restrict 'mimpid' value
59
target/riscv/cpu.c: restrict 'marchid' value
60
target/riscv: use KVM scratch CPUs to init KVM properties
61
target/riscv: read marchid/mimpid in kvm_riscv_init_machine_ids()
62
target/riscv: handle mvendorid/marchid/mimpid for KVM CPUs
63
target/riscv/kvm.c: init 'misa_ext_mask' with scratch CPU
64
target/riscv/cpu: add misa_ext_info_arr[]
65
target/riscv: add KVM specific MISA properties
66
target/riscv/kvm.c: update KVM MISA bits
67
target/riscv/kvm.c: add multi-letter extension KVM properties
68
target/riscv/cpu.c: add satp_mode properties earlier
69
target/riscv/cpu.c: remove priv_ver check from riscv_isa_string_ext()
70
target/riscv/cpu.c: create KVM mock properties
71
target/riscv: update multi-letter extension KVM properties
72
target/riscv/kvm.c: add kvmconfig_get_cfg_addr() helper
73
target/riscv/kvm.c: read/write (cbom|cboz)_blocksize in KVM
74
55
75
Guenter Roeck (1):
56
Cheng Yang (1):
76
riscv: Generate devicetree only after machine initialization is complete
57
hw/riscv/boot.c: Support 64-bit address for initrd
77
58
78
Ivan Klokov (1):
59
Christoph Müllner (1):
79
target/riscv: Add RVV registers to log
60
riscv: thead: Add th.sxstatus CSR emulation
80
61
81
Jason Chien (1):
62
Clément Léger (1):
82
target/riscv: Set the correct exception for implict G-stage translation fail
63
target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63
83
64
84
LIU Zhiwei (1):
65
Daniel Henrique Barboza (6):
85
target/riscv: Use xl instead of mxl for disassemble
66
target/riscv/kvm: implement SBI debug console (DBCN) calls
67
target/riscv/kvm: tolerate KVM disable ext errors
68
target/riscv/debug: set tval=pc in breakpoint exceptions
69
trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint
70
target/riscv: prioritize pmp errors in raise_mmu_exception()
71
riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature()
86
72
87
Lakshmi Bai Raja Subramanian (1):
73
Huang Tao (2):
88
hw/riscv: virt: Convert fdt_load_addr to uint64_t
74
target/riscv: Fix the element agnostic function problem
75
target/riscv: Implement dynamic establishment of custom decoder
89
76
90
Philippe Mathieu-Daudé (3):
77
Jason Chien (3):
91
target/riscv: Only unify 'riscv32/64' -> 'riscv' for host cpu in meson
78
target/riscv: Add support for Zve32x extension
92
target/riscv: Only build KVM guest with same wordsize as host
79
target/riscv: Add support for Zve64x extension
93
hw/riscv/virt: Restrict ACLINT to TCG
80
target/riscv: Relax vector register check in RISCV gdbstub
94
81
95
Robbin Ehn (1):
82
Max Chou (4):
96
linux-user/riscv: Add syscall riscv_hwprobe
83
target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
84
target/riscv: rvv: Check single width operator for vector fp widen instructions
85
target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w
86
target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions
97
87
98
Tommy Wu (3):
88
Rob Bradford (1):
99
hw/misc: sifive_e_aon: Support the watchdog timer of HiFive 1 rev b.
89
target/riscv: Remove experimental prefix from "B" extension
100
hw/riscv: sifive_e: Support the watchdog timer of HiFive 1 rev b.
101
tests/qtest: sifive-e-aon-watchdog-test.c: Add QTest of watchdog of sifive_e
102
90
103
Weiwei Li (11):
91
Yangyu Chen (1):
104
target/riscv: Make MPV only work when MPP != PRV_M
92
target/riscv/cpu.c: fix Zvkb extension config
105
target/riscv: Support MSTATUS.MPV/GVA only when RVH is enabled
93
106
target/riscv: Remove redundant assignment to SXL
94
Yong-Xuan Wang (1):
107
target/riscv: Add additional xlen for address when MPRV=1
95
target/riscv/kvm.c: Fix the hart bit setting of AIA
108
target/riscv: update cur_pmbase/pmmask based on mode affected by MPRV
96
109
target/riscv: Add properties for BF16 extensions
97
Yu-Ming Chang (1):
110
target/riscv: Add support for Zfbfmin extension
98
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR
111
target/riscv: Add support for Zvfbfmin extension
112
target/riscv: Add support for Zvfbfwma extension
113
target/riscv: Expose properties for BF16 extensions
114
target/riscv: Add disas support for BF16 extensions
115
99
116
yang.zhang (1):
100
yang.zhang (1):
117
target/riscv KVM_RISCV_SET_TIMER macro is not configured correctly
101
hw/intc/riscv_aplic: APLICs should add child earlier than realize
118
102
119
docs/system/riscv/virt.rst | 1 +
103
MAINTAINERS | 1 +
120
meson.build | 15 +-
104
target/riscv/cpu.h | 11 ++
121
disas/riscv-xthead.h | 28 +
105
target/riscv/cpu_bits.h | 2 +-
122
disas/riscv-xventana.h | 18 +
106
target/riscv/cpu_cfg.h | 2 +
123
disas/riscv.h | 302 +++++++++++
107
target/riscv/helper.h | 1 +
124
include/hw/misc/sifive_e_aon.h | 60 +++
108
target/riscv/sbi_ecall_interface.h | 17 +++
125
include/hw/riscv/sifive_e.h | 9 +-
109
target/riscv/tcg/tcg-cpu.h | 15 +++
126
linux-user/riscv/syscall32_nr.h | 1 +
110
disas/riscv.c | 65 +++++++++-
127
linux-user/riscv/syscall64_nr.h | 1 +
111
hw/intc/riscv_aplic.c | 8 +-
128
target/riscv/cpu.h | 56 +-
112
hw/riscv/boot.c | 4 +-
129
target/riscv/cpu_cfg.h | 41 ++
113
target/riscv/cpu.c | 10 +-
130
target/riscv/helper.h | 29 +
114
target/riscv/cpu_helper.c | 37 +++---
131
target/riscv/kvm_riscv.h | 1 +
115
target/riscv/csr.c | 71 +++++++++--
132
target/riscv/insn32.decode | 38 ++
116
target/riscv/debug.c | 3 +
133
disas/riscv-xthead.c | 707 +++++++++++++++++++++++++
117
target/riscv/gdbstub.c | 8 +-
134
disas/riscv-xventana.c | 41 ++
118
target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++-
135
disas/riscv.c | 559 +++++++++----------
119
target/riscv/op_helper.c | 17 ++-
136
hw/misc/sifive_e_aon.c | 319 +++++++++++
120
target/riscv/tcg/tcg-cpu.c | 50 +++++---
137
hw/riscv/sifive_e.c | 17 +-
121
target/riscv/th_csr.c | 79 +++++++++++++
138
hw/riscv/virt.c | 56 +-
122
target/riscv/translate.c | 31 +++--
139
linux-user/syscall.c | 146 +++++
123
target/riscv/vector_internals.c | 22 ++++
140
target/riscv/cpu.c | 439 +++++++++++++--
124
target/riscv/insn_trans/trans_privileged.c.inc | 2 +
141
target/riscv/cpu_helper.c | 12 +-
125
target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++---
142
target/riscv/csr.c | 41 +-
126
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++--
143
target/riscv/fpu_helper.c | 166 ++++++
127
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++-
144
target/riscv/kvm.c | 501 +++++++++++++++++-
128
target/riscv/meson.build | 1 +
145
target/riscv/op_helper.c | 3 +-
129
26 files changed, 596 insertions(+), 109 deletions(-)
146
target/riscv/translate.c | 42 +-
130
create mode 100644 target/riscv/th_csr.c
147
target/riscv/vector_helper.c | 17 +
148
tests/qtest/sifive-e-aon-watchdog-test.c | 450 ++++++++++++++++
149
tests/tcg/riscv64/test-fcvtmod.c | 345 ++++++++++++
150
target/riscv/insn_trans/trans_rvbf16.c.inc | 175 ++++++
151
target/riscv/insn_trans/trans_rvzfa.c.inc | 521 ++++++++++++++++++
152
target/riscv/insn_trans/trans_rvzfh.c.inc | 12 +-
153
disas/meson.build | 6 +-
154
hw/misc/Kconfig | 3 +
155
hw/misc/meson.build | 1 +
156
hw/riscv/Kconfig | 1 +
157
pc-bios/opensbi-riscv32-generic-fw_dynamic.bin | Bin 123072 -> 135344 bytes
158
pc-bios/opensbi-riscv64-generic-fw_dynamic.bin | Bin 121800 -> 138304 bytes
159
roms/opensbi | 2 +-
160
tests/avocado/riscv_opensbi.py | 2 -
161
tests/qtest/meson.build | 3 +
162
tests/tcg/riscv64/Makefile.target | 6 +
163
44 files changed, 4751 insertions(+), 442 deletions(-)
164
create mode 100644 disas/riscv-xthead.h
165
create mode 100644 disas/riscv-xventana.h
166
create mode 100644 disas/riscv.h
167
create mode 100644 include/hw/misc/sifive_e_aon.h
168
create mode 100644 disas/riscv-xthead.c
169
create mode 100644 disas/riscv-xventana.c
170
create mode 100644 hw/misc/sifive_e_aon.c
171
create mode 100644 tests/qtest/sifive-e-aon-watchdog-test.c
172
create mode 100644 tests/tcg/riscv64/test-fcvtmod.c
173
create mode 100644 target/riscv/insn_trans/trans_rvbf16.c.inc
174
create mode 100644 target/riscv/insn_trans/trans_rvzfa.c.inc
175
131
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: "yang.zhang" <yang.zhang@hexintek.com>
2
2
3
Using all TCG user properties in KVM is tricky. First because KVM
3
Since only root APLICs can have hw IRQ lines, aplic->parent should
4
supports only a small subset of what TCG provides, so most of the
4
be initialized first.
5
cpu->cfg flags do nothing for KVM.
6
5
7
Second, and more important, we don't have a way of telling if any given
6
Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation")
8
value is an user input or not. For TCG this has a small impact since we
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
just validating everything and error out if needed. But for KVM it would
8
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
10
be good to know if a given value was set by the user or if it's a value
9
Cc: qemu-stable <qemu-stable@nongnu.org>
11
already provided by KVM. Otherwise we don't know how to handle failed
10
Message-ID: <20240409014445.278-1-gaoshanliukou@163.com>
12
kvm_set_one_regs() when writing the configurations back.
13
14
These characteristics make it overly complicated to use the same user
15
facing flags for both KVM and TCG. A simpler approach is to create KVM
16
specific properties that have specialized logic, forking KVM and TCG use
17
cases for those cases only. Fully separating KVM/TCG properties is
18
unneeded at this point - in fact we want the user experience to be as
19
equal as possible, regardless of the acceleration chosen.
20
21
We'll start this fork with the MISA properties, adding the MISA bits
22
that the KVM driver currently supports. A new KVMCPUConfig type is
23
introduced. It'll hold general information about an extension. For MISA
24
extensions we're going to use the newly created getters of
25
misa_ext_infos[] to populate their name and description. 'offset' holds
26
the MISA bit (RVA, RVC, ...). We're calling it 'offset' instead of
27
'misa_bit' because this same KVMCPUConfig struct will be used to
28
multi-letter extensions later on.
29
30
This new type also holds a 'user_set' flag. This flag will be set when
31
the user set an option that's different than what is already configured
32
in the host, requiring KVM intervention to write the regs back during
33
kvm_arch_init_vcpu(). Similar mechanics will be implemented for
34
multi-letter extensions as well.
35
36
There is no need to duplicate more code than necessary, so we're going
37
to use the existing kvm_riscv_init_user_properties() to add the KVM
38
specific properties. Any code that is adding a TCG user prop is then
39
changed slightly to verify first if there's a KVM prop with the same
40
name already added.
41
42
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
43
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
44
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
45
Message-Id: <20230706101738.460804-13-dbarboza@ventanamicro.com>
46
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
47
---
12
---
48
target/riscv/cpu.c | 5 +++
13
hw/intc/riscv_aplic.c | 8 ++++----
49
target/riscv/kvm.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
14
1 file changed, 4 insertions(+), 4 deletions(-)
50
2 files changed, 83 insertions(+)
51
15
52
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
53
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
54
--- a/target/riscv/cpu.c
18
--- a/hw/intc/riscv_aplic.c
55
+++ b/target/riscv/cpu.c
19
+++ b/hw/intc/riscv_aplic.c
56
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
20
@@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
57
misa_cfg->name = riscv_get_misa_ext_name(bit);
21
qdev_prop_set_bit(dev, "msimode", msimode);
58
misa_cfg->description = riscv_get_misa_ext_description(bit);
22
qdev_prop_set_bit(dev, "mmode", mmode);
59
23
60
+ /* Check if KVM already created the property */
24
+ if (parent) {
61
+ if (object_property_find(cpu_obj, misa_cfg->name)) {
25
+ riscv_aplic_add_child(parent, dev);
62
+ continue;
63
+ }
64
+
65
object_property_add(cpu_obj, misa_cfg->name, "bool",
66
cpu_get_misa_ext_cfg,
67
cpu_set_misa_ext_cfg,
68
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
69
index XXXXXXX..XXXXXXX 100644
70
--- a/target/riscv/kvm.c
71
+++ b/target/riscv/kvm.c
72
@@ -XXX,XX +XXX,XX @@
73
#include <linux/kvm.h>
74
75
#include "qemu/timer.h"
76
+#include "qapi/error.h"
77
#include "qemu/error-report.h"
78
#include "qemu/main-loop.h"
79
+#include "qapi/visitor.h"
80
#include "sysemu/sysemu.h"
81
#include "sysemu/kvm.h"
82
#include "sysemu/kvm_int.h"
83
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
84
} \
85
} while (0)
86
87
+typedef struct KVMCPUConfig {
88
+ const char *name;
89
+ const char *description;
90
+ target_ulong offset;
91
+ int kvm_reg_id;
92
+ bool user_set;
93
+} KVMCPUConfig;
94
+
95
+#define KVM_MISA_CFG(_bit, _reg_id) \
96
+ {.offset = _bit, .kvm_reg_id = _reg_id}
97
+
98
+/* KVM ISA extensions */
99
+static KVMCPUConfig kvm_misa_ext_cfgs[] = {
100
+ KVM_MISA_CFG(RVA, KVM_RISCV_ISA_EXT_A),
101
+ KVM_MISA_CFG(RVC, KVM_RISCV_ISA_EXT_C),
102
+ KVM_MISA_CFG(RVD, KVM_RISCV_ISA_EXT_D),
103
+ KVM_MISA_CFG(RVF, KVM_RISCV_ISA_EXT_F),
104
+ KVM_MISA_CFG(RVH, KVM_RISCV_ISA_EXT_H),
105
+ KVM_MISA_CFG(RVI, KVM_RISCV_ISA_EXT_I),
106
+ KVM_MISA_CFG(RVM, KVM_RISCV_ISA_EXT_M),
107
+};
108
+
109
+static void kvm_cpu_set_misa_ext_cfg(Object *obj, Visitor *v,
110
+ const char *name,
111
+ void *opaque, Error **errp)
112
+{
113
+ KVMCPUConfig *misa_ext_cfg = opaque;
114
+ target_ulong misa_bit = misa_ext_cfg->offset;
115
+ RISCVCPU *cpu = RISCV_CPU(obj);
116
+ CPURISCVState *env = &cpu->env;
117
+ bool value, host_bit;
118
+
119
+ if (!visit_type_bool(v, name, &value, errp)) {
120
+ return;
121
+ }
26
+ }
122
+
27
+
123
+ host_bit = env->misa_ext_mask & misa_bit;
28
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
124
+
29
125
+ if (value == host_bit) {
30
if (!is_kvm_aia(msimode)) {
126
+ return;
31
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
127
+ }
128
+
129
+ if (!value) {
130
+ misa_ext_cfg->user_set = true;
131
+ return;
132
+ }
133
+
134
+ /*
135
+ * Forbid users to enable extensions that aren't
136
+ * available in the hart.
137
+ */
138
+ error_setg(errp, "Enabling MISA bit '%s' is not allowed: it's not "
139
+ "enabled in the host", misa_ext_cfg->name);
140
+}
141
+
142
+static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
143
+{
144
+ int i;
145
+
146
+ for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) {
147
+ KVMCPUConfig *misa_cfg = &kvm_misa_ext_cfgs[i];
148
+ int bit = misa_cfg->offset;
149
+
150
+ misa_cfg->name = riscv_get_misa_ext_name(bit);
151
+ misa_cfg->description = riscv_get_misa_ext_description(bit);
152
+
153
+ object_property_add(cpu_obj, misa_cfg->name, "bool",
154
+ NULL,
155
+ kvm_cpu_set_misa_ext_cfg,
156
+ NULL, misa_cfg);
157
+ object_property_set_description(cpu_obj, misa_cfg->name,
158
+ misa_cfg->description);
159
+ }
160
+}
161
+
162
static int kvm_riscv_get_regs_core(CPUState *cs)
163
{
164
int ret = 0;
165
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_init_user_properties(Object *cpu_obj)
166
return;
167
}
32
}
168
33
169
+ kvm_riscv_add_cpu_user_properties(cpu_obj);
34
- if (parent) {
170
kvm_riscv_init_machine_ids(cpu, &kvmcpu);
35
- riscv_aplic_add_child(parent, dev);
171
kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu);
36
- }
172
37
-
38
if (!msimode) {
39
for (i = 0; i < num_harts; i++) {
40
CPUState *cpu = cpu_by_arch_id(hartid_base + i);
173
--
41
--
174
2.40.1
42
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Andrew Jones <ajones@ventanamicro.com>
2
2
3
Next patch will add KVM specific user properties for both MISA and
3
The Zkr extension may only be exposed to KVM guests if the VMM
4
multi-letter extensions. For MISA extensions we want to make use of what
4
implements the SEED CSR. Use the same implementation as TCG.
5
is already available in misa_ext_cfgs[] to avoid code repetition.
6
5
7
misa_ext_info_arr[] array will hold name and description for each MISA
6
Without this patch, running with a KVM which does not forward the
8
extension that misa_ext_cfgs[] is declaring. We'll then use this new
7
SEED CSR access to QEMU will result in an ILL exception being
9
array in KVM code to avoid duplicating strings. Two getters were added
8
injected into the guest (this results in Linux guests crashing on
10
to allow KVM to retrieve the 'name' and 'description' for each MISA
9
boot). And, when running with a KVM which does forward the access,
11
property.
10
QEMU will crash, since QEMU doesn't know what to do with the exit.
12
11
13
There's nothing holding us back from doing the same with multi-letter
12
Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8")
14
extensions. For now doing just with MISA extensions is enough.
13
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
15
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
It is worth documenting that even using the __bultin_ctz() directive to
15
Cc: qemu-stable <qemu-stable@nongnu.org>
17
populate the misa_ext_info_arr[] we are forced to assign 'name' and
16
Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com>
18
'description' during runtime in riscv_cpu_add_misa_properties(). The
19
reason is that some Gitlab runners ('clang-user' and 'tsan-build') will
20
throw errors like this if we fetch 'name' and 'description' from the
21
array in the MISA_CFG() macro:
22
23
../target/riscv/cpu.c:1624:5: error: initializer element is not a
24
compile-time constant
25
MISA_CFG(RVA, true),
26
^~~~~~~~~~~~~~~~~~~
27
../target/riscv/cpu.c:1619:53: note: expanded from macro 'MISA_CFG'
28
{.name = misa_ext_info_arr[MISA_INFO_IDX(_bit)].name, \
29
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
30
31
gcc and others compilers/builders were fine with that change. We can't
32
ignore failures in the Gitlab pipeline though, so code was changed to
33
make every runner happy.
34
35
As a side effect, misa_ext_cfg[] is no longer a 'const' array because
36
it must be set during runtime.
37
38
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
39
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
40
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
41
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
42
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
43
Message-Id: <20230706101738.460804-12-dbarboza@ventanamicro.com>
44
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
45
---
18
---
46
target/riscv/cpu.h | 7 ++-
19
target/riscv/cpu.h | 3 +++
47
target/riscv/cpu.c | 110 +++++++++++++++++++++++++++++++++------------
20
target/riscv/csr.c | 18 ++++++++++++++----
48
2 files changed, 88 insertions(+), 29 deletions(-)
21
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++
22
3 files changed, 42 insertions(+), 4 deletions(-)
49
23
50
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
51
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
52
--- a/target/riscv/cpu.h
26
--- a/target/riscv/cpu.h
53
+++ b/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
54
@@ -XXX,XX +XXX,XX @@
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
55
29
56
#define RV(x) ((target_ulong)1 << (x - 'A'))
30
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
57
31
58
-/* Consider updating misa_ext_cfgs[] when adding new MISA bits here */
32
+target_ulong riscv_new_csr_seed(target_ulong new_value,
59
+/*
33
+ target_ulong write_mask);
60
+ * Consider updating misa_ext_info_arr[] and misa_ext_cfgs[]
34
+
61
+ * when adding new MISA bits here.
35
uint8_t satp_mode_max_from_map(uint32_t map);
62
+ */
36
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
63
#define RVI RV('I')
37
64
#define RVE RV('E') /* E and I are mutually exclusive */
38
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
65
#define RVM RV('M')
66
@@ -XXX,XX +XXX,XX @@
67
#define RVJ RV('J')
68
#define RVG RV('G')
69
70
+const char *riscv_get_misa_ext_name(uint32_t bit);
71
+const char *riscv_get_misa_ext_description(uint32_t bit);
72
73
/* Privileged specification version */
74
enum {
75
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
76
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
77
--- a/target/riscv/cpu.c
40
--- a/target/riscv/csr.c
78
+++ b/target/riscv/cpu.c
41
+++ b/target/riscv/csr.c
79
@@ -XXX,XX +XXX,XX @@ static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
42
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
80
visit_type_bool(v, name, &value, errp);
43
#endif
81
}
44
82
45
/* Crypto Extension */
83
-static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
46
-static RISCVException rmw_seed(CPURISCVState *env, int csrno,
84
- {.name = "a", .description = "Atomic instructions",
47
- target_ulong *ret_value,
85
- .misa_bit = RVA, .enabled = true},
48
- target_ulong new_value,
86
- {.name = "c", .description = "Compressed instructions",
49
- target_ulong write_mask)
87
- .misa_bit = RVC, .enabled = true},
50
+target_ulong riscv_new_csr_seed(target_ulong new_value,
88
- {.name = "d", .description = "Double-precision float point",
51
+ target_ulong write_mask)
89
- .misa_bit = RVD, .enabled = true},
52
{
90
- {.name = "f", .description = "Single-precision float point",
53
uint16_t random_v;
91
- .misa_bit = RVF, .enabled = true},
54
Error *random_e = NULL;
92
- {.name = "i", .description = "Base integer instruction set",
55
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
93
- .misa_bit = RVI, .enabled = true},
56
rval = random_v | SEED_OPST_ES16;
94
- {.name = "e", .description = "Base integer instruction set (embedded)",
57
}
95
- .misa_bit = RVE, .enabled = false},
58
96
- {.name = "m", .description = "Integer multiplication and division",
59
+ return rval;
97
- .misa_bit = RVM, .enabled = true},
98
- {.name = "s", .description = "Supervisor-level instructions",
99
- .misa_bit = RVS, .enabled = true},
100
- {.name = "u", .description = "User-level instructions",
101
- .misa_bit = RVU, .enabled = true},
102
- {.name = "h", .description = "Hypervisor",
103
- .misa_bit = RVH, .enabled = true},
104
- {.name = "x-j", .description = "Dynamic translated languages",
105
- .misa_bit = RVJ, .enabled = false},
106
- {.name = "v", .description = "Vector operations",
107
- .misa_bit = RVV, .enabled = false},
108
- {.name = "g", .description = "General purpose (IMAFD_Zicsr_Zifencei)",
109
- .misa_bit = RVG, .enabled = false},
110
+typedef struct misa_ext_info {
111
+ const char *name;
112
+ const char *description;
113
+} MISAExtInfo;
114
+
115
+#define MISA_INFO_IDX(_bit) \
116
+ __builtin_ctz(_bit)
117
+
118
+#define MISA_EXT_INFO(_bit, _propname, _descr) \
119
+ [MISA_INFO_IDX(_bit)] = {.name = _propname, .description = _descr}
120
+
121
+static const MISAExtInfo misa_ext_info_arr[] = {
122
+ MISA_EXT_INFO(RVA, "a", "Atomic instructions"),
123
+ MISA_EXT_INFO(RVC, "c", "Compressed instructions"),
124
+ MISA_EXT_INFO(RVD, "d", "Double-precision float point"),
125
+ MISA_EXT_INFO(RVF, "f", "Single-precision float point"),
126
+ MISA_EXT_INFO(RVI, "i", "Base integer instruction set"),
127
+ MISA_EXT_INFO(RVE, "e", "Base integer instruction set (embedded)"),
128
+ MISA_EXT_INFO(RVM, "m", "Integer multiplication and division"),
129
+ MISA_EXT_INFO(RVS, "s", "Supervisor-level instructions"),
130
+ MISA_EXT_INFO(RVU, "u", "User-level instructions"),
131
+ MISA_EXT_INFO(RVH, "h", "Hypervisor"),
132
+ MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
133
+ MISA_EXT_INFO(RVV, "v", "Vector operations"),
134
+ MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
135
+};
136
+
137
+static int riscv_validate_misa_info_idx(uint32_t bit)
138
+{
139
+ int idx;
140
+
141
+ /*
142
+ * Our lowest valid input (RVA) is 1 and
143
+ * __builtin_ctz() is UB with zero.
144
+ */
145
+ g_assert(bit != 0);
146
+ idx = MISA_INFO_IDX(bit);
147
+
148
+ g_assert(idx < ARRAY_SIZE(misa_ext_info_arr));
149
+ return idx;
150
+}
60
+}
151
+
61
+
152
+const char *riscv_get_misa_ext_name(uint32_t bit)
62
+static RISCVException rmw_seed(CPURISCVState *env, int csrno,
63
+ target_ulong *ret_value,
64
+ target_ulong new_value,
65
+ target_ulong write_mask)
153
+{
66
+{
154
+ int idx = riscv_validate_misa_info_idx(bit);
67
+ target_ulong rval;
155
+ const char *val = misa_ext_info_arr[idx].name;
156
+
68
+
157
+ g_assert(val != NULL);
69
+ rval = riscv_new_csr_seed(new_value, write_mask);
158
+ return val;
70
+
71
if (ret_value) {
72
*ret_value = rval;
73
}
74
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
75
index XXXXXXX..XXXXXXX 100644
76
--- a/target/riscv/kvm/kvm-cpu.c
77
+++ b/target/riscv/kvm/kvm-cpu.c
78
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
79
return ret;
80
}
81
82
+static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run)
83
+{
84
+ target_ulong csr_num = run->riscv_csr.csr_num;
85
+ target_ulong new_value = run->riscv_csr.new_value;
86
+ target_ulong write_mask = run->riscv_csr.write_mask;
87
+ int ret = 0;
88
+
89
+ switch (csr_num) {
90
+ case CSR_SEED:
91
+ run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask);
92
+ break;
93
+ default:
94
+ qemu_log_mask(LOG_UNIMP,
95
+ "%s: un-handled CSR EXIT for CSR %lx\n",
96
+ __func__, csr_num);
97
+ ret = -1;
98
+ break;
99
+ }
100
+
101
+ return ret;
159
+}
102
+}
160
+
103
+
161
+const char *riscv_get_misa_ext_description(uint32_t bit)
104
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
162
+{
105
{
163
+ int idx = riscv_validate_misa_info_idx(bit);
106
int ret = 0;
164
+ const char *val = misa_ext_info_arr[idx].description;
107
@@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
165
+
108
case KVM_EXIT_RISCV_SBI:
166
+ g_assert(val != NULL);
109
ret = kvm_riscv_handle_sbi(cs, run);
167
+ return val;
110
break;
168
+}
111
+ case KVM_EXIT_RISCV_CSR:
169
+
112
+ ret = kvm_riscv_handle_csr(cs, run);
170
+#define MISA_CFG(_bit, _enabled) \
113
+ break;
171
+ {.misa_bit = _bit, .enabled = _enabled}
114
default:
172
+
115
qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
173
+static RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
116
__func__, run->exit_reason);
174
+ MISA_CFG(RVA, true),
175
+ MISA_CFG(RVC, true),
176
+ MISA_CFG(RVD, true),
177
+ MISA_CFG(RVF, true),
178
+ MISA_CFG(RVI, true),
179
+ MISA_CFG(RVE, false),
180
+ MISA_CFG(RVM, true),
181
+ MISA_CFG(RVS, true),
182
+ MISA_CFG(RVU, true),
183
+ MISA_CFG(RVH, true),
184
+ MISA_CFG(RVJ, false),
185
+ MISA_CFG(RVV, false),
186
+ MISA_CFG(RVG, false),
187
};
188
189
static void riscv_cpu_add_misa_properties(Object *cpu_obj)
190
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
191
int i;
192
193
for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) {
194
- const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i];
195
+ RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i];
196
+ int bit = misa_cfg->misa_bit;
197
+
198
+ misa_cfg->name = riscv_get_misa_ext_name(bit);
199
+ misa_cfg->description = riscv_get_misa_ext_description(bit);
200
201
object_property_add(cpu_obj, misa_cfg->name, "bool",
202
cpu_get_misa_ext_cfg,
203
--
117
--
204
2.40.1
118
2.45.1
205
206
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Andrew Jones <ajones@ventanamicro.com>
2
2
3
Add trans_* and helper function for Zvfbfwma instructions.
3
Implementing wrs.nto to always just return is consistent with the
4
specification, as the instruction is permitted to terminate the
5
stall for any reason, but it's not useful for virtualization, where
6
we'd like the guest to trap to the hypervisor in order to allow
7
scheduling of the lock holding VCPU. Change to always immediately
8
raise exceptions when the appropriate conditions are present,
9
otherwise continue to just return. Note, immediately raising
10
exceptions is also consistent with the specification since the
11
time limit that should expire prior to the exception is
12
implementation-specific.
4
13
5
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
14
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
6
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
15
Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Message-Id: <20230615063302.102409-5-liweiwei@iscas.ac.cn>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
20
---
11
target/riscv/helper.h | 3 ++
21
target/riscv/helper.h | 1 +
12
target/riscv/insn32.decode | 4 ++
22
target/riscv/op_helper.c | 11 ++++++++
13
target/riscv/vector_helper.c | 11 ++++
23
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++-------
14
target/riscv/insn_trans/trans_rvbf16.c.inc | 58 ++++++++++++++++++++++
24
3 files changed, 32 insertions(+), 9 deletions(-)
15
4 files changed, 76 insertions(+)
16
25
17
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
26
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
18
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/helper.h
28
--- a/target/riscv/helper.h
20
+++ b/target/riscv/helper.h
29
+++ b/target/riscv/helper.h
21
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_s_bf16, TCG_CALL_NO_RWG, i64, env, i64)
30
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
22
31
DEF_HELPER_1(sret, tl, env)
23
DEF_HELPER_5(vfncvtbf16_f_f_w, void, ptr, ptr, ptr, env, i32)
32
DEF_HELPER_1(mret, tl, env)
24
DEF_HELPER_5(vfwcvtbf16_f_f_v, void, ptr, ptr, ptr, env, i32)
33
DEF_HELPER_1(wfi, void, env)
25
+
34
+DEF_HELPER_1(wrs_nto, void, env)
26
+DEF_HELPER_6(vfwmaccbf16_vv, void, ptr, ptr, ptr, ptr, env, i32)
35
DEF_HELPER_1(tlb_flush, void, env)
27
+DEF_HELPER_6(vfwmaccbf16_vf, void, ptr, ptr, i64, ptr, env, i32)
36
DEF_HELPER_1(tlb_flush_all, void, env)
28
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
37
/* Native Debug */
38
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
29
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/insn32.decode
40
--- a/target/riscv/op_helper.c
31
+++ b/target/riscv/insn32.decode
41
+++ b/target/riscv/op_helper.c
32
@@ -XXX,XX +XXX,XX @@ fcvt_s_bf16 0100000 00110 ..... ... ..... 1010011 @r2_rm
42
@@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env)
33
# *** Zvfbfmin Standard Extension ***
43
}
34
vfncvtbf16_f_f_w 010010 . ..... 11101 001 ..... 1010111 @r2_vm
44
}
35
vfwcvtbf16_f_f_v 010010 . ..... 01101 001 ..... 1010111 @r2_vm
45
36
+
46
+void helper_wrs_nto(CPURISCVState *env)
37
+# *** Zvfbfwma Standard Extension ***
38
+vfwmaccbf16_vv 111011 . ..... ..... 001 ..... 1010111 @r_vm
39
+vfwmaccbf16_vf 111011 . ..... ..... 101 ..... 1010111 @r_vm
40
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/vector_helper.c
43
+++ b/target/riscv/vector_helper.c
44
@@ -XXX,XX +XXX,XX @@ RVVCALL(OPFVF3, vfwmacc_vf_w, WOP_UUU_W, H8, H4, fwmacc32)
45
GEN_VEXT_VF(vfwmacc_vf_h, 4)
46
GEN_VEXT_VF(vfwmacc_vf_w, 8)
47
48
+static uint32_t fwmaccbf16(uint16_t a, uint16_t b, uint32_t d, float_status *s)
49
+{
47
+{
50
+ return float32_muladd(bfloat16_to_float32(a, s),
48
+ if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) &&
51
+ bfloat16_to_float32(b, s), d, 0, s);
49
+ get_field(env->hstatus, HSTATUS_VTW) &&
50
+ !get_field(env->mstatus, MSTATUS_TW)) {
51
+ riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC());
52
+ } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) {
53
+ riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
54
+ }
52
+}
55
+}
53
+
56
+
54
+RVVCALL(OPFVV3, vfwmaccbf16_vv, WOP_UUU_H, H4, H2, H2, fwmaccbf16)
57
void helper_tlb_flush(CPURISCVState *env)
55
+GEN_VEXT_VV_ENV(vfwmaccbf16_vv, 4)
58
{
56
+RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmacc16)
59
CPUState *cs = env_cpu(env);
57
+GEN_VEXT_VF(vfwmaccbf16_vf, 4)
60
diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc
61
index XXXXXXX..XXXXXXX 100644
62
--- a/target/riscv/insn_trans/trans_rvzawrs.c.inc
63
+++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc
64
@@ -XXX,XX +XXX,XX @@
65
* this program. If not, see <http://www.gnu.org/licenses/>.
66
*/
67
68
-static bool trans_wrs(DisasContext *ctx)
69
+static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a)
70
{
71
if (!ctx->cfg_ptr->ext_zawrs) {
72
return false;
73
@@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx)
74
return true;
75
}
76
77
-#define GEN_TRANS_WRS(insn) \
78
-static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \
79
-{ \
80
- (void)a; \
81
- return trans_wrs(ctx); \
82
-}
83
+static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a)
84
+{
85
+ if (!ctx->cfg_ptr->ext_zawrs) {
86
+ return false;
87
+ }
88
89
-GEN_TRANS_WRS(wrs_nto)
90
-GEN_TRANS_WRS(wrs_sto)
91
+ /*
92
+ * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto
93
+ * should raise an exception when the implementation-specific bounded time
94
+ * limit has expired. Our time limit is zero, so we either return
95
+ * immediately, as does our implementation of wrs.sto, or raise an
96
+ * exception, as handled by the wrs.nto helper.
97
+ */
98
+#ifndef CONFIG_USER_ONLY
99
+ gen_helper_wrs_nto(tcg_env);
100
+#endif
58
+
101
+
59
static uint32_t fwnmacc16(uint16_t a, uint16_t b, uint32_t d, float_status *s)
102
+ /* We only get here when helper_wrs_nto() doesn't raise an exception. */
60
{
103
+ return trans_wrs_sto(ctx, NULL);
61
return float32_muladd(float16_to_float32(a, true, s),
62
diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
63
index XXXXXXX..XXXXXXX 100644
64
--- a/target/riscv/insn_trans/trans_rvbf16.c.inc
65
+++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
66
@@ -XXX,XX +XXX,XX @@
67
} \
68
} while (0)
69
70
+#define REQUIRE_ZVFBFWMA(ctx) do { \
71
+ if (!ctx->cfg_ptr->ext_zvfbfwma) { \
72
+ return false; \
73
+ } \
74
+} while (0)
75
+
76
static bool trans_fcvt_bf16_s(DisasContext *ctx, arg_fcvt_bf16_s *a)
77
{
78
REQUIRE_FPU;
79
@@ -XXX,XX +XXX,XX @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
80
}
81
return false;
82
}
83
+
84
+static bool trans_vfwmaccbf16_vv(DisasContext *ctx, arg_vfwmaccbf16_vv *a)
85
+{
86
+ REQUIRE_FPU;
87
+ REQUIRE_ZVFBFWMA(ctx);
88
+
89
+ if (require_rvv(ctx) && vext_check_isa_ill(ctx) && (ctx->sew == MO_16) &&
90
+ vext_check_dss(ctx, a->rd, a->rs1, a->rs2, a->vm)) {
91
+ uint32_t data = 0;
92
+ TCGLabel *over = gen_new_label();
93
+
94
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
95
+ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over);
96
+ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);
97
+
98
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
99
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
100
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
101
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
102
+ tcg_gen_gvec_4_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
103
+ vreg_ofs(ctx, a->rs1),
104
+ vreg_ofs(ctx, a->rs2), cpu_env,
105
+ ctx->cfg_ptr->vlen / 8,
106
+ ctx->cfg_ptr->vlen / 8, data,
107
+ gen_helper_vfwmaccbf16_vv);
108
+ mark_vs_dirty(ctx);
109
+ gen_set_label(over);
110
+ return true;
111
+ }
112
+ return false;
113
+}
114
+
115
+static bool trans_vfwmaccbf16_vf(DisasContext *ctx, arg_vfwmaccbf16_vf *a)
116
+{
117
+ REQUIRE_FPU;
118
+ REQUIRE_ZVFBFWMA(ctx);
119
+
120
+ if (require_rvv(ctx) && (ctx->sew == MO_16) && vext_check_isa_ill(ctx) &&
121
+ vext_check_ds(ctx, a->rd, a->rs2, a->vm)) {
122
+ uint32_t data = 0;
123
+
124
+ gen_set_rm(ctx, RISCV_FRM_DYN);
125
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
126
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
127
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
128
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
129
+ return opfvf_trans(a->rd, a->rs1, a->rs2, data,
130
+ gen_helper_vfwmaccbf16_vf, ctx);
131
+ }
132
+
133
+ return false;
134
+}
104
+}
135
--
105
--
136
2.40.1
106
2.45.1
107
108
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Our design philosophy with KVM properties can be resumed in two main
3
SBI defines a Debug Console extension "DBCN" that will, in time, replace
4
decisions based on KVM interface availability and what the user wants to
4
the legacy console putchar and getchar SBI extensions.
5
do:
5
6
6
The appeal of the DBCN extension is that it allows multiple bytes to be
7
- if the user disables an extension that the host KVM module doesn't
7
read/written in the SBI console in a single SBI call.
8
know about (i.e. it doesn't implement the kvm_get_one_reg() interface),
8
9
keep booting the CPU. This will avoid users having to deal with issues
9
As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM
10
with older KVM versions while disabling features they don't care;
10
module to userspace. But this will only happens if the KVM module
11
11
actually supports this SBI extension and we activate it.
12
- for any other case we're going to error out immediately. If the user
12
13
wants to enable a feature that KVM doesn't know about this a problem that
13
We'll check for DBCN support during init time, checking if get-reg-list
14
is worth aborting - the user must know that the feature wasn't enabled
14
is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via
15
in the hart. Likewise, if KVM knows about the extension, the user wants
15
kvm_set_one_reg() during kvm_arch_init_vcpu().
16
to enable/disable it, and we fail to do it so, that's also a problem we
16
17
can't shrug it off.
17
Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for
18
18
SBI_EXT_DBCN, reading and writing as required.
19
In the case of MISA bits we won't even try enabling bits that aren't
19
20
already available in the host. The ioctl() is so likely to fail that
20
A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V
21
it's not worth trying. This check is already done in the previous patch,
21
host, takes around 20 seconds to boot without using DBCN. With this
22
in kvm_cpu_set_misa_ext_cfg(), thus we don't need to worry about it now.
22
patch we're taking around 14 seconds to boot due to the speed-up in the
23
23
terminal output. There's no change in boot time if the guest isn't
24
In kvm_riscv_update_cpu_misa_ext() we'll go through every potential user
24
using earlycon.
25
option and do as follows:
26
27
- if the user didn't set the property or set to the same value of the
28
host, do nothing;
29
30
- Disable the given extension in KVM. Error out if anything goes wrong.
31
25
32
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
33
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
34
Acked-by: Alistair Francis <alistair.francis@wdc.com>
28
Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com>
35
Message-Id: <20230706101738.460804-14-dbarboza@ventanamicro.com>
36
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
37
---
30
---
38
target/riscv/kvm.c | 40 ++++++++++++++++++++++++++++++++++++++++
31
target/riscv/sbi_ecall_interface.h | 17 +++++
39
1 file changed, 40 insertions(+)
32
target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++
40
33
2 files changed, 128 insertions(+)
41
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
34
35
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
42
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
43
--- a/target/riscv/kvm.c
37
--- a/target/riscv/sbi_ecall_interface.h
44
+++ b/target/riscv/kvm.c
38
+++ b/target/riscv/sbi_ecall_interface.h
45
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_set_misa_ext_cfg(Object *obj, Visitor *v,
39
@@ -XXX,XX +XXX,XX @@
46
"enabled in the host", misa_ext_cfg->name);
40
47
}
41
/* clang-format off */
48
42
49
+static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs)
43
+#define SBI_SUCCESS 0
44
+#define SBI_ERR_FAILED -1
45
+#define SBI_ERR_NOT_SUPPORTED -2
46
+#define SBI_ERR_INVALID_PARAM -3
47
+#define SBI_ERR_DENIED -4
48
+#define SBI_ERR_INVALID_ADDRESS -5
49
+#define SBI_ERR_ALREADY_AVAILABLE -6
50
+#define SBI_ERR_ALREADY_STARTED -7
51
+#define SBI_ERR_ALREADY_STOPPED -8
52
+#define SBI_ERR_NO_SHMEM -9
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;
96
}
97
98
+static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu,
99
+ KVMScratchCPU *kvmcpu,
100
+ struct kvm_reg_list *reglist)
50
+{
101
+{
51
+ CPURISCVState *env = &cpu->env;
102
+ struct kvm_reg_list *reg_search;
52
+ uint64_t id, reg;
103
+
53
+ int i, ret;
104
+ reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n,
54
+
105
+ sizeof(uint64_t), uint64_cmp);
55
+ for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) {
106
+
56
+ KVMCPUConfig *misa_cfg = &kvm_misa_ext_cfgs[i];
107
+ if (reg_search) {
57
+ target_ulong misa_bit = misa_cfg->offset;
108
+ kvm_sbi_dbcn.supported = true;
58
+
59
+ if (!misa_cfg->user_set) {
60
+ continue;
61
+ }
62
+
63
+ /* If we're here we're going to disable the MISA bit */
64
+ reg = 0;
65
+ id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
66
+ misa_cfg->kvm_reg_id);
67
+ ret = kvm_set_one_reg(cs, id, &reg);
68
+ if (ret != 0) {
69
+ /*
70
+ * We're not checking for -EINVAL because if the bit is about
71
+ * to be disabled, it means that it was already enabled by
72
+ * KVM. We determined that by fetching the 'isa' register
73
+ * during init() time. Any error at this point is worth
74
+ * aborting.
75
+ */
76
+ error_report("Unable to set KVM reg %s, error %d",
77
+ misa_cfg->name, ret);
78
+ exit(EXIT_FAILURE);
79
+ }
80
+ env->misa_ext &= ~misa_bit;
81
+ }
109
+ }
82
+}
110
+}
83
+
111
+
84
static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
112
static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
85
{
113
struct kvm_reg_list *reglist)
86
int i;
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;
87
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
142
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
88
143
kvm_riscv_update_cpu_misa_ext(cpu, cs);
89
if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) {
144
kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs);
90
ret = kvm_vcpu_set_machine_ids(cpu, cs);
145
91
+ if (ret != 0) {
146
+ ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs);
92
+ return ret;
93
+ }
94
}
95
96
+ kvm_riscv_update_cpu_misa_ext(cpu, cs);
97
+
147
+
98
return ret;
148
return ret;
99
}
149
}
100
150
151
@@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
152
return true;
153
}
154
155
+static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run)
156
+{
157
+ g_autofree uint8_t *buf = NULL;
158
+ RISCVCPU *cpu = RISCV_CPU(cs);
159
+ target_ulong num_bytes;
160
+ uint64_t addr;
161
+ unsigned char ch;
162
+ int ret;
163
+
164
+ switch (run->riscv_sbi.function_id) {
165
+ case SBI_EXT_DBCN_CONSOLE_READ:
166
+ case SBI_EXT_DBCN_CONSOLE_WRITE:
167
+ num_bytes = run->riscv_sbi.args[0];
168
+
169
+ if (num_bytes == 0) {
170
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
171
+ run->riscv_sbi.ret[1] = 0;
172
+ break;
173
+ }
174
+
175
+ addr = run->riscv_sbi.args[1];
176
+
177
+ /*
178
+ * Handle the case where a 32 bit CPU is running in a
179
+ * 64 bit addressing env.
180
+ */
181
+ if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) {
182
+ addr |= (uint64_t)run->riscv_sbi.args[2] << 32;
183
+ }
184
+
185
+ buf = g_malloc0(num_bytes);
186
+
187
+ if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) {
188
+ ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes);
189
+ if (ret < 0) {
190
+ error_report("SBI_EXT_DBCN_CONSOLE_READ: error when "
191
+ "reading chardev");
192
+ exit(1);
193
+ }
194
+
195
+ cpu_physical_memory_write(addr, buf, ret);
196
+ } else {
197
+ cpu_physical_memory_read(addr, buf, num_bytes);
198
+
199
+ ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes);
200
+ if (ret < 0) {
201
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when "
202
+ "writing chardev");
203
+ exit(1);
204
+ }
205
+ }
206
+
207
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
208
+ run->riscv_sbi.ret[1] = ret;
209
+ break;
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",
101
--
241
--
102
2.40.1
242
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Cheng Yang <yangcheng.work@foxmail.com>
2
2
3
At this moment we're retrieving env->misa_ext during
3
Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell()
4
kvm_arch_init_cpu(), leaving env->misa_ext_mask behind.
4
to set the address of initrd in FDT to support 64-bit address.
5
5
6
We want to set env->misa_ext_mask, and we want to set it as early as
6
Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
7
possible. The reason is that we're going to use it in the validation
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
process of the KVM MISA properties we're going to add next. Setting it
8
Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com>
9
during arch_init_cpu() is too late for user validation.
10
11
Move the code to a new helper that is going to be called during init()
12
time, via kvm_riscv_init_user_properties(), like we're already doing for
13
the machine ID properties. Set both misa_ext and misa_ext_mask to the
14
same value retrieved by the 'isa' config reg.
15
16
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
17
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
18
Acked-by: Alistair Francis <alistair.francis@wdc.com>
19
Message-Id: <20230706101738.460804-11-dbarboza@ventanamicro.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
21
---
10
---
22
target/riscv/kvm.c | 34 +++++++++++++++++++++++-----------
11
hw/riscv/boot.c | 4 ++--
23
1 file changed, 23 insertions(+), 11 deletions(-)
12
1 file changed, 2 insertions(+), 2 deletions(-)
24
13
25
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
14
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
26
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
27
--- a/target/riscv/kvm.c
16
--- a/hw/riscv/boot.c
28
+++ b/target/riscv/kvm.c
17
+++ b/hw/riscv/boot.c
29
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
18
@@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
19
/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
20
if (fdt) {
21
end = start + size;
22
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start);
23
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end);
24
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start);
25
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end);
30
}
26
}
31
}
27
}
32
28
33
+static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu,
34
+ KVMScratchCPU *kvmcpu)
35
+{
36
+ CPURISCVState *env = &cpu->env;
37
+ struct kvm_one_reg reg;
38
+ int ret;
39
+
40
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
41
+ KVM_REG_RISCV_CONFIG_REG(isa));
42
+ reg.addr = (uint64_t)&env->misa_ext_mask;
43
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
44
+
45
+ if (ret) {
46
+ error_report("Unable to fetch ISA register from KVM, "
47
+ "error %d", ret);
48
+ kvm_riscv_destroy_scratch_vcpu(kvmcpu);
49
+ exit(EXIT_FAILURE);
50
+ }
51
+
52
+ env->misa_ext = env->misa_ext_mask;
53
+}
54
+
55
void kvm_riscv_init_user_properties(Object *cpu_obj)
56
{
57
RISCVCPU *cpu = RISCV_CPU(cpu_obj);
58
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_init_user_properties(Object *cpu_obj)
59
}
60
61
kvm_riscv_init_machine_ids(cpu, &kvmcpu);
62
+ kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu);
63
64
kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
65
}
66
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
67
int kvm_arch_init_vcpu(CPUState *cs)
68
{
69
int ret = 0;
70
- target_ulong isa;
71
RISCVCPU *cpu = RISCV_CPU(cs);
72
- CPURISCVState *env = &cpu->env;
73
- uint64_t id;
74
75
qemu_add_vm_change_state_handler(kvm_riscv_vm_state_change, cs);
76
77
- id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
78
- KVM_REG_RISCV_CONFIG_REG(isa));
79
- ret = kvm_get_one_reg(cs, id, &isa);
80
- if (ret) {
81
- return ret;
82
- }
83
- env->misa_ext = isa;
84
-
85
if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) {
86
ret = kvm_vcpu_set_machine_ids(cpu, cs);
87
}
88
--
29
--
89
2.40.1
30
2.45.1
diff view generated by jsdifflib
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
The enum value 'rv_op_illegal' does not represent an
3
The current semihost exception number (16) is a reserved number (range
4
instruction, but is a catch-all value in case we have
4
[16-17]). The upcoming double trap specification uses that number for
5
no match in the decoder. Let's make the value a shared
5
the double trap exception. Since the privileged spec (Table 22) defines
6
one, so that other compile units can reuse it.
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>
7
11
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
13
Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com>
10
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
11
Message-Id: <20230612111034.3955227-5-christoph.muellner@vrull.eu>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
15
---
14
disas/riscv.h | 4 ++++
16
target/riscv/cpu_bits.h | 2 +-
15
disas/riscv.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
16
2 files changed, 5 insertions(+), 1 deletion(-)
17
18
18
diff --git a/disas/riscv.h b/disas/riscv.h
19
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
19
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
20
--- a/disas/riscv.h
21
--- a/target/riscv/cpu_bits.h
21
+++ b/disas/riscv.h
22
+++ b/target/riscv/cpu_bits.h
22
@@ -XXX,XX +XXX,XX @@ typedef struct {
23
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
23
const rvc_constraint *constraints;
24
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
24
} rv_comp_data;
25
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
25
26
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
26
+enum {
27
- RISCV_EXCP_SEMIHOST = 0x10,
27
+ rv_op_illegal = 0
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
28
+};
29
RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
29
+
30
RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
30
enum {
31
RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
31
rvcd_imm_nz = 0x1
32
+ RISCV_EXCP_SEMIHOST = 0x3f,
32
};
33
} RISCVException;
33
diff --git a/disas/riscv.c b/disas/riscv.c
34
34
index XXXXXXX..XXXXXXX 100644
35
#define RISCV_EXCP_INT_FLAG 0x80000000
35
--- a/disas/riscv.c
36
+++ b/disas/riscv.c
37
@@ -XXX,XX +XXX,XX @@
38
#include "disas/riscv.h"
39
40
typedef enum {
41
- rv_op_illegal = 0,
42
+ /* 0 is reserved for rv_op_illegal. */
43
rv_op_lui = 1,
44
rv_op_auipc = 2,
45
rv_op_jal = 3,
46
--
36
--
47
2.40.1
37
2.45.1
48
38
49
39
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Certain validations, such as the validations done for the machine IDs
3
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr
4
(mvendorid/marchid/mimpid), are done before starting the CPU.
4
enabled, will fail with a kernel oops SIGILL right at the start. The
5
Non-dynamic (named) CPUs tries to match user input with a preset
5
reason is that we can't expose zkr without implementing the SEED CSR.
6
default. As it is today we can't prefetch a KVM default for these cases
6
Disabling zkr in the guest would be a workaround, but if the KVM doesn't
7
because we're only able to read/write KVM regs after the vcpu is
7
allow it we'll error out and never boot.
8
spinning.
9
8
10
Our target/arm friends use a concept called "scratch CPU", which
9
In hindsight this is too strict. If we keep proceeding, despite not
11
consists of creating a vcpu for doing queries and validations and so on,
10
disabling the extension in the KVM vcpu, we'll not add the extension in
12
which is discarded shortly after use [1]. This is a suitable solution
11
the riscv,isa. The guest kernel will be unaware of the extension, i.e.
13
for what we need so let's implement it in target/riscv as well.
12
it doesn't matter if the KVM vcpu has it enabled underneath or not. So
13
it's ok to keep booting in this case.
14
14
15
kvm_riscv_init_machine_ids() will be used to do any pre-launch setup for
15
Change our current logic to not error out if we fail to disable an
16
KVM CPUs, via riscv_cpu_add_user_properties(). The function will create
16
extension in kvm_set_one_reg(), but show a warning and keep booting. It
17
a KVM scratch CPU, fetch KVM regs that work as default values for user
17
is important to throw a warning because we must make the user aware that
18
properties, and then discard the scratch CPU afterwards.
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.
19
21
20
We're starting by initializing 'mvendorid'. This concept will be used to
22
The case we're handling happens with an EINVAL error code. If we fail to
21
init other KVM specific properties in the next patches as well.
23
disable the extension in KVM for any other reason, error out.
22
24
23
[1] target/arm/kvm.c, kvm_arm_create_scratch_host_vcpu()
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.
24
28
25
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
29
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
28
Acked-by: Alistair Francis <alistair.francis@wdc.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
29
Message-Id: <20230706101738.460804-7-dbarboza@ventanamicro.com>
33
Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com>
30
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
31
---
35
---
32
target/riscv/kvm_riscv.h | 1 +
36
target/riscv/kvm/kvm-cpu.c | 12 ++++++++----
33
target/riscv/cpu.c | 6 +++
37
1 file changed, 8 insertions(+), 4 deletions(-)
34
target/riscv/kvm.c | 85 ++++++++++++++++++++++++++++++++++++++++
35
3 files changed, 92 insertions(+)
36
38
37
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
39
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
38
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
39
--- a/target/riscv/kvm_riscv.h
41
--- a/target/riscv/kvm/kvm-cpu.c
40
+++ b/target/riscv/kvm_riscv.h
42
+++ b/target/riscv/kvm/kvm-cpu.c
41
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
42
#ifndef QEMU_KVM_RISCV_H
44
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
43
#define QEMU_KVM_RISCV_H
45
ret = kvm_set_one_reg(cs, id, &reg);
44
46
if (ret != 0) {
45
+void kvm_riscv_init_user_properties(Object *cpu_obj);
47
- error_report("Unable to %s extension %s in KVM, error %d",
46
void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
48
- reg ? "enable" : "disable",
47
void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
49
- multi_ext_cfg->name, ret);
48
50
- exit(EXIT_FAILURE);
49
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
51
+ if (!reg && ret == -EINVAL) {
50
index XXXXXXX..XXXXXXX 100644
52
+ warn_report("KVM cannot disable extension %s",
51
--- a/target/riscv/cpu.c
53
+ multi_ext_cfg->name);
52
+++ b/target/riscv/cpu.c
54
+ } else {
53
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
55
+ error_report("Unable to enable extension %s in KVM, error %d",
54
Property *prop;
56
+ multi_ext_cfg->name, ret);
55
DeviceState *dev = DEVICE(obj);
57
+ exit(EXIT_FAILURE);
56
58
+ }
57
+#ifndef CONFIG_USER_ONLY
59
}
58
+ if (kvm_enabled()) {
60
}
59
+ kvm_riscv_init_user_properties(obj);
60
+ }
61
+#endif
62
+
63
riscv_cpu_add_misa_properties(obj);
64
65
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
66
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/kvm.c
69
+++ b/target/riscv/kvm.c
70
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
71
env->kvm_timer_dirty = false;
72
}
61
}
73
74
+typedef struct KVMScratchCPU {
75
+ int kvmfd;
76
+ int vmfd;
77
+ int cpufd;
78
+} KVMScratchCPU;
79
+
80
+/*
81
+ * Heavily inspired by kvm_arm_create_scratch_host_vcpu()
82
+ * from target/arm/kvm.c.
83
+ */
84
+static bool kvm_riscv_create_scratch_vcpu(KVMScratchCPU *scratch)
85
+{
86
+ int kvmfd = -1, vmfd = -1, cpufd = -1;
87
+
88
+ kvmfd = qemu_open_old("/dev/kvm", O_RDWR);
89
+ if (kvmfd < 0) {
90
+ goto err;
91
+ }
92
+ do {
93
+ vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0);
94
+ } while (vmfd == -1 && errno == EINTR);
95
+ if (vmfd < 0) {
96
+ goto err;
97
+ }
98
+ cpufd = ioctl(vmfd, KVM_CREATE_VCPU, 0);
99
+ if (cpufd < 0) {
100
+ goto err;
101
+ }
102
+
103
+ scratch->kvmfd = kvmfd;
104
+ scratch->vmfd = vmfd;
105
+ scratch->cpufd = cpufd;
106
+
107
+ return true;
108
+
109
+ err:
110
+ if (cpufd >= 0) {
111
+ close(cpufd);
112
+ }
113
+ if (vmfd >= 0) {
114
+ close(vmfd);
115
+ }
116
+ if (kvmfd >= 0) {
117
+ close(kvmfd);
118
+ }
119
+
120
+ return false;
121
+}
122
+
123
+static void kvm_riscv_destroy_scratch_vcpu(KVMScratchCPU *scratch)
124
+{
125
+ close(scratch->cpufd);
126
+ close(scratch->vmfd);
127
+ close(scratch->kvmfd);
128
+}
129
+
130
+static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
131
+{
132
+ CPURISCVState *env = &cpu->env;
133
+ struct kvm_one_reg reg;
134
+ int ret;
135
+
136
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
137
+ KVM_REG_RISCV_CONFIG_REG(mvendorid));
138
+ reg.addr = (uint64_t)&cpu->cfg.mvendorid;
139
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
140
+ if (ret != 0) {
141
+ error_report("Unable to retrieve mvendorid from host, error %d", ret);
142
+ }
143
+}
144
+
145
+void kvm_riscv_init_user_properties(Object *cpu_obj)
146
+{
147
+ RISCVCPU *cpu = RISCV_CPU(cpu_obj);
148
+ KVMScratchCPU kvmcpu;
149
+
150
+ if (!kvm_riscv_create_scratch_vcpu(&kvmcpu)) {
151
+ return;
152
+ }
153
+
154
+ kvm_riscv_init_machine_ids(cpu, &kvmcpu);
155
+
156
+ kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
157
+}
158
+
159
const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
160
KVM_CAP_LAST_INFO
161
};
162
--
62
--
163
2.40.1
63
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
KVM-specific properties are being created inside target/riscv/kvm.c. But
3
We're not setting (s/m)tval when triggering breakpoints of type 2
4
at this moment we're gathering all the remaining properties from TCG and
4
(mcontrol) and 6 (mcontrol6). According to the debug spec section
5
adding them as is when running KVM. This creates a situation where
5
5.7.12, "Match Control Type 6":
6
non-KVM properties are setting flags to 'true' due to its default
7
settings (e.g. Zawrs). Users can also freely enable them via command
8
line.
9
6
10
This doesn't impact runtime per se because KVM doesn't care about these
7
"The Privileged Spec says that breakpoint exceptions that occur on
11
flags, but code such as riscv_isa_string_ext() take those flags into
8
instruction fetches, loads, or stores update the tval CSR with either
12
account. The result is that, for a KVM guest, setting non-KVM properties
9
zero or the faulting virtual address. The faulting virtual address for
13
will make them appear in the riscv,isa DT.
10
an mcontrol6 trigger with action = 0 is the address being accessed and
11
which caused that trigger to fire."
14
12
15
We want to keep the same API for both TCG and KVM and at the same time,
13
A similar text is also found in the Debug spec section 5.7.11 w.r.t.
16
when running KVM, forbid non-KVM extensions to be enabled internally. We
14
mcontrol.
17
accomplish both by changing riscv_cpu_add_user_properties() to add a
15
18
mock boolean property for every non-KVM extension in
16
Note that what we're doing ATM is not violating the spec, but it's
19
riscv_cpu_extensions[]. Then, when running KVM, users are still free to
17
simple enough to set mtval/stval and it makes life easier for any
20
set extensions at will, but we'll error out if a non-KVM extension is
18
software that relies on this info.
21
enabled. Setting such extension to 'false' will be ignored.
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().
22
24
23
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
25
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
24
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Message-Id: <20230706101738.460804-18-dbarboza@ventanamicro.com>
27
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
28
Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
30
---
29
target/riscv/cpu.c | 36 ++++++++++++++++++++++++++++++++++++
31
target/riscv/cpu_helper.c | 1 +
30
1 file changed, 36 insertions(+)
32
target/riscv/debug.c | 3 +++
33
2 files changed, 4 insertions(+)
31
34
32
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
35
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
33
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/cpu.c
37
--- a/target/riscv/cpu_helper.c
35
+++ b/target/riscv/cpu.c
38
+++ b/target/riscv/cpu_helper.c
36
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
39
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
37
DEFINE_PROP_END_OF_LIST(),
40
tval = env->bins;
38
};
41
break;
39
42
case RISCV_EXCP_BREAKPOINT:
40
+
43
+ tval = env->badaddr;
41
+#ifndef CONFIG_USER_ONLY
44
if (cs->watchpoint_hit) {
42
+static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
45
tval = cs->watchpoint_hit->hitaddr;
43
+ const char *name,
46
cs->watchpoint_hit = NULL;
44
+ void *opaque, Error **errp)
47
diff --git a/target/riscv/debug.c b/target/riscv/debug.c
45
+{
48
index XXXXXXX..XXXXXXX 100644
46
+ const char *propname = opaque;
49
--- a/target/riscv/debug.c
47
+ bool value;
50
+++ b/target/riscv/debug.c
48
+
51
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
49
+ if (!visit_type_bool(v, name, &value, errp)) {
52
if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) {
50
+ return;
53
/* check U/S/M bit against current privilege level */
51
+ }
54
if ((ctrl >> 3) & BIT(env->priv)) {
52
+
55
+ env->badaddr = pc;
53
+ if (value) {
56
return true;
54
+ error_setg(errp, "extension %s is not available with KVM",
57
}
55
+ propname);
58
}
56
+ }
59
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
57
+}
60
if (env->virt_enabled) {
58
+#endif
61
/* check VU/VS bit against current privilege level */
59
+
62
if ((ctrl >> 23) & BIT(env->priv)) {
60
/*
63
+ env->badaddr = pc;
61
* Add CPU properties with user-facing flags.
64
return true;
62
*
65
}
63
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
66
} else {
64
if (object_property_find(obj, prop->name)) {
67
/* check U/S/M bit against current privilege level */
65
continue;
68
if ((ctrl >> 3) & BIT(env->priv)) {
66
}
69
+ env->badaddr = pc;
67
+
70
return true;
68
+ /*
71
}
69
+ * Set the default to disabled for every extension
72
}
70
+ * unknown to KVM and error out if the user attempts
71
+ * to enable any of them.
72
+ *
73
+ * We're giving a pass for non-bool properties since they're
74
+ * not related to the availability of extensions and can be
75
+ * safely ignored as is.
76
+ */
77
+ if (prop->info == &qdev_prop_bool) {
78
+ object_property_add(obj, prop->name, "bool",
79
+ NULL, cpu_set_cfg_unavailable,
80
+ NULL, (void *)prop->name);
81
+ continue;
82
+ }
83
}
84
#endif
85
qdev_property_add_static(dev, prop);
86
--
73
--
87
2.40.1
74
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Commit 7f0bdfb5bfc2 ("target/riscv/cpu.c: remove cfg setup from
3
Privileged spec section 4.1.9 mentions:
4
riscv_cpu_init()") removed code that was enabling mmu, pmp, ext_ifencei
5
and ext_icsr from riscv_cpu_init(), the init() function of
6
TYPE_RISCV_CPU, parent type of all RISC-V CPUss. This was done to force
7
CPUs to explictly enable all extensions and features it requires,
8
without any 'magic values' that were inherited by the parent type.
9
4
10
This commit failed to make appropriate changes in the 'veyron-v1' CPU,
5
"When a trap is taken into S-mode, stval is written with
11
added earlier by commit e1d084a8524a. The result is that the veyron-v1
6
exception-specific information to assist software in handling the trap.
12
CPU has ext_ifencei, ext_icsr and pmp set to 'false', which is not the
7
(...)
13
case.
14
8
15
The reason why it took this long to notice (thanks LIU Zhiwei for
9
If stval is written with a nonzero value when a breakpoint,
16
reporting it) is because Linux doesn't mind 'ifencei' and 'icsr' being
10
address-misaligned, access-fault, or page-fault exception occurs on an
17
absent in the 'riscv,isa' DT, implying that they're both present if the
11
instruction fetch, load, or store, then stval will contain the faulting
18
'i' extension is enabled. OpenSBI also doesn't error out or warns about
12
virtual address."
19
the lack of 'pmp', it'll just not protect memory pages.
20
13
21
Fix it by setting them to 'true' in rv64_veyron_v1_cpu_init() like
14
A similar text is found for mtval in section 3.1.16.
22
7f0bdfb5bfc2 already did with other CPUs.
23
15
24
Reported-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
16
Setting mtval/stval in this scenario is optional, but some softwares read
25
Fixes: 7f0bdfb5bfc2 ("target/riscv/cpu.c: remove cfg setup from riscv_cpu_init()")
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
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
28
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
24
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
29
Message-Id: <20230620152443.137079-1-dbarboza@ventanamicro.com>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26
Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com>
30
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
31
---
28
---
32
target/riscv/cpu.c | 3 +++
29
target/riscv/insn_trans/trans_privileged.c.inc | 2 ++
33
1 file changed, 3 insertions(+)
30
1 file changed, 2 insertions(+)
34
31
35
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
36
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
37
--- a/target/riscv/cpu.c
34
--- a/target/riscv/insn_trans/trans_privileged.c.inc
38
+++ b/target/riscv/cpu.c
35
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
39
@@ -XXX,XX +XXX,XX @@ static void rv64_veyron_v1_cpu_init(Object *obj)
36
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
40
37
if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
41
/* Enable ISA extensions */
38
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
42
cpu->cfg.mmu = true;
39
} else {
43
+ cpu->cfg.ext_ifencei = true;
40
+ tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env,
44
+ cpu->cfg.ext_icsr = true;
41
+ offsetof(CPURISCVState, badaddr));
45
+ cpu->cfg.pmp = true;
42
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
46
cpu->cfg.ext_icbom = true;
43
}
47
cpu->cfg.cbom_blocksize = 64;
44
return true;
48
cpu->cfg.cboz_blocksize = 64;
49
--
45
--
50
2.40.1
46
2.45.1
diff view generated by jsdifflib
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
This patch introduces the RISC-V Zfa extension, which introduces
3
Add support for Zve32x extension and replace some checks for Zve32f with
4
additional floating-point instructions:
4
Zve32x, since Zve32f depends on Zve32x.
5
* fli (load-immediate) with pre-defined immediates
6
* fminm/fmaxm (like fmin/fmax but with different NaN behaviour)
7
* fround/froundmx (round to integer)
8
* fcvtmod.w.d (Modular Convert-to-Integer)
9
* fmv* to access high bits of float register bigger than XLEN
10
* Quiet comparison instructions (fleq/fltq)
11
5
12
Zfa defines its instructions in combination with the following extensions:
6
Signed-off-by: Jason Chien <jason.chien@sifive.com>
13
* single-precision floating-point (F)
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
14
* double-precision floating-point (D)
8
Reviewed-by: Max Chou <max.chou@sifive.com>
15
* quad-precision floating-point (Q)
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
* half-precision floating-point (Zfh)
10
Message-ID: <20240328022343.6871-2-jason.chien@sifive.com>
17
18
Since QEMU does not support the RISC-V quad-precision floating-point
19
ISA extension (Q), this patch does not include the instructions that
20
depend on this extension. All other instructions are included in this
21
patch.
22
23
The Zfa specification can be found here:
24
https://github.com/riscv/riscv-isa-manual/blob/master/src/zfa.tex
25
The Zfa specifciation is frozen and is in public review since May 3, 2023:
26
https://groups.google.com/a/groups.riscv.org/g/isa-dev/c/SED4ntBkabg
27
28
The patch also includes a TCG test for the fcvtmod.w.d instruction.
29
The test cases test for correct results and flag behaviour.
30
Note, that the Zfa specification requires fcvtmod's flag behaviour
31
to be identical to a fcvt with the same operands (which is also
32
tested).
33
34
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
35
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
36
Message-Id: <20230710071243.282464-1-christoph.muellner@vrull.eu>
37
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
38
---
12
---
39
disas/riscv.h | 3 +
13
target/riscv/cpu_cfg.h | 1 +
40
target/riscv/cpu_cfg.h | 1 +
14
target/riscv/cpu.c | 2 ++
41
target/riscv/helper.h | 19 +
15
target/riscv/cpu_helper.c | 2 +-
42
target/riscv/insn32.decode | 26 ++
16
target/riscv/csr.c | 2 +-
43
disas/riscv.c | 139 ++++++
17
target/riscv/tcg/tcg-cpu.c | 16 ++++++++--------
44
target/riscv/cpu.c | 8 +
18
target/riscv/insn_trans/trans_rvv.c.inc | 4 ++--
45
target/riscv/fpu_helper.c | 154 +++++++
19
6 files changed, 15 insertions(+), 12 deletions(-)
46
target/riscv/translate.c | 1 +
47
tests/tcg/riscv64/test-fcvtmod.c | 345 ++++++++++++++
48
target/riscv/insn_trans/trans_rvzfa.c.inc | 521 ++++++++++++++++++++++
49
tests/tcg/riscv64/Makefile.target | 6 +
50
11 files changed, 1223 insertions(+)
51
create mode 100644 tests/tcg/riscv64/test-fcvtmod.c
52
create mode 100644 target/riscv/insn_trans/trans_rvzfa.c.inc
53
20
54
diff --git a/disas/riscv.h b/disas/riscv.h
55
index XXXXXXX..XXXXXXX 100644
56
--- a/disas/riscv.h
57
+++ b/disas/riscv.h
58
@@ -XXX,XX +XXX,XX @@ typedef enum {
59
rv_codec_r_imm2,
60
rv_codec_r2_immhl,
61
rv_codec_r2_imm2_imm5,
62
+ rv_codec_fli,
63
} rv_codec;
64
65
/* structures */
66
@@ -XXX,XX +XXX,XX @@ enum {
67
#define rv_fmt_rd_offset "O\t0,o"
68
#define rv_fmt_rd_rs1_rs2 "O\t0,1,2"
69
#define rv_fmt_frd_rs1 "O\t3,1"
70
+#define rv_fmt_frd_rs1_rs2 "O\t3,1,2"
71
#define rv_fmt_frd_frs1 "O\t3,4"
72
#define rv_fmt_rd_frs1 "O\t0,4"
73
#define rv_fmt_rd_frs1_frs2 "O\t0,4,5"
74
@@ -XXX,XX +XXX,XX @@ enum {
75
#define rv_fmt_rd_rs1_immh_imml "O\t0,1,i,j"
76
#define rv_fmt_rd_rs1_immh_imml_addr "O\t0,(1),i,j"
77
#define rv_fmt_rd2_imm "O\t0,2,(1),i"
78
+#define rv_fmt_fli "O\t3,h"
79
80
#endif /* DISAS_RISCV_H */
81
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
21
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
82
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
83
--- a/target/riscv/cpu_cfg.h
23
--- a/target/riscv/cpu_cfg.h
84
+++ b/target/riscv/cpu_cfg.h
24
+++ b/target/riscv/cpu_cfg.h
85
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
25
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
86
bool ext_svpbmt;
26
bool ext_zhinx;
87
bool ext_zdinx;
27
bool ext_zhinxmin;
88
bool ext_zawrs;
28
bool ext_zve32f;
89
+ bool ext_zfa;
29
+ bool ext_zve32x;
90
bool ext_zfbfmin;
30
bool ext_zve64f;
91
bool ext_zfh;
31
bool ext_zve64d;
92
bool ext_zfhmin;
32
bool ext_zvbb;
93
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
94
index XXXXXXX..XXXXXXX 100644
95
--- a/target/riscv/helper.h
96
+++ b/target/riscv/helper.h
97
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(fsub_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
98
DEF_HELPER_FLAGS_3(fmul_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
99
DEF_HELPER_FLAGS_3(fdiv_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
100
DEF_HELPER_FLAGS_3(fmin_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
101
+DEF_HELPER_FLAGS_3(fminm_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
102
DEF_HELPER_FLAGS_3(fmax_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
103
+DEF_HELPER_FLAGS_3(fmaxm_s, TCG_CALL_NO_RWG, i64, env, i64, i64)
104
DEF_HELPER_FLAGS_2(fsqrt_s, TCG_CALL_NO_RWG, i64, env, i64)
105
DEF_HELPER_FLAGS_3(fle_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
106
+DEF_HELPER_FLAGS_3(fleq_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
107
DEF_HELPER_FLAGS_3(flt_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
108
+DEF_HELPER_FLAGS_3(fltq_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
109
DEF_HELPER_FLAGS_3(feq_s, TCG_CALL_NO_RWG, tl, env, i64, i64)
110
DEF_HELPER_FLAGS_2(fcvt_w_s, TCG_CALL_NO_RWG, tl, env, i64)
111
DEF_HELPER_FLAGS_2(fcvt_wu_s, TCG_CALL_NO_RWG, tl, env, i64)
112
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl)
113
DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl)
114
DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl)
115
DEF_HELPER_FLAGS_2(fclass_s, TCG_CALL_NO_RWG_SE, tl, env, i64)
116
+DEF_HELPER_FLAGS_2(fround_s, TCG_CALL_NO_RWG_SE, i64, env, i64)
117
+DEF_HELPER_FLAGS_2(froundnx_s, TCG_CALL_NO_RWG_SE, i64, env, i64)
118
119
/* Floating Point - Double Precision */
120
DEF_HELPER_FLAGS_3(fadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
121
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(fsub_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
122
DEF_HELPER_FLAGS_3(fmul_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
123
DEF_HELPER_FLAGS_3(fdiv_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
124
DEF_HELPER_FLAGS_3(fmin_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
125
+DEF_HELPER_FLAGS_3(fminm_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
126
DEF_HELPER_FLAGS_3(fmax_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
127
+DEF_HELPER_FLAGS_3(fmaxm_d, TCG_CALL_NO_RWG, i64, env, i64, i64)
128
DEF_HELPER_FLAGS_2(fcvt_s_d, TCG_CALL_NO_RWG, i64, env, i64)
129
DEF_HELPER_FLAGS_2(fcvt_d_s, TCG_CALL_NO_RWG, i64, env, i64)
130
DEF_HELPER_FLAGS_2(fsqrt_d, TCG_CALL_NO_RWG, i64, env, i64)
131
DEF_HELPER_FLAGS_3(fle_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
132
+DEF_HELPER_FLAGS_3(fleq_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
133
DEF_HELPER_FLAGS_3(flt_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
134
+DEF_HELPER_FLAGS_3(fltq_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
135
DEF_HELPER_FLAGS_3(feq_d, TCG_CALL_NO_RWG, tl, env, i64, i64)
136
DEF_HELPER_FLAGS_2(fcvt_w_d, TCG_CALL_NO_RWG, tl, env, i64)
137
+DEF_HELPER_FLAGS_2(fcvtmod_w_d, TCG_CALL_NO_RWG, i64, env, i64)
138
DEF_HELPER_FLAGS_2(fcvt_wu_d, TCG_CALL_NO_RWG, tl, env, i64)
139
DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, tl, env, i64)
140
DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, tl, env, i64)
141
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_d_wu, TCG_CALL_NO_RWG, i64, env, tl)
142
DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, tl)
143
DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl)
144
DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64)
145
+DEF_HELPER_FLAGS_2(fround_d, TCG_CALL_NO_RWG_SE, i64, env, i64)
146
+DEF_HELPER_FLAGS_2(froundnx_d, TCG_CALL_NO_RWG_SE, i64, env, i64)
147
148
/* Bitmanip */
149
DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl)
150
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(fsub_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
151
DEF_HELPER_FLAGS_3(fmul_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
152
DEF_HELPER_FLAGS_3(fdiv_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
153
DEF_HELPER_FLAGS_3(fmin_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
154
+DEF_HELPER_FLAGS_3(fminm_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
155
DEF_HELPER_FLAGS_3(fmax_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
156
+DEF_HELPER_FLAGS_3(fmaxm_h, TCG_CALL_NO_RWG, i64, env, i64, i64)
157
DEF_HELPER_FLAGS_2(fsqrt_h, TCG_CALL_NO_RWG, i64, env, i64)
158
DEF_HELPER_FLAGS_3(fle_h, TCG_CALL_NO_RWG, tl, env, i64, i64)
159
+DEF_HELPER_FLAGS_3(fleq_h, TCG_CALL_NO_RWG, tl, env, i64, i64)
160
DEF_HELPER_FLAGS_3(flt_h, TCG_CALL_NO_RWG, tl, env, i64, i64)
161
+DEF_HELPER_FLAGS_3(fltq_h, TCG_CALL_NO_RWG, tl, env, i64, i64)
162
DEF_HELPER_FLAGS_3(feq_h, TCG_CALL_NO_RWG, tl, env, i64, i64)
163
DEF_HELPER_FLAGS_2(fcvt_s_h, TCG_CALL_NO_RWG, i64, env, i64)
164
DEF_HELPER_FLAGS_2(fcvt_h_s, TCG_CALL_NO_RWG, i64, env, i64)
165
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_h_wu, TCG_CALL_NO_RWG, i64, env, tl)
166
DEF_HELPER_FLAGS_2(fcvt_h_l, TCG_CALL_NO_RWG, i64, env, tl)
167
DEF_HELPER_FLAGS_2(fcvt_h_lu, TCG_CALL_NO_RWG, i64, env, tl)
168
DEF_HELPER_FLAGS_2(fclass_h, TCG_CALL_NO_RWG_SE, tl, env, i64)
169
+DEF_HELPER_FLAGS_2(fround_h, TCG_CALL_NO_RWG_SE, i64, env, i64)
170
+DEF_HELPER_FLAGS_2(froundnx_h, TCG_CALL_NO_RWG_SE, i64, env, i64)
171
172
/* Cache-block operations */
173
DEF_HELPER_2(cbo_clean_flush, void, env, tl)
174
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
175
index XXXXXXX..XXXXXXX 100644
176
--- a/target/riscv/insn32.decode
177
+++ b/target/riscv/insn32.decode
178
@@ -XXX,XX +XXX,XX @@ binvi 01101. ........... 001 ..... 0010011 @sh
179
bset 0010100 .......... 001 ..... 0110011 @r
180
bseti 00101. ........... 001 ..... 0010011 @sh
181
182
+# *** Zfa Standard Extension ***
183
+fli_s 1111000 00001 ..... 000 ..... 1010011 @r2
184
+fli_d 1111001 00001 ..... 000 ..... 1010011 @r2
185
+fli_h 1111010 00001 ..... 000 ..... 1010011 @r2
186
+fminm_s 0010100 ..... ..... 010 ..... 1010011 @r
187
+fmaxm_s 0010100 ..... ..... 011 ..... 1010011 @r
188
+fminm_d 0010101 ..... ..... 010 ..... 1010011 @r
189
+fmaxm_d 0010101 ..... ..... 011 ..... 1010011 @r
190
+fminm_h 0010110 ..... ..... 010 ..... 1010011 @r
191
+fmaxm_h 0010110 ..... ..... 011 ..... 1010011 @r
192
+fround_s 0100000 00100 ..... ... ..... 1010011 @r2_rm
193
+froundnx_s 0100000 00101 ..... ... ..... 1010011 @r2_rm
194
+fround_d 0100001 00100 ..... ... ..... 1010011 @r2_rm
195
+froundnx_d 0100001 00101 ..... ... ..... 1010011 @r2_rm
196
+fround_h 0100010 00100 ..... ... ..... 1010011 @r2_rm
197
+froundnx_h 0100010 00101 ..... ... ..... 1010011 @r2_rm
198
+fcvtmod_w_d 1100001 01000 ..... 001 ..... 1010011 @r2
199
+fmvh_x_d 1110001 00001 ..... 000 ..... 1010011 @r2
200
+fmvp_d_x 1011001 ..... ..... 000 ..... 1010011 @r
201
+fleq_s 1010000 ..... ..... 100 ..... 1010011 @r
202
+fltq_s 1010000 ..... ..... 101 ..... 1010011 @r
203
+fleq_d 1010001 ..... ..... 100 ..... 1010011 @r
204
+fltq_d 1010001 ..... ..... 101 ..... 1010011 @r
205
+fleq_h 1010010 ..... ..... 100 ..... 1010011 @r
206
+fltq_h 1010010 ..... ..... 101 ..... 1010011 @r
207
+
208
# *** RV32 Zfh Extension ***
209
flh ............ ..... 001 ..... 0000111 @i
210
fsh ....... ..... ..... 001 ..... 0100111 @s
211
diff --git a/disas/riscv.c b/disas/riscv.c
212
index XXXXXXX..XXXXXXX 100644
213
--- a/disas/riscv.c
214
+++ b/disas/riscv.c
215
@@ -XXX,XX +XXX,XX @@ typedef enum {
216
rv_op_fsh = 798,
217
rv_op_fmv_h_x = 799,
218
rv_op_fmv_x_h = 800,
219
+ rv_op_fli_s = 801,
220
+ rv_op_fli_d = 802,
221
+ rv_op_fli_q = 803,
222
+ rv_op_fli_h = 804,
223
+ rv_op_fminm_s = 805,
224
+ rv_op_fmaxm_s = 806,
225
+ rv_op_fminm_d = 807,
226
+ rv_op_fmaxm_d = 808,
227
+ rv_op_fminm_q = 809,
228
+ rv_op_fmaxm_q = 810,
229
+ rv_op_fminm_h = 811,
230
+ rv_op_fmaxm_h = 812,
231
+ rv_op_fround_s = 813,
232
+ rv_op_froundnx_s = 814,
233
+ rv_op_fround_d = 815,
234
+ rv_op_froundnx_d = 816,
235
+ rv_op_fround_q = 817,
236
+ rv_op_froundnx_q = 818,
237
+ rv_op_fround_h = 819,
238
+ rv_op_froundnx_h = 820,
239
+ rv_op_fcvtmod_w_d = 821,
240
+ rv_op_fmvh_x_d = 822,
241
+ rv_op_fmvp_d_x = 823,
242
+ rv_op_fmvh_x_q = 824,
243
+ rv_op_fmvp_q_x = 825,
244
+ rv_op_fleq_s = 826,
245
+ rv_op_fltq_s = 827,
246
+ rv_op_fleq_d = 828,
247
+ rv_op_fltq_d = 829,
248
+ rv_op_fleq_q = 830,
249
+ rv_op_fltq_q = 831,
250
+ rv_op_fleq_h = 832,
251
+ rv_op_fltq_h = 833,
252
} rv_op;
253
254
/* register names */
255
@@ -XXX,XX +XXX,XX @@ static const char rv_vreg_name_sym[32][4] = {
256
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
257
};
258
259
+/* The FLI.[HSDQ] numeric constants (0.0 for symbolic constants).
260
+ * The constants use the hex floating-point literal representation
261
+ * that is printed when using the printf %a format specifier,
262
+ * which matches the output that is generated by the disassembler.
263
+ */
264
+static const char rv_fli_name_const[32][9] =
265
+{
266
+ "0x1p+0", "min", "0x1p-16", "0x1p-15",
267
+ "0x1p-8", "0x1p-7", "0x1p-4", "0x1p-3",
268
+ "0x1p-2", "0x1.4p-2", "0x1.8p-2", "0x1.cp-2",
269
+ "0x1p-1", "0x1.4p-1", "0x1.8p-1", "0x1.cp-1",
270
+ "0x1p+0", "0x1.4p+0", "0x1.8p+0", "0x1.cp+0",
271
+ "0x1p+1", "0x1.4p+1", "0x1.8p+1", "0x1p+2",
272
+ "0x1p+3", "0x1p+4", "0x1p+7", "0x1p+8",
273
+ "0x1p+15", "0x1p+16", "inf", "nan"
274
+};
275
+
276
/* pseudo-instruction constraints */
277
278
static const rvc_constraint rvcc_jal[] = { rvc_rd_eq_ra, rvc_end };
279
@@ -XXX,XX +XXX,XX @@ const rv_opcode_data rvi_opcode_data[] = {
280
{ "fsh", rv_codec_s, rv_fmt_frs2_offset_rs1, NULL, 0, 0, 0 },
281
{ "fmv.h.x", rv_codec_r, rv_fmt_frd_rs1, NULL, 0, 0, 0 },
282
{ "fmv.x.h", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
283
+ { "fli.s", rv_codec_fli, rv_fmt_fli, NULL, 0, 0, 0 },
284
+ { "fli.d", rv_codec_fli, rv_fmt_fli, NULL, 0, 0, 0 },
285
+ { "fli.q", rv_codec_fli, rv_fmt_fli, NULL, 0, 0, 0 },
286
+ { "fli.h", rv_codec_fli, rv_fmt_fli, NULL, 0, 0, 0 },
287
+ { "fminm.s", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
288
+ { "fmaxm.s", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
289
+ { "fminm.d", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
290
+ { "fmaxm.d", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
291
+ { "fminm.q", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
292
+ { "fmaxm.q", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
293
+ { "fminm.h", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
294
+ { "fmaxm.h", rv_codec_r, rv_fmt_frd_frs1_frs2, NULL, 0, 0, 0 },
295
+ { "fround.s", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
296
+ { "froundnx.s", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
297
+ { "fround.d", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
298
+ { "froundnx.d", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
299
+ { "fround.q", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
300
+ { "froundnx.q", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
301
+ { "fround.h", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
302
+ { "froundnx.h", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
303
+ { "fcvtmod.w.d", rv_codec_r_m, rv_fmt_rm_rd_frs1, NULL, 0, 0, 0 },
304
+ { "fmvh.x.d", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
305
+ { "fmvp.d.x", rv_codec_r, rv_fmt_frd_rs1_rs2, NULL, 0, 0, 0 },
306
+ { "fmvh.x.q", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
307
+ { "fmvp.q.x", rv_codec_r, rv_fmt_frd_rs1_rs2, NULL, 0, 0, 0 },
308
+ { "fleq.s", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
309
+ { "fltq.s", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
310
+ { "fleq.d", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
311
+ { "fltq.d", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
312
+ { "fleq.q", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
313
+ { "fltq.q", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
314
+ { "fleq.h", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
315
+ { "fltq.h", rv_codec_r, rv_fmt_rd_frs1_frs2, NULL, 0, 0, 0 },
316
};
317
318
/* CSR names */
319
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
320
switch ((inst >> 12) & 0b111) {
321
case 0: op = rv_op_fmin_s; break;
322
case 1: op = rv_op_fmax_s; break;
323
+ case 2: op = rv_op_fminm_s; break;
324
+ case 3: op = rv_op_fmaxm_s; break;
325
}
326
break;
327
case 21:
328
switch ((inst >> 12) & 0b111) {
329
case 0: op = rv_op_fmin_d; break;
330
case 1: op = rv_op_fmax_d; break;
331
+ case 2: op = rv_op_fminm_d; break;
332
+ case 3: op = rv_op_fmaxm_d; break;
333
+ }
334
+ break;
335
+ case 22:
336
+ switch (((inst >> 12) & 0b111)) {
337
+ case 2: op = rv_op_fminm_h; break;
338
+ case 3: op = rv_op_fmaxm_h; break;
339
}
340
break;
341
case 23:
342
switch ((inst >> 12) & 0b111) {
343
case 0: op = rv_op_fmin_q; break;
344
case 1: op = rv_op_fmax_q; break;
345
+ case 2: op = rv_op_fminm_q; break;
346
+ case 3: op = rv_op_fmaxm_q; break;
347
}
348
break;
349
case 32:
350
switch ((inst >> 20) & 0b11111) {
351
case 1: op = rv_op_fcvt_s_d; break;
352
case 3: op = rv_op_fcvt_s_q; break;
353
+ case 4: op = rv_op_fround_s; break;
354
+ case 5: op = rv_op_froundnx_s; break;
355
case 6: op = rv_op_fcvt_s_bf16; break;
356
}
357
break;
358
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
359
switch ((inst >> 20) & 0b11111) {
360
case 0: op = rv_op_fcvt_d_s; break;
361
case 3: op = rv_op_fcvt_d_q; break;
362
+ case 4: op = rv_op_fround_d; break;
363
+ case 5: op = rv_op_froundnx_d; break;
364
}
365
break;
366
case 34:
367
switch (((inst >> 20) & 0b11111)) {
368
+ case 4: op = rv_op_fround_h; break;
369
+ case 5: op = rv_op_froundnx_h; break;
370
case 8: op = rv_op_fcvt_bf16_s; break;
371
}
372
break;
373
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
374
switch ((inst >> 20) & 0b11111) {
375
case 0: op = rv_op_fcvt_q_s; break;
376
case 1: op = rv_op_fcvt_q_d; break;
377
+ case 4: op = rv_op_fround_q; break;
378
+ case 5: op = rv_op_froundnx_q; break;
379
}
380
break;
381
case 44:
382
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
383
case 0: op = rv_op_fle_s; break;
384
case 1: op = rv_op_flt_s; break;
385
case 2: op = rv_op_feq_s; break;
386
+ case 4: op = rv_op_fleq_s; break;
387
+ case 5: op = rv_op_fltq_s; break;
388
}
389
break;
390
case 81:
391
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
392
case 0: op = rv_op_fle_d; break;
393
case 1: op = rv_op_flt_d; break;
394
case 2: op = rv_op_feq_d; break;
395
+ case 4: op = rv_op_fleq_d; break;
396
+ case 5: op = rv_op_fltq_d; break;
397
+ }
398
+ break;
399
+ case 82:
400
+ switch (((inst >> 12) & 0b111)) {
401
+ case 4: op = rv_op_fleq_h; break;
402
+ case 5: op = rv_op_fltq_h; break;
403
}
404
break;
405
case 83:
406
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
407
case 0: op = rv_op_fle_q; break;
408
case 1: op = rv_op_flt_q; break;
409
case 2: op = rv_op_feq_q; break;
410
+ case 4: op = rv_op_fleq_q; break;
411
+ case 5: op = rv_op_fltq_q; break;
412
+ }
413
+ break;
414
+ case 89:
415
+        switch (((inst >> 12) & 0b111)) {
416
+ case 0: op = rv_op_fmvp_d_x; break;
417
+ }
418
+ break;
419
+ case 91:
420
+        switch (((inst >> 12) & 0b111)) {
421
+ case 0: op = rv_op_fmvp_q_x; break;
422
}
423
break;
424
case 96:
425
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
426
case 1: op = rv_op_fcvt_wu_d; break;
427
case 2: op = rv_op_fcvt_l_d; break;
428
case 3: op = rv_op_fcvt_lu_d; break;
429
+ case 8: op = rv_op_fcvtmod_w_d; break;
430
}
431
break;
432
case 99:
433
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
434
((inst >> 12) & 0b00000111)) {
435
case 0: op = rv_op_fmv_x_d; break;
436
case 1: op = rv_op_fclass_d; break;
437
+ case 8: op = rv_op_fmvh_x_d; break;
438
}
439
break;
440
case 114:
441
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
442
((inst >> 12) & 0b00000111)) {
443
case 0: op = rv_op_fmv_x_q; break;
444
case 1: op = rv_op_fclass_q; break;
445
+ case 8: op = rv_op_fmvh_x_q; break;
446
}
447
break;
448
case 120:
449
switch (((inst >> 17) & 0b11111000) |
450
((inst >> 12) & 0b00000111)) {
451
case 0: op = rv_op_fmv_s_x; break;
452
+ case 8: op = rv_op_fli_s; break;
453
}
454
break;
455
case 121:
456
switch (((inst >> 17) & 0b11111000) |
457
((inst >> 12) & 0b00000111)) {
458
case 0: op = rv_op_fmv_d_x; break;
459
+ case 8: op = rv_op_fli_d; break;
460
}
461
break;
462
case 122:
463
switch (((inst >> 17) & 0b11111000) |
464
((inst >> 12) & 0b00000111)) {
465
case 0: op = rv_op_fmv_h_x; break;
466
+ case 8: op = rv_op_fli_h; break;
467
}
468
break;
469
case 123:
470
switch (((inst >> 17) & 0b11111000) |
471
((inst >> 12) & 0b00000111)) {
472
case 0: op = rv_op_fmv_q_x; break;
473
+ case 8: op = rv_op_fli_q; break;
474
}
475
break;
476
}
477
@@ -XXX,XX +XXX,XX @@ static void decode_inst_operands(rv_decode *dec, rv_isa isa)
478
break;
479
case rv_codec_zcmt_jt:
480
dec->imm = operand_tbl_index(inst);
481
+    break;
482
+ case rv_codec_fli:
483
+ dec->rd = operand_rd(inst);
484
+ dec->imm = operand_rs1(inst);
485
break;
486
case rv_codec_r2_imm5:
487
dec->rd = operand_rd(inst);
488
@@ -XXX,XX +XXX,XX @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
489
append(buf, tmp, buflen);
490
break;
491
}
492
+ case 'h':
493
+ append(buf, rv_fli_name_const[dec->imm], buflen);
494
+ break;
495
default:
496
break;
497
}
498
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
499
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
500
--- a/target/riscv/cpu.c
35
--- a/target/riscv/cpu.c
501
+++ b/target/riscv/cpu.c
36
+++ b/target/riscv/cpu.c
502
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
37
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
503
ISA_EXT_DATA_ENTRY(zifencei, PRIV_VERSION_1_10_0, ext_ifencei),
38
ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb),
504
ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause),
39
ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc),
505
ISA_EXT_DATA_ENTRY(zawrs, PRIV_VERSION_1_12_0, ext_zawrs),
40
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
506
+ ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),
41
+ ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
507
ISA_EXT_DATA_ENTRY(zfbfmin, PRIV_VERSION_1_12_0, ext_zfbfmin),
42
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
508
ISA_EXT_DATA_ENTRY(zfh, PRIV_VERSION_1_11_0, ext_zfh),
43
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
509
ISA_EXT_DATA_ENTRY(zfhmin, PRIV_VERSION_1_11_0, ext_zfhmin),
44
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
510
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
45
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
511
set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU);
46
MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false),
512
env->priv_ver = PRIV_VERSION_1_11_0;
47
MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false),
513
48
MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false),
514
+ cpu->cfg.ext_zfa = true;
49
+ MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
515
cpu->cfg.ext_zfh = true;
50
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
516
cpu->cfg.mmu = true;
51
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
517
cpu->cfg.ext_xtheadba = true;
52
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
53
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/riscv/cpu_helper.c
56
+++ b/target/riscv/cpu_helper.c
57
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
58
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
59
*cs_base = 0;
60
61
- if (cpu->cfg.ext_zve32f) {
62
+ if (cpu->cfg.ext_zve32x) {
63
/*
64
* If env->vl equals to VLMAX, we can use generic vector operation
65
* expanders (GVEC) to accerlate the vector operations.
66
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/csr.c
69
+++ b/target/riscv/csr.c
70
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
71
72
static RISCVException vs(CPURISCVState *env, int csrno)
73
{
74
- if (riscv_cpu_cfg(env)->ext_zve32f) {
75
+ if (riscv_cpu_cfg(env)->ext_zve32x) {
76
#if !defined(CONFIG_USER_ONLY)
77
if (!env->debugger && !riscv_cpu_vector_enabled(env)) {
78
return RISCV_EXCP_ILLEGAL_INST;
79
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/target/riscv/tcg/tcg-cpu.c
82
+++ b/target/riscv/tcg/tcg-cpu.c
518
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
83
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
519
return;
84
return;
520
}
85
}
521
86
522
+ if (cpu->cfg.ext_zfa && !riscv_has_ext(env, RVF)) {
87
- if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) {
523
+ error_setg(errp, "Zfa extension requires F extension");
88
- error_setg(errp, "Zve32f/Zve64f extensions require F extension");
524
+ return;
89
- return;
525
+ }
90
+ /* The Zve32f extension depends on the Zve32x extension */
526
+
91
+ if (cpu->cfg.ext_zve32f) {
527
if (cpu->cfg.ext_zfh) {
92
+ if (!riscv_has_ext(env, RVF)) {
528
cpu->cfg.ext_zfhmin = true;
93
+ error_setg(errp, "Zve32f/Zve64f extensions require F extension");
94
+ return;
95
+ }
96
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
529
}
97
}
530
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
98
531
DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true),
99
if (cpu->cfg.ext_zvfh) {
532
DEFINE_PROP_BOOL("Zihintpause", RISCVCPU, cfg.ext_zihintpause, true),
100
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
533
DEFINE_PROP_BOOL("Zawrs", RISCVCPU, cfg.ext_zawrs, true),
101
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true);
534
+ DEFINE_PROP_BOOL("Zfa", RISCVCPU, cfg.ext_zfa, true),
102
}
535
DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false),
103
536
DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, false),
104
- /*
537
DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),
105
- * In principle Zve*x would also suffice here, were they supported
538
diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c
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
539
index XXXXXXX..XXXXXXX 100644
116
index XXXXXXX..XXXXXXX 100644
540
--- a/target/riscv/fpu_helper.c
117
--- a/target/riscv/insn_trans/trans_rvv.c.inc
541
+++ b/target/riscv/fpu_helper.c
118
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
542
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmin_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
119
@@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
543
float32_minimum_number(frs1, frs2, &env->fp_status));
544
}
545
546
+uint64_t helper_fminm_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
547
+{
548
+ float32 frs1 = check_nanbox_s(env, rs1);
549
+ float32 frs2 = check_nanbox_s(env, rs2);
550
+ float32 ret = float32_min(frs1, frs2, &env->fp_status);
551
+ return nanbox_s(env, ret);
552
+}
553
+
554
uint64_t helper_fmax_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
555
{
120
{
556
float32 frs1 = check_nanbox_s(env, rs1);
121
TCGv s1, dst;
557
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmax_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
122
558
float32_maximum_number(frs1, frs2, &env->fp_status));
123
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
559
}
124
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
560
125
return false;
561
+uint64_t helper_fmaxm_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
126
}
562
+{
127
563
+ float32 frs1 = check_nanbox_s(env, rs1);
128
@@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
564
+ float32 frs2 = check_nanbox_s(env, rs2);
565
+ float32 ret = float32_max(frs1, frs2, &env->fp_status);
566
+ return nanbox_s(env, ret);
567
+}
568
+
569
uint64_t helper_fsqrt_s(CPURISCVState *env, uint64_t rs1)
570
{
129
{
571
float32 frs1 = check_nanbox_s(env, rs1);
130
TCGv dst;
572
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fle_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
131
573
return float32_le(frs1, frs2, &env->fp_status);
132
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
574
}
133
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
575
134
return false;
576
+target_ulong helper_fleq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
135
}
577
+{
136
578
+ float32 frs1 = check_nanbox_s(env, rs1);
579
+ float32 frs2 = check_nanbox_s(env, rs2);
580
+ return float32_le_quiet(frs1, frs2, &env->fp_status);
581
+}
582
+
583
target_ulong helper_flt_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
584
{
585
float32 frs1 = check_nanbox_s(env, rs1);
586
@@ -XXX,XX +XXX,XX @@ target_ulong helper_flt_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
587
return float32_lt(frs1, frs2, &env->fp_status);
588
}
589
590
+target_ulong helper_fltq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
591
+{
592
+ float32 frs1 = check_nanbox_s(env, rs1);
593
+ float32 frs2 = check_nanbox_s(env, rs2);
594
+ return float32_lt_quiet(frs1, frs2, &env->fp_status);
595
+}
596
+
597
target_ulong helper_feq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
598
{
599
float32 frs1 = check_nanbox_s(env, rs1);
600
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fclass_s(CPURISCVState *env, uint64_t rs1)
601
return fclass_s(frs1);
602
}
603
604
+uint64_t helper_fround_s(CPURISCVState *env, uint64_t rs1)
605
+{
606
+ float_status *fs = &env->fp_status;
607
+ uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact;
608
+ float32 frs1 = check_nanbox_s(env, rs1);
609
+
610
+ frs1 = float32_round_to_int(frs1, fs);
611
+
612
+ /* Restore the original NX flag. */
613
+ uint16_t flags = get_float_exception_flags(fs);
614
+ flags &= ~float_flag_inexact;
615
+ flags |= nx_old;
616
+ set_float_exception_flags(flags, fs);
617
+
618
+ return nanbox_s(env, frs1);
619
+}
620
+
621
+uint64_t helper_froundnx_s(CPURISCVState *env, uint64_t rs1)
622
+{
623
+ float32 frs1 = check_nanbox_s(env, rs1);
624
+ frs1 = float32_round_to_int(frs1, &env->fp_status);
625
+ return nanbox_s(env, frs1);
626
+}
627
+
628
uint64_t helper_fadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
629
{
630
return float64_add(frs1, frs2, &env->fp_status);
631
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmin_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
632
float64_minimum_number(frs1, frs2, &env->fp_status);
633
}
634
635
+uint64_t helper_fminm_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
636
+{
637
+ return float64_min(frs1, frs2, &env->fp_status);
638
+}
639
+
640
uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
641
{
642
return env->priv_ver < PRIV_VERSION_1_11_0 ?
643
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
644
float64_maximum_number(frs1, frs2, &env->fp_status);
645
}
646
647
+uint64_t helper_fmaxm_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
648
+{
649
+ return float64_max(frs1, frs2, &env->fp_status);
650
+}
651
+
652
uint64_t helper_fcvt_s_d(CPURISCVState *env, uint64_t rs1)
653
{
654
return nanbox_s(env, float64_to_float32(rs1, &env->fp_status));
655
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fle_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
656
return float64_le(frs1, frs2, &env->fp_status);
657
}
658
659
+target_ulong helper_fleq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
660
+{
661
+ return float64_le_quiet(frs1, frs2, &env->fp_status);
662
+}
663
+
664
target_ulong helper_flt_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
665
{
666
return float64_lt(frs1, frs2, &env->fp_status);
667
}
668
669
+target_ulong helper_fltq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
670
+{
671
+ return float64_lt_quiet(frs1, frs2, &env->fp_status);
672
+}
673
+
674
target_ulong helper_feq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2)
675
{
676
return float64_eq_quiet(frs1, frs2, &env->fp_status);
677
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_w_d(CPURISCVState *env, uint64_t frs1)
678
return float64_to_int32(frs1, &env->fp_status);
679
}
680
681
+uint64_t helper_fcvtmod_w_d(CPURISCVState *env, uint64_t value)
682
+{
683
+ return float64_to_int32_modulo(value, float_round_to_zero, &env->fp_status);
684
+}
685
+
686
target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1)
687
{
688
return (int32_t)float64_to_uint32(frs1, &env->fp_status);
689
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fclass_d(uint64_t frs1)
690
return fclass_d(frs1);
691
}
692
693
+uint64_t helper_fround_d(CPURISCVState *env, uint64_t frs1)
694
+{
695
+ float_status *fs = &env->fp_status;
696
+ uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact;
697
+
698
+ frs1 = float64_round_to_int(frs1, fs);
699
+
700
+ /* Restore the original NX flag. */
701
+ uint16_t flags = get_float_exception_flags(fs);
702
+ flags &= ~float_flag_inexact;
703
+ flags |= nx_old;
704
+ set_float_exception_flags(flags, fs);
705
+
706
+ return frs1;
707
+}
708
+
709
+uint64_t helper_froundnx_d(CPURISCVState *env, uint64_t frs1)
710
+{
711
+ return float64_round_to_int(frs1, &env->fp_status);
712
+}
713
+
714
uint64_t helper_fadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
715
{
716
float16 frs1 = check_nanbox_h(env, rs1);
717
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmin_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
718
float16_minimum_number(frs1, frs2, &env->fp_status));
719
}
720
721
+uint64_t helper_fminm_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
722
+{
723
+ float16 frs1 = check_nanbox_h(env, rs1);
724
+ float16 frs2 = check_nanbox_h(env, rs2);
725
+ float16 ret = float16_min(frs1, frs2, &env->fp_status);
726
+ return nanbox_h(env, ret);
727
+}
728
+
729
uint64_t helper_fmax_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
730
{
731
float16 frs1 = check_nanbox_h(env, rs1);
732
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fmax_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
733
float16_maximum_number(frs1, frs2, &env->fp_status));
734
}
735
736
+uint64_t helper_fmaxm_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
737
+{
738
+ float16 frs1 = check_nanbox_h(env, rs1);
739
+ float16 frs2 = check_nanbox_h(env, rs2);
740
+ float16 ret = float16_max(frs1, frs2, &env->fp_status);
741
+ return nanbox_h(env, ret);
742
+}
743
+
744
uint64_t helper_fsqrt_h(CPURISCVState *env, uint64_t rs1)
745
{
746
float16 frs1 = check_nanbox_h(env, rs1);
747
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fle_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
748
return float16_le(frs1, frs2, &env->fp_status);
749
}
750
751
+target_ulong helper_fleq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
752
+{
753
+ float16 frs1 = check_nanbox_h(env, rs1);
754
+ float16 frs2 = check_nanbox_h(env, rs2);
755
+ return float16_le_quiet(frs1, frs2, &env->fp_status);
756
+}
757
+
758
target_ulong helper_flt_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
759
{
760
float16 frs1 = check_nanbox_h(env, rs1);
761
@@ -XXX,XX +XXX,XX @@ target_ulong helper_flt_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
762
return float16_lt(frs1, frs2, &env->fp_status);
763
}
764
765
+target_ulong helper_fltq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
766
+{
767
+ float16 frs1 = check_nanbox_h(env, rs1);
768
+ float16 frs2 = check_nanbox_h(env, rs2);
769
+ return float16_lt_quiet(frs1, frs2, &env->fp_status);
770
+}
771
+
772
target_ulong helper_feq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2)
773
{
774
float16 frs1 = check_nanbox_h(env, rs1);
775
@@ -XXX,XX +XXX,XX @@ target_ulong helper_fclass_h(CPURISCVState *env, uint64_t rs1)
776
return fclass_h(frs1);
777
}
778
779
+uint64_t helper_fround_h(CPURISCVState *env, uint64_t rs1)
780
+{
781
+ float_status *fs = &env->fp_status;
782
+ uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact;
783
+ float16 frs1 = check_nanbox_h(env, rs1);
784
+
785
+ frs1 = float16_round_to_int(frs1, fs);
786
+
787
+ /* Restore the original NX flag. */
788
+ uint16_t flags = get_float_exception_flags(fs);
789
+ flags &= ~float_flag_inexact;
790
+ flags |= nx_old;
791
+ set_float_exception_flags(flags, fs);
792
+
793
+ return nanbox_h(env, frs1);
794
+}
795
+
796
+uint64_t helper_froundnx_h(CPURISCVState *env, uint64_t rs1)
797
+{
798
+ float16 frs1 = check_nanbox_s(env, rs1);
799
+ frs1 = float16_round_to_int(frs1, &env->fp_status);
800
+ return nanbox_h(env, frs1);
801
+}
802
+
803
target_ulong helper_fcvt_w_h(CPURISCVState *env, uint64_t rs1)
804
{
805
float16 frs1 = check_nanbox_h(env, rs1);
806
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
807
index XXXXXXX..XXXXXXX 100644
808
--- a/target/riscv/translate.c
809
+++ b/target/riscv/translate.c
810
@@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
811
#include "insn_trans/trans_rvzicond.c.inc"
812
#include "insn_trans/trans_rvzawrs.c.inc"
813
#include "insn_trans/trans_rvzicbo.c.inc"
814
+#include "insn_trans/trans_rvzfa.c.inc"
815
#include "insn_trans/trans_rvzfh.c.inc"
816
#include "insn_trans/trans_rvk.c.inc"
817
#include "insn_trans/trans_privileged.c.inc"
818
diff --git a/tests/tcg/riscv64/test-fcvtmod.c b/tests/tcg/riscv64/test-fcvtmod.c
819
new file mode 100644
820
index XXXXXXX..XXXXXXX
821
--- /dev/null
822
+++ b/tests/tcg/riscv64/test-fcvtmod.c
823
@@ -XXX,XX +XXX,XX @@
824
+#include <stdio.h>
825
+#include <stddef.h>
826
+#include <stdint.h>
827
+
828
+#define FFLAG_NX_SHIFT 0 /* inexact */
829
+#define FFLAG_UF_SHIFT 1 /* underflow */
830
+#define FFLAG_OF_SHIFT 2 /* overflow */
831
+#define FFLAG_DZ_SHIFT 3 /* divide by zero */
832
+#define FFLAG_NV_SHIFT 4 /* invalid operation */
833
+
834
+#define FFLAG_NV (1UL << FFLAG_NV_SHIFT)
835
+#define FFLAG_DZ (1UL << FFLAG_DZ_SHIFT)
836
+#define FFLAG_OF (1UL << FFLAG_OF_SHIFT)
837
+#define FFLAG_UF (1UL << FFLAG_UF_SHIFT)
838
+#define FFLAG_NX (1UL << FFLAG_NX_SHIFT)
839
+
840
+typedef struct fp64_fcvt_fcvtmod_testcase {
841
+ const char* name;
842
+ union {
843
+ uint64_t inp_lu;
844
+ double inp_lf;
845
+ };
846
+ uint64_t exp_fcvt;
847
+ uint8_t exp_fcvt_fflags;
848
+ uint64_t exp_fcvtmod;
849
+ uint8_t exp_fcvtmod_fflags;
850
+} fp64_fcvt_fcvtmod_testcase_t;
851
+
852
+void print_fflags(uint8_t fflags)
853
+{
854
+ int set = 0;
855
+
856
+ if (fflags == 0) {
857
+ printf("-");
858
+ return;
859
+ }
860
+
861
+ if (fflags & FFLAG_NV) {
862
+ printf("%sFFLAG_NV", set ? " | " : "");
863
+ set = 1;
864
+ }
865
+ if (fflags & FFLAG_DZ) {
866
+ printf("%sFFLAG_DZ", set ? " | " : "");
867
+ set = 1;
868
+ }
869
+ if (fflags & FFLAG_OF) {
870
+ printf("%sFFLAG_OF", set ? " | " : "");
871
+ set = 1;
872
+ }
873
+ if (fflags & FFLAG_UF) {
874
+ printf("%sFFLAG_UF", set ? " | " : "");
875
+ set = 1;
876
+ }
877
+ if (fflags & FFLAG_NX) {
878
+ printf("%sFFLAG_NX", set ? " | " : "");
879
+ set = 1;
880
+ }
881
+}
882
+
883
+/* Clear all FP flags. */
884
+static inline void clear_fflags()
885
+{
886
+ __asm__ __volatile__("fsflags zero");
887
+}
888
+
889
+/* Read all FP flags. */
890
+static inline uint8_t get_fflags()
891
+{
892
+ uint64_t v;
893
+ __asm__ __volatile__("frflags %0" : "=r"(v));
894
+ return (uint8_t)v;
895
+}
896
+
897
+/* Move input value (without conversations) into an FP register. */
898
+static inline double do_fmv_d_x(uint64_t inp)
899
+{
900
+ double fpr;
901
+ __asm__ __volatile__("fmv.d.x %0, %1" : "=f"(fpr) : "r"(inp));
902
+ return fpr;
903
+}
904
+
905
+static inline uint64_t do_fcvt_w_d(uint64_t inp, uint8_t *fflags)
906
+{
907
+ uint64_t ret;
908
+ double fpr = do_fmv_d_x(inp);
909
+
910
+ clear_fflags();
911
+
912
+ __asm__ __volatile__("fcvt.w.d %0, %1, rtz" : "=r"(ret) : "f"(fpr));
913
+
914
+ *fflags = get_fflags();
915
+
916
+ return ret;
917
+}
918
+
919
+static inline uint64_t do_fcvtmod_w_d(uint64_t inp, uint8_t *fflags)
920
+{
921
+ uint64_t ret;
922
+ double fpr = do_fmv_d_x(inp);
923
+
924
+ clear_fflags();
925
+
926
+ /* fcvtmod.w.d rd, rs1, rtz = 1100001 01000 rs1 001 rd 1010011 */
927
+ asm(".insn r 0x53, 0x1, 0x61, %0, %1, f8" : "=r"(ret) : "f"(fpr));
928
+
929
+ *fflags = get_fflags();
930
+
931
+ return ret;
932
+}
933
+
934
+static const fp64_fcvt_fcvtmod_testcase_t tests[] = {
935
+ /* Zero (exp=0, frac=0) */
936
+ { .name = "+0.0",
937
+ .inp_lf = 0x0p0,
938
+ .exp_fcvt = 0x0000000000000000,
939
+ .exp_fcvt_fflags = 0,
940
+ .exp_fcvtmod = 0x0000000000000000,
941
+ .exp_fcvtmod_fflags = 0 },
942
+ { .name = "-0.0",
943
+ .inp_lf = -0x0p0,
944
+ .exp_fcvt = 0x0000000000000000,
945
+ .exp_fcvt_fflags = 0,
946
+ .exp_fcvtmod = 0x0000000000000000,
947
+ .exp_fcvtmod_fflags = 0 },
948
+
949
+ /* Subnormal: exp=0 frac!=0 */
950
+ { .name = "Subnormal frac=1",
951
+ .inp_lu = 0x0000000000000001,
952
+ .exp_fcvt = 0x0000000000000000,
953
+ .exp_fcvt_fflags = FFLAG_NX,
954
+ .exp_fcvtmod = 0,
955
+ .exp_fcvtmod_fflags = FFLAG_NX },
956
+ { .name = "Subnormal frac=0xf..f",
957
+ .inp_lu = 0x0000ffffffffffff,
958
+ .exp_fcvt = 0x0000000000000000,
959
+ .exp_fcvt_fflags = FFLAG_NX,
960
+ .exp_fcvtmod = 0,
961
+ .exp_fcvtmod_fflags = FFLAG_NX },
962
+ { .name = "Neg subnormal frac=1",
963
+ .inp_lu = 0x0000000000000001,
964
+ .exp_fcvt = 0x0000000000000000,
965
+ .exp_fcvt_fflags = FFLAG_NX,
966
+ .exp_fcvtmod = 0,
967
+ .exp_fcvtmod_fflags = FFLAG_NX },
968
+ { .name = "Neg subnormal frac=0xf..f",
969
+ .inp_lu = 0x8000ffffffffffff,
970
+ .exp_fcvt = 0x0000000000000000,
971
+ .exp_fcvt_fflags = FFLAG_NX,
972
+ .exp_fcvtmod = 0,
973
+ .exp_fcvtmod_fflags = FFLAG_NX },
974
+
975
+ /* Infinity: exp=0x7ff, frac=0 */
976
+ { .name = "+INF",
977
+ .inp_lu = 0x7ff0000000000000,
978
+ .exp_fcvt = 0x000000007fffffff, /* int32 max */
979
+ .exp_fcvt_fflags = FFLAG_NV,
980
+ .exp_fcvtmod = 0,
981
+ .exp_fcvtmod_fflags = FFLAG_NV },
982
+ { .name = "-INF",
983
+ .inp_lu = 0xfff0000000000000,
984
+ .exp_fcvt = 0xffffffff80000000, /* int32 min */
985
+ .exp_fcvt_fflags = FFLAG_NV,
986
+ .exp_fcvtmod = 0,
987
+ .exp_fcvtmod_fflags = FFLAG_NV },
988
+
989
+ /* NaN: exp=7ff, frac!=0 */
990
+ { .name = "canonical NaN",
991
+ .inp_lu = 0x7ff8000000000000,
992
+ .exp_fcvt = 0x000000007fffffff, /* int32 max */
993
+ .exp_fcvt_fflags = FFLAG_NV,
994
+ .exp_fcvtmod = 0,
995
+ .exp_fcvtmod_fflags = FFLAG_NV },
996
+ { .name = "non-canonical NaN",
997
+ .inp_lu = 0x7ff8000000100000,
998
+ .exp_fcvt = 0x000000007fffffff, /* int32 min */
999
+ .exp_fcvt_fflags = FFLAG_NV,
1000
+ .exp_fcvtmod = 0,
1001
+ .exp_fcvtmod_fflags = FFLAG_NV },
1002
+
1003
+ /* Normal numbers: exp!=0, exp!=7ff */
1004
+ { .name = "+smallest normal value",
1005
+ .inp_lu = 0x0010000000000000,
1006
+ .exp_fcvt = 0,
1007
+ .exp_fcvt_fflags = FFLAG_NX,
1008
+ .exp_fcvtmod = 0,
1009
+ .exp_fcvtmod_fflags = FFLAG_NX },
1010
+ { .name = "-smallest normal value",
1011
+ .inp_lu = 0x8010000000000000,
1012
+ .exp_fcvt = 0,
1013
+ .exp_fcvt_fflags = FFLAG_NX,
1014
+ .exp_fcvtmod = 0,
1015
+ .exp_fcvtmod_fflags = FFLAG_NX },
1016
+
1017
+ { .name = "+0.5",
1018
+ .inp_lf = 0x1p-1,
1019
+ .exp_fcvt = 0,
1020
+ .exp_fcvt_fflags = FFLAG_NX,
1021
+ .exp_fcvtmod = 0,
1022
+ .exp_fcvtmod_fflags = FFLAG_NX },
1023
+ { .name = "-0.5",
1024
+ .inp_lf = -0x1p-1,
1025
+ .exp_fcvt = 0,
1026
+ .exp_fcvt_fflags = FFLAG_NX,
1027
+ .exp_fcvtmod = 0,
1028
+ .exp_fcvtmod_fflags = FFLAG_NX },
1029
+
1030
+ { .name = "+value just below 1.0",
1031
+ .inp_lu = 0x3fefffffffffffff,
1032
+ .exp_fcvt = 0,
1033
+ .exp_fcvt_fflags = FFLAG_NX,
1034
+ .exp_fcvtmod = 0,
1035
+ .exp_fcvtmod_fflags = FFLAG_NX },
1036
+ { .name = "-value just above -1.0",
1037
+ .inp_lu = 0xbfefffffffffffff,
1038
+ .exp_fcvt = 0,
1039
+ .exp_fcvt_fflags = FFLAG_NX,
1040
+ .exp_fcvtmod = 0,
1041
+ .exp_fcvtmod_fflags = FFLAG_NX },
1042
+
1043
+ { .name = "+1.0",
1044
+ .inp_lf = 0x1p0,
1045
+ .exp_fcvt = 0x0000000000000001,
1046
+ .exp_fcvt_fflags = 0,
1047
+ .exp_fcvtmod = 0x0000000000000001,
1048
+ .exp_fcvtmod_fflags = 0 },
1049
+ { .name = "-1.0",
1050
+ .inp_lf = -0x1p0,
1051
+ .exp_fcvt = 0xffffffffffffffff,
1052
+ .exp_fcvt_fflags = 0,
1053
+ .exp_fcvtmod = 0xffffffffffffffff,
1054
+ .exp_fcvtmod_fflags = 0 },
1055
+
1056
+ { .name = "+1.5",
1057
+ .inp_lu = 0x3ff8000000000000,
1058
+ .exp_fcvt = 1,
1059
+ .exp_fcvt_fflags = FFLAG_NX,
1060
+ .exp_fcvtmod = 1,
1061
+ .exp_fcvtmod_fflags = FFLAG_NX },
1062
+ { .name = "-1.5",
1063
+ .inp_lu = 0xbff8000000000000,
1064
+ .exp_fcvt = 0xffffffffffffffff,
1065
+ .exp_fcvt_fflags = FFLAG_NX,
1066
+ .exp_fcvtmod = 0xffffffffffffffff,
1067
+ .exp_fcvtmod_fflags = FFLAG_NX },
1068
+
1069
+ { .name = "+max int32 (2147483647)",
1070
+ .inp_lu = 0x41dfffffffc00000,
1071
+ .exp_fcvt = 0x000000007fffffff,
1072
+ .exp_fcvt_fflags = 0,
1073
+ .exp_fcvtmod = 0x000000007fffffff,
1074
+ .exp_fcvtmod_fflags = 0 },
1075
+ { .name = "+max int32 +1 (2147483648)",
1076
+ .inp_lf = 0x1p31,
1077
+ .exp_fcvt = 0x000000007fffffff,
1078
+ .exp_fcvt_fflags = FFLAG_NV,
1079
+ .exp_fcvtmod = (uint64_t)-2147483648l, /* int32 min */
1080
+ .exp_fcvtmod_fflags = FFLAG_NV },
1081
+ { .name = "+max int32 +2 (2147483649)",
1082
+ .inp_lu = 0x41e0000000200000,
1083
+ .exp_fcvt = 0x000000007fffffff,
1084
+ .exp_fcvt_fflags = FFLAG_NV,
1085
+ .exp_fcvtmod = (uint64_t)-2147483647l, /* int32 min +1 */
1086
+ .exp_fcvtmod_fflags = FFLAG_NV },
1087
+
1088
+ { .name = "-max int32 (-2147483648)",
1089
+ .inp_lf = -0x1p31,
1090
+ .exp_fcvt = 0xffffffff80000000,
1091
+ .exp_fcvt_fflags = 0,
1092
+ .exp_fcvtmod = 0xffffffff80000000,
1093
+ .exp_fcvtmod_fflags = 0 },
1094
+ { .name = "-max int32 -1 (-2147483649)",
1095
+ .inp_lf = -0x1.00000002p+31,
1096
+ .exp_fcvt = 0xffffffff80000000,
1097
+ .exp_fcvt_fflags = FFLAG_NV,
1098
+ .exp_fcvtmod = 2147483647, /* int32 max */
1099
+ .exp_fcvtmod_fflags = FFLAG_NV },
1100
+ { .name = "-max int32 -2 (-2147483650)",
1101
+ .inp_lf = -0x1.00000004p+31,
1102
+ .exp_fcvt = 0xffffffff80000000,
1103
+ .exp_fcvt_fflags = FFLAG_NV,
1104
+ .exp_fcvtmod = 2147483646, /* int32 max -1 */
1105
+ .exp_fcvtmod_fflags = FFLAG_NV },
1106
+};
1107
+
1108
+int run_fcvtmod_tests()
1109
+{
1110
+ uint64_t act_fcvt;
1111
+ uint8_t act_fcvt_fflags;
1112
+ uint64_t act_fcvtmod;
1113
+ uint8_t act_fcvtmod_fflags;
1114
+
1115
+ for (size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1116
+ const fp64_fcvt_fcvtmod_testcase_t *t = &tests[i];
1117
+
1118
+ act_fcvt = do_fcvt_w_d(t->inp_lu, &act_fcvt_fflags);
1119
+ int fcvt_correct = act_fcvt == t->exp_fcvt &&
1120
+ act_fcvt_fflags == t->exp_fcvt_fflags;
1121
+ act_fcvtmod = do_fcvtmod_w_d(t->inp_lu, &act_fcvtmod_fflags);
1122
+ int fcvtmod_correct = act_fcvtmod == t->exp_fcvtmod &&
1123
+ act_fcvtmod_fflags == t->exp_fcvtmod_fflags;
1124
+
1125
+ if (fcvt_correct && fcvtmod_correct) {
1126
+ continue;
1127
+ }
1128
+
1129
+ printf("Test %zu (%s) failed!\n", i, t->name);
1130
+
1131
+ double fpr = do_fmv_d_x(t->inp_lu);
1132
+ printf("inp_lu: 0x%016lx == %lf\n", t->inp_lu, fpr);
1133
+ printf("inp_lf: %lf\n", t->inp_lf);
1134
+
1135
+ uint32_t sign = (t->inp_lu >> 63);
1136
+ uint32_t exp = (uint32_t)(t->inp_lu >> 52) & 0x7ff;
1137
+ uint64_t frac = t->inp_lu & 0xfffffffffffffull; /* significand */
1138
+ int true_exp = exp - 1023;
1139
+ int shift = true_exp - 52;
1140
+ uint64_t true_frac = frac | 1ull << 52;
1141
+
1142
+ printf("sign=%d, exp=0x%03x, frac=0x%012lx\n", sign, exp, frac);
1143
+ printf("true_exp=%d, shift=%d, true_frac=0x%016lx\n", true_exp, shift, true_frac);
1144
+
1145
+ if (!fcvt_correct) {
1146
+ printf("act_fcvt: 0x%016lx == %li\n", act_fcvt, act_fcvt);
1147
+ printf("exp_fcvt: 0x%016lx == %li\n", t->exp_fcvt, t->exp_fcvt);
1148
+ printf("act_fcvt_fflags: "); print_fflags(act_fcvt_fflags); printf("\n");
1149
+ printf("exp_fcvt_fflags: "); print_fflags(t->exp_fcvt_fflags); printf("\n");
1150
+ }
1151
+
1152
+ if (!fcvtmod_correct) {
1153
+ printf("act_fcvtmod: 0x%016lx == %li\n", act_fcvtmod, act_fcvtmod);
1154
+ printf("exp_fcvtmod: 0x%016lx == %li\n", t->exp_fcvtmod, t->exp_fcvtmod);
1155
+ printf("act_fcvtmod_fflags: "); print_fflags(act_fcvtmod_fflags); printf("\n");
1156
+ printf("exp_fcvtmod_fflags: "); print_fflags(t->exp_fcvtmod_fflags); printf("\n");
1157
+ }
1158
+
1159
+ return 1;
1160
+ }
1161
+
1162
+ return 0;
1163
+}
1164
+
1165
+int main()
1166
+{
1167
+ return run_fcvtmod_tests();
1168
+}
1169
diff --git a/target/riscv/insn_trans/trans_rvzfa.c.inc b/target/riscv/insn_trans/trans_rvzfa.c.inc
1170
new file mode 100644
1171
index XXXXXXX..XXXXXXX
1172
--- /dev/null
1173
+++ b/target/riscv/insn_trans/trans_rvzfa.c.inc
1174
@@ -XXX,XX +XXX,XX @@
1175
+/*
1176
+ * RISC-V translation routines for the Zfa Standard Extension.
1177
+ *
1178
+ * Copyright (c) 2023 Christoph Müllner, christoph.muellner@vrull.eu
1179
+ *
1180
+ * This program is free software; you can redistribute it and/or modify it
1181
+ * under the terms and conditions of the GNU General Public License,
1182
+ * version 2 or later, as published by the Free Software Foundation.
1183
+ *
1184
+ * This program is distributed in the hope it will be useful, but WITHOUT
1185
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1186
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1187
+ * more details.
1188
+ *
1189
+ * You should have received a copy of the GNU General Public License along with
1190
+ * this program. If not, see <http://www.gnu.org/licenses/>.
1191
+ */
1192
+
1193
+#define REQUIRE_ZFA(ctx) do { \
1194
+ if (!ctx->cfg_ptr->ext_zfa) { \
1195
+ return false; \
1196
+ } \
1197
+} while (0)
1198
+
1199
+#define REQUIRE_ZFH(ctx) do { \
1200
+ if (!ctx->cfg_ptr->ext_zfh) { \
1201
+ return false; \
1202
+ } \
1203
+} while (0)
1204
+
1205
+static bool trans_fli_s(DisasContext *ctx, arg_fli_s *a)
1206
+{
1207
+ REQUIRE_FPU;
1208
+ REQUIRE_ZFA(ctx);
1209
+ REQUIRE_EXT(ctx, RVF);
1210
+
1211
+ /* Values below are NaN-boxed to avoid a gen_nanbox_s(). */
1212
+ static const uint64_t fli_s_table[] = {
1213
+ 0xffffffffbf800000, /* -1.0 */
1214
+ 0xffffffff00800000, /* minimum positive normal */
1215
+ 0xffffffff37800000, /* 1.0 * 2^-16 */
1216
+ 0xffffffff38000000, /* 1.0 * 2^-15 */
1217
+ 0xffffffff3b800000, /* 1.0 * 2^-8 */
1218
+ 0xffffffff3c000000, /* 1.0 * 2^-7 */
1219
+ 0xffffffff3d800000, /* 1.0 * 2^-4 */
1220
+ 0xffffffff3e000000, /* 1.0 * 2^-3 */
1221
+ 0xffffffff3e800000, /* 0.25 */
1222
+ 0xffffffff3ea00000, /* 0.3125 */
1223
+ 0xffffffff3ec00000, /* 0.375 */
1224
+ 0xffffffff3ee00000, /* 0.4375 */
1225
+ 0xffffffff3f000000, /* 0.5 */
1226
+ 0xffffffff3f200000, /* 0.625 */
1227
+ 0xffffffff3f400000, /* 0.75 */
1228
+ 0xffffffff3f600000, /* 0.875 */
1229
+ 0xffffffff3f800000, /* 1.0 */
1230
+ 0xffffffff3fa00000, /* 1.25 */
1231
+ 0xffffffff3fc00000, /* 1.5 */
1232
+ 0xffffffff3fe00000, /* 1.75 */
1233
+ 0xffffffff40000000, /* 2.0 */
1234
+ 0xffffffff40200000, /* 2.5 */
1235
+ 0xffffffff40400000, /* 3 */
1236
+ 0xffffffff40800000, /* 4 */
1237
+ 0xffffffff41000000, /* 8 */
1238
+ 0xffffffff41800000, /* 16 */
1239
+ 0xffffffff43000000, /* 2^7 */
1240
+ 0xffffffff43800000, /* 2^8 */
1241
+ 0xffffffff47000000, /* 2^15 */
1242
+ 0xffffffff47800000, /* 2^16 */
1243
+ 0xffffffff7f800000, /* +inf */
1244
+ 0xffffffff7fc00000, /* Canonical NaN */
1245
+ };
1246
+
1247
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1248
+ tcg_gen_movi_i64(dest, fli_s_table[a->rs1]);
1249
+ gen_set_fpr_hs(ctx, a->rd, dest);
1250
+
1251
+ mark_fs_dirty(ctx);
1252
+ return true;
1253
+}
1254
+
1255
+static bool trans_fli_d(DisasContext *ctx, arg_fli_d *a)
1256
+{
1257
+ REQUIRE_FPU;
1258
+ REQUIRE_ZFA(ctx);
1259
+ REQUIRE_EXT(ctx, RVD);
1260
+
1261
+ static const uint64_t fli_d_table[] = {
1262
+ 0xbff0000000000000, /* -1.0 */
1263
+ 0x0010000000000000, /* minimum positive normal */
1264
+ 0x3ef0000000000000, /* 1.0 * 2^-16 */
1265
+ 0x3f00000000000000, /* 1.0 * 2^-15 */
1266
+ 0x3f70000000000000, /* 1.0 * 2^-8 */
1267
+ 0x3f80000000000000, /* 1.0 * 2^-7 */
1268
+ 0x3fb0000000000000, /* 1.0 * 2^-4 */
1269
+ 0x3fc0000000000000, /* 1.0 * 2^-3 */
1270
+ 0x3fd0000000000000, /* 0.25 */
1271
+ 0x3fd4000000000000, /* 0.3125 */
1272
+ 0x3fd8000000000000, /* 0.375 */
1273
+ 0x3fdc000000000000, /* 0.4375 */
1274
+ 0x3fe0000000000000, /* 0.5 */
1275
+ 0x3fe4000000000000, /* 0.625 */
1276
+ 0x3fe8000000000000, /* 0.75 */
1277
+ 0x3fec000000000000, /* 0.875 */
1278
+ 0x3ff0000000000000, /* 1.0 */
1279
+ 0x3ff4000000000000, /* 1.25 */
1280
+ 0x3ff8000000000000, /* 1.5 */
1281
+ 0x3ffc000000000000, /* 1.75 */
1282
+ 0x4000000000000000, /* 2.0 */
1283
+ 0x4004000000000000, /* 2.5 */
1284
+ 0x4008000000000000, /* 3 */
1285
+ 0x4010000000000000, /* 4 */
1286
+ 0x4020000000000000, /* 8 */
1287
+ 0x4030000000000000, /* 16 */
1288
+ 0x4060000000000000, /* 2^7 */
1289
+ 0x4070000000000000, /* 2^8 */
1290
+ 0x40e0000000000000, /* 2^15 */
1291
+ 0x40f0000000000000, /* 2^16 */
1292
+ 0x7ff0000000000000, /* +inf */
1293
+ 0x7ff8000000000000, /* Canonical NaN */
1294
+ };
1295
+
1296
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1297
+ tcg_gen_movi_i64(dest, fli_d_table[a->rs1]);
1298
+ gen_set_fpr_d(ctx, a->rd, dest);
1299
+
1300
+ mark_fs_dirty(ctx);
1301
+ return true;
1302
+}
1303
+
1304
+static bool trans_fli_h(DisasContext *ctx, arg_fli_h *a)
1305
+{
1306
+ REQUIRE_FPU;
1307
+ REQUIRE_ZFA(ctx);
1308
+ REQUIRE_ZFH(ctx);
1309
+
1310
+ /* Values below are NaN-boxed to avoid a gen_nanbox_h(). */
1311
+ static const uint64_t fli_h_table[] = {
1312
+ 0xffffffffffffbc00, /* -1.0 */
1313
+ 0xffffffffffff0400, /* minimum positive normal */
1314
+ 0xffffffffffff0100, /* 1.0 * 2^-16 */
1315
+ 0xffffffffffff0200, /* 1.0 * 2^-15 */
1316
+ 0xffffffffffff1c00, /* 1.0 * 2^-8 */
1317
+ 0xffffffffffff2000, /* 1.0 * 2^-7 */
1318
+ 0xffffffffffff2c00, /* 1.0 * 2^-4 */
1319
+ 0xffffffffffff3000, /* 1.0 * 2^-3 */
1320
+ 0xffffffffffff3400, /* 0.25 */
1321
+ 0xffffffffffff3500, /* 0.3125 */
1322
+ 0xffffffffffff3600, /* 0.375 */
1323
+ 0xffffffffffff3700, /* 0.4375 */
1324
+ 0xffffffffffff3800, /* 0.5 */
1325
+ 0xffffffffffff3900, /* 0.625 */
1326
+ 0xffffffffffff3a00, /* 0.75 */
1327
+ 0xffffffffffff3b00, /* 0.875 */
1328
+ 0xffffffffffff3c00, /* 1.0 */
1329
+ 0xffffffffffff3d00, /* 1.25 */
1330
+ 0xffffffffffff3e00, /* 1.5 */
1331
+ 0xffffffffffff3f00, /* 1.75 */
1332
+ 0xffffffffffff4000, /* 2.0 */
1333
+ 0xffffffffffff4100, /* 2.5 */
1334
+ 0xffffffffffff4200, /* 3 */
1335
+ 0xffffffffffff4400, /* 4 */
1336
+ 0xffffffffffff4800, /* 8 */
1337
+ 0xffffffffffff4c00, /* 16 */
1338
+ 0xffffffffffff5800, /* 2^7 */
1339
+ 0xffffffffffff5c00, /* 2^8 */
1340
+ 0xffffffffffff7800, /* 2^15 */
1341
+ 0xffffffffffff7c00, /* 2^16 */
1342
+ 0xffffffffffff7c00, /* +inf */
1343
+ 0xffffffffffff7e00, /* Canonical NaN */
1344
+ };
1345
+
1346
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1347
+ tcg_gen_movi_i64(dest, fli_h_table[a->rs1]);
1348
+ gen_set_fpr_hs(ctx, a->rd, dest);
1349
+
1350
+ mark_fs_dirty(ctx);
1351
+ return true;
1352
+}
1353
+
1354
+static bool trans_fminm_s(DisasContext *ctx, arg_fminm_s *a)
1355
+{
1356
+ REQUIRE_FPU;
1357
+ REQUIRE_ZFA(ctx);
1358
+ REQUIRE_EXT(ctx, RVF);
1359
+
1360
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1361
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1362
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1363
+
1364
+ gen_helper_fminm_s(dest, cpu_env, src1, src2);
1365
+ gen_set_fpr_hs(ctx, a->rd, dest);
1366
+
1367
+ mark_fs_dirty(ctx);
1368
+ return true;
1369
+}
1370
+
1371
+static bool trans_fmaxm_s(DisasContext *ctx, arg_fmaxm_s *a)
1372
+{
1373
+ REQUIRE_FPU;
1374
+ REQUIRE_ZFA(ctx);
1375
+ REQUIRE_EXT(ctx, RVF);
1376
+
1377
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1378
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1379
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1380
+
1381
+ gen_helper_fmaxm_s(dest, cpu_env, src1, src2);
1382
+ gen_set_fpr_hs(ctx, a->rd, dest);
1383
+
1384
+ mark_fs_dirty(ctx);
1385
+ return true;
1386
+}
1387
+
1388
+static bool trans_fminm_d(DisasContext *ctx, arg_fminm_d *a)
1389
+{
1390
+ REQUIRE_FPU;
1391
+ REQUIRE_ZFA(ctx);
1392
+ REQUIRE_EXT(ctx, RVD);
1393
+
1394
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1395
+ TCGv_i64 src1 = get_fpr_d(ctx, a->rs1);
1396
+ TCGv_i64 src2 = get_fpr_d(ctx, a->rs2);
1397
+
1398
+ gen_helper_fminm_d(dest, cpu_env, src1, src2);
1399
+ gen_set_fpr_d(ctx, a->rd, dest);
1400
+
1401
+ mark_fs_dirty(ctx);
1402
+ return true;
1403
+}
1404
+
1405
+static bool trans_fmaxm_d(DisasContext *ctx, arg_fmaxm_d *a)
1406
+{
1407
+ REQUIRE_FPU;
1408
+ REQUIRE_ZFA(ctx);
1409
+ REQUIRE_EXT(ctx, RVD);
1410
+
1411
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1412
+ TCGv_i64 src1 = get_fpr_d(ctx, a->rs1);
1413
+ TCGv_i64 src2 = get_fpr_d(ctx, a->rs2);
1414
+
1415
+ gen_helper_fmaxm_d(dest, cpu_env, src1, src2);
1416
+ gen_set_fpr_d(ctx, a->rd, dest);
1417
+
1418
+ mark_fs_dirty(ctx);
1419
+ return true;
1420
+}
1421
+
1422
+static bool trans_fminm_h(DisasContext *ctx, arg_fminm_h *a)
1423
+{
1424
+ REQUIRE_FPU;
1425
+ REQUIRE_ZFA(ctx);
1426
+ REQUIRE_ZFH(ctx);
1427
+
1428
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1429
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1430
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1431
+
1432
+ gen_helper_fminm_h(dest, cpu_env, src1, src2);
1433
+ gen_set_fpr_hs(ctx, a->rd, dest);
1434
+
1435
+ mark_fs_dirty(ctx);
1436
+ return true;
1437
+}
1438
+
1439
+static bool trans_fmaxm_h(DisasContext *ctx, arg_fmaxm_h *a)
1440
+{
1441
+ REQUIRE_FPU;
1442
+ REQUIRE_ZFA(ctx);
1443
+ REQUIRE_ZFH(ctx);
1444
+
1445
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1446
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1447
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1448
+
1449
+ gen_helper_fmaxm_h(dest, cpu_env, src1, src2);
1450
+ gen_set_fpr_hs(ctx, a->rd, dest);
1451
+
1452
+ mark_fs_dirty(ctx);
1453
+ return true;
1454
+}
1455
+
1456
+static bool trans_fround_s(DisasContext *ctx, arg_fround_s *a)
1457
+{
1458
+ REQUIRE_FPU;
1459
+ REQUIRE_ZFA(ctx);
1460
+ REQUIRE_EXT(ctx, RVF);
1461
+
1462
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1463
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1464
+
1465
+ gen_set_rm(ctx, a->rm);
1466
+ gen_helper_fround_s(dest, cpu_env, src1);
1467
+ gen_set_fpr_hs(ctx, a->rd, dest);
1468
+
1469
+ mark_fs_dirty(ctx);
1470
+ return true;
1471
+}
1472
+
1473
+static bool trans_froundnx_s(DisasContext *ctx, arg_froundnx_s *a)
1474
+{
1475
+ REQUIRE_FPU;
1476
+ REQUIRE_ZFA(ctx);
1477
+ REQUIRE_EXT(ctx, RVF);
1478
+
1479
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1480
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1481
+
1482
+ gen_set_rm(ctx, a->rm);
1483
+ gen_helper_froundnx_s(dest, cpu_env, src1);
1484
+ gen_set_fpr_hs(ctx, a->rd, dest);
1485
+
1486
+ mark_fs_dirty(ctx);
1487
+ return true;
1488
+}
1489
+
1490
+static bool trans_fround_d(DisasContext *ctx, arg_fround_d *a)
1491
+{
1492
+ REQUIRE_FPU;
1493
+ REQUIRE_ZFA(ctx);
1494
+ REQUIRE_EXT(ctx, RVD);
1495
+
1496
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1497
+ TCGv_i64 src1 = get_fpr_d(ctx, a->rs1);
1498
+
1499
+ gen_set_rm(ctx, a->rm);
1500
+ gen_helper_fround_d(dest, cpu_env, src1);
1501
+ gen_set_fpr_hs(ctx, a->rd, dest);
1502
+
1503
+ mark_fs_dirty(ctx);
1504
+ return true;
1505
+}
1506
+
1507
+static bool trans_froundnx_d(DisasContext *ctx, arg_froundnx_d *a)
1508
+{
1509
+ REQUIRE_FPU;
1510
+ REQUIRE_ZFA(ctx);
1511
+ REQUIRE_EXT(ctx, RVD);
1512
+
1513
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1514
+ TCGv_i64 src1 = get_fpr_d(ctx, a->rs1);
1515
+
1516
+ gen_set_rm(ctx, a->rm);
1517
+ gen_helper_froundnx_d(dest, cpu_env, src1);
1518
+ gen_set_fpr_hs(ctx, a->rd, dest);
1519
+
1520
+ mark_fs_dirty(ctx);
1521
+ return true;
1522
+}
1523
+
1524
+static bool trans_fround_h(DisasContext *ctx, arg_fround_h *a)
1525
+{
1526
+ REQUIRE_FPU;
1527
+ REQUIRE_ZFA(ctx);
1528
+ REQUIRE_ZFH(ctx);
1529
+
1530
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1531
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1532
+
1533
+ gen_set_rm(ctx, a->rm);
1534
+ gen_helper_fround_h(dest, cpu_env, src1);
1535
+ gen_set_fpr_hs(ctx, a->rd, dest);
1536
+
1537
+ mark_fs_dirty(ctx);
1538
+ return true;
1539
+}
1540
+
1541
+static bool trans_froundnx_h(DisasContext *ctx, arg_froundnx_h *a)
1542
+{
1543
+ REQUIRE_FPU;
1544
+ REQUIRE_ZFA(ctx);
1545
+ REQUIRE_ZFH(ctx);
1546
+
1547
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
1548
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1549
+
1550
+ gen_set_rm(ctx, a->rm);
1551
+ gen_helper_froundnx_h(dest, cpu_env, src1);
1552
+ gen_set_fpr_hs(ctx, a->rd, dest);
1553
+
1554
+ mark_fs_dirty(ctx);
1555
+ return true;
1556
+}
1557
+
1558
+bool trans_fcvtmod_w_d(DisasContext *ctx, arg_fcvtmod_w_d *a)
1559
+{
1560
+ REQUIRE_FPU;
1561
+ REQUIRE_ZFA(ctx);
1562
+ REQUIRE_EXT(ctx, RVD);
1563
+
1564
+ TCGv dst = dest_gpr(ctx, a->rd);
1565
+ TCGv_i64 src1 = get_fpr_d(ctx, a->rs1);
1566
+ TCGv_i64 t1 = tcg_temp_new_i64();
1567
+
1568
+ /* Rounding mode is RTZ. */
1569
+ gen_set_rm(ctx, RISCV_FRM_RTZ);
1570
+ gen_helper_fcvtmod_w_d(t1, cpu_env, src1);
1571
+ tcg_gen_trunc_i64_tl(dst, t1);
1572
+ gen_set_gpr(ctx, a->rd, dst);
1573
+
1574
+ return true;
1575
+}
1576
+
1577
+bool trans_fmvh_x_d(DisasContext *ctx, arg_fmvh_x_d *a)
1578
+{
1579
+ REQUIRE_FPU;
1580
+ REQUIRE_ZFA(ctx);
1581
+ REQUIRE_EXT(ctx, RVD);
1582
+ REQUIRE_32BIT(ctx);
1583
+
1584
+ TCGv dst = dest_gpr(ctx, a->rd);
1585
+ TCGv_i64 t1 = tcg_temp_new_i64();
1586
+ tcg_gen_sari_i64(t1, cpu_fpr[a->rs1], 32);
1587
+ tcg_gen_trunc_i64_tl(dst, t1);
1588
+ gen_set_gpr(ctx, a->rd, dst);
1589
+ return true;
1590
+}
1591
+
1592
+bool trans_fmvp_d_x(DisasContext *ctx, arg_fmvp_d_x *a)
1593
+{
1594
+ REQUIRE_FPU;
1595
+ REQUIRE_ZFA(ctx);
1596
+ REQUIRE_EXT(ctx, RVD);
1597
+ REQUIRE_32BIT(ctx);
1598
+
1599
+ TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE);
1600
+ TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
1601
+ tcg_gen_concat_tl_i64(cpu_fpr[a->rd], src1, src2);
1602
+
1603
+ mark_fs_dirty(ctx);
1604
+ return true;
1605
+}
1606
+
1607
+bool trans_fleq_s(DisasContext *ctx, arg_fleq_s *a)
1608
+{
1609
+ REQUIRE_FPU;
1610
+ REQUIRE_ZFA(ctx);
1611
+ REQUIRE_EXT(ctx, RVF);
1612
+
1613
+ TCGv dest = dest_gpr(ctx, a->rd);
1614
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1615
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1616
+
1617
+ gen_helper_fleq_s(dest, cpu_env, src1, src2);
1618
+ gen_set_gpr(ctx, a->rd, dest);
1619
+ return true;
1620
+}
1621
+
1622
+bool trans_fltq_s(DisasContext *ctx, arg_fltq_s *a)
1623
+{
1624
+ REQUIRE_FPU;
1625
+ REQUIRE_ZFA(ctx);
1626
+ REQUIRE_EXT(ctx, RVF);
1627
+
1628
+ TCGv dest = dest_gpr(ctx, a->rd);
1629
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1630
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1631
+
1632
+ gen_helper_fltq_s(dest, cpu_env, src1, src2);
1633
+ gen_set_gpr(ctx, a->rd, dest);
1634
+ return true;
1635
+}
1636
+
1637
+bool trans_fleq_d(DisasContext *ctx, arg_fleq_d *a)
1638
+{
1639
+ REQUIRE_FPU;
1640
+ REQUIRE_ZFA(ctx);
1641
+ REQUIRE_EXT(ctx, RVD);
1642
+
1643
+ TCGv dest = dest_gpr(ctx, a->rd);
1644
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1645
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1646
+
1647
+ gen_helper_fltq_s(dest, cpu_env, src1, src2);
1648
+ gen_set_gpr(ctx, a->rd, dest);
1649
+ return true;
1650
+}
1651
+
1652
+bool trans_fltq_d(DisasContext *ctx, arg_fltq_d *a)
1653
+{
1654
+ REQUIRE_FPU;
1655
+ REQUIRE_ZFA(ctx);
1656
+ REQUIRE_EXT(ctx, RVD);
1657
+
1658
+ TCGv dest = dest_gpr(ctx, a->rd);
1659
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1660
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1661
+
1662
+ gen_helper_fltq_s(dest, cpu_env, src1, src2);
1663
+ gen_set_gpr(ctx, a->rd, dest);
1664
+ return true;
1665
+}
1666
+
1667
+bool trans_fleq_h(DisasContext *ctx, arg_fleq_h *a)
1668
+{
1669
+ REQUIRE_FPU;
1670
+ REQUIRE_ZFA(ctx);
1671
+ REQUIRE_ZFH(ctx);
1672
+
1673
+ TCGv dest = dest_gpr(ctx, a->rd);
1674
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1675
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1676
+
1677
+ gen_helper_fleq_h(dest, cpu_env, src1, src2);
1678
+ gen_set_gpr(ctx, a->rd, dest);
1679
+ return true;
1680
+}
1681
+
1682
+bool trans_fltq_h(DisasContext *ctx, arg_fltq_h *a)
1683
+{
1684
+ REQUIRE_FPU;
1685
+ REQUIRE_ZFA(ctx);
1686
+ REQUIRE_ZFH(ctx);
1687
+
1688
+ TCGv dest = dest_gpr(ctx, a->rd);
1689
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
1690
+ TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2);
1691
+
1692
+ gen_helper_fltq_h(dest, cpu_env, src1, src2);
1693
+ gen_set_gpr(ctx, a->rd, dest);
1694
+ return true;
1695
+}
1696
diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target
1697
index XXXXXXX..XXXXXXX 100644
1698
--- a/tests/tcg/riscv64/Makefile.target
1699
+++ b/tests/tcg/riscv64/Makefile.target
1700
@@ -XXX,XX +XXX,XX @@ run-test-noc: QEMU_OPTS += -cpu rv64,c=false
1701
1702
TESTS += test-aes
1703
run-test-aes: QEMU_OPTS += -cpu rv64,zk=on
1704
+
1705
+# Test for fcvtmod
1706
+TESTS += test-fcvtmod
1707
+test-fcvtmod: CFLAGS += -march=rv64imafdc
1708
+test-fcvtmod: LDFLAGS += -static
1709
+run-test-fcvtmod: QEMU_OPTS += -cpu rv64,d=true,Zfa=true
1710
--
137
--
1711
2.40.1
138
2.45.1
1712
1713
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
Add ext_zfbfmin/zvfbfmin/zvfbfwma properties.
3
Add support for Zve64x extension. Enabling Zve64f enables Zve64x and
4
Add require check for BF16 extensions.
4
enabling Zve64x enables Zve32x according to their dependency.
5
5
6
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107
7
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
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>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-Id: <20230615063302.102409-2-liweiwei@iscas.ac.cn>
11
Message-ID: <20240328022343.6871-3-jason.chien@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
13
---
12
target/riscv/cpu_cfg.h | 3 +++
14
target/riscv/cpu_cfg.h | 1 +
13
target/riscv/cpu.c | 20 ++++++++++++++++++++
15
target/riscv/cpu.c | 2 ++
14
2 files changed, 23 insertions(+)
16
target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------
17
3 files changed, 14 insertions(+), 6 deletions(-)
15
18
16
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
19
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
17
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/cpu_cfg.h
21
--- a/target/riscv/cpu_cfg.h
19
+++ b/target/riscv/cpu_cfg.h
22
+++ b/target/riscv/cpu_cfg.h
20
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
21
bool ext_svpbmt;
24
bool ext_zve32x;
22
bool ext_zdinx;
23
bool ext_zawrs;
24
+ bool ext_zfbfmin;
25
bool ext_zfh;
26
bool ext_zfhmin;
27
bool ext_zfinx;
28
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
29
bool ext_zve64f;
25
bool ext_zve64f;
30
bool ext_zve64d;
26
bool ext_zve64d;
31
bool ext_zmmul;
27
+ bool ext_zve64x;
32
+ bool ext_zvfbfmin;
28
bool ext_zvbb;
33
+ bool ext_zvfbfwma;
29
bool ext_zvbc;
34
bool ext_zvfh;
30
bool ext_zvkb;
35
bool ext_zvfhmin;
36
bool ext_smaia;
37
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
38
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
39
--- a/target/riscv/cpu.c
33
--- a/target/riscv/cpu.c
40
+++ b/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
36
ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
37
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
38
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
39
+ ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x),
40
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
41
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
42
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
43
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
44
MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
45
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
46
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
47
+ MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false),
48
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
49
MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false),
50
MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
51
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/tcg/tcg-cpu.c
54
+++ b/target/riscv/tcg/tcg-cpu.c
55
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
56
57
/* The Zve64d extension depends on the Zve64f extension */
58
if (cpu->cfg.ext_zve64d) {
59
+ if (!riscv_has_ext(env, RVD)) {
60
+ error_setg(errp, "Zve64d/V extensions require D extension");
61
+ return;
62
+ }
63
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true);
64
}
65
66
- /* The Zve64f extension depends on the Zve32f extension */
67
+ /* The Zve64f extension depends on the Zve64x and Zve32f extensions */
68
if (cpu->cfg.ext_zve64f) {
69
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true);
70
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true);
71
}
72
73
- if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) {
74
- error_setg(errp, "Zve64d/V extensions require D extension");
75
- return;
76
+ /* The Zve64x extension depends on the Zve32x extension */
77
+ if (cpu->cfg.ext_zve64x) {
78
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
79
}
80
81
/* The Zve32f extension depends on the Zve32x extension */
41
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
82
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
42
return;
83
return;
43
}
84
}
44
85
45
+ if (cpu->cfg.ext_zfbfmin && !riscv_has_ext(env, RVF)) {
86
- if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) {
46
+ error_setg(errp, "Zfbfmin extension depends on F extension");
87
+ if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) {
47
+ return;
88
error_setg(
48
+ }
89
errp,
49
+
90
- "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions");
50
if (riscv_has_ext(env, RVD) && !riscv_has_ext(env, RVF)) {
91
+ "Zvbc and Zvknhb extensions require V or Zve64x extensions");
51
error_setg(errp, "D extension requires F extension");
52
return;
53
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
54
return;
92
return;
55
}
93
}
56
94
57
+ if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zfbfmin) {
58
+ error_setg(errp, "Zvfbfmin extension depends on Zfbfmin extension");
59
+ return;
60
+ }
61
+
62
+ if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zve32f) {
63
+ error_setg(errp, "Zvfbfmin extension depends on Zve32f extension");
64
+ return;
65
+ }
66
+
67
+ if (cpu->cfg.ext_zvfbfwma && !cpu->cfg.ext_zvfbfmin) {
68
+ error_setg(errp, "Zvfbfwma extension depends on Zvfbfmin extension");
69
+ return;
70
+ }
71
+
72
/* Set the ISA extensions, checks should have happened above */
73
if (cpu->cfg.ext_zhinx) {
74
cpu->cfg.ext_zhinxmin = true;
75
--
95
--
76
2.40.1
96
2.45.1
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
The privileged spec states:
3
In current implementation, the gdbstub allows reading vector registers
4
For a memory access made to support VS-stage address translation (such as
4
only if V extension is supported. However, all vector extensions and
5
to read/write a VS-level page table), permissions are checked as though
5
vector crypto extensions have the vector registers and they all depend
6
for a load or store, not for the original access type. However, any
6
on Zve32x. The gdbstub should check for Zve32x instead.
7
exception is always reported for the original access type (instruction,
8
load, or store/AMO).
9
10
The current implementation converts the access type to LOAD if implicit
11
G-stage translation fails which results in only reporting "Load guest-page
12
fault". This commit removes the convertion of access type, so the reported
13
exception conforms to the spec.
14
7
15
Signed-off-by: Jason Chien <jason.chien@sifive.com>
8
Signed-off-by: Jason Chien <jason.chien@sifive.com>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Frank Chang <frank.chang@sifive.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
18
Message-Id: <20230627074915.7686-1-jason.chien@sifive.com>
11
Message-ID: <20240328022343.6871-4-jason.chien@sifive.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
---
13
---
21
target/riscv/cpu_helper.c | 1 -
14
target/riscv/gdbstub.c | 2 +-
22
1 file changed, 1 deletion(-)
15
1 file changed, 1 insertion(+), 1 deletion(-)
23
16
24
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
25
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu_helper.c
19
--- a/target/riscv/gdbstub.c
27
+++ b/target/riscv/cpu_helper.c
20
+++ b/target/riscv/gdbstub.c
28
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
29
if (ret == TRANSLATE_G_STAGE_FAIL) {
22
gdb_find_static_feature("riscv-32bit-fpu.xml"),
30
first_stage_error = false;
23
0);
31
two_stage_indirect_error = true;
24
}
32
- access_type = MMU_DATA_LOAD;
25
- if (env->misa_ext & RVV) {
33
}
26
+ if (cpu->cfg.ext_zve32x) {
34
27
gdb_register_coprocessor(cs, riscv_gdb_get_vector,
35
qemu_log_mask(CPU_LOG_MMU,
28
riscv_gdb_set_vector,
29
ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs),
36
--
30
--
37
2.40.1
31
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
2
3
Allow 'marchid' and 'mimpid' to also be initialized in
3
In RVV and vcrypto instructions, the masked and tail elements are set to 1s
4
kvm_riscv_init_machine_ids().
4
using vext_set_elems_1s function if the vma/vta bit is set. It is the element
5
agnostic policy.
5
6
6
After this change, the handling of mvendorid/marchid/mimpid for the
7
However, this function can't deal the big endian situation. This patch fixes
7
'host' CPU type will be equal to what we already have for TCG named
8
the problem by adding handling of such case.
8
CPUs, i.e. the user is not able to set these values to a different val
9
than the one that is already preset.
10
9
11
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
13
Acked-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
14
Message-Id: <20230706101738.460804-8-dbarboza@ventanamicro.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>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
16
---
17
target/riscv/kvm.c | 16 ++++++++++++++++
17
target/riscv/vector_internals.c | 22 ++++++++++++++++++++++
18
1 file changed, 16 insertions(+)
18
1 file changed, 22 insertions(+)
19
19
20
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
20
diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c
21
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/kvm.c
22
--- a/target/riscv/vector_internals.c
23
+++ b/target/riscv/kvm.c
23
+++ b/target/riscv/vector_internals.c
24
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
24
@@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
25
if (ret != 0) {
25
if (tot - cnt == 0) {
26
error_report("Unable to retrieve mvendorid from host, error %d", ret);
26
return ;
27
}
27
}
28
+
28
+
29
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
29
+ if (HOST_BIG_ENDIAN) {
30
+ KVM_REG_RISCV_CONFIG_REG(marchid));
30
+ /*
31
+ reg.addr = (uint64_t)&cpu->cfg.marchid;
31
+ * Deal the situation when the elements are insdie
32
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
32
+ * only one uint64 block including setting the
33
+ if (ret != 0) {
33
+ * masked-off element.
34
+ error_report("Unable to retrieve marchid from host, error %d", ret);
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 */
35
+ }
49
+ }
36
+
50
memset(base + cnt, -1, tot - cnt);
37
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
38
+ KVM_REG_RISCV_CONFIG_REG(mimpid));
39
+ reg.addr = (uint64_t)&cpu->cfg.mimpid;
40
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
41
+ if (ret != 0) {
42
+ error_report("Unable to retrieve mimpid from host, error %d", ret);
43
+ }
44
}
51
}
45
52
46
void kvm_riscv_init_user_properties(Object *cpu_obj)
47
--
53
--
48
2.40.1
54
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Yangyu Chen <cyy@cyyself.name>
2
2
3
riscv_cpu_add_user_properties() ended up with an excess of "#ifndef
3
This code has a typo that writes zvkb to zvkg, causing users can't
4
CONFIG_USER_ONLY" blocks after changes that added KVM properties
4
enable zvkb through the config. This patch gets this fixed.
5
handling.
6
5
7
KVM specific properties are required to be created earlier than their
6
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
8
TCG counterparts, but the remaining props can be created at any order.
7
Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions")
9
Move riscv_add_satp_mode_properties() to the start of the function,
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
10
inside the !CONFIG_USER_ONLY block already present there, to remove the
11
last ifndef block.
12
13
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
14
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
15
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
16
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
17
Message-Id: <20230706101738.460804-16-dbarboza@ventanamicro.com>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
11
Reviewed-by:  Weiwei Li <liwei1518@gmail.com>
12
Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
15
---
20
target/riscv/cpu.c | 6 ++----
16
target/riscv/cpu.c | 2 +-
21
1 file changed, 2 insertions(+), 4 deletions(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
22
18
23
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
24
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
25
--- a/target/riscv/cpu.c
21
--- a/target/riscv/cpu.c
26
+++ b/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
27
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
23
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
28
DeviceState *dev = DEVICE(obj);
24
/* Vector cryptography extensions */
29
25
MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
30
#ifndef CONFIG_USER_ONLY
26
MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false),
31
+ riscv_add_satp_mode_properties(obj);
27
- MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false),
32
+
28
+ MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false),
33
if (kvm_enabled()) {
29
MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false),
34
kvm_riscv_init_user_properties(obj);
30
MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false),
35
}
31
MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false),
36
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
37
#endif
38
qdev_property_add_static(dev, prop);
39
}
40
-
41
-#ifndef CONFIG_USER_ONLY
42
- riscv_add_satp_mode_properties(obj);
43
-#endif
44
}
45
46
static Property riscv_cpu_properties[] = {
47
--
32
--
48
2.40.1
33
2.45.1
49
34
50
35
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
2
3
As specified in privilege spec:"When MPRV=1, load and store memory
3
In this patch, we modify the decoder to be a freely composable data
4
addresses are treated as though the current XLEN were set to MPP’s
4
structure instead of a hardcoded one. It can be dynamically builded up
5
XLEN". So the xlen for address may be different from current xlen.
5
according to the extensions.
6
This approach has several benefits:
7
1. Provides support for heterogeneous cpu architectures. As we add decoder in
8
RISCVCPU, each cpu can have their own decoder, and the decoders can be
9
different due to cpu's features.
10
2. Improve the decoding efficiency. We run the guard_func to see if the decoder
11
can be added to the dynamic_decoder when building up the decoder. Therefore,
12
there is no need to run the guard_func when decoding each instruction. It can
13
improve the decoding efficiency
14
3. For vendor or dynamic cpus, it allows them to customize their own decoder
15
functions to improve decoding efficiency, especially when vendor-defined
16
instruction sets increase. Because of dynamic building up, it can skip the other
17
decoder guard functions when decoding.
18
4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal
19
overhead for users that don't need this particular vendor decoder.
6
20
7
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
21
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
8
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
22
Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu>
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
23
Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
10
Message-Id: <20230614032547.35895-2-liweiwei@iscas.ac.cn>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
28
---
13
target/riscv/cpu.h | 49 +++++++++++++++++++++++++++++++++------
29
target/riscv/cpu.h | 1 +
14
target/riscv/cpu_helper.c | 1 +
30
target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++
15
target/riscv/translate.c | 13 ++++++++++-
31
target/riscv/cpu.c | 1 +
16
3 files changed, 55 insertions(+), 8 deletions(-)
32
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
33
target/riscv/translate.c | 31 +++++++++++++++----------------
34
5 files changed, 47 insertions(+), 16 deletions(-)
17
35
18
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
36
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
19
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/cpu.h
38
--- a/target/riscv/cpu.h
21
+++ b/target/riscv/cpu.h
39
+++ b/target/riscv/cpu.h
22
@@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, ITRIGGER, 22, 1)
40
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
23
/* Virtual mode enabled */
41
uint32_t pmu_avail_ctrs;
24
FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1)
42
/* Mapping of events to counters */
25
FIELD(TB_FLAGS, PRIV, 24, 2)
43
GHashTable *pmu_event_ctr_map;
26
+FIELD(TB_FLAGS, AXL, 26, 2)
44
+ const GPtrArray *decoders;
27
45
};
28
#ifdef TARGET_RISCV32
46
29
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
47
/**
30
@@ -XXX,XX +XXX,XX @@ static inline const RISCVCPUConfig *riscv_cpu_cfg(CPURISCVState *env)
48
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
31
return &env_archcpu(env)->cfg;
49
index XXXXXXX..XXXXXXX 100644
50
--- a/target/riscv/tcg/tcg-cpu.h
51
+++ b/target/riscv/tcg/tcg-cpu.h
52
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
53
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
54
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu);
55
56
+struct DisasContext;
57
+struct RISCVCPUConfig;
58
+typedef struct RISCVDecoder {
59
+ bool (*guard_func)(const struct RISCVCPUConfig *);
60
+ bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
61
+} RISCVDecoder;
62
+
63
+typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
64
+
65
+extern const size_t decoder_table_size;
66
+
67
+extern const RISCVDecoder decoder_table[];
68
+
69
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu);
70
+
71
#endif
72
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
73
index XXXXXXX..XXXXXXX 100644
74
--- a/target/riscv/cpu.c
75
+++ b/target/riscv/cpu.c
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
77
error_propagate(errp, local_err);
78
return;
79
}
80
+ riscv_tcg_cpu_finalize_dynamic_decoder(cpu);
81
} else if (kvm_enabled()) {
82
riscv_kvm_cpu_finalize_features(cpu, &local_err);
83
if (local_err != NULL) {
84
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/tcg/tcg-cpu.c
87
+++ b/target/riscv/tcg/tcg-cpu.c
88
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
89
}
32
}
90
}
33
91
34
-#if defined(TARGET_RISCV32)
92
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
35
-#define cpu_recompute_xl(env) ((void)(env), MXL_RV32)
36
-#else
37
-static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
38
+#if !defined(CONFIG_USER_ONLY)
39
+static inline int cpu_address_mode(CPURISCVState *env)
40
+{
93
+{
41
+ int mode = env->priv;
94
+ GPtrArray *dynamic_decoders;
95
+ dynamic_decoders = g_ptr_array_sized_new(decoder_table_size);
96
+ for (size_t i = 0; i < decoder_table_size; ++i) {
97
+ if (decoder_table[i].guard_func &&
98
+ decoder_table[i].guard_func(&cpu->cfg)) {
99
+ g_ptr_array_add(dynamic_decoders,
100
+ (gpointer)decoder_table[i].riscv_cpu_decode_fn);
101
+ }
102
+ }
42
+
103
+
43
+ if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) {
104
+ cpu->decoders = dynamic_decoders;
44
+ mode = get_field(env->mstatus, MSTATUS_MPP);
45
+ }
46
+ return mode;
47
+}
105
+}
48
+
106
+
49
+static inline RISCVMXL cpu_get_xl(CPURISCVState *env, target_ulong mode)
107
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu)
50
{
108
{
51
RISCVMXL xl = env->misa_mxl;
109
return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL;
52
-#if !defined(CONFIG_USER_ONLY)
53
/*
54
* When emulating a 32-bit-only cpu, use RV32.
55
* When emulating a 64-bit cpu, and MXL has been reduced to RV32,
56
@@ -XXX,XX +XXX,XX @@ static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
57
* back to RV64 for lower privs.
58
*/
59
if (xl != MXL_RV32) {
60
- switch (env->priv) {
61
+ switch (mode) {
62
case PRV_M:
63
break;
64
case PRV_U:
65
@@ -XXX,XX +XXX,XX @@ static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
66
break;
67
}
68
}
69
-#endif
70
return xl;
71
}
72
#endif
73
74
+#if defined(TARGET_RISCV32)
75
+#define cpu_recompute_xl(env) ((void)(env), MXL_RV32)
76
+#else
77
+static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
78
+{
79
+#if !defined(CONFIG_USER_ONLY)
80
+ return cpu_get_xl(env, env->priv);
81
+#else
82
+ return env->misa_mxl;
83
+#endif
84
+}
85
+#endif
86
+
87
+#if defined(TARGET_RISCV32)
88
+#define cpu_address_xl(env) ((void)(env), MXL_RV32)
89
+#else
90
+static inline RISCVMXL cpu_address_xl(CPURISCVState *env)
91
+{
92
+#ifdef CONFIG_USER_ONLY
93
+ return env->xl;
94
+#else
95
+ int mode = cpu_address_mode(env);
96
+
97
+ return cpu_get_xl(env, mode);
98
+#endif
99
+}
100
+#endif
101
+
102
static inline int riscv_cpu_xlen(CPURISCVState *env)
103
{
104
return 16 << env->xl;
105
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
106
index XXXXXXX..XXXXXXX 100644
107
--- a/target/riscv/cpu_helper.c
108
+++ b/target/riscv/cpu_helper.c
109
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
110
flags = FIELD_DP32(flags, TB_FLAGS, FS, fs);
111
flags = FIELD_DP32(flags, TB_FLAGS, VS, vs);
112
flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl);
113
+ flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env));
114
if (env->cur_pmmask != 0) {
115
flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1);
116
}
117
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
110
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
118
index XXXXXXX..XXXXXXX 100644
111
index XXXXXXX..XXXXXXX 100644
119
--- a/target/riscv/translate.c
112
--- a/target/riscv/translate.c
120
+++ b/target/riscv/translate.c
113
+++ b/target/riscv/translate.c
114
@@ -XXX,XX +XXX,XX @@
115
#include "exec/helper-info.c.inc"
116
#undef HELPER_H
117
118
+#include "tcg/tcg-cpu.h"
119
+
120
/* global register indices */
121
static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart;
122
static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
121
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
123
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
122
target_ulong priv_ver;
124
/* FRM is known to contain a valid value. */
123
RISCVMXL misa_mxl_max;
125
bool frm_valid;
124
RISCVMXL xl;
126
bool insn_start_updated;
125
+ RISCVMXL address_xl;
127
+ const GPtrArray *decoders;
126
uint32_t misa_ext;
128
} DisasContext;
127
uint32_t opcode;
129
128
RISCVExtStatus mstatus_fs;
130
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
129
@@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
131
@@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word)
130
#define get_xl(ctx) ((ctx)->xl)
132
return (first_word & 3) == 3 ? 4 : 2;
131
#endif
133
}
132
134
133
+#ifdef TARGET_RISCV32
135
+const RISCVDecoder decoder_table[] = {
134
+#define get_address_xl(ctx) MXL_RV32
136
+ { always_true_p, decode_insn32 },
135
+#elif defined(CONFIG_USER_ONLY)
137
+ { has_xthead_p, decode_xthead},
136
+#define get_address_xl(ctx) MXL_RV64
138
+ { has_XVentanaCondOps_p, decode_XVentanaCodeOps},
137
+#else
139
+};
138
+#define get_address_xl(ctx) ((ctx)->address_xl)
139
+#endif
140
+
140
+
141
/* The word size for this machine mode. */
141
+const size_t decoder_table_size = ARRAY_SIZE(decoder_table);
142
static inline int __attribute__((unused)) get_xlen(DisasContext *ctx)
142
+
143
static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
143
{
144
{
144
@@ -XXX,XX +XXX,XX @@ static TCGv get_address(DisasContext *ctx, int rs1, int imm)
145
- /*
145
tcg_gen_addi_tl(addr, src1, imm);
146
- * A table with predicate (i.e., guard) functions and decoder functions
146
if (ctx->pm_mask_enabled) {
147
- * that are tested in-order until a decoder matches onto the opcode.
147
tcg_gen_andc_tl(addr, addr, pm_mask);
148
- */
148
- } else if (get_xl(ctx) == MXL_RV32) {
149
- static const struct {
149
+ } else if (get_address_xl(ctx) == MXL_RV32) {
150
- bool (*guard_func)(const RISCVCPUConfig *);
150
tcg_gen_ext32u_tl(addr, addr);
151
- bool (*decode_func)(DisasContext *, uint32_t);
151
}
152
- } decoders[] = {
152
if (ctx->pm_base_enabled) {
153
- { always_true_p, decode_insn32 },
153
tcg_gen_or_tl(addr, addr, pm_base);
154
- { has_xthead_p, decode_xthead },
154
}
155
- { has_XVentanaCondOps_p, decode_XVentanaCodeOps },
155
+
156
- };
156
return addr;
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;
157
}
179
}
158
180
159
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
181
static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
160
ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX);
161
ctx->misa_mxl_max = env->misa_mxl_max;
162
ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
163
+ ctx->address_xl = FIELD_EX32(tb_flags, TB_FLAGS, AXL);
164
ctx->cs = cs;
165
ctx->pm_mask_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_MASK_ENABLED);
166
ctx->pm_base_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLED);
167
--
182
--
168
2.40.1
183
2.45.1
169
170
diff view generated by jsdifflib
1
From: Tommy Wu <tommy.wu@sifive.com>
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
2
3
The watchdog timer is in the always-on domain device of HiFive 1 rev b,
3
The th.sxstatus CSR can be used to identify available custom extension
4
so this patch added the AON device to the sifive_e machine. This patch
4
on T-Head CPUs. The CSR is documented here:
5
only implemented the functionality of the watchdog timer.
5
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc
6
6
7
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
7
An important property of this patch is, that the th.sxstatus MAEE field
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
is not set (indicating that XTheadMae is not available).
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
XTheadMae is a memory attribute extension (similar to Svpbmt) which is
10
Message-Id: <20230627141216.3962299-2-tommy.wu@sifive.com>
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>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
25
---
13
include/hw/misc/sifive_e_aon.h | 60 +++++++
26
MAINTAINERS | 1 +
14
hw/misc/sifive_e_aon.c | 319 +++++++++++++++++++++++++++++++++
27
target/riscv/cpu.h | 3 ++
15
hw/misc/Kconfig | 3 +
28
target/riscv/cpu.c | 1 +
16
hw/misc/meson.build | 1 +
29
target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++
17
4 files changed, 383 insertions(+)
30
target/riscv/meson.build | 1 +
18
create mode 100644 include/hw/misc/sifive_e_aon.h
31
5 files changed, 85 insertions(+)
19
create mode 100644 hw/misc/sifive_e_aon.c
32
create mode 100644 target/riscv/th_csr.c
20
33
21
diff --git a/include/hw/misc/sifive_e_aon.h b/include/hw/misc/sifive_e_aon.h
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
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/cpu.h
49
+++ b/target/riscv/cpu.h
50
@@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value,
51
uint8_t satp_mode_max_from_map(uint32_t map);
52
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
53
54
+/* Implemented in th_csr.c */
55
+void th_register_custom_csrs(RISCVCPU *cpu);
56
+
57
#endif /* RISCV_CPU_H */
58
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/target/riscv/cpu.c
61
+++ b/target/riscv/cpu.c
62
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
63
cpu->cfg.mvendorid = THEAD_VENDOR_ID;
64
#ifndef CONFIG_USER_ONLY
65
set_satp_mode_max_supported(cpu, VM_1_10_SV39);
66
+ th_register_custom_csrs(cpu);
67
#endif
68
69
/* inherited from parent obj via riscv_cpu_init() */
70
diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c
22
new file mode 100644
71
new file mode 100644
23
index XXXXXXX..XXXXXXX
72
index XXXXXXX..XXXXXXX
24
--- /dev/null
73
--- /dev/null
25
+++ b/include/hw/misc/sifive_e_aon.h
74
+++ b/target/riscv/th_csr.c
26
@@ -XXX,XX +XXX,XX @@
75
@@ -XXX,XX +XXX,XX @@
27
+/*
76
+/*
28
+ * SiFive HiFive1 AON (Always On Domain) interface.
77
+ * T-Head-specific CSRs.
29
+ *
78
+ *
30
+ * Copyright (c) 2022 SiFive, Inc. All rights reserved.
79
+ * Copyright (c) 2024 VRULL GmbH
31
+ *
32
+ * This program is free software; you can redistribute it and/or modify it
33
+ * under the terms and conditions of the GNU General Public License,
34
+ * version 2 or later, as published by the Free Software Foundation.
35
+ *
36
+ * This program is distributed in the hope it will be useful, but WITHOUT
37
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
39
+ * more details.
40
+ *
41
+ * You should have received a copy of the GNU General Public License along with
42
+ * this program. If not, see <http://www.gnu.org/licenses/>.
43
+ */
44
+
45
+#ifndef HW_SIFIVE_AON_H
46
+#define HW_SIFIVE_AON_H
47
+
48
+#include "hw/sysbus.h"
49
+#include "qom/object.h"
50
+
51
+#define TYPE_SIFIVE_E_AON "riscv.sifive.e.aon"
52
+OBJECT_DECLARE_SIMPLE_TYPE(SiFiveEAONState, SIFIVE_E_AON)
53
+
54
+#define SIFIVE_E_AON_WDOGKEY (0x51F15E)
55
+#define SIFIVE_E_AON_WDOGFEED (0xD09F00D)
56
+#define SIFIVE_E_LFCLK_DEFAULT_FREQ (32768)
57
+
58
+enum {
59
+ SIFIVE_E_AON_WDT = 0x0,
60
+ SIFIVE_E_AON_RTC = 0x40,
61
+ SIFIVE_E_AON_LFROSC = 0x70,
62
+ SIFIVE_E_AON_BACKUP = 0x80,
63
+ SIFIVE_E_AON_PMU = 0x100,
64
+ SIFIVE_E_AON_MAX = 0x150
65
+};
66
+
67
+struct SiFiveEAONState {
68
+ /*< private >*/
69
+ SysBusDevice parent_obj;
70
+
71
+ /*< public >*/
72
+ MemoryRegion mmio;
73
+
74
+ /*< watchdog timer >*/
75
+ QEMUTimer *wdog_timer;
76
+ qemu_irq wdog_irq;
77
+ uint64_t wdog_restart_time;
78
+ uint64_t wdogclk_freq;
79
+
80
+ uint32_t wdogcfg;
81
+ uint16_t wdogcmp0;
82
+ uint32_t wdogcount;
83
+ uint8_t wdogunlock;
84
+};
85
+
86
+#endif
87
diff --git a/hw/misc/sifive_e_aon.c b/hw/misc/sifive_e_aon.c
88
new file mode 100644
89
index XXXXXXX..XXXXXXX
90
--- /dev/null
91
+++ b/hw/misc/sifive_e_aon.c
92
@@ -XXX,XX +XXX,XX @@
93
+/*
94
+ * SiFive HiFive1 AON (Always On Domain) for QEMU.
95
+ *
96
+ * Copyright (c) 2022 SiFive, Inc. All rights reserved.
97
+ *
80
+ *
98
+ * This program is free software; you can redistribute it and/or modify it
81
+ * This program is free software; you can redistribute it and/or modify it
99
+ * under the terms and conditions of the GNU General Public License,
82
+ * under the terms and conditions of the GNU General Public License,
100
+ * version 2 or later, as published by the Free Software Foundation.
83
+ * version 2 or later, as published by the Free Software Foundation.
101
+ *
84
+ *
...
...
107
+ * You should have received a copy of the GNU General Public License along with
90
+ * You should have received a copy of the GNU General Public License along with
108
+ * this program. If not, see <http://www.gnu.org/licenses/>.
91
+ * this program. If not, see <http://www.gnu.org/licenses/>.
109
+ */
92
+ */
110
+
93
+
111
+#include "qemu/osdep.h"
94
+#include "qemu/osdep.h"
112
+#include "qemu/timer.h"
95
+#include "cpu.h"
113
+#include "qemu/log.h"
96
+#include "cpu_vendorid.h"
114
+#include "hw/irq.h"
115
+#include "hw/registerfields.h"
116
+#include "hw/misc/sifive_e_aon.h"
117
+#include "qapi/visitor.h"
118
+#include "qapi/error.h"
119
+#include "sysemu/watchdog.h"
120
+#include "hw/qdev-properties.h"
121
+
97
+
122
+REG32(AON_WDT_WDOGCFG, 0x0)
98
+#define CSR_TH_SXSTATUS 0x5c0
123
+ FIELD(AON_WDT_WDOGCFG, SCALE, 0, 4)
124
+ FIELD(AON_WDT_WDOGCFG, RSVD0, 4, 4)
125
+ FIELD(AON_WDT_WDOGCFG, RSTEN, 8, 1)
126
+ FIELD(AON_WDT_WDOGCFG, ZEROCMP, 9, 1)
127
+ FIELD(AON_WDT_WDOGCFG, RSVD1, 10, 2)
128
+ FIELD(AON_WDT_WDOGCFG, EN_ALWAYS, 12, 1)
129
+ FIELD(AON_WDT_WDOGCFG, EN_CORE_AWAKE, 13, 1)
130
+ FIELD(AON_WDT_WDOGCFG, RSVD2, 14, 14)
131
+ FIELD(AON_WDT_WDOGCFG, IP0, 28, 1)
132
+ FIELD(AON_WDT_WDOGCFG, RSVD3, 29, 3)
133
+REG32(AON_WDT_WDOGCOUNT, 0x8)
134
+ FIELD(AON_WDT_WDOGCOUNT, VALUE, 0, 31)
135
+REG32(AON_WDT_WDOGS, 0x10)
136
+REG32(AON_WDT_WDOGFEED, 0x18)
137
+REG32(AON_WDT_WDOGKEY, 0x1c)
138
+REG32(AON_WDT_WDOGCMP0, 0x20)
139
+
99
+
140
+static void sifive_e_aon_wdt_update_wdogcount(SiFiveEAONState *r)
100
+/* TH_SXSTATUS bits */
101
+#define TH_SXSTATUS_UCME BIT(16)
102
+#define TH_SXSTATUS_MAEE BIT(21)
103
+#define TH_SXSTATUS_THEADISAEE BIT(22)
104
+
105
+typedef struct {
106
+ int csrno;
107
+ int (*insertion_test)(RISCVCPU *cpu);
108
+ riscv_csr_operations csr_ops;
109
+} riscv_csr;
110
+
111
+static RISCVException smode(CPURISCVState *env, int csrno)
141
+{
112
+{
142
+ int64_t now;
113
+ if (riscv_has_ext(env, RVS)) {
143
+ if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS) == 0 &&
114
+ return RISCV_EXCP_NONE;
144
+ FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE) == 0) {
145
+ return;
146
+ }
115
+ }
147
+
116
+
148
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
117
+ return RISCV_EXCP_ILLEGAL_INST;
149
+ r->wdogcount += muldiv64(now - r->wdog_restart_time,
150
+ r->wdogclk_freq, NANOSECONDS_PER_SECOND);
151
+
152
+ /* Clean the most significant bit. */
153
+ r->wdogcount &= R_AON_WDT_WDOGCOUNT_VALUE_MASK;
154
+ r->wdog_restart_time = now;
155
+}
118
+}
156
+
119
+
157
+static void sifive_e_aon_wdt_update_state(SiFiveEAONState *r)
120
+static int test_thead_mvendorid(RISCVCPU *cpu)
158
+{
121
+{
159
+ uint16_t wdogs;
122
+ if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) {
160
+ bool cmp_signal = false;
123
+ return -1;
161
+ sifive_e_aon_wdt_update_wdogcount(r);
162
+ wdogs = (uint16_t)(r->wdogcount >>
163
+ FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, SCALE));
164
+
165
+ if (wdogs >= r->wdogcmp0) {
166
+ cmp_signal = true;
167
+ if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, ZEROCMP) == 1) {
168
+ r->wdogcount = 0;
169
+ wdogs = 0;
170
+ }
171
+ }
172
+
173
+ if (cmp_signal) {
174
+ if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, RSTEN) == 1) {
175
+ watchdog_perform_action();
176
+ }
177
+ r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, IP0, 1);
178
+ }
179
+
180
+ qemu_set_irq(r->wdog_irq, FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, IP0));
181
+
182
+ if (wdogs < r->wdogcmp0 &&
183
+ (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS) == 1 ||
184
+ FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE) == 1)) {
185
+ int64_t next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
186
+ next += muldiv64((r->wdogcmp0 - wdogs) <<
187
+ FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, SCALE),
188
+ NANOSECONDS_PER_SECOND, r->wdogclk_freq);
189
+ timer_mod(r->wdog_timer, next);
190
+ } else {
191
+ timer_mod(r->wdog_timer, INT64_MAX);
192
+ }
193
+}
194
+
195
+/*
196
+ * Callback used when the timer set using timer_mod expires.
197
+ */
198
+static void sifive_e_aon_wdt_expired_cb(void *opaque)
199
+{
200
+ SiFiveEAONState *r = SIFIVE_E_AON(opaque);
201
+ sifive_e_aon_wdt_update_state(r);
202
+}
203
+
204
+static uint64_t
205
+sifive_e_aon_wdt_read(void *opaque, hwaddr addr, unsigned int size)
206
+{
207
+ SiFiveEAONState *r = SIFIVE_E_AON(opaque);
208
+
209
+ switch (addr) {
210
+ case A_AON_WDT_WDOGCFG:
211
+ return r->wdogcfg;
212
+ case A_AON_WDT_WDOGCOUNT:
213
+ sifive_e_aon_wdt_update_wdogcount(r);
214
+ return r->wdogcount;
215
+ case A_AON_WDT_WDOGS:
216
+ sifive_e_aon_wdt_update_wdogcount(r);
217
+ return r->wdogcount >>
218
+ FIELD_EX32(r->wdogcfg,
219
+ AON_WDT_WDOGCFG,
220
+ SCALE);
221
+ case A_AON_WDT_WDOGFEED:
222
+ return 0;
223
+ case A_AON_WDT_WDOGKEY:
224
+ return r->wdogunlock;
225
+ case A_AON_WDT_WDOGCMP0:
226
+ return r->wdogcmp0;
227
+ default:
228
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad read: addr=0x%x\n",
229
+ __func__, (int)addr);
230
+ }
124
+ }
231
+
125
+
232
+ return 0;
126
+ return 0;
233
+}
127
+}
234
+
128
+
235
+static void
129
+static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno,
236
+sifive_e_aon_wdt_write(void *opaque, hwaddr addr,
130
+ target_ulong *val)
237
+ uint64_t val64, unsigned int size)
238
+{
131
+{
239
+ SiFiveEAONState *r = SIFIVE_E_AON(opaque);
132
+ /* We don't set MAEE here, because QEMU does not implement MAEE. */
240
+ uint32_t value = val64;
133
+ *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE;
241
+
134
+ return RISCV_EXCP_NONE;
242
+ switch (addr) {
243
+ case A_AON_WDT_WDOGCFG: {
244
+ uint8_t new_en_always;
245
+ uint8_t new_en_core_awake;
246
+ uint8_t old_en_always;
247
+ uint8_t old_en_core_awake;
248
+ if (r->wdogunlock == 0) {
249
+ return;
250
+ }
251
+
252
+ new_en_always = FIELD_EX32(value, AON_WDT_WDOGCFG, EN_ALWAYS);
253
+ new_en_core_awake = FIELD_EX32(value, AON_WDT_WDOGCFG, EN_CORE_AWAKE);
254
+ old_en_always = FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS);
255
+ old_en_core_awake = FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG,
256
+ EN_CORE_AWAKE);
257
+
258
+ if ((old_en_always ||
259
+ old_en_core_awake) == 1 &&
260
+ (new_en_always ||
261
+ new_en_core_awake) == 0) {
262
+ sifive_e_aon_wdt_update_wdogcount(r);
263
+ } else if ((old_en_always ||
264
+ old_en_core_awake) == 0 &&
265
+ (new_en_always ||
266
+ new_en_core_awake) == 1) {
267
+ r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
268
+ }
269
+ r->wdogcfg = value;
270
+ r->wdogunlock = 0;
271
+ break;
272
+ }
273
+ case A_AON_WDT_WDOGCOUNT:
274
+ if (r->wdogunlock == 0) {
275
+ return;
276
+ }
277
+ r->wdogcount = value & R_AON_WDT_WDOGCOUNT_VALUE_MASK;
278
+ r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
279
+ r->wdogunlock = 0;
280
+ break;
281
+ case A_AON_WDT_WDOGS:
282
+ return;
283
+ case A_AON_WDT_WDOGFEED:
284
+ if (r->wdogunlock == 0) {
285
+ return;
286
+ }
287
+ if (value == SIFIVE_E_AON_WDOGFEED) {
288
+ r->wdogcount = 0;
289
+ r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
290
+ }
291
+ r->wdogunlock = 0;
292
+ break;
293
+ case A_AON_WDT_WDOGKEY:
294
+ if (value == SIFIVE_E_AON_WDOGKEY) {
295
+ r->wdogunlock = 1;
296
+ }
297
+ break;
298
+ case A_AON_WDT_WDOGCMP0:
299
+ if (r->wdogunlock == 0) {
300
+ return;
301
+ }
302
+ r->wdogcmp0 = (uint16_t) value;
303
+ r->wdogunlock = 0;
304
+ break;
305
+ default:
306
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%x v=0x%x\n",
307
+ __func__, (int)addr, (int)value);
308
+ }
309
+ sifive_e_aon_wdt_update_state(r);
310
+}
135
+}
311
+
136
+
312
+static uint64_t
137
+static riscv_csr th_csr_list[] = {
313
+sifive_e_aon_read(void *opaque, hwaddr addr, unsigned int size)
138
+ {
314
+{
139
+ .csrno = CSR_TH_SXSTATUS,
315
+ if (addr < SIFIVE_E_AON_RTC) {
140
+ .insertion_test = test_thead_mvendorid,
316
+ return sifive_e_aon_wdt_read(opaque, addr, size);
141
+ .csr_ops = { "th.sxstatus", smode, read_th_sxstatus }
317
+ } else if (addr < SIFIVE_E_AON_MAX) {
318
+ qemu_log_mask(LOG_UNIMP, "%s: Unimplemented read: addr=0x%x\n",
319
+ __func__, (int)addr);
320
+ } else {
321
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad read: addr=0x%x\n",
322
+ __func__, (int)addr);
323
+ }
324
+ return 0;
325
+}
326
+
327
+static void
328
+sifive_e_aon_write(void *opaque, hwaddr addr,
329
+ uint64_t val64, unsigned int size)
330
+{
331
+ if (addr < SIFIVE_E_AON_RTC) {
332
+ sifive_e_aon_wdt_write(opaque, addr, val64, size);
333
+ } else if (addr < SIFIVE_E_AON_MAX) {
334
+ qemu_log_mask(LOG_UNIMP, "%s: Unimplemented write: addr=0x%x\n",
335
+ __func__, (int)addr);
336
+ } else {
337
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%x\n",
338
+ __func__, (int)addr);
339
+ }
340
+}
341
+
342
+static const MemoryRegionOps sifive_e_aon_ops = {
343
+ .read = sifive_e_aon_read,
344
+ .write = sifive_e_aon_write,
345
+ .endianness = DEVICE_NATIVE_ENDIAN,
346
+ .impl = {
347
+ .min_access_size = 4,
348
+ .max_access_size = 4
349
+ },
350
+ .valid = {
351
+ .min_access_size = 4,
352
+ .max_access_size = 4
353
+ }
142
+ }
354
+};
143
+};
355
+
144
+
356
+static void sifive_e_aon_reset(DeviceState *dev)
145
+void th_register_custom_csrs(RISCVCPU *cpu)
357
+{
146
+{
358
+ SiFiveEAONState *r = SIFIVE_E_AON(dev);
147
+ for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) {
359
+
148
+ int csrno = th_csr_list[i].csrno;
360
+ r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, RSTEN, 0);
149
+ riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops;
361
+ r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS, 0);
150
+ if (!th_csr_list[i].insertion_test(cpu)) {
362
+ r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE, 0);
151
+ riscv_set_csr_ops(csrno, csr_ops);
363
+ r->wdogcmp0 = 0xbeef;
152
+ }
364
+
153
+ }
365
+ sifive_e_aon_wdt_update_state(r);
366
+}
154
+}
367
+
155
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
368
+static void sifive_e_aon_init(Object *obj)
369
+{
370
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
371
+ SiFiveEAONState *r = SIFIVE_E_AON(obj);
372
+
373
+ memory_region_init_io(&r->mmio, OBJECT(r), &sifive_e_aon_ops, r,
374
+ TYPE_SIFIVE_E_AON, SIFIVE_E_AON_MAX);
375
+ sysbus_init_mmio(sbd, &r->mmio);
376
+
377
+ /* watchdog timer */
378
+ r->wdog_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
379
+ sifive_e_aon_wdt_expired_cb, r);
380
+ r->wdogclk_freq = SIFIVE_E_LFCLK_DEFAULT_FREQ;
381
+ sysbus_init_irq(sbd, &r->wdog_irq);
382
+}
383
+
384
+static Property sifive_e_aon_properties[] = {
385
+ DEFINE_PROP_UINT64("wdogclk-frequency", SiFiveEAONState, wdogclk_freq,
386
+ SIFIVE_E_LFCLK_DEFAULT_FREQ),
387
+ DEFINE_PROP_END_OF_LIST(),
388
+};
389
+
390
+static void sifive_e_aon_class_init(ObjectClass *oc, void *data)
391
+{
392
+ DeviceClass *dc = DEVICE_CLASS(oc);
393
+
394
+ dc->reset = sifive_e_aon_reset;
395
+ device_class_set_props(dc, sifive_e_aon_properties);
396
+}
397
+
398
+static const TypeInfo sifive_e_aon_info = {
399
+ .name = TYPE_SIFIVE_E_AON,
400
+ .parent = TYPE_SYS_BUS_DEVICE,
401
+ .instance_size = sizeof(SiFiveEAONState),
402
+ .instance_init = sifive_e_aon_init,
403
+ .class_init = sifive_e_aon_class_init,
404
+};
405
+
406
+static void sifive_e_aon_register_types(void)
407
+{
408
+ type_register_static(&sifive_e_aon_info);
409
+}
410
+
411
+type_init(sifive_e_aon_register_types)
412
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
413
index XXXXXXX..XXXXXXX 100644
156
index XXXXXXX..XXXXXXX 100644
414
--- a/hw/misc/Kconfig
157
--- a/target/riscv/meson.build
415
+++ b/hw/misc/Kconfig
158
+++ b/target/riscv/meson.build
416
@@ -XXX,XX +XXX,XX @@ config SIFIVE_TEST
159
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
417
config SIFIVE_E_PRCI
160
'monitor.c',
418
bool
161
'machine.c',
419
162
'pmu.c',
420
+config SIFIVE_E_AON
163
+ 'th_csr.c',
421
+ bool
164
'time_helper.c',
422
+
165
'riscv-qmp-cmds.c',
423
config SIFIVE_U_OTP
166
))
424
bool
425
426
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
427
index XXXXXXX..XXXXXXX 100644
428
--- a/hw/misc/meson.build
429
+++ b/hw/misc/meson.build
430
@@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_MCHP_PFSOC_IOSCB', if_true: files('mchp_pfsoc_ioscb.
431
system_ss.add(when: 'CONFIG_MCHP_PFSOC_SYSREG', if_true: files('mchp_pfsoc_sysreg.c'))
432
system_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c'))
433
system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
434
+system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c'))
435
system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
436
system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c'))
437
438
--
167
--
439
2.40.1
168
2.45.1
169
170
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
Let's add KVM user properties for the multi-letter extensions that KVM
3
According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w
4
currently supports: zicbom, zicboz, zihintpause, zbb, ssaia, sstc,
4
instructions will be affected by Zvfhmin extension.
5
svinval and svpbmt.
5
And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the
6
conversions of
6
7
7
As with MISA extensions, we're using the KVMCPUConfig type to hold
8
* From 1*SEW(16/32) to 2*SEW(32/64)
8
information about the state of each extension. However, multi-letter
9
* From 2*SEW(32/64) to 1*SEW(16/32)
9
extensions have more cases to cover than MISA extensions, so we're
10
adding an extra 'supported' flag as well. This flag will reflect if a
11
given extension is supported by KVM, i.e. KVM knows how to handle it.
12
This is determined during KVM extension discovery in
13
kvm_riscv_init_multiext_cfg(), where we test for EINVAL errors. Any
14
other error will cause an abort.
15
10
16
The use of the 'user_set' is similar to what we already do with MISA
11
Signed-off-by: Max Chou <max.chou@sifive.com>
17
extensions: the flag set only if the user is changing the extension
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
state.
13
Cc: qemu-stable <qemu-stable@nongnu.org>
19
14
Message-ID: <20240322092600.1198921-2-max.chou@sifive.com>
20
The 'supported' flag will be used later on to make an exception for
21
users that are disabling multi-letter extensions that are unknown to
22
KVM.
23
24
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
25
Acked-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
27
Message-Id: <20230706101738.460804-15-dbarboza@ventanamicro.com>
28
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
---
16
---
30
target/riscv/cpu.c | 8 +++
17
target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++--
31
target/riscv/kvm.c | 119 +++++++++++++++++++++++++++++++++++++++++++++
18
1 file changed, 18 insertions(+), 2 deletions(-)
32
2 files changed, 127 insertions(+)
33
19
34
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
35
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/cpu.c
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
37
+++ b/target/riscv/cpu.c
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
38
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
24
@@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s)
39
riscv_cpu_add_misa_properties(obj);
40
41
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
42
+#ifndef CONFIG_USER_ONLY
43
+ if (kvm_enabled()) {
44
+ /* Check if KVM created the property already */
45
+ if (object_property_find(obj, prop->name)) {
46
+ continue;
47
+ }
48
+ }
49
+#endif
50
qdev_property_add_static(dev, prop);
51
}
52
53
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/riscv/kvm.c
56
+++ b/target/riscv/kvm.c
57
@@ -XXX,XX +XXX,XX @@ typedef struct KVMCPUConfig {
58
target_ulong offset;
59
int kvm_reg_id;
60
bool user_set;
61
+ bool supported;
62
} KVMCPUConfig;
63
64
#define KVM_MISA_CFG(_bit, _reg_id) \
65
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs)
66
}
25
}
67
}
26
}
68
27
69
+#define CPUCFG(_prop) offsetof(struct RISCVCPUConfig, _prop)
28
+static bool require_rvfmin(DisasContext *s)
70
+
71
+#define KVM_EXT_CFG(_name, _prop, _reg_id) \
72
+ {.name = _name, .offset = CPUCFG(_prop), \
73
+ .kvm_reg_id = _reg_id}
74
+
75
+static KVMCPUConfig kvm_multi_ext_cfgs[] = {
76
+ KVM_EXT_CFG("zicbom", ext_icbom, KVM_RISCV_ISA_EXT_ZICBOM),
77
+ KVM_EXT_CFG("zicboz", ext_icboz, KVM_RISCV_ISA_EXT_ZICBOZ),
78
+ KVM_EXT_CFG("zihintpause", ext_zihintpause, KVM_RISCV_ISA_EXT_ZIHINTPAUSE),
79
+ KVM_EXT_CFG("zbb", ext_zbb, KVM_RISCV_ISA_EXT_ZBB),
80
+ KVM_EXT_CFG("ssaia", ext_ssaia, KVM_RISCV_ISA_EXT_SSAIA),
81
+ KVM_EXT_CFG("sstc", ext_sstc, KVM_RISCV_ISA_EXT_SSTC),
82
+ KVM_EXT_CFG("svinval", ext_svinval, KVM_RISCV_ISA_EXT_SVINVAL),
83
+ KVM_EXT_CFG("svpbmt", ext_svpbmt, KVM_RISCV_ISA_EXT_SVPBMT),
84
+};
85
+
86
+static void kvm_cpu_cfg_set(RISCVCPU *cpu, KVMCPUConfig *multi_ext,
87
+ uint32_t val)
88
+{
29
+{
89
+ int cpu_cfg_offset = multi_ext->offset;
30
+ if (s->mstatus_fs == EXT_STATUS_DISABLED) {
90
+ bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
31
+ return false;
91
+
92
+ *ext_enabled = val;
93
+}
94
+
95
+static uint32_t kvm_cpu_cfg_get(RISCVCPU *cpu,
96
+ KVMCPUConfig *multi_ext)
97
+{
98
+ int cpu_cfg_offset = multi_ext->offset;
99
+ bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
100
+
101
+ return *ext_enabled;
102
+}
103
+
104
+static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v,
105
+ const char *name,
106
+ void *opaque, Error **errp)
107
+{
108
+ KVMCPUConfig *multi_ext_cfg = opaque;
109
+ RISCVCPU *cpu = RISCV_CPU(obj);
110
+ bool value, host_val;
111
+
112
+ if (!visit_type_bool(v, name, &value, errp)) {
113
+ return;
114
+ }
32
+ }
115
+
33
+
116
+ host_val = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
34
+ switch (s->sew) {
117
+
35
+ case MO_16:
118
+ /*
36
+ return s->cfg_ptr->ext_zvfhmin;
119
+ * Ignore if the user is setting the same value
37
+ case MO_32:
120
+ * as the host.
38
+ return s->cfg_ptr->ext_zve32f;
121
+ */
39
+ default:
122
+ if (value == host_val) {
40
+ return false;
123
+ return;
124
+ }
125
+
126
+ if (!multi_ext_cfg->supported) {
127
+ /*
128
+ * Error out if the user is trying to enable an
129
+ * extension that KVM doesn't support. Ignore
130
+ * option otherwise.
131
+ */
132
+ if (value) {
133
+ error_setg(errp, "KVM does not support disabling extension %s",
134
+ multi_ext_cfg->name);
135
+ }
136
+
137
+ return;
138
+ }
139
+
140
+ multi_ext_cfg->user_set = true;
141
+ kvm_cpu_cfg_set(cpu, multi_ext_cfg, value);
142
+}
143
+
144
static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
145
{
146
int i;
147
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
148
object_property_set_description(cpu_obj, misa_cfg->name,
149
misa_cfg->description);
150
}
151
+
152
+ for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) {
153
+ KVMCPUConfig *multi_cfg = &kvm_multi_ext_cfgs[i];
154
+
155
+ object_property_add(cpu_obj, multi_cfg->name, "bool",
156
+ NULL,
157
+ kvm_cpu_set_multi_ext_cfg,
158
+ NULL, multi_cfg);
159
+ }
160
}
161
162
static int kvm_riscv_get_regs_core(CPUState *cs)
163
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu,
164
env->misa_ext = env->misa_ext_mask;
165
}
166
167
+static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
168
+{
169
+ CPURISCVState *env = &cpu->env;
170
+ uint64_t val;
171
+ int i, ret;
172
+
173
+ for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) {
174
+ KVMCPUConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i];
175
+ struct kvm_one_reg reg;
176
+
177
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
178
+ multi_ext_cfg->kvm_reg_id);
179
+ reg.addr = (uint64_t)&val;
180
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
181
+ if (ret != 0) {
182
+ if (errno == EINVAL) {
183
+ /* Silently default to 'false' if KVM does not support it. */
184
+ multi_ext_cfg->supported = false;
185
+ val = false;
186
+ } else {
187
+ error_report("Unable to read ISA_EXT KVM register %s, "
188
+ "error %d", multi_ext_cfg->name, ret);
189
+ kvm_riscv_destroy_scratch_vcpu(kvmcpu);
190
+ exit(EXIT_FAILURE);
191
+ }
192
+ } else {
193
+ multi_ext_cfg->supported = true;
194
+ }
195
+
196
+ kvm_cpu_cfg_set(cpu, multi_ext_cfg, val);
197
+ }
41
+ }
198
+}
42
+}
199
+
43
+
200
void kvm_riscv_init_user_properties(Object *cpu_obj)
44
static bool require_scale_rvf(DisasContext *s)
201
{
45
{
202
RISCVCPU *cpu = RISCV_CPU(cpu_obj);
46
if (s->mstatus_fs == EXT_STATUS_DISABLED) {
203
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_init_user_properties(Object *cpu_obj)
47
@@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s)
204
kvm_riscv_add_cpu_user_properties(cpu_obj);
48
}
205
kvm_riscv_init_machine_ids(cpu, &kvmcpu);
49
206
kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu);
50
switch (s->sew) {
207
+ kvm_riscv_init_multiext_cfg(cpu, &kvmcpu);
51
- case MO_8:
208
52
- return s->cfg_ptr->ext_zvfhmin;
209
kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
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);
210
}
71
}
211
--
72
--
212
2.40.1
73
2.45.1
diff view generated by jsdifflib
1
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
Disassemble function(plugin_disas, target_disas, monitor_disas) will
3
The require_scale_rvf function only checks the double width operator for
4
always call set_disas_info before disassembling instructions.
4
the vector floating point widen instructions, so most of the widen
5
checking functions need to add require_rvf for single width operator.
5
6
6
plugin_disas and target_disas will always be called under a TB, which
7
The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width
7
has the same XLEN.
8
integer to double width float, so the opfxv_widen_check function doesn’t
9
need require_rvf for the single width operator(integer).
8
10
9
We can't ensure that monitor_disas will always be called under a TB,
11
Signed-off-by: Max Chou <max.chou@sifive.com>
10
but current XLEN will still be a better choice, thus we can ensure at
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
least the disassemble of the nearest one TB is right.
13
Cc: qemu-stable <qemu-stable@nongnu.org>
12
14
Message-ID: <20240322092600.1198921-3-max.chou@sifive.com>
13
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
17
Message-Id: <20230612111034.3955227-2-christoph.muellner@vrull.eu>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
16
---
20
target/riscv/cpu.c | 3 ++-
17
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++
21
1 file changed, 2 insertions(+), 1 deletion(-)
18
1 file changed, 5 insertions(+)
22
19
23
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
24
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
25
--- a/target/riscv/cpu.c
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
26
+++ b/target/riscv/cpu.c
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
27
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj)
24
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check)
28
static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
25
static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
29
{
26
{
30
RISCVCPU *cpu = RISCV_CPU(s);
27
return require_rvv(s) &&
31
+ CPURISCVState *env = &cpu->env;
28
+ require_rvf(s) &&
32
info->target_info = &cpu->cfg;
29
require_scale_rvf(s) &&
33
30
(s->sew != MO_8) &&
34
- switch (riscv_cpu_mxl(&cpu->env)) {
31
vext_check_isa_ill(s) &&
35
+ switch (env->xl) {
32
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check)
36
case MXL_RV32:
33
static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
37
info->print_insn = print_insn_riscv32;
34
{
38
break;
35
return require_rvv(s) &&
36
+ require_rvf(s) &&
37
require_scale_rvf(s) &&
38
(s->sew != MO_8) &&
39
vext_check_isa_ill(s) &&
40
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf)
41
static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
42
{
43
return require_rvv(s) &&
44
+ require_rvf(s) &&
45
require_scale_rvf(s) &&
46
(s->sew != MO_8) &&
47
vext_check_isa_ill(s) &&
48
@@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv)
49
static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
50
{
51
return require_rvv(s) &&
52
+ require_rvf(s) &&
53
require_scale_rvf(s) &&
54
(s->sew != MO_8) &&
55
vext_check_isa_ill(s) &&
56
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check)
57
static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
58
{
59
return reduction_widen_check(s, a) &&
60
+ require_rvf(s) &&
61
require_scale_rvf(s) &&
62
(s->sew != MO_8);
63
}
39
--
64
--
40
2.40.1
65
2.45.1
41
66
42
67
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
This patch moves the extension test functions that are used
4
to gate vendor extension decoders, into cpu_cfg.h.
5
This allows to reuse them in the disassembler.
6
7
This patch does not introduce new functionality.
8
However, the patch includes a small change:
9
The parameter for the extension test functions has been changed
10
from 'DisasContext*' to 'const RISCVCPUConfig*' to keep
11
the code in cpu_cfg.h self-contained.
12
13
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
16
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
17
Message-Id: <20230612111034.3955227-3-christoph.muellner@vrull.eu>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
20
target/riscv/cpu_cfg.h | 26 ++++++++++++++++++++++++++
21
target/riscv/translate.c | 27 ++-------------------------
22
2 files changed, 28 insertions(+), 25 deletions(-)
23
24
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
25
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu_cfg.h
27
+++ b/target/riscv/cpu_cfg.h
28
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
29
};
30
31
typedef struct RISCVCPUConfig RISCVCPUConfig;
32
+
33
+/* Helper functions to test for extensions. */
34
+
35
+static inline bool always_true_p(const RISCVCPUConfig *cfg __attribute__((__unused__)))
36
+{
37
+ return true;
38
+}
39
+
40
+static inline bool has_xthead_p(const RISCVCPUConfig *cfg)
41
+{
42
+ return cfg->ext_xtheadba || cfg->ext_xtheadbb ||
43
+ cfg->ext_xtheadbs || cfg->ext_xtheadcmo ||
44
+ cfg->ext_xtheadcondmov ||
45
+ cfg->ext_xtheadfmemidx || cfg->ext_xtheadfmv ||
46
+ cfg->ext_xtheadmac || cfg->ext_xtheadmemidx ||
47
+ cfg->ext_xtheadmempair || cfg->ext_xtheadsync;
48
+}
49
+
50
+#define MATERIALISE_EXT_PREDICATE(ext) \
51
+ static inline bool has_ ## ext ## _p(const RISCVCPUConfig *cfg) \
52
+ { \
53
+ return cfg->ext_ ## ext ; \
54
+ }
55
+
56
+MATERIALISE_EXT_PREDICATE(XVentanaCondOps)
57
+
58
#endif
59
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
60
index XXXXXXX..XXXXXXX 100644
61
--- a/target/riscv/translate.c
62
+++ b/target/riscv/translate.c
63
@@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
64
return ctx->misa_ext & ext;
65
}
66
67
-static bool always_true_p(DisasContext *ctx __attribute__((__unused__)))
68
-{
69
- return true;
70
-}
71
-
72
-static bool has_xthead_p(DisasContext *ctx __attribute__((__unused__)))
73
-{
74
- return ctx->cfg_ptr->ext_xtheadba || ctx->cfg_ptr->ext_xtheadbb ||
75
- ctx->cfg_ptr->ext_xtheadbs || ctx->cfg_ptr->ext_xtheadcmo ||
76
- ctx->cfg_ptr->ext_xtheadcondmov ||
77
- ctx->cfg_ptr->ext_xtheadfmemidx || ctx->cfg_ptr->ext_xtheadfmv ||
78
- ctx->cfg_ptr->ext_xtheadmac || ctx->cfg_ptr->ext_xtheadmemidx ||
79
- ctx->cfg_ptr->ext_xtheadmempair || ctx->cfg_ptr->ext_xtheadsync;
80
-}
81
-
82
-#define MATERIALISE_EXT_PREDICATE(ext) \
83
- static bool has_ ## ext ## _p(DisasContext *ctx) \
84
- { \
85
- return ctx->cfg_ptr->ext_ ## ext ; \
86
- }
87
-
88
-MATERIALISE_EXT_PREDICATE(XVentanaCondOps);
89
-
90
#ifdef TARGET_RISCV32
91
#define get_xl(ctx) MXL_RV32
92
#elif defined(CONFIG_USER_ONLY)
93
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
94
* that are tested in-order until a decoder matches onto the opcode.
95
*/
96
static const struct {
97
- bool (*guard_func)(DisasContext *);
98
+ bool (*guard_func)(const RISCVCPUConfig *);
99
bool (*decode_func)(DisasContext *, uint32_t);
100
} decoders[] = {
101
{ always_true_p, decode_insn32 },
102
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
103
ctx->opcode = opcode32;
104
105
for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) {
106
- if (decoders[i].guard_func(ctx) &&
107
+ if (decoders[i].guard_func(ctx->cfg_ptr) &&
108
decoders[i].decode_func(ctx, opcode32)) {
109
return;
110
}
111
--
112
2.40.1
113
114
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
In order to enable vendor disassembler support, we need to
4
move types and constants into a header file so that other
5
compilation units can use them as well.
6
7
This patch does not introduce any functional changes.
8
9
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
12
Message-Id: <20230612111034.3955227-4-christoph.muellner@vrull.eu>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
disas/riscv.h | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++
16
disas/riscv.c | 270 +----------------------------------------------
17
2 files changed, 283 insertions(+), 269 deletions(-)
18
create mode 100644 disas/riscv.h
19
20
diff --git a/disas/riscv.h b/disas/riscv.h
21
new file mode 100644
22
index XXXXXXX..XXXXXXX
23
--- /dev/null
24
+++ b/disas/riscv.h
25
@@ -XXX,XX +XXX,XX @@
26
+/*
27
+ * QEMU disassembler -- RISC-V specific header.
28
+ *
29
+ * SPDX-License-Identifier: GPL-2.0-or-later
30
+ */
31
+
32
+#ifndef DISAS_RISCV_H
33
+#define DISAS_RISCV_H
34
+
35
+#include "qemu/osdep.h"
36
+#include "target/riscv/cpu_cfg.h"
37
+
38
+/* types */
39
+
40
+typedef uint64_t rv_inst;
41
+typedef uint16_t rv_opcode;
42
+
43
+/* enums */
44
+
45
+typedef enum {
46
+ rv32,
47
+ rv64,
48
+ rv128
49
+} rv_isa;
50
+
51
+typedef enum {
52
+ rv_rm_rne = 0,
53
+ rv_rm_rtz = 1,
54
+ rv_rm_rdn = 2,
55
+ rv_rm_rup = 3,
56
+ rv_rm_rmm = 4,
57
+ rv_rm_dyn = 7,
58
+} rv_rm;
59
+
60
+typedef enum {
61
+ rv_fence_i = 8,
62
+ rv_fence_o = 4,
63
+ rv_fence_r = 2,
64
+ rv_fence_w = 1,
65
+} rv_fence;
66
+
67
+typedef enum {
68
+ rv_ireg_zero,
69
+ rv_ireg_ra,
70
+ rv_ireg_sp,
71
+ rv_ireg_gp,
72
+ rv_ireg_tp,
73
+ rv_ireg_t0,
74
+ rv_ireg_t1,
75
+ rv_ireg_t2,
76
+ rv_ireg_s0,
77
+ rv_ireg_s1,
78
+ rv_ireg_a0,
79
+ rv_ireg_a1,
80
+ rv_ireg_a2,
81
+ rv_ireg_a3,
82
+ rv_ireg_a4,
83
+ rv_ireg_a5,
84
+ rv_ireg_a6,
85
+ rv_ireg_a7,
86
+ rv_ireg_s2,
87
+ rv_ireg_s3,
88
+ rv_ireg_s4,
89
+ rv_ireg_s5,
90
+ rv_ireg_s6,
91
+ rv_ireg_s7,
92
+ rv_ireg_s8,
93
+ rv_ireg_s9,
94
+ rv_ireg_s10,
95
+ rv_ireg_s11,
96
+ rv_ireg_t3,
97
+ rv_ireg_t4,
98
+ rv_ireg_t5,
99
+ rv_ireg_t6,
100
+} rv_ireg;
101
+
102
+typedef enum {
103
+ rvc_end,
104
+ rvc_rd_eq_ra,
105
+ rvc_rd_eq_x0,
106
+ rvc_rs1_eq_x0,
107
+ rvc_rs2_eq_x0,
108
+ rvc_rs2_eq_rs1,
109
+ rvc_rs1_eq_ra,
110
+ rvc_imm_eq_zero,
111
+ rvc_imm_eq_n1,
112
+ rvc_imm_eq_p1,
113
+ rvc_csr_eq_0x001,
114
+ rvc_csr_eq_0x002,
115
+ rvc_csr_eq_0x003,
116
+ rvc_csr_eq_0xc00,
117
+ rvc_csr_eq_0xc01,
118
+ rvc_csr_eq_0xc02,
119
+ rvc_csr_eq_0xc80,
120
+ rvc_csr_eq_0xc81,
121
+ rvc_csr_eq_0xc82,
122
+} rvc_constraint;
123
+
124
+typedef enum {
125
+ rv_codec_illegal,
126
+ rv_codec_none,
127
+ rv_codec_u,
128
+ rv_codec_uj,
129
+ rv_codec_i,
130
+ rv_codec_i_sh5,
131
+ rv_codec_i_sh6,
132
+ rv_codec_i_sh7,
133
+ rv_codec_i_csr,
134
+ rv_codec_s,
135
+ rv_codec_sb,
136
+ rv_codec_r,
137
+ rv_codec_r_m,
138
+ rv_codec_r4_m,
139
+ rv_codec_r_a,
140
+ rv_codec_r_l,
141
+ rv_codec_r_f,
142
+ rv_codec_cb,
143
+ rv_codec_cb_imm,
144
+ rv_codec_cb_sh5,
145
+ rv_codec_cb_sh6,
146
+ rv_codec_ci,
147
+ rv_codec_ci_sh5,
148
+ rv_codec_ci_sh6,
149
+ rv_codec_ci_16sp,
150
+ rv_codec_ci_lwsp,
151
+ rv_codec_ci_ldsp,
152
+ rv_codec_ci_lqsp,
153
+ rv_codec_ci_li,
154
+ rv_codec_ci_lui,
155
+ rv_codec_ci_none,
156
+ rv_codec_ciw_4spn,
157
+ rv_codec_cj,
158
+ rv_codec_cj_jal,
159
+ rv_codec_cl_lw,
160
+ rv_codec_cl_ld,
161
+ rv_codec_cl_lq,
162
+ rv_codec_cr,
163
+ rv_codec_cr_mv,
164
+ rv_codec_cr_jalr,
165
+ rv_codec_cr_jr,
166
+ rv_codec_cs,
167
+ rv_codec_cs_sw,
168
+ rv_codec_cs_sd,
169
+ rv_codec_cs_sq,
170
+ rv_codec_css_swsp,
171
+ rv_codec_css_sdsp,
172
+ rv_codec_css_sqsp,
173
+ rv_codec_k_bs,
174
+ rv_codec_k_rnum,
175
+ rv_codec_v_r,
176
+ rv_codec_v_ldst,
177
+ rv_codec_v_i,
178
+ rv_codec_vsetvli,
179
+ rv_codec_vsetivli,
180
+ rv_codec_zcb_ext,
181
+ rv_codec_zcb_mul,
182
+ rv_codec_zcb_lb,
183
+ rv_codec_zcb_lh,
184
+ rv_codec_zcmp_cm_pushpop,
185
+ rv_codec_zcmp_cm_mv,
186
+ rv_codec_zcmt_jt,
187
+} rv_codec;
188
+
189
+/* structures */
190
+
191
+typedef struct {
192
+ RISCVCPUConfig *cfg;
193
+ uint64_t pc;
194
+ uint64_t inst;
195
+ int32_t imm;
196
+ uint16_t op;
197
+ uint8_t codec;
198
+ uint8_t rd;
199
+ uint8_t rs1;
200
+ uint8_t rs2;
201
+ uint8_t rs3;
202
+ uint8_t rm;
203
+ uint8_t pred;
204
+ uint8_t succ;
205
+ uint8_t aq;
206
+ uint8_t rl;
207
+ uint8_t bs;
208
+ uint8_t rnum;
209
+ uint8_t vm;
210
+ uint32_t vzimm;
211
+ uint8_t rlist;
212
+} rv_decode;
213
+
214
+typedef struct {
215
+ const int op;
216
+ const rvc_constraint *constraints;
217
+} rv_comp_data;
218
+
219
+enum {
220
+ rvcd_imm_nz = 0x1
221
+};
222
+
223
+typedef struct {
224
+ const char * const name;
225
+ const rv_codec codec;
226
+ const char * const format;
227
+ const rv_comp_data *pseudo;
228
+ const short decomp_rv32;
229
+ const short decomp_rv64;
230
+ const short decomp_rv128;
231
+ const short decomp_data;
232
+} rv_opcode_data;
233
+
234
+/* instruction formats */
235
+
236
+#define rv_fmt_none "O\t"
237
+#define rv_fmt_rs1 "O\t1"
238
+#define rv_fmt_offset "O\to"
239
+#define rv_fmt_pred_succ "O\tp,s"
240
+#define rv_fmt_rs1_rs2 "O\t1,2"
241
+#define rv_fmt_rd_imm "O\t0,i"
242
+#define rv_fmt_rd_offset "O\t0,o"
243
+#define rv_fmt_rd_rs1_rs2 "O\t0,1,2"
244
+#define rv_fmt_frd_rs1 "O\t3,1"
245
+#define rv_fmt_frd_frs1 "O\t3,4"
246
+#define rv_fmt_rd_frs1 "O\t0,4"
247
+#define rv_fmt_rd_frs1_frs2 "O\t0,4,5"
248
+#define rv_fmt_frd_frs1_frs2 "O\t3,4,5"
249
+#define rv_fmt_rm_frd_frs1 "O\tr,3,4"
250
+#define rv_fmt_rm_frd_rs1 "O\tr,3,1"
251
+#define rv_fmt_rm_rd_frs1 "O\tr,0,4"
252
+#define rv_fmt_rm_frd_frs1_frs2 "O\tr,3,4,5"
253
+#define rv_fmt_rm_frd_frs1_frs2_frs3 "O\tr,3,4,5,6"
254
+#define rv_fmt_rd_rs1_imm "O\t0,1,i"
255
+#define rv_fmt_rd_rs1_offset "O\t0,1,i"
256
+#define rv_fmt_rd_offset_rs1 "O\t0,i(1)"
257
+#define rv_fmt_frd_offset_rs1 "O\t3,i(1)"
258
+#define rv_fmt_rd_csr_rs1 "O\t0,c,1"
259
+#define rv_fmt_rd_csr_zimm "O\t0,c,7"
260
+#define rv_fmt_rs2_offset_rs1 "O\t2,i(1)"
261
+#define rv_fmt_frs2_offset_rs1 "O\t5,i(1)"
262
+#define rv_fmt_rs1_rs2_offset "O\t1,2,o"
263
+#define rv_fmt_rs2_rs1_offset "O\t2,1,o"
264
+#define rv_fmt_aqrl_rd_rs2_rs1 "OAR\t0,2,(1)"
265
+#define rv_fmt_aqrl_rd_rs1 "OAR\t0,(1)"
266
+#define rv_fmt_rd "O\t0"
267
+#define rv_fmt_rd_zimm "O\t0,7"
268
+#define rv_fmt_rd_rs1 "O\t0,1"
269
+#define rv_fmt_rd_rs2 "O\t0,2"
270
+#define rv_fmt_rs1_offset "O\t1,o"
271
+#define rv_fmt_rs2_offset "O\t2,o"
272
+#define rv_fmt_rs1_rs2_bs "O\t1,2,b"
273
+#define rv_fmt_rd_rs1_rnum "O\t0,1,n"
274
+#define rv_fmt_ldst_vd_rs1_vm "O\tD,(1)m"
275
+#define rv_fmt_ldst_vd_rs1_rs2_vm "O\tD,(1),2m"
276
+#define rv_fmt_ldst_vd_rs1_vs2_vm "O\tD,(1),Fm"
277
+#define rv_fmt_vd_vs2_vs1 "O\tD,F,E"
278
+#define rv_fmt_vd_vs2_vs1_vl "O\tD,F,El"
279
+#define rv_fmt_vd_vs2_vs1_vm "O\tD,F,Em"
280
+#define rv_fmt_vd_vs2_rs1_vl "O\tD,F,1l"
281
+#define rv_fmt_vd_vs2_fs1_vl "O\tD,F,4l"
282
+#define rv_fmt_vd_vs2_rs1_vm "O\tD,F,1m"
283
+#define rv_fmt_vd_vs2_fs1_vm "O\tD,F,4m"
284
+#define rv_fmt_vd_vs2_imm_vl "O\tD,F,il"
285
+#define rv_fmt_vd_vs2_imm_vm "O\tD,F,im"
286
+#define rv_fmt_vd_vs2_uimm_vm "O\tD,F,um"
287
+#define rv_fmt_vd_vs1_vs2_vm "O\tD,E,Fm"
288
+#define rv_fmt_vd_rs1_vs2_vm "O\tD,1,Fm"
289
+#define rv_fmt_vd_fs1_vs2_vm "O\tD,4,Fm"
290
+#define rv_fmt_vd_vs1 "O\tD,E"
291
+#define rv_fmt_vd_rs1 "O\tD,1"
292
+#define rv_fmt_vd_fs1 "O\tD,4"
293
+#define rv_fmt_vd_imm "O\tD,i"
294
+#define rv_fmt_vd_vs2 "O\tD,F"
295
+#define rv_fmt_vd_vs2_vm "O\tD,Fm"
296
+#define rv_fmt_rd_vs2_vm "O\t0,Fm"
297
+#define rv_fmt_rd_vs2 "O\t0,F"
298
+#define rv_fmt_fd_vs2 "O\t3,F"
299
+#define rv_fmt_vd_vm "O\tDm"
300
+#define rv_fmt_vsetvli "O\t0,1,v"
301
+#define rv_fmt_vsetivli "O\t0,u,v"
302
+#define rv_fmt_rs1_rs2_zce_ldst "O\t2,i(1)"
303
+#define rv_fmt_push_rlist "O\tx,-i"
304
+#define rv_fmt_pop_rlist "O\tx,i"
305
+#define rv_fmt_zcmt_index "O\ti"
306
+
307
+#endif /* DISAS_RISCV_H */
308
diff --git a/disas/riscv.c b/disas/riscv.c
309
index XXXXXXX..XXXXXXX 100644
310
--- a/disas/riscv.c
311
+++ b/disas/riscv.c
312
@@ -XXX,XX +XXX,XX @@
313
#include "qemu/osdep.h"
314
#include "disas/dis-asm.h"
315
#include "target/riscv/cpu_cfg.h"
316
-
317
-/* types */
318
-
319
-typedef uint64_t rv_inst;
320
-typedef uint16_t rv_opcode;
321
-
322
-/* enums */
323
-
324
-typedef enum {
325
- rv32,
326
- rv64,
327
- rv128
328
-} rv_isa;
329
-
330
-typedef enum {
331
- rv_rm_rne = 0,
332
- rv_rm_rtz = 1,
333
- rv_rm_rdn = 2,
334
- rv_rm_rup = 3,
335
- rv_rm_rmm = 4,
336
- rv_rm_dyn = 7,
337
-} rv_rm;
338
-
339
-typedef enum {
340
- rv_fence_i = 8,
341
- rv_fence_o = 4,
342
- rv_fence_r = 2,
343
- rv_fence_w = 1,
344
-} rv_fence;
345
-
346
-typedef enum {
347
- rv_ireg_zero,
348
- rv_ireg_ra,
349
- rv_ireg_sp,
350
- rv_ireg_gp,
351
- rv_ireg_tp,
352
- rv_ireg_t0,
353
- rv_ireg_t1,
354
- rv_ireg_t2,
355
- rv_ireg_s0,
356
- rv_ireg_s1,
357
- rv_ireg_a0,
358
- rv_ireg_a1,
359
- rv_ireg_a2,
360
- rv_ireg_a3,
361
- rv_ireg_a4,
362
- rv_ireg_a5,
363
- rv_ireg_a6,
364
- rv_ireg_a7,
365
- rv_ireg_s2,
366
- rv_ireg_s3,
367
- rv_ireg_s4,
368
- rv_ireg_s5,
369
- rv_ireg_s6,
370
- rv_ireg_s7,
371
- rv_ireg_s8,
372
- rv_ireg_s9,
373
- rv_ireg_s10,
374
- rv_ireg_s11,
375
- rv_ireg_t3,
376
- rv_ireg_t4,
377
- rv_ireg_t5,
378
- rv_ireg_t6,
379
-} rv_ireg;
380
-
381
-typedef enum {
382
- rvc_end,
383
- rvc_rd_eq_ra,
384
- rvc_rd_eq_x0,
385
- rvc_rs1_eq_x0,
386
- rvc_rs2_eq_x0,
387
- rvc_rs2_eq_rs1,
388
- rvc_rs1_eq_ra,
389
- rvc_imm_eq_zero,
390
- rvc_imm_eq_n1,
391
- rvc_imm_eq_p1,
392
- rvc_csr_eq_0x001,
393
- rvc_csr_eq_0x002,
394
- rvc_csr_eq_0x003,
395
- rvc_csr_eq_0xc00,
396
- rvc_csr_eq_0xc01,
397
- rvc_csr_eq_0xc02,
398
- rvc_csr_eq_0xc80,
399
- rvc_csr_eq_0xc81,
400
- rvc_csr_eq_0xc82,
401
-} rvc_constraint;
402
-
403
-typedef enum {
404
- rv_codec_illegal,
405
- rv_codec_none,
406
- rv_codec_u,
407
- rv_codec_uj,
408
- rv_codec_i,
409
- rv_codec_i_sh5,
410
- rv_codec_i_sh6,
411
- rv_codec_i_sh7,
412
- rv_codec_i_csr,
413
- rv_codec_s,
414
- rv_codec_sb,
415
- rv_codec_r,
416
- rv_codec_r_m,
417
- rv_codec_r4_m,
418
- rv_codec_r_a,
419
- rv_codec_r_l,
420
- rv_codec_r_f,
421
- rv_codec_cb,
422
- rv_codec_cb_imm,
423
- rv_codec_cb_sh5,
424
- rv_codec_cb_sh6,
425
- rv_codec_ci,
426
- rv_codec_ci_sh5,
427
- rv_codec_ci_sh6,
428
- rv_codec_ci_16sp,
429
- rv_codec_ci_lwsp,
430
- rv_codec_ci_ldsp,
431
- rv_codec_ci_lqsp,
432
- rv_codec_ci_li,
433
- rv_codec_ci_lui,
434
- rv_codec_ci_none,
435
- rv_codec_ciw_4spn,
436
- rv_codec_cj,
437
- rv_codec_cj_jal,
438
- rv_codec_cl_lw,
439
- rv_codec_cl_ld,
440
- rv_codec_cl_lq,
441
- rv_codec_cr,
442
- rv_codec_cr_mv,
443
- rv_codec_cr_jalr,
444
- rv_codec_cr_jr,
445
- rv_codec_cs,
446
- rv_codec_cs_sw,
447
- rv_codec_cs_sd,
448
- rv_codec_cs_sq,
449
- rv_codec_css_swsp,
450
- rv_codec_css_sdsp,
451
- rv_codec_css_sqsp,
452
- rv_codec_k_bs,
453
- rv_codec_k_rnum,
454
- rv_codec_v_r,
455
- rv_codec_v_ldst,
456
- rv_codec_v_i,
457
- rv_codec_vsetvli,
458
- rv_codec_vsetivli,
459
- rv_codec_zcb_ext,
460
- rv_codec_zcb_mul,
461
- rv_codec_zcb_lb,
462
- rv_codec_zcb_lh,
463
- rv_codec_zcmp_cm_pushpop,
464
- rv_codec_zcmp_cm_mv,
465
- rv_codec_zcmt_jt,
466
-} rv_codec;
467
+#include "disas/riscv.h"
468
469
typedef enum {
470
rv_op_illegal = 0,
471
@@ -XXX,XX +XXX,XX @@ typedef enum {
472
rv_op_czero_nez = 790,
473
} rv_op;
474
475
-/* structures */
476
-
477
-typedef struct {
478
- RISCVCPUConfig *cfg;
479
- uint64_t pc;
480
- uint64_t inst;
481
- int32_t imm;
482
- uint16_t op;
483
- uint8_t codec;
484
- uint8_t rd;
485
- uint8_t rs1;
486
- uint8_t rs2;
487
- uint8_t rs3;
488
- uint8_t rm;
489
- uint8_t pred;
490
- uint8_t succ;
491
- uint8_t aq;
492
- uint8_t rl;
493
- uint8_t bs;
494
- uint8_t rnum;
495
- uint8_t vm;
496
- uint32_t vzimm;
497
- uint8_t rlist;
498
-} rv_decode;
499
-
500
-typedef struct {
501
- const int op;
502
- const rvc_constraint *constraints;
503
-} rv_comp_data;
504
-
505
-enum {
506
- rvcd_imm_nz = 0x1
507
-};
508
-
509
-typedef struct {
510
- const char * const name;
511
- const rv_codec codec;
512
- const char * const format;
513
- const rv_comp_data *pseudo;
514
- const short decomp_rv32;
515
- const short decomp_rv64;
516
- const short decomp_rv128;
517
- const short decomp_data;
518
-} rv_opcode_data;
519
-
520
/* register names */
521
522
static const char rv_ireg_name_sym[32][5] = {
523
@@ -XXX,XX +XXX,XX @@ static const char rv_vreg_name_sym[32][4] = {
524
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
525
};
526
527
-/* instruction formats */
528
-
529
-#define rv_fmt_none "O\t"
530
-#define rv_fmt_rs1 "O\t1"
531
-#define rv_fmt_offset "O\to"
532
-#define rv_fmt_pred_succ "O\tp,s"
533
-#define rv_fmt_rs1_rs2 "O\t1,2"
534
-#define rv_fmt_rd_imm "O\t0,i"
535
-#define rv_fmt_rd_offset "O\t0,o"
536
-#define rv_fmt_rd_rs1_rs2 "O\t0,1,2"
537
-#define rv_fmt_frd_rs1 "O\t3,1"
538
-#define rv_fmt_frd_frs1 "O\t3,4"
539
-#define rv_fmt_rd_frs1 "O\t0,4"
540
-#define rv_fmt_rd_frs1_frs2 "O\t0,4,5"
541
-#define rv_fmt_frd_frs1_frs2 "O\t3,4,5"
542
-#define rv_fmt_rm_frd_frs1 "O\tr,3,4"
543
-#define rv_fmt_rm_frd_rs1 "O\tr,3,1"
544
-#define rv_fmt_rm_rd_frs1 "O\tr,0,4"
545
-#define rv_fmt_rm_frd_frs1_frs2 "O\tr,3,4,5"
546
-#define rv_fmt_rm_frd_frs1_frs2_frs3 "O\tr,3,4,5,6"
547
-#define rv_fmt_rd_rs1_imm "O\t0,1,i"
548
-#define rv_fmt_rd_rs1_offset "O\t0,1,i"
549
-#define rv_fmt_rd_offset_rs1 "O\t0,i(1)"
550
-#define rv_fmt_frd_offset_rs1 "O\t3,i(1)"
551
-#define rv_fmt_rd_csr_rs1 "O\t0,c,1"
552
-#define rv_fmt_rd_csr_zimm "O\t0,c,7"
553
-#define rv_fmt_rs2_offset_rs1 "O\t2,i(1)"
554
-#define rv_fmt_frs2_offset_rs1 "O\t5,i(1)"
555
-#define rv_fmt_rs1_rs2_offset "O\t1,2,o"
556
-#define rv_fmt_rs2_rs1_offset "O\t2,1,o"
557
-#define rv_fmt_aqrl_rd_rs2_rs1 "OAR\t0,2,(1)"
558
-#define rv_fmt_aqrl_rd_rs1 "OAR\t0,(1)"
559
-#define rv_fmt_rd "O\t0"
560
-#define rv_fmt_rd_zimm "O\t0,7"
561
-#define rv_fmt_rd_rs1 "O\t0,1"
562
-#define rv_fmt_rd_rs2 "O\t0,2"
563
-#define rv_fmt_rs1_offset "O\t1,o"
564
-#define rv_fmt_rs2_offset "O\t2,o"
565
-#define rv_fmt_rs1_rs2_bs "O\t1,2,b"
566
-#define rv_fmt_rd_rs1_rnum "O\t0,1,n"
567
-#define rv_fmt_ldst_vd_rs1_vm "O\tD,(1)m"
568
-#define rv_fmt_ldst_vd_rs1_rs2_vm "O\tD,(1),2m"
569
-#define rv_fmt_ldst_vd_rs1_vs2_vm "O\tD,(1),Fm"
570
-#define rv_fmt_vd_vs2_vs1 "O\tD,F,E"
571
-#define rv_fmt_vd_vs2_vs1_vl "O\tD,F,El"
572
-#define rv_fmt_vd_vs2_vs1_vm "O\tD,F,Em"
573
-#define rv_fmt_vd_vs2_rs1_vl "O\tD,F,1l"
574
-#define rv_fmt_vd_vs2_fs1_vl "O\tD,F,4l"
575
-#define rv_fmt_vd_vs2_rs1_vm "O\tD,F,1m"
576
-#define rv_fmt_vd_vs2_fs1_vm "O\tD,F,4m"
577
-#define rv_fmt_vd_vs2_imm_vl "O\tD,F,il"
578
-#define rv_fmt_vd_vs2_imm_vm "O\tD,F,im"
579
-#define rv_fmt_vd_vs2_uimm_vm "O\tD,F,um"
580
-#define rv_fmt_vd_vs1_vs2_vm "O\tD,E,Fm"
581
-#define rv_fmt_vd_rs1_vs2_vm "O\tD,1,Fm"
582
-#define rv_fmt_vd_fs1_vs2_vm "O\tD,4,Fm"
583
-#define rv_fmt_vd_vs1 "O\tD,E"
584
-#define rv_fmt_vd_rs1 "O\tD,1"
585
-#define rv_fmt_vd_fs1 "O\tD,4"
586
-#define rv_fmt_vd_imm "O\tD,i"
587
-#define rv_fmt_vd_vs2 "O\tD,F"
588
-#define rv_fmt_vd_vs2_vm "O\tD,Fm"
589
-#define rv_fmt_rd_vs2_vm "O\t0,Fm"
590
-#define rv_fmt_rd_vs2 "O\t0,F"
591
-#define rv_fmt_fd_vs2 "O\t3,F"
592
-#define rv_fmt_vd_vm "O\tDm"
593
-#define rv_fmt_vsetvli "O\t0,1,v"
594
-#define rv_fmt_vsetivli "O\t0,u,v"
595
-#define rv_fmt_rs1_rs2_zce_ldst "O\t2,i(1)"
596
-#define rv_fmt_push_rlist "O\tx,-i"
597
-#define rv_fmt_pop_rlist "O\tx,i"
598
-#define rv_fmt_zcmt_index "O\ti"
599
-
600
/* pseudo-instruction constraints */
601
602
static const rvc_constraint rvcc_jal[] = { rvc_rd_eq_ra, rvc_end };
603
--
604
2.40.1
605
606
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
This patch adds a reference to a struct rv_opcode_data object
4
into struct rv_decode. This further allows to remove all references
5
to the global variable opcode_data (which is renamed to rvi_opcode_data).
6
7
This patch does not introduce any functional change, but prepares
8
the code for more struct rv_opcode_data objects in the future.
9
10
This patch is based on previous work from Liu Zhiwei:
11
https://lists.nongnu.org/archive/html/qemu-devel/2022-08/msg03662.html
12
13
Co-developed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
16
Message-Id: <20230612111034.3955227-6-christoph.muellner@vrull.eu>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
19
disas/riscv.h | 33 +++++++++++++++++----------------
20
disas/riscv.c | 9 ++++++++-
21
2 files changed, 25 insertions(+), 17 deletions(-)
22
23
diff --git a/disas/riscv.h b/disas/riscv.h
24
index XXXXXXX..XXXXXXX 100644
25
--- a/disas/riscv.h
26
+++ b/disas/riscv.h
27
@@ -XXX,XX +XXX,XX @@ typedef enum {
28
29
/* structures */
30
31
+typedef struct {
32
+ const int op;
33
+ const rvc_constraint *constraints;
34
+} rv_comp_data;
35
+
36
+typedef struct {
37
+ const char * const name;
38
+ const rv_codec codec;
39
+ const char * const format;
40
+ const rv_comp_data *pseudo;
41
+ const short decomp_rv32;
42
+ const short decomp_rv64;
43
+ const short decomp_rv128;
44
+ const short decomp_data;
45
+} rv_opcode_data;
46
+
47
typedef struct {
48
RISCVCPUConfig *cfg;
49
uint64_t pc;
50
uint64_t inst;
51
+ const rv_opcode_data *opcode_data;
52
int32_t imm;
53
uint16_t op;
54
uint8_t codec;
55
@@ -XXX,XX +XXX,XX @@ typedef struct {
56
uint8_t rlist;
57
} rv_decode;
58
59
-typedef struct {
60
- const int op;
61
- const rvc_constraint *constraints;
62
-} rv_comp_data;
63
-
64
enum {
65
rv_op_illegal = 0
66
};
67
@@ -XXX,XX +XXX,XX @@ enum {
68
rvcd_imm_nz = 0x1
69
};
70
71
-typedef struct {
72
- const char * const name;
73
- const rv_codec codec;
74
- const char * const format;
75
- const rv_comp_data *pseudo;
76
- const short decomp_rv32;
77
- const short decomp_rv64;
78
- const short decomp_rv128;
79
- const short decomp_data;
80
-} rv_opcode_data;
81
-
82
/* instruction formats */
83
84
#define rv_fmt_none "O\t"
85
diff --git a/disas/riscv.c b/disas/riscv.c
86
index XXXXXXX..XXXXXXX 100644
87
--- a/disas/riscv.c
88
+++ b/disas/riscv.c
89
@@ -XXX,XX +XXX,XX @@ static const rv_comp_data rvcp_fsgnjx_q[] = {
90
91
/* instruction metadata */
92
93
-const rv_opcode_data opcode_data[] = {
94
+const rv_opcode_data rvi_opcode_data[] = {
95
{ "illegal", rv_codec_illegal, rv_fmt_none, NULL, 0, 0, 0 },
96
{ "lui", rv_codec_u, rv_fmt_rd_imm, NULL, 0, 0, 0 },
97
{ "auipc", rv_codec_u, rv_fmt_rd_offset, NULL, 0, 0, 0 },
98
@@ -XXX,XX +XXX,XX @@ static uint32_t operand_tbl_index(rv_inst inst)
99
100
static void decode_inst_operands(rv_decode *dec, rv_isa isa)
101
{
102
+ const rv_opcode_data *opcode_data = dec->opcode_data;
103
rv_inst inst = dec->inst;
104
dec->codec = opcode_data[dec->op].codec;
105
switch (dec->codec) {
106
@@ -XXX,XX +XXX,XX @@ static void append(char *s1, const char *s2, size_t n)
107
108
static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
109
{
110
+ const rv_opcode_data *opcode_data = dec->opcode_data;
111
char tmp[64];
112
const char *fmt;
113
114
@@ -XXX,XX +XXX,XX @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
115
116
static void decode_inst_lift_pseudo(rv_decode *dec)
117
{
118
+ const rv_opcode_data *opcode_data = dec->opcode_data;
119
const rv_comp_data *comp_data = opcode_data[dec->op].pseudo;
120
if (!comp_data) {
121
return;
122
@@ -XXX,XX +XXX,XX @@ static void decode_inst_lift_pseudo(rv_decode *dec)
123
124
static void decode_inst_decompress_rv32(rv_decode *dec)
125
{
126
+ const rv_opcode_data *opcode_data = dec->opcode_data;
127
int decomp_op = opcode_data[dec->op].decomp_rv32;
128
if (decomp_op != rv_op_illegal) {
129
if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
130
@@ -XXX,XX +XXX,XX @@ static void decode_inst_decompress_rv32(rv_decode *dec)
131
132
static void decode_inst_decompress_rv64(rv_decode *dec)
133
{
134
+ const rv_opcode_data *opcode_data = dec->opcode_data;
135
int decomp_op = opcode_data[dec->op].decomp_rv64;
136
if (decomp_op != rv_op_illegal) {
137
if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
138
@@ -XXX,XX +XXX,XX @@ static void decode_inst_decompress_rv64(rv_decode *dec)
139
140
static void decode_inst_decompress_rv128(rv_decode *dec)
141
{
142
+ const rv_opcode_data *opcode_data = dec->opcode_data;
143
int decomp_op = opcode_data[dec->op].decomp_rv128;
144
if (decomp_op != rv_op_illegal) {
145
if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
146
@@ -XXX,XX +XXX,XX @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst,
147
rv_decode dec = { 0 };
148
dec.pc = pc;
149
dec.inst = inst;
150
+ dec.opcode_data = rvi_opcode_data;
151
dec.cfg = cfg;
152
decode_inst_opcode(&dec, isa);
153
decode_inst_operands(&dec, isa);
154
--
155
2.40.1
156
157
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
A previous patch provides a pointer to the RISCVCPUConfig data.
4
Let's use this to add the necessary code for vendor extensions.
5
This patch does not change the current behaviour, but clearly
6
defines how vendor extension support can be added to the disassembler.
7
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
11
Message-Id: <20230612111034.3955227-7-christoph.muellner@vrull.eu>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
disas/riscv.c | 28 ++++++++++++++++++++++++++--
15
1 file changed, 26 insertions(+), 2 deletions(-)
16
17
diff --git a/disas/riscv.c b/disas/riscv.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/disas/riscv.c
20
+++ b/disas/riscv.c
21
@@ -XXX,XX +XXX,XX @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst,
22
rv_decode dec = { 0 };
23
dec.pc = pc;
24
dec.inst = inst;
25
- dec.opcode_data = rvi_opcode_data;
26
dec.cfg = cfg;
27
- decode_inst_opcode(&dec, isa);
28
+
29
+ static const struct {
30
+ bool (*guard_func)(const RISCVCPUConfig *);
31
+ const rv_opcode_data *opcode_data;
32
+ void (*decode_func)(rv_decode *, rv_isa);
33
+ } decoders[] = {
34
+ { always_true_p, rvi_opcode_data, decode_inst_opcode },
35
+ };
36
+
37
+ for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
38
+ bool (*guard_func)(const RISCVCPUConfig *) = decoders[i].guard_func;
39
+ const rv_opcode_data *opcode_data = decoders[i].opcode_data;
40
+ void (*decode_func)(rv_decode *, rv_isa) = decoders[i].decode_func;
41
+
42
+ if (guard_func(cfg)) {
43
+ dec.opcode_data = opcode_data;
44
+ decode_func(&dec, isa);
45
+ if (dec.op != rv_op_illegal)
46
+ break;
47
+ }
48
+ }
49
+
50
+ if (dec.op == rv_op_illegal) {
51
+ dec.opcode_data = rvi_opcode_data;
52
+ }
53
+
54
decode_inst_operands(&dec, isa);
55
decode_inst_decompress(&dec, isa);
56
decode_inst_lift_pseudo(&dec);
57
--
58
2.40.1
59
60
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
This patch adds XVentanaCondOps support to the RISC-V disassembler.
4
5
Co-developed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
6
Acked-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-Id: <20230612111034.3955227-8-christoph.muellner@vrull.eu>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
disas/riscv-xventana.h | 18 ++++++++++++++++++
13
disas/riscv-xventana.c | 41 +++++++++++++++++++++++++++++++++++++++++
14
disas/riscv.c | 4 ++++
15
disas/meson.build | 5 ++++-
16
4 files changed, 67 insertions(+), 1 deletion(-)
17
create mode 100644 disas/riscv-xventana.h
18
create mode 100644 disas/riscv-xventana.c
19
20
diff --git a/disas/riscv-xventana.h b/disas/riscv-xventana.h
21
new file mode 100644
22
index XXXXXXX..XXXXXXX
23
--- /dev/null
24
+++ b/disas/riscv-xventana.h
25
@@ -XXX,XX +XXX,XX @@
26
+/*
27
+ * QEMU disassembler -- RISC-V specific header (xventana*).
28
+ *
29
+ * Copyright (c) 2023 VRULL GmbH
30
+ *
31
+ * SPDX-License-Identifier: GPL-2.0-or-later
32
+ */
33
+
34
+#ifndef DISAS_RISCV_XVENTANA_H
35
+#define DISAS_RISCV_XVENTANA_H
36
+
37
+#include "disas/riscv.h"
38
+
39
+extern const rv_opcode_data ventana_opcode_data[];
40
+
41
+void decode_xventanacondops(rv_decode*, rv_isa);
42
+
43
+#endif /* DISAS_RISCV_XVENTANA_H */
44
diff --git a/disas/riscv-xventana.c b/disas/riscv-xventana.c
45
new file mode 100644
46
index XXXXXXX..XXXXXXX
47
--- /dev/null
48
+++ b/disas/riscv-xventana.c
49
@@ -XXX,XX +XXX,XX @@
50
+/*
51
+ * QEMU RISC-V Disassembler for xventana.
52
+ *
53
+ * SPDX-License-Identifier: GPL-2.0-or-later
54
+ */
55
+
56
+#include "disas/riscv.h"
57
+#include "disas/riscv-xventana.h"
58
+
59
+typedef enum {
60
+ /* 0 is reserved for rv_op_illegal. */
61
+ ventana_op_vt_maskc = 1,
62
+ ventana_op_vt_maskcn = 2,
63
+} rv_ventana_op;
64
+
65
+const rv_opcode_data ventana_opcode_data[] = {
66
+ { "vt.illegal", rv_codec_illegal, rv_fmt_none, NULL, 0, 0, 0 },
67
+ { "vt.maskc", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
68
+ { "vt.maskcn", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
69
+};
70
+
71
+void decode_xventanacondops(rv_decode *dec, rv_isa isa)
72
+{
73
+ rv_inst inst = dec->inst;
74
+ rv_opcode op = rv_op_illegal;
75
+
76
+ switch (((inst >> 0) & 0b11)) {
77
+ case 3:
78
+ switch (((inst >> 2) & 0b11111)) {
79
+ case 30:
80
+ switch (((inst >> 22) & 0b1111111000) | ((inst >> 12) & 0b0000000111)) {
81
+ case 6: op = ventana_op_vt_maskc; break;
82
+ case 7: op = ventana_op_vt_maskcn; break;
83
+ }
84
+ break;
85
+ }
86
+ break;
87
+ }
88
+
89
+ dec->op = op;
90
+}
91
diff --git a/disas/riscv.c b/disas/riscv.c
92
index XXXXXXX..XXXXXXX 100644
93
--- a/disas/riscv.c
94
+++ b/disas/riscv.c
95
@@ -XXX,XX +XXX,XX @@
96
#include "target/riscv/cpu_cfg.h"
97
#include "disas/riscv.h"
98
99
+/* Vendor extensions */
100
+#include "disas/riscv-xventana.h"
101
+
102
typedef enum {
103
/* 0 is reserved for rv_op_illegal. */
104
rv_op_lui = 1,
105
@@ -XXX,XX +XXX,XX @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst,
106
void (*decode_func)(rv_decode *, rv_isa);
107
} decoders[] = {
108
{ always_true_p, rvi_opcode_data, decode_inst_opcode },
109
+ { has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
110
};
111
112
for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
113
diff --git a/disas/meson.build b/disas/meson.build
114
index XXXXXXX..XXXXXXX 100644
115
--- a/disas/meson.build
116
+++ b/disas/meson.build
117
@@ -XXX,XX +XXX,XX @@ common_ss.add(when: 'CONFIG_M68K_DIS', if_true: files('m68k.c'))
118
common_ss.add(when: 'CONFIG_MICROBLAZE_DIS', if_true: files('microblaze.c'))
119
common_ss.add(when: 'CONFIG_MIPS_DIS', if_true: files('mips.c', 'nanomips.c'))
120
common_ss.add(when: 'CONFIG_NIOS2_DIS', if_true: files('nios2.c'))
121
-common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files('riscv.c'))
122
+common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files(
123
+ 'riscv.c',
124
+ 'riscv-xventana.c'
125
+))
126
common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
127
common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
128
common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
129
--
130
2.40.1
131
132
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
1
3
Support for emulating XThead* instruction has been added recently.
4
This patch adds support for these instructions to the RISC-V disassembler.
5
6
Co-developed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
7
Acked-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
9
Message-Id: <20230612111034.3955227-9-christoph.muellner@vrull.eu>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
disas/riscv-xthead.h | 28 ++
13
disas/riscv.h | 12 +
14
target/riscv/cpu_cfg.h | 11 +
15
disas/riscv-xthead.c | 707 +++++++++++++++++++++++++++++++++++++++++
16
disas/riscv.c | 69 ++++
17
disas/meson.build | 1 +
18
6 files changed, 828 insertions(+)
19
create mode 100644 disas/riscv-xthead.h
20
create mode 100644 disas/riscv-xthead.c
21
22
diff --git a/disas/riscv-xthead.h b/disas/riscv-xthead.h
23
new file mode 100644
24
index XXXXXXX..XXXXXXX
25
--- /dev/null
26
+++ b/disas/riscv-xthead.h
27
@@ -XXX,XX +XXX,XX @@
28
+/*
29
+ * QEMU disassembler -- RISC-V specific header (xthead*).
30
+ *
31
+ * Copyright (c) 2023 VRULL GmbH
32
+ *
33
+ * SPDX-License-Identifier: GPL-2.0-or-later
34
+ */
35
+
36
+#ifndef DISAS_RISCV_XTHEAD_H
37
+#define DISAS_RISCV_XTHEAD_H
38
+
39
+#include "disas/riscv.h"
40
+
41
+extern const rv_opcode_data xthead_opcode_data[];
42
+
43
+void decode_xtheadba(rv_decode *, rv_isa);
44
+void decode_xtheadbb(rv_decode *, rv_isa);
45
+void decode_xtheadbs(rv_decode *, rv_isa);
46
+void decode_xtheadcmo(rv_decode *, rv_isa);
47
+void decode_xtheadcondmov(rv_decode *, rv_isa);
48
+void decode_xtheadfmemidx(rv_decode *, rv_isa);
49
+void decode_xtheadfmv(rv_decode *, rv_isa);
50
+void decode_xtheadmac(rv_decode *, rv_isa);
51
+void decode_xtheadmemidx(rv_decode *, rv_isa);
52
+void decode_xtheadmempair(rv_decode *, rv_isa);
53
+void decode_xtheadsync(rv_decode *, rv_isa);
54
+
55
+#endif /* DISAS_RISCV_XTHEAD_H */
56
diff --git a/disas/riscv.h b/disas/riscv.h
57
index XXXXXXX..XXXXXXX 100644
58
--- a/disas/riscv.h
59
+++ b/disas/riscv.h
60
@@ -XXX,XX +XXX,XX @@ typedef enum {
61
rv_codec_zcmp_cm_pushpop,
62
rv_codec_zcmp_cm_mv,
63
rv_codec_zcmt_jt,
64
+ rv_codec_r2_imm5,
65
+ rv_codec_r2,
66
+ rv_codec_r2_imm6,
67
+ rv_codec_r_imm2,
68
+ rv_codec_r2_immhl,
69
+ rv_codec_r2_imm2_imm5,
70
} rv_codec;
71
72
/* structures */
73
@@ -XXX,XX +XXX,XX @@ typedef struct {
74
uint64_t inst;
75
const rv_opcode_data *opcode_data;
76
int32_t imm;
77
+ int32_t imm1;
78
uint16_t op;
79
uint8_t codec;
80
uint8_t rd;
81
@@ -XXX,XX +XXX,XX @@ enum {
82
#define rv_fmt_push_rlist "O\tx,-i"
83
#define rv_fmt_pop_rlist "O\tx,i"
84
#define rv_fmt_zcmt_index "O\ti"
85
+#define rv_fmt_rd_rs1_rs2_imm "O\t0,1,2,i"
86
+#define rv_fmt_frd_rs1_rs2_imm "O\t3,1,2,i"
87
+#define rv_fmt_rd_rs1_immh_imml "O\t0,1,i,j"
88
+#define rv_fmt_rd_rs1_immh_imml_addr "O\t0,(1),i,j"
89
+#define rv_fmt_rd2_imm "O\t0,2,(1),i"
90
91
#endif /* DISAS_RISCV_H */
92
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
93
index XXXXXXX..XXXXXXX 100644
94
--- a/target/riscv/cpu_cfg.h
95
+++ b/target/riscv/cpu_cfg.h
96
@@ -XXX,XX +XXX,XX @@ static inline bool has_xthead_p(const RISCVCPUConfig *cfg)
97
return cfg->ext_ ## ext ; \
98
}
99
100
+MATERIALISE_EXT_PREDICATE(xtheadba)
101
+MATERIALISE_EXT_PREDICATE(xtheadbb)
102
+MATERIALISE_EXT_PREDICATE(xtheadbs)
103
+MATERIALISE_EXT_PREDICATE(xtheadcmo)
104
+MATERIALISE_EXT_PREDICATE(xtheadcondmov)
105
+MATERIALISE_EXT_PREDICATE(xtheadfmemidx)
106
+MATERIALISE_EXT_PREDICATE(xtheadfmv)
107
+MATERIALISE_EXT_PREDICATE(xtheadmac)
108
+MATERIALISE_EXT_PREDICATE(xtheadmemidx)
109
+MATERIALISE_EXT_PREDICATE(xtheadmempair)
110
+MATERIALISE_EXT_PREDICATE(xtheadsync)
111
MATERIALISE_EXT_PREDICATE(XVentanaCondOps)
112
113
#endif
114
diff --git a/disas/riscv-xthead.c b/disas/riscv-xthead.c
115
new file mode 100644
116
index XXXXXXX..XXXXXXX
117
--- /dev/null
118
+++ b/disas/riscv-xthead.c
119
@@ -XXX,XX +XXX,XX @@
120
+/*
121
+ * QEMU RISC-V Disassembler for xthead.
122
+ *
123
+ * SPDX-License-Identifier: GPL-2.0-or-later
124
+ */
125
+
126
+#include "disas/riscv.h"
127
+#include "disas/riscv-xthead.h"
128
+
129
+typedef enum {
130
+ /* 0 is reserved for rv_op_illegal. */
131
+ /* XTheadBa */
132
+ rv_op_th_addsl = 1,
133
+ /* XTheadBb */
134
+ rv_op_th_srri,
135
+ rv_op_th_srriw,
136
+ rv_op_th_ext,
137
+ rv_op_th_extu,
138
+ rv_op_th_ff0,
139
+ rv_op_th_ff1,
140
+ rv_op_th_rev,
141
+ rv_op_th_revw,
142
+ rv_op_th_tstnbz,
143
+ /* XTheadBs */
144
+ rv_op_th_tst,
145
+ /* XTheadCmo */
146
+ rv_op_th_dcache_call,
147
+ rv_op_th_dcache_ciall,
148
+ rv_op_th_dcache_iall,
149
+ rv_op_th_dcache_cpa,
150
+ rv_op_th_dcache_cipa,
151
+ rv_op_th_dcache_ipa,
152
+ rv_op_th_dcache_cva,
153
+ rv_op_th_dcache_civa,
154
+ rv_op_th_dcache_iva,
155
+ rv_op_th_dcache_csw,
156
+ rv_op_th_dcache_cisw,
157
+ rv_op_th_dcache_isw,
158
+ rv_op_th_dcache_cpal1,
159
+ rv_op_th_dcache_cval1,
160
+ rv_op_th_icache_iall,
161
+ rv_op_th_icache_ialls,
162
+ rv_op_th_icache_ipa,
163
+ rv_op_th_icache_iva,
164
+ rv_op_th_l2cache_call,
165
+ rv_op_th_l2cache_ciall,
166
+ rv_op_th_l2cache_iall,
167
+ /* XTheadCondMov */
168
+ rv_op_th_mveqz,
169
+ rv_op_th_mvnez,
170
+ /* XTheadFMemIdx */
171
+ rv_op_th_flrd,
172
+ rv_op_th_flrw,
173
+ rv_op_th_flurd,
174
+ rv_op_th_flurw,
175
+ rv_op_th_fsrd,
176
+ rv_op_th_fsrw,
177
+ rv_op_th_fsurd,
178
+ rv_op_th_fsurw,
179
+ /* XTheadFmv */
180
+ rv_op_th_fmv_hw_x,
181
+ rv_op_th_fmv_x_hw,
182
+ /* XTheadMac */
183
+ rv_op_th_mula,
184
+ rv_op_th_mulah,
185
+ rv_op_th_mulaw,
186
+ rv_op_th_muls,
187
+ rv_op_th_mulsw,
188
+ rv_op_th_mulsh,
189
+ /* XTheadMemIdx */
190
+ rv_op_th_lbia,
191
+ rv_op_th_lbib,
192
+ rv_op_th_lbuia,
193
+ rv_op_th_lbuib,
194
+ rv_op_th_lhia,
195
+ rv_op_th_lhib,
196
+ rv_op_th_lhuia,
197
+ rv_op_th_lhuib,
198
+ rv_op_th_lwia,
199
+ rv_op_th_lwib,
200
+ rv_op_th_lwuia,
201
+ rv_op_th_lwuib,
202
+ rv_op_th_ldia,
203
+ rv_op_th_ldib,
204
+ rv_op_th_sbia,
205
+ rv_op_th_sbib,
206
+ rv_op_th_shia,
207
+ rv_op_th_shib,
208
+ rv_op_th_swia,
209
+ rv_op_th_swib,
210
+ rv_op_th_sdia,
211
+ rv_op_th_sdib,
212
+ rv_op_th_lrb,
213
+ rv_op_th_lrbu,
214
+ rv_op_th_lrh,
215
+ rv_op_th_lrhu,
216
+ rv_op_th_lrw,
217
+ rv_op_th_lrwu,
218
+ rv_op_th_lrd,
219
+ rv_op_th_srb,
220
+ rv_op_th_srh,
221
+ rv_op_th_srw,
222
+ rv_op_th_srd,
223
+ rv_op_th_lurb,
224
+ rv_op_th_lurbu,
225
+ rv_op_th_lurh,
226
+ rv_op_th_lurhu,
227
+ rv_op_th_lurw,
228
+ rv_op_th_lurwu,
229
+ rv_op_th_lurd,
230
+ rv_op_th_surb,
231
+ rv_op_th_surh,
232
+ rv_op_th_surw,
233
+ rv_op_th_surd,
234
+ /* XTheadMemPair */
235
+ rv_op_th_ldd,
236
+ rv_op_th_lwd,
237
+ rv_op_th_lwud,
238
+ rv_op_th_sdd,
239
+ rv_op_th_swd,
240
+ /* XTheadSync */
241
+ rv_op_th_sfence_vmas,
242
+ rv_op_th_sync,
243
+ rv_op_th_sync_i,
244
+ rv_op_th_sync_is,
245
+ rv_op_th_sync_s,
246
+} rv_xthead_op;
247
+
248
+const rv_opcode_data xthead_opcode_data[] = {
249
+ { "th.illegal", rv_codec_illegal, rv_fmt_none, NULL, 0, 0, 0 },
250
+ /* XTheadBa */
251
+ { "th.addsl", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
252
+ /* XTheadBb */
253
+ { "th.srri", rv_codec_r2_imm6, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 },
254
+ { "th.srriw", rv_codec_r2_imm5, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 },
255
+ { "th.ext", rv_codec_r2_immhl, rv_fmt_rd_rs1_immh_imml, NULL, 0, 0, 0 },
256
+ { "th.extu", rv_codec_r2_immhl, rv_fmt_rd_rs1_immh_imml, NULL, 0, 0, 0 },
257
+ { "th.ff0", rv_codec_r2, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
258
+ { "th.ff1", rv_codec_r2, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
259
+ { "th.rev", rv_codec_r2, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
260
+ { "th.revw", rv_codec_r2, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
261
+ { "th.tstnbz", rv_codec_r2, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
262
+ /* XTheadBs */
263
+ { "th.tst", rv_codec_r2_imm6, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 },
264
+ /* XTheadCmo */
265
+ { "th.dcache.call", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
266
+ { "th.dcache.ciall", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
267
+ { "th.dcache.iall", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
268
+ { "th.dcache.cpa", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
269
+ { "th.dcache.cipa", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
270
+ { "th.dcache.ipa", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
271
+ { "th.dcache.cva", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
272
+ { "th.dcache.civa", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
273
+ { "th.dcache.iva", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
274
+ { "th.dcache.csw", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
275
+ { "th.dcache.cisw", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
276
+ { "th.dcache.isw", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
277
+ { "th.dcache.cpal1", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
278
+ { "th.dcache.cval1", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
279
+ { "th.icache.iall", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
280
+ { "th.icache.ialls", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
281
+ { "th.icache.ipa", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
282
+ { "th.icache.iva", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 },
283
+ { "th.l2cache.call", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
284
+ { "th.l2cache.ciall", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
285
+ { "th.l2cache.iall", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
286
+ /* XTheadCondMov */
287
+ { "th.mveqz", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
288
+ { "th.mvnez", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
289
+ /* XTheadFMemIdx */
290
+ { "th.flrd", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
291
+ { "th.flrw", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
292
+ { "th.flurd", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
293
+ { "th.flurw", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
294
+ { "th.fsrd", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
295
+ { "th.fsrw", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
296
+ { "th.fsurd", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
297
+ { "th.fsurw", rv_codec_r_imm2, rv_fmt_frd_rs1_rs2_imm, NULL, 0, 0, 0 },
298
+ /* XTheadFmv */
299
+ { "th.fmv.hw.x", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
300
+ { "th.fmv.x.hw", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
301
+ /* XTheadMac */
302
+ { "th.mula", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
303
+ { "th.mulaw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
304
+ { "th.mulah", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
305
+ { "th.muls", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
306
+ { "th.mulsw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
307
+ { "th.mulsh", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
308
+ /* XTheadMemIdx */
309
+ { "th.lbia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
310
+ { "th.lbib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml, NULL, 0, 0, 0 },
311
+ { "th.lbuia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
312
+ { "th.lbuib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
313
+ { "th.lhia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
314
+ { "th.lhib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
315
+ { "th.lhuia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
316
+ { "th.lhuib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
317
+ { "th.lwia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
318
+ { "th.lwib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
319
+ { "th.lwuia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
320
+ { "th.lwuib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
321
+ { "th.ldia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
322
+ { "th.ldib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
323
+ { "th.sbia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
324
+ { "th.sbib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
325
+ { "th.shia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
326
+ { "th.shib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
327
+ { "th.swia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
328
+ { "th.swib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
329
+ { "th.sdia", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
330
+ { "th.sdib", rv_codec_r2_imm2_imm5, rv_fmt_rd_rs1_immh_imml_addr, NULL, 0, 0, 0 },
331
+ { "th.lrb", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
332
+ { "th.lrbu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
333
+ { "th.lrh", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
334
+ { "th.lrhu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
335
+ { "th.lrw", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
336
+ { "th.lrwu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
337
+ { "th.lrd", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
338
+ { "th.srb", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
339
+ { "th.srh", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
340
+ { "th.srw", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
341
+ { "th.srd", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
342
+ { "th.lurb", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
343
+ { "th.lurbu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
344
+ { "th.lurh", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
345
+ { "th.lurhu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
346
+ { "th.lurw", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
347
+ { "th.lurwu", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
348
+ { "th.lurd", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
349
+ { "th.surb", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
350
+ { "th.surh", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
351
+ { "th.surw", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
352
+ { "th.surd", rv_codec_r_imm2, rv_fmt_rd_rs1_rs2_imm, NULL, 0, 0, 0 },
353
+ /* XTheadMemPair */
354
+ { "th.ldd", rv_codec_r_imm2, rv_fmt_rd2_imm, NULL, 0, 0, 0 },
355
+ { "th.lwd", rv_codec_r_imm2, rv_fmt_rd2_imm, NULL, 0, 0, 0 },
356
+ { "th.lwud", rv_codec_r_imm2, rv_fmt_rd2_imm, NULL, 0, 0, 0 },
357
+ { "th.sdd", rv_codec_r_imm2, rv_fmt_rd2_imm, NULL, 0, 0, 0 },
358
+ { "th.swd", rv_codec_r_imm2, rv_fmt_rd2_imm, NULL, 0, 0, 0 },
359
+ /* XTheadSync */
360
+ { "th.sfence.vmas", rv_codec_r, rv_fmt_rs1_rs2, NULL, 0, 0, 0 },
361
+ { "th.sync", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
362
+ { "th.sync.i", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
363
+ { "th.sync.is", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
364
+ { "th.sync.s", rv_codec_none, rv_fmt_none, NULL, 0, 0, 0 },
365
+};
366
+
367
+void decode_xtheadba(rv_decode *dec, rv_isa isa)
368
+{
369
+ rv_inst inst = dec->inst;
370
+ rv_opcode op = rv_op_illegal;
371
+
372
+ switch (((inst >> 0) & 0b11)) {
373
+ case 3:
374
+ switch (((inst >> 2) & 0b11111)) {
375
+ case 2:
376
+ /* custom-0 */
377
+ switch ((inst >> 12) & 0b111) {
378
+ case 1:
379
+ switch ((inst >> 25) & 0b1111111) {
380
+ case 0b0000000:
381
+ case 0b0000001:
382
+ case 0b0000010:
383
+ case 0b0000011: op = rv_op_th_addsl; break;
384
+ }
385
+ break;
386
+ }
387
+ break;
388
+ /* custom-0 */
389
+ }
390
+ break;
391
+ }
392
+
393
+ dec->op = op;
394
+}
395
+
396
+void decode_xtheadbb(rv_decode *dec, rv_isa isa)
397
+{
398
+ rv_inst inst = dec->inst;
399
+ rv_opcode op = rv_op_illegal;
400
+
401
+ switch (((inst >> 0) & 0b11)) {
402
+ case 3:
403
+ switch (((inst >> 2) & 0b11111)) {
404
+ case 2:
405
+ /* custom-0 */
406
+ switch ((inst >> 12) & 0b111) {
407
+ case 1:
408
+ switch ((inst >> 25) & 0b1111111) {
409
+ case 0b0001010: op = rv_op_th_srriw; break;
410
+ case 0b1000000:
411
+ if (((inst >> 20) & 0b11111) == 0) {
412
+ op = rv_op_th_tstnbz;
413
+ }
414
+ break;
415
+ case 0b1000001:
416
+ if (((inst >> 20) & 0b11111) == 0) {
417
+ op = rv_op_th_rev;
418
+ }
419
+ break;
420
+ case 0b1000010:
421
+ if (((inst >> 20) & 0b11111) == 0) {
422
+ op = rv_op_th_ff0;
423
+ }
424
+ break;
425
+ case 0b1000011:
426
+ if (((inst >> 20) & 0b11111) == 0) {
427
+ op = rv_op_th_ff1;
428
+ }
429
+ break;
430
+ case 0b1000100:
431
+ case 0b1001000:
432
+ if (((inst >> 20) & 0b11111) == 0) {
433
+ op = rv_op_th_revw;
434
+ }
435
+ break;
436
+ case 0b0000100:
437
+ case 0b0000101: op = rv_op_th_srri; break;
438
+ }
439
+ break;
440
+ case 2: op = rv_op_th_ext; break;
441
+ case 3: op = rv_op_th_extu; break;
442
+ }
443
+ break;
444
+ /* custom-0 */
445
+ }
446
+ break;
447
+ }
448
+
449
+ dec->op = op;
450
+}
451
+
452
+void decode_xtheadbs(rv_decode *dec, rv_isa isa)
453
+{
454
+ rv_inst inst = dec->inst;
455
+ rv_opcode op = rv_op_illegal;
456
+
457
+ switch (((inst >> 0) & 0b11)) {
458
+ case 3:
459
+ switch (((inst >> 2) & 0b11111)) {
460
+ case 2:
461
+ /* custom-0 */
462
+ switch ((inst >> 12) & 0b111) {
463
+ case 1:
464
+ switch ((inst >> 26) & 0b111111) {
465
+ case 0b100010: op = rv_op_th_tst; break;
466
+ }
467
+ break;
468
+ }
469
+ break;
470
+ /* custom-0 */
471
+ }
472
+ break;
473
+ }
474
+
475
+ dec->op = op;
476
+}
477
+
478
+void decode_xtheadcmo(rv_decode *dec, rv_isa isa)
479
+{
480
+ rv_inst inst = dec->inst;
481
+ rv_opcode op = rv_op_illegal;
482
+
483
+ switch (((inst >> 0) & 0b11)) {
484
+ case 3:
485
+ switch (((inst >> 2) & 0b11111)) {
486
+ case 2:
487
+ /* custom-0 */
488
+ switch ((inst >> 12) & 0b111) {
489
+ case 0:
490
+ switch ((inst >> 20 & 0b111111111111)) {
491
+ case 0b000000000001:
492
+ if (((inst >> 20) & 0b11111) == 0) {
493
+ op = rv_op_th_dcache_call;
494
+ }
495
+ break;
496
+ case 0b000000000011:
497
+ if (((inst >> 20) & 0b11111) == 0) {
498
+ op = rv_op_th_dcache_ciall;
499
+ }
500
+ break;
501
+ case 0b000000000010:
502
+ if (((inst >> 20) & 0b11111) == 0) {
503
+ op = rv_op_th_dcache_iall;
504
+ }
505
+ break;
506
+ case 0b000000101001: op = rv_op_th_dcache_cpa; break;
507
+ case 0b000000101011: op = rv_op_th_dcache_cipa; break;
508
+ case 0b000000101010: op = rv_op_th_dcache_ipa; break;
509
+ case 0b000000100101: op = rv_op_th_dcache_cva; break;
510
+ case 0b000000100111: op = rv_op_th_dcache_civa; break;
511
+ case 0b000000100110: op = rv_op_th_dcache_iva; break;
512
+ case 0b000000100001: op = rv_op_th_dcache_csw; break;
513
+ case 0b000000100011: op = rv_op_th_dcache_cisw; break;
514
+ case 0b000000100010: op = rv_op_th_dcache_isw; break;
515
+ case 0b000000101000: op = rv_op_th_dcache_cpal1; break;
516
+ case 0b000000100100: op = rv_op_th_dcache_cval1; break;
517
+ case 0b000000010000:
518
+ if (((inst >> 20) & 0b11111) == 0) {
519
+ op = rv_op_th_icache_iall;
520
+ }
521
+ break;
522
+ case 0b000000010001:
523
+ if (((inst >> 20) & 0b11111) == 0) {
524
+ op = rv_op_th_icache_ialls;
525
+ }
526
+ break;
527
+ case 0b000000111000: op = rv_op_th_icache_ipa; break;
528
+ case 0b000000110000: op = rv_op_th_icache_iva; break;
529
+ case 0b000000010101:
530
+ if (((inst >> 20) & 0b11111) == 0) {
531
+ op = rv_op_th_l2cache_call;
532
+ }
533
+ break;
534
+ case 0b000000010111:
535
+ if (((inst >> 20) & 0b11111) == 0) {
536
+ op = rv_op_th_l2cache_ciall;
537
+ }
538
+ break;
539
+ case 0b000000010110:
540
+ if (((inst >> 20) & 0b11111) == 0) {
541
+ op = rv_op_th_l2cache_iall;
542
+ }
543
+ break;
544
+ }
545
+ break;
546
+ }
547
+ break;
548
+ /* custom-0 */
549
+ }
550
+ break;
551
+ }
552
+
553
+ dec->op = op;
554
+}
555
+
556
+void decode_xtheadcondmov(rv_decode *dec, rv_isa isa)
557
+{
558
+ rv_inst inst = dec->inst;
559
+ rv_opcode op = rv_op_illegal;
560
+
561
+ switch (((inst >> 0) & 0b11)) {
562
+ case 3:
563
+ switch (((inst >> 2) & 0b11111)) {
564
+ case 2:
565
+ /* custom-0 */
566
+ switch ((inst >> 12) & 0b111) {
567
+ case 1:
568
+ switch ((inst >> 25) & 0b1111111) {
569
+ case 0b0100000: op = rv_op_th_mveqz; break;
570
+ case 0b0100001: op = rv_op_th_mvnez; break;
571
+ }
572
+ break;
573
+ }
574
+ break;
575
+ /* custom-0 */
576
+ }
577
+ break;
578
+ }
579
+
580
+ dec->op = op;
581
+}
582
+
583
+void decode_xtheadfmemidx(rv_decode *dec, rv_isa isa)
584
+{
585
+ rv_inst inst = dec->inst;
586
+ rv_opcode op = rv_op_illegal;
587
+
588
+ switch (((inst >> 0) & 0b11)) {
589
+ case 3:
590
+ switch (((inst >> 2) & 0b11111)) {
591
+ case 2:
592
+ /* custom-0 */
593
+ switch ((inst >> 12) & 0b111) {
594
+ case 6:
595
+ switch ((inst >> 27) & 0b11111) {
596
+ case 8: op = rv_op_th_flrw; break;
597
+ case 10: op = rv_op_th_flurw; break;
598
+ case 12: op = rv_op_th_flrd; break;
599
+ case 14: op = rv_op_th_flurd; break;
600
+ }
601
+ break;
602
+ case 7:
603
+ switch ((inst >> 27) & 0b11111) {
604
+ case 8: op = rv_op_th_fsrw; break;
605
+ case 10: op = rv_op_th_fsurw; break;
606
+ case 12: op = rv_op_th_fsrd; break;
607
+ case 14: op = rv_op_th_fsurd; break;
608
+ }
609
+ break;
610
+ }
611
+ break;
612
+ /* custom-0 */
613
+ }
614
+ break;
615
+ }
616
+
617
+ dec->op = op;
618
+}
619
+
620
+void decode_xtheadfmv(rv_decode *dec, rv_isa isa)
621
+{
622
+ rv_inst inst = dec->inst;
623
+ rv_opcode op = rv_op_illegal;
624
+
625
+ switch (((inst >> 0) & 0b11)) {
626
+ case 3:
627
+ switch (((inst >> 2) & 0b11111)) {
628
+ case 2:
629
+ /* custom-0 */
630
+ switch ((inst >> 12) & 0b111) {
631
+ case 1:
632
+ switch ((inst >> 25) & 0b1111111) {
633
+ case 0b1010000:
634
+ if (((inst >> 20) & 0b11111) == 0) {
635
+ op = rv_op_th_fmv_hw_x;
636
+ }
637
+ break;
638
+ case 0b1100000:
639
+ if (((inst >> 20) & 0b11111) == 0) {
640
+ op = rv_op_th_fmv_x_hw;
641
+ }
642
+ break;
643
+ }
644
+ break;
645
+ }
646
+ break;
647
+ /* custom-0 */
648
+ }
649
+ break;
650
+ }
651
+
652
+ dec->op = op;
653
+}
654
+
655
+void decode_xtheadmac(rv_decode *dec, rv_isa isa)
656
+{
657
+ rv_inst inst = dec->inst;
658
+ rv_opcode op = rv_op_illegal;
659
+
660
+ switch (((inst >> 0) & 0b11)) {
661
+ case 3:
662
+ switch (((inst >> 2) & 0b11111)) {
663
+ case 2:
664
+ /* custom-0 */
665
+ switch ((inst >> 12) & 0b111) {
666
+ case 1:
667
+ switch ((inst >> 25) & 0b1111111) {
668
+ case 0b0010000: op = rv_op_th_mula; break;
669
+ case 0b0010001: op = rv_op_th_muls; break;
670
+ case 0b0010010: op = rv_op_th_mulaw; break;
671
+ case 0b0010011: op = rv_op_th_mulsw; break;
672
+ case 0b0010100: op = rv_op_th_mulah; break;
673
+ case 0b0010101: op = rv_op_th_mulsh; break;
674
+ }
675
+ break;
676
+ }
677
+ break;
678
+ /* custom-0 */
679
+ }
680
+ break;
681
+ }
682
+
683
+ dec->op = op;
684
+}
685
+
686
+void decode_xtheadmemidx(rv_decode *dec, rv_isa isa)
687
+{
688
+ rv_inst inst = dec->inst;
689
+ rv_opcode op = rv_op_illegal;
690
+
691
+ switch (((inst >> 0) & 0b11)) {
692
+ case 3:
693
+ switch (((inst >> 2) & 0b11111)) {
694
+ case 2:
695
+ /* custom-0 */
696
+ switch ((inst >> 12) & 0b111) {
697
+ case 4:
698
+ switch ((inst >> 27) & 0b11111) {
699
+ case 0: op = rv_op_th_lrb; break;
700
+ case 1: op = rv_op_th_lbib; break;
701
+ case 2: op = rv_op_th_lurb; break;
702
+ case 3: op = rv_op_th_lbia; break;
703
+ case 4: op = rv_op_th_lrh; break;
704
+ case 5: op = rv_op_th_lhib; break;
705
+ case 6: op = rv_op_th_lurh; break;
706
+ case 7: op = rv_op_th_lhia; break;
707
+ case 8: op = rv_op_th_lrw; break;
708
+ case 9: op = rv_op_th_lwib; break;
709
+ case 10: op = rv_op_th_lurw; break;
710
+ case 11: op = rv_op_th_lwia; break;
711
+ case 12: op = rv_op_th_lrd; break;
712
+ case 13: op = rv_op_th_ldib; break;
713
+ case 14: op = rv_op_th_lurd; break;
714
+ case 15: op = rv_op_th_ldia; break;
715
+ case 16: op = rv_op_th_lrbu; break;
716
+ case 17: op = rv_op_th_lbuib; break;
717
+ case 18: op = rv_op_th_lurbu; break;
718
+ case 19: op = rv_op_th_lbuia; break;
719
+ case 20: op = rv_op_th_lrhu; break;
720
+ case 21: op = rv_op_th_lhuib; break;
721
+ case 22: op = rv_op_th_lurhu; break;
722
+ case 23: op = rv_op_th_lhuia; break;
723
+ case 24: op = rv_op_th_lrwu; break;
724
+ case 25: op = rv_op_th_lwuib; break;
725
+ case 26: op = rv_op_th_lurwu; break;
726
+ case 27: op = rv_op_th_lwuia; break;
727
+ }
728
+ break;
729
+ case 5:
730
+ switch ((inst >> 27) & 0b11111) {
731
+ case 0: op = rv_op_th_srb; break;
732
+ case 1: op = rv_op_th_sbib; break;
733
+ case 2: op = rv_op_th_surb; break;
734
+ case 3: op = rv_op_th_sbia; break;
735
+ case 4: op = rv_op_th_srh; break;
736
+ case 5: op = rv_op_th_shib; break;
737
+ case 6: op = rv_op_th_surh; break;
738
+ case 7: op = rv_op_th_shia; break;
739
+ case 8: op = rv_op_th_srw; break;
740
+ case 9: op = rv_op_th_swib; break;
741
+ case 10: op = rv_op_th_surw; break;
742
+ case 11: op = rv_op_th_swia; break;
743
+ case 12: op = rv_op_th_srd; break;
744
+ case 13: op = rv_op_th_sdib; break;
745
+ case 14: op = rv_op_th_surd; break;
746
+ case 15: op = rv_op_th_sdia; break;
747
+ }
748
+ break;
749
+ break;
750
+ }
751
+ break;
752
+ /* custom-0 */
753
+ }
754
+ break;
755
+ }
756
+
757
+ dec->op = op;
758
+}
759
+
760
+void decode_xtheadmempair(rv_decode *dec, rv_isa isa)
761
+{
762
+ rv_inst inst = dec->inst;
763
+ rv_opcode op = rv_op_illegal;
764
+
765
+ switch (((inst >> 0) & 0b11)) {
766
+ case 3:
767
+ switch (((inst >> 2) & 0b11111)) {
768
+ case 2:
769
+ /* custom-0 */
770
+ switch ((inst >> 12) & 0b111) {
771
+ case 4:
772
+ switch ((inst >> 27) & 0b11111) {
773
+ case 28: op = rv_op_th_lwd; break;
774
+ case 30: op = rv_op_th_lwud; break;
775
+ case 31: op = rv_op_th_ldd; break;
776
+ }
777
+ break;
778
+ case 5:
779
+ switch ((inst >> 27) & 0b11111) {
780
+ case 28: op = rv_op_th_swd; break;
781
+ case 31: op = rv_op_th_sdd; break;
782
+ }
783
+ break;
784
+ }
785
+ break;
786
+ /* custom-0 */
787
+ }
788
+ break;
789
+ }
790
+
791
+ dec->op = op;
792
+}
793
+
794
+void decode_xtheadsync(rv_decode *dec, rv_isa isa)
795
+{
796
+ rv_inst inst = dec->inst;
797
+ rv_opcode op = rv_op_illegal;
798
+
799
+ switch (((inst >> 0) & 0b11)) {
800
+ case 3:
801
+ switch (((inst >> 2) & 0b11111)) {
802
+ case 2:
803
+ /* custom-0 */
804
+ switch ((inst >> 12) & 0b111) {
805
+ case 0:
806
+ switch ((inst >> 25) & 0b1111111) {
807
+ case 0b0000010: op = rv_op_th_sfence_vmas; break;
808
+ case 0b0000000:
809
+ switch ((inst >> 20) & 0b11111) {
810
+ case 0b11000: op = rv_op_th_sync; break;
811
+ case 0b11010: op = rv_op_th_sync_i; break;
812
+ case 0b11011: op = rv_op_th_sync_is; break;
813
+ case 0b11001: op = rv_op_th_sync_s; break;
814
+ }
815
+ break;
816
+ }
817
+ break;
818
+ }
819
+ break;
820
+ /* custom-0 */
821
+ }
822
+ break;
823
+ }
824
+
825
+ dec->op = op;
826
+}
827
diff --git a/disas/riscv.c b/disas/riscv.c
828
index XXXXXXX..XXXXXXX 100644
829
--- a/disas/riscv.c
830
+++ b/disas/riscv.c
831
@@ -XXX,XX +XXX,XX @@
832
*/
833
834
#include "qemu/osdep.h"
835
+#include "qemu/bitops.h"
836
#include "disas/dis-asm.h"
837
#include "target/riscv/cpu_cfg.h"
838
#include "disas/riscv.h"
839
840
/* Vendor extensions */
841
+#include "disas/riscv-xthead.h"
842
#include "disas/riscv-xventana.h"
843
844
typedef enum {
845
@@ -XXX,XX +XXX,XX @@ static uint32_t operand_zcmp_rlist(rv_inst inst)
846
return ((inst << 56) >> 60);
847
}
848
849
+static uint32_t operand_imm6(rv_inst inst)
850
+{
851
+ return (inst << 38) >> 60;
852
+}
853
+
854
+static uint32_t operand_imm2(rv_inst inst)
855
+{
856
+ return (inst << 37) >> 62;
857
+}
858
+
859
+static uint32_t operand_immh(rv_inst inst)
860
+{
861
+ return (inst << 32) >> 58;
862
+}
863
+
864
+static uint32_t operand_imml(rv_inst inst)
865
+{
866
+ return (inst << 38) >> 58;
867
+}
868
+
869
static uint32_t calculate_stack_adj(rv_isa isa, uint32_t rlist, uint32_t spimm)
870
{
871
int xlen_bytes_log2 = isa == rv64 ? 3 : 2;
872
@@ -XXX,XX +XXX,XX @@ static void decode_inst_operands(rv_decode *dec, rv_isa isa)
873
case rv_codec_zcmt_jt:
874
dec->imm = operand_tbl_index(inst);
875
break;
876
+ case rv_codec_r2_imm5:
877
+ dec->rd = operand_rd(inst);
878
+ dec->rs1 = operand_rs1(inst);
879
+ dec->imm = operand_rs2(inst);
880
+ break;
881
+ case rv_codec_r2:
882
+ dec->rd = operand_rd(inst);
883
+ dec->rs1 = operand_rs1(inst);
884
+ break;
885
+ case rv_codec_r2_imm6:
886
+ dec->rd = operand_rd(inst);
887
+ dec->rs1 = operand_rs1(inst);
888
+ dec->imm = operand_imm6(inst);
889
+ break;
890
+ case rv_codec_r_imm2:
891
+ dec->rd = operand_rd(inst);
892
+ dec->rs1 = operand_rs1(inst);
893
+ dec->rs2 = operand_rs2(inst);
894
+ dec->imm = operand_imm2(inst);
895
+ break;
896
+ case rv_codec_r2_immhl:
897
+ dec->rd = operand_rd(inst);
898
+ dec->rs1 = operand_rs1(inst);
899
+ dec->imm = operand_immh(inst);
900
+ dec->imm1 = operand_imml(inst);
901
+ break;
902
+ case rv_codec_r2_imm2_imm5:
903
+ dec->rd = operand_rd(inst);
904
+ dec->rs1 = operand_rs1(inst);
905
+ dec->imm = sextract32(operand_rs2(inst), 0, 5);
906
+ dec->imm1 = operand_imm2(inst);
907
+ break;
908
};
909
}
910
911
@@ -XXX,XX +XXX,XX @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
912
snprintf(tmp, sizeof(tmp), "%u", ((uint32_t)dec->imm & 0b11111));
913
append(buf, tmp, buflen);
914
break;
915
+ case 'j':
916
+ snprintf(tmp, sizeof(tmp), "%d", dec->imm1);
917
+ append(buf, tmp, buflen);
918
+ break;
919
case 'o':
920
snprintf(tmp, sizeof(tmp), "%d", dec->imm);
921
append(buf, tmp, buflen);
922
@@ -XXX,XX +XXX,XX @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst,
923
void (*decode_func)(rv_decode *, rv_isa);
924
} decoders[] = {
925
{ always_true_p, rvi_opcode_data, decode_inst_opcode },
926
+ { has_xtheadba_p, xthead_opcode_data, decode_xtheadba },
927
+ { has_xtheadbb_p, xthead_opcode_data, decode_xtheadbb },
928
+ { has_xtheadbs_p, xthead_opcode_data, decode_xtheadbs },
929
+ { has_xtheadcmo_p, xthead_opcode_data, decode_xtheadcmo },
930
+ { has_xtheadcondmov_p, xthead_opcode_data, decode_xtheadcondmov },
931
+ { has_xtheadfmemidx_p, xthead_opcode_data, decode_xtheadfmemidx },
932
+ { has_xtheadfmv_p, xthead_opcode_data, decode_xtheadfmv },
933
+ { has_xtheadmac_p, xthead_opcode_data, decode_xtheadmac },
934
+ { has_xtheadmemidx_p, xthead_opcode_data, decode_xtheadmemidx },
935
+ { has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
936
+ { has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
937
{ has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
938
};
939
940
diff --git a/disas/meson.build b/disas/meson.build
941
index XXXXXXX..XXXXXXX 100644
942
--- a/disas/meson.build
943
+++ b/disas/meson.build
944
@@ -XXX,XX +XXX,XX @@ common_ss.add(when: 'CONFIG_MIPS_DIS', if_true: files('mips.c', 'nanomips.c'))
945
common_ss.add(when: 'CONFIG_NIOS2_DIS', if_true: files('nios2.c'))
946
common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files(
947
'riscv.c',
948
+ 'riscv-xthead.c',
949
'riscv-xventana.c'
950
))
951
common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
952
--
953
2.40.1
954
955
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
There are 2 places in which we need to get a pointer to a certain
3
The opfv_narrow_check needs to check the single width float operator by
4
property of the cpu->cfg struct based on property offset. Next patch
4
require_rvf.
5
will add a couple more.
6
5
7
Create a helper to avoid repeating this code over and over.
6
Signed-off-by: Max Chou <max.chou@sifive.com>
8
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Message-ID: <20240322092600.1198921-4-max.chou@sifive.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Message-Id: <20230706101738.460804-20-dbarboza@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
11
---
15
target/riscv/kvm.c | 11 +++++++----
12
target/riscv/insn_trans/trans_rvv.c.inc | 1 +
16
1 file changed, 7 insertions(+), 4 deletions(-)
13
1 file changed, 1 insertion(+)
17
14
18
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
19
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/kvm.c
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
21
+++ b/target/riscv/kvm.c
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
22
@@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = {
19
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
23
KVM_EXT_CFG("svpbmt", ext_svpbmt, KVM_RISCV_ISA_EXT_SVPBMT),
20
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
24
};
25
26
+static void *kvmconfig_get_cfg_addr(RISCVCPU *cpu, KVMCPUConfig *kvmcfg)
27
+{
28
+ return (void *)&cpu->cfg + kvmcfg->offset;
29
+}
30
+
31
static void kvm_cpu_cfg_set(RISCVCPU *cpu, KVMCPUConfig *multi_ext,
32
uint32_t val)
33
{
21
{
34
- int cpu_cfg_offset = multi_ext->offset;
22
return opfv_narrow_check(s, a) &&
35
- bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
23
+ require_rvf(s) &&
36
+ bool *ext_enabled = kvmconfig_get_cfg_addr(cpu, multi_ext);
24
require_scale_rvf(s) &&
37
25
(s->sew != MO_8);
38
*ext_enabled = val;
39
}
40
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_cfg_set(RISCVCPU *cpu, KVMCPUConfig *multi_ext,
41
static uint32_t kvm_cpu_cfg_get(RISCVCPU *cpu,
42
KVMCPUConfig *multi_ext)
43
{
44
- int cpu_cfg_offset = multi_ext->offset;
45
- bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
46
+ bool *ext_enabled = kvmconfig_get_cfg_addr(cpu, multi_ext);
47
48
return *ext_enabled;
49
}
26
}
50
--
27
--
51
2.40.1
28
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
If we don't set a proper cbom_blocksize|cboz_blocksize in the FDT the
3
If the checking functions check both the single and double width
4
Linux Kernel will fail to detect the availability of the CBOM/CBOZ
4
operators at the same time, then the single width operator checking
5
extensions, regardless of the contents of the 'riscv,isa' DT prop.
5
functions (require_rvf[min]) will check whether the SEW is 8.
6
6
7
The FDT is being written using the cpu->cfg.cbom|z_blocksize attributes,
7
Signed-off-by: Max Chou <max.chou@sifive.com>
8
so let's expose them as user properties like it is already done with
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
TCG.
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
10
Message-ID: <20240322092600.1198921-5-max.chou@sifive.com>
11
This will also require us to determine proper blocksize values during
12
init() time since the FDT is already created during realize(). We'll
13
take a ride in kvm_riscv_init_multiext_cfg() to do it. Note that we
14
don't need to fetch both cbom and cboz blocksizes every time: check for
15
their parent extensions (icbom and icboz) and only read the blocksizes
16
if needed.
17
18
In contrast with cbom|z_blocksize properties from TCG, the user is not
19
able to set any value that is different from the 'host' value when
20
running KVM. KVM can be particularly harsh dealing with it: a ENOTSUPP
21
can be thrown for the mere attempt of executing kvm_set_one_reg() for
22
these 2 regs.
23
24
Hopefully we don't need to call kvm_set_one_reg() for these regs.
25
We'll check if the user input matches the host value in
26
kvm_cpu_set_cbomz_blksize(), the set() accessor for both blocksize
27
properties. We'll fail fast since it's already known to not be
28
supported.
29
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Acked-by: Alistair Francis <alistair.francis@wdc.com>
33
Message-Id: <20230706101738.460804-21-dbarboza@ventanamicro.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
35
---
12
---
36
target/riscv/kvm.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
13
target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------
37
1 file changed, 70 insertions(+)
14
1 file changed, 4 insertions(+), 12 deletions(-)
38
15
39
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
40
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/kvm.c
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
42
+++ b/target/riscv/kvm.c
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
43
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v,
20
@@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
44
kvm_cpu_cfg_set(cpu, multi_ext_cfg, value);
21
return require_rvv(s) &&
22
require_rvf(s) &&
23
require_scale_rvf(s) &&
24
- (s->sew != MO_8) &&
25
vext_check_isa_ill(s) &&
26
vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm);
45
}
27
}
46
28
@@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
47
+static KVMCPUConfig kvm_cbom_blocksize = {
29
return require_rvv(s) &&
48
+ .name = "cbom_blocksize",
30
require_rvf(s) &&
49
+ .offset = CPUCFG(cbom_blocksize),
31
require_scale_rvf(s) &&
50
+ .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicbom_block_size)
32
- (s->sew != MO_8) &&
51
+};
33
vext_check_isa_ill(s) &&
52
+
34
vext_check_ds(s, a->rd, a->rs2, a->vm);
53
+static KVMCPUConfig kvm_cboz_blocksize = {
35
}
54
+ .name = "cboz_blocksize",
36
@@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
55
+ .offset = CPUCFG(cboz_blocksize),
37
return require_rvv(s) &&
56
+ .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size)
38
require_rvf(s) &&
57
+};
39
require_scale_rvf(s) &&
58
+
40
- (s->sew != MO_8) &&
59
+static void kvm_cpu_set_cbomz_blksize(Object *obj, Visitor *v,
41
vext_check_isa_ill(s) &&
60
+ const char *name,
42
vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm);
61
+ void *opaque, Error **errp)
43
}
62
+{
44
@@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
63
+ KVMCPUConfig *cbomz_cfg = opaque;
45
return require_rvv(s) &&
64
+ RISCVCPU *cpu = RISCV_CPU(obj);
46
require_rvf(s) &&
65
+ uint16_t value, *host_val;
47
require_scale_rvf(s) &&
66
+
48
- (s->sew != MO_8) &&
67
+ if (!visit_type_uint16(v, name, &value, errp)) {
49
vext_check_isa_ill(s) &&
68
+ return;
50
vext_check_dd(s, a->rd, a->rs2, a->vm);
69
+ }
51
}
70
+
52
@@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
71
+ host_val = kvmconfig_get_cfg_addr(cpu, cbomz_cfg);
72
+
73
+ if (value != *host_val) {
74
+ error_report("Unable to set %s to a different value than "
75
+ "the host (%u)",
76
+ cbomz_cfg->name, *host_val);
77
+ exit(EXIT_FAILURE);
78
+ }
79
+
80
+ cbomz_cfg->user_set = true;
81
+}
82
+
83
static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
84
{
53
{
85
CPURISCVState *env = &cpu->env;
54
return opfv_widen_check(s, a) &&
86
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
55
require_rvfmin(s) &&
87
kvm_cpu_set_multi_ext_cfg,
56
- require_scale_rvfmin(s) &&
88
NULL, multi_cfg);
57
- (s->sew != MO_8);
89
}
58
+ require_scale_rvfmin(s);
90
+
91
+ object_property_add(cpu_obj, "cbom_blocksize", "uint16",
92
+ NULL, kvm_cpu_set_cbomz_blksize,
93
+ NULL, &kvm_cbom_blocksize);
94
+
95
+ object_property_add(cpu_obj, "cboz_blocksize", "uint16",
96
+ NULL, kvm_cpu_set_cbomz_blksize,
97
+ NULL, &kvm_cboz_blocksize);
98
}
59
}
99
60
100
static int kvm_riscv_get_regs_core(CPUState *cs)
61
#define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
101
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_misa_ext_mask(RISCVCPU *cpu,
62
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
102
env->misa_ext = env->misa_ext_mask;
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);
103
}
69
}
104
70
105
+static void kvm_riscv_read_cbomz_blksize(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
71
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
106
+ KVMCPUConfig *cbomz_cfg)
107
+{
108
+ CPURISCVState *env = &cpu->env;
109
+ struct kvm_one_reg reg;
110
+ int ret;
111
+
112
+ reg.id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
113
+ cbomz_cfg->kvm_reg_id);
114
+ reg.addr = (uint64_t)kvmconfig_get_cfg_addr(cpu, cbomz_cfg);
115
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
116
+ if (ret != 0) {
117
+ error_report("Unable to read KVM reg %s, error %d",
118
+ cbomz_cfg->name, ret);
119
+ exit(EXIT_FAILURE);
120
+ }
121
+}
122
+
123
static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
124
{
72
{
125
CPURISCVState *env = &cpu->env;
73
return opfv_narrow_check(s, a) &&
126
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
74
require_rvf(s) &&
127
75
- require_scale_rvf(s) &&
128
kvm_cpu_cfg_set(cpu, multi_ext_cfg, val);
76
- (s->sew != MO_8);
129
}
77
+ require_scale_rvf(s);
130
+
131
+ if (cpu->cfg.ext_icbom) {
132
+ kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cbom_blocksize);
133
+ }
134
+
135
+ if (cpu->cfg.ext_icboz) {
136
+ kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cboz_blocksize);
137
+ }
138
}
78
}
139
79
140
void kvm_riscv_init_user_properties(Object *cpu_obj)
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)
141
--
91
--
142
2.40.1
92
2.45.1
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Pointer mask is also affected by MPRV which means cur_pmbase/pmmask
3
raise_mmu_exception(), as is today, is prioritizing guest page faults by
4
should also take MPRV into consideration. As pointer mask for instruction
4
checking first if virt_enabled && !first_stage, and then considering the
5
is not supported currently, so we can directly update cur_pmbase/pmmask
5
regular inst/load/store faults.
6
based on address related mode and xlen affected by MPRV now.
7
6
8
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
7
There's no mention in the spec about guest page fault being a higher
9
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
8
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
11
Message-Id: <20230614032547.35895-3-liweiwei@iscas.ac.cn>
10
"Attempting to fetch an instruction from a PMP region that does not have
11
execute permissions raises an instruction access-fault exception.
12
Attempting to execute a load or load-reserved instruction which accesses
13
a physical address within a PMP region without read permissions raises a
14
load access-fault exception. Attempting to execute a store,
15
store-conditional, or AMO instruction which accesses a physical address
16
within a PMP region without write permissions raises a store
17
access-fault exception."
18
19
So, in fact, we're doing it wrong - PMP faults should always be thrown,
20
regardless of also being a first or second stage fault.
21
22
The way riscv_cpu_tlb_fill() and get_physical_address() work is
23
adequate: a TRANSLATE_PMP_FAIL error is immediately reported and
24
reflected in the 'pmp_violation' flag. What we need is to change
25
raise_mmu_exception() to prioritize it.
26
27
Reported-by: Joseph Chan <jchan@ventanamicro.com>
28
Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage")
29
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
30
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
31
Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
34
---
14
target/riscv/cpu_helper.c | 7 +++++--
35
target/riscv/cpu_helper.c | 22 ++++++++++++----------
15
target/riscv/csr.c | 27 ++++++++++++++++++++-------
36
1 file changed, 12 insertions(+), 10 deletions(-)
16
2 files changed, 25 insertions(+), 9 deletions(-)
17
37
18
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
38
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
19
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/cpu_helper.c
40
--- a/target/riscv/cpu_helper.c
21
+++ b/target/riscv/cpu_helper.c
41
+++ b/target/riscv/cpu_helper.c
22
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
42
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
23
void riscv_cpu_update_mask(CPURISCVState *env)
43
24
{
44
switch (access_type) {
25
target_ulong mask = 0, base = 0;
45
case MMU_INST_FETCH:
26
+ RISCVMXL xl = env->xl;
46
- if (env->virt_enabled && !first_stage) {
27
/*
47
+ if (pmp_violation) {
28
* TODO: Current RVJ spec does not specify
48
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
29
* how the extension interacts with XLEN.
49
+ } else if (env->virt_enabled && !first_stage) {
30
*/
50
cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
31
#ifndef CONFIG_USER_ONLY
51
} else {
32
+ int mode = cpu_address_mode(env);
52
- cs->exception_index = pmp_violation ?
33
+ xl = cpu_get_xl(env, mode);
53
- RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
34
if (riscv_has_ext(env, RVJ)) {
54
+ cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
35
- switch (env->priv) {
36
+ switch (mode) {
37
case PRV_M:
38
if (env->mmte & M_PM_ENABLE) {
39
mask = env->mpmmask;
40
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_update_mask(CPURISCVState *env)
41
}
55
}
42
}
56
break;
43
#endif
57
case MMU_DATA_LOAD:
44
- if (env->xl == MXL_RV32) {
58
- if (two_stage && !first_stage) {
45
+ if (xl == MXL_RV32) {
59
+ if (pmp_violation) {
46
env->cur_pmmask = mask & UINT32_MAX;
60
+ cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
47
env->cur_pmbase = base & UINT32_MAX;
61
+ } else if (two_stage && !first_stage) {
48
} else {
62
cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
49
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
63
} else {
50
index XXXXXXX..XXXXXXX 100644
64
- cs->exception_index = pmp_violation ?
51
--- a/target/riscv/csr.c
65
- RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
52
+++ b/target/riscv/csr.c
66
+ cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT;
53
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
67
}
54
*/
68
break;
55
if (env->debugger) {
69
case MMU_DATA_STORE:
56
env->xl = cpu_recompute_xl(env);
70
- if (two_stage && !first_stage) {
57
- riscv_cpu_update_mask(env);
71
+ if (pmp_violation) {
58
}
72
+ cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
59
+
73
+ } else if (two_stage && !first_stage) {
60
+ riscv_cpu_update_mask(env);
74
cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
61
return RISCV_EXCP_NONE;
75
} else {
62
}
76
- cs->exception_index = pmp_violation ?
63
77
- RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
64
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mpmmask(CPURISCVState *env, int csrno,
78
- RISCV_EXCP_STORE_PAGE_FAULT;
65
uint64_t mstatus;
79
+ cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
66
80
}
67
env->mpmmask = val;
81
break;
68
- if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) {
82
default:
69
+ if ((cpu_address_mode(env) == PRV_M) && (env->mmte & M_PM_ENABLE)) {
70
env->cur_pmmask = val;
71
}
72
env->mmte |= EXT_STATUS_DIRTY;
73
@@ -XXX,XX +XXX,XX @@ static RISCVException write_spmmask(CPURISCVState *env, int csrno,
74
return RISCV_EXCP_NONE;
75
}
76
env->spmmask = val;
77
- if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) {
78
+ if ((cpu_address_mode(env) == PRV_S) && (env->mmte & S_PM_ENABLE)) {
79
env->cur_pmmask = val;
80
+ if (cpu_get_xl(env, PRV_S) == MXL_RV32) {
81
+ env->cur_pmmask &= UINT32_MAX;
82
+ }
83
}
84
env->mmte |= EXT_STATUS_DIRTY;
85
86
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmmask(CPURISCVState *env, int csrno,
87
return RISCV_EXCP_NONE;
88
}
89
env->upmmask = val;
90
- if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) {
91
+ if ((cpu_address_mode(env) == PRV_U) && (env->mmte & U_PM_ENABLE)) {
92
env->cur_pmmask = val;
93
+ if (cpu_get_xl(env, PRV_U) == MXL_RV32) {
94
+ env->cur_pmmask &= UINT32_MAX;
95
+ }
96
}
97
env->mmte |= EXT_STATUS_DIRTY;
98
99
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mpmbase(CPURISCVState *env, int csrno,
100
uint64_t mstatus;
101
102
env->mpmbase = val;
103
- if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) {
104
+ if ((cpu_address_mode(env) == PRV_M) && (env->mmte & M_PM_ENABLE)) {
105
env->cur_pmbase = val;
106
}
107
env->mmte |= EXT_STATUS_DIRTY;
108
@@ -XXX,XX +XXX,XX @@ static RISCVException write_spmbase(CPURISCVState *env, int csrno,
109
return RISCV_EXCP_NONE;
110
}
111
env->spmbase = val;
112
- if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) {
113
+ if ((cpu_address_mode(env) == PRV_S) && (env->mmte & S_PM_ENABLE)) {
114
env->cur_pmbase = val;
115
+ if (cpu_get_xl(env, PRV_S) == MXL_RV32) {
116
+ env->cur_pmbase &= UINT32_MAX;
117
+ }
118
}
119
env->mmte |= EXT_STATUS_DIRTY;
120
121
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
122
return RISCV_EXCP_NONE;
123
}
124
env->upmbase = val;
125
- if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) {
126
+ if ((cpu_address_mode(env) == PRV_U) && (env->mmte & U_PM_ENABLE)) {
127
env->cur_pmbase = val;
128
+ if (cpu_get_xl(env, PRV_U) == MXL_RV32) {
129
+ env->cur_pmbase &= UINT32_MAX;
130
+ }
131
}
132
env->mmte |= EXT_STATUS_DIRTY;
133
134
--
83
--
135
2.40.1
84
2.45.1
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Alexei Filippov <alexei.filippov@syntacore.com>
2
2
3
Upon MRET or explicit memory access with MPRV=1, MPV should be ignored
3
Previous patch fixed the PMP priority in raise_mmu_exception() but we're still
4
when MPP=PRV_M.
4
setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage
5
translation part, mtval2 will be set in case of successes 2 stage translation but
6
failed pmp check.
5
7
6
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
8
In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of
7
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
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>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <20230603134236.15719-2-liweiwei@iscas.ac.cn>
18
Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com>
19
Cc: qemu-stable <qemu-stable@nongnu.org>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
21
---
13
target/riscv/cpu_helper.c | 3 ++-
22
target/riscv/cpu_helper.c | 12 ++++++------
14
target/riscv/op_helper.c | 3 ++-
23
1 file changed, 6 insertions(+), 6 deletions(-)
15
2 files changed, 4 insertions(+), 2 deletions(-)
16
24
17
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
25
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
18
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/cpu_helper.c
27
--- a/target/riscv/cpu_helper.c
20
+++ b/target/riscv/cpu_helper.c
28
+++ b/target/riscv/cpu_helper.c
21
@@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
29
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
22
30
__func__, pa, ret, prot_pmp, tlb_size);
23
if (mode == PRV_M && get_field(status, MSTATUS_MPRV)) {
31
24
mode = get_field(env->mstatus, MSTATUS_MPP);
32
prot &= prot_pmp;
25
- virt = get_field(env->mstatus, MSTATUS_MPV);
33
- }
26
+ virt = get_field(env->mstatus, MSTATUS_MPV) &&
34
-
27
+ (mode != PRV_M);
35
- if (ret != TRANSLATE_SUCCESS) {
28
if (virt) {
36
+ } else {
29
status = env->vsstatus;
37
/*
38
* Guest physical address translation failed, this is a HS
39
* level exception
40
*/
41
first_stage_error = false;
42
- env->guest_phys_fault_addr = (im_address |
43
- (address &
44
- (TARGET_PAGE_SIZE - 1))) >> 2;
45
+ if (ret != TRANSLATE_PMP_FAIL) {
46
+ env->guest_phys_fault_addr = (im_address |
47
+ (address &
48
+ (TARGET_PAGE_SIZE - 1))) >> 2;
49
+ }
30
}
50
}
31
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
51
}
32
index XXXXXXX..XXXXXXX 100644
52
} else {
33
--- a/target/riscv/op_helper.c
34
+++ b/target/riscv/op_helper.c
35
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env)
36
riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
37
}
38
39
- target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
40
+ target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV) &&
41
+ (prev_priv != PRV_M);
42
mstatus = set_field(mstatus, MSTATUS_MIE,
43
get_field(mstatus, MSTATUS_MPIE));
44
mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
45
--
53
--
46
2.40.1
54
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
2
1
3
MPV and GVA bits are added by hypervisor extension to mstatus
4
and mstatush (if MXLEN=32).
5
6
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
7
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <20230603134236.15719-3-liweiwei@iscas.ac.cn>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/csr.c | 10 ++++------
14
1 file changed, 4 insertions(+), 6 deletions(-)
15
16
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/csr.c
19
+++ b/target/riscv/csr.c
20
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
21
}
22
23
if (xl != MXL_RV32 || env->debugger) {
24
- /*
25
- * RV32: MPV and GVA are not in mstatus. The current plan is to
26
- * add them to mstatush. For now, we just don't support it.
27
- */
28
- mask |= MSTATUS_MPV | MSTATUS_GVA;
29
+ if (riscv_has_ext(env, RVH)) {
30
+ mask |= MSTATUS_MPV | MSTATUS_GVA;
31
+ }
32
if ((val & MSTATUS64_UXL) != 0) {
33
mask |= MSTATUS64_UXL;
34
}
35
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno,
36
target_ulong val)
37
{
38
uint64_t valh = (uint64_t)val << 32;
39
- uint64_t mask = MSTATUS_MPV | MSTATUS_GVA;
40
+ uint64_t mask = riscv_has_ext(env, RVH) ? MSTATUS_MPV | MSTATUS_GVA : 0;
41
42
env->mstatus = (env->mstatus & ~mask) | (valh & mask);
43
44
--
45
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
2
1
3
SXL is initialized as env->misa_mxl which is also the mxl value.
4
So we can just remain it unchanged to keep it read-only.
5
6
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
7
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <20230603134236.15719-4-liweiwei@iscas.ac.cn>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/csr.c | 4 ----
14
1 file changed, 4 deletions(-)
15
16
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/csr.c
19
+++ b/target/riscv/csr.c
20
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
21
22
mstatus = (mstatus & ~mask) | (val & mask);
23
24
- if (xl > MXL_RV32) {
25
- /* SXL field is for now read only */
26
- mstatus = set_field(mstatus, MSTATUS64_SXL, xl);
27
- }
28
env->mstatus = mstatus;
29
30
/*
31
--
32
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Bin Meng <bmeng@tinylab.org>
2
1
3
Upgrade OpenSBI from v1.2 to v1.3 and the pre-built bios images.
4
5
The v1.3 release includes the following commits:
6
7
440fa81 treewide: Replace TRUE/FALSE with true/false
8
6509127 Makefile: Remove -N ldflag to prevent linker RWX warning
9
65638f8 lib: utils/sys: Allow custom HTIF base address for RV32
10
f14595a lib: sbi: Allow platform to influence cold boot HART selection
11
6957ae0 platform: generic: Allow platform_override to select cold boot HART
12
cb7e7c3 platform: generic: Allow platform_override to perform firmware init
13
8020df8 generic/starfive: Add Starfive JH7110 platform implementation
14
6997552 lib: sbi_hsm: Rename 'priv' argument to 'arg1'
15
9e397e3 docs: domain_support: Use capital letter for privilege modes
16
9e0ba09 include: sbi: Fine grain the permissions for M and SU modes
17
aace1e1 lib: sbi: Use finer permission semantics for address validation
18
22dbdb3 lib: sbi: Add permissions for the firmware start till end
19
1ac14f1 lib: sbi: Use finer permission sematics to decide on PMP bits
20
44f736c lib: sbi: Modify the boot time region flag prints
21
20646e0 lib: utils: Use SU-{R/W/X} flags for region permissions during parsing
22
3e2f573 lib: utils: Disallow non-root domains from adding M-mode regions
23
59a08cd lib: utils: Add M-mode {R/W} flags to the MMIO regions
24
001106d docs: Update domain's region permissions and requirements
25
da5594b platform: generic: allwinner: Fix PLIC array bounds
26
ce2a834 docs: generic.md: fix typo of andes-ae350
27
8ecbe6d lib: sbi_hsm: handle failure when hart_stop returns SBI_ENOTSUPP
28
b1818ee include: types: add always inline compiler attribute
29
9c4eb35 lib: utils: atcsmu: Add Andes System Management Unit support
30
787296a platform: andes/ae350: Implement hart hotplug using HSM extension
31
7aaeeab lib: reset/fdt_reset_atcwdt200: Use defined macros and function in atcsmu.h
32
a990309 lib: utils: Fix reserved memory node for firmware memory
33
fefa548 firmware: Split RO/RX and RW sections
34
2f40a99 firmware: Move dynsym and reladyn sections to RX section
35
c10e3fe firmware: Add RW section offset in scratch
36
b666760 lib: sbi: Print the RW section offset
37
230278d lib: sbi: Add separate entries for firmware RX and RW regions
38
dea0922 platform: renesas/rzfive: Configure Local memory regions as part of root domain
39
33bf917 lib: utils: Add fdt_add_cpu_idle_states() helper function
40
c45992c platform: generic: allwinner: Advertise nonretentive suspend
41
c8ea836 firmware: Fix fw_rw_offset computation in fw_base.S
42
8050081 firmware: Not to clear all the MIP
43
84d15f4 lib: sbi_hsm: Use csr_set to restore the MIP
44
199189b lib: utils: Mark only the largest region as reserved in FDT
45
66b0e23 lib: sbi: Ensure domidx_to_domain_table is null-terminated
46
642f3de Makefile: Add missing .dep files for fw_*.elf.ld
47
09b34d8 include: Add support for byteorder/endianness conversion
48
680bea0 lib: utils/fdt: Use byteorder conversion functions in libfdt_env.h
49
b224ddb include: types: Add typedefs for endianness
50
aa5dafc include: sbi: Fix BSWAPx() macros for big-endian host
51
e3bf1af include: Add defines for SBI debug console extension
52
0ee3a86 lib: sbi: Add sbi_nputs() function
53
4e0572f lib: sbi: Add sbi_ngets() function
54
eab48c3 lib: sbi: Add sbi_domain_check_addr_range() function
55
5a41a38 lib: sbi: Implement SBI debug console extension
56
c43903c lib: sbi: Add console_puts() callback in the console device
57
29285ae lib: utils/serial: Implement console_puts() for semihosting
58
65c2190 lib: sbi: Speed-up sbi_printf() and friends using nputs()
59
321293c lib: utils/fdt: Fix fdt_pmu.c header dependency
60
aafcc90 platform: generic/allwinner: Fix sun20i-d1.c header dependency
61
745aaec platform: generic/andes: Fix ae350.c header dependency
62
99d09b6 include: fdt/fdt_helper: Change fdt_get_address() to return root.next_arg1
63
6861ee9 lib: utils: fdt_fixup: Fix compile error
64
4f2be40 docs: fix typo in fw.md
65
30ea806 lib: sbi_hart: Enable hcontext and scontext
66
81adc62 lib: sbi: Align SBI vendor extension id with mvendorid CSR
67
31b82e0 include: sbi: Remove extid parameter from vendor_ext_provider() callback
68
c100951 platform: generic: renesas: rzfive: Add support to configure the PMA
69
2491242 platform: generic: renesas: rzfive: Configure the PMA region
70
67b2a40 lib: sbi: sbi_ecall: Check the range of SBI error
71
5a75f53 lib: sbi/sbi_domain: cosmetic style fixes
72
bc06ff6 lib: utils/fdt/fdt_domain: Simplify region access permission check
73
17b3776 docs: domain_support: Update the DT example
74
1364d5a lib: sbi_hsm: Factor out invalid state detection
75
40f16a8 lib: sbi_hsm: Don't try to restore state on failed change
76
c88e039 lib: sbi_hsm: Ensure errors are consistent with spec
77
b1ae6ef lib: sbi_hsm: Move misplaced comment
78
07673fc lib: sbi_hsm: Remove unnecessary include
79
8a40306 lib: sbi_hsm: Export some functions
80
73623a0 lib: sbi: Add system suspend skeleton
81
c9917b6 lib: sbi: Add system_suspend_allowed domain property
82
7c964e2 lib: sbi: Implement system suspend
83
37558dc docs: Correct opensbi-domain property name
84
5ccebf0 platform: generic: Add system suspend test
85
908be1b gpio/starfive: add gpio driver and support gpio reset
86
4b28afc make: Add a command line option for debugging OpenSBI
87
e9d08bd lib: utils/i2c: Add minimal StarFive jh7110 I2C driver
88
568ea49 platform: starfive: add PMIC power ops in JH7110 visionfive2 board
89
506144f lib: serial: Cadence: Enable compatibility for cdns,uart-r1p8
90
1fe8dc9 lib: sbi_pmu: add callback for counter width
91
51951d9 lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi
92
60c358e lib: sbi_pmu: Reserve space for implementation specific firmware events
93
548e4b4 lib: sbi_pmu: Rename fw_counter_value
94
b51ddff lib: sbi_pmu: Update sbi_pmu dev ops
95
641d2e9 lib: sbi_pmu: Use dedicated event code for platform firmware events
96
57d3aa3 lib: sbi_pmu: Introduce fw_counter_write_value API
97
c631a7d lib: sbi_pmu: Add hartid parameter PMU device ops
98
d56049e lib: sbi: Refactor the calls to sbi_hart_switch_mode()
99
e8e9ed3 lib: sbi: Set the state of a hart to START_PENDING after the hart is ready
100
c6a092c lib: sbi: Clear IPIs before init_warm_startup in non-boot harts
101
ed88a63 lib: sbi_scratch: Optimize the alignment code for alloc size
102
73ab11d lib: sbi: Fix how to check whether the domain contains fw_region
103
f64dfcd lib: sbi: Introduce sbi_entry_count() function
104
30b9e7e lib: sbi_hsm: Fix sbi_hsm_hart_start() for platform with hart hotplug
105
8e90259 lib: sbi_hart: clear mip csr during hart init
106
45ba2b2 include: Add defines for SBI CPPC extension
107
33caae8 lib: sbi: Implement SBI CPPC extension
108
91767d0 lib: sbi: Print the CPPC device name
109
edc9914 lib: sbi_pmu: Align the event type offset as per SBI specification
110
ee016a7 docs: Correct FW_JUMP_FDT_ADDR calculation example
111
2868f26 lib: utils: fdt_fixup: avoid buffer overrun
112
66fa925 lib: sbi: Optimize sbi_tlb
113
24dde46 lib: sbi: Optimize sbi_ipi
114
80078ab sbi: tlb: Simplify to tlb_process_count/tlb_process function
115
bf40e07 lib: sbi: Optimize sbi_tlb queue waiting
116
eeab500 platform: generic: andes/renesas: Add SBI EXT to check for enabling IOCP errata
117
f692289 firmware: Optimize loading relocation type
118
e41dbb5 firmware: Change to use positive offset to access relocation entries
119
bdb3c42 lib: sbi: Do not clear active_events for cycle/instret when stopping
120
674e019 lib: sbi: Fix counter index calculation for SBI_PMU_CFG_FLAG_SKIP_MATCH
121
f5dfd99 lib: sbi: Don't check SBI error range for legacy console getchar
122
7919530 lib: sbi: Add debug print when sbi_pmu_init fails
123
4e33530 lib: sbi: Remove unnecessary semicolon
124
6bc02de lib: sbi: Simplify sbi_ipi_process remove goto
125
dc1c7db lib: sbi: Simplify BITS_PER_LONG definition
126
f58c140 lib: sbi: Introduce register_extensions extension callback
127
e307ba7 lib: sbi: Narrow vendor extension range
128
042f0c3 lib: sbi: pmu: Remove unnecessary probe function
129
8b952d4 lib: sbi: Only register available extensions
130
767b5fc lib: sbi: Optimize probe of srst/susp
131
c3e31cb lib: sbi: Remove 0/1 probe implementations
132
33f1722 lib: sbi: Document sbi_ecall_extension members
133
d4c46e0 Makefile: Dereference symlinks on install
134
8b99a7f lib: sbi: Fix return of sbi_console_init
135
264d0be lib: utils: Improve fdt_serial_init
136
9a0bdd0 lib: utils: Improve fdt_ipi
137
122f226 lib: utils: Improve fdt_timer
138
df75e09 lib: utils/ipi: buffer overrun aclint_mswi_cold_init
139
bdde2ec lib: sbi: Align system suspend errors with spec
140
aad7a37 include: sbi_scratch: Add helper macros to access data type
141
5cf9a54 platform: Allow platforms to specify heap size
142
40d36a6 lib: sbi: Introduce simple heap allocator
143
2a04f70 lib: sbi: Print scratch size and usage at boot time
144
bbff53f lib: sbi_pmu: Use heap for per-HART PMU state
145
ef4542d lib: sbi: Use heap for root domain creation
146
66daafe lib: sbi: Use scratch space to save per-HART domain pointer
147
fa5ad2e lib: utils/gpio: Use heap in SiFive and StartFive GPIO drivers
148
903e88c lib: utils/i2c: Use heap in DesignWare and SiFive I2C drivers
149
5a8cfcd lib: utils/ipi: Use heap in ACLINT MSWI driver
150
3013716 lib: utils/irqchip: Use heap in PLIC, APLIC and IMSIC drivers
151
7e5636a lib: utils/timer: Use heap in ACLINT MTIMER driver
152
3c1c972 lib: utils/fdt: Use heap in FDT domain parsing
153
acbd8fc lib: utils/ipi: Use scratch space to save per-HART MSWI pointer
154
f0516be lib: utils/timer: Use scratch space to save per-HART MTIMER pointer
155
b3594ac lib: utils/irqchip: Use scratch space to save per-HART PLIC pointer
156
1df52fa lib: utils/irqchip: Don't check hartid in imsic_update_hartid_table()
157
355796c lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointer
158
524feec docs: Add OpenSBI logo and use it in the top-level README.md
159
932be2c README.md: Improve project copyright information
160
8153b26 platform/lib: Set no-map attribute on all PMP regions
161
d64942f firmware: Fix find hart index
162
27c957a lib: reset: Move fdt_reset_init into generic_early_init
163
8bd666a lib: sbi: check A2 register in ecall_dbcn_handler.
164
2552799 include: Bump-up version to 1.3
165
166
Signed-off-by: Bin Meng <bmeng@tinylab.org>
167
Message-Id: <20230630160717.843044-1-bmeng@tinylab.org>
168
Tested-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
169
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
170
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
171
---
172
.../opensbi-riscv32-generic-fw_dynamic.bin | Bin 123072 -> 135344 bytes
173
.../opensbi-riscv64-generic-fw_dynamic.bin | Bin 121800 -> 138304 bytes
174
roms/opensbi | 2 +-
175
3 files changed, 1 insertion(+), 1 deletion(-)
176
177
diff --git a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin
178
index XXXXXXX..XXXXXXX 100644
179
Binary files a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin differ
180
diff --git a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin
181
index XXXXXXX..XXXXXXX 100644
182
Binary files a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin differ
183
diff --git a/roms/opensbi b/roms/opensbi
184
index XXXXXXX..XXXXXXX 160000
185
--- a/roms/opensbi
186
+++ b/roms/opensbi
187
@@ -1 +1 @@
188
-Subproject commit 6b5188ca14e59ce7bf71afe4e7d3d557c3d31bf8
189
+Subproject commit 2552799a1df30a3dcd2321a8b75d61d06f5fb9fc
190
--
191
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Bin Meng <bmeng@tinylab.org>
2
1
3
The 32-bit Spike boot issue has been fixed in the OpenSBI v1.3.
4
Let's enable the 32-bit Spike OpenSBI boot testing.
5
6
Signed-off-by: Bin Meng <bmeng@tinylab.org>
7
Message-Id: <20230630160717.843044-2-bmeng@tinylab.org>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
tests/avocado/riscv_opensbi.py | 2 --
13
1 file changed, 2 deletions(-)
14
15
diff --git a/tests/avocado/riscv_opensbi.py b/tests/avocado/riscv_opensbi.py
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/avocado/riscv_opensbi.py
18
+++ b/tests/avocado/riscv_opensbi.py
19
@@ -XXX,XX +XXX,XX @@
20
# later. See the COPYING file in the top-level directory.
21
22
from avocado_qemu import QemuSystemTest
23
-from avocado import skip
24
from avocado_qemu import wait_for_console_pattern
25
26
class RiscvOpenSBI(QemuSystemTest):
27
@@ -XXX,XX +XXX,XX @@ def boot_opensbi(self):
28
wait_for_console_pattern(self, 'Platform Name')
29
wait_for_console_pattern(self, 'Boot HART MEDELEG')
30
31
- @skip("requires OpenSBI fix to work")
32
def test_riscv32_spike(self):
33
"""
34
:avocado: tags=arch:riscv32
35
--
36
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Tommy Wu <tommy.wu@sifive.com>
2
1
3
Create the AON device when we realize the sifive_e machine.
4
This patch only implemented the functionality of the watchdog timer,
5
not all the functionality of the AON device.
6
7
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
Message-Id: <20230627141216.3962299-3-tommy.wu@sifive.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
include/hw/riscv/sifive_e.h | 9 ++++++---
15
hw/riscv/sifive_e.c | 17 +++++++++++++++--
16
hw/riscv/Kconfig | 1 +
17
3 files changed, 22 insertions(+), 5 deletions(-)
18
19
diff --git a/include/hw/riscv/sifive_e.h b/include/hw/riscv/sifive_e.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/riscv/sifive_e.h
22
+++ b/include/hw/riscv/sifive_e.h
23
@@ -XXX,XX +XXX,XX @@
24
#include "hw/riscv/riscv_hart.h"
25
#include "hw/riscv/sifive_cpu.h"
26
#include "hw/gpio/sifive_gpio.h"
27
+#include "hw/misc/sifive_e_aon.h"
28
#include "hw/boards.h"
29
30
#define TYPE_RISCV_E_SOC "riscv.sifive.e.soc"
31
@@ -XXX,XX +XXX,XX @@ typedef struct SiFiveESoCState {
32
/*< public >*/
33
RISCVHartArrayState cpus;
34
DeviceState *plic;
35
+ SiFiveEAONState aon;
36
SIFIVEGPIOState gpio;
37
MemoryRegion xip_mem;
38
MemoryRegion mask_rom;
39
@@ -XXX,XX +XXX,XX @@ enum {
40
};
41
42
enum {
43
- SIFIVE_E_UART0_IRQ = 3,
44
- SIFIVE_E_UART1_IRQ = 4,
45
- SIFIVE_E_GPIO0_IRQ0 = 8
46
+ SIFIVE_E_AON_WDT_IRQ = 1,
47
+ SIFIVE_E_UART0_IRQ = 3,
48
+ SIFIVE_E_UART1_IRQ = 4,
49
+ SIFIVE_E_GPIO0_IRQ0 = 8
50
};
51
52
#define SIFIVE_E_PLIC_HART_CONFIG "M"
53
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/hw/riscv/sifive_e.c
56
+++ b/hw/riscv/sifive_e.c
57
@@ -XXX,XX +XXX,XX @@
58
#include "hw/intc/riscv_aclint.h"
59
#include "hw/intc/sifive_plic.h"
60
#include "hw/misc/sifive_e_prci.h"
61
+#include "hw/misc/sifive_e_aon.h"
62
#include "chardev/char.h"
63
#include "sysemu/sysemu.h"
64
65
@@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_init(Object *obj)
66
object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort);
67
object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio,
68
TYPE_SIFIVE_GPIO);
69
+ object_initialize_child(obj, "riscv.sifive.e.aon", &s->aon,
70
+ TYPE_SIFIVE_E_AON);
71
}
72
73
static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
74
@@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
75
RISCV_ACLINT_DEFAULT_MTIMER_SIZE, 0, ms->smp.cpus,
76
RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
77
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, false);
78
- create_unimplemented_device("riscv.sifive.e.aon",
79
- memmap[SIFIVE_E_DEV_AON].base, memmap[SIFIVE_E_DEV_AON].size);
80
sifive_e_prci_create(memmap[SIFIVE_E_DEV_PRCI].base);
81
82
+ /* AON */
83
+
84
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->aon), errp)) {
85
+ return;
86
+ }
87
+
88
+ /* Map AON registers */
89
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->aon), 0, memmap[SIFIVE_E_DEV_AON].base);
90
+
91
/* GPIO */
92
93
if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio), errp)) {
94
@@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
95
qdev_get_gpio_in(DEVICE(s->plic),
96
SIFIVE_E_GPIO0_IRQ0 + i));
97
}
98
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->aon), 0,
99
+ qdev_get_gpio_in(DEVICE(s->plic),
100
+ SIFIVE_E_AON_WDT_IRQ));
101
102
sifive_uart_create(sys_mem, memmap[SIFIVE_E_DEV_UART0].base,
103
serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART0_IRQ));
104
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
105
index XXXXXXX..XXXXXXX 100644
106
--- a/hw/riscv/Kconfig
107
+++ b/hw/riscv/Kconfig
108
@@ -XXX,XX +XXX,XX @@ config SIFIVE_E
109
select SIFIVE_PLIC
110
select SIFIVE_UART
111
select SIFIVE_E_PRCI
112
+ select SIFIVE_E_AON
113
select UNIMP
114
115
config SIFIVE_U
116
--
117
2.40.1
118
119
diff view generated by jsdifflib
Deleted patch
1
From: Tommy Wu <tommy.wu@sifive.com>
2
1
3
Add some simple tests of the watchdog timer in the always-on domain device
4
of HiFive 1 rev b.
5
6
Signed-off-by: Tommy Wu <tommy.wu@sifive.com>
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
Acked-by: Thomas Huth <thuth@redhat.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <20230627141216.3962299-4-tommy.wu@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
tests/qtest/sifive-e-aon-watchdog-test.c | 450 +++++++++++++++++++++++
14
tests/qtest/meson.build | 3 +
15
2 files changed, 453 insertions(+)
16
create mode 100644 tests/qtest/sifive-e-aon-watchdog-test.c
17
18
diff --git a/tests/qtest/sifive-e-aon-watchdog-test.c b/tests/qtest/sifive-e-aon-watchdog-test.c
19
new file mode 100644
20
index XXXXXXX..XXXXXXX
21
--- /dev/null
22
+++ b/tests/qtest/sifive-e-aon-watchdog-test.c
23
@@ -XXX,XX +XXX,XX @@
24
+/*
25
+ * QTest testcase for the watchdog timer of HiFive 1 rev b.
26
+ *
27
+ * Copyright (c) 2023 SiFive, Inc.
28
+ *
29
+ * This program is free software; you can redistribute it and/or modify it
30
+ * under the terms and conditions of the GNU General Public License,
31
+ * version 2 or later, as published by the Free Software Foundation.
32
+ *
33
+ * This program is distributed in the hope it will be useful, but WITHOUT
34
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
36
+ * more details.
37
+ *
38
+ * You should have received a copy of the GNU General Public License along with
39
+ * this program. If not, see <http://www.gnu.org/licenses/>.
40
+ */
41
+
42
+#include "qemu/osdep.h"
43
+#include "qemu/timer.h"
44
+#include "qemu/bitops.h"
45
+#include "libqtest.h"
46
+#include "hw/registerfields.h"
47
+#include "hw/misc/sifive_e_aon.h"
48
+
49
+FIELD(AON_WDT_WDOGCFG, SCALE, 0, 4)
50
+FIELD(AON_WDT_WDOGCFG, RSVD0, 4, 4)
51
+FIELD(AON_WDT_WDOGCFG, RSTEN, 8, 1)
52
+FIELD(AON_WDT_WDOGCFG, ZEROCMP, 9, 1)
53
+FIELD(AON_WDT_WDOGCFG, RSVD1, 10, 2)
54
+FIELD(AON_WDT_WDOGCFG, EN_ALWAYS, 12, 1)
55
+FIELD(AON_WDT_WDOGCFG, EN_CORE_AWAKE, 13, 1)
56
+FIELD(AON_WDT_WDOGCFG, RSVD2, 14, 14)
57
+FIELD(AON_WDT_WDOGCFG, IP0, 28, 1)
58
+FIELD(AON_WDT_WDOGCFG, RSVD3, 29, 3)
59
+
60
+#define WDOG_BASE (0x10000000)
61
+#define WDOGCFG (0x0)
62
+#define WDOGCOUNT (0x8)
63
+#define WDOGS (0x10)
64
+#define WDOGFEED (0x18)
65
+#define WDOGKEY (0x1c)
66
+#define WDOGCMP0 (0x20)
67
+
68
+#define SIFIVE_E_AON_WDOGKEY (0x51F15E)
69
+#define SIFIVE_E_AON_WDOGFEED (0xD09F00D)
70
+#define SIFIVE_E_LFCLK_DEFAULT_FREQ (32768)
71
+
72
+static void test_init(QTestState *qts)
73
+{
74
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
75
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0);
76
+
77
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
78
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, 0);
79
+
80
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
81
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, 0xBEEF);
82
+}
83
+
84
+static void test_wdogcount(void)
85
+{
86
+ uint64_t tmp;
87
+ QTestState *qts = qtest_init("-machine sifive_e");
88
+
89
+ test_init(qts);
90
+
91
+ tmp = qtest_readl(qts, WDOG_BASE + WDOGCOUNT);
92
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0xBEEF);
93
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) == tmp);
94
+
95
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
96
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0xBEEF);
97
+ g_assert(0xBEEF == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
98
+
99
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
100
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0xAAAAAAAA);
101
+ g_assert(0x2AAAAAAA == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
102
+
103
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
104
+ qtest_writel(qts, WDOG_BASE + WDOGFEED, 0xAAAAAAAA);
105
+ g_assert(0x2AAAAAAA == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
106
+
107
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
108
+ qtest_writel(qts, WDOG_BASE + WDOGFEED, SIFIVE_E_AON_WDOGFEED);
109
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
110
+
111
+ qtest_quit(qts);
112
+}
113
+
114
+static void test_wdogcfg(void)
115
+{
116
+ uint32_t tmp_cfg;
117
+ QTestState *qts = qtest_init("-machine sifive_e");
118
+
119
+ test_init(qts);
120
+
121
+ tmp_cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
122
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, 0xFFFFFFFF);
123
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCFG) == tmp_cfg);
124
+
125
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
126
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, 0xFFFFFFFF);
127
+ g_assert(0xFFFFFFFF == qtest_readl(qts, WDOG_BASE + WDOGCFG));
128
+
129
+ tmp_cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
130
+ g_assert(15 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, SCALE));
131
+ g_assert(1 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, RSTEN));
132
+ g_assert(1 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, ZEROCMP));
133
+ g_assert(1 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
134
+ g_assert(1 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
135
+ g_assert(1 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, IP0));
136
+
137
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
138
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, 0);
139
+ tmp_cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
140
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, SCALE));
141
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, RSTEN));
142
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, ZEROCMP));
143
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
144
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
145
+ g_assert(0 == FIELD_EX32(tmp_cfg, AON_WDT_WDOGCFG, IP0));
146
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGCFG));
147
+
148
+ qtest_quit(qts);
149
+}
150
+
151
+static void test_wdogcmp0(void)
152
+{
153
+ uint32_t tmp;
154
+ QTestState *qts = qtest_init("-machine sifive_e");
155
+
156
+ test_init(qts);
157
+
158
+ tmp = qtest_readl(qts, WDOG_BASE + WDOGCMP0);
159
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, 0xBEEF);
160
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCMP0) == tmp);
161
+
162
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
163
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, 0xBEEF);
164
+ g_assert(0xBEEF == qtest_readl(qts, WDOG_BASE + WDOGCMP0));
165
+
166
+ qtest_quit(qts);
167
+}
168
+
169
+static void test_wdogkey(void)
170
+{
171
+ QTestState *qts = qtest_init("-machine sifive_e");
172
+
173
+ test_init(qts);
174
+
175
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGKEY));
176
+
177
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, 0xFFFF);
178
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGKEY));
179
+
180
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
181
+ g_assert(1 == qtest_readl(qts, WDOG_BASE + WDOGKEY));
182
+
183
+ qtest_writel(qts, WDOG_BASE + WDOGFEED, 0xAAAAAAAA);
184
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGKEY));
185
+
186
+ qtest_quit(qts);
187
+}
188
+
189
+static void test_wdogfeed(void)
190
+{
191
+ QTestState *qts = qtest_init("-machine sifive_e");
192
+
193
+ test_init(qts);
194
+
195
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGFEED));
196
+
197
+ qtest_writel(qts, WDOG_BASE + WDOGFEED, 0xFFFF);
198
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGFEED));
199
+
200
+ qtest_quit(qts);
201
+}
202
+
203
+static void test_scaled_wdogs(void)
204
+{
205
+ uint32_t cfg;
206
+ uint32_t fake_count = 0x12345678;
207
+ QTestState *qts = qtest_init("-machine sifive_e");
208
+
209
+ test_init(qts);
210
+
211
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
212
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, fake_count);
213
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) == fake_count);
214
+ g_assert((uint16_t)qtest_readl(qts, WDOG_BASE + WDOGS) ==
215
+ (uint16_t)fake_count);
216
+
217
+ for (int i = 0; i < 16; i++) {
218
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
219
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, SCALE, i);
220
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
221
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
222
+ g_assert((uint16_t)qtest_readl(qts, WDOG_BASE + WDOGS) ==
223
+ (uint16_t)(fake_count >>
224
+ FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE)));
225
+ }
226
+
227
+ qtest_quit(qts);
228
+}
229
+
230
+static void test_watchdog(void)
231
+{
232
+ uint32_t cfg;
233
+ QTestState *qts = qtest_init("-machine sifive_e");
234
+
235
+ test_init(qts);
236
+
237
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
238
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, SIFIVE_E_LFCLK_DEFAULT_FREQ);
239
+
240
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
241
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, SCALE, 0);
242
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 1);
243
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
244
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
245
+
246
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND);
247
+
248
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) ==
249
+ SIFIVE_E_LFCLK_DEFAULT_FREQ);
250
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGS) ==
251
+ SIFIVE_E_LFCLK_DEFAULT_FREQ);
252
+
253
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
254
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
255
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
256
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
257
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
258
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
259
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
260
+
261
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
262
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0);
263
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, IP0, 0);
264
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
265
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
266
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
267
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
268
+
269
+ qtest_quit(qts);
270
+}
271
+
272
+static void test_scaled_watchdog(void)
273
+{
274
+ uint32_t cfg;
275
+ QTestState *qts = qtest_init("-machine sifive_e");
276
+
277
+ test_init(qts);
278
+
279
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
280
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, 10);
281
+
282
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
283
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, SCALE, 15);
284
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 1);
285
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
286
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
287
+
288
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND * 10);
289
+
290
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) ==
291
+ SIFIVE_E_LFCLK_DEFAULT_FREQ * 10);
292
+
293
+ g_assert(10 == qtest_readl(qts, WDOG_BASE + WDOGS));
294
+
295
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
296
+ g_assert(15 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
297
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
298
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
299
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
300
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
301
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
302
+
303
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
304
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0);
305
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, IP0, 0);
306
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
307
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
308
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
309
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
310
+
311
+ qtest_quit(qts);
312
+}
313
+
314
+static void test_periodic_int(void)
315
+{
316
+ uint32_t cfg;
317
+ QTestState *qts = qtest_init("-machine sifive_e");
318
+
319
+ test_init(qts);
320
+
321
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
322
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, SIFIVE_E_LFCLK_DEFAULT_FREQ);
323
+
324
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
325
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, SCALE, 0);
326
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, ZEROCMP, 1);
327
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 1);
328
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
329
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
330
+
331
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND);
332
+
333
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
334
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGS));
335
+
336
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
337
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
338
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
339
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
340
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
341
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
342
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
343
+
344
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, IP0, 0);
345
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
346
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
347
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
348
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
349
+
350
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND);
351
+
352
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGCOUNT));
353
+ g_assert(0 == qtest_readl(qts, WDOG_BASE + WDOGS));
354
+
355
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
356
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
357
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
358
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
359
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
360
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
361
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
362
+
363
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, IP0, 0);
364
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
365
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
366
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
367
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
368
+
369
+ qtest_quit(qts);
370
+}
371
+
372
+static void test_enable_disable(void)
373
+{
374
+ uint32_t cfg;
375
+ QTestState *qts = qtest_init("-machine sifive_e");
376
+
377
+ test_init(qts);
378
+
379
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
380
+ qtest_writel(qts, WDOG_BASE + WDOGCMP0, 10);
381
+
382
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
383
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, SCALE, 15);
384
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 1);
385
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
386
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
387
+
388
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND * 2);
389
+
390
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) ==
391
+ SIFIVE_E_LFCLK_DEFAULT_FREQ * 2);
392
+ g_assert(2 == qtest_readl(qts, WDOG_BASE + WDOGS));
393
+
394
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
395
+ g_assert(15 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
396
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
397
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
398
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
399
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
400
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
401
+
402
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
403
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 0);
404
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
405
+
406
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND * 8);
407
+
408
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) ==
409
+ SIFIVE_E_LFCLK_DEFAULT_FREQ * 2);
410
+ g_assert(2 == qtest_readl(qts, WDOG_BASE + WDOGS));
411
+
412
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
413
+ g_assert(15 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
414
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
415
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
416
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
417
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
418
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
419
+
420
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS, 1);
421
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
422
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
423
+
424
+ qtest_clock_step(qts, NANOSECONDS_PER_SECOND * 8);
425
+
426
+ g_assert(qtest_readl(qts, WDOG_BASE + WDOGCOUNT) ==
427
+ SIFIVE_E_LFCLK_DEFAULT_FREQ * 10);
428
+ g_assert(10 == qtest_readl(qts, WDOG_BASE + WDOGS));
429
+
430
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
431
+ g_assert(15 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, SCALE));
432
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, RSTEN));
433
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, ZEROCMP));
434
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_ALWAYS));
435
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE));
436
+ g_assert(1 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
437
+
438
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
439
+ qtest_writel(qts, WDOG_BASE + WDOGCOUNT, 0);
440
+ cfg = FIELD_DP32(cfg, AON_WDT_WDOGCFG, IP0, 0);
441
+ qtest_writel(qts, WDOG_BASE + WDOGKEY, SIFIVE_E_AON_WDOGKEY);
442
+ qtest_writel(qts, WDOG_BASE + WDOGCFG, cfg);
443
+ cfg = qtest_readl(qts, WDOG_BASE + WDOGCFG);
444
+ g_assert(0 == FIELD_EX32(cfg, AON_WDT_WDOGCFG, IP0));
445
+
446
+ qtest_quit(qts);
447
+}
448
+
449
+int main(int argc, char *argv[])
450
+{
451
+ g_test_init(&argc, &argv, NULL);
452
+ qtest_add_func("/sifive-e-aon-watchdog-test/wdogcount",
453
+ test_wdogcount);
454
+ qtest_add_func("/sifive-e-aon-watchdog-test/wdogcfg",
455
+ test_wdogcfg);
456
+ qtest_add_func("/sifive-e-aon-watchdog-test/wdogcmp0",
457
+ test_wdogcmp0);
458
+ qtest_add_func("/sifive-e-aon-watchdog-test/wdogkey",
459
+ test_wdogkey);
460
+ qtest_add_func("/sifive-e-aon-watchdog-test/wdogfeed",
461
+ test_wdogfeed);
462
+ qtest_add_func("/sifive-e-aon-watchdog-test/scaled_wdogs",
463
+ test_scaled_wdogs);
464
+ qtest_add_func("/sifive-e-aon-watchdog-test/watchdog",
465
+ test_watchdog);
466
+ qtest_add_func("/sifive-e-aon-watchdog-test/scaled_watchdog",
467
+ test_scaled_watchdog);
468
+ qtest_add_func("/sifive-e-aon-watchdog-test/periodic_int",
469
+ test_periodic_int);
470
+ qtest_add_func("/sifive-e-aon-watchdog-test/enable_disable",
471
+ test_enable_disable);
472
+ return g_test_run();
473
+}
474
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
475
index XXXXXXX..XXXXXXX 100644
476
--- a/tests/qtest/meson.build
477
+++ b/tests/qtest/meson.build
478
@@ -XXX,XX +XXX,XX @@ qtests_s390x = \
479
'cpu-plug-test',
480
'migration-test']
481
482
+qtests_riscv32 = \
483
+ (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
484
+
485
qos_test_ss = ss.source_set()
486
qos_test_ss.add(
487
'ac97-test.c',
488
--
489
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
1
3
We want to keep the ability to distinct between 32/64-bit host.
4
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-Id: <20230627143235.29947-2-philmd@linaro.org>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
meson.build | 11 ++++-------
12
1 file changed, 4 insertions(+), 7 deletions(-)
13
14
diff --git a/meson.build b/meson.build
15
index XXXXXXX..XXXXXXX 100644
16
--- a/meson.build
17
+++ b/meson.build
18
@@ -XXX,XX +XXX,XX @@ qapi_trace_events = []
19
20
bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
21
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
22
-supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
23
+supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
24
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
25
26
cpu = host_machine.cpu_family()
27
28
-# Unify riscv* to a single family.
29
-if cpu in ['riscv32', 'riscv64']
30
- cpu = 'riscv'
31
-endif
32
-
33
target_dirs = config_host['TARGET_DIRS'].split()
34
have_linux_user = false
35
have_bsd_user = false
36
@@ -XXX,XX +XXX,XX @@ elif cpu == 'x86'
37
host_arch = 'i386'
38
elif cpu == 'mips64'
39
host_arch = 'mips'
40
+elif cpu in ['riscv32', 'riscv64']
41
+ host_arch = 'riscv'
42
else
43
host_arch = cpu
44
endif
45
@@ -XXX,XX +XXX,XX @@ elif cpu in ['ppc', 'ppc64']
46
kvm_targets = ['ppc-softmmu', 'ppc64-softmmu']
47
elif cpu in ['mips', 'mips64']
48
kvm_targets = ['mips-softmmu', 'mipsel-softmmu', 'mips64-softmmu', 'mips64el-softmmu']
49
-elif cpu in ['riscv']
50
+elif cpu in ['riscv32', 'riscv64']
51
kvm_targets = ['riscv32-softmmu', 'riscv64-softmmu']
52
else
53
kvm_targets = []
54
--
55
2.40.1
56
57
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
1
3
Per Anup Patel in [*]:
4
5
> Currently, we only support running rv64 guest on rv64 host
6
> and rv32 guest on rv32 host.
7
>
8
> In the future, we might support running rv32 guest on rv64
9
> host but as of now we don't see a strong push for it.
10
11
Therefore, when only using the KVM accelerator it is pointless
12
to build qemu-system-riscv32 on a rv64 host (or qemu-system-riscv64
13
on a rv32 host). Restrict meson to only build the correct binary,
14
avoiding to waste ressources building unusable code.
15
16
[*] https://lore.kernel.org/qemu-devel/CAAhSdy2JeRHeeoEc1XKQhPO3aDz4YKeyQsPT4S8yKJcYTA+AiQ@mail.gmail.com/
17
18
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Message-Id: <20230627143235.29947-3-philmd@linaro.org>
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
23
---
24
meson.build | 6 ++++--
25
1 file changed, 4 insertions(+), 2 deletions(-)
26
27
diff --git a/meson.build b/meson.build
28
index XXXXXXX..XXXXXXX 100644
29
--- a/meson.build
30
+++ b/meson.build
31
@@ -XXX,XX +XXX,XX @@ elif cpu in ['ppc', 'ppc64']
32
kvm_targets = ['ppc-softmmu', 'ppc64-softmmu']
33
elif cpu in ['mips', 'mips64']
34
kvm_targets = ['mips-softmmu', 'mipsel-softmmu', 'mips64-softmmu', 'mips64el-softmmu']
35
-elif cpu in ['riscv32', 'riscv64']
36
- kvm_targets = ['riscv32-softmmu', 'riscv64-softmmu']
37
+elif cpu in ['riscv32']
38
+ kvm_targets = ['riscv32-softmmu']
39
+elif cpu in ['riscv64']
40
+ kvm_targets = ['riscv64-softmmu']
41
else
42
kvm_targets = []
43
endif
44
--
45
2.40.1
46
47
diff view generated by jsdifflib
Deleted patch
1
From: Ivan Klokov <ivan.klokov@syntacore.com>
2
1
3
Print RvV extension register to log if VPU option is enabled.
4
5
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
6
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-Id: <20230629083730.386604-1-ivan.klokov@syntacore.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/cpu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-
12
1 file changed, 56 insertions(+), 1 deletion(-)
13
14
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
18
@@ -XXX,XX +XXX,XX @@ struct isa_ext_data {
19
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
20
{#_name, _min_ver, offsetof(struct RISCVCPUConfig, _prop)}
21
22
+/*
23
+ * From vector_helper.c
24
+ * Note that vector data is stored in host-endian 64-bit chunks,
25
+ * so addressing bytes needs a host-endian fixup.
26
+ */
27
+#if HOST_BIG_ENDIAN
28
+#define BYTE(x) ((x) ^ 7)
29
+#else
30
+#define BYTE(x) (x)
31
+#endif
32
+
33
/*
34
* Here are the ordering rules of extension naming defined by RISC-V
35
* specification :
36
@@ -XXX,XX +XXX,XX @@ const char * const riscv_fpr_regnames[] = {
37
"f30/ft10", "f31/ft11"
38
};
39
40
+const char * const riscv_rvv_regnames[] = {
41
+ "v0", "v1", "v2", "v3", "v4", "v5", "v6",
42
+ "v7", "v8", "v9", "v10", "v11", "v12", "v13",
43
+ "v14", "v15", "v16", "v17", "v18", "v19", "v20",
44
+ "v21", "v22", "v23", "v24", "v25", "v26", "v27",
45
+ "v28", "v29", "v30", "v31"
46
+};
47
+
48
static const char * const riscv_excp_names[] = {
49
"misaligned_fetch",
50
"fault_fetch",
51
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
52
{
53
RISCVCPU *cpu = RISCV_CPU(cs);
54
CPURISCVState *env = &cpu->env;
55
- int i;
56
+ int i, j;
57
+ uint8_t *p;
58
59
#if !defined(CONFIG_USER_ONLY)
60
if (riscv_has_ext(env, RVH)) {
61
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
62
}
63
}
64
}
65
+ if (riscv_has_ext(env, RVV) && (flags & CPU_DUMP_VPU)) {
66
+ static const int dump_rvv_csrs[] = {
67
+ CSR_VSTART,
68
+ CSR_VXSAT,
69
+ CSR_VXRM,
70
+ CSR_VCSR,
71
+ CSR_VL,
72
+ CSR_VTYPE,
73
+ CSR_VLENB,
74
+ };
75
+ for (int i = 0; i < ARRAY_SIZE(dump_rvv_csrs); ++i) {
76
+ int csrno = dump_rvv_csrs[i];
77
+ target_ulong val = 0;
78
+ RISCVException res = riscv_csrrw_debug(env, csrno, &val, 0, 0);
79
+
80
+ /*
81
+ * Rely on the smode, hmode, etc, predicates within csr.c
82
+ * to do the filtering of the registers that are present.
83
+ */
84
+ if (res == RISCV_EXCP_NONE) {
85
+ qemu_fprintf(f, " %-8s " TARGET_FMT_lx "\n",
86
+ csr_ops[csrno].name, val);
87
+ }
88
+ }
89
+ uint16_t vlenb = cpu->cfg.vlen >> 3;
90
+
91
+ for (i = 0; i < 32; i++) {
92
+ qemu_fprintf(f, " %-8s ", riscv_rvv_regnames[i]);
93
+ p = (uint8_t *)env->vreg;
94
+ for (j = vlenb - 1 ; j >= 0; j--) {
95
+ qemu_fprintf(f, "%02x", *(p + i * vlenb + BYTE(j)));
96
+ }
97
+ qemu_fprintf(f, "\n");
98
+ }
99
+ }
100
}
101
102
static void riscv_cpu_set_pc(CPUState *cs, vaddr value)
103
--
104
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
1
3
The Advanced Core Local Interruptor (ACLINT) device can
4
only be used with TCG. Check for TCG enabled instead of
5
KVM being not. Only add the property when TCG is used.
6
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <20230629121103.87733-3-philmd@linaro.org>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
docs/system/riscv/virt.rst | 1 +
14
hw/riscv/virt.c | 18 ++++++++++--------
15
2 files changed, 11 insertions(+), 8 deletions(-)
16
17
diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst
18
index XXXXXXX..XXXXXXX 100644
19
--- a/docs/system/riscv/virt.rst
20
+++ b/docs/system/riscv/virt.rst
21
@@ -XXX,XX +XXX,XX @@ The following machine-specific options are supported:
22
23
When this option is "on", ACLINT devices will be emulated instead of
24
SiFive CLINT. When not specified, this option is assumed to be "off".
25
+ This option is restricted to the TCG accelerator.
26
27
- aia=[none|aplic|aplic-imsic]
28
29
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/hw/riscv/virt.c
32
+++ b/hw/riscv/virt.c
33
@@ -XXX,XX +XXX,XX @@
34
#include "chardev/char.h"
35
#include "sysemu/device_tree.h"
36
#include "sysemu/sysemu.h"
37
+#include "sysemu/tcg.h"
38
#include "sysemu/kvm.h"
39
#include "sysemu/tpm.h"
40
#include "hw/pci/pci.h"
41
@@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
42
43
g_free(clust_name);
44
45
- if (!kvm_enabled()) {
46
+ if (tcg_enabled()) {
47
if (s->have_aclint) {
48
create_fdt_socket_aclint(s, memmap, socket,
49
&intc_phandles[phandle_pos]);
50
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
51
hart_count, &error_abort);
52
sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
53
54
- if (!kvm_enabled()) {
55
+ if (tcg_enabled()) {
56
if (s->have_aclint) {
57
if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) {
58
/* Per-socket ACLINT MTIMER */
59
@@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
60
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
61
#endif
62
63
- object_class_property_add_bool(oc, "aclint", virt_get_aclint,
64
- virt_set_aclint);
65
- object_class_property_set_description(oc, "aclint",
66
- "Set on/off to enable/disable "
67
- "emulating ACLINT devices");
68
-
69
+ if (tcg_enabled()) {
70
+ object_class_property_add_bool(oc, "aclint", virt_get_aclint,
71
+ virt_set_aclint);
72
+ object_class_property_set_description(oc, "aclint",
73
+ "Set on/off to enable/disable "
74
+ "emulating ACLINT devices");
75
+ }
76
object_class_property_add_str(oc, "aia", virt_get_aia,
77
virt_set_aia);
78
object_class_property_set_description(oc, "aia",
79
--
80
2.40.1
81
82
diff view generated by jsdifflib
Deleted patch
1
From: Robbin Ehn <rehn@rivosinc.com>
2
1
3
This patch adds the new syscall for the
4
"RISC-V Hardware Probing Interface"
5
(https://docs.kernel.org/riscv/hwprobe.html).
6
7
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
8
Signed-off-by: Robbin Ehn <rehn@rivosinc.com>
9
Message-Id: <06a4543df2aa6101ca9a48f21a3198064b4f1f87.camel@rivosinc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
linux-user/riscv/syscall32_nr.h | 1 +
13
linux-user/riscv/syscall64_nr.h | 1 +
14
linux-user/syscall.c | 146 ++++++++++++++++++++++++++++++++
15
3 files changed, 148 insertions(+)
16
17
diff --git a/linux-user/riscv/syscall32_nr.h b/linux-user/riscv/syscall32_nr.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/linux-user/riscv/syscall32_nr.h
20
+++ b/linux-user/riscv/syscall32_nr.h
21
@@ -XXX,XX +XXX,XX @@
22
#define TARGET_NR_accept4 242
23
#define TARGET_NR_arch_specific_syscall 244
24
#define TARGET_NR_riscv_flush_icache (TARGET_NR_arch_specific_syscall + 15)
25
+#define TARGET_NR_riscv_hwprobe (TARGET_NR_arch_specific_syscall + 14)
26
#define TARGET_NR_prlimit64 261
27
#define TARGET_NR_fanotify_init 262
28
#define TARGET_NR_fanotify_mark 263
29
diff --git a/linux-user/riscv/syscall64_nr.h b/linux-user/riscv/syscall64_nr.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/linux-user/riscv/syscall64_nr.h
32
+++ b/linux-user/riscv/syscall64_nr.h
33
@@ -XXX,XX +XXX,XX @@
34
#define TARGET_NR_recvmmsg 243
35
#define TARGET_NR_arch_specific_syscall 244
36
#define TARGET_NR_riscv_flush_icache (TARGET_NR_arch_specific_syscall + 15)
37
+#define TARGET_NR_riscv_hwprobe (TARGET_NR_arch_specific_syscall + 14)
38
#define TARGET_NR_wait4 260
39
#define TARGET_NR_prlimit64 261
40
#define TARGET_NR_fanotify_init 262
41
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/linux-user/syscall.c
44
+++ b/linux-user/syscall.c
45
@@ -XXX,XX +XXX,XX @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count)
46
}
47
#endif /* TARGET_NR_getdents64 */
48
49
+#if defined(TARGET_NR_riscv_hwprobe)
50
+
51
+#define RISCV_HWPROBE_KEY_MVENDORID 0
52
+#define RISCV_HWPROBE_KEY_MARCHID 1
53
+#define RISCV_HWPROBE_KEY_MIMPID 2
54
+
55
+#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3
56
+#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0)
57
+
58
+#define RISCV_HWPROBE_KEY_IMA_EXT_0 4
59
+#define RISCV_HWPROBE_IMA_FD (1 << 0)
60
+#define RISCV_HWPROBE_IMA_C (1 << 1)
61
+
62
+#define RISCV_HWPROBE_KEY_CPUPERF_0 5
63
+#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
64
+#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
65
+#define RISCV_HWPROBE_MISALIGNED_SLOW (2 << 0)
66
+#define RISCV_HWPROBE_MISALIGNED_FAST (3 << 0)
67
+#define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0)
68
+#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0)
69
+
70
+struct riscv_hwprobe {
71
+ abi_llong key;
72
+ abi_ullong value;
73
+};
74
+
75
+static void risc_hwprobe_fill_pairs(CPURISCVState *env,
76
+ struct riscv_hwprobe *pair,
77
+ size_t pair_count)
78
+{
79
+ const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
80
+
81
+ for (; pair_count > 0; pair_count--, pair++) {
82
+ abi_llong key;
83
+ abi_ullong value;
84
+ __put_user(0, &pair->value);
85
+ __get_user(key, &pair->key);
86
+ switch (key) {
87
+ case RISCV_HWPROBE_KEY_MVENDORID:
88
+ __put_user(cfg->mvendorid, &pair->value);
89
+ break;
90
+ case RISCV_HWPROBE_KEY_MARCHID:
91
+ __put_user(cfg->marchid, &pair->value);
92
+ break;
93
+ case RISCV_HWPROBE_KEY_MIMPID:
94
+ __put_user(cfg->mimpid, &pair->value);
95
+ break;
96
+ case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
97
+ value = riscv_has_ext(env, RVI) &&
98
+ riscv_has_ext(env, RVM) &&
99
+ riscv_has_ext(env, RVA) ?
100
+ RISCV_HWPROBE_BASE_BEHAVIOR_IMA : 0;
101
+ __put_user(value, &pair->value);
102
+ break;
103
+ case RISCV_HWPROBE_KEY_IMA_EXT_0:
104
+ value = riscv_has_ext(env, RVF) &&
105
+ riscv_has_ext(env, RVD) ?
106
+ RISCV_HWPROBE_IMA_FD : 0;
107
+ value |= riscv_has_ext(env, RVC) ?
108
+ RISCV_HWPROBE_IMA_C : pair->value;
109
+ __put_user(value, &pair->value);
110
+ break;
111
+ case RISCV_HWPROBE_KEY_CPUPERF_0:
112
+ __put_user(RISCV_HWPROBE_MISALIGNED_FAST, &pair->value);
113
+ break;
114
+ default:
115
+ __put_user(-1, &pair->key);
116
+ break;
117
+ }
118
+ }
119
+}
120
+
121
+static int cpu_set_valid(abi_long arg3, abi_long arg4)
122
+{
123
+ int ret, i, tmp;
124
+ size_t host_mask_size, target_mask_size;
125
+ unsigned long *host_mask;
126
+
127
+ /*
128
+ * cpu_set_t represent CPU masks as bit masks of type unsigned long *.
129
+ * arg3 contains the cpu count.
130
+ */
131
+ tmp = (8 * sizeof(abi_ulong));
132
+ target_mask_size = ((arg3 + tmp - 1) / tmp) * sizeof(abi_ulong);
133
+ host_mask_size = (target_mask_size + (sizeof(*host_mask) - 1)) &
134
+ ~(sizeof(*host_mask) - 1);
135
+
136
+ host_mask = alloca(host_mask_size);
137
+
138
+ ret = target_to_host_cpu_mask(host_mask, host_mask_size,
139
+ arg4, target_mask_size);
140
+ if (ret != 0) {
141
+ return ret;
142
+ }
143
+
144
+ for (i = 0 ; i < host_mask_size / sizeof(*host_mask); i++) {
145
+ if (host_mask[i] != 0) {
146
+ return 0;
147
+ }
148
+ }
149
+ return -TARGET_EINVAL;
150
+}
151
+
152
+static abi_long do_riscv_hwprobe(CPUArchState *cpu_env, abi_long arg1,
153
+ abi_long arg2, abi_long arg3,
154
+ abi_long arg4, abi_long arg5)
155
+{
156
+ int ret;
157
+ struct riscv_hwprobe *host_pairs;
158
+
159
+ /* flags must be 0 */
160
+ if (arg5 != 0) {
161
+ return -TARGET_EINVAL;
162
+ }
163
+
164
+ /* check cpu_set */
165
+ if (arg3 != 0) {
166
+ ret = cpu_set_valid(arg3, arg4);
167
+ if (ret != 0) {
168
+ return ret;
169
+ }
170
+ } else if (arg4 != 0) {
171
+ return -TARGET_EINVAL;
172
+ }
173
+
174
+ /* no pairs */
175
+ if (arg2 == 0) {
176
+ return 0;
177
+ }
178
+
179
+ host_pairs = lock_user(VERIFY_WRITE, arg1,
180
+ sizeof(*host_pairs) * (size_t)arg2, 0);
181
+ if (host_pairs == NULL) {
182
+ return -TARGET_EFAULT;
183
+ }
184
+ risc_hwprobe_fill_pairs(cpu_env, host_pairs, arg2);
185
+ unlock_user(host_pairs, arg1, sizeof(*host_pairs) * (size_t)arg2);
186
+ return 0;
187
+}
188
+#endif /* TARGET_NR_riscv_hwprobe */
189
+
190
#if defined(TARGET_NR_pivot_root) && defined(__NR_pivot_root)
191
_syscall2(int, pivot_root, const char *, new_root, const char *, put_old)
192
#endif
193
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
194
return ret;
195
#endif
196
197
+#if defined(TARGET_NR_riscv_hwprobe)
198
+ case TARGET_NR_riscv_hwprobe:
199
+ return do_riscv_hwprobe(cpu_env, arg1, arg2, arg3, arg4, arg5);
200
+#endif
201
+
202
default:
203
qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
204
return -TARGET_ENOSYS;
205
--
206
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
2
1
3
Add trans_* and helper function for Zfbfmin instructions.
4
5
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
6
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-Id: <20230615063302.102409-3-liweiwei@iscas.ac.cn>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/helper.h | 4 ++
12
target/riscv/insn32.decode | 4 ++
13
target/riscv/fpu_helper.c | 12 +++++
14
target/riscv/translate.c | 1 +
15
target/riscv/insn_trans/trans_rvbf16.c.inc | 53 ++++++++++++++++++++++
16
target/riscv/insn_trans/trans_rvzfh.c.inc | 12 ++---
17
6 files changed, 80 insertions(+), 6 deletions(-)
18
create mode 100644 target/riscv/insn_trans/trans_rvbf16.c.inc
19
20
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/helper.h
23
+++ b/target/riscv/helper.h
24
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(sm4ks, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl)
25
26
/* Zce helper */
27
DEF_HELPER_FLAGS_2(cm_jalt, TCG_CALL_NO_WG, tl, env, i32)
28
+
29
+/* BF16 functions */
30
+DEF_HELPER_FLAGS_2(fcvt_bf16_s, TCG_CALL_NO_RWG, i64, env, i64)
31
+DEF_HELPER_FLAGS_2(fcvt_s_bf16, TCG_CALL_NO_RWG, i64, env, i64)
32
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/insn32.decode
35
+++ b/target/riscv/insn32.decode
36
@@ -XXX,XX +XXX,XX @@ sm4ks .. 11010 ..... ..... 000 ..... 0110011 @k_aes
37
# *** RV32 Zicond Standard Extension ***
38
czero_eqz 0000111 ..... ..... 101 ..... 0110011 @r
39
czero_nez 0000111 ..... ..... 111 ..... 0110011 @r
40
+
41
+# *** Zfbfmin Standard Extension ***
42
+fcvt_bf16_s 0100010 01000 ..... ... ..... 1010011 @r2_rm
43
+fcvt_s_bf16 0100000 00110 ..... ... ..... 1010011 @r2_rm
44
diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/fpu_helper.c
47
+++ b/target/riscv/fpu_helper.c
48
@@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_d_h(CPURISCVState *env, uint64_t rs1)
49
float16 frs1 = check_nanbox_h(env, rs1);
50
return float16_to_float64(frs1, true, &env->fp_status);
51
}
52
+
53
+uint64_t helper_fcvt_bf16_s(CPURISCVState *env, uint64_t rs1)
54
+{
55
+ float32 frs1 = check_nanbox_s(env, rs1);
56
+ return nanbox_h(env, float32_to_bfloat16(frs1, &env->fp_status));
57
+}
58
+
59
+uint64_t helper_fcvt_s_bf16(CPURISCVState *env, uint64_t rs1)
60
+{
61
+ float16 frs1 = check_nanbox_h(env, rs1);
62
+ return nanbox_s(env, bfloat16_to_float32(frs1, &env->fp_status));
63
+}
64
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/target/riscv/translate.c
67
+++ b/target/riscv/translate.c
68
@@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
69
#include "insn_trans/trans_rvk.c.inc"
70
#include "insn_trans/trans_privileged.c.inc"
71
#include "insn_trans/trans_svinval.c.inc"
72
+#include "insn_trans/trans_rvbf16.c.inc"
73
#include "decode-xthead.c.inc"
74
#include "insn_trans/trans_xthead.c.inc"
75
#include "insn_trans/trans_xventanacondops.c.inc"
76
diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
77
new file mode 100644
78
index XXXXXXX..XXXXXXX
79
--- /dev/null
80
+++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
81
@@ -XXX,XX +XXX,XX @@
82
+/*
83
+ * RISC-V translation routines for the BF16 Standard Extensions.
84
+ *
85
+ * Copyright (c) 2020-2023 PLCT Lab
86
+ *
87
+ * This program is free software; you can redistribute it and/or modify it
88
+ * under the terms and conditions of the GNU General Public License,
89
+ * version 2 or later, as published by the Free Software Foundation.
90
+ *
91
+ * This program is distributed in the hope it will be useful, but WITHOUT
92
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
94
+ * more details.
95
+ *
96
+ * You should have received a copy of the GNU General Public License along with
97
+ * this program. If not, see <http://www.gnu.org/licenses/>.
98
+ */
99
+
100
+#define REQUIRE_ZFBFMIN(ctx) do { \
101
+ if (!ctx->cfg_ptr->ext_zfbfmin) { \
102
+ return false; \
103
+ } \
104
+} while (0)
105
+
106
+static bool trans_fcvt_bf16_s(DisasContext *ctx, arg_fcvt_bf16_s *a)
107
+{
108
+ REQUIRE_FPU;
109
+ REQUIRE_ZFBFMIN(ctx);
110
+
111
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
112
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
113
+
114
+ gen_set_rm(ctx, a->rm);
115
+ gen_helper_fcvt_bf16_s(dest, cpu_env, src1);
116
+ gen_set_fpr_hs(ctx, a->rd, dest);
117
+ mark_fs_dirty(ctx);
118
+ return true;
119
+}
120
+
121
+static bool trans_fcvt_s_bf16(DisasContext *ctx, arg_fcvt_s_bf16 *a)
122
+{
123
+ REQUIRE_FPU;
124
+ REQUIRE_ZFBFMIN(ctx);
125
+
126
+ TCGv_i64 dest = dest_fpr(ctx, a->rd);
127
+ TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
128
+
129
+ gen_set_rm(ctx, a->rm);
130
+ gen_helper_fcvt_s_bf16(dest, cpu_env, src1);
131
+ gen_set_fpr_hs(ctx, a->rd, dest);
132
+ mark_fs_dirty(ctx);
133
+ return true;
134
+}
135
diff --git a/target/riscv/insn_trans/trans_rvzfh.c.inc b/target/riscv/insn_trans/trans_rvzfh.c.inc
136
index XXXXXXX..XXXXXXX 100644
137
--- a/target/riscv/insn_trans/trans_rvzfh.c.inc
138
+++ b/target/riscv/insn_trans/trans_rvzfh.c.inc
139
@@ -XXX,XX +XXX,XX @@
140
} \
141
} while (0)
142
143
-#define REQUIRE_ZFHMIN(ctx) do { \
144
- if (!ctx->cfg_ptr->ext_zfhmin) { \
145
+#define REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx) do { \
146
+ if (!ctx->cfg_ptr->ext_zfhmin && !ctx->cfg_ptr->ext_zfbfmin) { \
147
return false; \
148
} \
149
} while (0)
150
@@ -XXX,XX +XXX,XX @@ static bool trans_flh(DisasContext *ctx, arg_flh *a)
151
TCGv t0;
152
153
REQUIRE_FPU;
154
- REQUIRE_ZFHMIN(ctx);
155
+ REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx);
156
157
decode_save_opc(ctx);
158
t0 = get_gpr(ctx, a->rs1, EXT_NONE);
159
@@ -XXX,XX +XXX,XX @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a)
160
TCGv t0;
161
162
REQUIRE_FPU;
163
- REQUIRE_ZFHMIN(ctx);
164
+ REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx);
165
166
decode_save_opc(ctx);
167
t0 = get_gpr(ctx, a->rs1, EXT_NONE);
168
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a)
169
static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a)
170
{
171
REQUIRE_FPU;
172
- REQUIRE_ZFHMIN(ctx);
173
+ REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx);
174
175
TCGv dest = dest_gpr(ctx, a->rd);
176
177
@@ -XXX,XX +XXX,XX @@ static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a)
178
static bool trans_fmv_h_x(DisasContext *ctx, arg_fmv_h_x *a)
179
{
180
REQUIRE_FPU;
181
- REQUIRE_ZFHMIN(ctx);
182
+ REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx);
183
184
TCGv t0 = get_gpr(ctx, a->rs1, EXT_ZERO);
185
186
--
187
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
2
1
3
Add trans_* and helper function for Zvfbfmin instructions.
4
5
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
6
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-Id: <20230615063302.102409-4-liweiwei@iscas.ac.cn>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/helper.h | 3 +
12
target/riscv/insn32.decode | 4 ++
13
target/riscv/vector_helper.c | 6 ++
14
target/riscv/insn_trans/trans_rvbf16.c.inc | 64 ++++++++++++++++++++++
15
4 files changed, 77 insertions(+)
16
17
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/helper.h
20
+++ b/target/riscv/helper.h
21
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(cm_jalt, TCG_CALL_NO_WG, tl, env, i32)
22
/* BF16 functions */
23
DEF_HELPER_FLAGS_2(fcvt_bf16_s, TCG_CALL_NO_RWG, i64, env, i64)
24
DEF_HELPER_FLAGS_2(fcvt_s_bf16, TCG_CALL_NO_RWG, i64, env, i64)
25
+
26
+DEF_HELPER_5(vfncvtbf16_f_f_w, void, ptr, ptr, ptr, env, i32)
27
+DEF_HELPER_5(vfwcvtbf16_f_f_v, void, ptr, ptr, ptr, env, i32)
28
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/insn32.decode
31
+++ b/target/riscv/insn32.decode
32
@@ -XXX,XX +XXX,XX @@ czero_nez 0000111 ..... ..... 111 ..... 0110011 @r
33
# *** Zfbfmin Standard Extension ***
34
fcvt_bf16_s 0100010 01000 ..... ... ..... 1010011 @r2_rm
35
fcvt_s_bf16 0100000 00110 ..... ... ..... 1010011 @r2_rm
36
+
37
+# *** Zvfbfmin Standard Extension ***
38
+vfncvtbf16_f_f_w 010010 . ..... 11101 001 ..... 1010111 @r2_vm
39
+vfwcvtbf16_f_f_v 010010 . ..... 01101 001 ..... 1010111 @r2_vm
40
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/vector_helper.c
43
+++ b/target/riscv/vector_helper.c
44
@@ -XXX,XX +XXX,XX @@ RVVCALL(OPFVV1, vfwcvt_f_f_v_w, WOP_UU_W, H8, H4, float32_to_float64)
45
GEN_VEXT_V_ENV(vfwcvt_f_f_v_h, 4)
46
GEN_VEXT_V_ENV(vfwcvt_f_f_v_w, 8)
47
48
+RVVCALL(OPFVV1, vfwcvtbf16_f_f_v, WOP_UU_H, H4, H2, bfloat16_to_float32)
49
+GEN_VEXT_V_ENV(vfwcvtbf16_f_f_v, 4)
50
+
51
/* Narrowing Floating-Point/Integer Type-Convert Instructions */
52
/* (TD, T2, TX2) */
53
#define NOP_UU_B uint8_t, uint16_t, uint32_t
54
@@ -XXX,XX +XXX,XX @@ RVVCALL(OPFVV1, vfncvt_f_f_w_w, NOP_UU_W, H4, H8, float64_to_float32)
55
GEN_VEXT_V_ENV(vfncvt_f_f_w_h, 2)
56
GEN_VEXT_V_ENV(vfncvt_f_f_w_w, 4)
57
58
+RVVCALL(OPFVV1, vfncvtbf16_f_f_w, NOP_UU_H, H2, H4, float32_to_bfloat16)
59
+GEN_VEXT_V_ENV(vfncvtbf16_f_f_w, 2)
60
+
61
/*
62
* Vector Reduction Operations
63
*/
64
diff --git a/target/riscv/insn_trans/trans_rvbf16.c.inc b/target/riscv/insn_trans/trans_rvbf16.c.inc
65
index XXXXXXX..XXXXXXX 100644
66
--- a/target/riscv/insn_trans/trans_rvbf16.c.inc
67
+++ b/target/riscv/insn_trans/trans_rvbf16.c.inc
68
@@ -XXX,XX +XXX,XX @@
69
} \
70
} while (0)
71
72
+#define REQUIRE_ZVFBFMIN(ctx) do { \
73
+ if (!ctx->cfg_ptr->ext_zvfbfmin) { \
74
+ return false; \
75
+ } \
76
+} while (0)
77
+
78
static bool trans_fcvt_bf16_s(DisasContext *ctx, arg_fcvt_bf16_s *a)
79
{
80
REQUIRE_FPU;
81
@@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_bf16(DisasContext *ctx, arg_fcvt_s_bf16 *a)
82
mark_fs_dirty(ctx);
83
return true;
84
}
85
+
86
+static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a)
87
+{
88
+ REQUIRE_FPU;
89
+ REQUIRE_ZVFBFMIN(ctx);
90
+
91
+ if (opfv_narrow_check(ctx, a) && (ctx->sew == MO_16)) {
92
+ uint32_t data = 0;
93
+ TCGLabel *over = gen_new_label();
94
+
95
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
96
+ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over);
97
+ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);
98
+
99
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
100
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
101
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
102
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
103
+ tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
104
+ vreg_ofs(ctx, a->rs2), cpu_env,
105
+ ctx->cfg_ptr->vlen / 8,
106
+ ctx->cfg_ptr->vlen / 8, data,
107
+ gen_helper_vfncvtbf16_f_f_w);
108
+ mark_vs_dirty(ctx);
109
+ gen_set_label(over);
110
+ return true;
111
+ }
112
+ return false;
113
+}
114
+
115
+static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a)
116
+{
117
+ REQUIRE_FPU;
118
+ REQUIRE_ZVFBFMIN(ctx);
119
+
120
+ if (opfv_widen_check(ctx, a) && (ctx->sew == MO_16)) {
121
+ uint32_t data = 0;
122
+ TCGLabel *over = gen_new_label();
123
+
124
+ gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN);
125
+ tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over);
126
+ tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);
127
+
128
+ data = FIELD_DP32(data, VDATA, VM, a->vm);
129
+ data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
130
+ data = FIELD_DP32(data, VDATA, VTA, ctx->vta);
131
+ data = FIELD_DP32(data, VDATA, VMA, ctx->vma);
132
+ tcg_gen_gvec_3_ptr(vreg_ofs(ctx, a->rd), vreg_ofs(ctx, 0),
133
+ vreg_ofs(ctx, a->rs2), cpu_env,
134
+ ctx->cfg_ptr->vlen / 8,
135
+ ctx->cfg_ptr->vlen / 8, data,
136
+ gen_helper_vfwcvtbf16_f_f_v);
137
+ mark_vs_dirty(ctx);
138
+ gen_set_label(over);
139
+ return true;
140
+ }
141
+ return false;
142
+}
143
--
144
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
2
1
3
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
4
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
5
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
6
Message-Id: <20230615063302.102409-6-liweiwei@iscas.ac.cn>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
---
9
target/riscv/cpu.c | 7 +++++++
10
1 file changed, 7 insertions(+)
11
12
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/target/riscv/cpu.c
15
+++ b/target/riscv/cpu.c
16
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
17
ISA_EXT_DATA_ENTRY(zifencei, PRIV_VERSION_1_10_0, ext_ifencei),
18
ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause),
19
ISA_EXT_DATA_ENTRY(zawrs, PRIV_VERSION_1_12_0, ext_zawrs),
20
+ ISA_EXT_DATA_ENTRY(zfbfmin, PRIV_VERSION_1_12_0, ext_zfbfmin),
21
ISA_EXT_DATA_ENTRY(zfh, PRIV_VERSION_1_11_0, ext_zfh),
22
ISA_EXT_DATA_ENTRY(zfhmin, PRIV_VERSION_1_11_0, ext_zfhmin),
23
ISA_EXT_DATA_ENTRY(zfinx, PRIV_VERSION_1_12_0, ext_zfinx),
24
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
25
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
26
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
27
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
28
+ ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
29
+ ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
30
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
31
ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin),
32
ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx),
33
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
34
DEFINE_PROP_BOOL("x-zvfh", RISCVCPU, cfg.ext_zvfh, false),
35
DEFINE_PROP_BOOL("x-zvfhmin", RISCVCPU, cfg.ext_zvfhmin, false),
36
37
+ DEFINE_PROP_BOOL("x-zfbfmin", RISCVCPU, cfg.ext_zfbfmin, false),
38
+ DEFINE_PROP_BOOL("x-zvfbfmin", RISCVCPU, cfg.ext_zvfbfmin, false),
39
+ DEFINE_PROP_BOOL("x-zvfbfwma", RISCVCPU, cfg.ext_zvfbfwma, false),
40
+
41
DEFINE_PROP_END_OF_LIST(),
42
};
43
44
--
45
2.40.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Rob Bradford <rbradford@rivosinc.com>
2
2
3
We're going to change the handling of mvendorid/marchid/mimpid by the
3
This extension has now been ratified:
4
KVM driver. Since these are always present in all CPUs let's put the
4
https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be
5
same validation for everyone.
5
removed.
6
6
7
It doesn't make sense to allow 'mvendorid' to be different than it
7
Since this is now a ratified extension add it to the list of extensions
8
is already set in named (vendor) CPUs. Generic (dynamic) CPUs can have
8
included in the "max" CPU variant.
9
any 'mvendorid' they want.
10
9
11
Change 'mvendorid' to be a class property created via
10
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
12
'object_class_property_add', instead of using the DEFINE_PROP_UINT32()
13
macro. This allow us to define a custom setter for it that will verify,
14
for named CPUs, if mvendorid is different than it is already set by the
15
CPU. This is the error thrown for the 'veyron-v1' CPU if 'mvendorid' is
16
set to an invalid value:
17
18
$ qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,mvendorid=2
19
qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.mvendorid=2:
20
Unable to change veyron-v1-riscv-cpu mvendorid (0x61f)
21
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
23
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Message-Id: <20230706101738.460804-4-dbarboza@ventanamicro.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>
26
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
---
17
---
28
target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++-
18
target/riscv/cpu.c | 2 +-
29
1 file changed, 37 insertions(+), 1 deletion(-)
19
target/riscv/tcg/tcg-cpu.c | 2 +-
20
2 files changed, 2 insertions(+), 2 deletions(-)
30
21
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
22
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
24
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
25
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
26
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
36
static Property riscv_cpu_properties[] = {
27
MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
37
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
28
MISA_EXT_INFO(RVV, "v", "Vector operations"),
38
29
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
39
- DEFINE_PROP_UINT32("mvendorid", RISCVCPU, cfg.mvendorid, 0),
30
- MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)")
40
DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID),
31
+ MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
41
DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID),
42
43
@@ -XXX,XX +XXX,XX @@ static const struct TCGCPUOps riscv_tcg_ops = {
44
#endif /* !CONFIG_USER_ONLY */
45
};
32
};
46
33
47
+static bool riscv_cpu_is_dynamic(Object *cpu_obj)
34
static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc)
48
+{
35
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
49
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
36
index XXXXXXX..XXXXXXX 100644
50
+}
37
--- a/target/riscv/tcg/tcg-cpu.c
51
+
38
+++ b/target/riscv/tcg/tcg-cpu.c
52
+static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name,
39
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
53
+ void *opaque, Error **errp)
40
const RISCVCPUMultiExtConfig *prop;
54
+{
41
55
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
42
/* Enable RVG, RVJ and RVV that are disabled by default */
56
+ RISCVCPU *cpu = RISCV_CPU(obj);
43
- riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV);
57
+ uint32_t prev_val = cpu->cfg.mvendorid;
44
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV);
58
+ uint32_t value;
45
59
+
46
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
60
+ if (!visit_type_uint32(v, name, &value, errp)) {
47
isa_ext_update_enabled(cpu, prop->offset, true);
61
+ return;
62
+ }
63
+
64
+ if (!dynamic_cpu && prev_val != value) {
65
+ error_setg(errp, "Unable to change %s mvendorid (0x%x)",
66
+ object_get_typename(obj), prev_val);
67
+ return;
68
+ }
69
+
70
+ cpu->cfg.mvendorid = value;
71
+}
72
+
73
+static void cpu_get_mvendorid(Object *obj, Visitor *v, const char *name,
74
+ void *opaque, Error **errp)
75
+{
76
+ bool value = RISCV_CPU(obj)->cfg.mvendorid;
77
+
78
+ visit_type_bool(v, name, &value, errp);
79
+}
80
+
81
static void riscv_cpu_class_init(ObjectClass *c, void *data)
82
{
83
RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
84
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
85
cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
86
cc->tcg_ops = &riscv_tcg_ops;
87
88
+ object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid,
89
+ cpu_set_mvendorid, NULL, NULL);
90
+
91
device_class_set_props(dc, riscv_cpu_properties);
92
}
93
94
--
48
--
95
2.40.1
49
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Alistair Francis <alistair23@gmail.com>
2
2
3
We're now ready to update the multi-letter extensions status for KVM.
3
When running the instruction
4
4
5
kvm_riscv_update_cpu_cfg_isa_ext() is called called during vcpu creation
5
```
6
time to verify which user options changes host defaults (via the 'user_set'
6
cbo.flush 0(x0)
7
flag) and tries to write them back to KVM.
7
```
8
8
9
Failure to commit a change to KVM is only ignored in case KVM doesn't
9
QEMU would segfault.
10
know about the extension (-EINVAL error code) and the user wanted to
11
disable the given extension. Otherwise we're going to abort the boot
12
process.
13
10
14
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0]
15
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
allocated.
16
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
17
Message-Id: <20230706101738.460804-19-dbarboza@ventanamicro.com>
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
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
Reported-by: Fabian Thomas <fabian.thomas@cispa.de>
29
Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension")
30
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
31
Cc: qemu-stable <qemu-stable@nongnu.org>
32
Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
34
---
20
target/riscv/kvm.c | 27 +++++++++++++++++++++++++++
35
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++----
21
1 file changed, 27 insertions(+)
36
1 file changed, 12 insertions(+), 4 deletions(-)
22
37
23
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
38
diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc
24
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
25
--- a/target/riscv/kvm.c
40
--- a/target/riscv/insn_trans/trans_rvzicbo.c.inc
26
+++ b/target/riscv/kvm.c
41
+++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc
27
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v,
42
@@ -XXX,XX +XXX,XX @@
28
kvm_cpu_cfg_set(cpu, multi_ext_cfg, value);
43
static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a)
44
{
45
REQUIRE_ZICBOM(ctx);
46
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
47
+ TCGv src = get_address(ctx, a->rs1, 0);
48
+
49
+ gen_helper_cbo_clean_flush(tcg_env, src);
50
return true;
29
}
51
}
30
52
31
+static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
53
static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
32
+{
54
{
33
+ CPURISCVState *env = &cpu->env;
55
REQUIRE_ZICBOM(ctx);
34
+ uint64_t id, reg;
56
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
35
+ int i, ret;
57
+ TCGv src = get_address(ctx, a->rs1, 0);
36
+
58
+
37
+ for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) {
59
+ gen_helper_cbo_clean_flush(tcg_env, src);
38
+ KVMCPUConfig *multi_ext_cfg = &kvm_multi_ext_cfgs[i];
60
return true;
61
}
62
63
static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
64
{
65
REQUIRE_ZICBOM(ctx);
66
- gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]);
67
+ TCGv src = get_address(ctx, a->rs1, 0);
39
+
68
+
40
+ if (!multi_ext_cfg->user_set) {
69
+ gen_helper_cbo_inval(tcg_env, src);
41
+ continue;
70
return true;
42
+ }
71
}
72
73
static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
74
{
75
REQUIRE_ZICBOZ(ctx);
76
- gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]);
77
+ TCGv src = get_address(ctx, a->rs1, 0);
43
+
78
+
44
+ id = kvm_riscv_reg_id(env, KVM_REG_RISCV_ISA_EXT,
79
+ gen_helper_cbo_zero(tcg_env, src);
45
+ multi_ext_cfg->kvm_reg_id);
80
return true;
46
+ reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
47
+ ret = kvm_set_one_reg(cs, id, &reg);
48
+ if (ret != 0) {
49
+ error_report("Unable to %s extension %s in KVM, error %d",
50
+ reg ? "enable" : "disable",
51
+ multi_ext_cfg->name, ret);
52
+ exit(EXIT_FAILURE);
53
+ }
54
+ }
55
+}
56
+
57
static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
58
{
59
int i;
60
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
61
}
62
63
kvm_riscv_update_cpu_misa_ext(cpu, cs);
64
+ kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs);
65
66
return ret;
67
}
81
}
68
--
82
--
69
2.40.1
83
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
2
2
3
'marchid' shouldn't be set to a different value as previously set for
3
In AIA spec, each hart (or each hart within a group) has a unique hart
4
named CPUs.
4
number to locate the memory pages of interrupt files in the address
5
space. The number of bits required to represent any hart number is equal
6
to ceil(log2(hmax + 1)), where hmax is the largest hart number among
7
groups.
5
8
6
For all other CPUs it shouldn't be freely set either - the spec requires
9
However, if the largest hart number among groups is a power of 2, QEMU
7
that 'marchid' can't have the MSB (most significant bit) set and every
10
will pass an inaccurate hart-index-bit setting to Linux. For example, when
8
other bit set to zero, i.e. 0x80000000 is an invalid 'marchid' value for
11
the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient
9
32 bit CPUs.
12
to represent 4 harts, but we passes 3 to Linux. The code needs to be
13
updated to ensure accurate hart-index-bit settings.
10
14
11
As with 'mimpid', setting a default value based on the current QEMU
15
Additionally, a Linux patch[1] is necessary to correctly recover the hart
12
version is not a good idea because it implies that the CPU
16
index when the guest OS has only 1 hart, where the hart-index-bit is 0.
13
implementation changes from one QEMU version to the other. Named CPUs
14
should set 'marchid' to a meaningful value instead, and generic CPUs can
15
set to any valid value.
16
17
17
For the 'veyron-v1' CPU this is the error thrown if 'marchid' is set to
18
[1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/
18
a different val:
19
19
20
$ ./build/qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,marchid=0x80000000
20
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
21
qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.marchid=0x80000000:
22
Unable to change veyron-v1-riscv-cpu marchid (0x8000000000010000)
23
24
And, for generics CPUs, this is the error when trying to set to an
25
invalid val:
26
27
$ ./build/qemu-system-riscv64 -M virt -nographic -cpu rv64,marchid=0x8000000000000000
28
qemu-system-riscv64: can't apply global rv64-riscv-cpu.marchid=0x8000000000000000:
29
Unable to set marchid with MSB (64) bit set and the remaining bits zero
30
31
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
32
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
33
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
22
Cc: qemu-stable <qemu-stable@nongnu.org>
34
Message-Id: <20230706101738.460804-6-dbarboza@ventanamicro.com>
23
Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com>
35
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
36
---
25
---
37
target/riscv/cpu.c | 60 ++++++++++++++++++++++++++++++++++++++++------
26
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
38
1 file changed, 53 insertions(+), 7 deletions(-)
27
1 file changed, 8 insertions(+), 1 deletion(-)
39
28
40
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
41
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
42
--- a/target/riscv/cpu.c
31
--- a/target/riscv/kvm/kvm-cpu.c
43
+++ b/target/riscv/cpu.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
44
@@ -XXX,XX +XXX,XX @@
33
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
45
#include "tcg/tcg.h"
34
}
46
35
}
47
/* RISC-V CPU definitions */
36
48
-
37
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
49
-#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \
50
- (QEMU_VERSION_MINOR << 8) | \
51
- (QEMU_VERSION_MICRO))
52
-
53
static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";
54
55
struct isa_ext_data {
56
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
57
static Property riscv_cpu_properties[] = {
58
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
59
60
- DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID),
61
-
62
#ifndef CONFIG_USER_ONLY
63
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
64
#endif
65
@@ -XXX,XX +XXX,XX @@ static void cpu_get_mimpid(Object *obj, Visitor *v, const char *name,
66
visit_type_bool(v, name, &value, errp);
67
}
68
69
+static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
70
+ void *opaque, Error **errp)
71
+{
72
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
73
+ RISCVCPU *cpu = RISCV_CPU(obj);
74
+ uint64_t prev_val = cpu->cfg.marchid;
75
+ uint64_t value, invalid_val;
76
+ uint32_t mxlen = 0;
77
+
38
+
78
+ if (!visit_type_uint64(v, name, &value, errp)) {
39
+ if (max_hart_per_socket > 1) {
79
+ return;
40
+ max_hart_per_socket--;
41
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
42
+ } else {
43
+ hart_bits = 0;
80
+ }
44
+ }
81
+
45
+
82
+ if (!dynamic_cpu && prev_val != value) {
46
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
83
+ error_setg(errp, "Unable to change %s marchid (0x%" PRIu64 ")",
47
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
84
+ object_get_typename(obj), prev_val);
48
&hart_bits, true, NULL);
85
+ return;
86
+ }
87
+
88
+ switch (riscv_cpu_mxl(&cpu->env)) {
89
+ case MXL_RV32:
90
+ mxlen = 32;
91
+ break;
92
+ case MXL_RV64:
93
+ case MXL_RV128:
94
+ mxlen = 64;
95
+ break;
96
+ default:
97
+ g_assert_not_reached();
98
+ }
99
+
100
+ invalid_val = 1LL << (mxlen - 1);
101
+
102
+ if (value == invalid_val) {
103
+ error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
104
+ "and the remaining bits zero", mxlen);
105
+ return;
106
+ }
107
+
108
+ cpu->cfg.marchid = value;
109
+}
110
+
111
+static void cpu_get_marchid(Object *obj, Visitor *v, const char *name,
112
+ void *opaque, Error **errp)
113
+{
114
+ bool value = RISCV_CPU(obj)->cfg.marchid;
115
+
116
+ visit_type_bool(v, name, &value, errp);
117
+}
118
+
119
static void riscv_cpu_class_init(ObjectClass *c, void *data)
120
{
121
RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
122
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
123
object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
124
cpu_set_mimpid, NULL, NULL);
125
126
+ object_class_property_add(c, "marchid", "uint64", cpu_get_marchid,
127
+ cpu_set_marchid, NULL, NULL);
128
+
129
device_class_set_props(dc, riscv_cpu_properties);
130
}
131
132
--
49
--
133
2.40.1
50
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
The absence of a satp mode in riscv_host_cpu_init() is causing the
3
Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length
4
following error:
4
in bytes, when in this context we want 'reg_width' as the length in
5
bits.
5
6
6
$ ./qemu/build/qemu-system-riscv64 -machine virt,accel=kvm \
7
Fix 'reg_width' back to the value in bits like 7cb59921c05a
7
-m 2G -smp 1 -nographic -snapshot \
8
("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set
8
-kernel ./guest_imgs/Image \
9
beforehand.
9
-initrd ./guest_imgs/rootfs_kvm_riscv64.img \
10
-append "earlycon=sbi root=/dev/ram rw" \
11
-cpu host
12
**
13
ERROR:../target/riscv/cpu.c:320:satp_mode_str: code should not be
14
reached
15
Bail out! ERROR:../target/riscv/cpu.c:320:satp_mode_str: code should
16
not be reached
17
Aborted
18
10
19
The error is triggered from create_fdt_socket_cpus() in hw/riscv/virt.c.
11
While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more
20
It's trying to get satp_mode_str for a NULL cpu->cfg.satp_mode.map.
12
clarity about what the variable represents. 'bitsize' is also used in
13
riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to
14
gdb_feature_builder_append_reg().
21
15
22
For this KVM cpu we would need to inherit the satp supported modes
16
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
23
from the RISC-V host. At this moment this is not possible because the
17
Cc: Alex Bennée <alex.bennee@linaro.org>
24
KVM driver does not support it. And even when it does we can't just let
18
Reported-by: Robin Dapp <rdapp.gcc@gmail.com>
25
this broken for every other older kernel.
19
Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML")
26
27
Since mmu-type is not a required node, according to [1], skip the
28
'mmu-type' FDT node if there's no satp_mode set. We'll revisit this
29
logic when we can get satp information from KVM.
30
31
[1] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/riscv/cpus.yaml
32
33
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
34
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
22
Acked-by: Alex Bennée <alex.bennee@linaro.org>
23
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
35
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
36
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
25
Cc: qemu-stable <qemu-stable@nongnu.org>
37
Message-Id: <20230706101738.460804-3-dbarboza@ventanamicro.com>
26
Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com>
38
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
39
---
28
---
40
hw/riscv/virt.c | 14 +++++++-------
29
target/riscv/gdbstub.c | 6 +++---
41
1 file changed, 7 insertions(+), 7 deletions(-)
30
1 file changed, 3 insertions(+), 3 deletions(-)
42
31
43
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
32
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
44
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
45
--- a/hw/riscv/virt.c
34
--- a/target/riscv/gdbstub.c
46
+++ b/hw/riscv/virt.c
35
+++ b/target/riscv/gdbstub.c
47
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket,
36
@@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg)
48
s->soc[socket].hartid_base + cpu);
37
static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
49
qemu_fdt_add_subnode(ms->fdt, cpu_name);
38
{
50
39
RISCVCPU *cpu = RISCV_CPU(cs);
51
- satp_mode_max = satp_mode_max_from_map(
40
- int reg_width = cpu->cfg.vlenb;
52
- s->soc[socket].harts[cpu].cfg.satp_mode.map);
41
+ int bitsize = cpu->cfg.vlenb << 3;
53
- sv_name = g_strdup_printf("riscv,%s",
42
GDBFeatureBuilder builder;
54
- satp_mode_str(satp_mode_max, is_32_bit));
43
int i;
55
- qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name);
44
56
- g_free(sv_name);
45
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
57
-
46
58
+ if (cpu_ptr->cfg.satp_mode.supported != 0) {
47
/* First define types and totals in a whole VL */
59
+ satp_mode_max = satp_mode_max_from_map(cpu_ptr->cfg.satp_mode.map);
48
for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) {
60
+ sv_name = g_strdup_printf("riscv,%s",
49
- int count = reg_width / vec_lanes[i].size;
61
+ satp_mode_str(satp_mode_max, is_32_bit));
50
+ int count = bitsize / vec_lanes[i].size;
62
+ qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name);
51
gdb_feature_builder_append_tag(
63
+ g_free(sv_name);
52
&builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
64
+ }
53
vec_lanes[i].id, vec_lanes[i].gdb_type, count);
65
54
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
66
name = riscv_isa_string(cpu_ptr);
55
/* Define vector registers */
67
qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name);
56
for (i = 0; i < 32; i++) {
57
gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i),
58
- reg_width, i, "riscv_vector", "vector");
59
+ bitsize, i, "riscv_vector", "vector");
60
}
61
62
gdb_feature_builder_end(&builder);
68
--
63
--
69
2.40.1
64
2.45.1
70
65
71
66
diff view generated by jsdifflib
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
From: Alistair Francis <alistair23@gmail.com>
2
2
3
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
3
Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr
4
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
4
CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr
5
Acked-by: Alistair Francis <alistair.francis@wdc.com>
5
CSRs are part of the disassembly.
6
Message-Id: <20230703071759.86775-2-liweiwei@iscas.ac.cn>
6
7
Reported-by: Eric DeVolder <eric_devolder@yahoo.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>
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
---
14
---
9
disas/riscv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
15
disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
10
1 file changed, 44 insertions(+)
16
1 file changed, 64 insertions(+), 1 deletion(-)
11
17
12
diff --git a/disas/riscv.c b/disas/riscv.c
18
diff --git a/disas/riscv.c b/disas/riscv.c
13
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
14
--- a/disas/riscv.c
20
--- a/disas/riscv.c
15
+++ b/disas/riscv.c
21
+++ b/disas/riscv.c
16
@@ -XXX,XX +XXX,XX @@ typedef enum {
22
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
17
rv_op_cm_jalt = 788,
23
case 0x0383: return "mibound";
18
rv_op_czero_eqz = 789,
24
case 0x0384: return "mdbase";
19
rv_op_czero_nez = 790,
25
case 0x0385: return "mdbound";
20
+ rv_op_fcvt_bf16_s = 791,
26
- case 0x03a0: return "pmpcfg3";
21
+ rv_op_fcvt_s_bf16 = 792,
27
+ case 0x03a0: return "pmpcfg0";
22
+ rv_op_vfncvtbf16_f_f_w = 793,
28
+ case 0x03a1: return "pmpcfg1";
23
+ rv_op_vfwcvtbf16_f_f_v = 794,
29
+ case 0x03a2: return "pmpcfg2";
24
+ rv_op_vfwmaccbf16_vv = 795,
30
+ case 0x03a3: return "pmpcfg3";
25
+ rv_op_vfwmaccbf16_vf = 796,
31
+ case 0x03a4: return "pmpcfg4";
26
+ rv_op_flh = 797,
32
+ case 0x03a5: return "pmpcfg5";
27
+ rv_op_fsh = 798,
33
+ case 0x03a6: return "pmpcfg6";
28
+ rv_op_fmv_h_x = 799,
34
+ case 0x03a7: return "pmpcfg7";
29
+ rv_op_fmv_x_h = 800,
35
+ case 0x03a8: return "pmpcfg8";
30
} rv_op;
36
+ case 0x03a9: return "pmpcfg9";
31
37
+ case 0x03aa: return "pmpcfg10";
32
/* register names */
38
+ case 0x03ab: return "pmpcfg11";
33
@@ -XXX,XX +XXX,XX @@ const rv_opcode_data rvi_opcode_data[] = {
39
+ case 0x03ac: return "pmpcfg12";
34
{ "cm.jalt", rv_codec_zcmt_jt, rv_fmt_zcmt_index, NULL, 0 },
40
+ case 0x03ad: return "pmpcfg13";
35
{ "czero.eqz", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
41
+ case 0x03ae: return "pmpcfg14";
36
{ "czero.nez", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 },
42
+ case 0x03af: return "pmpcfg15";
37
+ { "fcvt.bf16.s", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
43
case 0x03b0: return "pmpaddr0";
38
+ { "fcvt.s.bf16", rv_codec_r_m, rv_fmt_rm_frd_frs1, NULL, 0, 0, 0 },
44
case 0x03b1: return "pmpaddr1";
39
+ { "vfncvtbf16.f.f.w", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
45
case 0x03b2: return "pmpaddr2";
40
+ { "vfwcvtbf16.f.f.v", rv_codec_v_r, rv_fmt_vd_vs2_vm, NULL, 0, 0, 0 },
46
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
41
+ { "vfwmaccbf16.vv", rv_codec_v_r, rv_fmt_vd_vs1_vs2_vm, NULL, 0, 0, 0 },
47
case 0x03bd: return "pmpaddr13";
42
+ { "vfwmaccbf16.vf", rv_codec_v_r, rv_fmt_vd_fs1_vs2_vm, NULL, 0, 0, 0 },
48
case 0x03be: return "pmpaddr14";
43
+ { "flh", rv_codec_i, rv_fmt_frd_offset_rs1, NULL, 0, 0, 0 },
49
case 0x03bf: return "pmpaddr15";
44
+ { "fsh", rv_codec_s, rv_fmt_frs2_offset_rs1, NULL, 0, 0, 0 },
50
+ case 0x03c0: return "pmpaddr16";
45
+ { "fmv.h.x", rv_codec_r, rv_fmt_frd_rs1, NULL, 0, 0, 0 },
51
+ case 0x03c1: return "pmpaddr17";
46
+ { "fmv.x.h", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 },
52
+ case 0x03c2: return "pmpaddr18";
47
};
53
+ case 0x03c3: return "pmpaddr19";
48
54
+ case 0x03c4: return "pmpaddr20";
49
/* CSR names */
55
+ case 0x03c5: return "pmpaddr21";
50
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
56
+ case 0x03c6: return "pmpaddr22";
51
case 3: op = rv_op_vloxei8_v; break;
57
+ case 0x03c7: return "pmpaddr23";
52
}
58
+ case 0x03c8: return "pmpaddr24";
53
break;
59
+ case 0x03c9: return "pmpaddr25";
54
+ case 1: op = rv_op_flh; break;
60
+ case 0x03ca: return "pmpaddr26";
55
case 2: op = rv_op_flw; break;
61
+ case 0x03cb: return "pmpaddr27";
56
case 3: op = rv_op_fld; break;
62
+ case 0x03cc: return "pmpaddr28";
57
case 4: op = rv_op_flq; break;
63
+ case 0x03cd: return "pmpaddr29";
58
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
64
+ case 0x03ce: return "pmpaddr30";
59
case 3: op = rv_op_vsoxei8_v; break;
65
+ case 0x03cf: return "pmpaddr31";
60
}
66
+ case 0x03d0: return "pmpaddr32";
61
break;
67
+ case 0x03d1: return "pmpaddr33";
62
+ case 1: op = rv_op_fsh; break;
68
+ case 0x03d2: return "pmpaddr34";
63
case 2: op = rv_op_fsw; break;
69
+ case 0x03d3: return "pmpaddr35";
64
case 3: op = rv_op_fsd; break;
70
+ case 0x03d4: return "pmpaddr36";
65
case 4: op = rv_op_fsq; break;
71
+ case 0x03d5: return "pmpaddr37";
66
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
72
+ case 0x03d6: return "pmpaddr38";
67
switch ((inst >> 20) & 0b11111) {
73
+ case 0x03d7: return "pmpaddr39";
68
case 1: op = rv_op_fcvt_s_d; break;
74
+ case 0x03d8: return "pmpaddr40";
69
case 3: op = rv_op_fcvt_s_q; break;
75
+ case 0x03d9: return "pmpaddr41";
70
+ case 6: op = rv_op_fcvt_s_bf16; break;
76
+ case 0x03da: return "pmpaddr42";
71
}
77
+ case 0x03db: return "pmpaddr43";
72
break;
78
+ case 0x03dc: return "pmpaddr44";
73
case 33:
79
+ case 0x03dd: return "pmpaddr45";
74
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
80
+ case 0x03de: return "pmpaddr46";
75
case 3: op = rv_op_fcvt_d_q; break;
81
+ case 0x03df: return "pmpaddr47";
76
}
82
+ case 0x03e0: return "pmpaddr48";
77
break;
83
+ case 0x03e1: return "pmpaddr49";
78
+ case 34:
84
+ case 0x03e2: return "pmpaddr50";
79
+ switch (((inst >> 20) & 0b11111)) {
85
+ case 0x03e3: return "pmpaddr51";
80
+ case 8: op = rv_op_fcvt_bf16_s; break;
86
+ case 0x03e4: return "pmpaddr52";
81
+ }
87
+ case 0x03e5: return "pmpaddr53";
82
+ break;
88
+ case 0x03e6: return "pmpaddr54";
83
case 35:
89
+ case 0x03e7: return "pmpaddr55";
84
switch ((inst >> 20) & 0b11111) {
90
+ case 0x03e8: return "pmpaddr56";
85
case 0: op = rv_op_fcvt_q_s; break;
91
+ case 0x03e9: return "pmpaddr57";
86
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
92
+ case 0x03ea: return "pmpaddr58";
87
case 1: op = rv_op_fclass_d; break;
93
+ case 0x03eb: return "pmpaddr59";
88
}
94
+ case 0x03ec: return "pmpaddr60";
89
break;
95
+ case 0x03ed: return "pmpaddr61";
90
+ case 114:
96
+ case 0x03ee: return "pmpaddr62";
91
+ switch (((inst >> 17) & 0b11111000) |
97
+ case 0x03ef: return "pmpaddr63";
92
+ ((inst >> 12) & 0b00000111)) {
98
case 0x0780: return "mtohost";
93
+ case 0: op = rv_op_fmv_x_h; break;
99
case 0x0781: return "mfromhost";
94
+ }
100
case 0x0782: return "mreset";
95
+ break;
96
case 115:
97
switch (((inst >> 17) & 0b11111000) |
98
((inst >> 12) & 0b00000111)) {
99
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
100
case 0: op = rv_op_fmv_d_x; break;
101
}
102
break;
103
+ case 122:
104
+ switch (((inst >> 17) & 0b11111000) |
105
+ ((inst >> 12) & 0b00000111)) {
106
+ case 0: op = rv_op_fmv_h_x; break;
107
+ }
108
+ break;
109
case 123:
110
switch (((inst >> 17) & 0b11111000) |
111
((inst >> 12) & 0b00000111)) {
112
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
113
case 10: op = rv_op_vfwcvt_f_xu_v; break;
114
case 11: op = rv_op_vfwcvt_f_x_v; break;
115
case 12: op = rv_op_vfwcvt_f_f_v; break;
116
+ case 13: op = rv_op_vfwcvtbf16_f_f_v; break;
117
case 14: op = rv_op_vfwcvt_rtz_xu_f_v; break;
118
case 15: op = rv_op_vfwcvt_rtz_x_f_v; break;
119
case 16: op = rv_op_vfncvt_xu_f_w; break;
120
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
121
case 21: op = rv_op_vfncvt_rod_f_f_w; break;
122
case 22: op = rv_op_vfncvt_rtz_xu_f_w; break;
123
case 23: op = rv_op_vfncvt_rtz_x_f_w; break;
124
+ case 29: op = rv_op_vfncvtbf16_f_f_w; break;
125
}
126
break;
127
case 19:
128
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
129
case 52: op = rv_op_vfwadd_wv; break;
130
case 54: op = rv_op_vfwsub_wv; break;
131
case 56: op = rv_op_vfwmul_vv; break;
132
+ case 59: op = rv_op_vfwmaccbf16_vv; break;
133
case 60: op = rv_op_vfwmacc_vv; break;
134
case 61: op = rv_op_vfwnmacc_vv; break;
135
case 62: op = rv_op_vfwmsac_vv; break;
136
@@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
137
case 52: op = rv_op_vfwadd_wf; break;
138
case 54: op = rv_op_vfwsub_wf; break;
139
case 56: op = rv_op_vfwmul_vf; break;
140
+ case 59: op = rv_op_vfwmaccbf16_vf; break;
141
case 60: op = rv_op_vfwmacc_vf; break;
142
case 61: op = rv_op_vfwnmacc_vf; break;
143
case 62: op = rv_op_vfwmsac_vf; break;
144
--
101
--
145
2.40.1
102
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: "yang.zhang" <yang.zhang@hexintek.com>
2
1
3
Should set/get riscv all reg timer,i.e, time/compare/frequency/state.
4
5
Signed-off-by: Yang Zhang <yang.zhang@hexintek.com>
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1688
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-Id: <20230707032306.4606-1-gaoshanliukou@163.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/kvm.c | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
14
15
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/kvm.c
18
+++ b/target/riscv/kvm.c
19
@@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type,
20
21
#define KVM_RISCV_SET_TIMER(cs, env, name, reg) \
22
do { \
23
- int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(env, time), &reg); \
24
+ int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(env, name), &reg); \
25
if (ret) { \
26
abort(); \
27
} \
28
--
29
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Lakshmi Bai Raja Subramanian <lakshmi.bai.rajasubramanian@bodhicomputing.com>
2
1
3
fdt_load_addr was previously declared as uint32_t which doe not match
4
with the return type of riscv_compute_fdt_addr().
5
6
This patch modifies the fdt_load_addr type from a uint32_t to a uint64_t
7
to match the riscv_compute_fdt_addr() return type.
8
9
This fixes calculating the fdt address when DRAM is mapped to higher
10
64-bit address.
11
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Signed-off-by: Lakshmi Bai Raja Subramanian <lakshmi.bai.rajasubramanian@bodhicomputing.com>
14
[ Change by AF:
15
- Cleanup commit title and message
16
]
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-Id: <168872495192.6334.3845988291412774261-1@git.sr.ht>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
---
21
hw/riscv/virt.c | 2 +-
22
1 file changed, 1 insertion(+), 1 deletion(-)
23
24
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/riscv/virt.c
27
+++ b/hw/riscv/virt.c
28
@@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data)
29
target_ulong start_addr = memmap[VIRT_DRAM].base;
30
target_ulong firmware_end_addr, kernel_start_addr;
31
const char *firmware_name = riscv_default_firmware_name(&s->soc[0]);
32
- uint32_t fdt_load_addr;
33
+ uint64_t fdt_load_addr;
34
uint64_t kernel_entry = 0;
35
BlockBackend *pflash_blk0;
36
37
--
38
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
As it is today it's not possible to use '-cpu host' if the RISC-V host
4
has RVH enabled. This is the resulting error:
5
6
$ ./qemu/build/qemu-system-riscv64 \
7
-machine virt,accel=kvm -m 2G -smp 1 \
8
-nographic -snapshot -kernel ./guest_imgs/Image \
9
-initrd ./guest_imgs/rootfs_kvm_riscv64.img \
10
-append "earlycon=sbi root=/dev/ram rw" \
11
-cpu host
12
qemu-system-riscv64: H extension requires priv spec 1.12.0
13
14
This happens because we're checking for priv spec for all CPUs, and
15
since we're not setting env->priv_ver for the 'host' CPU, it's being
16
default to zero (i.e. PRIV_SPEC_1_10_0).
17
18
In reality env->priv_ver does not make sense when running with the KVM
19
'host' CPU. It's used to gate certain CSRs/extensions during translation
20
to make them unavailable if the hart declares an older spec version. It
21
doesn't have any other use. E.g. OpenSBI version 1.2 retrieves the spec
22
checking if the CSR_MCOUNTEREN, CSR_MCOUNTINHIBIT and CSR_MENVCFG CSRs
23
are available [1].
24
25
'priv_ver' is just one example. We're doing a lot of feature validation
26
and setup during riscv_cpu_realize() that it doesn't apply to KVM CPUs.
27
Validating the feature set for those CPUs is a KVM problem that should
28
be handled in KVM specific code.
29
30
The new riscv_cpu_realize_tcg() helper contains all validation logic that
31
are applicable to TCG CPUs only. riscv_cpu_realize() verifies if we're
32
running TCG and, if it's the case, proceed with the usual TCG realize()
33
logic.
34
35
[1] lib/sbi/sbi_hart.c, hart_detect_features()
36
37
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
38
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
39
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
40
Message-Id: <20230706101738.460804-2-dbarboza@ventanamicro.com>
41
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
42
---
43
target/riscv/cpu.c | 35 +++++++++++++++++++++++++----------
44
1 file changed, 25 insertions(+), 10 deletions(-)
45
46
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/cpu.c
49
+++ b/target/riscv/cpu.c
50
@@ -XXX,XX +XXX,XX @@
51
#include "migration/vmstate.h"
52
#include "fpu/softfloat-helpers.h"
53
#include "sysemu/kvm.h"
54
+#include "sysemu/tcg.h"
55
#include "kvm_riscv.h"
56
#include "tcg/tcg.h"
57
58
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
59
}
60
}
61
62
-static void riscv_cpu_realize(DeviceState *dev, Error **errp)
63
+static void riscv_cpu_realize_tcg(DeviceState *dev, Error **errp)
64
{
65
- CPUState *cs = CPU(dev);
66
RISCVCPU *cpu = RISCV_CPU(dev);
67
CPURISCVState *env = &cpu->env;
68
- RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
69
Error *local_err = NULL;
70
71
- cpu_exec_realizefn(cs, &local_err);
72
- if (local_err != NULL) {
73
- error_propagate(errp, local_err);
74
- return;
75
- }
76
-
77
riscv_cpu_validate_misa_mxl(cpu, &local_err);
78
if (local_err != NULL) {
79
error_propagate(errp, local_err);
80
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
81
}
82
83
#ifndef CONFIG_USER_ONLY
84
- cs->tcg_cflags |= CF_PCREL;
85
+ CPU(dev)->tcg_cflags |= CF_PCREL;
86
87
if (cpu->cfg.ext_sstc) {
88
riscv_timer_init(cpu);
89
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
90
}
91
}
92
#endif
93
+}
94
+
95
+static void riscv_cpu_realize(DeviceState *dev, Error **errp)
96
+{
97
+ CPUState *cs = CPU(dev);
98
+ RISCVCPU *cpu = RISCV_CPU(dev);
99
+ RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
100
+ Error *local_err = NULL;
101
+
102
+ cpu_exec_realizefn(cs, &local_err);
103
+ if (local_err != NULL) {
104
+ error_propagate(errp, local_err);
105
+ return;
106
+ }
107
+
108
+ if (tcg_enabled()) {
109
+ riscv_cpu_realize_tcg(dev, &local_err);
110
+ if (local_err != NULL) {
111
+ error_propagate(errp, local_err);
112
+ return;
113
+ }
114
+ }
115
116
riscv_cpu_finalize_features(cpu, &local_err);
117
if (local_err != NULL) {
118
--
119
2.40.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
Following the same logic used with 'mvendorid' let's also restrict
4
'mimpid' for named CPUs. Generic CPUs keep setting the value freely.
5
6
Note that we're getting rid of the default RISCV_CPU_MARCHID value. The
7
reason is that this is not a good default since it's dynamic, changing
8
with with every QEMU version, regardless of whether the actual
9
implementation of the CPU changed from one QEMU version to the other.
10
Named CPU should set it to a meaningful value instead and generic CPUs
11
can set whatever they want.
12
13
This is the error thrown for an invalid 'mimpid' value for the veyron-v1
14
CPU:
15
16
$ ./qemu-system-riscv64 -M virt -nographic -cpu veyron-v1,mimpid=2
17
qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.mimpid=2:
18
Unable to change veyron-v1-riscv-cpu mimpid (0x111)
19
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
23
Message-Id: <20230706101738.460804-5-dbarboza@ventanamicro.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
26
target/riscv/cpu.c | 34 ++++++++++++++++++++++++++++++++--
27
1 file changed, 32 insertions(+), 2 deletions(-)
28
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu.c
32
+++ b/target/riscv/cpu.c
33
@@ -XXX,XX +XXX,XX @@
34
#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \
35
(QEMU_VERSION_MINOR << 8) | \
36
(QEMU_VERSION_MICRO))
37
-#define RISCV_CPU_MIMPID RISCV_CPU_MARCHID
38
39
static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";
40
41
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
42
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
43
44
DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID),
45
- DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID),
46
47
#ifndef CONFIG_USER_ONLY
48
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
49
@@ -XXX,XX +XXX,XX @@ static void cpu_get_mvendorid(Object *obj, Visitor *v, const char *name,
50
visit_type_bool(v, name, &value, errp);
51
}
52
53
+static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
54
+ void *opaque, Error **errp)
55
+{
56
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
57
+ RISCVCPU *cpu = RISCV_CPU(obj);
58
+ uint64_t prev_val = cpu->cfg.mimpid;
59
+ uint64_t value;
60
+
61
+ if (!visit_type_uint64(v, name, &value, errp)) {
62
+ return;
63
+ }
64
+
65
+ if (!dynamic_cpu && prev_val != value) {
66
+ error_setg(errp, "Unable to change %s mimpid (0x%" PRIu64 ")",
67
+ object_get_typename(obj), prev_val);
68
+ return;
69
+ }
70
+
71
+ cpu->cfg.mimpid = value;
72
+}
73
+
74
+static void cpu_get_mimpid(Object *obj, Visitor *v, const char *name,
75
+ void *opaque, Error **errp)
76
+{
77
+ bool value = RISCV_CPU(obj)->cfg.mimpid;
78
+
79
+ visit_type_bool(v, name, &value, errp);
80
+}
81
+
82
static void riscv_cpu_class_init(ObjectClass *c, void *data)
83
{
84
RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
85
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
86
object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid,
87
cpu_set_mvendorid, NULL, NULL);
88
89
+ object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
90
+ cpu_set_mimpid, NULL, NULL);
91
+
92
device_class_set_props(dc, riscv_cpu_properties);
93
}
94
95
--
96
2.40.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Yu-Ming Chang <yumin686@andestech.com>
2
2
3
After changing user validation for mvendorid/marchid/mimpid to guarantee
3
Both CSRRS and CSRRC always read the addressed CSR and cause any read side
4
that the value is validated on user input time, coupled with the work in
4
effects regardless of rs1 and rd fields. Note that if rs1 specifies a register
5
fetching KVM default values for them by using a scratch CPU, we're
5
holding a zero value other than x0, the instruction will still attempt to write
6
certain that the values in cpu->cfg.(mvendorid|marchid|mimpid) are
6
the unmodified value back to the CSR and will cause any attendant side effects.
7
already good to be written back to KVM.
8
7
9
There's no need to write the values back for 'host' type CPUs since the
8
So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies
10
values can't be changed, so let's do that just for generic CPUs.
9
a register holding a zero value, an illegal instruction exception should be
10
raised.
11
11
12
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
12
Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
13
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Acked-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-ID: <20240403070823.80897-1-yumin686@andestech.com>
15
Message-Id: <20230706101738.460804-9-dbarboza@ventanamicro.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
16
---
18
target/riscv/kvm.c | 31 +++++++++++++++++++++++++++++++
17
target/riscv/cpu.h | 4 ++++
19
1 file changed, 31 insertions(+)
18
target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++----
19
target/riscv/op_helper.c | 6 ++---
20
3 files changed, 53 insertions(+), 8 deletions(-)
20
21
21
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/kvm.c
24
--- a/target/riscv/cpu.h
24
+++ b/target/riscv/kvm.c
25
+++ b/target/riscv/cpu.h
25
@@ -XXX,XX +XXX,XX @@ void kvm_arch_init_irq_routing(KVMState *s)
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
27
void riscv_cpu_update_mask(CPURISCVState *env);
28
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
29
30
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
31
+ target_ulong *ret_value);
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
33
target_ulong *ret_value,
34
target_ulong new_value, target_ulong write_mask);
35
@@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
36
target_ulong new_value,
37
target_ulong write_mask);
38
39
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
40
+ Int128 *ret_value);
41
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
42
Int128 *ret_value,
43
Int128 new_value, Int128 write_mask);
44
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/csr.c
47
+++ b/target/riscv/csr.c
48
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
49
50
static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
51
int csrno,
52
- bool write_mask)
53
+ bool write)
26
{
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;
27
}
68
}
28
69
29
+static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
70
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
71
+ target_ulong *ret_value)
30
+{
72
+{
31
+ CPURISCVState *env = &cpu->env;
73
+ RISCVException ret = riscv_csrrw_check(env, csrno, false);
32
+ uint64_t id;
74
+ if (ret != RISCV_EXCP_NONE) {
33
+ int ret;
34
+
35
+ id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
36
+ KVM_REG_RISCV_CONFIG_REG(mvendorid));
37
+ ret = kvm_set_one_reg(cs, id, &cpu->cfg.mvendorid);
38
+ if (ret != 0) {
39
+ return ret;
75
+ return ret;
40
+ }
76
+ }
41
+
77
+
42
+ id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
78
+ return riscv_csrrw_do64(env, csrno, ret_value, 0, 0);
43
+ KVM_REG_RISCV_CONFIG_REG(marchid));
79
+}
44
+ ret = kvm_set_one_reg(cs, id, &cpu->cfg.marchid);
80
+
45
+ if (ret != 0) {
81
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
82
target_ulong *ret_value,
83
target_ulong new_value, target_ulong write_mask)
84
{
85
- RISCVException ret = riscv_csrrw_check(env, csrno, write_mask);
86
+ RISCVException ret = riscv_csrrw_check(env, csrno, true);
87
if (ret != RISCV_EXCP_NONE) {
88
return ret;
89
}
90
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno,
91
return RISCV_EXCP_NONE;
92
}
93
94
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
95
+ Int128 *ret_value)
96
+{
97
+ RISCVException ret;
98
+
99
+ ret = riscv_csrrw_check(env, csrno, false);
100
+ if (ret != RISCV_EXCP_NONE) {
46
+ return ret;
101
+ return ret;
47
+ }
102
+ }
48
+
103
+
49
+ id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG,
104
+ if (csr_ops[csrno].read128) {
50
+ KVM_REG_RISCV_CONFIG_REG(mimpid));
105
+ return riscv_csrrw_do128(env, csrno, ret_value,
51
+ ret = kvm_set_one_reg(cs, id, &cpu->cfg.mimpid);
106
+ int128_zero(), int128_zero());
107
+ }
52
+
108
+
109
+ /*
110
+ * Fall back to 64-bit version for now, if the 128-bit alternative isn't
111
+ * at all defined.
112
+ * Note, some CSRs don't need to extend to MXLEN (64 upper bits non
113
+ * significant), for those, this fallback is correctly handling the
114
+ * accesses
115
+ */
116
+ target_ulong old_value;
117
+ ret = riscv_csrrw_do64(env, csrno, &old_value,
118
+ (target_ulong)0,
119
+ (target_ulong)0);
120
+ if (ret == RISCV_EXCP_NONE && ret_value) {
121
+ *ret_value = int128_make64(old_value);
122
+ }
53
+ return ret;
123
+ return ret;
54
+}
124
+}
55
+
125
+
56
int kvm_arch_init_vcpu(CPUState *cs)
126
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
127
Int128 *ret_value,
128
Int128 new_value, Int128 write_mask)
57
{
129
{
58
int ret = 0;
130
RISCVException ret;
59
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
131
132
- ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask));
133
+ ret = riscv_csrrw_check(env, csrno, true);
134
if (ret != RISCV_EXCP_NONE) {
135
return ret;
60
}
136
}
61
env->misa_ext = isa;
137
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
62
138
index XXXXXXX..XXXXXXX 100644
63
+ if (!object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) {
139
--- a/target/riscv/op_helper.c
64
+ ret = kvm_vcpu_set_machine_ids(cpu, cs);
140
+++ b/target/riscv/op_helper.c
65
+ }
141
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr)
66
+
142
}
67
return ret;
143
68
}
144
target_ulong val = 0;
69
145
- RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0);
146
+ RISCVException ret = riscv_csrr(env, csr, &val);
147
148
if (ret != RISCV_EXCP_NONE) {
149
riscv_raise_exception(env, ret, GETPC());
150
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr,
151
target_ulong helper_csrr_i128(CPURISCVState *env, int csr)
152
{
153
Int128 rv = int128_zero();
154
- RISCVException ret = riscv_csrrw_i128(env, csr, &rv,
155
- int128_zero(),
156
- int128_zero());
157
+ RISCVException ret = riscv_csrr_i128(env, csr, &rv);
158
159
if (ret != RISCV_EXCP_NONE) {
160
riscv_raise_exception(env, ret, GETPC());
70
--
161
--
71
2.40.1
162
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
riscv_isa_string_ext() is being used by riscv_isa_string(), which is
4
then used by boards to retrieve the 'riscv,isa' string to be written in
5
the FDT. All this happens after riscv_cpu_realize(), meaning that we're
6
already past riscv_cpu_validate_set_extensions() and, more important,
7
riscv_cpu_disable_priv_spec_isa_exts().
8
9
This means that all extensions that needed to be disabled due to
10
priv_spec mismatch are already disabled. Checking this again during
11
riscv_isa_string_ext() is unneeded. Remove it.
12
13
As a bonus, riscv_isa_string_ext() can now be used with the 'host'
14
KVM-only CPU type since it doesn't have a env->priv_ver assigned and it
15
would fail this check for no good reason.
16
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-Id: <20230706101738.460804-17-dbarboza@ventanamicro.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
23
target/riscv/cpu.c | 3 +--
24
1 file changed, 1 insertion(+), 2 deletions(-)
25
26
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/target/riscv/cpu.c
29
+++ b/target/riscv/cpu.c
30
@@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str,
31
int i;
32
33
for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
34
- if (cpu->env.priv_ver >= isa_edata_arr[i].min_version &&
35
- isa_ext_is_enabled(cpu, &isa_edata_arr[i])) {
36
+ if (isa_ext_is_enabled(cpu, &isa_edata_arr[i])) {
37
new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
38
g_free(old);
39
old = new;
40
--
41
2.40.1
diff view generated by jsdifflib