From nobody Mon Feb 2 07:32:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1769752951; cv=none; d=zohomail.com; s=zohoarc; b=eGEkWOS8NOMfpleDErX0whwtyt/wVkhNRn32hgK4IdMORZh4LVQdILF5GJ1mUF0YkPSBOzUJHglenb94y2BPecp4wR9jUZFKgqAelMBbNiT4M22gzlixZCYxYmdWyqkHwIeU87V2mM0GZvshk9JxngafQR+DY0/5h73Q6xxjaak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769752951; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O7WkHiVNJCD9TWHbxn4o1h9ogKNZelcybfMD61+3Zog=; b=jTcCOOHrNpEz9ZlUemx4XkdJTMK6G81JAGhEIxzlsih/jQhe+8Bbia8+IybAkHn7ExmR9AGV0Cz+eKRb+CyLGnw5/+wlnkyOflPCcS1NTOKn2gucWJXm/aMQGHurL/iPSwDYGgZ9Fqc/4S5/jWViY8WqFeieSduMQvLdEI5nIV4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769752951289294.4020577868316; Thu, 29 Jan 2026 22:02:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vlhZV-0004lE-DL; Fri, 30 Jan 2026 01:01:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vlhZS-0004ib-IZ for qemu-devel@nongnu.org; Fri, 30 Jan 2026 01:01:30 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vlhZQ-0000pm-NW for qemu-devel@nongnu.org; Fri, 30 Jan 2026 01:01:30 -0500 Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-2a07fac8aa1so12262205ad.1 for ; Thu, 29 Jan 2026 22:01:28 -0800 (PST) Received: from ZEVORN-PC.bbrouter ([183.195.20.181]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a88b3f6d77sm66274585ad.2.2026.01.29.22.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 22:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769752887; x=1770357687; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O7WkHiVNJCD9TWHbxn4o1h9ogKNZelcybfMD61+3Zog=; b=I1aywIW646BWwifIpMCVG5pjIQ3zQrmFCAE/GGRQNW97WogFrYQafOXtfpIGPmOpnG 1wOaZOVFAmy7e1xtniUkknJWWBIMP56cgBxcZqbEE6IEI67o7WMzVEEKHEJ1N+qEuSlD Hh6Ess7UVYtf2Qx6WYmyrv0he6ZKQeAUaiwPU1bddNdfGKD7xGEYDf2d/ox2r3hnl3Dk 6JrUNlZoq7ZLkrBgTvgf00Hb4OQX5Yg3Y3OL43NqlOxOYUBDGxGYwAqkG8kBjOnzGtLO 05vemSPvkJb7RVKHPY4EcPojC5k2enkRIUaXtxvpm3ht7m3neyOIeKFt34zNP7bUn8E9 LsHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769752887; x=1770357687; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=O7WkHiVNJCD9TWHbxn4o1h9ogKNZelcybfMD61+3Zog=; b=jA4T+nYciNJ4Zlw7dRFoBt1GJa8DauJ7zPP/tTZ80xupQXdFJulpY98X9hWJsehwo1 HQWryXfbYjBCZVYzD7Ox0Zy+gNKxVcTpiz39Db1QwSlsaEBo+6ETSWbcIxzGVNCZr2CF B1tFdQlqWmaOg4htcZvvH3CyuI7DqCOGbQEIpNsxCapTRKVFVXGd96UBTt8v4Bx6aM88 VoNKSdEFtZ1rhewUmOaefhgKKuM9AwcRfOukE7Pj3uh1K5L70BmxfuS/+1O48lruZEou GwEMOFe7rXke0PBz10KcG3v+sz9D+AtqdrKXqLJ8TZJ/CdMjqqmElMpWDCHjAJ75zqKe QJsw== X-Gm-Message-State: AOJu0YymPlAbGkA6Q44Egz8MXSUSzZr6ZV9s35O+Bu5SUL3dgEq+cE14 LGWuZhPOU0CUFNiPJ2azjf6nrebBeX2IxEKUS2XvGboF3/5C6nnGPr+G X-Gm-Gg: AZuq6aJsNFS/l/fxBSEBAIOmed9yh5V1IxR/2vkyZNIWceZ2fgGoh28wMo0/UPc2VNy XIsbZc6McAie+KqwncLwOls6SnwQ594JrWmjLrUlvB3esUC0j7u/KBgXuDbQGplJeOaZhf9lqAa QodFvsNxFfr7qAJ9q/rzOFzJ8p/+UJUqK7pGbJ8BamxSNehdEYgFjWq8+m5Dx+f8E09BJYy4Pg1 aqeNStDYwGDd4zTiiQlwsTcvB3mVDb1wrTsC20CeF/b35x3NN/Kq54nhXtXtFs3DVL9xL0TzhmU IcYt1kwYqqy6A1QYE2D3ZWzU2akuBS5Dr5alFIQUu9fWWU8S/VyljaQOv52+curi8BHx79NPNrS XFfoagk3AfvauJ/uGUU27W/xli0GG+nlGrVmZMMD7QjP3XmUDJ50HImTjm9h64znzzDICIEj/SO kZDTEHdS4yjBgHsAZiSCSfVnKTeD2h3TJHUfcTstTyprGr6I/Xt0XZBUwu0OE= X-Received: by 2002:a17:903:41d2:b0:2a0:ccef:a5d3 with SMTP id d9443c01a7336-2a8d7eb531amr24043985ad.3.1769752887362; Thu, 29 Jan 2026 22:01:27 -0800 (PST) From: Chao Liu To: Alistair Francis , Daniel Henrique Barboza , Palmer Dabbelt , Weiwei Li , Liu Zhiwei Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, hust-os-kernel-patches@googlegroups.com, wangjingwei@iscas.ac.cn, devel@lists.libvirt.org, Chao Liu Subject: [RFC PATCH v4 7/7] target/riscv: add sdtrig trigger action=debug mode Date: Fri, 30 Jan 2026 14:00:06 +0800 Message-ID: <8fe531a24703eb426a66618822649bf5ee78697f.1769751489.git.chao.liu.zevorn@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=chao.liu.zevorn@gmail.com; helo=mail-pl1-x641.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1769752953732158500 Content-Type: text/plain; charset="utf-8" RISC-V Debug Specification: https://github.com/riscv/riscv-debug-spec/releases/tag/1.0 Allow mcontrol/mcontrol6 action=3D1 when Sdext is enabled. When such a trigger hits, enter Debug Mode with cause=3Dtrigger and stop with EXCP_DEBUG. Also report inst-count triggers in tinfo and read their action field. Signed-off-by: Chao Liu --- target/riscv/debug.c | 53 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 5877a60c50..4e30d42905 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -110,6 +110,8 @@ static trigger_action_t get_trigger_action(CPURISCVStat= e *env, action =3D (tdata1 & TYPE6_ACTION) >> 12; break; case TRIGGER_TYPE_INST_CNT: + action =3D tdata1 & ITRIGGER_ACTION; + break; case TRIGGER_TYPE_INT: case TRIGGER_TYPE_EXCP: case TRIGGER_TYPE_EXT_SRC: @@ -280,6 +282,7 @@ static target_ulong textra_validate(CPURISCVState *env,= target_ulong tdata3) =20 static void do_trigger_action(CPURISCVState *env, target_ulong trigger_ind= ex) { + CPUState *cs =3D env_cpu(env); trigger_action_t action =3D get_trigger_action(env, trigger_index); =20 switch (action) { @@ -289,6 +292,21 @@ static void do_trigger_action(CPURISCVState *env, targ= et_ulong trigger_index) riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); break; case DBG_ACTION_DBG_MODE: + if (!env_archcpu(env)->cfg.ext_sdext) { + qemu_log_mask(LOG_UNIMP, + "trigger action=3Ddebug mode requires Sdext\n"); + riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); + } + riscv_cpu_enter_debug_mode(env, env->pc, DCSR_CAUSE_TRIGGER); + /* + * If this came from the Trigger Module's CPU breakpoint/watchpoin= t, + * we're already returning via EXCP_DEBUG. Otherwise, stop now. + */ + if (cs->exception_index !=3D EXCP_DEBUG) { + cs->exception_index =3D EXCP_DEBUG; + cpu_loop_exit_restore(cs, GETPC()); + } + break; case DBG_ACTION_TRACE0: case DBG_ACTION_TRACE1: case DBG_ACTION_TRACE2: @@ -441,6 +459,7 @@ static target_ulong type2_mcontrol_validate(CPURISCVSta= te *env, { target_ulong val; uint32_t size; + uint32_t action; =20 /* validate the generic part first */ val =3D tdata1_validate(env, ctrl, TRIGGER_TYPE_AD_MATCH); @@ -448,11 +467,25 @@ static target_ulong type2_mcontrol_validate(CPURISCVS= tate *env, /* validate unimplemented (always zero) bits */ warn_always_zero_bit(ctrl, TYPE2_MATCH, "match"); warn_always_zero_bit(ctrl, TYPE2_CHAIN, "chain"); - warn_always_zero_bit(ctrl, TYPE2_ACTION, "action"); warn_always_zero_bit(ctrl, TYPE2_TIMING, "timing"); warn_always_zero_bit(ctrl, TYPE2_SELECT, "select"); warn_always_zero_bit(ctrl, TYPE2_HIT, "hit"); =20 + action =3D (ctrl & TYPE2_ACTION) >> 12; + if (action =3D=3D DBG_ACTION_BP) { + val |=3D ctrl & TYPE2_ACTION; + } else if (action =3D=3D DBG_ACTION_DBG_MODE) { + if (env_archcpu(env)->cfg.ext_sdext) { + val |=3D ctrl & TYPE2_ACTION; + } else { + qemu_log_mask(LOG_UNIMP, + "trigger action=3Ddebug mode requires Sdext\n"); + } + } else { + qemu_log_mask(LOG_UNIMP, "trigger action: %u is not supported\n", + action); + } + /* validate size encoding */ size =3D type2_breakpoint_size(env, ctrl); if (access_size[size] =3D=3D -1) { @@ -569,6 +602,7 @@ static target_ulong type6_mcontrol6_validate(CPURISCVSt= ate *env, { target_ulong val; uint32_t size; + uint32_t action; =20 /* validate the generic part first */ val =3D tdata1_validate(env, ctrl, TRIGGER_TYPE_AD_MATCH6); @@ -576,11 +610,25 @@ static target_ulong type6_mcontrol6_validate(CPURISCV= State *env, /* validate unimplemented (always zero) bits */ warn_always_zero_bit(ctrl, TYPE6_MATCH, "match"); warn_always_zero_bit(ctrl, TYPE6_CHAIN, "chain"); - warn_always_zero_bit(ctrl, TYPE6_ACTION, "action"); warn_always_zero_bit(ctrl, TYPE6_TIMING, "timing"); warn_always_zero_bit(ctrl, TYPE6_SELECT, "select"); warn_always_zero_bit(ctrl, TYPE6_HIT, "hit"); =20 + action =3D (ctrl & TYPE6_ACTION) >> 12; + if (action =3D=3D DBG_ACTION_BP) { + val |=3D ctrl & TYPE6_ACTION; + } else if (action =3D=3D DBG_ACTION_DBG_MODE) { + if (env_archcpu(env)->cfg.ext_sdext) { + val |=3D ctrl & TYPE6_ACTION; + } else { + qemu_log_mask(LOG_UNIMP, + "trigger action=3Ddebug mode requires Sdext\n"); + } + } else { + qemu_log_mask(LOG_UNIMP, "trigger action: %u is not supported\n", + action); + } + /* validate size encoding */ size =3D extract32(ctrl, 16, 4); if (access_size[size] =3D=3D -1) { @@ -919,6 +967,7 @@ 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_INST_CNT) | BIT(TRIGGER_TYPE_AD_MATCH6); } =20 --=20 2.52.0