1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: | 1 | From: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700) | 3 | The following changes since commit 99d6b11b5b44d7dd64f4cb1973184e40a4a174f8: |
4 | |||
5 | Merge tag 'pull-target-arm-20220922' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-09-26 13:38:26 -0400) | ||
4 | 6 | ||
5 | are available in the Git repository at: | 7 | are available in the Git repository at: |
6 | 8 | ||
7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 | 9 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20220927 |
8 | 10 | ||
9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: | 11 | for you to fetch changes up to a3ab69f9f6c000481c439923d16416b8941d5b37: |
10 | 12 | ||
11 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000) | 13 | target/riscv: rvv-1.0: vf[w]redsum distinguish between ordered/unordered (2022-09-27 11:23:57 +1000) |
12 | 14 | ||
13 | ---------------------------------------------------------------- | 15 | ---------------------------------------------------------------- |
14 | RISC-V PR for 9.1 | 16 | Second RISC-V PR for QEMU 7.2 |
15 | 17 | ||
16 | * APLICs add child earlier than realize | 18 | * Fixup typos and register addresses for Ibex SPI |
17 | * Fix exposure of Zkr | 19 | * Cleanup the RISC-V virt machine documentation |
18 | * Raise exceptions on wrs.nto | 20 | * Remove the sideleg and sedeleg CSR macros |
19 | * Implement SBI debug console (DBCN) calls for KVM | 21 | * Fix the CSR check for cycle{h}, instret{h}, time{h}, hpmcounter3-31{h} |
20 | * Support 64-bit addresses for initrd | 22 | * Remove fixed numbering from GDB xml feature files |
21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 | 23 | * Allow setting the resetvec for the OpenTitan machine |
22 | * Tolerate KVM disable ext errors | 24 | * Check the correct exception cause in vector GDB stub |
23 | * Set tval in breakpoints | 25 | * Fix inheritance of SiFiveEState |
24 | * Add support for Zve32x extension | 26 | * Improvements to the RISC-V debugger spec |
25 | * Add support for Zve64x extension | 27 | * Simplify some vector code |
26 | * Relax vector register check in RISCV gdbstub | ||
27 | * Fix the element agnostic Vector function problem | ||
28 | * Fix Zvkb extension config | ||
29 | * Implement dynamic establishment of custom decoder | ||
30 | * Add th.sxstatus CSR emulation | ||
31 | * Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
32 | * Check single width operator for vector fp widen instructions | ||
33 | * Check single width operator for vfncvt.rod.f.f.w | ||
34 | * Remove redudant SEW checking for vector fp narrow/widen instructions | ||
35 | * Prioritize pmp errors in raise_mmu_exception() | ||
36 | * Do not set mtval2 for non guest-page faults | ||
37 | * Remove experimental prefix from "B" extension | ||
38 | * Fixup CBO extension register calculation | ||
39 | * Fix the hart bit setting of AIA | ||
40 | * Fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
41 | * Decode all of the pmpcfg and pmpaddr CSRs | ||
42 | * Raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
43 | 28 | ||
44 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
45 | Alexei Filippov (1): | 30 | Alex Bennée (1): |
46 | target/riscv: do not set mtval2 for non guest-page faults | 31 | docs/system: clean up code escape for riscv virt platform |
47 | 32 | ||
48 | Alistair Francis (2): | 33 | Alistair Francis (3): |
49 | target/riscv: rvzicbo: Fixup CBO extension register calculation | 34 | target/riscv: Set the CPU resetvec directly |
50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs | 35 | hw/riscv: opentitan: Fixup resetvec |
36 | hw/riscv: opentitan: Expose the resetvec as a SoC property | ||
51 | 37 | ||
52 | Andrew Jones (2): | 38 | Andrew Burgess (2): |
53 | target/riscv/kvm: Fix exposure of Zkr | 39 | target/riscv: remove fflags, frm, and fcsr from riscv-*-fpu.xml |
54 | target/riscv: Raise exceptions on wrs.nto | 40 | target/riscv: remove fixed numbering from GDB xml feature files |
55 | 41 | ||
56 | Cheng Yang (1): | 42 | Bernhard Beschow (1): |
57 | hw/riscv/boot.c: Support 64-bit address for initrd | 43 | hw/riscv/sifive_e: Fix inheritance of SiFiveEState |
58 | 44 | ||
59 | Christoph Müllner (1): | 45 | Frank Chang (9): |
60 | riscv: thead: Add th.sxstatus CSR emulation | 46 | target/riscv: Check the correct exception cause in vector GDB stub |
47 | target/riscv: debug: Determine the trigger type from tdata1.type | ||
48 | target/riscv: debug: Introduce build_tdata1() to build tdata1 register content | ||
49 | target/riscv: debug: Introduce tdata1, tdata2, and tdata3 CSRs | ||
50 | target/riscv: debug: Restrict the range of tselect value can be written | ||
51 | target/riscv: debug: Introduce tinfo CSR | ||
52 | target/riscv: debug: Create common trigger actions function | ||
53 | target/riscv: debug: Check VU/VS modes for type 2 trigger | ||
54 | target/riscv: debug: Add initial support of type 6 trigger | ||
61 | 55 | ||
62 | Clément Léger (1): | 56 | Rahul Pathak (1): |
63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 | 57 | target/riscv: Remove sideleg and sedeleg |
64 | 58 | ||
65 | Daniel Henrique Barboza (6): | 59 | Weiwei Li (1): |
66 | target/riscv/kvm: implement SBI debug console (DBCN) calls | 60 | target/riscv: fix csr check for cycle{h}, instret{h}, time{h}, hpmcounter3-31{h} |
67 | target/riscv/kvm: tolerate KVM disable ext errors | ||
68 | target/riscv/debug: set tval=pc in breakpoint exceptions | ||
69 | trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint | ||
70 | target/riscv: prioritize pmp errors in raise_mmu_exception() | ||
71 | riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
72 | 61 | ||
73 | Huang Tao (2): | 62 | Wilfred Mallawa (2): |
74 | target/riscv: Fix the element agnostic function problem | 63 | hw/ssi: ibex_spi: fixup typos in ibex_spi_host |
75 | target/riscv: Implement dynamic establishment of custom decoder | 64 | hw/ssi: ibex_spi: update reg addr |
76 | 65 | ||
77 | Jason Chien (3): | 66 | Yang Liu (2): |
78 | target/riscv: Add support for Zve32x extension | 67 | target/riscv: rvv-1.0: Simplify vfwredsum code |
79 | target/riscv: Add support for Zve64x extension | 68 | target/riscv: rvv-1.0: vf[w]redsum distinguish between ordered/unordered |
80 | target/riscv: Relax vector register check in RISCV gdbstub | ||
81 | 69 | ||
82 | Max Chou (4): | 70 | docs/system/riscv/virt.rst | 13 +- |
83 | target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | 71 | include/hw/riscv/opentitan.h | 2 + |
84 | target/riscv: rvv: Check single width operator for vector fp widen instructions | 72 | include/hw/riscv/sifive_e.h | 3 +- |
85 | target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w | 73 | target/riscv/cpu.h | 9 +- |
86 | target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions | 74 | target/riscv/cpu_bits.h | 3 +- |
87 | 75 | target/riscv/debug.h | 55 ++-- | |
88 | Rob Bradford (1): | 76 | target/riscv/helper.h | 15 +- |
89 | target/riscv: Remove experimental prefix from "B" extension | 77 | target/riscv/insn32.decode | 6 +- |
90 | 78 | disas/riscv.c | 2 - | |
91 | Yangyu Chen (1): | 79 | hw/riscv/opentitan.c | 8 +- |
92 | target/riscv/cpu.c: fix Zvkb extension config | 80 | hw/ssi/ibex_spi_host.c | 8 +- |
93 | 81 | target/riscv/cpu.c | 13 +- | |
94 | Yong-Xuan Wang (1): | 82 | target/riscv/csr.c | 23 +- |
95 | target/riscv/kvm.c: Fix the hart bit setting of AIA | 83 | target/riscv/debug.c | 484 +++++++++++++++++++++++++------- |
96 | 84 | target/riscv/gdbstub.c | 36 +-- | |
97 | Yu-Ming Chang (1): | 85 | target/riscv/machine.c | 26 +- |
98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR | 86 | target/riscv/vector_helper.c | 69 ++--- |
99 | 87 | target/riscv/insn_trans/trans_rvv.c.inc | 6 +- | |
100 | yang.zhang (1): | 88 | gdb-xml/riscv-32bit-cpu.xml | 6 +- |
101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize | 89 | gdb-xml/riscv-32bit-fpu.xml | 10 +- |
102 | 90 | gdb-xml/riscv-64bit-cpu.xml | 6 +- | |
103 | MAINTAINERS | 1 + | 91 | gdb-xml/riscv-64bit-fpu.xml | 10 +- |
104 | target/riscv/cpu.h | 11 ++ | 92 | 22 files changed, 531 insertions(+), 282 deletions(-) |
105 | target/riscv/cpu_bits.h | 2 +- | ||
106 | target/riscv/cpu_cfg.h | 2 + | ||
107 | target/riscv/helper.h | 1 + | ||
108 | target/riscv/sbi_ecall_interface.h | 17 +++ | ||
109 | target/riscv/tcg/tcg-cpu.h | 15 +++ | ||
110 | disas/riscv.c | 65 +++++++++- | ||
111 | hw/intc/riscv_aplic.c | 8 +- | ||
112 | hw/riscv/boot.c | 4 +- | ||
113 | target/riscv/cpu.c | 10 +- | ||
114 | target/riscv/cpu_helper.c | 37 +++--- | ||
115 | target/riscv/csr.c | 71 +++++++++-- | ||
116 | target/riscv/debug.c | 3 + | ||
117 | target/riscv/gdbstub.c | 8 +- | ||
118 | target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++- | ||
119 | target/riscv/op_helper.c | 17 ++- | ||
120 | target/riscv/tcg/tcg-cpu.c | 50 +++++--- | ||
121 | target/riscv/th_csr.c | 79 +++++++++++++ | ||
122 | target/riscv/translate.c | 31 +++-- | ||
123 | target/riscv/vector_internals.c | 22 ++++ | ||
124 | target/riscv/insn_trans/trans_privileged.c.inc | 2 + | ||
125 | target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++--- | ||
126 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++-- | ||
127 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++- | ||
128 | target/riscv/meson.build | 1 + | ||
129 | 26 files changed, 596 insertions(+), 109 deletions(-) | ||
130 | create mode 100644 target/riscv/th_csr.c | ||
131 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair23@gmail.com> | 1 | From: Wilfred Mallawa <wilfred.mallawa@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr | 3 | This patch fixes up minor typos in ibex_spi_host |
4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr | ||
5 | CSRs are part of the disassembly. | ||
6 | 4 | ||
7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> | 5 | Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> |
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Fixes: ea10325917 ("RISC-V Disassembler") | 7 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Message-Id: <20220823061201.132342-2-wilfred.mallawa@opensource.wdc.com> |
11 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 10 | --- |
15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- | 11 | hw/ssi/ibex_spi_host.c | 6 +++--- |
16 | 1 file changed, 64 insertions(+), 1 deletion(-) | 12 | 1 file changed, 3 insertions(+), 3 deletions(-) |
17 | 13 | ||
18 | diff --git a/disas/riscv.c b/disas/riscv.c | 14 | diff --git a/hw/ssi/ibex_spi_host.c b/hw/ssi/ibex_spi_host.c |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/disas/riscv.c | 16 | --- a/hw/ssi/ibex_spi_host.c |
21 | +++ b/disas/riscv.c | 17 | +++ b/hw/ssi/ibex_spi_host.c |
22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | 18 | @@ -XXX,XX +XXX,XX @@ static void ibex_spi_host_irq(IbexSPIHostState *s) |
23 | case 0x0383: return "mibound"; | 19 | & R_INTR_STATE_SPI_EVENT_MASK; |
24 | case 0x0384: return "mdbase"; | 20 | int err_irq = 0, event_irq = 0; |
25 | case 0x0385: return "mdbound"; | 21 | |
26 | - case 0x03a0: return "pmpcfg3"; | 22 | - /* Error IRQ enabled and Error IRQ Cleared*/ |
27 | + case 0x03a0: return "pmpcfg0"; | 23 | + /* Error IRQ enabled and Error IRQ Cleared */ |
28 | + case 0x03a1: return "pmpcfg1"; | 24 | if (error_en && !err_pending) { |
29 | + case 0x03a2: return "pmpcfg2"; | 25 | /* Event enabled, Interrupt Test Error */ |
30 | + case 0x03a3: return "pmpcfg3"; | 26 | if (s->regs[IBEX_SPI_HOST_INTR_TEST] & R_INTR_TEST_ERROR_MASK) { |
31 | + case 0x03a4: return "pmpcfg4"; | 27 | @@ -XXX,XX +XXX,XX @@ static void ibex_spi_host_write(void *opaque, hwaddr addr, |
32 | + case 0x03a5: return "pmpcfg5"; | 28 | case IBEX_SPI_HOST_TXDATA: |
33 | + case 0x03a6: return "pmpcfg6"; | 29 | /* |
34 | + case 0x03a7: return "pmpcfg7"; | 30 | * This is a hardware `feature` where |
35 | + case 0x03a8: return "pmpcfg8"; | 31 | - * the first word written TXDATA after init is omitted entirely |
36 | + case 0x03a9: return "pmpcfg9"; | 32 | + * the first word written to TXDATA after init is omitted entirely |
37 | + case 0x03aa: return "pmpcfg10"; | 33 | */ |
38 | + case 0x03ab: return "pmpcfg11"; | 34 | if (s->init_status) { |
39 | + case 0x03ac: return "pmpcfg12"; | 35 | s->init_status = false; |
40 | + case 0x03ad: return "pmpcfg13"; | 36 | @@ -XXX,XX +XXX,XX @@ static void ibex_spi_host_write(void *opaque, hwaddr addr, |
41 | + case 0x03ae: return "pmpcfg14"; | 37 | break; |
42 | + case 0x03af: return "pmpcfg15"; | 38 | case IBEX_SPI_HOST_ERROR_STATUS: |
43 | case 0x03b0: return "pmpaddr0"; | 39 | /* |
44 | case 0x03b1: return "pmpaddr1"; | 40 | - * Indicates that any errors that have occurred. |
45 | case 0x03b2: return "pmpaddr2"; | 41 | + * Indicates any errors that have occurred. |
46 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | 42 | * When an error occurs, the corresponding bit must be cleared |
47 | case 0x03bd: return "pmpaddr13"; | 43 | * here before issuing any further commands |
48 | case 0x03be: return "pmpaddr14"; | 44 | */ |
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"; | ||
101 | -- | 45 | -- |
102 | 2.45.1 | 46 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Yangyu Chen <cyy@cyyself.name> | 1 | From: Wilfred Mallawa <wilfred.mallawa@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | This code has a typo that writes zvkb to zvkg, causing users can't | 3 | Updates the `EVENT_ENABLE` register to offset `0x34` as per |
4 | enable zvkb through the config. This patch gets this fixed. | 4 | OpenTitan spec [1]. |
5 | 5 | ||
6 | Signed-off-by: Yangyu Chen <cyy@cyyself.name> | 6 | [1] https://docs.opentitan.org/hw/ip/spi_host/doc/#Reg_event_enable |
7 | Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions") | 7 | |
8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 8 | Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Reviewed-by: Max Chou <max.chou@sifive.com> | 10 | Message-Id: <20220823061201.132342-5-wilfred.mallawa@opensource.wdc.com> |
11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> | ||
12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 12 | --- |
16 | target/riscv/cpu.c | 2 +- | 13 | hw/ssi/ibex_spi_host.c | 2 +- |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
18 | 15 | ||
19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 16 | diff --git a/hw/ssi/ibex_spi_host.c b/hw/ssi/ibex_spi_host.c |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu.c | 18 | --- a/hw/ssi/ibex_spi_host.c |
22 | +++ b/target/riscv/cpu.c | 19 | +++ b/hw/ssi/ibex_spi_host.c |
23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 20 | @@ -XXX,XX +XXX,XX @@ REG32(ERROR_STATUS, 0x30) |
24 | /* Vector cryptography extensions */ | 21 | FIELD(ERROR_STATUS, CMDINVAL, 3, 1) |
25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), | 22 | FIELD(ERROR_STATUS, CSIDINVAL, 4, 1) |
26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), | 23 | FIELD(ERROR_STATUS, ACCESSINVAL, 5, 1) |
27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), | 24 | -REG32(EVENT_ENABLE, 0x30) |
28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), | 25 | +REG32(EVENT_ENABLE, 0x34) |
29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), | 26 | FIELD(EVENT_ENABLE, RXFULL, 0, 1) |
30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), | 27 | FIELD(EVENT_ENABLE, TXEMPTY, 1, 1) |
31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), | 28 | FIELD(EVENT_ENABLE, RXWM, 2, 1) |
32 | -- | 29 | -- |
33 | 2.45.1 | 30 | 2.37.3 |
34 | |||
35 | diff view generated by jsdifflib |
1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | In AIA spec, each hart (or each hart within a group) has a unique hart | 3 | The example code is rendered slightly mangled due to missing code |
4 | number to locate the memory pages of interrupt files in the address | 4 | block. Properly escape the code block and add shell prompt and qemu to |
5 | space. The number of bits required to represent any hart number is equal | 5 | fit in with the other examples on the page. |
6 | to ceil(log2(hmax + 1)), where hmax is the largest hart number among | ||
7 | groups. | ||
8 | 6 | ||
9 | However, if the largest hart number among groups is a power of 2, QEMU | 7 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient | 9 | Message-Id: <20220905163939.1599368-1-alex.bennee@linaro.org> |
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> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 11 | --- |
26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- | 12 | docs/system/riscv/virt.rst | 13 +++++++++---- |
27 | 1 file changed, 8 insertions(+), 1 deletion(-) | 13 | 1 file changed, 9 insertions(+), 4 deletions(-) |
28 | 14 | ||
29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 15 | diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst |
30 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/riscv/kvm/kvm-cpu.c | 17 | --- a/docs/system/riscv/virt.rst |
32 | +++ b/target/riscv/kvm/kvm-cpu.c | 18 | +++ b/docs/system/riscv/virt.rst |
33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | 19 | @@ -XXX,XX +XXX,XX @@ Enabling TPM |
34 | } | 20 | |
35 | } | 21 | A TPM device can be connected to the virt board by following the steps below. |
36 | 22 | ||
37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; | 23 | -First launch the TPM emulator |
24 | +First launch the TPM emulator: | ||
25 | |||
26 | - swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \ | ||
27 | +.. code-block:: bash | ||
38 | + | 28 | + |
39 | + if (max_hart_per_socket > 1) { | 29 | + $ swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \ |
40 | + max_hart_per_socket--; | 30 | --ctrl type=unixio,path=swtpm-sock |
41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; | 31 | |
42 | + } else { | 32 | -Then launch QEMU with: |
43 | + hart_bits = 0; | 33 | +Then launch QEMU with some additional arguments to link a TPM device to the backend: |
44 | + } | ||
45 | + | 34 | + |
46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | 35 | +.. code-block:: bash |
47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, | 36 | |
48 | &hart_bits, true, NULL); | 37 | - ... |
38 | + $ qemu-system-riscv64 \ | ||
39 | + ... other args .... \ | ||
40 | -chardev socket,id=chrtpm,path=swtpm-sock \ | ||
41 | -tpmdev emulator,id=tpm0,chardev=chrtpm \ | ||
42 | -device tpm-tis-device,tpmdev=tpm0 | ||
49 | -- | 43 | -- |
50 | 2.45.1 | 44 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Clément Léger <cleger@rivosinc.com> | 1 | From: Rahul Pathak <rpathak@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The current semihost exception number (16) is a reserved number (range | 3 | sideleg and sedeleg csrs are not part of riscv isa spec |
4 | [16-17]). The upcoming double trap specification uses that number for | 4 | anymore, these csrs were part of N extension which |
5 | the double trap exception. Since the privileged spec (Table 22) defines | 5 | is removed from the riscv isa specification. |
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 | 6 | ||
10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> | 7 | These commits removed all traces of these csrs from |
8 | riscv spec (https://github.com/riscv/riscv-isa-manual) - | ||
11 | 9 | ||
10 | commit f8d27f805b65 ("Remove or downgrade more references to N extension (#674)") | ||
11 | commit b6cade07034d ("Remove N extension chapter for now") | ||
12 | |||
13 | Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> | ||
14 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com> | 16 | Message-Id: <20220824145255.400040-1-rpathak@ventanamicro.com> |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 18 | --- |
16 | target/riscv/cpu_bits.h | 2 +- | 19 | target/riscv/cpu_bits.h | 2 -- |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | 20 | disas/riscv.c | 2 -- |
21 | 2 files changed, 4 deletions(-) | ||
18 | 22 | ||
19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | 23 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
20 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu_bits.h | 25 | --- a/target/riscv/cpu_bits.h |
22 | +++ b/target/riscv/cpu_bits.h | 26 | +++ b/target/riscv/cpu_bits.h |
23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | 27 | @@ -XXX,XX +XXX,XX @@ |
24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ | 28 | |
25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ | 29 | /* Supervisor Trap Setup */ |
26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ | 30 | #define CSR_SSTATUS 0x100 |
27 | - RISCV_EXCP_SEMIHOST = 0x10, | 31 | -#define CSR_SEDELEG 0x102 |
28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, | 32 | -#define CSR_SIDELEG 0x103 |
29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, | 33 | #define CSR_SIE 0x104 |
30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, | 34 | #define CSR_STVEC 0x105 |
31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, | 35 | #define CSR_SCOUNTEREN 0x106 |
32 | + RISCV_EXCP_SEMIHOST = 0x3f, | 36 | diff --git a/disas/riscv.c b/disas/riscv.c |
33 | } RISCVException; | 37 | index XXXXXXX..XXXXXXX 100644 |
34 | 38 | --- a/disas/riscv.c | |
35 | #define RISCV_EXCP_INT_FLAG 0x80000000 | 39 | +++ b/disas/riscv.c |
40 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
41 | case 0x0043: return "utval"; | ||
42 | case 0x0044: return "uip"; | ||
43 | case 0x0100: return "sstatus"; | ||
44 | - case 0x0102: return "sedeleg"; | ||
45 | - case 0x0103: return "sideleg"; | ||
46 | case 0x0104: return "sie"; | ||
47 | case 0x0105: return "stvec"; | ||
48 | case 0x0106: return "scounteren"; | ||
36 | -- | 49 | -- |
37 | 2.45.1 | 50 | 2.37.3 |
38 | |||
39 | diff view generated by jsdifflib |
1 | From: Jason Chien <jason.chien@sifive.com> | 1 | From: Weiwei Li <liweiwei@iscas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | Add support for Zve32x extension and replace some checks for Zve32f with | 3 | - modify check for mcounteren to work in all less-privilege mode |
4 | Zve32x, since Zve32f depends on Zve32x. | 4 | - modify check for scounteren to work only when S mode is enabled |
5 | - distinguish the exception type raised by check for scounteren between U | ||
6 | and VU mode | ||
5 | 7 | ||
6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | 8 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> |
7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 9 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> |
8 | Reviewed-by: Max Chou <max.chou@sifive.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 11 | Message-Id: <20220817083756.12471-1-liweiwei@iscas.ac.cn> |
10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 13 | --- |
13 | target/riscv/cpu_cfg.h | 1 + | 14 | target/riscv/csr.c | 13 +++++++++---- |
14 | target/riscv/cpu.c | 2 ++ | 15 | 1 file changed, 9 insertions(+), 4 deletions(-) |
15 | target/riscv/cpu_helper.c | 2 +- | ||
16 | target/riscv/csr.c | 2 +- | ||
17 | target/riscv/tcg/tcg-cpu.c | 16 ++++++++-------- | ||
18 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- | ||
19 | 6 files changed, 15 insertions(+), 12 deletions(-) | ||
20 | 16 | ||
21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu_cfg.h | ||
24 | +++ b/target/riscv/cpu_cfg.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
26 | bool ext_zhinx; | ||
27 | bool ext_zhinxmin; | ||
28 | bool ext_zve32f; | ||
29 | + bool ext_zve32x; | ||
30 | bool ext_zve64f; | ||
31 | bool ext_zve64d; | ||
32 | bool ext_zvbb; | ||
33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/riscv/cpu.c | ||
36 | +++ b/target/riscv/cpu.c | ||
37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), | ||
39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), | ||
40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | ||
41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), | ||
42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | ||
44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), | ||
45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | ||
47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | ||
48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | ||
49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
53 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/cpu_helper.c | ||
56 | +++ b/target/riscv/cpu_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
58 | *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; | ||
59 | *cs_base = 0; | ||
60 | |||
61 | - if (cpu->cfg.ext_zve32f) { | ||
62 | + if (cpu->cfg.ext_zve32x) { | ||
63 | /* | ||
64 | * If env->vl equals to VLMAX, we can use generic vector operation | ||
65 | * expanders (GVEC) to accerlate the vector operations. | ||
66 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 17 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
67 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/target/riscv/csr.c | 19 | --- a/target/riscv/csr.c |
69 | +++ b/target/riscv/csr.c | 20 | +++ b/target/riscv/csr.c |
70 | @@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno) | 21 | @@ -XXX,XX +XXX,XX @@ static RISCVException ctr(CPURISCVState *env, int csrno) |
71 | 22 | ||
72 | static RISCVException vs(CPURISCVState *env, int csrno) | 23 | skip_ext_pmu_check: |
73 | { | 24 | |
74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { | 25 | - if (((env->priv == PRV_S) && (!get_field(env->mcounteren, ctr_mask))) || |
75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { | 26 | - ((env->priv == PRV_U) && (!get_field(env->scounteren, ctr_mask)))) { |
76 | #if !defined(CONFIG_USER_ONLY) | 27 | + if (env->priv < PRV_M && !get_field(env->mcounteren, ctr_mask)) { |
77 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { | 28 | return RISCV_EXCP_ILLEGAL_INST; |
78 | return RISCV_EXCP_ILLEGAL_INST; | ||
79 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/target/riscv/tcg/tcg-cpu.c | ||
82 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
83 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
84 | return; | ||
85 | } | 29 | } |
86 | 30 | ||
87 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { | 31 | if (riscv_cpu_virt_enabled(env)) { |
88 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | 32 | - if (!get_field(env->hcounteren, ctr_mask) && |
89 | - return; | 33 | - get_field(env->mcounteren, ctr_mask)) { |
90 | + /* The Zve32f extension depends on the Zve32x extension */ | 34 | + if (!get_field(env->hcounteren, ctr_mask) || |
91 | + if (cpu->cfg.ext_zve32f) { | 35 | + (env->priv == PRV_U && !get_field(env->scounteren, ctr_mask))) { |
92 | + if (!riscv_has_ext(env, RVF)) { | 36 | return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; |
93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | 37 | } |
94 | + return; | ||
95 | + } | ||
96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
97 | } | 38 | } |
98 | 39 | + | |
99 | if (cpu->cfg.ext_zvfh) { | 40 | + if (riscv_has_ext(env, RVS) && env->priv == PRV_U && |
100 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 41 | + !get_field(env->scounteren, ctr_mask)) { |
101 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true); | 42 | + return RISCV_EXCP_ILLEGAL_INST; |
102 | } | 43 | + } |
103 | 44 | + | |
104 | - /* | 45 | #endif |
105 | - * In principle Zve*x would also suffice here, were they supported | 46 | return RISCV_EXCP_NONE; |
106 | - * in qemu | 47 | } |
107 | - */ | ||
108 | if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg || | ||
109 | cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || | ||
110 | - cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
111 | + cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) { | ||
112 | error_setg(errp, | ||
113 | "Vector crypto extensions require V or Zve* extensions"); | ||
114 | return; | ||
115 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
118 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
120 | { | ||
121 | TCGv s1, dst; | ||
122 | |||
123 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
124 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
125 | return false; | ||
126 | } | ||
127 | |||
128 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) | ||
129 | { | ||
130 | TCGv dst; | ||
131 | |||
132 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
133 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
134 | return false; | ||
135 | } | ||
136 | |||
137 | -- | 48 | -- |
138 | 2.45.1 | 49 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Jason Chien <jason.chien@sifive.com> | 1 | From: Andrew Burgess <aburgess@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In current implementation, the gdbstub allows reading vector registers | 3 | While testing some changes to GDB's handling for the RISC-V registers |
4 | only if V extension is supported. However, all vector extensions and | 4 | fcsr, fflags, and frm, I spotted that QEMU includes these registers |
5 | vector crypto extensions have the vector registers and they all depend | 5 | twice in the target description it sends to GDB, once in the fpu |
6 | on Zve32x. The gdbstub should check for Zve32x instead. | 6 | feature, and once in the csr feature. |
7 | 7 | ||
8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | 8 | Right now things basically work OK, QEMU maps these registers onto two |
9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 9 | different register numbers, e.g. fcsr maps to both 68 and 73, and GDB |
10 | Reviewed-by: Max Chou <max.chou@sifive.com> | 10 | can use either of these to access the register. |
11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> | 11 | |
12 | However, GDB's target descriptions don't really work this way, each | ||
13 | register should appear just once in a target description, mapping the | ||
14 | register name onto the number GDB should use when accessing the | ||
15 | register on the target. Duplicate register names actually result in | ||
16 | duplicate registers on the GDB side, however, as the registers have | ||
17 | the same name, the user can only access one of these registers. | ||
18 | |||
19 | Currently GDB has a hack in place, specifically for RISC-V, to spot | ||
20 | the duplicate copies of these three registers, and hide them from the | ||
21 | user, ensuring the user only ever sees a single copy of each. | ||
22 | |||
23 | In this commit I propose fixing this issue on the QEMU side, and in | ||
24 | the process, simplify the fpu register handling a little. | ||
25 | |||
26 | I think we should, remove fflags, frm, and fcsr from the two (32-bit | ||
27 | and 64-bit) fpu feature xml files. These files will only contain the | ||
28 | 32 core floating point register f0 to f31. The fflags, frm, and fcsr | ||
29 | registers will continue to be advertised in the csr feature as they | ||
30 | currently are. | ||
31 | |||
32 | With that change made, I will simplify riscv_gdb_get_fpu and | ||
33 | riscv_gdb_set_fpu, removing the extra handling for the 3 status | ||
34 | registers. | ||
35 | |||
36 | Signed-off-by: Andrew Burgess <aburgess@redhat.com> | ||
37 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
38 | Message-Id: <0fbf2a5b12e3210ff3867d5cf7022b3f3462c9c8.1661934573.git.aburgess@redhat.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 39 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 40 | --- |
14 | target/riscv/gdbstub.c | 2 +- | 41 | target/riscv/gdbstub.c | 32 ++------------------------------ |
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 42 | gdb-xml/riscv-32bit-fpu.xml | 4 ---- |
43 | gdb-xml/riscv-64bit-fpu.xml | 4 ---- | ||
44 | 3 files changed, 2 insertions(+), 38 deletions(-) | ||
16 | 45 | ||
17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | 46 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
18 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/gdbstub.c | 48 | --- a/target/riscv/gdbstub.c |
20 | +++ b/target/riscv/gdbstub.c | 49 | +++ b/target/riscv/gdbstub.c |
50 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) | ||
51 | if (env->misa_ext & RVF) { | ||
52 | return gdb_get_reg32(buf, env->fpr[n]); | ||
53 | } | ||
54 | - /* there is hole between ft11 and fflags in fpu.xml */ | ||
55 | - } else if (n < 36 && n > 32) { | ||
56 | - target_ulong val = 0; | ||
57 | - int result; | ||
58 | - /* | ||
59 | - * CSR_FFLAGS is at index 1 in csr_register, and gdb says it is FP | ||
60 | - * register 33, so we recalculate the map index. | ||
61 | - * This also works for CSR_FRM and CSR_FCSR. | ||
62 | - */ | ||
63 | - result = riscv_csrrw_debug(env, n - 32, &val, | ||
64 | - 0, 0); | ||
65 | - if (result == RISCV_EXCP_NONE) { | ||
66 | - return gdb_get_regl(buf, val); | ||
67 | - } | ||
68 | } | ||
69 | return 0; | ||
70 | } | ||
71 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
72 | if (n < 32) { | ||
73 | env->fpr[n] = ldq_p(mem_buf); /* always 64-bit */ | ||
74 | return sizeof(uint64_t); | ||
75 | - /* there is hole between ft11 and fflags in fpu.xml */ | ||
76 | - } else if (n < 36 && n > 32) { | ||
77 | - target_ulong val = ldtul_p(mem_buf); | ||
78 | - int result; | ||
79 | - /* | ||
80 | - * CSR_FFLAGS is at index 1 in csr_register, and gdb says it is FP | ||
81 | - * register 33, so we recalculate the map index. | ||
82 | - * This also works for CSR_FRM and CSR_FCSR. | ||
83 | - */ | ||
84 | - result = riscv_csrrw_debug(env, n - 32, NULL, | ||
85 | - val, -1); | ||
86 | - if (result == RISCV_EXCP_NONE) { | ||
87 | - return sizeof(target_ulong); | ||
88 | - } | ||
89 | } | ||
90 | return 0; | ||
91 | } | ||
21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) | 92 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) |
22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), | 93 | CPURISCVState *env = &cpu->env; |
23 | 0); | 94 | if (env->misa_ext & RVD) { |
95 | gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, | ||
96 | - 36, "riscv-64bit-fpu.xml", 0); | ||
97 | + 32, "riscv-64bit-fpu.xml", 0); | ||
98 | } else if (env->misa_ext & RVF) { | ||
99 | gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, | ||
100 | - 36, "riscv-32bit-fpu.xml", 0); | ||
101 | + 32, "riscv-32bit-fpu.xml", 0); | ||
24 | } | 102 | } |
25 | - if (env->misa_ext & RVV) { | 103 | if (env->misa_ext & RVV) { |
26 | + if (cpu->cfg.ext_zve32x) { | 104 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, riscv_gdb_set_vector, |
27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, | 105 | diff --git a/gdb-xml/riscv-32bit-fpu.xml b/gdb-xml/riscv-32bit-fpu.xml |
28 | riscv_gdb_set_vector, | 106 | index XXXXXXX..XXXXXXX 100644 |
29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), | 107 | --- a/gdb-xml/riscv-32bit-fpu.xml |
108 | +++ b/gdb-xml/riscv-32bit-fpu.xml | ||
109 | @@ -XXX,XX +XXX,XX @@ | ||
110 | <reg name="ft9" bitsize="32" type="ieee_single"/> | ||
111 | <reg name="ft10" bitsize="32" type="ieee_single"/> | ||
112 | <reg name="ft11" bitsize="32" type="ieee_single"/> | ||
113 | - | ||
114 | - <reg name="fflags" bitsize="32" type="int" regnum="66"/> | ||
115 | - <reg name="frm" bitsize="32" type="int" regnum="67"/> | ||
116 | - <reg name="fcsr" bitsize="32" type="int" regnum="68"/> | ||
117 | </feature> | ||
118 | diff --git a/gdb-xml/riscv-64bit-fpu.xml b/gdb-xml/riscv-64bit-fpu.xml | ||
119 | index XXXXXXX..XXXXXXX 100644 | ||
120 | --- a/gdb-xml/riscv-64bit-fpu.xml | ||
121 | +++ b/gdb-xml/riscv-64bit-fpu.xml | ||
122 | @@ -XXX,XX +XXX,XX @@ | ||
123 | <reg name="ft9" bitsize="64" type="riscv_double"/> | ||
124 | <reg name="ft10" bitsize="64" type="riscv_double"/> | ||
125 | <reg name="ft11" bitsize="64" type="riscv_double"/> | ||
126 | - | ||
127 | - <reg name="fflags" bitsize="32" type="int" regnum="66"/> | ||
128 | - <reg name="frm" bitsize="32" type="int" regnum="67"/> | ||
129 | - <reg name="fcsr" bitsize="32" type="int" regnum="68"/> | ||
130 | </feature> | ||
30 | -- | 131 | -- |
31 | 2.45.1 | 132 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair23@gmail.com> | 1 | From: Andrew Burgess <aburgess@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | When running the instruction | 3 | The fixed register numbering in the various GDB feature files for |
4 | RISC-V only exists because these files were originally copied from the | ||
5 | GDB source tree. | ||
4 | 6 | ||
5 | ``` | 7 | However, the fixed numbering only exists in the GDB source tree so |
6 | cbo.flush 0(x0) | 8 | that GDB, when it connects to a target that doesn't provide a target |
7 | ``` | 9 | description, will use a specific numbering scheme. |
8 | 10 | ||
9 | QEMU would segfault. | 11 | That numbering scheme is designed to be compatible with the first |
12 | versions of QEMU (for RISC-V), that didn't send a target description, | ||
13 | and relied on a fixed numbering scheme. | ||
10 | 14 | ||
11 | The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0] | 15 | Because of the way that QEMU manages its target descriptions, |
12 | allocated. | 16 | recording the number of registers in each feature, and just relying on |
17 | GDB's numbering starting from 0, then I propose that we remove all the | ||
18 | fixed numbering from the RISC-V feature xml files, and just rely on | ||
19 | the standard numbering scheme. Plenty of other targets manage their | ||
20 | xml files this way, e.g. ARM, AArch64, Loongarch, m68k, rx, and s390. | ||
13 | 21 | ||
14 | In order to fix this let's use the existing get_address() | 22 | Signed-off-by: Andrew Burgess <aburgess@redhat.com> |
15 | helper. This also has the benefit of performing pointer mask | 23 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
16 | calculations on the address specified in rs1. | 24 | Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> |
17 | 25 | Message-Id: <6069395f90e6fc24dac92197be815fedf42f5974.1661934573.git.aburgess@redhat.com> | |
18 | The pointer masking specificiation specifically states: | ||
19 | |||
20 | """ | ||
21 | Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz | ||
22 | """ | ||
23 | |||
24 | So this is the correct behaviour and we previously have been incorrectly | ||
25 | not masking the address. | ||
26 | |||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Reported-by: Fabian Thomas <fabian.thomas@cispa.de> | ||
29 | Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension") | ||
30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
31 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
32 | Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com> | ||
33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
34 | --- | 27 | --- |
35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- | 28 | gdb-xml/riscv-32bit-cpu.xml | 6 +----- |
36 | 1 file changed, 12 insertions(+), 4 deletions(-) | 29 | gdb-xml/riscv-32bit-fpu.xml | 6 +----- |
30 | gdb-xml/riscv-64bit-cpu.xml | 6 +----- | ||
31 | gdb-xml/riscv-64bit-fpu.xml | 6 +----- | ||
32 | 4 files changed, 4 insertions(+), 20 deletions(-) | ||
37 | 33 | ||
38 | diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc | 34 | diff --git a/gdb-xml/riscv-32bit-cpu.xml b/gdb-xml/riscv-32bit-cpu.xml |
39 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc | 36 | --- a/gdb-xml/riscv-32bit-cpu.xml |
41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc | 37 | +++ b/gdb-xml/riscv-32bit-cpu.xml |
42 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ |
43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) | 39 | are permitted in any medium without royalty provided the copyright |
44 | { | 40 | notice and this notice are preserved. --> |
45 | REQUIRE_ZICBOM(ctx); | 41 | |
46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); | 42 | -<!-- Register numbers are hard-coded in order to maintain backward |
47 | + TCGv src = get_address(ctx, a->rs1, 0); | 43 | - compatibility with older versions of tools that didn't use xml |
48 | + | 44 | - register descriptions. --> |
49 | + gen_helper_cbo_clean_flush(tcg_env, src); | 45 | - |
50 | return true; | 46 | <!DOCTYPE feature SYSTEM "gdb-target.dtd"> |
51 | } | 47 | <feature name="org.gnu.gdb.riscv.cpu"> |
52 | 48 | - <reg name="zero" bitsize="32" type="int" regnum="0"/> | |
53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) | 49 | + <reg name="zero" bitsize="32" type="int"/> |
54 | { | 50 | <reg name="ra" bitsize="32" type="code_ptr"/> |
55 | REQUIRE_ZICBOM(ctx); | 51 | <reg name="sp" bitsize="32" type="data_ptr"/> |
56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); | 52 | <reg name="gp" bitsize="32" type="data_ptr"/> |
57 | + TCGv src = get_address(ctx, a->rs1, 0); | 53 | diff --git a/gdb-xml/riscv-32bit-fpu.xml b/gdb-xml/riscv-32bit-fpu.xml |
58 | + | 54 | index XXXXXXX..XXXXXXX 100644 |
59 | + gen_helper_cbo_clean_flush(tcg_env, src); | 55 | --- a/gdb-xml/riscv-32bit-fpu.xml |
60 | return true; | 56 | +++ b/gdb-xml/riscv-32bit-fpu.xml |
61 | } | 57 | @@ -XXX,XX +XXX,XX @@ |
62 | 58 | are permitted in any medium without royalty provided the copyright | |
63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) | 59 | notice and this notice are preserved. --> |
64 | { | 60 | |
65 | REQUIRE_ZICBOM(ctx); | 61 | -<!-- Register numbers are hard-coded in order to maintain backward |
66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); | 62 | - compatibility with older versions of tools that didn't use xml |
67 | + TCGv src = get_address(ctx, a->rs1, 0); | 63 | - register descriptions. --> |
68 | + | 64 | - |
69 | + gen_helper_cbo_inval(tcg_env, src); | 65 | <!DOCTYPE feature SYSTEM "gdb-target.dtd"> |
70 | return true; | 66 | <feature name="org.gnu.gdb.riscv.fpu"> |
71 | } | 67 | - <reg name="ft0" bitsize="32" type="ieee_single" regnum="33"/> |
72 | 68 | + <reg name="ft0" bitsize="32" type="ieee_single"/> | |
73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) | 69 | <reg name="ft1" bitsize="32" type="ieee_single"/> |
74 | { | 70 | <reg name="ft2" bitsize="32" type="ieee_single"/> |
75 | REQUIRE_ZICBOZ(ctx); | 71 | <reg name="ft3" bitsize="32" type="ieee_single"/> |
76 | - gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]); | 72 | diff --git a/gdb-xml/riscv-64bit-cpu.xml b/gdb-xml/riscv-64bit-cpu.xml |
77 | + TCGv src = get_address(ctx, a->rs1, 0); | 73 | index XXXXXXX..XXXXXXX 100644 |
78 | + | 74 | --- a/gdb-xml/riscv-64bit-cpu.xml |
79 | + gen_helper_cbo_zero(tcg_env, src); | 75 | +++ b/gdb-xml/riscv-64bit-cpu.xml |
80 | return true; | 76 | @@ -XXX,XX +XXX,XX @@ |
81 | } | 77 | are permitted in any medium without royalty provided the copyright |
78 | notice and this notice are preserved. --> | ||
79 | |||
80 | -<!-- Register numbers are hard-coded in order to maintain backward | ||
81 | - compatibility with older versions of tools that didn't use xml | ||
82 | - register descriptions. --> | ||
83 | - | ||
84 | <!DOCTYPE feature SYSTEM "gdb-target.dtd"> | ||
85 | <feature name="org.gnu.gdb.riscv.cpu"> | ||
86 | - <reg name="zero" bitsize="64" type="int" regnum="0"/> | ||
87 | + <reg name="zero" bitsize="64" type="int"/> | ||
88 | <reg name="ra" bitsize="64" type="code_ptr"/> | ||
89 | <reg name="sp" bitsize="64" type="data_ptr"/> | ||
90 | <reg name="gp" bitsize="64" type="data_ptr"/> | ||
91 | diff --git a/gdb-xml/riscv-64bit-fpu.xml b/gdb-xml/riscv-64bit-fpu.xml | ||
92 | index XXXXXXX..XXXXXXX 100644 | ||
93 | --- a/gdb-xml/riscv-64bit-fpu.xml | ||
94 | +++ b/gdb-xml/riscv-64bit-fpu.xml | ||
95 | @@ -XXX,XX +XXX,XX @@ | ||
96 | are permitted in any medium without royalty provided the copyright | ||
97 | notice and this notice are preserved. --> | ||
98 | |||
99 | -<!-- Register numbers are hard-coded in order to maintain backward | ||
100 | - compatibility with older versions of tools that didn't use xml | ||
101 | - register descriptions. --> | ||
102 | - | ||
103 | <!DOCTYPE feature SYSTEM "gdb-target.dtd"> | ||
104 | <feature name="org.gnu.gdb.riscv.fpu"> | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ | ||
107 | <field name="double" type="ieee_double"/> | ||
108 | </union> | ||
109 | |||
110 | - <reg name="ft0" bitsize="64" type="riscv_double" regnum="33"/> | ||
111 | + <reg name="ft0" bitsize="64" type="riscv_double"/> | ||
112 | <reg name="ft1" bitsize="64" type="riscv_double"/> | ||
113 | <reg name="ft2" bitsize="64" type="riscv_double"/> | ||
114 | <reg name="ft3" bitsize="64" type="riscv_double"/> | ||
82 | -- | 115 | -- |
83 | 2.45.1 | 116 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Christoph Müllner <christoph.muellner@vrull.eu> | 1 | From: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | The th.sxstatus CSR can be used to identify available custom extension | 3 | Instead of using our properties to set a config value which then might |
4 | on T-Head CPUs. The CSR is documented here: | 4 | be used to set the resetvec (depending on your timing), let's instead |
5 | https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc | 5 | just set the resetvec directly in the env struct. |
6 | 6 | ||
7 | An important property of this patch is, that the th.sxstatus MAEE field | 7 | This allows us to set the reset vec from the command line with: |
8 | is not set (indicating that XTheadMae is not available). | 8 | -global driver=riscv.hart_array,property=resetvec,value=0x20000400 |
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 | 9 | ||
17 | Further context can be found on the list: | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html | 11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
19 | 12 | Message-Id: <20220914101108.82571-2-alistair.francis@wdc.com> | |
20 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> | ||
21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | ||
23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 14 | --- |
26 | MAINTAINERS | 1 + | 15 | target/riscv/cpu.h | 3 +-- |
27 | target/riscv/cpu.h | 3 ++ | 16 | target/riscv/cpu.c | 13 +++---------- |
28 | target/riscv/cpu.c | 1 + | 17 | target/riscv/machine.c | 6 +++--- |
29 | target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++ | 18 | 3 files changed, 7 insertions(+), 15 deletions(-) |
30 | target/riscv/meson.build | 1 + | ||
31 | 5 files changed, 85 insertions(+) | ||
32 | create mode 100644 target/riscv/th_csr.c | ||
33 | 19 | ||
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 | 20 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
47 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/riscv/cpu.h | 22 | --- a/target/riscv/cpu.h |
49 | +++ b/target/riscv/cpu.h | 23 | +++ b/target/riscv/cpu.h |
50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, | 24 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { |
51 | uint8_t satp_mode_max_from_map(uint32_t map); | 25 | /* This contains QEMU specific information about the virt state. */ |
52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); | 26 | target_ulong virt; |
53 | 27 | target_ulong geilen; | |
54 | +/* Implemented in th_csr.c */ | 28 | - target_ulong resetvec; |
55 | +void th_register_custom_csrs(RISCVCPU *cpu); | 29 | + uint64_t resetvec; |
56 | + | 30 | |
57 | #endif /* RISCV_CPU_H */ | 31 | target_ulong mhartid; |
32 | /* | ||
33 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
34 | bool pmp; | ||
35 | bool epmp; | ||
36 | bool debug; | ||
37 | - uint64_t resetvec; | ||
38 | |||
39 | bool short_isa_string; | ||
40 | }; | ||
58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 41 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
59 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
60 | --- a/target/riscv/cpu.c | 43 | --- a/target/riscv/cpu.c |
61 | +++ b/target/riscv/cpu.c | 44 | +++ b/target/riscv/cpu.c |
62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) | 45 | @@ -XXX,XX +XXX,XX @@ static void set_vext_version(CPURISCVState *env, int vext_ver) |
63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; | 46 | env->vext_ver = vext_ver; |
47 | } | ||
48 | |||
49 | -static void set_resetvec(CPURISCVState *env, target_ulong resetvec) | ||
50 | -{ | ||
51 | -#ifndef CONFIG_USER_ONLY | ||
52 | - env->resetvec = resetvec; | ||
53 | -#endif | ||
54 | -} | ||
55 | - | ||
56 | static void riscv_any_cpu_init(Object *obj) | ||
57 | { | ||
58 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
59 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) | ||
60 | |||
61 | set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); | ||
62 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
63 | - set_resetvec(env, DEFAULT_RSTVEC); | ||
64 | cpu->cfg.mmu = false; | ||
65 | } | ||
66 | #endif | ||
67 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
68 | riscv_set_feature(env, RISCV_FEATURE_DEBUG); | ||
69 | } | ||
70 | |||
71 | - set_resetvec(env, cpu->cfg.resetvec); | ||
72 | |||
64 | #ifndef CONFIG_USER_ONLY | 73 | #ifndef CONFIG_USER_ONLY |
65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); | 74 | if (cpu->cfg.ext_sstc) { |
66 | + th_register_custom_csrs(cpu); | 75 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { |
67 | #endif | 76 | DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), |
68 | 77 | DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID), | |
69 | /* inherited from parent obj via riscv_cpu_init() */ | 78 | |
70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c | 79 | - DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), |
71 | new file mode 100644 | 80 | +#ifndef CONFIG_USER_ONLY |
72 | index XXXXXXX..XXXXXXX | 81 | + DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC), |
73 | --- /dev/null | 82 | +#endif |
74 | +++ b/target/riscv/th_csr.c | 83 | |
75 | @@ -XXX,XX +XXX,XX @@ | 84 | DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, false), |
76 | +/* | 85 | |
77 | + * T-Head-specific CSRs. | 86 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c |
78 | + * | ||
79 | + * Copyright (c) 2024 VRULL GmbH | ||
80 | + * | ||
81 | + * This program is free software; you can redistribute it and/or modify it | ||
82 | + * under the terms and conditions of the GNU General Public License, | ||
83 | + * version 2 or later, as published by the Free Software Foundation. | ||
84 | + * | ||
85 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
86 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
87 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
88 | + * more details. | ||
89 | + * | ||
90 | + * You should have received a copy of the GNU General Public License along with | ||
91 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
92 | + */ | ||
93 | + | ||
94 | +#include "qemu/osdep.h" | ||
95 | +#include "cpu.h" | ||
96 | +#include "cpu_vendorid.h" | ||
97 | + | ||
98 | +#define CSR_TH_SXSTATUS 0x5c0 | ||
99 | + | ||
100 | +/* TH_SXSTATUS bits */ | ||
101 | +#define TH_SXSTATUS_UCME BIT(16) | ||
102 | +#define TH_SXSTATUS_MAEE BIT(21) | ||
103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) | ||
104 | + | ||
105 | +typedef struct { | ||
106 | + int csrno; | ||
107 | + int (*insertion_test)(RISCVCPU *cpu); | ||
108 | + riscv_csr_operations csr_ops; | ||
109 | +} riscv_csr; | ||
110 | + | ||
111 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
112 | +{ | ||
113 | + if (riscv_has_ext(env, RVS)) { | ||
114 | + return RISCV_EXCP_NONE; | ||
115 | + } | ||
116 | + | ||
117 | + return RISCV_EXCP_ILLEGAL_INST; | ||
118 | +} | ||
119 | + | ||
120 | +static int test_thead_mvendorid(RISCVCPU *cpu) | ||
121 | +{ | ||
122 | + if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) { | ||
123 | + return -1; | ||
124 | + } | ||
125 | + | ||
126 | + return 0; | ||
127 | +} | ||
128 | + | ||
129 | +static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno, | ||
130 | + target_ulong *val) | ||
131 | +{ | ||
132 | + /* We don't set MAEE here, because QEMU does not implement MAEE. */ | ||
133 | + *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE; | ||
134 | + return RISCV_EXCP_NONE; | ||
135 | +} | ||
136 | + | ||
137 | +static riscv_csr th_csr_list[] = { | ||
138 | + { | ||
139 | + .csrno = CSR_TH_SXSTATUS, | ||
140 | + .insertion_test = test_thead_mvendorid, | ||
141 | + .csr_ops = { "th.sxstatus", smode, read_th_sxstatus } | ||
142 | + } | ||
143 | +}; | ||
144 | + | ||
145 | +void th_register_custom_csrs(RISCVCPU *cpu) | ||
146 | +{ | ||
147 | + for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) { | ||
148 | + int csrno = th_csr_list[i].csrno; | ||
149 | + riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops; | ||
150 | + if (!th_csr_list[i].insertion_test(cpu)) { | ||
151 | + riscv_set_csr_ops(csrno, csr_ops); | ||
152 | + } | ||
153 | + } | ||
154 | +} | ||
155 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
156 | index XXXXXXX..XXXXXXX 100644 | 87 | index XXXXXXX..XXXXXXX 100644 |
157 | --- a/target/riscv/meson.build | 88 | --- a/target/riscv/machine.c |
158 | +++ b/target/riscv/meson.build | 89 | +++ b/target/riscv/machine.c |
159 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( | 90 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pmu_ctr_state = { |
160 | 'monitor.c', | 91 | |
161 | 'machine.c', | 92 | const VMStateDescription vmstate_riscv_cpu = { |
162 | 'pmu.c', | 93 | .name = "cpu", |
163 | + 'th_csr.c', | 94 | - .version_id = 4, |
164 | 'time_helper.c', | 95 | - .minimum_version_id = 4, |
165 | 'riscv-qmp-cmds.c', | 96 | + .version_id = 5, |
166 | )) | 97 | + .minimum_version_id = 5, |
98 | .post_load = riscv_cpu_post_load, | ||
99 | .fields = (VMStateField[]) { | ||
100 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | ||
101 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
102 | VMSTATE_UINT32(env.features, RISCVCPU), | ||
103 | VMSTATE_UINTTL(env.priv, RISCVCPU), | ||
104 | VMSTATE_UINTTL(env.virt, RISCVCPU), | ||
105 | - VMSTATE_UINTTL(env.resetvec, RISCVCPU), | ||
106 | + VMSTATE_UINT64(env.resetvec, RISCVCPU), | ||
107 | VMSTATE_UINTTL(env.mhartid, RISCVCPU), | ||
108 | VMSTATE_UINT64(env.mstatus, RISCVCPU), | ||
109 | VMSTATE_UINT64(env.mip, RISCVCPU), | ||
167 | -- | 110 | -- |
168 | 2.45.1 | 111 | 2.37.3 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Huang Tao <eric.huang@linux.alibaba.com> | 1 | From: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s | 3 | The resetvec for the OpenTitan machine ended up being set to an out of |
4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element | 4 | date value, so let's fix that and bump it to the correct start address |
5 | agnostic policy. | 5 | (after the boot ROM) |
6 | 6 | ||
7 | However, this function can't deal the big endian situation. This patch fixes | 7 | Fixes: bf8803c64d75 "hw/riscv: opentitan: bump opentitan version" |
8 | the problem by adding handling of such case. | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | 9 | Message-Id: <20220914101108.82571-3-alistair.francis@wdc.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> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 11 | --- |
17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ | 12 | hw/riscv/opentitan.c | 2 +- |
18 | 1 file changed, 22 insertions(+) | 13 | 1 file changed, 1 insertion(+), 1 deletion(-) |
19 | 14 | ||
20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c | 15 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/vector_internals.c | 17 | --- a/hw/riscv/opentitan.c |
23 | +++ b/target/riscv/vector_internals.c | 18 | +++ b/hw/riscv/opentitan.c |
24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, | 19 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) |
25 | if (tot - cnt == 0) { | 20 | &error_abort); |
26 | return ; | 21 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, |
27 | } | 22 | &error_abort); |
28 | + | 23 | - object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x20000490, |
29 | + if (HOST_BIG_ENDIAN) { | 24 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x20000400, |
30 | + /* | 25 | &error_abort); |
31 | + * Deal the situation when the elements are insdie | 26 | sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal); |
32 | + * only one uint64 block including setting the | ||
33 | + * masked-off element. | ||
34 | + */ | ||
35 | + if (((tot - 1) ^ cnt) < 8) { | ||
36 | + memset(base + H1(tot - 1), -1, tot - cnt); | ||
37 | + return; | ||
38 | + } | ||
39 | + /* | ||
40 | + * Otherwise, at least cross two uint64_t blocks. | ||
41 | + * Set first unaligned block. | ||
42 | + */ | ||
43 | + if (cnt % 8 != 0) { | ||
44 | + uint32_t j = ROUND_UP(cnt, 8); | ||
45 | + memset(base + H1(j - 1), -1, j - cnt); | ||
46 | + cnt = j; | ||
47 | + } | ||
48 | + /* Set other 64bit aligend blocks */ | ||
49 | + } | ||
50 | memset(base + cnt, -1, tot - cnt); | ||
51 | } | ||
52 | 27 | ||
53 | -- | 28 | -- |
54 | 2.45.1 | 29 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace | 3 | On the OpenTitan hardware the resetvec is fixed at the start of ROM. In |
4 | the legacy console putchar and getchar SBI extensions. | 4 | QEMU we don't run the ROM code and instead just jump to the next stage. |
5 | This means we need to be a little more flexible about what the resetvec | ||
6 | is. | ||
5 | 7 | ||
6 | The appeal of the DBCN extension is that it allows multiple bytes to be | 8 | This patch allows us to set the resetvec from the command line with |
7 | read/written in the SBI console in a single SBI call. | 9 | something like this: |
10 | -global driver=riscv.lowrisc.ibex.soc,property=resetvec,value=0x20000400 | ||
8 | 11 | ||
9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM | 12 | This way as the next stage changes we can update the resetvec. |
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 | ||
13 | We'll check for DBCN support during init time, checking if get-reg-list | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via | 15 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
15 | kvm_set_one_reg() during kvm_arch_init_vcpu(). | 16 | Message-Id: <20220914101108.82571-4-alistair.francis@wdc.com> |
16 | |||
17 | Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for | ||
18 | SBI_EXT_DBCN, reading and writing as required. | ||
19 | |||
20 | A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V | ||
21 | host, takes around 20 seconds to boot without using DBCN. With this | ||
22 | patch we're taking around 14 seconds to boot due to the speed-up in the | ||
23 | terminal output. There's no change in boot time if the guest isn't | ||
24 | using earlycon. | ||
25 | |||
26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
28 | Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com> | ||
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
30 | --- | 18 | --- |
31 | target/riscv/sbi_ecall_interface.h | 17 +++++ | 19 | include/hw/riscv/opentitan.h | 2 ++ |
32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ | 20 | hw/riscv/opentitan.c | 8 +++++++- |
33 | 2 files changed, 128 insertions(+) | 21 | 2 files changed, 9 insertions(+), 1 deletion(-) |
34 | 22 | ||
35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h | 23 | diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h |
36 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/riscv/sbi_ecall_interface.h | 25 | --- a/include/hw/riscv/opentitan.h |
38 | +++ b/target/riscv/sbi_ecall_interface.h | 26 | +++ b/include/hw/riscv/opentitan.h |
39 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ struct LowRISCIbexSoCState { |
40 | 28 | IbexTimerState timer; | |
41 | /* clang-format off */ | 29 | IbexSPIHostState spi_host[OPENTITAN_NUM_SPI_HOSTS]; |
42 | 30 | ||
43 | +#define SBI_SUCCESS 0 | 31 | + uint32_t resetvec; |
44 | +#define SBI_ERR_FAILED -1 | ||
45 | +#define SBI_ERR_NOT_SUPPORTED -2 | ||
46 | +#define SBI_ERR_INVALID_PARAM -3 | ||
47 | +#define SBI_ERR_DENIED -4 | ||
48 | +#define SBI_ERR_INVALID_ADDRESS -5 | ||
49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 | ||
50 | +#define SBI_ERR_ALREADY_STARTED -7 | ||
51 | +#define SBI_ERR_ALREADY_STOPPED -8 | ||
52 | +#define SBI_ERR_NO_SHMEM -9 | ||
53 | + | 32 | + |
54 | /* SBI Extension IDs */ | 33 | MemoryRegion flash_mem; |
55 | #define SBI_EXT_0_1_SET_TIMER 0x0 | 34 | MemoryRegion rom; |
56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 | 35 | MemoryRegion flash_alias; |
57 | @@ -XXX,XX +XXX,XX @@ | 36 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c |
58 | #define SBI_EXT_IPI 0x735049 | ||
59 | #define SBI_EXT_RFENCE 0x52464E43 | ||
60 | #define SBI_EXT_HSM 0x48534D | ||
61 | +#define SBI_EXT_DBCN 0x4442434E | ||
62 | |||
63 | /* SBI function IDs for BASE extension */ | ||
64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 | ||
65 | @@ -XXX,XX +XXX,XX @@ | ||
66 | #define SBI_EXT_HSM_HART_STOP 0x1 | ||
67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 | ||
68 | |||
69 | +/* SBI function IDs for DBCN extension */ | ||
70 | +#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0 | ||
71 | +#define SBI_EXT_DBCN_CONSOLE_READ 0x1 | ||
72 | +#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 | ||
73 | + | ||
74 | #define SBI_HSM_HART_STATUS_STARTED 0x0 | ||
75 | #define SBI_HSM_HART_STATUS_STOPPED 0x1 | ||
76 | #define SBI_HSM_HART_STATUS_START_PENDING 0x2 | ||
77 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
79 | --- a/target/riscv/kvm/kvm-cpu.c | 38 | --- a/hw/riscv/opentitan.c |
80 | +++ b/target/riscv/kvm/kvm-cpu.c | 39 | +++ b/hw/riscv/opentitan.c |
81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { | 40 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) |
82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) | 41 | &error_abort); |
83 | }; | 42 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, |
84 | 43 | &error_abort); | |
85 | +static KVMCPUConfig kvm_sbi_dbcn = { | 44 | - object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x20000400, |
86 | + .name = "sbi_dbcn", | 45 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", s->resetvec, |
87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | | 46 | &error_abort); |
88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN | 47 | sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal); |
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | ||
50 | memmap[IBEX_DEV_PERI].base, memmap[IBEX_DEV_PERI].size); | ||
51 | } | ||
52 | |||
53 | +static Property lowrisc_ibex_soc_props[] = { | ||
54 | + DEFINE_PROP_UINT32("resetvec", LowRISCIbexSoCState, resetvec, 0x20000400), | ||
55 | + DEFINE_PROP_END_OF_LIST() | ||
89 | +}; | 56 | +}; |
90 | + | 57 | + |
91 | static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) | 58 | static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data) |
92 | { | 59 | { |
93 | CPURISCVState *env = &cpu->env; | 60 | DeviceClass *dc = DEVICE_CLASS(oc); |
94 | @@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b) | 61 | |
95 | return 0; | 62 | + device_class_set_props(dc, lowrisc_ibex_soc_props); |
96 | } | 63 | dc->realize = lowrisc_ibex_soc_realize; |
97 | 64 | /* Reason: Uses serial_hds in realize function, thus can't be used twice */ | |
98 | +static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu, | 65 | dc->user_creatable = false; |
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 | |||
151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
152 | return true; | ||
153 | } | ||
154 | |||
155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) | ||
156 | +{ | ||
157 | + g_autofree uint8_t *buf = NULL; | ||
158 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
159 | + target_ulong num_bytes; | ||
160 | + uint64_t addr; | ||
161 | + unsigned char ch; | ||
162 | + int ret; | ||
163 | + | ||
164 | + switch (run->riscv_sbi.function_id) { | ||
165 | + case SBI_EXT_DBCN_CONSOLE_READ: | ||
166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: | ||
167 | + num_bytes = run->riscv_sbi.args[0]; | ||
168 | + | ||
169 | + if (num_bytes == 0) { | ||
170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
171 | + run->riscv_sbi.ret[1] = 0; | ||
172 | + break; | ||
173 | + } | ||
174 | + | ||
175 | + addr = run->riscv_sbi.args[1]; | ||
176 | + | ||
177 | + /* | ||
178 | + * Handle the case where a 32 bit CPU is running in a | ||
179 | + * 64 bit addressing env. | ||
180 | + */ | ||
181 | + if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) { | ||
182 | + addr |= (uint64_t)run->riscv_sbi.args[2] << 32; | ||
183 | + } | ||
184 | + | ||
185 | + buf = g_malloc0(num_bytes); | ||
186 | + | ||
187 | + if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) { | ||
188 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes); | ||
189 | + if (ret < 0) { | ||
190 | + error_report("SBI_EXT_DBCN_CONSOLE_READ: error when " | ||
191 | + "reading chardev"); | ||
192 | + exit(1); | ||
193 | + } | ||
194 | + | ||
195 | + cpu_physical_memory_write(addr, buf, ret); | ||
196 | + } else { | ||
197 | + cpu_physical_memory_read(addr, buf, num_bytes); | ||
198 | + | ||
199 | + ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes); | ||
200 | + if (ret < 0) { | ||
201 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when " | ||
202 | + "writing chardev"); | ||
203 | + exit(1); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
208 | + run->riscv_sbi.ret[1] = ret; | ||
209 | + break; | ||
210 | + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: | ||
211 | + ch = run->riscv_sbi.args[0]; | ||
212 | + ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); | ||
213 | + | ||
214 | + if (ret < 0) { | ||
215 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when " | ||
216 | + "writing chardev"); | ||
217 | + exit(1); | ||
218 | + } | ||
219 | + | ||
220 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
221 | + run->riscv_sbi.ret[1] = 0; | ||
222 | + break; | ||
223 | + default: | ||
224 | + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED; | ||
225 | + } | ||
226 | +} | ||
227 | + | ||
228 | static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
229 | { | ||
230 | int ret = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
232 | } | ||
233 | ret = 0; | ||
234 | break; | ||
235 | + case SBI_EXT_DBCN: | ||
236 | + kvm_riscv_handle_sbi_dbcn(cs, run); | ||
237 | + break; | ||
238 | default: | ||
239 | qemu_log_mask(LOG_UNIMP, | ||
240 | "%s: un-handled SBI EXIT, specific reasons is %lu\n", | ||
241 | -- | 66 | -- |
242 | 2.45.1 | 67 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length | 3 | After RISCVException enum is introduced, riscv_csrrw_debug() returns |
4 | in bytes, when in this context we want 'reg_width' as the length in | 4 | RISCV_EXCP_NONE to indicate there's no error. RISC-V vector GDB stub |
5 | bits. | 5 | should check the result against RISCV_EXCP_NONE instead of value 0. |
6 | Otherwise, 'E14' packet would be incorrectly reported for vector CSRs | ||
7 | when using "info reg vector" GDB command. | ||
6 | 8 | ||
7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a | 9 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set | 10 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
9 | beforehand. | 11 | Reviewed-by: Tommy Wu <tommy.wu@sifive.com> |
10 | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | |
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> | 13 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
22 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | 14 | Message-Id: <20220918083245.13028-1-frank.chang@sifive.com> |
23 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 16 | --- |
29 | target/riscv/gdbstub.c | 6 +++--- | 17 | target/riscv/gdbstub.c | 4 ++-- |
30 | 1 file changed, 3 insertions(+), 3 deletions(-) | 18 | 1 file changed, 2 insertions(+), 2 deletions(-) |
31 | 19 | ||
32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | 20 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
33 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/riscv/gdbstub.c | 22 | --- a/target/riscv/gdbstub.c |
35 | +++ b/target/riscv/gdbstub.c | 23 | +++ b/target/riscv/gdbstub.c |
36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) | 24 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_vector(CPURISCVState *env, GByteArray *buf, int n) |
37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | 25 | target_ulong val = 0; |
38 | { | 26 | int result = riscv_csrrw_debug(env, csrno, &val, 0, 0); |
39 | RISCVCPU *cpu = RISCV_CPU(cs); | 27 | |
40 | - int reg_width = cpu->cfg.vlenb; | 28 | - if (result == 0) { |
41 | + int bitsize = cpu->cfg.vlenb << 3; | 29 | + if (result == RISCV_EXCP_NONE) { |
42 | GDBFeatureBuilder builder; | 30 | return gdb_get_regl(buf, val); |
43 | int i; | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | ||
46 | |||
47 | /* First define types and totals in a whole VL */ | ||
48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { | ||
49 | - int count = reg_width / vec_lanes[i].size; | ||
50 | + int count = bitsize / vec_lanes[i].size; | ||
51 | gdb_feature_builder_append_tag( | ||
52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", | ||
53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); | ||
54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | ||
55 | /* Define vector registers */ | ||
56 | for (i = 0; i < 32; i++) { | ||
57 | gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), | ||
58 | - reg_width, i, "riscv_vector", "vector"); | ||
59 | + bitsize, i, "riscv_vector", "vector"); | ||
60 | } | 31 | } |
61 | 32 | ||
62 | gdb_feature_builder_end(&builder); | 33 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_vector(CPURISCVState *env, uint8_t *mem_buf, int n) |
34 | target_ulong val = ldtul_p(mem_buf); | ||
35 | int result = riscv_csrrw_debug(env, csrno, NULL, val, -1); | ||
36 | |||
37 | - if (result == 0) { | ||
38 | + if (result == RISCV_EXCP_NONE) { | ||
39 | return sizeof(target_ulong); | ||
40 | } | ||
41 | |||
63 | -- | 42 | -- |
64 | 2.45.1 | 43 | 2.37.3 |
65 | |||
66 | diff view generated by jsdifflib |
1 | From: Rob Bradford <rbradford@rivosinc.com> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | This extension has now been ratified: | 3 | SiFiveEState inherits from SysBusDevice while it's TypeInfo claims it to |
4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be | 4 | inherit from TYPE_MACHINE. This is an inconsistency which can cause |
5 | removed. | 5 | undefined behavior such as memory corruption. |
6 | 6 | ||
7 | Since this is now a ratified extension add it to the list of extensions | 7 | Change SiFiveEState to inherit from MachineState since it is registered |
8 | included in the "max" CPU variant. | 8 | as a machine. |
9 | 9 | ||
10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | 10 | Fixes: 0869490b1c ("riscv: sifive_e: Manually define the machine") |
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 11 | |
12 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
14 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 15 | Message-Id: <20220922075232.33653-1-shentey@gmail.com> |
15 | Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 17 | --- |
18 | target/riscv/cpu.c | 2 +- | 18 | include/hw/riscv/sifive_e.h | 3 ++- |
19 | target/riscv/tcg/tcg-cpu.c | 2 +- | 19 | 1 file changed, 2 insertions(+), 1 deletion(-) |
20 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
21 | 20 | ||
22 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 21 | diff --git a/include/hw/riscv/sifive_e.h b/include/hw/riscv/sifive_e.h |
23 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/cpu.c | 23 | --- a/include/hw/riscv/sifive_e.h |
25 | +++ b/target/riscv/cpu.c | 24 | +++ b/include/hw/riscv/sifive_e.h |
26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { | 25 | @@ -XXX,XX +XXX,XX @@ |
27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), | 26 | #include "hw/riscv/riscv_hart.h" |
28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), | 27 | #include "hw/riscv/sifive_cpu.h" |
29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), | 28 | #include "hw/gpio/sifive_gpio.h" |
30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") | 29 | +#include "hw/boards.h" |
31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") | 30 | |
32 | }; | 31 | #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc" |
33 | 32 | #define RISCV_E_SOC(obj) \ | |
34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) | 33 | @@ -XXX,XX +XXX,XX @@ typedef struct SiFiveESoCState { |
35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 34 | |
36 | index XXXXXXX..XXXXXXX 100644 | 35 | typedef struct SiFiveEState { |
37 | --- a/target/riscv/tcg/tcg-cpu.c | 36 | /*< private >*/ |
38 | +++ b/target/riscv/tcg/tcg-cpu.c | 37 | - SysBusDevice parent_obj; |
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | 38 | + MachineState parent_obj; |
40 | const RISCVCPUMultiExtConfig *prop; | 39 | |
41 | 40 | /*< public >*/ | |
42 | /* Enable RVG, RVJ and RVV that are disabled by default */ | 41 | SiFiveESoCState soc; |
43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); | ||
44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); | ||
45 | |||
46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
47 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
48 | -- | 42 | -- |
49 | 2.45.1 | 43 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Andrew Jones <ajones@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The Zkr extension may only be exposed to KVM guests if the VMM | 3 | Current RISC-V debug assumes that only type 2 trigger is supported. |
4 | implements the SEED CSR. Use the same implementation as TCG. | 4 | To allow more types of triggers to be supported in the future |
5 | (e.g. type 6 trigger, which is similar to type 2 trigger with additional | ||
6 | functionality), we should determine the trigger type from tdata1.type. | ||
5 | 7 | ||
6 | Without this patch, running with a KVM which does not forward the | 8 | RV_MAX_TRIGGERS is also introduced in replacement of TRIGGER_TYPE2_NUM. |
7 | SEED CSR access to QEMU will result in an ILL exception being | ||
8 | injected into the guest (this results in Linux guests crashing on | ||
9 | boot). And, when running with a KVM which does forward the access, | ||
10 | QEMU will crash, since QEMU doesn't know what to do with the exit. | ||
11 | 9 | ||
12 | Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8") | 10 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
13 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | 11 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 12 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
15 | Cc: qemu-stable <qemu-stable@nongnu.org> | 13 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
16 | Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com> | 14 | [bmeng: fixed MXL_RV128 case, and moved macros to the following patch] |
15 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
16 | Message-Id: <20220909134215.1843865-2-bmeng.cn@gmail.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 18 | --- |
19 | target/riscv/cpu.h | 3 +++ | 19 | target/riscv/cpu.h | 2 +- |
20 | target/riscv/csr.c | 18 ++++++++++++++---- | 20 | target/riscv/debug.h | 13 +-- |
21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ | 21 | target/riscv/csr.c | 2 +- |
22 | 3 files changed, 42 insertions(+), 4 deletions(-) | 22 | target/riscv/debug.c | 188 +++++++++++++++++++++++++++++------------ |
23 | target/riscv/machine.c | 2 +- | ||
24 | 5 files changed, 140 insertions(+), 67 deletions(-) | ||
23 | 25 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 26 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
25 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/cpu.h | 28 | --- a/target/riscv/cpu.h |
27 | +++ b/target/riscv/cpu.h | 29 | +++ b/target/riscv/cpu.h |
28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); | 30 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { |
29 | 31 | ||
30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); | 32 | /* trigger module */ |
31 | 33 | target_ulong trigger_cur; | |
32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | 34 | - type2_trigger_t type2_trig[TRIGGER_TYPE2_NUM]; |
33 | + target_ulong write_mask); | 35 | + type2_trigger_t type2_trig[RV_MAX_TRIGGERS]; |
34 | + | 36 | |
35 | uint8_t satp_mode_max_from_map(uint32_t map); | 37 | /* machine specific rdtime callback */ |
36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); | 38 | uint64_t (*rdtime_fn)(void *); |
37 | 39 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h | |
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/riscv/debug.h | ||
42 | +++ b/target/riscv/debug.h | ||
43 | @@ -XXX,XX +XXX,XX @@ | ||
44 | #ifndef RISCV_DEBUG_H | ||
45 | #define RISCV_DEBUG_H | ||
46 | |||
47 | -/* trigger indexes implemented */ | ||
48 | -enum { | ||
49 | - TRIGGER_TYPE2_IDX_0 = 0, | ||
50 | - TRIGGER_TYPE2_IDX_1, | ||
51 | - TRIGGER_TYPE2_NUM, | ||
52 | - TRIGGER_NUM = TRIGGER_TYPE2_NUM | ||
53 | -}; | ||
54 | +#define RV_MAX_TRIGGERS 2 | ||
55 | |||
56 | /* register index of tdata CSRs */ | ||
57 | enum { | ||
58 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
59 | TRIGGER_TYPE_EXCP = 5, /* exception trigger */ | ||
60 | TRIGGER_TYPE_AD_MATCH6 = 6, /* new address/data match trigger */ | ||
61 | TRIGGER_TYPE_EXT_SRC = 7, /* external source trigger */ | ||
62 | - TRIGGER_TYPE_UNAVAIL = 15 /* trigger exists, but unavailable */ | ||
63 | + TRIGGER_TYPE_UNAVAIL = 15, /* trigger exists, but unavailable */ | ||
64 | + TRIGGER_TYPE_NUM | ||
65 | } trigger_type_t; | ||
66 | |||
67 | typedef struct { | ||
68 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
69 | struct CPUWatchpoint *wp; | ||
70 | } type2_trigger_t; | ||
71 | |||
72 | -/* tdata field masks */ | ||
73 | +/* tdata1 field masks */ | ||
74 | |||
75 | #define RV32_TYPE(t) ((uint32_t)(t) << 28) | ||
76 | #define RV32_TYPE_MASK (0xf << 28) | ||
38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 77 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
39 | index XXXXXXX..XXXXXXX 100644 | 78 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/csr.c | 79 | --- a/target/riscv/csr.c |
41 | +++ b/target/riscv/csr.c | 80 | +++ b/target/riscv/csr.c |
42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, | 81 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_tdata(CPURISCVState *env, int csrno, |
43 | #endif | 82 | target_ulong *val) |
44 | 83 | { | |
45 | /* Crypto Extension */ | 84 | /* return 0 in tdata1 to end the trigger enumeration */ |
46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, | 85 | - if (env->trigger_cur >= TRIGGER_NUM && csrno == CSR_TDATA1) { |
47 | - target_ulong *ret_value, | 86 | + if (env->trigger_cur >= RV_MAX_TRIGGERS && csrno == CSR_TDATA1) { |
48 | - target_ulong new_value, | 87 | *val = 0; |
49 | - target_ulong write_mask) | 88 | return RISCV_EXCP_NONE; |
50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | 89 | } |
51 | + target_ulong write_mask) | 90 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
52 | { | 91 | index XXXXXXX..XXXXXXX 100644 |
53 | uint16_t random_v; | 92 | --- a/target/riscv/debug.c |
54 | Error *random_e = NULL; | 93 | +++ b/target/riscv/debug.c |
55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, | 94 | @@ -XXX,XX +XXX,XX @@ |
56 | rval = random_v | SEED_OPST_ES16; | 95 | /* tdata availability of a trigger */ |
57 | } | 96 | typedef bool tdata_avail[TDATA_NUM]; |
58 | 97 | ||
59 | + return rval; | 98 | -static tdata_avail tdata_mapping[TRIGGER_NUM] = { |
99 | - [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = { true, true, false }, | ||
100 | +static tdata_avail tdata_mapping[TRIGGER_TYPE_NUM] = { | ||
101 | + [TRIGGER_TYPE_NO_EXIST] = { false, false, false }, | ||
102 | + [TRIGGER_TYPE_AD_MATCH] = { true, true, true }, | ||
103 | + [TRIGGER_TYPE_INST_CNT] = { true, false, true }, | ||
104 | + [TRIGGER_TYPE_INT] = { true, true, true }, | ||
105 | + [TRIGGER_TYPE_EXCP] = { true, true, true }, | ||
106 | + [TRIGGER_TYPE_AD_MATCH6] = { true, true, true }, | ||
107 | + [TRIGGER_TYPE_EXT_SRC] = { true, false, false }, | ||
108 | + [TRIGGER_TYPE_UNAVAIL] = { true, true, true } | ||
109 | }; | ||
110 | |||
111 | /* only breakpoint size 1/2/4/8 supported */ | ||
112 | @@ -XXX,XX +XXX,XX @@ static int access_size[SIZE_NUM] = { | ||
113 | [6 ... 15] = -1, | ||
114 | }; | ||
115 | |||
116 | +static inline target_ulong extract_trigger_type(CPURISCVState *env, | ||
117 | + target_ulong tdata1) | ||
118 | +{ | ||
119 | + switch (riscv_cpu_mxl(env)) { | ||
120 | + case MXL_RV32: | ||
121 | + return extract32(tdata1, 28, 4); | ||
122 | + case MXL_RV64: | ||
123 | + case MXL_RV128: | ||
124 | + return extract64(tdata1, 60, 4); | ||
125 | + default: | ||
126 | + g_assert_not_reached(); | ||
127 | + } | ||
60 | +} | 128 | +} |
61 | + | 129 | + |
62 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, | 130 | +static inline target_ulong get_trigger_type(CPURISCVState *env, |
63 | + target_ulong *ret_value, | 131 | + target_ulong trigger_index) |
64 | + target_ulong new_value, | ||
65 | + target_ulong write_mask) | ||
66 | +{ | 132 | +{ |
67 | + target_ulong rval; | 133 | + target_ulong tdata1 = env->type2_trig[trigger_index].mcontrol; |
68 | + | 134 | + return extract_trigger_type(env, tdata1); |
69 | + rval = riscv_new_csr_seed(new_value, write_mask); | 135 | +} |
70 | + | 136 | + |
71 | if (ret_value) { | 137 | static inline target_ulong trigger_type(CPURISCVState *env, |
72 | *ret_value = rval; | 138 | trigger_type_t type) |
73 | } | 139 | { |
74 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 140 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong trigger_type(CPURISCVState *env, |
141 | |||
142 | bool tdata_available(CPURISCVState *env, int tdata_index) | ||
143 | { | ||
144 | + int trigger_type = get_trigger_type(env, env->trigger_cur); | ||
145 | + | ||
146 | if (unlikely(tdata_index >= TDATA_NUM)) { | ||
147 | return false; | ||
148 | } | ||
149 | |||
150 | - if (unlikely(env->trigger_cur >= TRIGGER_NUM)) { | ||
151 | + if (unlikely(env->trigger_cur >= RV_MAX_TRIGGERS)) { | ||
152 | return false; | ||
153 | } | ||
154 | |||
155 | - return tdata_mapping[env->trigger_cur][tdata_index]; | ||
156 | + return tdata_mapping[trigger_type][tdata_index]; | ||
157 | } | ||
158 | |||
159 | target_ulong tselect_csr_read(CPURISCVState *env) | ||
160 | @@ -XXX,XX +XXX,XX @@ static target_ulong tdata1_validate(CPURISCVState *env, target_ulong val, | ||
161 | qemu_log_mask(LOG_GUEST_ERROR, | ||
162 | "ignoring type write to tdata1 register\n"); | ||
163 | } | ||
164 | + | ||
165 | if (dmode != 0) { | ||
166 | qemu_log_mask(LOG_UNIMP, "debug mode is not supported\n"); | ||
167 | } | ||
168 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_remove(CPURISCVState *env, target_ulong index) | ||
169 | } | ||
170 | |||
171 | static target_ulong type2_reg_read(CPURISCVState *env, | ||
172 | - target_ulong trigger_index, int tdata_index) | ||
173 | + target_ulong index, int tdata_index) | ||
174 | { | ||
175 | - uint32_t index = trigger_index - TRIGGER_TYPE2_IDX_0; | ||
176 | target_ulong tdata; | ||
177 | |||
178 | switch (tdata_index) { | ||
179 | @@ -XXX,XX +XXX,XX @@ static target_ulong type2_reg_read(CPURISCVState *env, | ||
180 | return tdata; | ||
181 | } | ||
182 | |||
183 | -static void type2_reg_write(CPURISCVState *env, target_ulong trigger_index, | ||
184 | +static void type2_reg_write(CPURISCVState *env, target_ulong index, | ||
185 | int tdata_index, target_ulong val) | ||
186 | { | ||
187 | - uint32_t index = trigger_index - TRIGGER_TYPE2_IDX_0; | ||
188 | target_ulong new_val; | ||
189 | |||
190 | switch (tdata_index) { | ||
191 | @@ -XXX,XX +XXX,XX @@ static void type2_reg_write(CPURISCVState *env, target_ulong trigger_index, | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | -typedef target_ulong (*tdata_read_func)(CPURISCVState *env, | ||
196 | - target_ulong trigger_index, | ||
197 | - int tdata_index); | ||
198 | - | ||
199 | -static tdata_read_func trigger_read_funcs[TRIGGER_NUM] = { | ||
200 | - [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = type2_reg_read, | ||
201 | -}; | ||
202 | - | ||
203 | -typedef void (*tdata_write_func)(CPURISCVState *env, | ||
204 | - target_ulong trigger_index, | ||
205 | - int tdata_index, | ||
206 | - target_ulong val); | ||
207 | - | ||
208 | -static tdata_write_func trigger_write_funcs[TRIGGER_NUM] = { | ||
209 | - [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = type2_reg_write, | ||
210 | -}; | ||
211 | - | ||
212 | target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index) | ||
213 | { | ||
214 | - tdata_read_func read_func = trigger_read_funcs[env->trigger_cur]; | ||
215 | + int trigger_type = get_trigger_type(env, env->trigger_cur); | ||
216 | + | ||
217 | + switch (trigger_type) { | ||
218 | + case TRIGGER_TYPE_AD_MATCH: | ||
219 | + return type2_reg_read(env, env->trigger_cur, tdata_index); | ||
220 | + break; | ||
221 | + case TRIGGER_TYPE_INST_CNT: | ||
222 | + case TRIGGER_TYPE_INT: | ||
223 | + case TRIGGER_TYPE_EXCP: | ||
224 | + case TRIGGER_TYPE_AD_MATCH6: | ||
225 | + case TRIGGER_TYPE_EXT_SRC: | ||
226 | + qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", | ||
227 | + trigger_type); | ||
228 | + break; | ||
229 | + case TRIGGER_TYPE_NO_EXIST: | ||
230 | + case TRIGGER_TYPE_UNAVAIL: | ||
231 | + qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d does not exit\n", | ||
232 | + trigger_type); | ||
233 | + break; | ||
234 | + default: | ||
235 | + g_assert_not_reached(); | ||
236 | + } | ||
237 | |||
238 | - return read_func(env, env->trigger_cur, tdata_index); | ||
239 | + return 0; | ||
240 | } | ||
241 | |||
242 | void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) | ||
243 | { | ||
244 | - tdata_write_func write_func = trigger_write_funcs[env->trigger_cur]; | ||
245 | + int trigger_type; | ||
246 | |||
247 | - return write_func(env, env->trigger_cur, tdata_index, val); | ||
248 | + if (tdata_index == TDATA1) { | ||
249 | + trigger_type = extract_trigger_type(env, val); | ||
250 | + } else { | ||
251 | + trigger_type = get_trigger_type(env, env->trigger_cur); | ||
252 | + } | ||
253 | + | ||
254 | + switch (trigger_type) { | ||
255 | + case TRIGGER_TYPE_AD_MATCH: | ||
256 | + type2_reg_write(env, env->trigger_cur, tdata_index, val); | ||
257 | + break; | ||
258 | + case TRIGGER_TYPE_INST_CNT: | ||
259 | + case TRIGGER_TYPE_INT: | ||
260 | + case TRIGGER_TYPE_EXCP: | ||
261 | + case TRIGGER_TYPE_AD_MATCH6: | ||
262 | + case TRIGGER_TYPE_EXT_SRC: | ||
263 | + qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", | ||
264 | + trigger_type); | ||
265 | + break; | ||
266 | + case TRIGGER_TYPE_NO_EXIST: | ||
267 | + case TRIGGER_TYPE_UNAVAIL: | ||
268 | + qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d does not exit\n", | ||
269 | + trigger_type); | ||
270 | + break; | ||
271 | + default: | ||
272 | + g_assert_not_reached(); | ||
273 | + } | ||
274 | } | ||
275 | |||
276 | void riscv_cpu_debug_excp_handler(CPUState *cs) | ||
277 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | ||
278 | CPUBreakpoint *bp; | ||
279 | target_ulong ctrl; | ||
280 | target_ulong pc; | ||
281 | + int trigger_type; | ||
282 | int i; | ||
283 | |||
284 | QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { | ||
285 | - for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { | ||
286 | - ctrl = env->type2_trig[i].mcontrol; | ||
287 | - pc = env->type2_trig[i].maddress; | ||
288 | - | ||
289 | - if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { | ||
290 | - /* check U/S/M bit against current privilege level */ | ||
291 | - if ((ctrl >> 3) & BIT(env->priv)) { | ||
292 | - return true; | ||
293 | + for (i = 0; i < RV_MAX_TRIGGERS; i++) { | ||
294 | + trigger_type = get_trigger_type(env, i); | ||
295 | + | ||
296 | + switch (trigger_type) { | ||
297 | + case TRIGGER_TYPE_AD_MATCH: | ||
298 | + ctrl = env->type2_trig[i].mcontrol; | ||
299 | + pc = env->type2_trig[i].maddress; | ||
300 | + | ||
301 | + if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { | ||
302 | + /* check U/S/M bit against current privilege level */ | ||
303 | + if ((ctrl >> 3) & BIT(env->priv)) { | ||
304 | + return true; | ||
305 | + } | ||
306 | } | ||
307 | + break; | ||
308 | + default: | ||
309 | + /* other trigger types are not supported or irrelevant */ | ||
310 | + break; | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) | ||
315 | CPURISCVState *env = &cpu->env; | ||
316 | target_ulong ctrl; | ||
317 | target_ulong addr; | ||
318 | + int trigger_type; | ||
319 | int flags; | ||
320 | int i; | ||
321 | |||
322 | - for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { | ||
323 | - ctrl = env->type2_trig[i].mcontrol; | ||
324 | - addr = env->type2_trig[i].maddress; | ||
325 | - flags = 0; | ||
326 | + for (i = 0; i < RV_MAX_TRIGGERS; i++) { | ||
327 | + trigger_type = get_trigger_type(env, i); | ||
328 | |||
329 | - if (ctrl & TYPE2_LOAD) { | ||
330 | - flags |= BP_MEM_READ; | ||
331 | - } | ||
332 | - if (ctrl & TYPE2_STORE) { | ||
333 | - flags |= BP_MEM_WRITE; | ||
334 | - } | ||
335 | + switch (trigger_type) { | ||
336 | + case TRIGGER_TYPE_AD_MATCH: | ||
337 | + ctrl = env->type2_trig[i].mcontrol; | ||
338 | + addr = env->type2_trig[i].maddress; | ||
339 | + flags = 0; | ||
340 | |||
341 | - if ((wp->flags & flags) && (wp->vaddr == addr)) { | ||
342 | - /* check U/S/M bit against current privilege level */ | ||
343 | - if ((ctrl >> 3) & BIT(env->priv)) { | ||
344 | - return true; | ||
345 | + if (ctrl & TYPE2_LOAD) { | ||
346 | + flags |= BP_MEM_READ; | ||
347 | + } | ||
348 | + if (ctrl & TYPE2_STORE) { | ||
349 | + flags |= BP_MEM_WRITE; | ||
350 | + } | ||
351 | + | ||
352 | + if ((wp->flags & flags) && (wp->vaddr == addr)) { | ||
353 | + /* check U/S/M bit against current privilege level */ | ||
354 | + if ((ctrl >> 3) & BIT(env->priv)) { | ||
355 | + return true; | ||
356 | + } | ||
357 | } | ||
358 | + break; | ||
359 | + default: | ||
360 | + /* other trigger types are not supported */ | ||
361 | + break; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) | ||
366 | |||
367 | void riscv_trigger_init(CPURISCVState *env) | ||
368 | { | ||
369 | - target_ulong type2 = trigger_type(env, TRIGGER_TYPE_AD_MATCH); | ||
370 | + target_ulong tdata1 = trigger_type(env, TRIGGER_TYPE_AD_MATCH); | ||
371 | int i; | ||
372 | |||
373 | - /* type 2 triggers */ | ||
374 | - for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { | ||
375 | + /* init to type 2 triggers */ | ||
376 | + for (i = 0; i < RV_MAX_TRIGGERS; i++) { | ||
377 | /* | ||
378 | * type = TRIGGER_TYPE_AD_MATCH | ||
379 | * dmode = 0 (both debug and M-mode can write tdata) | ||
380 | @@ -XXX,XX +XXX,XX @@ void riscv_trigger_init(CPURISCVState *env) | ||
381 | * chain = 0 (unimplemented, always 0) | ||
382 | * match = 0 (always 0, when any compare value equals tdata2) | ||
383 | */ | ||
384 | - env->type2_trig[i].mcontrol = type2; | ||
385 | + env->type2_trig[i].mcontrol = tdata1; | ||
386 | env->type2_trig[i].maddress = 0; | ||
387 | env->type2_trig[i].bp = NULL; | ||
388 | env->type2_trig[i].wp = NULL; | ||
389 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | 390 | index XXXXXXX..XXXXXXX 100644 |
76 | --- a/target/riscv/kvm/kvm-cpu.c | 391 | --- a/target/riscv/machine.c |
77 | +++ b/target/riscv/kvm/kvm-cpu.c | 392 | +++ b/target/riscv/machine.c |
78 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | 393 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_debug = { |
79 | return ret; | 394 | .needed = debug_needed, |
80 | } | 395 | .fields = (VMStateField[]) { |
81 | 396 | VMSTATE_UINTTL(env.trigger_cur, RISCVCPU), | |
82 | +static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run) | 397 | - VMSTATE_STRUCT_ARRAY(env.type2_trig, RISCVCPU, TRIGGER_TYPE2_NUM, |
83 | +{ | 398 | + VMSTATE_STRUCT_ARRAY(env.type2_trig, RISCVCPU, RV_MAX_TRIGGERS, |
84 | + target_ulong csr_num = run->riscv_csr.csr_num; | 399 | 0, vmstate_debug_type2, type2_trigger_t), |
85 | + target_ulong new_value = run->riscv_csr.new_value; | 400 | VMSTATE_END_OF_LIST() |
86 | + target_ulong write_mask = run->riscv_csr.write_mask; | 401 | } |
87 | + int ret = 0; | ||
88 | + | ||
89 | + switch (csr_num) { | ||
90 | + case CSR_SEED: | ||
91 | + run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask); | ||
92 | + break; | ||
93 | + default: | ||
94 | + qemu_log_mask(LOG_UNIMP, | ||
95 | + "%s: un-handled CSR EXIT for CSR %lx\n", | ||
96 | + __func__, csr_num); | ||
97 | + ret = -1; | ||
98 | + break; | ||
99 | + } | ||
100 | + | ||
101 | + return ret; | ||
102 | +} | ||
103 | + | ||
104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
105 | { | ||
106 | int ret = 0; | ||
107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
108 | case KVM_EXIT_RISCV_SBI: | ||
109 | ret = kvm_riscv_handle_sbi(cs, run); | ||
110 | break; | ||
111 | + case KVM_EXIT_RISCV_CSR: | ||
112 | + ret = kvm_riscv_handle_csr(cs, run); | ||
113 | + break; | ||
114 | default: | ||
115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", | ||
116 | __func__, run->exit_reason); | ||
117 | -- | 402 | -- |
118 | 2.45.1 | 403 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by | 3 | Introduce build_tdata1() to build tdata1 register content, which can be |
4 | checking first if virt_enabled && !first_stage, and then considering the | 4 | shared among all types of triggers. |
5 | regular inst/load/store faults. | ||
6 | 5 | ||
7 | There's no mention in the spec about guest page fault being a higher | 6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
9 | 8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | |
10 | "Attempting to fetch an instruction from a PMP region that does not have | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
11 | execute permissions raises an instruction access-fault exception. | 10 | [bmeng: moved RV{32,64}_DATA_MASK definition to this patch] |
12 | Attempting to execute a load or load-reserved instruction which accesses | 11 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
13 | a physical address within a PMP region without read permissions raises a | 12 | Message-Id: <20220909134215.1843865-3-bmeng.cn@gmail.com> |
14 | load access-fault exception. Attempting to execute a store, | ||
15 | store-conditional, or AMO instruction which accesses a physical address | ||
16 | within a PMP region without write permissions raises a store | ||
17 | access-fault exception." | ||
18 | |||
19 | So, in fact, we're doing it wrong - PMP faults should always be thrown, | ||
20 | regardless of also being a first or second stage fault. | ||
21 | |||
22 | The way riscv_cpu_tlb_fill() and get_physical_address() work is | ||
23 | adequate: a TRANSLATE_PMP_FAIL error is immediately reported and | ||
24 | reflected in the 'pmp_violation' flag. What we need is to change | ||
25 | raise_mmu_exception() to prioritize it. | ||
26 | |||
27 | Reported-by: Joseph Chan <jchan@ventanamicro.com> | ||
28 | Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage") | ||
29 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> | ||
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
34 | --- | 14 | --- |
35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- | 15 | target/riscv/debug.h | 2 ++ |
36 | 1 file changed, 12 insertions(+), 10 deletions(-) | 16 | target/riscv/debug.c | 15 ++++++++++----- |
17 | 2 files changed, 12 insertions(+), 5 deletions(-) | ||
37 | 18 | ||
38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 19 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h |
39 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu_helper.c | 21 | --- a/target/riscv/debug.h |
41 | +++ b/target/riscv/cpu_helper.c | 22 | +++ b/target/riscv/debug.h |
42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
43 | 24 | #define RV32_TYPE(t) ((uint32_t)(t) << 28) | |
44 | switch (access_type) { | 25 | #define RV32_TYPE_MASK (0xf << 28) |
45 | case MMU_INST_FETCH: | 26 | #define RV32_DMODE BIT(27) |
46 | - if (env->virt_enabled && !first_stage) { | 27 | +#define RV32_DATA_MASK 0x7ffffff |
47 | + if (pmp_violation) { | 28 | #define RV64_TYPE(t) ((uint64_t)(t) << 60) |
48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; | 29 | #define RV64_TYPE_MASK (0xfULL << 60) |
49 | + } else if (env->virt_enabled && !first_stage) { | 30 | #define RV64_DMODE BIT_ULL(59) |
50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; | 31 | +#define RV64_DATA_MASK 0x7ffffffffffffff |
51 | } else { | 32 | |
52 | - cs->exception_index = pmp_violation ? | 33 | /* mcontrol field masks */ |
53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; | 34 | |
54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; | 35 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
55 | } | 36 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/riscv/debug.c | ||
38 | +++ b/target/riscv/debug.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong get_trigger_type(CPURISCVState *env, | ||
40 | return extract_trigger_type(env, tdata1); | ||
41 | } | ||
42 | |||
43 | -static inline target_ulong trigger_type(CPURISCVState *env, | ||
44 | - trigger_type_t type) | ||
45 | +static inline target_ulong build_tdata1(CPURISCVState *env, | ||
46 | + trigger_type_t type, | ||
47 | + bool dmode, target_ulong data) | ||
48 | { | ||
49 | target_ulong tdata1; | ||
50 | |||
51 | switch (riscv_cpu_mxl(env)) { | ||
52 | case MXL_RV32: | ||
53 | - tdata1 = RV32_TYPE(type); | ||
54 | + tdata1 = RV32_TYPE(type) | | ||
55 | + (dmode ? RV32_DMODE : 0) | | ||
56 | + (data & RV32_DATA_MASK); | ||
56 | break; | 57 | break; |
57 | case MMU_DATA_LOAD: | 58 | case MXL_RV64: |
58 | - if (two_stage && !first_stage) { | 59 | case MXL_RV128: |
59 | + if (pmp_violation) { | 60 | - tdata1 = RV64_TYPE(type); |
60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; | 61 | + tdata1 = RV64_TYPE(type) | |
61 | + } else if (two_stage && !first_stage) { | 62 | + (dmode ? RV64_DMODE : 0) | |
62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; | 63 | + (data & RV64_DATA_MASK); |
63 | } else { | ||
64 | - cs->exception_index = pmp_violation ? | ||
65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; | ||
66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; | ||
67 | } | ||
68 | break; | ||
69 | case MMU_DATA_STORE: | ||
70 | - if (two_stage && !first_stage) { | ||
71 | + if (pmp_violation) { | ||
72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; | ||
73 | + } else if (two_stage && !first_stage) { | ||
74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; | ||
75 | } else { | ||
76 | - cs->exception_index = pmp_violation ? | ||
77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : | ||
78 | - RISCV_EXCP_STORE_PAGE_FAULT; | ||
79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; | ||
80 | } | ||
81 | break; | 64 | break; |
82 | default: | 65 | default: |
66 | g_assert_not_reached(); | ||
67 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) | ||
68 | |||
69 | void riscv_trigger_init(CPURISCVState *env) | ||
70 | { | ||
71 | - target_ulong tdata1 = trigger_type(env, TRIGGER_TYPE_AD_MATCH); | ||
72 | + target_ulong tdata1 = build_tdata1(env, TRIGGER_TYPE_AD_MATCH, 0, 0); | ||
73 | int i; | ||
74 | |||
75 | /* init to type 2 triggers */ | ||
83 | -- | 76 | -- |
84 | 2.45.1 | 77 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr | 3 | Replace type2_trigger_t with the real tdata1, tdata2, and tdata3 CSRs, |
4 | enabled, will fail with a kernel oops SIGILL right at the start. The | 4 | which allows us to support more types of triggers in the future. |
5 | reason is that we can't expose zkr without implementing the SEED CSR. | ||
6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't | ||
7 | allow it we'll error out and never boot. | ||
8 | 5 | ||
9 | In hindsight this is too strict. If we keep proceeding, despite not | 6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
10 | disabling the extension in the KVM vcpu, we'll not add the extension in | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. | 8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
13 | it's ok to keep booting in this case. | 10 | Message-Id: <20220909134215.1843865-4-bmeng.cn@gmail.com> |
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> | ||
34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
35 | --- | 12 | --- |
36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- | 13 | target/riscv/cpu.h | 6 ++- |
37 | 1 file changed, 8 insertions(+), 4 deletions(-) | 14 | target/riscv/debug.h | 7 --- |
15 | target/riscv/debug.c | 103 +++++++++++++++-------------------------- | ||
16 | target/riscv/machine.c | 20 ++------ | ||
17 | 4 files changed, 48 insertions(+), 88 deletions(-) | ||
38 | 18 | ||
39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
40 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/riscv/kvm/kvm-cpu.c | 21 | --- a/target/riscv/cpu.h |
42 | +++ b/target/riscv/kvm/kvm-cpu.c | 22 | +++ b/target/riscv/cpu.h |
43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) | 23 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { |
44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); | 24 | |
45 | ret = kvm_set_one_reg(cs, id, ®); | 25 | /* trigger module */ |
46 | if (ret != 0) { | 26 | target_ulong trigger_cur; |
47 | - error_report("Unable to %s extension %s in KVM, error %d", | 27 | - type2_trigger_t type2_trig[RV_MAX_TRIGGERS]; |
48 | - reg ? "enable" : "disable", | 28 | + target_ulong tdata1[RV_MAX_TRIGGERS]; |
49 | - multi_ext_cfg->name, ret); | 29 | + target_ulong tdata2[RV_MAX_TRIGGERS]; |
50 | - exit(EXIT_FAILURE); | 30 | + target_ulong tdata3[RV_MAX_TRIGGERS]; |
51 | + if (!reg && ret == -EINVAL) { | 31 | + struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS]; |
52 | + warn_report("KVM cannot disable extension %s", | 32 | + struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS]; |
53 | + multi_ext_cfg->name); | 33 | |
54 | + } else { | 34 | /* machine specific rdtime callback */ |
55 | + error_report("Unable to enable extension %s in KVM, error %d", | 35 | uint64_t (*rdtime_fn)(void *); |
56 | + multi_ext_cfg->name, ret); | 36 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h |
57 | + exit(EXIT_FAILURE); | 37 | index XXXXXXX..XXXXXXX 100644 |
58 | + } | 38 | --- a/target/riscv/debug.h |
39 | +++ b/target/riscv/debug.h | ||
40 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
41 | TRIGGER_TYPE_NUM | ||
42 | } trigger_type_t; | ||
43 | |||
44 | -typedef struct { | ||
45 | - target_ulong mcontrol; | ||
46 | - target_ulong maddress; | ||
47 | - struct CPUBreakpoint *bp; | ||
48 | - struct CPUWatchpoint *wp; | ||
49 | -} type2_trigger_t; | ||
50 | - | ||
51 | /* tdata1 field masks */ | ||
52 | |||
53 | #define RV32_TYPE(t) ((uint32_t)(t) << 28) | ||
54 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/riscv/debug.c | ||
57 | +++ b/target/riscv/debug.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong extract_trigger_type(CPURISCVState *env, | ||
59 | static inline target_ulong get_trigger_type(CPURISCVState *env, | ||
60 | target_ulong trigger_index) | ||
61 | { | ||
62 | - target_ulong tdata1 = env->type2_trig[trigger_index].mcontrol; | ||
63 | - return extract_trigger_type(env, tdata1); | ||
64 | + return extract_trigger_type(env, env->tdata1[trigger_index]); | ||
65 | } | ||
66 | |||
67 | static inline target_ulong build_tdata1(CPURISCVState *env, | ||
68 | @@ -XXX,XX +XXX,XX @@ static inline void warn_always_zero_bit(target_ulong val, target_ulong mask, | ||
69 | } | ||
70 | } | ||
71 | |||
72 | +/* type 2 trigger */ | ||
73 | + | ||
74 | static uint32_t type2_breakpoint_size(CPURISCVState *env, target_ulong ctrl) | ||
75 | { | ||
76 | uint32_t size, sizelo, sizehi = 0; | ||
77 | @@ -XXX,XX +XXX,XX @@ static target_ulong type2_mcontrol_validate(CPURISCVState *env, | ||
78 | |||
79 | static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) | ||
80 | { | ||
81 | - target_ulong ctrl = env->type2_trig[index].mcontrol; | ||
82 | - target_ulong addr = env->type2_trig[index].maddress; | ||
83 | + target_ulong ctrl = env->tdata1[index]; | ||
84 | + target_ulong addr = env->tdata2[index]; | ||
85 | bool enabled = type2_breakpoint_enabled(ctrl); | ||
86 | CPUState *cs = env_cpu(env); | ||
87 | int flags = BP_CPU | BP_STOP_BEFORE_ACCESS; | ||
88 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) | ||
89 | } | ||
90 | |||
91 | if (ctrl & TYPE2_EXEC) { | ||
92 | - cpu_breakpoint_insert(cs, addr, flags, &env->type2_trig[index].bp); | ||
93 | + cpu_breakpoint_insert(cs, addr, flags, &env->cpu_breakpoint[index]); | ||
94 | } | ||
95 | |||
96 | if (ctrl & TYPE2_LOAD) { | ||
97 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) | ||
98 | size = type2_breakpoint_size(env, ctrl); | ||
99 | if (size != 0) { | ||
100 | cpu_watchpoint_insert(cs, addr, size, flags, | ||
101 | - &env->type2_trig[index].wp); | ||
102 | + &env->cpu_watchpoint[index]); | ||
103 | } else { | ||
104 | cpu_watchpoint_insert(cs, addr, 8, flags, | ||
105 | - &env->type2_trig[index].wp); | ||
106 | + &env->cpu_watchpoint[index]); | ||
59 | } | 107 | } |
60 | } | 108 | } |
61 | } | 109 | } |
110 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_remove(CPURISCVState *env, target_ulong index) | ||
111 | { | ||
112 | CPUState *cs = env_cpu(env); | ||
113 | |||
114 | - if (env->type2_trig[index].bp) { | ||
115 | - cpu_breakpoint_remove_by_ref(cs, env->type2_trig[index].bp); | ||
116 | - env->type2_trig[index].bp = NULL; | ||
117 | + if (env->cpu_breakpoint[index]) { | ||
118 | + cpu_breakpoint_remove_by_ref(cs, env->cpu_breakpoint[index]); | ||
119 | + env->cpu_breakpoint[index] = NULL; | ||
120 | } | ||
121 | |||
122 | - if (env->type2_trig[index].wp) { | ||
123 | - cpu_watchpoint_remove_by_ref(cs, env->type2_trig[index].wp); | ||
124 | - env->type2_trig[index].wp = NULL; | ||
125 | + if (env->cpu_watchpoint[index]) { | ||
126 | + cpu_watchpoint_remove_by_ref(cs, env->cpu_watchpoint[index]); | ||
127 | + env->cpu_watchpoint[index] = NULL; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | -static target_ulong type2_reg_read(CPURISCVState *env, | ||
132 | - target_ulong index, int tdata_index) | ||
133 | -{ | ||
134 | - target_ulong tdata; | ||
135 | - | ||
136 | - switch (tdata_index) { | ||
137 | - case TDATA1: | ||
138 | - tdata = env->type2_trig[index].mcontrol; | ||
139 | - break; | ||
140 | - case TDATA2: | ||
141 | - tdata = env->type2_trig[index].maddress; | ||
142 | - break; | ||
143 | - default: | ||
144 | - g_assert_not_reached(); | ||
145 | - } | ||
146 | - | ||
147 | - return tdata; | ||
148 | -} | ||
149 | - | ||
150 | static void type2_reg_write(CPURISCVState *env, target_ulong index, | ||
151 | int tdata_index, target_ulong val) | ||
152 | { | ||
153 | @@ -XXX,XX +XXX,XX @@ static void type2_reg_write(CPURISCVState *env, target_ulong index, | ||
154 | switch (tdata_index) { | ||
155 | case TDATA1: | ||
156 | new_val = type2_mcontrol_validate(env, val); | ||
157 | - if (new_val != env->type2_trig[index].mcontrol) { | ||
158 | - env->type2_trig[index].mcontrol = new_val; | ||
159 | + if (new_val != env->tdata1[index]) { | ||
160 | + env->tdata1[index] = new_val; | ||
161 | type2_breakpoint_remove(env, index); | ||
162 | type2_breakpoint_insert(env, index); | ||
163 | } | ||
164 | break; | ||
165 | case TDATA2: | ||
166 | - if (val != env->type2_trig[index].maddress) { | ||
167 | - env->type2_trig[index].maddress = val; | ||
168 | + if (val != env->tdata2[index]) { | ||
169 | + env->tdata2[index] = val; | ||
170 | type2_breakpoint_remove(env, index); | ||
171 | type2_breakpoint_insert(env, index); | ||
172 | } | ||
173 | break; | ||
174 | + case TDATA3: | ||
175 | + qemu_log_mask(LOG_UNIMP, | ||
176 | + "tdata3 is not supported for type 2 trigger\n"); | ||
177 | + break; | ||
178 | default: | ||
179 | g_assert_not_reached(); | ||
180 | } | ||
181 | @@ -XXX,XX +XXX,XX @@ static void type2_reg_write(CPURISCVState *env, target_ulong index, | ||
182 | |||
183 | target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index) | ||
184 | { | ||
185 | - int trigger_type = get_trigger_type(env, env->trigger_cur); | ||
186 | - | ||
187 | - switch (trigger_type) { | ||
188 | - case TRIGGER_TYPE_AD_MATCH: | ||
189 | - return type2_reg_read(env, env->trigger_cur, tdata_index); | ||
190 | - break; | ||
191 | - case TRIGGER_TYPE_INST_CNT: | ||
192 | - case TRIGGER_TYPE_INT: | ||
193 | - case TRIGGER_TYPE_EXCP: | ||
194 | - case TRIGGER_TYPE_AD_MATCH6: | ||
195 | - case TRIGGER_TYPE_EXT_SRC: | ||
196 | - qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", | ||
197 | - trigger_type); | ||
198 | - break; | ||
199 | - case TRIGGER_TYPE_NO_EXIST: | ||
200 | - case TRIGGER_TYPE_UNAVAIL: | ||
201 | - qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d does not exit\n", | ||
202 | - trigger_type); | ||
203 | - break; | ||
204 | + switch (tdata_index) { | ||
205 | + case TDATA1: | ||
206 | + return env->tdata1[env->trigger_cur]; | ||
207 | + case TDATA2: | ||
208 | + return env->tdata2[env->trigger_cur]; | ||
209 | + case TDATA3: | ||
210 | + return env->tdata3[env->trigger_cur]; | ||
211 | default: | ||
212 | g_assert_not_reached(); | ||
213 | } | ||
214 | - | ||
215 | - return 0; | ||
216 | } | ||
217 | |||
218 | void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) | ||
219 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | ||
220 | |||
221 | switch (trigger_type) { | ||
222 | case TRIGGER_TYPE_AD_MATCH: | ||
223 | - ctrl = env->type2_trig[i].mcontrol; | ||
224 | - pc = env->type2_trig[i].maddress; | ||
225 | + ctrl = env->tdata1[i]; | ||
226 | + pc = env->tdata2[i]; | ||
227 | |||
228 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { | ||
229 | /* check U/S/M bit against current privilege level */ | ||
230 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) | ||
231 | |||
232 | switch (trigger_type) { | ||
233 | case TRIGGER_TYPE_AD_MATCH: | ||
234 | - ctrl = env->type2_trig[i].mcontrol; | ||
235 | - addr = env->type2_trig[i].maddress; | ||
236 | + ctrl = env->tdata1[i]; | ||
237 | + addr = env->tdata2[i]; | ||
238 | flags = 0; | ||
239 | |||
240 | if (ctrl & TYPE2_LOAD) { | ||
241 | @@ -XXX,XX +XXX,XX @@ void riscv_trigger_init(CPURISCVState *env) | ||
242 | * chain = 0 (unimplemented, always 0) | ||
243 | * match = 0 (always 0, when any compare value equals tdata2) | ||
244 | */ | ||
245 | - env->type2_trig[i].mcontrol = tdata1; | ||
246 | - env->type2_trig[i].maddress = 0; | ||
247 | - env->type2_trig[i].bp = NULL; | ||
248 | - env->type2_trig[i].wp = NULL; | ||
249 | + env->tdata1[i] = tdata1; | ||
250 | + env->tdata2[i] = 0; | ||
251 | + env->tdata3[i] = 0; | ||
252 | + env->cpu_breakpoint[i] = NULL; | ||
253 | + env->cpu_watchpoint[i] = NULL; | ||
254 | } | ||
255 | } | ||
256 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
257 | index XXXXXXX..XXXXXXX 100644 | ||
258 | --- a/target/riscv/machine.c | ||
259 | +++ b/target/riscv/machine.c | ||
260 | @@ -XXX,XX +XXX,XX @@ static bool debug_needed(void *opaque) | ||
261 | return riscv_feature(env, RISCV_FEATURE_DEBUG); | ||
262 | } | ||
263 | |||
264 | -static const VMStateDescription vmstate_debug_type2 = { | ||
265 | - .name = "cpu/debug/type2", | ||
266 | - .version_id = 1, | ||
267 | - .minimum_version_id = 1, | ||
268 | - .fields = (VMStateField[]) { | ||
269 | - VMSTATE_UINTTL(mcontrol, type2_trigger_t), | ||
270 | - VMSTATE_UINTTL(maddress, type2_trigger_t), | ||
271 | - VMSTATE_END_OF_LIST() | ||
272 | - } | ||
273 | -}; | ||
274 | - | ||
275 | static const VMStateDescription vmstate_debug = { | ||
276 | .name = "cpu/debug", | ||
277 | - .version_id = 1, | ||
278 | - .minimum_version_id = 1, | ||
279 | + .version_id = 2, | ||
280 | + .minimum_version_id = 2, | ||
281 | .needed = debug_needed, | ||
282 | .fields = (VMStateField[]) { | ||
283 | VMSTATE_UINTTL(env.trigger_cur, RISCVCPU), | ||
284 | - VMSTATE_STRUCT_ARRAY(env.type2_trig, RISCVCPU, RV_MAX_TRIGGERS, | ||
285 | - 0, vmstate_debug_type2, type2_trigger_t), | ||
286 | + VMSTATE_UINTTL_ARRAY(env.tdata1, RISCVCPU, RV_MAX_TRIGGERS), | ||
287 | + VMSTATE_UINTTL_ARRAY(env.tdata2, RISCVCPU, RV_MAX_TRIGGERS), | ||
288 | + VMSTATE_UINTTL_ARRAY(env.tdata3, RISCVCPU, RV_MAX_TRIGGERS), | ||
289 | VMSTATE_END_OF_LIST() | ||
290 | } | ||
291 | }; | ||
62 | -- | 292 | -- |
63 | 2.45.1 | 293 | 2.37.3 | diff view generated by jsdifflib |
1 | From: "yang.zhang" <yang.zhang@hexintek.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Since only root APLICs can have hw IRQ lines, aplic->parent should | 3 | The value of tselect CSR can be written should be limited within the |
4 | be initialized first. | 4 | range of supported triggers number. |
5 | 5 | ||
6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") | 6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> | 8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
9 | Cc: qemu-stable <qemu-stable@nongnu.org> | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> | 10 | Message-Id: <20220909134215.1843865-5-bmeng.cn@gmail.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 12 | --- |
13 | hw/intc/riscv_aplic.c | 8 ++++---- | 13 | target/riscv/debug.c | 9 +++------ |
14 | 1 file changed, 4 insertions(+), 4 deletions(-) | 14 | 1 file changed, 3 insertions(+), 6 deletions(-) |
15 | 15 | ||
16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | 16 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/intc/riscv_aplic.c | 18 | --- a/target/riscv/debug.c |
19 | +++ b/hw/intc/riscv_aplic.c | 19 | +++ b/target/riscv/debug.c |
20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, | 20 | @@ -XXX,XX +XXX,XX @@ bool tdata_available(CPURISCVState *env, int tdata_index) |
21 | qdev_prop_set_bit(dev, "msimode", msimode); | 21 | return false; |
22 | qdev_prop_set_bit(dev, "mmode", mmode); | ||
23 | |||
24 | + if (parent) { | ||
25 | + riscv_aplic_add_child(parent, dev); | ||
26 | + } | ||
27 | + | ||
28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
29 | |||
30 | if (!is_kvm_aia(msimode)) { | ||
31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
32 | } | 22 | } |
33 | 23 | ||
34 | - if (parent) { | 24 | - if (unlikely(env->trigger_cur >= RV_MAX_TRIGGERS)) { |
35 | - riscv_aplic_add_child(parent, dev); | 25 | - return false; |
36 | - } | 26 | - } |
37 | - | 27 | - |
38 | if (!msimode) { | 28 | return tdata_mapping[trigger_type][tdata_index]; |
39 | for (i = 0; i < num_harts; i++) { | 29 | } |
40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); | 30 | |
31 | @@ -XXX,XX +XXX,XX @@ target_ulong tselect_csr_read(CPURISCVState *env) | ||
32 | |||
33 | void tselect_csr_write(CPURISCVState *env, target_ulong val) | ||
34 | { | ||
35 | - /* all target_ulong bits of tselect are implemented */ | ||
36 | - env->trigger_cur = val; | ||
37 | + if (val < RV_MAX_TRIGGERS) { | ||
38 | + env->trigger_cur = val; | ||
39 | + } | ||
40 | } | ||
41 | |||
42 | static target_ulong tdata1_validate(CPURISCVState *env, target_ulong val, | ||
41 | -- | 43 | -- |
42 | 2.45.1 | 44 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Yu-Ming Chang <yumin686@andestech.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side | 3 | tinfo.info: |
4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register | 4 | One bit for each possible type enumerated in tdata1. |
5 | holding a zero value other than x0, the instruction will still attempt to write | 5 | If the bit is set, then that type is supported by the currently |
6 | the unmodified value back to the CSR and will cause any attendant side effects. | 6 | selected trigger. |
7 | 7 | ||
8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies | 8 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
9 | a register holding a zero value, an illegal instruction exception should be | 9 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
10 | raised. | 10 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
11 | 11 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | |
12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> | 12 | Message-Id: <20220909134215.1843865-6-bmeng.cn@gmail.com> |
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 14 | --- |
17 | target/riscv/cpu.h | 4 ++++ | 15 | target/riscv/cpu_bits.h | 1 + |
18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- | 16 | target/riscv/debug.h | 2 ++ |
19 | target/riscv/op_helper.c | 6 ++--- | 17 | target/riscv/csr.c | 8 ++++++++ |
20 | 3 files changed, 53 insertions(+), 8 deletions(-) | 18 | target/riscv/debug.c | 10 +++++++--- |
19 | 4 files changed, 18 insertions(+), 3 deletions(-) | ||
21 | 20 | ||
22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 21 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
23 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/cpu.h | 23 | --- a/target/riscv/cpu_bits.h |
25 | +++ b/target/riscv/cpu.h | 24 | +++ b/target/riscv/cpu_bits.h |
26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | 25 | @@ -XXX,XX +XXX,XX @@ |
27 | void riscv_cpu_update_mask(CPURISCVState *env); | 26 | #define CSR_TDATA1 0x7a1 |
28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); | 27 | #define CSR_TDATA2 0x7a2 |
29 | 28 | #define CSR_TDATA3 0x7a3 | |
30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, | 29 | +#define CSR_TINFO 0x7a4 |
31 | + target_ulong *ret_value); | 30 | |
32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | 31 | /* Debug Mode Registers */ |
33 | target_ulong *ret_value, | 32 | #define CSR_DCSR 0x7b0 |
34 | target_ulong new_value, target_ulong write_mask); | 33 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h |
35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, | 34 | index XXXXXXX..XXXXXXX 100644 |
36 | target_ulong new_value, | 35 | --- a/target/riscv/debug.h |
37 | target_ulong write_mask); | 36 | +++ b/target/riscv/debug.h |
38 | 37 | @@ -XXX,XX +XXX,XX @@ void tselect_csr_write(CPURISCVState *env, target_ulong val); | |
39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | 38 | target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index); |
40 | + Int128 *ret_value); | 39 | void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val); |
41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | 40 | |
42 | Int128 *ret_value, | 41 | +target_ulong tinfo_csr_read(CPURISCVState *env); |
43 | Int128 new_value, Int128 write_mask); | 42 | + |
43 | void riscv_cpu_debug_excp_handler(CPUState *cs); | ||
44 | bool riscv_cpu_debug_check_breakpoint(CPUState *cs); | ||
45 | bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp); | ||
44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 46 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
45 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/target/riscv/csr.c | 48 | --- a/target/riscv/csr.c |
47 | +++ b/target/riscv/csr.c | 49 | +++ b/target/riscv/csr.c |
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, | 50 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_tdata(CPURISCVState *env, int csrno, |
49 | |||
50 | static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
51 | int csrno, | ||
52 | - bool write_mask) | ||
53 | + bool write) | ||
54 | { | ||
55 | /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ | ||
56 | bool read_only = get_field(csrno, 0xC00) == 3; | ||
57 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
58 | } | ||
59 | |||
60 | /* read / write check */ | ||
61 | - if (write_mask && read_only) { | ||
62 | + if (write && read_only) { | ||
63 | return RISCV_EXCP_ILLEGAL_INST; | ||
64 | } | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno, | ||
67 | return RISCV_EXCP_NONE; | 51 | return RISCV_EXCP_NONE; |
68 | } | 52 | } |
69 | 53 | ||
70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, | 54 | +static RISCVException read_tinfo(CPURISCVState *env, int csrno, |
71 | + target_ulong *ret_value) | 55 | + target_ulong *val) |
72 | +{ | 56 | +{ |
73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); | 57 | + *val = tinfo_csr_read(env); |
74 | + if (ret != RISCV_EXCP_NONE) { | 58 | + return RISCV_EXCP_NONE; |
75 | + return ret; | ||
76 | + } | ||
77 | + | ||
78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); | ||
79 | +} | 59 | +} |
80 | + | 60 | + |
81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | 61 | /* |
82 | target_ulong *ret_value, | 62 | * Functions to access Pointer Masking feature registers |
83 | target_ulong new_value, target_ulong write_mask) | 63 | * We have to check if current priv lvl could modify |
84 | { | 64 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { |
85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); | 65 | [CSR_TDATA1] = { "tdata1", debug, read_tdata, write_tdata }, |
86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); | 66 | [CSR_TDATA2] = { "tdata2", debug, read_tdata, write_tdata }, |
87 | if (ret != RISCV_EXCP_NONE) { | 67 | [CSR_TDATA3] = { "tdata3", debug, read_tdata, write_tdata }, |
88 | return ret; | 68 | + [CSR_TINFO] = { "tinfo", debug, read_tinfo, write_ignore }, |
69 | |||
70 | /* User Pointer Masking */ | ||
71 | [CSR_UMTE] = { "umte", pointer_masking, read_umte, write_umte }, | ||
72 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/target/riscv/debug.c | ||
75 | +++ b/target/riscv/debug.c | ||
76 | @@ -XXX,XX +XXX,XX @@ | ||
77 | * - tdata1 | ||
78 | * - tdata2 | ||
79 | * - tdata3 | ||
80 | - * | ||
81 | - * We don't support writable 'type' field in the tdata1 register, so there is | ||
82 | - * no need to implement the "tinfo" CSR. | ||
83 | + * - tinfo | ||
84 | * | ||
85 | * The following triggers are implemented: | ||
86 | * | ||
87 | @@ -XXX,XX +XXX,XX @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) | ||
89 | } | 88 | } |
90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, | ||
91 | return RISCV_EXCP_NONE; | ||
92 | } | 89 | } |
93 | 90 | ||
94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | 91 | +target_ulong tinfo_csr_read(CPURISCVState *env) |
95 | + Int128 *ret_value) | ||
96 | +{ | 92 | +{ |
97 | + RISCVException ret; | 93 | + /* assume all triggers support the same types of triggers */ |
98 | + | 94 | + return BIT(TRIGGER_TYPE_AD_MATCH); |
99 | + ret = riscv_csrrw_check(env, csrno, false); | ||
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; | ||
124 | +} | 95 | +} |
125 | + | 96 | + |
126 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | 97 | void riscv_cpu_debug_excp_handler(CPUState *cs) |
127 | Int128 *ret_value, | ||
128 | Int128 new_value, Int128 write_mask) | ||
129 | { | 98 | { |
130 | RISCVException ret; | 99 | RISCVCPU *cpu = RISCV_CPU(cs); |
131 | |||
132 | - ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask)); | ||
133 | + ret = riscv_csrrw_check(env, csrno, true); | ||
134 | if (ret != RISCV_EXCP_NONE) { | ||
135 | return ret; | ||
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()); | ||
161 | -- | 100 | -- |
162 | 2.45.1 | 101 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Max Chou <max.chou@sifive.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w | 3 | Trigger actions are shared among all triggers. Extract to a common |
4 | instructions will be affected by Zvfhmin extension. | 4 | function. |
5 | And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the | ||
6 | conversions of | ||
7 | 5 | ||
8 | * From 1*SEW(16/32) to 2*SEW(32/64) | 6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
9 | * From 2*SEW(32/64) to 1*SEW(16/32) | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
10 | 8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | |
11 | Signed-off-by: Max Chou <max.chou@sifive.com> | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 10 | [bmeng: handle the DBG_ACTION_NONE case] |
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | 11 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
14 | Message-ID: <20240322092600.1198921-2-max.chou@sifive.com> | 12 | Message-Id: <20220909134215.1843865-7-bmeng.cn@gmail.com> |
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 14 | --- |
17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- | 15 | target/riscv/debug.h | 13 ++++++++++ |
18 | 1 file changed, 18 insertions(+), 2 deletions(-) | 16 | target/riscv/debug.c | 59 ++++++++++++++++++++++++++++++++++++++++++-- |
17 | 2 files changed, 70 insertions(+), 2 deletions(-) | ||
19 | 18 | ||
20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 19 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h |
21 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 21 | --- a/target/riscv/debug.h |
23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 22 | +++ b/target/riscv/debug.h |
24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
24 | TRIGGER_TYPE_NUM | ||
25 | } trigger_type_t; | ||
26 | |||
27 | +/* actions */ | ||
28 | +typedef enum { | ||
29 | + DBG_ACTION_NONE = -1, /* sentinel value */ | ||
30 | + DBG_ACTION_BP = 0, | ||
31 | + DBG_ACTION_DBG_MODE, | ||
32 | + DBG_ACTION_TRACE0, | ||
33 | + DBG_ACTION_TRACE1, | ||
34 | + DBG_ACTION_TRACE2, | ||
35 | + DBG_ACTION_TRACE3, | ||
36 | + DBG_ACTION_EXT_DBG0 = 8, | ||
37 | + DBG_ACTION_EXT_DBG1 | ||
38 | +} trigger_action_t; | ||
39 | + | ||
40 | /* tdata1 field masks */ | ||
41 | |||
42 | #define RV32_TYPE(t) ((uint32_t)(t) << 28) | ||
43 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/riscv/debug.c | ||
46 | +++ b/target/riscv/debug.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong get_trigger_type(CPURISCVState *env, | ||
48 | return extract_trigger_type(env, env->tdata1[trigger_index]); | ||
49 | } | ||
50 | |||
51 | +static trigger_action_t get_trigger_action(CPURISCVState *env, | ||
52 | + target_ulong trigger_index) | ||
53 | +{ | ||
54 | + target_ulong tdata1 = env->tdata1[trigger_index]; | ||
55 | + int trigger_type = get_trigger_type(env, trigger_index); | ||
56 | + trigger_action_t action = DBG_ACTION_NONE; | ||
57 | + | ||
58 | + switch (trigger_type) { | ||
59 | + case TRIGGER_TYPE_AD_MATCH: | ||
60 | + action = (tdata1 & TYPE2_ACTION) >> 12; | ||
61 | + break; | ||
62 | + case TRIGGER_TYPE_INST_CNT: | ||
63 | + case TRIGGER_TYPE_INT: | ||
64 | + case TRIGGER_TYPE_EXCP: | ||
65 | + case TRIGGER_TYPE_AD_MATCH6: | ||
66 | + case TRIGGER_TYPE_EXT_SRC: | ||
67 | + qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", | ||
68 | + trigger_type); | ||
69 | + break; | ||
70 | + case TRIGGER_TYPE_NO_EXIST: | ||
71 | + case TRIGGER_TYPE_UNAVAIL: | ||
72 | + qemu_log_mask(LOG_GUEST_ERROR, "trigger type: %d does not exit\n", | ||
73 | + trigger_type); | ||
74 | + break; | ||
75 | + default: | ||
76 | + g_assert_not_reached(); | ||
77 | + } | ||
78 | + | ||
79 | + return action; | ||
80 | +} | ||
81 | + | ||
82 | static inline target_ulong build_tdata1(CPURISCVState *env, | ||
83 | trigger_type_t type, | ||
84 | bool dmode, target_ulong data) | ||
85 | @@ -XXX,XX +XXX,XX @@ static inline void warn_always_zero_bit(target_ulong val, target_ulong mask, | ||
25 | } | 86 | } |
26 | } | 87 | } |
27 | 88 | ||
28 | +static bool require_rvfmin(DisasContext *s) | 89 | +static void do_trigger_action(CPURISCVState *env, target_ulong trigger_index) |
29 | +{ | 90 | +{ |
30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { | 91 | + trigger_action_t action = get_trigger_action(env, trigger_index); |
31 | + return false; | ||
32 | + } | ||
33 | + | 92 | + |
34 | + switch (s->sew) { | 93 | + switch (action) { |
35 | + case MO_16: | 94 | + case DBG_ACTION_NONE: |
36 | + return s->cfg_ptr->ext_zvfhmin; | 95 | + break; |
37 | + case MO_32: | 96 | + case DBG_ACTION_BP: |
38 | + return s->cfg_ptr->ext_zve32f; | 97 | + riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); |
98 | + break; | ||
99 | + case DBG_ACTION_DBG_MODE: | ||
100 | + case DBG_ACTION_TRACE0: | ||
101 | + case DBG_ACTION_TRACE1: | ||
102 | + case DBG_ACTION_TRACE2: | ||
103 | + case DBG_ACTION_TRACE3: | ||
104 | + case DBG_ACTION_EXT_DBG0: | ||
105 | + case DBG_ACTION_EXT_DBG1: | ||
106 | + qemu_log_mask(LOG_UNIMP, "action: %d is not supported\n", action); | ||
107 | + break; | ||
39 | + default: | 108 | + default: |
40 | + return false; | 109 | + g_assert_not_reached(); |
41 | + } | 110 | + } |
42 | +} | 111 | +} |
43 | + | 112 | + |
44 | static bool require_scale_rvf(DisasContext *s) | 113 | /* type 2 trigger */ |
45 | { | 114 | |
46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { | 115 | static uint32_t type2_breakpoint_size(CPURISCVState *env, target_ulong ctrl) |
47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) | 116 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_debug_excp_handler(CPUState *cs) |
117 | if (cs->watchpoint_hit) { | ||
118 | if (cs->watchpoint_hit->flags & BP_CPU) { | ||
119 | cs->watchpoint_hit = NULL; | ||
120 | - riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); | ||
121 | + do_trigger_action(env, DBG_ACTION_BP); | ||
122 | } | ||
123 | } else { | ||
124 | if (cpu_breakpoint_test(cs, env->pc, BP_CPU)) { | ||
125 | - riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); | ||
126 | + do_trigger_action(env, DBG_ACTION_BP); | ||
127 | } | ||
48 | } | 128 | } |
49 | |||
50 | switch (s->sew) { | ||
51 | - case MO_8: | ||
52 | - return s->cfg_ptr->ext_zvfhmin; | ||
53 | case MO_16: | ||
54 | return s->cfg_ptr->ext_zve32f; | ||
55 | case MO_32: | ||
56 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) | ||
57 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
58 | { | ||
59 | return opfv_widen_check(s, a) && | ||
60 | + require_rvfmin(s) && | ||
61 | require_scale_rvfmin(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | ||
65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
66 | { | ||
67 | return opfv_narrow_check(s, a) && | ||
68 | + require_rvfmin(s) && | ||
69 | require_scale_rvfmin(s) && | ||
70 | (s->sew != MO_8); | ||
71 | } | 129 | } |
72 | -- | 130 | -- |
73 | 2.45.1 | 131 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | We're not setting (s/m)tval when triggering breakpoints of type 2 | 3 | Type 2 trigger cannot be fired in VU/VS modes. |
4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section | ||
5 | 5.7.12, "Match Control Type 6": | ||
6 | 4 | ||
7 | "The Privileged Spec says that breakpoint exceptions that occur on | 5 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
8 | instruction fetches, loads, or stores update the tval CSR with either | 6 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
9 | zero or the faulting virtual address. The faulting virtual address for | 7 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
10 | an mcontrol6 trigger with action = 0 is the address being accessed and | 8 | Message-Id: <20220909134215.1843865-8-bmeng.cn@gmail.com> |
11 | which caused that trigger to fire." | ||
12 | |||
13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. | ||
14 | mcontrol. | ||
15 | |||
16 | Note that what we're doing ATM is not violating the spec, but it's | ||
17 | simple enough to set mtval/stval and it makes life easier for any | ||
18 | software that relies on this info. | ||
19 | |||
20 | Given that we always use action = 0, save the faulting address for the | ||
21 | mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is | ||
22 | used as as scratch area for traps with address information. 'tval' is | ||
23 | then set during riscv_cpu_do_interrupt(). | ||
24 | |||
25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> | ||
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
30 | --- | 10 | --- |
31 | target/riscv/cpu_helper.c | 1 + | 11 | target/riscv/debug.c | 10 ++++++++++ |
32 | target/riscv/debug.c | 3 +++ | 12 | 1 file changed, 10 insertions(+) |
33 | 2 files changed, 4 insertions(+) | ||
34 | 13 | ||
35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/cpu_helper.c | ||
38 | +++ b/target/riscv/cpu_helper.c | ||
39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | ||
40 | tval = env->bins; | ||
41 | break; | ||
42 | case RISCV_EXCP_BREAKPOINT: | ||
43 | + tval = env->badaddr; | ||
44 | if (cs->watchpoint_hit) { | ||
45 | tval = cs->watchpoint_hit->hitaddr; | ||
46 | cs->watchpoint_hit = NULL; | ||
47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | 14 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
48 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/target/riscv/debug.c | 16 | --- a/target/riscv/debug.c |
50 | +++ b/target/riscv/debug.c | 17 | +++ b/target/riscv/debug.c |
51 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | 18 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
52 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { | 19 | |
53 | /* check U/S/M bit against current privilege level */ | 20 | switch (trigger_type) { |
54 | if ((ctrl >> 3) & BIT(env->priv)) { | 21 | case TRIGGER_TYPE_AD_MATCH: |
55 | + env->badaddr = pc; | 22 | + /* type 2 trigger cannot be fired in VU/VS mode */ |
56 | return true; | 23 | + if (riscv_cpu_virt_enabled(env)) { |
57 | } | 24 | + return false; |
58 | } | 25 | + } |
59 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | 26 | + |
60 | if (env->virt_enabled) { | 27 | ctrl = env->tdata1[i]; |
61 | /* check VU/VS bit against current privilege level */ | 28 | pc = env->tdata2[i]; |
62 | if ((ctrl >> 23) & BIT(env->priv)) { | 29 | |
63 | + env->badaddr = pc; | 30 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) |
64 | return true; | 31 | |
65 | } | 32 | switch (trigger_type) { |
66 | } else { | 33 | case TRIGGER_TYPE_AD_MATCH: |
67 | /* check U/S/M bit against current privilege level */ | 34 | + /* type 2 trigger cannot be fired in VU/VS mode */ |
68 | if ((ctrl >> 3) & BIT(env->priv)) { | 35 | + if (riscv_cpu_virt_enabled(env)) { |
69 | + env->badaddr = pc; | 36 | + return false; |
70 | return true; | 37 | + } |
71 | } | 38 | + |
72 | } | 39 | ctrl = env->tdata1[i]; |
40 | addr = env->tdata2[i]; | ||
41 | flags = 0; | ||
73 | -- | 42 | -- |
74 | 2.45.1 | 43 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Huang Tao <eric.huang@linux.alibaba.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | In this patch, we modify the decoder to be a freely composable data | 3 | Type 6 trigger is similar to a type 2 trigger, but provides additional |
4 | structure instead of a hardcoded one. It can be dynamically builded up | 4 | functionality and should be used instead of type 2 in newer |
5 | according to the extensions. | 5 | implementations. |
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. | ||
20 | 6 | ||
21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> | 7 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> | 8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 9 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Message-Id: <20220909134215.1843865-9-bmeng.cn@gmail.com> |
25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 12 | --- |
29 | target/riscv/cpu.h | 1 + | 13 | target/riscv/debug.h | 18 +++++ |
30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ | 14 | target/riscv/debug.c | 174 ++++++++++++++++++++++++++++++++++++++++++- |
31 | target/riscv/cpu.c | 1 + | 15 | 2 files changed, 188 insertions(+), 4 deletions(-) |
32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ | ||
33 | target/riscv/translate.c | 31 +++++++++++++++---------------- | ||
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
35 | 16 | ||
36 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 17 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h |
37 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/target/riscv/cpu.h | 19 | --- a/target/riscv/debug.h |
39 | +++ b/target/riscv/cpu.h | 20 | +++ b/target/riscv/debug.h |
40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { | 21 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
41 | uint32_t pmu_avail_ctrs; | 22 | #define TYPE2_HIT BIT(20) |
42 | /* Mapping of events to counters */ | 23 | #define TYPE2_SIZEHI (0x3 << 21) /* RV64 only */ |
43 | GHashTable *pmu_event_ctr_map; | 24 | |
44 | + const GPtrArray *decoders; | 25 | +/* mcontrol6 field masks */ |
45 | }; | 26 | + |
46 | 27 | +#define TYPE6_LOAD BIT(0) | |
47 | /** | 28 | +#define TYPE6_STORE BIT(1) |
48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h | 29 | +#define TYPE6_EXEC BIT(2) |
30 | +#define TYPE6_U BIT(3) | ||
31 | +#define TYPE6_S BIT(4) | ||
32 | +#define TYPE6_M BIT(6) | ||
33 | +#define TYPE6_MATCH (0xf << 7) | ||
34 | +#define TYPE6_CHAIN BIT(11) | ||
35 | +#define TYPE6_ACTION (0xf << 12) | ||
36 | +#define TYPE6_SIZE (0xf << 16) | ||
37 | +#define TYPE6_TIMING BIT(20) | ||
38 | +#define TYPE6_SELECT BIT(21) | ||
39 | +#define TYPE6_HIT BIT(22) | ||
40 | +#define TYPE6_VU BIT(23) | ||
41 | +#define TYPE6_VS BIT(24) | ||
42 | + | ||
43 | /* access size */ | ||
44 | enum { | ||
45 | SIZE_ANY = 0, | ||
46 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/target/riscv/tcg/tcg-cpu.h | 48 | --- a/target/riscv/debug.c |
51 | +++ b/target/riscv/tcg/tcg-cpu.h | 49 | +++ b/target/riscv/debug.c |
52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | 50 | @@ -XXX,XX +XXX,XX @@ |
53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); | 51 | * - tdata3 |
54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); | 52 | * - tinfo |
55 | 53 | * | |
56 | +struct DisasContext; | 54 | - * The following triggers are implemented: |
57 | +struct RISCVCPUConfig; | 55 | + * The following triggers are initialized by default: |
58 | +typedef struct RISCVDecoder { | 56 | * |
59 | + bool (*guard_func)(const struct RISCVCPUConfig *); | 57 | * Index | Type | tdata mapping | Description |
60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | 58 | * ------+------+------------------------+------------ |
61 | +} RISCVDecoder; | 59 | @@ -XXX,XX +XXX,XX @@ static trigger_action_t get_trigger_action(CPURISCVState *env, |
62 | + | 60 | case TRIGGER_TYPE_AD_MATCH: |
63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | 61 | action = (tdata1 & TYPE2_ACTION) >> 12; |
64 | + | 62 | break; |
65 | +extern const size_t decoder_table_size; | 63 | + case TRIGGER_TYPE_AD_MATCH6: |
66 | + | 64 | + action = (tdata1 & TYPE6_ACTION) >> 12; |
67 | +extern const RISCVDecoder decoder_table[]; | 65 | + break; |
68 | + | 66 | case TRIGGER_TYPE_INST_CNT: |
69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); | 67 | case TRIGGER_TYPE_INT: |
70 | + | 68 | case TRIGGER_TYPE_EXCP: |
71 | #endif | 69 | - case TRIGGER_TYPE_AD_MATCH6: |
72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 70 | case TRIGGER_TYPE_EXT_SRC: |
73 | index XXXXXXX..XXXXXXX 100644 | 71 | qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", |
74 | --- a/target/riscv/cpu.c | 72 | trigger_type); |
75 | +++ b/target/riscv/cpu.c | 73 | @@ -XXX,XX +XXX,XX @@ static void type2_reg_write(CPURISCVState *env, target_ulong index, |
76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | 74 | return; |
77 | error_propagate(errp, local_err); | ||
78 | return; | ||
79 | } | ||
80 | + riscv_tcg_cpu_finalize_dynamic_decoder(cpu); | ||
81 | } else if (kvm_enabled()) { | ||
82 | riscv_kvm_cpu_finalize_features(cpu, &local_err); | ||
83 | if (local_err != NULL) { | ||
84 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/riscv/tcg/tcg-cpu.c | ||
87 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
88 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
89 | } | ||
90 | } | 75 | } |
91 | 76 | ||
92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) | 77 | +/* type 6 trigger */ |
93 | +{ | 78 | + |
94 | + GPtrArray *dynamic_decoders; | 79 | +static inline bool type6_breakpoint_enabled(target_ulong ctrl) |
95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); | 80 | +{ |
96 | + for (size_t i = 0; i < decoder_table_size; ++i) { | 81 | + bool mode = !!(ctrl & (TYPE6_VU | TYPE6_VS | TYPE6_U | TYPE6_S | TYPE6_M)); |
97 | + if (decoder_table[i].guard_func && | 82 | + bool rwx = !!(ctrl & (TYPE6_LOAD | TYPE6_STORE | TYPE6_EXEC)); |
98 | + decoder_table[i].guard_func(&cpu->cfg)) { | 83 | + |
99 | + g_ptr_array_add(dynamic_decoders, | 84 | + return mode && rwx; |
100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); | 85 | +} |
86 | + | ||
87 | +static target_ulong type6_mcontrol6_validate(CPURISCVState *env, | ||
88 | + target_ulong ctrl) | ||
89 | +{ | ||
90 | + target_ulong val; | ||
91 | + uint32_t size; | ||
92 | + | ||
93 | + /* validate the generic part first */ | ||
94 | + val = tdata1_validate(env, ctrl, TRIGGER_TYPE_AD_MATCH6); | ||
95 | + | ||
96 | + /* validate unimplemented (always zero) bits */ | ||
97 | + warn_always_zero_bit(ctrl, TYPE6_MATCH, "match"); | ||
98 | + warn_always_zero_bit(ctrl, TYPE6_CHAIN, "chain"); | ||
99 | + warn_always_zero_bit(ctrl, TYPE6_ACTION, "action"); | ||
100 | + warn_always_zero_bit(ctrl, TYPE6_TIMING, "timing"); | ||
101 | + warn_always_zero_bit(ctrl, TYPE6_SELECT, "select"); | ||
102 | + warn_always_zero_bit(ctrl, TYPE6_HIT, "hit"); | ||
103 | + | ||
104 | + /* validate size encoding */ | ||
105 | + size = extract32(ctrl, 16, 4); | ||
106 | + if (access_size[size] == -1) { | ||
107 | + qemu_log_mask(LOG_UNIMP, "access size %d is not supported, using SIZE_ANY\n", | ||
108 | + size); | ||
109 | + } else { | ||
110 | + val |= (ctrl & TYPE6_SIZE); | ||
111 | + } | ||
112 | + | ||
113 | + /* keep the mode and attribute bits */ | ||
114 | + val |= (ctrl & (TYPE6_VU | TYPE6_VS | TYPE6_U | TYPE6_S | TYPE6_M | | ||
115 | + TYPE6_LOAD | TYPE6_STORE | TYPE6_EXEC)); | ||
116 | + | ||
117 | + return val; | ||
118 | +} | ||
119 | + | ||
120 | +static void type6_breakpoint_insert(CPURISCVState *env, target_ulong index) | ||
121 | +{ | ||
122 | + target_ulong ctrl = env->tdata1[index]; | ||
123 | + target_ulong addr = env->tdata2[index]; | ||
124 | + bool enabled = type6_breakpoint_enabled(ctrl); | ||
125 | + CPUState *cs = env_cpu(env); | ||
126 | + int flags = BP_CPU | BP_STOP_BEFORE_ACCESS; | ||
127 | + uint32_t size; | ||
128 | + | ||
129 | + if (!enabled) { | ||
130 | + return; | ||
131 | + } | ||
132 | + | ||
133 | + if (ctrl & TYPE6_EXEC) { | ||
134 | + cpu_breakpoint_insert(cs, addr, flags, &env->cpu_breakpoint[index]); | ||
135 | + } | ||
136 | + | ||
137 | + if (ctrl & TYPE6_LOAD) { | ||
138 | + flags |= BP_MEM_READ; | ||
139 | + } | ||
140 | + | ||
141 | + if (ctrl & TYPE6_STORE) { | ||
142 | + flags |= BP_MEM_WRITE; | ||
143 | + } | ||
144 | + | ||
145 | + if (flags & BP_MEM_ACCESS) { | ||
146 | + size = extract32(ctrl, 16, 4); | ||
147 | + if (size != 0) { | ||
148 | + cpu_watchpoint_insert(cs, addr, size, flags, | ||
149 | + &env->cpu_watchpoint[index]); | ||
150 | + } else { | ||
151 | + cpu_watchpoint_insert(cs, addr, 8, flags, | ||
152 | + &env->cpu_watchpoint[index]); | ||
101 | + } | 153 | + } |
102 | + } | 154 | + } |
103 | + | 155 | +} |
104 | + cpu->decoders = dynamic_decoders; | 156 | + |
105 | +} | 157 | +static void type6_breakpoint_remove(CPURISCVState *env, target_ulong index) |
106 | + | 158 | +{ |
107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) | 159 | + type2_breakpoint_remove(env, index); |
160 | +} | ||
161 | + | ||
162 | +static void type6_reg_write(CPURISCVState *env, target_ulong index, | ||
163 | + int tdata_index, target_ulong val) | ||
164 | +{ | ||
165 | + target_ulong new_val; | ||
166 | + | ||
167 | + switch (tdata_index) { | ||
168 | + case TDATA1: | ||
169 | + new_val = type6_mcontrol6_validate(env, val); | ||
170 | + if (new_val != env->tdata1[index]) { | ||
171 | + env->tdata1[index] = new_val; | ||
172 | + type6_breakpoint_remove(env, index); | ||
173 | + type6_breakpoint_insert(env, index); | ||
174 | + } | ||
175 | + break; | ||
176 | + case TDATA2: | ||
177 | + if (val != env->tdata2[index]) { | ||
178 | + env->tdata2[index] = val; | ||
179 | + type6_breakpoint_remove(env, index); | ||
180 | + type6_breakpoint_insert(env, index); | ||
181 | + } | ||
182 | + break; | ||
183 | + case TDATA3: | ||
184 | + qemu_log_mask(LOG_UNIMP, | ||
185 | + "tdata3 is not supported for type 6 trigger\n"); | ||
186 | + break; | ||
187 | + default: | ||
188 | + g_assert_not_reached(); | ||
189 | + } | ||
190 | + | ||
191 | + return; | ||
192 | +} | ||
193 | + | ||
194 | target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index) | ||
108 | { | 195 | { |
109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; | 196 | switch (tdata_index) { |
110 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 197 | @@ -XXX,XX +XXX,XX @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) |
111 | index XXXXXXX..XXXXXXX 100644 | 198 | case TRIGGER_TYPE_AD_MATCH: |
112 | --- a/target/riscv/translate.c | 199 | type2_reg_write(env, env->trigger_cur, tdata_index, val); |
113 | +++ b/target/riscv/translate.c | 200 | break; |
114 | @@ -XXX,XX +XXX,XX @@ | 201 | + case TRIGGER_TYPE_AD_MATCH6: |
115 | #include "exec/helper-info.c.inc" | 202 | + type6_reg_write(env, env->trigger_cur, tdata_index, val); |
116 | #undef HELPER_H | 203 | + break; |
117 | 204 | case TRIGGER_TYPE_INST_CNT: | |
118 | +#include "tcg/tcg-cpu.h" | 205 | case TRIGGER_TYPE_INT: |
119 | + | 206 | case TRIGGER_TYPE_EXCP: |
120 | /* global register indices */ | 207 | - case TRIGGER_TYPE_AD_MATCH6: |
121 | static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart; | 208 | case TRIGGER_TYPE_EXT_SRC: |
122 | static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ | 209 | qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n", |
123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 210 | trigger_type); |
124 | /* FRM is known to contain a valid value. */ | 211 | @@ -XXX,XX +XXX,XX @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) |
125 | bool frm_valid; | 212 | target_ulong tinfo_csr_read(CPURISCVState *env) |
126 | bool insn_start_updated; | 213 | { |
127 | + const GPtrArray *decoders; | 214 | /* assume all triggers support the same types of triggers */ |
128 | } DisasContext; | 215 | - return BIT(TRIGGER_TYPE_AD_MATCH); |
129 | 216 | + return BIT(TRIGGER_TYPE_AD_MATCH) | | |
130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | 217 | + BIT(TRIGGER_TYPE_AD_MATCH6); |
131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) | ||
132 | return (first_word & 3) == 3 ? 4 : 2; | ||
133 | } | 218 | } |
134 | 219 | ||
135 | +const RISCVDecoder decoder_table[] = { | 220 | void riscv_cpu_debug_excp_handler(CPUState *cs) |
136 | + { always_true_p, decode_insn32 }, | 221 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
137 | + { has_xthead_p, decode_xthead}, | 222 | } |
138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, | 223 | } |
139 | +}; | 224 | break; |
140 | + | 225 | + case TRIGGER_TYPE_AD_MATCH6: |
141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); | 226 | + ctrl = env->tdata1[i]; |
142 | + | 227 | + pc = env->tdata2[i]; |
143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | 228 | + |
144 | { | 229 | + if ((ctrl & TYPE6_EXEC) && (bp->pc == pc)) { |
145 | - /* | 230 | + if (riscv_cpu_virt_enabled(env)) { |
146 | - * A table with predicate (i.e., guard) functions and decoder functions | 231 | + /* check VU/VS bit against current privilege level */ |
147 | - * that are tested in-order until a decoder matches onto the opcode. | 232 | + if ((ctrl >> 23) & BIT(env->priv)) { |
148 | - */ | 233 | + return true; |
149 | - static const struct { | 234 | + } |
150 | - bool (*guard_func)(const RISCVCPUConfig *); | 235 | + } else { |
151 | - bool (*decode_func)(DisasContext *, uint32_t); | 236 | + /* check U/S/M bit against current privilege level */ |
152 | - } decoders[] = { | 237 | + if ((ctrl >> 3) & BIT(env->priv)) { |
153 | - { always_true_p, decode_insn32 }, | 238 | + return true; |
154 | - { has_xthead_p, decode_xthead }, | 239 | + } |
155 | - { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, | 240 | + } |
156 | - }; | 241 | + } |
157 | - | 242 | + break; |
158 | ctx->virt_inst_excp = false; | 243 | default: |
159 | ctx->cur_insn_len = insn_len(opcode); | 244 | /* other trigger types are not supported or irrelevant */ |
160 | /* Check for compressed insn */ | 245 | break; |
161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | 246 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) |
162 | ctx->base.pc_next + 2)); | 247 | } |
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 | } | 248 | } |
173 | } | 249 | break; |
174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 250 | + case TRIGGER_TYPE_AD_MATCH6: |
175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); | 251 | + ctrl = env->tdata1[i]; |
176 | ctx->zero = tcg_constant_tl(0); | 252 | + addr = env->tdata2[i]; |
177 | ctx->virt_inst_excp = false; | 253 | + flags = 0; |
178 | + ctx->decoders = cpu->decoders; | 254 | + |
179 | } | 255 | + if (ctrl & TYPE6_LOAD) { |
180 | 256 | + flags |= BP_MEM_READ; | |
181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) | 257 | + } |
258 | + if (ctrl & TYPE6_STORE) { | ||
259 | + flags |= BP_MEM_WRITE; | ||
260 | + } | ||
261 | + | ||
262 | + if ((wp->flags & flags) && (wp->vaddr == addr)) { | ||
263 | + if (riscv_cpu_virt_enabled(env)) { | ||
264 | + /* check VU/VS bit against current privilege level */ | ||
265 | + if ((ctrl >> 23) & BIT(env->priv)) { | ||
266 | + return true; | ||
267 | + } | ||
268 | + } else { | ||
269 | + /* check U/S/M bit against current privilege level */ | ||
270 | + if ((ctrl >> 3) & BIT(env->priv)) { | ||
271 | + return true; | ||
272 | + } | ||
273 | + } | ||
274 | + } | ||
275 | + break; | ||
276 | default: | ||
277 | /* other trigger types are not supported */ | ||
278 | break; | ||
182 | -- | 279 | -- |
183 | 2.45.1 | 280 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Cheng Yang <yangcheng.work@foxmail.com> | 1 | From: Yang Liu <liuyang22@iscas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() | 3 | Remove duplicate code by wrapping vfwredsum_vs's OP function. |
4 | to set the address of initrd in FDT to support 64-bit address. | ||
5 | 4 | ||
6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> | 5 | Signed-off-by: Yang Liu <liuyang22@iscas.ac.cn> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> | 7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | Message-Id: <20220817074802.20765-1-liuyang22@iscas.ac.cn> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 10 | --- |
11 | hw/riscv/boot.c | 4 ++-- | 11 | target/riscv/vector_helper.c | 56 +++++++----------------------------- |
12 | 1 file changed, 2 insertions(+), 2 deletions(-) | 12 | 1 file changed, 10 insertions(+), 46 deletions(-) |
13 | 13 | ||
14 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 14 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/boot.c | 16 | --- a/target/riscv/vector_helper.c |
17 | +++ b/hw/riscv/boot.c | 17 | +++ b/target/riscv/vector_helper.c |
18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | 18 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_FRED(vfredmin_vs_h, uint16_t, uint16_t, H2, H2, float16_minimum_number) |
19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ | 19 | GEN_VEXT_FRED(vfredmin_vs_w, uint32_t, uint32_t, H4, H4, float32_minimum_number) |
20 | if (fdt) { | 20 | GEN_VEXT_FRED(vfredmin_vs_d, uint64_t, uint64_t, H8, H8, float64_minimum_number) |
21 | end = start + size; | 21 | |
22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); | 22 | -/* Vector Widening Floating-Point Reduction Instructions */ |
23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); | 23 | -/* Unordered reduce 2*SEW = 2*SEW + sum(promote(SEW)) */ |
24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); | 24 | -void HELPER(vfwredsum_vs_h)(void *vd, void *v0, void *vs1, |
25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); | 25 | - void *vs2, CPURISCVState *env, uint32_t desc) |
26 | } | 26 | +/* Vector Widening Floating-Point Add Instructions */ |
27 | +static uint32_t fwadd16(uint32_t a, uint16_t b, float_status *s) | ||
28 | { | ||
29 | - uint32_t vm = vext_vm(desc); | ||
30 | - uint32_t vl = env->vl; | ||
31 | - uint32_t esz = sizeof(uint32_t); | ||
32 | - uint32_t vlenb = simd_maxsz(desc); | ||
33 | - uint32_t vta = vext_vta(desc); | ||
34 | - uint32_t i; | ||
35 | - uint32_t s1 = *((uint32_t *)vs1 + H4(0)); | ||
36 | - | ||
37 | - for (i = env->vstart; i < vl; i++) { | ||
38 | - uint16_t s2 = *((uint16_t *)vs2 + H2(i)); | ||
39 | - if (!vm && !vext_elem_mask(v0, i)) { | ||
40 | - continue; | ||
41 | - } | ||
42 | - s1 = float32_add(s1, float16_to_float32(s2, true, &env->fp_status), | ||
43 | - &env->fp_status); | ||
44 | - } | ||
45 | - *((uint32_t *)vd + H4(0)) = s1; | ||
46 | - env->vstart = 0; | ||
47 | - /* set tail elements to 1s */ | ||
48 | - vext_set_elems_1s(vd, vta, esz, vlenb); | ||
49 | + return float32_add(a, float16_to_float32(b, true, s), s); | ||
27 | } | 50 | } |
28 | 51 | ||
52 | -void HELPER(vfwredsum_vs_w)(void *vd, void *v0, void *vs1, | ||
53 | - void *vs2, CPURISCVState *env, uint32_t desc) | ||
54 | +static uint64_t fwadd32(uint64_t a, uint32_t b, float_status *s) | ||
55 | { | ||
56 | - uint32_t vm = vext_vm(desc); | ||
57 | - uint32_t vl = env->vl; | ||
58 | - uint32_t esz = sizeof(uint64_t); | ||
59 | - uint32_t vlenb = simd_maxsz(desc); | ||
60 | - uint32_t vta = vext_vta(desc); | ||
61 | - uint32_t i; | ||
62 | - uint64_t s1 = *((uint64_t *)vs1); | ||
63 | - | ||
64 | - for (i = env->vstart; i < vl; i++) { | ||
65 | - uint32_t s2 = *((uint32_t *)vs2 + H4(i)); | ||
66 | - if (!vm && !vext_elem_mask(v0, i)) { | ||
67 | - continue; | ||
68 | - } | ||
69 | - s1 = float64_add(s1, float32_to_float64(s2, &env->fp_status), | ||
70 | - &env->fp_status); | ||
71 | - } | ||
72 | - *((uint64_t *)vd) = s1; | ||
73 | - env->vstart = 0; | ||
74 | - /* set tail elements to 1s */ | ||
75 | - vext_set_elems_1s(vd, vta, esz, vlenb); | ||
76 | + return float64_add(a, float32_to_float64(b, s), s); | ||
77 | } | ||
78 | |||
79 | +/* Vector Widening Floating-Point Reduction Instructions */ | ||
80 | +/* Unordered reduce 2*SEW = 2*SEW + sum(promote(SEW)) */ | ||
81 | +GEN_VEXT_FRED(vfwredsum_vs_h, uint32_t, uint16_t, H4, H2, fwadd16) | ||
82 | +GEN_VEXT_FRED(vfwredsum_vs_w, uint64_t, uint32_t, H8, H4, fwadd32) | ||
83 | + | ||
84 | /* | ||
85 | *** Vector Mask Operations | ||
86 | */ | ||
29 | -- | 87 | -- |
30 | 2.45.1 | 88 | 2.37.3 | diff view generated by jsdifflib |
1 | From: Andrew Jones <ajones@ventanamicro.com> | 1 | From: Yang Liu <liuyang22@iscas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | Implementing wrs.nto to always just return is consistent with the | 3 | Starting with RVV1.0, the original vf[w]redsum_vs instruction was renamed |
4 | specification, as the instruction is permitted to terminate the | 4 | to vf[w]redusum_vs. The distinction between ordered and unordered is also |
5 | stall for any reason, but it's not useful for virtualization, where | 5 | more consistent with other instructions, although there is no difference |
6 | we'd like the guest to trap to the hypervisor in order to allow | 6 | in implementation between the two for QEMU. |
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. | ||
13 | 7 | ||
14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | 8 | Signed-off-by: Yang Liu <liuyang22@iscas.ac.cn> |
15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> | 9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 10 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Message-Id: <20220817074802.20765-2-liuyang22@iscas.ac.cn> |
18 | Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com> | ||
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 13 | --- |
21 | target/riscv/helper.h | 1 + | 14 | target/riscv/helper.h | 15 ++++++++++----- |
22 | target/riscv/op_helper.c | 11 ++++++++ | 15 | target/riscv/insn32.decode | 6 ++++-- |
23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- | 16 | target/riscv/vector_helper.c | 19 +++++++++++++------ |
24 | 3 files changed, 32 insertions(+), 9 deletions(-) | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 6 ++++-- |
18 | 4 files changed, 31 insertions(+), 15 deletions(-) | ||
25 | 19 | ||
26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 20 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
27 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/riscv/helper.h | 22 | --- a/target/riscv/helper.h |
29 | +++ b/target/riscv/helper.h | 23 | +++ b/target/riscv/helper.h |
30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) | 24 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vwredsum_vs_b, void, ptr, ptr, ptr, ptr, env, i32) |
31 | DEF_HELPER_1(sret, tl, env) | 25 | DEF_HELPER_6(vwredsum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) |
32 | DEF_HELPER_1(mret, tl, env) | 26 | DEF_HELPER_6(vwredsum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) |
33 | DEF_HELPER_1(wfi, void, env) | 27 | |
34 | +DEF_HELPER_1(wrs_nto, void, env) | 28 | -DEF_HELPER_6(vfredsum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) |
35 | DEF_HELPER_1(tlb_flush, void, env) | 29 | -DEF_HELPER_6(vfredsum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) |
36 | DEF_HELPER_1(tlb_flush_all, void, env) | 30 | -DEF_HELPER_6(vfredsum_vs_d, void, ptr, ptr, ptr, ptr, env, i32) |
37 | /* Native Debug */ | 31 | +DEF_HELPER_6(vfredusum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) |
38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | 32 | +DEF_HELPER_6(vfredusum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) |
33 | +DEF_HELPER_6(vfredusum_vs_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
34 | +DEF_HELPER_6(vfredosum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
35 | +DEF_HELPER_6(vfredosum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
36 | +DEF_HELPER_6(vfredosum_vs_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
37 | DEF_HELPER_6(vfredmax_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
38 | DEF_HELPER_6(vfredmax_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
39 | DEF_HELPER_6(vfredmax_vs_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
40 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vfredmin_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
41 | DEF_HELPER_6(vfredmin_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
42 | DEF_HELPER_6(vfredmin_vs_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
43 | |||
44 | -DEF_HELPER_6(vfwredsum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
45 | -DEF_HELPER_6(vfwredsum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
46 | +DEF_HELPER_6(vfwredusum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
47 | +DEF_HELPER_6(vfwredusum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
48 | +DEF_HELPER_6(vfwredosum_vs_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
49 | +DEF_HELPER_6(vfwredosum_vs_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
50 | |||
51 | DEF_HELPER_6(vmand_mm, void, ptr, ptr, ptr, ptr, env, i32) | ||
52 | DEF_HELPER_6(vmnand_mm, void, ptr, ptr, ptr, ptr, env, i32) | ||
53 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
39 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/op_helper.c | 55 | --- a/target/riscv/insn32.decode |
41 | +++ b/target/riscv/op_helper.c | 56 | +++ b/target/riscv/insn32.decode |
42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) | 57 | @@ -XXX,XX +XXX,XX @@ vredmax_vs 000111 . ..... ..... 010 ..... 1010111 @r_vm |
43 | } | 58 | vwredsumu_vs 110000 . ..... ..... 000 ..... 1010111 @r_vm |
59 | vwredsum_vs 110001 . ..... ..... 000 ..... 1010111 @r_vm | ||
60 | # Vector ordered and unordered reduction sum | ||
61 | -vfredsum_vs 0000-1 . ..... ..... 001 ..... 1010111 @r_vm | ||
62 | +vfredusum_vs 000001 . ..... ..... 001 ..... 1010111 @r_vm | ||
63 | +vfredosum_vs 000011 . ..... ..... 001 ..... 1010111 @r_vm | ||
64 | vfredmin_vs 000101 . ..... ..... 001 ..... 1010111 @r_vm | ||
65 | vfredmax_vs 000111 . ..... ..... 001 ..... 1010111 @r_vm | ||
66 | # Vector widening ordered and unordered float reduction sum | ||
67 | -vfwredsum_vs 1100-1 . ..... ..... 001 ..... 1010111 @r_vm | ||
68 | +vfwredusum_vs 110001 . ..... ..... 001 ..... 1010111 @r_vm | ||
69 | +vfwredosum_vs 110011 . ..... ..... 001 ..... 1010111 @r_vm | ||
70 | vmand_mm 011001 - ..... ..... 010 ..... 1010111 @r | ||
71 | vmnand_mm 011101 - ..... ..... 010 ..... 1010111 @r | ||
72 | vmandn_mm 011000 - ..... ..... 010 ..... 1010111 @r | ||
73 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/target/riscv/vector_helper.c | ||
76 | +++ b/target/riscv/vector_helper.c | ||
77 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \ | ||
44 | } | 78 | } |
45 | 79 | ||
46 | +void helper_wrs_nto(CPURISCVState *env) | 80 | /* Unordered sum */ |
47 | +{ | 81 | -GEN_VEXT_FRED(vfredsum_vs_h, uint16_t, uint16_t, H2, H2, float16_add) |
48 | + if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) && | 82 | -GEN_VEXT_FRED(vfredsum_vs_w, uint32_t, uint32_t, H4, H4, float32_add) |
49 | + get_field(env->hstatus, HSTATUS_VTW) && | 83 | -GEN_VEXT_FRED(vfredsum_vs_d, uint64_t, uint64_t, H8, H8, float64_add) |
50 | + !get_field(env->mstatus, MSTATUS_TW)) { | 84 | +GEN_VEXT_FRED(vfredusum_vs_h, uint16_t, uint16_t, H2, H2, float16_add) |
51 | + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); | 85 | +GEN_VEXT_FRED(vfredusum_vs_w, uint32_t, uint32_t, H4, H4, float32_add) |
52 | + } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) { | 86 | +GEN_VEXT_FRED(vfredusum_vs_d, uint64_t, uint64_t, H8, H8, float64_add) |
53 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
54 | + } | ||
55 | +} | ||
56 | + | 87 | + |
57 | void helper_tlb_flush(CPURISCVState *env) | 88 | +/* Ordered sum */ |
58 | { | 89 | +GEN_VEXT_FRED(vfredosum_vs_h, uint16_t, uint16_t, H2, H2, float16_add) |
59 | CPUState *cs = env_cpu(env); | 90 | +GEN_VEXT_FRED(vfredosum_vs_w, uint32_t, uint32_t, H4, H4, float32_add) |
60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc | 91 | +GEN_VEXT_FRED(vfredosum_vs_d, uint64_t, uint64_t, H8, H8, float64_add) |
92 | |||
93 | /* Maximum value */ | ||
94 | GEN_VEXT_FRED(vfredmax_vs_h, uint16_t, uint16_t, H2, H2, float16_maximum_number) | ||
95 | @@ -XXX,XX +XXX,XX @@ static uint64_t fwadd32(uint64_t a, uint32_t b, float_status *s) | ||
96 | } | ||
97 | |||
98 | /* Vector Widening Floating-Point Reduction Instructions */ | ||
99 | -/* Unordered reduce 2*SEW = 2*SEW + sum(promote(SEW)) */ | ||
100 | -GEN_VEXT_FRED(vfwredsum_vs_h, uint32_t, uint16_t, H4, H2, fwadd16) | ||
101 | -GEN_VEXT_FRED(vfwredsum_vs_w, uint64_t, uint32_t, H8, H4, fwadd32) | ||
102 | +/* Ordered/unordered reduce 2*SEW = 2*SEW + sum(promote(SEW)) */ | ||
103 | +GEN_VEXT_FRED(vfwredusum_vs_h, uint32_t, uint16_t, H4, H2, fwadd16) | ||
104 | +GEN_VEXT_FRED(vfwredusum_vs_w, uint64_t, uint32_t, H8, H4, fwadd32) | ||
105 | +GEN_VEXT_FRED(vfwredosum_vs_h, uint32_t, uint16_t, H4, H2, fwadd16) | ||
106 | +GEN_VEXT_FRED(vfwredosum_vs_w, uint64_t, uint32_t, H8, H4, fwadd32) | ||
107 | |||
108 | /* | ||
109 | *** Vector Mask Operations | ||
110 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
61 | index XXXXXXX..XXXXXXX 100644 | 111 | index XXXXXXX..XXXXXXX 100644 |
62 | --- a/target/riscv/insn_trans/trans_rvzawrs.c.inc | 112 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
63 | +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc | 113 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
64 | @@ -XXX,XX +XXX,XX @@ | 114 | @@ -XXX,XX +XXX,XX @@ static bool freduction_check(DisasContext *s, arg_rmrr *a) |
65 | * this program. If not, see <http://www.gnu.org/licenses/>. | 115 | require_zve64f(s); |
66 | */ | ||
67 | |||
68 | -static bool trans_wrs(DisasContext *ctx) | ||
69 | +static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a) | ||
70 | { | ||
71 | if (!ctx->cfg_ptr->ext_zawrs) { | ||
72 | return false; | ||
73 | @@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx) | ||
74 | return true; | ||
75 | } | 116 | } |
76 | 117 | ||
77 | -#define GEN_TRANS_WRS(insn) \ | 118 | -GEN_OPFVV_TRANS(vfredsum_vs, freduction_check) |
78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ | 119 | +GEN_OPFVV_TRANS(vfredusum_vs, freduction_check) |
79 | -{ \ | 120 | +GEN_OPFVV_TRANS(vfredosum_vs, freduction_check) |
80 | - (void)a; \ | 121 | GEN_OPFVV_TRANS(vfredmax_vs, freduction_check) |
81 | - return trans_wrs(ctx); \ | 122 | GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) |
82 | -} | 123 | |
83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) | 124 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) |
84 | +{ | 125 | (s->sew != MO_8); |
85 | + if (!ctx->cfg_ptr->ext_zawrs) { | 126 | } |
86 | + return false; | 127 | |
87 | + } | 128 | -GEN_OPFVV_WIDEN_TRANS(vfwredsum_vs, freduction_widen_check) |
88 | 129 | +GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) | |
89 | -GEN_TRANS_WRS(wrs_nto) | 130 | +GEN_OPFVV_WIDEN_TRANS(vfwredosum_vs, freduction_widen_check) |
90 | -GEN_TRANS_WRS(wrs_sto) | 131 | |
91 | + /* | 132 | /* |
92 | + * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto | 133 | *** Vector Mask Operations |
93 | + * should raise an exception when the implementation-specific bounded time | ||
94 | + * limit has expired. Our time limit is zero, so we either return | ||
95 | + * immediately, as does our implementation of wrs.sto, or raise an | ||
96 | + * exception, as handled by the wrs.nto helper. | ||
97 | + */ | ||
98 | +#ifndef CONFIG_USER_ONLY | ||
99 | + gen_helper_wrs_nto(tcg_env); | ||
100 | +#endif | ||
101 | + | ||
102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ | ||
103 | + return trans_wrs_sto(ctx, NULL); | ||
104 | +} | ||
105 | -- | 134 | -- |
106 | 2.45.1 | 135 | 2.37.3 |
107 | |||
108 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Privileged spec section 4.1.9 mentions: | ||
4 | |||
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> | ||
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | --- | ||
29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ | ||
30 | 1 file changed, 2 insertions(+) | ||
31 | |||
32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | ||
35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) | ||
37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { | ||
38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); | ||
39 | } else { | ||
40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, | ||
41 | + offsetof(CPURISCVState, badaddr)); | ||
42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); | ||
43 | } | ||
44 | return true; | ||
45 | -- | ||
46 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
2 | 1 | ||
3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and | ||
4 | enabling Zve64x enables Zve32x according to their dependency. | ||
5 | |||
6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107 | ||
7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
9 | Reviewed-by: Max Chou <max.chou@sifive.com> | ||
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Message-ID: <20240328022343.6871-3-jason.chien@sifive.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/cpu_cfg.h | 1 + | ||
15 | target/riscv/cpu.c | 2 ++ | ||
16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ | ||
17 | 3 files changed, 14 insertions(+), 6 deletions(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
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; | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), | ||
37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | ||
39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), | ||
40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), | ||
41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), | ||
42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), | ||
43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), | ||
48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), | ||
50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), | ||
51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/tcg/tcg-cpu.c | ||
54 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
56 | |||
57 | /* The Zve64d extension depends on the Zve64f extension */ | ||
58 | if (cpu->cfg.ext_zve64d) { | ||
59 | + if (!riscv_has_ext(env, RVD)) { | ||
60 | + error_setg(errp, "Zve64d/V extensions require D extension"); | ||
61 | + return; | ||
62 | + } | ||
63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
64 | } | ||
65 | |||
66 | - /* The Zve64f extension depends on the Zve32f extension */ | ||
67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ | ||
68 | if (cpu->cfg.ext_zve64f) { | ||
69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); | ||
70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | ||
71 | } | ||
72 | |||
73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
74 | - error_setg(errp, "Zve64d/V extensions require D extension"); | ||
75 | - return; | ||
76 | + /* The Zve64x extension depends on the Zve32x extension */ | ||
77 | + if (cpu->cfg.ext_zve64x) { | ||
78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
79 | } | ||
80 | |||
81 | /* The Zve32f extension depends on the Zve32x extension */ | ||
82 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { | ||
88 | error_setg( | ||
89 | errp, | ||
90 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
91 | + "Zvbc and Zvknhb extensions require V or Zve64x extensions"); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | -- | ||
96 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Max Chou <max.chou@sifive.com> | ||
2 | 1 | ||
3 | The require_scale_rvf function only checks the double width operator for | ||
4 | the vector floating point widen instructions, so most of the widen | ||
5 | checking functions need to add require_rvf for single width operator. | ||
6 | |||
7 | The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width | ||
8 | integer to double width float, so the opfxv_widen_check function doesn’t | ||
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> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ | ||
18 | 1 file changed, 5 insertions(+) | ||
19 | |||
20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) | ||
25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | ||
26 | { | ||
27 | return require_rvv(s) && | ||
28 | + require_rvf(s) && | ||
29 | require_scale_rvf(s) && | ||
30 | (s->sew != MO_8) && | ||
31 | vext_check_isa_ill(s) && | ||
32 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check) | ||
33 | static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
34 | { | ||
35 | return require_rvv(s) && | ||
36 | + require_rvf(s) && | ||
37 | require_scale_rvf(s) && | ||
38 | (s->sew != MO_8) && | ||
39 | vext_check_isa_ill(s) && | ||
40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) | ||
41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
42 | { | ||
43 | return require_rvv(s) && | ||
44 | + require_rvf(s) && | ||
45 | require_scale_rvf(s) && | ||
46 | (s->sew != MO_8) && | ||
47 | vext_check_isa_ill(s) && | ||
48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) | ||
49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
50 | { | ||
51 | return require_rvv(s) && | ||
52 | + require_rvf(s) && | ||
53 | require_scale_rvf(s) && | ||
54 | (s->sew != MO_8) && | ||
55 | vext_check_isa_ill(s) && | ||
56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) | ||
57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
58 | { | ||
59 | return reduction_widen_check(s, a) && | ||
60 | + require_rvf(s) && | ||
61 | require_scale_rvf(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
64 | -- | ||
65 | 2.45.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Max Chou <max.chou@sifive.com> | ||
2 | 1 | ||
3 | The opfv_narrow_check needs to check the single width float operator by | ||
4 | require_rvf. | ||
5 | |||
6 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + | ||
13 | 1 file changed, 1 insertion(+) | ||
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 opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) | ||
21 | { | ||
22 | return opfv_narrow_check(s, a) && | ||
23 | + require_rvf(s) && | ||
24 | require_scale_rvf(s) && | ||
25 | (s->sew != MO_8); | ||
26 | } | ||
27 | -- | ||
28 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Max Chou <max.chou@sifive.com> | ||
2 | 1 | ||
3 | If the checking functions check both the single and double width | ||
4 | operators at the same time, then the single width operator checking | ||
5 | functions (require_rvf[min]) will check whether the SEW is 8. | ||
6 | |||
7 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ | ||
14 | 1 file changed, 4 insertions(+), 12 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 @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | ||
21 | return require_rvv(s) && | ||
22 | require_rvf(s) && | ||
23 | require_scale_rvf(s) && | ||
24 | - (s->sew != MO_8) && | ||
25 | vext_check_isa_ill(s) && | ||
26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); | ||
27 | } | ||
28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
29 | return require_rvv(s) && | ||
30 | require_rvf(s) && | ||
31 | require_scale_rvf(s) && | ||
32 | - (s->sew != MO_8) && | ||
33 | vext_check_isa_ill(s) && | ||
34 | vext_check_ds(s, a->rd, a->rs2, a->vm); | ||
35 | } | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
37 | return require_rvv(s) && | ||
38 | require_rvf(s) && | ||
39 | require_scale_rvf(s) && | ||
40 | - (s->sew != MO_8) && | ||
41 | vext_check_isa_ill(s) && | ||
42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); | ||
43 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
45 | return require_rvv(s) && | ||
46 | require_rvf(s) && | ||
47 | require_scale_rvf(s) && | ||
48 | - (s->sew != MO_8) && | ||
49 | vext_check_isa_ill(s) && | ||
50 | vext_check_dd(s, a->rd, a->rs2, a->vm); | ||
51 | } | ||
52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
53 | { | ||
54 | return opfv_widen_check(s, a) && | ||
55 | require_rvfmin(s) && | ||
56 | - require_scale_rvfmin(s) && | ||
57 | - (s->sew != MO_8); | ||
58 | + require_scale_rvfmin(s); | ||
59 | } | ||
60 | |||
61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
63 | { | ||
64 | return opfv_narrow_check(s, a) && | ||
65 | require_rvfmin(s) && | ||
66 | - require_scale_rvfmin(s) && | ||
67 | - (s->sew != MO_8); | ||
68 | + require_scale_rvfmin(s); | ||
69 | } | ||
70 | |||
71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) | ||
72 | { | ||
73 | return opfv_narrow_check(s, a) && | ||
74 | require_rvf(s) && | ||
75 | - require_scale_rvf(s) && | ||
76 | - (s->sew != MO_8); | ||
77 | + require_scale_rvf(s); | ||
78 | } | ||
79 | |||
80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ | ||
81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
82 | { | ||
83 | return reduction_widen_check(s, a) && | ||
84 | require_rvf(s) && | ||
85 | - require_scale_rvf(s) && | ||
86 | - (s->sew != MO_8); | ||
87 | + require_scale_rvf(s); | ||
88 | } | ||
89 | |||
90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) | ||
91 | -- | ||
92 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Alexei Filippov <alexei.filippov@syntacore.com> | ||
2 | 1 | ||
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. | ||
7 | |||
8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of | ||
9 | riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2 | ||
10 | should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest | ||
11 | page-fault is taken into M-mode, mtval2 is written with either zero or guest | ||
12 | physical address that faulted, shifted by 2 bits. *For other traps, mtval2 | ||
13 | is set to zero...* | ||
14 | |||
15 | Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com> | ||
16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> | ||
19 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | --- | ||
22 | target/riscv/cpu_helper.c | 12 ++++++------ | ||
23 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
24 | |||
25 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/riscv/cpu_helper.c | ||
28 | +++ b/target/riscv/cpu_helper.c | ||
29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
30 | __func__, pa, ret, prot_pmp, tlb_size); | ||
31 | |||
32 | prot &= prot_pmp; | ||
33 | - } | ||
34 | - | ||
35 | - if (ret != TRANSLATE_SUCCESS) { | ||
36 | + } else { | ||
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 { | ||
53 | -- | ||
54 | 2.45.1 | diff view generated by jsdifflib |