From nobody Tue May 21 01:56:04 2024 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=1650501361; cv=none; d=zohomail.com; s=zohoarc; b=HkS0v/lJaZ81WUViZGy0s4PDjMSaewG0NiS9fClweFJzH1KmnO63x0lly9noknfQ3cW8liPWQ3c4VfJEpKI67x0hMyi9uqFL5Pe59DILuOx4G7+yKRtb8i7u8M5PqFMhWKs/bEXs3QL9w4Opm0oCtLkAnF0+OEgucWpeng+qaZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501361; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2Lz2G/hb97IGHtw6/0Pb9pbuc3s2oIBQewIdI5tbs3o=; b=PXF+WEim6SIIAh/6xmzxTkkhPfGP4tqY6J4Hyd0EP4CUGej/mCy5VNay/aerKoqlp5rDLMXGHK/NY8j/24darMFNNZFdrfSlO02CAYpNmo9dbvkhEdsrrFqMYb0tNY9QCD4C6+z9xQ1nOMKow2Pjy1+lG8L48vw9zN9FbAmhYH0= 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 165050136119576.94341221645209; Wed, 20 Apr 2022 17:36:01 -0700 (PDT) Received: from localhost ([::1]:47676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKng-0007gG-43 for importer@patchew.org; Wed, 20 Apr 2022 20:36:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlM-0004io-Mq; Wed, 20 Apr 2022 20:33:36 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:39473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKlK-0008Kd-Vg; Wed, 20 Apr 2022 20:33:36 -0400 Received: by mail-pg1-x52b.google.com with SMTP id q19so3242238pgm.6; Wed, 20 Apr 2022 17:33:34 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Lz2G/hb97IGHtw6/0Pb9pbuc3s2oIBQewIdI5tbs3o=; b=hRLguUpmm93O+I+Ct4uZiOz/VGJ3Umi8bVo2u8tibF1+HjXI6uFvit8XS5J+VgDMB6 pCJXAPuU4bHGBGXbKE40z48Vp2Cae1pnzNJzy7no+oem1VFqExcSfI+QIbSWd3xeEMGv NDfb8zLXdLnuPqTBqsU8pki93Q1GRBiWw4Q5Iab8QuIYxRydtdJcdSR3sGBOcMGINkon H74IYmwBqnIF3KGRcmFSzLF8+ade6Bvhythb4nl5EAy0xO7EoudHhC7h2zQYImUDpL4N /aRRky5830/PkaS1nuS6bH+5VDavuzbqZqAJ5gwRbESw+p+7yy0JK6hNge+VpVIbll0P k2bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Lz2G/hb97IGHtw6/0Pb9pbuc3s2oIBQewIdI5tbs3o=; b=m2rPCzGagXN5ZNrGBvw4J2Tte/hv8rt/NXH1P/comDTvZgiXtkxzgHTxt1G8xLrYQS qMg0tICYs9CRPN382MxRgsYh9xWlbj+NfJspR4eAF1IE8iFp7ImbzRyVeGXG0ZJeMzk2 9aFucqzmMFHd/+8Vr95fhMzBSiPO5ISkffstankj0sQ7AxaaHP0Qnnukr2XlUCIk+vsv tL35KTBUuAiAgXNLjm5OII8Me6qFDygFzB+6bLatmK9FNxoZ+Z1TVN6kFyN7HLYKi7Xy tgOOCdDEb5v+T4nTsGauwSsSnBnoXmm0yaRh0m0mka2/JBQS1DP8V1WziKUD5kqSeXSB BgKg== X-Gm-Message-State: AOAM532HDbso2BqT8CZ9+mtQvluqlnZj8hzCTu9k2CEMlPX8Sqtk4Zjj LyIb5isxrZf6BR4c78H4tFEG24fjd6k= X-Google-Smtp-Source: ABdhPJyCgJM2jS7Kk4/PvhoZOUniE27yATL0FFY6j7AuhEYNN0vllseMhipsJXDRqxZK8qvpp9gKQQ== X-Received: by 2002:a65:45c9:0:b0:3aa:2a19:4bb8 with SMTP id m9-20020a6545c9000000b003aa2a194bb8mr11249955pgr.500.1650501213401; Wed, 20 Apr 2022 17:33:33 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 1/6] target/riscv: debug: Implement debug related TCGCPUOps Date: Thu, 21 Apr 2022 08:33:19 +0800 Message-Id: <20220421003324.1134983-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::52b; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52b.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501363825100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng Implement .debug_excp_handler, .debug_check_{breakpoint, watchpoint} TCGCPUOps and hook them into riscv_tcg_ops. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- (no changes since v2) Changes in v2: - use 0 instead of GETPC() target/riscv/debug.h | 4 +++ target/riscv/cpu.c | 3 ++ target/riscv/debug.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index fbc5f946e2..fb21706e1c 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -105,4 +105,8 @@ void tselect_csr_write(CPURISCVState *env, target_ulong= val); target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index); void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val= ); =20 +void riscv_cpu_debug_excp_handler(CPUState *cs); +bool riscv_cpu_debug_check_breakpoint(CPUState *cs); +bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp); + #endif /* RISCV_DEBUG_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 94f9434411..8919928f4f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -880,6 +880,9 @@ static const struct TCGCPUOps riscv_tcg_ops =3D { .do_interrupt =3D riscv_cpu_do_interrupt, .do_transaction_failed =3D riscv_cpu_do_transaction_failed, .do_unaligned_access =3D riscv_cpu_do_unaligned_access, + .debug_excp_handler =3D riscv_cpu_debug_excp_handler, + .debug_check_breakpoint =3D riscv_cpu_debug_check_breakpoint, + .debug_check_watchpoint =3D riscv_cpu_debug_check_watchpoint, #endif /* !CONFIG_USER_ONLY */ }; =20 diff --git a/target/riscv/debug.c b/target/riscv/debug.c index c8cec39217..1a9392645e 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -337,3 +337,78 @@ void tdata_csr_write(CPURISCVState *env, int tdata_ind= ex, target_ulong val) =20 return write_func(env, env->trigger_cur, tdata_index, val); } + +void riscv_cpu_debug_excp_handler(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + + if (cs->watchpoint_hit) { + if (cs->watchpoint_hit->flags & BP_CPU) { + cs->watchpoint_hit =3D NULL; + riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); + } + } else { + if (cpu_breakpoint_test(cs, env->pc, BP_CPU)) { + riscv_raise_exception(env, RISCV_EXCP_BREAKPOINT, 0); + } + } +} + +bool riscv_cpu_debug_check_breakpoint(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + CPUBreakpoint *bp; + target_ulong ctrl; + target_ulong pc; + int i; + + QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { + for (i =3D 0; i < TRIGGER_TYPE2_NUM; i++) { + ctrl =3D env->type2_trig[i].mcontrol; + pc =3D env->type2_trig[i].maddress; + + if ((ctrl & TYPE2_EXEC) && (bp->pc =3D=3D pc)) { + /* check U/S/M bit against current privilege level */ + if ((ctrl >> 3) & BIT(env->priv)) { + return true; + } + } + } + } + + return false; +} + +bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + target_ulong ctrl; + target_ulong addr; + int flags; + int i; + + for (i =3D 0; i < TRIGGER_TYPE2_NUM; i++) { + ctrl =3D env->type2_trig[i].mcontrol; + addr =3D env->type2_trig[i].maddress; + flags =3D 0; + + if (ctrl & TYPE2_LOAD) { + flags |=3D BP_MEM_READ; + } + if (ctrl & TYPE2_STORE) { + flags |=3D BP_MEM_WRITE; + } + + if ((wp->flags & flags) && (wp->vaddr =3D=3D addr)) { + /* check U/S/M bit against current privilege level */ + if ((ctrl >> 3) & BIT(env->priv)) { + return true; + } + } + } + + return false; +} --=20 2.25.1 From nobody Tue May 21 01:56:04 2024 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=1650501476; cv=none; d=zohomail.com; s=zohoarc; b=J9/36aUcsjt9DQZpX3e8VeKKqwgBR2dZQwBQ21AM/Qroj+H6ptmvIVKKKv2OHifg/qRnJ2dOmJJXZ/RrksEROXBvnglGyx7q4DZnA+2wpn5BOIHwRWyJ9kv48FUt/pdK4kR05zcYOMWgKqDR1M0jk47qtEfR3m7aWhu2yaYLBrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501476; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P/pnhp1A4GJG7oK6uz/bK1pJd0JOqr3ziTmqekfUUDc=; b=N1Lhe4O+orWEMSwf2BNszOlZfeX7cgb0L76gJjXL8THgIgywsKogIsiSwa6yQ6+lIFwJ+ufXFZjy6jQ3FOAbXBW2cSFj/bj8rV8UHFK/ZlfsOG1s9muhJPYi32bNKBpBaboo8cAWeVcTuB3HA9x7r4anFtFHDYeddT6kHK3UNYQ= 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 1650501476202388.79364741883217; Wed, 20 Apr 2022 17:37:56 -0700 (PDT) Received: from localhost ([::1]:53852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKpX-0003Qu-4E for importer@patchew.org; Wed, 20 Apr 2022 20:37:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlP-0004pt-Bv; Wed, 20 Apr 2022 20:33:39 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:36824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKlN-0008L1-S4; Wed, 20 Apr 2022 20:33:39 -0400 Received: by mail-pj1-x102b.google.com with SMTP id ga4-20020a17090b038400b001d4b33c74ccso2443396pjb.1; Wed, 20 Apr 2022 17:33:37 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P/pnhp1A4GJG7oK6uz/bK1pJd0JOqr3ziTmqekfUUDc=; b=i7T+xQuR1cCLH9AduNJoBmfex0badMn+W2SUVR7cARiwQqMmKe5X+bSRKGnQpnusuW JDBcIj+9KtxR8XilK8wAfJq009by2sQBZcZd++IaUwBusBqGXnau3moSvbtpfintppNN SwfBMUte2NW0FVmDCR0OX91v6iOoYrPIlj3ZfCpsidmV0KLe5MeZn/ib+b45mIIblute 7Hj3WF1wFI9AcXrY/2FveN9LM9hvm0Mcrq2U5rhV3ufZO7fWfGOaZRqf31GLPRUPZAIe 5UwlXdExBAJJotJk3OtrcuYKYdBRsvGGS2yJEubV03EErWWEjgkl/zaaL08ObYLCN1km 104w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P/pnhp1A4GJG7oK6uz/bK1pJd0JOqr3ziTmqekfUUDc=; b=IdvoysdYErcP2W1kMrePNKJbW2ofPDghVjLsGqQDxdTy9+gtOZJmbm98wHafecRFNq vl3OoliBwyfsHlbQJGgxHaPFRQDkzEdLU1mrK4FEcPdLA601VG5S+iorhf38OzncsVZ0 RqoJAdlfELsEa93aLPht6ly0tS7x/5ggQ/73i8MGo8E/QJRng1uuCrqiZSGugPXmxZgT 5qWJ9Cx1trmDufKTjw8ygMQN+Szalhw6l8QDu1IZ3mOlUobZkW6rly3qyK6k64l91vEN i5fKqMkCJevHmv8AYZa64cbNPTGFtWZ2AVZuFKpAZJd9R3W6XVUMun78KJWdNx3jBWU7 4/PQ== X-Gm-Message-State: AOAM530xe66jUCElDdzLd/OPzgZ7WF6BedxrRZRRuHHNnCzZwry4hCQG ansIjY4zF24GWIoxfGJne4Q= X-Google-Smtp-Source: ABdhPJzaop1L3rgvA45CD61PD1pZCrNAjCTxVNc0Qq6K4pucO8Eue0uOITryWpyS038lmCJ721M8Gg== X-Received: by 2002:a17:90a:7e97:b0:1d2:7bcb:ee78 with SMTP id j23-20020a17090a7e9700b001d27bcbee78mr7455398pjl.40.1650501216282; Wed, 20 Apr 2022 17:33:36 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 2/6] target/riscv: cpu: Add a config option for native debug Date: Thu, 21 Apr 2022 08:33:20 +0800 Message-Id: <20220421003324.1134983-3-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::102b; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102b.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501477597100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng Add a config option to enable support for native M-mode debug. This is disabled by default and can be enabled with 'debug=3Dtrue'. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- (no changes since v2) Changes in v2: - change the config option to 'disabled' by default target/riscv/cpu.h | 4 +++- target/riscv/cpu.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 39a9ff17d3..62e53e3653 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -79,7 +79,8 @@ enum { RISCV_FEATURE_PMP, RISCV_FEATURE_EPMP, RISCV_FEATURE_MISA, - RISCV_FEATURE_AIA + RISCV_FEATURE_AIA, + RISCV_FEATURE_DEBUG }; =20 /* Privileged specification version */ @@ -405,6 +406,7 @@ struct RISCVCPUConfig { bool pmp; bool epmp; bool aia; + bool debug; uint64_t resetvec; }; =20 diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8919928f4f..477961b619 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -548,6 +548,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error = **errp) riscv_set_feature(env, RISCV_FEATURE_AIA); } =20 + if (cpu->cfg.debug) { + riscv_set_feature(env, RISCV_FEATURE_DEBUG); + } + set_resetvec(env, cpu->cfg.resetvec); =20 /* Validate that MISA_MXL is set properly. */ @@ -795,6 +799,7 @@ static Property riscv_cpu_properties[] =3D { DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), + DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, false), =20 DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), --=20 2.25.1 From nobody Tue May 21 01:56:04 2024 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=1650501634; cv=none; d=zohomail.com; s=zohoarc; b=P8oFDguZK8yjznu0jWtYY17vKKfCHDN1OLTyldBm5djI++yn/g1Wym/h5wT/TP/Z2FBhGGSkBTFXGZC6/9jeUWluUWeIQZljRixBQGopa8qgeZ7txtgsaCyl33H3EFz4uj7ZkhCXIETFgVOeCU+U4lkQlUbNzGURcj5F9KSYLmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501634; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pilLq+OstDyLRY1TYpKnSQvJeKND4ZKT0W2rSuEGaFY=; b=H44BC0o+P8B24u5Rx8fwFQJ6natQIPP4BckgXcg+M1f05yZhZ/6SYZrZyT6L7x0MsN+l1YhGDtf4z+dE9ZVTZYeV+mR+p9Xb8dTSKXY4dEuy0uno54Bc7HbbNkmaw6NPGF+/HiYr4i7bxZB68N2Ycra28RgXtZfgI4URkOx0hg4= 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 1650501634076526.2166711503459; Wed, 20 Apr 2022 17:40:34 -0700 (PDT) Received: from localhost ([::1]:58934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKs4-00076Q-Vb for importer@patchew.org; Wed, 20 Apr 2022 20:40:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlS-0004uV-WB; Wed, 20 Apr 2022 20:33:43 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKlR-0008LV-78; Wed, 20 Apr 2022 20:33:42 -0400 Received: by mail-pj1-x1036.google.com with SMTP id s14-20020a17090a880e00b001caaf6d3dd1so6321398pjn.3; Wed, 20 Apr 2022 17:33:40 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pilLq+OstDyLRY1TYpKnSQvJeKND4ZKT0W2rSuEGaFY=; b=ExnP5TwsgVInO28fmgmrsCmn1EA7juw7nBYXCG6mV/+NGRxgYcOhxtBC+midTzUZQ2 6+NaJVdSTkkXyn++vW1FJL0zHasmpO+HCyCADiMcN5QbJe+b8cEPJcPPnPI9NNpxVfTs u8agEqWHFqk2fp7bpKGmxbTtp3VVerdwgJ2sQZkTTpl1twYxt3AU4njUa4GpHyaonYZa eI18VLWnQN8TcdV6J5pYlOMwFPtVfWxDMLF97PLbvMGwVb9gK6Furcao7hDqoHfIbGLI jy6PlFLV1wIsPSfeRUOdRU0FPmJULg/DpYUkpqPGZ2qM5oE7lj7nqGdBktqTKZIplKZs Q8cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pilLq+OstDyLRY1TYpKnSQvJeKND4ZKT0W2rSuEGaFY=; b=rhuH987LnhXXtFwgbKjq4WQ0A8ZLL3MHRneCqkdMzSEwP1nVHnkeQaMdGB5GXzQ8pY 8/r9MbLg1zeaNIq/+nQabCJ8BbVqXs1JGHJK4I1w5/c2J8nXW5d/L5P+zMletkw6ltPg oFxulmfeXNn6rZDT3ZQITylD9Z1IH9+PPvoeUMIywySYQb0u6BbNpbr7PvFsL96cpHch +xC1GMOgaKMVEGIkkazFNK/AZO5a5mHCRtd7VNGNQMMEbQ+5jZQyXmv/9XAysVGS/3SG WTypz31sDP1xblGZzDZw+Emttd8DsV4+7O/NC8SUXee6NTyUof/sR8AXlvJMXwYAq8Bd IdMQ== X-Gm-Message-State: AOAM532KkIlPFQAy1LB2ucUOTSaaXRCsmXRPQpyU9SqXSKQKo9C3srkO /jASA5AdyWifE0BA0ELir2k= X-Google-Smtp-Source: ABdhPJxMVKu+L4xJd6MqMLGHx8NVIavwQlbJ1zSM+8fe6YggWQ/wyVCD0asP/EMmq6QZaswvkeYU/w== X-Received: by 2002:a17:90b:4d08:b0:1ce:8d09:1c58 with SMTP id mw8-20020a17090b4d0800b001ce8d091c58mr7355611pjb.168.1650501219687; Wed, 20 Apr 2022 17:33:39 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 3/6] target/riscv: csr: Hook debug CSR read/write Date: Thu, 21 Apr 2022 08:33:21 +0800 Message-Id: <20220421003324.1134983-4-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::1036; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1036.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501636125100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng This adds debug CSR read/write support to the RISC-V CSR RW table. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- (no changes since v4) Changes in v4: - move riscv_trigger_init() call to riscv_cpu_reset() Changes in v3: - add riscv_trigger_init(), moved from patch #1 to this patch target/riscv/debug.h | 2 ++ target/riscv/cpu.c | 4 ++++ target/riscv/csr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ target/riscv/debug.c | 27 +++++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index fb21706e1c..27b9cac6b4 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -109,4 +109,6 @@ void riscv_cpu_debug_excp_handler(CPUState *cs); bool riscv_cpu_debug_check_breakpoint(CPUState *cs); bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp); =20 +void riscv_trigger_init(CPURISCVState *env); + #endif /* RISCV_DEBUG_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 477961b619..85656cdcc3 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -466,6 +466,10 @@ static void riscv_cpu_reset(DeviceState *dev) set_default_nan_mode(1, &env->fp_status); =20 #ifndef CONFIG_USER_ONLY + if (riscv_feature(env, RISCV_FEATURE_DEBUG)) { + riscv_trigger_init(env); + } + if (kvm_enabled()) { kvm_riscv_reset_vcpu(cpu); } diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a09126a011..6ba85e7b5d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -290,6 +290,15 @@ static RISCVException epmp(CPURISCVState *env, int csr= no) =20 return RISCV_EXCP_ILLEGAL_INST; } + +static RISCVException debug(CPURISCVState *env, int csrno) +{ + if (riscv_feature(env, RISCV_FEATURE_DEBUG)) { + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; +} #endif =20 /* User Floating-Point CSRs */ @@ -2677,6 +2686,48 @@ static RISCVException write_pmpaddr(CPURISCVState *e= nv, int csrno, return RISCV_EXCP_NONE; } =20 +static RISCVException read_tselect(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val =3D tselect_csr_read(env); + return RISCV_EXCP_NONE; +} + +static RISCVException write_tselect(CPURISCVState *env, int csrno, + target_ulong val) +{ + tselect_csr_write(env, val); + return RISCV_EXCP_NONE; +} + +static RISCVException read_tdata(CPURISCVState *env, int csrno, + target_ulong *val) +{ + /* return 0 in tdata1 to end the trigger enumeration */ + if (env->trigger_cur >=3D TRIGGER_NUM && csrno =3D=3D CSR_TDATA1) { + *val =3D 0; + return RISCV_EXCP_NONE; + } + + if (!tdata_available(env, csrno - CSR_TDATA1)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + *val =3D tdata_csr_read(env, csrno - CSR_TDATA1); + return RISCV_EXCP_NONE; +} + +static RISCVException write_tdata(CPURISCVState *env, int csrno, + target_ulong val) +{ + if (!tdata_available(env, csrno - CSR_TDATA1)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + tdata_csr_write(env, csrno - CSR_TDATA1, val); + return RISCV_EXCP_NONE; +} + /* * Functions to access Pointer Masking feature registers * We have to check if current priv lvl could modify @@ -3418,6 +3469,12 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_PMPADDR14] =3D { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR15] =3D { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr }, =20 + /* Debug CSRs */ + [CSR_TSELECT] =3D { "tselect", debug, read_tselect, write_tselect }, + [CSR_TDATA1] =3D { "tdata1", debug, read_tdata, write_tdata }, + [CSR_TDATA2] =3D { "tdata2", debug, read_tdata, write_tdata }, + [CSR_TDATA3] =3D { "tdata3", debug, read_tdata, write_tdata }, + /* User Pointer Masking */ [CSR_UMTE] =3D { "umte", pointer_masking, read_umte, write= _umte }, [CSR_UPMMASK] =3D { "upmmask", pointer_masking, read_upmmask, write= _upmmask }, diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 1a9392645e..2f2a51c732 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -412,3 +412,30 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CP= UWatchpoint *wp) =20 return false; } + +void riscv_trigger_init(CPURISCVState *env) +{ + target_ulong type2 =3D trigger_type(env, TRIGGER_TYPE_AD_MATCH); + int i; + + /* type 2 triggers */ + for (i =3D 0; i < TRIGGER_TYPE2_NUM; i++) { + /* + * type =3D TRIGGER_TYPE_AD_MATCH + * dmode =3D 0 (both debug and M-mode can write tdata) + * maskmax =3D 0 (unimplemented, always 0) + * sizehi =3D 0 (match against any size, RV64 only) + * hit =3D 0 (unimplemented, always 0) + * select =3D 0 (always 0, perform match on address) + * timing =3D 0 (always 0, trigger before instruction) + * sizelo =3D 0 (match against any size) + * action =3D 0 (always 0, raise a breakpoint exception) + * chain =3D 0 (unimplemented, always 0) + * match =3D 0 (always 0, when any compare value equals tdata2) + */ + env->type2_trig[i].mcontrol =3D type2; + env->type2_trig[i].maddress =3D 0; + env->type2_trig[i].bp =3D NULL; + env->type2_trig[i].wp =3D NULL; + } +} --=20 2.25.1 From nobody Tue May 21 01:56:04 2024 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=1650501365; cv=none; d=zohomail.com; s=zohoarc; b=RqWJ+TAcp9Ez+t36ZWdu/K+i2V7b/GFHwe8JG07BAC7sebmGz1MVho0f44pA7M2oRIgvc9nJwYtqehc0npNVE44rizFXdDxzVXUJGrkOK756o6IP2yq9wJtgKG5nH7QzTJZ+3l0ERzIfZm3OuX+tyWHad6SKlq33Ye7QdHF9KZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501365; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GH2FT9hl0QobN2IwU/hnYZutReJp+9cZOVo+GqkwIiU=; b=ecBOaGC16/SpG8pPmkj0j3uJY0+Ot4dDiOcBnBWxXFG6Np+rK0+g/rxwrr5j1yYILRVHcZho+nnl1M4H5QO2LSUYbw1OJJCzRVaDYI29YdV2C8dkmrko0QE2poIRUx1ySreCBi6Sv4K7o2sLXhrNlbqswChMzS3WqAyK0NTHuuo= 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 1650501365736114.81850530318991; Wed, 20 Apr 2022 17:36:05 -0700 (PDT) Received: from localhost ([::1]:47976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKnk-0007sO-FV for importer@patchew.org; Wed, 20 Apr 2022 20:36:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlV-0004wt-RN; Wed, 20 Apr 2022 20:33:47 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:39546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKlU-0008Ls-Bd; Wed, 20 Apr 2022 20:33:45 -0400 Received: by mail-pf1-x436.google.com with SMTP id l127so3485046pfl.6; Wed, 20 Apr 2022 17:33:43 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GH2FT9hl0QobN2IwU/hnYZutReJp+9cZOVo+GqkwIiU=; b=C9PFtI82dw5q4V2bl8D/5mFH7h0TaR2vKI3CsCCq9vk3KlYDjO64HJYKgWQYTCwP+u ndyg8Co57Dhr78EkW6VOEhk8FFMp/NPmfSjOzXgroI7cwg+v8Bfrq93BAYkbYCxp1Q/g T8C/gbCAB2/asDKdwoOuwUy1rlKbo9dNYuiLvZIVLXIO57Q9z/CSssJCFT1XkQ0yknq9 vqXMeTXSlygUfkd0sSR4p1TM8vOGb8SI4jqPLgY3tUVMStn9dx+zT6BDzvqbfb4aP96T +PYH4Iy8GeEFYOxxdTDM0Y7jW3zpwHUH1OQ2Bpqz3IuyMqm8Tf+rcilaIf++Ci6hbypd BPrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GH2FT9hl0QobN2IwU/hnYZutReJp+9cZOVo+GqkwIiU=; b=3eHx9nQ23h3pa2P/cwpVjsx+diBNzt850se+Y8IcqusQ1KFtxi9xeJtFZ0nlapw+iH GuEedPrQVg3aYK/G9YbnzIh5pV5JuuSrQiIe2axN+siyt5BFRu1qGUBjC0UWOb5+pC/s ZPHapj40eXb++Pl8uSdox1YzmahSSijm3SOgovjOhCwAZ+zC2Lm0xXtj/h+qJLXHpmea f9gRpAYEPy1hTPkdxQJvTRke0SwaIJSu349rOsrBzRB46T9tSYW7uwbA8mNbRtvXM6XE 7MXqDLVxBkUvRRWlrQxLt+b9qM/ViTo4fbaood1rggt4RZAngGEVVy+otQl6lK9dy6kr fdUw== X-Gm-Message-State: AOAM533t1k6UNGcLgRzSsNjHINOtpsuaXHUU6ArXZ8yWYqglKeKjdt7v DwPBZvYVqA/KB4PtDUD0BoE= X-Google-Smtp-Source: ABdhPJw7wGcIlOgd9mjfeldRwDzH6wLAK3A8+EVnC+Rh09nv5SgSyUE4rXqdLInqT+znjD6eR90NSQ== X-Received: by 2002:a63:5518:0:b0:3a8:c75d:8536 with SMTP id j24-20020a635518000000b003a8c75d8536mr18696083pgb.366.1650501222690; Wed, 20 Apr 2022 17:33:42 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 4/6] target/riscv: machine: Add debug state description Date: Thu, 21 Apr 2022 08:33:22 +0800 Message-Id: <20220421003324.1134983-5-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::436; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x436.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501366815100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng Add a subsection to machine.c to migrate debug CSR state. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- (no changes since v2) Changes in v2: - new patch: add debug state description target/riscv/machine.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 243f567949..2a437b29a1 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -216,7 +216,38 @@ static const VMStateDescription vmstate_kvmtimer =3D { VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU), VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU), VMSTATE_UINT64(env.kvm_timer_state, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + +static bool debug_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; + CPURISCVState *env =3D &cpu->env; + + return riscv_feature(env, RISCV_FEATURE_DEBUG); +} =20 +static const VMStateDescription vmstate_debug_type2 =3D { + .name =3D "cpu/debug/type2", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINTTL(mcontrol, type2_trigger_t), + VMSTATE_UINTTL(maddress, type2_trigger_t), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_debug =3D { + .name =3D "cpu/debug", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D debug_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINTTL(env.trigger_cur, RISCVCPU), + VMSTATE_STRUCT_ARRAY(env.type2_trig, RISCVCPU, TRIGGER_TYPE2_NUM, + 0, vmstate_debug_type2, type2_trigger_t), VMSTATE_END_OF_LIST() } }; @@ -315,6 +346,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_rv128, &vmstate_kvmtimer, &vmstate_envcfg, + &vmstate_debug, NULL } }; --=20 2.25.1 From nobody Tue May 21 01:56:04 2024 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=1650501483; cv=none; d=zohomail.com; s=zohoarc; b=KZf65X9YnH8hphV/UChAEx9z6pUx5TraolBqd2I8GBdIq9GB+qq5Yap7RFMeInP+RBs/e3fe30AguvziwdgUbX8uNdCCCm5iKF2W/7CFYOqGKg9+UxWn8HpXE4Wp7rdE3P6Tl32UmthMgvFvRZiRVFkdzH3Ve4vnA/HuXPASRV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501483; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ArTHn4klHalFoaByuoITqQEzLR2lLcXEBce/s25Aacs=; b=UBVBL3ZstkDIFdQhG6IReDayv/HxFPX4tuJFAGYqsWk4BJNauW8HcAdI8pArDlojGHjpc2JWK0hM983z8+AsCFFr/nxMKFXvxrv3ix0cZ/6ltFWlSYTMsa3dMdkznzkBpW85lZqpXXRB8T8/xkzTxRRxgD+EPPppdL7zK4gyu9E= 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 1650501483266569.3566709079498; Wed, 20 Apr 2022 17:38:03 -0700 (PDT) Received: from localhost ([::1]:54404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKpe-0003nR-9v for importer@patchew.org; Wed, 20 Apr 2022 20:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlZ-0004zh-CC; Wed, 20 Apr 2022 20:33:49 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:53144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKlX-0008NH-WF; Wed, 20 Apr 2022 20:33:49 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 2so3484098pjw.2; Wed, 20 Apr 2022 17:33:46 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ArTHn4klHalFoaByuoITqQEzLR2lLcXEBce/s25Aacs=; b=IXUiVY7e84MTTQ8qiyZUYBLvcIAHDLy8lcV0MRYTvGCKlzEtc+im/Elr6nLhGIEFIU ERw7QJMX4c8KHGSof+igDSmz6tSY8XZZLOJvflWOTguAd3NXZzO+bfp83dTJqz7D9nFL 7pjW2haRNcA+LqaHfuPm7tzGETuJI1cDxgBSlvq4u4qvD7Xx0l5fxLuWma4x7yQ97Sbf 0BImOMOMVM+f1ydPcwDhQ3hOaCG8KUMv2dRVa7pQLRDk9GlXEtank7jjOabYcQ8bZlAe g4inFJkM4WH7PsNuR9KM7L1kN0XIyzU3rL23hOdcUAUecBZPkLe2L+rLZDLg6Y7I9UdZ HzXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ArTHn4klHalFoaByuoITqQEzLR2lLcXEBce/s25Aacs=; b=4d/Pz81Fs0R2unhX514Ans3+ZvyHKl3Yv1QPiDsBTSFrSE9oA1k1znHknCZy6ppRNH tHa9FAhOLBAQVcu5Fg/pMsg82GQGRe6rtAul3MeccgV4Pk1iS3gvWg9UKIzl4Sa1t07a rlf0cyeG028dgzJ3ra2R99sRew4lODtdStMHZRgCViJBwxEUh9ciFChANifeAwHVJOeR 2tPY0SQLfP0K5O8xcQXS2TBcurU0VwgweNGlxw/ZQvVZcGscKoMP6Bu4jXDEoctRCNgm mWwKQkvpzxTwF2KVPUfO8aYlkrR/mEECboCPulMak9Ar804j3kX67cB6D7w7IMON4bWI 31zQ== X-Gm-Message-State: AOAM5313NnHcJq5vnu0gHaPANa81cgB/ot+EGbAXPFf8qdisYr8VVkmW gA9xhgDr4rFIXAFOp2N+nyU= X-Google-Smtp-Source: ABdhPJwOEE/oFa2XO8rD4b9ibe/ZJqM9ui7tyhaAlBqD1rFfVIsdb1o53IUXA82fhYNI6NjxLRn6JQ== X-Received: by 2002:a17:902:8306:b0:158:ea27:307d with SMTP id bd6-20020a170902830600b00158ea27307dmr21714183plb.164.1650501225553; Wed, 20 Apr 2022 17:33:45 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 5/6] target/riscv: cpu: Enable native debug feature Date: Thu, 21 Apr 2022 08:33:23 +0800 Message-Id: <20220421003324.1134983-6-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::102c; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501483555100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng Turn on native debug feature by default for all CPUs. Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- (no changes since v3) Changes in v3: - enable debug feature by default for all CPUs target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 85656cdcc3..0c774056c5 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -803,7 +803,7 @@ static Property riscv_cpu_properties[] =3D { DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), - DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, false), + DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), =20 DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), --=20 2.25.1 From nobody Tue May 21 01:56:04 2024 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=1650501492; cv=none; d=zohomail.com; s=zohoarc; b=FTYqvv4TUySQhRpY3vQT6id6uFMXPcTgmh1CksXGCYQbsvscIg/OHt8p+jU1Y2yNQUrM2k8n9vJiFQ2pcDUXFnJx3XmE9ihzRvkMoqG4GQDfOTcaXbHllYLaa5grD+7chYpSYiZkNF5XzY/MjSVN0wrAXrSVIyL2US/ZMJ0ozXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650501492; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k03hqsrN3r2DAcpcEZo3Qmaha1XCoOaXcqqhAGM9cU0=; b=DGypk2eF5bJKDRpwDi9Hjw9i6P7yE920SiyTYyDVsxzEcsmL8sTE92gSYKovc9qjVexCGQbhTHSzB6/nuUmD+Z/ujdOHDbCCrN0WBLEoeua+vN7vGdgfg3skPG7BQne6GQQ+GWTZgk8zNgRRXNn1TLX42EQH4xLi4+bzpJXXlQI= 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 165050149289433.223733041066794; Wed, 20 Apr 2022 17:38:12 -0700 (PDT) Received: from localhost ([::1]:55092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhKpn-0004HL-US for importer@patchew.org; Wed, 20 Apr 2022 20:38:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhKlc-00057u-QO; Wed, 20 Apr 2022 20:33:52 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:41957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhKla-0008Nx-PG; Wed, 20 Apr 2022 20:33:51 -0400 Received: by mail-pg1-x52c.google.com with SMTP id t13so3241143pgn.8; Wed, 20 Apr 2022 17:33:49 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id z6-20020a056a00240600b004e17ab23340sm22981969pfh.177.2022.04.20.17.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 17:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k03hqsrN3r2DAcpcEZo3Qmaha1XCoOaXcqqhAGM9cU0=; b=qfbK/YVww+veIVQb6g8pekVxYFSInAitfMQ4btBr/DIapSEsPv4Wl5lSkm8CS40FzB sAGveyrnbk2jWSzqnl/T8TZg2TRk7Ss6RvsbDSavJiCGQr0QHw9EIzZwYtVnA3ARJpzQ mvK7K4WUAxavYPtAPRS7qUo6ra9SaNr+jpH1TaciWCcD6oqANO5yXWqyz0Ux/WdtgM88 +jYvDfawcSBagHgMQuQ+nLojom37vFA/0aTLwhbs1+dLymohS4I1iUNLSVYrmQGI5V/S JshHhNCPKZ6ezGijiRxZuqY9fwcWBt5w0uJO+DpTEBXHrtF/6bKSQbaC59juZ/u57XRc Ui4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k03hqsrN3r2DAcpcEZo3Qmaha1XCoOaXcqqhAGM9cU0=; b=rF59MYUG+f9PNgmFH9o9fRZLpfKlIrOH0oHtjpJQik511mC7171InjgNybDIoAjRVs M8R4UvJG2TXtfXW3Pkb8WmgAjSD0JtM9ZhZHBbLJciNiqQm3xz19LWYSsD3akuHG3KMP XiQSLZHF3dHZIZhTdv7L3SwSsI6WT9x+GDziZ+eJCiNiVgGf8Dd9NKDNvFuKp+7erKFg e6yHmtKgSg1T49DcAE8B2Y2EEeZQdRy0jnkHpMKcVo433QbM48OdnP39Ko7+WxyrQVNF yDHdzO5dm2z2H/e+qdtuQvEGtlzRhAu8rr2x3QJQPXJjjpjC63Uq54Tr/ZSS7XmDgZ0l 1IIQ== X-Gm-Message-State: AOAM532X0kgd0la4raGEE4Xu4IP5e3XKhsgn+LIvDyIYHT0qC3JtBXif NQ4qOky7G+EtRYRPuEF2wxg= X-Google-Smtp-Source: ABdhPJwEa7XXGI53bvyBP1KcxJGov+qyqcF6RQC42+4rrltmlHDs3PzHF6/7PKt1qBS5+JoSslkAPQ== X-Received: by 2002:a05:6a00:1505:b0:50a:641f:c688 with SMTP id q5-20020a056a00150500b0050a641fc688mr21898157pfu.86.1650501228922; Wed, 20 Apr 2022 17:33:48 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 6/6] hw/core: tcg-cpu-ops.h: Update comments of debug_check_watchpoint() Date: Thu, 21 Apr 2022 08:33:24 +0800 Message-Id: <20220421003324.1134983-7-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421003324.1134983-1-bmeng.cn@gmail.com> References: <20220421003324.1134983-1-bmeng.cn@gmail.com> 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::52c; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1650501493606100003 Content-Type: text/plain; charset="utf-8" From: Bin Meng This is now used by RISC-V as well. Update the comments. Signed-off-by: Bin Meng Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- (no changes since v1) include/hw/core/tcg-cpu-ops.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h index e13898553a..f98671ff32 100644 --- a/include/hw/core/tcg-cpu-ops.h +++ b/include/hw/core/tcg-cpu-ops.h @@ -90,6 +90,7 @@ struct TCGCPUOps { /** * @debug_check_watchpoint: return true if the architectural * watchpoint whose address has matched should really fire, used by ARM + * and RISC-V */ bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); =20 --=20 2.25.1