RISC-V: Add preliminary textra trigger CSR functions
v4 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 v3:
- Simplify the comparison between mcontext and textra.MHVALUE
Changes from v2:
- Remove redundant log
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 | 114 +++++++++++++++++++++++++++++++++++++--- target/riscv/debug.h | 3 ++ 3 files changed, 120 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 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 | 69 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 6 deletions(-)
target/riscv/cpu_bits.h +10 -0
@@ -947,6 +947,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 +63 -6
93 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 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 | 45 +++++++++++++++++++++++++++++++++++++++++++- target/riscv/debug.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-)
target/riscv/debug.c +44 -1
@@ -364,11 +364,54 @@ 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 if the low bits of mcontext/hcontext equal mhvalue. */ +if (mhvalue != env->mcontext) { +return false; + } +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
Re: [PATCH v4 2/2] target/riscv: Add textra matching condition for the triggers
On Mon, Aug 26, 2024 at 12:48 PM Alvin Chang via <[email protected]> wrote:
Your From is still wrong
Quoted 28 lines
According 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.
Signed-off-by Alvin Chang <[email protected]>--- target/riscv/debug.c | 45 +++++++++++++++++++++++++++++++++++++++++++- target/riscv/debug.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-)target/riscv/debug.c +0
-0@@ -364,11 +364,54 @@ static bool trigger_priv_match(CPURISCVState *env, trigger_type_t type,return false; }
target/riscv/debug.c static bool trigger_priv_match(CPURISCVState *env, trigger_type_t type, · line 375
Quoted 10 lines
target/riscv/debug.c +9
-0+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;
Shouldn't this be false?
Alistair
Quoted 61 lines
target/riscv/debug.c +35
-1+ } + +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 if the low bits of mcontext/hcontext equal mhvalue. */ +if (mhvalue != env->mcontext) { +return false; + } +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
-1@@ -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); --2.34.1
RE: [PATCH v4 2/2] target/riscv: Add textra matching condition for the triggers
Hi Alistair,
Quoted 10 lines
-----Original Message-----
From: Alistair Francis <[email protected]>
Sent: Friday, September 6, 2024 8:29 AM
To: Alvin Che-Chia Chang(張哲嘉) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] target/riscv: Add textra matching condition for the triggers
Quoted 6 lines
[EXTERNAL MAIL]
On Mon, Aug 26, 2024 at 12:48 PM Alvin Chang via
<[email protected]> wrote:Your From is still wrong
Oh sorry for inconvenience. Seems it randomly happens on our server. I will ask my colleagues.
Quoted 39 lines
target/riscv/debug.c static bool trigger_priv_match(CPURISCVState
Quoted 28 lines
According 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.
Signed-off-by Alvin Chang <[email protected]>--- target/riscv/debug.c | 45 +++++++++++++++++++++++++++++++++++++++++++- target/riscv/debug.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-)target/riscv/debug.c index renamed from target/riscv/debug.c +0
-0
d6b4a06144..c79b51af30100644target/riscv/debug.c +0
-0@@ -364,11 +364,54 @@ static bool trigger_priv_match(CPURISCVState*env,
trigger_type_ttype,target/riscv/debug.c static bool trigger_priv_match(CPURISCVState *env, trigger_type_t type,
Quoted 9 lines
target/riscv/debug.c +6
-0return 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) {
Quoted 5 lines
target/riscv/debug.c static bool trigger_priv_match(CPURISCVState · line 373
Quoted 1 line
target/riscv/debug.c +1
-0+/* textra checking is only applicable when type is 2, 3, 4, 5, or 6 */
target/riscv/debug.c static bool trigger_priv_match(CPURISCVState · line 374
Quoted 1 line
target/riscv/debug.c +1
-0+return true;Shouldn't this be false?
My idea is: only type 2, 3, 4, 5, 6 triggers need to further check textra CSR.
Other types of trigger should bypass check on textra CSR, which means they pass the check on textra CSR. Thus, return true should be correct.
Alvin
Quoted 59 lines
Alistair
Quoted 34 lines
target/riscv/debug.c +33
-0+ } + +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 if the low bits of mcontext/hcontext equal mhvalue. */ +if (mhvalue != env->mcontext) { +return false; + } +break ; +default : +break ; + } + +return true; +} +/* Common matching conditions for all types of the triggers. */ Quoted 1 line
static bool trigger_common_match(CPURISCVState *env,
trigger_type_ttype,
Quoted 20 lines
int trigger_index) {target/riscv/debug.c +2
-1-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 index renamed from target/riscv/debug.h +0
-0
c347863578..f76b8f944a100644target/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);
Quoted 5 lines
Quoted 5 lines
target/riscv/debug.h +0
-1target_ulong tselect_csr_read (CPURISCVState *env); --2.34.1
CONFIDENTIALITY NOTICE:
This e-mail (and its attachments) may contain confidential and legally privileged information or information protected from disclosure. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein is strictly prohibited. In this case, please immediately notify the sender by return e-mail, delete the message (and any accompanying documents) and destroy all printed hard copies. Thank you for your cooperation.
Copyright ANDES TECHNOLOGY CORPORATION - All Rights Reserved.
Re: [PATCH v4 2/2] target/riscv: Add textra matching condition for the triggers
In reply to Alvin Chang viaQuoted 15 lines · Alvin Chang via
According 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.
Quoted 1 line
Signed-off-by Alvin Chang <[email protected]>
Alistair
Quoted 83 lines
--- target/riscv/debug.c | 45 +++++++++++++++++++++++++++++++++++++++++++- target/riscv/debug.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-)target/riscv/debug.c +44
-1@@ -364,11 +364,54 @@ 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 if the low bits of mcontext/hcontext equal mhvalue. */ +if (mhvalue != env->mcontext) { +return false; + } +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
-1@@ -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); --2.34.1
Alistair Francis
AppliedQuoted 15 lines · Alvin Chang via
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 v3:
- Simplify the comparison between mcontext and textra.MHVALUEChanges from v2:
- Remove redundant log
Quoted 7 lines
Changes from v1:
- Log that mhselect only supports 0 or 4 for now
- Simplify writing of tdata3Alvin Chang (2):
target/riscv: Preliminary textra trigger CSR writting support target/riscv: Add textra matching condition for the triggers
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 10 lines
target/riscv/cpu_bits.h | 10 ++++ target/riscv/debug.c | 114 +++++++++++++++++++++++++++++++++++++--- target/riscv/debug.h | 3 ++ 3 files changed, 120 insertions(+), 7 deletions(-)--
2.34.1