1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: |
---|---|---|---|
2 | 2 | ||
3 | The following changes since commit 2c89b5af5e72ab8c9d544c6e30399528b2238827: | 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/pmaydell/tags/pull-target-arm-20220120-1' into staging (2022-01-20 16:13:17 +0000) | ||
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-20220121-1 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 |
10 | 8 | ||
11 | for you to fetch changes up to f297245f6a780f496fb171af6fcd21ff3e6783c3: | 9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: |
12 | 10 | ||
13 | target/riscv: Relax UXL field for debugging (2022-01-21 15:52:57 +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 | Third RISC-V PR for QEMU 7.0 | 14 | RISC-V PR for 9.1 |
17 | 15 | ||
18 | * Fixes for OpenTitan timer | 16 | * APLICs add child earlier than realize |
19 | * Correction of OpenTitan PLIC stride length | 17 | * Fix exposure of Zkr |
20 | * RISC-V KVM support | 18 | * Raise exceptions on wrs.nto |
21 | * Device tree code cleanup | 19 | * Implement SBI debug console (DBCN) calls for KVM |
22 | * Support for the Zve64f and Zve32f extensions | 20 | * Support 64-bit addresses for initrd |
23 | * OpenSBI binary loading support for the Spike machine | 21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 |
24 | * Removal of OpenSBI ELFs | 22 | * Tolerate KVM disable ext errors |
25 | * Support for the UXL field in xstatus | 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 | ||
26 | 43 | ||
27 | ---------------------------------------------------------------- | 44 | ---------------------------------------------------------------- |
28 | Anup Patel (3): | 45 | Alexei Filippov (1): |
29 | hw/riscv: spike: Allow using binary firmware as bios | 46 | target/riscv: do not set mtval2 for non guest-page faults |
30 | hw/riscv: Remove macros for ELF BIOS image names | ||
31 | roms/opensbi: Remove ELF images | ||
32 | 47 | ||
33 | Frank Chang (17): | 48 | Alistair Francis (2): |
34 | target/riscv: rvv-1.0: Add Zve64f extension into RISC-V | 49 | target/riscv: rvzicbo: Fixup CBO extension register calculation |
35 | target/riscv: rvv-1.0: Add Zve64f support for configuration insns | 50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs |
36 | target/riscv: rvv-1.0: Add Zve64f support for load and store insns | ||
37 | target/riscv: rvv-1.0: Add Zve64f support for vmulh variant insns | ||
38 | target/riscv: rvv-1.0: Add Zve64f support for vsmul.vv and vsmul.vx insns | ||
39 | target/riscv: rvv-1.0: Add Zve64f support for scalar fp insns | ||
40 | target/riscv: rvv-1.0: Add Zve64f support for single-width fp reduction insns | ||
41 | target/riscv: rvv-1.0: Add Zve64f support for widening type-convert insns | ||
42 | target/riscv: rvv-1.0: Add Zve64f support for narrowing type-convert insns | ||
43 | target/riscv: rvv-1.0: Allow Zve64f extension to be turned on | ||
44 | target/riscv: rvv-1.0: Add Zve32f extension into RISC-V | ||
45 | target/riscv: rvv-1.0: Add Zve32f support for configuration insns | ||
46 | target/riscv: rvv-1.0: Add Zve32f support for scalar fp insns | ||
47 | target/riscv: rvv-1.0: Add Zve32f support for single-width fp reduction insns | ||
48 | target/riscv: rvv-1.0: Add Zve32f support for widening type-convert insns | ||
49 | target/riscv: rvv-1.0: Add Zve32f support for narrowing type-convert insns | ||
50 | target/riscv: rvv-1.0: Allow Zve32f extension to be turned on | ||
51 | 51 | ||
52 | LIU Zhiwei (23): | 52 | Andrew Jones (2): |
53 | target/riscv: Adjust pmpcfg access with mxl | 53 | target/riscv/kvm: Fix exposure of Zkr |
54 | target/riscv: Don't save pc when exception return | 54 | target/riscv: Raise exceptions on wrs.nto |
55 | target/riscv: Sign extend link reg for jal and jalr | ||
56 | target/riscv: Sign extend pc for different XLEN | ||
57 | target/riscv: Create xl field in env | ||
58 | target/riscv: Ignore the pc bits above XLEN | ||
59 | target/riscv: Extend pc for runtime pc write | ||
60 | target/riscv: Use gdb xml according to max mxlen | ||
61 | target/riscv: Relax debug check for pm write | ||
62 | target/riscv: Adjust csr write mask with XLEN | ||
63 | target/riscv: Create current pm fields in env | ||
64 | target/riscv: Alloc tcg global for cur_pm[mask|base] | ||
65 | target/riscv: Calculate address according to XLEN | ||
66 | target/riscv: Split pm_enabled into mask and base | ||
67 | target/riscv: Split out the vill from vtype | ||
68 | target/riscv: Adjust vsetvl according to XLEN | ||
69 | target/riscv: Remove VILL field in VTYPE | ||
70 | target/riscv: Fix check range for first fault only | ||
71 | target/riscv: Adjust vector address with mask | ||
72 | target/riscv: Adjust scalar reg in vector with XLEN | ||
73 | target/riscv: Set default XLEN for hypervisor | ||
74 | target/riscv: Enable uxl field write | ||
75 | target/riscv: Relax UXL field for debugging | ||
76 | 55 | ||
77 | Thomas Huth (1): | 56 | Cheng Yang (1): |
78 | softmmu/device_tree: Silence compiler warning with --enable-sanitizers | 57 | hw/riscv/boot.c: Support 64-bit address for initrd |
79 | 58 | ||
80 | Wilfred Mallawa (3): | 59 | Christoph Müllner (1): |
81 | hw: timer: ibex_timer: Fixup reading w/o register | 60 | riscv: thead: Add th.sxstatus CSR emulation |
82 | riscv: opentitan: fixup plic stride len | ||
83 | hw: timer: ibex_timer: update/add reg address | ||
84 | 61 | ||
85 | Yanan Wang (1): | 62 | Clément Léger (1): |
86 | softmmu/device_tree: Remove redundant pointer assignment | 63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 |
87 | 64 | ||
88 | Yifei Jiang (13): | 65 | Daniel Henrique Barboza (6): |
89 | update-linux-headers: Add asm-riscv/kvm.h | 66 | target/riscv/kvm: implement SBI debug console (DBCN) calls |
90 | target/riscv: Add target/riscv/kvm.c to place the public kvm interface | 67 | target/riscv/kvm: tolerate KVM disable ext errors |
91 | target/riscv: Implement function kvm_arch_init_vcpu | 68 | target/riscv/debug: set tval=pc in breakpoint exceptions |
92 | target/riscv: Implement kvm_arch_get_registers | 69 | trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint |
93 | target/riscv: Implement kvm_arch_put_registers | 70 | target/riscv: prioritize pmp errors in raise_mmu_exception() |
94 | target/riscv: Support start kernel directly by KVM | 71 | riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature() |
95 | target/riscv: Support setting external interrupt by KVM | ||
96 | target/riscv: Handle KVM_EXIT_RISCV_SBI exit | ||
97 | target/riscv: Add host cpu type | ||
98 | target/riscv: Add kvm_riscv_get/put_regs_timer | ||
99 | target/riscv: Implement virtual time adjusting with vm state changing | ||
100 | target/riscv: Support virtual time context synchronization | ||
101 | target/riscv: enable riscv kvm accel | ||
102 | 72 | ||
103 | meson.build | 2 + | 73 | Huang Tao (2): |
104 | include/hw/char/riscv_htif.h | 5 +- | 74 | target/riscv: Fix the element agnostic function problem |
105 | include/hw/riscv/boot.h | 3 +- | 75 | target/riscv: Implement dynamic establishment of custom decoder |
106 | include/hw/riscv/spike.h | 1 + | 76 | |
107 | include/hw/timer/ibex_timer.h | 1 - | 77 | Jason Chien (3): |
108 | linux-headers/asm-riscv/kvm.h | 128 ++++++ | 78 | target/riscv: Add support for Zve32x extension |
109 | target/riscv/cpu.h | 58 ++- | 79 | target/riscv: Add support for Zve64x extension |
110 | target/riscv/cpu_bits.h | 3 + | 80 | target/riscv: Relax vector register check in RISCV gdbstub |
111 | target/riscv/helper.h | 4 +- | 81 | |
112 | target/riscv/kvm_riscv.h | 25 ++ | 82 | Max Chou (4): |
113 | target/riscv/sbi_ecall_interface.h | 72 ++++ | 83 | target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions |
114 | hw/char/riscv_htif.c | 33 +- | 84 | target/riscv: rvv: Check single width operator for vector fp widen instructions |
115 | hw/intc/sifive_plic.c | 20 +- | 85 | target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w |
116 | hw/riscv/boot.c | 16 +- | 86 | target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions |
117 | hw/riscv/opentitan.c | 2 +- | 87 | |
118 | hw/riscv/spike.c | 45 ++- | 88 | Rob Bradford (1): |
119 | hw/riscv/virt.c | 83 ++-- | 89 | target/riscv: Remove experimental prefix from "B" extension |
120 | hw/timer/ibex_timer.c | 25 +- | 90 | |
121 | softmmu/device_tree.c | 11 +- | 91 | Yangyu Chen (1): |
122 | target/riscv/cpu.c | 77 +++- | 92 | target/riscv/cpu.c: fix Zvkb extension config |
123 | target/riscv/cpu_helper.c | 99 ++--- | 93 | |
124 | target/riscv/csr.c | 90 ++++- | 94 | Yong-Xuan Wang (1): |
125 | target/riscv/gdbstub.c | 71 +++- | 95 | target/riscv/kvm.c: Fix the hart bit setting of AIA |
126 | target/riscv/kvm-stub.c | 30 ++ | 96 | |
127 | target/riscv/kvm.c | 535 +++++++++++++++++++++++++ | 97 | Yu-Ming Chang (1): |
128 | target/riscv/machine.c | 46 ++- | 98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR |
129 | target/riscv/op_helper.c | 7 +- | 99 | |
130 | target/riscv/pmp.c | 12 +- | 100 | yang.zhang (1): |
131 | target/riscv/translate.c | 94 +++-- | 101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize |
132 | target/riscv/vector_helper.c | 39 +- | 102 | |
133 | target/riscv/insn_trans/trans_privileged.c.inc | 9 +- | 103 | MAINTAINERS | 1 + |
134 | target/riscv/insn_trans/trans_rva.c.inc | 9 +- | 104 | target/riscv/cpu.h | 11 ++ |
135 | target/riscv/insn_trans/trans_rvd.c.inc | 19 +- | 105 | target/riscv/cpu_bits.h | 2 +- |
136 | target/riscv/insn_trans/trans_rvf.c.inc | 19 +- | 106 | target/riscv/cpu_cfg.h | 2 + |
137 | target/riscv/insn_trans/trans_rvi.c.inc | 39 +- | 107 | target/riscv/helper.h | 1 + |
138 | target/riscv/insn_trans/trans_rvv.c.inc | 225 +++++++++-- | 108 | target/riscv/sbi_ecall_interface.h | 17 +++ |
139 | .gitlab-ci.d/opensbi.yml | 2 - | 109 | target/riscv/tcg/tcg-cpu.h | 15 +++ |
140 | pc-bios/meson.build | 2 - | 110 | disas/riscv.c | 65 +++++++++- |
141 | pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | Bin 838904 -> 0 bytes | 111 | hw/intc/riscv_aplic.c | 8 +- |
142 | pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | Bin 934696 -> 0 bytes | 112 | hw/riscv/boot.c | 4 +- |
143 | roms/Makefile | 2 - | 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 ++- | ||
144 | target/riscv/meson.build | 1 + | 128 | target/riscv/meson.build | 1 + |
145 | 42 files changed, 1608 insertions(+), 356 deletions(-) | 129 | 26 files changed, 596 insertions(+), 109 deletions(-) |
146 | create mode 100644 linux-headers/asm-riscv/kvm.h | 130 | create mode 100644 target/riscv/th_csr.c |
147 | create mode 100644 target/riscv/kvm_riscv.h | ||
148 | create mode 100644 target/riscv/sbi_ecall_interface.h | ||
149 | create mode 100644 target/riscv/kvm-stub.c | ||
150 | create mode 100644 target/riscv/kvm.c | ||
151 | delete mode 100644 pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | ||
152 | delete mode 100644 pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | ||
153 | 131 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
2 | 1 | ||
3 | This change fixes a bug where a write only register is read. | ||
4 | As per https://docs.opentitan.org/hw/ip/rv_timer/doc/#register-table | ||
5 | the 'INTR_TEST0' register is write only. | ||
6 | |||
7 | Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20220110051606.4031241-1-alistair.francis@opensource.wdc.com | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | include/hw/timer/ibex_timer.h | 1 - | ||
15 | hw/timer/ibex_timer.c | 14 +++++--------- | ||
16 | 2 files changed, 5 insertions(+), 10 deletions(-) | ||
17 | |||
18 | diff --git a/include/hw/timer/ibex_timer.h b/include/hw/timer/ibex_timer.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/hw/timer/ibex_timer.h | ||
21 | +++ b/include/hw/timer/ibex_timer.h | ||
22 | @@ -XXX,XX +XXX,XX @@ struct IbexTimerState { | ||
23 | uint32_t timer_compare_upper0; | ||
24 | uint32_t timer_intr_enable; | ||
25 | uint32_t timer_intr_state; | ||
26 | - uint32_t timer_intr_test; | ||
27 | |||
28 | uint32_t timebase_freq; | ||
29 | |||
30 | diff --git a/hw/timer/ibex_timer.c b/hw/timer/ibex_timer.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/timer/ibex_timer.c | ||
33 | +++ b/hw/timer/ibex_timer.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void ibex_timer_reset(DeviceState *dev) | ||
35 | s->timer_compare_upper0 = 0xFFFFFFFF; | ||
36 | s->timer_intr_enable = 0x00000000; | ||
37 | s->timer_intr_state = 0x00000000; | ||
38 | - s->timer_intr_test = 0x00000000; | ||
39 | |||
40 | ibex_timer_update_irqs(s); | ||
41 | } | ||
42 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_timer_read(void *opaque, hwaddr addr, | ||
43 | retvalue = s->timer_intr_state; | ||
44 | break; | ||
45 | case R_INTR_TEST: | ||
46 | - retvalue = s->timer_intr_test; | ||
47 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
48 | + "Attempted to read INTR_TEST, a write only register"); | ||
49 | break; | ||
50 | default: | ||
51 | qemu_log_mask(LOG_GUEST_ERROR, | ||
52 | @@ -XXX,XX +XXX,XX @@ static void ibex_timer_write(void *opaque, hwaddr addr, | ||
53 | s->timer_intr_state &= ~val; | ||
54 | break; | ||
55 | case R_INTR_TEST: | ||
56 | - s->timer_intr_test = val; | ||
57 | - if (s->timer_intr_enable & | ||
58 | - s->timer_intr_test & | ||
59 | - R_INTR_ENABLE_IE_0_MASK) { | ||
60 | + if (s->timer_intr_enable & val & R_INTR_ENABLE_IE_0_MASK) { | ||
61 | s->timer_intr_state |= R_INTR_STATE_IS_0_MASK; | ||
62 | qemu_set_irq(s->irq, true); | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static int ibex_timer_post_load(void *opaque, int version_id) | ||
65 | |||
66 | static const VMStateDescription vmstate_ibex_timer = { | ||
67 | .name = TYPE_IBEX_TIMER, | ||
68 | - .version_id = 1, | ||
69 | - .minimum_version_id = 1, | ||
70 | + .version_id = 2, | ||
71 | + .minimum_version_id = 2, | ||
72 | .post_load = ibex_timer_post_load, | ||
73 | .fields = (VMStateField[]) { | ||
74 | VMSTATE_UINT32(timer_ctrl, IbexTimerState), | ||
75 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ibex_timer = { | ||
76 | VMSTATE_UINT32(timer_compare_upper0, IbexTimerState), | ||
77 | VMSTATE_UINT32(timer_intr_enable, IbexTimerState), | ||
78 | VMSTATE_UINT32(timer_intr_state, IbexTimerState), | ||
79 | - VMSTATE_UINT32(timer_intr_test, IbexTimerState), | ||
80 | VMSTATE_END_OF_LIST() | ||
81 | } | ||
82 | }; | ||
83 | -- | ||
84 | 2.31.1 | ||
85 | |||
86 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
2 | 1 | ||
3 | The following change was made to rectify incorrectly set stride length | ||
4 | on the PLIC [1]. Where it should be 32bit and not 24bit (0x18). This was | ||
5 | discovered whilst attempting to fix a bug where a timer_interrupt was | ||
6 | not serviced on TockOS-OpenTitan. | ||
7 | |||
8 | [1] https://docs.opentitan.org/hw/top_earlgrey/ip_autogen/rv_plic/doc/ | ||
9 | |||
10 | Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Tested-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | Message-id: 20220111071025.4169189-1-alistair.francis@opensource.wdc.com | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | hw/riscv/opentitan.c | 2 +- | ||
18 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
19 | |||
20 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/riscv/opentitan.c | ||
23 | +++ b/hw/riscv/opentitan.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | ||
25 | qdev_prop_set_uint32(DEVICE(&s->plic), "priority-base", 0x00); | ||
26 | qdev_prop_set_uint32(DEVICE(&s->plic), "pending-base", 0x1000); | ||
27 | qdev_prop_set_uint32(DEVICE(&s->plic), "enable-base", 0x2000); | ||
28 | - qdev_prop_set_uint32(DEVICE(&s->plic), "enable-stride", 0x18); | ||
29 | + qdev_prop_set_uint32(DEVICE(&s->plic), "enable-stride", 32); | ||
30 | qdev_prop_set_uint32(DEVICE(&s->plic), "context-base", 0x200000); | ||
31 | qdev_prop_set_uint32(DEVICE(&s->plic), "context-stride", 8); | ||
32 | qdev_prop_set_uint32(DEVICE(&s->plic), "aperture-size", memmap[IBEX_DEV_PLIC].size); | ||
33 | -- | ||
34 | 2.31.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
2 | 1 | ||
3 | The following changes: | ||
4 | 1. Fixes the incorrectly set CTRL register address. As | ||
5 | per [1] https://docs.opentitan.org/hw/ip/rv_timer/doc/#register-table | ||
6 | |||
7 | The CTRL register is @ 0x04. | ||
8 | |||
9 | This was found when attempting to fixup a bug where a timer_interrupt | ||
10 | was not serviced on TockOS-OpenTitan. | ||
11 | |||
12 | 2. Adds ALERT_TEST register as documented on [1], adding repective | ||
13 | switch cases to error handle and later implement functionality. | ||
14 | |||
15 | Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Tested-by: Alistair Francis <alistair.francis@wdc.com> | ||
18 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
19 | Message-id: 20220111071025.4169189-2-alistair.francis@opensource.wdc.com | ||
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | --- | ||
22 | hw/timer/ibex_timer.c | 11 ++++++++++- | ||
23 | 1 file changed, 10 insertions(+), 1 deletion(-) | ||
24 | |||
25 | diff --git a/hw/timer/ibex_timer.c b/hw/timer/ibex_timer.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/timer/ibex_timer.c | ||
28 | +++ b/hw/timer/ibex_timer.c | ||
29 | @@ -XXX,XX +XXX,XX @@ | ||
30 | #include "target/riscv/cpu.h" | ||
31 | #include "migration/vmstate.h" | ||
32 | |||
33 | -REG32(CTRL, 0x00) | ||
34 | +REG32(ALERT_TEST, 0x00) | ||
35 | + FIELD(ALERT_TEST, FATAL_FAULT, 0, 1) | ||
36 | +REG32(CTRL, 0x04) | ||
37 | FIELD(CTRL, ACTIVE, 0, 1) | ||
38 | REG32(CFG0, 0x100) | ||
39 | FIELD(CFG0, PRESCALE, 0, 12) | ||
40 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_timer_read(void *opaque, hwaddr addr, | ||
41 | uint64_t retvalue = 0; | ||
42 | |||
43 | switch (addr >> 2) { | ||
44 | + case R_ALERT_TEST: | ||
45 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
46 | + "Attempted to read ALERT_TEST, a write only register"); | ||
47 | + break; | ||
48 | case R_CTRL: | ||
49 | retvalue = s->timer_ctrl; | ||
50 | break; | ||
51 | @@ -XXX,XX +XXX,XX @@ static void ibex_timer_write(void *opaque, hwaddr addr, | ||
52 | uint32_t val = val64; | ||
53 | |||
54 | switch (addr >> 2) { | ||
55 | + case R_ALERT_TEST: | ||
56 | + qemu_log_mask(LOG_UNIMP, "Alert triggering not supported"); | ||
57 | + break; | ||
58 | case R_CTRL: | ||
59 | s->timer_ctrl = val; | ||
60 | break; | ||
61 | -- | ||
62 | 2.31.1 | ||
63 | |||
64 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Add asm-riscv/kvm.h for RISC-V KVM. | ||
4 | |||
5 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
6 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
9 | Message-id: 20220112081329.1835-2-jiangyifei@huawei.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | linux-headers/asm-riscv/kvm.h | 128 ++++++++++++++++++++++++++++++++++ | ||
13 | 1 file changed, 128 insertions(+) | ||
14 | create mode 100644 linux-headers/asm-riscv/kvm.h | ||
15 | |||
16 | diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h | ||
17 | new file mode 100644 | ||
18 | index XXXXXXX..XXXXXXX | ||
19 | --- /dev/null | ||
20 | +++ b/linux-headers/asm-riscv/kvm.h | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
23 | +/* | ||
24 | + * Copyright (C) 2019 Western Digital Corporation or its affiliates. | ||
25 | + * | ||
26 | + * Authors: | ||
27 | + * Anup Patel <anup.patel@wdc.com> | ||
28 | + */ | ||
29 | + | ||
30 | +#ifndef __LINUX_KVM_RISCV_H | ||
31 | +#define __LINUX_KVM_RISCV_H | ||
32 | + | ||
33 | +#ifndef __ASSEMBLY__ | ||
34 | + | ||
35 | +#include <linux/types.h> | ||
36 | +#include <asm/ptrace.h> | ||
37 | + | ||
38 | +#define __KVM_HAVE_READONLY_MEM | ||
39 | + | ||
40 | +#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 | ||
41 | + | ||
42 | +#define KVM_INTERRUPT_SET -1U | ||
43 | +#define KVM_INTERRUPT_UNSET -2U | ||
44 | + | ||
45 | +/* for KVM_GET_REGS and KVM_SET_REGS */ | ||
46 | +struct kvm_regs { | ||
47 | +}; | ||
48 | + | ||
49 | +/* for KVM_GET_FPU and KVM_SET_FPU */ | ||
50 | +struct kvm_fpu { | ||
51 | +}; | ||
52 | + | ||
53 | +/* KVM Debug exit structure */ | ||
54 | +struct kvm_debug_exit_arch { | ||
55 | +}; | ||
56 | + | ||
57 | +/* for KVM_SET_GUEST_DEBUG */ | ||
58 | +struct kvm_guest_debug_arch { | ||
59 | +}; | ||
60 | + | ||
61 | +/* definition of registers in kvm_run */ | ||
62 | +struct kvm_sync_regs { | ||
63 | +}; | ||
64 | + | ||
65 | +/* for KVM_GET_SREGS and KVM_SET_SREGS */ | ||
66 | +struct kvm_sregs { | ||
67 | +}; | ||
68 | + | ||
69 | +/* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ | ||
70 | +struct kvm_riscv_config { | ||
71 | + unsigned long isa; | ||
72 | +}; | ||
73 | + | ||
74 | +/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ | ||
75 | +struct kvm_riscv_core { | ||
76 | + struct user_regs_struct regs; | ||
77 | + unsigned long mode; | ||
78 | +}; | ||
79 | + | ||
80 | +/* Possible privilege modes for kvm_riscv_core */ | ||
81 | +#define KVM_RISCV_MODE_S 1 | ||
82 | +#define KVM_RISCV_MODE_U 0 | ||
83 | + | ||
84 | +/* CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ | ||
85 | +struct kvm_riscv_csr { | ||
86 | + unsigned long sstatus; | ||
87 | + unsigned long sie; | ||
88 | + unsigned long stvec; | ||
89 | + unsigned long sscratch; | ||
90 | + unsigned long sepc; | ||
91 | + unsigned long scause; | ||
92 | + unsigned long stval; | ||
93 | + unsigned long sip; | ||
94 | + unsigned long satp; | ||
95 | + unsigned long scounteren; | ||
96 | +}; | ||
97 | + | ||
98 | +/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ | ||
99 | +struct kvm_riscv_timer { | ||
100 | + __u64 frequency; | ||
101 | + __u64 time; | ||
102 | + __u64 compare; | ||
103 | + __u64 state; | ||
104 | +}; | ||
105 | + | ||
106 | +/* Possible states for kvm_riscv_timer */ | ||
107 | +#define KVM_RISCV_TIMER_STATE_OFF 0 | ||
108 | +#define KVM_RISCV_TIMER_STATE_ON 1 | ||
109 | + | ||
110 | +#define KVM_REG_SIZE(id) \ | ||
111 | + (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) | ||
112 | + | ||
113 | +/* If you need to interpret the index values, here is the key: */ | ||
114 | +#define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 | ||
115 | +#define KVM_REG_RISCV_TYPE_SHIFT 24 | ||
116 | + | ||
117 | +/* Config registers are mapped as type 1 */ | ||
118 | +#define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT) | ||
119 | +#define KVM_REG_RISCV_CONFIG_REG(name) \ | ||
120 | + (offsetof(struct kvm_riscv_config, name) / sizeof(unsigned long)) | ||
121 | + | ||
122 | +/* Core registers are mapped as type 2 */ | ||
123 | +#define KVM_REG_RISCV_CORE (0x02 << KVM_REG_RISCV_TYPE_SHIFT) | ||
124 | +#define KVM_REG_RISCV_CORE_REG(name) \ | ||
125 | + (offsetof(struct kvm_riscv_core, name) / sizeof(unsigned long)) | ||
126 | + | ||
127 | +/* Control and status registers are mapped as type 3 */ | ||
128 | +#define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT) | ||
129 | +#define KVM_REG_RISCV_CSR_REG(name) \ | ||
130 | + (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long)) | ||
131 | + | ||
132 | +/* Timer registers are mapped as type 4 */ | ||
133 | +#define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT) | ||
134 | +#define KVM_REG_RISCV_TIMER_REG(name) \ | ||
135 | + (offsetof(struct kvm_riscv_timer, name) / sizeof(__u64)) | ||
136 | + | ||
137 | +/* F extension registers are mapped as type 5 */ | ||
138 | +#define KVM_REG_RISCV_FP_F (0x05 << KVM_REG_RISCV_TYPE_SHIFT) | ||
139 | +#define KVM_REG_RISCV_FP_F_REG(name) \ | ||
140 | + (offsetof(struct __riscv_f_ext_state, name) / sizeof(__u32)) | ||
141 | + | ||
142 | +/* D extension registers are mapped as type 6 */ | ||
143 | +#define KVM_REG_RISCV_FP_D (0x06 << KVM_REG_RISCV_TYPE_SHIFT) | ||
144 | +#define KVM_REG_RISCV_FP_D_REG(name) \ | ||
145 | + (offsetof(struct __riscv_d_ext_state, name) / sizeof(__u64)) | ||
146 | + | ||
147 | +#endif | ||
148 | + | ||
149 | +#endif /* __LINUX_KVM_RISCV_H */ | ||
150 | -- | ||
151 | 2.31.1 | ||
152 | |||
153 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: "yang.zhang" <yang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 3 | Since only root APLICs can have hw IRQ lines, aplic->parent should |
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 4 | be initialized first. |
5 | Message-id: 20220120122050.41546-24-zhiwei_liu@c-sky.com | 5 | |
6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> | ||
9 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 12 | --- |
8 | target/riscv/csr.c | 8 ++++---- | 13 | hw/intc/riscv_aplic.c | 8 ++++---- |
9 | 1 file changed, 4 insertions(+), 4 deletions(-) | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
10 | 15 | ||
11 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
12 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/csr.c | 18 | --- a/hw/intc/riscv_aplic.c |
14 | +++ b/target/riscv/csr.c | 19 | +++ b/hw/intc/riscv_aplic.c |
15 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | 20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
16 | MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR | | 21 | qdev_prop_set_bit(dev, "msimode", msimode); |
17 | MSTATUS_TW | MSTATUS_VS; | 22 | qdev_prop_set_bit(dev, "mmode", mmode); |
18 | 23 | ||
19 | - if (xl != MXL_RV32) { | 24 | + if (parent) { |
20 | + if (xl != MXL_RV32 || env->debugger) { | 25 | + riscv_aplic_add_child(parent, dev); |
21 | /* | 26 | + } |
22 | * RV32: MPV and GVA are not in mstatus. The current plan is to | 27 | + |
23 | * add them to mstatush. For now, we just don't support it. | 28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
24 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno, | 29 | |
25 | { | 30 | if (!is_kvm_aia(msimode)) { |
26 | uint64_t mask = sstatus_v1_10_mask; | 31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); |
27 | uint64_t sstatus = env->mstatus & mask; | ||
28 | - if (env->xl != MXL_RV32) { | ||
29 | + if (env->xl != MXL_RV32 || env->debugger) { | ||
30 | mask |= SSTATUS64_UXL; | ||
31 | } | 32 | } |
32 | 33 | ||
33 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, | 34 | - if (parent) { |
34 | target_ulong *val) | 35 | - riscv_aplic_add_child(parent, dev); |
35 | { | 36 | - } |
36 | target_ulong mask = (sstatus_v1_10_mask); | 37 | - |
37 | - if (env->xl != MXL_RV32) { | 38 | if (!msimode) { |
38 | + if (env->xl != MXL_RV32 || env->debugger) { | 39 | for (i = 0; i < num_harts; i++) { |
39 | mask |= SSTATUS64_UXL; | 40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); |
40 | } | ||
41 | /* TODO: Use SXL not MXL. */ | ||
42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno, | ||
43 | { | ||
44 | target_ulong mask = (sstatus_v1_10_mask); | ||
45 | |||
46 | - if (env->xl != MXL_RV32) { | ||
47 | + if (env->xl != MXL_RV32 || env->debugger) { | ||
48 | if ((val & SSTATUS64_UXL) != 0) { | ||
49 | mask |= SSTATUS64_UXL; | ||
50 | } | ||
51 | -- | 41 | -- |
52 | 2.31.1 | 42 | 2.45.1 |
53 | |||
54 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | We need not specially process vtype when XLEN changes. | 3 | The Zkr extension may only be exposed to KVM guests if the VMM |
4 | implements the SEED CSR. Use the same implementation as TCG. | ||
4 | 5 | ||
5 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 6 | Without this patch, running with a KVM which does not forward the |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | SEED CSR access to QEMU will result in an ILL exception being |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | injected into the guest (this results in Linux guests crashing on |
8 | Message-id: 20220120122050.41546-16-zhiwei_liu@c-sky.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> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 18 | --- |
11 | target/riscv/cpu.h | 1 + | 19 | target/riscv/cpu.h | 3 +++ |
12 | target/riscv/cpu_helper.c | 3 +-- | 20 | target/riscv/csr.c | 18 ++++++++++++++---- |
13 | target/riscv/csr.c | 13 ++++++++++++- | 21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ |
14 | target/riscv/machine.c | 5 +++-- | 22 | 3 files changed, 42 insertions(+), 4 deletions(-) |
15 | target/riscv/vector_helper.c | 3 ++- | ||
16 | 5 files changed, 19 insertions(+), 6 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 @@ struct CPURISCVState { | 28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); |
23 | target_ulong vl; | 29 | |
24 | target_ulong vstart; | 30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); |
25 | target_ulong vtype; | 31 | |
26 | + bool vill; | 32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, |
27 | 33 | + target_ulong write_mask); | |
28 | target_ulong pc; | 34 | + |
29 | target_ulong load_res; | 35 | uint8_t satp_mode_max_from_map(uint32_t map); |
30 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
31 | index XXXXXXX..XXXXXXX 100644 | 37 | |
32 | --- a/target/riscv/cpu_helper.c | ||
33 | +++ b/target/riscv/cpu_helper.c | ||
34 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
35 | uint32_t maxsz = vlmax << sew; | ||
36 | bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl) && | ||
37 | (maxsz >= 8); | ||
38 | - flags = FIELD_DP32(flags, TB_FLAGS, VILL, | ||
39 | - FIELD_EX64(env->vtype, VTYPE, VILL)); | ||
40 | + flags = FIELD_DP32(flags, TB_FLAGS, VILL, env->vill); | ||
41 | flags = FIELD_DP32(flags, TB_FLAGS, SEW, sew); | ||
42 | flags = FIELD_DP32(flags, TB_FLAGS, LMUL, | ||
43 | FIELD_EX64(env->vtype, VTYPE, VLMUL)); | ||
44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
45 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/target/riscv/csr.c | 40 | --- a/target/riscv/csr.c |
47 | +++ b/target/riscv/csr.c | 41 | +++ b/target/riscv/csr.c |
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_fcsr(CPURISCVState *env, int csrno, | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, |
49 | static RISCVException read_vtype(CPURISCVState *env, int csrno, | 43 | #endif |
50 | target_ulong *val) | 44 | |
45 | /* Crypto Extension */ | ||
46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, | ||
47 | - target_ulong *ret_value, | ||
48 | - target_ulong new_value, | ||
49 | - target_ulong write_mask) | ||
50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
51 | + target_ulong write_mask) | ||
51 | { | 52 | { |
52 | - *val = env->vtype; | 53 | uint16_t random_v; |
53 | + uint64_t vill; | 54 | Error *random_e = NULL; |
54 | + switch (env->xl) { | 55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
55 | + case MXL_RV32: | 56 | rval = random_v | SEED_OPST_ES16; |
56 | + vill = (uint32_t)env->vill << 31; | 57 | } |
57 | + break; | 58 | |
58 | + case MXL_RV64: | 59 | + return rval; |
59 | + vill = (uint64_t)env->vill << 63; | 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); | ||
60 | + break; | 92 | + break; |
61 | + default: | 93 | + default: |
62 | + g_assert_not_reached(); | 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; | ||
63 | + } | 99 | + } |
64 | + *val = (target_ulong)vill | env->vtype; | 100 | + |
65 | return RISCV_EXCP_NONE; | 101 | + return ret; |
66 | } | 102 | +} |
67 | 103 | + | |
68 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | 104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
69 | index XXXXXXX..XXXXXXX 100644 | 105 | { |
70 | --- a/target/riscv/machine.c | 106 | int ret = 0; |
71 | +++ b/target/riscv/machine.c | 107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
72 | @@ -XXX,XX +XXX,XX @@ static bool vector_needed(void *opaque) | 108 | case KVM_EXIT_RISCV_SBI: |
73 | 109 | ret = kvm_riscv_handle_sbi(cs, run); | |
74 | static const VMStateDescription vmstate_vector = { | 110 | break; |
75 | .name = "cpu/vector", | 111 | + case KVM_EXIT_RISCV_CSR: |
76 | - .version_id = 1, | 112 | + ret = kvm_riscv_handle_csr(cs, run); |
77 | - .minimum_version_id = 1, | 113 | + break; |
78 | + .version_id = 2, | 114 | default: |
79 | + .minimum_version_id = 2, | 115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", |
80 | .needed = vector_needed, | 116 | __func__, run->exit_reason); |
81 | .fields = (VMStateField[]) { | ||
82 | VMSTATE_UINT64_ARRAY(env.vreg, RISCVCPU, 32 * RV_VLEN_MAX / 64), | ||
83 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_vector = { | ||
84 | VMSTATE_UINTTL(env.vl, RISCVCPU), | ||
85 | VMSTATE_UINTTL(env.vstart, RISCVCPU), | ||
86 | VMSTATE_UINTTL(env.vtype, RISCVCPU), | ||
87 | + VMSTATE_BOOL(env.vill, RISCVCPU), | ||
88 | VMSTATE_END_OF_LIST() | ||
89 | } | ||
90 | }; | ||
91 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
92 | index XXXXXXX..XXXXXXX 100644 | ||
93 | --- a/target/riscv/vector_helper.c | ||
94 | +++ b/target/riscv/vector_helper.c | ||
95 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | ||
96 | || (ediv != 0) | ||
97 | || (reserved != 0)) { | ||
98 | /* only set vill bit. */ | ||
99 | - env->vtype = FIELD_DP64(0, VTYPE, VILL, 1); | ||
100 | + env->vill = 1; | ||
101 | + env->vtype = 0; | ||
102 | env->vl = 0; | ||
103 | env->vstart = 0; | ||
104 | return 0; | ||
105 | -- | 117 | -- |
106 | 2.31.1 | 118 | 2.45.1 |
107 | |||
108 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | As pc will be written by the xepc in exception return, just ignore | 3 | Implementing wrs.nto to always just return is consistent with the |
4 | pc in translation. | 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 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> |
16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20220120122050.41546-3-zhiwei_liu@c-sky.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/helper.h | 4 ++-- | 21 | target/riscv/helper.h | 1 + |
13 | target/riscv/op_helper.c | 4 ++-- | 22 | target/riscv/op_helper.c | 11 ++++++++ |
14 | target/riscv/insn_trans/trans_privileged.c.inc | 7 ++----- | 23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- |
15 | 3 files changed, 6 insertions(+), 9 deletions(-) | 24 | 3 files changed, 32 insertions(+), 9 deletions(-) |
16 | 25 | ||
17 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
18 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/helper.h | 28 | --- a/target/riscv/helper.h |
20 | +++ b/target/riscv/helper.h | 29 | +++ b/target/riscv/helper.h |
21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(csrr_i128, tl, env, int) | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) |
22 | DEF_HELPER_4(csrw_i128, void, env, int, tl, tl) | 31 | DEF_HELPER_1(sret, tl, env) |
23 | DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) | 32 | DEF_HELPER_1(mret, tl, env) |
24 | #ifndef CONFIG_USER_ONLY | ||
25 | -DEF_HELPER_2(sret, tl, env, tl) | ||
26 | -DEF_HELPER_2(mret, tl, env, tl) | ||
27 | +DEF_HELPER_1(sret, tl, env) | ||
28 | +DEF_HELPER_1(mret, tl, env) | ||
29 | DEF_HELPER_1(wfi, void, env) | 33 | DEF_HELPER_1(wfi, void, env) |
34 | +DEF_HELPER_1(wrs_nto, void, env) | ||
30 | DEF_HELPER_1(tlb_flush, void, env) | 35 | DEF_HELPER_1(tlb_flush, void, env) |
31 | #endif | 36 | DEF_HELPER_1(tlb_flush_all, void, env) |
37 | /* Native Debug */ | ||
32 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | 38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
33 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/riscv/op_helper.c | 40 | --- a/target/riscv/op_helper.c |
35 | +++ b/target/riscv/op_helper.c | 41 | +++ b/target/riscv/op_helper.c |
36 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw_i128(CPURISCVState *env, int csr, | 42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) |
37 | 43 | } | |
38 | #ifndef CONFIG_USER_ONLY | 44 | } |
39 | 45 | ||
40 | -target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) | 46 | +void helper_wrs_nto(CPURISCVState *env) |
41 | +target_ulong helper_sret(CPURISCVState *env) | 47 | +{ |
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 | + } | ||
55 | +} | ||
56 | + | ||
57 | void helper_tlb_flush(CPURISCVState *env) | ||
42 | { | 58 | { |
43 | uint64_t mstatus; | 59 | CPUState *cs = env_cpu(env); |
44 | target_ulong prev_priv, prev_virt; | 60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc |
45 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb) | 61 | index XXXXXXX..XXXXXXX 100644 |
46 | return retpc; | 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; | ||
47 | } | 75 | } |
48 | 76 | ||
49 | -target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb) | 77 | -#define GEN_TRANS_WRS(insn) \ |
50 | +target_ulong helper_mret(CPURISCVState *env) | 78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ |
51 | { | 79 | -{ \ |
52 | if (!(env->priv >= PRV_M)) { | 80 | - (void)a; \ |
53 | riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | 81 | - return trans_wrs(ctx); \ |
54 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | 82 | -} |
55 | index XXXXXXX..XXXXXXX 100644 | 83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) |
56 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | 84 | +{ |
57 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | 85 | + if (!ctx->cfg_ptr->ext_zawrs) { |
58 | @@ -XXX,XX +XXX,XX @@ static bool trans_uret(DisasContext *ctx, arg_uret *a) | 86 | + return false; |
59 | static bool trans_sret(DisasContext *ctx, arg_sret *a) | 87 | + } |
60 | { | 88 | |
61 | #ifndef CONFIG_USER_ONLY | 89 | -GEN_TRANS_WRS(wrs_nto) |
62 | - tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | 90 | -GEN_TRANS_WRS(wrs_sto) |
63 | - | 91 | + /* |
64 | if (has_ext(ctx, RVS)) { | 92 | + * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto |
65 | - gen_helper_sret(cpu_pc, cpu_env, cpu_pc); | 93 | + * should raise an exception when the implementation-specific bounded time |
66 | + gen_helper_sret(cpu_pc, cpu_env); | 94 | + * limit has expired. Our time limit is zero, so we either return |
67 | tcg_gen_exit_tb(NULL, 0); /* no chaining */ | 95 | + * immediately, as does our implementation of wrs.sto, or raise an |
68 | ctx->base.is_jmp = DISAS_NORETURN; | 96 | + * exception, as handled by the wrs.nto helper. |
69 | } else { | 97 | + */ |
70 | @@ -XXX,XX +XXX,XX @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) | 98 | +#ifndef CONFIG_USER_ONLY |
71 | static bool trans_mret(DisasContext *ctx, arg_mret *a) | 99 | + gen_helper_wrs_nto(tcg_env); |
72 | { | 100 | +#endif |
73 | #ifndef CONFIG_USER_ONLY | 101 | + |
74 | - tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | 102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ |
75 | - gen_helper_mret(cpu_pc, cpu_env, cpu_pc); | 103 | + return trans_wrs_sto(ctx, NULL); |
76 | + gen_helper_mret(cpu_pc, cpu_env); | 104 | +} |
77 | tcg_gen_exit_tb(NULL, 0); /* no chaining */ | ||
78 | ctx->base.is_jmp = DISAS_NORETURN; | ||
79 | return true; | ||
80 | -- | 105 | -- |
81 | 2.31.1 | 106 | 2.45.1 |
82 | 107 | ||
83 | 108 | diff view generated by jsdifflib |
1 | From: Yifei Jiang <jiangyifei@huawei.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Use char-fe to handle console sbi call, which implement early | 3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace |
4 | console io while apply 'earlycon=sbi' into kernel parameters. | 4 | the legacy console putchar and getchar SBI extensions. |
5 | 5 | ||
6 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | 6 | The appeal of the DBCN extension is that it allows multiple bytes to be |
7 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | 7 | read/written in the SBI console in a single SBI call. |
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | 8 | |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM |
10 | Message-id: 20220112081329.1835-9-jiangyifei@huawei.com | 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> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 30 | --- |
13 | target/riscv/sbi_ecall_interface.h | 72 ++++++++++++++++++++++++++++++ | 31 | target/riscv/sbi_ecall_interface.h | 17 +++++ |
14 | target/riscv/kvm.c | 42 ++++++++++++++++- | 32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ |
15 | 2 files changed, 113 insertions(+), 1 deletion(-) | 33 | 2 files changed, 128 insertions(+) |
16 | create mode 100644 target/riscv/sbi_ecall_interface.h | ||
17 | 34 | ||
18 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h | 35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h |
19 | new file mode 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
20 | index XXXXXXX..XXXXXXX | 37 | --- a/target/riscv/sbi_ecall_interface.h |
21 | --- /dev/null | ||
22 | +++ b/target/riscv/sbi_ecall_interface.h | 38 | +++ b/target/riscv/sbi_ecall_interface.h |
23 | @@ -XXX,XX +XXX,XX @@ | 39 | @@ -XXX,XX +XXX,XX @@ |
24 | +/* | 40 | |
25 | + * SPDX-License-Identifier: BSD-2-Clause | 41 | /* clang-format off */ |
26 | + * | 42 | |
27 | + * Copyright (c) 2019 Western Digital Corporation or its affiliates. | 43 | +#define SBI_SUCCESS 0 |
28 | + * | 44 | +#define SBI_ERR_FAILED -1 |
29 | + * Authors: | 45 | +#define SBI_ERR_NOT_SUPPORTED -2 |
30 | + * Anup Patel <anup.patel@wdc.com> | 46 | +#define SBI_ERR_INVALID_PARAM -3 |
31 | + */ | 47 | +#define SBI_ERR_DENIED -4 |
32 | + | 48 | +#define SBI_ERR_INVALID_ADDRESS -5 |
33 | +#ifndef __SBI_ECALL_INTERFACE_H__ | 49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 |
34 | +#define __SBI_ECALL_INTERFACE_H__ | 50 | +#define SBI_ERR_ALREADY_STARTED -7 |
35 | + | 51 | +#define SBI_ERR_ALREADY_STOPPED -8 |
36 | +/* clang-format off */ | 52 | +#define SBI_ERR_NO_SHMEM -9 |
37 | + | 53 | + |
38 | +/* SBI Extension IDs */ | 54 | /* SBI Extension IDs */ |
39 | +#define SBI_EXT_0_1_SET_TIMER 0x0 | 55 | #define SBI_EXT_0_1_SET_TIMER 0x0 |
40 | +#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 | 56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 |
41 | +#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 | 57 | @@ -XXX,XX +XXX,XX @@ |
42 | +#define SBI_EXT_0_1_CLEAR_IPI 0x3 | 58 | #define SBI_EXT_IPI 0x735049 |
43 | +#define SBI_EXT_0_1_SEND_IPI 0x4 | 59 | #define SBI_EXT_RFENCE 0x52464E43 |
44 | +#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5 | 60 | #define SBI_EXT_HSM 0x48534D |
45 | +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6 | 61 | +#define SBI_EXT_DBCN 0x4442434E |
46 | +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7 | 62 | |
47 | +#define SBI_EXT_0_1_SHUTDOWN 0x8 | 63 | /* SBI function IDs for BASE extension */ |
48 | +#define SBI_EXT_BASE 0x10 | 64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 |
49 | +#define SBI_EXT_TIME 0x54494D45 | 65 | @@ -XXX,XX +XXX,XX @@ |
50 | +#define SBI_EXT_IPI 0x735049 | 66 | #define SBI_EXT_HSM_HART_STOP 0x1 |
51 | +#define SBI_EXT_RFENCE 0x52464E43 | 67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 |
52 | +#define SBI_EXT_HSM 0x48534D | 68 | |
53 | + | 69 | +/* SBI function IDs for DBCN extension */ |
54 | +/* SBI function IDs for BASE extension*/ | 70 | +#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0 |
55 | +#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 | 71 | +#define SBI_EXT_DBCN_CONSOLE_READ 0x1 |
56 | +#define SBI_EXT_BASE_GET_IMP_ID 0x1 | 72 | +#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 |
57 | +#define SBI_EXT_BASE_GET_IMP_VERSION 0x2 | 73 | + |
58 | +#define SBI_EXT_BASE_PROBE_EXT 0x3 | 74 | #define SBI_HSM_HART_STATUS_STARTED 0x0 |
59 | +#define SBI_EXT_BASE_GET_MVENDORID 0x4 | 75 | #define SBI_HSM_HART_STATUS_STOPPED 0x1 |
60 | +#define SBI_EXT_BASE_GET_MARCHID 0x5 | 76 | #define SBI_HSM_HART_STATUS_START_PENDING 0x2 |
61 | +#define SBI_EXT_BASE_GET_MIMPID 0x6 | 77 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
62 | + | ||
63 | +/* SBI function IDs for TIME extension*/ | ||
64 | +#define SBI_EXT_TIME_SET_TIMER 0x0 | ||
65 | + | ||
66 | +/* SBI function IDs for IPI extension*/ | ||
67 | +#define SBI_EXT_IPI_SEND_IPI 0x0 | ||
68 | + | ||
69 | +/* SBI function IDs for RFENCE extension*/ | ||
70 | +#define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0 | ||
71 | +#define SBI_EXT_RFENCE_REMOTE_SFENCE_VMA 0x1 | ||
72 | +#define SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID 0x2 | ||
73 | +#define SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA 0x3 | ||
74 | +#define SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID 0x4 | ||
75 | +#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA 0x5 | ||
76 | +#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID 0x6 | ||
77 | + | ||
78 | +/* SBI function IDs for HSM extension */ | ||
79 | +#define SBI_EXT_HSM_HART_START 0x0 | ||
80 | +#define SBI_EXT_HSM_HART_STOP 0x1 | ||
81 | +#define SBI_EXT_HSM_HART_GET_STATUS 0x2 | ||
82 | + | ||
83 | +#define SBI_HSM_HART_STATUS_STARTED 0x0 | ||
84 | +#define SBI_HSM_HART_STATUS_STOPPED 0x1 | ||
85 | +#define SBI_HSM_HART_STATUS_START_PENDING 0x2 | ||
86 | +#define SBI_HSM_HART_STATUS_STOP_PENDING 0x3 | ||
87 | + | ||
88 | +#define SBI_SPEC_VERSION_MAJOR_OFFSET 24 | ||
89 | +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f | ||
90 | +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff | ||
91 | +#define SBI_EXT_VENDOR_START 0x09000000 | ||
92 | +#define SBI_EXT_VENDOR_END 0x09FFFFFF | ||
93 | +/* clang-format on */ | ||
94 | + | ||
95 | +#endif | ||
96 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | 78 | index XXXXXXX..XXXXXXX 100644 |
98 | --- a/target/riscv/kvm.c | 79 | --- a/target/riscv/kvm/kvm-cpu.c |
99 | +++ b/target/riscv/kvm.c | 80 | +++ b/target/riscv/kvm/kvm-cpu.c |
100 | @@ -XXX,XX +XXX,XX @@ | 81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { |
101 | #include "qemu/log.h" | 82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) |
102 | #include "hw/loader.h" | 83 | }; |
103 | #include "kvm_riscv.h" | 84 | |
104 | +#include "sbi_ecall_interface.h" | 85 | +static KVMCPUConfig kvm_sbi_dbcn = { |
105 | +#include "chardev/char-fe.h" | 86 | + .name = "sbi_dbcn", |
106 | 87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | | |
107 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | 88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN |
108 | uint64_t idx) | 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, ®); | ||
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 | |||
109 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) | 151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) |
110 | return true; | 152 | return true; |
111 | } | 153 | } |
112 | 154 | ||
113 | +static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | 155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) |
114 | +{ | 156 | +{ |
115 | + int ret = 0; | 157 | + g_autofree uint8_t *buf = NULL; |
158 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
159 | + target_ulong num_bytes; | ||
160 | + uint64_t addr; | ||
116 | + unsigned char ch; | 161 | + unsigned char ch; |
117 | + switch (run->riscv_sbi.extension_id) { | 162 | + int ret; |
118 | + case SBI_EXT_0_1_CONSOLE_PUTCHAR: | 163 | + |
164 | + switch (run->riscv_sbi.function_id) { | ||
165 | + case SBI_EXT_DBCN_CONSOLE_READ: | ||
166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: | ||
167 | + num_bytes = run->riscv_sbi.args[0]; | ||
168 | + | ||
169 | + if (num_bytes == 0) { | ||
170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
171 | + run->riscv_sbi.ret[1] = 0; | ||
172 | + break; | ||
173 | + } | ||
174 | + | ||
175 | + addr = run->riscv_sbi.args[1]; | ||
176 | + | ||
177 | + /* | ||
178 | + * Handle the case where a 32 bit CPU is running in a | ||
179 | + * 64 bit addressing env. | ||
180 | + */ | ||
181 | + if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) { | ||
182 | + addr |= (uint64_t)run->riscv_sbi.args[2] << 32; | ||
183 | + } | ||
184 | + | ||
185 | + buf = g_malloc0(num_bytes); | ||
186 | + | ||
187 | + if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) { | ||
188 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes); | ||
189 | + if (ret < 0) { | ||
190 | + error_report("SBI_EXT_DBCN_CONSOLE_READ: error when " | ||
191 | + "reading chardev"); | ||
192 | + exit(1); | ||
193 | + } | ||
194 | + | ||
195 | + cpu_physical_memory_write(addr, buf, ret); | ||
196 | + } else { | ||
197 | + cpu_physical_memory_read(addr, buf, num_bytes); | ||
198 | + | ||
199 | + ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes); | ||
200 | + if (ret < 0) { | ||
201 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when " | ||
202 | + "writing chardev"); | ||
203 | + exit(1); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
208 | + run->riscv_sbi.ret[1] = ret; | ||
209 | + break; | ||
210 | + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: | ||
119 | + ch = run->riscv_sbi.args[0]; | 211 | + ch = run->riscv_sbi.args[0]; |
120 | + qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); | 212 | + ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); |
121 | + break; | 213 | + |
122 | + case SBI_EXT_0_1_CONSOLE_GETCHAR: | 214 | + if (ret < 0) { |
123 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch)); | 215 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when " |
124 | + if (ret == sizeof(ch)) { | 216 | + "writing chardev"); |
125 | + run->riscv_sbi.args[0] = ch; | 217 | + exit(1); |
126 | + } else { | 218 | + } |
127 | + run->riscv_sbi.args[0] = -1; | 219 | + |
128 | + } | 220 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; |
221 | + run->riscv_sbi.ret[1] = 0; | ||
129 | + break; | 222 | + break; |
130 | + default: | 223 | + default: |
131 | + qemu_log_mask(LOG_UNIMP, | 224 | + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED; |
132 | + "%s: un-handled SBI EXIT, specific reasons is %lu\n", | 225 | + } |
133 | + __func__, run->riscv_sbi.extension_id); | 226 | +} |
134 | + ret = -1; | 227 | + |
228 | static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
229 | { | ||
230 | int ret = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
232 | } | ||
233 | ret = 0; | ||
234 | break; | ||
235 | + case SBI_EXT_DBCN: | ||
236 | + kvm_riscv_handle_sbi_dbcn(cs, run); | ||
135 | + break; | 237 | + break; |
136 | + } | 238 | default: |
137 | + return ret; | 239 | qemu_log_mask(LOG_UNIMP, |
138 | +} | 240 | "%s: un-handled SBI EXIT, specific reasons is %lu\n", |
139 | + | ||
140 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
141 | { | ||
142 | - return 0; | ||
143 | + int ret = 0; | ||
144 | + switch (run->exit_reason) { | ||
145 | + case KVM_EXIT_RISCV_SBI: | ||
146 | + ret = kvm_riscv_handle_sbi(cs, run); | ||
147 | + break; | ||
148 | + default: | ||
149 | + qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", | ||
150 | + __func__, run->exit_reason); | ||
151 | + ret = -1; | ||
152 | + break; | ||
153 | + } | ||
154 | + return ret; | ||
155 | } | ||
156 | |||
157 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
158 | -- | 241 | -- |
159 | 2.31.1 | 242 | 2.45.1 |
160 | |||
161 | diff view generated by jsdifflib |
1 | From: Yifei Jiang <jiangyifei@huawei.com> | 1 | From: Cheng Yang <yangcheng.work@foxmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Get kernel and fdt start address in virt.c, and pass them to KVM | 3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() |
4 | when cpu reset. Add kvm_riscv.h to place riscv specific interface. | 4 | to set the address of initrd in FDT to support 64-bit address. |
5 | 5 | ||
6 | In addition, PLIC is created without M-mode PLIC contexts when KVM | 6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> |
7 | is enabled. | ||
8 | |||
9 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
10 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Reviewed-by: Anup Patel <anup@brainfault.org> | 8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> |
13 | Message-id: 20220112081329.1835-7-jiangyifei@huawei.com | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 10 | --- |
16 | include/hw/riscv/boot.h | 1 + | 11 | hw/riscv/boot.c | 4 ++-- |
17 | target/riscv/cpu.h | 3 ++ | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
18 | target/riscv/kvm_riscv.h | 24 ++++++++++++ | ||
19 | hw/intc/sifive_plic.c | 20 +++++++--- | ||
20 | hw/riscv/boot.c | 16 +++++++- | ||
21 | hw/riscv/virt.c | 83 ++++++++++++++++++++++++++++------------ | ||
22 | target/riscv/cpu.c | 8 ++++ | ||
23 | target/riscv/kvm-stub.c | 25 ++++++++++++ | ||
24 | target/riscv/kvm.c | 14 +++++++ | ||
25 | target/riscv/meson.build | 2 +- | ||
26 | 10 files changed, 164 insertions(+), 32 deletions(-) | ||
27 | create mode 100644 target/riscv/kvm_riscv.h | ||
28 | create mode 100644 target/riscv/kvm-stub.c | ||
29 | 13 | ||
30 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/hw/riscv/boot.h | ||
33 | +++ b/include/hw/riscv/boot.h | ||
34 | @@ -XXX,XX +XXX,XX @@ void riscv_rom_copy_firmware_info(MachineState *machine, hwaddr rom_base, | ||
35 | hwaddr rom_size, | ||
36 | uint32_t reset_vec_size, | ||
37 | uint64_t kernel_entry); | ||
38 | +void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr); | ||
39 | |||
40 | #endif /* RISCV_BOOT_H */ | ||
41 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/riscv/cpu.h | ||
44 | +++ b/target/riscv/cpu.h | ||
45 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | ||
46 | |||
47 | /* Fields from here on are preserved across CPU reset. */ | ||
48 | QEMUTimer *timer; /* Internal timer */ | ||
49 | + | ||
50 | + hwaddr kernel_addr; | ||
51 | + hwaddr fdt_addr; | ||
52 | }; | ||
53 | |||
54 | OBJECT_DECLARE_TYPE(RISCVCPU, RISCVCPUClass, | ||
55 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
56 | new file mode 100644 | ||
57 | index XXXXXXX..XXXXXXX | ||
58 | --- /dev/null | ||
59 | +++ b/target/riscv/kvm_riscv.h | ||
60 | @@ -XXX,XX +XXX,XX @@ | ||
61 | +/* | ||
62 | + * QEMU KVM support -- RISC-V specific functions. | ||
63 | + * | ||
64 | + * Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
65 | + * | ||
66 | + * This program is free software; you can redistribute it and/or modify it | ||
67 | + * under the terms and conditions of the GNU General Public License, | ||
68 | + * version 2 or later, as published by the Free Software Foundation. | ||
69 | + * | ||
70 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
71 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
72 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
73 | + * more details. | ||
74 | + * | ||
75 | + * You should have received a copy of the GNU General Public License along with | ||
76 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
77 | + */ | ||
78 | + | ||
79 | +#ifndef QEMU_KVM_RISCV_H | ||
80 | +#define QEMU_KVM_RISCV_H | ||
81 | + | ||
82 | +void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
83 | + | ||
84 | +#endif | ||
85 | diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/hw/intc/sifive_plic.c | ||
88 | +++ b/hw/intc/sifive_plic.c | ||
89 | @@ -XXX,XX +XXX,XX @@ | ||
90 | #include "target/riscv/cpu.h" | ||
91 | #include "migration/vmstate.h" | ||
92 | #include "hw/irq.h" | ||
93 | +#include "sysemu/kvm.h" | ||
94 | |||
95 | static bool addr_between(uint32_t addr, uint32_t base, uint32_t num) | ||
96 | { | ||
97 | @@ -XXX,XX +XXX,XX @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, | ||
98 | uint32_t context_stride, uint32_t aperture_size) | ||
99 | { | ||
100 | DeviceState *dev = qdev_new(TYPE_SIFIVE_PLIC); | ||
101 | - int i; | ||
102 | + int i, j = 0; | ||
103 | + SiFivePLICState *plic; | ||
104 | |||
105 | assert(enable_stride == (enable_stride & -enable_stride)); | ||
106 | assert(context_stride == (context_stride & -context_stride)); | ||
107 | @@ -XXX,XX +XXX,XX @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, | ||
108 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
109 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
110 | |||
111 | + plic = SIFIVE_PLIC(dev); | ||
112 | for (i = 0; i < num_harts; i++) { | ||
113 | CPUState *cpu = qemu_get_cpu(hartid_base + i); | ||
114 | |||
115 | - qdev_connect_gpio_out(dev, i, | ||
116 | - qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT)); | ||
117 | - qdev_connect_gpio_out(dev, num_harts + i, | ||
118 | - qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT)); | ||
119 | + if (plic->addr_config[j].mode == PLICMode_M) { | ||
120 | + j++; | ||
121 | + qdev_connect_gpio_out(dev, num_harts + i, | ||
122 | + qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT)); | ||
123 | + } | ||
124 | + | ||
125 | + if (plic->addr_config[j].mode == PLICMode_S) { | ||
126 | + j++; | ||
127 | + qdev_connect_gpio_out(dev, i, | ||
128 | + qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT)); | ||
129 | + } | ||
130 | } | ||
131 | |||
132 | return dev; | ||
133 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 14 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
134 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
135 | --- a/hw/riscv/boot.c | 16 | --- a/hw/riscv/boot.c |
136 | +++ b/hw/riscv/boot.c | 17 | +++ b/hw/riscv/boot.c |
137 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) |
138 | #include "elf.h" | 19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
139 | #include "sysemu/device_tree.h" | 20 | if (fdt) { |
140 | #include "sysemu/qtest.h" | 21 | end = start + size; |
141 | +#include "sysemu/kvm.h" | 22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); |
142 | 23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); | |
143 | #include <libfdt.h> | 24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); |
144 | 25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); | |
145 | @@ -XXX,XX +XXX,XX @@ char *riscv_plic_hart_config_string(int hart_count) | 26 | } |
146 | CPUState *cs = qemu_get_cpu(i); | ||
147 | CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
148 | |||
149 | - if (riscv_has_ext(env, RVS)) { | ||
150 | + if (kvm_enabled()) { | ||
151 | + vals[i] = "S"; | ||
152 | + } else if (riscv_has_ext(env, RVS)) { | ||
153 | vals[i] = "MS"; | ||
154 | } else { | ||
155 | vals[i] = "M"; | ||
156 | @@ -XXX,XX +XXX,XX @@ void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts | ||
157 | |||
158 | return; | ||
159 | } | 27 | } |
160 | + | 28 | |
161 | +void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr) | ||
162 | +{ | ||
163 | + CPUState *cs; | ||
164 | + | ||
165 | + for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) { | ||
166 | + RISCVCPU *riscv_cpu = RISCV_CPU(cs); | ||
167 | + riscv_cpu->env.kernel_addr = kernel_addr; | ||
168 | + riscv_cpu->env.fdt_addr = fdt_addr; | ||
169 | + } | ||
170 | +} | ||
171 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/hw/riscv/virt.c | ||
174 | +++ b/hw/riscv/virt.c | ||
175 | @@ -XXX,XX +XXX,XX @@ | ||
176 | #include "chardev/char.h" | ||
177 | #include "sysemu/device_tree.h" | ||
178 | #include "sysemu/sysemu.h" | ||
179 | +#include "sysemu/kvm.h" | ||
180 | #include "hw/pci/pci.h" | ||
181 | #include "hw/pci-host/gpex.h" | ||
182 | #include "hw/display/ramfb.h" | ||
183 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s, | ||
184 | "sifive,plic-1.0.0", "riscv,plic0" | ||
185 | }; | ||
186 | |||
187 | - plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4); | ||
188 | + if (kvm_enabled()) { | ||
189 | + plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2); | ||
190 | + } else { | ||
191 | + plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4); | ||
192 | + } | ||
193 | |||
194 | for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { | ||
195 | - plic_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
196 | - plic_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT); | ||
197 | - plic_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandles[cpu]); | ||
198 | - plic_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT); | ||
199 | + if (kvm_enabled()) { | ||
200 | + plic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
201 | + plic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); | ||
202 | + } else { | ||
203 | + plic_cells[cpu * 4 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
204 | + plic_cells[cpu * 4 + 1] = cpu_to_be32(IRQ_M_EXT); | ||
205 | + plic_cells[cpu * 4 + 2] = cpu_to_be32(intc_phandles[cpu]); | ||
206 | + plic_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_S_EXT); | ||
207 | + } | ||
208 | } | ||
209 | |||
210 | plic_phandles[socket] = (*phandle)++; | ||
211 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
212 | |||
213 | create_fdt_socket_memory(s, memmap, socket); | ||
214 | |||
215 | - if (s->have_aclint) { | ||
216 | - create_fdt_socket_aclint(s, memmap, socket, intc_phandles); | ||
217 | - } else { | ||
218 | - create_fdt_socket_clint(s, memmap, socket, intc_phandles); | ||
219 | + if (!kvm_enabled()) { | ||
220 | + if (s->have_aclint) { | ||
221 | + create_fdt_socket_aclint(s, memmap, socket, intc_phandles); | ||
222 | + } else { | ||
223 | + create_fdt_socket_clint(s, memmap, socket, intc_phandles); | ||
224 | + } | ||
225 | } | ||
226 | |||
227 | create_fdt_socket_plic(s, memmap, socket, phandle, | ||
228 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
229 | hart_count, &error_abort); | ||
230 | sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort); | ||
231 | |||
232 | - /* Per-socket CLINT */ | ||
233 | - riscv_aclint_swi_create( | ||
234 | - memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, | ||
235 | - base_hartid, hart_count, false); | ||
236 | - riscv_aclint_mtimer_create( | ||
237 | - memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size + | ||
238 | - RISCV_ACLINT_SWI_SIZE, | ||
239 | - RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, | ||
240 | - RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, | ||
241 | - RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); | ||
242 | - | ||
243 | - /* Per-socket ACLINT SSWI */ | ||
244 | - if (s->have_aclint) { | ||
245 | + if (!kvm_enabled()) { | ||
246 | + /* Per-socket CLINT */ | ||
247 | riscv_aclint_swi_create( | ||
248 | - memmap[VIRT_ACLINT_SSWI].base + | ||
249 | - i * memmap[VIRT_ACLINT_SSWI].size, | ||
250 | - base_hartid, hart_count, true); | ||
251 | + memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, | ||
252 | + base_hartid, hart_count, false); | ||
253 | + riscv_aclint_mtimer_create( | ||
254 | + memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size + | ||
255 | + RISCV_ACLINT_SWI_SIZE, | ||
256 | + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, | ||
257 | + RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, | ||
258 | + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); | ||
259 | + | ||
260 | + /* Per-socket ACLINT SSWI */ | ||
261 | + if (s->have_aclint) { | ||
262 | + riscv_aclint_swi_create( | ||
263 | + memmap[VIRT_ACLINT_SSWI].base + | ||
264 | + i * memmap[VIRT_ACLINT_SSWI].size, | ||
265 | + base_hartid, hart_count, true); | ||
266 | + } | ||
267 | } | ||
268 | |||
269 | /* Per-socket PLIC hart topology configuration string */ | ||
270 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
271 | memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base, | ||
272 | mask_rom); | ||
273 | |||
274 | + /* | ||
275 | + * Only direct boot kernel is currently supported for KVM VM, | ||
276 | + * so the "-bios" parameter is ignored and treated like "-bios none" | ||
277 | + * when KVM is enabled. | ||
278 | + */ | ||
279 | + if (kvm_enabled()) { | ||
280 | + g_free(machine->firmware); | ||
281 | + machine->firmware = g_strdup("none"); | ||
282 | + } | ||
283 | + | ||
284 | if (riscv_is_32bit(&s->soc[0])) { | ||
285 | firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
286 | RISCV32_BIOS_BIN, start_addr, NULL); | ||
287 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
288 | virt_memmap[VIRT_MROM].size, kernel_entry, | ||
289 | fdt_load_addr, machine->fdt); | ||
290 | |||
291 | + /* | ||
292 | + * Only direct boot kernel is currently supported for KVM VM, | ||
293 | + * So here setup kernel start address and fdt address. | ||
294 | + * TODO:Support firmware loading and integrate to TCG start | ||
295 | + */ | ||
296 | + if (kvm_enabled()) { | ||
297 | + riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); | ||
298 | + } | ||
299 | + | ||
300 | /* SiFive Test MMIO device */ | ||
301 | sifive_test_create(memmap[VIRT_TEST].base); | ||
302 | |||
303 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
304 | index XXXXXXX..XXXXXXX 100644 | ||
305 | --- a/target/riscv/cpu.c | ||
306 | +++ b/target/riscv/cpu.c | ||
307 | @@ -XXX,XX +XXX,XX @@ | ||
308 | #include "hw/qdev-properties.h" | ||
309 | #include "migration/vmstate.h" | ||
310 | #include "fpu/softfloat-helpers.h" | ||
311 | +#include "sysemu/kvm.h" | ||
312 | +#include "kvm_riscv.h" | ||
313 | |||
314 | /* RISC-V CPU definitions */ | ||
315 | |||
316 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | ||
317 | cs->exception_index = RISCV_EXCP_NONE; | ||
318 | env->load_res = -1; | ||
319 | set_default_nan_mode(1, &env->fp_status); | ||
320 | + | ||
321 | +#ifndef CONFIG_USER_ONLY | ||
322 | + if (kvm_enabled()) { | ||
323 | + kvm_riscv_reset_vcpu(cpu); | ||
324 | + } | ||
325 | +#endif | ||
326 | } | ||
327 | |||
328 | static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | ||
329 | diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c | ||
330 | new file mode 100644 | ||
331 | index XXXXXXX..XXXXXXX | ||
332 | --- /dev/null | ||
333 | +++ b/target/riscv/kvm-stub.c | ||
334 | @@ -XXX,XX +XXX,XX @@ | ||
335 | +/* | ||
336 | + * QEMU KVM RISC-V specific function stubs | ||
337 | + * | ||
338 | + * Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
339 | + * | ||
340 | + * This program is free software; you can redistribute it and/or modify it | ||
341 | + * under the terms and conditions of the GNU General Public License, | ||
342 | + * version 2 or later, as published by the Free Software Foundation. | ||
343 | + * | ||
344 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
345 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
346 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
347 | + * more details. | ||
348 | + * | ||
349 | + * You should have received a copy of the GNU General Public License along with | ||
350 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
351 | + */ | ||
352 | +#include "qemu/osdep.h" | ||
353 | +#include "cpu.h" | ||
354 | +#include "kvm_riscv.h" | ||
355 | + | ||
356 | +void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
357 | +{ | ||
358 | + abort(); | ||
359 | +} | ||
360 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
361 | index XXXXXXX..XXXXXXX 100644 | ||
362 | --- a/target/riscv/kvm.c | ||
363 | +++ b/target/riscv/kvm.c | ||
364 | @@ -XXX,XX +XXX,XX @@ | ||
365 | #include "hw/irq.h" | ||
366 | #include "qemu/log.h" | ||
367 | #include "hw/loader.h" | ||
368 | +#include "kvm_riscv.h" | ||
369 | |||
370 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
371 | uint64_t idx) | ||
372 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
373 | return 0; | ||
374 | } | ||
375 | |||
376 | +void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
377 | +{ | ||
378 | + CPURISCVState *env = &cpu->env; | ||
379 | + | ||
380 | + if (!kvm_enabled()) { | ||
381 | + return; | ||
382 | + } | ||
383 | + env->pc = cpu->env.kernel_addr; | ||
384 | + env->gpr[10] = kvm_arch_vcpu_id(CPU(cpu)); /* a0 */ | ||
385 | + env->gpr[11] = cpu->env.fdt_addr; /* a1 */ | ||
386 | + env->satp = 0; | ||
387 | +} | ||
388 | + | ||
389 | bool kvm_arch_cpu_check_are_resettable(void) | ||
390 | { | ||
391 | return true; | ||
392 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
393 | index XXXXXXX..XXXXXXX 100644 | ||
394 | --- a/target/riscv/meson.build | ||
395 | +++ b/target/riscv/meson.build | ||
396 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | ||
397 | 'translate.c', | ||
398 | 'm128_helper.c' | ||
399 | )) | ||
400 | -riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) | ||
401 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c')) | ||
402 | |||
403 | riscv_softmmu_ss = ss.source_set() | ||
404 | riscv_softmmu_ss.add(files( | ||
405 | -- | 29 | -- |
406 | 2.31.1 | 30 | 2.45.1 |
407 | |||
408 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Clément Léger <cleger@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 3 | The current semihost exception number (16) is a reserved number (range |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 4 | [16-17]). The upcoming double trap specification uses that number for |
5 | the double trap exception. Since the privileged spec (Table 22) defines | ||
6 | ranges for custom uses change the semihosting exception number to 63 | ||
7 | which belongs to the range [48-63] in order to avoid any future | ||
8 | collisions with reserved exception. | ||
9 | |||
10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> | ||
11 | |||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Message-id: 20220120122050.41546-23-zhiwei_liu@c-sky.com | 13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com> |
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | --- | 15 | --- |
9 | target/riscv/cpu_bits.h | 3 +++ | 16 | target/riscv/cpu_bits.h | 2 +- |
10 | target/riscv/csr.c | 28 ++++++++++++++++++++++------ | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 2 files changed, 25 insertions(+), 6 deletions(-) | ||
12 | 18 | ||
13 | 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 |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/cpu_bits.h | 21 | --- a/target/riscv/cpu_bits.h |
16 | +++ b/target/riscv/cpu_bits.h | 22 | +++ b/target/riscv/cpu_bits.h |
17 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
18 | #define COUNTEREN_IR (1 << 2) | 24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ |
19 | #define COUNTEREN_HPM3 (1 << 3) | 25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ |
20 | 26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ | |
21 | +/* vsstatus CSR bits */ | 27 | - RISCV_EXCP_SEMIHOST = 0x10, |
22 | +#define VSSTATUS64_UXL 0x0000000300000000ULL | 28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, |
23 | + | 29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, |
24 | /* Privilege modes */ | 30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, |
25 | #define PRV_U 0 | 31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, |
26 | #define PRV_S 1 | 32 | + RISCV_EXCP_SEMIHOST = 0x3f, |
27 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 33 | } RISCVException; |
28 | index XXXXXXX..XXXXXXX 100644 | 34 | |
29 | --- a/target/riscv/csr.c | 35 | #define RISCV_EXCP_INT_FLAG 0x80000000 |
30 | +++ b/target/riscv/csr.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static const target_ulong vs_delegable_excps = DELEGABLE_EXCPS & | ||
32 | (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT))); | ||
33 | static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | | ||
34 | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | | ||
35 | - SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS | (target_ulong)SSTATUS64_UXL; | ||
36 | + SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS; | ||
37 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; | ||
38 | static const target_ulong hip_writable_mask = MIP_VSSIP; | ||
39 | static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | ||
40 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | ||
41 | { | ||
42 | uint64_t mstatus = env->mstatus; | ||
43 | uint64_t mask = 0; | ||
44 | + RISCVMXL xl = riscv_cpu_mxl(env); | ||
45 | |||
46 | /* flush tlb on mstatus fields that affect VM */ | ||
47 | if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV | | ||
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | ||
49 | MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR | | ||
50 | MSTATUS_TW | MSTATUS_VS; | ||
51 | |||
52 | - if (riscv_cpu_mxl(env) != MXL_RV32) { | ||
53 | + if (xl != MXL_RV32) { | ||
54 | /* | ||
55 | * RV32: MPV and GVA are not in mstatus. The current plan is to | ||
56 | * add them to mstatush. For now, we just don't support it. | ||
57 | */ | ||
58 | mask |= MSTATUS_MPV | MSTATUS_GVA; | ||
59 | + if ((val & MSTATUS64_UXL) != 0) { | ||
60 | + mask |= MSTATUS64_UXL; | ||
61 | + } | ||
62 | } | ||
63 | |||
64 | mstatus = (mstatus & ~mask) | (val & mask); | ||
65 | |||
66 | - RISCVMXL xl = riscv_cpu_mxl(env); | ||
67 | if (xl > MXL_RV32) { | ||
68 | - /* SXL and UXL fields are for now read only */ | ||
69 | + /* SXL field is for now read only */ | ||
70 | mstatus = set_field(mstatus, MSTATUS64_SXL, xl); | ||
71 | - mstatus = set_field(mstatus, MSTATUS64_UXL, xl); | ||
72 | } | ||
73 | env->mstatus = mstatus; | ||
74 | env->xl = cpu_recompute_xl(env); | ||
75 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno, | ||
76 | { | ||
77 | uint64_t mask = sstatus_v1_10_mask; | ||
78 | uint64_t sstatus = env->mstatus & mask; | ||
79 | + if (env->xl != MXL_RV32) { | ||
80 | + mask |= SSTATUS64_UXL; | ||
81 | + } | ||
82 | |||
83 | *val = int128_make128(sstatus, add_status_sd(MXL_RV128, sstatus)); | ||
84 | return RISCV_EXCP_NONE; | ||
85 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, | ||
86 | target_ulong *val) | ||
87 | { | ||
88 | target_ulong mask = (sstatus_v1_10_mask); | ||
89 | - | ||
90 | + if (env->xl != MXL_RV32) { | ||
91 | + mask |= SSTATUS64_UXL; | ||
92 | + } | ||
93 | /* TODO: Use SXL not MXL. */ | ||
94 | *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask); | ||
95 | return RISCV_EXCP_NONE; | ||
96 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno, | ||
97 | target_ulong val) | ||
98 | { | ||
99 | target_ulong mask = (sstatus_v1_10_mask); | ||
100 | + | ||
101 | + if (env->xl != MXL_RV32) { | ||
102 | + if ((val & SSTATUS64_UXL) != 0) { | ||
103 | + mask |= SSTATUS64_UXL; | ||
104 | + } | ||
105 | + } | ||
106 | target_ulong newval = (env->mstatus & ~mask) | (val & mask); | ||
107 | return write_mstatus(env, CSR_MSTATUS, newval); | ||
108 | } | ||
109 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno, | ||
110 | target_ulong val) | ||
111 | { | ||
112 | uint64_t mask = (target_ulong)-1; | ||
113 | + if ((val & VSSTATUS64_UXL) == 0) { | ||
114 | + mask &= ~VSSTATUS64_UXL; | ||
115 | + } | ||
116 | env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val; | ||
117 | return RISCV_EXCP_NONE; | ||
118 | } | ||
119 | -- | 36 | -- |
120 | 2.31.1 | 37 | 2.45.1 |
121 | 38 | ||
122 | 39 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The mask comes from the pointer masking extension, or the max value | 3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr |
4 | corresponding to XLEN bits. | 4 | enabled, will fail with a kernel oops SIGILL right at the start. The |
5 | reason is that we can't expose zkr without implementing the SEED CSR. | ||
6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't | ||
7 | allow it we'll error out and never boot. | ||
5 | 8 | ||
6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 9 | In hindsight this is too strict. If we keep proceeding, despite not |
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 10 | disabling the extension in the KVM vcpu, we'll not add the extension in |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. |
9 | Message-id: 20220120122050.41546-20-zhiwei_liu@c-sky.com | 12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So |
13 | it's ok to keep booting in this case. | ||
14 | |||
15 | Change our current logic to not error out if we fail to disable an | ||
16 | extension in kvm_set_one_reg(), but show a warning and keep booting. It | ||
17 | is important to throw a warning because we must make the user aware that | ||
18 | the extension is still available in the vcpu, meaning that an | ||
19 | ill-behaved guest can ignore the riscv,isa settings and use the | ||
20 | extension. | ||
21 | |||
22 | The case we're handling happens with an EINVAL error code. If we fail to | ||
23 | disable the extension in KVM for any other reason, error out. | ||
24 | |||
25 | We'll also keep erroring out when we fail to enable an extension in KVM, | ||
26 | since adding the extension in riscv,isa at this point will cause a guest | ||
27 | malfunction because the extension isn't enabled in the vcpu. | ||
28 | |||
29 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
31 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
33 | Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 35 | --- |
12 | target/riscv/vector_helper.c | 25 +++++++++++++++---------- | 36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- |
13 | 1 file changed, 15 insertions(+), 10 deletions(-) | 37 | 1 file changed, 8 insertions(+), 4 deletions(-) |
14 | 38 | ||
15 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | 39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
16 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/vector_helper.c | 41 | --- a/target/riscv/kvm/kvm-cpu.c |
18 | +++ b/target/riscv/vector_helper.c | 42 | +++ b/target/riscv/kvm/kvm-cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t esz) | 43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
20 | return scale < 0 ? vlenb >> -scale : vlenb << scale; | 44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); |
21 | } | 45 | ret = kvm_set_one_reg(cs, id, ®); |
22 | 46 | if (ret != 0) { | |
23 | +static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr) | 47 | - error_report("Unable to %s extension %s in KVM, error %d", |
24 | +{ | 48 | - reg ? "enable" : "disable", |
25 | + return (addr & env->cur_pmmask) | env->cur_pmbase; | 49 | - multi_ext_cfg->name, ret); |
26 | +} | 50 | - exit(EXIT_FAILURE); |
27 | + | 51 | + if (!reg && ret == -EINVAL) { |
28 | /* | 52 | + warn_report("KVM cannot disable extension %s", |
29 | * This function checks watchpoint before real load operation. | 53 | + multi_ext_cfg->name); |
30 | * | 54 | + } else { |
31 | @@ -XXX,XX +XXX,XX @@ static void probe_pages(CPURISCVState *env, target_ulong addr, | 55 | + error_report("Unable to enable extension %s in KVM, error %d", |
32 | target_ulong pagelen = -(addr | TARGET_PAGE_MASK); | 56 | + multi_ext_cfg->name, ret); |
33 | target_ulong curlen = MIN(pagelen, len); | 57 | + exit(EXIT_FAILURE); |
34 | 58 | + } | |
35 | - probe_access(env, addr, curlen, access_type, | 59 | } |
36 | + probe_access(env, adjust_addr(env, addr), curlen, access_type, | ||
37 | cpu_mmu_index(env, false), ra); | ||
38 | if (len > curlen) { | ||
39 | addr += curlen; | ||
40 | curlen = len - curlen; | ||
41 | - probe_access(env, addr, curlen, access_type, | ||
42 | + probe_access(env, adjust_addr(env, addr), curlen, access_type, | ||
43 | cpu_mmu_index(env, false), ra); | ||
44 | } | 60 | } |
45 | } | 61 | } |
46 | @@ -XXX,XX +XXX,XX @@ vext_ldst_stride(void *vd, void *v0, target_ulong base, | ||
47 | k = 0; | ||
48 | while (k < nf) { | ||
49 | target_ulong addr = base + stride * i + (k << esz); | ||
50 | - ldst_elem(env, addr, i + k * max_elems, vd, ra); | ||
51 | + ldst_elem(env, adjust_addr(env, addr), i + k * max_elems, vd, ra); | ||
52 | k++; | ||
53 | } | ||
54 | } | ||
55 | @@ -XXX,XX +XXX,XX @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, | ||
56 | k = 0; | ||
57 | while (k < nf) { | ||
58 | target_ulong addr = base + ((i * nf + k) << esz); | ||
59 | - ldst_elem(env, addr, i + k * max_elems, vd, ra); | ||
60 | + ldst_elem(env, adjust_addr(env, addr), i + k * max_elems, vd, ra); | ||
61 | k++; | ||
62 | } | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ vext_ldst_index(void *vd, void *v0, target_ulong base, | ||
65 | k = 0; | ||
66 | while (k < nf) { | ||
67 | abi_ptr addr = get_index_addr(base, i, vs2) + (k << esz); | ||
68 | - ldst_elem(env, addr, i + k * max_elems, vd, ra); | ||
69 | + ldst_elem(env, adjust_addr(env, addr), i + k * max_elems, vd, ra); | ||
70 | k++; | ||
71 | } | ||
72 | } | ||
73 | @@ -XXX,XX +XXX,XX @@ vext_ldff(void *vd, void *v0, target_ulong base, | ||
74 | if (!vm && !vext_elem_mask(v0, i)) { | ||
75 | continue; | ||
76 | } | ||
77 | - addr = base + i * (nf << esz); | ||
78 | + addr = adjust_addr(env, base + i * (nf << esz)); | ||
79 | if (i == 0) { | ||
80 | probe_pages(env, addr, nf << esz, ra, MMU_DATA_LOAD); | ||
81 | } else { | ||
82 | @@ -XXX,XX +XXX,XX @@ vext_ldff(void *vd, void *v0, target_ulong base, | ||
83 | break; | ||
84 | } | ||
85 | remain -= offset; | ||
86 | - addr += offset; | ||
87 | + addr = adjust_addr(env, addr + offset); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | @@ -XXX,XX +XXX,XX @@ ProbeSuccess: | ||
92 | } | ||
93 | while (k < nf) { | ||
94 | target_ulong addr = base + ((i * nf + k) << esz); | ||
95 | - ldst_elem(env, addr, i + k * max_elems, vd, ra); | ||
96 | + ldst_elem(env, adjust_addr(env, addr), i + k * max_elems, vd, ra); | ||
97 | k++; | ||
98 | } | ||
99 | } | ||
100 | @@ -XXX,XX +XXX,XX @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, | ||
101 | /* load/store rest of elements of current segment pointed by vstart */ | ||
102 | for (pos = off; pos < max_elems; pos++, env->vstart++) { | ||
103 | target_ulong addr = base + ((pos + k * max_elems) << esz); | ||
104 | - ldst_elem(env, addr, pos + k * max_elems, vd, ra); | ||
105 | + ldst_elem(env, adjust_addr(env, addr), pos + k * max_elems, vd, ra); | ||
106 | } | ||
107 | k++; | ||
108 | } | ||
109 | @@ -XXX,XX +XXX,XX @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, | ||
110 | for (; k < nf; k++) { | ||
111 | for (i = 0; i < max_elems; i++, env->vstart++) { | ||
112 | target_ulong addr = base + ((i + k * max_elems) << esz); | ||
113 | - ldst_elem(env, addr, i + k * max_elems, vd, ra); | ||
114 | + ldst_elem(env, adjust_addr(env, addr), i + k * max_elems, vd, ra); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | -- | 62 | -- |
119 | 2.31.1 | 63 | 2.45.1 |
120 | |||
121 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 3 | We're not setting (s/m)tval when triggering breakpoints of type 2 |
4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section | ||
5 | 5.7.12, "Match Control Type 6": | ||
6 | |||
7 | "The Privileged Spec says that breakpoint exceptions that occur on | ||
8 | instruction fetches, loads, or stores update the tval CSR with either | ||
9 | zero or the faulting virtual address. The faulting virtual address for | ||
10 | an mcontrol6 trigger with action = 0 is the address being accessed and | ||
11 | which caused that trigger to fire." | ||
12 | |||
13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. | ||
14 | mcontrol. | ||
15 | |||
16 | Note that what we're doing ATM is not violating the spec, but it's | ||
17 | simple enough to set mtval/stval and it makes life easier for any | ||
18 | software that relies on this info. | ||
19 | |||
20 | Given that we always use action = 0, save the faulting address for the | ||
21 | mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is | ||
22 | used as as scratch area for traps with address information. 'tval' is | ||
23 | then set during riscv_cpu_do_interrupt(). | ||
24 | |||
25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
6 | Message-id: 20220120122050.41546-12-zhiwei_liu@c-sky.com | 28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> |
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | --- | 30 | --- |
9 | target/riscv/cpu.h | 4 ++++ | 31 | target/riscv/cpu_helper.c | 1 + |
10 | target/riscv/cpu.c | 1 + | 32 | target/riscv/debug.c | 3 +++ |
11 | target/riscv/cpu_helper.c | 43 +++++++++++++++++++++++++++++++++++++++ | 33 | 2 files changed, 4 insertions(+) |
12 | target/riscv/csr.c | 19 +++++++++++++++++ | ||
13 | target/riscv/machine.c | 1 + | ||
14 | 5 files changed, 68 insertions(+) | ||
15 | 34 | ||
16 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/riscv/cpu.h | ||
19 | +++ b/target/riscv/cpu.h | ||
20 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | ||
21 | target_ulong upmmask; | ||
22 | target_ulong upmbase; | ||
23 | #endif | ||
24 | + target_ulong cur_pmmask; | ||
25 | + target_ulong cur_pmbase; | ||
26 | |||
27 | float_status fp_status; | ||
28 | |||
29 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype) | ||
30 | void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
31 | target_ulong *cs_base, uint32_t *pflags); | ||
32 | |||
33 | +void riscv_cpu_update_mask(CPURISCVState *env); | ||
34 | + | ||
35 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
36 | target_ulong *ret_value, | ||
37 | target_ulong new_value, target_ulong write_mask); | ||
38 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/target/riscv/cpu.c | ||
41 | +++ b/target/riscv/cpu.c | ||
42 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | ||
43 | env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT); | ||
44 | #endif | ||
45 | env->xl = riscv_cpu_mxl(env); | ||
46 | + riscv_cpu_update_mask(env); | ||
47 | cs->exception_index = RISCV_EXCP_NONE; | ||
48 | env->load_res = -1; | ||
49 | set_default_nan_mode(1, &env->fp_status); | ||
50 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
51 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
52 | --- a/target/riscv/cpu_helper.c | 37 | --- a/target/riscv/cpu_helper.c |
53 | +++ b/target/riscv/cpu_helper.c | 38 | +++ b/target/riscv/cpu_helper.c |
54 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
55 | *pflags = flags; | 40 | tval = env->bins; |
56 | } | 41 | break; |
57 | 42 | case RISCV_EXCP_BREAKPOINT: | |
58 | +void riscv_cpu_update_mask(CPURISCVState *env) | 43 | + tval = env->badaddr; |
59 | +{ | 44 | if (cs->watchpoint_hit) { |
60 | + target_ulong mask = -1, base = 0; | 45 | tval = cs->watchpoint_hit->hitaddr; |
61 | + /* | 46 | cs->watchpoint_hit = NULL; |
62 | + * TODO: Current RVJ spec does not specify | 47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
63 | + * how the extension interacts with XLEN. | ||
64 | + */ | ||
65 | +#ifndef CONFIG_USER_ONLY | ||
66 | + if (riscv_has_ext(env, RVJ)) { | ||
67 | + switch (env->priv) { | ||
68 | + case PRV_M: | ||
69 | + if (env->mmte & M_PM_ENABLE) { | ||
70 | + mask = env->mpmmask; | ||
71 | + base = env->mpmbase; | ||
72 | + } | ||
73 | + break; | ||
74 | + case PRV_S: | ||
75 | + if (env->mmte & S_PM_ENABLE) { | ||
76 | + mask = env->spmmask; | ||
77 | + base = env->spmbase; | ||
78 | + } | ||
79 | + break; | ||
80 | + case PRV_U: | ||
81 | + if (env->mmte & U_PM_ENABLE) { | ||
82 | + mask = env->upmmask; | ||
83 | + base = env->upmbase; | ||
84 | + } | ||
85 | + break; | ||
86 | + default: | ||
87 | + g_assert_not_reached(); | ||
88 | + } | ||
89 | + } | ||
90 | +#endif | ||
91 | + if (env->xl == MXL_RV32) { | ||
92 | + env->cur_pmmask = mask & UINT32_MAX; | ||
93 | + env->cur_pmbase = base & UINT32_MAX; | ||
94 | + } else { | ||
95 | + env->cur_pmmask = mask; | ||
96 | + env->cur_pmbase = base; | ||
97 | + } | ||
98 | +} | ||
99 | + | ||
100 | #ifndef CONFIG_USER_ONLY | ||
101 | static int riscv_cpu_local_irq_pending(CPURISCVState *env) | ||
102 | { | ||
103 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) | ||
104 | /* tlb_flush is unnecessary as mode is contained in mmu_idx */ | ||
105 | env->priv = newpriv; | ||
106 | env->xl = cpu_recompute_xl(env); | ||
107 | + riscv_cpu_update_mask(env); | ||
108 | |||
109 | /* | ||
110 | * Clear the load reservation - otherwise a reservation placed in one | ||
111 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
113 | --- a/target/riscv/csr.c | 49 | --- a/target/riscv/debug.c |
114 | +++ b/target/riscv/csr.c | 50 | +++ b/target/riscv/debug.c |
115 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mmte(CPURISCVState *env, int csrno, | 51 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
116 | /* hardwiring pm.instruction bit to 0, since it's not supported yet */ | 52 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { |
117 | wpri_val &= ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN); | 53 | /* check U/S/M bit against current privilege level */ |
118 | env->mmte = wpri_val | PM_EXT_DIRTY; | 54 | if ((ctrl >> 3) & BIT(env->priv)) { |
119 | + riscv_cpu_update_mask(env); | 55 | + env->badaddr = pc; |
120 | 56 | return true; | |
121 | /* Set XS and SD bits, since PM CSRs are dirty */ | 57 | } |
122 | mstatus = env->mstatus | MSTATUS_XS; | 58 | } |
123 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mpmmask(CPURISCVState *env, int csrno, | 59 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
124 | uint64_t mstatus; | 60 | if (env->virt_enabled) { |
125 | 61 | /* check VU/VS bit against current privilege level */ | |
126 | env->mpmmask = val; | 62 | if ((ctrl >> 23) & BIT(env->priv)) { |
127 | + if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) { | 63 | + env->badaddr = pc; |
128 | + env->cur_pmmask = val; | 64 | return true; |
129 | + } | 65 | } |
130 | env->mmte |= PM_EXT_DIRTY; | 66 | } else { |
131 | 67 | /* check U/S/M bit against current privilege level */ | |
132 | /* Set XS and SD bits, since PM CSRs are dirty */ | 68 | if ((ctrl >> 3) & BIT(env->priv)) { |
133 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_spmmask(CPURISCVState *env, int csrno, | 69 | + env->badaddr = pc; |
134 | return RISCV_EXCP_NONE; | 70 | return true; |
135 | } | 71 | } |
136 | env->spmmask = val; | 72 | } |
137 | + if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) { | ||
138 | + env->cur_pmmask = val; | ||
139 | + } | ||
140 | env->mmte |= PM_EXT_DIRTY; | ||
141 | |||
142 | /* Set XS and SD bits, since PM CSRs are dirty */ | ||
143 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmmask(CPURISCVState *env, int csrno, | ||
144 | return RISCV_EXCP_NONE; | ||
145 | } | ||
146 | env->upmmask = val; | ||
147 | + if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) { | ||
148 | + env->cur_pmmask = val; | ||
149 | + } | ||
150 | env->mmte |= PM_EXT_DIRTY; | ||
151 | |||
152 | /* Set XS and SD bits, since PM CSRs are dirty */ | ||
153 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mpmbase(CPURISCVState *env, int csrno, | ||
154 | uint64_t mstatus; | ||
155 | |||
156 | env->mpmbase = val; | ||
157 | + if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) { | ||
158 | + env->cur_pmbase = val; | ||
159 | + } | ||
160 | env->mmte |= PM_EXT_DIRTY; | ||
161 | |||
162 | /* Set XS and SD bits, since PM CSRs are dirty */ | ||
163 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_spmbase(CPURISCVState *env, int csrno, | ||
164 | return RISCV_EXCP_NONE; | ||
165 | } | ||
166 | env->spmbase = val; | ||
167 | + if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) { | ||
168 | + env->cur_pmbase = val; | ||
169 | + } | ||
170 | env->mmte |= PM_EXT_DIRTY; | ||
171 | |||
172 | /* Set XS and SD bits, since PM CSRs are dirty */ | ||
173 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, | ||
174 | return RISCV_EXCP_NONE; | ||
175 | } | ||
176 | env->upmbase = val; | ||
177 | + if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) { | ||
178 | + env->cur_pmbase = val; | ||
179 | + } | ||
180 | env->mmte |= PM_EXT_DIRTY; | ||
181 | |||
182 | /* Set XS and SD bits, since PM CSRs are dirty */ | ||
183 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
184 | index XXXXXXX..XXXXXXX 100644 | ||
185 | --- a/target/riscv/machine.c | ||
186 | +++ b/target/riscv/machine.c | ||
187 | @@ -XXX,XX +XXX,XX @@ static int riscv_cpu_post_load(void *opaque, int version_id) | ||
188 | CPURISCVState *env = &cpu->env; | ||
189 | |||
190 | env->xl = cpu_recompute_xl(env); | ||
191 | + riscv_cpu_update_mask(env); | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | -- | 73 | -- |
196 | 2.31.1 | 74 | 2.45.1 |
197 | |||
198 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | When pc is written, it is sign-extended to fill the widest supported XLEN. | 3 | Privileged spec section 4.1.9 mentions: |
4 | 4 | ||
5 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 5 | "When a trap is taken into S-mode, stval is written with |
6 | exception-specific information to assist software in handling the trap. | ||
7 | (...) | ||
8 | |||
9 | If stval is written with a nonzero value when a breakpoint, | ||
10 | address-misaligned, access-fault, or page-fault exception occurs on an | ||
11 | instruction fetch, load, or store, then stval will contain the faulting | ||
12 | virtual address." | ||
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> | ||
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com> |
8 | Message-id: 20220120122050.41546-5-zhiwei_liu@c-sky.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 28 | --- |
11 | target/riscv/translate.c | 25 ++++++++++++++++--- | 29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ |
12 | .../riscv/insn_trans/trans_privileged.c.inc | 2 +- | 30 | 1 file changed, 2 insertions(+) |
13 | target/riscv/insn_trans/trans_rvi.c.inc | 5 ++-- | ||
14 | target/riscv/insn_trans/trans_rvv.c.inc | 4 +-- | ||
15 | 4 files changed, 27 insertions(+), 9 deletions(-) | ||
16 | 31 | ||
17 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/translate.c | ||
20 | +++ b/target/riscv/translate.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64 in) | ||
22 | tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan); | ||
23 | } | ||
24 | |||
25 | +static void gen_set_pc_imm(DisasContext *ctx, target_ulong dest) | ||
26 | +{ | ||
27 | + if (get_xl(ctx) == MXL_RV32) { | ||
28 | + dest = (int32_t)dest; | ||
29 | + } | ||
30 | + tcg_gen_movi_tl(cpu_pc, dest); | ||
31 | +} | ||
32 | + | ||
33 | +static void gen_set_pc(DisasContext *ctx, TCGv dest) | ||
34 | +{ | ||
35 | + if (get_xl(ctx) == MXL_RV32) { | ||
36 | + tcg_gen_ext32s_tl(cpu_pc, dest); | ||
37 | + } else { | ||
38 | + tcg_gen_mov_tl(cpu_pc, dest); | ||
39 | + } | ||
40 | +} | ||
41 | + | ||
42 | static void generate_exception(DisasContext *ctx, int excp) | ||
43 | { | ||
44 | - tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | ||
45 | + gen_set_pc_imm(ctx, ctx->base.pc_next); | ||
46 | gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp)); | ||
47 | ctx->base.is_jmp = DISAS_NORETURN; | ||
48 | } | ||
49 | |||
50 | static void generate_exception_mtval(DisasContext *ctx, int excp) | ||
51 | { | ||
52 | - tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | ||
53 | + gen_set_pc_imm(ctx, ctx->base.pc_next); | ||
54 | tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); | ||
55 | gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp)); | ||
56 | ctx->base.is_jmp = DISAS_NORETURN; | ||
57 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | ||
58 | { | ||
59 | if (translator_use_goto_tb(&ctx->base, dest)) { | ||
60 | tcg_gen_goto_tb(n); | ||
61 | - tcg_gen_movi_tl(cpu_pc, dest); | ||
62 | + gen_set_pc_imm(ctx, dest); | ||
63 | tcg_gen_exit_tb(ctx->base.tb, n); | ||
64 | } else { | ||
65 | - tcg_gen_movi_tl(cpu_pc, dest); | ||
66 | + gen_set_pc_imm(ctx, dest); | ||
67 | tcg_gen_lookup_and_goto_ptr(); | ||
68 | } | ||
69 | } | ||
70 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | 32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc |
71 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
72 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | 34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc |
73 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | 35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc |
74 | @@ -XXX,XX +XXX,XX @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) | 36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) |
75 | static bool trans_wfi(DisasContext *ctx, arg_wfi *a) | 37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { |
76 | { | 38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); |
77 | #ifndef CONFIG_USER_ONLY | 39 | } else { |
78 | - tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | 40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, |
79 | + gen_set_pc_imm(ctx, ctx->pc_succ_insn); | 41 | + offsetof(CPURISCVState, badaddr)); |
80 | gen_helper_wfi(cpu_env); | 42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); |
43 | } | ||
81 | return true; | 44 | return true; |
82 | #else | ||
83 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
86 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
87 | @@ -XXX,XX +XXX,XX @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) | ||
88 | tcg_gen_addi_tl(cpu_pc, get_gpr(ctx, a->rs1, EXT_NONE), a->imm); | ||
89 | tcg_gen_andi_tl(cpu_pc, cpu_pc, (target_ulong)-2); | ||
90 | |||
91 | + gen_set_pc(ctx, cpu_pc); | ||
92 | if (!has_ext(ctx, RVC)) { | ||
93 | TCGv t0 = tcg_temp_new(); | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a) | ||
96 | * FENCE_I is a no-op in QEMU, | ||
97 | * however we need to end the translation block | ||
98 | */ | ||
99 | - tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | ||
100 | + gen_set_pc_imm(ctx, ctx->pc_succ_insn); | ||
101 | tcg_gen_exit_tb(NULL, 0); | ||
102 | ctx->base.is_jmp = DISAS_NORETURN; | ||
103 | return true; | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a) | ||
105 | static bool do_csr_post(DisasContext *ctx) | ||
106 | { | ||
107 | /* We may have changed important cpu state -- exit to main loop. */ | ||
108 | - tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | ||
109 | + gen_set_pc_imm(ctx, ctx->pc_succ_insn); | ||
110 | tcg_gen_exit_tb(NULL, 0); | ||
111 | ctx->base.is_jmp = DISAS_NORETURN; | ||
112 | return true; | ||
113 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
118 | gen_set_gpr(s, rd, dst); | ||
119 | mark_vs_dirty(s); | ||
120 | |||
121 | - tcg_gen_movi_tl(cpu_pc, s->pc_succ_insn); | ||
122 | + gen_set_pc_imm(s, s->pc_succ_insn); | ||
123 | tcg_gen_lookup_and_goto_ptr(); | ||
124 | s->base.is_jmp = DISAS_NORETURN; | ||
125 | |||
126 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) | ||
127 | gen_helper_vsetvl(dst, cpu_env, s1, s2); | ||
128 | gen_set_gpr(s, rd, dst); | ||
129 | mark_vs_dirty(s); | ||
130 | - tcg_gen_movi_tl(cpu_pc, s->pc_succ_insn); | ||
131 | + gen_set_pc_imm(s, s->pc_succ_insn); | ||
132 | tcg_gen_lookup_and_goto_ptr(); | ||
133 | s->base.is_jmp = DISAS_NORETURN; | ||
134 | |||
135 | -- | 45 | -- |
136 | 2.31.1 | 46 | 2.45.1 |
137 | |||
138 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 3 | Add support for Zve32x extension and replace some checks for Zve32f with |
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 4 | Zve32x, since Zve32f depends on Zve32x. |
5 | Message-id: 20220118014522.13613-2-frank.chang@sifive.com | 5 | |
6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
8 | Reviewed-by: Max Chou <max.chou@sifive.com> | ||
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 12 | --- |
8 | target/riscv/cpu.h | 1 + | 13 | target/riscv/cpu_cfg.h | 1 + |
9 | target/riscv/cpu.c | 4 ++++ | 14 | target/riscv/cpu.c | 2 ++ |
10 | target/riscv/cpu_helper.c | 5 ++++- | 15 | target/riscv/cpu_helper.c | 2 +- |
11 | target/riscv/csr.c | 6 +++++- | 16 | target/riscv/csr.c | 2 +- |
12 | target/riscv/translate.c | 2 ++ | 17 | target/riscv/tcg/tcg-cpu.c | 16 ++++++++-------- |
13 | 5 files changed, 16 insertions(+), 2 deletions(-) | 18 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- |
19 | 6 files changed, 15 insertions(+), 12 deletions(-) | ||
14 | 20 | ||
15 | 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 |
16 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.h | 23 | --- a/target/riscv/cpu_cfg.h |
18 | +++ b/target/riscv/cpu.h | 24 | +++ b/target/riscv/cpu_cfg.h |
19 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | 25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
20 | bool ext_icsr; | 26 | bool ext_zhinx; |
21 | bool ext_zfh; | 27 | bool ext_zhinxmin; |
22 | bool ext_zfhmin; | 28 | bool ext_zve32f; |
23 | + bool ext_zve64f; | 29 | + bool ext_zve32x; |
24 | 30 | bool ext_zve64f; | |
25 | char *priv_spec; | 31 | bool ext_zve64d; |
26 | char *user_spec; | 32 | bool ext_zvbb; |
27 | 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 |
28 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/riscv/cpu.c | 35 | --- a/target/riscv/cpu.c |
30 | +++ b/target/riscv/cpu.c | 36 | +++ b/target/riscv/cpu.c |
31 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
32 | } | 38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), |
33 | set_vext_version(env, vext_version); | 39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), |
34 | } | 40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), |
35 | + if (cpu->cfg.ext_zve64f && !cpu->cfg.ext_f) { | 41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
36 | + error_setg(errp, "Zve64f extension depends upon RVF."); | 42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
37 | + return; | 43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
38 | + } | 44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
39 | if (cpu->cfg.ext_j) { | 45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
40 | ext |= RVJ; | 46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), |
41 | } | 47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), |
48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | ||
49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
42 | 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 |
43 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/riscv/cpu_helper.c | 55 | --- a/target/riscv/cpu_helper.c |
45 | +++ b/target/riscv/cpu_helper.c | 56 | +++ b/target/riscv/cpu_helper.c |
46 | @@ -XXX,XX +XXX,XX @@ static RISCVMXL cpu_get_xl(CPURISCVState *env) | 57 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
47 | void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 58 | *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; |
48 | target_ulong *cs_base, uint32_t *pflags) | ||
49 | { | ||
50 | + CPUState *cs = env_cpu(env); | ||
51 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
52 | + | ||
53 | uint32_t flags = 0; | ||
54 | |||
55 | *pc = env->pc; | ||
56 | *cs_base = 0; | 59 | *cs_base = 0; |
57 | 60 | ||
58 | - if (riscv_has_ext(env, RVV)) { | 61 | - if (cpu->cfg.ext_zve32f) { |
59 | + if (riscv_has_ext(env, RVV) || cpu->cfg.ext_zve64f) { | 62 | + if (cpu->cfg.ext_zve32x) { |
60 | /* | 63 | /* |
61 | * If env->vl equals to VLMAX, we can use generic vector operation | 64 | * If env->vl equals to VLMAX, we can use generic vector operation |
62 | * expanders (GVEC) to accerlate the vector operations. | 65 | * expanders (GVEC) to accerlate the vector operations. |
63 | 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 |
64 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
65 | --- a/target/riscv/csr.c | 68 | --- a/target/riscv/csr.c |
66 | +++ b/target/riscv/csr.c | 69 | +++ b/target/riscv/csr.c |
67 | @@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno) | 70 | @@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno) |
68 | 71 | ||
69 | static RISCVException vs(CPURISCVState *env, int csrno) | 72 | static RISCVException vs(CPURISCVState *env, int csrno) |
70 | { | 73 | { |
71 | - if (env->misa_ext & RVV) { | 74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { |
72 | + CPUState *cs = env_cpu(env); | 75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { |
73 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
74 | + | ||
75 | + if (env->misa_ext & RVV || | ||
76 | + cpu->cfg.ext_zve64f) { | ||
77 | #if !defined(CONFIG_USER_ONLY) | 76 | #if !defined(CONFIG_USER_ONLY) |
78 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { | 77 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { |
79 | return RISCV_EXCP_ILLEGAL_INST; | 78 | return RISCV_EXCP_ILLEGAL_INST; |
80 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 79 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
81 | index XXXXXXX..XXXXXXX 100644 | 80 | index XXXXXXX..XXXXXXX 100644 |
82 | --- a/target/riscv/translate.c | 81 | --- a/target/riscv/tcg/tcg-cpu.c |
83 | +++ b/target/riscv/translate.c | 82 | +++ b/target/riscv/tcg/tcg-cpu.c |
84 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 83 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
85 | bool ext_ifencei; | 84 | return; |
86 | bool ext_zfh; | 85 | } |
87 | bool ext_zfhmin; | 86 | |
88 | + bool ext_zve64f; | 87 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { |
89 | bool hlsx; | 88 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); |
90 | /* vector extension */ | 89 | - return; |
91 | bool vill; | 90 | + /* The Zve32f extension depends on the Zve32x extension */ |
92 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 91 | + if (cpu->cfg.ext_zve32f) { |
93 | ctx->ext_ifencei = cpu->cfg.ext_ifencei; | 92 | + if (!riscv_has_ext(env, RVF)) { |
94 | ctx->ext_zfh = cpu->cfg.ext_zfh; | 93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); |
95 | ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; | 94 | + return; |
96 | + ctx->ext_zve64f = cpu->cfg.ext_zve64f; | 95 | + } |
97 | ctx->vlen = cpu->cfg.vlen; | 96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); |
98 | ctx->elen = cpu->cfg.elen; | 97 | } |
99 | ctx->mstatus_hs_fs = FIELD_EX32(tb_flags, TB_FLAGS, MSTATUS_HS_FS); | 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 | |||
100 | -- | 137 | -- |
101 | 2.31.1 | 138 | 2.45.1 |
102 | |||
103 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and |
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 4 | enabling Zve64x enables Zve32x according to their dependency. |
5 | Message-id: 20220118014522.13613-11-frank.chang@sifive.com | 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 | --- | 13 | --- |
8 | target/riscv/cpu.c | 1 + | 14 | target/riscv/cpu_cfg.h | 1 + |
9 | 1 file changed, 1 insertion(+) | 15 | target/riscv/cpu.c | 2 ++ |
16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ | ||
17 | 3 files changed, 14 insertions(+), 6 deletions(-) | ||
10 | 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; | ||
11 | 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 |
12 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
14 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
16 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | 36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
17 | DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), | 37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
18 | DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, false), | 38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
19 | + DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), | 39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), |
20 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | 40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
21 | DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | 41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), |
42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), | ||
43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), | ||
48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), | ||
50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), | ||
51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/tcg/tcg-cpu.c | ||
54 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
56 | |||
57 | /* The Zve64d extension depends on the Zve64f extension */ | ||
58 | if (cpu->cfg.ext_zve64d) { | ||
59 | + if (!riscv_has_ext(env, RVD)) { | ||
60 | + error_setg(errp, "Zve64d/V extensions require D extension"); | ||
61 | + return; | ||
62 | + } | ||
63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
64 | } | ||
65 | |||
66 | - /* The Zve64f extension depends on the Zve32f extension */ | ||
67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ | ||
68 | if (cpu->cfg.ext_zve64f) { | ||
69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); | ||
70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | ||
71 | } | ||
72 | |||
73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
74 | - error_setg(errp, "Zve64d/V extensions require D extension"); | ||
75 | - return; | ||
76 | + /* The Zve64x extension depends on the Zve32x extension */ | ||
77 | + if (cpu->cfg.ext_zve64x) { | ||
78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
79 | } | ||
80 | |||
81 | /* The Zve32f extension depends on the Zve32x extension */ | ||
82 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { | ||
88 | error_setg( | ||
89 | errp, | ||
90 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
91 | + "Zvbc and Zvknhb extensions require V or Zve64x extensions"); | ||
92 | return; | ||
93 | } | ||
22 | 94 | ||
23 | -- | 95 | -- |
24 | 2.31.1 | 96 | 2.45.1 |
25 | |||
26 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | When sew <= 32bits, not need to extend scalar reg. | 3 | In current implementation, the gdbstub allows reading vector registers |
4 | When sew > 32bits, if xlen is less that sew, we should sign extend | 4 | only if V extension is supported. However, all vector extensions and |
5 | the scalar register, except explicitly specified by the spec. | 5 | vector crypto extensions have the vector registers and they all depend |
6 | on Zve32x. The gdbstub should check for Zve32x instead. | ||
6 | 7 | ||
7 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
9 | Message-id: 20220120122050.41546-21-zhiwei_liu@c-sky.com | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 13 | --- |
12 | target/riscv/insn_trans/trans_rvv.c.inc | 2 +- | 14 | target/riscv/gdbstub.c | 2 +- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 16 | ||
15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 19 | --- a/target/riscv/gdbstub.c |
18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 20 | +++ b/target/riscv/gdbstub.c |
19 | @@ -XXX,XX +XXX,XX @@ static bool opivx_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, uint32_t vm, | 21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) |
20 | dest = tcg_temp_new_ptr(); | 22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), |
21 | mask = tcg_temp_new_ptr(); | 23 | 0); |
22 | src2 = tcg_temp_new_ptr(); | 24 | } |
23 | - src1 = get_gpr(s, rs1, EXT_NONE); | 25 | - if (env->misa_ext & RVV) { |
24 | + src1 = get_gpr(s, rs1, EXT_SIGN); | 26 | + if (cpu->cfg.ext_zve32x) { |
25 | 27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, | |
26 | data = FIELD_DP32(data, VDATA, VM, vm); | 28 | riscv_gdb_set_vector, |
27 | data = FIELD_DP32(data, VDATA, LMUL, s->lmul); | 29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), |
28 | -- | 30 | -- |
29 | 2.31.1 | 31 | 2.45.1 |
30 | |||
31 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | In some cases, we must restore the guest PC to the address of the start of | 3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s |
4 | the TB, such as when the instruction counter hits zero. So extend pc register | 4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element |
5 | according to current xlen for these cases. | 5 | agnostic policy. |
6 | 6 | ||
7 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 7 | However, this function can't deal the big endian situation. This patch fixes |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | the problem by adding handling of such case. |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | |
10 | Message-id: 20220120122050.41546-8-zhiwei_liu@c-sky.com | 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> | ||
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/cpu.c | 22 +++++++++++++++++++--- | 17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ |
14 | 1 file changed, 19 insertions(+), 3 deletions(-) | 18 | 1 file changed, 22 insertions(+) |
15 | 19 | ||
16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c |
17 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu.c | 22 | --- a/target/riscv/vector_internals.c |
19 | +++ b/target/riscv/cpu.c | 23 | +++ b/target/riscv/vector_internals.c |
20 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_set_pc(CPUState *cs, vaddr value) | 24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, |
21 | { | 25 | if (tot - cnt == 0) { |
22 | RISCVCPU *cpu = RISCV_CPU(cs); | 26 | return ; |
23 | CPURISCVState *env = &cpu->env; | 27 | } |
24 | - env->pc = value; | ||
25 | + | 28 | + |
26 | + if (env->xl == MXL_RV32) { | 29 | + if (HOST_BIG_ENDIAN) { |
27 | + env->pc = (int32_t)value; | 30 | + /* |
28 | + } else { | 31 | + * Deal the situation when the elements are insdie |
29 | + env->pc = value; | 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 */ | ||
30 | + } | 49 | + } |
50 | memset(base + cnt, -1, tot - cnt); | ||
31 | } | 51 | } |
32 | 52 | ||
33 | static void riscv_cpu_synchronize_from_tb(CPUState *cs, | ||
34 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_synchronize_from_tb(CPUState *cs, | ||
35 | { | ||
36 | RISCVCPU *cpu = RISCV_CPU(cs); | ||
37 | CPURISCVState *env = &cpu->env; | ||
38 | - env->pc = tb->pc; | ||
39 | + RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
40 | + | ||
41 | + if (xl == MXL_RV32) { | ||
42 | + env->pc = (int32_t)tb->pc; | ||
43 | + } else { | ||
44 | + env->pc = tb->pc; | ||
45 | + } | ||
46 | } | ||
47 | |||
48 | static bool riscv_cpu_has_work(CPUState *cs) | ||
49 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_work(CPUState *cs) | ||
50 | void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb, | ||
51 | target_ulong *data) | ||
52 | { | ||
53 | - env->pc = data[0]; | ||
54 | + RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
55 | + if (xl == MXL_RV32) { | ||
56 | + env->pc = (int32_t)data[0]; | ||
57 | + } else { | ||
58 | + env->pc = data[0]; | ||
59 | + } | ||
60 | } | ||
61 | |||
62 | static void riscv_cpu_reset(DeviceState *dev) | ||
63 | -- | 53 | -- |
64 | 2.31.1 | 54 | 2.45.1 |
65 | |||
66 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Yangyu Chen <cyy@cyyself.name> |
---|---|---|---|
2 | 2 | ||
3 | When swap regs for hypervisor, the value of vsstatus or mstatus_hs | 3 | This code has a typo that writes zvkb to zvkg, causing users can't |
4 | should have the right XLEN. Otherwise, it will propagate to mstatus. | 4 | enable zvkb through the config. This patch gets this fixed. |
5 | 5 | ||
6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 6 | Signed-off-by: Yangyu Chen <cyy@cyyself.name> |
7 | Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions") | ||
8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20220120122050.41546-22-zhiwei_liu@c-sky.com | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> | ||
12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 15 | --- |
11 | target/riscv/cpu.c | 10 ++++++++++ | 16 | target/riscv/cpu.c | 2 +- |
12 | 1 file changed, 10 insertions(+) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 18 | ||
14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu.c | 21 | --- a/target/riscv/cpu.c |
17 | +++ b/target/riscv/cpu.c | 22 | +++ b/target/riscv/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | 23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
19 | */ | 24 | /* Vector cryptography extensions */ |
20 | env->mstatus = set_field(env->mstatus, MSTATUS64_SXL, env->misa_mxl); | 25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), |
21 | env->mstatus = set_field(env->mstatus, MSTATUS64_UXL, env->misa_mxl); | 26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), |
22 | + if (riscv_has_ext(env, RVH)) { | 27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), |
23 | + env->vsstatus = set_field(env->vsstatus, | 28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), |
24 | + MSTATUS64_SXL, env->misa_mxl); | 29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), |
25 | + env->vsstatus = set_field(env->vsstatus, | 30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), |
26 | + MSTATUS64_UXL, env->misa_mxl); | 31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), |
27 | + env->mstatus_hs = set_field(env->mstatus_hs, | ||
28 | + MSTATUS64_SXL, env->misa_mxl); | ||
29 | + env->mstatus_hs = set_field(env->mstatus_hs, | ||
30 | + MSTATUS64_UXL, env->misa_mxl); | ||
31 | + } | ||
32 | } | ||
33 | env->mcause = 0; | ||
34 | env->pc = env->resetvec; | ||
35 | -- | 32 | -- |
36 | 2.31.1 | 33 | 2.45.1 |
37 | 34 | ||
38 | 35 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | Use cached cur_pmmask and cur_pmbase to infer the | 3 | In this patch, we modify the decoder to be a freely composable data |
4 | current PM mode. | 4 | structure instead of a hardcoded one. It can be dynamically builded up |
5 | according to the extensions. | ||
6 | This approach has several benefits: | ||
7 | 1. Provides support for heterogeneous cpu architectures. As we add decoder in | ||
8 | RISCVCPU, each cpu can have their own decoder, and the decoders can be | ||
9 | different due to cpu's features. | ||
10 | 2. Improve the decoding efficiency. We run the guard_func to see if the decoder | ||
11 | can be added to the dynamic_decoder when building up the decoder. Therefore, | ||
12 | there is no need to run the guard_func when decoding each instruction. It can | ||
13 | improve the decoding efficiency | ||
14 | 3. For vendor or dynamic cpus, it allows them to customize their own decoder | ||
15 | functions to improve decoding efficiency, especially when vendor-defined | ||
16 | instruction sets increase. Because of dynamic building up, it can skip the other | ||
17 | decoder guard functions when decoding. | ||
18 | 4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal | ||
19 | overhead for users that don't need this particular vendor decoder. | ||
5 | 20 | ||
6 | This may decrease the TCG IR by one when pm_enabled | 21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
7 | is true and pm_base_enabled is false. | 22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> |
8 | 23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | |
9 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-id: 20220120122050.41546-15-zhiwei_liu@c-sky.com | 26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 28 | --- |
15 | target/riscv/cpu.h | 3 ++- | 29 | target/riscv/cpu.h | 1 + |
16 | target/riscv/cpu_helper.c | 24 ++++++------------------ | 30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ |
17 | target/riscv/translate.c | 12 ++++++++---- | 31 | target/riscv/cpu.c | 1 + |
18 | 3 files changed, 16 insertions(+), 23 deletions(-) | 32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ |
33 | target/riscv/translate.c | 31 +++++++++++++++---------------- | ||
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
19 | 35 | ||
20 | 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 |
21 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/cpu.h | 38 | --- a/target/riscv/cpu.h |
23 | +++ b/target/riscv/cpu.h | 39 | +++ b/target/riscv/cpu.h |
24 | @@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, MSTATUS_HS_VS, 18, 2) | 40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
25 | /* The combination of MXL/SXL/UXL that applies to the current cpu mode. */ | 41 | uint32_t pmu_avail_ctrs; |
26 | FIELD(TB_FLAGS, XL, 20, 2) | 42 | /* Mapping of events to counters */ |
27 | /* If PointerMasking should be applied */ | 43 | GHashTable *pmu_event_ctr_map; |
28 | -FIELD(TB_FLAGS, PM_ENABLED, 22, 1) | 44 | + const GPtrArray *decoders; |
29 | +FIELD(TB_FLAGS, PM_MASK_ENABLED, 22, 1) | 45 | }; |
30 | +FIELD(TB_FLAGS, PM_BASE_ENABLED, 23, 1) | 46 | |
31 | 47 | /** | |
32 | #ifdef TARGET_RISCV32 | 48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h |
33 | #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) | ||
34 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/cpu_helper.c | 50 | --- a/target/riscv/tcg/tcg-cpu.h |
37 | +++ b/target/riscv/cpu_helper.c | 51 | +++ b/target/riscv/tcg/tcg-cpu.h |
38 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); |
39 | flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_VS, | 53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); |
40 | get_field(env->mstatus_hs, MSTATUS_VS)); | 54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); |
55 | |||
56 | +struct DisasContext; | ||
57 | +struct RISCVCPUConfig; | ||
58 | +typedef struct RISCVDecoder { | ||
59 | + bool (*guard_func)(const struct RISCVCPUConfig *); | ||
60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
61 | +} RISCVDecoder; | ||
62 | + | ||
63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
64 | + | ||
65 | +extern const size_t decoder_table_size; | ||
66 | + | ||
67 | +extern const RISCVDecoder decoder_table[]; | ||
68 | + | ||
69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); | ||
70 | + | ||
71 | #endif | ||
72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/target/riscv/cpu.c | ||
75 | +++ b/target/riscv/cpu.c | ||
76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
77 | error_propagate(errp, local_err); | ||
78 | return; | ||
79 | } | ||
80 | + riscv_tcg_cpu_finalize_dynamic_decoder(cpu); | ||
81 | } else if (kvm_enabled()) { | ||
82 | riscv_kvm_cpu_finalize_features(cpu, &local_err); | ||
83 | if (local_err != NULL) { | ||
84 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/riscv/tcg/tcg-cpu.c | ||
87 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
88 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
41 | } | 89 | } |
42 | - if (riscv_has_ext(env, RVJ)) { | 90 | } |
43 | - int priv = flags & TB_FLAGS_PRIV_MMU_MASK; | 91 | |
44 | - bool pm_enabled = false; | 92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
45 | - switch (priv) { | 93 | +{ |
46 | - case PRV_U: | 94 | + GPtrArray *dynamic_decoders; |
47 | - pm_enabled = env->mmte & U_PM_ENABLE; | 95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); |
48 | - break; | 96 | + for (size_t i = 0; i < decoder_table_size; ++i) { |
49 | - case PRV_S: | 97 | + if (decoder_table[i].guard_func && |
50 | - pm_enabled = env->mmte & S_PM_ENABLE; | 98 | + decoder_table[i].guard_func(&cpu->cfg)) { |
51 | - break; | 99 | + g_ptr_array_add(dynamic_decoders, |
52 | - case PRV_M: | 100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); |
53 | - pm_enabled = env->mmte & M_PM_ENABLE; | 101 | + } |
54 | - break; | ||
55 | - default: | ||
56 | - g_assert_not_reached(); | ||
57 | - } | ||
58 | - flags = FIELD_DP32(flags, TB_FLAGS, PM_ENABLED, pm_enabled); | ||
59 | - } | ||
60 | #endif | ||
61 | |||
62 | flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl); | ||
63 | + if (env->cur_pmmask < (env->xl == MXL_RV32 ? UINT32_MAX : UINT64_MAX)) { | ||
64 | + flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1); | ||
65 | + } | 102 | + } |
66 | + if (env->cur_pmbase != 0) { | 103 | + |
67 | + flags = FIELD_DP32(flags, TB_FLAGS, PM_BASE_ENABLED, 1); | 104 | + cpu->decoders = dynamic_decoders; |
68 | + } | 105 | +} |
69 | 106 | + | |
70 | *pflags = flags; | 107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) |
71 | } | 108 | { |
109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; | ||
72 | 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 |
73 | index XXXXXXX..XXXXXXX 100644 | 111 | index XXXXXXX..XXXXXXX 100644 |
74 | --- a/target/riscv/translate.c | 112 | --- a/target/riscv/translate.c |
75 | +++ 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 */ | ||
76 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
77 | /* Space for 3 operands plus 1 extra for address computation. */ | 124 | /* FRM is known to contain a valid value. */ |
78 | TCGv temp[4]; | 125 | bool frm_valid; |
79 | /* PointerMasking extension */ | 126 | bool insn_start_updated; |
80 | - bool pm_enabled; | 127 | + const GPtrArray *decoders; |
81 | + bool pm_mask_enabled; | ||
82 | + bool pm_base_enabled; | ||
83 | } DisasContext; | 128 | } DisasContext; |
84 | 129 | ||
85 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | 130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) |
86 | @@ -XXX,XX +XXX,XX @@ static TCGv get_address(DisasContext *ctx, int rs1, int imm) | 131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) |
87 | TCGv src1 = get_gpr(ctx, rs1, EXT_NONE); | 132 | return (first_word & 3) == 3 ? 4 : 2; |
88 | |||
89 | tcg_gen_addi_tl(addr, src1, imm); | ||
90 | - if (ctx->pm_enabled) { | ||
91 | + if (ctx->pm_mask_enabled) { | ||
92 | tcg_gen_and_tl(addr, addr, pm_mask); | ||
93 | - tcg_gen_or_tl(addr, addr, pm_base); | ||
94 | } else if (get_xl(ctx) == MXL_RV32) { | ||
95 | tcg_gen_ext32u_tl(addr, addr); | ||
96 | } | ||
97 | + if (ctx->pm_base_enabled) { | ||
98 | + tcg_gen_or_tl(addr, addr, pm_base); | ||
99 | + } | ||
100 | return addr; | ||
101 | } | 133 | } |
102 | 134 | ||
135 | +const RISCVDecoder decoder_table[] = { | ||
136 | + { always_true_p, decode_insn32 }, | ||
137 | + { has_xthead_p, decode_xthead}, | ||
138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, | ||
139 | +}; | ||
140 | + | ||
141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); | ||
142 | + | ||
143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
144 | { | ||
145 | - /* | ||
146 | - * A table with predicate (i.e., guard) functions and decoder functions | ||
147 | - * that are tested in-order until a decoder matches onto the opcode. | ||
148 | - */ | ||
149 | - static const struct { | ||
150 | - bool (*guard_func)(const RISCVCPUConfig *); | ||
151 | - bool (*decode_func)(DisasContext *, uint32_t); | ||
152 | - } decoders[] = { | ||
153 | - { always_true_p, decode_insn32 }, | ||
154 | - { has_xthead_p, decode_xthead }, | ||
155 | - { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, | ||
156 | - }; | ||
157 | - | ||
158 | ctx->virt_inst_excp = false; | ||
159 | ctx->cur_insn_len = insn_len(opcode); | ||
160 | /* Check for compressed insn */ | ||
161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
162 | ctx->base.pc_next + 2)); | ||
163 | ctx->opcode = opcode32; | ||
164 | |||
165 | - for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) { | ||
166 | - if (decoders[i].guard_func(ctx->cfg_ptr) && | ||
167 | - decoders[i].decode_func(ctx, opcode32)) { | ||
168 | + for (guint i = 0; i < ctx->decoders->len; ++i) { | ||
169 | + riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i); | ||
170 | + if (func(ctx, opcode32)) { | ||
171 | return; | ||
172 | } | ||
173 | } | ||
103 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) |
104 | ctx->cs = cs; | 175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); |
105 | ctx->ntemp = 0; | ||
106 | memset(ctx->temp, 0, sizeof(ctx->temp)); | ||
107 | - ctx->pm_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_ENABLED); | ||
108 | + ctx->pm_mask_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_MASK_ENABLED); | ||
109 | + ctx->pm_base_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLED); | ||
110 | ctx->zero = tcg_constant_tl(0); | 176 | ctx->zero = tcg_constant_tl(0); |
177 | ctx->virt_inst_excp = false; | ||
178 | + ctx->decoders = cpu->decoders; | ||
111 | } | 179 | } |
112 | 180 | ||
181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) | ||
113 | -- | 182 | -- |
114 | 2.31.1 | 183 | 2.45.1 |
115 | |||
116 | diff view generated by jsdifflib |
1 | From: Yifei Jiang <jiangyifei@huawei.com> | 1 | From: Christoph Müllner <christoph.muellner@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | Add target/riscv/kvm.c to place kvm_arch_* function needed by | 3 | The th.sxstatus CSR can be used to identify available custom extension |
4 | kvm/kvm-all.c. | 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 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | 7 | An important property of this patch is, that the th.sxstatus MAEE field |
7 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | 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> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | 22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> |
10 | Message-id: 20220112081329.1835-3-jiangyifei@huawei.com | 23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 25 | --- |
13 | target/riscv/kvm.c | 133 +++++++++++++++++++++++++++++++++++++++ | 26 | MAINTAINERS | 1 + |
14 | target/riscv/meson.build | 1 + | 27 | target/riscv/cpu.h | 3 ++ |
15 | 2 files changed, 134 insertions(+) | 28 | target/riscv/cpu.c | 1 + |
16 | create mode 100644 target/riscv/kvm.c | 29 | target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++ |
30 | target/riscv/meson.build | 1 + | ||
31 | 5 files changed, 85 insertions(+) | ||
32 | create mode 100644 target/riscv/th_csr.c | ||
17 | 33 | ||
18 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | 34 | diff --git a/MAINTAINERS b/MAINTAINERS |
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/MAINTAINERS | ||
37 | +++ b/MAINTAINERS | ||
38 | @@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org | ||
39 | S: Supported | ||
40 | F: target/riscv/insn_trans/trans_xthead.c.inc | ||
41 | F: target/riscv/xthead*.decode | ||
42 | +F: target/riscv/th_* | ||
43 | F: disas/riscv-xthead* | ||
44 | |||
45 | RISC-V XVentanaCondOps extension | ||
46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/riscv/cpu.h | ||
49 | +++ b/target/riscv/cpu.h | ||
50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
51 | uint8_t satp_mode_max_from_map(uint32_t map); | ||
52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); | ||
53 | |||
54 | +/* Implemented in th_csr.c */ | ||
55 | +void th_register_custom_csrs(RISCVCPU *cpu); | ||
56 | + | ||
57 | #endif /* RISCV_CPU_H */ | ||
58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/riscv/cpu.c | ||
61 | +++ b/target/riscv/cpu.c | ||
62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) | ||
63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; | ||
64 | #ifndef CONFIG_USER_ONLY | ||
65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); | ||
66 | + th_register_custom_csrs(cpu); | ||
67 | #endif | ||
68 | |||
69 | /* inherited from parent obj via riscv_cpu_init() */ | ||
70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c | ||
19 | new file mode 100644 | 71 | new file mode 100644 |
20 | index XXXXXXX..XXXXXXX | 72 | index XXXXXXX..XXXXXXX |
21 | --- /dev/null | 73 | --- /dev/null |
22 | +++ b/target/riscv/kvm.c | 74 | +++ b/target/riscv/th_csr.c |
23 | @@ -XXX,XX +XXX,XX @@ | 75 | @@ -XXX,XX +XXX,XX @@ |
24 | +/* | 76 | +/* |
25 | + * RISC-V implementation of KVM hooks | 77 | + * T-Head-specific CSRs. |
26 | + * | 78 | + * |
27 | + * Copyright (c) 2020 Huawei Technologies Co., Ltd | 79 | + * Copyright (c) 2024 VRULL GmbH |
28 | + * | 80 | + * |
29 | + * This program is free software; you can redistribute it and/or modify it | 81 | + * This program is free software; you can redistribute it and/or modify it |
30 | + * under the terms and conditions of the GNU General Public License, | 82 | + * under the terms and conditions of the GNU General Public License, |
31 | + * version 2 or later, as published by the Free Software Foundation. | 83 | + * version 2 or later, as published by the Free Software Foundation. |
32 | + * | 84 | + * |
... | ... | ||
38 | + * You should have received a copy of the GNU General Public License along with | 90 | + * You should have received a copy of the GNU General Public License along with |
39 | + * this program. If not, see <http://www.gnu.org/licenses/>. | 91 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
40 | + */ | 92 | + */ |
41 | + | 93 | + |
42 | +#include "qemu/osdep.h" | 94 | +#include "qemu/osdep.h" |
43 | +#include <sys/ioctl.h> | 95 | +#include "cpu.h" |
96 | +#include "cpu_vendorid.h" | ||
44 | + | 97 | + |
45 | +#include <linux/kvm.h> | 98 | +#define CSR_TH_SXSTATUS 0x5c0 |
46 | + | 99 | + |
47 | +#include "qemu-common.h" | 100 | +/* TH_SXSTATUS bits */ |
48 | +#include "qemu/timer.h" | 101 | +#define TH_SXSTATUS_UCME BIT(16) |
49 | +#include "qemu/error-report.h" | 102 | +#define TH_SXSTATUS_MAEE BIT(21) |
50 | +#include "qemu/main-loop.h" | 103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) |
51 | +#include "sysemu/sysemu.h" | ||
52 | +#include "sysemu/kvm.h" | ||
53 | +#include "sysemu/kvm_int.h" | ||
54 | +#include "cpu.h" | ||
55 | +#include "trace.h" | ||
56 | +#include "hw/pci/pci.h" | ||
57 | +#include "exec/memattrs.h" | ||
58 | +#include "exec/address-spaces.h" | ||
59 | +#include "hw/boards.h" | ||
60 | +#include "hw/irq.h" | ||
61 | +#include "qemu/log.h" | ||
62 | +#include "hw/loader.h" | ||
63 | + | 104 | + |
64 | +const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | 105 | +typedef struct { |
65 | + KVM_CAP_LAST_INFO | 106 | + int csrno; |
66 | +}; | 107 | + int (*insertion_test)(RISCVCPU *cpu); |
108 | + riscv_csr_operations csr_ops; | ||
109 | +} riscv_csr; | ||
67 | + | 110 | + |
68 | +int kvm_arch_get_registers(CPUState *cs) | 111 | +static RISCVException smode(CPURISCVState *env, int csrno) |
69 | +{ | 112 | +{ |
113 | + if (riscv_has_ext(env, RVS)) { | ||
114 | + return RISCV_EXCP_NONE; | ||
115 | + } | ||
116 | + | ||
117 | + return RISCV_EXCP_ILLEGAL_INST; | ||
118 | +} | ||
119 | + | ||
120 | +static int test_thead_mvendorid(RISCVCPU *cpu) | ||
121 | +{ | ||
122 | + if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) { | ||
123 | + return -1; | ||
124 | + } | ||
125 | + | ||
70 | + return 0; | 126 | + return 0; |
71 | +} | 127 | +} |
72 | + | 128 | + |
73 | +int kvm_arch_put_registers(CPUState *cs, int level) | 129 | +static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno, |
130 | + target_ulong *val) | ||
74 | +{ | 131 | +{ |
75 | + return 0; | 132 | + /* We don't set MAEE here, because QEMU does not implement MAEE. */ |
133 | + *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE; | ||
134 | + return RISCV_EXCP_NONE; | ||
76 | +} | 135 | +} |
77 | + | 136 | + |
78 | +int kvm_arch_release_virq_post(int virq) | 137 | +static riscv_csr th_csr_list[] = { |
138 | + { | ||
139 | + .csrno = CSR_TH_SXSTATUS, | ||
140 | + .insertion_test = test_thead_mvendorid, | ||
141 | + .csr_ops = { "th.sxstatus", smode, read_th_sxstatus } | ||
142 | + } | ||
143 | +}; | ||
144 | + | ||
145 | +void th_register_custom_csrs(RISCVCPU *cpu) | ||
79 | +{ | 146 | +{ |
80 | + return 0; | 147 | + for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) { |
81 | +} | 148 | + int csrno = th_csr_list[i].csrno; |
82 | + | 149 | + riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops; |
83 | +int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, | 150 | + if (!th_csr_list[i].insertion_test(cpu)) { |
84 | + uint64_t address, uint32_t data, PCIDevice *dev) | 151 | + riscv_set_csr_ops(csrno, csr_ops); |
85 | +{ | 152 | + } |
86 | + return 0; | 153 | + } |
87 | +} | ||
88 | + | ||
89 | +int kvm_arch_destroy_vcpu(CPUState *cs) | ||
90 | +{ | ||
91 | + return 0; | ||
92 | +} | ||
93 | + | ||
94 | +unsigned long kvm_arch_vcpu_id(CPUState *cpu) | ||
95 | +{ | ||
96 | + return cpu->cpu_index; | ||
97 | +} | ||
98 | + | ||
99 | +void kvm_arch_init_irq_routing(KVMState *s) | ||
100 | +{ | ||
101 | +} | ||
102 | + | ||
103 | +int kvm_arch_init_vcpu(CPUState *cs) | ||
104 | +{ | ||
105 | + return 0; | ||
106 | +} | ||
107 | + | ||
108 | +int kvm_arch_msi_data_to_gsi(uint32_t data) | ||
109 | +{ | ||
110 | + abort(); | ||
111 | +} | ||
112 | + | ||
113 | +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, | ||
114 | + int vector, PCIDevice *dev) | ||
115 | +{ | ||
116 | + return 0; | ||
117 | +} | ||
118 | + | ||
119 | +int kvm_arch_init(MachineState *ms, KVMState *s) | ||
120 | +{ | ||
121 | + return 0; | ||
122 | +} | ||
123 | + | ||
124 | +int kvm_arch_irqchip_create(KVMState *s) | ||
125 | +{ | ||
126 | + return 0; | ||
127 | +} | ||
128 | + | ||
129 | +int kvm_arch_process_async_events(CPUState *cs) | ||
130 | +{ | ||
131 | + return 0; | ||
132 | +} | ||
133 | + | ||
134 | +void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) | ||
135 | +{ | ||
136 | +} | ||
137 | + | ||
138 | +MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) | ||
139 | +{ | ||
140 | + return MEMTXATTRS_UNSPECIFIED; | ||
141 | +} | ||
142 | + | ||
143 | +bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
144 | +{ | ||
145 | + return true; | ||
146 | +} | ||
147 | + | ||
148 | +int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
149 | +{ | ||
150 | + return 0; | ||
151 | +} | ||
152 | + | ||
153 | +bool kvm_arch_cpu_check_are_resettable(void) | ||
154 | +{ | ||
155 | + return true; | ||
156 | +} | 154 | +} |
157 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | 155 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
158 | index XXXXXXX..XXXXXXX 100644 | 156 | index XXXXXXX..XXXXXXX 100644 |
159 | --- a/target/riscv/meson.build | 157 | --- a/target/riscv/meson.build |
160 | +++ b/target/riscv/meson.build | 158 | +++ b/target/riscv/meson.build |
161 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | 159 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( |
162 | 'translate.c', | 160 | 'monitor.c', |
163 | 'm128_helper.c' | 161 | 'machine.c', |
162 | 'pmu.c', | ||
163 | + 'th_csr.c', | ||
164 | 'time_helper.c', | ||
165 | 'riscv-qmp-cmds.c', | ||
164 | )) | 166 | )) |
165 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) | ||
166 | |||
167 | riscv_softmmu_ss = ss.source_set() | ||
168 | riscv_softmmu_ss.add(files( | ||
169 | -- | 167 | -- |
170 | 2.31.1 | 168 | 2.45.1 |
171 | 169 | ||
172 | 170 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Get isa info from kvm while kvm init. | ||
4 | |||
5 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
6 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
9 | Message-id: 20220112081329.1835-4-jiangyifei@huawei.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/kvm.c | 34 +++++++++++++++++++++++++++++++++- | ||
13 | 1 file changed, 33 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/kvm.c | ||
18 | +++ b/target/riscv/kvm.c | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #include "qemu/log.h" | ||
21 | #include "hw/loader.h" | ||
22 | |||
23 | +static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
24 | + uint64_t idx) | ||
25 | +{ | ||
26 | + uint64_t id = KVM_REG_RISCV | type | idx; | ||
27 | + | ||
28 | + switch (riscv_cpu_mxl(env)) { | ||
29 | + case MXL_RV32: | ||
30 | + id |= KVM_REG_SIZE_U32; | ||
31 | + break; | ||
32 | + case MXL_RV64: | ||
33 | + id |= KVM_REG_SIZE_U64; | ||
34 | + break; | ||
35 | + default: | ||
36 | + g_assert_not_reached(); | ||
37 | + } | ||
38 | + return id; | ||
39 | +} | ||
40 | + | ||
41 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
42 | KVM_CAP_LAST_INFO | ||
43 | }; | ||
44 | @@ -XXX,XX +XXX,XX @@ void kvm_arch_init_irq_routing(KVMState *s) | ||
45 | |||
46 | int kvm_arch_init_vcpu(CPUState *cs) | ||
47 | { | ||
48 | - return 0; | ||
49 | + int ret = 0; | ||
50 | + target_ulong isa; | ||
51 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
52 | + CPURISCVState *env = &cpu->env; | ||
53 | + uint64_t id; | ||
54 | + | ||
55 | + id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, | ||
56 | + KVM_REG_RISCV_CONFIG_REG(isa)); | ||
57 | + ret = kvm_get_one_reg(cs, id, &isa); | ||
58 | + if (ret) { | ||
59 | + return ret; | ||
60 | + } | ||
61 | + env->misa_ext = isa; | ||
62 | + | ||
63 | + return ret; | ||
64 | } | ||
65 | |||
66 | int kvm_arch_msi_data_to_gsi(uint32_t data) | ||
67 | -- | ||
68 | 2.31.1 | ||
69 | |||
70 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Get GPR CSR and FP registers from kvm by KVM_GET_ONE_REG ioctl. | ||
4 | |||
5 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
6 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
9 | Message-id: 20220112081329.1835-5-jiangyifei@huawei.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/kvm.c | 112 ++++++++++++++++++++++++++++++++++++++++++++- | ||
13 | 1 file changed, 111 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/kvm.c | ||
18 | +++ b/target/riscv/kvm.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
20 | return id; | ||
21 | } | ||
22 | |||
23 | +#define RISCV_CORE_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, \ | ||
24 | + KVM_REG_RISCV_CORE_REG(name)) | ||
25 | + | ||
26 | +#define RISCV_CSR_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \ | ||
27 | + KVM_REG_RISCV_CSR_REG(name)) | ||
28 | + | ||
29 | +#define RISCV_FP_F_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_F, idx) | ||
30 | + | ||
31 | +#define RISCV_FP_D_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_D, idx) | ||
32 | + | ||
33 | +#define KVM_RISCV_GET_CSR(cs, env, csr, reg) \ | ||
34 | + do { \ | ||
35 | + int ret = kvm_get_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \ | ||
36 | + if (ret) { \ | ||
37 | + return ret; \ | ||
38 | + } \ | ||
39 | + } while (0) | ||
40 | + | ||
41 | +static int kvm_riscv_get_regs_core(CPUState *cs) | ||
42 | +{ | ||
43 | + int ret = 0; | ||
44 | + int i; | ||
45 | + target_ulong reg; | ||
46 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
47 | + | ||
48 | + ret = kvm_get_one_reg(cs, RISCV_CORE_REG(env, regs.pc), ®); | ||
49 | + if (ret) { | ||
50 | + return ret; | ||
51 | + } | ||
52 | + env->pc = reg; | ||
53 | + | ||
54 | + for (i = 1; i < 32; i++) { | ||
55 | + uint64_t id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, i); | ||
56 | + ret = kvm_get_one_reg(cs, id, ®); | ||
57 | + if (ret) { | ||
58 | + return ret; | ||
59 | + } | ||
60 | + env->gpr[i] = reg; | ||
61 | + } | ||
62 | + | ||
63 | + return ret; | ||
64 | +} | ||
65 | + | ||
66 | +static int kvm_riscv_get_regs_csr(CPUState *cs) | ||
67 | +{ | ||
68 | + int ret = 0; | ||
69 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
70 | + | ||
71 | + KVM_RISCV_GET_CSR(cs, env, sstatus, env->mstatus); | ||
72 | + KVM_RISCV_GET_CSR(cs, env, sie, env->mie); | ||
73 | + KVM_RISCV_GET_CSR(cs, env, stvec, env->stvec); | ||
74 | + KVM_RISCV_GET_CSR(cs, env, sscratch, env->sscratch); | ||
75 | + KVM_RISCV_GET_CSR(cs, env, sepc, env->sepc); | ||
76 | + KVM_RISCV_GET_CSR(cs, env, scause, env->scause); | ||
77 | + KVM_RISCV_GET_CSR(cs, env, stval, env->stval); | ||
78 | + KVM_RISCV_GET_CSR(cs, env, sip, env->mip); | ||
79 | + KVM_RISCV_GET_CSR(cs, env, satp, env->satp); | ||
80 | + return ret; | ||
81 | +} | ||
82 | + | ||
83 | +static int kvm_riscv_get_regs_fp(CPUState *cs) | ||
84 | +{ | ||
85 | + int ret = 0; | ||
86 | + int i; | ||
87 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
88 | + | ||
89 | + if (riscv_has_ext(env, RVD)) { | ||
90 | + uint64_t reg; | ||
91 | + for (i = 0; i < 32; i++) { | ||
92 | + ret = kvm_get_one_reg(cs, RISCV_FP_D_REG(env, i), ®); | ||
93 | + if (ret) { | ||
94 | + return ret; | ||
95 | + } | ||
96 | + env->fpr[i] = reg; | ||
97 | + } | ||
98 | + return ret; | ||
99 | + } | ||
100 | + | ||
101 | + if (riscv_has_ext(env, RVF)) { | ||
102 | + uint32_t reg; | ||
103 | + for (i = 0; i < 32; i++) { | ||
104 | + ret = kvm_get_one_reg(cs, RISCV_FP_F_REG(env, i), ®); | ||
105 | + if (ret) { | ||
106 | + return ret; | ||
107 | + } | ||
108 | + env->fpr[i] = reg; | ||
109 | + } | ||
110 | + return ret; | ||
111 | + } | ||
112 | + | ||
113 | + return ret; | ||
114 | +} | ||
115 | + | ||
116 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
117 | KVM_CAP_LAST_INFO | ||
118 | }; | ||
119 | |||
120 | int kvm_arch_get_registers(CPUState *cs) | ||
121 | { | ||
122 | - return 0; | ||
123 | + int ret = 0; | ||
124 | + | ||
125 | + ret = kvm_riscv_get_regs_core(cs); | ||
126 | + if (ret) { | ||
127 | + return ret; | ||
128 | + } | ||
129 | + | ||
130 | + ret = kvm_riscv_get_regs_csr(cs); | ||
131 | + if (ret) { | ||
132 | + return ret; | ||
133 | + } | ||
134 | + | ||
135 | + ret = kvm_riscv_get_regs_fp(cs); | ||
136 | + if (ret) { | ||
137 | + return ret; | ||
138 | + } | ||
139 | + | ||
140 | + return ret; | ||
141 | } | ||
142 | |||
143 | int kvm_arch_put_registers(CPUState *cs, int level) | ||
144 | -- | ||
145 | 2.31.1 | ||
146 | |||
147 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Put GPR CSR and FP registers to kvm by KVM_SET_ONE_REG ioctl | ||
4 | |||
5 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
6 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
9 | Message-id: 20220112081329.1835-6-jiangyifei@huawei.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/kvm.c | 104 ++++++++++++++++++++++++++++++++++++++++++++- | ||
13 | 1 file changed, 103 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/kvm.c | ||
18 | +++ b/target/riscv/kvm.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
20 | } \ | ||
21 | } while (0) | ||
22 | |||
23 | +#define KVM_RISCV_SET_CSR(cs, env, csr, reg) \ | ||
24 | + do { \ | ||
25 | + int ret = kvm_set_one_reg(cs, RISCV_CSR_REG(env, csr), ®); \ | ||
26 | + if (ret) { \ | ||
27 | + return ret; \ | ||
28 | + } \ | ||
29 | + } while (0) | ||
30 | + | ||
31 | static int kvm_riscv_get_regs_core(CPUState *cs) | ||
32 | { | ||
33 | int ret = 0; | ||
34 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_core(CPUState *cs) | ||
35 | return ret; | ||
36 | } | ||
37 | |||
38 | +static int kvm_riscv_put_regs_core(CPUState *cs) | ||
39 | +{ | ||
40 | + int ret = 0; | ||
41 | + int i; | ||
42 | + target_ulong reg; | ||
43 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
44 | + | ||
45 | + reg = env->pc; | ||
46 | + ret = kvm_set_one_reg(cs, RISCV_CORE_REG(env, regs.pc), ®); | ||
47 | + if (ret) { | ||
48 | + return ret; | ||
49 | + } | ||
50 | + | ||
51 | + for (i = 1; i < 32; i++) { | ||
52 | + uint64_t id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CORE, i); | ||
53 | + reg = env->gpr[i]; | ||
54 | + ret = kvm_set_one_reg(cs, id, ®); | ||
55 | + if (ret) { | ||
56 | + return ret; | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + return ret; | ||
61 | +} | ||
62 | + | ||
63 | static int kvm_riscv_get_regs_csr(CPUState *cs) | ||
64 | { | ||
65 | int ret = 0; | ||
66 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_csr(CPUState *cs) | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | +static int kvm_riscv_put_regs_csr(CPUState *cs) | ||
71 | +{ | ||
72 | + int ret = 0; | ||
73 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
74 | + | ||
75 | + KVM_RISCV_SET_CSR(cs, env, sstatus, env->mstatus); | ||
76 | + KVM_RISCV_SET_CSR(cs, env, sie, env->mie); | ||
77 | + KVM_RISCV_SET_CSR(cs, env, stvec, env->stvec); | ||
78 | + KVM_RISCV_SET_CSR(cs, env, sscratch, env->sscratch); | ||
79 | + KVM_RISCV_SET_CSR(cs, env, sepc, env->sepc); | ||
80 | + KVM_RISCV_SET_CSR(cs, env, scause, env->scause); | ||
81 | + KVM_RISCV_SET_CSR(cs, env, stval, env->stval); | ||
82 | + KVM_RISCV_SET_CSR(cs, env, sip, env->mip); | ||
83 | + KVM_RISCV_SET_CSR(cs, env, satp, env->satp); | ||
84 | + | ||
85 | + return ret; | ||
86 | +} | ||
87 | + | ||
88 | static int kvm_riscv_get_regs_fp(CPUState *cs) | ||
89 | { | ||
90 | int ret = 0; | ||
91 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_fp(CPUState *cs) | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | +static int kvm_riscv_put_regs_fp(CPUState *cs) | ||
96 | +{ | ||
97 | + int ret = 0; | ||
98 | + int i; | ||
99 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
100 | + | ||
101 | + if (riscv_has_ext(env, RVD)) { | ||
102 | + uint64_t reg; | ||
103 | + for (i = 0; i < 32; i++) { | ||
104 | + reg = env->fpr[i]; | ||
105 | + ret = kvm_set_one_reg(cs, RISCV_FP_D_REG(env, i), ®); | ||
106 | + if (ret) { | ||
107 | + return ret; | ||
108 | + } | ||
109 | + } | ||
110 | + return ret; | ||
111 | + } | ||
112 | + | ||
113 | + if (riscv_has_ext(env, RVF)) { | ||
114 | + uint32_t reg; | ||
115 | + for (i = 0; i < 32; i++) { | ||
116 | + reg = env->fpr[i]; | ||
117 | + ret = kvm_set_one_reg(cs, RISCV_FP_F_REG(env, i), ®); | ||
118 | + if (ret) { | ||
119 | + return ret; | ||
120 | + } | ||
121 | + } | ||
122 | + return ret; | ||
123 | + } | ||
124 | + | ||
125 | + return ret; | ||
126 | +} | ||
127 | + | ||
128 | + | ||
129 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
130 | KVM_CAP_LAST_INFO | ||
131 | }; | ||
132 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs) | ||
133 | |||
134 | int kvm_arch_put_registers(CPUState *cs, int level) | ||
135 | { | ||
136 | - return 0; | ||
137 | + int ret = 0; | ||
138 | + | ||
139 | + ret = kvm_riscv_put_regs_core(cs); | ||
140 | + if (ret) { | ||
141 | + return ret; | ||
142 | + } | ||
143 | + | ||
144 | + ret = kvm_riscv_put_regs_csr(cs); | ||
145 | + if (ret) { | ||
146 | + return ret; | ||
147 | + } | ||
148 | + | ||
149 | + ret = kvm_riscv_put_regs_fp(cs); | ||
150 | + if (ret) { | ||
151 | + return ret; | ||
152 | + } | ||
153 | + | ||
154 | + return ret; | ||
155 | } | ||
156 | |||
157 | int kvm_arch_release_virq_post(int virq) | ||
158 | -- | ||
159 | 2.31.1 | ||
160 | |||
161 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | When KVM is enabled, set the S-mode external interrupt through | ||
4 | kvm_riscv_set_irq function. | ||
5 | |||
6 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
7 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
10 | Message-id: 20220112081329.1835-8-jiangyifei@huawei.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/kvm_riscv.h | 1 + | ||
14 | target/riscv/cpu.c | 6 +++++- | ||
15 | target/riscv/kvm-stub.c | 5 +++++ | ||
16 | target/riscv/kvm.c | 17 +++++++++++++++++ | ||
17 | 4 files changed, 28 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/kvm_riscv.h | ||
22 | +++ b/target/riscv/kvm_riscv.h | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | #define QEMU_KVM_RISCV_H | ||
25 | |||
26 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
27 | +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); | ||
28 | |||
29 | #endif | ||
30 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/riscv/cpu.c | ||
33 | +++ b/target/riscv/cpu.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level) | ||
35 | case IRQ_S_EXT: | ||
36 | case IRQ_VS_EXT: | ||
37 | case IRQ_M_EXT: | ||
38 | - riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level)); | ||
39 | + if (kvm_enabled()) { | ||
40 | + kvm_riscv_set_irq(cpu, irq, level); | ||
41 | + } else { | ||
42 | + riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level)); | ||
43 | + } | ||
44 | break; | ||
45 | default: | ||
46 | g_assert_not_reached(); | ||
47 | diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/riscv/kvm-stub.c | ||
50 | +++ b/target/riscv/kvm-stub.c | ||
51 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
52 | { | ||
53 | abort(); | ||
54 | } | ||
55 | + | ||
56 | +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
57 | +{ | ||
58 | + abort(); | ||
59 | +} | ||
60 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/kvm.c | ||
63 | +++ b/target/riscv/kvm.c | ||
64 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
65 | env->satp = 0; | ||
66 | } | ||
67 | |||
68 | +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
69 | +{ | ||
70 | + int ret; | ||
71 | + unsigned virq = level ? KVM_INTERRUPT_SET : KVM_INTERRUPT_UNSET; | ||
72 | + | ||
73 | + if (irq != IRQ_S_EXT) { | ||
74 | + perror("kvm riscv set irq != IRQ_S_EXT\n"); | ||
75 | + abort(); | ||
76 | + } | ||
77 | + | ||
78 | + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_INTERRUPT, &virq); | ||
79 | + if (ret < 0) { | ||
80 | + perror("Set irq failed"); | ||
81 | + abort(); | ||
82 | + } | ||
83 | +} | ||
84 | + | ||
85 | bool kvm_arch_cpu_check_are_resettable(void) | ||
86 | { | ||
87 | return true; | ||
88 | -- | ||
89 | 2.31.1 | ||
90 | |||
91 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | 'host' type cpu is set isa to RV32 or RV64 simply, more isa info | ||
4 | will obtain from KVM in kvm_arch_init_vcpu() | ||
5 | |||
6 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
7 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
10 | Message-id: 20220112081329.1835-10-jiangyifei@huawei.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/cpu.h | 1 + | ||
14 | target/riscv/cpu.c | 15 +++++++++++++++ | ||
15 | 2 files changed, 16 insertions(+) | ||
16 | |||
17 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/cpu.h | ||
20 | +++ b/target/riscv/cpu.h | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") | ||
23 | #define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34") | ||
24 | #define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") | ||
25 | +#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") | ||
26 | |||
27 | #if defined(TARGET_RISCV32) | ||
28 | # define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE32 | ||
29 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/cpu.c | ||
32 | +++ b/target/riscv/cpu.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | +#if defined(CONFIG_KVM) | ||
38 | +static void riscv_host_cpu_init(Object *obj) | ||
39 | +{ | ||
40 | + CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
41 | +#if defined(TARGET_RISCV32) | ||
42 | + set_misa(env, MXL_RV32, 0); | ||
43 | +#elif defined(TARGET_RISCV64) | ||
44 | + set_misa(env, MXL_RV64, 0); | ||
45 | +#endif | ||
46 | +} | ||
47 | +#endif | ||
48 | + | ||
49 | static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) | ||
50 | { | ||
51 | ObjectClass *oc; | ||
52 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
53 | .class_init = riscv_cpu_class_init, | ||
54 | }, | ||
55 | DEFINE_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), | ||
56 | +#if defined(CONFIG_KVM) | ||
57 | + DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), | ||
58 | +#endif | ||
59 | #if defined(TARGET_RISCV32) | ||
60 | DEFINE_CPU(TYPE_RISCV_CPU_BASE32, rv32_base_cpu_init), | ||
61 | DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init), | ||
62 | -- | ||
63 | 2.31.1 | ||
64 | |||
65 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Add kvm_riscv_get/put_regs_timer to synchronize virtual time context | ||
4 | from KVM. | ||
5 | |||
6 | To set register of RISCV_TIMER_REG(state) will occur a error from KVM | ||
7 | on kvm_timer_state == 0. It's better to adapt in KVM, but it doesn't matter | ||
8 | that adaping in QEMU. | ||
9 | |||
10 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
11 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
12 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-id: 20220112081329.1835-11-jiangyifei@huawei.com | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/cpu.h | 7 +++++ | ||
18 | target/riscv/kvm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
19 | 2 files changed, 79 insertions(+) | ||
20 | |||
21 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu.h | ||
24 | +++ b/target/riscv/cpu.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | ||
26 | |||
27 | hwaddr kernel_addr; | ||
28 | hwaddr fdt_addr; | ||
29 | + | ||
30 | + /* kvm timer */ | ||
31 | + bool kvm_timer_dirty; | ||
32 | + uint64_t kvm_timer_time; | ||
33 | + uint64_t kvm_timer_compare; | ||
34 | + uint64_t kvm_timer_state; | ||
35 | + uint64_t kvm_timer_frequency; | ||
36 | }; | ||
37 | |||
38 | OBJECT_DECLARE_TYPE(RISCVCPU, RISCVCPUClass, | ||
39 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/riscv/kvm.c | ||
42 | +++ b/target/riscv/kvm.c | ||
43 | @@ -XXX,XX +XXX,XX @@ | ||
44 | #include "kvm_riscv.h" | ||
45 | #include "sbi_ecall_interface.h" | ||
46 | #include "chardev/char-fe.h" | ||
47 | +#include "migration/migration.h" | ||
48 | |||
49 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
50 | uint64_t idx) | ||
51 | @@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
52 | #define RISCV_CSR_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \ | ||
53 | KVM_REG_RISCV_CSR_REG(name)) | ||
54 | |||
55 | +#define RISCV_TIMER_REG(env, name) kvm_riscv_reg_id(env, KVM_REG_RISCV_TIMER, \ | ||
56 | + KVM_REG_RISCV_TIMER_REG(name)) | ||
57 | + | ||
58 | #define RISCV_FP_F_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_F, idx) | ||
59 | |||
60 | #define RISCV_FP_D_REG(env, idx) kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_D, idx) | ||
61 | @@ -XXX,XX +XXX,XX @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
62 | } \ | ||
63 | } while (0) | ||
64 | |||
65 | +#define KVM_RISCV_GET_TIMER(cs, env, name, reg) \ | ||
66 | + do { \ | ||
67 | + int ret = kvm_get_one_reg(cs, RISCV_TIMER_REG(env, name), ®); \ | ||
68 | + if (ret) { \ | ||
69 | + abort(); \ | ||
70 | + } \ | ||
71 | + } while (0) | ||
72 | + | ||
73 | +#define KVM_RISCV_SET_TIMER(cs, env, name, reg) \ | ||
74 | + do { \ | ||
75 | + int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(env, time), ®); \ | ||
76 | + if (ret) { \ | ||
77 | + abort(); \ | ||
78 | + } \ | ||
79 | + } while (0) | ||
80 | + | ||
81 | static int kvm_riscv_get_regs_core(CPUState *cs) | ||
82 | { | ||
83 | int ret = 0; | ||
84 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_fp(CPUState *cs) | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | +static void kvm_riscv_get_regs_timer(CPUState *cs) | ||
89 | +{ | ||
90 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
91 | + | ||
92 | + if (env->kvm_timer_dirty) { | ||
93 | + return; | ||
94 | + } | ||
95 | + | ||
96 | + KVM_RISCV_GET_TIMER(cs, env, time, env->kvm_timer_time); | ||
97 | + KVM_RISCV_GET_TIMER(cs, env, compare, env->kvm_timer_compare); | ||
98 | + KVM_RISCV_GET_TIMER(cs, env, state, env->kvm_timer_state); | ||
99 | + KVM_RISCV_GET_TIMER(cs, env, frequency, env->kvm_timer_frequency); | ||
100 | + | ||
101 | + env->kvm_timer_dirty = true; | ||
102 | +} | ||
103 | + | ||
104 | +static void kvm_riscv_put_regs_timer(CPUState *cs) | ||
105 | +{ | ||
106 | + uint64_t reg; | ||
107 | + CPURISCVState *env = &RISCV_CPU(cs)->env; | ||
108 | + | ||
109 | + if (!env->kvm_timer_dirty) { | ||
110 | + return; | ||
111 | + } | ||
112 | + | ||
113 | + KVM_RISCV_SET_TIMER(cs, env, time, env->kvm_timer_time); | ||
114 | + KVM_RISCV_SET_TIMER(cs, env, compare, env->kvm_timer_compare); | ||
115 | + | ||
116 | + /* | ||
117 | + * To set register of RISCV_TIMER_REG(state) will occur a error from KVM | ||
118 | + * on env->kvm_timer_state == 0, It's better to adapt in KVM, but it | ||
119 | + * doesn't matter that adaping in QEMU now. | ||
120 | + * TODO If KVM changes, adapt here. | ||
121 | + */ | ||
122 | + if (env->kvm_timer_state) { | ||
123 | + KVM_RISCV_SET_TIMER(cs, env, state, env->kvm_timer_state); | ||
124 | + } | ||
125 | + | ||
126 | + /* | ||
127 | + * For now, migration will not work between Hosts with different timer | ||
128 | + * frequency. Therefore, we should check whether they are the same here | ||
129 | + * during the migration. | ||
130 | + */ | ||
131 | + if (migration_is_running(migrate_get_current()->state)) { | ||
132 | + KVM_RISCV_GET_TIMER(cs, env, frequency, reg); | ||
133 | + if (reg != env->kvm_timer_frequency) { | ||
134 | + error_report("Dst Hosts timer frequency != Src Hosts"); | ||
135 | + } | ||
136 | + } | ||
137 | + | ||
138 | + env->kvm_timer_dirty = false; | ||
139 | +} | ||
140 | |||
141 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
142 | KVM_CAP_LAST_INFO | ||
143 | -- | ||
144 | 2.31.1 | ||
145 | |||
146 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | We hope that virtual time adjusts with vm state changing. When a vm | ||
4 | is stopped, guest virtual time should stop counting and kvm_timer | ||
5 | should be stopped. When the vm is resumed, guest virtual time should | ||
6 | continue to count and kvm_timer should be restored. | ||
7 | |||
8 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
9 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
10 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-id: 20220112081329.1835-12-jiangyifei@huawei.com | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/kvm.c | 15 +++++++++++++++ | ||
16 | 1 file changed, 15 insertions(+) | ||
17 | |||
18 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/kvm.c | ||
21 | +++ b/target/riscv/kvm.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include "sbi_ecall_interface.h" | ||
24 | #include "chardev/char-fe.h" | ||
25 | #include "migration/migration.h" | ||
26 | +#include "sysemu/runstate.h" | ||
27 | |||
28 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
29 | uint64_t idx) | ||
30 | @@ -XXX,XX +XXX,XX @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu) | ||
31 | return cpu->cpu_index; | ||
32 | } | ||
33 | |||
34 | +static void kvm_riscv_vm_state_change(void *opaque, bool running, | ||
35 | + RunState state) | ||
36 | +{ | ||
37 | + CPUState *cs = opaque; | ||
38 | + | ||
39 | + if (running) { | ||
40 | + kvm_riscv_put_regs_timer(cs); | ||
41 | + } else { | ||
42 | + kvm_riscv_get_regs_timer(cs); | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
46 | void kvm_arch_init_irq_routing(KVMState *s) | ||
47 | { | ||
48 | } | ||
49 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
50 | CPURISCVState *env = &cpu->env; | ||
51 | uint64_t id; | ||
52 | |||
53 | + qemu_add_vm_change_state_handler(kvm_riscv_vm_state_change, cs); | ||
54 | + | ||
55 | id = kvm_riscv_reg_id(env, KVM_REG_RISCV_CONFIG, | ||
56 | KVM_REG_RISCV_CONFIG_REG(isa)); | ||
57 | ret = kvm_get_one_reg(cs, id, &isa); | ||
58 | -- | ||
59 | 2.31.1 | ||
60 | |||
61 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Add virtual time context description to vmstate_kvmtimer. After cpu being | ||
4 | loaded, virtual time context is updated to KVM. | ||
5 | |||
6 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
7 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
8 | Reviewed-by: Anup Patel <anup.patel@wdc.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20220112081329.1835-13-jiangyifei@huawei.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/machine.c | 30 ++++++++++++++++++++++++++++++ | ||
14 | 1 file changed, 30 insertions(+) | ||
15 | |||
16 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/riscv/machine.c | ||
19 | +++ b/target/riscv/machine.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_rv128 = { | ||
21 | } | ||
22 | }; | ||
23 | |||
24 | +static bool kvmtimer_needed(void *opaque) | ||
25 | +{ | ||
26 | + return kvm_enabled(); | ||
27 | +} | ||
28 | + | ||
29 | +static int cpu_post_load(void *opaque, int version_id) | ||
30 | +{ | ||
31 | + RISCVCPU *cpu = opaque; | ||
32 | + CPURISCVState *env = &cpu->env; | ||
33 | + | ||
34 | + env->kvm_timer_dirty = true; | ||
35 | + return 0; | ||
36 | +} | ||
37 | + | ||
38 | +static const VMStateDescription vmstate_kvmtimer = { | ||
39 | + .name = "cpu/kvmtimer", | ||
40 | + .version_id = 1, | ||
41 | + .minimum_version_id = 1, | ||
42 | + .needed = kvmtimer_needed, | ||
43 | + .post_load = cpu_post_load, | ||
44 | + .fields = (VMStateField[]) { | ||
45 | + VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU), | ||
46 | + VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU), | ||
47 | + VMSTATE_UINT64(env.kvm_timer_state, RISCVCPU), | ||
48 | + | ||
49 | + VMSTATE_END_OF_LIST() | ||
50 | + } | ||
51 | +}; | ||
52 | + | ||
53 | const VMStateDescription vmstate_riscv_cpu = { | ||
54 | .name = "cpu", | ||
55 | .version_id = 3, | ||
56 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
57 | &vmstate_vector, | ||
58 | &vmstate_pointermasking, | ||
59 | &vmstate_rv128, | ||
60 | + &vmstate_kvmtimer, | ||
61 | NULL | ||
62 | } | ||
63 | }; | ||
64 | -- | ||
65 | 2.31.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yifei Jiang <jiangyifei@huawei.com> | ||
2 | 1 | ||
3 | Add riscv kvm support in meson.build file. | ||
4 | |||
5 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | ||
6 | Signed-off-by: Mingwang Li <limingwang@huawei.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Anup Patel <anup@brainfault.org> | ||
9 | Message-id: 20220112081329.1835-14-jiangyifei@huawei.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | meson.build | 2 ++ | ||
13 | 1 file changed, 2 insertions(+) | ||
14 | |||
15 | diff --git a/meson.build b/meson.build | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/meson.build | ||
18 | +++ b/meson.build | ||
19 | @@ -XXX,XX +XXX,XX @@ elif cpu in ['ppc', 'ppc64'] | ||
20 | kvm_targets = ['ppc-softmmu', 'ppc64-softmmu'] | ||
21 | elif cpu in ['mips', 'mips64'] | ||
22 | kvm_targets = ['mips-softmmu', 'mipsel-softmmu', 'mips64-softmmu', 'mips64el-softmmu'] | ||
23 | +elif cpu in ['riscv'] | ||
24 | + kvm_targets = ['riscv32-softmmu', 'riscv64-softmmu'] | ||
25 | else | ||
26 | kvm_targets = [] | ||
27 | endif | ||
28 | -- | ||
29 | 2.31.1 | ||
30 | |||
31 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | If I configure my build with --enable-sanitizers, my GCC (v8.5.0) | ||
4 | complains: | ||
5 | |||
6 | .../softmmu/device_tree.c: In function ‘qemu_fdt_add_path’: | ||
7 | .../softmmu/device_tree.c:560:18: error: ‘retval’ may be used uninitialized | ||
8 | in this function [-Werror=maybe-uninitialized] | ||
9 | int namelen, retval; | ||
10 | ^~~~~~ | ||
11 | |||
12 | It's a false warning since the while loop is always executed at least | ||
13 | once (p has to be non-NULL, otherwise the derefence in the if-statement | ||
14 | earlier will crash). Thus let's switch to a do-while loop here instead | ||
15 | to make the compiler happy in all cases. | ||
16 | |||
17 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
18 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
19 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | Reviewed-by: Yanan Wang <wangyanan55@huawei.com> | ||
23 | Message-id: 20220107133844.145039-1-thuth@redhat.com | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | --- | ||
26 | softmmu/device_tree.c | 4 ++-- | ||
27 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
28 | |||
29 | diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/softmmu/device_tree.c | ||
32 | +++ b/softmmu/device_tree.c | ||
33 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path) | ||
34 | return -1; | ||
35 | } | ||
36 | |||
37 | - while (p) { | ||
38 | + do { | ||
39 | name = p + 1; | ||
40 | p = strchr(name, '/'); | ||
41 | namelen = p != NULL ? p - name : strlen(name); | ||
42 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path) | ||
43 | } | ||
44 | |||
45 | parent = retval; | ||
46 | - } | ||
47 | + } while (p); | ||
48 | |||
49 | return retval; | ||
50 | } | ||
51 | -- | ||
52 | 2.31.1 | ||
53 | |||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Yanan Wang <wangyanan55@huawei.com> | ||
2 | 1 | ||
3 | The pointer assignment "const char *p = path;" in function | ||
4 | qemu_fdt_add_path is unnecessary. Let's remove it and just | ||
5 | use the "path" passed in. No functional change. | ||
6 | |||
7 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Signed-off-by: Yanan Wang <wangyanan55@huawei.com> | ||
9 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
12 | Message-id: 20220111032758.27804-1-wangyanan55@huawei.com | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | softmmu/device_tree.c | 9 ++++----- | ||
16 | 1 file changed, 4 insertions(+), 5 deletions(-) | ||
17 | |||
18 | diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/softmmu/device_tree.c | ||
21 | +++ b/softmmu/device_tree.c | ||
22 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_subnode(void *fdt, const char *name) | ||
23 | int qemu_fdt_add_path(void *fdt, const char *path) | ||
24 | { | ||
25 | const char *name; | ||
26 | - const char *p = path; | ||
27 | int namelen, retval; | ||
28 | int parent = 0; | ||
29 | |||
30 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path) | ||
31 | } | ||
32 | |||
33 | do { | ||
34 | - name = p + 1; | ||
35 | - p = strchr(name, '/'); | ||
36 | - namelen = p != NULL ? p - name : strlen(name); | ||
37 | + name = path + 1; | ||
38 | + path = strchr(name, '/'); | ||
39 | + namelen = path != NULL ? path - name : strlen(name); | ||
40 | |||
41 | retval = fdt_subnode_offset_namelen(fdt, parent, name, namelen); | ||
42 | if (retval < 0 && retval != -FDT_ERR_NOTFOUND) { | ||
43 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path) | ||
44 | } | ||
45 | |||
46 | parent = retval; | ||
47 | - } while (p); | ||
48 | + } while (path); | ||
49 | |||
50 | return retval; | ||
51 | } | ||
52 | -- | ||
53 | 2.31.1 | ||
54 | |||
55 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | All Zve* extensions support the vector configuration instructions. | ||
4 | |||
5 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: 20220118014522.13613-3-frank.chang@sifive.com | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | target/riscv/insn_trans/trans_rvv.c.inc | 6 ++++-- | ||
11 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
16 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
18 | { | ||
19 | TCGv s1, dst; | ||
20 | |||
21 | - if (!require_rvv(s) || !has_ext(s, RVV)) { | ||
22 | + if (!require_rvv(s) || | ||
23 | + !(has_ext(s, RVV) || s->ext_zve64f)) { | ||
24 | return false; | ||
25 | } | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) | ||
28 | { | ||
29 | TCGv dst; | ||
30 | |||
31 | - if (!require_rvv(s) || !has_ext(s, RVV)) { | ||
32 | + if (!require_rvv(s) || | ||
33 | + !(has_ext(s, RVV) || s->ext_zve64f)) { | ||
34 | return false; | ||
35 | } | ||
36 | |||
37 | -- | ||
38 | 2.31.1 | ||
39 | |||
40 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | All Zve* extensions support all vector load and store instructions, | ||
4 | except Zve64* extensions do not support EEW=64 for index values when | ||
5 | XLEN=32. | ||
6 | |||
7 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-id: 20220118014522.13613-4-frank.chang@sifive.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/insn_trans/trans_rvv.c.inc | 19 +++++++++++++++---- | ||
13 | 1 file changed, 15 insertions(+), 4 deletions(-) | ||
14 | |||
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 | ||
17 | --- a/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 vext_check_st_index(DisasContext *s, int vd, int vs2, int nf, | ||
20 | uint8_t eew) | ||
21 | { | ||
22 | int8_t emul = eew - s->sew + s->lmul; | ||
23 | - return (emul >= -3 && emul <= 3) && | ||
24 | - require_align(vs2, emul) && | ||
25 | - require_align(vd, s->lmul) && | ||
26 | - require_nf(vd, nf, s->lmul); | ||
27 | + bool ret = (emul >= -3 && emul <= 3) && | ||
28 | + require_align(vs2, emul) && | ||
29 | + require_align(vd, s->lmul) && | ||
30 | + require_nf(vd, nf, s->lmul); | ||
31 | + | ||
32 | + /* | ||
33 | + * All Zve* extensions support all vector load and store instructions, | ||
34 | + * except Zve64* extensions do not support EEW=64 for index values | ||
35 | + * when XLEN=32. (Section 18.2) | ||
36 | + */ | ||
37 | + if (get_xl(s) == MXL_RV32) { | ||
38 | + ret &= (!has_ext(s, RVV) && s->ext_zve64f ? eew != MO_64 : true); | ||
39 | + } | ||
40 | + | ||
41 | + return ret; | ||
42 | } | ||
43 | |||
44 | /* | ||
45 | -- | ||
46 | 2.31.1 | ||
47 | |||
48 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | All Zve* extensions support all vector integer instructions, | ||
4 | except that the vmulh integer multiply variants that return the | ||
5 | high word of the product (vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, | ||
6 | vmulhsu.vv, vmulhsu.vx) are not included for EEW=64 in Zve64*. | ||
7 | |||
8 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20220118014522.13613-5-frank.chang@sifive.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/insn_trans/trans_rvv.c.inc | 39 +++++++++++++++++++++---- | ||
14 | 1 file changed, 33 insertions(+), 6 deletions(-) | ||
15 | |||
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 | ||
18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
20 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVX_TRANS(vmaxu_vx, opivx_check) | ||
21 | GEN_OPIVX_TRANS(vmax_vx, opivx_check) | ||
22 | |||
23 | /* Vector Single-Width Integer Multiply Instructions */ | ||
24 | + | ||
25 | +static bool vmulh_vv_check(DisasContext *s, arg_rmrr *a) | ||
26 | +{ | ||
27 | + /* | ||
28 | + * All Zve* extensions support all vector integer instructions, | ||
29 | + * except that the vmulh integer multiply variants | ||
30 | + * that return the high word of the product | ||
31 | + * (vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx) | ||
32 | + * are not included for EEW=64 in Zve64*. (Section 18.2) | ||
33 | + */ | ||
34 | + return opivv_check(s, a) && | ||
35 | + (!has_ext(s, RVV) && s->ext_zve64f ? s->sew != MO_64 : true); | ||
36 | +} | ||
37 | + | ||
38 | +static bool vmulh_vx_check(DisasContext *s, arg_rmrr *a) | ||
39 | +{ | ||
40 | + /* | ||
41 | + * All Zve* extensions support all vector integer instructions, | ||
42 | + * except that the vmulh integer multiply variants | ||
43 | + * that return the high word of the product | ||
44 | + * (vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx) | ||
45 | + * are not included for EEW=64 in Zve64*. (Section 18.2) | ||
46 | + */ | ||
47 | + return opivx_check(s, a) && | ||
48 | + (!has_ext(s, RVV) && s->ext_zve64f ? s->sew != MO_64 : true); | ||
49 | +} | ||
50 | + | ||
51 | GEN_OPIVV_GVEC_TRANS(vmul_vv, mul) | ||
52 | -GEN_OPIVV_TRANS(vmulh_vv, opivv_check) | ||
53 | -GEN_OPIVV_TRANS(vmulhu_vv, opivv_check) | ||
54 | -GEN_OPIVV_TRANS(vmulhsu_vv, opivv_check) | ||
55 | +GEN_OPIVV_TRANS(vmulh_vv, vmulh_vv_check) | ||
56 | +GEN_OPIVV_TRANS(vmulhu_vv, vmulh_vv_check) | ||
57 | +GEN_OPIVV_TRANS(vmulhsu_vv, vmulh_vv_check) | ||
58 | GEN_OPIVX_GVEC_TRANS(vmul_vx, muls) | ||
59 | -GEN_OPIVX_TRANS(vmulh_vx, opivx_check) | ||
60 | -GEN_OPIVX_TRANS(vmulhu_vx, opivx_check) | ||
61 | -GEN_OPIVX_TRANS(vmulhsu_vx, opivx_check) | ||
62 | +GEN_OPIVX_TRANS(vmulh_vx, vmulh_vx_check) | ||
63 | +GEN_OPIVX_TRANS(vmulhu_vx, vmulh_vx_check) | ||
64 | +GEN_OPIVX_TRANS(vmulhsu_vx, vmulh_vx_check) | ||
65 | |||
66 | /* Vector Integer Divide Instructions */ | ||
67 | GEN_OPIVV_TRANS(vdivu_vv, opivv_check) | ||
68 | -- | ||
69 | 2.31.1 | ||
70 | |||
71 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | All Zve* extensions support all vector fixed-point arithmetic | ||
4 | instructions, except that vsmul.vv and vsmul.vx are not supported | ||
5 | for EEW=64 in Zve64*. | ||
6 | |||
7 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-id: 20220118014522.13613-6-frank.chang@sifive.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/insn_trans/trans_rvv.c.inc | 27 +++++++++++++++++++++++-- | ||
13 | 1 file changed, 25 insertions(+), 2 deletions(-) | ||
14 | |||
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 | ||
17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
19 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVX_TRANS(vasub_vx, opivx_check) | ||
20 | GEN_OPIVX_TRANS(vasubu_vx, opivx_check) | ||
21 | |||
22 | /* Vector Single-Width Fractional Multiply with Rounding and Saturation */ | ||
23 | -GEN_OPIVV_TRANS(vsmul_vv, opivv_check) | ||
24 | -GEN_OPIVX_TRANS(vsmul_vx, opivx_check) | ||
25 | + | ||
26 | +static bool vsmul_vv_check(DisasContext *s, arg_rmrr *a) | ||
27 | +{ | ||
28 | + /* | ||
29 | + * All Zve* extensions support all vector fixed-point arithmetic | ||
30 | + * instructions, except that vsmul.vv and vsmul.vx are not supported | ||
31 | + * for EEW=64 in Zve64*. (Section 18.2) | ||
32 | + */ | ||
33 | + return opivv_check(s, a) && | ||
34 | + (!has_ext(s, RVV) && s->ext_zve64f ? s->sew != MO_64 : true); | ||
35 | +} | ||
36 | + | ||
37 | +static bool vsmul_vx_check(DisasContext *s, arg_rmrr *a) | ||
38 | +{ | ||
39 | + /* | ||
40 | + * All Zve* extensions support all vector fixed-point arithmetic | ||
41 | + * instructions, except that vsmul.vv and vsmul.vx are not supported | ||
42 | + * for EEW=64 in Zve64*. (Section 18.2) | ||
43 | + */ | ||
44 | + return opivx_check(s, a) && | ||
45 | + (!has_ext(s, RVV) && s->ext_zve64f ? s->sew != MO_64 : true); | ||
46 | +} | ||
47 | + | ||
48 | +GEN_OPIVV_TRANS(vsmul_vv, vsmul_vv_check) | ||
49 | +GEN_OPIVX_TRANS(vsmul_vx, vsmul_vx_check) | ||
50 | |||
51 | /* Vector Single-Width Scaling Shift Instructions */ | ||
52 | GEN_OPIVV_TRANS(vssrl_vv, opivv_check) | ||
53 | -- | ||
54 | 2.31.1 | ||
55 | |||
56 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Zve32f extension requires the scalar processor to implement the F | 3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w |
4 | extension and implement all vector floating-point instructions for | 4 | instructions will be affected by Zvfhmin extension. |
5 | floating-point operands with EEW=32 (i.e., no widening floating-point | 5 | And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the |
6 | operations). | 6 | conversions of |
7 | 7 | ||
8 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 8 | * From 1*SEW(16/32) to 2*SEW(32/64) |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | * From 2*SEW(32/64) to 1*SEW(16/32) |
10 | Message-id: 20220118014522.13613-14-frank.chang@sifive.com | 10 | |
11 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240322092600.1198921-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 | 21 +++++++++++++++++++++ | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- |
14 | 1 file changed, 21 insertions(+) | 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 require_scale_rvf(DisasContext *s) | 24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) |
21 | } | 25 | } |
22 | } | 26 | } |
23 | 27 | ||
24 | +static bool require_zve32f(DisasContext *s) | 28 | +static bool require_rvfmin(DisasContext *s) |
25 | +{ | 29 | +{ |
26 | + /* RVV + Zve32f = RVV. */ | 30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
27 | + if (has_ext(s, RVV)) { | 31 | + return false; |
28 | + return true; | ||
29 | + } | 32 | + } |
30 | + | 33 | + |
31 | + /* Zve32f doesn't support FP64. (Section 18.2) */ | 34 | + switch (s->sew) { |
32 | + return s->ext_zve32f ? s->sew <= MO_32 : true; | 35 | + case MO_16: |
36 | + return s->cfg_ptr->ext_zvfhmin; | ||
37 | + case MO_32: | ||
38 | + return s->cfg_ptr->ext_zve32f; | ||
39 | + default: | ||
40 | + return false; | ||
41 | + } | ||
33 | +} | 42 | +} |
34 | + | 43 | + |
35 | static bool require_zve64f(DisasContext *s) | 44 | static bool require_scale_rvf(DisasContext *s) |
36 | { | 45 | { |
37 | /* RVV + Zve64f = RVV. */ | 46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
38 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_check(DisasContext *s, arg_rmrr *a) | 47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) |
39 | require_rvf(s) && | 48 | } |
40 | vext_check_isa_ill(s) && | 49 | |
41 | vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm) && | 50 | switch (s->sew) { |
42 | + require_zve32f(s) && | 51 | - case MO_8: |
43 | require_zve64f(s); | 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); | ||
44 | } | 63 | } |
45 | 64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | |
46 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_check(DisasContext *s, arg_rmrr *a) | 65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
47 | require_rvf(s) && | 66 | { |
48 | vext_check_isa_ill(s) && | 67 | return opfv_narrow_check(s, a) && |
49 | vext_check_ss(s, a->rd, a->rs2, a->vm) && | 68 | + require_rvfmin(s) && |
50 | + require_zve32f(s) && | 69 | require_scale_rvfmin(s) && |
51 | require_zve64f(s); | 70 | (s->sew != MO_8); |
52 | } | 71 | } |
53 | |||
54 | @@ -XXX,XX +XXX,XX @@ static bool opfv_check(DisasContext *s, arg_rmr *a) | ||
55 | vext_check_isa_ill(s) && | ||
56 | /* OPFV instructions ignore vs1 check */ | ||
57 | vext_check_ss(s, a->rd, a->rs2, a->vm) && | ||
58 | + require_zve32f(s) && | ||
59 | require_zve64f(s); | ||
60 | } | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_cmp_check(DisasContext *s, arg_rmrr *a) | ||
63 | require_rvf(s) && | ||
64 | vext_check_isa_ill(s) && | ||
65 | vext_check_mss(s, a->rd, a->rs1, a->rs2) && | ||
66 | + require_zve32f(s) && | ||
67 | require_zve64f(s); | ||
68 | } | ||
69 | |||
70 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_cmp_check(DisasContext *s, arg_rmrr *a) | ||
71 | require_rvf(s) && | ||
72 | vext_check_isa_ill(s) && | ||
73 | vext_check_ms(s, a->rd, a->rs2) && | ||
74 | + require_zve32f(s) && | ||
75 | require_zve64f(s); | ||
76 | } | ||
77 | |||
78 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) | ||
79 | require_rvf(s) && | ||
80 | vext_check_isa_ill(s) && | ||
81 | require_align(a->rd, s->lmul) && | ||
82 | + require_zve32f(s) && | ||
83 | require_zve64f(s)) { | ||
84 | gen_set_rm(s, RISCV_FRM_DYN); | ||
85 | |||
86 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) | ||
87 | if (require_rvv(s) && | ||
88 | require_rvf(s) && | ||
89 | vext_check_isa_ill(s) && | ||
90 | + require_zve32f(s) && | ||
91 | require_zve64f(s)) { | ||
92 | gen_set_rm(s, RISCV_FRM_DYN); | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) | ||
95 | if (require_rvv(s) && | ||
96 | require_rvf(s) && | ||
97 | vext_check_isa_ill(s) && | ||
98 | + require_zve32f(s) && | ||
99 | require_zve64f(s)) { | ||
100 | gen_set_rm(s, RISCV_FRM_DYN); | ||
101 | |||
102 | @@ -XXX,XX +XXX,XX @@ static bool fslideup_check(DisasContext *s, arg_rmrr *a) | ||
103 | { | ||
104 | return slideup_check(s, a) && | ||
105 | require_rvf(s) && | ||
106 | + require_zve32f(s) && | ||
107 | require_zve64f(s); | ||
108 | } | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ static bool fslidedown_check(DisasContext *s, arg_rmrr *a) | ||
111 | { | ||
112 | return slidedown_check(s, a) && | ||
113 | require_rvf(s) && | ||
114 | + require_zve32f(s) && | ||
115 | require_zve64f(s); | ||
116 | } | ||
117 | |||
118 | -- | 72 | -- |
119 | 2.31.1 | 73 | 2.45.1 |
120 | |||
121 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Vector widening conversion instructions are provided to and from all | 3 | The require_scale_rvf function only checks the double width operator for |
4 | supported integer EEWs for Zve64f extension. | 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 | Signed-off-by: Frank Chang <frank.chang@sifive.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 | Message-id: 20220118014522.13613-9-frank.chang@sifive.com | 9 | need require_rvf for the single width operator(integer). |
10 | |||
11 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240322092600.1198921-3-max.chou@sifive.com> | ||
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/insn_trans/trans_rvv.c.inc | 32 +++++++++++++++++++------ | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ |
12 | 1 file changed, 25 insertions(+), 7 deletions(-) | 18 | 1 file changed, 5 insertions(+) |
13 | 19 | ||
14 | 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 |
15 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ static bool require_zve64f(DisasContext *s) | 24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) |
19 | return s->ext_zve64f ? s->sew <= MO_32 : true; | 25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
20 | } | ||
21 | |||
22 | +static bool require_scale_zve64f(DisasContext *s) | ||
23 | +{ | ||
24 | + /* RVV + Zve64f = RVV. */ | ||
25 | + if (has_ext(s, RVV)) { | ||
26 | + return true; | ||
27 | + } | ||
28 | + | ||
29 | + /* Zve64f doesn't support FP64. (Section 18.2) */ | ||
30 | + return s->ext_zve64f ? s->sew <= MO_16 : true; | ||
31 | +} | ||
32 | + | ||
33 | /* Destination vector register group cannot overlap source mask register. */ | ||
34 | static bool require_vm(int vm, int vd) | ||
35 | { | 26 | { |
36 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | 27 | return require_rvv(s) && |
28 | + require_rvf(s) && | ||
37 | require_scale_rvf(s) && | 29 | require_scale_rvf(s) && |
38 | (s->sew != MO_8) && | 30 | (s->sew != MO_8) && |
39 | vext_check_isa_ill(s) && | 31 | vext_check_isa_ill(s) && |
40 | - vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); | 32 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check) |
41 | + vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm) && | 33 | static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) |
42 | + require_scale_zve64f(s); | 34 | { |
43 | } | 35 | return require_rvv(s) && |
44 | 36 | + require_rvf(s) && | |
45 | /* OPFVV with WIDEN */ | ||
46 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
47 | require_scale_rvf(s) && | 37 | require_scale_rvf(s) && |
48 | (s->sew != MO_8) && | 38 | (s->sew != MO_8) && |
49 | vext_check_isa_ill(s) && | 39 | vext_check_isa_ill(s) && |
50 | - vext_check_ds(s, a->rd, a->rs2, a->vm); | 40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) |
51 | + vext_check_ds(s, a->rd, a->rs2, a->vm) && | 41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) |
52 | + require_scale_zve64f(s); | 42 | { |
53 | } | 43 | return require_rvv(s) && |
54 | 44 | + require_rvf(s) && | |
55 | /* OPFVF with WIDEN */ | ||
56 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
57 | require_scale_rvf(s) && | 45 | require_scale_rvf(s) && |
58 | (s->sew != MO_8) && | 46 | (s->sew != MO_8) && |
59 | vext_check_isa_ill(s) && | 47 | vext_check_isa_ill(s) && |
60 | - vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); | 48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) |
61 | + vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm) && | 49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) |
62 | + require_scale_zve64f(s); | 50 | { |
63 | } | 51 | return require_rvv(s) && |
64 | 52 | + require_rvf(s) && | |
65 | /* WIDEN OPFVV with WIDEN */ | ||
66 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
67 | require_scale_rvf(s) && | 53 | require_scale_rvf(s) && |
68 | (s->sew != MO_8) && | 54 | (s->sew != MO_8) && |
69 | vext_check_isa_ill(s) && | 55 | vext_check_isa_ill(s) && |
70 | - vext_check_dd(s, a->rd, a->rs2, a->vm); | 56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) |
71 | + vext_check_dd(s, a->rd, a->rs2, a->vm) && | 57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) |
72 | + require_scale_zve64f(s); | 58 | { |
59 | return reduction_widen_check(s, a) && | ||
60 | + require_rvf(s) && | ||
61 | require_scale_rvf(s) && | ||
62 | (s->sew != MO_8); | ||
73 | } | 63 | } |
74 | |||
75 | /* WIDEN OPFVF with WIDEN */ | ||
76 | @@ -XXX,XX +XXX,XX @@ static bool opfv_widen_check(DisasContext *s, arg_rmr *a) | ||
77 | static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) | ||
78 | { | ||
79 | return opfv_widen_check(s, a) && | ||
80 | - require_rvf(s); | ||
81 | + require_rvf(s) && | ||
82 | + require_zve64f(s); | ||
83 | } | ||
84 | |||
85 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
86 | { | ||
87 | return opfv_widen_check(s, a) && | ||
88 | require_scale_rvf(s) && | ||
89 | - (s->sew != MO_8); | ||
90 | + (s->sew != MO_8) && | ||
91 | + require_scale_zve64f(s); | ||
92 | } | ||
93 | |||
94 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ | ||
95 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_widen_check(DisasContext *s, arg_rmr *a) | ||
96 | require_scale_rvf(s) && | ||
97 | vext_check_isa_ill(s) && | ||
98 | /* OPFV widening instructions ignore vs1 check */ | ||
99 | - vext_check_ds(s, a->rd, a->rs2, a->vm); | ||
100 | + vext_check_ds(s, a->rd, a->rs2, a->vm) && | ||
101 | + require_scale_zve64f(s); | ||
102 | } | ||
103 | |||
104 | #define GEN_OPFXV_WIDEN_TRANS(NAME) \ | ||
105 | -- | 64 | -- |
106 | 2.31.1 | 65 | 2.45.1 |
107 | 66 | ||
108 | 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 | Vector single-width floating-point reduction operations for EEW=32 are | 3 | The opfv_narrow_check needs to check the single width float operator by |
4 | supported for Zve32f extension. | 4 | require_rvf. |
5 | 5 | ||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 6 | Signed-off-by: Max Chou <max.chou@sifive.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
8 | Message-id: 20220118014522.13613-15-frank.chang@sifive.com | 8 | Cc: qemu-stable <qemu-stable@nongnu.org> |
9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 11 | --- |
11 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + |
12 | 1 file changed, 1 insertion(+) | 13 | 1 file changed, 1 insertion(+) |
13 | 14 | ||
14 | 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 |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ static bool freduction_check(DisasContext *s, arg_rmrr *a) | 19 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) | ||
19 | { | 21 | { |
20 | return reduction_check(s, a) && | 22 | return opfv_narrow_check(s, a) && |
21 | require_rvf(s) && | 23 | + require_rvf(s) && |
22 | + require_zve32f(s) && | 24 | require_scale_rvf(s) && |
23 | require_zve64f(s); | 25 | (s->sew != MO_8); |
24 | } | 26 | } |
25 | |||
26 | -- | 27 | -- |
27 | 2.31.1 | 28 | 2.45.1 |
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Zve64f extension requires the scalar processor to implement the F | 3 | If the checking functions check both the single and double width |
4 | extension and implement all vector floating-point instructions for | 4 | operators at the same time, then the single width operator checking |
5 | floating-point operands with EEW=32 (i.e., no widening floating-point | 5 | functions (require_rvf[min]) will check whether the SEW is 8. |
6 | operations). | ||
7 | 6 | ||
8 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Message-id: 20220118014522.13613-7-frank.chang@sifive.com | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 12 | --- |
13 | target/riscv/insn_trans/trans_rvv.c.inc | 41 +++++++++++++++++++------ | 13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ |
14 | 1 file changed, 31 insertions(+), 10 deletions(-) | 14 | 1 file changed, 4 insertions(+), 12 deletions(-) |
15 | 15 | ||
16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 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/insn_trans/trans_rvv.c.inc | 18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvf(DisasContext *s) | 20 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
21 | } | ||
22 | } | ||
23 | |||
24 | +static bool require_zve64f(DisasContext *s) | ||
25 | +{ | ||
26 | + /* RVV + Zve64f = RVV. */ | ||
27 | + if (has_ext(s, RVV)) { | ||
28 | + return true; | ||
29 | + } | ||
30 | + | ||
31 | + /* Zve64f doesn't support FP64. (Section 18.2) */ | ||
32 | + return s->ext_zve64f ? s->sew <= MO_32 : true; | ||
33 | +} | ||
34 | + | ||
35 | /* Destination vector register group cannot overlap source mask register. */ | ||
36 | static bool require_vm(int vm, int vd) | ||
37 | { | ||
38 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_check(DisasContext *s, arg_rmrr *a) | ||
39 | return require_rvv(s) && | 21 | return require_rvv(s) && |
40 | require_rvf(s) && | 22 | require_rvf(s) && |
23 | require_scale_rvf(s) && | ||
24 | - (s->sew != MO_8) && | ||
41 | vext_check_isa_ill(s) && | 25 | vext_check_isa_ill(s) && |
42 | - vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm); | 26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); |
43 | + vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm) && | ||
44 | + require_zve64f(s); | ||
45 | } | 27 | } |
46 | 28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | |
47 | /* OPFVV without GVEC IR */ | ||
48 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_check(DisasContext *s, arg_rmrr *a) | ||
49 | return require_rvv(s) && | 29 | return require_rvv(s) && |
50 | require_rvf(s) && | 30 | require_rvf(s) && |
31 | require_scale_rvf(s) && | ||
32 | - (s->sew != MO_8) && | ||
51 | vext_check_isa_ill(s) && | 33 | vext_check_isa_ill(s) && |
52 | - vext_check_ss(s, a->rd, a->rs2, a->vm); | 34 | vext_check_ds(s, a->rd, a->rs2, a->vm); |
53 | + vext_check_ss(s, a->rd, a->rs2, a->vm) && | ||
54 | + require_zve64f(s); | ||
55 | } | 35 | } |
56 | 36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | |
57 | /* OPFVF without GVEC IR */ | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool opfv_check(DisasContext *s, arg_rmr *a) | ||
59 | require_rvf(s) && | ||
60 | vext_check_isa_ill(s) && | ||
61 | /* OPFV instructions ignore vs1 check */ | ||
62 | - vext_check_ss(s, a->rd, a->rs2, a->vm); | ||
63 | + vext_check_ss(s, a->rd, a->rs2, a->vm) && | ||
64 | + require_zve64f(s); | ||
65 | } | ||
66 | |||
67 | static bool do_opfv(DisasContext *s, arg_rmr *a, | ||
68 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_cmp_check(DisasContext *s, arg_rmrr *a) | ||
69 | return require_rvv(s) && | 37 | return require_rvv(s) && |
70 | require_rvf(s) && | 38 | require_rvf(s) && |
39 | require_scale_rvf(s) && | ||
40 | - (s->sew != MO_8) && | ||
71 | vext_check_isa_ill(s) && | 41 | vext_check_isa_ill(s) && |
72 | - vext_check_mss(s, a->rd, a->rs1, a->rs2); | 42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); |
73 | + vext_check_mss(s, a->rd, a->rs1, a->rs2) && | ||
74 | + require_zve64f(s); | ||
75 | } | 43 | } |
76 | 44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | |
77 | GEN_OPFVV_TRANS(vmfeq_vv, opfvv_cmp_check) | ||
78 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_cmp_check(DisasContext *s, arg_rmrr *a) | ||
79 | return require_rvv(s) && | 45 | return require_rvv(s) && |
80 | require_rvf(s) && | 46 | require_rvf(s) && |
47 | require_scale_rvf(s) && | ||
48 | - (s->sew != MO_8) && | ||
81 | vext_check_isa_ill(s) && | 49 | vext_check_isa_ill(s) && |
82 | - vext_check_ms(s, a->rd, a->rs2); | 50 | vext_check_dd(s, a->rd, a->rs2, a->vm); |
83 | + vext_check_ms(s, a->rd, a->rs2) && | ||
84 | + require_zve64f(s); | ||
85 | } | 51 | } |
86 | 52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | |
87 | GEN_OPFVF_TRANS(vmfeq_vf, opfvf_cmp_check) | ||
88 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) | ||
89 | if (require_rvv(s) && | ||
90 | require_rvf(s) && | ||
91 | vext_check_isa_ill(s) && | ||
92 | - require_align(a->rd, s->lmul)) { | ||
93 | + require_align(a->rd, s->lmul) && | ||
94 | + require_zve64f(s)) { | ||
95 | gen_set_rm(s, RISCV_FRM_DYN); | ||
96 | |||
97 | TCGv_i64 t1; | ||
98 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) | ||
99 | { | 53 | { |
100 | if (require_rvv(s) && | 54 | return opfv_widen_check(s, a) && |
101 | require_rvf(s) && | 55 | require_rvfmin(s) && |
102 | - vext_check_isa_ill(s)) { | 56 | - require_scale_rvfmin(s) && |
103 | + vext_check_isa_ill(s) && | 57 | - (s->sew != MO_8); |
104 | + require_zve64f(s)) { | 58 | + require_scale_rvfmin(s); |
105 | gen_set_rm(s, RISCV_FRM_DYN); | 59 | } |
106 | 60 | ||
107 | unsigned int ofs = (8 << s->sew); | 61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ |
108 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) | 62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
109 | { | 63 | { |
110 | if (require_rvv(s) && | 64 | return opfv_narrow_check(s, a) && |
111 | require_rvf(s) && | 65 | require_rvfmin(s) && |
112 | - vext_check_isa_ill(s)) { | 66 | - require_scale_rvfmin(s) && |
113 | + vext_check_isa_ill(s) && | 67 | - (s->sew != MO_8); |
114 | + require_zve64f(s)) { | 68 | + require_scale_rvfmin(s); |
115 | gen_set_rm(s, RISCV_FRM_DYN); | 69 | } |
116 | 70 | ||
117 | /* The instructions ignore LMUL and vector register group. */ | 71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
118 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVI_TRANS(vslidedown_vi, IMM_ZX, vslidedown_vx, slidedown_check) | ||
119 | static bool fslideup_check(DisasContext *s, arg_rmrr *a) | ||
120 | { | 72 | { |
121 | return slideup_check(s, a) && | 73 | return opfv_narrow_check(s, a) && |
122 | - require_rvf(s); | 74 | require_rvf(s) && |
123 | + require_rvf(s) && | 75 | - require_scale_rvf(s) && |
124 | + require_zve64f(s); | 76 | - (s->sew != MO_8); |
77 | + require_scale_rvf(s); | ||
125 | } | 78 | } |
126 | 79 | ||
127 | static bool fslidedown_check(DisasContext *s, arg_rmrr *a) | 80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ |
81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
128 | { | 82 | { |
129 | return slidedown_check(s, a) && | 83 | return reduction_widen_check(s, a) && |
130 | - require_rvf(s); | 84 | require_rvf(s) && |
131 | + require_rvf(s) && | 85 | - require_scale_rvf(s) && |
132 | + require_zve64f(s); | 86 | - (s->sew != MO_8); |
87 | + require_scale_rvf(s); | ||
133 | } | 88 | } |
134 | 89 | ||
135 | GEN_OPFVF_TRANS(vfslide1up_vf, fslideup_check) | 90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) |
136 | -- | 91 | -- |
137 | 2.31.1 | 92 | 2.45.1 |
138 | |||
139 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | Vector single-width floating-point reduction operations for EEW=32 are | ||
4 | supported for Zve64f extension. | ||
5 | |||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20220118014522.13613-8-frank.chang@sifive.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/insn_trans/trans_rvv.c.inc | 3 ++- | ||
12 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
18 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVV_WIDEN_TRANS(vwredsumu_vs, reduction_widen_check) | ||
19 | static bool freduction_check(DisasContext *s, arg_rmrr *a) | ||
20 | { | ||
21 | return reduction_check(s, a) && | ||
22 | - require_rvf(s); | ||
23 | + require_rvf(s) && | ||
24 | + require_zve64f(s); | ||
25 | } | ||
26 | |||
27 | GEN_OPFVV_TRANS(vfredsum_vs, freduction_check) | ||
28 | -- | ||
29 | 2.31.1 | ||
30 | |||
31 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | Vector narrowing conversion instructions are provided to and from all | ||
4 | supported integer EEWs for Zve64f extension. | ||
5 | |||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20220118014522.13613-10-frank.chang@sifive.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/insn_trans/trans_rvv.c.inc | 9 ++++++--- | ||
12 | 1 file changed, 6 insertions(+), 3 deletions(-) | ||
13 | |||
14 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
18 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | ||
19 | { | ||
20 | return opfv_narrow_check(s, a) && | ||
21 | require_rvf(s) && | ||
22 | - (s->sew != MO_64); | ||
23 | + (s->sew != MO_64) && | ||
24 | + require_zve64f(s); | ||
25 | } | ||
26 | |||
27 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
28 | { | ||
29 | return opfv_narrow_check(s, a) && | ||
30 | require_scale_rvf(s) && | ||
31 | - (s->sew != MO_8); | ||
32 | + (s->sew != MO_8) && | ||
33 | + require_scale_zve64f(s); | ||
34 | } | ||
35 | |||
36 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ | ||
37 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) | ||
38 | require_scale_rvf(s) && | ||
39 | vext_check_isa_ill(s) && | ||
40 | /* OPFV narrowing instructions ignore vs1 check */ | ||
41 | - vext_check_sd(s, a->rd, a->rs2, a->vm); | ||
42 | + vext_check_sd(s, a->rd, a->rs2, a->vm) && | ||
43 | + require_scale_zve64f(s); | ||
44 | } | ||
45 | |||
46 | #define GEN_OPXFV_NARROW_TRANS(NAME, HELPER, FRM) \ | ||
47 | -- | ||
48 | 2.31.1 | ||
49 | |||
50 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by |
4 | checking first if virt_enabled && !first_stage, and then considering the | ||
5 | regular inst/load/store faults. | ||
6 | |||
7 | There's no mention in the spec about guest page fault being a higher | ||
8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: | ||
9 | |||
10 | "Attempting to fetch an instruction from a PMP region that does not have | ||
11 | execute permissions raises an instruction access-fault exception. | ||
12 | Attempting to execute a load or load-reserved instruction which accesses | ||
13 | a physical address within a PMP region without read permissions raises a | ||
14 | load access-fault exception. Attempting to execute a store, | ||
15 | store-conditional, or AMO instruction which accesses a physical address | ||
16 | within a PMP region without write permissions raises a store | ||
17 | access-fault exception." | ||
18 | |||
19 | So, in fact, we're doing it wrong - PMP faults should always be thrown, | ||
20 | regardless of also being a first or second stage fault. | ||
21 | |||
22 | The way riscv_cpu_tlb_fill() and get_physical_address() work is | ||
23 | adequate: a TRANSLATE_PMP_FAIL error is immediately reported and | ||
24 | reflected in the 'pmp_violation' flag. What we need is to change | ||
25 | raise_mmu_exception() to prioritize it. | ||
26 | |||
27 | Reported-by: Joseph Chan <jchan@ventanamicro.com> | ||
28 | Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage") | ||
29 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Message-id: 20220118014522.13613-12-frank.chang@sifive.com | 31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> |
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 34 | --- |
8 | target/riscv/cpu.h | 1 + | 35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- |
9 | target/riscv/cpu.c | 4 ++-- | 36 | 1 file changed, 12 insertions(+), 10 deletions(-) |
10 | target/riscv/cpu_helper.c | 2 +- | ||
11 | target/riscv/csr.c | 2 +- | ||
12 | target/riscv/translate.c | 2 ++ | ||
13 | 5 files changed, 7 insertions(+), 4 deletions(-) | ||
14 | 37 | ||
15 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/cpu.h | ||
18 | +++ b/target/riscv/cpu.h | ||
19 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
20 | bool ext_icsr; | ||
21 | bool ext_zfh; | ||
22 | bool ext_zfhmin; | ||
23 | + bool ext_zve32f; | ||
24 | bool ext_zve64f; | ||
25 | |||
26 | char *priv_spec; | ||
27 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/riscv/cpu.c | ||
30 | +++ b/target/riscv/cpu.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
32 | } | ||
33 | set_vext_version(env, vext_version); | ||
34 | } | ||
35 | - if (cpu->cfg.ext_zve64f && !cpu->cfg.ext_f) { | ||
36 | - error_setg(errp, "Zve64f extension depends upon RVF."); | ||
37 | + if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { | ||
38 | + error_setg(errp, "Zve32f/Zve64f extension depends upon RVF."); | ||
39 | return; | ||
40 | } | ||
41 | if (cpu->cfg.ext_j) { | ||
42 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
43 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/riscv/cpu_helper.c | 40 | --- a/target/riscv/cpu_helper.c |
45 | +++ b/target/riscv/cpu_helper.c | 41 | +++ b/target/riscv/cpu_helper.c |
46 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, |
47 | *pc = env->pc; | 43 | |
48 | *cs_base = 0; | 44 | switch (access_type) { |
49 | 45 | case MMU_INST_FETCH: | |
50 | - if (riscv_has_ext(env, RVV) || cpu->cfg.ext_zve64f) { | 46 | - if (env->virt_enabled && !first_stage) { |
51 | + if (riscv_has_ext(env, RVV) || cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { | 47 | + if (pmp_violation) { |
52 | /* | 48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; |
53 | * If env->vl equals to VLMAX, we can use generic vector operation | 49 | + } else if (env->virt_enabled && !first_stage) { |
54 | * expanders (GVEC) to accerlate the vector operations. | 50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; |
55 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 51 | } else { |
56 | index XXXXXXX..XXXXXXX 100644 | 52 | - cs->exception_index = pmp_violation ? |
57 | --- a/target/riscv/csr.c | 53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; |
58 | +++ b/target/riscv/csr.c | 54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; |
59 | @@ -XXX,XX +XXX,XX @@ static RISCVException vs(CPURISCVState *env, int csrno) | 55 | } |
60 | RISCVCPU *cpu = RISCV_CPU(cs); | 56 | break; |
61 | 57 | case MMU_DATA_LOAD: | |
62 | if (env->misa_ext & RVV || | 58 | - if (two_stage && !first_stage) { |
63 | - cpu->cfg.ext_zve64f) { | 59 | + if (pmp_violation) { |
64 | + cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { | 60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; |
65 | #if !defined(CONFIG_USER_ONLY) | 61 | + } else if (two_stage && !first_stage) { |
66 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { | 62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; |
67 | return RISCV_EXCP_ILLEGAL_INST; | 63 | } else { |
68 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 64 | - cs->exception_index = pmp_violation ? |
69 | index XXXXXXX..XXXXXXX 100644 | 65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; |
70 | --- a/target/riscv/translate.c | 66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; |
71 | +++ b/target/riscv/translate.c | 67 | } |
72 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 68 | break; |
73 | bool ext_ifencei; | 69 | case MMU_DATA_STORE: |
74 | bool ext_zfh; | 70 | - if (two_stage && !first_stage) { |
75 | bool ext_zfhmin; | 71 | + if (pmp_violation) { |
76 | + bool ext_zve32f; | 72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; |
77 | bool ext_zve64f; | 73 | + } else if (two_stage && !first_stage) { |
78 | bool hlsx; | 74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; |
79 | /* vector extension */ | 75 | } else { |
80 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 76 | - cs->exception_index = pmp_violation ? |
81 | ctx->ext_ifencei = cpu->cfg.ext_ifencei; | 77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : |
82 | ctx->ext_zfh = cpu->cfg.ext_zfh; | 78 | - RISCV_EXCP_STORE_PAGE_FAULT; |
83 | ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; | 79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; |
84 | + ctx->ext_zve32f = cpu->cfg.ext_zve32f; | 80 | } |
85 | ctx->ext_zve64f = cpu->cfg.ext_zve64f; | 81 | break; |
86 | ctx->vlen = cpu->cfg.vlen; | 82 | default: |
87 | ctx->elen = cpu->cfg.elen; | ||
88 | -- | 83 | -- |
89 | 2.31.1 | 84 | 2.45.1 |
90 | |||
91 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | All Zve* extensions support the vector configuration instructions. | ||
4 | |||
5 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: 20220118014522.13613-13-frank.chang@sifive.com | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- | ||
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
16 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
18 | TCGv s1, dst; | ||
19 | |||
20 | if (!require_rvv(s) || | ||
21 | - !(has_ext(s, RVV) || s->ext_zve64f)) { | ||
22 | + !(has_ext(s, RVV) || s->ext_zve32f || s->ext_zve64f)) { | ||
23 | return false; | ||
24 | } | ||
25 | |||
26 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) | ||
27 | TCGv dst; | ||
28 | |||
29 | if (!require_rvv(s) || | ||
30 | - !(has_ext(s, RVV) || s->ext_zve64f)) { | ||
31 | + !(has_ext(s, RVV) || s->ext_zve32f || s->ext_zve64f)) { | ||
32 | return false; | ||
33 | } | ||
34 | |||
35 | -- | ||
36 | 2.31.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | Vector widening conversion instructions are provided to and from all | ||
4 | supported integer EEWs for Zve32f extension. | ||
5 | |||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20220118014522.13613-16-frank.chang@sifive.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/insn_trans/trans_rvv.c.inc | 18 ++++++++++++++++++ | ||
12 | 1 file changed, 18 insertions(+) | ||
13 | |||
14 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
18 | @@ -XXX,XX +XXX,XX @@ static bool require_zve32f(DisasContext *s) | ||
19 | return s->ext_zve32f ? s->sew <= MO_32 : true; | ||
20 | } | ||
21 | |||
22 | +static bool require_scale_zve32f(DisasContext *s) | ||
23 | +{ | ||
24 | + /* RVV + Zve32f = RVV. */ | ||
25 | + if (has_ext(s, RVV)) { | ||
26 | + return true; | ||
27 | + } | ||
28 | + | ||
29 | + /* Zve32f doesn't support FP64. (Section 18.2) */ | ||
30 | + return s->ext_zve64f ? s->sew <= MO_16 : true; | ||
31 | +} | ||
32 | + | ||
33 | static bool require_zve64f(DisasContext *s) | ||
34 | { | ||
35 | /* RVV + Zve64f = RVV. */ | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | ||
37 | (s->sew != MO_8) && | ||
38 | vext_check_isa_ill(s) && | ||
39 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm) && | ||
40 | + require_scale_zve32f(s) && | ||
41 | require_scale_zve64f(s); | ||
42 | } | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
45 | (s->sew != MO_8) && | ||
46 | vext_check_isa_ill(s) && | ||
47 | vext_check_ds(s, a->rd, a->rs2, a->vm) && | ||
48 | + require_scale_zve32f(s) && | ||
49 | require_scale_zve64f(s); | ||
50 | } | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
53 | (s->sew != MO_8) && | ||
54 | vext_check_isa_ill(s) && | ||
55 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm) && | ||
56 | + require_scale_zve32f(s) && | ||
57 | require_scale_zve64f(s); | ||
58 | } | ||
59 | |||
60 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
61 | (s->sew != MO_8) && | ||
62 | vext_check_isa_ill(s) && | ||
63 | vext_check_dd(s, a->rd, a->rs2, a->vm) && | ||
64 | + require_scale_zve32f(s) && | ||
65 | require_scale_zve64f(s); | ||
66 | } | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) | ||
69 | { | ||
70 | return opfv_widen_check(s, a) && | ||
71 | require_rvf(s) && | ||
72 | + require_zve32f(s) && | ||
73 | require_zve64f(s); | ||
74 | } | ||
75 | |||
76 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
77 | return opfv_widen_check(s, a) && | ||
78 | require_scale_rvf(s) && | ||
79 | (s->sew != MO_8) && | ||
80 | + require_scale_zve32f(s) && | ||
81 | require_scale_zve64f(s); | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_widen_check(DisasContext *s, arg_rmr *a) | ||
85 | vext_check_isa_ill(s) && | ||
86 | /* OPFV widening instructions ignore vs1 check */ | ||
87 | vext_check_ds(s, a->rd, a->rs2, a->vm) && | ||
88 | + require_scale_zve32f(s) && | ||
89 | require_scale_zve64f(s); | ||
90 | } | ||
91 | |||
92 | -- | ||
93 | 2.31.1 | ||
94 | |||
95 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Frank Chang <frank.chang@sifive.com> | ||
2 | 1 | ||
3 | Vector narrowing conversion instructions are provided to and from all | ||
4 | supported integer EEWs for Zve32f extension. | ||
5 | |||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20220118014522.13613-17-frank.chang@sifive.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/insn_trans/trans_rvv.c.inc | 3 +++ | ||
12 | 1 file changed, 3 insertions(+) | ||
13 | |||
14 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
17 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
18 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | ||
19 | return opfv_narrow_check(s, a) && | ||
20 | require_rvf(s) && | ||
21 | (s->sew != MO_64) && | ||
22 | + require_zve32f(s) && | ||
23 | require_zve64f(s); | ||
24 | } | ||
25 | |||
26 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
27 | return opfv_narrow_check(s, a) && | ||
28 | require_scale_rvf(s) && | ||
29 | (s->sew != MO_8) && | ||
30 | + require_scale_zve32f(s) && | ||
31 | require_scale_zve64f(s); | ||
32 | } | ||
33 | |||
34 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) | ||
35 | vext_check_isa_ill(s) && | ||
36 | /* OPFV narrowing instructions ignore vs1 check */ | ||
37 | vext_check_sd(s, a->rd, a->rs2, a->vm) && | ||
38 | + require_scale_zve32f(s) && | ||
39 | require_scale_zve64f(s); | ||
40 | } | ||
41 | |||
42 | -- | ||
43 | 2.31.1 | ||
44 | |||
45 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Alexei Filippov <alexei.filippov@syntacore.com> |
---|---|---|---|
2 | 2 | ||
3 | The read from PC for translation is in cpu_get_tb_cpu_state, before translation. | 3 | Previous patch fixed the PMP priority in raise_mmu_exception() but we're still |
4 | setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage | ||
5 | translation part, mtval2 will be set in case of successes 2 stage translation but | ||
6 | failed pmp check. | ||
4 | 7 | ||
5 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 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 | Message-id: 20220120122050.41546-7-zhiwei_liu@c-sky.com | 18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> |
19 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 21 | --- |
11 | target/riscv/cpu_helper.c | 2 +- | 22 | target/riscv/cpu_helper.c | 12 ++++++------ |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 23 | 1 file changed, 6 insertions(+), 6 deletions(-) |
13 | 24 | ||
14 | 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 |
15 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu_helper.c | 27 | --- a/target/riscv/cpu_helper.c |
17 | +++ b/target/riscv/cpu_helper.c | 28 | +++ b/target/riscv/cpu_helper.c |
18 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
19 | 30 | __func__, pa, ret, prot_pmp, tlb_size); | |
20 | uint32_t flags = 0; | 31 | |
21 | 32 | prot &= prot_pmp; | |
22 | - *pc = env->pc; | 33 | - } |
23 | + *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; | 34 | - |
24 | *cs_base = 0; | 35 | - if (ret != TRANSLATE_SUCCESS) { |
25 | 36 | + } else { | |
26 | if (riscv_has_ext(env, RVV) || cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { | 37 | /* |
38 | * Guest physical address translation failed, this is a HS | ||
39 | * level exception | ||
40 | */ | ||
41 | first_stage_error = false; | ||
42 | - env->guest_phys_fault_addr = (im_address | | ||
43 | - (address & | ||
44 | - (TARGET_PAGE_SIZE - 1))) >> 2; | ||
45 | + if (ret != TRANSLATE_PMP_FAIL) { | ||
46 | + env->guest_phys_fault_addr = (im_address | | ||
47 | + (address & | ||
48 | + (TARGET_PAGE_SIZE - 1))) >> 2; | ||
49 | + } | ||
50 | } | ||
51 | } | ||
52 | } else { | ||
27 | -- | 53 | -- |
28 | 2.31.1 | 54 | 2.45.1 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 3 | This extension has now been ratified: |
4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be | ||
5 | removed. | ||
6 | |||
7 | Since this is now a ratified extension add it to the list of extensions | ||
8 | included in the "max" CPU variant. | ||
9 | |||
10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Message-id: 20220118014522.13613-18-frank.chang@sifive.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> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 17 | --- |
8 | target/riscv/cpu.c | 1 + | 18 | target/riscv/cpu.c | 2 +- |
9 | 1 file changed, 1 insertion(+) | 19 | target/riscv/tcg/tcg-cpu.c | 2 +- |
20 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
10 | 21 | ||
11 | 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 |
12 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/cpu.c | 24 | --- a/target/riscv/cpu.c |
14 | +++ b/target/riscv/cpu.c | 25 | +++ b/target/riscv/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { |
16 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | 27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), |
17 | DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), | 28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), |
18 | DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, false), | 29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), |
19 | + DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false), | 30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") |
20 | DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), | 31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") |
21 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | 32 | }; |
22 | DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | 33 | |
34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) | ||
35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/tcg/tcg-cpu.c | ||
38 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
40 | const RISCVCPUMultiExtConfig *prop; | ||
41 | |||
42 | /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); | ||
44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); | ||
45 | |||
46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
47 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
23 | -- | 48 | -- |
24 | 2.31.1 | 49 | 2.45.1 |
25 | |||
26 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Anup Patel <apatel@ventanamicro.com> | ||
2 | 1 | ||
3 | Currently, we have to use OpenSBI firmware ELF as bios for the spike | ||
4 | machine because the HTIF console requires ELF for parsing "fromhost" | ||
5 | and "tohost" symbols. | ||
6 | |||
7 | The latest OpenSBI can now optionally pick-up HTIF register address | ||
8 | from HTIF DT node so using this feature spike machine can now use | ||
9 | OpenSBI firmware BIN as bios. | ||
10 | |||
11 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | include/hw/char/riscv_htif.h | 5 ++++- | ||
17 | include/hw/riscv/spike.h | 1 + | ||
18 | hw/char/riscv_htif.c | 33 +++++++++++++++++++---------- | ||
19 | hw/riscv/spike.c | 41 ++++++++++++++++++++++-------------- | ||
20 | 4 files changed, 52 insertions(+), 28 deletions(-) | ||
21 | |||
22 | diff --git a/include/hw/char/riscv_htif.h b/include/hw/char/riscv_htif.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/include/hw/char/riscv_htif.h | ||
25 | +++ b/include/hw/char/riscv_htif.h | ||
26 | @@ -XXX,XX +XXX,XX @@ extern const MemoryRegionOps htif_io_ops; | ||
27 | void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value, | ||
28 | uint64_t st_size); | ||
29 | |||
30 | +/* Check if HTIF uses ELF symbols */ | ||
31 | +bool htif_uses_elf_symbols(void); | ||
32 | + | ||
33 | /* legacy pre qom */ | ||
34 | HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
35 | - CPURISCVState *env, Chardev *chr); | ||
36 | + CPURISCVState *env, Chardev *chr, uint64_t nonelf_base); | ||
37 | |||
38 | #endif | ||
39 | diff --git a/include/hw/riscv/spike.h b/include/hw/riscv/spike.h | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/include/hw/riscv/spike.h | ||
42 | +++ b/include/hw/riscv/spike.h | ||
43 | @@ -XXX,XX +XXX,XX @@ struct SpikeState { | ||
44 | |||
45 | enum { | ||
46 | SPIKE_MROM, | ||
47 | + SPIKE_HTIF, | ||
48 | SPIKE_CLINT, | ||
49 | SPIKE_DRAM | ||
50 | }; | ||
51 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/hw/char/riscv_htif.c | ||
54 | +++ b/hw/char/riscv_htif.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps htif_mm_ops = { | ||
56 | .write = htif_mm_write, | ||
57 | }; | ||
58 | |||
59 | +bool htif_uses_elf_symbols(void) | ||
60 | +{ | ||
61 | + return (address_symbol_set == 3) ? true : false; | ||
62 | +} | ||
63 | + | ||
64 | HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
65 | - CPURISCVState *env, Chardev *chr) | ||
66 | + CPURISCVState *env, Chardev *chr, uint64_t nonelf_base) | ||
67 | { | ||
68 | - uint64_t base = MIN(tohost_addr, fromhost_addr); | ||
69 | - uint64_t size = MAX(tohost_addr + 8, fromhost_addr + 8) - base; | ||
70 | - uint64_t tohost_offset = tohost_addr - base; | ||
71 | - uint64_t fromhost_offset = fromhost_addr - base; | ||
72 | + uint64_t base, size, tohost_offset, fromhost_offset; | ||
73 | + | ||
74 | + if (!htif_uses_elf_symbols()) { | ||
75 | + fromhost_addr = nonelf_base; | ||
76 | + tohost_addr = nonelf_base + 8; | ||
77 | + } | ||
78 | + | ||
79 | + base = MIN(tohost_addr, fromhost_addr); | ||
80 | + size = MAX(tohost_addr + 8, fromhost_addr + 8) - base; | ||
81 | + tohost_offset = tohost_addr - base; | ||
82 | + fromhost_offset = fromhost_addr - base; | ||
83 | |||
84 | HTIFState *s = g_malloc0(sizeof(HTIFState)); | ||
85 | s->address_space = address_space; | ||
86 | @@ -XXX,XX +XXX,XX @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem, | ||
87 | qemu_chr_fe_init(&s->chr, chr, &error_abort); | ||
88 | qemu_chr_fe_set_handlers(&s->chr, htif_can_recv, htif_recv, htif_event, | ||
89 | htif_be_change, s, NULL, true); | ||
90 | - if (address_symbol_set == 3) { | ||
91 | - memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s, | ||
92 | - TYPE_HTIF_UART, size); | ||
93 | - memory_region_add_subregion_overlap(address_space, base, | ||
94 | - &s->mmio, 1); | ||
95 | - } | ||
96 | + | ||
97 | + memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s, | ||
98 | + TYPE_HTIF_UART, size); | ||
99 | + memory_region_add_subregion_overlap(address_space, base, | ||
100 | + &s->mmio, 1); | ||
101 | |||
102 | return s; | ||
103 | } | ||
104 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/hw/riscv/spike.c | ||
107 | +++ b/hw/riscv/spike.c | ||
108 | @@ -XXX,XX +XXX,XX @@ | ||
109 | |||
110 | static const MemMapEntry spike_memmap[] = { | ||
111 | [SPIKE_MROM] = { 0x1000, 0xf000 }, | ||
112 | + [SPIKE_HTIF] = { 0x1000000, 0x1000 }, | ||
113 | [SPIKE_CLINT] = { 0x2000000, 0x10000 }, | ||
114 | [SPIKE_DRAM] = { 0x80000000, 0x0 }, | ||
115 | }; | ||
116 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
117 | |||
118 | qemu_fdt_add_subnode(fdt, "/htif"); | ||
119 | qemu_fdt_setprop_string(fdt, "/htif", "compatible", "ucb,htif0"); | ||
120 | + if (!htif_uses_elf_symbols()) { | ||
121 | + qemu_fdt_setprop_cells(fdt, "/htif", "reg", | ||
122 | + 0x0, memmap[SPIKE_HTIF].base, 0x0, memmap[SPIKE_HTIF].size); | ||
123 | + } | ||
124 | |||
125 | qemu_fdt_add_subnode(fdt, "/soc"); | ||
126 | qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0); | ||
127 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | ||
128 | if (cmdline) { | ||
129 | qemu_fdt_add_subnode(fdt, "/chosen"); | ||
130 | qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | ||
131 | + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
136 | memory_region_add_subregion(system_memory, memmap[SPIKE_DRAM].base, | ||
137 | machine->ram); | ||
138 | |||
139 | - /* create device tree */ | ||
140 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
141 | - riscv_is_32bit(&s->soc[0])); | ||
142 | - | ||
143 | /* boot rom */ | ||
144 | memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom", | ||
145 | memmap[SPIKE_MROM].size, &error_fatal); | ||
146 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
147 | htif_symbol_callback); | ||
148 | } | ||
149 | |||
150 | + /* Load kernel */ | ||
151 | if (machine->kernel_filename) { | ||
152 | kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
153 | firmware_end_addr); | ||
154 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
155 | kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
156 | kernel_start_addr, | ||
157 | htif_symbol_callback); | ||
158 | - | ||
159 | - if (machine->initrd_filename) { | ||
160 | - hwaddr start; | ||
161 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
162 | - machine->ram_size, kernel_entry, | ||
163 | - &start); | ||
164 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", | ||
165 | - "linux,initrd-start", start); | ||
166 | - qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", | ||
167 | - end); | ||
168 | - } | ||
169 | } else { | ||
170 | /* | ||
171 | * If dynamic firmware is used, it doesn't know where is the next mode | ||
172 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
173 | kernel_entry = 0; | ||
174 | } | ||
175 | |||
176 | + /* Create device tree */ | ||
177 | + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
178 | + riscv_is_32bit(&s->soc[0])); | ||
179 | + | ||
180 | + /* Load initrd */ | ||
181 | + if (machine->kernel_filename && machine->initrd_filename) { | ||
182 | + hwaddr start; | ||
183 | + hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
184 | + machine->ram_size, kernel_entry, | ||
185 | + &start); | ||
186 | + qemu_fdt_setprop_cell(s->fdt, "/chosen", | ||
187 | + "linux,initrd-start", start); | ||
188 | + qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end", | ||
189 | + end); | ||
190 | + } | ||
191 | + | ||
192 | /* Compute the fdt load address in dram */ | ||
193 | fdt_load_addr = riscv_load_fdt(memmap[SPIKE_DRAM].base, | ||
194 | machine->ram_size, s->fdt); | ||
195 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
196 | |||
197 | /* initialize HTIF using symbols found in load_kernel */ | ||
198 | htif_mm_init(system_memory, mask_rom, | ||
199 | - &s->soc[0].harts[0].env, serial_hd(0)); | ||
200 | + &s->soc[0].harts[0].env, serial_hd(0), | ||
201 | + memmap[SPIKE_HTIF].base); | ||
202 | } | ||
203 | |||
204 | static void spike_machine_instance_init(Object *obj) | ||
205 | -- | ||
206 | 2.31.1 | ||
207 | |||
208 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Anup Patel <apatel@ventanamicro.com> | ||
2 | 1 | ||
3 | Now that RISC-V Spike machine can use BIN BIOS images, we remove | ||
4 | the macros used for ELF BIOS image names. | ||
5 | |||
6 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | include/hw/riscv/boot.h | 2 -- | ||
12 | hw/riscv/spike.c | 4 ++-- | ||
13 | 2 files changed, 2 insertions(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/hw/riscv/boot.h | ||
18 | +++ b/include/hw/riscv/boot.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #include "hw/riscv/riscv_hart.h" | ||
21 | |||
22 | #define RISCV32_BIOS_BIN "opensbi-riscv32-generic-fw_dynamic.bin" | ||
23 | -#define RISCV32_BIOS_ELF "opensbi-riscv32-generic-fw_dynamic.elf" | ||
24 | #define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin" | ||
25 | -#define RISCV64_BIOS_ELF "opensbi-riscv64-generic-fw_dynamic.elf" | ||
26 | |||
27 | bool riscv_is_32bit(RISCVHartArrayState *harts); | ||
28 | |||
29 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/riscv/spike.c | ||
32 | +++ b/hw/riscv/spike.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
34 | */ | ||
35 | if (riscv_is_32bit(&s->soc[0])) { | ||
36 | firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
37 | - RISCV32_BIOS_ELF, memmap[SPIKE_DRAM].base, | ||
38 | + RISCV32_BIOS_BIN, memmap[SPIKE_DRAM].base, | ||
39 | htif_symbol_callback); | ||
40 | } else { | ||
41 | firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
42 | - RISCV64_BIOS_ELF, memmap[SPIKE_DRAM].base, | ||
43 | + RISCV64_BIOS_BIN, memmap[SPIKE_DRAM].base, | ||
44 | htif_symbol_callback); | ||
45 | } | ||
46 | |||
47 | -- | ||
48 | 2.31.1 | ||
49 | |||
50 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Anup Patel <apatel@ventanamicro.com> | ||
2 | 1 | ||
3 | Now that all RISC-V machines can use OpenSBI BIN images, we remove | ||
4 | OpenSBI ELF images and also exclude these images from BIOS build. | ||
5 | |||
6 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | .gitlab-ci.d/opensbi.yml | 2 -- | ||
12 | pc-bios/meson.build | 2 -- | ||
13 | pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | Bin 838904 -> 0 bytes | ||
14 | pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | Bin 934696 -> 0 bytes | ||
15 | roms/Makefile | 2 -- | ||
16 | 5 files changed, 6 deletions(-) | ||
17 | delete mode 100644 pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | ||
18 | delete mode 100644 pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | ||
19 | |||
20 | diff --git a/.gitlab-ci.d/opensbi.yml b/.gitlab-ci.d/opensbi.yml | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/.gitlab-ci.d/opensbi.yml | ||
23 | +++ b/.gitlab-ci.d/opensbi.yml | ||
24 | @@ -XXX,XX +XXX,XX @@ build-opensbi: | ||
25 | artifacts: | ||
26 | paths: # 'artifacts.zip' will contains the following files: | ||
27 | - pc-bios/opensbi-riscv32-generic-fw_dynamic.bin | ||
28 | - - pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | ||
29 | - pc-bios/opensbi-riscv64-generic-fw_dynamic.bin | ||
30 | - - pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | ||
31 | - opensbi32-generic-stdout.log | ||
32 | - opensbi32-generic-stderr.log | ||
33 | - opensbi64-generic-stdout.log | ||
34 | diff --git a/pc-bios/meson.build b/pc-bios/meson.build | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/pc-bios/meson.build | ||
37 | +++ b/pc-bios/meson.build | ||
38 | @@ -XXX,XX +XXX,XX @@ blobs = files( | ||
39 | 'hppa-firmware.img', | ||
40 | 'opensbi-riscv32-generic-fw_dynamic.bin', | ||
41 | 'opensbi-riscv64-generic-fw_dynamic.bin', | ||
42 | - 'opensbi-riscv32-generic-fw_dynamic.elf', | ||
43 | - 'opensbi-riscv64-generic-fw_dynamic.elf', | ||
44 | 'npcm7xx_bootrom.bin', | ||
45 | ) | ||
46 | |||
47 | diff --git a/pc-bios/opensbi-riscv32-generic-fw_dynamic.elf b/pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | ||
48 | deleted file mode 100644 | ||
49 | index XXXXXXX..XXXXXXX | ||
50 | Binary files a/pc-bios/opensbi-riscv32-generic-fw_dynamic.elf and /dev/null differ | ||
51 | diff --git a/pc-bios/opensbi-riscv64-generic-fw_dynamic.elf b/pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | ||
52 | deleted file mode 100644 | ||
53 | index XXXXXXX..XXXXXXX | ||
54 | Binary files a/pc-bios/opensbi-riscv64-generic-fw_dynamic.elf and /dev/null differ | ||
55 | diff --git a/roms/Makefile b/roms/Makefile | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/roms/Makefile | ||
58 | +++ b/roms/Makefile | ||
59 | @@ -XXX,XX +XXX,XX @@ opensbi32-generic: | ||
60 | CROSS_COMPILE=$(riscv32_cross_prefix) \ | ||
61 | PLATFORM="generic" | ||
62 | cp opensbi/build/platform/generic/firmware/fw_dynamic.bin ../pc-bios/opensbi-riscv32-generic-fw_dynamic.bin | ||
63 | - cp opensbi/build/platform/generic/firmware/fw_dynamic.elf ../pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | ||
64 | |||
65 | opensbi64-generic: | ||
66 | $(MAKE) -C opensbi \ | ||
67 | CROSS_COMPILE=$(riscv64_cross_prefix) \ | ||
68 | PLATFORM="generic" | ||
69 | cp opensbi/build/platform/generic/firmware/fw_dynamic.bin ../pc-bios/opensbi-riscv64-generic-fw_dynamic.bin | ||
70 | - cp opensbi/build/platform/generic/firmware/fw_dynamic.elf ../pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | ||
71 | |||
72 | MESON = meson | ||
73 | NINJA = ninja | ||
74 | -- | ||
75 | 2.31.1 | ||
76 | |||
77 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Message-id: 20220120122050.41546-2-zhiwei_liu@c-sky.com | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | ||
9 | target/riscv/csr.c | 19 +++++++++++++++++++ | ||
10 | target/riscv/pmp.c | 12 ++++-------- | ||
11 | 2 files changed, 23 insertions(+), 8 deletions(-) | ||
12 | |||
13 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/csr.c | ||
16 | +++ b/target/riscv/csr.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mseccfg(CPURISCVState *env, int csrno, | ||
18 | return RISCV_EXCP_NONE; | ||
19 | } | ||
20 | |||
21 | +static bool check_pmp_reg_index(CPURISCVState *env, uint32_t reg_index) | ||
22 | +{ | ||
23 | + /* TODO: RV128 restriction check */ | ||
24 | + if ((reg_index & 1) && (riscv_cpu_mxl(env) == MXL_RV64)) { | ||
25 | + return false; | ||
26 | + } | ||
27 | + return true; | ||
28 | +} | ||
29 | + | ||
30 | static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, | ||
31 | target_ulong *val) | ||
32 | { | ||
33 | + uint32_t reg_index = csrno - CSR_PMPCFG0; | ||
34 | + | ||
35 | + if (!check_pmp_reg_index(env, reg_index)) { | ||
36 | + return RISCV_EXCP_ILLEGAL_INST; | ||
37 | + } | ||
38 | *val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0); | ||
39 | return RISCV_EXCP_NONE; | ||
40 | } | ||
41 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, | ||
42 | static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, | ||
43 | target_ulong val) | ||
44 | { | ||
45 | + uint32_t reg_index = csrno - CSR_PMPCFG0; | ||
46 | + | ||
47 | + if (!check_pmp_reg_index(env, reg_index)) { | ||
48 | + return RISCV_EXCP_ILLEGAL_INST; | ||
49 | + } | ||
50 | pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val); | ||
51 | return RISCV_EXCP_NONE; | ||
52 | } | ||
53 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/pmp.c | ||
56 | +++ b/target/riscv/pmp.c | ||
57 | @@ -XXX,XX +XXX,XX @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, | ||
58 | { | ||
59 | int i; | ||
60 | uint8_t cfg_val; | ||
61 | + int pmpcfg_nums = 2 << riscv_cpu_mxl(env); | ||
62 | |||
63 | trace_pmpcfg_csr_write(env->mhartid, reg_index, val); | ||
64 | |||
65 | - if ((reg_index & 1) && (sizeof(target_ulong) == 8)) { | ||
66 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
67 | - "ignoring pmpcfg write - incorrect address\n"); | ||
68 | - return; | ||
69 | - } | ||
70 | - | ||
71 | - for (i = 0; i < sizeof(target_ulong); i++) { | ||
72 | + for (i = 0; i < pmpcfg_nums; i++) { | ||
73 | cfg_val = (val >> 8 * i) & 0xff; | ||
74 | pmp_write_cfg(env, (reg_index * 4) + i, cfg_val); | ||
75 | } | ||
76 | @@ -XXX,XX +XXX,XX @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index) | ||
77 | int i; | ||
78 | target_ulong cfg_val = 0; | ||
79 | target_ulong val = 0; | ||
80 | + int pmpcfg_nums = 2 << riscv_cpu_mxl(env); | ||
81 | |||
82 | - for (i = 0; i < sizeof(target_ulong); i++) { | ||
83 | + for (i = 0; i < pmpcfg_nums; i++) { | ||
84 | val = pmp_read_cfg(env, (reg_index * 4) + i); | ||
85 | cfg_val |= (val << (i * 8)); | ||
86 | } | ||
87 | -- | ||
88 | 2.31.1 | ||
89 | |||
90 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Define one common function to compute a canonical address from a register | 3 | When running the instruction |
4 | plus offset. Merge gen_pm_adjust_address into this function. | ||
5 | 4 | ||
6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 5 | ``` |
6 | cbo.flush 0(x0) | ||
7 | ``` | ||
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") | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 31 | Cc: qemu-stable <qemu-stable@nongnu.org> |
9 | Message-id: 20220120122050.41546-14-zhiwei_liu@c-sky.com | 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 | 25 ++++++++++++------------- | 35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- |
13 | target/riscv/insn_trans/trans_rva.c.inc | 9 +++------ | 36 | 1 file changed, 12 insertions(+), 4 deletions(-) |
14 | target/riscv/insn_trans/trans_rvd.c.inc | 19 ++----------------- | ||
15 | target/riscv/insn_trans/trans_rvf.c.inc | 19 ++----------------- | ||
16 | target/riscv/insn_trans/trans_rvi.c.inc | 18 ++---------------- | ||
17 | 5 files changed, 21 insertions(+), 69 deletions(-) | ||
18 | 37 | ||
19 | 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 |
20 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/translate.c | 40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc |
22 | +++ b/target/riscv/translate.c | 41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
23 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | 42 | @@ -XXX,XX +XXX,XX @@ |
24 | ctx->base.is_jmp = DISAS_NORETURN; | 43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) |
25 | } | ||
26 | |||
27 | -/* | ||
28 | - * Generates address adjustment for PointerMasking | ||
29 | - */ | ||
30 | -static TCGv gen_pm_adjust_address(DisasContext *s, TCGv src) | ||
31 | +/* Compute a canonical address from a register plus offset. */ | ||
32 | +static TCGv get_address(DisasContext *ctx, int rs1, int imm) | ||
33 | { | 44 | { |
34 | - TCGv temp; | 45 | REQUIRE_ZICBOM(ctx); |
35 | - if (!s->pm_enabled) { | 46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
36 | - /* Load unmodified address */ | 47 | + TCGv src = get_address(ctx, a->rs1, 0); |
37 | - return src; | ||
38 | - } else { | ||
39 | - temp = temp_new(s); | ||
40 | - tcg_gen_andc_tl(temp, src, pm_mask); | ||
41 | - tcg_gen_or_tl(temp, temp, pm_base); | ||
42 | - return temp; | ||
43 | + TCGv addr = temp_new(ctx); | ||
44 | + TCGv src1 = get_gpr(ctx, rs1, EXT_NONE); | ||
45 | + | 48 | + |
46 | + tcg_gen_addi_tl(addr, src1, imm); | 49 | + gen_helper_cbo_clean_flush(tcg_env, src); |
47 | + if (ctx->pm_enabled) { | ||
48 | + tcg_gen_and_tl(addr, addr, pm_mask); | ||
49 | + tcg_gen_or_tl(addr, addr, pm_base); | ||
50 | + } else if (get_xl(ctx) == MXL_RV32) { | ||
51 | + tcg_gen_ext32u_tl(addr, addr); | ||
52 | } | ||
53 | + return addr; | ||
54 | } | ||
55 | |||
56 | #ifndef CONFIG_USER_ONLY | ||
57 | diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/riscv/insn_trans/trans_rva.c.inc | ||
60 | +++ b/target/riscv/insn_trans/trans_rva.c.inc | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | |||
63 | static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop) | ||
64 | { | ||
65 | - TCGv src1 = get_gpr(ctx, a->rs1, EXT_ZERO); | ||
66 | + TCGv src1 = get_address(ctx, a->rs1, 0); | ||
67 | |||
68 | if (a->rl) { | ||
69 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | ||
70 | } | ||
71 | - src1 = gen_pm_adjust_address(ctx, src1); | ||
72 | tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop); | ||
73 | if (a->aq) { | ||
74 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | ||
75 | @@ -XXX,XX +XXX,XX @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop) | ||
76 | TCGLabel *l1 = gen_new_label(); | ||
77 | TCGLabel *l2 = gen_new_label(); | ||
78 | |||
79 | - src1 = get_gpr(ctx, a->rs1, EXT_ZERO); | ||
80 | - src1 = gen_pm_adjust_address(ctx, src1); | ||
81 | + src1 = get_address(ctx, a->rs1, 0); | ||
82 | tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); | ||
83 | |||
84 | /* | ||
85 | @@ -XXX,XX +XXX,XX @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a, | ||
86 | MemOp mop) | ||
87 | { | ||
88 | TCGv dest = dest_gpr(ctx, a->rd); | ||
89 | - TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); | ||
90 | + TCGv src1 = get_address(ctx, a->rs1, 0); | ||
91 | TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); | ||
92 | |||
93 | - src1 = gen_pm_adjust_address(ctx, src1); | ||
94 | func(dest, src1, src2, ctx->mem_idx, mop); | ||
95 | |||
96 | gen_set_gpr(ctx, a->rd, dest); | ||
97 | diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/target/riscv/insn_trans/trans_rvd.c.inc | ||
100 | +++ b/target/riscv/insn_trans/trans_rvd.c.inc | ||
101 | @@ -XXX,XX +XXX,XX @@ static bool trans_fld(DisasContext *ctx, arg_fld *a) | ||
102 | REQUIRE_FPU; | ||
103 | REQUIRE_EXT(ctx, RVD); | ||
104 | |||
105 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | ||
106 | - if (a->imm) { | ||
107 | - TCGv temp = temp_new(ctx); | ||
108 | - tcg_gen_addi_tl(temp, addr, a->imm); | ||
109 | - addr = temp; | ||
110 | - } | ||
111 | - addr = gen_pm_adjust_address(ctx, addr); | ||
112 | - | ||
113 | + addr = get_address(ctx, a->rs1, a->imm); | ||
114 | tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, MO_TEUQ); | ||
115 | |||
116 | mark_fs_dirty(ctx); | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) | ||
118 | REQUIRE_FPU; | ||
119 | REQUIRE_EXT(ctx, RVD); | ||
120 | |||
121 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | ||
122 | - if (a->imm) { | ||
123 | - TCGv temp = temp_new(ctx); | ||
124 | - tcg_gen_addi_tl(temp, addr, a->imm); | ||
125 | - addr = temp; | ||
126 | - } | ||
127 | - addr = gen_pm_adjust_address(ctx, addr); | ||
128 | - | ||
129 | + addr = get_address(ctx, a->rs1, a->imm); | ||
130 | tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUQ); | ||
131 | - | ||
132 | return true; | 50 | return true; |
133 | } | 51 | } |
134 | 52 | ||
135 | diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc | 53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) |
136 | index XXXXXXX..XXXXXXX 100644 | 54 | { |
137 | --- a/target/riscv/insn_trans/trans_rvf.c.inc | 55 | REQUIRE_ZICBOM(ctx); |
138 | +++ b/target/riscv/insn_trans/trans_rvf.c.inc | 56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
139 | @@ -XXX,XX +XXX,XX @@ static bool trans_flw(DisasContext *ctx, arg_flw *a) | 57 | + TCGv src = get_address(ctx, a->rs1, 0); |
140 | REQUIRE_FPU; | 58 | + |
141 | REQUIRE_EXT(ctx, RVF); | 59 | + gen_helper_cbo_clean_flush(tcg_env, src); |
142 | |||
143 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | ||
144 | - if (a->imm) { | ||
145 | - TCGv temp = temp_new(ctx); | ||
146 | - tcg_gen_addi_tl(temp, addr, a->imm); | ||
147 | - addr = temp; | ||
148 | - } | ||
149 | - addr = gen_pm_adjust_address(ctx, addr); | ||
150 | - | ||
151 | + addr = get_address(ctx, a->rs1, a->imm); | ||
152 | dest = cpu_fpr[a->rd]; | ||
153 | tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_TEUL); | ||
154 | gen_nanbox_s(dest, dest); | ||
155 | @@ -XXX,XX +XXX,XX @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) | ||
156 | REQUIRE_FPU; | ||
157 | REQUIRE_EXT(ctx, RVF); | ||
158 | |||
159 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | ||
160 | - if (a->imm) { | ||
161 | - TCGv temp = tcg_temp_new(); | ||
162 | - tcg_gen_addi_tl(temp, addr, a->imm); | ||
163 | - addr = temp; | ||
164 | - } | ||
165 | - addr = gen_pm_adjust_address(ctx, addr); | ||
166 | - | ||
167 | + addr = get_address(ctx, a->rs1, a->imm); | ||
168 | tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUL); | ||
169 | - | ||
170 | return true; | 60 | return true; |
171 | } | 61 | } |
172 | 62 | ||
173 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | 63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) |
174 | index XXXXXXX..XXXXXXX 100644 | ||
175 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
176 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
177 | @@ -XXX,XX +XXX,XX @@ static bool trans_bgeu(DisasContext *ctx, arg_bgeu *a) | ||
178 | static bool gen_load_tl(DisasContext *ctx, arg_lb *a, MemOp memop) | ||
179 | { | 64 | { |
180 | TCGv dest = dest_gpr(ctx, a->rd); | 65 | REQUIRE_ZICBOM(ctx); |
181 | - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | 66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); |
182 | - | 67 | + TCGv src = get_address(ctx, a->rs1, 0); |
183 | - if (a->imm) { | 68 | + |
184 | - TCGv temp = temp_new(ctx); | 69 | + gen_helper_cbo_inval(tcg_env, src); |
185 | - tcg_gen_addi_tl(temp, addr, a->imm); | 70 | return true; |
186 | - addr = temp; | 71 | } |
187 | - } | 72 | |
188 | - addr = gen_pm_adjust_address(ctx, addr); | 73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) |
189 | + TCGv addr = get_address(ctx, a->rs1, a->imm); | ||
190 | |||
191 | tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); | ||
192 | gen_set_gpr(ctx, a->rd, dest); | ||
193 | @@ -XXX,XX +XXX,XX @@ static bool trans_ldu(DisasContext *ctx, arg_ldu *a) | ||
194 | |||
195 | static bool gen_store_tl(DisasContext *ctx, arg_sb *a, MemOp memop) | ||
196 | { | 74 | { |
197 | - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | 75 | REQUIRE_ZICBOZ(ctx); |
198 | + TCGv addr = get_address(ctx, a->rs1, a->imm); | 76 | - gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]); |
199 | TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); | 77 | + TCGv src = get_address(ctx, a->rs1, 0); |
200 | 78 | + | |
201 | - if (a->imm) { | 79 | + gen_helper_cbo_zero(tcg_env, src); |
202 | - TCGv temp = temp_new(ctx); | ||
203 | - tcg_gen_addi_tl(temp, addr, a->imm); | ||
204 | - addr = temp; | ||
205 | - } | ||
206 | - addr = gen_pm_adjust_address(ctx, addr); | ||
207 | - | ||
208 | tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); | ||
209 | return true; | 80 | return true; |
210 | } | 81 | } |
211 | -- | 82 | -- |
212 | 2.31.1 | 83 | 2.45.1 |
213 | |||
214 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 3 | In AIA spec, each hart (or each hart within a group) has a unique hart |
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 4 | number to locate the memory pages of interrupt files in the address |
5 | Message-id: 20220120122050.41546-4-zhiwei_liu@c-sky.com | 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. | ||
8 | |||
9 | However, if the largest hart number among groups is a power of 2, QEMU | ||
10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when | ||
11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient | ||
12 | to represent 4 harts, but we passes 3 to Linux. The code needs to be | ||
13 | updated to ensure accurate hart-index-bit settings. | ||
14 | |||
15 | Additionally, a Linux patch[1] is necessary to correctly recover the hart | ||
16 | index when the guest OS has only 1 hart, where the hart-index-bit is 0. | ||
17 | |||
18 | [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ | ||
19 | |||
20 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> | ||
21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
22 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
23 | Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 25 | --- |
8 | target/riscv/translate.c | 4 +--- | 26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- |
9 | target/riscv/insn_trans/trans_rvi.c.inc | 4 +--- | 27 | 1 file changed, 8 insertions(+), 1 deletion(-) |
10 | 2 files changed, 2 insertions(+), 6 deletions(-) | ||
11 | 28 | ||
12 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/riscv/translate.c | 31 | --- a/target/riscv/kvm/kvm-cpu.c |
15 | +++ b/target/riscv/translate.c | 32 | +++ b/target/riscv/kvm/kvm-cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | 33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
17 | return; | ||
18 | } | 34 | } |
19 | } | 35 | } |
20 | - if (rd != 0) { | 36 | |
21 | - tcg_gen_movi_tl(cpu_gpr[rd], ctx->pc_succ_insn); | 37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
22 | - } | 38 | + |
23 | 39 | + if (max_hart_per_socket > 1) { | |
24 | + gen_set_gpri(ctx, rd, ctx->pc_succ_insn); | 40 | + max_hart_per_socket--; |
25 | gen_goto_tb(ctx, 0, ctx->base.pc_next + imm); /* must use this for safety */ | 41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
26 | ctx->base.is_jmp = DISAS_NORETURN; | 42 | + } else { |
27 | } | 43 | + hart_bits = 0; |
28 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | 44 | + } |
29 | index XXXXXXX..XXXXXXX 100644 | 45 | + |
30 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | 46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, |
31 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | 47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, |
32 | @@ -XXX,XX +XXX,XX @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) | 48 | &hart_bits, true, NULL); |
33 | tcg_temp_free(t0); | ||
34 | } | ||
35 | |||
36 | - if (a->rd != 0) { | ||
37 | - tcg_gen_movi_tl(cpu_gpr[a->rd], ctx->pc_succ_insn); | ||
38 | - } | ||
39 | + gen_set_gpri(ctx, a->rd, ctx->pc_succ_insn); | ||
40 | tcg_gen_lookup_and_goto_ptr(); | ||
41 | |||
42 | if (misaligned) { | ||
43 | -- | 49 | -- |
44 | 2.31.1 | 50 | 2.45.1 |
45 | |||
46 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 4 | in bytes, when in this context we want 'reg_width' as the length in |
5 | bits. | ||
6 | |||
7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a | ||
8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set | ||
9 | beforehand. | ||
10 | |||
11 | While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more | ||
12 | clarity about what the variable represents. 'bitsize' is also used in | ||
13 | riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to | ||
14 | gdb_feature_builder_append_reg(). | ||
15 | |||
16 | Cc: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
17 | Cc: Alex Bennée <alex.bennee@linaro.org> | ||
18 | Reported-by: Robin Dapp <rdapp.gcc@gmail.com> | ||
19 | Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML") | ||
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
21 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
22 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
23 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Message-id: 20220120122050.41546-9-zhiwei_liu@c-sky.com | 25 | Cc: qemu-stable <qemu-stable@nongnu.org> |
26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | --- | 28 | --- |
9 | target/riscv/cpu.c | 8 ++--- | 29 | target/riscv/gdbstub.c | 6 +++--- |
10 | target/riscv/gdbstub.c | 71 +++++++++++++++++++++++++++++++----------- | 30 | 1 file changed, 3 insertions(+), 3 deletions(-) |
11 | 2 files changed, 55 insertions(+), 24 deletions(-) | ||
12 | 31 | ||
13 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/cpu.c | ||
16 | +++ b/target/riscv/cpu.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
18 | RISCVCPU *cpu = RISCV_CPU(dev); | ||
19 | CPURISCVState *env = &cpu->env; | ||
20 | RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); | ||
21 | + CPUClass *cc = CPU_CLASS(mcc); | ||
22 | int priv_version = 0; | ||
23 | Error *local_err = NULL; | ||
24 | |||
25 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
26 | switch (env->misa_mxl_max) { | ||
27 | #ifdef TARGET_RISCV64 | ||
28 | case MXL_RV64: | ||
29 | + cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; | ||
30 | break; | ||
31 | case MXL_RV128: | ||
32 | break; | ||
33 | #endif | ||
34 | case MXL_RV32: | ||
35 | + cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; | ||
36 | break; | ||
37 | default: | ||
38 | g_assert_not_reached(); | ||
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
40 | cc->gdb_read_register = riscv_cpu_gdb_read_register; | ||
41 | cc->gdb_write_register = riscv_cpu_gdb_write_register; | ||
42 | cc->gdb_num_core_regs = 33; | ||
43 | -#if defined(TARGET_RISCV32) | ||
44 | - cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; | ||
45 | -#elif defined(TARGET_RISCV64) | ||
46 | - cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; | ||
47 | -#endif | ||
48 | cc->gdb_stop_before_watchpoint = true; | ||
49 | cc->disas_set_info = riscv_cpu_disas_set_info; | ||
50 | #ifndef CONFIG_USER_ONLY | ||
51 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | 32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
52 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/target/riscv/gdbstub.c | 34 | --- a/target/riscv/gdbstub.c |
54 | +++ b/target/riscv/gdbstub.c | 35 | +++ b/target/riscv/gdbstub.c |
55 | @@ -XXX,XX +XXX,XX @@ int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) | 36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) |
37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | ||
56 | { | 38 | { |
57 | RISCVCPU *cpu = RISCV_CPU(cs); | 39 | RISCVCPU *cpu = RISCV_CPU(cs); |
58 | CPURISCVState *env = &cpu->env; | 40 | - int reg_width = cpu->cfg.vlenb; |
59 | + target_ulong tmp; | 41 | + int bitsize = cpu->cfg.vlenb << 3; |
60 | 42 | GDBFeatureBuilder builder; | |
61 | if (n < 32) { | 43 | int i; |
62 | - return gdb_get_regl(mem_buf, env->gpr[n]); | 44 | |
63 | + tmp = env->gpr[n]; | 45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
64 | } else if (n == 32) { | 46 | |
65 | - return gdb_get_regl(mem_buf, env->pc); | 47 | /* First define types and totals in a whole VL */ |
66 | + tmp = env->pc; | 48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { |
67 | + } else { | 49 | - int count = reg_width / vec_lanes[i].size; |
68 | + return 0; | 50 | + int count = bitsize / vec_lanes[i].size; |
69 | + } | 51 | gdb_feature_builder_append_tag( |
70 | + | 52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", |
71 | + switch (env->misa_mxl_max) { | 53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); |
72 | + case MXL_RV32: | 54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
73 | + return gdb_get_reg32(mem_buf, tmp); | 55 | /* Define vector registers */ |
74 | + case MXL_RV64: | 56 | for (i = 0; i < 32; i++) { |
75 | + return gdb_get_reg64(mem_buf, tmp); | 57 | gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), |
76 | + default: | 58 | - reg_width, i, "riscv_vector", "vector"); |
77 | + g_assert_not_reached(); | 59 | + bitsize, i, "riscv_vector", "vector"); |
78 | } | 60 | } |
79 | return 0; | 61 | |
80 | } | 62 | gdb_feature_builder_end(&builder); |
81 | @@ -XXX,XX +XXX,XX @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) | ||
82 | { | ||
83 | RISCVCPU *cpu = RISCV_CPU(cs); | ||
84 | CPURISCVState *env = &cpu->env; | ||
85 | - | ||
86 | - if (n == 0) { | ||
87 | - /* discard writes to x0 */ | ||
88 | - return sizeof(target_ulong); | ||
89 | - } else if (n < 32) { | ||
90 | - env->gpr[n] = ldtul_p(mem_buf); | ||
91 | - return sizeof(target_ulong); | ||
92 | + int length = 0; | ||
93 | + target_ulong tmp; | ||
94 | + | ||
95 | + switch (env->misa_mxl_max) { | ||
96 | + case MXL_RV32: | ||
97 | + tmp = (int32_t)ldl_p(mem_buf); | ||
98 | + length = 4; | ||
99 | + break; | ||
100 | + case MXL_RV64: | ||
101 | + if (env->xl < MXL_RV64) { | ||
102 | + tmp = (int32_t)ldq_p(mem_buf); | ||
103 | + } else { | ||
104 | + tmp = ldq_p(mem_buf); | ||
105 | + } | ||
106 | + length = 8; | ||
107 | + break; | ||
108 | + default: | ||
109 | + g_assert_not_reached(); | ||
110 | + } | ||
111 | + if (n > 0 && n < 32) { | ||
112 | + env->gpr[n] = tmp; | ||
113 | } else if (n == 32) { | ||
114 | - env->pc = ldtul_p(mem_buf); | ||
115 | - return sizeof(target_ulong); | ||
116 | + env->pc = tmp; | ||
117 | } | ||
118 | - return 0; | ||
119 | + | ||
120 | + return length; | ||
121 | } | ||
122 | |||
123 | static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) | ||
124 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) | ||
125 | cs->gdb_num_regs), | ||
126 | "riscv-vector.xml", 0); | ||
127 | } | ||
128 | -#if defined(TARGET_RISCV32) | ||
129 | - gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, | ||
130 | - 1, "riscv-32bit-virtual.xml", 0); | ||
131 | -#elif defined(TARGET_RISCV64) | ||
132 | - gdb_register_coprocessor(cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual, | ||
133 | - 1, "riscv-64bit-virtual.xml", 0); | ||
134 | -#endif | ||
135 | + switch (env->misa_mxl_max) { | ||
136 | + case MXL_RV32: | ||
137 | + gdb_register_coprocessor(cs, riscv_gdb_get_virtual, | ||
138 | + riscv_gdb_set_virtual, | ||
139 | + 1, "riscv-32bit-virtual.xml", 0); | ||
140 | + break; | ||
141 | + case MXL_RV64: | ||
142 | + gdb_register_coprocessor(cs, riscv_gdb_get_virtual, | ||
143 | + riscv_gdb_set_virtual, | ||
144 | + 1, "riscv-64bit-virtual.xml", 0); | ||
145 | + break; | ||
146 | + default: | ||
147 | + g_assert_not_reached(); | ||
148 | + } | ||
149 | |||
150 | gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, | ||
151 | riscv_gen_dynamic_csr_xml(cs, cs->gdb_num_regs), | ||
152 | -- | 63 | -- |
153 | 2.31.1 | 64 | 2.45.1 |
154 | 65 | ||
155 | 66 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Only check the range that has passed the address translation. | 3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr |
4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr | ||
5 | CSRs are part of the disassembly. | ||
4 | 6 | ||
5 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Fixes: ea10325917 ("RISC-V Disassembler") |
8 | Message-id: 20220120122050.41546-19-zhiwei_liu@c-sky.com | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 14 | --- |
11 | target/riscv/vector_helper.c | 4 ++-- | 15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- |
12 | 1 file changed, 2 insertions(+), 2 deletions(-) | 16 | 1 file changed, 64 insertions(+), 1 deletion(-) |
13 | 17 | ||
14 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | 18 | diff --git a/disas/riscv.c b/disas/riscv.c |
15 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/vector_helper.c | 20 | --- a/disas/riscv.c |
17 | +++ b/target/riscv/vector_helper.c | 21 | +++ b/disas/riscv.c |
18 | @@ -XXX,XX +XXX,XX @@ vext_ldff(void *vd, void *v0, target_ulong base, | 22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
19 | cpu_mmu_index(env, false)); | 23 | case 0x0383: return "mibound"; |
20 | if (host) { | 24 | case 0x0384: return "mdbase"; |
21 | #ifdef CONFIG_USER_ONLY | 25 | case 0x0385: return "mdbound"; |
22 | - if (page_check_range(addr, nf << esz, PAGE_READ) < 0) { | 26 | - case 0x03a0: return "pmpcfg3"; |
23 | + if (page_check_range(addr, offset, PAGE_READ) < 0) { | 27 | + case 0x03a0: return "pmpcfg0"; |
24 | vl = i; | 28 | + case 0x03a1: return "pmpcfg1"; |
25 | goto ProbeSuccess; | 29 | + case 0x03a2: return "pmpcfg2"; |
26 | } | 30 | + case 0x03a3: return "pmpcfg3"; |
27 | #else | 31 | + case 0x03a4: return "pmpcfg4"; |
28 | - probe_pages(env, addr, nf << esz, ra, MMU_DATA_LOAD); | 32 | + case 0x03a5: return "pmpcfg5"; |
29 | + probe_pages(env, addr, offset, ra, MMU_DATA_LOAD); | 33 | + case 0x03a6: return "pmpcfg6"; |
30 | #endif | 34 | + case 0x03a7: return "pmpcfg7"; |
31 | } else { | 35 | + case 0x03a8: return "pmpcfg8"; |
32 | vl = i; | 36 | + case 0x03a9: return "pmpcfg9"; |
37 | + case 0x03aa: return "pmpcfg10"; | ||
38 | + case 0x03ab: return "pmpcfg11"; | ||
39 | + case 0x03ac: return "pmpcfg12"; | ||
40 | + case 0x03ad: return "pmpcfg13"; | ||
41 | + case 0x03ae: return "pmpcfg14"; | ||
42 | + case 0x03af: return "pmpcfg15"; | ||
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"; | ||
33 | -- | 101 | -- |
34 | 2.31.1 | 102 | 2.45.1 |
35 | |||
36 | diff view generated by jsdifflib |
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | 1 | From: Yu-Ming Chang <yumin686@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | Current xlen has been used in helper functions and many other places. | 3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side |
4 | The computation of current xlen is not so trivial, so that we should | 4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register |
5 | recompute it as little as possible. | 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. | ||
6 | 7 | ||
7 | Fortunately, xlen only changes in very seldom cases, such as exception, | 8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies |
8 | misa write, mstatus write, cpu reset, migration load. So that we can only | 9 | a register holding a zero value, an illegal instruction exception should be |
9 | recompute xlen in this places and cache it into CPURISCVState. | 10 | raised. |
10 | 11 | ||
11 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | 12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-id: 20220120122050.41546-6-zhiwei_liu@c-sky.com | 14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 16 | --- |
16 | target/riscv/cpu.h | 31 +++++++++++++++++++++++++++++++ | 17 | target/riscv/cpu.h | 4 ++++ |
17 | target/riscv/cpu.c | 1 + | 18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- |
18 | target/riscv/cpu_helper.c | 34 ++-------------------------------- | 19 | target/riscv/op_helper.c | 6 ++--- |
19 | target/riscv/csr.c | 2 ++ | 20 | 3 files changed, 53 insertions(+), 8 deletions(-) |
20 | target/riscv/machine.c | 10 ++++++++++ | ||
21 | 5 files changed, 46 insertions(+), 32 deletions(-) | ||
22 | 21 | ||
23 | 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 |
24 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/riscv/cpu.h | 24 | --- a/target/riscv/cpu.h |
26 | +++ b/target/riscv/cpu.h | 25 | +++ b/target/riscv/cpu.h |
27 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | 26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
28 | uint32_t misa_mxl_max; /* max mxl for this cpu */ | 27 | void riscv_cpu_update_mask(CPURISCVState *env); |
29 | uint32_t misa_ext; /* current extensions */ | 28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
30 | uint32_t misa_ext_mask; /* max ext for this cpu */ | 29 | |
31 | + uint32_t xl; /* current xlen */ | 30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
32 | 31 | + target_ulong *ret_value); | |
33 | /* 128-bit helpers upper part return value */ | 32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
34 | target_ulong retxh; | 33 | target_ulong *ret_value, |
35 | @@ -XXX,XX +XXX,XX @@ static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env) | 34 | target_ulong new_value, target_ulong write_mask); |
36 | } | 35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, |
37 | #endif | 36 | target_ulong new_value, |
38 | 37 | target_ulong write_mask); | |
39 | +#if defined(TARGET_RISCV32) | 38 | |
40 | +#define cpu_recompute_xl(env) ((void)(env), MXL_RV32) | 39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
41 | +#else | 40 | + Int128 *ret_value); |
42 | +static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env) | 41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, |
43 | +{ | 42 | Int128 *ret_value, |
44 | + RISCVMXL xl = env->misa_mxl; | 43 | Int128 new_value, Int128 write_mask); |
45 | +#if !defined(CONFIG_USER_ONLY) | ||
46 | + /* | ||
47 | + * When emulating a 32-bit-only cpu, use RV32. | ||
48 | + * When emulating a 64-bit cpu, and MXL has been reduced to RV32, | ||
49 | + * MSTATUSH doesn't have UXL/SXL, therefore XLEN cannot be widened | ||
50 | + * back to RV64 for lower privs. | ||
51 | + */ | ||
52 | + if (xl != MXL_RV32) { | ||
53 | + switch (env->priv) { | ||
54 | + case PRV_M: | ||
55 | + break; | ||
56 | + case PRV_U: | ||
57 | + xl = get_field(env->mstatus, MSTATUS64_UXL); | ||
58 | + break; | ||
59 | + default: /* PRV_S | PRV_H */ | ||
60 | + xl = get_field(env->mstatus, MSTATUS64_SXL); | ||
61 | + break; | ||
62 | + } | ||
63 | + } | ||
64 | +#endif | ||
65 | + return xl; | ||
66 | +} | ||
67 | +#endif | ||
68 | + | ||
69 | /* | ||
70 | * Encode LMUL to lmul as follows: | ||
71 | * LMUL vlmul lmul | ||
72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/target/riscv/cpu.c | ||
75 | +++ b/target/riscv/cpu.c | ||
76 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | ||
77 | /* mmte is supposed to have pm.current hardwired to 1 */ | ||
78 | env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT); | ||
79 | #endif | ||
80 | + env->xl = riscv_cpu_mxl(env); | ||
81 | cs->exception_index = RISCV_EXCP_NONE; | ||
82 | env->load_res = -1; | ||
83 | set_default_nan_mode(1, &env->fp_status); | ||
84 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/riscv/cpu_helper.c | ||
87 | +++ b/target/riscv/cpu_helper.c | ||
88 | @@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) | ||
89 | #endif | ||
90 | } | ||
91 | |||
92 | -static RISCVMXL cpu_get_xl(CPURISCVState *env) | ||
93 | -{ | ||
94 | -#if defined(TARGET_RISCV32) | ||
95 | - return MXL_RV32; | ||
96 | -#elif defined(CONFIG_USER_ONLY) | ||
97 | - return MXL_RV64; | ||
98 | -#else | ||
99 | - RISCVMXL xl = riscv_cpu_mxl(env); | ||
100 | - | ||
101 | - /* | ||
102 | - * When emulating a 32-bit-only cpu, use RV32. | ||
103 | - * When emulating a 64-bit cpu, and MXL has been reduced to RV32, | ||
104 | - * MSTATUSH doesn't have UXL/SXL, therefore XLEN cannot be widened | ||
105 | - * back to RV64 for lower privs. | ||
106 | - */ | ||
107 | - if (xl != MXL_RV32) { | ||
108 | - switch (env->priv) { | ||
109 | - case PRV_M: | ||
110 | - break; | ||
111 | - case PRV_U: | ||
112 | - xl = get_field(env->mstatus, MSTATUS64_UXL); | ||
113 | - break; | ||
114 | - default: /* PRV_S | PRV_H */ | ||
115 | - xl = get_field(env->mstatus, MSTATUS64_SXL); | ||
116 | - break; | ||
117 | - } | ||
118 | - } | ||
119 | - return xl; | ||
120 | -#endif | ||
121 | -} | ||
122 | - | ||
123 | void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
124 | target_ulong *cs_base, uint32_t *pflags) | ||
125 | { | ||
126 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
127 | } | ||
128 | #endif | ||
129 | |||
130 | - flags = FIELD_DP32(flags, TB_FLAGS, XL, cpu_get_xl(env)); | ||
131 | + flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl); | ||
132 | |||
133 | *pflags = flags; | ||
134 | } | ||
135 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) | ||
136 | } | ||
137 | /* tlb_flush is unnecessary as mode is contained in mmu_idx */ | ||
138 | env->priv = newpriv; | ||
139 | + env->xl = cpu_recompute_xl(env); | ||
140 | |||
141 | /* | ||
142 | * Clear the load reservation - otherwise a reservation placed in one | ||
143 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
144 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
145 | --- a/target/riscv/csr.c | 46 | --- a/target/riscv/csr.c |
146 | +++ b/target/riscv/csr.c | 47 | +++ b/target/riscv/csr.c |
147 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | 48 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
148 | mstatus = set_field(mstatus, MSTATUS64_UXL, xl); | 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, | ||
149 | } | 58 | } |
150 | env->mstatus = mstatus; | 59 | |
151 | + env->xl = cpu_recompute_xl(env); | 60 | /* read / write check */ |
152 | 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, | ||
153 | return RISCV_EXCP_NONE; | 67 | return RISCV_EXCP_NONE; |
154 | } | 68 | } |
155 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno, | 69 | |
156 | /* flush translation cache */ | 70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
157 | tb_flush(env_cpu(env)); | 71 | + target_ulong *ret_value) |
158 | env->misa_ext = val; | 72 | +{ |
159 | + env->xl = riscv_cpu_mxl(env); | 73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); |
74 | + if (ret != RISCV_EXCP_NONE) { | ||
75 | + return ret; | ||
76 | + } | ||
77 | + | ||
78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); | ||
79 | +} | ||
80 | + | ||
81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
82 | target_ulong *ret_value, | ||
83 | target_ulong new_value, target_ulong write_mask) | ||
84 | { | ||
85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); | ||
86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); | ||
87 | if (ret != RISCV_EXCP_NONE) { | ||
88 | return ret; | ||
89 | } | ||
90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, | ||
160 | return RISCV_EXCP_NONE; | 91 | return RISCV_EXCP_NONE; |
161 | } | 92 | } |
162 | 93 | ||
163 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | 94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
164 | index XXXXXXX..XXXXXXX 100644 | 95 | + Int128 *ret_value) |
165 | --- a/target/riscv/machine.c | ||
166 | +++ b/target/riscv/machine.c | ||
167 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_kvmtimer = { | ||
168 | } | ||
169 | }; | ||
170 | |||
171 | +static int riscv_cpu_post_load(void *opaque, int version_id) | ||
172 | +{ | 96 | +{ |
173 | + RISCVCPU *cpu = opaque; | 97 | + RISCVException ret; |
174 | + CPURISCVState *env = &cpu->env; | ||
175 | + | 98 | + |
176 | + env->xl = cpu_recompute_xl(env); | 99 | + ret = riscv_csrrw_check(env, csrno, false); |
177 | + return 0; | 100 | + if (ret != RISCV_EXCP_NONE) { |
101 | + return ret; | ||
102 | + } | ||
103 | + | ||
104 | + if (csr_ops[csrno].read128) { | ||
105 | + return riscv_csrrw_do128(env, csrno, ret_value, | ||
106 | + int128_zero(), int128_zero()); | ||
107 | + } | ||
108 | + | ||
109 | + /* | ||
110 | + * Fall back to 64-bit version for now, if the 128-bit alternative isn't | ||
111 | + * at all defined. | ||
112 | + * Note, some CSRs don't need to extend to MXLEN (64 upper bits non | ||
113 | + * significant), for those, this fallback is correctly handling the | ||
114 | + * accesses | ||
115 | + */ | ||
116 | + target_ulong old_value; | ||
117 | + ret = riscv_csrrw_do64(env, csrno, &old_value, | ||
118 | + (target_ulong)0, | ||
119 | + (target_ulong)0); | ||
120 | + if (ret == RISCV_EXCP_NONE && ret_value) { | ||
121 | + *ret_value = int128_make64(old_value); | ||
122 | + } | ||
123 | + return ret; | ||
178 | +} | 124 | +} |
179 | + | 125 | + |
180 | const VMStateDescription vmstate_riscv_cpu = { | 126 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, |
181 | .name = "cpu", | 127 | Int128 *ret_value, |
182 | .version_id = 3, | 128 | Int128 new_value, Int128 write_mask) |
183 | .minimum_version_id = 3, | 129 | { |
184 | + .post_load = riscv_cpu_post_load, | 130 | RISCVException ret; |
185 | .fields = (VMStateField[]) { | 131 | |
186 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | 132 | - ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask)); |
187 | VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), | 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()); | ||
188 | -- | 161 | -- |
189 | 2.31.1 | 162 | 2.45.1 |
190 | |||
191 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Message-id: 20220120122050.41546-10-zhiwei_liu@c-sky.com | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | ||
9 | target/riscv/csr.c | 3 +++ | ||
10 | 1 file changed, 3 insertions(+) | ||
11 | |||
12 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/riscv/csr.c | ||
15 | +++ b/target/riscv/csr.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static bool check_pm_current_disabled(CPURISCVState *env, int csrno) | ||
17 | int csr_priv = get_field(csrno, 0x300); | ||
18 | int pm_current; | ||
19 | |||
20 | + if (env->debugger) { | ||
21 | + return false; | ||
22 | + } | ||
23 | /* | ||
24 | * If priv lvls differ that means we're accessing csr from higher priv lvl, | ||
25 | * so allow the access | ||
26 | -- | ||
27 | 2.31.1 | ||
28 | |||
29 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Write mask is representing the bits we care about. | ||
4 | |||
5 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20220120122050.41546-11-zhiwei_liu@c-sky.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/op_helper.c | 3 ++- | ||
12 | target/riscv/insn_trans/trans_rvi.c.inc | 12 ++++++++---- | ||
13 | 2 files changed, 10 insertions(+), 5 deletions(-) | ||
14 | |||
15 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/op_helper.c | ||
18 | +++ b/target/riscv/op_helper.c | ||
19 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr) | ||
20 | |||
21 | void helper_csrw(CPURISCVState *env, int csr, target_ulong src) | ||
22 | { | ||
23 | - RISCVException ret = riscv_csrrw(env, csr, NULL, src, -1); | ||
24 | + target_ulong mask = env->xl == MXL_RV32 ? UINT32_MAX : (target_ulong)-1; | ||
25 | + RISCVException ret = riscv_csrrw(env, csr, NULL, src, mask); | ||
26 | |||
27 | if (ret != RISCV_EXCP_NONE) { | ||
28 | riscv_raise_exception(env, ret, GETPC()); | ||
29 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
32 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
33 | @@ -XXX,XX +XXX,XX @@ static bool do_csrrw_i128(DisasContext *ctx, int rd, int rc, | ||
34 | |||
35 | static bool trans_csrrw(DisasContext *ctx, arg_csrrw *a) | ||
36 | { | ||
37 | - if (get_xl(ctx) < MXL_RV128) { | ||
38 | + RISCVMXL xl = get_xl(ctx); | ||
39 | + if (xl < MXL_RV128) { | ||
40 | TCGv src = get_gpr(ctx, a->rs1, EXT_NONE); | ||
41 | |||
42 | /* | ||
43 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrrw(DisasContext *ctx, arg_csrrw *a) | ||
44 | return do_csrw(ctx, a->csr, src); | ||
45 | } | ||
46 | |||
47 | - TCGv mask = tcg_constant_tl(-1); | ||
48 | + TCGv mask = tcg_constant_tl(xl == MXL_RV32 ? UINT32_MAX : | ||
49 | + (target_ulong)-1); | ||
50 | return do_csrrw(ctx, a->rd, a->csr, src, mask); | ||
51 | } else { | ||
52 | TCGv srcl = get_gpr(ctx, a->rs1, EXT_NONE); | ||
53 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrrc(DisasContext *ctx, arg_csrrc *a) | ||
54 | |||
55 | static bool trans_csrrwi(DisasContext *ctx, arg_csrrwi *a) | ||
56 | { | ||
57 | - if (get_xl(ctx) < MXL_RV128) { | ||
58 | + RISCVMXL xl = get_xl(ctx); | ||
59 | + if (xl < MXL_RV128) { | ||
60 | TCGv src = tcg_constant_tl(a->rs1); | ||
61 | |||
62 | /* | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrrwi(DisasContext *ctx, arg_csrrwi *a) | ||
64 | return do_csrw(ctx, a->csr, src); | ||
65 | } | ||
66 | |||
67 | - TCGv mask = tcg_constant_tl(-1); | ||
68 | + TCGv mask = tcg_constant_tl(xl == MXL_RV32 ? UINT32_MAX : | ||
69 | + (target_ulong)-1); | ||
70 | return do_csrrw(ctx, a->rd, a->csr, src, mask); | ||
71 | } else { | ||
72 | TCGv src = tcg_constant_tl(a->rs1); | ||
73 | -- | ||
74 | 2.31.1 | ||
75 | |||
76 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Replace the array of pm_mask/pm_base with scalar variables. | ||
4 | Remove the cached array value in DisasContext. | ||
5 | |||
6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-id: 20220120122050.41546-13-zhiwei_liu@c-sky.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/translate.c | 32 ++++++++------------------------ | ||
13 | 1 file changed, 8 insertions(+), 24 deletions(-) | ||
14 | |||
15 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/translate.c | ||
18 | +++ b/target/riscv/translate.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ | ||
20 | static TCGv load_res; | ||
21 | static TCGv load_val; | ||
22 | /* globals for PM CSRs */ | ||
23 | -static TCGv pm_mask[4]; | ||
24 | -static TCGv pm_base[4]; | ||
25 | +static TCGv pm_mask; | ||
26 | +static TCGv pm_base; | ||
27 | |||
28 | #include "exec/gen-icount.h" | ||
29 | |||
30 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
31 | TCGv temp[4]; | ||
32 | /* PointerMasking extension */ | ||
33 | bool pm_enabled; | ||
34 | - TCGv pm_mask; | ||
35 | - TCGv pm_base; | ||
36 | } DisasContext; | ||
37 | |||
38 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
39 | @@ -XXX,XX +XXX,XX @@ static TCGv gen_pm_adjust_address(DisasContext *s, TCGv src) | ||
40 | return src; | ||
41 | } else { | ||
42 | temp = temp_new(s); | ||
43 | - tcg_gen_andc_tl(temp, src, s->pm_mask); | ||
44 | - tcg_gen_or_tl(temp, temp, s->pm_base); | ||
45 | + tcg_gen_andc_tl(temp, src, pm_mask); | ||
46 | + tcg_gen_or_tl(temp, temp, pm_base); | ||
47 | return temp; | ||
48 | } | ||
49 | } | ||
50 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
51 | ctx->ntemp = 0; | ||
52 | memset(ctx->temp, 0, sizeof(ctx->temp)); | ||
53 | ctx->pm_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_ENABLED); | ||
54 | - int priv = tb_flags & TB_FLAGS_PRIV_MMU_MASK; | ||
55 | - ctx->pm_mask = pm_mask[priv]; | ||
56 | - ctx->pm_base = pm_base[priv]; | ||
57 | - | ||
58 | ctx->zero = tcg_constant_tl(0); | ||
59 | } | ||
60 | |||
61 | @@ -XXX,XX +XXX,XX @@ void riscv_translate_init(void) | ||
62 | "load_res"); | ||
63 | load_val = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, load_val), | ||
64 | "load_val"); | ||
65 | -#ifndef CONFIG_USER_ONLY | ||
66 | /* Assign PM CSRs to tcg globals */ | ||
67 | - pm_mask[PRV_U] = | ||
68 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, upmmask), "upmmask"); | ||
69 | - pm_base[PRV_U] = | ||
70 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, upmbase), "upmbase"); | ||
71 | - pm_mask[PRV_S] = | ||
72 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, spmmask), "spmmask"); | ||
73 | - pm_base[PRV_S] = | ||
74 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, spmbase), "spmbase"); | ||
75 | - pm_mask[PRV_M] = | ||
76 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, mpmmask), "mpmmask"); | ||
77 | - pm_base[PRV_M] = | ||
78 | - tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, mpmbase), "mpmbase"); | ||
79 | -#endif | ||
80 | + pm_mask = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, cur_pmmask), | ||
81 | + "pmmask"); | ||
82 | + pm_base = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, cur_pmbase), | ||
83 | + "pmbase"); | ||
84 | } | ||
85 | -- | ||
86 | 2.31.1 | ||
87 | |||
88 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Message-id: 20220120122050.41546-17-zhiwei_liu@c-sky.com | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | ||
9 | target/riscv/cpu.h | 5 +++++ | ||
10 | target/riscv/vector_helper.c | 7 +++++-- | ||
11 | 2 files changed, 10 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/cpu.h | ||
16 | +++ b/target/riscv/cpu.h | ||
17 | @@ -XXX,XX +XXX,XX @@ static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env) | ||
18 | } | ||
19 | #endif | ||
20 | |||
21 | +static inline int riscv_cpu_xlen(CPURISCVState *env) | ||
22 | +{ | ||
23 | + return 16 << env->xl; | ||
24 | +} | ||
25 | + | ||
26 | /* | ||
27 | * Encode LMUL to lmul as follows: | ||
28 | * LMUL vlmul lmul | ||
29 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/vector_helper.c | ||
32 | +++ b/target/riscv/vector_helper.c | ||
33 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | ||
34 | uint64_t lmul = FIELD_EX64(s2, VTYPE, VLMUL); | ||
35 | uint16_t sew = 8 << FIELD_EX64(s2, VTYPE, VSEW); | ||
36 | uint8_t ediv = FIELD_EX64(s2, VTYPE, VEDIV); | ||
37 | - bool vill = FIELD_EX64(s2, VTYPE, VILL); | ||
38 | - target_ulong reserved = FIELD_EX64(s2, VTYPE, RESERVED); | ||
39 | + int xlen = riscv_cpu_xlen(env); | ||
40 | + bool vill = (s2 >> (xlen - 1)) & 0x1; | ||
41 | + target_ulong reserved = s2 & | ||
42 | + MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT, | ||
43 | + xlen - 1 - R_VTYPE_RESERVED_SHIFT); | ||
44 | |||
45 | if (lmul & 4) { | ||
46 | /* Fractional LMUL. */ | ||
47 | -- | ||
48 | 2.31.1 | ||
49 | |||
50 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
2 | 1 | ||
3 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
4 | Acked-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Message-id: 20220120122050.41546-18-zhiwei_liu@c-sky.com | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | ||
9 | target/riscv/cpu.h | 1 - | ||
10 | 1 file changed, 1 deletion(-) | ||
11 | |||
12 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/riscv/cpu.h | ||
15 | +++ b/target/riscv/cpu.h | ||
16 | @@ -XXX,XX +XXX,XX @@ FIELD(VTYPE, VTA, 6, 1) | ||
17 | FIELD(VTYPE, VMA, 7, 1) | ||
18 | FIELD(VTYPE, VEDIV, 8, 2) | ||
19 | FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11) | ||
20 | -FIELD(VTYPE, VILL, sizeof(target_ulong) * 8 - 1, 1) | ||
21 | |||
22 | struct CPURISCVState { | ||
23 | target_ulong gpr[32]; | ||
24 | -- | ||
25 | 2.31.1 | ||
26 | |||
27 | diff view generated by jsdifflib |