From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
To: Alvin Chang <alvinga@andestech.com>,
qemu-riscv@nongnu.org, qemu-devel@nongnu.org
Cc: alistair.francis@wdc.com, bin.meng@windriver.com,
liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com,
vivahavey@gmail.com, Yu-Ming Chang <yumin686@andestech.com>
Subject: Re: [PATCH v2 2/2] target/riscv: Simpily support versioning of debug trigger module
Date: Fri, 28 Nov 2025 08:38:36 -0300 [thread overview]
Message-ID: <dbe5461f-2388-4dd0-a876-37d16bca2fa5@ventanamicro.com> (raw)
In-Reply-To: <20251126164329.2157287-3-alvinga@andestech.com>
On 11/26/25 1:43 PM, Alvin Chang wrote:
> To support multiple versions of debug specification, we have added
> "debug-1.0" CPU property. Now the debug trigger module inspects this
> property to determine the supported trigger types by the CPU. In this
> commit we validate written trigger type with CPU debug version. For
> example, the debug specification v0.13 does not support mcontrol6, and
> the indended tdata_csr_write() on tdata1 with type=mcontrol6 will be
I suppose you meant 'intended'.
With the typo fixed:
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ignored.
>
> If debug v1.0 is selected, the default trigger type is mcontrol6
> instead of legacy mcontrol.
>
> Signed-off-by: Alvin Chang <alvinga@andestech.com>
> Reviewed-by: Yu-Ming Chang <yumin686@andestech.com>
> ---
> target/riscv/debug.c | 56 +++++++++++++++++++++++++++++++++++++++++---
> target/riscv/debug.h | 1 +
> 2 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/target/riscv/debug.c b/target/riscv/debug.c
> index 5664466..5163193 100644
> --- a/target/riscv/debug.c
> +++ b/target/riscv/debug.c
> @@ -64,6 +64,26 @@ static tdata_avail tdata_mapping[TRIGGER_TYPE_NUM] = {
> [TRIGGER_TYPE_UNAVAIL] = { true, true, true }
> };
>
> +/* Valid trigger types supported by debug specification v0.13 */
> +static bool valid_trigger_type_v013[TRIGGER_TYPE_NUM] = {
> + [TRIGGER_TYPE_AD_MATCH] = true,
> + [TRIGGER_TYPE_INST_CNT] = true,
> + [TRIGGER_TYPE_INT] = true,
> + [TRIGGER_TYPE_EXCP] = true,
> + [TRIGGER_TYPE_UNAVAIL] = true
> +};
> +
> +/* Valid trigger types supported by debug specification v1.0 */
> +static bool valid_trigger_type_v100[TRIGGER_TYPE_NUM] = {
> + [TRIGGER_TYPE_AD_MATCH] = true,
> + [TRIGGER_TYPE_INST_CNT] = true,
> + [TRIGGER_TYPE_INT] = true,
> + [TRIGGER_TYPE_EXCP] = true,
> + [TRIGGER_TYPE_AD_MATCH6] = true,
> + [TRIGGER_TYPE_EXT_SRC] = true,
> + [TRIGGER_TYPE_DISABLED] = true
> +};
> +
> /* only breakpoint size 1/2/4/8 supported */
> static int access_size[SIZE_NUM] = {
> [SIZE_ANY] = 0,
> @@ -95,6 +115,20 @@ static inline target_ulong get_trigger_type(CPURISCVState *env,
> return extract_trigger_type(env, env->tdata1[trigger_index]);
> }
>
> +static inline bool validate_trigger_type(CPURISCVState *env,
> + target_ulong trigger_type)
> +{
> + if (trigger_type >= TRIGGER_TYPE_NUM) {
> + return false;
> + }
> +
> + if (riscv_cpu_cfg(env)->debug_1_00) {
> + return valid_trigger_type_v100[trigger_type];
> + }
> +
> + return valid_trigger_type_v013[trigger_type];
> +}
> +
> static trigger_action_t get_trigger_action(CPURISCVState *env,
> target_ulong trigger_index)
> {
> @@ -889,6 +923,13 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val)
> trigger_type = get_trigger_type(env, env->trigger_cur);
> }
>
> + if (!validate_trigger_type(env, trigger_type)) {
> + /* Since the tdada1.type is WARL, we simpily ignore write here. */
> + qemu_log_mask(LOG_UNIMP, "trigger type: %d is not supported\n",
> + trigger_type);
> + return;
> + }
> +
> switch (trigger_type) {
> case TRIGGER_TYPE_AD_MATCH:
> type2_reg_write(env, env->trigger_cur, tdata_index, val);
> @@ -918,8 +959,11 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val)
> target_ulong tinfo_csr_read(CPURISCVState *env)
> {
> /* assume all triggers support the same types of triggers */
> - return BIT(TRIGGER_TYPE_AD_MATCH) |
> - BIT(TRIGGER_TYPE_AD_MATCH6);
> + if (riscv_cpu_cfg(env)->debug_1_00) {
> + return BIT(TRIGGER_TYPE_AD_MATCH) | BIT(TRIGGER_TYPE_AD_MATCH6);
> + }
> +
> + return BIT(TRIGGER_TYPE_AD_MATCH);
> }
>
> void riscv_cpu_debug_excp_handler(CPUState *cs)
> @@ -1056,9 +1100,15 @@ void riscv_trigger_realize(CPURISCVState *env)
>
> void riscv_trigger_reset_hold(CPURISCVState *env)
> {
> - target_ulong tdata1 = build_tdata1(env, TRIGGER_TYPE_AD_MATCH, 0, 0);
> + target_ulong tdata1;
> int i;
>
> + if (riscv_cpu_cfg(env)->debug_1_00) {
> + tdata1 = build_tdata1(env, TRIGGER_TYPE_AD_MATCH6, 0, 0);
> + } else {
> + tdata1 = build_tdata1(env, TRIGGER_TYPE_AD_MATCH, 0, 0);
> + }
> +
> /* init to type 2 triggers */
> for (i = 0; i < RV_MAX_TRIGGERS; i++) {
> /*
> diff --git a/target/riscv/debug.h b/target/riscv/debug.h
> index f76b8f9..0127cb9 100644
> --- a/target/riscv/debug.h
> +++ b/target/riscv/debug.h
> @@ -43,6 +43,7 @@ typedef enum {
> TRIGGER_TYPE_AD_MATCH6 = 6, /* new address/data match trigger */
> TRIGGER_TYPE_EXT_SRC = 7, /* external source trigger */
> TRIGGER_TYPE_UNAVAIL = 15, /* trigger exists, but unavailable */
> + TRIGGER_TYPE_DISABLED = 15, /* trigger exists, but disabled */
> TRIGGER_TYPE_NUM
> } trigger_type_t;
>
prev parent reply other threads:[~2025-11-28 11:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 16:43 [PATCH v2 0/2] RISC-V: Initial support versioning of debug specification Alvin Chang via
2025-11-26 16:43 ` [PATCH v2 1/2] target/riscv: Add "debug-1.0" to specify debug specification v1.0 Alvin Chang via
2025-11-28 11:32 ` Daniel Henrique Barboza
2025-11-26 16:43 ` [PATCH v2 2/2] target/riscv: Simpily support versioning of debug trigger module Alvin Chang via
2025-11-28 11:38 ` Daniel Henrique Barboza [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbe5461f-2388-4dd0-a876-37d16bca2fa5@ventanamicro.com \
--to=dbarboza@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=alvinga@andestech.com \
--cc=bin.meng@windriver.com \
--cc=liwei1518@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=vivahavey@gmail.com \
--cc=yumin686@andestech.com \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.