1
From: Alistair Francis <alistair.francis@wdc.com>
1
The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946:
2
2
3
The following changes since commit 4c127fdbe81d66e7cafed90908d0fd1f6f2a6cd0:
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
5
Merge remote-tracking branch 'remotes/rth/tags/pull-arm-20211021' into staging (2021-10-21 09:53:27 -0700)
6
4
7
are available in the Git repository at:
5
are available in the Git repository at:
8
6
9
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20211022-2
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528
10
8
11
for you to fetch changes up to 11ec06f9eaedc801ded34c79861367b76ab2b731:
9
for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393:
12
10
13
hw/riscv: spike: Use MachineState::ram and MachineClass::default_ram_id (2021-10-22 23:35:47 +1000)
11
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000)
14
12
15
----------------------------------------------------------------
13
----------------------------------------------------------------
16
Fourth RISC-V PR for QEMU 6.2
14
RISC-V PR for 9.1
17
15
18
- Vector extension bug fixes
16
* APLICs add child earlier than realize
19
- Bit manipulation extension bug fix
17
* Fix exposure of Zkr
20
- Support vhost-user and numa mem options on all boards
18
* Raise exceptions on wrs.nto
21
- Rationalise XLEN and operand lengths
19
* Implement SBI debug console (DBCN) calls for KVM
22
- Bump the OpenTitan FPGA support
20
* Support 64-bit addresses for initrd
23
- Remove the Ibex PLIC
21
* Change RISCV_EXCP_SEMIHOST exception number to 63
24
- General code cleanup
22
* Tolerate KVM disable ext errors
23
* Set tval in breakpoints
24
* Add support for Zve32x extension
25
* Add support for Zve64x extension
26
* Relax vector register check in RISCV gdbstub
27
* Fix the element agnostic Vector function problem
28
* Fix Zvkb extension config
29
* Implement dynamic establishment of custom decoder
30
* Add th.sxstatus CSR emulation
31
* Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
32
* Check single width operator for vector fp widen instructions
33
* Check single width operator for vfncvt.rod.f.f.w
34
* Remove redudant SEW checking for vector fp narrow/widen instructions
35
* Prioritize pmp errors in raise_mmu_exception()
36
* Do not set mtval2 for non guest-page faults
37
* Remove experimental prefix from "B" extension
38
* Fixup CBO extension register calculation
39
* Fix the hart bit setting of AIA
40
* Fix reg_width in ricsv_gen_dynamic_vector_feature()
41
* Decode all of the pmpcfg and pmpaddr CSRs
42
* Raise an exception when CSRRS/CSRRC writes a read-only CSR
25
43
26
----------------------------------------------------------------
44
----------------------------------------------------------------
27
Alistair Francis (7):
45
Alexei Filippov (1):
28
target/riscv: Remove some unused macros
46
target/riscv: do not set mtval2 for non guest-page faults
29
target/riscv: Organise the CPU properties
30
hw/riscv: opentitan: Update to the latest build
31
hw/intc: Remove the Ibex PLIC
32
hw/intc: sifive_plic: Move the properties
33
hw/intc: sifive_plic: Cleanup the realize function
34
hw/intc: sifive_plic: Cleanup the irq_request function
35
47
36
Bin Meng (6):
48
Alistair Francis (2):
37
hw/riscv: microchip_pfsoc: Use MachineState::ram and MachineClass::default_ram_id
49
target/riscv: rvzicbo: Fixup CBO extension register calculation
38
hw/riscv: opentitan: Use MachineState::ram and MachineClass::default_ram_id
50
disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs
39
hw/riscv: shakti_c: Use MachineState::ram and MachineClass::default_ram_id
40
hw/riscv: sifive_e: Use MachineState::ram and MachineClass::default_ram_id
41
hw/riscv: sifive_u: Use MachineState::ram and MachineClass::default_ram_id
42
hw/riscv: spike: Use MachineState::ram and MachineClass::default_ram_id
43
51
44
Frank Chang (2):
52
Andrew Jones (2):
45
target/riscv: Pass the same value to oprsz and maxsz for vmv.v.v
53
target/riscv/kvm: Fix exposure of Zkr
46
target/riscv: fix TB_FLAGS bits overlapping bug for rvv/rvh
54
target/riscv: Raise exceptions on wrs.nto
47
55
48
Mingwang Li (1):
56
Cheng Yang (1):
49
hw/riscv: virt: Use machine->ram as the system memory
57
hw/riscv/boot.c: Support 64-bit address for initrd
50
58
51
Philipp Tomsich (1):
59
Christoph Müllner (1):
52
target/riscv: Fix orc.b implementation
60
riscv: thead: Add th.sxstatus CSR emulation
53
61
54
Richard Henderson (15):
62
Clément Léger (1):
55
target/riscv: Move cpu_get_tb_cpu_state out of line
63
target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63
56
target/riscv: Create RISCVMXL enumeration
57
target/riscv: Split misa.mxl and misa.ext
58
target/riscv: Replace riscv_cpu_is_32bit with riscv_cpu_mxl
59
target/riscv: Add MXL/SXL/UXL to TB_FLAGS
60
target/riscv: Use REQUIRE_64BIT in amo_check64
61
target/riscv: Properly check SEW in amo_op
62
target/riscv: Replace is_32bit with get_xl/get_xlen
63
target/riscv: Replace DisasContext.w with DisasContext.ol
64
target/riscv: Use gen_arith_per_ol for RVM
65
target/riscv: Adjust trans_rev8_32 for riscv64
66
target/riscv: Use gen_unary_per_ol for RVB
67
target/riscv: Use gen_shift*_per_ol for RVB, RVI
68
target/riscv: Use riscv_csrrw_debug for cpu_dump
69
target/riscv: Compute mstatus.sd on demand
70
64
71
Travis Geiselbrecht (1):
65
Daniel Henrique Barboza (6):
72
target/riscv: line up all of the registers in the info register dump
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()
73
72
74
include/hw/riscv/opentitan.h | 6 +-
73
Huang Tao (2):
75
target/riscv/cpu.h | 87 +++------
74
target/riscv: Fix the element agnostic function problem
76
target/riscv/cpu_bits.h | 16 +-
75
target/riscv: Implement dynamic establishment of custom decoder
77
hw/intc/ibex_plic.c | 307 --------------------------------
78
hw/intc/sifive_plic.c | 85 ++++-----
79
hw/riscv/boot.c | 2 +-
80
hw/riscv/microchip_pfsoc.c | 36 ++--
81
hw/riscv/opentitan.c | 38 +++-
82
hw/riscv/shakti_c.c | 6 +-
83
hw/riscv/sifive_e.c | 16 +-
84
hw/riscv/sifive_u.c | 6 +-
85
hw/riscv/spike.c | 6 +-
86
hw/riscv/virt.c | 6 +-
87
linux-user/elfload.c | 2 +-
88
linux-user/riscv/cpu_loop.c | 2 +-
89
semihosting/arm-compat-semi.c | 2 +-
90
target/riscv/cpu.c | 216 ++++++++++++----------
91
target/riscv/cpu_helper.c | 92 +++++++++-
92
target/riscv/csr.c | 104 ++++++-----
93
target/riscv/gdbstub.c | 10 +-
94
target/riscv/machine.c | 10 +-
95
target/riscv/monitor.c | 4 +-
96
target/riscv/translate.c | 174 +++++++++++++-----
97
target/riscv/insn_trans/trans_rvb.c.inc | 153 +++++++++-------
98
target/riscv/insn_trans/trans_rvi.c.inc | 44 ++---
99
target/riscv/insn_trans/trans_rvm.c.inc | 36 +++-
100
target/riscv/insn_trans/trans_rvv.c.inc | 32 ++--
101
hw/intc/meson.build | 1 -
102
28 files changed, 720 insertions(+), 779 deletions(-)
103
delete mode 100644 hw/intc/ibex_plic.c
104
76
77
Jason Chien (3):
78
target/riscv: Add support for Zve32x extension
79
target/riscv: Add support for Zve64x extension
80
target/riscv: Relax vector register check in RISCV gdbstub
81
82
Max Chou (4):
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
87
88
Rob Bradford (1):
89
target/riscv: Remove experimental prefix from "B" extension
90
91
Yangyu Chen (1):
92
target/riscv/cpu.c: fix Zvkb extension config
93
94
Yong-Xuan Wang (1):
95
target/riscv/kvm.c: Fix the hart bit setting of AIA
96
97
Yu-Ming Chang (1):
98
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR
99
100
yang.zhang (1):
101
hw/intc/riscv_aplic: APLICs should add child earlier than realize
102
103
MAINTAINERS | 1 +
104
target/riscv/cpu.h | 11 ++
105
target/riscv/cpu_bits.h | 2 +-
106
target/riscv/cpu_cfg.h | 2 +
107
target/riscv/helper.h | 1 +
108
target/riscv/sbi_ecall_interface.h | 17 +++
109
target/riscv/tcg/tcg-cpu.h | 15 +++
110
disas/riscv.c | 65 +++++++++-
111
hw/intc/riscv_aplic.c | 8 +-
112
hw/riscv/boot.c | 4 +-
113
target/riscv/cpu.c | 10 +-
114
target/riscv/cpu_helper.c | 37 +++---
115
target/riscv/csr.c | 71 +++++++++--
116
target/riscv/debug.c | 3 +
117
target/riscv/gdbstub.c | 8 +-
118
target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++-
119
target/riscv/op_helper.c | 17 ++-
120
target/riscv/tcg/tcg-cpu.c | 50 +++++---
121
target/riscv/th_csr.c | 79 +++++++++++++
122
target/riscv/translate.c | 31 +++--
123
target/riscv/vector_internals.c | 22 ++++
124
target/riscv/insn_trans/trans_privileged.c.inc | 2 +
125
target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++---
126
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++--
127
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++-
128
target/riscv/meson.build | 1 +
129
26 files changed, 596 insertions(+), 109 deletions(-)
130
create mode 100644 target/riscv/th_csr.c
131
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: "yang.zhang" <yang.zhang@hexintek.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
Since only root APLICs can have hw IRQ lines, aplic->parent should
4
and can't work as expected with '-numa node,memdev' options.
4
be initialized first.
5
5
6
Use MachineState::ram instead of manually initializing RAM memory
6
Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation")
7
region, as well as by providing MachineClass::default_ram_id to
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
opt in to memdev scheme.
8
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
9
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
10
Message-ID: <20240409014445.278-1-gaoshanliukou@163.com>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-id: 20211020014112.7336-7-bmeng.cn@gmail.com
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
12
---
17
hw/riscv/spike.c | 6 ++----
13
hw/intc/riscv_aplic.c | 8 ++++----
18
1 file changed, 2 insertions(+), 4 deletions(-)
14
1 file changed, 4 insertions(+), 4 deletions(-)
19
15
20
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
16
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/riscv/spike.c
18
--- a/hw/intc/riscv_aplic.c
23
+++ b/hw/riscv/spike.c
19
+++ b/hw/intc/riscv_aplic.c
24
@@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine)
20
@@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
25
const MemMapEntry *memmap = spike_memmap;
21
qdev_prop_set_bit(dev, "msimode", msimode);
26
SpikeState *s = SPIKE_MACHINE(machine);
22
qdev_prop_set_bit(dev, "mmode", mmode);
27
MemoryRegion *system_memory = get_system_memory();
23
28
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
24
+ if (parent) {
29
MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
25
+ riscv_aplic_add_child(parent, dev);
30
target_ulong firmware_end_addr, kernel_start_addr;
26
+ }
31
uint32_t fdt_load_addr;
27
+
32
@@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine)
28
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
29
30
if (!is_kvm_aia(msimode)) {
31
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
33
}
32
}
34
33
35
/* register system main memory (actual RAM) */
34
- if (parent) {
36
- memory_region_init_ram(main_mem, NULL, "riscv.spike.ram",
35
- riscv_aplic_add_child(parent, dev);
37
- machine->ram_size, &error_fatal);
36
- }
38
memory_region_add_subregion(system_memory, memmap[SPIKE_DRAM].base,
37
-
39
- main_mem);
38
if (!msimode) {
40
+ machine->ram);
39
for (i = 0; i < num_harts; i++) {
41
40
CPUState *cpu = cpu_by_arch_id(hartid_base + i);
42
/* create device tree */
43
create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline,
44
@@ -XXX,XX +XXX,XX @@ static void spike_machine_class_init(ObjectClass *oc, void *data)
45
mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
46
mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
47
mc->numa_mem_supported = true;
48
+ mc->default_ram_id = "riscv.spike.ram";
49
}
50
51
static const TypeInfo spike_machine_typeinfo = {
52
--
41
--
53
2.31.1
42
2.45.1
54
55
diff view generated by jsdifflib
1
From: Frank Chang <frank.chang@sifive.com>
1
From: Andrew Jones <ajones@ventanamicro.com>
2
2
3
TB_FLAGS mem_idx bits was extended from 2 bits to 3 bits in
3
The Zkr extension may only be exposed to KVM guests if the VMM
4
commit: c445593, but other TB_FLAGS bits for rvv and rvh were
4
implements the SEED CSR. Use the same implementation as TCG.
5
not shift as well so these bits may overlap with each other when
6
rvv is enabled.
7
5
8
Signed-off-by: Frank Chang <frank.chang@sifive.com>
6
Without this patch, running with a KVM which does not forward the
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
SEED CSR access to QEMU will result in an ILL exception being
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
injected into the guest (this results in Linux guests crashing on
11
Message-Id: <20211015074627.3957162-2-frank.chang@sifive.com>
9
boot). And, when running with a KVM which does forward the access,
10
QEMU will crash, since QEMU doesn't know what to do with the exit.
11
12
Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8")
13
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Cc: qemu-stable <qemu-stable@nongnu.org>
16
Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
18
---
14
target/riscv/cpu.h | 14 +++++++-------
19
target/riscv/cpu.h | 3 +++
15
target/riscv/translate.c | 2 +-
20
target/riscv/csr.c | 18 ++++++++++++++----
16
2 files changed, 8 insertions(+), 8 deletions(-)
21
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++
22
3 files changed, 42 insertions(+), 4 deletions(-)
17
23
18
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
19
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/cpu.h
26
--- a/target/riscv/cpu.h
21
+++ b/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
22
@@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env,
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
23
target_ulong riscv_cpu_get_fflags(CPURISCVState *env);
29
24
void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong);
30
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
25
31
26
-#define TB_FLAGS_MMU_MASK 7
32
+target_ulong riscv_new_csr_seed(target_ulong new_value,
27
#define TB_FLAGS_PRIV_MMU_MASK 3
33
+ target_ulong write_mask);
28
#define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2)
34
+
29
#define TB_FLAGS_MSTATUS_FS MSTATUS_FS
35
uint8_t satp_mode_max_from_map(uint32_t map);
30
@@ -XXX,XX +XXX,XX @@ typedef CPURISCVState CPUArchState;
36
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
31
typedef RISCVCPU ArchCPU;
37
32
#include "exec/cpu-all.h"
38
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
33
34
-FIELD(TB_FLAGS, VL_EQ_VLMAX, 2, 1)
35
-FIELD(TB_FLAGS, LMUL, 3, 2)
36
-FIELD(TB_FLAGS, SEW, 5, 3)
37
-FIELD(TB_FLAGS, VILL, 8, 1)
38
+FIELD(TB_FLAGS, MEM_IDX, 0, 3)
39
+FIELD(TB_FLAGS, VL_EQ_VLMAX, 3, 1)
40
+FIELD(TB_FLAGS, LMUL, 4, 2)
41
+FIELD(TB_FLAGS, SEW, 6, 3)
42
+FIELD(TB_FLAGS, VILL, 9, 1)
43
/* Is a Hypervisor instruction load/store allowed? */
44
-FIELD(TB_FLAGS, HLSX, 9, 1)
45
-FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2)
46
+FIELD(TB_FLAGS, HLSX, 10, 1)
47
+FIELD(TB_FLAGS, MSTATUS_HS_FS, 11, 2)
48
49
bool riscv_cpu_is_32bit(CPURISCVState *env);
50
51
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
52
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/translate.c
40
--- a/target/riscv/csr.c
54
+++ b/target/riscv/translate.c
41
+++ b/target/riscv/csr.c
55
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
42
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
56
uint32_t tb_flags = ctx->base.tb->flags;
43
#endif
57
44
58
ctx->pc_succ_insn = ctx->base.pc_first;
45
/* Crypto Extension */
59
- ctx->mem_idx = tb_flags & TB_FLAGS_MMU_MASK;
46
-static RISCVException rmw_seed(CPURISCVState *env, int csrno,
60
+ ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX);
47
- target_ulong *ret_value,
61
ctx->mstatus_fs = tb_flags & TB_FLAGS_MSTATUS_FS;
48
- target_ulong new_value,
62
ctx->priv_ver = env->priv_ver;
49
- target_ulong write_mask)
63
#if !defined(CONFIG_USER_ONLY)
50
+target_ulong riscv_new_csr_seed(target_ulong new_value,
51
+ target_ulong write_mask)
52
{
53
uint16_t random_v;
54
Error *random_e = NULL;
55
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
56
rval = random_v | SEED_OPST_ES16;
57
}
58
59
+ return rval;
60
+}
61
+
62
+static RISCVException rmw_seed(CPURISCVState *env, int csrno,
63
+ target_ulong *ret_value,
64
+ target_ulong new_value,
65
+ target_ulong write_mask)
66
+{
67
+ target_ulong rval;
68
+
69
+ rval = riscv_new_csr_seed(new_value, write_mask);
70
+
71
if (ret_value) {
72
*ret_value = rval;
73
}
74
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
75
index XXXXXXX..XXXXXXX 100644
76
--- a/target/riscv/kvm/kvm-cpu.c
77
+++ b/target/riscv/kvm/kvm-cpu.c
78
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
79
return ret;
80
}
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;
102
+}
103
+
104
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
105
{
106
int ret = 0;
107
@@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
108
case KVM_EXIT_RISCV_SBI:
109
ret = kvm_riscv_handle_sbi(cs, run);
110
break;
111
+ case KVM_EXIT_RISCV_CSR:
112
+ ret = kvm_riscv_handle_csr(cs, run);
113
+ break;
114
default:
115
qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
116
__func__, run->exit_reason);
64
--
117
--
65
2.31.1
118
2.45.1
66
67
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Andrew Jones <ajones@ventanamicro.com>
2
2
3
When target_long is 64-bit, we still want a 32-bit bswap for rev8.
3
Implementing wrs.nto to always just return is consistent with the
4
Since this opcode is specific to RV32, we need not conditionalize.
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.
5
13
6
Acked-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
7
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
15
Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-id: 20211020031709.359469-12-richard.henderson@linaro.org
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
20
---
12
target/riscv/insn_trans/trans_rvb.c.inc | 7 ++++++-
21
target/riscv/helper.h | 1 +
13
1 file changed, 6 insertions(+), 1 deletion(-)
22
target/riscv/op_helper.c | 11 ++++++++
23
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++-------
24
3 files changed, 32 insertions(+), 9 deletions(-)
14
25
15
diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
26
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
16
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvb.c.inc
28
--- a/target/riscv/helper.h
18
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
29
+++ b/target/riscv/helper.h
19
@@ -XXX,XX +XXX,XX @@ static bool trans_rol(DisasContext *ctx, arg_rol *a)
30
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
20
return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl);
31
DEF_HELPER_1(sret, tl, env)
32
DEF_HELPER_1(mret, tl, env)
33
DEF_HELPER_1(wfi, void, env)
34
+DEF_HELPER_1(wrs_nto, void, env)
35
DEF_HELPER_1(tlb_flush, void, env)
36
DEF_HELPER_1(tlb_flush_all, void, env)
37
/* Native Debug */
38
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/op_helper.c
41
+++ b/target/riscv/op_helper.c
42
@@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env)
43
}
21
}
44
}
22
45
23
+static void gen_rev8_32(TCGv ret, TCGv src1)
46
+void helper_wrs_nto(CPURISCVState *env)
24
+{
47
+{
25
+ tcg_gen_bswap32_tl(ret, src1, TCG_BSWAP_OS);
48
+ if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) &&
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
+ }
26
+}
55
+}
27
+
56
+
28
static bool trans_rev8_32(DisasContext *ctx, arg_rev8_32 *a)
57
void helper_tlb_flush(CPURISCVState *env)
29
{
58
{
30
REQUIRE_32BIT(ctx);
59
CPUState *cs = env_cpu(env);
31
REQUIRE_ZBB(ctx);
60
diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc
32
- return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl);
61
index XXXXXXX..XXXXXXX 100644
33
+ return gen_unary(ctx, a, EXT_NONE, gen_rev8_32);
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;
34
}
75
}
35
76
36
static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a)
77
-#define GEN_TRANS_WRS(insn) \
78
-static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \
79
-{ \
80
- (void)a; \
81
- return trans_wrs(ctx); \
82
-}
83
+static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a)
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
101
+
102
+ /* We only get here when helper_wrs_nto() doesn't raise an exception. */
103
+ return trans_wrs_sto(ctx, NULL);
104
+}
37
--
105
--
38
2.31.1
106
2.45.1
39
107
40
108
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
The count zeros instructions require a separate implementation
3
SBI defines a Debug Console extension "DBCN" that will, in time, replace
4
for RV32 when TARGET_LONG_BITS == 64.
4
the legacy console putchar and getchar SBI extensions.
5
5
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
6
The appeal of the DBCN extension is that it allows multiple bytes to be
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
read/written in the SBI console in a single SBI call.
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
9
Message-id: 20211020031709.359469-13-richard.henderson@linaro.org
9
As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM
10
module to userspace. But this will only happens if the KVM module
11
actually supports this SBI extension and we activate it.
12
13
We'll check for DBCN support during init time, checking if get-reg-list
14
is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via
15
kvm_set_one_reg() during kvm_arch_init_vcpu().
16
17
Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for
18
SBI_EXT_DBCN, reading and writing as required.
19
20
A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V
21
host, takes around 20 seconds to boot without using DBCN. With this
22
patch we're taking around 14 seconds to boot due to the speed-up in the
23
terminal output. There's no change in boot time if the guest isn't
24
using earlycon.
25
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
28
Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
30
---
12
target/riscv/translate.c | 16 ++++++++++++
31
target/riscv/sbi_ecall_interface.h | 17 +++++
13
target/riscv/insn_trans/trans_rvb.c.inc | 33 ++++++++++++-------------
32
target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++
14
2 files changed, 32 insertions(+), 17 deletions(-)
33
2 files changed, 128 insertions(+)
15
34
16
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
35
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
17
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/translate.c
37
--- a/target/riscv/sbi_ecall_interface.h
19
+++ b/target/riscv/translate.c
38
+++ b/target/riscv/sbi_ecall_interface.h
20
@@ -XXX,XX +XXX,XX @@ static bool gen_unary(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
39
@@ -XXX,XX +XXX,XX @@
40
41
/* clang-format off */
42
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)
101
+{
102
+ struct kvm_reg_list *reg_search;
103
+
104
+ reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n,
105
+ sizeof(uint64_t), uint64_cmp);
106
+
107
+ if (reg_search) {
108
+ kvm_sbi_dbcn.supported = true;
109
+ }
110
+}
111
+
112
static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
113
struct kvm_reg_list *reglist)
114
{
115
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
116
if (riscv_has_ext(&cpu->env, RVV)) {
117
kvm_riscv_read_vlenb(cpu, kvmcpu, reglist);
118
}
119
+
120
+ kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist);
121
}
122
123
static void riscv_init_kvm_registers(Object *cpu_obj)
124
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
125
return ret;
126
}
127
128
+static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs)
129
+{
130
+ target_ulong reg = 1;
131
+
132
+ if (!kvm_sbi_dbcn.supported) {
133
+ return 0;
134
+ }
135
+
136
+ return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, &reg);
137
+}
138
+
139
int kvm_arch_init_vcpu(CPUState *cs)
140
{
141
int ret = 0;
142
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
143
kvm_riscv_update_cpu_misa_ext(cpu, cs);
144
kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs);
145
146
+ ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs);
147
+
148
return ret;
149
}
150
151
@@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
21
return true;
152
return true;
22
}
153
}
23
154
24
+static bool gen_unary_per_ol(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
155
+static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run)
25
+ void (*f_tl)(TCGv, TCGv),
26
+ void (*f_32)(TCGv, TCGv))
27
+{
156
+{
28
+ int olen = get_olen(ctx);
157
+ g_autofree uint8_t *buf = NULL;
29
+
158
+ RISCVCPU *cpu = RISCV_CPU(cs);
30
+ if (olen != TARGET_LONG_BITS) {
159
+ target_ulong num_bytes;
31
+ if (olen == 32) {
160
+ uint64_t addr;
32
+ f_tl = f_32;
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);
33
+ } else {
196
+ } else {
34
+ g_assert_not_reached();
197
+ cpu_physical_memory_read(addr, buf, num_bytes);
35
+ }
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;
36
+ }
225
+ }
37
+ return gen_unary(ctx, a, ext, f_tl);
38
+}
226
+}
39
+
227
+
40
static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
228
static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
41
{
229
{
42
DisasContext *ctx = container_of(dcbase, DisasContext, base);
230
int ret = 0;
43
diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
231
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
44
index XXXXXXX..XXXXXXX 100644
232
}
45
--- a/target/riscv/insn_trans/trans_rvb.c.inc
233
ret = 0;
46
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
234
break;
47
@@ -XXX,XX +XXX,XX @@ static void gen_clz(TCGv ret, TCGv arg1)
235
+ case SBI_EXT_DBCN:
48
tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS);
236
+ kvm_riscv_handle_sbi_dbcn(cs, run);
49
}
237
+ break;
50
238
default:
51
+static void gen_clzw(TCGv ret, TCGv arg1)
239
qemu_log_mask(LOG_UNIMP,
52
+{
240
"%s: un-handled SBI EXIT, specific reasons is %lu\n",
53
+ TCGv t = tcg_temp_new();
54
+ tcg_gen_shli_tl(t, arg1, 32);
55
+ tcg_gen_clzi_tl(ret, t, 32);
56
+ tcg_temp_free(t);
57
+}
58
+
59
static bool trans_clz(DisasContext *ctx, arg_clz *a)
60
{
61
REQUIRE_ZBB(ctx);
62
- return gen_unary(ctx, a, EXT_ZERO, gen_clz);
63
+ return gen_unary_per_ol(ctx, a, EXT_NONE, gen_clz, gen_clzw);
64
}
65
66
static void gen_ctz(TCGv ret, TCGv arg1)
67
@@ -XXX,XX +XXX,XX @@ static void gen_ctz(TCGv ret, TCGv arg1)
68
tcg_gen_ctzi_tl(ret, arg1, TARGET_LONG_BITS);
69
}
70
71
+static void gen_ctzw(TCGv ret, TCGv arg1)
72
+{
73
+ tcg_gen_ctzi_tl(ret, arg1, 32);
74
+}
75
+
76
static bool trans_ctz(DisasContext *ctx, arg_ctz *a)
77
{
78
REQUIRE_ZBB(ctx);
79
- return gen_unary(ctx, a, EXT_ZERO, gen_ctz);
80
+ return gen_unary_per_ol(ctx, a, EXT_ZERO, gen_ctz, gen_ctzw);
81
}
82
83
static bool trans_cpop(DisasContext *ctx, arg_cpop *a)
84
@@ -XXX,XX +XXX,XX @@ static bool trans_zext_h_64(DisasContext *ctx, arg_zext_h_64 *a)
85
return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl);
86
}
87
88
-static void gen_clzw(TCGv ret, TCGv arg1)
89
-{
90
- TCGv t = tcg_temp_new();
91
- tcg_gen_shli_tl(t, arg1, 32);
92
- tcg_gen_clzi_tl(ret, t, 32);
93
- tcg_temp_free(t);
94
-}
95
-
96
static bool trans_clzw(DisasContext *ctx, arg_clzw *a)
97
{
98
REQUIRE_64BIT(ctx);
99
@@ -XXX,XX +XXX,XX @@ static bool trans_clzw(DisasContext *ctx, arg_clzw *a)
100
return gen_unary(ctx, a, EXT_NONE, gen_clzw);
101
}
102
103
-static void gen_ctzw(TCGv ret, TCGv arg1)
104
-{
105
- tcg_gen_ori_tl(ret, arg1, (target_ulong)MAKE_64BIT_MASK(32, 32));
106
- tcg_gen_ctzi_tl(ret, ret, 64);
107
-}
108
-
109
static bool trans_ctzw(DisasContext *ctx, arg_ctzw *a)
110
{
111
REQUIRE_64BIT(ctx);
112
REQUIRE_ZBB(ctx);
113
- return gen_unary(ctx, a, EXT_NONE, gen_ctzw);
114
+ return gen_unary(ctx, a, EXT_ZERO, gen_ctzw);
115
}
116
117
static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a)
118
--
241
--
119
2.31.1
242
2.45.1
120
121
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@wdc.com>
1
From: Cheng Yang <yangcheng.work@foxmail.com>
2
2
3
Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell()
4
to set the address of initrd in FDT to support 64-bit address.
5
6
Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com>
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
5
Message-id: 4200da222a65c89ed1ba35f754dcca7fdd9f08d6.1634524691.git.alistair.francis@wdc.com
6
---
10
---
7
hw/intc/sifive_plic.c | 10 ++++------
11
hw/riscv/boot.c | 4 ++--
8
1 file changed, 4 insertions(+), 6 deletions(-)
12
1 file changed, 2 insertions(+), 2 deletions(-)
9
13
10
diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
14
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
11
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/sifive_plic.c
16
--- a/hw/riscv/boot.c
13
+++ b/hw/intc/sifive_plic.c
17
+++ b/hw/riscv/boot.c
14
@@ -XXX,XX +XXX,XX @@ static void parse_hart_config(SiFivePLICState *plic)
18
@@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
15
19
/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
16
static void sifive_plic_irq_request(void *opaque, int irq, int level)
20
if (fdt) {
17
{
21
end = start + size;
18
- SiFivePLICState *plic = opaque;
22
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start);
19
- if (RISCV_DEBUG_PLIC) {
23
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end);
20
- qemu_log("sifive_plic_irq_request: irq=%d level=%d\n", irq, level);
24
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start);
21
- }
25
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end);
22
- sifive_plic_set_pending(plic, irq, level > 0);
26
}
23
- sifive_plic_update(plic);
24
+ SiFivePLICState *s = opaque;
25
+
26
+ sifive_plic_set_pending(s, irq, level > 0);
27
+ sifive_plic_update(s);
28
}
27
}
29
28
30
static void sifive_plic_realize(DeviceState *dev, Error **errp)
31
--
29
--
32
2.31.1
30
2.45.1
33
34
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Clément Léger <cleger@rivosinc.com>
2
2
3
Move the MXL_RV* defines to enumerators.
3
The current semihost exception number (16) is a reserved number (range
4
[16-17]). The upcoming double trap specification uses that number for
5
the double trap exception. Since the privileged spec (Table 22) defines
6
ranges for custom uses change the semihosting exception number to 63
7
which belongs to the range [48-63] in order to avoid any future
8
collisions with reserved exception.
4
9
5
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
10
Signed-off-by: Clément Léger <cleger@rivosinc.com>
11
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com>
8
Message-id: 20211020031709.359469-3-richard.henderson@linaro.org
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
15
---
11
target/riscv/cpu_bits.h | 8 +++++---
16
target/riscv/cpu_bits.h | 2 +-
12
1 file changed, 5 insertions(+), 3 deletions(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
13
18
14
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
19
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu_bits.h
21
--- a/target/riscv/cpu_bits.h
17
+++ b/target/riscv/cpu_bits.h
22
+++ b/target/riscv/cpu_bits.h
18
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
19
#define MISA32_MXL 0xC0000000
24
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
20
#define MISA64_MXL 0xC000000000000000ULL
25
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
21
26
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
22
-#define MXL_RV32 1
27
- RISCV_EXCP_SEMIHOST = 0x10,
23
-#define MXL_RV64 2
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
24
-#define MXL_RV128 3
29
RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
25
+typedef enum {
30
RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
26
+ MXL_RV32 = 1,
31
RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
27
+ MXL_RV64 = 2,
32
+ RISCV_EXCP_SEMIHOST = 0x3f,
28
+ MXL_RV128 = 3,
33
} RISCVException;
29
+} RISCVMXL;
34
30
35
#define RISCV_EXCP_INT_FLAG 0x80000000
31
/* sstatus CSR bits */
32
#define SSTATUS_UIE 0x00000001
33
--
36
--
34
2.31.1
37
2.45.1
35
38
36
39
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
In preparation for RV128, consider more than just "w" for
3
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr
4
operand size modification. This will be used for the "d"
4
enabled, will fail with a kernel oops SIGILL right at the start. The
5
insns from RV128 as well.
5
reason is that we can't expose zkr without implementing the SEED CSR.
6
Disabling zkr in the guest would be a workaround, but if the KVM doesn't
7
allow it we'll error out and never boot.
6
8
7
Rename oper_len to get_olen to better match get_xlen.
9
In hindsight this is too strict. If we keep proceeding, despite not
10
disabling the extension in the KVM vcpu, we'll not add the extension in
11
the riscv,isa. The guest kernel will be unaware of the extension, i.e.
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.
8
14
9
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
15
Change our current logic to not error out if we fail to disable an
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
extension in kvm_set_one_reg(), but show a warning and keep booting. It
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
17
is important to throw a warning because we must make the user aware that
12
Message-id: 20211020031709.359469-10-richard.henderson@linaro.org
18
the extension is still available in the vcpu, meaning that an
19
ill-behaved guest can ignore the riscv,isa settings and use the
20
extension.
21
22
The case we're handling happens with an EINVAL error code. If we fail to
23
disable the extension in KVM for any other reason, error out.
24
25
We'll also keep erroring out when we fail to enable an extension in KVM,
26
since adding the extension in riscv,isa at this point will cause a guest
27
malfunction because the extension isn't enabled in the vcpu.
28
29
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
33
Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
35
---
15
target/riscv/translate.c | 69 ++++++++++++++++---------
36
target/riscv/kvm/kvm-cpu.c | 12 ++++++++----
16
target/riscv/insn_trans/trans_rvb.c.inc | 8 +--
37
1 file changed, 8 insertions(+), 4 deletions(-)
17
target/riscv/insn_trans/trans_rvi.c.inc | 18 +++----
18
target/riscv/insn_trans/trans_rvm.c.inc | 10 ++--
19
4 files changed, 62 insertions(+), 43 deletions(-)
20
38
21
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
39
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
22
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/translate.c
41
--- a/target/riscv/kvm/kvm-cpu.c
24
+++ b/target/riscv/translate.c
42
+++ b/target/riscv/kvm/kvm-cpu.c
25
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
43
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
26
to any system register, which includes CSR_FRM, so we do not have
44
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
27
to reset this known value. */
45
ret = kvm_set_one_reg(cs, id, &reg);
28
int frm;
46
if (ret != 0) {
29
- bool w;
47
- error_report("Unable to %s extension %s in KVM, error %d",
30
+ RISCVMXL ol;
48
- reg ? "enable" : "disable",
31
bool virt_enabled;
49
- multi_ext_cfg->name, ret);
32
bool ext_ifencei;
50
- exit(EXIT_FAILURE);
33
bool hlsx;
51
+ if (!reg && ret == -EINVAL) {
34
@@ -XXX,XX +XXX,XX @@ static inline int __attribute__((unused)) get_xlen(DisasContext *ctx)
52
+ warn_report("KVM cannot disable extension %s",
35
return 16 << get_xl(ctx);
53
+ multi_ext_cfg->name);
36
}
54
+ } else {
37
55
+ error_report("Unable to enable extension %s in KVM, error %d",
38
-/* The word size for this operation. */
56
+ multi_ext_cfg->name, ret);
39
-static inline int oper_len(DisasContext *ctx)
57
+ exit(EXIT_FAILURE);
40
+/* The operation length, as opposed to the xlen. */
58
+ }
41
+#ifdef TARGET_RISCV32
42
+#define get_ol(ctx) MXL_RV32
43
+#else
44
+#define get_ol(ctx) ((ctx)->ol)
45
+#endif
46
+
47
+static inline int get_olen(DisasContext *ctx)
48
{
49
- return ctx->w ? 32 : TARGET_LONG_BITS;
50
+ return 16 << get_ol(ctx);
51
}
52
53
-
54
/*
55
* RISC-V requires NaN-boxing of narrower width floating point values.
56
* This applies when a 32-bit value is assigned to a 64-bit FP register.
57
@@ -XXX,XX +XXX,XX @@ static TCGv get_gpr(DisasContext *ctx, int reg_num, DisasExtend ext)
58
return ctx->zero;
59
}
60
61
- switch (ctx->w ? ext : EXT_NONE) {
62
- case EXT_NONE:
63
- return cpu_gpr[reg_num];
64
- case EXT_SIGN:
65
- t = temp_new(ctx);
66
- tcg_gen_ext32s_tl(t, cpu_gpr[reg_num]);
67
- return t;
68
- case EXT_ZERO:
69
- t = temp_new(ctx);
70
- tcg_gen_ext32u_tl(t, cpu_gpr[reg_num]);
71
- return t;
72
+ switch (get_ol(ctx)) {
73
+ case MXL_RV32:
74
+ switch (ext) {
75
+ case EXT_NONE:
76
+ break;
77
+ case EXT_SIGN:
78
+ t = temp_new(ctx);
79
+ tcg_gen_ext32s_tl(t, cpu_gpr[reg_num]);
80
+ return t;
81
+ case EXT_ZERO:
82
+ t = temp_new(ctx);
83
+ tcg_gen_ext32u_tl(t, cpu_gpr[reg_num]);
84
+ return t;
85
+ default:
86
+ g_assert_not_reached();
87
+ }
88
+ break;
89
+ case MXL_RV64:
90
+ break;
91
+ default:
92
+ g_assert_not_reached();
93
}
94
- g_assert_not_reached();
95
+ return cpu_gpr[reg_num];
96
}
97
98
static TCGv dest_gpr(DisasContext *ctx, int reg_num)
99
{
100
- if (reg_num == 0 || ctx->w) {
101
+ if (reg_num == 0 || get_olen(ctx) < TARGET_LONG_BITS) {
102
return temp_new(ctx);
103
}
104
return cpu_gpr[reg_num];
105
@@ -XXX,XX +XXX,XX @@ static TCGv dest_gpr(DisasContext *ctx, int reg_num)
106
static void gen_set_gpr(DisasContext *ctx, int reg_num, TCGv t)
107
{
108
if (reg_num != 0) {
109
- if (ctx->w) {
110
+ switch (get_ol(ctx)) {
111
+ case MXL_RV32:
112
tcg_gen_ext32s_tl(cpu_gpr[reg_num], t);
113
- } else {
114
+ break;
115
+ case MXL_RV64:
116
tcg_gen_mov_tl(cpu_gpr[reg_num], t);
117
+ break;
118
+ default:
119
+ g_assert_not_reached();
120
}
59
}
121
}
60
}
122
}
61
}
123
@@ -XXX,XX +XXX,XX @@ static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext,
124
void (*func)(TCGv, TCGv, target_long))
125
{
126
TCGv dest, src1;
127
- int max_len = oper_len(ctx);
128
+ int max_len = get_olen(ctx);
129
130
if (a->shamt >= max_len) {
131
return false;
132
@@ -XXX,XX +XXX,XX @@ static bool gen_shift_imm_tl(DisasContext *ctx, arg_shift *a, DisasExtend ext,
133
void (*func)(TCGv, TCGv, TCGv))
134
{
135
TCGv dest, src1, src2;
136
- int max_len = oper_len(ctx);
137
+ int max_len = get_olen(ctx);
138
139
if (a->shamt >= max_len) {
140
return false;
141
@@ -XXX,XX +XXX,XX @@ static bool gen_shift(DisasContext *ctx, arg_r *a, DisasExtend ext,
142
TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
143
TCGv ext2 = tcg_temp_new();
144
145
- tcg_gen_andi_tl(ext2, src2, oper_len(ctx) - 1);
146
+ tcg_gen_andi_tl(ext2, src2, get_olen(ctx) - 1);
147
func(dest, src1, ext2);
148
149
gen_set_gpr(ctx, a->rd, dest);
150
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
151
ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX);
152
ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
153
ctx->cs = cs;
154
- ctx->w = false;
155
ctx->ntemp = 0;
156
memset(ctx->temp, 0, sizeof(ctx->temp));
157
158
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
159
CPURISCVState *env = cpu->env_ptr;
160
uint16_t opcode16 = translator_lduw(env, &ctx->base, ctx->base.pc_next);
161
162
+ ctx->ol = ctx->xl;
163
decode_opc(env, ctx, opcode16);
164
ctx->base.pc_next = ctx->pc_succ_insn;
165
- ctx->w = false;
166
167
for (int i = ctx->ntemp - 1; i >= 0; --i) {
168
tcg_temp_free(ctx->temp[i]);
169
diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
170
index XXXXXXX..XXXXXXX 100644
171
--- a/target/riscv/insn_trans/trans_rvb.c.inc
172
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
173
@@ -XXX,XX +XXX,XX @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a)
174
{
175
REQUIRE_64BIT(ctx);
176
REQUIRE_ZBB(ctx);
177
- ctx->w = true;
178
+ ctx->ol = MXL_RV32;
179
return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl);
180
}
181
182
@@ -XXX,XX +XXX,XX @@ static bool trans_rorw(DisasContext *ctx, arg_rorw *a)
183
{
184
REQUIRE_64BIT(ctx);
185
REQUIRE_ZBB(ctx);
186
- ctx->w = true;
187
+ ctx->ol = MXL_RV32;
188
return gen_shift(ctx, a, EXT_NONE, gen_rorw);
189
}
190
191
@@ -XXX,XX +XXX,XX @@ static bool trans_roriw(DisasContext *ctx, arg_roriw *a)
192
{
193
REQUIRE_64BIT(ctx);
194
REQUIRE_ZBB(ctx);
195
- ctx->w = true;
196
+ ctx->ol = MXL_RV32;
197
return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_rorw);
198
}
199
200
@@ -XXX,XX +XXX,XX @@ static bool trans_rolw(DisasContext *ctx, arg_rolw *a)
201
{
202
REQUIRE_64BIT(ctx);
203
REQUIRE_ZBB(ctx);
204
- ctx->w = true;
205
+ ctx->ol = MXL_RV32;
206
return gen_shift(ctx, a, EXT_NONE, gen_rolw);
207
}
208
209
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
210
index XXXXXXX..XXXXXXX 100644
211
--- a/target/riscv/insn_trans/trans_rvi.c.inc
212
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
213
@@ -XXX,XX +XXX,XX @@ static bool trans_and(DisasContext *ctx, arg_and *a)
214
static bool trans_addiw(DisasContext *ctx, arg_addiw *a)
215
{
216
REQUIRE_64BIT(ctx);
217
- ctx->w = true;
218
+ ctx->ol = MXL_RV32;
219
return gen_arith_imm_fn(ctx, a, EXT_NONE, tcg_gen_addi_tl);
220
}
221
222
static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
223
{
224
REQUIRE_64BIT(ctx);
225
- ctx->w = true;
226
+ ctx->ol = MXL_RV32;
227
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_shli_tl);
228
}
229
230
@@ -XXX,XX +XXX,XX @@ static void gen_srliw(TCGv dst, TCGv src, target_long shamt)
231
static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
232
{
233
REQUIRE_64BIT(ctx);
234
- ctx->w = true;
235
+ ctx->ol = MXL_RV32;
236
return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_srliw);
237
}
238
239
@@ -XXX,XX +XXX,XX @@ static void gen_sraiw(TCGv dst, TCGv src, target_long shamt)
240
static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
241
{
242
REQUIRE_64BIT(ctx);
243
- ctx->w = true;
244
+ ctx->ol = MXL_RV32;
245
return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_sraiw);
246
}
247
248
static bool trans_addw(DisasContext *ctx, arg_addw *a)
249
{
250
REQUIRE_64BIT(ctx);
251
- ctx->w = true;
252
+ ctx->ol = MXL_RV32;
253
return gen_arith(ctx, a, EXT_NONE, tcg_gen_add_tl);
254
}
255
256
static bool trans_subw(DisasContext *ctx, arg_subw *a)
257
{
258
REQUIRE_64BIT(ctx);
259
- ctx->w = true;
260
+ ctx->ol = MXL_RV32;
261
return gen_arith(ctx, a, EXT_NONE, tcg_gen_sub_tl);
262
}
263
264
static bool trans_sllw(DisasContext *ctx, arg_sllw *a)
265
{
266
REQUIRE_64BIT(ctx);
267
- ctx->w = true;
268
+ ctx->ol = MXL_RV32;
269
return gen_shift(ctx, a, EXT_NONE, tcg_gen_shl_tl);
270
}
271
272
static bool trans_srlw(DisasContext *ctx, arg_srlw *a)
273
{
274
REQUIRE_64BIT(ctx);
275
- ctx->w = true;
276
+ ctx->ol = MXL_RV32;
277
return gen_shift(ctx, a, EXT_ZERO, tcg_gen_shr_tl);
278
}
279
280
static bool trans_sraw(DisasContext *ctx, arg_sraw *a)
281
{
282
REQUIRE_64BIT(ctx);
283
- ctx->w = true;
284
+ ctx->ol = MXL_RV32;
285
return gen_shift(ctx, a, EXT_SIGN, tcg_gen_sar_tl);
286
}
287
288
diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc
289
index XXXXXXX..XXXXXXX 100644
290
--- a/target/riscv/insn_trans/trans_rvm.c.inc
291
+++ b/target/riscv/insn_trans/trans_rvm.c.inc
292
@@ -XXX,XX +XXX,XX @@ static bool trans_mulw(DisasContext *ctx, arg_mulw *a)
293
{
294
REQUIRE_64BIT(ctx);
295
REQUIRE_EXT(ctx, RVM);
296
- ctx->w = true;
297
+ ctx->ol = MXL_RV32;
298
return gen_arith(ctx, a, EXT_NONE, tcg_gen_mul_tl);
299
}
300
301
@@ -XXX,XX +XXX,XX @@ static bool trans_divw(DisasContext *ctx, arg_divw *a)
302
{
303
REQUIRE_64BIT(ctx);
304
REQUIRE_EXT(ctx, RVM);
305
- ctx->w = true;
306
+ ctx->ol = MXL_RV32;
307
return gen_arith(ctx, a, EXT_SIGN, gen_div);
308
}
309
310
@@ -XXX,XX +XXX,XX @@ static bool trans_divuw(DisasContext *ctx, arg_divuw *a)
311
{
312
REQUIRE_64BIT(ctx);
313
REQUIRE_EXT(ctx, RVM);
314
- ctx->w = true;
315
+ ctx->ol = MXL_RV32;
316
return gen_arith(ctx, a, EXT_ZERO, gen_divu);
317
}
318
319
@@ -XXX,XX +XXX,XX @@ static bool trans_remw(DisasContext *ctx, arg_remw *a)
320
{
321
REQUIRE_64BIT(ctx);
322
REQUIRE_EXT(ctx, RVM);
323
- ctx->w = true;
324
+ ctx->ol = MXL_RV32;
325
return gen_arith(ctx, a, EXT_SIGN, gen_rem);
326
}
327
328
@@ -XXX,XX +XXX,XX @@ static bool trans_remuw(DisasContext *ctx, arg_remuw *a)
329
{
330
REQUIRE_64BIT(ctx);
331
REQUIRE_EXT(ctx, RVM);
332
- ctx->w = true;
333
+ ctx->ol = MXL_RV32;
334
return gen_arith(ctx, a, EXT_ZERO, gen_remu);
335
}
336
--
62
--
337
2.31.1
63
2.45.1
338
339
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
We're not setting (s/m)tval when triggering breakpoints of type 2
4
and can't work as expected with '-numa node,memdev' options.
4
(mcontrol) and 6 (mcontrol6). According to the debug spec section
5
5.7.12, "Match Control Type 6":
5
6
6
Use MachineState::ram instead of manually initializing RAM memory
7
"The Privileged Spec says that breakpoint exceptions that occur on
7
region, as well as by providing MachineClass::default_ram_id to
8
instruction fetches, loads, or stores update the tval CSR with either
8
opt in to memdev scheme.
9
zero or the faulting virtual address. The faulting virtual address for
10
an mcontrol6 trigger with action = 0 is the address being accessed and
11
which caused that trigger to fire."
9
12
10
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
13
A similar text is also found in the Debug spec section 5.7.11 w.r.t.
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
mcontrol.
12
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
15
16
Note that what we're doing ATM is not violating the spec, but it's
17
simple enough to set mtval/stval and it makes life easier for any
18
software that relies on this info.
19
20
Given that we always use action = 0, save the faulting address for the
21
mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is
22
used as as scratch area for traps with address information. 'tval' is
23
then set during riscv_cpu_do_interrupt().
24
25
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-id: 20211020014112.7336-6-bmeng.cn@gmail.com
27
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
28
Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
30
---
17
hw/riscv/sifive_u.c | 6 ++----
31
target/riscv/cpu_helper.c | 1 +
18
1 file changed, 2 insertions(+), 4 deletions(-)
32
target/riscv/debug.c | 3 +++
33
2 files changed, 4 insertions(+)
19
34
20
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
35
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
21
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/riscv/sifive_u.c
37
--- a/target/riscv/cpu_helper.c
23
+++ b/hw/riscv/sifive_u.c
38
+++ b/target/riscv/cpu_helper.c
24
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine)
39
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
25
const MemMapEntry *memmap = sifive_u_memmap;
40
tval = env->bins;
26
SiFiveUState *s = RISCV_U_MACHINE(machine);
41
break;
27
MemoryRegion *system_memory = get_system_memory();
42
case RISCV_EXCP_BREAKPOINT:
28
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
43
+ tval = env->badaddr;
29
MemoryRegion *flash0 = g_new(MemoryRegion, 1);
44
if (cs->watchpoint_hit) {
30
target_ulong start_addr = memmap[SIFIVE_U_DEV_DRAM].base;
45
tval = cs->watchpoint_hit->hitaddr;
31
target_ulong firmware_end_addr, kernel_start_addr;
46
cs->watchpoint_hit = NULL;
32
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine)
47
diff --git a/target/riscv/debug.c b/target/riscv/debug.c
33
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
48
index XXXXXXX..XXXXXXX 100644
34
49
--- a/target/riscv/debug.c
35
/* register RAM */
50
+++ b/target/riscv/debug.c
36
- memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram",
51
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
37
- machine->ram_size, &error_fatal);
52
if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) {
38
memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_DRAM].base,
53
/* check U/S/M bit against current privilege level */
39
- main_mem);
54
if ((ctrl >> 3) & BIT(env->priv)) {
40
+ machine->ram);
55
+ env->badaddr = pc;
41
56
return true;
42
/* register QSPI0 Flash */
57
}
43
memory_region_init_ram(flash0, NULL, "riscv.sifive.u.flash0",
58
}
44
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_class_init(ObjectClass *oc, void *data)
59
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
45
mc->min_cpus = SIFIVE_U_MANAGEMENT_CPU_COUNT + 1;
60
if (env->virt_enabled) {
46
mc->default_cpu_type = SIFIVE_U_CPU;
61
/* check VU/VS bit against current privilege level */
47
mc->default_cpus = mc->min_cpus;
62
if ((ctrl >> 23) & BIT(env->priv)) {
48
+ mc->default_ram_id = "riscv.sifive.u.ram";
63
+ env->badaddr = pc;
49
64
return true;
50
object_class_property_add_bool(oc, "start-in-flash",
65
}
51
sifive_u_machine_get_start_in_flash,
66
} else {
67
/* check U/S/M bit against current privilege level */
68
if ((ctrl >> 3) & BIT(env->priv)) {
69
+ env->badaddr = pc;
70
return true;
71
}
72
}
52
--
73
--
53
2.31.1
74
2.45.1
54
55
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
Privileged spec section 4.1.9 mentions:
4
and can't work as expected with '-numa node,memdev' options.
5
4
6
Use MachineState::ram instead of manually initializing RAM memory
5
"When a trap is taken into S-mode, stval is written with
7
region, as well as by providing MachineClass::default_ram_id to
6
exception-specific information to assist software in handling the trap.
8
opt in to memdev scheme.
7
(...)
9
8
10
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
9
If stval is written with a nonzero value when a breakpoint,
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
address-misaligned, access-fault, or page-fault exception occurs on an
12
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
11
instruction fetch, load, or store, then stval will contain the faulting
12
virtual address."
13
14
A similar text is found for mtval in section 3.1.16.
15
16
Setting mtval/stval in this scenario is optional, but some softwares read
17
these regs when handling ebreaks.
18
19
Write 'badaddr' in all ebreak breakpoints to write the appropriate
20
'tval' during riscv_do_cpu_interrrupt().
21
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-id: 20211020014112.7336-4-bmeng.cn@gmail.com
24
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26
Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
28
---
17
hw/riscv/shakti_c.c | 6 ++----
29
target/riscv/insn_trans/trans_privileged.c.inc | 2 ++
18
1 file changed, 2 insertions(+), 4 deletions(-)
30
1 file changed, 2 insertions(+)
19
31
20
diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c
32
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
21
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/riscv/shakti_c.c
34
--- a/target/riscv/insn_trans/trans_privileged.c.inc
23
+++ b/hw/riscv/shakti_c.c
35
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
24
@@ -XXX,XX +XXX,XX @@ static void shakti_c_machine_state_init(MachineState *mstate)
36
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
25
{
37
if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
26
ShaktiCMachineState *sms = RISCV_SHAKTI_MACHINE(mstate);
38
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
27
MemoryRegion *system_memory = get_system_memory();
39
} else {
28
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
40
+ tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env,
29
41
+ offsetof(CPURISCVState, badaddr));
30
/* Allow only Shakti C CPU for this platform */
42
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
31
if (strcmp(mstate->cpu_type, TYPE_RISCV_CPU_SHAKTI_C) != 0) {
43
}
32
@@ -XXX,XX +XXX,XX @@ static void shakti_c_machine_state_init(MachineState *mstate)
44
return true;
33
qdev_realize(DEVICE(&sms->soc), NULL, &error_abort);
34
35
/* register RAM */
36
- memory_region_init_ram(main_mem, NULL, "riscv.shakti.c.ram",
37
- mstate->ram_size, &error_fatal);
38
memory_region_add_subregion(system_memory,
39
shakti_c_memmap[SHAKTI_C_RAM].base,
40
- main_mem);
41
+ mstate->ram);
42
43
/* ROM reset vector */
44
riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus,
45
@@ -XXX,XX +XXX,XX @@ static void shakti_c_machine_class_init(ObjectClass *klass, void *data)
46
mc->desc = "RISC-V Board compatible with Shakti SDK";
47
mc->init = shakti_c_machine_state_init;
48
mc->default_cpu_type = TYPE_RISCV_CPU_SHAKTI_C;
49
+ mc->default_ram_id = "riscv.shakti.c.ram";
50
}
51
52
static const TypeInfo shakti_c_machine_type_info = {
53
--
45
--
54
2.31.1
46
2.45.1
55
56
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
Shortly, the set of supported XL will not be just 32 and 64,
3
Add support for Zve32x extension and replace some checks for Zve32f with
4
and representing that properly using the enumeration will be
4
Zve32x, since Zve32f depends on Zve32x.
5
imperative.
6
5
7
Two places, booting and gdb, intentionally use misa_mxl_max
6
Signed-off-by: Jason Chien <jason.chien@sifive.com>
8
to emphasize the use of the reset value of misa.mxl, and not
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
the current cpu state.
8
Reviewed-by: Max Chou <max.chou@sifive.com>
10
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
10
Message-ID: <20240328022343.6871-2-jason.chien@sifive.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20211020031709.359469-5-richard.henderson@linaro.org
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
12
---
17
target/riscv/cpu.h | 9 ++++++++-
13
target/riscv/cpu_cfg.h | 1 +
18
hw/riscv/boot.c | 2 +-
14
target/riscv/cpu.c | 2 ++
19
semihosting/arm-compat-semi.c | 2 +-
15
target/riscv/cpu_helper.c | 2 +-
20
target/riscv/cpu.c | 24 ++++++++++++++----------
16
target/riscv/csr.c | 2 +-
21
target/riscv/cpu_helper.c | 12 ++++++------
17
target/riscv/tcg/tcg-cpu.c | 16 ++++++++--------
22
target/riscv/csr.c | 24 ++++++++++++------------
18
target/riscv/insn_trans/trans_rvv.c.inc | 4 ++--
23
target/riscv/gdbstub.c | 2 +-
19
6 files changed, 15 insertions(+), 12 deletions(-)
24
target/riscv/monitor.c | 4 ++--
25
8 files changed, 45 insertions(+), 34 deletions(-)
26
20
27
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
21
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
28
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
29
--- a/target/riscv/cpu.h
23
--- a/target/riscv/cpu_cfg.h
30
+++ b/target/riscv/cpu.h
24
+++ b/target/riscv/cpu_cfg.h
31
@@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, VILL, 9, 1)
25
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
32
FIELD(TB_FLAGS, HLSX, 10, 1)
26
bool ext_zhinx;
33
FIELD(TB_FLAGS, MSTATUS_HS_FS, 11, 2)
27
bool ext_zhinxmin;
34
28
bool ext_zve32f;
35
-bool riscv_cpu_is_32bit(CPURISCVState *env);
29
+ bool ext_zve32x;
36
+#ifdef TARGET_RISCV32
30
bool ext_zve64f;
37
+#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
31
bool ext_zve64d;
38
+#else
32
bool ext_zvbb;
39
+static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env)
40
+{
41
+ return env->misa_mxl;
42
+}
43
+#endif
44
45
/*
46
* A simplification for VLMAX
47
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/riscv/boot.c
50
+++ b/hw/riscv/boot.c
51
@@ -XXX,XX +XXX,XX @@
52
53
bool riscv_is_32bit(RISCVHartArrayState *harts)
54
{
55
- return riscv_cpu_is_32bit(&harts->harts[0].env);
56
+ return harts->harts[0].env.misa_mxl_max == MXL_RV32;
57
}
58
59
target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts,
60
diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/semihosting/arm-compat-semi.c
63
+++ b/semihosting/arm-compat-semi.c
64
@@ -XXX,XX +XXX,XX @@ static inline bool is_64bit_semihosting(CPUArchState *env)
65
#if defined(TARGET_ARM)
66
return is_a64(env);
67
#elif defined(TARGET_RISCV)
68
- return !riscv_cpu_is_32bit(env);
69
+ return riscv_cpu_mxl(env) != MXL_RV32;
70
#else
71
#error un-handled architecture
72
#endif
73
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
74
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
75
--- a/target/riscv/cpu.c
35
--- a/target/riscv/cpu.c
76
+++ b/target/riscv/cpu.c
36
+++ b/target/riscv/cpu.c
77
@@ -XXX,XX +XXX,XX @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async)
37
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
78
}
38
ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb),
79
}
39
ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc),
80
40
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
81
-bool riscv_cpu_is_32bit(CPURISCVState *env)
41
+ ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
82
-{
42
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
83
- return env->misa_mxl == MXL_RV32;
43
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
84
-}
44
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
85
-
45
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
86
static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext)
46
MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false),
87
{
47
MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false),
88
env->misa_mxl_max = env->misa_mxl = mxl;
48
MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false),
89
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
49
+ MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
90
#ifndef CONFIG_USER_ONLY
50
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
91
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mhartid ", env->mhartid);
51
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
92
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", (target_ulong)env->mstatus);
52
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
93
- if (riscv_cpu_is_32bit(env)) {
94
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
95
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ",
96
(target_ulong)(env->mstatus >> 32));
97
}
98
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
99
static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
100
{
101
RISCVCPU *cpu = RISCV_CPU(s);
102
- if (riscv_cpu_is_32bit(&cpu->env)) {
103
+
104
+ switch (riscv_cpu_mxl(&cpu->env)) {
105
+ case MXL_RV32:
106
info->print_insn = print_insn_riscv32;
107
- } else {
108
+ break;
109
+ case MXL_RV64:
110
info->print_insn = print_insn_riscv64;
111
+ break;
112
+ default:
113
+ g_assert_not_reached();
114
}
115
}
116
117
@@ -XXX,XX +XXX,XX @@ static gchar *riscv_gdb_arch_name(CPUState *cs)
118
RISCVCPU *cpu = RISCV_CPU(cs);
119
CPURISCVState *env = &cpu->env;
120
121
- if (riscv_cpu_is_32bit(env)) {
122
+ switch (riscv_cpu_mxl(env)) {
123
+ case MXL_RV32:
124
return g_strdup("riscv:rv32");
125
- } else {
126
+ case MXL_RV64:
127
return g_strdup("riscv:rv64");
128
+ default:
129
+ g_assert_not_reached();
130
}
131
}
132
133
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
53
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
134
index XXXXXXX..XXXXXXX 100644
54
index XXXXXXX..XXXXXXX 100644
135
--- a/target/riscv/cpu_helper.c
55
--- a/target/riscv/cpu_helper.c
136
+++ b/target/riscv/cpu_helper.c
56
+++ b/target/riscv/cpu_helper.c
137
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
57
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
138
58
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
139
void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
59
*cs_base = 0;
140
{
60
141
- uint64_t sd = riscv_cpu_is_32bit(env) ? MSTATUS32_SD : MSTATUS64_SD;
61
- if (cpu->cfg.ext_zve32f) {
142
+ uint64_t sd = riscv_cpu_mxl(env) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD;
62
+ if (cpu->cfg.ext_zve32x) {
143
uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
63
/*
144
MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
64
* If env->vl equals to VLMAX, we can use generic vector operation
145
MSTATUS64_UXL | sd;
65
* expanders (GVEC) to accerlate the vector operations.
146
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
147
148
if (first_stage == true) {
149
if (use_background) {
150
- if (riscv_cpu_is_32bit(env)) {
151
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
152
base = (hwaddr)get_field(env->vsatp, SATP32_PPN) << PGSHIFT;
153
vm = get_field(env->vsatp, SATP32_MODE);
154
} else {
155
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
156
vm = get_field(env->vsatp, SATP64_MODE);
157
}
158
} else {
159
- if (riscv_cpu_is_32bit(env)) {
160
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
161
base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT;
162
vm = get_field(env->satp, SATP32_MODE);
163
} else {
164
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
165
}
166
widened = 0;
167
} else {
168
- if (riscv_cpu_is_32bit(env)) {
169
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
170
base = (hwaddr)get_field(env->hgatp, SATP32_PPN) << PGSHIFT;
171
vm = get_field(env->hgatp, SATP32_MODE);
172
} else {
173
@@ -XXX,XX +XXX,XX @@ restart:
174
}
175
176
target_ulong pte;
177
- if (riscv_cpu_is_32bit(env)) {
178
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
179
pte = address_space_ldl(cs->as, pte_addr, attrs, &res);
180
} else {
181
pte = address_space_ldq(cs->as, pte_addr, attrs, &res);
182
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
183
int page_fault_exceptions, vm;
184
uint64_t stap_mode;
185
186
- if (riscv_cpu_is_32bit(env)) {
187
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
188
stap_mode = SATP32_MODE;
189
} else {
190
stap_mode = SATP64_MODE;
191
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
66
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
192
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
193
--- a/target/riscv/csr.c
68
--- a/target/riscv/csr.c
194
+++ b/target/riscv/csr.c
69
+++ b/target/riscv/csr.c
195
@@ -XXX,XX +XXX,XX @@ static RISCVException ctr(CPURISCVState *env, int csrno)
70
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
196
}
71
197
break;
72
static RISCVException vs(CPURISCVState *env, int csrno)
198
}
199
- if (riscv_cpu_is_32bit(env)) {
200
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
201
switch (csrno) {
202
case CSR_CYCLEH:
203
if (!get_field(env->hcounteren, COUNTEREN_CY) &&
204
@@ -XXX,XX +XXX,XX @@ static RISCVException ctr(CPURISCVState *env, int csrno)
205
206
static RISCVException ctr32(CPURISCVState *env, int csrno)
207
{
73
{
208
- if (!riscv_cpu_is_32bit(env)) {
74
- if (riscv_cpu_cfg(env)->ext_zve32f) {
209
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
75
+ if (riscv_cpu_cfg(env)->ext_zve32x) {
210
return RISCV_EXCP_ILLEGAL_INST;
76
#if !defined(CONFIG_USER_ONLY)
211
}
77
if (!env->debugger && !riscv_cpu_vector_enabled(env)) {
212
213
@@ -XXX,XX +XXX,XX @@ static RISCVException any(CPURISCVState *env, int csrno)
214
215
static RISCVException any32(CPURISCVState *env, int csrno)
216
{
217
- if (!riscv_cpu_is_32bit(env)) {
218
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
219
return RISCV_EXCP_ILLEGAL_INST;
220
}
221
222
@@ -XXX,XX +XXX,XX @@ static RISCVException hmode(CPURISCVState *env, int csrno)
223
224
static RISCVException hmode32(CPURISCVState *env, int csrno)
225
{
226
- if (!riscv_cpu_is_32bit(env)) {
227
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
228
if (riscv_cpu_virt_enabled(env)) {
229
return RISCV_EXCP_ILLEGAL_INST;
78
return RISCV_EXCP_ILLEGAL_INST;
230
} else {
79
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
231
@@ -XXX,XX +XXX,XX @@ static RISCVException read_mstatus(CPURISCVState *env, int csrno,
232
233
static int validate_vm(CPURISCVState *env, target_ulong vm)
234
{
235
- if (riscv_cpu_is_32bit(env)) {
236
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
237
return valid_vm_1_10_32[vm & 0xf];
238
} else {
239
return valid_vm_1_10_64[vm & 0xf];
240
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
241
MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR |
242
MSTATUS_TW;
243
244
- if (!riscv_cpu_is_32bit(env)) {
245
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
246
/*
247
* RV32: MPV and GVA are not in mstatus. The current plan is to
248
* add them to mstatush. For now, we just don't support it.
249
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
250
251
dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) |
252
((mstatus & MSTATUS_XS) == MSTATUS_XS);
253
- if (riscv_cpu_is_32bit(env)) {
254
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
255
mstatus = set_field(mstatus, MSTATUS32_SD, dirty);
256
} else {
257
mstatus = set_field(mstatus, MSTATUS64_SD, dirty);
258
@@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno,
259
{
260
target_ulong mask = (sstatus_v1_10_mask);
261
262
- if (riscv_cpu_is_32bit(env)) {
263
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
264
mask |= SSTATUS32_SD;
265
} else {
266
mask |= SSTATUS64_SD;
267
@@ -XXX,XX +XXX,XX @@ static RISCVException write_satp(CPURISCVState *env, int csrno,
268
return RISCV_EXCP_NONE;
269
}
270
271
- if (riscv_cpu_is_32bit(env)) {
272
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
273
vm = validate_vm(env, get_field(val, SATP32_MODE));
274
mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN);
275
asid = (val ^ env->satp) & SATP32_ASID;
276
@@ -XXX,XX +XXX,XX @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno,
277
target_ulong *val)
278
{
279
*val = env->hstatus;
280
- if (!riscv_cpu_is_32bit(env)) {
281
+ if (riscv_cpu_mxl(env) != MXL_RV32) {
282
/* We only support 64-bit VSXL */
283
*val = set_field(*val, HSTATUS_VSXL, 2);
284
}
285
@@ -XXX,XX +XXX,XX @@ static RISCVException write_hstatus(CPURISCVState *env, int csrno,
286
target_ulong val)
287
{
288
env->hstatus = val;
289
- if (!riscv_cpu_is_32bit(env) && get_field(val, HSTATUS_VSXL) != 2) {
290
+ if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) {
291
qemu_log_mask(LOG_UNIMP, "QEMU does not support mixed HSXLEN options.");
292
}
293
if (get_field(val, HSTATUS_VSBE) != 0) {
294
@@ -XXX,XX +XXX,XX @@ static RISCVException write_htimedelta(CPURISCVState *env, int csrno,
295
return RISCV_EXCP_ILLEGAL_INST;
296
}
297
298
- if (riscv_cpu_is_32bit(env)) {
299
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
300
env->htimedelta = deposit64(env->htimedelta, 0, 32, (uint64_t)val);
301
} else {
302
env->htimedelta = val;
303
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
304
index XXXXXXX..XXXXXXX 100644
80
index XXXXXXX..XXXXXXX 100644
305
--- a/target/riscv/gdbstub.c
81
--- a/target/riscv/tcg/tcg-cpu.c
306
+++ b/target/riscv/gdbstub.c
82
+++ b/target/riscv/tcg/tcg-cpu.c
307
@@ -XXX,XX +XXX,XX @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)
83
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
308
CPURISCVState *env = &cpu->env;
309
GString *s = g_string_new(NULL);
310
riscv_csr_predicate_fn predicate;
311
- int bitsize = riscv_cpu_is_32bit(env) ? 32 : 64;
312
+ int bitsize = 16 << env->misa_mxl_max;
313
int i;
314
315
g_string_printf(s, "<?xml version=\"1.0\"?>");
316
diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c
317
index XXXXXXX..XXXXXXX 100644
318
--- a/target/riscv/monitor.c
319
+++ b/target/riscv/monitor.c
320
@@ -XXX,XX +XXX,XX @@ static void mem_info_svxx(Monitor *mon, CPUArchState *env)
321
target_ulong last_size;
322
int last_attr;
323
324
- if (riscv_cpu_is_32bit(env)) {
325
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
326
base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT;
327
vm = get_field(env->satp, SATP32_MODE);
328
} else {
329
@@ -XXX,XX +XXX,XX @@ void hmp_info_mem(Monitor *mon, const QDict *qdict)
330
return;
84
return;
331
}
85
}
332
86
333
- if (riscv_cpu_is_32bit(env)) {
87
- if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) {
334
+ if (riscv_cpu_mxl(env) == MXL_RV32) {
88
- error_setg(errp, "Zve32f/Zve64f extensions require F extension");
335
if (!(env->satp & SATP32_MODE)) {
89
- return;
336
monitor_printf(mon, "No translation or protection\n");
90
+ /* The Zve32f extension depends on the Zve32x extension */
337
return;
91
+ if (cpu->cfg.ext_zve32f) {
92
+ if (!riscv_has_ext(env, RVF)) {
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);
97
}
98
99
if (cpu->cfg.ext_zvfh) {
100
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
101
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true);
102
}
103
104
- /*
105
- * In principle Zve*x would also suffice here, were they supported
106
- * in qemu
107
- */
108
if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg ||
109
cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed ||
110
- cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) {
111
+ cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) {
112
error_setg(errp,
113
"Vector crypto extensions require V or Zve* extensions");
114
return;
115
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
116
index XXXXXXX..XXXXXXX 100644
117
--- a/target/riscv/insn_trans/trans_rvv.c.inc
118
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
119
@@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
120
{
121
TCGv s1, dst;
122
123
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
124
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
125
return false;
126
}
127
128
@@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
129
{
130
TCGv dst;
131
132
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
133
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
134
return false;
135
}
136
338
--
137
--
339
2.31.1
138
2.45.1
340
341
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@wdc.com>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
Organise the CPU properties so that standard extensions come first
3
Add support for Zve64x extension. Enabling Zve64f enables Zve64x and
4
then followed by experimental extensions.
4
enabling Zve64x enables Zve32x according to their dependency.
5
5
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107
7
Signed-off-by: Jason Chien <jason.chien@sifive.com>
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Reviewed-by: Max Chou <max.chou@sifive.com>
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Message-ID: <20240328022343.6871-3-jason.chien@sifive.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
9
Message-id: b6598570f60c5ee7f402be56d837bb44b289cc4d.1634531504.git.alistair.francis@wdc.com
10
---
13
---
11
target/riscv/cpu.c | 17 ++++++++++-------
14
target/riscv/cpu_cfg.h | 1 +
12
1 file changed, 10 insertions(+), 7 deletions(-)
15
target/riscv/cpu.c | 2 ++
16
target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------
17
3 files changed, 14 insertions(+), 6 deletions(-)
13
18
19
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu_cfg.h
22
+++ b/target/riscv/cpu_cfg.h
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
24
bool ext_zve32x;
25
bool ext_zve64f;
26
bool ext_zve64d;
27
+ bool ext_zve64x;
28
bool ext_zvbb;
29
bool ext_zvbc;
30
bool ext_zvkb;
14
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
15
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu.c
33
--- a/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
18
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
35
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
19
}
36
ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
20
37
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
21
static Property riscv_cpu_properties[] = {
38
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
22
+ /* Defaults for standard extensions */
39
+ ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x),
23
DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true),
40
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
24
DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false),
41
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
25
DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, true),
42
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
26
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
43
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
27
DEFINE_PROP_BOOL("c", RISCVCPU, cfg.ext_c, true),
44
MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
28
DEFINE_PROP_BOOL("s", RISCVCPU, cfg.ext_s, true),
45
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
29
DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true),
46
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
30
- /* This is experimental so mark with 'x-' */
47
+ MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false),
31
+ DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true),
48
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
32
+ DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),
49
MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false),
33
+ DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true),
50
MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
34
+ DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
51
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
35
+ DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
52
index XXXXXXX..XXXXXXX 100644
36
+
53
--- a/target/riscv/tcg/tcg-cpu.c
37
+ DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
54
+++ b/target/riscv/tcg/tcg-cpu.c
38
+
55
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
39
+ /* These are experimental so mark with 'x-' */
56
40
DEFINE_PROP_BOOL("x-zba", RISCVCPU, cfg.ext_zba, false),
57
/* The Zve64d extension depends on the Zve64f extension */
41
DEFINE_PROP_BOOL("x-zbb", RISCVCPU, cfg.ext_zbb, false),
58
if (cpu->cfg.ext_zve64d) {
42
DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false),
59
+ if (!riscv_has_ext(env, RVD)) {
43
DEFINE_PROP_BOOL("x-zbs", RISCVCPU, cfg.ext_zbs, false),
60
+ error_setg(errp, "Zve64d/V extensions require D extension");
44
DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false),
61
+ return;
45
DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false),
62
+ }
46
- DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true),
63
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true);
47
- DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),
64
}
48
- DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true),
65
49
- DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
66
- /* The Zve64f extension depends on the Zve32f extension */
50
DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
67
+ /* The Zve64f extension depends on the Zve64x and Zve32f extensions */
51
DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
68
if (cpu->cfg.ext_zve64f) {
52
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
69
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true);
53
- DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
70
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true);
54
- DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
71
}
55
/* ePMP 0.9.3 */
72
56
DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false),
73
- if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) {
74
- error_setg(errp, "Zve64d/V extensions require D extension");
75
- return;
76
+ /* The Zve64x extension depends on the Zve32x extension */
77
+ if (cpu->cfg.ext_zve64x) {
78
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
79
}
80
81
/* The Zve32f extension depends on the Zve32x extension */
82
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
83
return;
84
}
85
86
- if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) {
87
+ if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) {
88
error_setg(
89
errp,
90
- "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions");
91
+ "Zvbc and Zvknhb extensions require V or Zve64x extensions");
92
return;
93
}
57
94
58
--
95
--
59
2.31.1
96
2.45.1
60
61
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: Jason Chien <jason.chien@sifive.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
In current implementation, the gdbstub allows reading vector registers
4
and can't work as expected with '-numa node,memdev' options.
4
only if V extension is supported. However, all vector extensions and
5
vector crypto extensions have the vector registers and they all depend
6
on Zve32x. The gdbstub should check for Zve32x instead.
5
7
6
Use MachineState::ram instead of manually initializing RAM memory
8
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
region, as well as by providing MachineClass::default_ram_id to
9
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
opt in to memdev scheme.
10
Reviewed-by: Max Chou <max.chou@sifive.com>
9
11
Message-ID: <20240328022343.6871-4-jason.chien@sifive.com>
10
While at it add check for user supplied RAM size and error out if it
11
mismatches board expected value.
12
13
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
17
Message-id: 20211020014112.7336-3-bmeng.cn@gmail.com
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
13
---
20
hw/riscv/opentitan.c | 16 ++++++++++++----
14
target/riscv/gdbstub.c | 2 +-
21
1 file changed, 12 insertions(+), 4 deletions(-)
15
1 file changed, 1 insertion(+), 1 deletion(-)
22
16
23
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
24
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
25
--- a/hw/riscv/opentitan.c
19
--- a/target/riscv/gdbstub.c
26
+++ b/hw/riscv/opentitan.c
20
+++ b/target/riscv/gdbstub.c
27
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
28
*/
22
gdb_find_static_feature("riscv-32bit-fpu.xml"),
29
23
0);
30
#include "qemu/osdep.h"
24
}
31
+#include "qemu/cutils.h"
25
- if (env->misa_ext & RVV) {
32
#include "hw/riscv/opentitan.h"
26
+ if (cpu->cfg.ext_zve32x) {
33
#include "qapi/error.h"
27
gdb_register_coprocessor(cs, riscv_gdb_get_vector,
34
#include "hw/boards.h"
28
riscv_gdb_set_vector,
35
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry ibex_memmap[] = {
29
ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs),
36
37
static void opentitan_board_init(MachineState *machine)
38
{
39
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
40
const MemMapEntry *memmap = ibex_memmap;
41
OpenTitanState *s = g_new0(OpenTitanState, 1);
42
MemoryRegion *sys_mem = get_system_memory();
43
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
44
+
45
+ if (machine->ram_size != mc->default_ram_size) {
46
+ char *sz = size_to_str(mc->default_ram_size);
47
+ error_report("Invalid RAM size, should be %s", sz);
48
+ g_free(sz);
49
+ exit(EXIT_FAILURE);
50
+ }
51
52
/* Initialize SoC */
53
object_initialize_child(OBJECT(machine), "soc", &s->soc,
54
TYPE_RISCV_IBEX_SOC);
55
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
56
57
- memory_region_init_ram(main_mem, NULL, "riscv.lowrisc.ibex.ram",
58
- memmap[IBEX_DEV_RAM].size, &error_fatal);
59
memory_region_add_subregion(sys_mem,
60
- memmap[IBEX_DEV_RAM].base, main_mem);
61
+ memmap[IBEX_DEV_RAM].base, machine->ram);
62
63
if (machine->firmware) {
64
riscv_load_firmware(machine->firmware, memmap[IBEX_DEV_RAM].base, NULL);
65
@@ -XXX,XX +XXX,XX @@ static void opentitan_machine_init(MachineClass *mc)
66
mc->init = opentitan_board_init;
67
mc->max_cpus = 1;
68
mc->default_cpu_type = TYPE_RISCV_CPU_IBEX;
69
+ mc->default_ram_id = "riscv.lowrisc.ibex.ram";
70
+ mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
71
}
72
73
DEFINE_MACHINE("opentitan", opentitan_machine_init)
74
--
30
--
75
2.31.1
31
2.45.1
76
77
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
2
3
In preparation for RV128, replace a simple predicate
3
In RVV and vcrypto instructions, the masked and tail elements are set to 1s
4
with a more versatile test.
4
using vext_set_elems_1s function if the vma/vta bit is set. It is the element
5
agnostic policy.
5
6
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
7
However, this function can't deal the big endian situation. This patch fixes
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
the problem by adding handling of such case.
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
9
Message-id: 20211020031709.359469-9-richard.henderson@linaro.org
10
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
11
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
16
---
12
target/riscv/translate.c | 31 +++++++++++++++++--------------
17
target/riscv/vector_internals.c | 22 ++++++++++++++++++++++
13
1 file changed, 17 insertions(+), 14 deletions(-)
18
1 file changed, 22 insertions(+)
14
19
15
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
20
diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/translate.c
22
--- a/target/riscv/vector_internals.c
18
+++ b/target/riscv/translate.c
23
+++ b/target/riscv/vector_internals.c
19
@@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
24
@@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
25
if (tot - cnt == 0) {
26
return ;
27
}
28
+
29
+ if (HOST_BIG_ENDIAN) {
30
+ /*
31
+ * Deal the situation when the elements are insdie
32
+ * only one uint64 block including setting the
33
+ * masked-off element.
34
+ */
35
+ if (((tot - 1) ^ cnt) < 8) {
36
+ memset(base + H1(tot - 1), -1, tot - cnt);
37
+ return;
38
+ }
39
+ /*
40
+ * Otherwise, at least cross two uint64_t blocks.
41
+ * Set first unaligned block.
42
+ */
43
+ if (cnt % 8 != 0) {
44
+ uint32_t j = ROUND_UP(cnt, 8);
45
+ memset(base + H1(j - 1), -1, j - cnt);
46
+ cnt = j;
47
+ }
48
+ /* Set other 64bit aligend blocks */
49
+ }
50
memset(base + cnt, -1, tot - cnt);
20
}
51
}
21
52
22
#ifdef TARGET_RISCV32
23
-# define is_32bit(ctx) true
24
+#define get_xl(ctx) MXL_RV32
25
#elif defined(CONFIG_USER_ONLY)
26
-# define is_32bit(ctx) false
27
+#define get_xl(ctx) MXL_RV64
28
#else
29
-static inline bool is_32bit(DisasContext *ctx)
30
+#define get_xl(ctx) ((ctx)->xl)
31
+#endif
32
+
33
+/* The word size for this machine mode. */
34
+static inline int __attribute__((unused)) get_xlen(DisasContext *ctx)
35
{
36
- return ctx->xl == MXL_RV32;
37
+ return 16 << get_xl(ctx);
38
}
39
-#endif
40
41
/* The word size for this operation. */
42
static inline int oper_len(DisasContext *ctx)
43
@@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
44
static void mark_fs_dirty(DisasContext *ctx)
45
{
46
TCGv tmp;
47
- target_ulong sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD;
48
+ target_ulong sd = get_xl(ctx) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD;
49
50
if (ctx->mstatus_fs != MSTATUS_FS) {
51
/* Remember the state change for the rest of the TB. */
52
@@ -XXX,XX +XXX,XX @@ EX_SH(12)
53
} \
54
} while (0)
55
56
-#define REQUIRE_32BIT(ctx) do { \
57
- if (!is_32bit(ctx)) { \
58
- return false; \
59
- } \
60
+#define REQUIRE_32BIT(ctx) do { \
61
+ if (get_xl(ctx) != MXL_RV32) { \
62
+ return false; \
63
+ } \
64
} while (0)
65
66
-#define REQUIRE_64BIT(ctx) do { \
67
- if (is_32bit(ctx)) { \
68
- return false; \
69
- } \
70
+#define REQUIRE_64BIT(ctx) do { \
71
+ if (get_xl(ctx) < MXL_RV64) { \
72
+ return false; \
73
+ } \
74
} while (0)
75
76
static int ex_rvc_register(DisasContext *ctx, int reg)
77
--
53
--
78
2.31.1
54
2.45.1
79
80
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Yangyu Chen <cyy@cyyself.name>
2
2
3
Use the official debug read interface to the csrs,
3
This code has a typo that writes zvkb to zvkg, causing users can't
4
rather than referencing the env slots directly.
4
enable zvkb through the config. This patch gets this fixed.
5
Put the list of csrs to dump into a table.
6
5
6
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
7
Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions")
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
9
Message-id: 20211020031709.359469-15-richard.henderson@linaro.org
11
Reviewed-by:  Weiwei Li <liwei1518@gmail.com>
12
Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
15
---
12
target/riscv/cpu.c | 89 +++++++++++++++++++++++-----------------------
16
target/riscv/cpu.c | 2 +-
13
1 file changed, 45 insertions(+), 44 deletions(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
14
18
15
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
16
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
21
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
23
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
20
#endif
24
/* Vector cryptography extensions */
21
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc ", env->pc);
25
MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
22
#ifndef CONFIG_USER_ONLY
26
MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false),
23
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mhartid ", env->mhartid);
27
- MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false),
24
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", (target_ulong)env->mstatus);
28
+ MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false),
25
- if (riscv_cpu_mxl(env) == MXL_RV32) {
29
MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false),
26
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ",
30
MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false),
27
- (target_ulong)(env->mstatus >> 32));
31
MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false),
28
- }
29
- if (riscv_has_ext(env, RVH)) {
30
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hstatus ", env->hstatus);
31
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus",
32
- (target_ulong)env->vsstatus);
33
- }
34
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip ", env->mip);
35
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mie ", env->mie);
36
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mideleg ", env->mideleg);
37
- if (riscv_has_ext(env, RVH)) {
38
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hideleg ", env->hideleg);
39
- }
40
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "medeleg ", env->medeleg);
41
- if (riscv_has_ext(env, RVH)) {
42
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hedeleg ", env->hedeleg);
43
- }
44
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtvec ", env->mtvec);
45
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stvec ", env->stvec);
46
- if (riscv_has_ext(env, RVH)) {
47
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vstvec ", env->vstvec);
48
- }
49
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mepc ", env->mepc);
50
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sepc ", env->sepc);
51
- if (riscv_has_ext(env, RVH)) {
52
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsepc ", env->vsepc);
53
- }
54
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mcause ", env->mcause);
55
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "scause ", env->scause);
56
- if (riscv_has_ext(env, RVH)) {
57
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause);
58
- }
59
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval);
60
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval);
61
- if (riscv_has_ext(env, RVH)) {
62
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
63
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
64
+ {
65
+ static const int dump_csrs[] = {
66
+ CSR_MHARTID,
67
+ CSR_MSTATUS,
68
+ CSR_MSTATUSH,
69
+ CSR_HSTATUS,
70
+ CSR_VSSTATUS,
71
+ CSR_MIP,
72
+ CSR_MIE,
73
+ CSR_MIDELEG,
74
+ CSR_HIDELEG,
75
+ CSR_MEDELEG,
76
+ CSR_HEDELEG,
77
+ CSR_MTVEC,
78
+ CSR_STVEC,
79
+ CSR_VSTVEC,
80
+ CSR_MEPC,
81
+ CSR_SEPC,
82
+ CSR_VSEPC,
83
+ CSR_MCAUSE,
84
+ CSR_SCAUSE,
85
+ CSR_VSCAUSE,
86
+ CSR_MTVAL,
87
+ CSR_STVAL,
88
+ CSR_HTVAL,
89
+ CSR_MTVAL2,
90
+ CSR_MSCRATCH,
91
+ CSR_SSCRATCH,
92
+ CSR_SATP,
93
+ };
94
+
95
+ for (int i = 0; i < ARRAY_SIZE(dump_csrs); ++i) {
96
+ int csrno = dump_csrs[i];
97
+ target_ulong val = 0;
98
+ RISCVException res = riscv_csrrw_debug(env, csrno, &val, 0, 0);
99
+
100
+ /*
101
+ * Rely on the smode, hmode, etc, predicates within csr.c
102
+ * to do the filtering of the registers that are present.
103
+ */
104
+ if (res == RISCV_EXCP_NONE) {
105
+ qemu_fprintf(f, " %-8s " TARGET_FMT_lx "\n",
106
+ csr_ops[csrno].name, val);
107
+ }
108
+ }
109
}
110
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mscratch", env->mscratch);
111
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sscratch", env->sscratch);
112
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "satp ", env->satp);
113
#endif
114
115
for (i = 0; i < 32; i++) {
116
--
32
--
117
2.31.1
33
2.45.1
118
34
119
35
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Huang Tao <eric.huang@linux.alibaba.com>
2
2
3
The hw representation of misa.mxl is at the high bits of the
3
In this patch, we modify the decoder to be a freely composable data
4
misa csr. Representing this in the same way inside QEMU
4
structure instead of a hardcoded one. It can be dynamically builded up
5
results in overly complex code trying to check that field.
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
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
21
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
22
Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu>
23
Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
26
Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com>
10
Message-id: 20211020031709.359469-4-richard.henderson@linaro.org
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 | 15 +++----
29
target/riscv/cpu.h | 1 +
14
linux-user/elfload.c | 2 +-
30
target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++
15
linux-user/riscv/cpu_loop.c | 2 +-
31
target/riscv/cpu.c | 1 +
16
target/riscv/cpu.c | 78 +++++++++++++++++++++----------------
32
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
17
target/riscv/csr.c | 44 ++++++++++++++-------
33
target/riscv/translate.c | 31 +++++++++++++++----------------
18
target/riscv/gdbstub.c | 8 ++--
34
5 files changed, 47 insertions(+), 16 deletions(-)
19
target/riscv/machine.c | 10 +++--
20
target/riscv/translate.c | 10 +++--
21
8 files changed, 100 insertions(+), 69 deletions(-)
22
35
23
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
24
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
25
--- a/target/riscv/cpu.h
38
--- a/target/riscv/cpu.h
26
+++ b/target/riscv/cpu.h
39
+++ b/target/riscv/cpu.h
27
@@ -XXX,XX +XXX,XX @@
40
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
28
#include "exec/cpu-defs.h"
41
uint32_t pmu_avail_ctrs;
29
#include "fpu/softfloat-types.h"
42
/* Mapping of events to counters */
30
#include "qom/object.h"
43
GHashTable *pmu_event_ctr_map;
31
+#include "cpu_bits.h"
44
+ const GPtrArray *decoders;
32
45
};
33
#define TCG_GUEST_DEFAULT_MO 0
46
34
47
/**
35
@@ -XXX,XX +XXX,XX @@
48
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
36
# define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE64
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
+
37
#endif
71
#endif
38
39
-#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))
40
-#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
41
-
42
#define RV(x) ((target_ulong)1 << (x - 'A'))
43
44
#define RVI RV('I')
45
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
46
target_ulong priv_ver;
47
target_ulong bext_ver;
48
target_ulong vext_ver;
49
- target_ulong misa;
50
- target_ulong misa_mask;
51
+
52
+ /* RISCVMXL, but uint32_t for vmstate migration */
53
+ uint32_t misa_mxl; /* current mxl */
54
+ uint32_t misa_mxl_max; /* max mxl for this cpu */
55
+ uint32_t misa_ext; /* current extensions */
56
+ uint32_t misa_ext_mask; /* max ext for this cpu */
57
58
uint32_t features;
59
60
@@ -XXX,XX +XXX,XX @@ struct RISCVCPU {
61
62
static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext)
63
{
64
- return (env->misa & ext) != 0;
65
+ return (env->misa_ext & ext) != 0;
66
}
67
68
static inline bool riscv_feature(CPURISCVState *env, int feature)
69
@@ -XXX,XX +XXX,XX @@ static inline bool riscv_feature(CPURISCVState *env, int feature)
70
}
71
72
#include "cpu_user.h"
73
-#include "cpu_bits.h"
74
75
extern const char * const riscv_int_regnames[];
76
extern const char * const riscv_fpr_regnames[];
77
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/linux-user/elfload.c
80
+++ b/linux-user/elfload.c
81
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
82
uint32_t mask = MISA_BIT('I') | MISA_BIT('M') | MISA_BIT('A')
83
| MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C');
84
85
- return cpu->env.misa & mask;
86
+ return cpu->env.misa_ext & mask;
87
#undef MISA_BIT
88
}
89
90
diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c
91
index XXXXXXX..XXXXXXX 100644
92
--- a/linux-user/riscv/cpu_loop.c
93
+++ b/linux-user/riscv/cpu_loop.c
94
@@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
95
env->gpr[xSP] = regs->sp;
96
env->elf_flags = info->elf_flags;
97
98
- if ((env->misa & RVE) && !(env->elf_flags & EF_RISCV_RVE)) {
99
+ if ((env->misa_ext & RVE) && !(env->elf_flags & EF_RISCV_RVE)) {
100
error_report("Incompatible ELF: RVE cpu requires RVE ABI binary");
101
exit(EXIT_FAILURE);
102
}
103
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
72
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
104
index XXXXXXX..XXXXXXX 100644
73
index XXXXXXX..XXXXXXX 100644
105
--- a/target/riscv/cpu.c
74
--- a/target/riscv/cpu.c
106
+++ b/target/riscv/cpu.c
75
+++ b/target/riscv/cpu.c
107
@@ -XXX,XX +XXX,XX @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async)
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
108
77
error_propagate(errp, local_err);
109
bool riscv_cpu_is_32bit(CPURISCVState *env)
78
return;
110
{
79
}
111
- if (env->misa & RV64) {
80
+ riscv_tcg_cpu_finalize_dynamic_decoder(cpu);
112
- return false;
81
} else if (kvm_enabled()) {
113
- }
82
riscv_kvm_cpu_finalize_features(cpu, &local_err);
114
-
83
if (local_err != NULL) {
115
- return true;
84
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
116
+ return env->misa_mxl == MXL_RV32;
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/tcg/tcg-cpu.c
87
+++ b/target/riscv/tcg/tcg-cpu.c
88
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
89
}
117
}
90
}
118
91
119
-static void set_misa(CPURISCVState *env, target_ulong misa)
92
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
120
+static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext)
93
+{
121
{
94
+ GPtrArray *dynamic_decoders;
122
- env->misa_mask = env->misa = misa;
95
+ dynamic_decoders = g_ptr_array_sized_new(decoder_table_size);
123
+ env->misa_mxl_max = env->misa_mxl = mxl;
96
+ for (size_t i = 0; i < decoder_table_size; ++i) {
124
+ env->misa_ext_mask = env->misa_ext = ext;
97
+ if (decoder_table[i].guard_func &&
125
}
98
+ decoder_table[i].guard_func(&cpu->cfg)) {
126
99
+ g_ptr_array_add(dynamic_decoders,
127
static void set_priv_version(CPURISCVState *env, int priv_ver)
100
+ (gpointer)decoder_table[i].riscv_cpu_decode_fn);
128
@@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj)
101
+ }
129
{
130
CPURISCVState *env = &RISCV_CPU(obj)->env;
131
#if defined(TARGET_RISCV32)
132
- set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
133
+ set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
134
#elif defined(TARGET_RISCV64)
135
- set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
136
+ set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
137
#endif
138
set_priv_version(env, PRIV_VERSION_1_11_0);
139
}
140
@@ -XXX,XX +XXX,XX @@ static void rv64_base_cpu_init(Object *obj)
141
{
142
CPURISCVState *env = &RISCV_CPU(obj)->env;
143
/* We set this in the realise function */
144
- set_misa(env, RV64);
145
+ set_misa(env, MXL_RV64, 0);
146
}
147
148
static void rv64_sifive_u_cpu_init(Object *obj)
149
{
150
CPURISCVState *env = &RISCV_CPU(obj)->env;
151
- set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
152
+ set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
153
set_priv_version(env, PRIV_VERSION_1_10_0);
154
}
155
156
static void rv64_sifive_e_cpu_init(Object *obj)
157
{
158
CPURISCVState *env = &RISCV_CPU(obj)->env;
159
- set_misa(env, RV64 | RVI | RVM | RVA | RVC | RVU);
160
+ set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
161
set_priv_version(env, PRIV_VERSION_1_10_0);
162
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
163
}
164
@@ -XXX,XX +XXX,XX @@ static void rv32_base_cpu_init(Object *obj)
165
{
166
CPURISCVState *env = &RISCV_CPU(obj)->env;
167
/* We set this in the realise function */
168
- set_misa(env, RV32);
169
+ set_misa(env, MXL_RV32, 0);
170
}
171
172
static void rv32_sifive_u_cpu_init(Object *obj)
173
{
174
CPURISCVState *env = &RISCV_CPU(obj)->env;
175
- set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
176
+ set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
177
set_priv_version(env, PRIV_VERSION_1_10_0);
178
}
179
180
static void rv32_sifive_e_cpu_init(Object *obj)
181
{
182
CPURISCVState *env = &RISCV_CPU(obj)->env;
183
- set_misa(env, RV32 | RVI | RVM | RVA | RVC | RVU);
184
+ set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
185
set_priv_version(env, PRIV_VERSION_1_10_0);
186
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
187
}
188
@@ -XXX,XX +XXX,XX @@ static void rv32_sifive_e_cpu_init(Object *obj)
189
static void rv32_ibex_cpu_init(Object *obj)
190
{
191
CPURISCVState *env = &RISCV_CPU(obj)->env;
192
- set_misa(env, RV32 | RVI | RVM | RVC | RVU);
193
+ set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU);
194
set_priv_version(env, PRIV_VERSION_1_10_0);
195
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
196
qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
197
@@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj)
198
static void rv32_imafcu_nommu_cpu_init(Object *obj)
199
{
200
CPURISCVState *env = &RISCV_CPU(obj)->env;
201
- set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU);
202
+ set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU);
203
set_priv_version(env, PRIV_VERSION_1_10_0);
204
set_resetvec(env, DEFAULT_RSTVEC);
205
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
206
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
207
208
mcc->parent_reset(dev);
209
#ifndef CONFIG_USER_ONLY
210
+ env->misa_mxl = env->misa_mxl_max;
211
env->priv = PRV_M;
212
env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV);
213
env->mcause = 0;
214
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
215
CPURISCVState *env = &cpu->env;
216
RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
217
int priv_version = 0;
218
- target_ulong target_misa = env->misa;
219
Error *local_err = NULL;
220
221
cpu_exec_realizefn(cs, &local_err);
222
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
223
224
set_resetvec(env, cpu->cfg.resetvec);
225
226
- /* If only XLEN is set for misa, then set misa from properties */
227
- if (env->misa == RV32 || env->misa == RV64) {
228
+ /* Validate that MISA_MXL is set properly. */
229
+ switch (env->misa_mxl_max) {
230
+#ifdef TARGET_RISCV64
231
+ case MXL_RV64:
232
+ break;
233
+#endif
234
+ case MXL_RV32:
235
+ break;
236
+ default:
237
+ g_assert_not_reached();
238
+ }
239
+ assert(env->misa_mxl_max == env->misa_mxl);
240
+
241
+ /* If only MISA_EXT is unset for misa, then set it from properties */
242
+ if (env->misa_ext == 0) {
243
+ uint32_t ext = 0;
244
+
245
/* Do some ISA extension error checking */
246
if (cpu->cfg.ext_i && cpu->cfg.ext_e) {
247
error_setg(errp,
248
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
249
250
/* Set the ISA extensions, checks should have happened above */
251
if (cpu->cfg.ext_i) {
252
- target_misa |= RVI;
253
+ ext |= RVI;
254
}
255
if (cpu->cfg.ext_e) {
256
- target_misa |= RVE;
257
+ ext |= RVE;
258
}
259
if (cpu->cfg.ext_m) {
260
- target_misa |= RVM;
261
+ ext |= RVM;
262
}
263
if (cpu->cfg.ext_a) {
264
- target_misa |= RVA;
265
+ ext |= RVA;
266
}
267
if (cpu->cfg.ext_f) {
268
- target_misa |= RVF;
269
+ ext |= RVF;
270
}
271
if (cpu->cfg.ext_d) {
272
- target_misa |= RVD;
273
+ ext |= RVD;
274
}
275
if (cpu->cfg.ext_c) {
276
- target_misa |= RVC;
277
+ ext |= RVC;
278
}
279
if (cpu->cfg.ext_s) {
280
- target_misa |= RVS;
281
+ ext |= RVS;
282
}
283
if (cpu->cfg.ext_u) {
284
- target_misa |= RVU;
285
+ ext |= RVU;
286
}
287
if (cpu->cfg.ext_h) {
288
- target_misa |= RVH;
289
+ ext |= RVH;
290
}
291
if (cpu->cfg.ext_v) {
292
int vext_version = VEXT_VERSION_0_07_1;
293
- target_misa |= RVV;
294
+ ext |= RVV;
295
if (!is_power_of_2(cpu->cfg.vlen)) {
296
error_setg(errp,
297
"Vector extension VLEN must be power of 2");
298
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
299
set_vext_version(env, vext_version);
300
}
301
302
- set_misa(env, target_misa);
303
+ set_misa(env, env->misa_mxl, ext);
304
}
305
306
riscv_cpu_register_gdb_regs_for_features(cs);
307
@@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu)
308
char *isa_str = g_new(char, maxlen);
309
char *p = isa_str + snprintf(isa_str, maxlen, "rv%d", TARGET_LONG_BITS);
310
for (i = 0; i < sizeof(riscv_exts); i++) {
311
- if (cpu->env.misa & RV(riscv_exts[i])) {
312
+ if (cpu->env.misa_ext & RV(riscv_exts[i])) {
313
*p++ = qemu_tolower(riscv_exts[i]);
314
}
315
}
316
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
317
index XXXXXXX..XXXXXXX 100644
318
--- a/target/riscv/csr.c
319
+++ b/target/riscv/csr.c
320
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
321
{
322
#if !defined(CONFIG_USER_ONLY)
323
/* loose check condition for fcsr in vector extension */
324
- if ((csrno == CSR_FCSR) && (env->misa & RVV)) {
325
+ if ((csrno == CSR_FCSR) && (env->misa_ext & RVV)) {
326
return RISCV_EXCP_NONE;
327
}
328
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
329
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
330
331
static RISCVException vs(CPURISCVState *env, int csrno)
332
{
333
- if (env->misa & RVV) {
334
+ if (env->misa_ext & RVV) {
335
return RISCV_EXCP_NONE;
336
}
337
return RISCV_EXCP_ILLEGAL_INST;
338
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno,
339
static RISCVException read_misa(CPURISCVState *env, int csrno,
340
target_ulong *val)
341
{
342
- *val = env->misa;
343
+ target_ulong misa;
344
+
345
+ switch (env->misa_mxl) {
346
+ case MXL_RV32:
347
+ misa = (target_ulong)MXL_RV32 << 30;
348
+ break;
349
+#ifdef TARGET_RISCV64
350
+ case MXL_RV64:
351
+ misa = (target_ulong)MXL_RV64 << 62;
352
+ break;
353
+#endif
354
+ default:
355
+ g_assert_not_reached();
356
+ }
102
+ }
357
+
103
+
358
+ *val = misa | env->misa_ext;
104
+ cpu->decoders = dynamic_decoders;
359
return RISCV_EXCP_NONE;
105
+}
360
}
361
362
@@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno,
363
return RISCV_EXCP_NONE;
364
}
365
366
+ /*
367
+ * misa.MXL writes are not supported by QEMU.
368
+ * Drop writes to those bits.
369
+ */
370
+
106
+
371
/* Mask extensions that are not supported by this hart */
107
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu)
372
- val &= env->misa_mask;
373
+ val &= env->misa_ext_mask;
374
375
/* Mask extensions that are not supported by QEMU */
376
val &= (RVI | RVE | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
377
@@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno,
378
val &= ~RVC;
379
}
380
381
- /* misa.MXL writes are not supported by QEMU */
382
- if (riscv_cpu_is_32bit(env)) {
383
- val = (env->misa & MISA32_MXL) | (val & ~MISA32_MXL);
384
- } else {
385
- val = (env->misa & MISA64_MXL) | (val & ~MISA64_MXL);
386
+ /* If nothing changed, do nothing. */
387
+ if (val == env->misa_ext) {
388
+ return RISCV_EXCP_NONE;
389
}
390
391
/* flush translation cache */
392
- if (val != env->misa) {
393
- tb_flush(env_cpu(env));
394
- }
395
-
396
- env->misa = val;
397
-
398
+ tb_flush(env_cpu(env));
399
+ env->misa_ext = val;
400
return RISCV_EXCP_NONE;
401
}
402
403
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
404
index XXXXXXX..XXXXXXX 100644
405
--- a/target/riscv/gdbstub.c
406
+++ b/target/riscv/gdbstub.c
407
@@ -XXX,XX +XXX,XX @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
408
static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n)
409
{
108
{
410
if (n < 32) {
109
return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL;
411
- if (env->misa & RVD) {
412
+ if (env->misa_ext & RVD) {
413
return gdb_get_reg64(buf, env->fpr[n]);
414
}
415
- if (env->misa & RVF) {
416
+ if (env->misa_ext & RVF) {
417
return gdb_get_reg32(buf, env->fpr[n]);
418
}
419
/* there is hole between ft11 and fflags in fpu.xml */
420
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
421
{
422
RISCVCPU *cpu = RISCV_CPU(cs);
423
CPURISCVState *env = &cpu->env;
424
- if (env->misa & RVD) {
425
+ if (env->misa_ext & RVD) {
426
gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu,
427
36, "riscv-64bit-fpu.xml", 0);
428
- } else if (env->misa & RVF) {
429
+ } else if (env->misa_ext & RVF) {
430
gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu,
431
36, "riscv-32bit-fpu.xml", 0);
432
}
433
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
434
index XXXXXXX..XXXXXXX 100644
435
--- a/target/riscv/machine.c
436
+++ b/target/riscv/machine.c
437
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_hyper = {
438
439
const VMStateDescription vmstate_riscv_cpu = {
440
.name = "cpu",
441
- .version_id = 2,
442
- .minimum_version_id = 2,
443
+ .version_id = 3,
444
+ .minimum_version_id = 3,
445
.fields = (VMStateField[]) {
446
VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32),
447
VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32),
448
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
449
VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU),
450
VMSTATE_UINTTL(env.priv_ver, RISCVCPU),
451
VMSTATE_UINTTL(env.vext_ver, RISCVCPU),
452
- VMSTATE_UINTTL(env.misa, RISCVCPU),
453
- VMSTATE_UINTTL(env.misa_mask, RISCVCPU),
454
+ VMSTATE_UINT32(env.misa_mxl, RISCVCPU),
455
+ VMSTATE_UINT32(env.misa_ext, RISCVCPU),
456
+ VMSTATE_UINT32(env.misa_mxl_max, RISCVCPU),
457
+ VMSTATE_UINT32(env.misa_ext_mask, RISCVCPU),
458
VMSTATE_UINT32(env.features, RISCVCPU),
459
VMSTATE_UINTTL(env.priv, RISCVCPU),
460
VMSTATE_UINTTL(env.virt, RISCVCPU),
461
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
462
index XXXXXXX..XXXXXXX 100644
111
index XXXXXXX..XXXXXXX 100644
463
--- a/target/riscv/translate.c
112
--- a/target/riscv/translate.c
464
+++ 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 */
465
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
123
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
466
/* pc_succ_insn points to the instruction following base.pc_next */
124
/* FRM is known to contain a valid value. */
467
target_ulong pc_succ_insn;
125
bool frm_valid;
468
target_ulong priv_ver;
126
bool insn_start_updated;
469
- target_ulong misa;
127
+ const GPtrArray *decoders;
470
+ RISCVMXL xl;
128
} DisasContext;
471
+ uint32_t misa_ext;
472
uint32_t opcode;
473
uint32_t mstatus_fs;
474
uint32_t mstatus_hs_fs;
475
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
476
129
477
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
130
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
131
@@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word)
132
return (first_word & 3) == 3 ? 4 : 2;
133
}
134
135
+const RISCVDecoder decoder_table[] = {
136
+ { always_true_p, decode_insn32 },
137
+ { has_xthead_p, decode_xthead},
138
+ { has_XVentanaCondOps_p, decode_XVentanaCodeOps},
139
+};
140
+
141
+const size_t decoder_table_size = ARRAY_SIZE(decoder_table);
142
+
143
static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
478
{
144
{
479
- return ctx->misa & ext;
145
- /*
480
+ return ctx->misa_ext & ext;
146
- * A table with predicate (i.e., guard) functions and decoder functions
147
- * that are tested in-order until a decoder matches onto the opcode.
148
- */
149
- static const struct {
150
- bool (*guard_func)(const RISCVCPUConfig *);
151
- bool (*decode_func)(DisasContext *, uint32_t);
152
- } decoders[] = {
153
- { always_true_p, decode_insn32 },
154
- { has_xthead_p, decode_xthead },
155
- { has_XVentanaCondOps_p, decode_XVentanaCodeOps },
156
- };
157
-
158
ctx->virt_inst_excp = false;
159
ctx->cur_insn_len = insn_len(opcode);
160
/* Check for compressed insn */
161
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
162
ctx->base.pc_next + 2));
163
ctx->opcode = opcode32;
164
165
- for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) {
166
- if (decoders[i].guard_func(ctx->cfg_ptr) &&
167
- decoders[i].decode_func(ctx, opcode32)) {
168
+ for (guint i = 0; i < ctx->decoders->len; ++i) {
169
+ riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i);
170
+ if (func(ctx, opcode32)) {
171
return;
172
}
173
}
174
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
175
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
176
ctx->zero = tcg_constant_tl(0);
177
ctx->virt_inst_excp = false;
178
+ ctx->decoders = cpu->decoders;
481
}
179
}
482
180
483
#ifdef TARGET_RISCV32
181
static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
484
@@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
485
#else
486
static inline bool is_32bit(DisasContext *ctx)
487
{
488
- return (ctx->misa & RV32) == RV32;
489
+ return ctx->xl == MXL_RV32;
490
}
491
#endif
492
493
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
494
#else
495
ctx->virt_enabled = false;
496
#endif
497
- ctx->misa = env->misa;
498
+ ctx->xl = env->misa_mxl;
499
+ ctx->misa_ext = env->misa_ext;
500
ctx->frm = -1; /* unknown rounding mode */
501
ctx->ext_ifencei = cpu->cfg.ext_ifencei;
502
ctx->vlen = cpu->cfg.vlen;
503
--
182
--
504
2.31.1
183
2.45.1
505
506
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
2
2
3
Begin adding support for switching XLEN at runtime. Extract the
3
The th.sxstatus CSR can be used to identify available custom extension
4
effective XLEN from MISA and MSTATUS and store for use during translation.
4
on T-Head CPUs. The CSR is documented here:
5
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc
5
6
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
7
An important property of this patch is, that the th.sxstatus MAEE field
8
is not set (indicating that XTheadMae is not available).
9
XTheadMae is a memory attribute extension (similar to Svpbmt) which is
10
implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits
11
in PTEs that are marked as reserved. QEMU maintainers prefer to not
12
implement XTheadMae, so we need give kernels a mechanism to identify
13
if XTheadMae is available in a system or not. And this patch introduces
14
this mechanism in QEMU in a way that's compatible with real HW
15
(i.e., probing the th.sxstatus.MAEE bit).
16
17
Further context can be found on the list:
18
https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html
19
20
Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
22
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
9
Message-id: 20211020031709.359469-6-richard.henderson@linaro.org
23
Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
25
---
12
target/riscv/cpu.h | 2 ++
26
MAINTAINERS | 1 +
13
target/riscv/cpu.c | 8 ++++++++
27
target/riscv/cpu.h | 3 ++
14
target/riscv/cpu_helper.c | 33 +++++++++++++++++++++++++++++++++
28
target/riscv/cpu.c | 1 +
15
target/riscv/csr.c | 3 +++
29
target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++
16
target/riscv/translate.c | 2 +-
30
target/riscv/meson.build | 1 +
17
5 files changed, 47 insertions(+), 1 deletion(-)
31
5 files changed, 85 insertions(+)
32
create mode 100644 target/riscv/th_csr.c
18
33
34
diff --git a/MAINTAINERS b/MAINTAINERS
35
index XXXXXXX..XXXXXXX 100644
36
--- a/MAINTAINERS
37
+++ b/MAINTAINERS
38
@@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org
39
S: Supported
40
F: target/riscv/insn_trans/trans_xthead.c.inc
41
F: target/riscv/xthead*.decode
42
+F: target/riscv/th_*
43
F: disas/riscv-xthead*
44
45
RISC-V XVentanaCondOps extension
19
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
46
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.h
48
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu.h
49
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, VILL, 9, 1)
50
@@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value,
24
/* Is a Hypervisor instruction load/store allowed? */
51
uint8_t satp_mode_max_from_map(uint32_t map);
25
FIELD(TB_FLAGS, HLSX, 10, 1)
52
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
26
FIELD(TB_FLAGS, MSTATUS_HS_FS, 11, 2)
53
27
+/* The combination of MXL/SXL/UXL that applies to the current cpu mode. */
54
+/* Implemented in th_csr.c */
28
+FIELD(TB_FLAGS, XL, 13, 2)
55
+void th_register_custom_csrs(RISCVCPU *cpu);
29
56
+
30
#ifdef TARGET_RISCV32
57
#endif /* RISCV_CPU_H */
31
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
32
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
58
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
33
index XXXXXXX..XXXXXXX 100644
59
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/cpu.c
60
--- a/target/riscv/cpu.c
35
+++ b/target/riscv/cpu.c
61
+++ b/target/riscv/cpu.c
36
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
62
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
37
env->misa_mxl = env->misa_mxl_max;
63
cpu->cfg.mvendorid = THEAD_VENDOR_ID;
38
env->priv = PRV_M;
64
#ifndef CONFIG_USER_ONLY
39
env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV);
65
set_satp_mode_max_supported(cpu, VM_1_10_SV39);
40
+ if (env->misa_mxl > MXL_RV32) {
66
+ th_register_custom_csrs(cpu);
41
+ /*
67
#endif
42
+ * The reset status of SXL/UXL is undefined, but mstatus is WARL
68
43
+ * and we must ensure that the value after init is valid for read.
69
/* inherited from parent obj via riscv_cpu_init() */
44
+ */
70
diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c
45
+ env->mstatus = set_field(env->mstatus, MSTATUS64_SXL, env->misa_mxl);
71
new file mode 100644
46
+ env->mstatus = set_field(env->mstatus, MSTATUS64_UXL, env->misa_mxl);
72
index XXXXXXX..XXXXXXX
73
--- /dev/null
74
+++ b/target/riscv/th_csr.c
75
@@ -XXX,XX +XXX,XX @@
76
+/*
77
+ * T-Head-specific CSRs.
78
+ *
79
+ * Copyright (c) 2024 VRULL GmbH
80
+ *
81
+ * This program is free software; you can redistribute it and/or modify it
82
+ * under the terms and conditions of the GNU General Public License,
83
+ * version 2 or later, as published by the Free Software Foundation.
84
+ *
85
+ * This program is distributed in the hope it will be useful, but WITHOUT
86
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
88
+ * more details.
89
+ *
90
+ * You should have received a copy of the GNU General Public License along with
91
+ * this program. If not, see <http://www.gnu.org/licenses/>.
92
+ */
93
+
94
+#include "qemu/osdep.h"
95
+#include "cpu.h"
96
+#include "cpu_vendorid.h"
97
+
98
+#define CSR_TH_SXSTATUS 0x5c0
99
+
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)
112
+{
113
+ if (riscv_has_ext(env, RVS)) {
114
+ return RISCV_EXCP_NONE;
47
+ }
115
+ }
48
env->mcause = 0;
116
+
49
env->pc = env->resetvec;
117
+ return RISCV_EXCP_ILLEGAL_INST;
50
env->two_stage_lookup = false;
118
+}
51
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
119
+
52
index XXXXXXX..XXXXXXX 100644
120
+static int test_thead_mvendorid(RISCVCPU *cpu)
53
--- a/target/riscv/cpu_helper.c
54
+++ b/target/riscv/cpu_helper.c
55
@@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
56
#endif
57
}
58
59
+static RISCVMXL cpu_get_xl(CPURISCVState *env)
60
+{
121
+{
61
+#if defined(TARGET_RISCV32)
122
+ if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) {
62
+ return MXL_RV32;
123
+ return -1;
63
+#elif defined(CONFIG_USER_ONLY)
124
+ }
64
+ return MXL_RV64;
65
+#else
66
+ RISCVMXL xl = riscv_cpu_mxl(env);
67
+
125
+
68
+ /*
126
+ return 0;
69
+ * When emulating a 32-bit-only cpu, use RV32.
127
+}
70
+ * When emulating a 64-bit cpu, and MXL has been reduced to RV32,
128
+
71
+ * MSTATUSH doesn't have UXL/SXL, therefore XLEN cannot be widened
129
+static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno,
72
+ * back to RV64 for lower privs.
130
+ target_ulong *val)
73
+ */
131
+{
74
+ if (xl != MXL_RV32) {
132
+ /* We don't set MAEE here, because QEMU does not implement MAEE. */
75
+ switch (env->priv) {
133
+ *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE;
76
+ case PRV_M:
134
+ return RISCV_EXCP_NONE;
77
+ break;
135
+}
78
+ case PRV_U:
136
+
79
+ xl = get_field(env->mstatus, MSTATUS64_UXL);
137
+static riscv_csr th_csr_list[] = {
80
+ break;
138
+ {
81
+ default: /* PRV_S | PRV_H */
139
+ .csrno = CSR_TH_SXSTATUS,
82
+ xl = get_field(env->mstatus, MSTATUS64_SXL);
140
+ .insertion_test = test_thead_mvendorid,
83
+ break;
141
+ .csr_ops = { "th.sxstatus", smode, read_th_sxstatus }
142
+ }
143
+};
144
+
145
+void th_register_custom_csrs(RISCVCPU *cpu)
146
+{
147
+ for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) {
148
+ int csrno = th_csr_list[i].csrno;
149
+ riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops;
150
+ if (!th_csr_list[i].insertion_test(cpu)) {
151
+ riscv_set_csr_ops(csrno, csr_ops);
84
+ }
152
+ }
85
+ }
153
+ }
86
+ return xl;
87
+#endif
88
+}
154
+}
89
+
155
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
90
void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
91
target_ulong *cs_base, uint32_t *pflags)
92
{
93
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
94
}
95
#endif
96
97
+ flags = FIELD_DP32(flags, TB_FLAGS, XL, cpu_get_xl(env));
98
+
99
*pflags = flags;
100
}
101
102
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
103
index XXXXXXX..XXXXXXX 100644
156
index XXXXXXX..XXXXXXX 100644
104
--- a/target/riscv/csr.c
157
--- a/target/riscv/meson.build
105
+++ b/target/riscv/csr.c
158
+++ b/target/riscv/meson.build
106
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
159
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
107
mstatus = set_field(mstatus, MSTATUS32_SD, dirty);
160
'monitor.c',
108
} else {
161
'machine.c',
109
mstatus = set_field(mstatus, MSTATUS64_SD, dirty);
162
'pmu.c',
110
+ /* SXL and UXL fields are for now read only */
163
+ 'th_csr.c',
111
+ mstatus = set_field(mstatus, MSTATUS64_SXL, MXL_RV64);
164
'time_helper.c',
112
+ mstatus = set_field(mstatus, MSTATUS64_UXL, MXL_RV64);
165
'riscv-qmp-cmds.c',
113
}
166
))
114
env->mstatus = mstatus;
115
116
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
117
index XXXXXXX..XXXXXXX 100644
118
--- a/target/riscv/translate.c
119
+++ b/target/riscv/translate.c
120
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
121
#else
122
ctx->virt_enabled = false;
123
#endif
124
- ctx->xl = env->misa_mxl;
125
ctx->misa_ext = env->misa_ext;
126
ctx->frm = -1; /* unknown rounding mode */
127
ctx->ext_ifencei = cpu->cfg.ext_ifencei;
128
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
129
ctx->lmul = FIELD_EX32(tb_flags, TB_FLAGS, LMUL);
130
ctx->mlen = 1 << (ctx->sew + 3 - ctx->lmul);
131
ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX);
132
+ ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL);
133
ctx->cs = cs;
134
ctx->w = false;
135
ctx->ntemp = 0;
136
--
167
--
137
2.31.1
168
2.45.1
138
169
139
170
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
We're currently assuming SEW <= 3, and the "else" from
3
According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w
4
the SEW == 3 must be less. Use a switch and explicitly
4
instructions will be affected by Zvfhmin extension.
5
bound both SEW and SEQ for all cases.
5
And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the
6
conversions of
6
7
7
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
8
* From 1*SEW(16/32) to 2*SEW(32/64)
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
* From 2*SEW(32/64) to 1*SEW(16/32)
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
10
Message-id: 20211020031709.359469-8-richard.henderson@linaro.org
11
Signed-off-by: Max Chou <max.chou@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-2-max.chou@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
16
---
13
target/riscv/insn_trans/trans_rvv.c.inc | 26 +++++++++++++------------
17
target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++--
14
1 file changed, 14 insertions(+), 12 deletions(-)
18
1 file changed, 18 insertions(+), 2 deletions(-)
15
19
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
17
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
20
@@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq)
24
@@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s)
21
gen_helper_exit_atomic(cpu_env);
25
}
22
s->base.is_jmp = DISAS_NORETURN;
26
}
23
return true;
27
24
- } else {
28
+static bool require_rvfmin(DisasContext *s)
25
- if (s->sew == 3) {
29
+{
26
- if (!is_32bit(s)) {
30
+ if (s->mstatus_fs == EXT_STATUS_DISABLED) {
27
- fn = fnsd[seq];
31
+ return false;
28
- } else {
29
- /* Check done in amo_check(). */
30
- g_assert_not_reached();
31
- }
32
- } else {
33
- assert(seq < ARRAY_SIZE(fnsw));
34
- fn = fnsw[seq];
35
- }
36
+ }
32
+ }
37
+
33
+
38
+ switch (s->sew) {
34
+ switch (s->sew) {
39
+ case 0 ... 2:
35
+ case MO_16:
40
+ assert(seq < ARRAY_SIZE(fnsw));
36
+ return s->cfg_ptr->ext_zvfhmin;
41
+ fn = fnsw[seq];
37
+ case MO_32:
42
+ break;
38
+ return s->cfg_ptr->ext_zve32f;
43
+ case 3:
44
+ /* XLEN check done in amo_check(). */
45
+ assert(seq < ARRAY_SIZE(fnsd));
46
+ fn = fnsd[seq];
47
+ break;
48
+ default:
39
+ default:
49
+ g_assert_not_reached();
40
+ return false;
41
+ }
42
+}
43
+
44
static bool require_scale_rvf(DisasContext *s)
45
{
46
if (s->mstatus_fs == EXT_STATUS_DISABLED) {
47
@@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s)
50
}
48
}
51
49
52
data = FIELD_DP32(data, VDATA, MLEN, s->mlen);
50
switch (s->sew) {
51
- case MO_8:
52
- return s->cfg_ptr->ext_zvfhmin;
53
case MO_16:
54
return s->cfg_ptr->ext_zve32f;
55
case MO_32:
56
@@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a)
57
static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
58
{
59
return opfv_widen_check(s, a) &&
60
+ require_rvfmin(s) &&
61
require_scale_rvfmin(s) &&
62
(s->sew != MO_8);
63
}
64
@@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a)
65
static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
66
{
67
return opfv_narrow_check(s, a) &&
68
+ require_rvfmin(s) &&
69
require_scale_rvfmin(s) &&
70
(s->sew != MO_8);
71
}
53
--
72
--
54
2.31.1
73
2.45.1
55
56
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
Use the same REQUIRE_64BIT check that we use elsewhere,
3
The require_scale_rvf function only checks the double width operator for
4
rather than open-coding the use of is_32bit.
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
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
7
The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
integer to double width float, so the opfxv_widen_check function doesn’t
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
need require_rvf for the single width operator(integer).
9
Message-id: 20211020031709.359469-7-richard.henderson@linaro.org
10
11
Signed-off-by: Max Chou <max.chou@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-3-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
16
---
12
target/riscv/insn_trans/trans_rvv.c.inc | 3 ++-
17
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++
13
1 file changed, 2 insertions(+), 1 deletion(-)
18
1 file changed, 5 insertions(+)
14
19
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
@@ -XXX,XX +XXX,XX @@ static bool amo_check(DisasContext *s, arg_rwdvm* a)
24
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check)
20
25
static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
21
static bool amo_check64(DisasContext *s, arg_rwdvm* a)
22
{
26
{
23
- return !is_32bit(s) && amo_check(s, a);
27
return require_rvv(s) &&
24
+ REQUIRE_64BIT(s);
28
+ require_rvf(s) &&
25
+ return amo_check(s, a);
29
require_scale_rvf(s) &&
30
(s->sew != MO_8) &&
31
vext_check_isa_ill(s) &&
32
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check)
33
static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
34
{
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);
26
}
63
}
27
28
GEN_VEXT_TRANS(vamoswapw_v, 0, rwdvm, amo_op, amo_check)
29
--
64
--
30
2.31.1
65
2.45.1
31
66
32
67
diff view generated by jsdifflib
1
From: Frank Chang <frank.chang@sifive.com>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
oprsz and maxsz are passed with the same value in commit: eee2d61e202.
3
The opfv_narrow_check needs to check the single width float operator by
4
However, vmv.v.v was missed in that commit and should pass the same
4
require_rvf.
5
value as well in its tcg_gen_gvec_2_ptr() call.
6
5
7
Signed-off-by: Frank Chang <frank.chang@sifive.com>
6
Signed-off-by: Max Chou <max.chou@sifive.com>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-id: 20211007081803.1705656-1-frank.chang@sifive.com
8
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Message-ID: <20240322092600.1198921-4-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
11
---
12
target/riscv/insn_trans/trans_rvv.c.inc | 3 ++-
12
target/riscv/insn_trans/trans_rvv.c.inc | 1 +
13
1 file changed, 2 insertions(+), 1 deletion(-)
13
1 file changed, 1 insertion(+)
14
14
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
@@ -XXX,XX +XXX,XX @@ static bool trans_vmv_v_v(DisasContext *s, arg_vmv_v_v *a)
19
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
20
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over);
20
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
21
21
{
22
tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs1),
22
return opfv_narrow_check(s, a) &&
23
- cpu_env, 0, s->vlen / 8, data, fns[s->sew]);
23
+ require_rvf(s) &&
24
+ cpu_env, s->vlen / 8, s->vlen / 8, data,
24
require_scale_rvf(s) &&
25
+ fns[s->sew]);
25
(s->sew != MO_8);
26
gen_set_label(over);
26
}
27
}
28
return true;
29
--
27
--
30
2.31.1
28
2.45.1
31
32
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Max Chou <max.chou@sifive.com>
2
2
3
The multiply high-part instructions require a separate
3
If the checking functions check both the single and double width
4
implementation for RV32 when TARGET_LONG_BITS == 64.
4
operators at the same time, then the single width operator checking
5
functions (require_rvf[min]) will check whether the SEW is 8.
5
6
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
7
Signed-off-by: Max Chou <max.chou@sifive.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Message-id: 20211020031709.359469-11-richard.henderson@linaro.org
10
Message-ID: <20240322092600.1198921-5-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
---
12
target/riscv/translate.c | 16 +++++++++++++++
13
target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------
13
target/riscv/insn_trans/trans_rvm.c.inc | 26 ++++++++++++++++++++++---
14
1 file changed, 4 insertions(+), 12 deletions(-)
14
2 files changed, 39 insertions(+), 3 deletions(-)
15
15
16
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
17
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/translate.c
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
19
+++ b/target/riscv/translate.c
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
20
@@ -XXX,XX +XXX,XX @@ static bool gen_arith(DisasContext *ctx, arg_r *a, DisasExtend ext,
20
@@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
21
return true;
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);
22
}
27
}
23
28
@@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
24
+static bool gen_arith_per_ol(DisasContext *ctx, arg_r *a, DisasExtend ext,
29
return require_rvv(s) &&
25
+ void (*f_tl)(TCGv, TCGv, TCGv),
30
require_rvf(s) &&
26
+ void (*f_32)(TCGv, TCGv, TCGv))
31
require_scale_rvf(s) &&
27
+{
32
- (s->sew != MO_8) &&
28
+ int olen = get_olen(ctx);
33
vext_check_isa_ill(s) &&
29
+
34
vext_check_ds(s, a->rd, a->rs2, a->vm);
30
+ if (olen != TARGET_LONG_BITS) {
35
}
31
+ if (olen == 32) {
36
@@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
32
+ f_tl = f_32;
37
return require_rvv(s) &&
33
+ } else {
38
require_rvf(s) &&
34
+ g_assert_not_reached();
39
require_scale_rvf(s) &&
35
+ }
40
- (s->sew != MO_8) &&
36
+ }
41
vext_check_isa_ill(s) &&
37
+ return gen_arith(ctx, a, ext, f_tl);
42
vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm);
38
+}
43
}
39
+
44
@@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
40
static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext,
45
return require_rvv(s) &&
41
void (*func)(TCGv, TCGv, target_long))
46
require_rvf(s) &&
47
require_scale_rvf(s) &&
48
- (s->sew != MO_8) &&
49
vext_check_isa_ill(s) &&
50
vext_check_dd(s, a->rd, a->rs2, a->vm);
51
}
52
@@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
42
{
53
{
43
diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc
54
return opfv_widen_check(s, a) &&
44
index XXXXXXX..XXXXXXX 100644
55
require_rvfmin(s) &&
45
--- a/target/riscv/insn_trans/trans_rvm.c.inc
56
- require_scale_rvfmin(s) &&
46
+++ b/target/riscv/insn_trans/trans_rvm.c.inc
57
- (s->sew != MO_8);
47
@@ -XXX,XX +XXX,XX @@ static void gen_mulh(TCGv ret, TCGv s1, TCGv s2)
58
+ require_scale_rvfmin(s);
48
tcg_temp_free(discard);
49
}
59
}
50
60
51
+static void gen_mulh_w(TCGv ret, TCGv s1, TCGv s2)
61
#define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
52
+{
62
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
53
+ tcg_gen_mul_tl(ret, s1, s2);
54
+ tcg_gen_sari_tl(ret, ret, 32);
55
+}
56
+
57
static bool trans_mulh(DisasContext *ctx, arg_mulh *a)
58
{
63
{
59
REQUIRE_EXT(ctx, RVM);
64
return opfv_narrow_check(s, a) &&
60
- return gen_arith(ctx, a, EXT_NONE, gen_mulh);
65
require_rvfmin(s) &&
61
+ return gen_arith_per_ol(ctx, a, EXT_SIGN, gen_mulh, gen_mulh_w);
66
- require_scale_rvfmin(s) &&
67
- (s->sew != MO_8);
68
+ require_scale_rvfmin(s);
62
}
69
}
63
70
64
static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2)
71
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
65
@@ -XXX,XX +XXX,XX @@ static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2)
72
{
66
tcg_temp_free(rh);
73
return opfv_narrow_check(s, a) &&
74
require_rvf(s) &&
75
- require_scale_rvf(s) &&
76
- (s->sew != MO_8);
77
+ require_scale_rvf(s);
67
}
78
}
68
79
69
+static void gen_mulhsu_w(TCGv ret, TCGv arg1, TCGv arg2)
80
#define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \
70
+{
81
@@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
71
+ TCGv t1 = tcg_temp_new();
72
+ TCGv t2 = tcg_temp_new();
73
+
74
+ tcg_gen_ext32s_tl(t1, arg1);
75
+ tcg_gen_ext32u_tl(t2, arg2);
76
+ tcg_gen_mul_tl(ret, t1, t2);
77
+ tcg_temp_free(t1);
78
+ tcg_temp_free(t2);
79
+ tcg_gen_sari_tl(ret, ret, 32);
80
+}
81
+
82
static bool trans_mulhsu(DisasContext *ctx, arg_mulhsu *a)
83
{
82
{
84
REQUIRE_EXT(ctx, RVM);
83
return reduction_widen_check(s, a) &&
85
- return gen_arith(ctx, a, EXT_NONE, gen_mulhsu);
84
require_rvf(s) &&
86
+ return gen_arith_per_ol(ctx, a, EXT_NONE, gen_mulhsu, gen_mulhsu_w);
85
- require_scale_rvf(s) &&
86
- (s->sew != MO_8);
87
+ require_scale_rvf(s);
87
}
88
}
88
89
89
static void gen_mulhu(TCGv ret, TCGv s1, TCGv s2)
90
GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check)
90
@@ -XXX,XX +XXX,XX @@ static void gen_mulhu(TCGv ret, TCGv s1, TCGv s2)
91
static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a)
92
{
93
REQUIRE_EXT(ctx, RVM);
94
- return gen_arith(ctx, a, EXT_NONE, gen_mulhu);
95
+ /* gen_mulh_w works for either sign as input. */
96
+ return gen_arith_per_ol(ctx, a, EXT_ZERO, gen_mulhu, gen_mulh_w);
97
}
98
99
static void gen_div(TCGv ret, TCGv source1, TCGv source2)
100
--
91
--
101
2.31.1
92
2.45.1
102
103
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
raise_mmu_exception(), as is today, is prioritizing guest page faults by
4
and can't work as expected with '-numa node,memdev' options.
4
checking first if virt_enabled && !first_stage, and then considering the
5
regular inst/load/store faults.
5
6
6
Use MachineState::ram instead of manually initializing RAM memory
7
There's no mention in the spec about guest page fault being a higher
7
region, as well as by providing MachineClass::default_ram_id to
8
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
8
opt in to memdev scheme.
9
9
10
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
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>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
30
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
31
Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com>
13
Message-id: 20211020014112.7336-2-bmeng.cn@gmail.com
32
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
34
---
16
hw/riscv/microchip_pfsoc.c | 36 ++++++++++++++++++++----------------
35
target/riscv/cpu_helper.c | 22 ++++++++++++----------
17
1 file changed, 20 insertions(+), 16 deletions(-)
36
1 file changed, 12 insertions(+), 10 deletions(-)
18
37
19
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
38
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
20
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/riscv/microchip_pfsoc.c
40
--- a/target/riscv/cpu_helper.c
22
+++ b/hw/riscv/microchip_pfsoc.c
41
+++ b/target/riscv/cpu_helper.c
23
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
42
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
24
MemoryRegion *mem_low_alias = g_new(MemoryRegion, 1);
43
25
MemoryRegion *mem_high = g_new(MemoryRegion, 1);
44
switch (access_type) {
26
MemoryRegion *mem_high_alias = g_new(MemoryRegion, 1);
45
case MMU_INST_FETCH:
27
- uint64_t mem_high_size;
46
- if (env->virt_enabled && !first_stage) {
28
+ uint64_t mem_low_size, mem_high_size;
47
+ if (pmp_violation) {
29
hwaddr firmware_load_addr;
48
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
30
const char *firmware_name;
49
+ } else if (env->virt_enabled && !first_stage) {
31
bool kernel_as_payload = false;
50
cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
32
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
51
} else {
33
TYPE_MICROCHIP_PFSOC);
52
- cs->exception_index = pmp_violation ?
34
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
53
- RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
35
54
+ cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
36
+ /* Split RAM into low and high regions using aliases to machine->ram */
55
}
37
+ mem_low_size = memmap[MICROCHIP_PFSOC_DRAM_LO].size;
56
break;
38
+ mem_high_size = machine->ram_size - mem_low_size;
57
case MMU_DATA_LOAD:
39
+ memory_region_init_alias(mem_low, NULL,
58
- if (two_stage && !first_stage) {
40
+ "microchip.icicle.kit.ram_low", machine->ram,
59
+ if (pmp_violation) {
41
+ 0, mem_low_size);
60
+ cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
42
+ memory_region_init_alias(mem_high, NULL,
61
+ } else if (two_stage && !first_stage) {
43
+ "microchip.icicle.kit.ram_high", machine->ram,
62
cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
44
+ mem_low_size, mem_high_size);
63
} else {
45
+
64
- cs->exception_index = pmp_violation ?
46
/* Register RAM */
65
- RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
47
- memory_region_init_ram(mem_low, NULL, "microchip.icicle.kit.ram_low",
66
+ cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT;
48
- memmap[MICROCHIP_PFSOC_DRAM_LO].size,
67
}
49
- &error_fatal);
68
break;
50
- memory_region_init_alias(mem_low_alias, NULL,
69
case MMU_DATA_STORE:
51
- "microchip.icicle.kit.ram_low.alias",
70
- if (two_stage && !first_stage) {
52
- mem_low, 0,
71
+ if (pmp_violation) {
53
- memmap[MICROCHIP_PFSOC_DRAM_LO_ALIAS].size);
72
+ cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
54
memory_region_add_subregion(system_memory,
73
+ } else if (two_stage && !first_stage) {
55
memmap[MICROCHIP_PFSOC_DRAM_LO].base,
74
cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
56
mem_low);
75
} else {
57
+ memory_region_add_subregion(system_memory,
76
- cs->exception_index = pmp_violation ?
58
+ memmap[MICROCHIP_PFSOC_DRAM_HI].base,
77
- RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
59
+ mem_high);
78
- RISCV_EXCP_STORE_PAGE_FAULT;
60
+
79
+ cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
61
+ /* Create aliases for the low and high RAM regions */
80
}
62
+ memory_region_init_alias(mem_low_alias, NULL,
81
break;
63
+ "microchip.icicle.kit.ram_low.alias",
82
default:
64
+ mem_low, 0, mem_low_size);
65
memory_region_add_subregion(system_memory,
66
memmap[MICROCHIP_PFSOC_DRAM_LO_ALIAS].base,
67
mem_low_alias);
68
-
69
- mem_high_size = machine->ram_size - 1 * GiB;
70
-
71
- memory_region_init_ram(mem_high, NULL, "microchip.icicle.kit.ram_high",
72
- mem_high_size, &error_fatal);
73
memory_region_init_alias(mem_high_alias, NULL,
74
"microchip.icicle.kit.ram_high.alias",
75
mem_high, 0, mem_high_size);
76
- memory_region_add_subregion(system_memory,
77
- memmap[MICROCHIP_PFSOC_DRAM_HI].base,
78
- mem_high);
79
memory_region_add_subregion(system_memory,
80
memmap[MICROCHIP_PFSOC_DRAM_HI_ALIAS].base,
81
mem_high_alias);
82
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data)
83
MICROCHIP_PFSOC_COMPUTE_CPU_COUNT;
84
mc->min_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT + 1;
85
mc->default_cpus = mc->min_cpus;
86
+ mc->default_ram_id = "microchip.icicle.kit.ram";
87
88
/*
89
* Map 513 MiB high memory, the mimimum required high memory size, because
90
--
83
--
91
2.31.1
84
2.45.1
92
93
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Alexei Filippov <alexei.filippov@syntacore.com>
2
2
3
The position of this read-only field is dependent on the current xlen.
3
Previous patch fixed the PMP priority in raise_mmu_exception() but we're still
4
Rather than having to compute that difference in many places, compute
4
setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage
5
it only on read.
5
translation part, mtval2 will be set in case of successes 2 stage translation but
6
failed pmp check.
6
7
8
In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of
9
riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2
10
should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest
11
page-fault is taken into M-mode, mtval2 is written with either zero or guest
12
physical address that faulted, shifted by 2 bits. *For other traps, mtval2
13
is set to zero...*
14
15
Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
18
Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com>
9
Message-id: 20211020031709.359469-16-richard.henderson@linaro.org
19
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
21
---
12
target/riscv/cpu_helper.c | 3 +--
22
target/riscv/cpu_helper.c | 12 ++++++------
13
target/riscv/csr.c | 37 ++++++++++++++++++++++---------------
23
1 file changed, 6 insertions(+), 6 deletions(-)
14
target/riscv/translate.c | 5 ++---
15
3 files changed, 25 insertions(+), 20 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 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
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
void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
31
24
{
32
prot &= prot_pmp;
25
- uint64_t sd = riscv_cpu_mxl(env) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD;
33
- }
26
uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
27
MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
28
- MSTATUS64_UXL | sd;
29
+ MSTATUS64_UXL;
30
bool current_virt = riscv_cpu_virt_enabled(env);
31
32
g_assert(riscv_has_ext(env, RVH));
33
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/csr.c
36
+++ b/target/riscv/csr.c
37
@@ -XXX,XX +XXX,XX @@ static RISCVException read_mhartid(CPURISCVState *env, int csrno,
38
}
39
40
/* Machine Trap Setup */
41
+
42
+/* We do not store SD explicitly, only compute it on demand. */
43
+static uint64_t add_status_sd(RISCVMXL xl, uint64_t status)
44
+{
45
+ if ((status & MSTATUS_FS) == MSTATUS_FS ||
46
+ (status & MSTATUS_XS) == MSTATUS_XS) {
47
+ switch (xl) {
48
+ case MXL_RV32:
49
+ return status | MSTATUS32_SD;
50
+ case MXL_RV64:
51
+ return status | MSTATUS64_SD;
52
+ default:
53
+ g_assert_not_reached();
54
+ }
55
+ }
56
+ return status;
57
+}
58
+
59
static RISCVException read_mstatus(CPURISCVState *env, int csrno,
60
target_ulong *val)
61
{
62
- *val = env->mstatus;
63
+ *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus);
64
return RISCV_EXCP_NONE;
65
}
66
67
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
68
{
69
uint64_t mstatus = env->mstatus;
70
uint64_t mask = 0;
71
- int dirty;
72
73
/* flush tlb on mstatus fields that affect VM */
74
if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV |
75
@@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
76
77
mstatus = (mstatus & ~mask) | (val & mask);
78
79
- dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) |
80
- ((mstatus & MSTATUS_XS) == MSTATUS_XS);
81
- if (riscv_cpu_mxl(env) == MXL_RV32) {
82
- mstatus = set_field(mstatus, MSTATUS32_SD, dirty);
83
- } else {
84
- mstatus = set_field(mstatus, MSTATUS64_SD, dirty);
85
+ if (riscv_cpu_mxl(env) == MXL_RV64) {
86
/* SXL and UXL fields are for now read only */
87
mstatus = set_field(mstatus, MSTATUS64_SXL, MXL_RV64);
88
mstatus = set_field(mstatus, MSTATUS64_UXL, MXL_RV64);
89
@@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno,
90
{
91
target_ulong mask = (sstatus_v1_10_mask);
92
93
- if (riscv_cpu_mxl(env) == MXL_RV32) {
94
- mask |= SSTATUS32_SD;
95
- } else {
96
- mask |= SSTATUS64_SD;
97
- }
98
-
34
-
99
- *val = env->mstatus & mask;
35
- if (ret != TRANSLATE_SUCCESS) {
100
+ /* TODO: Use SXL not MXL. */
36
+ } else {
101
+ *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask);
37
/*
102
return RISCV_EXCP_NONE;
38
* Guest physical address translation failed, this is a HS
103
}
39
* level exception
104
40
*/
105
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
41
first_stage_error = false;
106
index XXXXXXX..XXXXXXX 100644
42
- env->guest_phys_fault_addr = (im_address |
107
--- a/target/riscv/translate.c
43
- (address &
108
+++ b/target/riscv/translate.c
44
- (TARGET_PAGE_SIZE - 1))) >> 2;
109
@@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
45
+ if (ret != TRANSLATE_PMP_FAIL) {
110
static void mark_fs_dirty(DisasContext *ctx)
46
+ env->guest_phys_fault_addr = (im_address |
111
{
47
+ (address &
112
TCGv tmp;
48
+ (TARGET_PAGE_SIZE - 1))) >> 2;
113
- target_ulong sd = get_xl(ctx) == MXL_RV32 ? MSTATUS32_SD : MSTATUS64_SD;
49
+ }
114
50
}
115
if (ctx->mstatus_fs != MSTATUS_FS) {
51
}
116
/* Remember the state change for the rest of the TB. */
52
} else {
117
@@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx)
118
119
tmp = tcg_temp_new();
120
tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
121
- tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
122
+ tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS);
123
tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
124
tcg_temp_free(tmp);
125
}
126
@@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx)
127
128
tmp = tcg_temp_new();
129
tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
130
- tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);
131
+ tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS);
132
tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs));
133
tcg_temp_free(tmp);
134
}
135
--
53
--
136
2.31.1
54
2.45.1
137
138
diff view generated by jsdifflib
1
From: Travis Geiselbrecht <travisg@gmail.com>
1
From: Rob Bradford <rbradford@rivosinc.com>
2
2
3
Ensure the columns for all of the register names and values line up.
3
This extension has now been ratified:
4
No functional change, just a minor tweak to the output.
4
https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be
5
removed.
5
6
6
Signed-off-by: Travis Geiselbrecht <travisg@gmail.com>
7
Since this is now a ratified extension add it to the list of extensions
8
included in the "max" CPU variant.
9
10
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20211009055019.545153-1-travisg@gmail.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>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
17
---
11
target/riscv/cpu.c | 10 +++++-----
18
target/riscv/cpu.c | 2 +-
12
1 file changed, 5 insertions(+), 5 deletions(-)
19
target/riscv/tcg/tcg-cpu.c | 2 +-
20
2 files changed, 2 insertions(+), 2 deletions(-)
13
21
14
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
15
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu.c
24
--- a/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
25
+++ b/target/riscv/cpu.c
18
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
26
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
19
}
27
MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
20
if (riscv_has_ext(env, RVH)) {
28
MISA_EXT_INFO(RVV, "v", "Vector operations"),
21
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hstatus ", env->hstatus);
29
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
22
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ",
30
- MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)")
23
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus",
31
+ MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
24
(target_ulong)env->vsstatus);
32
};
25
}
33
26
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip ", env->mip);
34
static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc)
27
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
35
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
28
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval);
36
index XXXXXXX..XXXXXXX 100644
29
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval);
37
--- a/target/riscv/tcg/tcg-cpu.c
30
if (riscv_has_ext(env, RVH)) {
38
+++ b/target/riscv/tcg/tcg-cpu.c
31
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
39
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
32
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
40
const RISCVCPUMultiExtConfig *prop;
33
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval);
41
34
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2);
42
/* Enable RVG, RVJ and RVV that are disabled by default */
35
}
43
- riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV);
36
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mscratch", env->mscratch);
44
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV);
37
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sscratch", env->sscratch);
45
38
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
46
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
39
#endif
47
isa_ext_update_enabled(cpu, prop->offset, true);
40
41
for (i = 0; i < 32; i++) {
42
- qemu_fprintf(f, " %s " TARGET_FMT_lx,
43
+ qemu_fprintf(f, " %-8s " TARGET_FMT_lx,
44
riscv_int_regnames[i], env->gpr[i]);
45
if ((i & 3) == 3) {
46
qemu_fprintf(f, "\n");
47
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
48
}
49
if (flags & CPU_DUMP_FPU) {
50
for (i = 0; i < 32; i++) {
51
- qemu_fprintf(f, " %s %016" PRIx64,
52
+ qemu_fprintf(f, " %-8s %016" PRIx64,
53
riscv_fpr_regnames[i], env->fpr[i]);
54
if ((i & 3) == 3) {
55
qemu_fprintf(f, "\n");
56
--
48
--
57
2.31.1
49
2.45.1
58
59
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Alistair Francis <alistair23@gmail.com>
2
2
3
Most shift instructions require a separate implementation
3
When running the instruction
4
for RV32 when TARGET_LONG_BITS == 64.
5
4
6
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
5
```
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
cbo.flush 0(x0)
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
```
9
Message-id: 20211020031709.359469-14-richard.henderson@linaro.org
8
9
QEMU would segfault.
10
11
The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0]
12
allocated.
13
14
In order to fix this let's use the existing get_address()
15
helper. This also has the benefit of performing pointer mask
16
calculations on the address specified in rs1.
17
18
The pointer masking specificiation specifically states:
19
20
"""
21
Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz
22
"""
23
24
So this is the correct behaviour and we previously have been incorrectly
25
not masking the address.
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>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
34
---
12
target/riscv/translate.c | 31 +++++++++
35
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++----
13
target/riscv/insn_trans/trans_rvb.c.inc | 92 ++++++++++++++-----------
36
1 file changed, 12 insertions(+), 4 deletions(-)
14
target/riscv/insn_trans/trans_rvi.c.inc | 26 +++----
15
3 files changed, 97 insertions(+), 52 deletions(-)
16
37
17
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
38
diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc
18
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/translate.c
40
--- a/target/riscv/insn_trans/trans_rvzicbo.c.inc
20
+++ b/target/riscv/translate.c
41
+++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc
21
@@ -XXX,XX +XXX,XX @@ static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext,
42
@@ -XXX,XX +XXX,XX @@
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);
22
return true;
50
return true;
23
}
51
}
24
52
25
+static bool gen_shift_imm_fn_per_ol(DisasContext *ctx, arg_shift *a,
53
static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
26
+ DisasExtend ext,
54
{
27
+ void (*f_tl)(TCGv, TCGv, target_long),
55
REQUIRE_ZICBOM(ctx);
28
+ void (*f_32)(TCGv, TCGv, target_long))
56
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
29
+{
57
+ TCGv src = get_address(ctx, a->rs1, 0);
30
+ int olen = get_olen(ctx);
31
+ if (olen != TARGET_LONG_BITS) {
32
+ if (olen == 32) {
33
+ f_tl = f_32;
34
+ } else {
35
+ g_assert_not_reached();
36
+ }
37
+ }
38
+ return gen_shift_imm_fn(ctx, a, ext, f_tl);
39
+}
40
+
58
+
41
static bool gen_shift_imm_tl(DisasContext *ctx, arg_shift *a, DisasExtend ext,
59
+ gen_helper_cbo_clean_flush(tcg_env, src);
42
void (*func)(TCGv, TCGv, TCGv))
43
{
44
@@ -XXX,XX +XXX,XX @@ static bool gen_shift(DisasContext *ctx, arg_r *a, DisasExtend ext,
45
return true;
60
return true;
46
}
61
}
47
62
48
+static bool gen_shift_per_ol(DisasContext *ctx, arg_r *a, DisasExtend ext,
63
static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
49
+ void (*f_tl)(TCGv, TCGv, TCGv),
64
{
50
+ void (*f_32)(TCGv, TCGv, TCGv))
65
REQUIRE_ZICBOM(ctx);
51
+{
66
- gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]);
52
+ int olen = get_olen(ctx);
67
+ TCGv src = get_address(ctx, a->rs1, 0);
53
+ if (olen != TARGET_LONG_BITS) {
54
+ if (olen == 32) {
55
+ f_tl = f_32;
56
+ } else {
57
+ g_assert_not_reached();
58
+ }
59
+ }
60
+ return gen_shift(ctx, a, ext, f_tl);
61
+}
62
+
68
+
63
static bool gen_unary(DisasContext *ctx, arg_r2 *a, DisasExtend ext,
69
+ gen_helper_cbo_inval(tcg_env, src);
64
void (*func)(TCGv, TCGv))
70
return true;
71
}
72
73
static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
65
{
74
{
66
diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
75
REQUIRE_ZICBOZ(ctx);
67
index XXXXXXX..XXXXXXX 100644
76
- gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]);
68
--- a/target/riscv/insn_trans/trans_rvb.c.inc
77
+ TCGv src = get_address(ctx, a->rs1, 0);
69
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
78
+
70
@@ -XXX,XX +XXX,XX @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a)
79
+ gen_helper_cbo_zero(tcg_env, src);
71
return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext);
80
return true;
72
}
81
}
73
74
+static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2)
75
+{
76
+ TCGv_i32 t1 = tcg_temp_new_i32();
77
+ TCGv_i32 t2 = tcg_temp_new_i32();
78
+
79
+ /* truncate to 32-bits */
80
+ tcg_gen_trunc_tl_i32(t1, arg1);
81
+ tcg_gen_trunc_tl_i32(t2, arg2);
82
+
83
+ tcg_gen_rotr_i32(t1, t1, t2);
84
+
85
+ /* sign-extend 64-bits */
86
+ tcg_gen_ext_i32_tl(ret, t1);
87
+
88
+ tcg_temp_free_i32(t1);
89
+ tcg_temp_free_i32(t2);
90
+}
91
+
92
static bool trans_ror(DisasContext *ctx, arg_ror *a)
93
{
94
REQUIRE_ZBB(ctx);
95
- return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotr_tl);
96
+ return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotr_tl, gen_rorw);
97
+}
98
+
99
+static void gen_roriw(TCGv ret, TCGv arg1, target_long shamt)
100
+{
101
+ TCGv_i32 t1 = tcg_temp_new_i32();
102
+
103
+ tcg_gen_trunc_tl_i32(t1, arg1);
104
+ tcg_gen_rotri_i32(t1, t1, shamt);
105
+ tcg_gen_ext_i32_tl(ret, t1);
106
+
107
+ tcg_temp_free_i32(t1);
108
}
109
110
static bool trans_rori(DisasContext *ctx, arg_rori *a)
111
{
112
REQUIRE_ZBB(ctx);
113
- return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_rotri_tl);
114
+ return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
115
+ tcg_gen_rotri_tl, gen_roriw);
116
+}
117
+
118
+static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2)
119
+{
120
+ TCGv_i32 t1 = tcg_temp_new_i32();
121
+ TCGv_i32 t2 = tcg_temp_new_i32();
122
+
123
+ /* truncate to 32-bits */
124
+ tcg_gen_trunc_tl_i32(t1, arg1);
125
+ tcg_gen_trunc_tl_i32(t2, arg2);
126
+
127
+ tcg_gen_rotl_i32(t1, t1, t2);
128
+
129
+ /* sign-extend 64-bits */
130
+ tcg_gen_ext_i32_tl(ret, t1);
131
+
132
+ tcg_temp_free_i32(t1);
133
+ tcg_temp_free_i32(t2);
134
}
135
136
static bool trans_rol(DisasContext *ctx, arg_rol *a)
137
{
138
REQUIRE_ZBB(ctx);
139
- return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl);
140
+ return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotl_tl, gen_rolw);
141
}
142
143
static void gen_rev8_32(TCGv ret, TCGv src1)
144
@@ -XXX,XX +XXX,XX @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a)
145
return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl);
146
}
147
148
-static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2)
149
-{
150
- TCGv_i32 t1 = tcg_temp_new_i32();
151
- TCGv_i32 t2 = tcg_temp_new_i32();
152
-
153
- /* truncate to 32-bits */
154
- tcg_gen_trunc_tl_i32(t1, arg1);
155
- tcg_gen_trunc_tl_i32(t2, arg2);
156
-
157
- tcg_gen_rotr_i32(t1, t1, t2);
158
-
159
- /* sign-extend 64-bits */
160
- tcg_gen_ext_i32_tl(ret, t1);
161
-
162
- tcg_temp_free_i32(t1);
163
- tcg_temp_free_i32(t2);
164
-}
165
-
166
static bool trans_rorw(DisasContext *ctx, arg_rorw *a)
167
{
168
REQUIRE_64BIT(ctx);
169
@@ -XXX,XX +XXX,XX @@ static bool trans_roriw(DisasContext *ctx, arg_roriw *a)
170
REQUIRE_64BIT(ctx);
171
REQUIRE_ZBB(ctx);
172
ctx->ol = MXL_RV32;
173
- return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_rorw);
174
-}
175
-
176
-static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2)
177
-{
178
- TCGv_i32 t1 = tcg_temp_new_i32();
179
- TCGv_i32 t2 = tcg_temp_new_i32();
180
-
181
- /* truncate to 32-bits */
182
- tcg_gen_trunc_tl_i32(t1, arg1);
183
- tcg_gen_trunc_tl_i32(t2, arg2);
184
-
185
- tcg_gen_rotl_i32(t1, t1, t2);
186
-
187
- /* sign-extend 64-bits */
188
- tcg_gen_ext_i32_tl(ret, t1);
189
-
190
- tcg_temp_free_i32(t1);
191
- tcg_temp_free_i32(t2);
192
+ return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_roriw);
193
}
194
195
static bool trans_rolw(DisasContext *ctx, arg_rolw *a)
196
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
197
index XXXXXXX..XXXXXXX 100644
198
--- a/target/riscv/insn_trans/trans_rvi.c.inc
199
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
200
@@ -XXX,XX +XXX,XX @@ static bool trans_slli(DisasContext *ctx, arg_slli *a)
201
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_shli_tl);
202
}
203
204
+static void gen_srliw(TCGv dst, TCGv src, target_long shamt)
205
+{
206
+ tcg_gen_extract_tl(dst, src, shamt, 32 - shamt);
207
+}
208
+
209
static bool trans_srli(DisasContext *ctx, arg_srli *a)
210
{
211
- return gen_shift_imm_fn(ctx, a, EXT_ZERO, tcg_gen_shri_tl);
212
+ return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
213
+ tcg_gen_shri_tl, gen_srliw);
214
+}
215
+
216
+static void gen_sraiw(TCGv dst, TCGv src, target_long shamt)
217
+{
218
+ tcg_gen_sextract_tl(dst, src, shamt, 32 - shamt);
219
}
220
221
static bool trans_srai(DisasContext *ctx, arg_srai *a)
222
{
223
- return gen_shift_imm_fn(ctx, a, EXT_SIGN, tcg_gen_sari_tl);
224
+ return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE,
225
+ tcg_gen_sari_tl, gen_sraiw);
226
}
227
228
static bool trans_add(DisasContext *ctx, arg_add *a)
229
@@ -XXX,XX +XXX,XX @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
230
return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_shli_tl);
231
}
232
233
-static void gen_srliw(TCGv dst, TCGv src, target_long shamt)
234
-{
235
- tcg_gen_extract_tl(dst, src, shamt, 32 - shamt);
236
-}
237
-
238
static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
239
{
240
REQUIRE_64BIT(ctx);
241
@@ -XXX,XX +XXX,XX @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
242
return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_srliw);
243
}
244
245
-static void gen_sraiw(TCGv dst, TCGv src, target_long shamt)
246
-{
247
- tcg_gen_sextract_tl(dst, src, shamt, 32 - shamt);
248
-}
249
-
250
static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
251
{
252
REQUIRE_64BIT(ctx);
253
--
82
--
254
2.31.1
83
2.45.1
255
256
diff view generated by jsdifflib
1
From: Bin Meng <bmeng.cn@gmail.com>
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
2
2
3
Using memory_region_init_ram(), which can't possibly handle vhost-user,
3
In AIA spec, each hart (or each hart within a group) has a unique hart
4
and can't work as expected with '-numa node,memdev' options.
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
Use MachineState::ram instead of manually initializing RAM memory
9
However, if the largest hart number among groups is a power of 2, QEMU
7
region, as well as by providing MachineClass::default_ram_id to
10
will pass an inaccurate hart-index-bit setting to Linux. For example, when
8
opt in to memdev scheme.
11
the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient
12
to represent 4 harts, but we passes 3 to Linux. The code needs to be
13
updated to ensure accurate hart-index-bit settings.
9
14
10
While at it add check for user supplied RAM size and error out if it
15
Additionally, a Linux patch[1] is necessary to correctly recover the hart
11
mismatches board expected value.
16
index when the guest OS has only 1 hart, where the hart-index-bit is 0.
12
17
13
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
18
[1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
19
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
16
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
17
Message-id: 20211020014112.7336-5-bmeng.cn@gmail.com
22
Cc: qemu-stable <qemu-stable@nongnu.org>
23
Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
25
---
20
hw/riscv/sifive_e.c | 16 ++++++++++++----
26
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
21
1 file changed, 12 insertions(+), 4 deletions(-)
27
1 file changed, 8 insertions(+), 1 deletion(-)
22
28
23
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
24
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
25
--- a/hw/riscv/sifive_e.c
31
--- a/target/riscv/kvm/kvm-cpu.c
26
+++ b/hw/riscv/sifive_e.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
27
@@ -XXX,XX +XXX,XX @@
33
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
28
*/
34
}
29
35
}
30
#include "qemu/osdep.h"
36
31
+#include "qemu/cutils.h"
37
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
32
#include "qemu/error-report.h"
38
+
33
#include "qapi/error.h"
39
+ if (max_hart_per_socket > 1) {
34
#include "hw/boards.h"
40
+ max_hart_per_socket--;
35
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sifive_e_memmap[] = {
41
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
36
42
+ } else {
37
static void sifive_e_machine_init(MachineState *machine)
43
+ hart_bits = 0;
38
{
39
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
40
const MemMapEntry *memmap = sifive_e_memmap;
41
42
SiFiveEState *s = RISCV_E_MACHINE(machine);
43
MemoryRegion *sys_mem = get_system_memory();
44
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
45
int i;
46
47
+ if (machine->ram_size != mc->default_ram_size) {
48
+ char *sz = size_to_str(mc->default_ram_size);
49
+ error_report("Invalid RAM size, should be %s", sz);
50
+ g_free(sz);
51
+ exit(EXIT_FAILURE);
52
+ }
44
+ }
53
+
45
+
54
/* Initialize SoC */
46
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
55
object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_E_SOC);
47
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
56
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
48
&hart_bits, true, NULL);
57
58
/* Data Tightly Integrated Memory */
59
- memory_region_init_ram(main_mem, NULL, "riscv.sifive.e.ram",
60
- memmap[SIFIVE_E_DEV_DTIM].size, &error_fatal);
61
memory_region_add_subregion(sys_mem,
62
- memmap[SIFIVE_E_DEV_DTIM].base, main_mem);
63
+ memmap[SIFIVE_E_DEV_DTIM].base, machine->ram);
64
65
/* Mask ROM reset vector */
66
uint32_t reset_vec[4];
67
@@ -XXX,XX +XXX,XX @@ static void sifive_e_machine_class_init(ObjectClass *oc, void *data)
68
mc->init = sifive_e_machine_init;
69
mc->max_cpus = 1;
70
mc->default_cpu_type = SIFIVE_E_CPU;
71
+ mc->default_ram_id = "riscv.sifive.e.ram";
72
+ mc->default_ram_size = sifive_e_memmap[SIFIVE_E_DEV_DTIM].size;
73
74
object_class_property_add_bool(oc, "revb", sifive_e_machine_get_revb,
75
sifive_e_machine_set_revb);
76
--
49
--
77
2.31.1
50
2.45.1
78
79
diff view generated by jsdifflib
1
From: Mingwang Li <limingwang@huawei.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
If default main_mem is used to be registered as the system memory,
3
Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length
4
other memory cannot be initialized. Therefore, the system memory
4
in bytes, when in this context we want 'reg_width' as the length in
5
should be initialized to the machine->ram, which consists of the
5
bits.
6
default main_mem and other possible memory required by applications,
7
such as shared hugepage memory in DPDK.
8
6
9
Also, the mc->defaul_ram_id should be set to the default main_mem,
7
Fix 'reg_width' back to the value in bits like 7cb59921c05a
10
such as "riscv_virt_board.ram" for the virt machine.
8
("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set
9
beforehand.
11
10
12
Signed-off-by: Mingwang Li <limingwang@huawei.com>
11
While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more
13
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
12
clarity about what the variable represents. 'bitsize' is also used in
13
riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to
14
gdb_feature_builder_append_reg().
15
16
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
17
Cc: Alex Bennée <alex.bennee@linaro.org>
18
Reported-by: Robin Dapp <rdapp.gcc@gmail.com>
19
Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML")
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
22
Acked-by: Alex Bennée <alex.bennee@linaro.org>
23
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Message-id: 20211016030908.40480-1-limingwang@huawei.com
25
Cc: qemu-stable <qemu-stable@nongnu.org>
26
Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
28
---
18
hw/riscv/virt.c | 6 ++----
29
target/riscv/gdbstub.c | 6 +++---
19
1 file changed, 2 insertions(+), 4 deletions(-)
30
1 file changed, 3 insertions(+), 3 deletions(-)
20
31
21
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
22
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/riscv/virt.c
34
--- a/target/riscv/gdbstub.c
24
+++ b/hw/riscv/virt.c
35
+++ b/target/riscv/gdbstub.c
25
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
36
@@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg)
26
const MemMapEntry *memmap = virt_memmap;
37
static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
27
RISCVVirtState *s = RISCV_VIRT_MACHINE(machine);
38
{
28
MemoryRegion *system_memory = get_system_memory();
39
RISCVCPU *cpu = RISCV_CPU(cs);
29
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
40
- int reg_width = cpu->cfg.vlenb;
30
MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
41
+ int bitsize = cpu->cfg.vlenb << 3;
31
char *plic_hart_config, *soc_name;
42
GDBFeatureBuilder builder;
32
target_ulong start_addr = memmap[VIRT_DRAM].base;
43
int i;
33
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
44
45
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
46
47
/* First define types and totals in a whole VL */
48
for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) {
49
- int count = reg_width / vec_lanes[i].size;
50
+ int count = bitsize / vec_lanes[i].size;
51
gdb_feature_builder_append_tag(
52
&builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
53
vec_lanes[i].id, vec_lanes[i].gdb_type, count);
54
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
55
/* Define vector registers */
56
for (i = 0; i < 32; i++) {
57
gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i),
58
- reg_width, i, "riscv_vector", "vector");
59
+ bitsize, i, "riscv_vector", "vector");
34
}
60
}
35
61
36
/* register system main memory (actual RAM) */
62
gdb_feature_builder_end(&builder);
37
- memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram",
38
- machine->ram_size, &error_fatal);
39
memory_region_add_subregion(system_memory, memmap[VIRT_DRAM].base,
40
- main_mem);
41
+ machine->ram);
42
43
/* create device tree */
44
create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline,
45
@@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
46
mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
47
mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
48
mc->numa_mem_supported = true;
49
+ mc->default_ram_id = "riscv_virt_board.ram";
50
51
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
52
53
--
63
--
54
2.31.1
64
2.45.1
55
65
56
66
diff view generated by jsdifflib
1
From: Philipp Tomsich <philipp.tomsich@vrull.eu>
1
From: Alistair Francis <alistair23@gmail.com>
2
2
3
The earlier implementation fell into a corner case for bytes that were
3
Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr
4
0x01, giving a wrong result (but not affecting our application test
4
CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr
5
cases for strings, as an ASCII value 0x01 is rare in those...).
5
CSRs are part of the disassembly.
6
6
7
This changes the algorithm to:
7
Reported-by: Eric DeVolder <eric_devolder@yahoo.com>
8
1. Mask out the high-bit of each bytes (so that each byte is <= 127).
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
2. Add 127 to each byte (i.e. if the low 7 bits are not 0, this will overflow
9
Fixes: ea10325917 ("RISC-V Disassembler")
10
into the highest bit of each byte).
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
3. Bitwise-or the original value back in (to cover those cases where the
11
Cc: qemu-stable <qemu-stable@nongnu.org>
12
source byte was exactly 128) to saturate the high-bit.
12
Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com>
13
4. Shift-and-mask (implemented as a mask-and-shift) to extract the MSB of
14
each byte into its LSB.
15
5. Multiply with 0xff to fan out the LSB to all bits of each byte.
16
17
Fixes: d7a4fcb034 ("target/riscv: Add orc.b instruction for Zbb, removing gorc/gorci")
18
19
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
20
Reported-by: Vincent Palatin <vpalatin@rivosinc.com>
21
Tested-by: Vincent Palatin <vpalatin@rivosinc.com>
22
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
Message-id: 20211013184125.2010897-1-philipp.tomsich@vrull.eu
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
14
---
26
target/riscv/insn_trans/trans_rvb.c.inc | 13 ++++++++-----
15
disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
27
1 file changed, 8 insertions(+), 5 deletions(-)
16
1 file changed, 64 insertions(+), 1 deletion(-)
28
17
29
diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
18
diff --git a/disas/riscv.c b/disas/riscv.c
30
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/insn_trans/trans_rvb.c.inc
20
--- a/disas/riscv.c
32
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
21
+++ b/disas/riscv.c
33
@@ -XXX,XX +XXX,XX @@ static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a)
22
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
34
static void gen_orc_b(TCGv ret, TCGv source1)
23
case 0x0383: return "mibound";
35
{
24
case 0x0384: return "mdbase";
36
TCGv tmp = tcg_temp_new();
25
case 0x0385: return "mdbound";
37
- TCGv ones = tcg_constant_tl(dup_const_tl(MO_8, 0x01));
26
- case 0x03a0: return "pmpcfg3";
38
+ TCGv low7 = tcg_constant_tl(dup_const_tl(MO_8, 0x7f));
27
+ case 0x03a0: return "pmpcfg0";
39
28
+ case 0x03a1: return "pmpcfg1";
40
- /* Set lsb in each byte if the byte was zero. */
29
+ case 0x03a2: return "pmpcfg2";
41
- tcg_gen_sub_tl(tmp, source1, ones);
30
+ case 0x03a3: return "pmpcfg3";
42
- tcg_gen_andc_tl(tmp, tmp, source1);
31
+ case 0x03a4: return "pmpcfg4";
43
+ /* Set msb in each byte if the byte was non-zero. */
32
+ case 0x03a5: return "pmpcfg5";
44
+ tcg_gen_and_tl(tmp, source1, low7);
33
+ case 0x03a6: return "pmpcfg6";
45
+ tcg_gen_add_tl(tmp, tmp, low7);
34
+ case 0x03a7: return "pmpcfg7";
46
+ tcg_gen_or_tl(tmp, tmp, source1);
35
+ case 0x03a8: return "pmpcfg8";
47
+
36
+ case 0x03a9: return "pmpcfg9";
48
+ /* Extract the msb to the lsb in each byte */
37
+ case 0x03aa: return "pmpcfg10";
49
+ tcg_gen_andc_tl(tmp, tmp, low7);
38
+ case 0x03ab: return "pmpcfg11";
50
tcg_gen_shri_tl(tmp, tmp, 7);
39
+ case 0x03ac: return "pmpcfg12";
51
- tcg_gen_andc_tl(tmp, ones, tmp);
40
+ case 0x03ad: return "pmpcfg13";
52
41
+ case 0x03ae: return "pmpcfg14";
53
/* Replicate the lsb of each byte across the byte. */
42
+ case 0x03af: return "pmpcfg15";
54
tcg_gen_muli_tl(ret, tmp, 0xff);
43
case 0x03b0: return "pmpaddr0";
44
case 0x03b1: return "pmpaddr1";
45
case 0x03b2: return "pmpaddr2";
46
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
47
case 0x03bd: return "pmpaddr13";
48
case 0x03be: return "pmpaddr14";
49
case 0x03bf: return "pmpaddr15";
50
+ case 0x03c0: return "pmpaddr16";
51
+ case 0x03c1: return "pmpaddr17";
52
+ case 0x03c2: return "pmpaddr18";
53
+ case 0x03c3: return "pmpaddr19";
54
+ case 0x03c4: return "pmpaddr20";
55
+ case 0x03c5: return "pmpaddr21";
56
+ case 0x03c6: return "pmpaddr22";
57
+ case 0x03c7: return "pmpaddr23";
58
+ case 0x03c8: return "pmpaddr24";
59
+ case 0x03c9: return "pmpaddr25";
60
+ case 0x03ca: return "pmpaddr26";
61
+ case 0x03cb: return "pmpaddr27";
62
+ case 0x03cc: return "pmpaddr28";
63
+ case 0x03cd: return "pmpaddr29";
64
+ case 0x03ce: return "pmpaddr30";
65
+ case 0x03cf: return "pmpaddr31";
66
+ case 0x03d0: return "pmpaddr32";
67
+ case 0x03d1: return "pmpaddr33";
68
+ case 0x03d2: return "pmpaddr34";
69
+ case 0x03d3: return "pmpaddr35";
70
+ case 0x03d4: return "pmpaddr36";
71
+ case 0x03d5: return "pmpaddr37";
72
+ case 0x03d6: return "pmpaddr38";
73
+ case 0x03d7: return "pmpaddr39";
74
+ case 0x03d8: return "pmpaddr40";
75
+ case 0x03d9: return "pmpaddr41";
76
+ case 0x03da: return "pmpaddr42";
77
+ case 0x03db: return "pmpaddr43";
78
+ case 0x03dc: return "pmpaddr44";
79
+ case 0x03dd: return "pmpaddr45";
80
+ case 0x03de: return "pmpaddr46";
81
+ case 0x03df: return "pmpaddr47";
82
+ case 0x03e0: return "pmpaddr48";
83
+ case 0x03e1: return "pmpaddr49";
84
+ case 0x03e2: return "pmpaddr50";
85
+ case 0x03e3: return "pmpaddr51";
86
+ case 0x03e4: return "pmpaddr52";
87
+ case 0x03e5: return "pmpaddr53";
88
+ case 0x03e6: return "pmpaddr54";
89
+ case 0x03e7: return "pmpaddr55";
90
+ case 0x03e8: return "pmpaddr56";
91
+ case 0x03e9: return "pmpaddr57";
92
+ case 0x03ea: return "pmpaddr58";
93
+ case 0x03eb: return "pmpaddr59";
94
+ case 0x03ec: return "pmpaddr60";
95
+ case 0x03ed: return "pmpaddr61";
96
+ case 0x03ee: return "pmpaddr62";
97
+ case 0x03ef: return "pmpaddr63";
98
case 0x0780: return "mtohost";
99
case 0x0781: return "mfromhost";
100
case 0x0782: return "mreset";
55
--
101
--
56
2.31.1
102
2.45.1
57
58
diff view generated by jsdifflib
Deleted patch
1
From: Alistair Francis <alistair.francis@wdc.com>
2
1
3
Since commit 1a9540d1f1a
4
("target/riscv: Drop support for ISA spec version 1.09.1")
5
these definitions are unused, remove them.
6
7
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
11
Message-id: f4d8a7a035f39c0a35d44c1e371c5c99cc2fa15a.1634531504.git.alistair.francis@wdc.com
12
---
13
target/riscv/cpu_bits.h | 8 --------
14
1 file changed, 8 deletions(-)
15
16
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/cpu_bits.h
19
+++ b/target/riscv/cpu_bits.h
20
@@ -XXX,XX +XXX,XX @@
21
#define SATP64_ASID 0x0FFFF00000000000ULL
22
#define SATP64_PPN 0x00000FFFFFFFFFFFULL
23
24
-/* VM modes (mstatus.vm) privileged ISA 1.9.1 */
25
-#define VM_1_09_MBARE 0
26
-#define VM_1_09_MBB 1
27
-#define VM_1_09_MBBID 2
28
-#define VM_1_09_SV32 8
29
-#define VM_1_09_SV39 9
30
-#define VM_1_09_SV48 10
31
-
32
/* VM modes (satp.mode) privileged ISA 1.10 */
33
#define VM_1_10_MBARE 0
34
#define VM_1_10_SV32 1
35
--
36
2.31.1
37
38
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Yu-Ming Chang <yumin686@andestech.com>
2
2
3
Move the function to cpu_helper.c, as it is large and growing.
3
Both CSRRS and CSRRC always read the addressed CSR and cause any read side
4
effects regardless of rs1 and rd fields. Note that if rs1 specifies a register
5
holding a zero value other than x0, the instruction will still attempt to write
6
the unmodified value back to the CSR and will cause any attendant side effects.
4
7
5
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
8
So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies
9
a register holding a zero value, an illegal instruction exception should be
10
raised.
11
12
Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-ID: <20240403070823.80897-1-yumin686@andestech.com>
8
Message-id: 20211020031709.359469-2-richard.henderson@linaro.org
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
16
---
11
target/riscv/cpu.h | 47 ++-------------------------------------
17
target/riscv/cpu.h | 4 ++++
12
target/riscv/cpu_helper.c | 46 ++++++++++++++++++++++++++++++++++++++
18
target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++----
13
2 files changed, 48 insertions(+), 45 deletions(-)
19
target/riscv/op_helper.c | 6 ++---
20
3 files changed, 53 insertions(+), 8 deletions(-)
14
21
15
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
16
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.h
24
--- a/target/riscv/cpu.h
18
+++ b/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
19
@@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype)
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
20
return cpu->cfg.vlen >> (sew + 3 - lmul);
27
void riscv_cpu_update_mask(CPURISCVState *env);
21
}
28
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
22
29
23
-static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
30
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
24
- target_ulong *cs_base, uint32_t *pflags)
31
+ target_ulong *ret_value);
25
-{
26
- uint32_t flags = 0;
27
-
28
- *pc = env->pc;
29
- *cs_base = 0;
30
-
31
- if (riscv_has_ext(env, RVV)) {
32
- uint32_t vlmax = vext_get_vlmax(env_archcpu(env), env->vtype);
33
- bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl);
34
- flags = FIELD_DP32(flags, TB_FLAGS, VILL,
35
- FIELD_EX64(env->vtype, VTYPE, VILL));
36
- flags = FIELD_DP32(flags, TB_FLAGS, SEW,
37
- FIELD_EX64(env->vtype, VTYPE, VSEW));
38
- flags = FIELD_DP32(flags, TB_FLAGS, LMUL,
39
- FIELD_EX64(env->vtype, VTYPE, VLMUL));
40
- flags = FIELD_DP32(flags, TB_FLAGS, VL_EQ_VLMAX, vl_eq_vlmax);
41
- } else {
42
- flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1);
43
- }
44
-
45
-#ifdef CONFIG_USER_ONLY
46
- flags |= TB_FLAGS_MSTATUS_FS;
47
-#else
48
- flags |= cpu_mmu_index(env, 0);
49
- if (riscv_cpu_fp_enabled(env)) {
50
- flags |= env->mstatus & MSTATUS_FS;
51
- }
52
-
53
- if (riscv_has_ext(env, RVH)) {
54
- if (env->priv == PRV_M ||
55
- (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
56
- (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) &&
57
- get_field(env->hstatus, HSTATUS_HU))) {
58
- flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1);
59
- }
60
-
61
- flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS,
62
- get_field(env->mstatus_hs, MSTATUS_FS));
63
- }
64
-#endif
65
-
66
- *pflags = flags;
67
-}
68
+void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
69
+ target_ulong *cs_base, uint32_t *pflags);
70
71
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
72
target_ulong *ret_value,
33
target_ulong *ret_value,
73
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
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
74
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
75
--- a/target/riscv/cpu_helper.c
46
--- a/target/riscv/csr.c
76
+++ b/target/riscv/cpu_helper.c
47
+++ b/target/riscv/csr.c
77
@@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
48
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
78
#endif
49
50
static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
51
int csrno,
52
- bool write_mask)
53
+ bool write)
54
{
55
/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
56
bool read_only = get_field(csrno, 0xC00) == 3;
57
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
58
}
59
60
/* read / write check */
61
- if (write_mask && read_only) {
62
+ if (write && read_only) {
63
return RISCV_EXCP_ILLEGAL_INST;
64
}
65
66
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno,
67
return RISCV_EXCP_NONE;
79
}
68
}
80
69
81
+void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
70
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
82
+ target_ulong *cs_base, uint32_t *pflags)
71
+ target_ulong *ret_value)
83
+{
72
+{
84
+ uint32_t flags = 0;
73
+ RISCVException ret = riscv_csrrw_check(env, csrno, false);
85
+
74
+ if (ret != RISCV_EXCP_NONE) {
86
+ *pc = env->pc;
75
+ return ret;
87
+ *cs_base = 0;
88
+
89
+ if (riscv_has_ext(env, RVV)) {
90
+ uint32_t vlmax = vext_get_vlmax(env_archcpu(env), env->vtype);
91
+ bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl);
92
+ flags = FIELD_DP32(flags, TB_FLAGS, VILL,
93
+ FIELD_EX64(env->vtype, VTYPE, VILL));
94
+ flags = FIELD_DP32(flags, TB_FLAGS, SEW,
95
+ FIELD_EX64(env->vtype, VTYPE, VSEW));
96
+ flags = FIELD_DP32(flags, TB_FLAGS, LMUL,
97
+ FIELD_EX64(env->vtype, VTYPE, VLMUL));
98
+ flags = FIELD_DP32(flags, TB_FLAGS, VL_EQ_VLMAX, vl_eq_vlmax);
99
+ } else {
100
+ flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1);
101
+ }
76
+ }
102
+
77
+
103
+#ifdef CONFIG_USER_ONLY
78
+ return riscv_csrrw_do64(env, csrno, ret_value, 0, 0);
104
+ flags |= TB_FLAGS_MSTATUS_FS;
79
+}
105
+#else
80
+
106
+ flags |= cpu_mmu_index(env, 0);
81
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
107
+ if (riscv_cpu_fp_enabled(env)) {
82
target_ulong *ret_value,
108
+ flags |= env->mstatus & MSTATUS_FS;
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) {
101
+ return ret;
109
+ }
102
+ }
110
+
103
+
111
+ if (riscv_has_ext(env, RVH)) {
104
+ if (csr_ops[csrno].read128) {
112
+ if (env->priv == PRV_M ||
105
+ return riscv_csrrw_do128(env, csrno, ret_value,
113
+ (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
106
+ int128_zero(), int128_zero());
114
+ (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) &&
107
+ }
115
+ get_field(env->hstatus, HSTATUS_HU))) {
116
+ flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1);
117
+ }
118
+
108
+
119
+ flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS,
109
+ /*
120
+ get_field(env->mstatus_hs, MSTATUS_FS));
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);
121
+ }
122
+ }
122
+#endif
123
+ return ret;
123
+
124
+ *pflags = flags;
125
+}
124
+}
126
+
125
+
127
#ifndef CONFIG_USER_ONLY
126
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
128
static int riscv_cpu_local_irq_pending(CPURISCVState *env)
127
Int128 *ret_value,
128
Int128 new_value, Int128 write_mask)
129
{
129
{
130
RISCVException ret;
131
132
- ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask));
133
+ ret = riscv_csrrw_check(env, csrno, true);
134
if (ret != RISCV_EXCP_NONE) {
135
return ret;
136
}
137
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
138
index XXXXXXX..XXXXXXX 100644
139
--- a/target/riscv/op_helper.c
140
+++ b/target/riscv/op_helper.c
141
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr)
142
}
143
144
target_ulong val = 0;
145
- RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0);
146
+ RISCVException ret = riscv_csrr(env, csr, &val);
147
148
if (ret != RISCV_EXCP_NONE) {
149
riscv_raise_exception(env, ret, GETPC());
150
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr,
151
target_ulong helper_csrr_i128(CPURISCVState *env, int csr)
152
{
153
Int128 rv = int128_zero();
154
- RISCVException ret = riscv_csrrw_i128(env, csr, &rv,
155
- int128_zero(),
156
- int128_zero());
157
+ RISCVException ret = riscv_csrr_i128(env, csr, &rv);
158
159
if (ret != RISCV_EXCP_NONE) {
160
riscv_raise_exception(env, ret, GETPC());
130
--
161
--
131
2.31.1
162
2.45.1
132
133
diff view generated by jsdifflib
Deleted patch
1
From: Alistair Francis <alistair.francis@wdc.com>
2
1
3
Update the OpenTitan machine model to match the latest OpenTitan FPGA
4
design.
5
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 18b1b681b0f8dd2461e819d1217bf0b530812680.1634524691.git.alistair.francis@wdc.com
9
---
10
include/hw/riscv/opentitan.h | 6 +++---
11
hw/riscv/opentitan.c | 22 +++++++++++++++++-----
12
2 files changed, 20 insertions(+), 8 deletions(-)
13
14
diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/riscv/opentitan.h
17
+++ b/include/hw/riscv/opentitan.h
18
@@ -XXX,XX +XXX,XX @@
19
#define HW_OPENTITAN_H
20
21
#include "hw/riscv/riscv_hart.h"
22
-#include "hw/intc/ibex_plic.h"
23
+#include "hw/intc/sifive_plic.h"
24
#include "hw/char/ibex_uart.h"
25
#include "hw/timer/ibex_timer.h"
26
#include "qom/object.h"
27
@@ -XXX,XX +XXX,XX @@ struct LowRISCIbexSoCState {
28
29
/*< public >*/
30
RISCVHartArrayState cpus;
31
- IbexPlicState plic;
32
+ SiFivePLICState plic;
33
IbexUartState uart;
34
IbexTimerState timer;
35
36
@@ -XXX,XX +XXX,XX @@ enum {
37
};
38
39
enum {
40
- IBEX_TIMER_TIMEREXPIRED0_0 = 125,
41
+ IBEX_TIMER_TIMEREXPIRED0_0 = 126,
42
IBEX_UART0_RX_PARITY_ERR_IRQ = 8,
43
IBEX_UART0_RX_TIMEOUT_IRQ = 7,
44
IBEX_UART0_RX_BREAK_ERR_IRQ = 6,
45
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/riscv/opentitan.c
48
+++ b/hw/riscv/opentitan.c
49
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry ibex_memmap[] = {
50
[IBEX_DEV_PINMUX] = { 0x40460000, 0x1000 },
51
[IBEX_DEV_PADCTRL] = { 0x40470000, 0x1000 },
52
[IBEX_DEV_FLASH_CTRL] = { 0x41000000, 0x1000 },
53
- [IBEX_DEV_PLIC] = { 0x41010000, 0x1000 },
54
[IBEX_DEV_AES] = { 0x41100000, 0x1000 },
55
[IBEX_DEV_HMAC] = { 0x41110000, 0x1000 },
56
[IBEX_DEV_KMAC] = { 0x41120000, 0x1000 },
57
- [IBEX_DEV_KEYMGR] = { 0x41130000, 0x1000 },
58
+ [IBEX_DEV_OTBN] = { 0x41130000, 0x10000 },
59
+ [IBEX_DEV_KEYMGR] = { 0x41140000, 0x1000 },
60
[IBEX_DEV_CSRNG] = { 0x41150000, 0x1000 },
61
[IBEX_DEV_ENTROPY] = { 0x41160000, 0x1000 },
62
[IBEX_DEV_EDNO] = { 0x41170000, 0x1000 },
63
[IBEX_DEV_EDN1] = { 0x41180000, 0x1000 },
64
[IBEX_DEV_ALERT_HANDLER] = { 0x411b0000, 0x1000 },
65
[IBEX_DEV_NMI_GEN] = { 0x411c0000, 0x1000 },
66
- [IBEX_DEV_OTBN] = { 0x411d0000, 0x10000 },
67
[IBEX_DEV_PERI] = { 0x411f0000, 0x10000 },
68
+ [IBEX_DEV_PLIC] = { 0x48000000, 0x4005000 },
69
[IBEX_DEV_FLASH_VIRTUAL] = { 0x80000000, 0x80000 },
70
};
71
72
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_init(Object *obj)
73
74
object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
75
76
- object_initialize_child(obj, "plic", &s->plic, TYPE_IBEX_PLIC);
77
+ object_initialize_child(obj, "plic", &s->plic, TYPE_SIFIVE_PLIC);
78
79
object_initialize_child(obj, "uart", &s->uart, TYPE_IBEX_UART);
80
81
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
82
&s->flash_alias);
83
84
/* PLIC */
85
+ qdev_prop_set_string(DEVICE(&s->plic), "hart-config", "M");
86
+ qdev_prop_set_uint32(DEVICE(&s->plic), "hartid-base", 0);
87
+ qdev_prop_set_uint32(DEVICE(&s->plic), "num-sources", 180);
88
+ qdev_prop_set_uint32(DEVICE(&s->plic), "num-priorities", 3);
89
+ qdev_prop_set_uint32(DEVICE(&s->plic), "priority-base", 0x00);
90
+ qdev_prop_set_uint32(DEVICE(&s->plic), "pending-base", 0x1000);
91
+ qdev_prop_set_uint32(DEVICE(&s->plic), "enable-base", 0x2000);
92
+ qdev_prop_set_uint32(DEVICE(&s->plic), "enable-stride", 0x18);
93
+ qdev_prop_set_uint32(DEVICE(&s->plic), "context-base", 0x200004);
94
+ qdev_prop_set_uint32(DEVICE(&s->plic), "context-stride", 4);
95
+ qdev_prop_set_uint32(DEVICE(&s->plic), "aperture-size", memmap[IBEX_DEV_PLIC].size);
96
+
97
if (!sysbus_realize(SYS_BUS_DEVICE(&s->plic), errp)) {
98
return;
99
}
100
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
101
for (i = 0; i < ms->smp.cpus; i++) {
102
CPUState *cpu = qemu_get_cpu(i);
103
104
- qdev_connect_gpio_out(DEVICE(&s->plic), i,
105
+ qdev_connect_gpio_out(DEVICE(&s->plic), ms->smp.cpus + i,
106
qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
107
}
108
109
--
110
2.31.1
111
112
diff view generated by jsdifflib
Deleted patch
1
From: Alistair Francis <alistair.francis@wdc.com>
2
1
3
The Ibex PLIC is now spec compliant. Let's remove the Ibex PLIC and
4
instead use the SiFive PLIC.
5
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 5557935c2660c5e6281b6d21e6514e019593662e.1634524691.git.alistair.francis@wdc.com
9
---
10
hw/intc/ibex_plic.c | 307 --------------------------------------------
11
hw/intc/meson.build | 1 -
12
2 files changed, 308 deletions(-)
13
delete mode 100644 hw/intc/ibex_plic.c
14
15
diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
16
deleted file mode 100644
17
index XXXXXXX..XXXXXXX
18
--- a/hw/intc/ibex_plic.c
19
+++ /dev/null
20
@@ -XXX,XX +XXX,XX @@
21
-/*
22
- * QEMU RISC-V lowRISC Ibex PLIC
23
- *
24
- * Copyright (c) 2020 Western Digital
25
- *
26
- * Documentation avaliable: https://docs.opentitan.org/hw/ip/rv_plic/doc/
27
- *
28
- * This program is free software; you can redistribute it and/or modify it
29
- * under the terms and conditions of the GNU General Public License,
30
- * version 2 or later, as published by the Free Software Foundation.
31
- *
32
- * This program is distributed in the hope it will be useful, but WITHOUT
33
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
35
- * more details.
36
- *
37
- * You should have received a copy of the GNU General Public License along with
38
- * this program. If not, see <http://www.gnu.org/licenses/>.
39
- */
40
-
41
-#include "qemu/osdep.h"
42
-#include "qemu/log.h"
43
-#include "hw/qdev-properties.h"
44
-#include "hw/core/cpu.h"
45
-#include "hw/boards.h"
46
-#include "hw/pci/msi.h"
47
-#include "target/riscv/cpu_bits.h"
48
-#include "target/riscv/cpu.h"
49
-#include "hw/intc/ibex_plic.h"
50
-#include "hw/irq.h"
51
-
52
-static bool addr_between(uint32_t addr, uint32_t base, uint32_t num)
53
-{
54
- uint32_t end = base + (num * 0x04);
55
-
56
- if (addr >= base && addr < end) {
57
- return true;
58
- }
59
-
60
- return false;
61
-}
62
-
63
-static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool level)
64
-{
65
- int pending_num = irq / 32;
66
-
67
- if (!level) {
68
- /*
69
- * If the level is low make sure we clear the hidden_pending.
70
- */
71
- s->hidden_pending[pending_num] &= ~(1 << (irq % 32));
72
- }
73
-
74
- if (s->claimed[pending_num] & 1 << (irq % 32)) {
75
- /*
76
- * The interrupt has been claimed, but not completed.
77
- * The pending bit can't be set.
78
- * Save the pending level for after the interrupt is completed.
79
- */
80
- s->hidden_pending[pending_num] |= level << (irq % 32);
81
- } else {
82
- s->pending[pending_num] |= level << (irq % 32);
83
- }
84
-}
85
-
86
-static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
87
-{
88
- int i;
89
- uint32_t max_irq = 0;
90
- uint32_t max_prio = s->threshold;
91
-
92
- for (i = 0; i < s->pending_num; i++) {
93
- uint32_t irq_num = ctz64(s->pending[i]) + (i * 32);
94
-
95
- if (!(s->pending[i] & s->enable[i])) {
96
- /* No pending and enabled IRQ */
97
- continue;
98
- }
99
-
100
- if (s->priority[irq_num] > max_prio) {
101
- max_irq = irq_num;
102
- max_prio = s->priority[irq_num];
103
- }
104
- }
105
-
106
- if (max_irq) {
107
- s->claim = max_irq;
108
- return true;
109
- }
110
-
111
- return false;
112
-}
113
-
114
-static void ibex_plic_update(IbexPlicState *s)
115
-{
116
- int i;
117
-
118
- for (i = 0; i < s->num_cpus; i++) {
119
- qemu_set_irq(s->external_irqs[i], ibex_plic_irqs_pending(s, 0));
120
- }
121
-}
122
-
123
-static void ibex_plic_reset(DeviceState *dev)
124
-{
125
- IbexPlicState *s = IBEX_PLIC(dev);
126
-
127
- s->threshold = 0x00000000;
128
- s->claim = 0x00000000;
129
-}
130
-
131
-static uint64_t ibex_plic_read(void *opaque, hwaddr addr,
132
- unsigned int size)
133
-{
134
- IbexPlicState *s = opaque;
135
- int offset;
136
- uint32_t ret = 0;
137
-
138
- if (addr_between(addr, s->pending_base, s->pending_num)) {
139
- offset = (addr - s->pending_base) / 4;
140
- ret = s->pending[offset];
141
- } else if (addr_between(addr, s->source_base, s->source_num)) {
142
- qemu_log_mask(LOG_UNIMP,
143
- "%s: Interrupt source mode not supported\n", __func__);
144
- } else if (addr_between(addr, s->priority_base, s->priority_num)) {
145
- offset = (addr - s->priority_base) / 4;
146
- ret = s->priority[offset];
147
- } else if (addr_between(addr, s->enable_base, s->enable_num)) {
148
- offset = (addr - s->enable_base) / 4;
149
- ret = s->enable[offset];
150
- } else if (addr_between(addr, s->threshold_base, 1)) {
151
- ret = s->threshold;
152
- } else if (addr_between(addr, s->claim_base, 1)) {
153
- int pending_num = s->claim / 32;
154
- s->pending[pending_num] &= ~(1 << (s->claim % 32));
155
-
156
- /* Set the interrupt as claimed, but not completed */
157
- s->claimed[pending_num] |= 1 << (s->claim % 32);
158
-
159
- /* Return the current claimed interrupt */
160
- ret = s->claim;
161
-
162
- /* Clear the claimed interrupt */
163
- s->claim = 0x00000000;
164
-
165
- /* Update the interrupt status after the claim */
166
- ibex_plic_update(s);
167
- }
168
-
169
- return ret;
170
-}
171
-
172
-static void ibex_plic_write(void *opaque, hwaddr addr,
173
- uint64_t value, unsigned int size)
174
-{
175
- IbexPlicState *s = opaque;
176
-
177
- if (addr_between(addr, s->pending_base, s->pending_num)) {
178
- qemu_log_mask(LOG_GUEST_ERROR,
179
- "%s: Pending registers are read only\n", __func__);
180
- } else if (addr_between(addr, s->source_base, s->source_num)) {
181
- qemu_log_mask(LOG_UNIMP,
182
- "%s: Interrupt source mode not supported\n", __func__);
183
- } else if (addr_between(addr, s->priority_base, s->priority_num)) {
184
- uint32_t irq = ((addr - s->priority_base) >> 2) + 1;
185
- s->priority[irq] = value & 7;
186
- ibex_plic_update(s);
187
- } else if (addr_between(addr, s->enable_base, s->enable_num)) {
188
- uint32_t enable_reg = (addr - s->enable_base) / 4;
189
-
190
- s->enable[enable_reg] = value;
191
- } else if (addr_between(addr, s->threshold_base, 1)) {
192
- s->threshold = value & 3;
193
- } else if (addr_between(addr, s->claim_base, 1)) {
194
- if (s->claim == value) {
195
- /* Interrupt was completed */
196
- s->claim = 0;
197
- }
198
- if (s->claimed[value / 32] & 1 << (value % 32)) {
199
- int pending_num = value / 32;
200
-
201
- /* This value was already claimed, clear it. */
202
- s->claimed[pending_num] &= ~(1 << (value % 32));
203
-
204
- if (s->hidden_pending[pending_num] & (1 << (value % 32))) {
205
- /*
206
- * If the bit in hidden_pending is set then that means we
207
- * received an interrupt between claiming and completing
208
- * the interrupt that hasn't since been de-asserted.
209
- * On hardware this would trigger an interrupt, so let's
210
- * trigger one here as well.
211
- */
212
- s->pending[pending_num] |= 1 << (value % 32);
213
- }
214
- }
215
- }
216
-
217
- ibex_plic_update(s);
218
-}
219
-
220
-static const MemoryRegionOps ibex_plic_ops = {
221
- .read = ibex_plic_read,
222
- .write = ibex_plic_write,
223
- .endianness = DEVICE_NATIVE_ENDIAN,
224
- .valid = {
225
- .min_access_size = 4,
226
- .max_access_size = 4
227
- }
228
-};
229
-
230
-static void ibex_plic_irq_request(void *opaque, int irq, int level)
231
-{
232
- IbexPlicState *s = opaque;
233
-
234
- ibex_plic_irqs_set_pending(s, irq, level > 0);
235
- ibex_plic_update(s);
236
-}
237
-
238
-static Property ibex_plic_properties[] = {
239
- DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1),
240
- DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 176),
241
-
242
- DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0),
243
- DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 6),
244
-
245
- DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x18),
246
- DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 6),
247
-
248
- DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x30),
249
- DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 177),
250
-
251
- DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x300),
252
- DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 6),
253
-
254
- DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x318),
255
-
256
- DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x31c),
257
- DEFINE_PROP_END_OF_LIST(),
258
-};
259
-
260
-static void ibex_plic_init(Object *obj)
261
-{
262
- IbexPlicState *s = IBEX_PLIC(obj);
263
-
264
- memory_region_init_io(&s->mmio, obj, &ibex_plic_ops, s,
265
- TYPE_IBEX_PLIC, 0x400);
266
- sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
267
-}
268
-
269
-static void ibex_plic_realize(DeviceState *dev, Error **errp)
270
-{
271
- IbexPlicState *s = IBEX_PLIC(dev);
272
- int i;
273
-
274
- s->pending = g_new0(uint32_t, s->pending_num);
275
- s->hidden_pending = g_new0(uint32_t, s->pending_num);
276
- s->claimed = g_new0(uint32_t, s->pending_num);
277
- s->source = g_new0(uint32_t, s->source_num);
278
- s->priority = g_new0(uint32_t, s->priority_num);
279
- s->enable = g_new0(uint32_t, s->enable_num);
280
-
281
- qdev_init_gpio_in(dev, ibex_plic_irq_request, s->num_sources);
282
-
283
- s->external_irqs = g_malloc(sizeof(qemu_irq) * s->num_cpus);
284
- qdev_init_gpio_out(dev, s->external_irqs, s->num_cpus);
285
-
286
- /*
287
- * We can't allow the supervisor to control SEIP as this would allow the
288
- * supervisor to clear a pending external interrupt which will result in
289
- * a lost interrupt in the case a PLIC is attached. The SEIP bit must be
290
- * hardware controlled when a PLIC is attached.
291
- */
292
- MachineState *ms = MACHINE(qdev_get_machine());
293
- unsigned int smp_cpus = ms->smp.cpus;
294
- for (i = 0; i < smp_cpus; i++) {
295
- RISCVCPU *cpu = RISCV_CPU(qemu_get_cpu(i));
296
- if (riscv_cpu_claim_interrupts(cpu, MIP_SEIP) < 0) {
297
- error_report("SEIP already claimed");
298
- exit(1);
299
- }
300
- }
301
-
302
- msi_nonbroken = true;
303
-}
304
-
305
-static void ibex_plic_class_init(ObjectClass *klass, void *data)
306
-{
307
- DeviceClass *dc = DEVICE_CLASS(klass);
308
-
309
- dc->reset = ibex_plic_reset;
310
- device_class_set_props(dc, ibex_plic_properties);
311
- dc->realize = ibex_plic_realize;
312
-}
313
-
314
-static const TypeInfo ibex_plic_info = {
315
- .name = TYPE_IBEX_PLIC,
316
- .parent = TYPE_SYS_BUS_DEVICE,
317
- .instance_size = sizeof(IbexPlicState),
318
- .instance_init = ibex_plic_init,
319
- .class_init = ibex_plic_class_init,
320
-};
321
-
322
-static void ibex_plic_register_types(void)
323
-{
324
- type_register_static(&ibex_plic_info);
325
-}
326
-
327
-type_init(ibex_plic_register_types)
328
diff --git a/hw/intc/meson.build b/hw/intc/meson.build
329
index XXXXXXX..XXXXXXX 100644
330
--- a/hw/intc/meson.build
331
+++ b/hw/intc/meson.build
332
@@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_nvic.c'))
333
specific_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_vic.c'))
334
specific_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_gic.c', 'exynos4210_combiner.c'))
335
specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_irqmp.c'))
336
-specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_plic.c'))
337
specific_ss.add(when: 'CONFIG_IOAPIC', if_true: files('ioapic.c'))
338
specific_ss.add(when: 'CONFIG_LOONGSON_LIOINTC', if_true: files('loongson_liointc.c'))
339
specific_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gic.c'))
340
--
341
2.31.1
342
343
diff view generated by jsdifflib
Deleted patch
1
From: Alistair Francis <alistair.francis@wdc.com>
2
1
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
5
Message-id: 3c125e27c49a4969df82bf8b197535ccd1996939.1634524691.git.alistair.francis@wdc.com
6
---
7
hw/intc/sifive_plic.c | 30 +++++++++++++++---------------
8
1 file changed, 15 insertions(+), 15 deletions(-)
9
10
diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/sifive_plic.c
13
+++ b/hw/intc/sifive_plic.c
14
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps sifive_plic_ops = {
15
}
16
};
17
18
-static Property sifive_plic_properties[] = {
19
- DEFINE_PROP_STRING("hart-config", SiFivePLICState, hart_config),
20
- DEFINE_PROP_UINT32("hartid-base", SiFivePLICState, hartid_base, 0),
21
- DEFINE_PROP_UINT32("num-sources", SiFivePLICState, num_sources, 0),
22
- DEFINE_PROP_UINT32("num-priorities", SiFivePLICState, num_priorities, 0),
23
- DEFINE_PROP_UINT32("priority-base", SiFivePLICState, priority_base, 0),
24
- DEFINE_PROP_UINT32("pending-base", SiFivePLICState, pending_base, 0),
25
- DEFINE_PROP_UINT32("enable-base", SiFivePLICState, enable_base, 0),
26
- DEFINE_PROP_UINT32("enable-stride", SiFivePLICState, enable_stride, 0),
27
- DEFINE_PROP_UINT32("context-base", SiFivePLICState, context_base, 0),
28
- DEFINE_PROP_UINT32("context-stride", SiFivePLICState, context_stride, 0),
29
- DEFINE_PROP_UINT32("aperture-size", SiFivePLICState, aperture_size, 0),
30
- DEFINE_PROP_END_OF_LIST(),
31
-};
32
-
33
/*
34
* parse PLIC hart/mode address offset config
35
*
36
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_sifive_plic = {
37
}
38
};
39
40
+static Property sifive_plic_properties[] = {
41
+ DEFINE_PROP_STRING("hart-config", SiFivePLICState, hart_config),
42
+ DEFINE_PROP_UINT32("hartid-base", SiFivePLICState, hartid_base, 0),
43
+ DEFINE_PROP_UINT32("num-sources", SiFivePLICState, num_sources, 0),
44
+ DEFINE_PROP_UINT32("num-priorities", SiFivePLICState, num_priorities, 0),
45
+ DEFINE_PROP_UINT32("priority-base", SiFivePLICState, priority_base, 0),
46
+ DEFINE_PROP_UINT32("pending-base", SiFivePLICState, pending_base, 0),
47
+ DEFINE_PROP_UINT32("enable-base", SiFivePLICState, enable_base, 0),
48
+ DEFINE_PROP_UINT32("enable-stride", SiFivePLICState, enable_stride, 0),
49
+ DEFINE_PROP_UINT32("context-base", SiFivePLICState, context_base, 0),
50
+ DEFINE_PROP_UINT32("context-stride", SiFivePLICState, context_stride, 0),
51
+ DEFINE_PROP_UINT32("aperture-size", SiFivePLICState, aperture_size, 0),
52
+ DEFINE_PROP_END_OF_LIST(),
53
+};
54
+
55
static void sifive_plic_class_init(ObjectClass *klass, void *data)
56
{
57
DeviceClass *dc = DEVICE_CLASS(klass);
58
--
59
2.31.1
60
61
diff view generated by jsdifflib
Deleted patch
1
From: Alistair Francis <alistair.francis@wdc.com>
2
1
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
5
Message-id: b94c098cb221e744683349b1ac794c23102ef471.1634524691.git.alistair.francis@wdc.com
6
---
7
hw/intc/sifive_plic.c | 45 +++++++++++++++++++++++--------------------
8
1 file changed, 24 insertions(+), 21 deletions(-)
9
10
diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/sifive_plic.c
13
+++ b/hw/intc/sifive_plic.c
14
@@ -XXX,XX +XXX,XX @@ static void sifive_plic_irq_request(void *opaque, int irq, int level)
15
16
static void sifive_plic_realize(DeviceState *dev, Error **errp)
17
{
18
- SiFivePLICState *plic = SIFIVE_PLIC(dev);
19
+ SiFivePLICState *s = SIFIVE_PLIC(dev);
20
int i;
21
22
- memory_region_init_io(&plic->mmio, OBJECT(dev), &sifive_plic_ops, plic,
23
- TYPE_SIFIVE_PLIC, plic->aperture_size);
24
- parse_hart_config(plic);
25
- plic->bitfield_words = (plic->num_sources + 31) >> 5;
26
- plic->num_enables = plic->bitfield_words * plic->num_addrs;
27
- plic->source_priority = g_new0(uint32_t, plic->num_sources);
28
- plic->target_priority = g_new(uint32_t, plic->num_addrs);
29
- plic->pending = g_new0(uint32_t, plic->bitfield_words);
30
- plic->claimed = g_new0(uint32_t, plic->bitfield_words);
31
- plic->enable = g_new0(uint32_t, plic->num_enables);
32
- sysbus_init_mmio(SYS_BUS_DEVICE(dev), &plic->mmio);
33
- qdev_init_gpio_in(dev, sifive_plic_irq_request, plic->num_sources);
34
-
35
- plic->s_external_irqs = g_malloc(sizeof(qemu_irq) * plic->num_harts);
36
- qdev_init_gpio_out(dev, plic->s_external_irqs, plic->num_harts);
37
-
38
- plic->m_external_irqs = g_malloc(sizeof(qemu_irq) * plic->num_harts);
39
- qdev_init_gpio_out(dev, plic->m_external_irqs, plic->num_harts);
40
+ memory_region_init_io(&s->mmio, OBJECT(dev), &sifive_plic_ops, s,
41
+ TYPE_SIFIVE_PLIC, s->aperture_size);
42
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
43
+
44
+ parse_hart_config(s);
45
+
46
+ s->bitfield_words = (s->num_sources + 31) >> 5;
47
+ s->num_enables = s->bitfield_words * s->num_addrs;
48
+ s->source_priority = g_new0(uint32_t, s->num_sources);
49
+ s->target_priority = g_new(uint32_t, s->num_addrs);
50
+ s->pending = g_new0(uint32_t, s->bitfield_words);
51
+ s->claimed = g_new0(uint32_t, s->bitfield_words);
52
+ s->enable = g_new0(uint32_t, s->num_enables);
53
+
54
+ qdev_init_gpio_in(dev, sifive_plic_irq_request, s->num_sources);
55
+
56
+ s->s_external_irqs = g_malloc(sizeof(qemu_irq) * s->num_harts);
57
+ qdev_init_gpio_out(dev, s->s_external_irqs, s->num_harts);
58
+
59
+ s->m_external_irqs = g_malloc(sizeof(qemu_irq) * s->num_harts);
60
+ qdev_init_gpio_out(dev, s->m_external_irqs, s->num_harts);
61
62
/* We can't allow the supervisor to control SEIP as this would allow the
63
* supervisor to clear a pending external interrupt which will result in
64
* lost a interrupt in the case a PLIC is attached. The SEIP bit must be
65
* hardware controlled when a PLIC is attached.
66
*/
67
- for (i = 0; i < plic->num_harts; i++) {
68
- RISCVCPU *cpu = RISCV_CPU(qemu_get_cpu(plic->hartid_base + i));
69
+ for (i = 0; i < s->num_harts; i++) {
70
+ RISCVCPU *cpu = RISCV_CPU(qemu_get_cpu(s->hartid_base + i));
71
if (riscv_cpu_claim_interrupts(cpu, MIP_SEIP) < 0) {
72
error_report("SEIP already claimed");
73
exit(1);
74
--
75
2.31.1
76
77
diff view generated by jsdifflib