1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Hi, | 3 | Hi, |
4 | 4 | ||
5 | Rebased and addressed Daniel's comments about the return type of the helper. | ||
6 | |||
7 | Thanks | ||
8 | |||
9 | [v12]: | ||
10 | Rebased and addressed Richard's comments about proper masking virtualized accesses. | ||
11 | |||
12 | Thanks | ||
13 | |||
14 | [v11]: | ||
15 | As suggested on the mailing list by Daniel, I'm resubmitting this series and keeping the original versioning number. | ||
16 | So that makes this one v11 and previous - v10. | ||
17 | Also I applied previously issues reviewed-by tags on some of the patches that were present in v9 series, but only for the code, that didn't change much. | ||
18 | For the others I'd really like to have them reviewed as there were a lot of comments on v9 series. | ||
19 | Also rebased on the current upstream. | ||
20 | |||
21 | Thanks | ||
22 | |||
23 | [v10]: | ||
24 | I've rebased this patch series and addressed Richard's and Daniel's comments. | ||
25 | Thanks | ||
26 | |||
27 | [v0]: | ||
5 | As Pointer Masking is finally ratified, these patches intend to update the existing code to the final version. | 28 | As Pointer Masking is finally ratified, these patches intend to update the existing code to the final version. |
6 | These patches have been submitted previously and I tried to address all the suggestions, but I'd suggest to review them from the clean slate and then finally push them to the repo. | 29 | These patches have been submitted previously and I tried to address all the suggestions, but I'd suggest to review them from the clean slate and then finally push them to the repo. |
7 | Thanks. | 30 | Thanks. |
8 | 31 | ||
9 | Alexey Baturo (7): | 32 | Alexey Baturo (7): |
... | ... | ||
17 | pointer masking | 40 | pointer masking |
18 | target/riscv: Apply pointer masking for virtualized memory accesses | 41 | target/riscv: Apply pointer masking for virtualized memory accesses |
19 | target/riscv: Enable updates for pointer masking variables and thus | 42 | target/riscv: Enable updates for pointer masking variables and thus |
20 | enable pointer masking extension | 43 | enable pointer masking extension |
21 | 44 | ||
22 | target/riscv/cpu.c | 19 +- | 45 | target/riscv/cpu.c | 19 +- |
23 | target/riscv/cpu.h | 51 ++-- | 46 | target/riscv/cpu.h | 50 ++--- |
24 | target/riscv/cpu_bits.h | 91 +----- | 47 | target/riscv/cpu_bits.h | 91 +-------- |
25 | target/riscv/cpu_cfg.h | 3 + | 48 | target/riscv/cpu_cfg.h | 3 + |
26 | target/riscv/cpu_helper.c | 124 ++++++--- | 49 | target/riscv/cpu_helper.c | 122 ++++++++---- |
27 | target/riscv/csr.c | 356 ++---------------------- | 50 | target/riscv/csr.c | 357 +++-------------------------------- |
28 | target/riscv/insn_trans/trans_rvh.c.inc | 11 + | 51 | target/riscv/internals.h | 44 +++++ |
29 | target/riscv/machine.c | 17 +- | 52 | target/riscv/machine.c | 17 +- |
30 | target/riscv/pmp.c | 14 +- | 53 | target/riscv/op_helper.c | 16 +- |
31 | target/riscv/pmp.h | 1 + | 54 | target/riscv/pmp.c | 14 +- |
32 | target/riscv/tcg/tcg-cpu.c | 5 +- | 55 | target/riscv/pmp.h | 1 + |
33 | target/riscv/translate.c | 51 ++-- | 56 | target/riscv/tcg/tcg-cpu.c | 5 +- |
34 | target/riscv/vector_helper.c | 18 +- | 57 | target/riscv/translate.c | 47 ++--- |
35 | 13 files changed, 224 insertions(+), 537 deletions(-) | 58 | target/riscv/vector_helper.c | 5 - |
59 | 14 files changed, 241 insertions(+), 550 deletions(-) | ||
36 | 60 | ||
37 | -- | 61 | -- |
38 | 2.39.5 | 62 | 2.39.5 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
3 | Zjpm extension is finally ratified. And it's much simplier compared to the experimental one. | 3 | Zjpm extension is finally ratified. And it's much simplier compared to the experimental one. |
4 | The newer version doesn't allow to specify custom mask or base for pointer masking. | 4 | The newer version doesn't allow to specify custom mask or base for pointer masking. |
5 | Instead it allows only certain options for masking top bits. | 5 | Instead it allows only certain options for masking top bits. |
6 | 6 | ||
7 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 7 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
8 | |||
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | 10 | --- |
9 | target/riscv/cpu.c | 13 +- | 11 | target/riscv/cpu.c | 13 +- |
10 | target/riscv/cpu.h | 33 +--- | 12 | target/riscv/cpu.h | 33 +--- |
11 | target/riscv/cpu_bits.h | 87 ---------- | 13 | target/riscv/cpu_bits.h | 87 ---------- |
12 | target/riscv/cpu_helper.c | 52 ------ | 14 | target/riscv/cpu_helper.c | 52 ------ |
... | ... | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | |||
5 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
4 | --- | 6 | --- |
5 | target/riscv/cpu.h | 8 ++++++++ | 7 | target/riscv/cpu.h | 8 ++++++++ |
6 | target/riscv/cpu_bits.h | 4 ++++ | 8 | target/riscv/cpu_bits.h | 4 ++++ |
7 | target/riscv/cpu_cfg.h | 3 +++ | 9 | target/riscv/cpu_cfg.h | 3 +++ |
8 | target/riscv/csr.c | 30 ++++++++++++++++++++++++++++++ | 10 | target/riscv/csr.c | 31 ++++++++++++++++++++++++++++++- |
9 | target/riscv/pmp.c | 14 +++++++++++--- | 11 | target/riscv/pmp.c | 14 +++++++++++--- |
10 | target/riscv/pmp.h | 1 + | 12 | target/riscv/pmp.h | 1 + |
11 | 6 files changed, 57 insertions(+), 3 deletions(-) | 13 | 6 files changed, 57 insertions(+), 4 deletions(-) |
12 | 14 | ||
13 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 15 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/cpu.h | 17 | --- a/target/riscv/cpu.h |
16 | +++ b/target/riscv/cpu.h | 18 | +++ b/target/riscv/cpu.h |
... | ... | ||
98 | mask |= MENVCFG_SSE; | 100 | mask |= MENVCFG_SSE; |
99 | } | 101 | } |
100 | + | 102 | + |
101 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ | 103 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ |
102 | + if (env_archcpu(env)->cfg.ext_smnpm && | 104 | + if (env_archcpu(env)->cfg.ext_smnpm && |
103 | + (get_field(val, MENVCFG_PMM) != PMM_FIELD_RESERVED)) { | 105 | + get_field(val, MENVCFG_PMM) != PMM_FIELD_RESERVED) { |
104 | + mask |= MENVCFG_PMM; | 106 | + mask |= MENVCFG_PMM; |
105 | + } | 107 | + } |
106 | } | 108 | } |
107 | env->menvcfg = (env->menvcfg & ~mask) | (val & mask); | 109 | env->menvcfg = (env->menvcfg & ~mask) | (val & mask); |
108 | 110 | ||
109 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno, | 111 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno, |
110 | target_ulong val) | ||
111 | { | 112 | { |
112 | uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE; | 113 | uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE; |
114 | RISCVException ret; | ||
113 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ | 115 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ |
114 | + if (env_archcpu(env)->cfg.ext_ssnpm && | 116 | + if (env_archcpu(env)->cfg.ext_ssnpm && |
115 | + riscv_cpu_mxl(env) == MXL_RV64 && | 117 | + riscv_cpu_mxl(env) == MXL_RV64 && |
116 | + (get_field(val, SENVCFG_PMM) != PMM_FIELD_RESERVED)) { | 118 | + get_field(val, SENVCFG_PMM) != PMM_FIELD_RESERVED) { |
117 | + mask |= SENVCFG_PMM; | 119 | + mask |= SENVCFG_PMM; |
118 | + } | 120 | + } |
119 | RISCVException ret; | ||
120 | 121 | ||
121 | ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); | 122 | ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); |
123 | if (ret != RISCV_EXCP_NONE) { | ||
122 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, | 124 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, |
123 | get_field(env->menvcfg, MENVCFG_SSE)) { | 125 | get_field(env->menvcfg, MENVCFG_SSE)) { |
124 | mask |= HENVCFG_SSE; | 126 | mask |= HENVCFG_SSE; |
125 | } | 127 | } |
126 | + | 128 | + |
127 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ | 129 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ |
128 | + if (env_archcpu(env)->cfg.ext_ssnpm && | 130 | + if (env_archcpu(env)->cfg.ext_ssnpm && |
129 | + (get_field(val, HENVCFG_PMM) != PMM_FIELD_RESERVED)) { | 131 | + get_field(val, HENVCFG_PMM) != PMM_FIELD_RESERVED) { |
130 | + mask |= HENVCFG_PMM; | 132 | + mask |= HENVCFG_PMM; |
131 | + } | 133 | + } |
132 | } | 134 | } |
133 | 135 | ||
134 | env->henvcfg = (env->henvcfg & ~mask) | (val & mask); | 136 | env->henvcfg = (env->henvcfg & ~mask) | (val & mask); |
135 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno, | 137 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno, |
136 | static RISCVException write_hstatus(CPURISCVState *env, int csrno, | 138 | static RISCVException write_hstatus(CPURISCVState *env, int csrno, |
137 | target_ulong val) | 139 | target_ulong val) |
138 | { | 140 | { |
141 | - env->hstatus = val; | ||
139 | + uint64_t mask = (target_ulong)-1; | 142 | + uint64_t mask = (target_ulong)-1; |
140 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ | 143 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ |
141 | + if (env_archcpu(env)->cfg.ext_ssnpm && | 144 | + if (!env_archcpu(env)->cfg.ext_ssnpm || |
142 | + (riscv_cpu_mxl(env) == MXL_RV64) && | 145 | + riscv_cpu_mxl(env) != MXL_RV64 || |
143 | + (get_field(val, HSTATUS_HUPMM) == PMM_FIELD_RESERVED)) { | 146 | + get_field(val, HSTATUS_HUPMM) == PMM_FIELD_RESERVED) { |
144 | + mask &= ~HSTATUS_HUPMM; | 147 | + mask &= ~HSTATUS_HUPMM; |
145 | + } | 148 | + } |
146 | + env->hstatus = (env->hstatus & ~mask) | (val & mask); | 149 | + env->hstatus = (env->hstatus & ~mask) | (val & mask); |
147 | + | 150 | + |
148 | env->hstatus = val; | ||
149 | if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) { | 151 | if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) { |
150 | qemu_log_mask(LOG_UNIMP, | 152 | qemu_log_mask(LOG_UNIMP, |
153 | "QEMU does not support mixed HSXLEN options."); | ||
151 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | 154 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
152 | index XXXXXXX..XXXXXXX 100644 | 155 | index XXXXXXX..XXXXXXX 100644 |
153 | --- a/target/riscv/pmp.c | 156 | --- a/target/riscv/pmp.c |
154 | +++ b/target/riscv/pmp.c | 157 | +++ b/target/riscv/pmp.c |
155 | @@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) | 158 | @@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) |
... | ... | ||
158 | int i; | 161 | int i; |
159 | + uint64_t mask = MSECCFG_MMWP | MSECCFG_MML; | 162 | + uint64_t mask = MSECCFG_MMWP | MSECCFG_MML; |
160 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ | 163 | + /* Update PMM field only if the value is valid according to Zjpm v1.0 */ |
161 | + if (riscv_cpu_cfg(env)->ext_smmpm && | 164 | + if (riscv_cpu_cfg(env)->ext_smmpm && |
162 | + riscv_cpu_mxl(env) == MXL_RV64 && | 165 | + riscv_cpu_mxl(env) == MXL_RV64 && |
163 | + (get_field(val, MSECCFG_PMM) != PMM_FIELD_RESERVED)) { | 166 | + get_field(val, MSECCFG_PMM) != PMM_FIELD_RESERVED) { |
164 | + mask |= MSECCFG_PMM; | 167 | + mask |= MSECCFG_PMM; |
165 | + } | 168 | + } |
166 | 169 | ||
167 | trace_mseccfg_csr_write(env->mhartid, val); | 170 | trace_mseccfg_csr_write(env->mhartid, val); |
168 | 171 | ||
... | ... | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | --- | 4 | --- |
5 | target/riscv/cpu.h | 5 +++ | 5 | target/riscv/cpu.h | 5 +++ |
6 | target/riscv/cpu_helper.c | 74 +++++++++++++++++++++++++++++++++++++++ | 6 | target/riscv/cpu_helper.c | 73 +++++++++++++++++++++++++++++++++++++++ |
7 | 2 files changed, 79 insertions(+) | 7 | 2 files changed, 78 insertions(+) |
8 | 8 | ||
9 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 9 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
10 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/riscv/cpu.h | 11 | --- a/target/riscv/cpu.h |
12 | +++ b/target/riscv/cpu.h | 12 | +++ b/target/riscv/cpu.h |
13 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | 13 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
14 | 14 | ||
15 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); | 15 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
16 | 16 | ||
17 | +bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); | 17 | +bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); |
18 | +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); | 18 | +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); |
19 | +int riscv_pm_get_pmlen(RISCVPmPmm pmm); | 19 | +uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm); |
20 | + | 20 | + |
21 | RISCVException riscv_csrr(CPURISCVState *env, int csrno, | 21 | RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
22 | target_ulong *ret_value); | 22 | target_ulong *ret_value); |
23 | + | 23 | + |
24 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | 24 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
... | ... | ||
89 | + virt_mem_en = ((satp_mode != VM_1_10_MBARE) && (priv_mode != PRV_M)); | 89 | + virt_mem_en = ((satp_mode != VM_1_10_MBARE) && (priv_mode != PRV_M)); |
90 | +#endif | 90 | +#endif |
91 | + return virt_mem_en; | 91 | + return virt_mem_en; |
92 | +} | 92 | +} |
93 | + | 93 | + |
94 | +int riscv_pm_get_pmlen(RISCVPmPmm pmm) | 94 | +uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm) |
95 | +{ | 95 | +{ |
96 | + switch (pmm) { | 96 | + switch (pmm) { |
97 | + case PMM_FIELD_DISABLED: | 97 | + case PMM_FIELD_DISABLED: |
98 | + return 0; | 98 | + return 0; |
99 | + case PMM_FIELD_PMLEN7: | 99 | + case PMM_FIELD_PMLEN7: |
100 | + return 7; | 100 | + return 7; |
101 | + case PMM_FIELD_PMLEN16: | 101 | + case PMM_FIELD_PMLEN16: |
102 | + return 16; | 102 | + return 16; |
103 | + default: | 103 | + default: |
104 | + g_assert_not_reached(); | 104 | + g_assert_not_reached(); |
105 | + } | 105 | + } |
106 | + return -1; | ||
107 | +} | 106 | +} |
108 | + | 107 | + |
109 | #ifndef CONFIG_USER_ONLY | 108 | #ifndef CONFIG_USER_ONLY |
110 | 109 | ||
111 | /* | 110 | /* |
112 | -- | 111 | -- |
113 | 2.39.5 | 112 | 2.39.5 | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | |||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
4 | --- | 8 | --- |
5 | target/riscv/cpu.h | 3 +++ | 9 | target/riscv/cpu.h | 3 +++ |
6 | target/riscv/cpu_helper.c | 3 +++ | 10 | target/riscv/cpu_helper.c | 3 +++ |
7 | target/riscv/translate.c | 5 +++++ | 11 | target/riscv/translate.c | 5 +++++ |
8 | 3 files changed, 11 insertions(+) | 12 | 3 files changed, 11 insertions(+) |
... | ... | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | |||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
4 | --- | 7 | --- |
5 | target/riscv/translate.c | 22 ++++++++++++++++------ | 8 | target/riscv/translate.c | 22 ++++++++++++++++------ |
6 | target/riscv/vector_helper.c | 16 ++++++++++++++++ | 9 | target/riscv/vector_helper.c | 16 ++++++++++++++++ |
7 | 2 files changed, 32 insertions(+), 6 deletions(-) | 10 | 2 files changed, 32 insertions(+), 6 deletions(-) |
8 | 11 | ||
... | ... | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | --- | 4 | --- |
5 | target/riscv/cpu.h | 2 ++ | 5 | target/riscv/cpu.h | 1 + |
6 | target/riscv/cpu_helper.c | 19 +++++++++++++++++++ | 6 | target/riscv/cpu_helper.c | 18 +++++++++++++++ |
7 | target/riscv/insn_trans/trans_rvh.c.inc | 11 +++++++++++ | 7 | target/riscv/internals.h | 44 ++++++++++++++++++++++++++++++++++++ |
8 | target/riscv/translate.c | 4 ++++ | 8 | target/riscv/op_helper.c | 16 ++++++------- |
9 | 4 files changed, 36 insertions(+) | 9 | target/riscv/vector_helper.c | 21 ----------------- |
10 | 5 files changed, 71 insertions(+), 29 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 12 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/cpu.h | 14 | --- a/target/riscv/cpu.h |
14 | +++ b/target/riscv/cpu.h | 15 | +++ b/target/riscv/cpu.h |
15 | @@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, BCFI_ENABLED, 28, 1) | ||
16 | /* If pointer masking should be applied and address sign extended */ | ||
17 | FIELD(TB_FLAGS, PM_PMM, 29, 2) | ||
18 | FIELD(TB_FLAGS, PM_SIGNEXTEND, 31, 1) | ||
19 | +FIELD(TB_FLAGS, PM_VPMM, 32, 2) | ||
20 | |||
21 | #ifdef TARGET_RISCV32 | ||
22 | #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) | ||
23 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu); | 16 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
24 | 17 | ||
25 | bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); | 18 | bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); |
26 | RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); | 19 | RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); |
27 | +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env); | 20 | +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env); |
28 | int riscv_pm_get_pmlen(RISCVPmPmm pmm); | 21 | uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm); |
29 | 22 | ||
30 | RISCVException riscv_csrr(CPURISCVState *env, int csrno, | 23 | RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
31 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 24 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
32 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/cpu_helper.c | 26 | --- a/target/riscv/cpu_helper.c |
34 | +++ b/target/riscv/cpu_helper.c | 27 | +++ b/target/riscv/cpu_helper.c |
35 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
36 | flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env)); | ||
37 | flags = FIELD_DP32(flags, TB_FLAGS, PM_PMM, riscv_pm_get_pmm(env)); | ||
38 | flags = FIELD_DP32(flags, TB_FLAGS, PM_SIGNEXTEND, pm_signext); | ||
39 | + flags = FIELD_DP64(flags, TB_FLAGS, PM_VPMM, riscv_pm_get_virt_pmm(env)); | ||
40 | |||
41 | *pflags = flags; | ||
42 | } | ||
43 | @@ -XXX,XX +XXX,XX @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env) | 28 | @@ -XXX,XX +XXX,XX @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env) |
44 | return pmm; | 29 | return pmm; |
45 | } | 30 | } |
46 | 31 | ||
47 | +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env) | 32 | +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env) |
... | ... | ||
63 | +} | 48 | +} |
64 | + | 49 | + |
65 | bool riscv_cpu_virt_mem_enabled(CPURISCVState *env) | 50 | bool riscv_cpu_virt_mem_enabled(CPURISCVState *env) |
66 | { | 51 | { |
67 | bool virt_mem_en = false; | 52 | bool virt_mem_en = false; |
68 | diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc | 53 | diff --git a/target/riscv/internals.h b/target/riscv/internals.h |
69 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
70 | --- a/target/riscv/insn_trans/trans_rvh.c.inc | 55 | --- a/target/riscv/internals.h |
71 | +++ b/target/riscv/insn_trans/trans_rvh.c.inc | 56 | +++ b/target/riscv/internals.h |
72 | @@ -XXX,XX +XXX,XX @@ static bool do_hlv(DisasContext *ctx, arg_r2 *a, | 57 | @@ -XXX,XX +XXX,XX @@ static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f) |
73 | TCGv dest = dest_gpr(ctx, a->rd); | 58 | /* Our implementation of CPUClass::has_work */ |
74 | TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | 59 | bool riscv_cpu_has_work(CPUState *cs); |
75 | 60 | ||
76 | + bool is_hlvx = (func == gen_helper_hyp_hlvx_hu) || | 61 | +/* Zjpm addr masking routine */ |
77 | + (func == gen_helper_hyp_hlvx_wu); | 62 | +static inline target_ulong adjust_addr_body(CPURISCVState *env, |
78 | + | 63 | + target_ulong addr, |
79 | + /* Apply Zjpm pointer masking */ | 64 | + bool is_virt) |
80 | + if (!is_hlvx) { | 65 | +{ |
81 | + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_vxl); | 66 | + if (riscv_cpu_mxl(env) == MXL_RV32) { |
82 | + } | 67 | + return addr; |
83 | + | 68 | + } |
84 | decode_save_opc(ctx, 0); | 69 | + RISCVPmPmm pmm = PMM_FIELD_DISABLED; |
85 | func(dest, tcg_env, addr); | 70 | + if (is_virt) { |
86 | gen_set_gpr(ctx, a->rd, dest); | 71 | + pmm = riscv_pm_get_virt_pmm(env); |
87 | @@ -XXX,XX +XXX,XX @@ static bool do_hsv(DisasContext *ctx, arg_r2_s *a, | 72 | + } else { |
88 | TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | 73 | + pmm = riscv_pm_get_pmm(env); |
89 | TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); | 74 | + } |
90 | 75 | + if (pmm == PMM_FIELD_DISABLED) { | |
91 | + /* Apply Zjpm pointer masking */ | 76 | + return addr; |
92 | + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_vxl); | 77 | + } |
93 | + | 78 | + uint32_t pmlen = riscv_pm_get_pmlen(pmm); |
94 | decode_save_opc(ctx, 0); | 79 | + bool signext = false; |
95 | func(tcg_env, addr, data); | 80 | + if (!is_virt) { |
96 | return true; | 81 | + signext = riscv_cpu_virt_mem_enabled(env); |
97 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 82 | + } |
98 | index XXXXXXX..XXXXXXX 100644 | 83 | + addr = addr << pmlen; |
99 | --- a/target/riscv/translate.c | 84 | + /* sign/zero extend masked address by N-1 bit */ |
100 | +++ b/target/riscv/translate.c | 85 | + if (signext) { |
101 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 86 | + addr = (target_long)addr >> pmlen; |
102 | TCGv zero; | 87 | + } else { |
103 | /* actual address width */ | 88 | + addr = addr >> pmlen; |
104 | uint8_t addr_xl; | 89 | + } |
105 | + uint8_t addr_vxl; | 90 | + return addr; |
106 | bool addr_signed; | 91 | +} |
107 | /* Ztso */ | 92 | + |
108 | bool ztso; | 93 | +static inline target_ulong adjust_addr(CPURISCVState *env, |
109 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 94 | + target_ulong addr) |
110 | ctx->cs = cs; | 95 | +{ |
111 | if (get_xl(ctx) == MXL_RV32) { | 96 | + return adjust_addr_body(env, addr, false); |
112 | ctx->addr_xl = 32; | 97 | +} |
113 | + ctx->addr_vxl = 32; | 98 | + |
114 | ctx->addr_signed = false; | 99 | +static inline target_ulong adjust_addr_virt(CPURISCVState *env, |
115 | } else { | 100 | + target_ulong addr) |
116 | int pm_pmm = FIELD_EX32(tb_flags, TB_FLAGS, PM_PMM); | 101 | +{ |
117 | ctx->addr_xl = 64 - riscv_pm_get_pmlen(pm_pmm); | 102 | + return adjust_addr_body(env, addr, true); |
118 | + int pm_vpmm = FIELD_EX64(tb_flags, TB_FLAGS, PM_VPMM); | 103 | +} |
119 | + ctx->addr_vxl = 64 - riscv_pm_get_pmlen(pm_vpmm); | 104 | + |
120 | ctx->addr_signed = FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND); | 105 | #endif |
121 | } | 106 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
122 | ctx->ztso = cpu->cfg.ext_ztso; | 107 | index XXXXXXX..XXXXXXX 100644 |
108 | --- a/target/riscv/op_helper.c | ||
109 | +++ b/target/riscv/op_helper.c | ||
110 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr) | ||
111 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
112 | MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx); | ||
113 | |||
114 | - return cpu_ldb_mmu(env, addr, oi, ra); | ||
115 | + return cpu_ldb_mmu(env, adjust_addr_virt(env, addr), oi, ra); | ||
116 | } | ||
117 | |||
118 | target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr) | ||
119 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr) | ||
120 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
121 | MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); | ||
122 | |||
123 | - return cpu_ldw_mmu(env, addr, oi, ra); | ||
124 | + return cpu_ldw_mmu(env, adjust_addr_virt(env, addr), oi, ra); | ||
125 | } | ||
126 | |||
127 | target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr) | ||
128 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr) | ||
129 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
130 | MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); | ||
131 | |||
132 | - return cpu_ldl_mmu(env, addr, oi, ra); | ||
133 | + return cpu_ldl_mmu(env, adjust_addr_virt(env, addr), oi, ra); | ||
134 | } | ||
135 | |||
136 | target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr) | ||
137 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr) | ||
138 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
139 | MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx); | ||
140 | |||
141 | - return cpu_ldq_mmu(env, addr, oi, ra); | ||
142 | + return cpu_ldq_mmu(env, adjust_addr_virt(env, addr), oi, ra); | ||
143 | } | ||
144 | |||
145 | void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
146 | @@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
147 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
148 | MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx); | ||
149 | |||
150 | - cpu_stb_mmu(env, addr, val, oi, ra); | ||
151 | + cpu_stb_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); | ||
152 | } | ||
153 | |||
154 | void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
155 | @@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
156 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
157 | MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); | ||
158 | |||
159 | - cpu_stw_mmu(env, addr, val, oi, ra); | ||
160 | + cpu_stw_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); | ||
161 | } | ||
162 | |||
163 | void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
164 | @@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
165 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
166 | MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); | ||
167 | |||
168 | - cpu_stl_mmu(env, addr, val, oi, ra); | ||
169 | + cpu_stl_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); | ||
170 | } | ||
171 | |||
172 | void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
173 | @@ -XXX,XX +XXX,XX @@ void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val) | ||
174 | int mmu_idx = check_access_hlsv(env, false, ra); | ||
175 | MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx); | ||
176 | |||
177 | - cpu_stq_mmu(env, addr, val, oi, ra); | ||
178 | + cpu_stq_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
183 | index XXXXXXX..XXXXXXX 100644 | ||
184 | --- a/target/riscv/vector_helper.c | ||
185 | +++ b/target/riscv/vector_helper.c | ||
186 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t log2_esz) | ||
187 | return scale < 0 ? vlenb >> -scale : vlenb << scale; | ||
188 | } | ||
189 | |||
190 | -static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr) | ||
191 | -{ | ||
192 | - if (riscv_cpu_mxl(env) == MXL_RV32) { | ||
193 | - return addr; | ||
194 | - } | ||
195 | - RISCVPmPmm pmm = riscv_pm_get_pmm(env); | ||
196 | - if (pmm == PMM_FIELD_DISABLED) { | ||
197 | - return addr; | ||
198 | - } | ||
199 | - int pmlen = riscv_pm_get_pmlen(pmm); | ||
200 | - bool signext = riscv_cpu_virt_mem_enabled(env); | ||
201 | - addr = addr << pmlen; | ||
202 | - /* sign/zero extend masked address by N-1 bit */ | ||
203 | - if (signext) { | ||
204 | - addr = (target_long)addr >> pmlen; | ||
205 | - } else { | ||
206 | - addr = addr >> pmlen; | ||
207 | - } | ||
208 | - return addr; | ||
209 | -} | ||
210 | - | ||
211 | /* | ||
212 | * This function checks watchpoint before real load operation. | ||
213 | * | ||
123 | -- | 214 | -- |
124 | 2.39.5 | 215 | 2.39.5 | diff view generated by jsdifflib |
1 | From: Alexey Baturo <baturo.alexey@gmail.com> | 1 | From: Alexey Baturo <baturo.alexey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> | 3 | Signed-off-by: Alexey Baturo <baturo.alexey@gmail.com> |
4 | |||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
4 | --- | 6 | --- |
5 | target/riscv/cpu.c | 6 ++++++ | 7 | target/riscv/cpu.c | 6 ++++++ |
6 | 1 file changed, 6 insertions(+) | 8 | 1 file changed, 6 insertions(+) |
7 | 9 | ||
8 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 10 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/riscv/cpu.c | 12 | --- a/target/riscv/cpu.c |
11 | +++ b/target/riscv/cpu.c | 13 | +++ b/target/riscv/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 14 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
13 | ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), | 15 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
14 | ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt), | 16 | ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), |
15 | ISA_EXT_DATA_ENTRY(svvptc, PRIV_VERSION_1_13_0, ext_svvptc), | 17 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), |
18 | + ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm), | ||
19 | + ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm), | ||
20 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), | ||
21 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), | ||
22 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), | ||
23 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), | ||
24 | ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), | ||
16 | + ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm), | 25 | + ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm), |
17 | + ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm), | 26 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), |
18 | + ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm), | 27 | ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), |
19 | ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba), | 28 | ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), |
20 | ISA_EXT_DATA_ENTRY(xtheadbb, PRIV_VERSION_1_11_0, ext_xtheadbb), | ||
21 | ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs), | ||
22 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 29 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
23 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), | 30 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), |
24 | MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false), | 31 | MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false), |
25 | MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), | 32 | MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), |
26 | + MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false), | 33 | + MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false), |
... | ... | diff view generated by jsdifflib |