1 | The following changes since commit c95bd5ff1660883d15ad6e0005e4c8571604f51a: | 1 | The following changes since commit e4f3ede95ce813d5705c65e1c0e1c80c70739ebb: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/philmd/tags/mips-fixes-20210322' into staging (2021-03-22 14:26:13 +0000) | 3 | Merge remote-tracking branch 'remotes/kraxel/tags/usb-20210505-pull-request' into staging (2021-05-10 19:55:06 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210322-2 | 7 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210511 |
8 | 8 | ||
9 | for you to fetch changes up to 9a27f69bd668d9d71674407badc412ce1231c7d5: | 9 | for you to fetch changes up to c30a0757f094c107e491820e3d35224eb68859c7: |
10 | 10 | ||
11 | target/riscv: Prevent lost illegal instruction exceptions (2021-03-22 21:54:40 -0400) | 11 | target/riscv: Fix the RV64H decode comment (2021-05-11 20:02:07 +1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | RISC-V PR for 6.0 | 14 | A large collection of RISC-V fixes, improvements and features |
15 | 15 | ||
16 | This PR includes: | 16 | - Clenaup some left over v1.9 code |
17 | - Fix for vector CSR access | 17 | - Documentation improvements |
18 | - Improvements to the Ibex UART device | 18 | - Support for the shakti_c machine |
19 | - PMP improvements and bug fixes | 19 | - Internal cleanup of the CSR accesses |
20 | - Hypervisor extension bug fixes | 20 | - Updates to the OpenTitan platform |
21 | - ramfb support for the virt machine | 21 | - Support for the virtio-vga |
22 | - Fast read support for SST flash | 22 | - Fix for the saturate subtract in vector extensions |
23 | - Improvements to the microchip_pfsoc machine | 23 | - Experimental support for the ePMP spec |
24 | - A range of other internal code cleanups and bug fixes | ||
24 | 25 | ||
25 | ---------------------------------------------------------------- | 26 | ---------------------------------------------------------------- |
26 | Alexander Wagner (1): | 27 | Alexander Wagner (1): |
27 | hw/char: disable ibex uart receive if the buffer is full | 28 | hw/riscv: Fix OT IBEX reset vector |
28 | 29 | ||
29 | Asherah Connor (2): | 30 | Alistair Francis (22): |
30 | hw/riscv: Add fw_cfg support to virt | 31 | target/riscv: Convert the RISC-V exceptions to an enum |
31 | hw/riscv: allow ramfb on virt | 32 | target/riscv: Use the RISCVException enum for CSR predicates |
33 | target/riscv: Fix 32-bit HS mode access permissions | ||
34 | target/riscv: Use the RISCVException enum for CSR operations | ||
35 | target/riscv: Use RISCVException enum for CSR access | ||
36 | MAINTAINERS: Update the RISC-V CPU Maintainers | ||
37 | hw/opentitan: Update the interrupt layout | ||
38 | hw/riscv: Enable VIRTIO_VGA for RISC-V virt machine | ||
39 | target/riscv: Fix the PMP is locked check when using TOR | ||
40 | target/riscv: Add the ePMP feature | ||
41 | target/riscv/pmp: Remove outdated comment | ||
42 | target/riscv: Add ePMP support for the Ibex CPU | ||
43 | target/riscv: Remove the hardcoded RVXLEN macro | ||
44 | target/riscv: Remove the hardcoded SSTATUS_SD macro | ||
45 | target/riscv: Remove the hardcoded HGATP_MODE macro | ||
46 | target/riscv: Remove the hardcoded MSTATUS_SD macro | ||
47 | target/riscv: Remove the hardcoded SATP_MODE macro | ||
48 | target/riscv: Remove the unused HSTATUS_WPRI macro | ||
49 | target/riscv: Remove an unused CASE_OP_32_64 macro | ||
50 | target/riscv: Consolidate RV32/64 32-bit instructions | ||
51 | target/riscv: Consolidate RV32/64 16-bit instructions | ||
52 | target/riscv: Fix the RV64H decode comment | ||
32 | 53 | ||
33 | Bin Meng (3): | 54 | Atish Patra (1): |
34 | hw/block: m25p80: Support fast read for SST flashes | 55 | target/riscv: Remove privilege v1.9 specific CSR related code |
35 | hw/riscv: microchip_pfsoc: Map EMMC/SD mux register | ||
36 | docs/system: riscv: Add documentation for 'microchip-icicle-kit' machine | ||
37 | 56 | ||
38 | Frank Chang (1): | 57 | Axel Heider (1): |
39 | target/riscv: fix vs() to return proper error code | 58 | docs/system/generic-loader.rst: Fix style |
40 | 59 | ||
41 | Georg Kotheimer (6): | 60 | Bin Meng (1): |
42 | target/riscv: Adjust privilege level for HLV(X)/HSV instructions | 61 | hw/riscv: sifive_e: Add 'const' to sifive_e_memmap[] |
43 | target/riscv: Make VSTIP and VSEIP read-only in hip | ||
44 | target/riscv: Use background registers also for MSTATUS_MPV | ||
45 | target/riscv: Fix read and write accesses to vsip and vsie | ||
46 | target/riscv: Add proper two-stage lookup exception detection | ||
47 | target/riscv: Prevent lost illegal instruction exceptions | ||
48 | 62 | ||
49 | Jim Shu (3): | 63 | Dylan Jhong (1): |
50 | target/riscv: propagate PMP permission to TLB page | 64 | target/riscv: Align the data type of reset vector address |
51 | target/riscv: add log of PMP permission checking | ||
52 | target/riscv: flush TLB pages if PMP permission has been changed | ||
53 | 65 | ||
54 | docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++ | 66 | Emmanuel Blot (2): |
55 | docs/system/target-riscv.rst | 1 + | 67 | target/riscv: fix exception index on instruction access fault |
56 | include/hw/char/ibex_uart.h | 4 + | 68 | target/riscv: fix a typo with interrupt names |
57 | include/hw/riscv/microchip_pfsoc.h | 1 + | ||
58 | include/hw/riscv/virt.h | 2 + | ||
59 | target/riscv/cpu.h | 4 + | ||
60 | target/riscv/pmp.h | 4 +- | ||
61 | hw/block/m25p80.c | 3 + | ||
62 | hw/char/ibex_uart.c | 23 +++- | ||
63 | hw/riscv/microchip_pfsoc.c | 6 + | ||
64 | hw/riscv/virt.c | 33 ++++++ | ||
65 | target/riscv/cpu.c | 1 + | ||
66 | target/riscv/cpu_helper.c | 144 +++++++++++++++-------- | ||
67 | target/riscv/csr.c | 77 +++++++------ | ||
68 | target/riscv/pmp.c | 84 ++++++++++---- | ||
69 | target/riscv/translate.c | 179 +---------------------------- | ||
70 | hw/riscv/Kconfig | 1 + | ||
71 | 17 files changed, 367 insertions(+), 289 deletions(-) | ||
72 | create mode 100644 docs/system/riscv/microchip-icicle-kit.rst | ||
73 | 69 | ||
70 | Frank Chang (2): | ||
71 | target/riscv: fix vrgather macro index variable type bug | ||
72 | fpu/softfloat: set invalid excp flag for RISC-V muladd instructions | ||
73 | |||
74 | Hou Weiying (4): | ||
75 | target/riscv: Define ePMP mseccfg | ||
76 | target/riscv: Add ePMP CSR access functions | ||
77 | target/riscv: Implementation of enhanced PMP (ePMP) | ||
78 | target/riscv: Add a config option for ePMP | ||
79 | |||
80 | Jade Fink (1): | ||
81 | riscv: don't look at SUM when accessing memory from a debugger context | ||
82 | |||
83 | LIU Zhiwei (1): | ||
84 | target/riscv: Fixup saturate subtract function | ||
85 | |||
86 | Vijai Kumar K (5): | ||
87 | target/riscv: Add Shakti C class CPU | ||
88 | riscv: Add initial support for Shakti C machine | ||
89 | hw/char: Add Shakti UART emulation | ||
90 | hw/riscv: Connect Shakti UART to Shakti platform | ||
91 | docs: Add documentation for shakti_c machine | ||
92 | |||
93 | docs/system/generic-loader.rst | 9 +- | ||
94 | docs/system/riscv/shakti-c.rst | 82 +++ | ||
95 | docs/system/target-riscv.rst | 1 + | ||
96 | default-configs/devices/riscv64-softmmu.mak | 1 + | ||
97 | include/hw/char/shakti_uart.h | 74 +++ | ||
98 | include/hw/riscv/opentitan.h | 16 +- | ||
99 | include/hw/riscv/shakti_c.h | 75 +++ | ||
100 | target/riscv/cpu.h | 42 +- | ||
101 | target/riscv/cpu_bits.h | 114 +--- | ||
102 | target/riscv/helper.h | 18 +- | ||
103 | target/riscv/pmp.h | 14 + | ||
104 | target/riscv/insn16-32.decode | 28 - | ||
105 | target/riscv/insn16-64.decode | 36 -- | ||
106 | target/riscv/insn16.decode | 30 + | ||
107 | target/riscv/insn32-64.decode | 88 --- | ||
108 | target/riscv/insn32.decode | 67 ++- | ||
109 | hw/char/shakti_uart.c | 185 +++++++ | ||
110 | hw/intc/ibex_plic.c | 20 +- | ||
111 | hw/riscv/opentitan.c | 10 +- | ||
112 | hw/riscv/shakti_c.c | 181 ++++++ | ||
113 | hw/riscv/sifive_e.c | 2 +- | ||
114 | target/riscv/cpu.c | 26 +- | ||
115 | target/riscv/cpu_helper.c | 88 ++- | ||
116 | target/riscv/csr.c | 824 +++++++++++++++++----------- | ||
117 | target/riscv/fpu_helper.c | 16 +- | ||
118 | target/riscv/gdbstub.c | 8 +- | ||
119 | target/riscv/machine.c | 8 +- | ||
120 | target/riscv/monitor.c | 22 +- | ||
121 | target/riscv/op_helper.c | 18 +- | ||
122 | target/riscv/pmp.c | 218 +++++++- | ||
123 | target/riscv/translate.c | 38 +- | ||
124 | target/riscv/vector_helper.c | 18 +- | ||
125 | fpu/softfloat-specialize.c.inc | 6 + | ||
126 | target/riscv/insn_trans/trans_rva.c.inc | 14 +- | ||
127 | target/riscv/insn_trans/trans_rvd.c.inc | 17 +- | ||
128 | target/riscv/insn_trans/trans_rvf.c.inc | 6 +- | ||
129 | target/riscv/insn_trans/trans_rvh.c.inc | 8 +- | ||
130 | target/riscv/insn_trans/trans_rvi.c.inc | 22 +- | ||
131 | target/riscv/insn_trans/trans_rvm.c.inc | 12 +- | ||
132 | target/riscv/insn_trans/trans_rvv.c.inc | 39 +- | ||
133 | MAINTAINERS | 14 +- | ||
134 | hw/char/meson.build | 1 + | ||
135 | hw/char/trace-events | 4 + | ||
136 | hw/riscv/Kconfig | 11 + | ||
137 | hw/riscv/meson.build | 1 + | ||
138 | target/riscv/meson.build | 13 +- | ||
139 | target/riscv/trace-events | 3 + | ||
140 | 47 files changed, 1759 insertions(+), 789 deletions(-) | ||
141 | create mode 100644 docs/system/riscv/shakti-c.rst | ||
142 | create mode 100644 include/hw/char/shakti_uart.h | ||
143 | create mode 100644 include/hw/riscv/shakti_c.h | ||
144 | delete mode 100644 target/riscv/insn16-32.decode | ||
145 | delete mode 100644 target/riscv/insn16-64.decode | ||
146 | delete mode 100644 target/riscv/insn32-64.decode | ||
147 | create mode 100644 hw/char/shakti_uart.c | ||
148 | create mode 100644 hw/riscv/shakti_c.c | ||
149 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Atish Patra <atish.patra@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | The current two-stage lookup detection in riscv_cpu_do_interrupt falls | 3 | Qemu doesn't support RISC-V privilege specification v1.9. Remove the |
4 | short of its purpose, as all it checks is whether two-stage address | 4 | remaining v1.9 specific references from the implementation. |
5 | translation either via the hypervisor-load store instructions or the | 5 | |
6 | MPRV feature would be allowed. | 6 | Signed-off-by: Atish Patra <atish.patra@wdc.com> |
7 | |||
8 | What we really need instead is whether two-stage address translation was | ||
9 | active when the exception was raised. However, in riscv_cpu_do_interrupt | ||
10 | we do not have the information to reliably detect this. Therefore, when | ||
11 | we raise a memory fault exception we have to record whether two-stage | ||
12 | address translation is active. | ||
13 | |||
14 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
16 | Message-id: 20210319141459.1196741-1-georg.kotheimer@kernkonzept.com | 8 | Message-Id: <20210319194534.2082397-2-atish.patra@wdc.com> |
9 | [Changes by AF: | ||
10 | - Rebase on latest patches | ||
11 | - Bump the vmstate_riscv_cpu version_id and minimum_version_id | ||
12 | ] | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 14 | --- |
19 | target/riscv/cpu.h | 4 ++++ | 15 | target/riscv/cpu.h | 4 +--- |
20 | target/riscv/cpu.c | 1 + | 16 | target/riscv/cpu_bits.h | 23 --------------------- |
21 | target/riscv/cpu_helper.c | 21 ++++++++------------- | 17 | target/riscv/cpu.c | 2 +- |
22 | 3 files changed, 13 insertions(+), 13 deletions(-) | 18 | target/riscv/cpu_helper.c | 12 +++++------ |
19 | target/riscv/csr.c | 42 ++++++++++----------------------------- | ||
20 | target/riscv/machine.c | 8 +++----- | ||
21 | target/riscv/translate.c | 4 ++-- | ||
22 | 7 files changed, 23 insertions(+), 72 deletions(-) | ||
23 | 23 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
25 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/cpu.h | 26 | --- a/target/riscv/cpu.h |
27 | +++ b/target/riscv/cpu.h | 27 | +++ b/target/riscv/cpu.h |
28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | 28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { |
29 | target_ulong satp_hs; | 29 | target_ulong mie; |
30 | uint64_t mstatus_hs; | 30 | target_ulong mideleg; |
31 | 31 | ||
32 | + /* Signals whether the current exception occurred with two-stage address | 32 | - target_ulong sptbr; /* until: priv-1.9.1 */ |
33 | + translation active. */ | 33 | target_ulong satp; /* since: priv-1.10.0 */ |
34 | + bool two_stage_lookup; | 34 | - target_ulong sbadaddr; |
35 | + | 35 | - target_ulong mbadaddr; |
36 | target_ulong scounteren; | 36 | + target_ulong stval; |
37 | target_ulong mcounteren; | 37 | target_ulong medeleg; |
38 | |||
39 | target_ulong stvec; | ||
40 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/riscv/cpu_bits.h | ||
43 | +++ b/target/riscv/cpu_bits.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | /* 32-bit only */ | ||
46 | #define CSR_MSTATUSH 0x310 | ||
47 | |||
48 | -/* Legacy Counter Setup (priv v1.9.1) */ | ||
49 | -/* Update to #define CSR_MCOUNTINHIBIT 0x320 for 1.11.0 */ | ||
50 | -#define CSR_MUCOUNTEREN 0x320 | ||
51 | -#define CSR_MSCOUNTEREN 0x321 | ||
52 | -#define CSR_MHCOUNTEREN 0x322 | ||
53 | - | ||
54 | /* Machine Trap Handling */ | ||
55 | #define CSR_MSCRATCH 0x340 | ||
56 | #define CSR_MEPC 0x341 | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | #define CSR_MTVAL 0x343 | ||
59 | #define CSR_MIP 0x344 | ||
60 | |||
61 | -/* Legacy Machine Trap Handling (priv v1.9.1) */ | ||
62 | -#define CSR_MBADADDR 0x343 | ||
63 | - | ||
64 | /* Supervisor Trap Setup */ | ||
65 | #define CSR_SSTATUS 0x100 | ||
66 | #define CSR_SEDELEG 0x102 | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | #define CSR_STVAL 0x143 | ||
69 | #define CSR_SIP 0x144 | ||
70 | |||
71 | -/* Legacy Supervisor Trap Handling (priv v1.9.1) */ | ||
72 | -#define CSR_SBADADDR 0x143 | ||
73 | - | ||
74 | /* Supervisor Protection and Translation */ | ||
75 | #define CSR_SPTBR 0x180 | ||
76 | #define CSR_SATP 0x180 | ||
77 | @@ -XXX,XX +XXX,XX @@ | ||
78 | #define CSR_MHPMCOUNTER30H 0xb9e | ||
79 | #define CSR_MHPMCOUNTER31H 0xb9f | ||
80 | |||
81 | -/* Legacy Machine Protection and Translation (priv v1.9.1) */ | ||
82 | -#define CSR_MBASE 0x380 | ||
83 | -#define CSR_MBOUND 0x381 | ||
84 | -#define CSR_MIBASE 0x382 | ||
85 | -#define CSR_MIBOUND 0x383 | ||
86 | -#define CSR_MDBASE 0x384 | ||
87 | -#define CSR_MDBOUND 0x385 | ||
88 | - | ||
89 | /* mstatus CSR bits */ | ||
90 | #define MSTATUS_UIE 0x00000001 | ||
91 | #define MSTATUS_SIE 0x00000002 | ||
92 | @@ -XXX,XX +XXX,XX @@ | ||
93 | #define MSTATUS_FS 0x00006000 | ||
94 | #define MSTATUS_XS 0x00018000 | ||
95 | #define MSTATUS_MPRV 0x00020000 | ||
96 | -#define MSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */ | ||
97 | #define MSTATUS_SUM 0x00040000 /* since: priv-1.10 */ | ||
98 | #define MSTATUS_MXR 0x00080000 | ||
99 | -#define MSTATUS_VM 0x1F000000 /* until: priv-1.9.1 */ | ||
100 | #define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */ | ||
101 | #define MSTATUS_TW 0x00200000 /* since: priv-1.10 */ | ||
102 | #define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */ | ||
103 | @@ -XXX,XX +XXX,XX @@ | ||
104 | #define SSTATUS_SPP 0x00000100 | ||
105 | #define SSTATUS_FS 0x00006000 | ||
106 | #define SSTATUS_XS 0x00018000 | ||
107 | -#define SSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */ | ||
108 | #define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */ | ||
109 | #define SSTATUS_MXR 0x00080000 | ||
38 | 110 | ||
39 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 111 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
40 | index XXXXXXX..XXXXXXX 100644 | 112 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/riscv/cpu.c | 113 | --- a/target/riscv/cpu.c |
42 | +++ b/target/riscv/cpu.c | 114 | +++ b/target/riscv/cpu.c |
43 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | 115 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) |
44 | env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV); | 116 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause); |
45 | env->mcause = 0; | 117 | } |
46 | env->pc = env->resetvec; | 118 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval); |
47 | + env->two_stage_lookup = false; | 119 | - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->sbadaddr); |
48 | #endif | 120 | + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval); |
49 | cs->exception_index = EXCP_NONE; | 121 | if (riscv_has_ext(env, RVH)) { |
50 | env->load_res = -1; | 122 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval); |
123 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2); | ||
51 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 124 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
52 | index XXXXXXX..XXXXXXX 100644 | 125 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/target/riscv/cpu_helper.c | 126 | --- a/target/riscv/cpu_helper.c |
54 | +++ b/target/riscv/cpu_helper.c | 127 | +++ b/target/riscv/cpu_helper.c |
55 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | 128 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) |
56 | g_assert_not_reached(); | 129 | env->vscause = env->scause; |
57 | } | 130 | env->scause = env->scause_hs; |
58 | env->badaddr = address; | 131 | |
59 | + env->two_stage_lookup = two_stage; | 132 | - env->vstval = env->sbadaddr; |
60 | } | 133 | - env->sbadaddr = env->stval_hs; |
61 | 134 | + env->vstval = env->stval; | |
62 | hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | 135 | + env->stval = env->stval_hs; |
63 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, | 136 | |
64 | } | 137 | env->vsatp = env->satp; |
65 | 138 | env->satp = env->satp_hs; | |
66 | env->badaddr = addr; | 139 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) |
67 | + env->two_stage_lookup = riscv_cpu_virt_enabled(env) || | 140 | env->scause_hs = env->scause; |
68 | + riscv_cpu_two_stage_lookup(mmu_idx); | 141 | env->scause = env->vscause; |
69 | riscv_raise_exception(&cpu->env, cs->exception_index, retaddr); | 142 | |
70 | } | 143 | - env->stval_hs = env->sbadaddr; |
71 | 144 | - env->sbadaddr = env->vstval; | |
72 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, | 145 | + env->stval_hs = env->stval; |
73 | g_assert_not_reached(); | 146 | + env->stval = env->vstval; |
74 | } | 147 | |
75 | env->badaddr = addr; | 148 | env->satp_hs = env->satp; |
76 | + env->two_stage_lookup = riscv_cpu_virt_enabled(env) || | 149 | env->satp = env->vsatp; |
77 | + riscv_cpu_two_stage_lookup(mmu_idx); | ||
78 | riscv_raise_exception(env, cs->exception_index, retaddr); | ||
79 | } | ||
80 | #endif /* !CONFIG_USER_ONLY */ | ||
81 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 150 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
82 | /* handle the trap in S-mode */ | 151 | env->mstatus = s; |
83 | if (riscv_has_ext(env, RVH)) { | 152 | env->scause = cause | ((target_ulong)async << (TARGET_LONG_BITS - 1)); |
84 | target_ulong hdeleg = async ? env->hideleg : env->hedeleg; | 153 | env->sepc = env->pc; |
85 | - bool two_stage_lookup = false; | 154 | - env->sbadaddr = tval; |
86 | 155 | + env->stval = tval; | |
87 | - if (env->priv == PRV_M || | 156 | env->htval = htval; |
88 | - (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || | 157 | env->pc = (env->stvec >> 2 << 2) + |
89 | - (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) && | 158 | ((async && (env->stvec & 3) == 1) ? cause * 4 : 0); |
90 | - get_field(env->hstatus, HSTATUS_HU))) { | ||
91 | - two_stage_lookup = true; | ||
92 | - } | ||
93 | - | ||
94 | - if ((riscv_cpu_virt_enabled(env) || two_stage_lookup) && write_tval) { | ||
95 | + if (env->two_stage_lookup && write_tval) { | ||
96 | /* | ||
97 | * If we are writing a guest virtual address to stval, set | ||
98 | * this to 1. If we are trapping to VS we will set this to 0 | ||
99 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 159 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
100 | riscv_cpu_set_force_hs_excep(env, 0); | 160 | env->mstatus = s; |
101 | } else { | 161 | env->mcause = cause | ~(((target_ulong)-1) >> async); |
102 | /* Trap into HS mode */ | 162 | env->mepc = env->pc; |
103 | - if (!two_stage_lookup) { | 163 | - env->mbadaddr = tval; |
104 | - env->hstatus = set_field(env->hstatus, HSTATUS_SPV, | 164 | + env->mtval = tval; |
105 | - riscv_cpu_virt_enabled(env)); | 165 | env->mtval2 = mtval2; |
106 | - } | 166 | env->pc = (env->mtvec >> 2 << 2) + |
107 | + env->hstatus = set_field(env->hstatus, HSTATUS_SPV, false); | 167 | ((async && (env->mtvec & 3) == 1) ? cause * 4 : 0); |
108 | htval = env->guest_phys_fault_addr; | 168 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
109 | } | 169 | index XXXXXXX..XXXXXXX 100644 |
110 | } | 170 | --- a/target/riscv/csr.c |
111 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 171 | +++ b/target/riscv/csr.c |
112 | * RISC-V ISA Specification. | 172 | @@ -XXX,XX +XXX,XX @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) |
113 | */ | 173 | return 0; |
114 | 174 | } | |
115 | + env->two_stage_lookup = false; | 175 | |
116 | #endif | 176 | -/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ |
117 | cs->exception_index = EXCP_NONE; /* mark handled to qemu */ | 177 | -static int read_mscounteren(CPURISCVState *env, int csrno, target_ulong *val) |
118 | } | 178 | -{ |
179 | - if (env->priv_ver < PRIV_VERSION_1_11_0) { | ||
180 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
181 | - } | ||
182 | - *val = env->mcounteren; | ||
183 | - return 0; | ||
184 | -} | ||
185 | - | ||
186 | -/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ | ||
187 | -static int write_mscounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
188 | -{ | ||
189 | - if (env->priv_ver < PRIV_VERSION_1_11_0) { | ||
190 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
191 | - } | ||
192 | - env->mcounteren = val; | ||
193 | - return 0; | ||
194 | -} | ||
195 | - | ||
196 | /* Machine Trap Handling */ | ||
197 | static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
198 | { | ||
199 | @@ -XXX,XX +XXX,XX @@ static int write_mcause(CPURISCVState *env, int csrno, target_ulong val) | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | -static int read_mbadaddr(CPURISCVState *env, int csrno, target_ulong *val) | ||
204 | +static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val) | ||
205 | { | ||
206 | - *val = env->mbadaddr; | ||
207 | + *val = env->mtval; | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | -static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val) | ||
212 | +static int write_mtval(CPURISCVState *env, int csrno, target_ulong val) | ||
213 | { | ||
214 | - env->mbadaddr = val; | ||
215 | + env->mtval = val; | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | @@ -XXX,XX +XXX,XX @@ static int write_scause(CPURISCVState *env, int csrno, target_ulong val) | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | -static int read_sbadaddr(CPURISCVState *env, int csrno, target_ulong *val) | ||
224 | +static int read_stval(CPURISCVState *env, int csrno, target_ulong *val) | ||
225 | { | ||
226 | - *val = env->sbadaddr; | ||
227 | + *val = env->stval; | ||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | -static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) | ||
232 | +static int write_stval(CPURISCVState *env, int csrno, target_ulong val) | ||
233 | { | ||
234 | - env->sbadaddr = val; | ||
235 | + env->stval = val; | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | ||
240 | |||
241 | [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush }, | ||
242 | |||
243 | - [CSR_MSCOUNTEREN] = { "msounteren", any, read_mscounteren, write_mscounteren }, | ||
244 | - | ||
245 | /* Machine Trap Handling */ | ||
246 | [CSR_MSCRATCH] = { "mscratch", any, read_mscratch, write_mscratch }, | ||
247 | [CSR_MEPC] = { "mepc", any, read_mepc, write_mepc }, | ||
248 | [CSR_MCAUSE] = { "mcause", any, read_mcause, write_mcause }, | ||
249 | - [CSR_MBADADDR] = { "mbadaddr", any, read_mbadaddr, write_mbadaddr }, | ||
250 | + [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, | ||
251 | [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, | ||
252 | |||
253 | /* Supervisor Trap Setup */ | ||
254 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | ||
255 | [CSR_SSCRATCH] = { "sscratch", smode, read_sscratch, write_sscratch }, | ||
256 | [CSR_SEPC] = { "sepc", smode, read_sepc, write_sepc }, | ||
257 | [CSR_SCAUSE] = { "scause", smode, read_scause, write_scause }, | ||
258 | - [CSR_SBADADDR] = { "sbadaddr", smode, read_sbadaddr, write_sbadaddr }, | ||
259 | + [CSR_STVAL] = { "stval", smode, read_stval, write_stval }, | ||
260 | [CSR_SIP] = { "sip", smode, NULL, NULL, rmw_sip }, | ||
261 | |||
262 | /* Supervisor Protection and Translation */ | ||
263 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
264 | index XXXXXXX..XXXXXXX 100644 | ||
265 | --- a/target/riscv/machine.c | ||
266 | +++ b/target/riscv/machine.c | ||
267 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_hyper = { | ||
268 | |||
269 | const VMStateDescription vmstate_riscv_cpu = { | ||
270 | .name = "cpu", | ||
271 | - .version_id = 1, | ||
272 | - .minimum_version_id = 1, | ||
273 | + .version_id = 2, | ||
274 | + .minimum_version_id = 2, | ||
275 | .fields = (VMStateField[]) { | ||
276 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | ||
277 | VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), | ||
278 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
279 | VMSTATE_UINT32(env.miclaim, RISCVCPU), | ||
280 | VMSTATE_UINTTL(env.mie, RISCVCPU), | ||
281 | VMSTATE_UINTTL(env.mideleg, RISCVCPU), | ||
282 | - VMSTATE_UINTTL(env.sptbr, RISCVCPU), | ||
283 | VMSTATE_UINTTL(env.satp, RISCVCPU), | ||
284 | - VMSTATE_UINTTL(env.sbadaddr, RISCVCPU), | ||
285 | - VMSTATE_UINTTL(env.mbadaddr, RISCVCPU), | ||
286 | + VMSTATE_UINTTL(env.stval, RISCVCPU), | ||
287 | VMSTATE_UINTTL(env.medeleg, RISCVCPU), | ||
288 | VMSTATE_UINTTL(env.stvec, RISCVCPU), | ||
289 | VMSTATE_UINTTL(env.sepc, RISCVCPU), | ||
290 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
291 | index XXXXXXX..XXXXXXX 100644 | ||
292 | --- a/target/riscv/translate.c | ||
293 | +++ b/target/riscv/translate.c | ||
294 | @@ -XXX,XX +XXX,XX @@ static void generate_exception(DisasContext *ctx, int excp) | ||
295 | ctx->base.is_jmp = DISAS_NORETURN; | ||
296 | } | ||
297 | |||
298 | -static void generate_exception_mbadaddr(DisasContext *ctx, int excp) | ||
299 | +static void generate_exception_mtval(DisasContext *ctx, int excp) | ||
300 | { | ||
301 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | ||
302 | tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); | ||
303 | @@ -XXX,XX +XXX,XX @@ static void gen_exception_illegal(DisasContext *ctx) | ||
304 | |||
305 | static void gen_exception_inst_addr_mis(DisasContext *ctx) | ||
306 | { | ||
307 | - generate_exception_mbadaddr(ctx, RISCV_EXCP_INST_ADDR_MIS); | ||
308 | + generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS); | ||
309 | } | ||
310 | |||
311 | static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) | ||
119 | -- | 312 | -- |
120 | 2.30.1 | 313 | 2.31.1 |
121 | 314 | ||
122 | 315 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Axel Heider <axelheider@gmx.de> | ||
1 | 2 | ||
3 | Fix style to have a proper description of the parameter 'force-raw'. | ||
4 | |||
5 | Signed-off-by: Axel Heider <axelheider@gmx.de> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: a7e50a64-1c7c-2d41-96d3-d8a417a659ac@gmx.de | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | docs/system/generic-loader.rst | 9 ++++++--- | ||
11 | 1 file changed, 6 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/docs/system/generic-loader.rst b/docs/system/generic-loader.rst | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/docs/system/generic-loader.rst | ||
16 | +++ b/docs/system/generic-loader.rst | ||
17 | @@ -XXX,XX +XXX,XX @@ shown below: | ||
18 | specified in the executable format header. This option should only | ||
19 | be used for the boot image. This will also cause the image to be | ||
20 | written to the specified CPU's address space. If not specified, the | ||
21 | - default is CPU 0. <force-raw> - Setting force-raw=on forces the file | ||
22 | - to be treated as a raw image. This can be used to load supported | ||
23 | - executable formats as if they were raw. | ||
24 | + default is CPU 0. | ||
25 | + | ||
26 | +``<force-raw>`` | ||
27 | + Setting 'force-raw=on' forces the file to be treated as a raw image. | ||
28 | + This can be used to load supported executable formats as if they | ||
29 | + were raw. | ||
30 | |||
31 | All values are parsed using the standard QemuOpts parsing. This allows the user | ||
32 | to specify any values in any format supported. By default the values | ||
33 | -- | ||
34 | 2.31.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
1 | From: Asherah Connor <ashe@kivikakk.ee> | 1 | From: Dylan Jhong <dylan@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | Allow ramfb on virt. This lets `-device ramfb' work. | 3 | Use target_ulong to instead of uint64_t on reset vector address |
4 | to adapt on both 32/64 machine. | ||
4 | 5 | ||
5 | Signed-off-by: Asherah Connor <ashe@kivikakk.ee> | 6 | Signed-off-by: Dylan Jhong <dylan@andestech.com> |
7 | Signed-off-by: Ruinland ChuanTzu Tsai <ruinland@andestech.com> | ||
6 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20210318235041.17175-3-ashe@kivikakk.ee | 10 | Message-id: 20210329034801.22667-1-dylan@andestech.com |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 12 | --- |
11 | hw/riscv/virt.c | 3 +++ | 13 | target/riscv/cpu.c | 2 +- |
12 | 1 file changed, 3 insertions(+) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/virt.c | 18 | --- a/target/riscv/cpu.c |
17 | +++ b/hw/riscv/virt.c | 19 | +++ b/target/riscv/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static void set_feature(CPURISCVState *env, int feature) |
19 | #include "sysemu/sysemu.h" | 21 | env->features |= (1ULL << feature); |
20 | #include "hw/pci/pci.h" | ||
21 | #include "hw/pci-host/gpex.h" | ||
22 | +#include "hw/display/ramfb.h" | ||
23 | |||
24 | static const MemMapEntry virt_memmap[] = { | ||
25 | [VIRT_DEBUG] = { 0x0, 0x100 }, | ||
26 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | ||
27 | mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props; | ||
28 | mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id; | ||
29 | mc->numa_mem_supported = true; | ||
30 | + | ||
31 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | ||
32 | } | 22 | } |
33 | 23 | ||
34 | static const TypeInfo virt_machine_typeinfo = { | 24 | -static void set_resetvec(CPURISCVState *env, int resetvec) |
25 | +static void set_resetvec(CPURISCVState *env, target_ulong resetvec) | ||
26 | { | ||
27 | #ifndef CONFIG_USER_ONLY | ||
28 | env->resetvec = resetvec; | ||
35 | -- | 29 | -- |
36 | 2.30.1 | 30 | 2.31.1 |
37 | 31 | ||
38 | 32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bin Meng <bmeng.cn@gmail.com> | ||
1 | 2 | ||
3 | This was accidentally dropped before. Add it back. | ||
4 | |||
5 | Fixes: 732612856a8 ("hw/riscv: Drop 'struct MemmapEntry'") | ||
6 | Reported-by: Emmanuel Blot <eblot.ml@gmail.com> | ||
7 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20210331103612.654261-1-bmeng.cn@gmail.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | hw/riscv/sifive_e.c | 2 +- | ||
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/riscv/sifive_e.c | ||
19 | +++ b/hw/riscv/sifive_e.c | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | #include "sysemu/arch_init.h" | ||
22 | #include "sysemu/sysemu.h" | ||
23 | |||
24 | -static MemMapEntry sifive_e_memmap[] = { | ||
25 | +static const MemMapEntry sifive_e_memmap[] = { | ||
26 | [SIFIVE_E_DEV_DEBUG] = { 0x0, 0x1000 }, | ||
27 | [SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 }, | ||
28 | [SIFIVE_E_DEV_OTP] = { 0x20000, 0x2000 }, | ||
29 | -- | ||
30 | 2.31.1 | ||
31 | |||
32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vijai Kumar K <vijai@behindbytes.com> | ||
1 | 2 | ||
3 | C-Class is a member of the SHAKTI family of processors from IIT-M. | ||
4 | |||
5 | It is an extremely configurable and commercial-grade 5-stage in-order | ||
6 | core supporting the standard RV64GCSUN ISA extensions. | ||
7 | |||
8 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20210401181457.73039-2-vijai@behindbytes.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/cpu.h | 1 + | ||
14 | target/riscv/cpu.c | 1 + | ||
15 | 2 files changed, 2 insertions(+) | ||
16 | |||
17 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/cpu.h | ||
20 | +++ b/target/riscv/cpu.h | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") | ||
23 | #define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") | ||
24 | #define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") | ||
25 | +#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c") | ||
26 | #define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") | ||
27 | #define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34") | ||
28 | #define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") | ||
29 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/cpu.c | ||
32 | +++ b/target/riscv/cpu.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
34 | DEFINE_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init), | ||
35 | DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init), | ||
36 | DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init), | ||
37 | + DEFINE_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init), | ||
38 | #endif | ||
39 | }; | ||
40 | |||
41 | -- | ||
42 | 2.31.1 | ||
43 | |||
44 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vijai Kumar K <vijai@behindbytes.com> | |
2 | |||
3 | Add support for emulating Shakti reference platform based on C-class | ||
4 | running on arty-100T board. | ||
5 | |||
6 | https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/README.rst | ||
7 | |||
8 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20210401181457.73039-3-vijai@behindbytes.com | ||
11 | [Changes by AF: | ||
12 | - Check for mstate->firmware before loading it | ||
13 | ] | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | default-configs/devices/riscv64-softmmu.mak | 1 + | ||
17 | include/hw/riscv/shakti_c.h | 73 +++++++++ | ||
18 | hw/riscv/shakti_c.c | 173 ++++++++++++++++++++ | ||
19 | MAINTAINERS | 7 + | ||
20 | hw/riscv/Kconfig | 10 ++ | ||
21 | hw/riscv/meson.build | 1 + | ||
22 | 6 files changed, 265 insertions(+) | ||
23 | create mode 100644 include/hw/riscv/shakti_c.h | ||
24 | create mode 100644 hw/riscv/shakti_c.c | ||
25 | |||
26 | diff --git a/default-configs/devices/riscv64-softmmu.mak b/default-configs/devices/riscv64-softmmu.mak | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/default-configs/devices/riscv64-softmmu.mak | ||
29 | +++ b/default-configs/devices/riscv64-softmmu.mak | ||
30 | @@ -XXX,XX +XXX,XX @@ CONFIG_SIFIVE_E=y | ||
31 | CONFIG_SIFIVE_U=y | ||
32 | CONFIG_RISCV_VIRT=y | ||
33 | CONFIG_MICROCHIP_PFSOC=y | ||
34 | +CONFIG_SHAKTI_C=y | ||
35 | diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h | ||
36 | new file mode 100644 | ||
37 | index XXXXXXX..XXXXXXX | ||
38 | --- /dev/null | ||
39 | +++ b/include/hw/riscv/shakti_c.h | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | +/* | ||
42 | + * Shakti C-class SoC emulation | ||
43 | + * | ||
44 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
45 | + * | ||
46 | + * This program is free software; you can redistribute it and/or modify it | ||
47 | + * under the terms and conditions of the GNU General Public License, | ||
48 | + * version 2 or later, as published by the Free Software Foundation. | ||
49 | + * | ||
50 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
51 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
52 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
53 | + * more details. | ||
54 | + * | ||
55 | + * You should have received a copy of the GNU General Public License along with | ||
56 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
57 | + */ | ||
58 | + | ||
59 | +#ifndef HW_SHAKTI_H | ||
60 | +#define HW_SHAKTI_H | ||
61 | + | ||
62 | +#include "hw/riscv/riscv_hart.h" | ||
63 | +#include "hw/boards.h" | ||
64 | + | ||
65 | +#define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc" | ||
66 | +#define RISCV_SHAKTI_SOC(obj) \ | ||
67 | + OBJECT_CHECK(ShaktiCSoCState, (obj), TYPE_RISCV_SHAKTI_SOC) | ||
68 | + | ||
69 | +typedef struct ShaktiCSoCState { | ||
70 | + /*< private >*/ | ||
71 | + DeviceState parent_obj; | ||
72 | + | ||
73 | + /*< public >*/ | ||
74 | + RISCVHartArrayState cpus; | ||
75 | + DeviceState *plic; | ||
76 | + MemoryRegion rom; | ||
77 | + | ||
78 | +} ShaktiCSoCState; | ||
79 | + | ||
80 | +#define TYPE_RISCV_SHAKTI_MACHINE MACHINE_TYPE_NAME("shakti_c") | ||
81 | +#define RISCV_SHAKTI_MACHINE(obj) \ | ||
82 | + OBJECT_CHECK(ShaktiCMachineState, (obj), TYPE_RISCV_SHAKTI_MACHINE) | ||
83 | +typedef struct ShaktiCMachineState { | ||
84 | + /*< private >*/ | ||
85 | + MachineState parent_obj; | ||
86 | + | ||
87 | + /*< public >*/ | ||
88 | + ShaktiCSoCState soc; | ||
89 | +} ShaktiCMachineState; | ||
90 | + | ||
91 | +enum { | ||
92 | + SHAKTI_C_ROM, | ||
93 | + SHAKTI_C_RAM, | ||
94 | + SHAKTI_C_UART, | ||
95 | + SHAKTI_C_GPIO, | ||
96 | + SHAKTI_C_PLIC, | ||
97 | + SHAKTI_C_CLINT, | ||
98 | + SHAKTI_C_I2C, | ||
99 | +}; | ||
100 | + | ||
101 | +#define SHAKTI_C_PLIC_HART_CONFIG "MS" | ||
102 | +/* Including Interrupt ID 0 (no interrupt)*/ | ||
103 | +#define SHAKTI_C_PLIC_NUM_SOURCES 28 | ||
104 | +/* Excluding Priority 0 */ | ||
105 | +#define SHAKTI_C_PLIC_NUM_PRIORITIES 2 | ||
106 | +#define SHAKTI_C_PLIC_PRIORITY_BASE 0x04 | ||
107 | +#define SHAKTI_C_PLIC_PENDING_BASE 0x1000 | ||
108 | +#define SHAKTI_C_PLIC_ENABLE_BASE 0x2000 | ||
109 | +#define SHAKTI_C_PLIC_ENABLE_STRIDE 0x80 | ||
110 | +#define SHAKTI_C_PLIC_CONTEXT_BASE 0x200000 | ||
111 | +#define SHAKTI_C_PLIC_CONTEXT_STRIDE 0x1000 | ||
112 | + | ||
113 | +#endif | ||
114 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c | ||
115 | new file mode 100644 | ||
116 | index XXXXXXX..XXXXXXX | ||
117 | --- /dev/null | ||
118 | +++ b/hw/riscv/shakti_c.c | ||
119 | @@ -XXX,XX +XXX,XX @@ | ||
120 | +/* | ||
121 | + * Shakti C-class SoC emulation | ||
122 | + * | ||
123 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
124 | + * | ||
125 | + * This program is free software; you can redistribute it and/or modify it | ||
126 | + * under the terms and conditions of the GNU General Public License, | ||
127 | + * version 2 or later, as published by the Free Software Foundation. | ||
128 | + * | ||
129 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
130 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
131 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
132 | + * more details. | ||
133 | + * | ||
134 | + * You should have received a copy of the GNU General Public License along with | ||
135 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
136 | + */ | ||
137 | + | ||
138 | +#include "qemu/osdep.h" | ||
139 | +#include "hw/boards.h" | ||
140 | +#include "hw/riscv/shakti_c.h" | ||
141 | +#include "qapi/error.h" | ||
142 | +#include "hw/intc/sifive_plic.h" | ||
143 | +#include "hw/intc/sifive_clint.h" | ||
144 | +#include "sysemu/sysemu.h" | ||
145 | +#include "hw/qdev-properties.h" | ||
146 | +#include "exec/address-spaces.h" | ||
147 | +#include "hw/riscv/boot.h" | ||
148 | + | ||
149 | + | ||
150 | +static const struct MemmapEntry { | ||
151 | + hwaddr base; | ||
152 | + hwaddr size; | ||
153 | +} shakti_c_memmap[] = { | ||
154 | + [SHAKTI_C_ROM] = { 0x00001000, 0x2000 }, | ||
155 | + [SHAKTI_C_RAM] = { 0x80000000, 0x0 }, | ||
156 | + [SHAKTI_C_UART] = { 0x00011300, 0x00040 }, | ||
157 | + [SHAKTI_C_GPIO] = { 0x020d0000, 0x00100 }, | ||
158 | + [SHAKTI_C_PLIC] = { 0x0c000000, 0x20000 }, | ||
159 | + [SHAKTI_C_CLINT] = { 0x02000000, 0xc0000 }, | ||
160 | + [SHAKTI_C_I2C] = { 0x20c00000, 0x00100 }, | ||
161 | +}; | ||
162 | + | ||
163 | +static void shakti_c_machine_state_init(MachineState *mstate) | ||
164 | +{ | ||
165 | + ShaktiCMachineState *sms = RISCV_SHAKTI_MACHINE(mstate); | ||
166 | + MemoryRegion *system_memory = get_system_memory(); | ||
167 | + MemoryRegion *main_mem = g_new(MemoryRegion, 1); | ||
168 | + | ||
169 | + /* Allow only Shakti C CPU for this platform */ | ||
170 | + if (strcmp(mstate->cpu_type, TYPE_RISCV_CPU_SHAKTI_C) != 0) { | ||
171 | + error_report("This board can only be used with Shakti C CPU"); | ||
172 | + exit(1); | ||
173 | + } | ||
174 | + | ||
175 | + /* Initialize SoC */ | ||
176 | + object_initialize_child(OBJECT(mstate), "soc", &sms->soc, | ||
177 | + TYPE_RISCV_SHAKTI_SOC); | ||
178 | + qdev_realize(DEVICE(&sms->soc), NULL, &error_abort); | ||
179 | + | ||
180 | + /* register RAM */ | ||
181 | + memory_region_init_ram(main_mem, NULL, "riscv.shakti.c.ram", | ||
182 | + mstate->ram_size, &error_fatal); | ||
183 | + memory_region_add_subregion(system_memory, | ||
184 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
185 | + main_mem); | ||
186 | + | ||
187 | + /* ROM reset vector */ | ||
188 | + riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus, | ||
189 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
190 | + shakti_c_memmap[SHAKTI_C_ROM].base, | ||
191 | + shakti_c_memmap[SHAKTI_C_ROM].size, 0, 0, | ||
192 | + NULL); | ||
193 | + if (mstate->firmware) { | ||
194 | + riscv_load_firmware(mstate->firmware, | ||
195 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
196 | + NULL); | ||
197 | + } | ||
198 | +} | ||
199 | + | ||
200 | +static void shakti_c_machine_instance_init(Object *obj) | ||
201 | +{ | ||
202 | +} | ||
203 | + | ||
204 | +static void shakti_c_machine_class_init(ObjectClass *klass, void *data) | ||
205 | +{ | ||
206 | + MachineClass *mc = MACHINE_CLASS(klass); | ||
207 | + mc->desc = "RISC-V Board compatible with Shakti SDK"; | ||
208 | + mc->init = shakti_c_machine_state_init; | ||
209 | + mc->default_cpu_type = TYPE_RISCV_CPU_SHAKTI_C; | ||
210 | +} | ||
211 | + | ||
212 | +static const TypeInfo shakti_c_machine_type_info = { | ||
213 | + .name = TYPE_RISCV_SHAKTI_MACHINE, | ||
214 | + .parent = TYPE_MACHINE, | ||
215 | + .class_init = shakti_c_machine_class_init, | ||
216 | + .instance_init = shakti_c_machine_instance_init, | ||
217 | + .instance_size = sizeof(ShaktiCMachineState), | ||
218 | +}; | ||
219 | + | ||
220 | +static void shakti_c_machine_type_info_register(void) | ||
221 | +{ | ||
222 | + type_register_static(&shakti_c_machine_type_info); | ||
223 | +} | ||
224 | +type_init(shakti_c_machine_type_info_register) | ||
225 | + | ||
226 | +static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp) | ||
227 | +{ | ||
228 | + ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(dev); | ||
229 | + MemoryRegion *system_memory = get_system_memory(); | ||
230 | + | ||
231 | + sysbus_realize(SYS_BUS_DEVICE(&sss->cpus), &error_abort); | ||
232 | + | ||
233 | + sss->plic = sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base, | ||
234 | + (char *)SHAKTI_C_PLIC_HART_CONFIG, 0, | ||
235 | + SHAKTI_C_PLIC_NUM_SOURCES, | ||
236 | + SHAKTI_C_PLIC_NUM_PRIORITIES, | ||
237 | + SHAKTI_C_PLIC_PRIORITY_BASE, | ||
238 | + SHAKTI_C_PLIC_PENDING_BASE, | ||
239 | + SHAKTI_C_PLIC_ENABLE_BASE, | ||
240 | + SHAKTI_C_PLIC_ENABLE_STRIDE, | ||
241 | + SHAKTI_C_PLIC_CONTEXT_BASE, | ||
242 | + SHAKTI_C_PLIC_CONTEXT_STRIDE, | ||
243 | + shakti_c_memmap[SHAKTI_C_PLIC].size); | ||
244 | + | ||
245 | + sifive_clint_create(shakti_c_memmap[SHAKTI_C_CLINT].base, | ||
246 | + shakti_c_memmap[SHAKTI_C_CLINT].size, 0, 1, | ||
247 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | ||
248 | + SIFIVE_CLINT_TIMEBASE_FREQ, false); | ||
249 | + | ||
250 | + /* ROM */ | ||
251 | + memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom", | ||
252 | + shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal); | ||
253 | + memory_region_add_subregion(system_memory, | ||
254 | + shakti_c_memmap[SHAKTI_C_ROM].base, &sss->rom); | ||
255 | +} | ||
256 | + | ||
257 | +static void shakti_c_soc_class_init(ObjectClass *klass, void *data) | ||
258 | +{ | ||
259 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
260 | + dc->realize = shakti_c_soc_state_realize; | ||
261 | +} | ||
262 | + | ||
263 | +static void shakti_c_soc_instance_init(Object *obj) | ||
264 | +{ | ||
265 | + ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj); | ||
266 | + | ||
267 | + object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY); | ||
268 | + | ||
269 | + /* | ||
270 | + * CPU type is fixed and we are not supporting passing from commandline yet. | ||
271 | + * So let it be in instance_init. When supported should use ms->cpu_type | ||
272 | + * instead of TYPE_RISCV_CPU_SHAKTI_C | ||
273 | + */ | ||
274 | + object_property_set_str(OBJECT(&sss->cpus), "cpu-type", | ||
275 | + TYPE_RISCV_CPU_SHAKTI_C, &error_abort); | ||
276 | + object_property_set_int(OBJECT(&sss->cpus), "num-harts", 1, | ||
277 | + &error_abort); | ||
278 | +} | ||
279 | + | ||
280 | +static const TypeInfo shakti_c_type_info = { | ||
281 | + .name = TYPE_RISCV_SHAKTI_SOC, | ||
282 | + .parent = TYPE_DEVICE, | ||
283 | + .class_init = shakti_c_soc_class_init, | ||
284 | + .instance_init = shakti_c_soc_instance_init, | ||
285 | + .instance_size = sizeof(ShaktiCSoCState), | ||
286 | +}; | ||
287 | + | ||
288 | +static void shakti_c_type_info_register(void) | ||
289 | +{ | ||
290 | + type_register_static(&shakti_c_type_info); | ||
291 | +} | ||
292 | +type_init(shakti_c_type_info_register) | ||
293 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
294 | index XXXXXXX..XXXXXXX 100644 | ||
295 | --- a/MAINTAINERS | ||
296 | +++ b/MAINTAINERS | ||
297 | @@ -XXX,XX +XXX,XX @@ F: include/hw/misc/mchp_pfsoc_dmc.h | ||
298 | F: include/hw/misc/mchp_pfsoc_ioscb.h | ||
299 | F: include/hw/misc/mchp_pfsoc_sysreg.h | ||
300 | |||
301 | +Shakti C class SoC | ||
302 | +M: Vijai Kumar K <vijai@behindbytes.com> | ||
303 | +L: qemu-riscv@nongnu.org | ||
304 | +S: Supported | ||
305 | +F: hw/riscv/shakti_c.c | ||
306 | +F: include/hw/riscv/shakti_c.h | ||
307 | + | ||
308 | SiFive Machines | ||
309 | M: Alistair Francis <Alistair.Francis@wdc.com> | ||
310 | M: Bin Meng <bin.meng@windriver.com> | ||
311 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
312 | index XXXXXXX..XXXXXXX 100644 | ||
313 | --- a/hw/riscv/Kconfig | ||
314 | +++ b/hw/riscv/Kconfig | ||
315 | @@ -XXX,XX +XXX,XX @@ config OPENTITAN | ||
316 | select IBEX | ||
317 | select UNIMP | ||
318 | |||
319 | +config SHAKTI | ||
320 | + bool | ||
321 | + | ||
322 | +config SHAKTI_C | ||
323 | + bool | ||
324 | + select UNIMP | ||
325 | + select SHAKTI | ||
326 | + select SIFIVE_CLINT | ||
327 | + select SIFIVE_PLIC | ||
328 | + | ||
329 | config RISCV_VIRT | ||
330 | bool | ||
331 | imply PCI_DEVICES | ||
332 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
333 | index XXXXXXX..XXXXXXX 100644 | ||
334 | --- a/hw/riscv/meson.build | ||
335 | +++ b/hw/riscv/meson.build | ||
336 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c')) | ||
337 | riscv_ss.add(files('riscv_hart.c')) | ||
338 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
339 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
340 | +riscv_ss.add(when: 'CONFIG_SHAKTI_C', if_true: files('shakti_c.c')) | ||
341 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
342 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
343 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | ||
344 | -- | ||
345 | 2.31.1 | ||
346 | |||
347 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Vijai Kumar K <vijai@behindbytes.com> | |
2 | |||
3 | This is the initial implementation of Shakti UART. | ||
4 | |||
5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: 20210401181457.73039-4-vijai@behindbytes.com | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | include/hw/char/shakti_uart.h | 74 ++++++++++++++ | ||
11 | hw/char/shakti_uart.c | 185 ++++++++++++++++++++++++++++++++++ | ||
12 | MAINTAINERS | 2 + | ||
13 | hw/char/meson.build | 1 + | ||
14 | hw/char/trace-events | 4 + | ||
15 | 5 files changed, 266 insertions(+) | ||
16 | create mode 100644 include/hw/char/shakti_uart.h | ||
17 | create mode 100644 hw/char/shakti_uart.c | ||
18 | |||
19 | diff --git a/include/hw/char/shakti_uart.h b/include/hw/char/shakti_uart.h | ||
20 | new file mode 100644 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/include/hw/char/shakti_uart.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +/* | ||
26 | + * SHAKTI UART | ||
27 | + * | ||
28 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
29 | + * | ||
30 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
31 | + * of this software and associated documentation files (the "Software"), to deal | ||
32 | + * in the Software without restriction, including without limitation the rights | ||
33 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
34 | + * copies of the Software, and to permit persons to whom the Software is | ||
35 | + * furnished to do so, subject to the following conditions: | ||
36 | + * | ||
37 | + * The above copyright notice and this permission notice shall be included in | ||
38 | + * all copies or substantial portions of the Software. | ||
39 | + * | ||
40 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
41 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
42 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
43 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
44 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
45 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
46 | + * THE SOFTWARE. | ||
47 | + */ | ||
48 | + | ||
49 | +#ifndef HW_SHAKTI_UART_H | ||
50 | +#define HW_SHAKTI_UART_H | ||
51 | + | ||
52 | +#include "hw/sysbus.h" | ||
53 | +#include "chardev/char-fe.h" | ||
54 | + | ||
55 | +#define SHAKTI_UART_BAUD 0x00 | ||
56 | +#define SHAKTI_UART_TX 0x04 | ||
57 | +#define SHAKTI_UART_RX 0x08 | ||
58 | +#define SHAKTI_UART_STATUS 0x0C | ||
59 | +#define SHAKTI_UART_DELAY 0x10 | ||
60 | +#define SHAKTI_UART_CONTROL 0x14 | ||
61 | +#define SHAKTI_UART_INT_EN 0x18 | ||
62 | +#define SHAKTI_UART_IQ_CYCLES 0x1C | ||
63 | +#define SHAKTI_UART_RX_THRES 0x20 | ||
64 | + | ||
65 | +#define SHAKTI_UART_STATUS_TX_EMPTY (1 << 0) | ||
66 | +#define SHAKTI_UART_STATUS_TX_FULL (1 << 1) | ||
67 | +#define SHAKTI_UART_STATUS_RX_NOT_EMPTY (1 << 2) | ||
68 | +#define SHAKTI_UART_STATUS_RX_FULL (1 << 3) | ||
69 | +/* 9600 8N1 is the default setting */ | ||
70 | +/* Reg value = (50000000 Hz)/(16 * 9600)*/ | ||
71 | +#define SHAKTI_UART_BAUD_DEFAULT 0x0145 | ||
72 | +#define SHAKTI_UART_CONTROL_DEFAULT 0x0100 | ||
73 | + | ||
74 | +#define TYPE_SHAKTI_UART "shakti-uart" | ||
75 | +#define SHAKTI_UART(obj) \ | ||
76 | + OBJECT_CHECK(ShaktiUartState, (obj), TYPE_SHAKTI_UART) | ||
77 | + | ||
78 | +typedef struct { | ||
79 | + /* <private> */ | ||
80 | + SysBusDevice parent_obj; | ||
81 | + | ||
82 | + /* <public> */ | ||
83 | + MemoryRegion mmio; | ||
84 | + | ||
85 | + uint32_t uart_baud; | ||
86 | + uint32_t uart_tx; | ||
87 | + uint32_t uart_rx; | ||
88 | + uint32_t uart_status; | ||
89 | + uint32_t uart_delay; | ||
90 | + uint32_t uart_control; | ||
91 | + uint32_t uart_interrupt; | ||
92 | + uint32_t uart_iq_cycles; | ||
93 | + uint32_t uart_rx_threshold; | ||
94 | + | ||
95 | + CharBackend chr; | ||
96 | +} ShaktiUartState; | ||
97 | + | ||
98 | +#endif /* HW_SHAKTI_UART_H */ | ||
99 | diff --git a/hw/char/shakti_uart.c b/hw/char/shakti_uart.c | ||
100 | new file mode 100644 | ||
101 | index XXXXXXX..XXXXXXX | ||
102 | --- /dev/null | ||
103 | +++ b/hw/char/shakti_uart.c | ||
104 | @@ -XXX,XX +XXX,XX @@ | ||
105 | +/* | ||
106 | + * SHAKTI UART | ||
107 | + * | ||
108 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
109 | + * | ||
110 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
111 | + * of this software and associated documentation files (the "Software"), to deal | ||
112 | + * in the Software without restriction, including without limitation the rights | ||
113 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
114 | + * copies of the Software, and to permit persons to whom the Software is | ||
115 | + * furnished to do so, subject to the following conditions: | ||
116 | + * | ||
117 | + * The above copyright notice and this permission notice shall be included in | ||
118 | + * all copies or substantial portions of the Software. | ||
119 | + * | ||
120 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
121 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
122 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
123 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
124 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
125 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
126 | + * THE SOFTWARE. | ||
127 | + */ | ||
128 | + | ||
129 | +#include "qemu/osdep.h" | ||
130 | +#include "hw/char/shakti_uart.h" | ||
131 | +#include "hw/qdev-properties.h" | ||
132 | +#include "hw/qdev-properties-system.h" | ||
133 | +#include "qemu/log.h" | ||
134 | + | ||
135 | +static uint64_t shakti_uart_read(void *opaque, hwaddr addr, unsigned size) | ||
136 | +{ | ||
137 | + ShaktiUartState *s = opaque; | ||
138 | + | ||
139 | + switch (addr) { | ||
140 | + case SHAKTI_UART_BAUD: | ||
141 | + return s->uart_baud; | ||
142 | + case SHAKTI_UART_RX: | ||
143 | + qemu_chr_fe_accept_input(&s->chr); | ||
144 | + s->uart_status &= ~SHAKTI_UART_STATUS_RX_NOT_EMPTY; | ||
145 | + return s->uart_rx; | ||
146 | + case SHAKTI_UART_STATUS: | ||
147 | + return s->uart_status; | ||
148 | + case SHAKTI_UART_DELAY: | ||
149 | + return s->uart_delay; | ||
150 | + case SHAKTI_UART_CONTROL: | ||
151 | + return s->uart_control; | ||
152 | + case SHAKTI_UART_INT_EN: | ||
153 | + return s->uart_interrupt; | ||
154 | + case SHAKTI_UART_IQ_CYCLES: | ||
155 | + return s->uart_iq_cycles; | ||
156 | + case SHAKTI_UART_RX_THRES: | ||
157 | + return s->uart_rx_threshold; | ||
158 | + default: | ||
159 | + /* Also handles TX REG which is write only */ | ||
160 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
161 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); | ||
162 | + } | ||
163 | + | ||
164 | + return 0; | ||
165 | +} | ||
166 | + | ||
167 | +static void shakti_uart_write(void *opaque, hwaddr addr, | ||
168 | + uint64_t data, unsigned size) | ||
169 | +{ | ||
170 | + ShaktiUartState *s = opaque; | ||
171 | + uint32_t value = data; | ||
172 | + uint8_t ch; | ||
173 | + | ||
174 | + switch (addr) { | ||
175 | + case SHAKTI_UART_BAUD: | ||
176 | + s->uart_baud = value; | ||
177 | + break; | ||
178 | + case SHAKTI_UART_TX: | ||
179 | + ch = value; | ||
180 | + qemu_chr_fe_write_all(&s->chr, &ch, 1); | ||
181 | + s->uart_status &= ~SHAKTI_UART_STATUS_TX_FULL; | ||
182 | + break; | ||
183 | + case SHAKTI_UART_STATUS: | ||
184 | + s->uart_status = value; | ||
185 | + break; | ||
186 | + case SHAKTI_UART_DELAY: | ||
187 | + s->uart_delay = value; | ||
188 | + break; | ||
189 | + case SHAKTI_UART_CONTROL: | ||
190 | + s->uart_control = value; | ||
191 | + break; | ||
192 | + case SHAKTI_UART_INT_EN: | ||
193 | + s->uart_interrupt = value; | ||
194 | + break; | ||
195 | + case SHAKTI_UART_IQ_CYCLES: | ||
196 | + s->uart_iq_cycles = value; | ||
197 | + break; | ||
198 | + case SHAKTI_UART_RX_THRES: | ||
199 | + s->uart_rx_threshold = value; | ||
200 | + break; | ||
201 | + default: | ||
202 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
203 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); | ||
204 | + } | ||
205 | +} | ||
206 | + | ||
207 | +static const MemoryRegionOps shakti_uart_ops = { | ||
208 | + .read = shakti_uart_read, | ||
209 | + .write = shakti_uart_write, | ||
210 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
211 | + .impl = {.min_access_size = 1, .max_access_size = 4}, | ||
212 | + .valid = {.min_access_size = 1, .max_access_size = 4}, | ||
213 | +}; | ||
214 | + | ||
215 | +static void shakti_uart_reset(DeviceState *dev) | ||
216 | +{ | ||
217 | + ShaktiUartState *s = SHAKTI_UART(dev); | ||
218 | + | ||
219 | + s->uart_baud = SHAKTI_UART_BAUD_DEFAULT; | ||
220 | + s->uart_tx = 0x0; | ||
221 | + s->uart_rx = 0x0; | ||
222 | + s->uart_status = 0x0000; | ||
223 | + s->uart_delay = 0x0000; | ||
224 | + s->uart_control = SHAKTI_UART_CONTROL_DEFAULT; | ||
225 | + s->uart_interrupt = 0x0000; | ||
226 | + s->uart_iq_cycles = 0x00; | ||
227 | + s->uart_rx_threshold = 0x00; | ||
228 | +} | ||
229 | + | ||
230 | +static int shakti_uart_can_receive(void *opaque) | ||
231 | +{ | ||
232 | + ShaktiUartState *s = opaque; | ||
233 | + | ||
234 | + return !(s->uart_status & SHAKTI_UART_STATUS_RX_NOT_EMPTY); | ||
235 | +} | ||
236 | + | ||
237 | +static void shakti_uart_receive(void *opaque, const uint8_t *buf, int size) | ||
238 | +{ | ||
239 | + ShaktiUartState *s = opaque; | ||
240 | + | ||
241 | + s->uart_rx = *buf; | ||
242 | + s->uart_status |= SHAKTI_UART_STATUS_RX_NOT_EMPTY; | ||
243 | +} | ||
244 | + | ||
245 | +static void shakti_uart_realize(DeviceState *dev, Error **errp) | ||
246 | +{ | ||
247 | + ShaktiUartState *sus = SHAKTI_UART(dev); | ||
248 | + qemu_chr_fe_set_handlers(&sus->chr, shakti_uart_can_receive, | ||
249 | + shakti_uart_receive, NULL, NULL, sus, NULL, true); | ||
250 | +} | ||
251 | + | ||
252 | +static void shakti_uart_instance_init(Object *obj) | ||
253 | +{ | ||
254 | + ShaktiUartState *sus = SHAKTI_UART(obj); | ||
255 | + memory_region_init_io(&sus->mmio, | ||
256 | + obj, | ||
257 | + &shakti_uart_ops, | ||
258 | + sus, | ||
259 | + TYPE_SHAKTI_UART, | ||
260 | + 0x1000); | ||
261 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &sus->mmio); | ||
262 | +} | ||
263 | + | ||
264 | +static Property shakti_uart_properties[] = { | ||
265 | + DEFINE_PROP_CHR("chardev", ShaktiUartState, chr), | ||
266 | + DEFINE_PROP_END_OF_LIST(), | ||
267 | +}; | ||
268 | + | ||
269 | +static void shakti_uart_class_init(ObjectClass *klass, void *data) | ||
270 | +{ | ||
271 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
272 | + dc->reset = shakti_uart_reset; | ||
273 | + dc->realize = shakti_uart_realize; | ||
274 | + device_class_set_props(dc, shakti_uart_properties); | ||
275 | +} | ||
276 | + | ||
277 | +static const TypeInfo shakti_uart_info = { | ||
278 | + .name = TYPE_SHAKTI_UART, | ||
279 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
280 | + .instance_size = sizeof(ShaktiUartState), | ||
281 | + .class_init = shakti_uart_class_init, | ||
282 | + .instance_init = shakti_uart_instance_init, | ||
283 | +}; | ||
284 | + | ||
285 | +static void shakti_uart_register_types(void) | ||
286 | +{ | ||
287 | + type_register_static(&shakti_uart_info); | ||
288 | +} | ||
289 | +type_init(shakti_uart_register_types) | ||
290 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
291 | index XXXXXXX..XXXXXXX 100644 | ||
292 | --- a/MAINTAINERS | ||
293 | +++ b/MAINTAINERS | ||
294 | @@ -XXX,XX +XXX,XX @@ M: Vijai Kumar K <vijai@behindbytes.com> | ||
295 | L: qemu-riscv@nongnu.org | ||
296 | S: Supported | ||
297 | F: hw/riscv/shakti_c.c | ||
298 | +F: hw/char/shakti_uart.c | ||
299 | F: include/hw/riscv/shakti_c.h | ||
300 | +F: include/hw/char/shakti_uart.h | ||
301 | |||
302 | SiFive Machines | ||
303 | M: Alistair Francis <Alistair.Francis@wdc.com> | ||
304 | diff --git a/hw/char/meson.build b/hw/char/meson.build | ||
305 | index XXXXXXX..XXXXXXX 100644 | ||
306 | --- a/hw/char/meson.build | ||
307 | +++ b/hw/char/meson.build | ||
308 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SERIAL', if_true: files('serial.c')) | ||
309 | softmmu_ss.add(when: 'CONFIG_SERIAL_ISA', if_true: files('serial-isa.c')) | ||
310 | softmmu_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c')) | ||
311 | softmmu_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c')) | ||
312 | +softmmu_ss.add(when: 'CONFIG_SHAKTI', if_true: files('shakti_uart.c')) | ||
313 | softmmu_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-console.c')) | ||
314 | softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen_console.c')) | ||
315 | softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_uartlite.c')) | ||
316 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
317 | index XXXXXXX..XXXXXXX 100644 | ||
318 | --- a/hw/char/trace-events | ||
319 | +++ b/hw/char/trace-events | ||
320 | @@ -XXX,XX +XXX,XX @@ cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1" | ||
321 | nrf51_uart_read(uint64_t addr, uint64_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
322 | nrf51_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
323 | |||
324 | +# shakti_uart.c | ||
325 | +shakti_uart_read(uint64_t addr, uint16_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx16 " size %u" | ||
326 | +shakti_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
327 | + | ||
328 | # exynos4210_uart.c | ||
329 | exynos_uart_dmabusy(uint32_t channel) "UART%d: DMA busy (Rx buffer empty)" | ||
330 | exynos_uart_dmaready(uint32_t channel) "UART%d: DMA ready" | ||
331 | -- | ||
332 | 2.31.1 | ||
333 | |||
334 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vijai Kumar K <vijai@behindbytes.com> | ||
1 | 2 | ||
3 | Connect one shakti uart to the shakti_c machine. | ||
4 | |||
5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: 20210401181457.73039-5-vijai@behindbytes.com | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | include/hw/riscv/shakti_c.h | 2 ++ | ||
11 | hw/riscv/shakti_c.c | 8 ++++++++ | ||
12 | 2 files changed, 10 insertions(+) | ||
13 | |||
14 | diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/riscv/shakti_c.h | ||
17 | +++ b/include/hw/riscv/shakti_c.h | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | |||
20 | #include "hw/riscv/riscv_hart.h" | ||
21 | #include "hw/boards.h" | ||
22 | +#include "hw/char/shakti_uart.h" | ||
23 | |||
24 | #define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc" | ||
25 | #define RISCV_SHAKTI_SOC(obj) \ | ||
26 | @@ -XXX,XX +XXX,XX @@ typedef struct ShaktiCSoCState { | ||
27 | /*< public >*/ | ||
28 | RISCVHartArrayState cpus; | ||
29 | DeviceState *plic; | ||
30 | + ShaktiUartState uart; | ||
31 | MemoryRegion rom; | ||
32 | |||
33 | } ShaktiCSoCState; | ||
34 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/riscv/shakti_c.c | ||
37 | +++ b/hw/riscv/shakti_c.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp) | ||
39 | SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | ||
40 | SIFIVE_CLINT_TIMEBASE_FREQ, false); | ||
41 | |||
42 | + qdev_prop_set_chr(DEVICE(&(sss->uart)), "chardev", serial_hd(0)); | ||
43 | + if (!sysbus_realize(SYS_BUS_DEVICE(&sss->uart), errp)) { | ||
44 | + return; | ||
45 | + } | ||
46 | + sysbus_mmio_map(SYS_BUS_DEVICE(&sss->uart), 0, | ||
47 | + shakti_c_memmap[SHAKTI_C_UART].base); | ||
48 | + | ||
49 | /* ROM */ | ||
50 | memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom", | ||
51 | shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal); | ||
52 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_instance_init(Object *obj) | ||
53 | ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj); | ||
54 | |||
55 | object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY); | ||
56 | + object_initialize_child(obj, "uart", &sss->uart, TYPE_SHAKTI_UART); | ||
57 | |||
58 | /* | ||
59 | * CPU type is fixed and we are not supporting passing from commandline yet. | ||
60 | -- | ||
61 | 2.31.1 | ||
62 | |||
63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | Message-id: f191dcf08bf413a822e743a7c7f824d68879a527.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu_bits.h | 44 ++++++++++++++++++++------------------- | ||
7 | target/riscv/cpu.c | 2 +- | ||
8 | target/riscv/cpu_helper.c | 4 ++-- | ||
9 | 3 files changed, 26 insertions(+), 24 deletions(-) | ||
1 | 10 | ||
11 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/riscv/cpu_bits.h | ||
14 | +++ b/target/riscv/cpu_bits.h | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | #define DEFAULT_RSTVEC 0x1000 | ||
17 | |||
18 | /* Exception causes */ | ||
19 | -#define EXCP_NONE -1 /* sentinel value */ | ||
20 | -#define RISCV_EXCP_INST_ADDR_MIS 0x0 | ||
21 | -#define RISCV_EXCP_INST_ACCESS_FAULT 0x1 | ||
22 | -#define RISCV_EXCP_ILLEGAL_INST 0x2 | ||
23 | -#define RISCV_EXCP_BREAKPOINT 0x3 | ||
24 | -#define RISCV_EXCP_LOAD_ADDR_MIS 0x4 | ||
25 | -#define RISCV_EXCP_LOAD_ACCESS_FAULT 0x5 | ||
26 | -#define RISCV_EXCP_STORE_AMO_ADDR_MIS 0x6 | ||
27 | -#define RISCV_EXCP_STORE_AMO_ACCESS_FAULT 0x7 | ||
28 | -#define RISCV_EXCP_U_ECALL 0x8 | ||
29 | -#define RISCV_EXCP_S_ECALL 0x9 | ||
30 | -#define RISCV_EXCP_VS_ECALL 0xa | ||
31 | -#define RISCV_EXCP_M_ECALL 0xb | ||
32 | -#define RISCV_EXCP_INST_PAGE_FAULT 0xc /* since: priv-1.10.0 */ | ||
33 | -#define RISCV_EXCP_LOAD_PAGE_FAULT 0xd /* since: priv-1.10.0 */ | ||
34 | -#define RISCV_EXCP_STORE_PAGE_FAULT 0xf /* since: priv-1.10.0 */ | ||
35 | -#define RISCV_EXCP_SEMIHOST 0x10 | ||
36 | -#define RISCV_EXCP_INST_GUEST_PAGE_FAULT 0x14 | ||
37 | -#define RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT 0x15 | ||
38 | -#define RISCV_EXCP_VIRT_INSTRUCTION_FAULT 0x16 | ||
39 | -#define RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT 0x17 | ||
40 | +typedef enum RISCVException { | ||
41 | + RISCV_EXCP_NONE = -1, /* sentinel value */ | ||
42 | + RISCV_EXCP_INST_ADDR_MIS = 0x0, | ||
43 | + RISCV_EXCP_INST_ACCESS_FAULT = 0x1, | ||
44 | + RISCV_EXCP_ILLEGAL_INST = 0x2, | ||
45 | + RISCV_EXCP_BREAKPOINT = 0x3, | ||
46 | + RISCV_EXCP_LOAD_ADDR_MIS = 0x4, | ||
47 | + RISCV_EXCP_LOAD_ACCESS_FAULT = 0x5, | ||
48 | + RISCV_EXCP_STORE_AMO_ADDR_MIS = 0x6, | ||
49 | + RISCV_EXCP_STORE_AMO_ACCESS_FAULT = 0x7, | ||
50 | + RISCV_EXCP_U_ECALL = 0x8, | ||
51 | + RISCV_EXCP_S_ECALL = 0x9, | ||
52 | + RISCV_EXCP_VS_ECALL = 0xa, | ||
53 | + RISCV_EXCP_M_ECALL = 0xb, | ||
54 | + RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ | ||
55 | + RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ | ||
56 | + RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ | ||
57 | + RISCV_EXCP_SEMIHOST = 0x10, | ||
58 | + RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, | ||
59 | + RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, | ||
60 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, | ||
61 | + RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, | ||
62 | +} RISCVException; | ||
63 | |||
64 | #define RISCV_EXCP_INT_FLAG 0x80000000 | ||
65 | #define RISCV_EXCP_INT_MASK 0x7fffffff | ||
66 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/target/riscv/cpu.c | ||
69 | +++ b/target/riscv/cpu.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | ||
71 | env->pc = env->resetvec; | ||
72 | env->two_stage_lookup = false; | ||
73 | #endif | ||
74 | - cs->exception_index = EXCP_NONE; | ||
75 | + cs->exception_index = RISCV_EXCP_NONE; | ||
76 | env->load_res = -1; | ||
77 | set_default_nan_mode(1, &env->fp_status); | ||
78 | } | ||
79 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/target/riscv/cpu_helper.c | ||
82 | +++ b/target/riscv/cpu_helper.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env) | ||
84 | if (irqs) { | ||
85 | return ctz64(irqs); /* since non-zero */ | ||
86 | } else { | ||
87 | - return EXCP_NONE; /* indicates no pending interrupt */ | ||
88 | + return RISCV_EXCP_NONE; /* indicates no pending interrupt */ | ||
89 | } | ||
90 | } | ||
91 | #endif | ||
92 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | ||
93 | |||
94 | env->two_stage_lookup = false; | ||
95 | #endif | ||
96 | - cs->exception_index = EXCP_NONE; /* mark handled to qemu */ | ||
97 | + cs->exception_index = RISCV_EXCP_NONE; /* mark handled to qemu */ | ||
98 | } | ||
99 | -- | ||
100 | 2.31.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 3 +- | ||
7 | target/riscv/csr.c | 80 +++++++++++++++++++++++++--------------------- | ||
8 | 2 files changed, 46 insertions(+), 37 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/riscv/cpu.h | ||
13 | +++ b/target/riscv/cpu.h | ||
14 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) | ||
15 | return val; | ||
16 | } | ||
17 | |||
18 | -typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); | ||
19 | +typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, | ||
20 | + int csrno); | ||
21 | typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, | ||
22 | target_ulong *ret_value); | ||
23 | typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, | ||
24 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/riscv/csr.c | ||
27 | +++ b/target/riscv/csr.c | ||
28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) | ||
29 | } | ||
30 | |||
31 | /* Predicates */ | ||
32 | -static int fs(CPURISCVState *env, int csrno) | ||
33 | +static RISCVException fs(CPURISCVState *env, int csrno) | ||
34 | { | ||
35 | #if !defined(CONFIG_USER_ONLY) | ||
36 | /* loose check condition for fcsr in vector extension */ | ||
37 | if ((csrno == CSR_FCSR) && (env->misa & RVV)) { | ||
38 | - return 0; | ||
39 | + return RISCV_EXCP_NONE; | ||
40 | } | ||
41 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
42 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
43 | + return RISCV_EXCP_ILLEGAL_INST; | ||
44 | } | ||
45 | #endif | ||
46 | - return 0; | ||
47 | + return RISCV_EXCP_NONE; | ||
48 | } | ||
49 | |||
50 | -static int vs(CPURISCVState *env, int csrno) | ||
51 | +static RISCVException vs(CPURISCVState *env, int csrno) | ||
52 | { | ||
53 | if (env->misa & RVV) { | ||
54 | - return 0; | ||
55 | + return RISCV_EXCP_NONE; | ||
56 | } | ||
57 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
58 | + return RISCV_EXCP_ILLEGAL_INST; | ||
59 | } | ||
60 | |||
61 | -static int ctr(CPURISCVState *env, int csrno) | ||
62 | +static RISCVException ctr(CPURISCVState *env, int csrno) | ||
63 | { | ||
64 | #if !defined(CONFIG_USER_ONLY) | ||
65 | CPUState *cs = env_cpu(env); | ||
66 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) | ||
67 | |||
68 | if (!cpu->cfg.ext_counters) { | ||
69 | /* The Counters extensions is not enabled */ | ||
70 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
71 | + return RISCV_EXCP_ILLEGAL_INST; | ||
72 | } | ||
73 | |||
74 | if (riscv_cpu_virt_enabled(env)) { | ||
75 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) | ||
76 | case CSR_CYCLE: | ||
77 | if (!get_field(env->hcounteren, HCOUNTEREN_CY) && | ||
78 | get_field(env->mcounteren, HCOUNTEREN_CY)) { | ||
79 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
80 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
81 | } | ||
82 | break; | ||
83 | case CSR_TIME: | ||
84 | if (!get_field(env->hcounteren, HCOUNTEREN_TM) && | ||
85 | get_field(env->mcounteren, HCOUNTEREN_TM)) { | ||
86 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
87 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
88 | } | ||
89 | break; | ||
90 | case CSR_INSTRET: | ||
91 | if (!get_field(env->hcounteren, HCOUNTEREN_IR) && | ||
92 | get_field(env->mcounteren, HCOUNTEREN_IR)) { | ||
93 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
94 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
95 | } | ||
96 | break; | ||
97 | case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: | ||
98 | if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)) && | ||
99 | get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))) { | ||
100 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
101 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
102 | } | ||
103 | break; | ||
104 | } | ||
105 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) | ||
106 | case CSR_CYCLEH: | ||
107 | if (!get_field(env->hcounteren, HCOUNTEREN_CY) && | ||
108 | get_field(env->mcounteren, HCOUNTEREN_CY)) { | ||
109 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
110 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
111 | } | ||
112 | break; | ||
113 | case CSR_TIMEH: | ||
114 | if (!get_field(env->hcounteren, HCOUNTEREN_TM) && | ||
115 | get_field(env->mcounteren, HCOUNTEREN_TM)) { | ||
116 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
117 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
118 | } | ||
119 | break; | ||
120 | case CSR_INSTRETH: | ||
121 | if (!get_field(env->hcounteren, HCOUNTEREN_IR) && | ||
122 | get_field(env->mcounteren, HCOUNTEREN_IR)) { | ||
123 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
124 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
125 | } | ||
126 | break; | ||
127 | case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: | ||
128 | if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3H)) && | ||
129 | get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3H))) { | ||
130 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
131 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
132 | } | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | #endif | ||
138 | - return 0; | ||
139 | + return RISCV_EXCP_NONE; | ||
140 | } | ||
141 | |||
142 | -static int ctr32(CPURISCVState *env, int csrno) | ||
143 | +static RISCVException ctr32(CPURISCVState *env, int csrno) | ||
144 | { | ||
145 | if (!riscv_cpu_is_32bit(env)) { | ||
146 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
147 | + return RISCV_EXCP_ILLEGAL_INST; | ||
148 | } | ||
149 | |||
150 | return ctr(env, csrno); | ||
151 | } | ||
152 | |||
153 | #if !defined(CONFIG_USER_ONLY) | ||
154 | -static int any(CPURISCVState *env, int csrno) | ||
155 | +static RISCVException any(CPURISCVState *env, int csrno) | ||
156 | { | ||
157 | - return 0; | ||
158 | + return RISCV_EXCP_NONE; | ||
159 | } | ||
160 | |||
161 | -static int any32(CPURISCVState *env, int csrno) | ||
162 | +static RISCVException any32(CPURISCVState *env, int csrno) | ||
163 | { | ||
164 | if (!riscv_cpu_is_32bit(env)) { | ||
165 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
166 | + return RISCV_EXCP_ILLEGAL_INST; | ||
167 | } | ||
168 | |||
169 | return any(env, csrno); | ||
170 | |||
171 | } | ||
172 | |||
173 | -static int smode(CPURISCVState *env, int csrno) | ||
174 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
175 | { | ||
176 | - return -!riscv_has_ext(env, RVS); | ||
177 | + if (riscv_has_ext(env, RVS)) { | ||
178 | + return RISCV_EXCP_NONE; | ||
179 | + } | ||
180 | + | ||
181 | + return RISCV_EXCP_ILLEGAL_INST; | ||
182 | } | ||
183 | |||
184 | -static int hmode(CPURISCVState *env, int csrno) | ||
185 | +static RISCVException hmode(CPURISCVState *env, int csrno) | ||
186 | { | ||
187 | if (riscv_has_ext(env, RVS) && | ||
188 | riscv_has_ext(env, RVH)) { | ||
189 | /* Hypervisor extension is supported */ | ||
190 | if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || | ||
191 | env->priv == PRV_M) { | ||
192 | - return 0; | ||
193 | + return RISCV_EXCP_NONE; | ||
194 | } else { | ||
195 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
196 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
201 | + return RISCV_EXCP_ILLEGAL_INST; | ||
202 | } | ||
203 | |||
204 | -static int hmode32(CPURISCVState *env, int csrno) | ||
205 | +static RISCVException hmode32(CPURISCVState *env, int csrno) | ||
206 | { | ||
207 | if (!riscv_cpu_is_32bit(env)) { | ||
208 | - return 0; | ||
209 | + return RISCV_EXCP_NONE; | ||
210 | } | ||
211 | |||
212 | return hmode(env, csrno); | ||
213 | |||
214 | } | ||
215 | |||
216 | -static int pmp(CPURISCVState *env, int csrno) | ||
217 | +static RISCVException pmp(CPURISCVState *env, int csrno) | ||
218 | { | ||
219 | - return -!riscv_feature(env, RISCV_FEATURE_PMP); | ||
220 | + if (riscv_feature(env, RISCV_FEATURE_PMP)) { | ||
221 | + return RISCV_EXCP_NONE; | ||
222 | + } | ||
223 | + | ||
224 | + return RISCV_EXCP_ILLEGAL_INST; | ||
225 | } | ||
226 | #endif | ||
227 | |||
228 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
229 | return -RISCV_EXCP_ILLEGAL_INST; | ||
230 | } | ||
231 | ret = csr_ops[csrno].predicate(env, csrno); | ||
232 | - if (ret < 0) { | ||
233 | - return ret; | ||
234 | + if (ret != RISCV_EXCP_NONE) { | ||
235 | + return -ret; | ||
236 | } | ||
237 | |||
238 | /* execute combined read/write operation if it exists */ | ||
239 | -- | ||
240 | 2.31.1 | ||
241 | |||
242 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: cb1ef2061547dc9028ce3cf4f6622588f9c09149.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/csr.c | 6 +++++- | ||
7 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
1 | 8 | ||
9 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/riscv/csr.c | ||
12 | +++ b/target/riscv/csr.c | ||
13 | @@ -XXX,XX +XXX,XX @@ static RISCVException hmode(CPURISCVState *env, int csrno) | ||
14 | static RISCVException hmode32(CPURISCVState *env, int csrno) | ||
15 | { | ||
16 | if (!riscv_cpu_is_32bit(env)) { | ||
17 | - return RISCV_EXCP_NONE; | ||
18 | + if (riscv_cpu_virt_enabled(env)) { | ||
19 | + return RISCV_EXCP_ILLEGAL_INST; | ||
20 | + } else { | ||
21 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
22 | + } | ||
23 | } | ||
24 | |||
25 | return hmode(env, csrno); | ||
26 | -- | ||
27 | 2.31.1 | ||
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 8566c4c271723f27f3ae8fc2429f906a459f17ce.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 14 +- | ||
7 | target/riscv/csr.c | 629 +++++++++++++++++++++++++++------------------ | ||
8 | 2 files changed, 382 insertions(+), 261 deletions(-) | ||
2 | 9 | ||
3 | The previous implementation was broken in many ways: | 10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
4 | - Used mideleg instead of hideleg to mask accesses | 11 | index XXXXXXX..XXXXXXX 100644 |
5 | - Used MIP_VSSIP instead of VS_MODE_INTERRUPTS to mask writes to vsie | 12 | --- a/target/riscv/cpu.h |
6 | - Did not shift between S bits and VS bits (VSEIP <-> SEIP, ...) | 13 | +++ b/target/riscv/cpu.h |
7 | 14 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) | |
8 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 15 | |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 16 | typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, |
10 | Message-id: 20210311094738.1376795-1-georg.kotheimer@kernkonzept.com | 17 | int csrno); |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | -typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, |
12 | --- | 19 | - target_ulong *ret_value); |
13 | target/riscv/csr.c | 68 +++++++++++++++++++++++----------------------- | 20 | -typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, |
14 | 1 file changed, 34 insertions(+), 34 deletions(-) | 21 | - target_ulong new_value); |
15 | 22 | -typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, | |
23 | - target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); | ||
24 | +typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, | ||
25 | + target_ulong *ret_value); | ||
26 | +typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, | ||
27 | + target_ulong new_value); | ||
28 | +typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, | ||
29 | + target_ulong *ret_value, | ||
30 | + target_ulong new_value, | ||
31 | + target_ulong write_mask); | ||
32 | |||
33 | typedef struct { | ||
34 | const char *name; | ||
16 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 35 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
17 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/csr.c | 37 | --- a/target/riscv/csr.c |
19 | +++ b/target/riscv/csr.c | 38 | +++ b/target/riscv/csr.c |
20 | @@ -XXX,XX +XXX,XX @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) | 39 | @@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno) |
40 | #endif | ||
41 | |||
42 | /* User Floating-Point CSRs */ | ||
43 | -static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) | ||
44 | +static RISCVException read_fflags(CPURISCVState *env, int csrno, | ||
45 | + target_ulong *val) | ||
46 | { | ||
47 | #if !defined(CONFIG_USER_ONLY) | ||
48 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
49 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
50 | + return RISCV_EXCP_ILLEGAL_INST; | ||
51 | } | ||
52 | #endif | ||
53 | *val = riscv_cpu_get_fflags(env); | ||
54 | - return 0; | ||
55 | + return RISCV_EXCP_NONE; | ||
56 | } | ||
57 | |||
58 | -static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) | ||
59 | +static RISCVException write_fflags(CPURISCVState *env, int csrno, | ||
60 | + target_ulong val) | ||
61 | { | ||
62 | #if !defined(CONFIG_USER_ONLY) | ||
63 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
64 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
65 | + return RISCV_EXCP_ILLEGAL_INST; | ||
66 | } | ||
67 | env->mstatus |= MSTATUS_FS; | ||
68 | #endif | ||
69 | riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT)); | ||
70 | - return 0; | ||
71 | + return RISCV_EXCP_NONE; | ||
72 | } | ||
73 | |||
74 | -static int read_frm(CPURISCVState *env, int csrno, target_ulong *val) | ||
75 | +static RISCVException read_frm(CPURISCVState *env, int csrno, | ||
76 | + target_ulong *val) | ||
77 | { | ||
78 | #if !defined(CONFIG_USER_ONLY) | ||
79 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
80 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
81 | + return RISCV_EXCP_ILLEGAL_INST; | ||
82 | } | ||
83 | #endif | ||
84 | *val = env->frm; | ||
85 | - return 0; | ||
86 | + return RISCV_EXCP_NONE; | ||
87 | } | ||
88 | |||
89 | -static int write_frm(CPURISCVState *env, int csrno, target_ulong val) | ||
90 | +static RISCVException write_frm(CPURISCVState *env, int csrno, | ||
91 | + target_ulong val) | ||
92 | { | ||
93 | #if !defined(CONFIG_USER_ONLY) | ||
94 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
95 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
96 | + return RISCV_EXCP_ILLEGAL_INST; | ||
97 | } | ||
98 | env->mstatus |= MSTATUS_FS; | ||
99 | #endif | ||
100 | env->frm = val & (FSR_RD >> FSR_RD_SHIFT); | ||
101 | - return 0; | ||
102 | + return RISCV_EXCP_NONE; | ||
103 | } | ||
104 | |||
105 | -static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) | ||
106 | +static RISCVException read_fcsr(CPURISCVState *env, int csrno, | ||
107 | + target_ulong *val) | ||
108 | { | ||
109 | #if !defined(CONFIG_USER_ONLY) | ||
110 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
111 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
112 | + return RISCV_EXCP_ILLEGAL_INST; | ||
113 | } | ||
114 | #endif | ||
115 | *val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT) | ||
116 | @@ -XXX,XX +XXX,XX @@ static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) | ||
117 | *val |= (env->vxrm << FSR_VXRM_SHIFT) | ||
118 | | (env->vxsat << FSR_VXSAT_SHIFT); | ||
119 | } | ||
120 | - return 0; | ||
121 | + return RISCV_EXCP_NONE; | ||
122 | } | ||
123 | |||
124 | -static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) | ||
125 | +static RISCVException write_fcsr(CPURISCVState *env, int csrno, | ||
126 | + target_ulong val) | ||
127 | { | ||
128 | #if !defined(CONFIG_USER_ONLY) | ||
129 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
130 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
131 | + return RISCV_EXCP_ILLEGAL_INST; | ||
132 | } | ||
133 | env->mstatus |= MSTATUS_FS; | ||
134 | #endif | ||
135 | @@ -XXX,XX +XXX,XX @@ static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) | ||
136 | env->vxsat = (val & FSR_VXSAT) >> FSR_VXSAT_SHIFT; | ||
137 | } | ||
138 | riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT); | ||
139 | - return 0; | ||
140 | + return RISCV_EXCP_NONE; | ||
141 | } | ||
142 | |||
143 | -static int read_vtype(CPURISCVState *env, int csrno, target_ulong *val) | ||
144 | +static RISCVException read_vtype(CPURISCVState *env, int csrno, | ||
145 | + target_ulong *val) | ||
146 | { | ||
147 | *val = env->vtype; | ||
148 | - return 0; | ||
149 | + return RISCV_EXCP_NONE; | ||
150 | } | ||
151 | |||
152 | -static int read_vl(CPURISCVState *env, int csrno, target_ulong *val) | ||
153 | +static RISCVException read_vl(CPURISCVState *env, int csrno, | ||
154 | + target_ulong *val) | ||
155 | { | ||
156 | *val = env->vl; | ||
157 | - return 0; | ||
158 | + return RISCV_EXCP_NONE; | ||
159 | } | ||
160 | |||
161 | -static int read_vxrm(CPURISCVState *env, int csrno, target_ulong *val) | ||
162 | +static RISCVException read_vxrm(CPURISCVState *env, int csrno, | ||
163 | + target_ulong *val) | ||
164 | { | ||
165 | *val = env->vxrm; | ||
166 | - return 0; | ||
167 | + return RISCV_EXCP_NONE; | ||
168 | } | ||
169 | |||
170 | -static int write_vxrm(CPURISCVState *env, int csrno, target_ulong val) | ||
171 | +static RISCVException write_vxrm(CPURISCVState *env, int csrno, | ||
172 | + target_ulong val) | ||
173 | { | ||
174 | env->vxrm = val; | ||
175 | - return 0; | ||
176 | + return RISCV_EXCP_NONE; | ||
177 | } | ||
178 | |||
179 | -static int read_vxsat(CPURISCVState *env, int csrno, target_ulong *val) | ||
180 | +static RISCVException read_vxsat(CPURISCVState *env, int csrno, | ||
181 | + target_ulong *val) | ||
182 | { | ||
183 | *val = env->vxsat; | ||
184 | - return 0; | ||
185 | + return RISCV_EXCP_NONE; | ||
186 | } | ||
187 | |||
188 | -static int write_vxsat(CPURISCVState *env, int csrno, target_ulong val) | ||
189 | +static RISCVException write_vxsat(CPURISCVState *env, int csrno, | ||
190 | + target_ulong val) | ||
191 | { | ||
192 | env->vxsat = val; | ||
193 | - return 0; | ||
194 | + return RISCV_EXCP_NONE; | ||
195 | } | ||
196 | |||
197 | -static int read_vstart(CPURISCVState *env, int csrno, target_ulong *val) | ||
198 | +static RISCVException read_vstart(CPURISCVState *env, int csrno, | ||
199 | + target_ulong *val) | ||
200 | { | ||
201 | *val = env->vstart; | ||
202 | - return 0; | ||
203 | + return RISCV_EXCP_NONE; | ||
204 | } | ||
205 | |||
206 | -static int write_vstart(CPURISCVState *env, int csrno, target_ulong val) | ||
207 | +static RISCVException write_vstart(CPURISCVState *env, int csrno, | ||
208 | + target_ulong val) | ||
209 | { | ||
210 | env->vstart = val; | ||
211 | - return 0; | ||
212 | + return RISCV_EXCP_NONE; | ||
213 | } | ||
214 | |||
215 | /* User Timers and Counters */ | ||
216 | -static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) | ||
217 | +static RISCVException read_instret(CPURISCVState *env, int csrno, | ||
218 | + target_ulong *val) | ||
219 | { | ||
220 | #if !defined(CONFIG_USER_ONLY) | ||
221 | if (icount_enabled()) { | ||
222 | @@ -XXX,XX +XXX,XX @@ static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) | ||
223 | #else | ||
224 | *val = cpu_get_host_ticks(); | ||
225 | #endif | ||
226 | - return 0; | ||
227 | + return RISCV_EXCP_NONE; | ||
228 | } | ||
229 | |||
230 | -static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) | ||
231 | +static RISCVException read_instreth(CPURISCVState *env, int csrno, | ||
232 | + target_ulong *val) | ||
233 | { | ||
234 | #if !defined(CONFIG_USER_ONLY) | ||
235 | if (icount_enabled()) { | ||
236 | @@ -XXX,XX +XXX,XX @@ static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) | ||
237 | #else | ||
238 | *val = cpu_get_host_ticks() >> 32; | ||
239 | #endif | ||
240 | - return 0; | ||
241 | + return RISCV_EXCP_NONE; | ||
242 | } | ||
243 | |||
244 | #if defined(CONFIG_USER_ONLY) | ||
245 | -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) | ||
246 | +static RISCVException read_time(CPURISCVState *env, int csrno, | ||
247 | + target_ulong *val) | ||
248 | { | ||
249 | *val = cpu_get_host_ticks(); | ||
250 | - return 0; | ||
251 | + return RISCV_EXCP_NONE; | ||
252 | } | ||
253 | |||
254 | -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) | ||
255 | +static RISCVException read_timeh(CPURISCVState *env, int csrno, | ||
256 | + target_ulong *val) | ||
257 | { | ||
258 | *val = cpu_get_host_ticks() >> 32; | ||
259 | - return 0; | ||
260 | + return RISCV_EXCP_NONE; | ||
261 | } | ||
262 | |||
263 | #else /* CONFIG_USER_ONLY */ | ||
264 | |||
265 | -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) | ||
266 | +static RISCVException read_time(CPURISCVState *env, int csrno, | ||
267 | + target_ulong *val) | ||
268 | { | ||
269 | uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; | ||
270 | |||
271 | if (!env->rdtime_fn) { | ||
272 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
273 | + return RISCV_EXCP_ILLEGAL_INST; | ||
274 | } | ||
275 | |||
276 | *val = env->rdtime_fn(env->rdtime_fn_arg) + delta; | ||
277 | - return 0; | ||
278 | + return RISCV_EXCP_NONE; | ||
279 | } | ||
280 | |||
281 | -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) | ||
282 | +static RISCVException read_timeh(CPURISCVState *env, int csrno, | ||
283 | + target_ulong *val) | ||
284 | { | ||
285 | uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; | ||
286 | |||
287 | if (!env->rdtime_fn) { | ||
288 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
289 | + return RISCV_EXCP_ILLEGAL_INST; | ||
290 | } | ||
291 | |||
292 | *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32; | ||
293 | - return 0; | ||
294 | + return RISCV_EXCP_NONE; | ||
295 | } | ||
296 | |||
297 | /* Machine constants */ | ||
298 | @@ -XXX,XX +XXX,XX @@ static const char valid_vm_1_10_64[16] = { | ||
299 | }; | ||
300 | |||
301 | /* Machine Information Registers */ | ||
302 | -static int read_zero(CPURISCVState *env, int csrno, target_ulong *val) | ||
303 | +static RISCVException read_zero(CPURISCVState *env, int csrno, | ||
304 | + target_ulong *val) | ||
305 | { | ||
306 | - return *val = 0; | ||
307 | + *val = 0; | ||
308 | + return RISCV_EXCP_NONE; | ||
309 | } | ||
310 | |||
311 | -static int read_mhartid(CPURISCVState *env, int csrno, target_ulong *val) | ||
312 | +static RISCVException read_mhartid(CPURISCVState *env, int csrno, | ||
313 | + target_ulong *val) | ||
314 | { | ||
315 | *val = env->mhartid; | ||
316 | - return 0; | ||
317 | + return RISCV_EXCP_NONE; | ||
318 | } | ||
319 | |||
320 | /* Machine Trap Setup */ | ||
321 | -static int read_mstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
322 | +static RISCVException read_mstatus(CPURISCVState *env, int csrno, | ||
323 | + target_ulong *val) | ||
324 | { | ||
325 | *val = env->mstatus; | ||
326 | - return 0; | ||
327 | + return RISCV_EXCP_NONE; | ||
328 | } | ||
329 | |||
330 | static int validate_vm(CPURISCVState *env, target_ulong vm) | ||
331 | @@ -XXX,XX +XXX,XX @@ static int validate_vm(CPURISCVState *env, target_ulong vm) | ||
332 | } | ||
333 | } | ||
334 | |||
335 | -static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
336 | +static RISCVException write_mstatus(CPURISCVState *env, int csrno, | ||
337 | + target_ulong val) | ||
338 | { | ||
339 | uint64_t mstatus = env->mstatus; | ||
340 | uint64_t mask = 0; | ||
341 | @@ -XXX,XX +XXX,XX @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
342 | mstatus = set_field(mstatus, MSTATUS_SD, dirty); | ||
343 | env->mstatus = mstatus; | ||
344 | |||
345 | - return 0; | ||
346 | + return RISCV_EXCP_NONE; | ||
347 | } | ||
348 | |||
349 | -static int read_mstatush(CPURISCVState *env, int csrno, target_ulong *val) | ||
350 | +static RISCVException read_mstatush(CPURISCVState *env, int csrno, | ||
351 | + target_ulong *val) | ||
352 | { | ||
353 | *val = env->mstatus >> 32; | ||
354 | - return 0; | ||
355 | + return RISCV_EXCP_NONE; | ||
356 | } | ||
357 | |||
358 | -static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val) | ||
359 | +static RISCVException write_mstatush(CPURISCVState *env, int csrno, | ||
360 | + target_ulong val) | ||
361 | { | ||
362 | uint64_t valh = (uint64_t)val << 32; | ||
363 | uint64_t mask = MSTATUS_MPV | MSTATUS_GVA; | ||
364 | @@ -XXX,XX +XXX,XX @@ static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val) | ||
365 | |||
366 | env->mstatus = (env->mstatus & ~mask) | (valh & mask); | ||
367 | |||
368 | - return 0; | ||
369 | + return RISCV_EXCP_NONE; | ||
370 | } | ||
371 | |||
372 | -static int read_misa(CPURISCVState *env, int csrno, target_ulong *val) | ||
373 | +static RISCVException read_misa(CPURISCVState *env, int csrno, | ||
374 | + target_ulong *val) | ||
375 | { | ||
376 | *val = env->misa; | ||
377 | - return 0; | ||
378 | + return RISCV_EXCP_NONE; | ||
379 | } | ||
380 | |||
381 | -static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
382 | +static RISCVException write_misa(CPURISCVState *env, int csrno, | ||
383 | + target_ulong val) | ||
384 | { | ||
385 | if (!riscv_feature(env, RISCV_FEATURE_MISA)) { | ||
386 | /* drop write to misa */ | ||
387 | - return 0; | ||
388 | + return RISCV_EXCP_NONE; | ||
389 | } | ||
390 | |||
391 | /* 'I' or 'E' must be present */ | ||
392 | if (!(val & (RVI | RVE))) { | ||
393 | /* It is not, drop write to misa */ | ||
394 | - return 0; | ||
395 | + return RISCV_EXCP_NONE; | ||
396 | } | ||
397 | |||
398 | /* 'E' excludes all other extensions */ | ||
399 | @@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
400 | /* when we support 'E' we can do "val = RVE;" however | ||
401 | * for now we just drop writes if 'E' is present. | ||
402 | */ | ||
403 | - return 0; | ||
404 | + return RISCV_EXCP_NONE; | ||
405 | } | ||
406 | |||
407 | /* Mask extensions that are not supported by this hart */ | ||
408 | @@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
409 | |||
410 | env->misa = val; | ||
411 | |||
412 | - return 0; | ||
413 | + return RISCV_EXCP_NONE; | ||
414 | } | ||
415 | |||
416 | -static int read_medeleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
417 | +static RISCVException read_medeleg(CPURISCVState *env, int csrno, | ||
418 | + target_ulong *val) | ||
419 | { | ||
420 | *val = env->medeleg; | ||
421 | - return 0; | ||
422 | + return RISCV_EXCP_NONE; | ||
423 | } | ||
424 | |||
425 | -static int write_medeleg(CPURISCVState *env, int csrno, target_ulong val) | ||
426 | +static RISCVException write_medeleg(CPURISCVState *env, int csrno, | ||
427 | + target_ulong val) | ||
428 | { | ||
429 | env->medeleg = (env->medeleg & ~delegable_excps) | (val & delegable_excps); | ||
430 | - return 0; | ||
431 | + return RISCV_EXCP_NONE; | ||
432 | } | ||
433 | |||
434 | -static int read_mideleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
435 | +static RISCVException read_mideleg(CPURISCVState *env, int csrno, | ||
436 | + target_ulong *val) | ||
437 | { | ||
438 | *val = env->mideleg; | ||
439 | - return 0; | ||
440 | + return RISCV_EXCP_NONE; | ||
441 | } | ||
442 | |||
443 | -static int write_mideleg(CPURISCVState *env, int csrno, target_ulong val) | ||
444 | +static RISCVException write_mideleg(CPURISCVState *env, int csrno, | ||
445 | + target_ulong val) | ||
446 | { | ||
447 | env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints); | ||
448 | if (riscv_has_ext(env, RVH)) { | ||
449 | env->mideleg |= VS_MODE_INTERRUPTS; | ||
450 | } | ||
451 | - return 0; | ||
452 | + return RISCV_EXCP_NONE; | ||
453 | } | ||
454 | |||
455 | -static int read_mie(CPURISCVState *env, int csrno, target_ulong *val) | ||
456 | +static RISCVException read_mie(CPURISCVState *env, int csrno, | ||
457 | + target_ulong *val) | ||
458 | { | ||
459 | *val = env->mie; | ||
460 | - return 0; | ||
461 | + return RISCV_EXCP_NONE; | ||
462 | } | ||
463 | |||
464 | -static int write_mie(CPURISCVState *env, int csrno, target_ulong val) | ||
465 | +static RISCVException write_mie(CPURISCVState *env, int csrno, | ||
466 | + target_ulong val) | ||
467 | { | ||
468 | env->mie = (env->mie & ~all_ints) | (val & all_ints); | ||
469 | - return 0; | ||
470 | + return RISCV_EXCP_NONE; | ||
471 | } | ||
472 | |||
473 | -static int read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
474 | +static RISCVException read_mtvec(CPURISCVState *env, int csrno, | ||
475 | + target_ulong *val) | ||
476 | { | ||
477 | *val = env->mtvec; | ||
478 | - return 0; | ||
479 | + return RISCV_EXCP_NONE; | ||
480 | } | ||
481 | |||
482 | -static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val) | ||
483 | +static RISCVException write_mtvec(CPURISCVState *env, int csrno, | ||
484 | + target_ulong val) | ||
485 | { | ||
486 | /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ | ||
487 | if ((val & 3) < 2) { | ||
488 | @@ -XXX,XX +XXX,XX @@ static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val) | ||
489 | } else { | ||
490 | qemu_log_mask(LOG_UNIMP, "CSR_MTVEC: reserved mode not supported\n"); | ||
491 | } | ||
492 | - return 0; | ||
493 | + return RISCV_EXCP_NONE; | ||
494 | } | ||
495 | |||
496 | -static int read_mcounteren(CPURISCVState *env, int csrno, target_ulong *val) | ||
497 | +static RISCVException read_mcounteren(CPURISCVState *env, int csrno, | ||
498 | + target_ulong *val) | ||
499 | { | ||
500 | *val = env->mcounteren; | ||
501 | - return 0; | ||
502 | + return RISCV_EXCP_NONE; | ||
503 | } | ||
504 | |||
505 | -static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
506 | +static RISCVException write_mcounteren(CPURISCVState *env, int csrno, | ||
507 | + target_ulong val) | ||
508 | { | ||
509 | env->mcounteren = val; | ||
510 | - return 0; | ||
511 | + return RISCV_EXCP_NONE; | ||
512 | } | ||
513 | |||
514 | /* Machine Trap Handling */ | ||
515 | -static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
516 | +static RISCVException read_mscratch(CPURISCVState *env, int csrno, | ||
517 | + target_ulong *val) | ||
518 | { | ||
519 | *val = env->mscratch; | ||
520 | - return 0; | ||
521 | + return RISCV_EXCP_NONE; | ||
522 | } | ||
523 | |||
524 | -static int write_mscratch(CPURISCVState *env, int csrno, target_ulong val) | ||
525 | +static RISCVException write_mscratch(CPURISCVState *env, int csrno, | ||
526 | + target_ulong val) | ||
527 | { | ||
528 | env->mscratch = val; | ||
529 | - return 0; | ||
530 | + return RISCV_EXCP_NONE; | ||
531 | } | ||
532 | |||
533 | -static int read_mepc(CPURISCVState *env, int csrno, target_ulong *val) | ||
534 | +static RISCVException read_mepc(CPURISCVState *env, int csrno, | ||
535 | + target_ulong *val) | ||
536 | { | ||
537 | *val = env->mepc; | ||
538 | - return 0; | ||
539 | + return RISCV_EXCP_NONE; | ||
540 | } | ||
541 | |||
542 | -static int write_mepc(CPURISCVState *env, int csrno, target_ulong val) | ||
543 | +static RISCVException write_mepc(CPURISCVState *env, int csrno, | ||
544 | + target_ulong val) | ||
545 | { | ||
546 | env->mepc = val; | ||
547 | - return 0; | ||
548 | + return RISCV_EXCP_NONE; | ||
549 | } | ||
550 | |||
551 | -static int read_mcause(CPURISCVState *env, int csrno, target_ulong *val) | ||
552 | +static RISCVException read_mcause(CPURISCVState *env, int csrno, | ||
553 | + target_ulong *val) | ||
554 | { | ||
555 | *val = env->mcause; | ||
556 | - return 0; | ||
557 | + return RISCV_EXCP_NONE; | ||
558 | } | ||
559 | |||
560 | -static int write_mcause(CPURISCVState *env, int csrno, target_ulong val) | ||
561 | +static RISCVException write_mcause(CPURISCVState *env, int csrno, | ||
562 | + target_ulong val) | ||
563 | { | ||
564 | env->mcause = val; | ||
565 | - return 0; | ||
566 | + return RISCV_EXCP_NONE; | ||
567 | } | ||
568 | |||
569 | -static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val) | ||
570 | +static RISCVException read_mtval(CPURISCVState *env, int csrno, | ||
571 | + target_ulong *val) | ||
572 | { | ||
573 | *val = env->mtval; | ||
574 | - return 0; | ||
575 | + return RISCV_EXCP_NONE; | ||
576 | } | ||
577 | |||
578 | -static int write_mtval(CPURISCVState *env, int csrno, target_ulong val) | ||
579 | +static RISCVException write_mtval(CPURISCVState *env, int csrno, | ||
580 | + target_ulong val) | ||
581 | { | ||
582 | env->mtval = val; | ||
583 | - return 0; | ||
584 | + return RISCV_EXCP_NONE; | ||
585 | } | ||
586 | |||
587 | -static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
588 | - target_ulong new_value, target_ulong write_mask) | ||
589 | +static RISCVException rmw_mip(CPURISCVState *env, int csrno, | ||
590 | + target_ulong *ret_value, | ||
591 | + target_ulong new_value, target_ulong write_mask) | ||
592 | { | ||
593 | RISCVCPU *cpu = env_archcpu(env); | ||
594 | /* Allow software control of delegable interrupts not claimed by hardware */ | ||
595 | @@ -XXX,XX +XXX,XX @@ static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
596 | *ret_value = old_mip; | ||
597 | } | ||
598 | |||
599 | - return 0; | ||
600 | + return RISCV_EXCP_NONE; | ||
601 | } | ||
602 | |||
603 | /* Supervisor Trap Setup */ | ||
604 | -static int read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
605 | +static RISCVException read_sstatus(CPURISCVState *env, int csrno, | ||
606 | + target_ulong *val) | ||
607 | { | ||
608 | target_ulong mask = (sstatus_v1_10_mask); | ||
609 | *val = env->mstatus & mask; | ||
610 | - return 0; | ||
611 | + return RISCV_EXCP_NONE; | ||
612 | } | ||
613 | |||
614 | -static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
615 | +static RISCVException write_sstatus(CPURISCVState *env, int csrno, | ||
616 | + target_ulong val) | ||
617 | { | ||
618 | target_ulong mask = (sstatus_v1_10_mask); | ||
619 | target_ulong newval = (env->mstatus & ~mask) | (val & mask); | ||
21 | return write_mstatus(env, CSR_MSTATUS, newval); | 620 | return write_mstatus(env, CSR_MSTATUS, newval); |
22 | } | 621 | } |
23 | 622 | ||
24 | +static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) | 623 | -static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) |
25 | +{ | 624 | +static RISCVException read_vsie(CPURISCVState *env, int csrno, |
26 | + /* Shift the VS bits to their S bit location in vsie */ | 625 | + target_ulong *val) |
27 | + *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; | 626 | { |
28 | + return 0; | 627 | /* Shift the VS bits to their S bit location in vsie */ |
29 | +} | 628 | *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; |
30 | + | 629 | - return 0; |
31 | static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) | 630 | + return RISCV_EXCP_NONE; |
631 | } | ||
632 | |||
633 | -static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) | ||
634 | +static RISCVException read_sie(CPURISCVState *env, int csrno, | ||
635 | + target_ulong *val) | ||
32 | { | 636 | { |
33 | if (riscv_cpu_virt_enabled(env)) { | 637 | if (riscv_cpu_virt_enabled(env)) { |
34 | - /* Tell the guest the VS bits, shifted to the S bit locations */ | 638 | read_vsie(env, CSR_VSIE, val); |
35 | - *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1; | ||
36 | + read_vsie(env, CSR_VSIE, val); | ||
37 | } else { | 639 | } else { |
38 | *val = env->mie & env->mideleg; | 640 | *val = env->mie & env->mideleg; |
39 | } | 641 | } |
40 | return 0; | 642 | - return 0; |
41 | } | 643 | + return RISCV_EXCP_NONE; |
42 | 644 | } | |
43 | -static int write_sie(CPURISCVState *env, int csrno, target_ulong val) | 645 | |
44 | +static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) | 646 | -static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) |
45 | { | 647 | +static RISCVException write_vsie(CPURISCVState *env, int csrno, |
46 | - target_ulong newval; | 648 | + target_ulong val) |
47 | + /* Shift the S bits to their VS bit location in mie */ | 649 | { |
48 | + target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | | 650 | /* Shift the S bits to their VS bit location in mie */ |
49 | + ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS); | 651 | target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | |
50 | + return write_mie(env, CSR_MIE, newval); | 652 | @@ -XXX,XX +XXX,XX @@ static int write_sie(CPURISCVState *env, int csrno, target_ulong val) |
51 | +} | 653 | write_mie(env, CSR_MIE, newval); |
52 | 654 | } | |
53 | +static int write_sie(CPURISCVState *env, int csrno, target_ulong val) | 655 | |
54 | +{ | 656 | - return 0; |
55 | if (riscv_cpu_virt_enabled(env)) { | 657 | + return RISCV_EXCP_NONE; |
56 | - /* Shift the guests S bits to VS */ | 658 | } |
57 | - newval = (env->mie & ~VS_MODE_INTERRUPTS) | | 659 | |
58 | - ((val << 1) & VS_MODE_INTERRUPTS); | 660 | -static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val) |
59 | + write_vsie(env, CSR_VSIE, val); | 661 | +static RISCVException read_stvec(CPURISCVState *env, int csrno, |
662 | + target_ulong *val) | ||
663 | { | ||
664 | *val = env->stvec; | ||
665 | - return 0; | ||
666 | + return RISCV_EXCP_NONE; | ||
667 | } | ||
668 | |||
669 | -static int write_stvec(CPURISCVState *env, int csrno, target_ulong val) | ||
670 | +static RISCVException write_stvec(CPURISCVState *env, int csrno, | ||
671 | + target_ulong val) | ||
672 | { | ||
673 | /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ | ||
674 | if ((val & 3) < 2) { | ||
675 | @@ -XXX,XX +XXX,XX @@ static int write_stvec(CPURISCVState *env, int csrno, target_ulong val) | ||
60 | } else { | 676 | } else { |
61 | - newval = (env->mie & ~S_MODE_INTERRUPTS) | (val & S_MODE_INTERRUPTS); | 677 | qemu_log_mask(LOG_UNIMP, "CSR_STVEC: reserved mode not supported\n"); |
62 | + target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) | | 678 | } |
63 | + (val & S_MODE_INTERRUPTS); | 679 | - return 0; |
64 | + write_mie(env, CSR_MIE, newval); | 680 | + return RISCV_EXCP_NONE; |
65 | } | 681 | } |
66 | 682 | ||
67 | - return write_mie(env, CSR_MIE, newval); | 683 | -static int read_scounteren(CPURISCVState *env, int csrno, target_ulong *val) |
68 | + return 0; | 684 | +static RISCVException read_scounteren(CPURISCVState *env, int csrno, |
69 | } | 685 | + target_ulong *val) |
70 | 686 | { | |
71 | static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val) | 687 | *val = env->scounteren; |
72 | @@ -XXX,XX +XXX,XX @@ static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) | 688 | - return 0; |
73 | return 0; | 689 | + return RISCV_EXCP_NONE; |
74 | } | 690 | } |
75 | 691 | ||
76 | +static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 692 | -static int write_scounteren(CPURISCVState *env, int csrno, target_ulong val) |
77 | + target_ulong new_value, target_ulong write_mask) | 693 | +static RISCVException write_scounteren(CPURISCVState *env, int csrno, |
78 | +{ | 694 | + target_ulong val) |
79 | + /* Shift the S bits to their VS bit location in mip */ | 695 | { |
80 | + int ret = rmw_mip(env, 0, ret_value, new_value << 1, | 696 | env->scounteren = val; |
81 | + (write_mask << 1) & vsip_writable_mask & env->hideleg); | 697 | - return 0; |
82 | + *ret_value &= VS_MODE_INTERRUPTS; | 698 | + return RISCV_EXCP_NONE; |
83 | + /* Shift the VS bits to their S bit location in vsip */ | 699 | } |
84 | + *ret_value >>= 1; | 700 | |
85 | + return ret; | 701 | /* Supervisor Trap Handling */ |
86 | +} | 702 | -static int read_sscratch(CPURISCVState *env, int csrno, target_ulong *val) |
87 | + | 703 | +static RISCVException read_sscratch(CPURISCVState *env, int csrno, |
88 | static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 704 | + target_ulong *val) |
89 | target_ulong new_value, target_ulong write_mask) | 705 | { |
90 | { | 706 | *val = env->sscratch; |
91 | int ret; | 707 | - return 0; |
92 | 708 | + return RISCV_EXCP_NONE; | |
93 | if (riscv_cpu_virt_enabled(env)) { | 709 | } |
94 | - /* Shift the new values to line up with the VS bits */ | 710 | |
95 | - ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value << 1, | 711 | -static int write_sscratch(CPURISCVState *env, int csrno, target_ulong val) |
96 | - (write_mask & sip_writable_mask) << 1 & env->mideleg); | 712 | +static RISCVException write_sscratch(CPURISCVState *env, int csrno, |
97 | - ret &= vsip_writable_mask; | 713 | + target_ulong val) |
98 | - ret >>= 1; | 714 | { |
99 | + ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); | 715 | env->sscratch = val; |
100 | } else { | 716 | - return 0; |
101 | ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value, | 717 | + return RISCV_EXCP_NONE; |
102 | write_mask & env->mideleg & sip_writable_mask); | 718 | } |
103 | @@ -XXX,XX +XXX,XX @@ static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val) | 719 | |
104 | return 0; | 720 | -static int read_sepc(CPURISCVState *env, int csrno, target_ulong *val) |
105 | } | 721 | +static RISCVException read_sepc(CPURISCVState *env, int csrno, |
722 | + target_ulong *val) | ||
723 | { | ||
724 | *val = env->sepc; | ||
725 | - return 0; | ||
726 | + return RISCV_EXCP_NONE; | ||
727 | } | ||
728 | |||
729 | -static int write_sepc(CPURISCVState *env, int csrno, target_ulong val) | ||
730 | +static RISCVException write_sepc(CPURISCVState *env, int csrno, | ||
731 | + target_ulong val) | ||
732 | { | ||
733 | env->sepc = val; | ||
734 | - return 0; | ||
735 | + return RISCV_EXCP_NONE; | ||
736 | } | ||
737 | |||
738 | -static int read_scause(CPURISCVState *env, int csrno, target_ulong *val) | ||
739 | +static RISCVException read_scause(CPURISCVState *env, int csrno, | ||
740 | + target_ulong *val) | ||
741 | { | ||
742 | *val = env->scause; | ||
743 | - return 0; | ||
744 | + return RISCV_EXCP_NONE; | ||
745 | } | ||
746 | |||
747 | -static int write_scause(CPURISCVState *env, int csrno, target_ulong val) | ||
748 | +static RISCVException write_scause(CPURISCVState *env, int csrno, | ||
749 | + target_ulong val) | ||
750 | { | ||
751 | env->scause = val; | ||
752 | - return 0; | ||
753 | + return RISCV_EXCP_NONE; | ||
754 | } | ||
755 | |||
756 | -static int read_stval(CPURISCVState *env, int csrno, target_ulong *val) | ||
757 | +static RISCVException read_stval(CPURISCVState *env, int csrno, | ||
758 | + target_ulong *val) | ||
759 | { | ||
760 | *val = env->stval; | ||
761 | - return 0; | ||
762 | + return RISCV_EXCP_NONE; | ||
763 | } | ||
764 | |||
765 | -static int write_stval(CPURISCVState *env, int csrno, target_ulong val) | ||
766 | +static RISCVException write_stval(CPURISCVState *env, int csrno, | ||
767 | + target_ulong val) | ||
768 | { | ||
769 | env->stval = val; | ||
770 | - return 0; | ||
771 | + return RISCV_EXCP_NONE; | ||
772 | } | ||
106 | 773 | ||
107 | -static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 774 | -static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, |
108 | - target_ulong new_value, target_ulong write_mask) | 775 | - target_ulong new_value, target_ulong write_mask) |
109 | -{ | 776 | +static RISCVException rmw_vsip(CPURISCVState *env, int csrno, |
110 | - int ret = rmw_mip(env, 0, ret_value, new_value, | 777 | + target_ulong *ret_value, |
111 | - write_mask & env->mideleg & vsip_writable_mask); | 778 | + target_ulong new_value, target_ulong write_mask) |
112 | - return ret; | 779 | { |
113 | -} | 780 | /* Shift the S bits to their VS bit location in mip */ |
781 | int ret = rmw_mip(env, 0, ret_value, new_value << 1, | ||
782 | @@ -XXX,XX +XXX,XX @@ static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
783 | return ret; | ||
784 | } | ||
785 | |||
786 | -static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
787 | - target_ulong new_value, target_ulong write_mask) | ||
788 | +static RISCVException rmw_sip(CPURISCVState *env, int csrno, | ||
789 | + target_ulong *ret_value, | ||
790 | + target_ulong new_value, target_ulong write_mask) | ||
791 | { | ||
792 | int ret; | ||
793 | |||
794 | @@ -XXX,XX +XXX,XX @@ static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
795 | } | ||
796 | |||
797 | /* Supervisor Protection and Translation */ | ||
798 | -static int read_satp(CPURISCVState *env, int csrno, target_ulong *val) | ||
799 | +static RISCVException read_satp(CPURISCVState *env, int csrno, | ||
800 | + target_ulong *val) | ||
801 | { | ||
802 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { | ||
803 | *val = 0; | ||
804 | - return 0; | ||
805 | + return RISCV_EXCP_NONE; | ||
806 | } | ||
807 | |||
808 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { | ||
809 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
810 | + return RISCV_EXCP_ILLEGAL_INST; | ||
811 | } else { | ||
812 | *val = env->satp; | ||
813 | } | ||
814 | |||
815 | - return 0; | ||
816 | + return RISCV_EXCP_NONE; | ||
817 | } | ||
818 | |||
819 | -static int write_satp(CPURISCVState *env, int csrno, target_ulong val) | ||
820 | +static RISCVException write_satp(CPURISCVState *env, int csrno, | ||
821 | + target_ulong val) | ||
822 | { | ||
823 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { | ||
824 | - return 0; | ||
825 | + return RISCV_EXCP_NONE; | ||
826 | } | ||
827 | if (validate_vm(env, get_field(val, SATP_MODE)) && | ||
828 | ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) | ||
829 | { | ||
830 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { | ||
831 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
832 | + return RISCV_EXCP_ILLEGAL_INST; | ||
833 | } else { | ||
834 | if ((val ^ env->satp) & SATP_ASID) { | ||
835 | tlb_flush(env_cpu(env)); | ||
836 | @@ -XXX,XX +XXX,XX @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) | ||
837 | env->satp = val; | ||
838 | } | ||
839 | } | ||
840 | - return 0; | ||
841 | + return RISCV_EXCP_NONE; | ||
842 | } | ||
843 | |||
844 | /* Hypervisor Extensions */ | ||
845 | -static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
846 | +static RISCVException read_hstatus(CPURISCVState *env, int csrno, | ||
847 | + target_ulong *val) | ||
848 | { | ||
849 | *val = env->hstatus; | ||
850 | if (!riscv_cpu_is_32bit(env)) { | ||
851 | @@ -XXX,XX +XXX,XX @@ static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
852 | } | ||
853 | /* We only support little endian */ | ||
854 | *val = set_field(*val, HSTATUS_VSBE, 0); | ||
855 | - return 0; | ||
856 | + return RISCV_EXCP_NONE; | ||
857 | } | ||
858 | |||
859 | -static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
860 | +static RISCVException write_hstatus(CPURISCVState *env, int csrno, | ||
861 | + target_ulong val) | ||
862 | { | ||
863 | env->hstatus = val; | ||
864 | if (!riscv_cpu_is_32bit(env) && get_field(val, HSTATUS_VSXL) != 2) { | ||
865 | @@ -XXX,XX +XXX,XX @@ static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
866 | if (get_field(val, HSTATUS_VSBE) != 0) { | ||
867 | qemu_log_mask(LOG_UNIMP, "QEMU does not support big endian guests."); | ||
868 | } | ||
869 | - return 0; | ||
870 | + return RISCV_EXCP_NONE; | ||
871 | } | ||
872 | |||
873 | -static int read_hedeleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
874 | +static RISCVException read_hedeleg(CPURISCVState *env, int csrno, | ||
875 | + target_ulong *val) | ||
876 | { | ||
877 | *val = env->hedeleg; | ||
878 | - return 0; | ||
879 | + return RISCV_EXCP_NONE; | ||
880 | } | ||
881 | |||
882 | -static int write_hedeleg(CPURISCVState *env, int csrno, target_ulong val) | ||
883 | +static RISCVException write_hedeleg(CPURISCVState *env, int csrno, | ||
884 | + target_ulong val) | ||
885 | { | ||
886 | env->hedeleg = val; | ||
887 | - return 0; | ||
888 | + return RISCV_EXCP_NONE; | ||
889 | } | ||
890 | |||
891 | -static int read_hideleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
892 | +static RISCVException read_hideleg(CPURISCVState *env, int csrno, | ||
893 | + target_ulong *val) | ||
894 | { | ||
895 | *val = env->hideleg; | ||
896 | - return 0; | ||
897 | + return RISCV_EXCP_NONE; | ||
898 | } | ||
899 | |||
900 | -static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val) | ||
901 | +static RISCVException write_hideleg(CPURISCVState *env, int csrno, | ||
902 | + target_ulong val) | ||
903 | { | ||
904 | env->hideleg = val; | ||
905 | - return 0; | ||
906 | + return RISCV_EXCP_NONE; | ||
907 | } | ||
908 | |||
909 | -static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
910 | - target_ulong new_value, target_ulong write_mask) | ||
911 | +static RISCVException rmw_hvip(CPURISCVState *env, int csrno, | ||
912 | + target_ulong *ret_value, | ||
913 | + target_ulong new_value, target_ulong write_mask) | ||
914 | { | ||
915 | int ret = rmw_mip(env, 0, ret_value, new_value, | ||
916 | write_mask & hvip_writable_mask); | ||
917 | @@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
918 | return ret; | ||
919 | } | ||
920 | |||
921 | -static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
922 | - target_ulong new_value, target_ulong write_mask) | ||
923 | +static RISCVException rmw_hip(CPURISCVState *env, int csrno, | ||
924 | + target_ulong *ret_value, | ||
925 | + target_ulong new_value, target_ulong write_mask) | ||
926 | { | ||
927 | int ret = rmw_mip(env, 0, ret_value, new_value, | ||
928 | write_mask & hip_writable_mask); | ||
929 | @@ -XXX,XX +XXX,XX @@ static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
930 | return ret; | ||
931 | } | ||
932 | |||
933 | -static int read_hie(CPURISCVState *env, int csrno, target_ulong *val) | ||
934 | +static RISCVException read_hie(CPURISCVState *env, int csrno, | ||
935 | + target_ulong *val) | ||
936 | { | ||
937 | *val = env->mie & VS_MODE_INTERRUPTS; | ||
938 | - return 0; | ||
939 | + return RISCV_EXCP_NONE; | ||
940 | } | ||
941 | |||
942 | -static int write_hie(CPURISCVState *env, int csrno, target_ulong val) | ||
943 | +static RISCVException write_hie(CPURISCVState *env, int csrno, | ||
944 | + target_ulong val) | ||
945 | { | ||
946 | target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS); | ||
947 | return write_mie(env, CSR_MIE, newval); | ||
948 | } | ||
949 | |||
950 | -static int read_hcounteren(CPURISCVState *env, int csrno, target_ulong *val) | ||
951 | +static RISCVException read_hcounteren(CPURISCVState *env, int csrno, | ||
952 | + target_ulong *val) | ||
953 | { | ||
954 | *val = env->hcounteren; | ||
955 | - return 0; | ||
956 | + return RISCV_EXCP_NONE; | ||
957 | } | ||
958 | |||
959 | -static int write_hcounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
960 | +static RISCVException write_hcounteren(CPURISCVState *env, int csrno, | ||
961 | + target_ulong val) | ||
962 | { | ||
963 | env->hcounteren = val; | ||
964 | - return 0; | ||
965 | + return RISCV_EXCP_NONE; | ||
966 | } | ||
967 | |||
968 | -static int read_hgeie(CPURISCVState *env, int csrno, target_ulong *val) | ||
969 | +static RISCVException read_hgeie(CPURISCVState *env, int csrno, | ||
970 | + target_ulong *val) | ||
971 | { | ||
972 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
973 | - return 0; | ||
974 | + return RISCV_EXCP_NONE; | ||
975 | } | ||
976 | |||
977 | -static int write_hgeie(CPURISCVState *env, int csrno, target_ulong val) | ||
978 | +static RISCVException write_hgeie(CPURISCVState *env, int csrno, | ||
979 | + target_ulong val) | ||
980 | { | ||
981 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
982 | - return 0; | ||
983 | + return RISCV_EXCP_NONE; | ||
984 | } | ||
985 | |||
986 | -static int read_htval(CPURISCVState *env, int csrno, target_ulong *val) | ||
987 | +static RISCVException read_htval(CPURISCVState *env, int csrno, | ||
988 | + target_ulong *val) | ||
989 | { | ||
990 | *val = env->htval; | ||
991 | - return 0; | ||
992 | + return RISCV_EXCP_NONE; | ||
993 | } | ||
994 | |||
995 | -static int write_htval(CPURISCVState *env, int csrno, target_ulong val) | ||
996 | +static RISCVException write_htval(CPURISCVState *env, int csrno, | ||
997 | + target_ulong val) | ||
998 | { | ||
999 | env->htval = val; | ||
1000 | - return 0; | ||
1001 | + return RISCV_EXCP_NONE; | ||
1002 | } | ||
1003 | |||
1004 | -static int read_htinst(CPURISCVState *env, int csrno, target_ulong *val) | ||
1005 | +static RISCVException read_htinst(CPURISCVState *env, int csrno, | ||
1006 | + target_ulong *val) | ||
1007 | { | ||
1008 | *val = env->htinst; | ||
1009 | - return 0; | ||
1010 | + return RISCV_EXCP_NONE; | ||
1011 | } | ||
1012 | |||
1013 | -static int write_htinst(CPURISCVState *env, int csrno, target_ulong val) | ||
1014 | +static RISCVException write_htinst(CPURISCVState *env, int csrno, | ||
1015 | + target_ulong val) | ||
1016 | { | ||
1017 | - return 0; | ||
1018 | + return RISCV_EXCP_NONE; | ||
1019 | } | ||
1020 | |||
1021 | -static int read_hgeip(CPURISCVState *env, int csrno, target_ulong *val) | ||
1022 | +static RISCVException read_hgeip(CPURISCVState *env, int csrno, | ||
1023 | + target_ulong *val) | ||
1024 | { | ||
1025 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
1026 | - return 0; | ||
1027 | + return RISCV_EXCP_NONE; | ||
1028 | } | ||
1029 | |||
1030 | -static int write_hgeip(CPURISCVState *env, int csrno, target_ulong val) | ||
1031 | +static RISCVException write_hgeip(CPURISCVState *env, int csrno, | ||
1032 | + target_ulong val) | ||
1033 | { | ||
1034 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
1035 | - return 0; | ||
1036 | + return RISCV_EXCP_NONE; | ||
1037 | } | ||
1038 | |||
1039 | -static int read_hgatp(CPURISCVState *env, int csrno, target_ulong *val) | ||
1040 | +static RISCVException read_hgatp(CPURISCVState *env, int csrno, | ||
1041 | + target_ulong *val) | ||
1042 | { | ||
1043 | *val = env->hgatp; | ||
1044 | - return 0; | ||
1045 | + return RISCV_EXCP_NONE; | ||
1046 | } | ||
1047 | |||
1048 | -static int write_hgatp(CPURISCVState *env, int csrno, target_ulong val) | ||
1049 | +static RISCVException write_hgatp(CPURISCVState *env, int csrno, | ||
1050 | + target_ulong val) | ||
1051 | { | ||
1052 | env->hgatp = val; | ||
1053 | - return 0; | ||
1054 | + return RISCV_EXCP_NONE; | ||
1055 | } | ||
1056 | |||
1057 | -static int read_htimedelta(CPURISCVState *env, int csrno, target_ulong *val) | ||
1058 | +static RISCVException read_htimedelta(CPURISCVState *env, int csrno, | ||
1059 | + target_ulong *val) | ||
1060 | { | ||
1061 | if (!env->rdtime_fn) { | ||
1062 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1063 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1064 | } | ||
1065 | |||
1066 | *val = env->htimedelta; | ||
1067 | - return 0; | ||
1068 | + return RISCV_EXCP_NONE; | ||
1069 | } | ||
1070 | |||
1071 | -static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val) | ||
1072 | +static RISCVException write_htimedelta(CPURISCVState *env, int csrno, | ||
1073 | + target_ulong val) | ||
1074 | { | ||
1075 | if (!env->rdtime_fn) { | ||
1076 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1077 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1078 | } | ||
1079 | |||
1080 | if (riscv_cpu_is_32bit(env)) { | ||
1081 | @@ -XXX,XX +XXX,XX @@ static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val) | ||
1082 | } else { | ||
1083 | env->htimedelta = val; | ||
1084 | } | ||
1085 | - return 0; | ||
1086 | + return RISCV_EXCP_NONE; | ||
1087 | } | ||
1088 | |||
1089 | -static int read_htimedeltah(CPURISCVState *env, int csrno, target_ulong *val) | ||
1090 | +static RISCVException read_htimedeltah(CPURISCVState *env, int csrno, | ||
1091 | + target_ulong *val) | ||
1092 | { | ||
1093 | if (!env->rdtime_fn) { | ||
1094 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1095 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1096 | } | ||
1097 | |||
1098 | *val = env->htimedelta >> 32; | ||
1099 | - return 0; | ||
1100 | + return RISCV_EXCP_NONE; | ||
1101 | } | ||
1102 | |||
1103 | -static int write_htimedeltah(CPURISCVState *env, int csrno, target_ulong val) | ||
1104 | +static RISCVException write_htimedeltah(CPURISCVState *env, int csrno, | ||
1105 | + target_ulong val) | ||
1106 | { | ||
1107 | if (!env->rdtime_fn) { | ||
1108 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1109 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1110 | } | ||
1111 | |||
1112 | env->htimedelta = deposit64(env->htimedelta, 32, 32, (uint64_t)val); | ||
1113 | - return 0; | ||
1114 | + return RISCV_EXCP_NONE; | ||
1115 | } | ||
1116 | |||
1117 | /* Virtual CSR Registers */ | ||
1118 | -static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
1119 | +static RISCVException read_vsstatus(CPURISCVState *env, int csrno, | ||
1120 | + target_ulong *val) | ||
1121 | { | ||
1122 | *val = env->vsstatus; | ||
1123 | - return 0; | ||
1124 | + return RISCV_EXCP_NONE; | ||
1125 | } | ||
1126 | |||
1127 | -static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
1128 | +static RISCVException write_vsstatus(CPURISCVState *env, int csrno, | ||
1129 | + target_ulong val) | ||
1130 | { | ||
1131 | uint64_t mask = (target_ulong)-1; | ||
1132 | env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val; | ||
1133 | - return 0; | ||
1134 | + return RISCV_EXCP_NONE; | ||
1135 | } | ||
1136 | |||
1137 | static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
1138 | { | ||
1139 | *val = env->vstvec; | ||
1140 | - return 0; | ||
1141 | + return RISCV_EXCP_NONE; | ||
1142 | } | ||
1143 | |||
1144 | -static int write_vstvec(CPURISCVState *env, int csrno, target_ulong val) | ||
1145 | +static RISCVException write_vstvec(CPURISCVState *env, int csrno, | ||
1146 | + target_ulong val) | ||
1147 | { | ||
1148 | env->vstvec = val; | ||
1149 | - return 0; | ||
1150 | + return RISCV_EXCP_NONE; | ||
1151 | } | ||
1152 | |||
1153 | -static int read_vsscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
1154 | +static RISCVException read_vsscratch(CPURISCVState *env, int csrno, | ||
1155 | + target_ulong *val) | ||
1156 | { | ||
1157 | *val = env->vsscratch; | ||
1158 | - return 0; | ||
1159 | + return RISCV_EXCP_NONE; | ||
1160 | } | ||
1161 | |||
1162 | -static int write_vsscratch(CPURISCVState *env, int csrno, target_ulong val) | ||
1163 | +static RISCVException write_vsscratch(CPURISCVState *env, int csrno, | ||
1164 | + target_ulong val) | ||
1165 | { | ||
1166 | env->vsscratch = val; | ||
1167 | - return 0; | ||
1168 | + return RISCV_EXCP_NONE; | ||
1169 | } | ||
1170 | |||
1171 | -static int read_vsepc(CPURISCVState *env, int csrno, target_ulong *val) | ||
1172 | +static RISCVException read_vsepc(CPURISCVState *env, int csrno, | ||
1173 | + target_ulong *val) | ||
1174 | { | ||
1175 | *val = env->vsepc; | ||
1176 | - return 0; | ||
1177 | + return RISCV_EXCP_NONE; | ||
1178 | } | ||
1179 | |||
1180 | -static int write_vsepc(CPURISCVState *env, int csrno, target_ulong val) | ||
1181 | +static RISCVException write_vsepc(CPURISCVState *env, int csrno, | ||
1182 | + target_ulong val) | ||
1183 | { | ||
1184 | env->vsepc = val; | ||
1185 | - return 0; | ||
1186 | + return RISCV_EXCP_NONE; | ||
1187 | } | ||
1188 | |||
1189 | -static int read_vscause(CPURISCVState *env, int csrno, target_ulong *val) | ||
1190 | +static RISCVException read_vscause(CPURISCVState *env, int csrno, | ||
1191 | + target_ulong *val) | ||
1192 | { | ||
1193 | *val = env->vscause; | ||
1194 | - return 0; | ||
1195 | + return RISCV_EXCP_NONE; | ||
1196 | } | ||
1197 | |||
1198 | -static int write_vscause(CPURISCVState *env, int csrno, target_ulong val) | ||
1199 | +static RISCVException write_vscause(CPURISCVState *env, int csrno, | ||
1200 | + target_ulong val) | ||
1201 | { | ||
1202 | env->vscause = val; | ||
1203 | - return 0; | ||
1204 | + return RISCV_EXCP_NONE; | ||
1205 | } | ||
1206 | |||
1207 | -static int read_vstval(CPURISCVState *env, int csrno, target_ulong *val) | ||
1208 | +static RISCVException read_vstval(CPURISCVState *env, int csrno, | ||
1209 | + target_ulong *val) | ||
1210 | { | ||
1211 | *val = env->vstval; | ||
1212 | - return 0; | ||
1213 | + return RISCV_EXCP_NONE; | ||
1214 | } | ||
1215 | |||
1216 | -static int write_vstval(CPURISCVState *env, int csrno, target_ulong val) | ||
1217 | +static RISCVException write_vstval(CPURISCVState *env, int csrno, | ||
1218 | + target_ulong val) | ||
1219 | { | ||
1220 | env->vstval = val; | ||
1221 | - return 0; | ||
1222 | + return RISCV_EXCP_NONE; | ||
1223 | } | ||
1224 | |||
1225 | -static int read_vsatp(CPURISCVState *env, int csrno, target_ulong *val) | ||
1226 | +static RISCVException read_vsatp(CPURISCVState *env, int csrno, | ||
1227 | + target_ulong *val) | ||
1228 | { | ||
1229 | *val = env->vsatp; | ||
1230 | - return 0; | ||
1231 | + return RISCV_EXCP_NONE; | ||
1232 | } | ||
1233 | |||
1234 | -static int write_vsatp(CPURISCVState *env, int csrno, target_ulong val) | ||
1235 | +static RISCVException write_vsatp(CPURISCVState *env, int csrno, | ||
1236 | + target_ulong val) | ||
1237 | { | ||
1238 | env->vsatp = val; | ||
1239 | - return 0; | ||
1240 | + return RISCV_EXCP_NONE; | ||
1241 | } | ||
1242 | |||
1243 | -static int read_mtval2(CPURISCVState *env, int csrno, target_ulong *val) | ||
1244 | +static RISCVException read_mtval2(CPURISCVState *env, int csrno, | ||
1245 | + target_ulong *val) | ||
1246 | { | ||
1247 | *val = env->mtval2; | ||
1248 | - return 0; | ||
1249 | + return RISCV_EXCP_NONE; | ||
1250 | } | ||
1251 | |||
1252 | -static int write_mtval2(CPURISCVState *env, int csrno, target_ulong val) | ||
1253 | +static RISCVException write_mtval2(CPURISCVState *env, int csrno, | ||
1254 | + target_ulong val) | ||
1255 | { | ||
1256 | env->mtval2 = val; | ||
1257 | - return 0; | ||
1258 | + return RISCV_EXCP_NONE; | ||
1259 | } | ||
1260 | |||
1261 | -static int read_mtinst(CPURISCVState *env, int csrno, target_ulong *val) | ||
1262 | +static RISCVException read_mtinst(CPURISCVState *env, int csrno, | ||
1263 | + target_ulong *val) | ||
1264 | { | ||
1265 | *val = env->mtinst; | ||
1266 | - return 0; | ||
1267 | + return RISCV_EXCP_NONE; | ||
1268 | } | ||
1269 | |||
1270 | -static int write_mtinst(CPURISCVState *env, int csrno, target_ulong val) | ||
1271 | +static RISCVException write_mtinst(CPURISCVState *env, int csrno, | ||
1272 | + target_ulong val) | ||
1273 | { | ||
1274 | env->mtinst = val; | ||
1275 | - return 0; | ||
1276 | + return RISCV_EXCP_NONE; | ||
1277 | } | ||
1278 | |||
1279 | /* Physical Memory Protection */ | ||
1280 | -static int read_pmpcfg(CPURISCVState *env, int csrno, target_ulong *val) | ||
1281 | +static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, | ||
1282 | + target_ulong *val) | ||
1283 | { | ||
1284 | *val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0); | ||
1285 | - return 0; | ||
1286 | + return RISCV_EXCP_NONE; | ||
1287 | } | ||
1288 | |||
1289 | -static int write_pmpcfg(CPURISCVState *env, int csrno, target_ulong val) | ||
1290 | +static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, | ||
1291 | + target_ulong val) | ||
1292 | { | ||
1293 | pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val); | ||
1294 | - return 0; | ||
1295 | + return RISCV_EXCP_NONE; | ||
1296 | } | ||
1297 | |||
1298 | -static int read_pmpaddr(CPURISCVState *env, int csrno, target_ulong *val) | ||
1299 | +static RISCVException read_pmpaddr(CPURISCVState *env, int csrno, | ||
1300 | + target_ulong *val) | ||
1301 | { | ||
1302 | *val = pmpaddr_csr_read(env, csrno - CSR_PMPADDR0); | ||
1303 | - return 0; | ||
1304 | + return RISCV_EXCP_NONE; | ||
1305 | } | ||
1306 | |||
1307 | -static int write_pmpaddr(CPURISCVState *env, int csrno, target_ulong val) | ||
1308 | +static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, | ||
1309 | + target_ulong val) | ||
1310 | { | ||
1311 | pmpaddr_csr_write(env, csrno - CSR_PMPADDR0, val); | ||
1312 | - return 0; | ||
1313 | + return RISCV_EXCP_NONE; | ||
1314 | } | ||
1315 | |||
1316 | #endif | ||
1317 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
1318 | |||
1319 | /* execute combined read/write operation if it exists */ | ||
1320 | if (csr_ops[csrno].op) { | ||
1321 | - return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
1322 | + ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
1323 | + if (ret != RISCV_EXCP_NONE) { | ||
1324 | + return -ret; | ||
1325 | + } | ||
1326 | + return 0; | ||
1327 | } | ||
1328 | |||
1329 | /* if no accessor exists then return failure */ | ||
1330 | if (!csr_ops[csrno].read) { | ||
1331 | return -RISCV_EXCP_ILLEGAL_INST; | ||
1332 | } | ||
114 | - | 1333 | - |
115 | -static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) | 1334 | /* read old value */ |
116 | -{ | 1335 | ret = csr_ops[csrno].read(env, csrno, &old_value); |
117 | - *val = env->mie & env->mideleg & VS_MODE_INTERRUPTS; | 1336 | - if (ret < 0) { |
118 | - return 0; | 1337 | - return ret; |
119 | -} | 1338 | + if (ret != RISCV_EXCP_NONE) { |
120 | - | 1339 | + return -ret; |
121 | -static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) | 1340 | } |
122 | -{ | 1341 | |
123 | - target_ulong newval = (env->mie & ~env->mideleg) | (val & env->mideleg & MIP_VSSIP); | 1342 | /* write value if writable and write mask set, otherwise drop writes */ |
124 | - return write_mie(env, CSR_MIE, newval); | 1343 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
125 | -} | 1344 | new_value = (old_value & ~write_mask) | (new_value & write_mask); |
126 | - | 1345 | if (csr_ops[csrno].write) { |
127 | static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val) | 1346 | ret = csr_ops[csrno].write(env, csrno, new_value); |
128 | { | 1347 | - if (ret < 0) { |
129 | *val = env->vstvec; | 1348 | - return ret; |
1349 | + if (ret != RISCV_EXCP_NONE) { | ||
1350 | + return -ret; | ||
1351 | } | ||
1352 | } | ||
1353 | } | ||
130 | -- | 1354 | -- |
131 | 2.30.1 | 1355 | 2.31.1 |
132 | 1356 | ||
133 | 1357 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 302b208f40373557fa11b351b5c9f43039ca8ea3.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 11 +++++++---- | ||
7 | target/riscv/csr.c | 37 ++++++++++++++++++------------------- | ||
8 | target/riscv/gdbstub.c | 8 ++++---- | ||
9 | target/riscv/op_helper.c | 18 +++++++++--------- | ||
10 | 4 files changed, 38 insertions(+), 36 deletions(-) | ||
1 | 11 | ||
12 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/riscv/cpu.h | ||
15 | +++ b/target/riscv/cpu.h | ||
16 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
17 | *pflags = flags; | ||
18 | } | ||
19 | |||
20 | -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
21 | - target_ulong new_value, target_ulong write_mask); | ||
22 | -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
23 | - target_ulong new_value, target_ulong write_mask); | ||
24 | +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
25 | + target_ulong *ret_value, | ||
26 | + target_ulong new_value, target_ulong write_mask); | ||
27 | +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, | ||
28 | + target_ulong *ret_value, | ||
29 | + target_ulong new_value, | ||
30 | + target_ulong write_mask); | ||
31 | |||
32 | static inline void riscv_csr_write(CPURISCVState *env, int csrno, | ||
33 | target_ulong val) | ||
34 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/riscv/csr.c | ||
37 | +++ b/target/riscv/csr.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, | ||
39 | * csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value); | ||
40 | */ | ||
41 | |||
42 | -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
43 | - target_ulong new_value, target_ulong write_mask) | ||
44 | +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
45 | + target_ulong *ret_value, | ||
46 | + target_ulong new_value, target_ulong write_mask) | ||
47 | { | ||
48 | - int ret; | ||
49 | + RISCVException ret; | ||
50 | target_ulong old_value; | ||
51 | RISCVCPU *cpu = env_archcpu(env); | ||
52 | |||
53 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
54 | |||
55 | if ((write_mask && read_only) || | ||
56 | (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) { | ||
57 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
58 | + return RISCV_EXCP_ILLEGAL_INST; | ||
59 | } | ||
60 | #endif | ||
61 | |||
62 | /* ensure the CSR extension is enabled. */ | ||
63 | if (!cpu->cfg.ext_icsr) { | ||
64 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
65 | + return RISCV_EXCP_ILLEGAL_INST; | ||
66 | } | ||
67 | |||
68 | /* check predicate */ | ||
69 | if (!csr_ops[csrno].predicate) { | ||
70 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
71 | + return RISCV_EXCP_ILLEGAL_INST; | ||
72 | } | ||
73 | ret = csr_ops[csrno].predicate(env, csrno); | ||
74 | if (ret != RISCV_EXCP_NONE) { | ||
75 | - return -ret; | ||
76 | + return ret; | ||
77 | } | ||
78 | |||
79 | /* execute combined read/write operation if it exists */ | ||
80 | if (csr_ops[csrno].op) { | ||
81 | - ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
82 | - if (ret != RISCV_EXCP_NONE) { | ||
83 | - return -ret; | ||
84 | - } | ||
85 | - return 0; | ||
86 | + return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
87 | } | ||
88 | |||
89 | /* if no accessor exists then return failure */ | ||
90 | if (!csr_ops[csrno].read) { | ||
91 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
92 | + return RISCV_EXCP_ILLEGAL_INST; | ||
93 | } | ||
94 | /* read old value */ | ||
95 | ret = csr_ops[csrno].read(env, csrno, &old_value); | ||
96 | if (ret != RISCV_EXCP_NONE) { | ||
97 | - return -ret; | ||
98 | + return ret; | ||
99 | } | ||
100 | |||
101 | /* write value if writable and write mask set, otherwise drop writes */ | ||
102 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
103 | if (csr_ops[csrno].write) { | ||
104 | ret = csr_ops[csrno].write(env, csrno, new_value); | ||
105 | if (ret != RISCV_EXCP_NONE) { | ||
106 | - return -ret; | ||
107 | + return ret; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
112 | *ret_value = old_value; | ||
113 | } | ||
114 | |||
115 | - return 0; | ||
116 | + return RISCV_EXCP_NONE; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Debugger support. If not in user mode, set env->debugger before the | ||
121 | * riscv_csrrw call and clear it after the call. | ||
122 | */ | ||
123 | -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
124 | - target_ulong new_value, target_ulong write_mask) | ||
125 | +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, | ||
126 | + target_ulong *ret_value, | ||
127 | + target_ulong new_value, | ||
128 | + target_ulong write_mask) | ||
129 | { | ||
130 | - int ret; | ||
131 | + RISCVException ret; | ||
132 | #if !defined(CONFIG_USER_ONLY) | ||
133 | env->debugger = true; | ||
134 | #endif | ||
135 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/target/riscv/gdbstub.c | ||
138 | +++ b/target/riscv/gdbstub.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) | ||
140 | */ | ||
141 | result = riscv_csrrw_debug(env, n - 32, &val, | ||
142 | 0, 0); | ||
143 | - if (result == 0) { | ||
144 | + if (result == RISCV_EXCP_NONE) { | ||
145 | return gdb_get_regl(buf, val); | ||
146 | } | ||
147 | } | ||
148 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
149 | */ | ||
150 | result = riscv_csrrw_debug(env, n - 32, NULL, | ||
151 | val, -1); | ||
152 | - if (result == 0) { | ||
153 | + if (result == RISCV_EXCP_NONE) { | ||
154 | return sizeof(target_ulong); | ||
155 | } | ||
156 | } | ||
157 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n) | ||
158 | int result; | ||
159 | |||
160 | result = riscv_csrrw_debug(env, n, &val, 0, 0); | ||
161 | - if (result == 0) { | ||
162 | + if (result == RISCV_EXCP_NONE) { | ||
163 | return gdb_get_regl(buf, val); | ||
164 | } | ||
165 | } | ||
166 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
167 | int result; | ||
168 | |||
169 | result = riscv_csrrw_debug(env, n, NULL, val, -1); | ||
170 | - if (result == 0) { | ||
171 | + if (result == RISCV_EXCP_NONE) { | ||
172 | return sizeof(target_ulong); | ||
173 | } | ||
174 | } | ||
175 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/target/riscv/op_helper.c | ||
178 | +++ b/target/riscv/op_helper.c | ||
179 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, target_ulong src, | ||
180 | target_ulong csr) | ||
181 | { | ||
182 | target_ulong val = 0; | ||
183 | - int ret = riscv_csrrw(env, csr, &val, src, -1); | ||
184 | + RISCVException ret = riscv_csrrw(env, csr, &val, src, -1); | ||
185 | |||
186 | - if (ret < 0) { | ||
187 | - riscv_raise_exception(env, -ret, GETPC()); | ||
188 | + if (ret != RISCV_EXCP_NONE) { | ||
189 | + riscv_raise_exception(env, ret, GETPC()); | ||
190 | } | ||
191 | return val; | ||
192 | } | ||
193 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrs(CPURISCVState *env, target_ulong src, | ||
194 | target_ulong csr, target_ulong rs1_pass) | ||
195 | { | ||
196 | target_ulong val = 0; | ||
197 | - int ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0); | ||
198 | + RISCVException ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0); | ||
199 | |||
200 | - if (ret < 0) { | ||
201 | - riscv_raise_exception(env, -ret, GETPC()); | ||
202 | + if (ret != RISCV_EXCP_NONE) { | ||
203 | + riscv_raise_exception(env, ret, GETPC()); | ||
204 | } | ||
205 | return val; | ||
206 | } | ||
207 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src, | ||
208 | target_ulong csr, target_ulong rs1_pass) | ||
209 | { | ||
210 | target_ulong val = 0; | ||
211 | - int ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0); | ||
212 | + RISCVException ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0); | ||
213 | |||
214 | - if (ret < 0) { | ||
215 | - riscv_raise_exception(env, -ret, GETPC()); | ||
216 | + if (ret != RISCV_EXCP_NONE) { | ||
217 | + riscv_raise_exception(env, ret, GETPC()); | ||
218 | } | ||
219 | return val; | ||
220 | } | ||
221 | -- | ||
222 | 2.31.1 | ||
223 | |||
224 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Update the RISC-V maintainers by removing Sagar and Bastian who haven't | ||
2 | been involved recently. | ||
1 | 3 | ||
4 | Also add Bin who has been helping with reviews. | ||
5 | |||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Acked-by: Bin Meng <bin.meng@windriver.com> | ||
8 | Acked-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 6564ba829c40ad9aa7d28f43be69d8eb5cf4b56b.1617749142.git.alistair.francis@wdc.com | ||
11 | --- | ||
12 | MAINTAINERS | 5 ++--- | ||
13 | 1 file changed, 2 insertions(+), 3 deletions(-) | ||
14 | |||
15 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/MAINTAINERS | ||
18 | +++ b/MAINTAINERS | ||
19 | @@ -XXX,XX +XXX,XX @@ F: tests/acceptance/machine_ppc.py | ||
20 | |||
21 | RISC-V TCG CPUs | ||
22 | M: Palmer Dabbelt <palmer@dabbelt.com> | ||
23 | -M: Alistair Francis <Alistair.Francis@wdc.com> | ||
24 | -M: Sagar Karandikar <sagark@eecs.berkeley.edu> | ||
25 | -M: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> | ||
26 | +M: Alistair Francis <alistair.francis@wdc.com> | ||
27 | +M: Bin Meng <bin.meng@windriver.com> | ||
28 | L: qemu-riscv@nongnu.org | ||
29 | S: Supported | ||
30 | F: target/riscv/ | ||
31 | -- | ||
32 | 2.31.1 | ||
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Update the OpenTitan interrupt layout to match the latest OpenTitan | ||
2 | bitstreams. This involves changing the Ibex PLIC memory layout and the | ||
3 | UART interrupts. | ||
1 | 4 | ||
5 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
7 | Message-id: e92b696f1809c9fa4410da2e9f23c414db5a6960.1617202791.git.alistair.francis@wdc.com | ||
8 | --- | ||
9 | include/hw/riscv/opentitan.h | 16 ++++++++-------- | ||
10 | hw/intc/ibex_plic.c | 20 ++++++++++---------- | ||
11 | hw/riscv/opentitan.c | 8 ++++---- | ||
12 | 3 files changed, 22 insertions(+), 22 deletions(-) | ||
13 | |||
14 | diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/riscv/opentitan.h | ||
17 | +++ b/include/hw/riscv/opentitan.h | ||
18 | @@ -XXX,XX +XXX,XX @@ enum { | ||
19 | }; | ||
20 | |||
21 | enum { | ||
22 | - IBEX_UART_RX_PARITY_ERR_IRQ = 0x28, | ||
23 | - IBEX_UART_RX_TIMEOUT_IRQ = 0x27, | ||
24 | - IBEX_UART_RX_BREAK_ERR_IRQ = 0x26, | ||
25 | - IBEX_UART_RX_FRAME_ERR_IRQ = 0x25, | ||
26 | - IBEX_UART_RX_OVERFLOW_IRQ = 0x24, | ||
27 | - IBEX_UART_TX_EMPTY_IRQ = 0x23, | ||
28 | - IBEX_UART_RX_WATERMARK_IRQ = 0x22, | ||
29 | - IBEX_UART_TX_WATERMARK_IRQ = 0x21, | ||
30 | + IBEX_UART0_RX_PARITY_ERR_IRQ = 8, | ||
31 | + IBEX_UART0_RX_TIMEOUT_IRQ = 7, | ||
32 | + IBEX_UART0_RX_BREAK_ERR_IRQ = 6, | ||
33 | + IBEX_UART0_RX_FRAME_ERR_IRQ = 5, | ||
34 | + IBEX_UART0_RX_OVERFLOW_IRQ = 4, | ||
35 | + IBEX_UART0_TX_EMPTY_IRQ = 3, | ||
36 | + IBEX_UART0_RX_WATERMARK_IRQ = 2, | ||
37 | + IBEX_UART0_TX_WATERMARK_IRQ = 1, | ||
38 | }; | ||
39 | |||
40 | #endif | ||
41 | diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/intc/ibex_plic.c | ||
44 | +++ b/hw/intc/ibex_plic.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static void ibex_plic_irq_request(void *opaque, int irq, int level) | ||
46 | |||
47 | static Property ibex_plic_properties[] = { | ||
48 | DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1), | ||
49 | - DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 80), | ||
50 | + DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 176), | ||
51 | |||
52 | DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0), | ||
53 | - DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 3), | ||
54 | + DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 6), | ||
55 | |||
56 | - DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x0c), | ||
57 | - DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 3), | ||
58 | + DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x18), | ||
59 | + DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 6), | ||
60 | |||
61 | - DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x18), | ||
62 | - DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 80), | ||
63 | + DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x30), | ||
64 | + DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 177), | ||
65 | |||
66 | - DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x200), | ||
67 | - DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 3), | ||
68 | + DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x300), | ||
69 | + DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 6), | ||
70 | |||
71 | - DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x20c), | ||
72 | + DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x318), | ||
73 | |||
74 | - DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x210), | ||
75 | + DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x31c), | ||
76 | DEFINE_PROP_END_OF_LIST(), | ||
77 | }; | ||
78 | |||
79 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/hw/riscv/opentitan.c | ||
82 | +++ b/hw/riscv/opentitan.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | ||
84 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart), 0, memmap[IBEX_DEV_UART].base); | ||
85 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
86 | 0, qdev_get_gpio_in(DEVICE(&s->plic), | ||
87 | - IBEX_UART_TX_WATERMARK_IRQ)); | ||
88 | + IBEX_UART0_TX_WATERMARK_IRQ)); | ||
89 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
90 | 1, qdev_get_gpio_in(DEVICE(&s->plic), | ||
91 | - IBEX_UART_RX_WATERMARK_IRQ)); | ||
92 | + IBEX_UART0_RX_WATERMARK_IRQ)); | ||
93 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
94 | 2, qdev_get_gpio_in(DEVICE(&s->plic), | ||
95 | - IBEX_UART_TX_EMPTY_IRQ)); | ||
96 | + IBEX_UART0_TX_EMPTY_IRQ)); | ||
97 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
98 | 3, qdev_get_gpio_in(DEVICE(&s->plic), | ||
99 | - IBEX_UART_RX_OVERFLOW_IRQ)); | ||
100 | + IBEX_UART0_RX_OVERFLOW_IRQ)); | ||
101 | |||
102 | create_unimplemented_device("riscv.lowrisc.ibex.gpio", | ||
103 | memmap[IBEX_DEV_GPIO].base, memmap[IBEX_DEV_GPIO].size); | ||
104 | -- | ||
105 | 2.31.1 | ||
106 | |||
107 | diff view generated by jsdifflib |
1 | From: Asherah Connor <ashe@kivikakk.ee> | 1 | imply VIRTIO_VGA for the virt machine, this fixes the following error |
---|---|---|---|
2 | when specifying `-vga virtio` as a command line argument: | ||
2 | 3 | ||
3 | Provides fw_cfg for the virt machine on riscv. This enables | 4 | qemu-system-riscv64: Virtio VGA not available |
4 | using e.g. ramfb later. | ||
5 | 5 | ||
6 | Signed-off-by: Asherah Connor <ashe@kivikakk.ee> | 6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Message-id: 7ac26fafee8bd59d2a0640f3233f8ad1ab270e1e.1617367317.git.alistair.francis@wdc.com |
9 | Message-id: 20210318235041.17175-2-ashe@kivikakk.ee | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | 9 | --- |
12 | include/hw/riscv/virt.h | 2 ++ | 10 | hw/riscv/Kconfig | 1 + |
13 | hw/riscv/virt.c | 30 ++++++++++++++++++++++++++++++ | 11 | 1 file changed, 1 insertion(+) |
14 | hw/riscv/Kconfig | 1 + | ||
15 | 3 files changed, 33 insertions(+) | ||
16 | 12 | ||
17 | diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/hw/riscv/virt.h | ||
20 | +++ b/include/hw/riscv/virt.h | ||
21 | @@ -XXX,XX +XXX,XX @@ struct RISCVVirtState { | ||
22 | RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; | ||
23 | DeviceState *plic[VIRT_SOCKETS_MAX]; | ||
24 | PFlashCFI01 *flash[2]; | ||
25 | + FWCfgState *fw_cfg; | ||
26 | |||
27 | int fdt_size; | ||
28 | }; | ||
29 | @@ -XXX,XX +XXX,XX @@ enum { | ||
30 | VIRT_PLIC, | ||
31 | VIRT_UART0, | ||
32 | VIRT_VIRTIO, | ||
33 | + VIRT_FW_CFG, | ||
34 | VIRT_FLASH, | ||
35 | VIRT_DRAM, | ||
36 | VIRT_PCIE_MMIO, | ||
37 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/hw/riscv/virt.c | ||
40 | +++ b/hw/riscv/virt.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry virt_memmap[] = { | ||
42 | [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, | ||
43 | [VIRT_UART0] = { 0x10000000, 0x100 }, | ||
44 | [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, | ||
45 | + [VIRT_FW_CFG] = { 0x10100000, 0x18 }, | ||
46 | [VIRT_FLASH] = { 0x20000000, 0x4000000 }, | ||
47 | [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, | ||
48 | [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, | ||
49 | @@ -XXX,XX +XXX,XX @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, | ||
50 | return dev; | ||
51 | } | ||
52 | |||
53 | +static FWCfgState *create_fw_cfg(const MachineState *mc) | ||
54 | +{ | ||
55 | + hwaddr base = virt_memmap[VIRT_FW_CFG].base; | ||
56 | + hwaddr size = virt_memmap[VIRT_FW_CFG].size; | ||
57 | + FWCfgState *fw_cfg; | ||
58 | + char *nodename; | ||
59 | + | ||
60 | + fw_cfg = fw_cfg_init_mem_wide(base + 8, base, 8, base + 16, | ||
61 | + &address_space_memory); | ||
62 | + fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)mc->smp.cpus); | ||
63 | + | ||
64 | + nodename = g_strdup_printf("/fw-cfg@%" PRIx64, base); | ||
65 | + qemu_fdt_add_subnode(mc->fdt, nodename); | ||
66 | + qemu_fdt_setprop_string(mc->fdt, nodename, | ||
67 | + "compatible", "qemu,fw-cfg-mmio"); | ||
68 | + qemu_fdt_setprop_sized_cells(mc->fdt, nodename, "reg", | ||
69 | + 2, base, 2, size); | ||
70 | + qemu_fdt_setprop(mc->fdt, nodename, "dma-coherent", NULL, 0); | ||
71 | + g_free(nodename); | ||
72 | + return fw_cfg; | ||
73 | +} | ||
74 | + | ||
75 | static void virt_machine_init(MachineState *machine) | ||
76 | { | ||
77 | const MemMapEntry *memmap = virt_memmap; | ||
78 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
79 | start_addr = virt_memmap[VIRT_FLASH].base; | ||
80 | } | ||
81 | |||
82 | + /* | ||
83 | + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | ||
84 | + * tree cannot be altered and we get FDT_ERR_NOSPACE. | ||
85 | + */ | ||
86 | + s->fw_cfg = create_fw_cfg(machine); | ||
87 | + rom_set_fw(s->fw_cfg); | ||
88 | + | ||
89 | /* Compute the fdt load address in dram */ | ||
90 | fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base, | ||
91 | machine->ram_size, machine->fdt); | ||
92 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 13 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig |
93 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
94 | --- a/hw/riscv/Kconfig | 15 | --- a/hw/riscv/Kconfig |
95 | +++ b/hw/riscv/Kconfig | 16 | +++ b/hw/riscv/Kconfig |
96 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | 17 | @@ -XXX,XX +XXX,XX @@ config SHAKTI_C |
97 | select SIFIVE_PLIC | 18 | config RISCV_VIRT |
98 | select SIFIVE_TEST | ||
99 | select VIRTIO_MMIO | ||
100 | + select FW_CFG_DMA | ||
101 | |||
102 | config SIFIVE_E | ||
103 | bool | 19 | bool |
20 | imply PCI_DEVICES | ||
21 | + imply VIRTIO_VGA | ||
22 | imply TEST_DEVICES | ||
23 | select GOLDFISH_RTC | ||
24 | select MSI_NONBROKEN | ||
104 | -- | 25 | -- |
105 | 2.30.1 | 26 | 2.31.1 |
106 | 27 | ||
107 | 28 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | 1 | From: Jade Fink <qemu@jade.fyi> |
---|---|---|---|
2 | 2 | ||
3 | Like MMU translation, add qemu log of PMP permission checking for | 3 | Previously the qemu monitor and gdbstub looked at SUM and refused to |
4 | perform accesses to user memory if it is off, which was an impediment to | ||
4 | debugging. | 5 | debugging. |
5 | 6 | ||
6 | Signed-off-by: Jim Shu <cwshu@andestech.com> | 7 | Signed-off-by: Jade Fink <qemu@jade.fyi> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 1613916082-19528-3-git-send-email-cwshu@andestech.com | 9 | Message-id: 20210406113109.1031033-1-qemu@jade.fyi |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 11 | --- |
11 | target/riscv/cpu_helper.c | 12 ++++++++++++ | 12 | target/riscv/cpu_helper.c | 20 ++++++++++++-------- |
12 | 1 file changed, 12 insertions(+) | 13 | 1 file changed, 12 insertions(+), 8 deletions(-) |
13 | 14 | ||
14 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu_helper.c | 17 | --- a/target/riscv/cpu_helper.c |
17 | +++ b/target/riscv/cpu_helper.c | 18 | +++ b/target/riscv/cpu_helper.c |
18 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, |
19 | if (ret == TRANSLATE_SUCCESS) { | 20 | * @first_stage: Are we in first stage translation? |
20 | ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | 21 | * Second stage is used for hypervisor guest translation |
21 | size, access_type, mode); | 22 | * @two_stage: Are we going to perform two stage translation |
22 | + | 23 | + * @is_debug: Is this access from a debugger or the monitor? |
23 | + qemu_log_mask(CPU_LOG_MMU, | 24 | */ |
24 | + "%s PMP address=" TARGET_FMT_plx " ret %d prot" | 25 | static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
25 | + " %d tlb_size " TARGET_FMT_lu "\n", | 26 | int *prot, target_ulong addr, |
26 | + __func__, pa, ret, prot_pmp, tlb_size); | 27 | target_ulong *fault_pte_addr, |
27 | + | 28 | int access_type, int mmu_idx, |
28 | prot &= prot_pmp; | 29 | - bool first_stage, bool two_stage) |
29 | } | 30 | + bool first_stage, bool two_stage, |
30 | 31 | + bool is_debug) | |
31 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 32 | { |
32 | if (ret == TRANSLATE_SUCCESS) { | 33 | /* NOTE: the env->pc value visible here will not be |
33 | ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | 34 | * correct, but the value visible to the exception handler |
34 | size, access_type, mode); | 35 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
35 | + | 36 | widened = 2; |
36 | + qemu_log_mask(CPU_LOG_MMU, | 37 | } |
37 | + "%s PMP address=" TARGET_FMT_plx " ret %d prot" | 38 | /* status.SUM will be ignored if execute on background */ |
38 | + " %d tlb_size " TARGET_FMT_lu "\n", | 39 | - sum = get_field(env->mstatus, MSTATUS_SUM) || use_background; |
39 | + __func__, pa, ret, prot_pmp, tlb_size); | 40 | + sum = get_field(env->mstatus, MSTATUS_SUM) || use_background || is_debug; |
40 | + | 41 | switch (vm) { |
41 | prot &= prot_pmp; | 42 | case VM_1_10_SV32: |
43 | levels = 2; ptidxbits = 10; ptesize = 4; break; | ||
44 | @@ -XXX,XX +XXX,XX @@ restart: | ||
45 | /* Do the second stage translation on the base PTE address. */ | ||
46 | int vbase_ret = get_physical_address(env, &vbase, &vbase_prot, | ||
47 | base, NULL, MMU_DATA_LOAD, | ||
48 | - mmu_idx, false, true); | ||
49 | + mmu_idx, false, true, | ||
50 | + is_debug); | ||
51 | |||
52 | if (vbase_ret != TRANSLATE_SUCCESS) { | ||
53 | if (fault_pte_addr) { | ||
54 | @@ -XXX,XX +XXX,XX @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | ||
55 | int mmu_idx = cpu_mmu_index(&cpu->env, false); | ||
56 | |||
57 | if (get_physical_address(env, &phys_addr, &prot, addr, NULL, 0, mmu_idx, | ||
58 | - true, riscv_cpu_virt_enabled(env))) { | ||
59 | + true, riscv_cpu_virt_enabled(env), true)) { | ||
60 | return -1; | ||
61 | } | ||
62 | |||
63 | if (riscv_cpu_virt_enabled(env)) { | ||
64 | if (get_physical_address(env, &phys_addr, &prot, phys_addr, NULL, | ||
65 | - 0, mmu_idx, false, true)) { | ||
66 | + 0, mmu_idx, false, true, true)) { | ||
67 | return -1; | ||
42 | } | 68 | } |
43 | } | 69 | } |
70 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
71 | /* Two stage lookup */ | ||
72 | ret = get_physical_address(env, &pa, &prot, address, | ||
73 | &env->guest_phys_fault_addr, access_type, | ||
74 | - mmu_idx, true, true); | ||
75 | + mmu_idx, true, true, false); | ||
76 | |||
77 | /* | ||
78 | * A G-stage exception may be triggered during two state lookup. | ||
79 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
80 | im_address = pa; | ||
81 | |||
82 | ret = get_physical_address(env, &pa, &prot2, im_address, NULL, | ||
83 | - access_type, mmu_idx, false, true); | ||
84 | + access_type, mmu_idx, false, true, | ||
85 | + false); | ||
86 | |||
87 | qemu_log_mask(CPU_LOG_MMU, | ||
88 | "%s 2nd-stage address=%" VADDR_PRIx " ret %d physical " | ||
89 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
90 | } else { | ||
91 | /* Single stage lookup */ | ||
92 | ret = get_physical_address(env, &pa, &prot, address, NULL, | ||
93 | - access_type, mmu_idx, true, false); | ||
94 | + access_type, mmu_idx, true, false, false); | ||
95 | |||
96 | qemu_log_mask(CPU_LOG_MMU, | ||
97 | "%s address=%" VADDR_PRIx " ret %d physical " | ||
44 | -- | 98 | -- |
45 | 2.30.1 | 99 | 2.31.1 |
46 | 100 | ||
47 | 101 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
1 | 2 | ||
3 | The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right. | ||
4 | However, when the predication is ture and a is 0, it should return maximum. | ||
5 | |||
6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/vector_helper.c | 8 ++++---- | ||
13 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/vector_helper.c | ||
18 | +++ b/target/riscv/vector_helper.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static inline int8_t ssub8(CPURISCVState *env, int vxrm, int8_t a, int8_t b) | ||
20 | { | ||
21 | int8_t res = a - b; | ||
22 | if ((res ^ a) & (a ^ b) & INT8_MIN) { | ||
23 | - res = a > 0 ? INT8_MAX : INT8_MIN; | ||
24 | + res = a >= 0 ? INT8_MAX : INT8_MIN; | ||
25 | env->vxsat = 0x1; | ||
26 | } | ||
27 | return res; | ||
28 | @@ -XXX,XX +XXX,XX @@ static inline int16_t ssub16(CPURISCVState *env, int vxrm, int16_t a, int16_t b) | ||
29 | { | ||
30 | int16_t res = a - b; | ||
31 | if ((res ^ a) & (a ^ b) & INT16_MIN) { | ||
32 | - res = a > 0 ? INT16_MAX : INT16_MIN; | ||
33 | + res = a >= 0 ? INT16_MAX : INT16_MIN; | ||
34 | env->vxsat = 0x1; | ||
35 | } | ||
36 | return res; | ||
37 | @@ -XXX,XX +XXX,XX @@ static inline int32_t ssub32(CPURISCVState *env, int vxrm, int32_t a, int32_t b) | ||
38 | { | ||
39 | int32_t res = a - b; | ||
40 | if ((res ^ a) & (a ^ b) & INT32_MIN) { | ||
41 | - res = a > 0 ? INT32_MAX : INT32_MIN; | ||
42 | + res = a >= 0 ? INT32_MAX : INT32_MIN; | ||
43 | env->vxsat = 0x1; | ||
44 | } | ||
45 | return res; | ||
46 | @@ -XXX,XX +XXX,XX @@ static inline int64_t ssub64(CPURISCVState *env, int vxrm, int64_t a, int64_t b) | ||
47 | { | ||
48 | int64_t res = a - b; | ||
49 | if ((res ^ a) & (a ^ b) & INT64_MIN) { | ||
50 | - res = a > 0 ? INT64_MAX : INT64_MIN; | ||
51 | + res = a >= 0 ? INT64_MAX : INT64_MIN; | ||
52 | env->vxsat = 0x1; | ||
53 | } | ||
54 | return res; | ||
55 | -- | ||
56 | 2.31.1 | ||
57 | |||
58 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | This adds the documentation to describe what is supported for the | 3 | Add documentation for Shakti C reference platform. |
4 | 'microchip-icicle-kit' machine, and how to boot the machine in QEMU. | ||
5 | 4 | ||
6 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20210322075248.136255-2-bmeng.cn@gmail.com | 7 | Message-id: 20210412174248.8668-1-vijai@behindbytes.com |
8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | [ Changes from Bin Meng: | ||
10 | - Add missing TOC | ||
11 | Message-id: 20210430070534.1487242-1-bmeng.cn@gmail.com | ||
12 | ] | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 14 | --- |
11 | docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++++++++++ | 15 | docs/system/riscv/shakti-c.rst | 82 ++++++++++++++++++++++++++++++++++ |
12 | docs/system/target-riscv.rst | 1 + | 16 | docs/system/target-riscv.rst | 1 + |
13 | 2 files changed, 90 insertions(+) | 17 | 2 files changed, 83 insertions(+) |
14 | create mode 100644 docs/system/riscv/microchip-icicle-kit.rst | 18 | create mode 100644 docs/system/riscv/shakti-c.rst |
15 | 19 | ||
16 | diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst | 20 | diff --git a/docs/system/riscv/shakti-c.rst b/docs/system/riscv/shakti-c.rst |
17 | new file mode 100644 | 21 | new file mode 100644 |
18 | index XXXXXXX..XXXXXXX | 22 | index XXXXXXX..XXXXXXX |
19 | --- /dev/null | 23 | --- /dev/null |
20 | +++ b/docs/system/riscv/microchip-icicle-kit.rst | 24 | +++ b/docs/system/riscv/shakti-c.rst |
21 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ |
22 | +Microchip PolarFire SoC Icicle Kit (``microchip-icicle-kit``) | 26 | +Shakti C Reference Platform (``shakti_c``) |
23 | +============================================================= | 27 | +========================================== |
24 | + | 28 | + |
25 | +Microchip PolarFire SoC Icicle Kit integrates a PolarFire SoC, with one | 29 | +Shakti C Reference Platform is a reference platform based on arty a7 100t |
26 | +SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA. | 30 | +for the Shakti SoC. |
27 | + | 31 | + |
28 | +For more details about Microchip PolarFire SoC, please see: | 32 | +Shakti SoC is a SoC based on the Shakti C-class processor core. Shakti C |
29 | +https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga | 33 | +is a 64bit RV64GCSUN processor core. |
30 | + | 34 | + |
31 | +The Icicle Kit board information can be found here: | 35 | +For more details on Shakti SoC, please see: |
32 | +https://www.microsemi.com/existing-parts/parts/152514 | 36 | +https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/fpga/boards/artya7-100t/c-class/README.rst |
37 | + | ||
38 | +For more info on the Shakti C-class core, please see: | ||
39 | +https://c-class.readthedocs.io/en/latest/ | ||
33 | + | 40 | + |
34 | +Supported devices | 41 | +Supported devices |
35 | +----------------- | 42 | +----------------- |
36 | + | 43 | + |
37 | +The ``microchip-icicle-kit`` machine supports the following devices: | 44 | +The ``shakti_c`` machine supports the following devices: |
38 | + | 45 | + |
39 | + * 1 E51 core | 46 | + * 1 C-class core |
40 | + * 4 U54 cores | ||
41 | + * Core Level Interruptor (CLINT) | 47 | + * Core Level Interruptor (CLINT) |
42 | + * Platform-Level Interrupt Controller (PLIC) | 48 | + * Platform-Level Interrupt Controller (PLIC) |
43 | + * L2 Loosely Integrated Memory (L2-LIM) | 49 | + * 1 UART |
44 | + * DDR memory controller | ||
45 | + * 5 MMUARTs | ||
46 | + * 1 DMA controller | ||
47 | + * 2 GEM Ethernet controllers | ||
48 | + * 1 SDHC storage controller | ||
49 | + | 50 | + |
50 | +Boot options | 51 | +Boot options |
51 | +------------ | 52 | +------------ |
52 | + | 53 | + |
53 | +The ``microchip-icicle-kit`` machine can start using the standard -bios | 54 | +The ``shakti_c`` machine can start using the standard -bios |
54 | +functionality for loading its BIOS image, aka Hart Software Services (HSS_). | 55 | +functionality for loading the baremetal application or opensbi. |
55 | +HSS loads the second stage bootloader U-Boot from an SD card. It does not | ||
56 | +support direct kernel loading via the -kernel option. One has to load kernel | ||
57 | +from U-Boot. | ||
58 | + | ||
59 | +The memory is set to 1537 MiB by default which is the minimum required high | ||
60 | +memory size by HSS. A sanity check on ram size is performed in the machine | ||
61 | +init routine to prompt user to increase the RAM size to > 1537 MiB when less | ||
62 | +than 1537 MiB ram is detected. | ||
63 | + | 56 | + |
64 | +Boot the machine | 57 | +Boot the machine |
65 | +---------------- | 58 | +---------------- |
66 | + | 59 | + |
67 | +HSS 2020.12 release is tested at the time of writing. To build an HSS image | 60 | +Shakti SDK |
68 | +that can be booted by the ``microchip-icicle-kit`` machine, type the following | 61 | +~~~~~~~~~~ |
69 | +in the HSS source tree: | 62 | +Shakti SDK can be used to generate the baremetal example UART applications. |
70 | + | 63 | + |
71 | +.. code-block:: bash | 64 | +.. code-block:: bash |
72 | + | 65 | + |
73 | + $ export CROSS_COMPILE=riscv64-linux- | 66 | + $ git clone https://gitlab.com/behindbytes/shakti-sdk.git |
74 | + $ cp boards/mpfs-icicle-kit-es/def_config .config | 67 | + $ cd shakti-sdk |
75 | + $ make BOARD=mpfs-icicle-kit-es | 68 | + $ make software PROGRAM=loopback TARGET=artix7_100t |
76 | + | 69 | + |
77 | +Download the official SD card image released by Microchip and prepare it for | 70 | +Binary would be generated in: |
78 | +QEMU usage: | 71 | + software/examples/uart_applns/loopback/output/loopback.shakti |
72 | + | ||
73 | +You could also download the precompiled example applicatons using below | ||
74 | +commands. | ||
79 | + | 75 | + |
80 | +.. code-block:: bash | 76 | +.. code-block:: bash |
81 | + | 77 | + |
82 | + $ wget ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz | 78 | + $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/sdk/shakti_sdk_qemu.zip |
83 | + $ gunzip core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz | 79 | + $ unzip shakti_sdk_qemu.zip |
84 | + $ qemu-img resize core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic 4G | ||
85 | + | 80 | + |
86 | +Then we can boot the machine by: | 81 | +Then we can run the UART example using: |
87 | + | 82 | + |
88 | +.. code-block:: bash | 83 | +.. code-block:: bash |
89 | + | 84 | + |
90 | + $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \ | 85 | + $ qemu-system-riscv64 -M shakti_c -nographic \ |
91 | + -bios path/to/hss.bin -sd path/to/sdcard.img \ | 86 | + -bios path/to/shakti_sdk_qemu/loopback.shakti |
92 | + -nic user,model=cadence_gem \ | ||
93 | + -nic tap,ifname=tap,model=cadence_gem,script=no \ | ||
94 | + -display none -serial stdio \ | ||
95 | + -chardev socket,id=serial1,path=serial1.sock,server=on,wait=on \ | ||
96 | + -serial chardev:serial1 | ||
97 | + | 87 | + |
98 | +With above command line, current terminal session will be used for the first | 88 | +OpenSBI |
99 | +serial port. Open another terminal window, and use `minicom` to connect the | 89 | +~~~~~~~ |
100 | +second serial port. | 90 | +We can also run OpenSBI with Test Payload. |
101 | + | 91 | + |
102 | +.. code-block:: bash | 92 | +.. code-block:: bash |
103 | + | 93 | + |
104 | + $ minicom -D unix\#serial1.sock | 94 | + $ git clone https://github.com/riscv/opensbi.git -b v0.9 |
95 | + $ cd opensbi | ||
96 | + $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/dts/shakti.dtb | ||
97 | + $ export CROSS_COMPILE=riscv64-unknown-elf- | ||
98 | + $ export FW_FDT_PATH=./shakti.dtb | ||
99 | + $ make PLATFORM=generic | ||
105 | + | 100 | + |
106 | +HSS output is on the first serial port (stdio) and U-Boot outputs on the | 101 | +fw_payload.elf would be generated in build/platform/generic/firmware/fw_payload.elf. |
107 | +second serial port. U-Boot will automatically load the Linux kernel from | 102 | +Boot it using the below qemu command. |
108 | +the SD card image. | ||
109 | + | 103 | + |
110 | +.. _HSS: https://github.com/polarfire-soc/hart-software-services | 104 | +.. code-block:: bash |
105 | + | ||
106 | + $ qemu-system-riscv64 -M shakti_c -nographic \ | ||
107 | + -bios path/to/fw_payload.elf | ||
111 | diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst | 108 | diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst |
112 | index XXXXXXX..XXXXXXX 100644 | 109 | index XXXXXXX..XXXXXXX 100644 |
113 | --- a/docs/system/target-riscv.rst | 110 | --- a/docs/system/target-riscv.rst |
114 | +++ b/docs/system/target-riscv.rst | 111 | +++ b/docs/system/target-riscv.rst |
115 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | 112 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running |
116 | .. toctree:: | ||
117 | :maxdepth: 1 | 113 | :maxdepth: 1 |
118 | 114 | ||
119 | + riscv/microchip-icicle-kit | 115 | riscv/microchip-icicle-kit |
116 | + riscv/shakti-c | ||
120 | riscv/sifive_u | 117 | riscv/sifive_u |
121 | 118 | ||
122 | RISC-V CPU features | 119 | RISC-V CPU features |
123 | -- | 120 | -- |
124 | 2.30.1 | 121 | 2.31.1 |
125 | 122 | ||
126 | 123 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The RISC-V spec says: | ||
2 | if PMP entry i is locked and pmpicfg.A is set to TOR, writes to | ||
3 | pmpaddri-1 are ignored. | ||
1 | 4 | ||
5 | The current QEMU code ignores accesses to pmpaddri-1 and pmpcfgi-1 which | ||
6 | is incorrect. | ||
7 | |||
8 | Update the pmp_is_locked() function to not check the supporting fields | ||
9 | and instead enforce the lock functionality in the pmpaddr write operation. | ||
10 | |||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
13 | Message-id: 2831241458163f445a89bd59c59990247265b0c6.1618812899.git.alistair.francis@wdc.com | ||
14 | --- | ||
15 | target/riscv/pmp.c | 26 ++++++++++++++++---------- | ||
16 | 1 file changed, 16 insertions(+), 10 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/pmp.c | ||
21 | +++ b/target/riscv/pmp.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index) | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | - /* In TOR mode, need to check the lock bit of the next pmp | ||
27 | - * (if there is a next) | ||
28 | - */ | ||
29 | - const uint8_t a_field = | ||
30 | - pmp_get_a_field(env->pmp_state.pmp[pmp_index + 1].cfg_reg); | ||
31 | - if ((env->pmp_state.pmp[pmp_index + 1u].cfg_reg & PMP_LOCK) && | ||
32 | - (PMP_AMATCH_TOR == a_field)) { | ||
33 | - return 1; | ||
34 | - } | ||
35 | - | ||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | @@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | ||
40 | target_ulong val) | ||
41 | { | ||
42 | trace_pmpaddr_csr_write(env->mhartid, addr_index, val); | ||
43 | + | ||
44 | if (addr_index < MAX_RISCV_PMPS) { | ||
45 | + /* | ||
46 | + * In TOR mode, need to check the lock bit of the next pmp | ||
47 | + * (if there is a next). | ||
48 | + */ | ||
49 | + if (addr_index + 1 < MAX_RISCV_PMPS) { | ||
50 | + uint8_t pmp_cfg = env->pmp_state.pmp[addr_index + 1].cfg_reg; | ||
51 | + | ||
52 | + if (pmp_cfg & PMP_LOCK && | ||
53 | + PMP_AMATCH_TOR == pmp_get_a_field(pmp_cfg)) { | ||
54 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
55 | + "ignoring pmpaddr write - pmpcfg + 1 locked\n"); | ||
56 | + return; | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | if (!pmp_is_locked(env, addr_index)) { | ||
61 | env->pmp_state.pmp[addr_index].addr_reg = val; | ||
62 | pmp_update_rule(env, addr_index); | ||
63 | -- | ||
64 | 2.31.1 | ||
65 | |||
66 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Hou Weiying <weiying_hou@outlook.com> | ||
1 | 2 | ||
3 | Use address 0x390 and 0x391 for the ePMP CSRs. | ||
4 | |||
5 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> | ||
6 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> | ||
7 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: 63245b559f477a9ce6d4f930136d2d7fd7f99c78.1618812899.git.alistair.francis@wdc.com | ||
12 | [ Changes by AF: | ||
13 | - Tidy up commit message | ||
14 | ] | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
17 | --- | ||
18 | target/riscv/cpu_bits.h | 3 +++ | ||
19 | 1 file changed, 3 insertions(+) | ||
20 | |||
21 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu_bits.h | ||
24 | +++ b/target/riscv/cpu_bits.h | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | #define CSR_MTINST 0x34a | ||
27 | #define CSR_MTVAL2 0x34b | ||
28 | |||
29 | +/* Enhanced Physical Memory Protection (ePMP) */ | ||
30 | +#define CSR_MSECCFG 0x390 | ||
31 | +#define CSR_MSECCFGH 0x391 | ||
32 | /* Physical Memory Protection */ | ||
33 | #define CSR_PMPCFG0 0x3a0 | ||
34 | #define CSR_PMPCFG1 0x3a1 | ||
35 | -- | ||
36 | 2.31.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The spec is avaliable at: | ||
2 | https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8 | ||
1 | 3 | ||
4 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
6 | Message-id: 28c8855c80b0388a08c3ae009f5467e2b3960ce0.1618812899.git.alistair.francis@wdc.com | ||
7 | --- | ||
8 | target/riscv/cpu.h | 1 + | ||
9 | 1 file changed, 1 insertion(+) | ||
10 | |||
11 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/riscv/cpu.h | ||
14 | +++ b/target/riscv/cpu.h | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | enum { | ||
17 | RISCV_FEATURE_MMU, | ||
18 | RISCV_FEATURE_PMP, | ||
19 | + RISCV_FEATURE_EPMP, | ||
20 | RISCV_FEATURE_MISA | ||
21 | }; | ||
22 | |||
23 | -- | ||
24 | 2.31.1 | ||
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | 1 | From: Hou Weiying <weiying_hou@outlook.com> |
---|---|---|---|
2 | 2 | ||
3 | Currently, PMP permission checking of TLB page is bypassed if TLB hits | 3 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> |
4 | Fix it by propagating PMP permission to TLB page permission. | 4 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> |
5 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
8 | Message-id: 270762cb2507fba6a9eeb99a774cf49f7da9cc32.1618812899.git.alistair.francis@wdc.com | ||
9 | [ Changes by AF: | ||
10 | - Rebase on master | ||
11 | - Fix build errors | ||
12 | - Fix some style issues | ||
13 | ] | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
16 | --- | ||
17 | target/riscv/cpu.h | 1 + | ||
18 | target/riscv/pmp.h | 14 ++++++++++++++ | ||
19 | target/riscv/csr.c | 24 ++++++++++++++++++++++++ | ||
20 | target/riscv/pmp.c | 34 ++++++++++++++++++++++++++++++++++ | ||
21 | target/riscv/trace-events | 3 +++ | ||
22 | 5 files changed, 76 insertions(+) | ||
5 | 23 | ||
6 | PMP permission checking also use MMU-style API to change TLB permission | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
7 | and size. | 25 | index XXXXXXX..XXXXXXX 100644 |
8 | 26 | --- a/target/riscv/cpu.h | |
9 | Signed-off-by: Jim Shu <cwshu@andestech.com> | 27 | +++ b/target/riscv/cpu.h |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { |
11 | Message-id: 1613916082-19528-2-git-send-email-cwshu@andestech.com | 29 | |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 30 | /* physical memory protection */ |
13 | --- | 31 | pmp_table_t pmp_state; |
14 | target/riscv/pmp.h | 4 +- | 32 | + target_ulong mseccfg; |
15 | target/riscv/cpu_helper.c | 84 +++++++++++++++++++++++++++++---------- | 33 | |
16 | target/riscv/pmp.c | 80 +++++++++++++++++++++++++++---------- | 34 | /* machine specific rdtime callback */ |
17 | 3 files changed, 125 insertions(+), 43 deletions(-) | 35 | uint64_t (*rdtime_fn)(uint32_t); |
18 | |||
19 | diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h | 36 | diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h |
20 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/pmp.h | 38 | --- a/target/riscv/pmp.h |
22 | +++ b/target/riscv/pmp.h | 39 | +++ b/target/riscv/pmp.h |
23 | @@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | 40 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
41 | PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */ | ||
42 | } pmp_am_t; | ||
43 | |||
44 | +typedef enum { | ||
45 | + MSECCFG_MML = 1 << 0, | ||
46 | + MSECCFG_MMWP = 1 << 1, | ||
47 | + MSECCFG_RLB = 1 << 2 | ||
48 | +} mseccfg_field_t; | ||
49 | + | ||
50 | typedef struct { | ||
51 | target_ulong addr_reg; | ||
52 | uint8_t cfg_reg; | ||
53 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
54 | void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, | ||
55 | target_ulong val); | ||
56 | target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index); | ||
57 | + | ||
58 | +void mseccfg_csr_write(CPURISCVState *env, target_ulong val); | ||
59 | +target_ulong mseccfg_csr_read(CPURISCVState *env); | ||
60 | + | ||
61 | void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | ||
24 | target_ulong val); | 62 | target_ulong val); |
25 | target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); | 63 | target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); |
26 | bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | 64 | @@ -XXX,XX +XXX,XX @@ void pmp_update_rule_nums(CPURISCVState *env); |
27 | - target_ulong size, pmp_priv_t priv, target_ulong mode); | ||
28 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | ||
29 | + target_ulong mode); | ||
30 | bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, | ||
31 | target_ulong *tlb_size); | ||
32 | void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index); | ||
33 | void pmp_update_rule_nums(CPURISCVState *env); | ||
34 | uint32_t pmp_get_num_rules(CPURISCVState *env); | 65 | uint32_t pmp_get_num_rules(CPURISCVState *env); |
35 | +int pmp_priv_to_page_prot(pmp_priv_t pmp_priv); | 66 | int pmp_priv_to_page_prot(pmp_priv_t pmp_priv); |
36 | 67 | ||
68 | +#define MSECCFG_MML_ISSET(env) get_field(env->mseccfg, MSECCFG_MML) | ||
69 | +#define MSECCFG_MMWP_ISSET(env) get_field(env->mseccfg, MSECCFG_MMWP) | ||
70 | +#define MSECCFG_RLB_ISSET(env) get_field(env->mseccfg, MSECCFG_RLB) | ||
71 | + | ||
37 | #endif | 72 | #endif |
38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 73 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
39 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu_helper.c | 75 | --- a/target/riscv/csr.c |
41 | +++ b/target/riscv/cpu_helper.c | 76 | +++ b/target/riscv/csr.c |
42 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) | 77 | @@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno) |
43 | env->load_res = -1; | 78 | |
79 | return RISCV_EXCP_ILLEGAL_INST; | ||
44 | } | 80 | } |
45 | 81 | + | |
46 | +/* | 82 | +static RISCVException epmp(CPURISCVState *env, int csrno) |
47 | + * get_physical_address_pmp - check PMP permission for this physical address | ||
48 | + * | ||
49 | + * Match the PMP region and check permission for this physical address and it's | ||
50 | + * TLB page. Returns 0 if the permission checking was successful | ||
51 | + * | ||
52 | + * @env: CPURISCVState | ||
53 | + * @prot: The returned protection attributes | ||
54 | + * @tlb_size: TLB page size containing addr. It could be modified after PMP | ||
55 | + * permission checking. NULL if not set TLB page for addr. | ||
56 | + * @addr: The physical address to be checked permission | ||
57 | + * @access_type: The type of MMU access | ||
58 | + * @mode: Indicates current privilege level. | ||
59 | + */ | ||
60 | +static int get_physical_address_pmp(CPURISCVState *env, int *prot, | ||
61 | + target_ulong *tlb_size, hwaddr addr, | ||
62 | + int size, MMUAccessType access_type, | ||
63 | + int mode) | ||
64 | +{ | 83 | +{ |
65 | + pmp_priv_t pmp_priv; | 84 | + if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) { |
66 | + target_ulong tlb_size_pmp = 0; | 85 | + return RISCV_EXCP_NONE; |
67 | + | ||
68 | + if (!riscv_feature(env, RISCV_FEATURE_PMP)) { | ||
69 | + *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; | ||
70 | + return TRANSLATE_SUCCESS; | ||
71 | + } | 86 | + } |
72 | + | 87 | + |
73 | + if (!pmp_hart_has_privs(env, addr, size, 1 << access_type, &pmp_priv, | 88 | + return RISCV_EXCP_ILLEGAL_INST; |
74 | + mode)) { | 89 | +} |
75 | + *prot = 0; | 90 | #endif |
76 | + return TRANSLATE_PMP_FAIL; | 91 | |
77 | + } | 92 | /* User Floating-Point CSRs */ |
78 | + | 93 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mtinst(CPURISCVState *env, int csrno, |
79 | + *prot = pmp_priv_to_page_prot(pmp_priv); | 94 | } |
80 | + if (tlb_size != NULL) { | 95 | |
81 | + if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) { | 96 | /* Physical Memory Protection */ |
82 | + *tlb_size = tlb_size_pmp; | 97 | +static RISCVException read_mseccfg(CPURISCVState *env, int csrno, |
83 | + } | 98 | + target_ulong *val) |
84 | + } | 99 | +{ |
85 | + | 100 | + *val = mseccfg_csr_read(env); |
86 | + return TRANSLATE_SUCCESS; | 101 | + return RISCV_EXCP_NONE; |
87 | +} | 102 | +} |
88 | + | 103 | + |
89 | /* get_physical_address - get the physical address for this virtual address | 104 | +static RISCVException write_mseccfg(CPURISCVState *env, int csrno, |
90 | * | 105 | + target_ulong val) |
91 | * Do a page table walk to obtain the physical address corresponding to a | 106 | +{ |
92 | @@ -XXX,XX +XXX,XX @@ restart: | 107 | + mseccfg_csr_write(env, val); |
93 | pte_addr = base + idx * ptesize; | 108 | + return RISCV_EXCP_NONE; |
94 | } | 109 | +} |
95 | |||
96 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
97 | - !pmp_hart_has_privs(env, pte_addr, sizeof(target_ulong), | ||
98 | - 1 << MMU_DATA_LOAD, PRV_S)) { | ||
99 | + int pmp_prot; | ||
100 | + int pmp_ret = get_physical_address_pmp(env, &pmp_prot, NULL, pte_addr, | ||
101 | + sizeof(target_ulong), | ||
102 | + MMU_DATA_LOAD, PRV_S); | ||
103 | + if (pmp_ret != TRANSLATE_SUCCESS) { | ||
104 | return TRANSLATE_PMP_FAIL; | ||
105 | } | ||
106 | |||
107 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
108 | #ifndef CONFIG_USER_ONLY | ||
109 | vaddr im_address; | ||
110 | hwaddr pa = 0; | ||
111 | - int prot, prot2; | ||
112 | + int prot, prot2, prot_pmp; | ||
113 | bool pmp_violation = false; | ||
114 | bool first_stage_error = true; | ||
115 | bool two_stage_lookup = false; | ||
116 | int ret = TRANSLATE_FAIL; | ||
117 | int mode = mmu_idx; | ||
118 | - target_ulong tlb_size = 0; | ||
119 | + /* default TLB page size */ | ||
120 | + target_ulong tlb_size = TARGET_PAGE_SIZE; | ||
121 | |||
122 | env->guest_phys_fault_addr = 0; | ||
123 | |||
124 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
125 | |||
126 | prot &= prot2; | ||
127 | |||
128 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
129 | - (ret == TRANSLATE_SUCCESS) && | ||
130 | - !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { | ||
131 | - ret = TRANSLATE_PMP_FAIL; | ||
132 | + if (ret == TRANSLATE_SUCCESS) { | ||
133 | + ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | ||
134 | + size, access_type, mode); | ||
135 | + prot &= prot_pmp; | ||
136 | } | ||
137 | |||
138 | if (ret != TRANSLATE_SUCCESS) { | ||
139 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
140 | "%s address=%" VADDR_PRIx " ret %d physical " | ||
141 | TARGET_FMT_plx " prot %d\n", | ||
142 | __func__, address, ret, pa, prot); | ||
143 | - } | ||
144 | |||
145 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
146 | - (ret == TRANSLATE_SUCCESS) && | ||
147 | - !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { | ||
148 | - ret = TRANSLATE_PMP_FAIL; | ||
149 | + if (ret == TRANSLATE_SUCCESS) { | ||
150 | + ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | ||
151 | + size, access_type, mode); | ||
152 | + prot &= prot_pmp; | ||
153 | + } | ||
154 | } | ||
155 | + | 110 | + |
156 | if (ret == TRANSLATE_PMP_FAIL) { | 111 | static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, |
157 | pmp_violation = true; | 112 | target_ulong *val) |
158 | } | 113 | { |
159 | 114 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | |
160 | if (ret == TRANSLATE_SUCCESS) { | 115 | [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, |
161 | - if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) { | 116 | |
162 | - tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1), | 117 | /* Physical Memory Protection */ |
163 | - prot, mmu_idx, tlb_size); | 118 | + [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg }, |
164 | - } else { | 119 | [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, |
165 | - tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, | 120 | [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, |
166 | - prot, mmu_idx, TARGET_PAGE_SIZE); | 121 | [CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, |
167 | - } | ||
168 | + tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1), | ||
169 | + prot, mmu_idx, tlb_size); | ||
170 | return true; | ||
171 | } else if (probe) { | ||
172 | return false; | ||
173 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | 122 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
174 | index XXXXXXX..XXXXXXX 100644 | 123 | index XXXXXXX..XXXXXXX 100644 |
175 | --- a/target/riscv/pmp.c | 124 | --- a/target/riscv/pmp.c |
176 | +++ b/target/riscv/pmp.c | 125 | +++ b/target/riscv/pmp.c |
177 | @@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr) | 126 | @@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) |
178 | return result; | 127 | return val; |
179 | } | 128 | } |
180 | 129 | ||
181 | +/* | 130 | +/* |
182 | + * Check if the address has required RWX privs when no PMP entry is matched. | 131 | + * Handle a write to a mseccfg CSR |
183 | + */ | 132 | + */ |
184 | +static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, | 133 | +void mseccfg_csr_write(CPURISCVState *env, target_ulong val) |
185 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | ||
186 | + target_ulong mode) | ||
187 | +{ | 134 | +{ |
188 | + bool ret; | 135 | + int i; |
189 | + | 136 | + |
190 | + if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) { | 137 | + trace_mseccfg_csr_write(env->mhartid, val); |
191 | + /* | 138 | + |
192 | + * Privileged spec v1.10 states if HW doesn't implement any PMP entry | 139 | + /* RLB cannot be enabled if it's already 0 and if any regions are locked */ |
193 | + * or no PMP entry matches an M-Mode access, the access succeeds. | 140 | + if (!MSECCFG_RLB_ISSET(env)) { |
194 | + */ | 141 | + for (i = 0; i < MAX_RISCV_PMPS; i++) { |
195 | + ret = true; | 142 | + if (pmp_is_locked(env, i)) { |
196 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | 143 | + val &= ~MSECCFG_RLB; |
197 | + } else { | 144 | + break; |
198 | + /* | 145 | + } |
199 | + * Other modes are not allowed to succeed if they don't * match a rule, | 146 | + } |
200 | + * but there are rules. We've checked for no rule earlier in this | ||
201 | + * function. | ||
202 | + */ | ||
203 | + ret = false; | ||
204 | + *allowed_privs = 0; | ||
205 | + } | 147 | + } |
206 | + | 148 | + |
207 | + return ret; | 149 | + /* Sticky bits */ |
150 | + val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML)); | ||
151 | + | ||
152 | + env->mseccfg = val; | ||
208 | +} | 153 | +} |
209 | + | 154 | + |
210 | 155 | +/* | |
156 | + * Handle a read from a mseccfg CSR | ||
157 | + */ | ||
158 | +target_ulong mseccfg_csr_read(CPURISCVState *env) | ||
159 | +{ | ||
160 | + trace_mseccfg_csr_read(env->mhartid, env->mseccfg); | ||
161 | + return env->mseccfg; | ||
162 | +} | ||
163 | + | ||
211 | /* | 164 | /* |
212 | * Public Interface | 165 | * Calculate the TLB size if the start address or the end address of |
213 | @@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr) | 166 | * PMP entry is presented in thie TLB page. |
214 | * Check if the address has required RWX privs to complete desired operation | 167 | diff --git a/target/riscv/trace-events b/target/riscv/trace-events |
215 | */ | 168 | index XXXXXXX..XXXXXXX 100644 |
216 | bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | 169 | --- a/target/riscv/trace-events |
217 | - target_ulong size, pmp_priv_t privs, target_ulong mode) | 170 | +++ b/target/riscv/trace-events |
218 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | 171 | @@ -XXX,XX +XXX,XX @@ pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRI |
219 | + target_ulong mode) | 172 | pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64 |
220 | { | 173 | pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64 |
221 | int i = 0; | 174 | pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64 |
222 | int ret = -1; | ||
223 | int pmp_size = 0; | ||
224 | target_ulong s = 0; | ||
225 | target_ulong e = 0; | ||
226 | - pmp_priv_t allowed_privs = 0; | ||
227 | |||
228 | /* Short cut if no rules */ | ||
229 | if (0 == pmp_get_num_rules(env)) { | ||
230 | - return (env->priv == PRV_M) ? true : false; | ||
231 | + return pmp_hart_has_privs_default(env, addr, size, privs, | ||
232 | + allowed_privs, mode); | ||
233 | } | ||
234 | |||
235 | if (size == 0) { | ||
236 | @@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | ||
237 | * check | ||
238 | */ | ||
239 | if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) { | ||
240 | - allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
241 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
242 | if ((mode != PRV_M) || pmp_is_locked(env, i)) { | ||
243 | - allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
244 | + *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
245 | } | ||
246 | |||
247 | - if ((privs & allowed_privs) == privs) { | ||
248 | - ret = 1; | ||
249 | - break; | ||
250 | - } else { | ||
251 | - ret = 0; | ||
252 | - break; | ||
253 | - } | ||
254 | + ret = ((privs & *allowed_privs) == privs); | ||
255 | + break; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | /* No rule matched */ | ||
260 | if (ret == -1) { | ||
261 | - if (mode == PRV_M) { | ||
262 | - ret = 1; /* Privileged spec v1.10 states if no PMP entry matches an | ||
263 | - * M-Mode access, the access succeeds */ | ||
264 | - } else { | ||
265 | - ret = 0; /* Other modes are not allowed to succeed if they don't | ||
266 | - * match a rule, but there are rules. We've checked for | ||
267 | - * no rule earlier in this function. */ | ||
268 | - } | ||
269 | + return pmp_hart_has_privs_default(env, addr, size, privs, | ||
270 | + allowed_privs, mode); | ||
271 | } | ||
272 | |||
273 | return ret == 1 ? true : false; | ||
274 | } | ||
275 | |||
276 | - | ||
277 | /* | ||
278 | * Handle a write to a pmpcfg CSP | ||
279 | */ | ||
280 | @@ -XXX,XX +XXX,XX @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, | ||
281 | |||
282 | return false; | ||
283 | } | ||
284 | + | 175 | + |
285 | +/* | 176 | +mseccfg_csr_read(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": read mseccfg, val: 0x%" PRIx64 |
286 | + * Convert PMP privilege to TLB page privilege. | 177 | +mseccfg_csr_write(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": write mseccfg, val: 0x%" PRIx64 |
287 | + */ | ||
288 | +int pmp_priv_to_page_prot(pmp_priv_t pmp_priv) | ||
289 | +{ | ||
290 | + int prot = 0; | ||
291 | + | ||
292 | + if (pmp_priv & PMP_READ) { | ||
293 | + prot |= PAGE_READ; | ||
294 | + } | ||
295 | + if (pmp_priv & PMP_WRITE) { | ||
296 | + prot |= PAGE_WRITE; | ||
297 | + } | ||
298 | + if (pmp_priv & PMP_EXEC) { | ||
299 | + prot |= PAGE_EXEC; | ||
300 | + } | ||
301 | + | ||
302 | + return prot; | ||
303 | +} | ||
304 | -- | 178 | -- |
305 | 2.30.1 | 179 | 2.31.1 |
306 | 180 | ||
307 | 181 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Hou Weiying <weiying_hou@outlook.com> | |
2 | |||
3 | This commit adds support for ePMP v0.9.1. | ||
4 | |||
5 | The ePMP spec can be found in: | ||
6 | https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8 | ||
7 | |||
8 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> | ||
9 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> | ||
10 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
13 | Message-id: fef23b885f9649a4d54e7c98b168bdec5d297bb1.1618812899.git.alistair.francis@wdc.com | ||
14 | [ Changes by AF: | ||
15 | - Rebase on master | ||
16 | - Update to latest spec | ||
17 | - Use a switch case to handle ePMP MML permissions | ||
18 | - Fix a few bugs | ||
19 | ] | ||
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | --- | ||
22 | target/riscv/pmp.c | 154 ++++++++++++++++++++++++++++++++++++++++++--- | ||
23 | 1 file changed, 146 insertions(+), 8 deletions(-) | ||
24 | |||
25 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/riscv/pmp.c | ||
28 | +++ b/target/riscv/pmp.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index) | ||
30 | static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) | ||
31 | { | ||
32 | if (pmp_index < MAX_RISCV_PMPS) { | ||
33 | - if (!pmp_is_locked(env, pmp_index)) { | ||
34 | - env->pmp_state.pmp[pmp_index].cfg_reg = val; | ||
35 | - pmp_update_rule(env, pmp_index); | ||
36 | + bool locked = true; | ||
37 | + | ||
38 | + if (riscv_feature(env, RISCV_FEATURE_EPMP)) { | ||
39 | + /* mseccfg.RLB is set */ | ||
40 | + if (MSECCFG_RLB_ISSET(env)) { | ||
41 | + locked = false; | ||
42 | + } | ||
43 | + | ||
44 | + /* mseccfg.MML is not set */ | ||
45 | + if (!MSECCFG_MML_ISSET(env) && !pmp_is_locked(env, pmp_index)) { | ||
46 | + locked = false; | ||
47 | + } | ||
48 | + | ||
49 | + /* mseccfg.MML is set */ | ||
50 | + if (MSECCFG_MML_ISSET(env)) { | ||
51 | + /* not adding execute bit */ | ||
52 | + if ((val & PMP_LOCK) != 0 && (val & PMP_EXEC) != PMP_EXEC) { | ||
53 | + locked = false; | ||
54 | + } | ||
55 | + /* shared region and not adding X bit */ | ||
56 | + if ((val & PMP_LOCK) != PMP_LOCK && | ||
57 | + (val & 0x7) != (PMP_WRITE | PMP_EXEC)) { | ||
58 | + locked = false; | ||
59 | + } | ||
60 | + } | ||
61 | } else { | ||
62 | + if (!pmp_is_locked(env, pmp_index)) { | ||
63 | + locked = false; | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + if (locked) { | ||
68 | qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n"); | ||
69 | + } else { | ||
70 | + env->pmp_state.pmp[pmp_index].cfg_reg = val; | ||
71 | + pmp_update_rule(env, pmp_index); | ||
72 | } | ||
73 | } else { | ||
74 | qemu_log_mask(LOG_GUEST_ERROR, | ||
75 | @@ -XXX,XX +XXX,XX @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, | ||
76 | { | ||
77 | bool ret; | ||
78 | |||
79 | + if (riscv_feature(env, RISCV_FEATURE_EPMP)) { | ||
80 | + if (MSECCFG_MMWP_ISSET(env)) { | ||
81 | + /* | ||
82 | + * The Machine Mode Whitelist Policy (mseccfg.MMWP) is set | ||
83 | + * so we default to deny all, even for M-mode. | ||
84 | + */ | ||
85 | + *allowed_privs = 0; | ||
86 | + return false; | ||
87 | + } else if (MSECCFG_MML_ISSET(env)) { | ||
88 | + /* | ||
89 | + * The Machine Mode Lockdown (mseccfg.MML) bit is set | ||
90 | + * so we can only execute code in M-mode with an applicable | ||
91 | + * rule. Other modes are disabled. | ||
92 | + */ | ||
93 | + if (mode == PRV_M && !(privs & PMP_EXEC)) { | ||
94 | + ret = true; | ||
95 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
96 | + } else { | ||
97 | + ret = false; | ||
98 | + *allowed_privs = 0; | ||
99 | + } | ||
100 | + | ||
101 | + return ret; | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) { | ||
106 | /* | ||
107 | * Privileged spec v1.10 states if HW doesn't implement any PMP entry | ||
108 | @@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | ||
109 | pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg); | ||
110 | |||
111 | /* | ||
112 | - * If the PMP entry is not off and the address is in range, do the priv | ||
113 | - * check | ||
114 | + * Convert the PMP permissions to match the truth table in the | ||
115 | + * ePMP spec. | ||
116 | */ | ||
117 | + const uint8_t epmp_operation = | ||
118 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_LOCK) >> 4) | | ||
119 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_READ) << 2) | | ||
120 | + (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) | | ||
121 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2); | ||
122 | + | ||
123 | if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) { | ||
124 | - *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
125 | - if ((mode != PRV_M) || pmp_is_locked(env, i)) { | ||
126 | - *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
127 | + /* | ||
128 | + * If the PMP entry is not off and the address is in range, | ||
129 | + * do the priv check | ||
130 | + */ | ||
131 | + if (!MSECCFG_MML_ISSET(env)) { | ||
132 | + /* | ||
133 | + * If mseccfg.MML Bit is not set, do pmp priv check | ||
134 | + * This will always apply to regular PMP. | ||
135 | + */ | ||
136 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
137 | + if ((mode != PRV_M) || pmp_is_locked(env, i)) { | ||
138 | + *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
139 | + } | ||
140 | + } else { | ||
141 | + /* | ||
142 | + * If mseccfg.MML Bit set, do the enhanced pmp priv check | ||
143 | + */ | ||
144 | + if (mode == PRV_M) { | ||
145 | + switch (epmp_operation) { | ||
146 | + case 0: | ||
147 | + case 1: | ||
148 | + case 4: | ||
149 | + case 5: | ||
150 | + case 6: | ||
151 | + case 7: | ||
152 | + case 8: | ||
153 | + *allowed_privs = 0; | ||
154 | + break; | ||
155 | + case 2: | ||
156 | + case 3: | ||
157 | + case 14: | ||
158 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
159 | + break; | ||
160 | + case 9: | ||
161 | + case 10: | ||
162 | + *allowed_privs = PMP_EXEC; | ||
163 | + break; | ||
164 | + case 11: | ||
165 | + case 13: | ||
166 | + *allowed_privs = PMP_READ | PMP_EXEC; | ||
167 | + break; | ||
168 | + case 12: | ||
169 | + case 15: | ||
170 | + *allowed_privs = PMP_READ; | ||
171 | + break; | ||
172 | + } | ||
173 | + } else { | ||
174 | + switch (epmp_operation) { | ||
175 | + case 0: | ||
176 | + case 8: | ||
177 | + case 9: | ||
178 | + case 12: | ||
179 | + case 13: | ||
180 | + case 14: | ||
181 | + *allowed_privs = 0; | ||
182 | + break; | ||
183 | + case 1: | ||
184 | + case 10: | ||
185 | + case 11: | ||
186 | + *allowed_privs = PMP_EXEC; | ||
187 | + break; | ||
188 | + case 2: | ||
189 | + case 4: | ||
190 | + case 15: | ||
191 | + *allowed_privs = PMP_READ; | ||
192 | + break; | ||
193 | + case 3: | ||
194 | + case 6: | ||
195 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
196 | + break; | ||
197 | + case 5: | ||
198 | + *allowed_privs = PMP_READ | PMP_EXEC; | ||
199 | + break; | ||
200 | + case 7: | ||
201 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
202 | + break; | ||
203 | + } | ||
204 | + } | ||
205 | } | ||
206 | |||
207 | ret = ((privs & *allowed_privs) == privs); | ||
208 | -- | ||
209 | 2.31.1 | ||
210 | |||
211 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Hou Weiying <weiying_hou@outlook.com> | ||
1 | 2 | ||
3 | Add a config option to enable experimental support for ePMP. This | ||
4 | is disabled by default and can be enabled with 'x-epmp=true'. | ||
5 | |||
6 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> | ||
7 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> | ||
8 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: a22ccdaf9314078bc735d3b323f966623f8af020.1618812899.git.alistair.francis@wdc.com | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | --- | ||
15 | target/riscv/cpu.h | 1 + | ||
16 | target/riscv/cpu.c | 10 ++++++++++ | ||
17 | 2 files changed, 11 insertions(+) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
24 | uint16_t elen; | ||
25 | bool mmu; | ||
26 | bool pmp; | ||
27 | + bool epmp; | ||
28 | uint64_t resetvec; | ||
29 | } cfg; | ||
30 | }; | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
36 | |||
37 | if (cpu->cfg.pmp) { | ||
38 | set_feature(env, RISCV_FEATURE_PMP); | ||
39 | + | ||
40 | + /* | ||
41 | + * Enhanced PMP should only be available | ||
42 | + * on harts with PMP support | ||
43 | + */ | ||
44 | + if (cpu->cfg.epmp) { | ||
45 | + set_feature(env, RISCV_FEATURE_EPMP); | ||
46 | + } | ||
47 | } | ||
48 | |||
49 | set_resetvec(env, cpu->cfg.resetvec); | ||
50 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | ||
51 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | ||
52 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | ||
53 | DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | ||
54 | + DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), | ||
55 | + | ||
56 | DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), | ||
57 | DEFINE_PROP_END_OF_LIST(), | ||
58 | }; | ||
59 | -- | ||
60 | 2.31.1 | ||
61 | |||
62 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | ||
---|---|---|---|
2 | |||
3 | If PMP permission of any address has been changed by updating PMP entry, | ||
4 | flush all TLB pages to prevent from getting old permission. | ||
5 | |||
6 | Signed-off-by: Jim Shu <cwshu@andestech.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 1613916082-19528-4-git-send-email-cwshu@andestech.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
2 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
3 | Message-id: 10387eec21d2f17c499a78fdba85280cab4dd27f.1618812899.git.alistair.francis@wdc.com | ||
10 | --- | 4 | --- |
11 | target/riscv/pmp.c | 4 ++++ | 5 | target/riscv/pmp.c | 4 ---- |
12 | 1 file changed, 4 insertions(+) | 6 | 1 file changed, 4 deletions(-) |
13 | 7 | ||
14 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | 8 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
15 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/pmp.c | 10 | --- a/target/riscv/pmp.c |
17 | +++ b/target/riscv/pmp.c | 11 | +++ b/target/riscv/pmp.c |
18 | @@ -XXX,XX +XXX,XX @@ | 12 | @@ -XXX,XX +XXX,XX @@ |
13 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
14 | */ | ||
15 | |||
16 | -/* | ||
17 | - * PMP (Physical Memory Protection) is as-of-yet unused and needs testing. | ||
18 | - */ | ||
19 | - | ||
20 | #include "qemu/osdep.h" | ||
21 | #include "qemu/log.h" | ||
19 | #include "qapi/error.h" | 22 | #include "qapi/error.h" |
20 | #include "cpu.h" | ||
21 | #include "trace.h" | ||
22 | +#include "exec/exec-all.h" | ||
23 | |||
24 | static void pmp_write_cfg(CPURISCVState *env, uint32_t addr_index, | ||
25 | uint8_t val); | ||
26 | @@ -XXX,XX +XXX,XX @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, | ||
27 | cfg_val = (val >> 8 * i) & 0xff; | ||
28 | pmp_write_cfg(env, (reg_index * 4) + i, cfg_val); | ||
29 | } | ||
30 | + | ||
31 | + /* If PMP permission of any addr has been changed, flush TLB pages. */ | ||
32 | + tlb_flush(env_cpu(env)); | ||
33 | } | ||
34 | |||
35 | |||
36 | -- | 23 | -- |
37 | 2.30.1 | 24 | 2.31.1 |
38 | 25 | ||
39 | 26 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The physical Ibex CPU has ePMP support and it's enabled for the | ||
2 | OpenTitan machine so let's enable ePMP support for the Ibex CPU in QEMU. | ||
1 | 3 | ||
4 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
6 | Message-id: d426baabab0c9361ed2e989dbe416e417a551fd1.1618812899.git.alistair.francis@wdc.com | ||
7 | --- | ||
8 | target/riscv/cpu.c | 1 + | ||
9 | 1 file changed, 1 insertion(+) | ||
10 | |||
11 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/riscv/cpu.c | ||
14 | +++ b/target/riscv/cpu.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj) | ||
16 | set_misa(env, RV32 | RVI | RVM | RVC | RVU); | ||
17 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
18 | qdev_prop_set_bit(DEVICE(obj), "mmu", false); | ||
19 | + qdev_prop_set_bit(DEVICE(obj), "x-epmp", true); | ||
20 | } | ||
21 | |||
22 | static void rv32_imafcu_nommu_cpu_init(Object *obj) | ||
23 | -- | ||
24 | 2.31.1 | ||
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Since HSS commit c20a89f8dcac, the Icicle Kit reference design has | 3 | ETYPE may be type of uint64_t, thus index variable has to be declared as |
4 | been updated to use a register mapped at 0x4f000000 instead of a | 4 | type of uint64_t, too. Otherwise the value read from vs1 register may be |
5 | GPIO to control whether eMMC or SD card is to be used. With this | 5 | truncated to type of uint32_t. |
6 | support the same HSS image can be used for both eMMC and SD card | ||
7 | boot flow, while previously two different board configurations were | ||
8 | used. This is undocumented but one can take a look at the HSS code | ||
9 | HSS_MMCInit() in services/mmc/mmc_api.c. | ||
10 | 6 | ||
11 | With this commit, HSS image built from 2020.12 release boots again. | 7 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
12 | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | |
13 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 9 | Message-id: 20210419060302.14075-1-frank.chang@sifive.com |
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Message-id: 20210322075248.136255-1-bmeng.cn@gmail.com | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 11 | --- |
18 | include/hw/riscv/microchip_pfsoc.h | 1 + | 12 | target/riscv/vector_helper.c | 6 ++++-- |
19 | hw/riscv/microchip_pfsoc.c | 6 ++++++ | 13 | 1 file changed, 4 insertions(+), 2 deletions(-) |
20 | 2 files changed, 7 insertions(+) | ||
21 | 14 | ||
22 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 15 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
23 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/riscv/microchip_pfsoc.h | 17 | --- a/target/riscv/vector_helper.c |
25 | +++ b/include/hw/riscv/microchip_pfsoc.h | 18 | +++ b/target/riscv/vector_helper.c |
26 | @@ -XXX,XX +XXX,XX @@ enum { | 19 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \ |
27 | MICROCHIP_PFSOC_ENVM_DATA, | 20 | uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \ |
28 | MICROCHIP_PFSOC_QSPI_XIP, | 21 | uint32_t vm = vext_vm(desc); \ |
29 | MICROCHIP_PFSOC_IOSCB, | 22 | uint32_t vl = env->vl; \ |
30 | + MICROCHIP_PFSOC_EMMC_SD_MUX, | 23 | - uint32_t index, i; \ |
31 | MICROCHIP_PFSOC_DRAM_LO, | 24 | + uint64_t index; \ |
32 | MICROCHIP_PFSOC_DRAM_LO_ALIAS, | 25 | + uint32_t i; \ |
33 | MICROCHIP_PFSOC_DRAM_HI, | 26 | \ |
34 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 27 | for (i = 0; i < vl; i++) { \ |
35 | index XXXXXXX..XXXXXXX 100644 | 28 | if (!vm && !vext_elem_mask(v0, mlen, i)) { \ |
36 | --- a/hw/riscv/microchip_pfsoc.c | 29 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \ |
37 | +++ b/hw/riscv/microchip_pfsoc.c | 30 | uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \ |
38 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry microchip_pfsoc_memmap[] = { | 31 | uint32_t vm = vext_vm(desc); \ |
39 | [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | 32 | uint32_t vl = env->vl; \ |
40 | [MICROCHIP_PFSOC_QSPI_XIP] = { 0x21000000, 0x1000000 }, | 33 | - uint32_t index = s1, i; \ |
41 | [MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 }, | 34 | + uint64_t index = s1; \ |
42 | + [MICROCHIP_PFSOC_EMMC_SD_MUX] = { 0x4f000000, 0x4 }, | 35 | + uint32_t i; \ |
43 | [MICROCHIP_PFSOC_DRAM_LO] = { 0x80000000, 0x40000000 }, | 36 | \ |
44 | [MICROCHIP_PFSOC_DRAM_LO_ALIAS] = { 0xc0000000, 0x40000000 }, | 37 | for (i = 0; i < vl; i++) { \ |
45 | [MICROCHIP_PFSOC_DRAM_HI] = { 0x1000000000, 0x0 }, | 38 | if (!vm && !vext_elem_mask(v0, mlen, i)) { \ |
46 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
47 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->ioscb), 0, | ||
48 | memmap[MICROCHIP_PFSOC_IOSCB].base); | ||
49 | |||
50 | + /* eMMC/SD mux */ | ||
51 | + create_unimplemented_device("microchip.pfsoc.emmc_sd_mux", | ||
52 | + memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].base, | ||
53 | + memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].size); | ||
54 | + | ||
55 | /* QSPI Flash */ | ||
56 | memory_region_init_rom(qspi_xip_mem, OBJECT(dev), | ||
57 | "microchip.pfsoc.qspi_xip", | ||
58 | -- | 39 | -- |
59 | 2.30.1 | 40 | 2.31.1 |
60 | 41 | ||
61 | 42 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Emmanuel Blot <emmanuel.blot@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The current condition for the use of background registers only | 3 | When no MMU is used and the guest code attempts to fetch an instruction |
4 | considers the hypervisor load and store instructions, | 4 | from an invalid memory location, the exception index defaults to a data |
5 | but not accesses from M mode via MSTATUS_MPRV+MPV. | 5 | load access fault, rather an instruction access fault. |
6 | 6 | ||
7 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 7 | Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210311103036.1401073-1-georg.kotheimer@kernkonzept.com | 9 | Message-id: FB9EA197-B018-4879-AB0F-922C2047A08B@sifive.com |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | target/riscv/cpu_helper.c | 2 +- | 12 | target/riscv/cpu_helper.c | 4 +++- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | 1 file changed, 3 insertions(+), 1 deletion(-) |
14 | 14 | ||
15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu_helper.c | 17 | --- a/target/riscv/cpu_helper.c |
18 | +++ b/target/riscv/cpu_helper.c | 18 | +++ b/target/riscv/cpu_helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 19 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, |
20 | * was called. Background registers will be used if the guest has | 20 | |
21 | * forced a two stage translation to be on (in HS or M mode). | 21 | if (access_type == MMU_DATA_STORE) { |
22 | */ | 22 | cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; |
23 | - if (!riscv_cpu_virt_enabled(env) && riscv_cpu_two_stage_lookup(mmu_idx)) { | 23 | - } else { |
24 | + if (!riscv_cpu_virt_enabled(env) && two_stage) { | 24 | + } else if (access_type == MMU_DATA_LOAD) { |
25 | use_background = true; | 25 | cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; |
26 | + } else { | ||
27 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; | ||
26 | } | 28 | } |
27 | 29 | ||
30 | env->badaddr = addr; | ||
28 | -- | 31 | -- |
29 | 2.30.1 | 32 | 2.31.1 |
30 | 33 | ||
31 | 34 | diff view generated by jsdifflib |
1 | From: Alexander Wagner <alexander.wagner@ulal.de> | 1 | From: Alexander Wagner <alexander.wagner@ulal.de> |
---|---|---|---|
2 | 2 | ||
3 | Not disabling the UART leads to QEMU overwriting the UART receive buffer with | 3 | The IBEX documentation [1] specifies the reset vector to be "the most |
4 | the newest received byte. The rx_level variable is added to allow the use of | 4 | significant 3 bytes of the boot address and the reset value (0x80) as |
5 | the existing OpenTitan driver libraries. | 5 | the least significant byte". |
6 | |||
7 | [1] https://github.com/lowRISC/ibex/blob/master/doc/03_reference/exception_interrupts.rst | ||
6 | 8 | ||
7 | Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de> | 9 | Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210309152130.13038-1-alexander.wagner@ulal.de | 11 | Message-id: 20210420080008.119798-1-alexander.wagner@ulal.de |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 13 | --- |
12 | include/hw/char/ibex_uart.h | 4 ++++ | 14 | hw/riscv/opentitan.c | 2 +- |
13 | hw/char/ibex_uart.c | 23 ++++++++++++++++++----- | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 2 files changed, 22 insertions(+), 5 deletions(-) | ||
15 | 16 | ||
16 | diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h | 17 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/include/hw/char/ibex_uart.h | 19 | --- a/hw/riscv/opentitan.c |
19 | +++ b/include/hw/char/ibex_uart.h | 20 | +++ b/hw/riscv/opentitan.c |
20 | @@ -XXX,XX +XXX,XX @@ REG32(FIFO_CTRL, 0x1c) | 21 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) |
21 | FIELD(FIFO_CTRL, RXILVL, 2, 3) | 22 | &error_abort); |
22 | FIELD(FIFO_CTRL, TXILVL, 5, 2) | 23 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, |
23 | REG32(FIFO_STATUS, 0x20) | 24 | &error_abort); |
24 | + FIELD(FIFO_STATUS, TXLVL, 0, 5) | 25 | - object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort); |
25 | + FIELD(FIFO_STATUS, RXLVL, 16, 5) | 26 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort); |
26 | REG32(OVRD, 0x24) | 27 | sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); |
27 | REG32(VAL, 0x28) | 28 | |
28 | REG32(TIMEOUT_CTRL, 0x2c) | 29 | /* Boot ROM */ |
29 | @@ -XXX,XX +XXX,XX @@ struct IbexUartState { | ||
30 | uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE]; | ||
31 | uint32_t tx_level; | ||
32 | |||
33 | + uint32_t rx_level; | ||
34 | + | ||
35 | QEMUTimer *fifo_trigger_handle; | ||
36 | uint64_t char_tx_time; | ||
37 | |||
38 | diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/hw/char/ibex_uart.c | ||
41 | +++ b/hw/char/ibex_uart.c | ||
42 | @@ -XXX,XX +XXX,XX @@ static int ibex_uart_can_receive(void *opaque) | ||
43 | { | ||
44 | IbexUartState *s = opaque; | ||
45 | |||
46 | - if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) { | ||
47 | + if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) | ||
48 | + && !(s->uart_status & R_STATUS_RXFULL_MASK)) { | ||
49 | return 1; | ||
50 | } | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size) | ||
53 | |||
54 | s->uart_status &= ~R_STATUS_RXIDLE_MASK; | ||
55 | s->uart_status &= ~R_STATUS_RXEMPTY_MASK; | ||
56 | + /* The RXFULL is set after receiving a single byte | ||
57 | + * as the FIFO buffers are not yet implemented. | ||
58 | + */ | ||
59 | + s->uart_status |= R_STATUS_RXFULL_MASK; | ||
60 | + s->rx_level += 1; | ||
61 | |||
62 | if (size > rx_fifo_level) { | ||
63 | s->uart_intr_state |= R_INTR_STATE_RX_WATERMARK_MASK; | ||
64 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_reset(DeviceState *dev) | ||
65 | s->uart_timeout_ctrl = 0x00000000; | ||
66 | |||
67 | s->tx_level = 0; | ||
68 | + s->rx_level = 0; | ||
69 | |||
70 | s->char_tx_time = (NANOSECONDS_PER_SECOND / 230400) * 10; | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr, | ||
73 | |||
74 | case R_RDATA: | ||
75 | retvalue = s->uart_rdata; | ||
76 | - if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) { | ||
77 | + if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) && (s->rx_level > 0)) { | ||
78 | qemu_chr_fe_accept_input(&s->chr); | ||
79 | |||
80 | - s->uart_status |= R_STATUS_RXIDLE_MASK; | ||
81 | - s->uart_status |= R_STATUS_RXEMPTY_MASK; | ||
82 | + s->rx_level -= 1; | ||
83 | + s->uart_status &= ~R_STATUS_RXFULL_MASK; | ||
84 | + if (s->rx_level == 0) { | ||
85 | + s->uart_status |= R_STATUS_RXIDLE_MASK; | ||
86 | + s->uart_status |= R_STATUS_RXEMPTY_MASK; | ||
87 | + } | ||
88 | } | ||
89 | break; | ||
90 | case R_WDATA: | ||
91 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr, | ||
92 | case R_FIFO_STATUS: | ||
93 | retvalue = s->uart_fifo_status; | ||
94 | |||
95 | - retvalue |= s->tx_level & 0x1F; | ||
96 | + retvalue |= (s->rx_level & 0x1F) << R_FIFO_STATUS_RXLVL_SHIFT; | ||
97 | + retvalue |= (s->tx_level & 0x1F) << R_FIFO_STATUS_TXLVL_SHIFT; | ||
98 | |||
99 | qemu_log_mask(LOG_UNIMP, | ||
100 | "%s: RX fifos are not supported\n", __func__); | ||
101 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_write(void *opaque, hwaddr addr, | ||
102 | s->uart_fifo_ctrl = value; | ||
103 | |||
104 | if (value & R_FIFO_CTRL_RXRST_MASK) { | ||
105 | + s->rx_level = 0; | ||
106 | qemu_log_mask(LOG_UNIMP, | ||
107 | "%s: RX fifos are not supported\n", __func__); | ||
108 | } | ||
109 | -- | 30 | -- |
110 | 2.30.1 | 31 | 2.31.1 |
111 | 32 | ||
112 | 33 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature | 3 | In IEEE 754-2008 spec: |
4 | is not enabled. | 4 | Invalid operation exception is signaled when doing: |
5 | fusedMultiplyAdd(0, Inf, c) or fusedMultiplyAdd(Inf, 0, c) | ||
6 | unless c is a quiet NaN; if c is a quiet NaN then it is | ||
7 | implementation defined whether the invalid operation exception | ||
8 | is signaled. | ||
5 | 9 | ||
6 | If -1 is returned, exception will be raised and cs->exception_index will | 10 | In RISC-V Unprivileged ISA spec: |
7 | be set to the negative return value. The exception will then be treated | 11 | The fused multiply-add instructions must set the invalid |
8 | as an instruction access fault instead of illegal instruction fault. | 12 | operation exception flag when the multiplicands are Inf and |
13 | zero, even when the addend is a quiet NaN. | ||
14 | |||
15 | This commit set invalid operation execption flag for RISC-V when | ||
16 | multiplicands of muladd instructions are Inf and zero. | ||
9 | 17 | ||
10 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 18 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Message-id: 20210420013150.21992-1-frank.chang@sifive.com |
13 | Message-id: 20210223065935.20208-1-frank.chang@sifive.com | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 22 | --- |
16 | target/riscv/csr.c | 2 +- | 23 | fpu/softfloat-specialize.c.inc | 6 ++++++ |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | 24 | 1 file changed, 6 insertions(+) |
18 | 25 | ||
19 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 26 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc |
20 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/csr.c | 28 | --- a/fpu/softfloat-specialize.c.inc |
22 | +++ b/target/riscv/csr.c | 29 | +++ b/fpu/softfloat-specialize.c.inc |
23 | @@ -XXX,XX +XXX,XX @@ static int vs(CPURISCVState *env, int csrno) | 30 | @@ -XXX,XX +XXX,XX @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, |
24 | if (env->misa & RVV) { | 31 | } else { |
25 | return 0; | 32 | return 1; |
26 | } | 33 | } |
27 | - return -1; | 34 | +#elif defined(TARGET_RISCV) |
28 | + return -RISCV_EXCP_ILLEGAL_INST; | 35 | + /* For RISC-V, InvalidOp is set when multiplicands are Inf and zero */ |
29 | } | 36 | + if (infzero) { |
30 | 37 | + float_raise(float_flag_invalid, status); | |
31 | static int ctr(CPURISCVState *env, int csrno) | 38 | + } |
39 | + return 3; /* default NaN */ | ||
40 | #elif defined(TARGET_XTENSA) | ||
41 | /* | ||
42 | * For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns | ||
32 | -- | 43 | -- |
33 | 2.30.1 | 44 | 2.31.1 |
34 | 45 | ||
35 | 46 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Emmanuel Blot <emmanuel.blot@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Per SST25VF016B datasheet [1], SST flash requires a dummy byte after | 3 | Interrupt names have been swapped in 205377f8 and do not follow |
4 | the address bytes. Note only SPI mode is supported by SST flashes. | 4 | IRQ_*_EXT definition order. |
5 | 5 | ||
6 | [1] http://ww1.microchip.com/downloads/en/devicedoc/s71271_04.pdf | 6 | Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com> |
7 | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | |
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 8 | Message-id: 20210421133236.11323-1-emmanuel.blot@sifive.com |
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-id: 20210306060152.7250-1-bmeng.cn@gmail.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 10 | --- |
13 | hw/block/m25p80.c | 3 +++ | 11 | target/riscv/cpu.c | 2 +- |
14 | 1 file changed, 3 insertions(+) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | 13 | ||
16 | diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c | 14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/block/m25p80.c | 16 | --- a/target/riscv/cpu.c |
19 | +++ b/hw/block/m25p80.c | 17 | +++ b/target/riscv/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ static void decode_fast_read_cmd(Flash *s) | 18 | @@ -XXX,XX +XXX,XX @@ const char * const riscv_intr_names[] = { |
21 | s->needed_bytes = get_addr_length(s); | 19 | "vs_timer", |
22 | switch (get_man(s)) { | 20 | "m_timer", |
23 | /* Dummy cycles - modeled with bytes writes instead of bits */ | 21 | "u_external", |
24 | + case MAN_SST: | 22 | + "s_external", |
25 | + s->needed_bytes += 1; | 23 | "vs_external", |
26 | + break; | 24 | - "h_external", |
27 | case MAN_WINBOND: | 25 | "m_external", |
28 | s->needed_bytes += 8; | 26 | "reserved", |
29 | break; | 27 | "reserved", |
30 | -- | 28 | -- |
31 | 2.30.1 | 29 | 2.31.1 |
32 | 30 | ||
33 | 31 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: a07bc0c6dc4958681b4f93cbc5d0acc31ed3344a.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 6 ------ | ||
7 | target/riscv/cpu.c | 6 +++++- | ||
8 | 2 files changed, 5 insertions(+), 7 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/riscv/cpu.h | ||
13 | +++ b/target/riscv/cpu.h | ||
14 | @@ -XXX,XX +XXX,XX @@ | ||
15 | #define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2)) | ||
16 | #define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2)) | ||
17 | |||
18 | -#if defined(TARGET_RISCV32) | ||
19 | -#define RVXLEN RV32 | ||
20 | -#elif defined(TARGET_RISCV64) | ||
21 | -#define RVXLEN RV64 | ||
22 | -#endif | ||
23 | - | ||
24 | #define RV(x) ((target_ulong)1 << (x - 'A')) | ||
25 | |||
26 | #define RVI RV('I') | ||
27 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/riscv/cpu.c | ||
30 | +++ b/target/riscv/cpu.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void set_resetvec(CPURISCVState *env, target_ulong resetvec) | ||
32 | static void riscv_any_cpu_init(Object *obj) | ||
33 | { | ||
34 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
35 | - set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
36 | +#if defined(TARGET_RISCV32) | ||
37 | + set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
38 | +#elif defined(TARGET_RISCV64) | ||
39 | + set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
40 | +#endif | ||
41 | set_priv_version(env, PRIV_VERSION_1_11_0); | ||
42 | } | ||
43 | |||
44 | -- | ||
45 | 2.31.1 | ||
46 | |||
47 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | This also ensures that the SD bit is not writable. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Message-id: 20210311094902.1377593-1-georg.kotheimer@kernkonzept.com | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 3 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
6 | Message-id: 9ea842309f0fd7adff172790f5b5fc058b40f2f1.1619234854.git.alistair.francis@wdc.com | ||
7 | --- | 7 | --- |
8 | target/riscv/csr.c | 7 ++++--- | 8 | target/riscv/cpu_bits.h | 6 ------ |
9 | 1 file changed, 4 insertions(+), 3 deletions(-) | 9 | target/riscv/csr.c | 9 ++++++++- |
10 | 2 files changed, 8 insertions(+), 7 deletions(-) | ||
10 | 11 | ||
12 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/riscv/cpu_bits.h | ||
15 | +++ b/target/riscv/cpu_bits.h | ||
16 | @@ -XXX,XX +XXX,XX @@ | ||
17 | #define SSTATUS32_SD 0x80000000 | ||
18 | #define SSTATUS64_SD 0x8000000000000000ULL | ||
19 | |||
20 | -#if defined(TARGET_RISCV32) | ||
21 | -#define SSTATUS_SD SSTATUS32_SD | ||
22 | -#elif defined(TARGET_RISCV64) | ||
23 | -#define SSTATUS_SD SSTATUS64_SD | ||
24 | -#endif | ||
25 | - | ||
26 | /* hstatus CSR bits */ | ||
27 | #define HSTATUS_VSBE 0x00000020 | ||
28 | #define HSTATUS_GVA 0x00000040 | ||
11 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 29 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
12 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/csr.c | 31 | --- a/target/riscv/csr.c |
14 | +++ b/target/riscv/csr.c | 32 | +++ b/target/riscv/csr.c |
15 | @@ -XXX,XX +XXX,XX @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | | 33 | @@ -XXX,XX +XXX,XX @@ static const target_ulong delegable_excps = |
34 | (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)); | ||
35 | static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | | ||
16 | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | | 36 | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | |
17 | SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD; | 37 | - SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD; |
38 | + SSTATUS_SUM | SSTATUS_MXR; | ||
18 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; | 39 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; |
19 | -static const target_ulong hip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | 40 | static const target_ulong hip_writable_mask = MIP_VSSIP; |
20 | +static const target_ulong hip_writable_mask = MIP_VSSIP; | 41 | static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; |
21 | +static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, |
22 | static const target_ulong vsip_writable_mask = MIP_VSSIP; | 43 | target_ulong *val) |
23 | |||
24 | static const char valid_vm_1_10_32[16] = { | ||
25 | @@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
26 | target_ulong new_value, target_ulong write_mask) | ||
27 | { | 44 | { |
28 | int ret = rmw_mip(env, 0, ret_value, new_value, | 45 | target_ulong mask = (sstatus_v1_10_mask); |
29 | - write_mask & hip_writable_mask); | 46 | + |
30 | + write_mask & hvip_writable_mask); | 47 | + if (riscv_cpu_is_32bit(env)) { |
31 | 48 | + mask |= SSTATUS32_SD; | |
32 | - *ret_value &= hip_writable_mask; | 49 | + } else { |
33 | + *ret_value &= hvip_writable_mask; | 50 | + mask |= SSTATUS64_SD; |
34 | 51 | + } | |
35 | return ret; | 52 | + |
53 | *val = env->mstatus & mask; | ||
54 | return RISCV_EXCP_NONE; | ||
36 | } | 55 | } |
37 | -- | 56 | -- |
38 | 2.30.1 | 57 | 2.31.1 |
39 | 58 | ||
40 | 59 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 665f624bfdc2e3ca64265004b07de7489c77a766.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu_bits.h | 11 ----------- | ||
7 | target/riscv/cpu_helper.c | 24 +++++++++++++++--------- | ||
8 | 2 files changed, 15 insertions(+), 20 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/riscv/cpu_bits.h | ||
13 | +++ b/target/riscv/cpu_bits.h | ||
14 | @@ -XXX,XX +XXX,XX @@ | ||
15 | #define CSR_HTIMEDELTA 0x605 | ||
16 | #define CSR_HTIMEDELTAH 0x615 | ||
17 | |||
18 | -#if defined(TARGET_RISCV32) | ||
19 | -#define HGATP_MODE SATP32_MODE | ||
20 | -#define HGATP_VMID SATP32_ASID | ||
21 | -#define HGATP_PPN SATP32_PPN | ||
22 | -#endif | ||
23 | -#if defined(TARGET_RISCV64) | ||
24 | -#define HGATP_MODE SATP64_MODE | ||
25 | -#define HGATP_VMID SATP64_ASID | ||
26 | -#define HGATP_PPN SATP64_PPN | ||
27 | -#endif | ||
28 | - | ||
29 | /* Virtual CSRs */ | ||
30 | #define CSR_VSSTATUS 0x200 | ||
31 | #define CSR_VSIE 0x204 | ||
32 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/cpu_helper.c | ||
35 | +++ b/target/riscv/cpu_helper.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | ||
37 | } | ||
38 | widened = 0; | ||
39 | } else { | ||
40 | - base = (hwaddr)get_field(env->hgatp, HGATP_PPN) << PGSHIFT; | ||
41 | - vm = get_field(env->hgatp, HGATP_MODE); | ||
42 | + if (riscv_cpu_is_32bit(env)) { | ||
43 | + base = (hwaddr)get_field(env->hgatp, SATP32_PPN) << PGSHIFT; | ||
44 | + vm = get_field(env->hgatp, SATP32_MODE); | ||
45 | + } else { | ||
46 | + base = (hwaddr)get_field(env->hgatp, SATP64_PPN) << PGSHIFT; | ||
47 | + vm = get_field(env->hgatp, SATP64_MODE); | ||
48 | + } | ||
49 | widened = 2; | ||
50 | } | ||
51 | /* status.SUM will be ignored if execute on background */ | ||
52 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | ||
53 | bool first_stage, bool two_stage) | ||
54 | { | ||
55 | CPUState *cs = env_cpu(env); | ||
56 | - int page_fault_exceptions; | ||
57 | + int page_fault_exceptions, vm; | ||
58 | + | ||
59 | if (first_stage) { | ||
60 | - page_fault_exceptions = | ||
61 | - get_field(env->satp, SATP_MODE) != VM_1_10_MBARE && | ||
62 | - !pmp_violation; | ||
63 | + vm = get_field(env->satp, SATP_MODE); | ||
64 | + } else if (riscv_cpu_is_32bit(env)) { | ||
65 | + vm = get_field(env->hgatp, SATP32_MODE); | ||
66 | } else { | ||
67 | - page_fault_exceptions = | ||
68 | - get_field(env->hgatp, HGATP_MODE) != VM_1_10_MBARE && | ||
69 | - !pmp_violation; | ||
70 | + vm = get_field(env->hgatp, SATP64_MODE); | ||
71 | } | ||
72 | + page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation; | ||
73 | + | ||
74 | switch (access_type) { | ||
75 | case MMU_INST_FETCH: | ||
76 | if (riscv_cpu_virt_enabled(env) && !first_stage) { | ||
77 | -- | ||
78 | 2.31.1 | ||
79 | |||
80 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Message-id: fcc125d96da941b56c817c9dd6068dc36478fc53.1619234854.git.alistair.francis@wdc.com | ||
4 | --- | ||
5 | target/riscv/cpu_bits.h | 10 ---------- | ||
6 | target/riscv/csr.c | 12 ++++++++++-- | ||
7 | target/riscv/translate.c | 19 +++++++++++++++++-- | ||
8 | 3 files changed, 27 insertions(+), 14 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/riscv/cpu_bits.h | ||
13 | +++ b/target/riscv/cpu_bits.h | ||
14 | @@ -XXX,XX +XXX,XX @@ | ||
15 | #define MXL_RV64 2 | ||
16 | #define MXL_RV128 3 | ||
17 | |||
18 | -#if defined(TARGET_RISCV32) | ||
19 | -#define MSTATUS_SD MSTATUS32_SD | ||
20 | -#define MISA_MXL MISA32_MXL | ||
21 | -#define MXL_VAL MXL_RV32 | ||
22 | -#elif defined(TARGET_RISCV64) | ||
23 | -#define MSTATUS_SD MSTATUS64_SD | ||
24 | -#define MISA_MXL MISA64_MXL | ||
25 | -#define MXL_VAL MXL_RV64 | ||
26 | -#endif | ||
27 | - | ||
28 | /* sstatus CSR bits */ | ||
29 | #define SSTATUS_UIE 0x00000001 | ||
30 | #define SSTATUS_SIE 0x00000002 | ||
31 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/csr.c | ||
34 | +++ b/target/riscv/csr.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | ||
36 | |||
37 | dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) | | ||
38 | ((mstatus & MSTATUS_XS) == MSTATUS_XS); | ||
39 | - mstatus = set_field(mstatus, MSTATUS_SD, dirty); | ||
40 | + if (riscv_cpu_is_32bit(env)) { | ||
41 | + mstatus = set_field(mstatus, MSTATUS32_SD, dirty); | ||
42 | + } else { | ||
43 | + mstatus = set_field(mstatus, MSTATUS64_SD, dirty); | ||
44 | + } | ||
45 | env->mstatus = mstatus; | ||
46 | |||
47 | return RISCV_EXCP_NONE; | ||
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno, | ||
49 | } | ||
50 | |||
51 | /* misa.MXL writes are not supported by QEMU */ | ||
52 | - val = (env->misa & MISA_MXL) | (val & ~MISA_MXL); | ||
53 | + if (riscv_cpu_is_32bit(env)) { | ||
54 | + val = (env->misa & MISA32_MXL) | (val & ~MISA32_MXL); | ||
55 | + } else { | ||
56 | + val = (env->misa & MISA64_MXL) | (val & ~MISA64_MXL); | ||
57 | + } | ||
58 | |||
59 | /* flush translation cache */ | ||
60 | if (val != env->misa) { | ||
61 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/target/riscv/translate.c | ||
64 | +++ b/target/riscv/translate.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
66 | return ctx->misa & ext; | ||
67 | } | ||
68 | |||
69 | +#ifdef TARGET_RISCV32 | ||
70 | +# define is_32bit(ctx) true | ||
71 | +#elif defined(CONFIG_USER_ONLY) | ||
72 | +# define is_32bit(ctx) false | ||
73 | +#else | ||
74 | +static inline bool is_32bit(DisasContext *ctx) | ||
75 | +{ | ||
76 | + return (ctx->misa & RV32) == RV32; | ||
77 | +} | ||
78 | +#endif | ||
79 | + | ||
80 | /* | ||
81 | * RISC-V requires NaN-boxing of narrower width floating point values. | ||
82 | * This applies when a 32-bit value is assigned to a 64-bit FP register. | ||
83 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
84 | static void mark_fs_dirty(DisasContext *ctx) | ||
85 | { | ||
86 | TCGv tmp; | ||
87 | + target_ulong sd; | ||
88 | + | ||
89 | if (ctx->mstatus_fs == MSTATUS_FS) { | ||
90 | return; | ||
91 | } | ||
92 | @@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx) | ||
93 | ctx->mstatus_fs = MSTATUS_FS; | ||
94 | |||
95 | tmp = tcg_temp_new(); | ||
96 | + sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | ||
97 | + | ||
98 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
99 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD); | ||
100 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
101 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
102 | |||
103 | if (ctx->virt_enabled) { | ||
104 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
105 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD); | ||
106 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
107 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
108 | } | ||
109 | tcg_temp_free(tmp); | ||
110 | -- | ||
111 | 2.31.1 | ||
112 | |||
113 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Message-id: 6b701769d6621f45ba1739334198e36a64fe04df.1619234854.git.alistair.francis@wdc.com | ||
4 | --- | ||
5 | target/riscv/cpu_bits.h | 11 ----------- | ||
6 | target/riscv/cpu_helper.c | 32 ++++++++++++++++++++++++-------- | ||
7 | target/riscv/csr.c | 19 +++++++++++++++---- | ||
8 | target/riscv/monitor.c | 22 +++++++++++++++++----- | ||
9 | 4 files changed, 56 insertions(+), 28 deletions(-) | ||
2 | 10 | ||
3 | According to the specification the "field SPVP of hstatus controls the | 11 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
4 | privilege level of the access" for the hypervisor virtual-machine load | 12 | index XXXXXXX..XXXXXXX 100644 |
5 | and store instructions HLV, HLVX and HSV. | 13 | --- a/target/riscv/cpu_bits.h |
6 | 14 | +++ b/target/riscv/cpu_bits.h | |
7 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 15 | @@ -XXX,XX +XXX,XX @@ |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 16 | #define SATP64_ASID 0x0FFFF00000000000ULL |
9 | Message-id: 20210311103005.1400718-1-georg.kotheimer@kernkonzept.com | 17 | #define SATP64_PPN 0x00000FFFFFFFFFFFULL |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | |
11 | --- | 19 | -#if defined(TARGET_RISCV32) |
12 | target/riscv/cpu_helper.c | 25 ++++++++++++++----------- | 20 | -#define SATP_MODE SATP32_MODE |
13 | 1 file changed, 14 insertions(+), 11 deletions(-) | 21 | -#define SATP_ASID SATP32_ASID |
14 | 22 | -#define SATP_PPN SATP32_PPN | |
23 | -#endif | ||
24 | -#if defined(TARGET_RISCV64) | ||
25 | -#define SATP_MODE SATP64_MODE | ||
26 | -#define SATP_ASID SATP64_ASID | ||
27 | -#define SATP_PPN SATP64_PPN | ||
28 | -#endif | ||
29 | - | ||
30 | /* VM modes (mstatus.vm) privileged ISA 1.9.1 */ | ||
31 | #define VM_1_09_MBARE 0 | ||
32 | #define VM_1_09_MBB 1 | ||
15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 33 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu_helper.c | 35 | --- a/target/riscv/cpu_helper.c |
18 | +++ b/target/riscv/cpu_helper.c | 36 | +++ b/target/riscv/cpu_helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 37 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
20 | use_background = true; | 38 | |
39 | if (first_stage == true) { | ||
40 | if (use_background) { | ||
41 | - base = (hwaddr)get_field(env->vsatp, SATP_PPN) << PGSHIFT; | ||
42 | - vm = get_field(env->vsatp, SATP_MODE); | ||
43 | + if (riscv_cpu_is_32bit(env)) { | ||
44 | + base = (hwaddr)get_field(env->vsatp, SATP32_PPN) << PGSHIFT; | ||
45 | + vm = get_field(env->vsatp, SATP32_MODE); | ||
46 | + } else { | ||
47 | + base = (hwaddr)get_field(env->vsatp, SATP64_PPN) << PGSHIFT; | ||
48 | + vm = get_field(env->vsatp, SATP64_MODE); | ||
49 | + } | ||
50 | } else { | ||
51 | - base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT; | ||
52 | - vm = get_field(env->satp, SATP_MODE); | ||
53 | + if (riscv_cpu_is_32bit(env)) { | ||
54 | + base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT; | ||
55 | + vm = get_field(env->satp, SATP32_MODE); | ||
56 | + } else { | ||
57 | + base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT; | ||
58 | + vm = get_field(env->satp, SATP64_MODE); | ||
59 | + } | ||
60 | } | ||
61 | widened = 0; | ||
62 | } else { | ||
63 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | ||
64 | { | ||
65 | CPUState *cs = env_cpu(env); | ||
66 | int page_fault_exceptions, vm; | ||
67 | + uint64_t stap_mode; | ||
68 | + | ||
69 | + if (riscv_cpu_is_32bit(env)) { | ||
70 | + stap_mode = SATP32_MODE; | ||
71 | + } else { | ||
72 | + stap_mode = SATP64_MODE; | ||
73 | + } | ||
74 | |||
75 | if (first_stage) { | ||
76 | - vm = get_field(env->satp, SATP_MODE); | ||
77 | - } else if (riscv_cpu_is_32bit(env)) { | ||
78 | - vm = get_field(env->hgatp, SATP32_MODE); | ||
79 | + vm = get_field(env->satp, stap_mode); | ||
80 | } else { | ||
81 | - vm = get_field(env->hgatp, SATP64_MODE); | ||
82 | + vm = get_field(env->hgatp, stap_mode); | ||
21 | } | 83 | } |
22 | 84 | + | |
23 | - if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 85 | page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation; |
24 | + /* MPRV does not affect the virtual-machine load/store | 86 | |
25 | + instructions, HLV, HLVX, and HSV. */ | 87 | switch (access_type) { |
26 | + if (riscv_cpu_two_stage_lookup(mmu_idx)) { | 88 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
27 | + mode = get_field(env->hstatus, HSTATUS_SPVP); | 89 | index XXXXXXX..XXXXXXX 100644 |
28 | + } else if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 90 | --- a/target/riscv/csr.c |
29 | if (get_field(env->mstatus, MSTATUS_MPRV)) { | 91 | +++ b/target/riscv/csr.c |
30 | mode = get_field(env->mstatus, MSTATUS_MPP); | 92 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_satp(CPURISCVState *env, int csrno, |
31 | } | 93 | static RISCVException write_satp(CPURISCVState *env, int csrno, |
32 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 94 | target_ulong val) |
33 | qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n", | 95 | { |
34 | __func__, address, access_type, mmu_idx); | 96 | + int vm, mask, asid; |
35 | 97 | + | |
36 | - if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 98 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { |
37 | - if (get_field(env->mstatus, MSTATUS_MPRV)) { | 99 | return RISCV_EXCP_NONE; |
38 | - mode = get_field(env->mstatus, MSTATUS_MPP); | ||
39 | + /* MPRV does not affect the virtual-machine load/store | ||
40 | + instructions, HLV, HLVX, and HSV. */ | ||
41 | + if (riscv_cpu_two_stage_lookup(mmu_idx)) { | ||
42 | + mode = get_field(env->hstatus, HSTATUS_SPVP); | ||
43 | + } else if (mode == PRV_M && access_type != MMU_INST_FETCH && | ||
44 | + get_field(env->mstatus, MSTATUS_MPRV)) { | ||
45 | + mode = get_field(env->mstatus, MSTATUS_MPP); | ||
46 | + if (riscv_has_ext(env, RVH) && get_field(env->mstatus, MSTATUS_MPV)) { | ||
47 | + two_stage_lookup = true; | ||
48 | } | ||
49 | } | 100 | } |
50 | 101 | - if (validate_vm(env, get_field(val, SATP_MODE)) && | |
51 | - if (riscv_has_ext(env, RVH) && env->priv == PRV_M && | 102 | - ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) |
52 | - access_type != MMU_INST_FETCH && | 103 | - { |
53 | - get_field(env->mstatus, MSTATUS_MPRV) && | 104 | + |
54 | - get_field(env->mstatus, MSTATUS_MPV)) { | 105 | + if (riscv_cpu_is_32bit(env)) { |
55 | - two_stage_lookup = true; | 106 | + vm = validate_vm(env, get_field(val, SATP32_MODE)); |
56 | - } | 107 | + mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN); |
57 | - | 108 | + asid = (val ^ env->satp) & SATP32_ASID; |
58 | if (riscv_cpu_virt_enabled(env) || | 109 | + } else { |
59 | ((riscv_cpu_two_stage_lookup(mmu_idx) || two_stage_lookup) && | 110 | + vm = validate_vm(env, get_field(val, SATP64_MODE)); |
60 | access_type != MMU_INST_FETCH)) { | 111 | + mask = (val ^ env->satp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN); |
112 | + asid = (val ^ env->satp) & SATP64_ASID; | ||
113 | + } | ||
114 | + | ||
115 | + if (vm && mask) { | ||
116 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { | ||
117 | return RISCV_EXCP_ILLEGAL_INST; | ||
118 | } else { | ||
119 | - if ((val ^ env->satp) & SATP_ASID) { | ||
120 | + if (asid) { | ||
121 | tlb_flush(env_cpu(env)); | ||
122 | } | ||
123 | env->satp = val; | ||
124 | diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/target/riscv/monitor.c | ||
127 | +++ b/target/riscv/monitor.c | ||
128 | @@ -XXX,XX +XXX,XX @@ static void mem_info_svxx(Monitor *mon, CPUArchState *env) | ||
129 | target_ulong last_size; | ||
130 | int last_attr; | ||
131 | |||
132 | - base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT; | ||
133 | + if (riscv_cpu_is_32bit(env)) { | ||
134 | + base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT; | ||
135 | + vm = get_field(env->satp, SATP32_MODE); | ||
136 | + } else { | ||
137 | + base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT; | ||
138 | + vm = get_field(env->satp, SATP64_MODE); | ||
139 | + } | ||
140 | |||
141 | - vm = get_field(env->satp, SATP_MODE); | ||
142 | switch (vm) { | ||
143 | case VM_1_10_SV32: | ||
144 | levels = 2; | ||
145 | @@ -XXX,XX +XXX,XX @@ void hmp_info_mem(Monitor *mon, const QDict *qdict) | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | - if (!(env->satp & SATP_MODE)) { | ||
150 | - monitor_printf(mon, "No translation or protection\n"); | ||
151 | - return; | ||
152 | + if (riscv_cpu_is_32bit(env)) { | ||
153 | + if (!(env->satp & SATP32_MODE)) { | ||
154 | + monitor_printf(mon, "No translation or protection\n"); | ||
155 | + return; | ||
156 | + } | ||
157 | + } else { | ||
158 | + if (!(env->satp & SATP64_MODE)) { | ||
159 | + monitor_printf(mon, "No translation or protection\n"); | ||
160 | + return; | ||
161 | + } | ||
162 | } | ||
163 | |||
164 | mem_info_svxx(mon, env); | ||
61 | -- | 165 | -- |
62 | 2.30.1 | 166 | 2.31.1 |
63 | 167 | ||
64 | 168 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: e095b57af0d419c8ed822958f04dfc732d7beb7e.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu_bits.h | 6 ------ | ||
7 | 1 file changed, 6 deletions(-) | ||
1 | 8 | ||
9 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/riscv/cpu_bits.h | ||
12 | +++ b/target/riscv/cpu_bits.h | ||
13 | @@ -XXX,XX +XXX,XX @@ | ||
14 | #define HSTATUS32_WPRI 0xFF8FF87E | ||
15 | #define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL | ||
16 | |||
17 | -#if defined(TARGET_RISCV32) | ||
18 | -#define HSTATUS_WPRI HSTATUS32_WPRI | ||
19 | -#elif defined(TARGET_RISCV64) | ||
20 | -#define HSTATUS_WPRI HSTATUS64_WPRI | ||
21 | -#endif | ||
22 | - | ||
23 | #define HCOUNTEREN_CY (1 << 0) | ||
24 | #define HCOUNTEREN_TM (1 << 1) | ||
25 | #define HCOUNTEREN_IR (1 << 2) | ||
26 | -- | ||
27 | 2.31.1 | ||
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | |||
3 | When decode_insn16() fails, we fall back to decode_RV32_64C() for | ||
4 | further compressed instruction decoding. However, prior to this change, | ||
5 | we did not raise an illegal instruction exception, if decode_RV32_64C() | ||
6 | fails to decode the instruction. This means that we skipped illegal | ||
7 | compressed instructions instead of raising an illegal instruction | ||
8 | exception. | ||
9 | |||
10 | Instead of patching decode_RV32_64C(), we can just remove it, | ||
11 | as it is dead code since f330433b363 anyway. | ||
12 | |||
13 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
16 | Message-id: 20210322121609.3097928-1-georg.kotheimer@kernkonzept.com | 3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 4 | Message-id: 4853459564af35a6690120c74ad892f60cec35ff.1619234854.git.alistair.francis@wdc.com |
18 | --- | 5 | --- |
19 | target/riscv/translate.c | 179 +-------------------------------------- | 6 | target/riscv/translate.c | 6 ------ |
20 | 1 file changed, 1 insertion(+), 178 deletions(-) | 7 | 1 file changed, 6 deletions(-) |
21 | 8 | ||
22 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 9 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
23 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/translate.c | 11 | --- a/target/riscv/translate.c |
25 | +++ b/target/riscv/translate.c | 12 | +++ b/target/riscv/translate.c |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 13 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
27 | CPUState *cs; | 14 | CPUState *cs; |
28 | } DisasContext; | 15 | } DisasContext; |
29 | 16 | ||
30 | -#ifdef TARGET_RISCV64 | 17 | -#ifdef TARGET_RISCV64 |
31 | -/* convert riscv funct3 to qemu memop for load/store */ | 18 | -#define CASE_OP_32_64(X) case X: case glue(X, W) |
32 | -static const int tcg_memop_lookup[8] = { | 19 | -#else |
33 | - [0 ... 7] = -1, | 20 | -#define CASE_OP_32_64(X) case X |
34 | - [0] = MO_SB, | ||
35 | - [1] = MO_TESW, | ||
36 | - [2] = MO_TESL, | ||
37 | - [3] = MO_TEQ, | ||
38 | - [4] = MO_UB, | ||
39 | - [5] = MO_TEUW, | ||
40 | - [6] = MO_TEUL, | ||
41 | -}; | ||
42 | -#endif | 21 | -#endif |
43 | - | 22 | - |
44 | #ifdef TARGET_RISCV64 | 23 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) |
45 | #define CASE_OP_32_64(X) case X: case glue(X, W) | ||
46 | #else | ||
47 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
48 | ctx->base.is_jmp = DISAS_NORETURN; | ||
49 | } | ||
50 | |||
51 | -#ifdef TARGET_RISCV64 | ||
52 | -static void gen_load_c(DisasContext *ctx, uint32_t opc, int rd, int rs1, | ||
53 | - target_long imm) | ||
54 | -{ | ||
55 | - TCGv t0 = tcg_temp_new(); | ||
56 | - TCGv t1 = tcg_temp_new(); | ||
57 | - gen_get_gpr(t0, rs1); | ||
58 | - tcg_gen_addi_tl(t0, t0, imm); | ||
59 | - int memop = tcg_memop_lookup[(opc >> 12) & 0x7]; | ||
60 | - | ||
61 | - if (memop < 0) { | ||
62 | - gen_exception_illegal(ctx); | ||
63 | - return; | ||
64 | - } | ||
65 | - | ||
66 | - tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, memop); | ||
67 | - gen_set_gpr(rd, t1); | ||
68 | - tcg_temp_free(t0); | ||
69 | - tcg_temp_free(t1); | ||
70 | -} | ||
71 | - | ||
72 | -static void gen_store_c(DisasContext *ctx, uint32_t opc, int rs1, int rs2, | ||
73 | - target_long imm) | ||
74 | -{ | ||
75 | - TCGv t0 = tcg_temp_new(); | ||
76 | - TCGv dat = tcg_temp_new(); | ||
77 | - gen_get_gpr(t0, rs1); | ||
78 | - tcg_gen_addi_tl(t0, t0, imm); | ||
79 | - gen_get_gpr(dat, rs2); | ||
80 | - int memop = tcg_memop_lookup[(opc >> 12) & 0x7]; | ||
81 | - | ||
82 | - if (memop < 0) { | ||
83 | - gen_exception_illegal(ctx); | ||
84 | - return; | ||
85 | - } | ||
86 | - | ||
87 | - tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx, memop); | ||
88 | - tcg_temp_free(t0); | ||
89 | - tcg_temp_free(dat); | ||
90 | -} | ||
91 | -#endif | ||
92 | - | ||
93 | #ifndef CONFIG_USER_ONLY | ||
94 | /* The states of mstatus_fs are: | ||
95 | * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty | ||
96 | @@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx) | ||
97 | static inline void mark_fs_dirty(DisasContext *ctx) { } | ||
98 | #endif | ||
99 | |||
100 | -#if !defined(TARGET_RISCV64) | ||
101 | -static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, | ||
102 | - int rs1, target_long imm) | ||
103 | -{ | ||
104 | - TCGv t0; | ||
105 | - | ||
106 | - if (ctx->mstatus_fs == 0) { | ||
107 | - gen_exception_illegal(ctx); | ||
108 | - return; | ||
109 | - } | ||
110 | - | ||
111 | - t0 = tcg_temp_new(); | ||
112 | - gen_get_gpr(t0, rs1); | ||
113 | - tcg_gen_addi_tl(t0, t0, imm); | ||
114 | - | ||
115 | - switch (opc) { | ||
116 | - case OPC_RISC_FLW: | ||
117 | - if (!has_ext(ctx, RVF)) { | ||
118 | - goto do_illegal; | ||
119 | - } | ||
120 | - tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEUL); | ||
121 | - /* RISC-V requires NaN-boxing of narrower width floating point values */ | ||
122 | - tcg_gen_ori_i64(cpu_fpr[rd], cpu_fpr[rd], 0xffffffff00000000ULL); | ||
123 | - break; | ||
124 | - case OPC_RISC_FLD: | ||
125 | - if (!has_ext(ctx, RVD)) { | ||
126 | - goto do_illegal; | ||
127 | - } | ||
128 | - tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEQ); | ||
129 | - break; | ||
130 | - do_illegal: | ||
131 | - default: | ||
132 | - gen_exception_illegal(ctx); | ||
133 | - break; | ||
134 | - } | ||
135 | - tcg_temp_free(t0); | ||
136 | - | ||
137 | - mark_fs_dirty(ctx); | ||
138 | -} | ||
139 | - | ||
140 | -static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1, | ||
141 | - int rs2, target_long imm) | ||
142 | -{ | ||
143 | - TCGv t0; | ||
144 | - | ||
145 | - if (ctx->mstatus_fs == 0) { | ||
146 | - gen_exception_illegal(ctx); | ||
147 | - return; | ||
148 | - } | ||
149 | - | ||
150 | - t0 = tcg_temp_new(); | ||
151 | - gen_get_gpr(t0, rs1); | ||
152 | - tcg_gen_addi_tl(t0, t0, imm); | ||
153 | - | ||
154 | - switch (opc) { | ||
155 | - case OPC_RISC_FSW: | ||
156 | - if (!has_ext(ctx, RVF)) { | ||
157 | - goto do_illegal; | ||
158 | - } | ||
159 | - tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEUL); | ||
160 | - break; | ||
161 | - case OPC_RISC_FSD: | ||
162 | - if (!has_ext(ctx, RVD)) { | ||
163 | - goto do_illegal; | ||
164 | - } | ||
165 | - tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEQ); | ||
166 | - break; | ||
167 | - do_illegal: | ||
168 | - default: | ||
169 | - gen_exception_illegal(ctx); | ||
170 | - break; | ||
171 | - } | ||
172 | - | ||
173 | - tcg_temp_free(t0); | ||
174 | -} | ||
175 | -#endif | ||
176 | - | ||
177 | static void gen_set_rm(DisasContext *ctx, int rm) | ||
178 | { | 24 | { |
179 | TCGv_i32 t0; | 25 | return ctx->misa & ext; |
180 | @@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm) | ||
181 | tcg_temp_free_i32(t0); | ||
182 | } | ||
183 | |||
184 | -static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode) | ||
185 | -{ | ||
186 | - uint8_t funct3 = extract16(opcode, 13, 3); | ||
187 | - uint8_t rd_rs2 = GET_C_RS2S(opcode); | ||
188 | - uint8_t rs1s = GET_C_RS1S(opcode); | ||
189 | - | ||
190 | - switch (funct3) { | ||
191 | - case 3: | ||
192 | -#if defined(TARGET_RISCV64) | ||
193 | - /* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/ | ||
194 | - gen_load_c(ctx, OPC_RISC_LD, rd_rs2, rs1s, | ||
195 | - GET_C_LD_IMM(opcode)); | ||
196 | -#else | ||
197 | - /* C.FLW (RV32) -> flw rd', offset[6:2](rs1')*/ | ||
198 | - gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s, | ||
199 | - GET_C_LW_IMM(opcode)); | ||
200 | -#endif | ||
201 | - break; | ||
202 | - case 7: | ||
203 | -#if defined(TARGET_RISCV64) | ||
204 | - /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/ | ||
205 | - gen_store_c(ctx, OPC_RISC_SD, rs1s, rd_rs2, | ||
206 | - GET_C_LD_IMM(opcode)); | ||
207 | -#else | ||
208 | - /* C.FSW (RV32) -> fsw rs2', offset[6:2](rs1')*/ | ||
209 | - gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2, | ||
210 | - GET_C_LW_IMM(opcode)); | ||
211 | -#endif | ||
212 | - break; | ||
213 | - } | ||
214 | -} | ||
215 | - | ||
216 | -static void decode_RV32_64C(DisasContext *ctx, uint16_t opcode) | ||
217 | -{ | ||
218 | - uint8_t op = extract16(opcode, 0, 2); | ||
219 | - | ||
220 | - switch (op) { | ||
221 | - case 0: | ||
222 | - decode_RV32_64C0(ctx, opcode); | ||
223 | - break; | ||
224 | - } | ||
225 | -} | ||
226 | - | ||
227 | static int ex_plus_1(DisasContext *ctx, int nf) | ||
228 | { | ||
229 | return nf + 1; | ||
230 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
231 | } else { | ||
232 | ctx->pc_succ_insn = ctx->base.pc_next + 2; | ||
233 | if (!decode_insn16(ctx, opcode)) { | ||
234 | - /* fall back to old decoder */ | ||
235 | - decode_RV32_64C(ctx, opcode); | ||
236 | + gen_exception_illegal(ctx); | ||
237 | } | ||
238 | } | ||
239 | } else { | ||
240 | -- | 26 | -- |
241 | 2.30.1 | 27 | 2.31.1 |
242 | 28 | ||
243 | 29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This patch removes the insn32-64.decode decode file and consolidates the | ||
2 | instructions into the general RISC-V insn32.decode decode tree. | ||
1 | 3 | ||
4 | This means that all of the instructions are avaliable in both the 32-bit | ||
5 | and 64-bit builds. This also means that we run a check to ensure we are | ||
6 | running a 64-bit softmmu before we execute the 64-bit only instructions. | ||
7 | This allows us to include the 32-bit instructions in the 64-bit build, | ||
8 | while also ensuring that 32-bit only software can not execute the | ||
9 | instructions. | ||
10 | |||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-id: db709360e2be47d2f9c6483ab973fe4791aefa77.1619234854.git.alistair.francis@wdc.com | ||
14 | --- | ||
15 | target/riscv/helper.h | 18 +++-- | ||
16 | target/riscv/insn32-64.decode | 88 ------------------------- | ||
17 | target/riscv/insn32.decode | 67 ++++++++++++++++++- | ||
18 | target/riscv/fpu_helper.c | 16 ++--- | ||
19 | target/riscv/translate.c | 9 ++- | ||
20 | target/riscv/vector_helper.c | 4 -- | ||
21 | target/riscv/insn_trans/trans_rva.c.inc | 14 +++- | ||
22 | target/riscv/insn_trans/trans_rvd.c.inc | 17 ++++- | ||
23 | target/riscv/insn_trans/trans_rvf.c.inc | 6 +- | ||
24 | target/riscv/insn_trans/trans_rvh.c.inc | 8 ++- | ||
25 | target/riscv/insn_trans/trans_rvi.c.inc | 16 +++-- | ||
26 | target/riscv/insn_trans/trans_rvm.c.inc | 12 +++- | ||
27 | target/riscv/insn_trans/trans_rvv.c.inc | 39 +++++------ | ||
28 | target/riscv/meson.build | 2 +- | ||
29 | 14 files changed, 166 insertions(+), 150 deletions(-) | ||
30 | delete mode 100644 target/riscv/insn32-64.decode | ||
31 | |||
32 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/helper.h | ||
35 | +++ b/target/riscv/helper.h | ||
36 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_s, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
37 | DEF_HELPER_FLAGS_3(feq_s, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
38 | DEF_HELPER_FLAGS_2(fcvt_w_s, TCG_CALL_NO_RWG, tl, env, i64) | ||
39 | DEF_HELPER_FLAGS_2(fcvt_wu_s, TCG_CALL_NO_RWG, tl, env, i64) | ||
40 | -DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, i64, env, i64) | ||
41 | -DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, i64, env, i64) | ||
42 | +DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, tl, env, i64) | ||
43 | +DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, tl, env, i64) | ||
44 | DEF_HELPER_FLAGS_2(fcvt_s_w, TCG_CALL_NO_RWG, i64, env, tl) | ||
45 | DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl) | ||
46 | -DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, i64) | ||
47 | -DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, i64) | ||
48 | +DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl) | ||
49 | +DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl) | ||
50 | DEF_HELPER_FLAGS_1(fclass_s, TCG_CALL_NO_RWG_SE, tl, i64) | ||
51 | |||
52 | /* Floating Point - Double Precision */ | ||
53 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_d, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
54 | DEF_HELPER_FLAGS_3(feq_d, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
55 | DEF_HELPER_FLAGS_2(fcvt_w_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
56 | DEF_HELPER_FLAGS_2(fcvt_wu_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
57 | -DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, i64, env, i64) | ||
58 | -DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, i64, env, i64) | ||
59 | +DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
60 | +DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
61 | DEF_HELPER_FLAGS_2(fcvt_d_w, TCG_CALL_NO_RWG, i64, env, tl) | ||
62 | DEF_HELPER_FLAGS_2(fcvt_d_wu, TCG_CALL_NO_RWG, i64, env, tl) | ||
63 | -DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, i64) | ||
64 | -DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, i64) | ||
65 | +DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, tl) | ||
66 | +DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl) | ||
67 | DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) | ||
68 | |||
69 | /* Special functions */ | ||
70 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vlhuff_v_w, void, ptr, ptr, tl, env, i32) | ||
71 | DEF_HELPER_5(vlhuff_v_d, void, ptr, ptr, tl, env, i32) | ||
72 | DEF_HELPER_5(vlwuff_v_w, void, ptr, ptr, tl, env, i32) | ||
73 | DEF_HELPER_5(vlwuff_v_d, void, ptr, ptr, tl, env, i32) | ||
74 | -#ifdef TARGET_RISCV64 | ||
75 | DEF_HELPER_6(vamoswapw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
76 | DEF_HELPER_6(vamoswapd_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
77 | DEF_HELPER_6(vamoaddw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
78 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vamominuw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
79 | DEF_HELPER_6(vamominud_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
80 | DEF_HELPER_6(vamomaxuw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
81 | DEF_HELPER_6(vamomaxud_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
82 | -#endif | ||
83 | DEF_HELPER_6(vamoswapw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
84 | DEF_HELPER_6(vamoaddw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
85 | DEF_HELPER_6(vamoxorw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
86 | diff --git a/target/riscv/insn32-64.decode b/target/riscv/insn32-64.decode | ||
87 | deleted file mode 100644 | ||
88 | index XXXXXXX..XXXXXXX | ||
89 | --- a/target/riscv/insn32-64.decode | ||
90 | +++ /dev/null | ||
91 | @@ -XXX,XX +XXX,XX @@ | ||
92 | -# | ||
93 | -# RISC-V translation routines for the RV Instruction Set. | ||
94 | -# | ||
95 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
96 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
97 | -# | ||
98 | -# This program is free software; you can redistribute it and/or modify it | ||
99 | -# under the terms and conditions of the GNU General Public License, | ||
100 | -# version 2 or later, as published by the Free Software Foundation. | ||
101 | -# | ||
102 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
103 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
104 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
105 | -# more details. | ||
106 | -# | ||
107 | -# You should have received a copy of the GNU General Public License along with | ||
108 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
109 | - | ||
110 | -# This is concatenated with insn32.decode for risc64 targets. | ||
111 | -# Most of the fields and formats are there. | ||
112 | - | ||
113 | -%sh5 20:5 | ||
114 | - | ||
115 | -@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
116 | - | ||
117 | -# *** RV64I Base Instruction Set (in addition to RV32I) *** | ||
118 | -lwu ............ ..... 110 ..... 0000011 @i | ||
119 | -ld ............ ..... 011 ..... 0000011 @i | ||
120 | -sd ....... ..... ..... 011 ..... 0100011 @s | ||
121 | -addiw ............ ..... 000 ..... 0011011 @i | ||
122 | -slliw 0000000 ..... ..... 001 ..... 0011011 @sh5 | ||
123 | -srliw 0000000 ..... ..... 101 ..... 0011011 @sh5 | ||
124 | -sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5 | ||
125 | -addw 0000000 ..... ..... 000 ..... 0111011 @r | ||
126 | -subw 0100000 ..... ..... 000 ..... 0111011 @r | ||
127 | -sllw 0000000 ..... ..... 001 ..... 0111011 @r | ||
128 | -srlw 0000000 ..... ..... 101 ..... 0111011 @r | ||
129 | -sraw 0100000 ..... ..... 101 ..... 0111011 @r | ||
130 | - | ||
131 | -# *** RV64M Standard Extension (in addition to RV32M) *** | ||
132 | -mulw 0000001 ..... ..... 000 ..... 0111011 @r | ||
133 | -divw 0000001 ..... ..... 100 ..... 0111011 @r | ||
134 | -divuw 0000001 ..... ..... 101 ..... 0111011 @r | ||
135 | -remw 0000001 ..... ..... 110 ..... 0111011 @r | ||
136 | -remuw 0000001 ..... ..... 111 ..... 0111011 @r | ||
137 | - | ||
138 | -# *** RV64A Standard Extension (in addition to RV32A) *** | ||
139 | -lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld | ||
140 | -sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st | ||
141 | -amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st | ||
142 | -amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
143 | -amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
144 | -amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
145 | -amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
146 | -amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
147 | -amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
148 | -amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
149 | -amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
150 | - | ||
151 | -#*** Vector AMO operations (in addition to Zvamo) *** | ||
152 | -vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
153 | -vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
154 | -vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
155 | -vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
156 | -vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
157 | -vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
158 | -vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
159 | -vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
160 | -vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
161 | - | ||
162 | -# *** RV64F Standard Extension (in addition to RV32F) *** | ||
163 | -fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm | ||
164 | -fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm | ||
165 | -fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm | ||
166 | -fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm | ||
167 | - | ||
168 | -# *** RV64D Standard Extension (in addition to RV32D) *** | ||
169 | -fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm | ||
170 | -fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm | ||
171 | -fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2 | ||
172 | -fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm | ||
173 | -fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm | ||
174 | -fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2 | ||
175 | - | ||
176 | -# *** RV32H Base Instruction Set *** | ||
177 | -hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 | ||
178 | -hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 | ||
179 | -hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s | ||
180 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
181 | index XXXXXXX..XXXXXXX 100644 | ||
182 | --- a/target/riscv/insn32.decode | ||
183 | +++ b/target/riscv/insn32.decode | ||
184 | @@ -XXX,XX +XXX,XX @@ | ||
185 | %rs2 20:5 | ||
186 | %rs1 15:5 | ||
187 | %rd 7:5 | ||
188 | +%sh5 20:5 | ||
189 | |||
190 | %sh10 20:10 | ||
191 | %csr 20:12 | ||
192 | @@ -XXX,XX +XXX,XX @@ | ||
193 | @sfence_vma ....... ..... ..... ... ..... ....... %rs2 %rs1 | ||
194 | @sfence_vm ....... ..... ..... ... ..... ....... %rs1 | ||
195 | |||
196 | +# Formats 64: | ||
197 | +@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
198 | |||
199 | # *** Privileged Instructions *** | ||
200 | ecall 000000000000 00000 000 00000 1110011 | ||
201 | @@ -XXX,XX +XXX,XX @@ csrrwi ............ ..... 101 ..... 1110011 @csr | ||
202 | csrrsi ............ ..... 110 ..... 1110011 @csr | ||
203 | csrrci ............ ..... 111 ..... 1110011 @csr | ||
204 | |||
205 | +# *** RV64I Base Instruction Set (in addition to RV32I) *** | ||
206 | +lwu ............ ..... 110 ..... 0000011 @i | ||
207 | +ld ............ ..... 011 ..... 0000011 @i | ||
208 | +sd ....... ..... ..... 011 ..... 0100011 @s | ||
209 | +addiw ............ ..... 000 ..... 0011011 @i | ||
210 | +slliw 0000000 ..... ..... 001 ..... 0011011 @sh5 | ||
211 | +srliw 0000000 ..... ..... 101 ..... 0011011 @sh5 | ||
212 | +sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5 | ||
213 | +addw 0000000 ..... ..... 000 ..... 0111011 @r | ||
214 | +subw 0100000 ..... ..... 000 ..... 0111011 @r | ||
215 | +sllw 0000000 ..... ..... 001 ..... 0111011 @r | ||
216 | +srlw 0000000 ..... ..... 101 ..... 0111011 @r | ||
217 | +sraw 0100000 ..... ..... 101 ..... 0111011 @r | ||
218 | + | ||
219 | # *** RV32M Standard Extension *** | ||
220 | mul 0000001 ..... ..... 000 ..... 0110011 @r | ||
221 | mulh 0000001 ..... ..... 001 ..... 0110011 @r | ||
222 | @@ -XXX,XX +XXX,XX @@ divu 0000001 ..... ..... 101 ..... 0110011 @r | ||
223 | rem 0000001 ..... ..... 110 ..... 0110011 @r | ||
224 | remu 0000001 ..... ..... 111 ..... 0110011 @r | ||
225 | |||
226 | +# *** RV64M Standard Extension (in addition to RV32M) *** | ||
227 | +mulw 0000001 ..... ..... 000 ..... 0111011 @r | ||
228 | +divw 0000001 ..... ..... 100 ..... 0111011 @r | ||
229 | +divuw 0000001 ..... ..... 101 ..... 0111011 @r | ||
230 | +remw 0000001 ..... ..... 110 ..... 0111011 @r | ||
231 | +remuw 0000001 ..... ..... 111 ..... 0111011 @r | ||
232 | + | ||
233 | # *** RV32A Standard Extension *** | ||
234 | lr_w 00010 . . 00000 ..... 010 ..... 0101111 @atom_ld | ||
235 | sc_w 00011 . . ..... ..... 010 ..... 0101111 @atom_st | ||
236 | @@ -XXX,XX +XXX,XX @@ amomax_w 10100 . . ..... ..... 010 ..... 0101111 @atom_st | ||
237 | amominu_w 11000 . . ..... ..... 010 ..... 0101111 @atom_st | ||
238 | amomaxu_w 11100 . . ..... ..... 010 ..... 0101111 @atom_st | ||
239 | |||
240 | +# *** RV64A Standard Extension (in addition to RV32A) *** | ||
241 | +lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld | ||
242 | +sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st | ||
243 | +amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st | ||
244 | +amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
245 | +amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
246 | +amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
247 | +amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
248 | +amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
249 | +amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
250 | +amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
251 | +amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
252 | + | ||
253 | # *** RV32F Standard Extension *** | ||
254 | flw ............ ..... 010 ..... 0000111 @i | ||
255 | fsw ....... ..... ..... 010 ..... 0100111 @s | ||
256 | @@ -XXX,XX +XXX,XX @@ fcvt_s_w 1101000 00000 ..... ... ..... 1010011 @r2_rm | ||
257 | fcvt_s_wu 1101000 00001 ..... ... ..... 1010011 @r2_rm | ||
258 | fmv_w_x 1111000 00000 ..... 000 ..... 1010011 @r2 | ||
259 | |||
260 | +# *** RV64F Standard Extension (in addition to RV32F) *** | ||
261 | +fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm | ||
262 | +fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm | ||
263 | +fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm | ||
264 | +fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm | ||
265 | + | ||
266 | # *** RV32D Standard Extension *** | ||
267 | fld ............ ..... 011 ..... 0000111 @i | ||
268 | fsd ....... ..... ..... 011 ..... 0100111 @s | ||
269 | @@ -XXX,XX +XXX,XX @@ fcvt_wu_d 1100001 00001 ..... ... ..... 1010011 @r2_rm | ||
270 | fcvt_d_w 1101001 00000 ..... ... ..... 1010011 @r2_rm | ||
271 | fcvt_d_wu 1101001 00001 ..... ... ..... 1010011 @r2_rm | ||
272 | |||
273 | +# *** RV64D Standard Extension (in addition to RV32D) *** | ||
274 | +fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm | ||
275 | +fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm | ||
276 | +fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2 | ||
277 | +fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm | ||
278 | +fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm | ||
279 | +fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2 | ||
280 | + | ||
281 | # *** RV32H Base Instruction Set *** | ||
282 | hlv_b 0110000 00000 ..... 100 ..... 1110011 @r2 | ||
283 | hlv_bu 0110000 00001 ..... 100 ..... 1110011 @r2 | ||
284 | @@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s | ||
285 | hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma | ||
286 | hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma | ||
287 | |||
288 | -# *** RV32V Extension *** | ||
289 | +# *** RV32H Base Instruction Set *** | ||
290 | +hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 | ||
291 | +hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 | ||
292 | +hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s | ||
293 | |||
294 | # *** Vector loads and stores are encoded within LOADFP/STORE-FP *** | ||
295 | vlb_v ... 100 . 00000 ..... 000 ..... 0000111 @r2_nfvm | ||
296 | @@ -XXX,XX +XXX,XX @@ vcompress_vm 010111 - ..... ..... 010 ..... 1010111 @r | ||
297 | |||
298 | vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm | ||
299 | vsetvl 1000000 ..... ..... 111 ..... 1010111 @r | ||
300 | + | ||
301 | +#*** Vector AMO operations (in addition to Zvamo) *** | ||
302 | +vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
303 | +vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
304 | +vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
305 | +vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
306 | +vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
307 | +vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
308 | +vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
309 | +vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
310 | +vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
311 | diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c | ||
312 | index XXXXXXX..XXXXXXX 100644 | ||
313 | --- a/target/riscv/fpu_helper.c | ||
314 | +++ b/target/riscv/fpu_helper.c | ||
315 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_s(CPURISCVState *env, uint64_t rs1) | ||
316 | return (int32_t)float32_to_uint32(frs1, &env->fp_status); | ||
317 | } | ||
318 | |||
319 | -uint64_t helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1) | ||
320 | +target_ulong helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1) | ||
321 | { | ||
322 | float32 frs1 = check_nanbox_s(rs1); | ||
323 | return float32_to_int64(frs1, &env->fp_status); | ||
324 | } | ||
325 | |||
326 | -uint64_t helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1) | ||
327 | +target_ulong helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1) | ||
328 | { | ||
329 | float32 frs1 = check_nanbox_s(rs1); | ||
330 | return float32_to_uint64(frs1, &env->fp_status); | ||
331 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1) | ||
332 | return nanbox_s(uint32_to_float32((uint32_t)rs1, &env->fp_status)); | ||
333 | } | ||
334 | |||
335 | -uint64_t helper_fcvt_s_l(CPURISCVState *env, uint64_t rs1) | ||
336 | +uint64_t helper_fcvt_s_l(CPURISCVState *env, target_ulong rs1) | ||
337 | { | ||
338 | return nanbox_s(int64_to_float32(rs1, &env->fp_status)); | ||
339 | } | ||
340 | |||
341 | -uint64_t helper_fcvt_s_lu(CPURISCVState *env, uint64_t rs1) | ||
342 | +uint64_t helper_fcvt_s_lu(CPURISCVState *env, target_ulong rs1) | ||
343 | { | ||
344 | return nanbox_s(uint64_to_float32(rs1, &env->fp_status)); | ||
345 | } | ||
346 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1) | ||
347 | return (int32_t)float64_to_uint32(frs1, &env->fp_status); | ||
348 | } | ||
349 | |||
350 | -uint64_t helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1) | ||
351 | +target_ulong helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1) | ||
352 | { | ||
353 | return float64_to_int64(frs1, &env->fp_status); | ||
354 | } | ||
355 | |||
356 | -uint64_t helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) | ||
357 | +target_ulong helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) | ||
358 | { | ||
359 | return float64_to_uint64(frs1, &env->fp_status); | ||
360 | } | ||
361 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_d_wu(CPURISCVState *env, target_ulong rs1) | ||
362 | return uint32_to_float64((uint32_t)rs1, &env->fp_status); | ||
363 | } | ||
364 | |||
365 | -uint64_t helper_fcvt_d_l(CPURISCVState *env, uint64_t rs1) | ||
366 | +uint64_t helper_fcvt_d_l(CPURISCVState *env, target_ulong rs1) | ||
367 | { | ||
368 | return int64_to_float64(rs1, &env->fp_status); | ||
369 | } | ||
370 | |||
371 | -uint64_t helper_fcvt_d_lu(CPURISCVState *env, uint64_t rs1) | ||
372 | +uint64_t helper_fcvt_d_lu(CPURISCVState *env, target_ulong rs1) | ||
373 | { | ||
374 | return uint64_to_float64(rs1, &env->fp_status); | ||
375 | } | ||
376 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
377 | index XXXXXXX..XXXXXXX 100644 | ||
378 | --- a/target/riscv/translate.c | ||
379 | +++ b/target/riscv/translate.c | ||
380 | @@ -XXX,XX +XXX,XX @@ EX_SH(12) | ||
381 | } \ | ||
382 | } while (0) | ||
383 | |||
384 | +#define REQUIRE_64BIT(ctx) do { \ | ||
385 | + if (is_32bit(ctx)) { \ | ||
386 | + return false; \ | ||
387 | + } \ | ||
388 | +} while (0) | ||
389 | + | ||
390 | static int ex_rvc_register(DisasContext *ctx, int reg) | ||
391 | { | ||
392 | return 8 + reg; | ||
393 | @@ -XXX,XX +XXX,XX @@ static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a, | ||
394 | return true; | ||
395 | } | ||
396 | |||
397 | -#ifdef TARGET_RISCV64 | ||
398 | static void gen_addw(TCGv ret, TCGv arg1, TCGv arg2) | ||
399 | { | ||
400 | tcg_gen_add_tl(ret, arg1, arg2); | ||
401 | @@ -XXX,XX +XXX,XX @@ static bool gen_arith_div_uw(DisasContext *ctx, arg_r *a, | ||
402 | return true; | ||
403 | } | ||
404 | |||
405 | -#endif | ||
406 | - | ||
407 | static bool gen_arith(DisasContext *ctx, arg_r *a, | ||
408 | void(*func)(TCGv, TCGv, TCGv)) | ||
409 | { | ||
410 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
411 | index XXXXXXX..XXXXXXX 100644 | ||
412 | --- a/target/riscv/vector_helper.c | ||
413 | +++ b/target/riscv/vector_helper.c | ||
414 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominw_v_w, 32, 32, H4, DO_MIN, l) | ||
415 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxw_v_w, 32, 32, H4, DO_MAX, l) | ||
416 | GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_w, 32, 32, H4, DO_MINU, l) | ||
417 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_w, 32, 32, H4, DO_MAXU, l) | ||
418 | -#ifdef TARGET_RISCV64 | ||
419 | GEN_VEXT_AMO_NOATOMIC_OP(vamoswapw_v_d, 64, 32, H8, DO_SWAP, l) | ||
420 | GEN_VEXT_AMO_NOATOMIC_OP(vamoswapd_v_d, 64, 64, H8, DO_SWAP, q) | ||
421 | GEN_VEXT_AMO_NOATOMIC_OP(vamoaddw_v_d, 64, 32, H8, DO_ADD, l) | ||
422 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_d, 64, 32, H8, DO_MINU, l) | ||
423 | GEN_VEXT_AMO_NOATOMIC_OP(vamominud_v_d, 64, 64, H8, DO_MINU, q) | ||
424 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_d, 64, 32, H8, DO_MAXU, l) | ||
425 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxud_v_d, 64, 64, H8, DO_MAXU, q) | ||
426 | -#endif | ||
427 | |||
428 | static inline void | ||
429 | vext_amo_noatomic(void *vs3, void *v0, target_ulong base, | ||
430 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vs3, void *v0, target_ulong base, \ | ||
431 | GETPC()); \ | ||
432 | } | ||
433 | |||
434 | -#ifdef TARGET_RISCV64 | ||
435 | GEN_VEXT_AMO(vamoswapw_v_d, int32_t, int64_t, idx_d, clearq) | ||
436 | GEN_VEXT_AMO(vamoswapd_v_d, int64_t, int64_t, idx_d, clearq) | ||
437 | GEN_VEXT_AMO(vamoaddw_v_d, int32_t, int64_t, idx_d, clearq) | ||
438 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO(vamominuw_v_d, uint32_t, uint64_t, idx_d, clearq) | ||
439 | GEN_VEXT_AMO(vamominud_v_d, uint64_t, uint64_t, idx_d, clearq) | ||
440 | GEN_VEXT_AMO(vamomaxuw_v_d, uint32_t, uint64_t, idx_d, clearq) | ||
441 | GEN_VEXT_AMO(vamomaxud_v_d, uint64_t, uint64_t, idx_d, clearq) | ||
442 | -#endif | ||
443 | GEN_VEXT_AMO(vamoswapw_v_w, int32_t, int32_t, idx_w, clearl) | ||
444 | GEN_VEXT_AMO(vamoaddw_v_w, int32_t, int32_t, idx_w, clearl) | ||
445 | GEN_VEXT_AMO(vamoxorw_v_w, int32_t, int32_t, idx_w, clearl) | ||
446 | diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc | ||
447 | index XXXXXXX..XXXXXXX 100644 | ||
448 | --- a/target/riscv/insn_trans/trans_rva.c.inc | ||
449 | +++ b/target/riscv/insn_trans/trans_rva.c.inc | ||
450 | @@ -XXX,XX +XXX,XX @@ static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a) | ||
451 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL)); | ||
452 | } | ||
453 | |||
454 | -#ifdef TARGET_RISCV64 | ||
455 | - | ||
456 | static bool trans_lr_d(DisasContext *ctx, arg_lr_d *a) | ||
457 | { | ||
458 | + REQUIRE_64BIT(ctx); | ||
459 | return gen_lr(ctx, a, MO_ALIGN | MO_TEQ); | ||
460 | } | ||
461 | |||
462 | static bool trans_sc_d(DisasContext *ctx, arg_sc_d *a) | ||
463 | { | ||
464 | + REQUIRE_64BIT(ctx); | ||
465 | return gen_sc(ctx, a, (MO_ALIGN | MO_TEQ)); | ||
466 | } | ||
467 | |||
468 | static bool trans_amoswap_d(DisasContext *ctx, arg_amoswap_d *a) | ||
469 | { | ||
470 | + REQUIRE_64BIT(ctx); | ||
471 | return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TEQ)); | ||
472 | } | ||
473 | |||
474 | static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a) | ||
475 | { | ||
476 | + REQUIRE_64BIT(ctx); | ||
477 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TEQ)); | ||
478 | } | ||
479 | |||
480 | static bool trans_amoxor_d(DisasContext *ctx, arg_amoxor_d *a) | ||
481 | { | ||
482 | + REQUIRE_64BIT(ctx); | ||
483 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TEQ)); | ||
484 | } | ||
485 | |||
486 | static bool trans_amoand_d(DisasContext *ctx, arg_amoand_d *a) | ||
487 | { | ||
488 | + REQUIRE_64BIT(ctx); | ||
489 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TEQ)); | ||
490 | } | ||
491 | |||
492 | static bool trans_amoor_d(DisasContext *ctx, arg_amoor_d *a) | ||
493 | { | ||
494 | + REQUIRE_64BIT(ctx); | ||
495 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TEQ)); | ||
496 | } | ||
497 | |||
498 | static bool trans_amomin_d(DisasContext *ctx, arg_amomin_d *a) | ||
499 | { | ||
500 | + REQUIRE_64BIT(ctx); | ||
501 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TEQ)); | ||
502 | } | ||
503 | |||
504 | static bool trans_amomax_d(DisasContext *ctx, arg_amomax_d *a) | ||
505 | { | ||
506 | + REQUIRE_64BIT(ctx); | ||
507 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TEQ)); | ||
508 | } | ||
509 | |||
510 | static bool trans_amominu_d(DisasContext *ctx, arg_amominu_d *a) | ||
511 | { | ||
512 | + REQUIRE_64BIT(ctx); | ||
513 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TEQ)); | ||
514 | } | ||
515 | |||
516 | static bool trans_amomaxu_d(DisasContext *ctx, arg_amomaxu_d *a) | ||
517 | { | ||
518 | + REQUIRE_64BIT(ctx); | ||
519 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TEQ)); | ||
520 | } | ||
521 | -#endif | ||
522 | diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc | ||
523 | index XXXXXXX..XXXXXXX 100644 | ||
524 | --- a/target/riscv/insn_trans/trans_rvd.c.inc | ||
525 | +++ b/target/riscv/insn_trans/trans_rvd.c.inc | ||
526 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a) | ||
527 | return true; | ||
528 | } | ||
529 | |||
530 | -#ifdef TARGET_RISCV64 | ||
531 | - | ||
532 | static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a) | ||
533 | { | ||
534 | + REQUIRE_64BIT(ctx); | ||
535 | REQUIRE_FPU; | ||
536 | REQUIRE_EXT(ctx, RVD); | ||
537 | |||
538 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a) | ||
539 | |||
540 | static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a) | ||
541 | { | ||
542 | + REQUIRE_64BIT(ctx); | ||
543 | REQUIRE_FPU; | ||
544 | REQUIRE_EXT(ctx, RVD); | ||
545 | |||
546 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a) | ||
547 | |||
548 | static bool trans_fmv_x_d(DisasContext *ctx, arg_fmv_x_d *a) | ||
549 | { | ||
550 | + REQUIRE_64BIT(ctx); | ||
551 | REQUIRE_FPU; | ||
552 | REQUIRE_EXT(ctx, RVD); | ||
553 | |||
554 | +#ifdef TARGET_RISCV64 | ||
555 | gen_set_gpr(a->rd, cpu_fpr[a->rs1]); | ||
556 | return true; | ||
557 | +#else | ||
558 | + qemu_build_not_reached(); | ||
559 | +#endif | ||
560 | } | ||
561 | |||
562 | static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a) | ||
563 | { | ||
564 | + REQUIRE_64BIT(ctx); | ||
565 | REQUIRE_FPU; | ||
566 | REQUIRE_EXT(ctx, RVD); | ||
567 | |||
568 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a) | ||
569 | |||
570 | static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a) | ||
571 | { | ||
572 | + REQUIRE_64BIT(ctx); | ||
573 | REQUIRE_FPU; | ||
574 | REQUIRE_EXT(ctx, RVD); | ||
575 | |||
576 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a) | ||
577 | |||
578 | static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a) | ||
579 | { | ||
580 | + REQUIRE_64BIT(ctx); | ||
581 | REQUIRE_FPU; | ||
582 | REQUIRE_EXT(ctx, RVD); | ||
583 | |||
584 | +#ifdef TARGET_RISCV64 | ||
585 | TCGv t0 = tcg_temp_new(); | ||
586 | gen_get_gpr(t0, a->rs1); | ||
587 | |||
588 | @@ -XXX,XX +XXX,XX @@ static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a) | ||
589 | tcg_temp_free(t0); | ||
590 | mark_fs_dirty(ctx); | ||
591 | return true; | ||
592 | -} | ||
593 | +#else | ||
594 | + qemu_build_not_reached(); | ||
595 | #endif | ||
596 | +} | ||
597 | diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc | ||
598 | index XXXXXXX..XXXXXXX 100644 | ||
599 | --- a/target/riscv/insn_trans/trans_rvf.c.inc | ||
600 | +++ b/target/riscv/insn_trans/trans_rvf.c.inc | ||
601 | @@ -XXX,XX +XXX,XX @@ static bool trans_fmv_w_x(DisasContext *ctx, arg_fmv_w_x *a) | ||
602 | return true; | ||
603 | } | ||
604 | |||
605 | -#ifdef TARGET_RISCV64 | ||
606 | static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a) | ||
607 | { | ||
608 | + REQUIRE_64BIT(ctx); | ||
609 | REQUIRE_FPU; | ||
610 | REQUIRE_EXT(ctx, RVF); | ||
611 | |||
612 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a) | ||
613 | |||
614 | static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a) | ||
615 | { | ||
616 | + REQUIRE_64BIT(ctx); | ||
617 | REQUIRE_FPU; | ||
618 | REQUIRE_EXT(ctx, RVF); | ||
619 | |||
620 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a) | ||
621 | |||
622 | static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a) | ||
623 | { | ||
624 | + REQUIRE_64BIT(ctx); | ||
625 | REQUIRE_FPU; | ||
626 | REQUIRE_EXT(ctx, RVF); | ||
627 | |||
628 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a) | ||
629 | |||
630 | static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a) | ||
631 | { | ||
632 | + REQUIRE_64BIT(ctx); | ||
633 | REQUIRE_FPU; | ||
634 | REQUIRE_EXT(ctx, RVF); | ||
635 | |||
636 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a) | ||
637 | tcg_temp_free(t0); | ||
638 | return true; | ||
639 | } | ||
640 | -#endif | ||
641 | diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc | ||
642 | index XXXXXXX..XXXXXXX 100644 | ||
643 | --- a/target/riscv/insn_trans/trans_rvh.c.inc | ||
644 | +++ b/target/riscv/insn_trans/trans_rvh.c.inc | ||
645 | @@ -XXX,XX +XXX,XX @@ static bool trans_hsv_w(DisasContext *ctx, arg_hsv_w *a) | ||
646 | #endif | ||
647 | } | ||
648 | |||
649 | -#ifdef TARGET_RISCV64 | ||
650 | static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a) | ||
651 | { | ||
652 | + REQUIRE_64BIT(ctx); | ||
653 | REQUIRE_EXT(ctx, RVH); | ||
654 | + | ||
655 | #ifndef CONFIG_USER_ONLY | ||
656 | TCGv t0 = tcg_temp_new(); | ||
657 | TCGv t1 = tcg_temp_new(); | ||
658 | @@ -XXX,XX +XXX,XX @@ static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a) | ||
659 | |||
660 | static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a) | ||
661 | { | ||
662 | + REQUIRE_64BIT(ctx); | ||
663 | REQUIRE_EXT(ctx, RVH); | ||
664 | + | ||
665 | #ifndef CONFIG_USER_ONLY | ||
666 | TCGv t0 = tcg_temp_new(); | ||
667 | TCGv t1 = tcg_temp_new(); | ||
668 | @@ -XXX,XX +XXX,XX @@ static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a) | ||
669 | |||
670 | static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a) | ||
671 | { | ||
672 | + REQUIRE_64BIT(ctx); | ||
673 | REQUIRE_EXT(ctx, RVH); | ||
674 | + | ||
675 | #ifndef CONFIG_USER_ONLY | ||
676 | TCGv t0 = tcg_temp_new(); | ||
677 | TCGv dat = tcg_temp_new(); | ||
678 | @@ -XXX,XX +XXX,XX @@ static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a) | ||
679 | return false; | ||
680 | #endif | ||
681 | } | ||
682 | -#endif | ||
683 | |||
684 | static bool trans_hlvx_hu(DisasContext *ctx, arg_hlvx_hu *a) | ||
685 | { | ||
686 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
687 | index XXXXXXX..XXXXXXX 100644 | ||
688 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
689 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
690 | @@ -XXX,XX +XXX,XX @@ static bool trans_sw(DisasContext *ctx, arg_sw *a) | ||
691 | return gen_store(ctx, a, MO_TESL); | ||
692 | } | ||
693 | |||
694 | -#ifdef TARGET_RISCV64 | ||
695 | static bool trans_lwu(DisasContext *ctx, arg_lwu *a) | ||
696 | { | ||
697 | + REQUIRE_64BIT(ctx); | ||
698 | return gen_load(ctx, a, MO_TEUL); | ||
699 | } | ||
700 | |||
701 | static bool trans_ld(DisasContext *ctx, arg_ld *a) | ||
702 | { | ||
703 | + REQUIRE_64BIT(ctx); | ||
704 | return gen_load(ctx, a, MO_TEQ); | ||
705 | } | ||
706 | |||
707 | static bool trans_sd(DisasContext *ctx, arg_sd *a) | ||
708 | { | ||
709 | + REQUIRE_64BIT(ctx); | ||
710 | return gen_store(ctx, a, MO_TEQ); | ||
711 | } | ||
712 | -#endif | ||
713 | |||
714 | static bool trans_addi(DisasContext *ctx, arg_addi *a) | ||
715 | { | ||
716 | @@ -XXX,XX +XXX,XX @@ static bool trans_and(DisasContext *ctx, arg_and *a) | ||
717 | return gen_arith(ctx, a, &tcg_gen_and_tl); | ||
718 | } | ||
719 | |||
720 | -#ifdef TARGET_RISCV64 | ||
721 | static bool trans_addiw(DisasContext *ctx, arg_addiw *a) | ||
722 | { | ||
723 | + REQUIRE_64BIT(ctx); | ||
724 | return gen_arith_imm_tl(ctx, a, &gen_addw); | ||
725 | } | ||
726 | |||
727 | static bool trans_slliw(DisasContext *ctx, arg_slliw *a) | ||
728 | { | ||
729 | + REQUIRE_64BIT(ctx); | ||
730 | TCGv source1; | ||
731 | source1 = tcg_temp_new(); | ||
732 | gen_get_gpr(source1, a->rs1); | ||
733 | @@ -XXX,XX +XXX,XX @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a) | ||
734 | |||
735 | static bool trans_srliw(DisasContext *ctx, arg_srliw *a) | ||
736 | { | ||
737 | + REQUIRE_64BIT(ctx); | ||
738 | TCGv t = tcg_temp_new(); | ||
739 | gen_get_gpr(t, a->rs1); | ||
740 | tcg_gen_extract_tl(t, t, a->shamt, 32 - a->shamt); | ||
741 | @@ -XXX,XX +XXX,XX @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a) | ||
742 | |||
743 | static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a) | ||
744 | { | ||
745 | + REQUIRE_64BIT(ctx); | ||
746 | TCGv t = tcg_temp_new(); | ||
747 | gen_get_gpr(t, a->rs1); | ||
748 | tcg_gen_sextract_tl(t, t, a->shamt, 32 - a->shamt); | ||
749 | @@ -XXX,XX +XXX,XX @@ static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a) | ||
750 | |||
751 | static bool trans_addw(DisasContext *ctx, arg_addw *a) | ||
752 | { | ||
753 | + REQUIRE_64BIT(ctx); | ||
754 | return gen_arith(ctx, a, &gen_addw); | ||
755 | } | ||
756 | |||
757 | static bool trans_subw(DisasContext *ctx, arg_subw *a) | ||
758 | { | ||
759 | + REQUIRE_64BIT(ctx); | ||
760 | return gen_arith(ctx, a, &gen_subw); | ||
761 | } | ||
762 | |||
763 | static bool trans_sllw(DisasContext *ctx, arg_sllw *a) | ||
764 | { | ||
765 | + REQUIRE_64BIT(ctx); | ||
766 | TCGv source1 = tcg_temp_new(); | ||
767 | TCGv source2 = tcg_temp_new(); | ||
768 | |||
769 | @@ -XXX,XX +XXX,XX @@ static bool trans_sllw(DisasContext *ctx, arg_sllw *a) | ||
770 | |||
771 | static bool trans_srlw(DisasContext *ctx, arg_srlw *a) | ||
772 | { | ||
773 | + REQUIRE_64BIT(ctx); | ||
774 | TCGv source1 = tcg_temp_new(); | ||
775 | TCGv source2 = tcg_temp_new(); | ||
776 | |||
777 | @@ -XXX,XX +XXX,XX @@ static bool trans_srlw(DisasContext *ctx, arg_srlw *a) | ||
778 | |||
779 | static bool trans_sraw(DisasContext *ctx, arg_sraw *a) | ||
780 | { | ||
781 | + REQUIRE_64BIT(ctx); | ||
782 | TCGv source1 = tcg_temp_new(); | ||
783 | TCGv source2 = tcg_temp_new(); | ||
784 | |||
785 | @@ -XXX,XX +XXX,XX @@ static bool trans_sraw(DisasContext *ctx, arg_sraw *a) | ||
786 | |||
787 | return true; | ||
788 | } | ||
789 | -#endif | ||
790 | |||
791 | static bool trans_fence(DisasContext *ctx, arg_fence *a) | ||
792 | { | ||
793 | diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc | ||
794 | index XXXXXXX..XXXXXXX 100644 | ||
795 | --- a/target/riscv/insn_trans/trans_rvm.c.inc | ||
796 | +++ b/target/riscv/insn_trans/trans_rvm.c.inc | ||
797 | @@ -XXX,XX +XXX,XX @@ static bool trans_remu(DisasContext *ctx, arg_remu *a) | ||
798 | return gen_arith(ctx, a, &gen_remu); | ||
799 | } | ||
800 | |||
801 | -#ifdef TARGET_RISCV64 | ||
802 | static bool trans_mulw(DisasContext *ctx, arg_mulw *a) | ||
803 | { | ||
804 | + REQUIRE_64BIT(ctx); | ||
805 | REQUIRE_EXT(ctx, RVM); | ||
806 | + | ||
807 | return gen_arith(ctx, a, &gen_mulw); | ||
808 | } | ||
809 | |||
810 | static bool trans_divw(DisasContext *ctx, arg_divw *a) | ||
811 | { | ||
812 | + REQUIRE_64BIT(ctx); | ||
813 | REQUIRE_EXT(ctx, RVM); | ||
814 | + | ||
815 | return gen_arith_div_w(ctx, a, &gen_div); | ||
816 | } | ||
817 | |||
818 | static bool trans_divuw(DisasContext *ctx, arg_divuw *a) | ||
819 | { | ||
820 | + REQUIRE_64BIT(ctx); | ||
821 | REQUIRE_EXT(ctx, RVM); | ||
822 | + | ||
823 | return gen_arith_div_uw(ctx, a, &gen_divu); | ||
824 | } | ||
825 | |||
826 | static bool trans_remw(DisasContext *ctx, arg_remw *a) | ||
827 | { | ||
828 | + REQUIRE_64BIT(ctx); | ||
829 | REQUIRE_EXT(ctx, RVM); | ||
830 | + | ||
831 | return gen_arith_div_w(ctx, a, &gen_rem); | ||
832 | } | ||
833 | |||
834 | static bool trans_remuw(DisasContext *ctx, arg_remuw *a) | ||
835 | { | ||
836 | + REQUIRE_64BIT(ctx); | ||
837 | REQUIRE_EXT(ctx, RVM); | ||
838 | + | ||
839 | return gen_arith_div_uw(ctx, a, &gen_remu); | ||
840 | } | ||
841 | -#endif | ||
842 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
843 | index XXXXXXX..XXXXXXX 100644 | ||
844 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
845 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
846 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
847 | gen_helper_vamominuw_v_w, | ||
848 | gen_helper_vamomaxuw_v_w | ||
849 | }; | ||
850 | -#ifdef TARGET_RISCV64 | ||
851 | static gen_helper_amo *const fnsd[18] = { | ||
852 | gen_helper_vamoswapw_v_d, | ||
853 | gen_helper_vamoaddw_v_d, | ||
854 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
855 | gen_helper_vamominud_v_d, | ||
856 | gen_helper_vamomaxud_v_d | ||
857 | }; | ||
858 | -#endif | ||
859 | |||
860 | if (tb_cflags(s->base.tb) & CF_PARALLEL) { | ||
861 | gen_helper_exit_atomic(cpu_env); | ||
862 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
863 | return true; | ||
864 | } else { | ||
865 | if (s->sew == 3) { | ||
866 | -#ifdef TARGET_RISCV64 | ||
867 | - fn = fnsd[seq]; | ||
868 | -#else | ||
869 | - /* Check done in amo_check(). */ | ||
870 | - g_assert_not_reached(); | ||
871 | -#endif | ||
872 | + if (!is_32bit(s)) { | ||
873 | + fn = fnsd[seq]; | ||
874 | + } else { | ||
875 | + /* Check done in amo_check(). */ | ||
876 | + g_assert_not_reached(); | ||
877 | + } | ||
878 | } else { | ||
879 | assert(seq < ARRAY_SIZE(fnsw)); | ||
880 | fn = fnsw[seq]; | ||
881 | @@ -XXX,XX +XXX,XX @@ static bool amo_check(DisasContext *s, arg_rwdvm* a) | ||
882 | ((1 << s->sew) >= 4)); | ||
883 | } | ||
884 | |||
885 | +static bool amo_check64(DisasContext *s, arg_rwdvm* a) | ||
886 | +{ | ||
887 | + return !is_32bit(s) && amo_check(s, a); | ||
888 | +} | ||
889 | + | ||
890 | GEN_VEXT_TRANS(vamoswapw_v, 0, rwdvm, amo_op, amo_check) | ||
891 | GEN_VEXT_TRANS(vamoaddw_v, 1, rwdvm, amo_op, amo_check) | ||
892 | GEN_VEXT_TRANS(vamoxorw_v, 2, rwdvm, amo_op, amo_check) | ||
893 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_TRANS(vamominw_v, 5, rwdvm, amo_op, amo_check) | ||
894 | GEN_VEXT_TRANS(vamomaxw_v, 6, rwdvm, amo_op, amo_check) | ||
895 | GEN_VEXT_TRANS(vamominuw_v, 7, rwdvm, amo_op, amo_check) | ||
896 | GEN_VEXT_TRANS(vamomaxuw_v, 8, rwdvm, amo_op, amo_check) | ||
897 | -#ifdef TARGET_RISCV64 | ||
898 | -GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check) | ||
899 | -GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check) | ||
900 | -GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check) | ||
901 | -GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check) | ||
902 | -GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check) | ||
903 | -GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check) | ||
904 | -GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check) | ||
905 | -GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check) | ||
906 | -GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check) | ||
907 | -#endif | ||
908 | +GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check64) | ||
909 | +GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check64) | ||
910 | +GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check64) | ||
911 | +GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check64) | ||
912 | +GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check64) | ||
913 | +GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check64) | ||
914 | +GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check64) | ||
915 | +GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check64) | ||
916 | +GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check64) | ||
917 | |||
918 | /* | ||
919 | *** Vector Integer Arithmetic Instructions | ||
920 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
921 | index XXXXXXX..XXXXXXX 100644 | ||
922 | --- a/target/riscv/meson.build | ||
923 | +++ b/target/riscv/meson.build | ||
924 | @@ -XXX,XX +XXX,XX @@ gen32 = [ | ||
925 | |||
926 | gen64 = [ | ||
927 | decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']), | ||
928 | - decodetree.process('insn32.decode', extra_args: [dir / 'insn32-64.decode', '--static-decode=decode_insn32']), | ||
929 | + decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), | ||
930 | ] | ||
931 | |||
932 | riscv_ss = ss.source_set() | ||
933 | -- | ||
934 | 2.31.1 | ||
935 | |||
936 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This patch removes the insn16-32.decode and insn16-64.decode decode | ||
2 | files and consolidates the instructions into the general RISC-V | ||
3 | insn16.decode decode tree. | ||
1 | 4 | ||
5 | This means that all of the instructions are avaliable in both the 32-bit | ||
6 | and 64-bit builds. This also means that we run a check to ensure we are | ||
7 | running a 64-bit softmmu before we execute the 64-bit only instructions. | ||
8 | This allows us to include the 32-bit instructions in the 64-bit build, | ||
9 | while also ensuring that 32-bit only software can not execute the | ||
10 | instructions. | ||
11 | |||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 01e2b0efeae311adc7ebf133c2cde6a7a37224d7.1619234854.git.alistair.francis@wdc.com | ||
15 | --- | ||
16 | target/riscv/insn16-32.decode | 28 ------------------- | ||
17 | target/riscv/insn16-64.decode | 36 ------------------------- | ||
18 | target/riscv/insn16.decode | 30 +++++++++++++++++++++ | ||
19 | target/riscv/insn_trans/trans_rvi.c.inc | 6 +++++ | ||
20 | target/riscv/meson.build | 11 +++----- | ||
21 | 5 files changed, 39 insertions(+), 72 deletions(-) | ||
22 | delete mode 100644 target/riscv/insn16-32.decode | ||
23 | delete mode 100644 target/riscv/insn16-64.decode | ||
24 | |||
25 | diff --git a/target/riscv/insn16-32.decode b/target/riscv/insn16-32.decode | ||
26 | deleted file mode 100644 | ||
27 | index XXXXXXX..XXXXXXX | ||
28 | --- a/target/riscv/insn16-32.decode | ||
29 | +++ /dev/null | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | -# | ||
32 | -# RISC-V translation routines for the RVXI Base Integer Instruction Set. | ||
33 | -# | ||
34 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
35 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
36 | -# | ||
37 | -# This program is free software; you can redistribute it and/or modify it | ||
38 | -# under the terms and conditions of the GNU General Public License, | ||
39 | -# version 2 or later, as published by the Free Software Foundation. | ||
40 | -# | ||
41 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
42 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
43 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
44 | -# more details. | ||
45 | -# | ||
46 | -# You should have received a copy of the GNU General Public License along with | ||
47 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
48 | - | ||
49 | -# *** RV32C Standard Extension (Quadrant 0) *** | ||
50 | -flw 011 ... ... .. ... 00 @cl_w | ||
51 | -fsw 111 ... ... .. ... 00 @cs_w | ||
52 | - | ||
53 | -# *** RV32C Standard Extension (Quadrant 1) *** | ||
54 | -jal 001 ........... 01 @cj rd=1 # C.JAL | ||
55 | - | ||
56 | -# *** RV32C Standard Extension (Quadrant 2) *** | ||
57 | -flw 011 . ..... ..... 10 @c_lwsp | ||
58 | -fsw 111 . ..... ..... 10 @c_swsp | ||
59 | diff --git a/target/riscv/insn16-64.decode b/target/riscv/insn16-64.decode | ||
60 | deleted file mode 100644 | ||
61 | index XXXXXXX..XXXXXXX | ||
62 | --- a/target/riscv/insn16-64.decode | ||
63 | +++ /dev/null | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | -# | ||
66 | -# RISC-V translation routines for the RVXI Base Integer Instruction Set. | ||
67 | -# | ||
68 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
69 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
70 | -# | ||
71 | -# This program is free software; you can redistribute it and/or modify it | ||
72 | -# under the terms and conditions of the GNU General Public License, | ||
73 | -# version 2 or later, as published by the Free Software Foundation. | ||
74 | -# | ||
75 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
76 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
77 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
78 | -# more details. | ||
79 | -# | ||
80 | -# You should have received a copy of the GNU General Public License along with | ||
81 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
82 | - | ||
83 | -# *** RV64C Standard Extension (Quadrant 0) *** | ||
84 | -ld 011 ... ... .. ... 00 @cl_d | ||
85 | -sd 111 ... ... .. ... 00 @cs_d | ||
86 | - | ||
87 | -# *** RV64C Standard Extension (Quadrant 1) *** | ||
88 | -{ | ||
89 | - illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0 | ||
90 | - addiw 001 . ..... ..... 01 @ci | ||
91 | -} | ||
92 | -subw 100 1 11 ... 00 ... 01 @cs_2 | ||
93 | -addw 100 1 11 ... 01 ... 01 @cs_2 | ||
94 | - | ||
95 | -# *** RV64C Standard Extension (Quadrant 2) *** | ||
96 | -{ | ||
97 | - illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0 | ||
98 | - ld 011 . ..... ..... 10 @c_ldsp | ||
99 | -} | ||
100 | -sd 111 . ..... ..... 10 @c_sdsp | ||
101 | diff --git a/target/riscv/insn16.decode b/target/riscv/insn16.decode | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/target/riscv/insn16.decode | ||
104 | +++ b/target/riscv/insn16.decode | ||
105 | @@ -XXX,XX +XXX,XX @@ lw 010 ... ... .. ... 00 @cl_w | ||
106 | fsd 101 ... ... .. ... 00 @cs_d | ||
107 | sw 110 ... ... .. ... 00 @cs_w | ||
108 | |||
109 | +# *** RV32C and RV64C specific Standard Extension (Quadrant 0) *** | ||
110 | +{ | ||
111 | + ld 011 ... ... .. ... 00 @cl_d | ||
112 | + flw 011 ... ... .. ... 00 @cl_w | ||
113 | +} | ||
114 | +{ | ||
115 | + sd 111 ... ... .. ... 00 @cs_d | ||
116 | + fsw 111 ... ... .. ... 00 @cs_w | ||
117 | +} | ||
118 | + | ||
119 | # *** RV32/64C Standard Extension (Quadrant 1) *** | ||
120 | addi 000 . ..... ..... 01 @ci | ||
121 | addi 010 . ..... ..... 01 @c_li | ||
122 | @@ -XXX,XX +XXX,XX @@ jal 101 ........... 01 @cj rd=0 # C.J | ||
123 | beq 110 ... ... ..... 01 @cb_z | ||
124 | bne 111 ... ... ..... 01 @cb_z | ||
125 | |||
126 | +# *** RV64C and RV32C specific Standard Extension (Quadrant 1) *** | ||
127 | +{ | ||
128 | + c64_illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0 | ||
129 | + addiw 001 . ..... ..... 01 @ci | ||
130 | + jal 001 ........... 01 @cj rd=1 # C.JAL | ||
131 | +} | ||
132 | +subw 100 1 11 ... 00 ... 01 @cs_2 | ||
133 | +addw 100 1 11 ... 01 ... 01 @cs_2 | ||
134 | + | ||
135 | # *** RV32/64C Standard Extension (Quadrant 2) *** | ||
136 | slli 000 . ..... ..... 10 @c_shift2 | ||
137 | fld 001 . ..... ..... 10 @c_ldsp | ||
138 | @@ -XXX,XX +XXX,XX @@ fld 001 . ..... ..... 10 @c_ldsp | ||
139 | } | ||
140 | fsd 101 ...... ..... 10 @c_sdsp | ||
141 | sw 110 . ..... ..... 10 @c_swsp | ||
142 | + | ||
143 | +# *** RV32C and RV64C specific Standard Extension (Quadrant 2) *** | ||
144 | +{ | ||
145 | + c64_illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0 | ||
146 | + ld 011 . ..... ..... 10 @c_ldsp | ||
147 | + flw 011 . ..... ..... 10 @c_lwsp | ||
148 | +} | ||
149 | +{ | ||
150 | + sd 111 . ..... ..... 10 @c_sdsp | ||
151 | + fsw 111 . ..... ..... 10 @c_swsp | ||
152 | +} | ||
153 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
154 | index XXXXXXX..XXXXXXX 100644 | ||
155 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
156 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
157 | @@ -XXX,XX +XXX,XX @@ static bool trans_illegal(DisasContext *ctx, arg_empty *a) | ||
158 | return true; | ||
159 | } | ||
160 | |||
161 | +static bool trans_c64_illegal(DisasContext *ctx, arg_empty *a) | ||
162 | +{ | ||
163 | + REQUIRE_64BIT(ctx); | ||
164 | + return trans_illegal(ctx, a); | ||
165 | +} | ||
166 | + | ||
167 | static bool trans_lui(DisasContext *ctx, arg_lui *a) | ||
168 | { | ||
169 | if (a->rd != 0) { | ||
170 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/target/riscv/meson.build | ||
173 | +++ b/target/riscv/meson.build | ||
174 | @@ -XXX,XX +XXX,XX @@ | ||
175 | # FIXME extra_args should accept files() | ||
176 | dir = meson.current_source_dir() | ||
177 | -gen32 = [ | ||
178 | - decodetree.process('insn16.decode', extra_args: [dir / 'insn16-32.decode', '--static-decode=decode_insn16', '--insnwidth=16']), | ||
179 | - decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), | ||
180 | -] | ||
181 | |||
182 | -gen64 = [ | ||
183 | - decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']), | ||
184 | +gen = [ | ||
185 | + decodetree.process('insn16.decode', extra_args: ['--static-decode=decode_insn16', '--insnwidth=16']), | ||
186 | decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), | ||
187 | ] | ||
188 | |||
189 | riscv_ss = ss.source_set() | ||
190 | -riscv_ss.add(when: 'TARGET_RISCV32', if_true: gen32) | ||
191 | -riscv_ss.add(when: 'TARGET_RISCV64', if_true: gen64) | ||
192 | +riscv_ss.add(gen) | ||
193 | riscv_ss.add(files( | ||
194 | 'cpu.c', | ||
195 | 'cpu_helper.c', | ||
196 | -- | ||
197 | 2.31.1 | ||
198 | |||
199 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | BugLink: https://gitlab.com/qemu-project/qemu/-/issues/47 | ||
2 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | Message-id: 024ce841221c1d15c74b253512428c4baca7e4ba.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/insn32.decode | 2 +- | ||
7 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
1 | 8 | ||
9 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/riscv/insn32.decode | ||
12 | +++ b/target/riscv/insn32.decode | ||
13 | @@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s | ||
14 | hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma | ||
15 | hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma | ||
16 | |||
17 | -# *** RV32H Base Instruction Set *** | ||
18 | +# *** RV64H Base Instruction Set *** | ||
19 | hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 | ||
20 | hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 | ||
21 | hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s | ||
22 | -- | ||
23 | 2.31.1 | ||
24 | |||
25 | diff view generated by jsdifflib |