RISC-V: Add preliminary textra trigger CSR functions
v2 cover RISC-V: Add preliminary textra trigger CSR functions
According to RISC-V Debug specification, the optional textra32 and textra64 trigger CSRs can be used to configure additional matching conditions for the triggers.
This series support to write MHVALUE and MHSELECT fields into textra32 and textra64 trigger CSRs. Besides, the additional matching condition between textra.MHVALUE and mcontext CSR is also implemented.
Changes from v1:
- Log that mhselect only supports 0 or 4 for now
- Simplify writing of tdata3
Alvin Chang (2):
target/riscv: Preliminary textra trigger CSR writting support target/riscv: Add textra matching condition for the triggers
target/riscv/cpu_bits.h | 10 +++ target/riscv/debug.c | 138 ++++++++++++++++++++++++++++++++++++++-- target/riscv/debug.h | 3 + 3 files changed, 144 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 target/riscv: Preliminary textra trigger CSR writting support
This commit allows program to write textra trigger CSR for type 2, 3, 6 triggers. In this preliminary patch, the textra.MHVALUE and the textra.MHSELECT fields are allowed to be configured. Other fields, such as textra.SBYTEMASK, textra.SVALUE, and textra.SSELECT, are hardwired to zero for now.
For textra.MHSELECT field, the only legal values are 0 (ignore) and 4 (mcontext). Writing 1~3 into textra.MHSELECT will be changed to 0, and writing 5~7 into textra.MHSELECT will be changed to 4. This behavior is aligned to RISC-V SPIKE simulator.
--- target/riscv/cpu_bits.h | 10 ++++++ target/riscv/debug.c | 75 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 6 deletions(-)
target/riscv/cpu_bits.h +10 -0
@@ -906,6 +906,16 @@ typedef enum RISCVException {#define JVT_BASE (~0x3F)/* Debug Sdtrig CSR masks */ +#define TEXTRA32_MHVALUE 0xFC000000 +#define TEXTRA32_MHSELECT 0x03800000 +#define TEXTRA32_SBYTEMASK 0x000C0000 +#define TEXTRA32_SVALUE 0x0003FFFC +#define TEXTRA32_SSELECT 0x00000003 +#define TEXTRA64_MHVALUE 0xFFF8000000000000ULL +#define TEXTRA64_MHSELECT 0x0007000000000000ULL +#define TEXTRA64_SBYTEMASK 0x000000F000000000ULL +#define TEXTRA64_SVALUE 0x00000003FFFFFFFCULL +#define TEXTRA64_SSELECT 0x0000000000000003ULL#define MCONTEXT32 0x0000003F#define MCONTEXT64 0x0000000000001FFFULL#define MCONTEXT32_HCONTEXT 0x0000007F
target/riscv/debug.c +69 -6
99 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] target/riscv: Preliminary textra trigger CSR writting support
Quoted 99 lines · Alvin Chang via
This commit allows program to write textra trigger CSR for type 2, 3, 6 triggers. In this preliminary patch, the textra.MHVALUE and the textra.MHSELECT fields are allowed to be configured. Other fields, such as textra.SBYTEMASK, textra.SVALUE, and textra.SSELECT, are hardwired to zero for now.
For textra.MHSELECT field, the only legal values are 0 (ignore) and 4 (mcontext). Writing 1~3 into textra.MHSELECT will be changed to 0, and writing 5~7 into textra.MHSELECT will be changed to 4. This behavior is aligned to RISC-V SPIKE simulator.
Signed-off-by Alvin Chang <[email protected]>--- target/riscv/cpu_bits.h | 10 ++++++ target/riscv/debug.c | 75 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 6 deletions(-)target/riscv/cpu_bits.h +10
-0@@ -906,6 +906,16 @@ typedef enum RISCVException {#define JVT_BASE (~0x3F)/* Debug Sdtrig CSR masks */ +#define TEXTRA32_MHVALUE 0xFC000000 +#define TEXTRA32_MHSELECT 0x03800000 +#define TEXTRA32_SBYTEMASK 0x000C0000 +#define TEXTRA32_SVALUE 0x0003FFFC +#define TEXTRA32_SSELECT 0x00000003 +#define TEXTRA64_MHVALUE 0xFFF8000000000000ULL +#define TEXTRA64_MHSELECT 0x0007000000000000ULL +#define TEXTRA64_SBYTEMASK 0x000000F000000000ULL +#define TEXTRA64_SVALUE 0x00000003FFFFFFFCULL +#define TEXTRA64_SSELECT 0x0000000000000003ULL#define MCONTEXT32 0x0000003F#define MCONTEXT64 0x0000000000001FFFULL#define MCONTEXT32_HCONTEXT 0x0000007Ftarget/riscv/debug.c +52
-0@@ -217,6 +217,72 @@ static inline void warn_always_zero_bit(target_ulong val, target_ulong mask, } } +static target_ulong textra_validate (CPURISCVState *env,target_ulong tdata3) +{ +target_ulong mhvalue, mhselect; +target_ulong mhselect_new; +target_ulong textra; +const uint32_t mhselect_no_rvh[8 ] = {0 ,0 ,0 ,0 ,4 ,4 ,4 ,4 }; + +switch (riscv_cpu_mxl (env)) { +case MXL_RV32 : + mhvalue =get_field (tdata3,TEXTRA32_MHVALUE ); + mhselect =get_field (tdata3,TEXTRA32_MHSELECT ); +/* Validate unimplemented (always zero) bits */ +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA32_SBYTEMASK , +"sbytemask" ); +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA32_SVALUE , +"svalue" ); +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA32_SSELECT , +"sselect" ); +break ; +case MXL_RV64 : +case MXL_RV128 : + mhvalue =get_field (tdata3,TEXTRA64_MHVALUE ); + mhselect =get_field (tdata3,TEXTRA64_MHSELECT ); +/* Validate unimplemented (always zero) bits */ +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA64_SBYTEMASK , +"sbytemask" ); +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA64_SVALUE , +"svalue" ); +warn_always_zero_bit (tdata3, (target_ulong )TEXTRA64_SSELECT , +"sselect" ); +break ; +default : +g_assert_not_reached (); + } + +/* Validate mhselect. */ + mhselect_new = mhselect_no_rvh[mhselect]; +if (mhselect != mhselect_new) { +qemu_log_mask (LOG_UNIMP ,"mhselect only supports 0 or 4 for now\n" ); + } + +/* Write legal values into textra */ + textra =0 ; +switch (riscv_cpu_mxl (env)) { +case MXL_RV32 : + textra =set_field (textra,TEXTRA32_MHVALUE , mhvalue); + textra =set_field (textra,TEXTRA32_MHSELECT , mhselect_new); +break ; +case MXL_RV64 : +case MXL_RV128 : + textra =set_field (textra,TEXTRA64_MHVALUE , mhvalue); + textra =set_field (textra,TEXTRA64_MHSELECT , mhselect_new);
target/riscv/debug.c static inline void warn_always_zero_bit(target_ulong val, target_ulong mask, · line 281
Quoted 10 lines
target/riscv/debug.c +10
-0+break ; +default : +g_assert_not_reached (); + } + +if (textra != tdata3) { +qemu_log_mask (LOG_GUEST_ERROR , +"different value 0x" TARGET_FMT_lx" write to tdata3\n" , + textra); + }
You don't need this, you have already reported on all of the possible differences
With the above removed
Alistair
PATCH v2 2/2 target/riscv: Add textra matching condition for the triggers
In reply to Alvin Chang viaAccording to RISC-V Debug specification, the optional textra32 and textra64 trigger CSRs can be used to configure additional matching conditions for the triggers. For example, if the textra.MHSELECT field is set to 4 (mcontext), this trigger will only match or fire if the low bits of mcontext/hcontext equal textra.MHVALUE field.
This commit adds the aforementioned matching condition as common trigger matching conditions. Currently, the only legal values of textra.MHSELECT are 0 (ignore) and 4 (mcontext). When textra.MHSELECT is 0, we pass the checking. When textra.MHSELECT is 4, we compare textra.MHVALUE with mcontext CSR. The remaining fields, such as textra.SBYTEMASK, textra.SVALUE, and textra.SSELECT, are hardwired to zero for now. Thus, we skip checking them here.
--- target/riscv/debug.c | 63 +++++++++++++++++++++++++++++++++++++++++++- target/riscv/debug.h | 3 +++ 2 files changed, 65 insertions(+), 1 deletion(-)
target/riscv/debug.c +62 -1
@@ -370,11 +370,72 @@ static bool trigger_priv_match(CPURISCVState *env, trigger_type_t type,return false; } +static bool trigger_textra_match (CPURISCVState *env,trigger_type_t type, +int trigger_index) +{ +target_ulong textra = env->tdata3[trigger_index]; +target_ulong mhvalue, mhselect; + +if (type <TRIGGER_TYPE_AD_MATCH || type >TRIGGER_TYPE_AD_MATCH6 ) { +/* textra checking is only applicable when type is 2, 3, 4, 5, or 6 */ +return true; + } + +switch (riscv_cpu_mxl (env)) { +case MXL_RV32 : + mhvalue =get_field (textra,TEXTRA32_MHVALUE ); + mhselect =get_field (textra,TEXTRA32_MHSELECT ); +break ; +case MXL_RV64 : +case MXL_RV128 : + mhvalue =get_field (textra,TEXTRA64_MHVALUE ); + mhselect =get_field (textra,TEXTRA64_MHSELECT ); +break ; +default : +g_assert_not_reached (); + } + +/* Check mhvalue and mhselect. */ +switch (mhselect) { +case MHSELECT_IGNORE : +break ; +case MHSELECT_MCONTEXT : +/* Match or fire if the low bits of mcontext/hcontext equal mhvalue. */ +if (riscv_has_ext (env,RVH )) { +if (mhvalue != env->mcontext) { +return false; + } + }else { +switch (riscv_cpu_mxl (env)) { +case MXL_RV32 : +if (mhvalue != (env->mcontext &MCONTEXT32 )) { +return false; + } +break ; +case MXL_RV64 : +case MXL_RV128 : +if (mhvalue != (env->mcontext &MCONTEXT64 )) { +return false; + } +break ; +default : +g_assert_not_reached (); + } + } +break ; +default : +break ; + } + +return true; +} +/* Common matching conditions for all types of the triggers. */ static bool trigger_common_match (CPURISCVState *env,trigger_type_t type,int trigger_index) { -return trigger_priv_match (env, type, trigger_index); +return trigger_priv_match (env, type, trigger_index) && +trigger_textra_match (env, type, trigger_index); }/* type 2 trigger */
target/riscv/debug.h +3 -0
@@ -131,6 +131,9 @@ enum {#define ITRIGGER_VU BIT(25)#define ITRIGGER_VS BIT(26) +#define MHSELECT_IGNORE 0 +#define MHSELECT_MCONTEXT 4 +bool tdata_available (CPURISCVState *env,int tdata_index);target_ulong tselect_csr_read (CPURISCVState *env);
Signature · 1 line
2.34.1