From patchwork Wed Jan 5 03:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RdxmzlAT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDyH5FTlz9sSs for ; Wed, 5 Jan 2022 14:10:46 +1100 (AEDT) Received: from localhost ([::1]:38986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4whG-00070R-WC for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:10:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wfY-0006ya-Ki; Tue, 04 Jan 2022 22:08:56 -0500 Received: from [2607:f8b0:4864:20::1033] (port=53824 helo=mail-pj1-x1033.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wfV-0001wC-NU; Tue, 04 Jan 2022 22:08:56 -0500 Received: by mail-pj1-x1033.google.com with SMTP id m13so466512pji.3; Tue, 04 Jan 2022 19:08:53 -0800 (PST) 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=9WqiQIt+cavYu/kgllAaaEN8WB4U9OE5aa5Z26l3cBs=; b=RdxmzlATFY0/RslVmEIiIbgPaGycGgtQ70dhge489mE+sR1qd4c+YNOg7CAQH0vW0b akNtiC8ffXgkC/svA+LMuVy9bIT6l956Ip7R9c6AAycYZ+mnxxKqi58BGmGpaIfZ6EQD hl/tCAuggAXgGzP7EUoukD0vfx5NA5Pw0hsFqilUhC+RXgrA+sZMuRJM23dn0M7T0U1p CQX8C/pQuVt4ckNFW4cHiMyZEdlt6Fiozh0jKMRzqPqud+5tRZVyv5PduubB5yiVMbYB t8fdElLXX0zhaW+1bxD2n++41C977q36VVn18omYCQXt2psGwEdGYYOvyNoMVPq7HpgI VHvg== 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=9WqiQIt+cavYu/kgllAaaEN8WB4U9OE5aa5Z26l3cBs=; b=gAK78wmlMYf9ErB188b/KFMRIX9yM+cWSImuCI0fUlFOu7gThmYY846K5ZKzfS8DRv I6ECCvkVcU9fuxII83ZM1I1ZXuWJa0FfEKop2Eifa6m5d4/Dgm7cdOhg4qOM+v//b8lw awCuHNH4QZhzo+m4RCXfJ428L4guHrae32VzfaxkPZQWLKpko0NrJTB9hPX7ac0+Pflc KhYJGvc1gEjPnNdNXty5XBm8DG1eFnPt3/0qJnyqFvsoNWOG3+FjvLxs65m7ssORe/g3 kCa8IDxFx3AL6vLz8ez8tsTD+Ug+YQv2SzeuoXa7ULcvzh6dW+NcQAnqMBmHuAojNtHS I7lQ== X-Gm-Message-State: AOAM532komBTN5Gj4Qa3AcQoqhruuqVH3ZfKedXYADLWIbqyIp85Knbk t5Tm5uolsxizn1OD2BwixVBcIrOpYjSbKA== X-Google-Smtp-Source: ABdhPJzkUq7bhWU9uT/zoJ87S8DLyb6tKNHGG13tgKHyC9jEfDxFZ7bJ3wRAtvqY+cgFchCkPZJZTQ== X-Received: by 2002:a17:90b:1d8f:: with SMTP id pf15mr1681881pjb.237.1641352132041; Tue, 04 Jan 2022 19:08:52 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t191sm36206889pgd.3.2022.01.04.19.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:08:51 -0800 (PST) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [RESEND PATCH v3 1/7] target/riscv: Add initial support for native debug Date: Wed, 5 Jan 2022 11:08:38 +0800 Message-Id: <20220105030844.780642-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030844.780642-1-bmeng.cn@gmail.com> References: <20220105030844.780642-1-bmeng.cn@gmail.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1033 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng This adds initial support for the native debug via the Trigger Module, as defined in the RISC-V Debug Specification [1]. Only "Address / Data Match" trigger (type 2) is implemented as of now, which is mainly used for hardware breakpoint and watchpoint. The number of type 2 triggers implemented is 2, which is the number that we can find in the SiFive U54/U74 cores. [1] https://github.com/riscv/riscv-debug-spec/raw/master/riscv-debug-stable.pdf Signed-off-by: Bin Meng --- Changes in v3: - drop riscv_trigger_init(), which will be moved to patch #5 target/riscv/cpu.h | 5 + target/riscv/debug.h | 108 +++++++++++++ target/riscv/debug.c | 339 +++++++++++++++++++++++++++++++++++++++ target/riscv/meson.build | 1 + 4 files changed, 453 insertions(+) create mode 100644 target/riscv/debug.h create mode 100644 target/riscv/debug.c diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index dc10f27093..0f3b3a4219 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -98,6 +98,7 @@ typedef struct CPURISCVState CPURISCVState; #if !defined(CONFIG_USER_ONLY) #include "pmp.h" +#include "debug.h" #endif #define RV_VLEN_MAX 1024 @@ -234,6 +235,10 @@ struct CPURISCVState { pmp_table_t pmp_state; target_ulong mseccfg; + /* trigger module */ + target_ulong trigger_cur; + trigger_type2_t trigger_type2[TRIGGER_TYPE2_NUM]; + /* machine specific rdtime callback */ uint64_t (*rdtime_fn)(uint32_t); uint32_t rdtime_fn_arg; diff --git a/target/riscv/debug.h b/target/riscv/debug.h new file mode 100644 index 0000000000..0a3fda6c72 --- /dev/null +++ b/target/riscv/debug.h @@ -0,0 +1,108 @@ +/* + * QEMU RISC-V Native Debug Support + * + * Copyright (c) 2022 Wind River Systems, Inc. + * + * Author: + * Bin Meng + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef RISCV_DEBUG_H +#define RISCV_DEBUG_H + +/* trigger indexes implemented */ +enum { + TRIGGER_TYPE2_IDX_0 = 0, + TRIGGER_TYPE2_IDX_1, + TRIGGER_TYPE2_NUM, + TRIGGER_NUM = TRIGGER_TYPE2_NUM +}; + +/* register index of tdata CSRs */ +enum { + TDATA1 = 0, + TDATA2, + TDATA3, + TDATA_NUM +}; + +typedef enum { + TRIGGER_TYPE_NO_EXIST = 0, /* trigger does not exist */ + TRIGGER_TYPE_AD_MATCH = 2, /* address/data match trigger */ + TRIGGER_TYPE_INST_CNT = 3, /* instruction count trigger */ + TRIGGER_TYPE_INT = 4, /* interrupt trigger */ + TRIGGER_TYPE_EXCP = 5, /* exception trigger */ + 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_t; + +typedef struct { + target_ulong mcontrol; + target_ulong maddress; + struct CPUBreakpoint *bp; + struct CPUWatchpoint *wp; +} trigger_type2_t; + +/* tdata field masks */ + +#define RV32_TYPE(t) ((uint32_t)(t) << 28) +#define RV32_TYPE_MASK (0xf << 28) +#define RV32_DMODE BIT(27) +#define RV64_TYPE(t) ((uint64_t)(t) << 60) +#define RV64_TYPE_MASK (0xfULL << 60) +#define RV64_DMODE BIT_ULL(59) + +/* mcontrol field masks */ + +#define TYPE2_LOAD BIT(0) +#define TYPE2_STORE BIT(1) +#define TYPE2_EXEC BIT(2) +#define TYPE2_U BIT(3) +#define TYPE2_S BIT(4) +#define TYPE2_M BIT(6) +#define TYPE2_MATCH (0xf << 7) +#define TYPE2_CHAIN BIT(11) +#define TYPE2_ACTION (0xf << 12) +#define TYPE2_SIZELO (0x3 << 16) +#define TYPE2_TIMING BIT(18) +#define TYPE2_SELECT BIT(19) +#define TYPE2_HIT BIT(20) +#define TYPE2_SIZEHI (0x3 << 21) /* RV64 only */ + +/* access size */ +enum { + SIZE_ANY = 0, + SIZE_1B, + SIZE_2B, + SIZE_4B, + SIZE_6B, + SIZE_8B, + SIZE_10B, + SIZE_12B, + SIZE_14B, + SIZE_16B, + SIZE_NUM = 16 +}; + +bool tdata_available(CPURISCVState *env, int tdata_index); + +target_ulong tselect_csr_read(CPURISCVState *env); +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); + +#endif /* RISCV_DEBUG_H */ diff --git a/target/riscv/debug.c b/target/riscv/debug.c new file mode 100644 index 0000000000..530e030007 --- /dev/null +++ b/target/riscv/debug.c @@ -0,0 +1,339 @@ +/* + * QEMU RISC-V Native Debug Support + * + * Copyright (c) 2022 Wind River Systems, Inc. + * + * Author: + * Bin Meng + * + * This provides the native debug support via the Trigger Module, as defined + * in the RISC-V Debug Specification: + * https://github.com/riscv/riscv-debug-spec/raw/master/riscv-debug-stable.pdf + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "cpu.h" +#include "trace.h" +#include "exec/exec-all.h" + +/* + * The following M-mode trigger CSRs are implemented: + * + * - tselect + * - tdata1 + * - tdata2 + * - tdata3 + * + * We don't support writable 'type' field in the tdata1 register, so there is + * no need to implement the "tinfo" CSR. + * + * The following triggers are implemented: + * + * Index | Type | tdata mapping | Description + * ------+------+------------------------+------------ + * 0 | 2 | tdata1, tdata2 | Address / Data Match + * 1 | 2 | tdata1, tdata2 | Address / Data Match + */ + +/* tdata availability of a trigger */ +typedef bool tdata_avail[TDATA_NUM]; + +static tdata_avail tdata_mapping[TRIGGER_NUM] = { + [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = { true, true, false }, +}; + +/* only breakpoint size 1/2/4/8 supported */ +static int access_size[SIZE_NUM] = { + [SIZE_ANY] = 0, + [SIZE_1B] = 1, + [SIZE_2B] = 2, + [SIZE_4B] = 4, + [SIZE_6B] = -1, + [SIZE_8B] = 8, + [6 ... 15] = -1, +}; + +static inline target_ulong trigger_type(CPURISCVState *env, + trigger_type_t type) +{ + target_ulong tdata1; + + switch (riscv_cpu_mxl(env)) { + case MXL_RV32: + tdata1 = RV32_TYPE(type); + break; + case MXL_RV64: + tdata1 = RV64_TYPE(type); + break; + default: + g_assert_not_reached(); + } + + return tdata1; +} + +bool tdata_available(CPURISCVState *env, int tdata_index) +{ + if (unlikely(tdata_index >= TDATA_NUM)) { + return false; + } + + if (unlikely(env->trigger_cur >= TRIGGER_NUM)) { + return false; + } + + return tdata_mapping[env->trigger_cur][tdata_index]; +} + +target_ulong tselect_csr_read(CPURISCVState *env) +{ + return env->trigger_cur; +} + +void tselect_csr_write(CPURISCVState *env, target_ulong val) +{ + /* all target_ulong bits of tselect are implemented */ + env->trigger_cur = val; +} + +static target_ulong tdata1_validate(CPURISCVState *env, target_ulong val, + trigger_type_t t) +{ + uint32_t type, dmode; + target_ulong tdata1; + + switch (riscv_cpu_mxl(env)) { + case MXL_RV32: + type = extract32(val, 28, 4); + dmode = extract32(val, 27, 1); + tdata1 = RV32_TYPE(t); + break; + case MXL_RV64: + type = extract64(val, 60, 4); + dmode = extract64(val, 59, 1); + tdata1 = RV64_TYPE(t); + break; + default: + g_assert_not_reached(); + } + + if (type != t) { + qemu_log_mask(LOG_GUEST_ERROR, + "ignoring type write to tdata1 register\n"); + } + if (dmode != 0) { + qemu_log_mask(LOG_UNIMP, "debug mode is not supported\n"); + } + + return tdata1; +} + +static inline void warn_always_zero_bit(target_ulong val, target_ulong mask, + const char *msg) +{ + if (val & mask) { + qemu_log_mask(LOG_UNIMP, "%s bit is always zero\n", msg); + } +} + +static uint32_t type2_breakpoint_size(CPURISCVState *env, target_ulong ctrl) +{ + uint32_t size, sizelo, sizehi = 0; + + if (riscv_cpu_mxl(env) == MXL_RV64) { + sizehi = extract32(ctrl, 21, 2); + } + sizelo = extract32(ctrl, 16, 2); + size = (sizehi << 2) | sizelo; + + return size; +} + +static inline bool type2_breakpoint_enabled(target_ulong ctrl) +{ + bool mode = !!(ctrl & (TYPE2_U | TYPE2_S | TYPE2_M)); + bool rwx = !!(ctrl & (TYPE2_LOAD | TYPE2_STORE | TYPE2_EXEC)); + + return mode && rwx; +} + +static target_ulong type2_mcontrol_validate(CPURISCVState *env, + target_ulong ctrl) +{ + target_ulong val; + uint32_t size; + + /* validate the generic part first */ + val = tdata1_validate(env, ctrl, TRIGGER_TYPE_AD_MATCH); + + /* 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"); + + /* validate size encoding */ + size = type2_breakpoint_size(env, ctrl); + if (access_size[size] == -1) { + qemu_log_mask(LOG_UNIMP, "access size %d is not supported, using SIZE_ANY\n", + size); + } else { + val |= (ctrl & TYPE2_SIZELO); + if (riscv_cpu_mxl(env) == MXL_RV64) { + val |= (ctrl & TYPE2_SIZEHI); + } + } + + /* keep the mode and attribute bits */ + val |= (ctrl & (TYPE2_U | TYPE2_S | TYPE2_M | + TYPE2_LOAD | TYPE2_STORE | TYPE2_EXEC)); + + return val; +} + +static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) +{ + target_ulong ctrl = env->trigger_type2[index].mcontrol; + target_ulong addr = env->trigger_type2[index].maddress; + bool enabled = type2_breakpoint_enabled(ctrl); + CPUState *cs = env_cpu(env); + int flags = BP_CPU | BP_STOP_BEFORE_ACCESS; + uint32_t size; + + if (!enabled) { + return; + } + + if (ctrl & TYPE2_EXEC) { + cpu_breakpoint_insert(cs, addr, flags, &env->trigger_type2[index].bp); + } + + if (ctrl & TYPE2_LOAD) { + flags |= BP_MEM_READ; + } + if (ctrl & TYPE2_STORE) { + flags |= BP_MEM_WRITE; + } + + if (flags & BP_MEM_ACCESS) { + size = type2_breakpoint_size(env, ctrl); + if (size != 0) { + cpu_watchpoint_insert(cs, addr, size, flags, + &env->trigger_type2[index].wp); + } else { + cpu_watchpoint_insert(cs, addr, 8, flags, + &env->trigger_type2[index].wp); + } + } +} + +static void type2_breakpoint_remove(CPURISCVState *env, target_ulong index) +{ + CPUState *cs = env_cpu(env); + + if (env->trigger_type2[index].bp) { + cpu_breakpoint_remove_by_ref(cs, env->trigger_type2[index].bp); + env->trigger_type2[index].bp = NULL; + } + + if (env->trigger_type2[index].wp) { + cpu_watchpoint_remove_by_ref(cs, env->trigger_type2[index].wp); + env->trigger_type2[index].wp = NULL; + } +} + +static target_ulong type2_reg_read(CPURISCVState *env, + target_ulong trigger_index, int tdata_index) +{ + uint32_t index = trigger_index - TRIGGER_TYPE2_IDX_0; + target_ulong tdata; + + switch (tdata_index) { + case TDATA1: + tdata = env->trigger_type2[index].mcontrol; + break; + case TDATA2: + tdata = env->trigger_type2[index].maddress; + break; + default: + g_assert_not_reached(); + } + + return tdata; +} + +static void type2_reg_write(CPURISCVState *env, target_ulong trigger_index, + int tdata_index, target_ulong val) +{ + uint32_t index = trigger_index - TRIGGER_TYPE2_IDX_0; + target_ulong new_val; + + switch (tdata_index) { + case TDATA1: + new_val = type2_mcontrol_validate(env, val); + if (new_val != env->trigger_type2[index].mcontrol) { + env->trigger_type2[index].mcontrol = new_val; + type2_breakpoint_remove(env, index); + type2_breakpoint_insert(env, index); + } + break; + case TDATA2: + if (val != env->trigger_type2[index].maddress) { + env->trigger_type2[index].maddress = val; + type2_breakpoint_remove(env, index); + type2_breakpoint_insert(env, index); + } + break; + default: + g_assert_not_reached(); + } + + return; +} + +typedef target_ulong (*tdata_read_func)(CPURISCVState *env, + target_ulong trigger_index, + int tdata_index); + +static tdata_read_func trigger_read_funcs[TRIGGER_NUM] = { + [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = type2_reg_read, +}; + +typedef void (*tdata_write_func)(CPURISCVState *env, + target_ulong trigger_index, + int tdata_index, + target_ulong val); + +static tdata_write_func trigger_write_funcs[TRIGGER_NUM] = { + [TRIGGER_TYPE2_IDX_0 ... TRIGGER_TYPE2_IDX_1] = type2_reg_write, +}; + +target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index) +{ + tdata_read_func read_func = trigger_read_funcs[env->trigger_cur]; + + return read_func(env, env->trigger_cur, tdata_index); +} + +void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) +{ + tdata_write_func write_func = trigger_write_funcs[env->trigger_cur]; + + return write_func(env, env->trigger_cur, tdata_index, val); +} diff --git a/target/riscv/meson.build b/target/riscv/meson.build index d5e0bc93ea..966d97237a 100644 --- a/target/riscv/meson.build +++ b/target/riscv/meson.build @@ -24,6 +24,7 @@ riscv_softmmu_ss = ss.source_set() riscv_softmmu_ss.add(files( 'arch_dump.c', 'pmp.c', + 'debug.c', 'monitor.c', 'machine.c' )) From patchwork Wed Jan 5 03:01:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qdHdsHbR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDnt6CfGz9sSs for ; Wed, 5 Jan 2022 14:03:30 +1100 (AEDT) Received: from localhost ([::1]:56008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4waG-0007dk-BK for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:03:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYe-0007c8-PL; Tue, 04 Jan 2022 22:01:48 -0500 Received: from [2607:f8b0:4864:20::1029] (port=43783 helo=mail-pj1-x1029.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYZ-0007PS-Vw; Tue, 04 Jan 2022 22:01:46 -0500 Received: by mail-pj1-x1029.google.com with SMTP id a11-20020a17090a854b00b001b11aae38d6so5064621pjw.2; Tue, 04 Jan 2022 19:01:42 -0800 (PST) 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=jrAL6g1TphcXjMCq2zldzmFnpuJynAAzFwwf2uBTSZk=; b=qdHdsHbRqx/V8KEO71KncmLPurE5FIhw/oHW7uPsiag5Dc/hO+AvsbrJ6cvAqdPqON JO7a4H5bm9+h591UZLwXurKMlsG3SX14IOdd9dPObkQIn/nQZUNcxCH9+4UrI8nM1E5Q cooslR0tNiqXFmdS8ysfsS2jhk9ZcukF8bv2Wv11Mw5sOFOcDwoTaa1ai9r2ZOEpQts0 XyzVM0BXRoTJ/L88rmmwq280nvMZgLK8NWz/NHgywlDEhmIWBb+j3gsNe8mmoQFvL7Ni 1r1Rh4jZbUO9BET13A69V8gvq1QFAkNUGX9Q/A84m9vkHbEBe2efNgRkjo6Rto8xNg8q OczQ== 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=jrAL6g1TphcXjMCq2zldzmFnpuJynAAzFwwf2uBTSZk=; b=owqlr6UoCA4ULDb/Ti5i3tT+KLlDvgor9UyNeZyVyGX1lyhbATzdHJW0ei+mDbGis/ H8q3x4gVaR9U6ThkfLVWNmi/IGfECia/ylI44yKDiECZHlpGBAluXt7pcKV3IA282TCT ht1bzRFYsynEK/LggpsEI5b7oprra7iptfTzbwNm/Uzbk/e/uRACwVvoWus1T/ZkSJ42 R48+qBXoB6VDwTN+UEgQ/w9rzO8GmoJZLGPMBU2vx0D7Zaas7Vr6F4CekdaShLAJvYKG xNRASvik5uQjGph4ERkblxhPYwODtzAm0sB9Y1LEC2ExIU5da498atbLKOS6RkeH4k7V f1hQ== X-Gm-Message-State: AOAM531vUhYTvbmPuE+XtbO83SGvt2jXpvkCjJwkmWsvaYbh+l0PsIE3 KAwGTYxZjg4w9n7lpCP2S6Y= X-Google-Smtp-Source: ABdhPJyyzqF7TjTv05xFneXy23U1S0u1h3Q9qmFh73EKHBuBwUo+ekOpnQsqz9NkoYCOz9pJ8ccb0Q== X-Received: by 2002:a17:90b:33d2:: with SMTP id lk18mr1682773pjb.218.1641351701895; Tue, 04 Jan 2022 19:01:41 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:41 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 2/7] target/riscv: machine: Add debug state description Date: Wed, 5 Jan 2022 11:01:21 +0800 Message-Id: <20220105030126.778503-3-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1029 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/target/riscv/machine.c b/target/riscv/machine.c index ad8248ebfd..25aa3b38f7 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -164,6 +164,38 @@ static const VMStateDescription vmstate_pointermasking = { } }; +static bool debug_needed(void *opaque) +{ + RISCVCPU *cpu = opaque; + CPURISCVState *env = &cpu->env; + + return riscv_feature(env, RISCV_FEATURE_DEBUG); +} + +static const VMStateDescription vmstate_debug_type2 = { + .name = "cpu/debug/type2", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINTTL(mcontrol, trigger_type2_t), + VMSTATE_UINTTL(maddress, trigger_type2_t), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_debug = { + .name = "cpu/debug", + .version_id = 1, + .minimum_version_id = 1, + .needed = debug_needed, + .fields = (VMStateField[]) { + VMSTATE_UINTTL(env.trigger_cur, RISCVCPU), + VMSTATE_STRUCT_ARRAY(env.trigger_type2, RISCVCPU, TRIGGER_TYPE2_NUM, + 0, vmstate_debug_type2, trigger_type2_t), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu = { .name = "cpu", .version_id = 3, @@ -218,6 +250,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_hyper, &vmstate_vector, &vmstate_pointermasking, + &vmstate_debug, NULL } }; From patchwork Wed Jan 5 03:01:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RAWKdIOS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDtR1ZYXz9sSs for ; Wed, 5 Jan 2022 14:07:27 +1100 (AEDT) Received: from localhost ([::1]:35914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4we4-0004tn-TT for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:07:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYh-0007fA-8W; Tue, 04 Jan 2022 22:01:51 -0500 Received: from [2607:f8b0:4864:20::1033] (port=45992 helo=mail-pj1-x1033.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYb-0007Pf-Ut; Tue, 04 Jan 2022 22:01:49 -0500 Received: by mail-pj1-x1033.google.com with SMTP id l16-20020a17090a409000b001b2e9628c9cso5059824pjg.4; Tue, 04 Jan 2022 19:01:45 -0800 (PST) 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=vlDH6s4R16z8Xc97NfVhwVfcxr4VS3Gifdo5Yi4zqeA=; b=RAWKdIOS8TpgZ4UIpbTNz1K3vD3vefaI4M9sSDdDgfthQiTL2DA7McZmktB2knrqvH oJ6GCVpdQn+yHFql6kKj9cywAbtfW4UuBfb+EhXDKH6KmUn6AqEC+MqB/X8cwMYyow6g EntUxXBYEBusyA9nXstAdSluEbfM7dKI2EWJWshy1QWNRwbRUJQYpw+mSdoFPamJVG8k vbk0dnmOzOoXTPAWMCqE81ySCppXmFeNPO4sFjnaWm9fWuxrgacnnRqVPUa+CuHcp0wG l1hT6E0wJ/C7LDXYY+ooEzzNbkHyCnQgn7j+GUSRMZJXHw9EvoylPDelStn226Ade+/t xz3w== 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=vlDH6s4R16z8Xc97NfVhwVfcxr4VS3Gifdo5Yi4zqeA=; b=c24dzke1YEWSvAk/HDogWj/AkHstsLvJEpJPl5M7xu7+iM0i3rGlmR73bb4oj1Qxwq q9+sYN8Zb3qkNBJdYT7zlpPpJQ2qqe7bZ6IH+OxRP91XyVUhm5iHwOuisw2RCSYCOHHW qXIFpEz+HWWDIuNN5jbGTRljDB3qS4if1IoOMgdluSE1ZA9t6OkgFoocpu3Ict8pcMh5 zZFFFc5GwNcXaME0nXqKI8UFP4Q9Phs6z+NRdgeRU3AlNpD1gklfL48bkQ9GQAJiRQzH 0SVX3IExO7IILOIJDYyWIzw4P1KudAFi7XiAdiNutqZwKeHTY+twEbh8T6rC/W9C5kud jNsg== X-Gm-Message-State: AOAM530yMppRioEaj7dxFr+YMIyPn3yNrPwzoII+p7HQJ7lS0d+fFNQA b5MHEn+51dRez8uyxf+AgNc= X-Google-Smtp-Source: ABdhPJxS5enwnsG/PphSSrro0ZNQNBew321xA0iMwMat0SMp4dOf0ZW9i0DVX5G5UPhKCSqKL30xVw== X-Received: by 2002:a17:90b:38c6:: with SMTP id nn6mr1741952pjb.26.1641351704384; Tue, 04 Jan 2022 19:01:44 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:44 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 3/7] target/riscv: debug: Implement debug related TCGCPUOps Date: Wed, 5 Jan 2022 11:01:22 +0800 Message-Id: <20220105030126.778503-4-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1033 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 0a3fda6c72..d0f63e2414 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); +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 6ef3314bce..3aa07bc019 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -705,6 +705,9 @@ static const struct TCGCPUOps riscv_tcg_ops = { .do_interrupt = riscv_cpu_do_interrupt, .do_transaction_failed = riscv_cpu_do_transaction_failed, .do_unaligned_access = riscv_cpu_do_unaligned_access, + .debug_excp_handler = riscv_cpu_debug_excp_handler, + .debug_check_breakpoint = riscv_cpu_debug_check_breakpoint, + .debug_check_watchpoint = riscv_cpu_debug_check_watchpoint, #endif /* !CONFIG_USER_ONLY */ }; diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 530e030007..7760c4611f 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -337,3 +337,78 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val) return write_func(env, env->trigger_cur, tdata_index, val); } + +void riscv_cpu_debug_excp_handler(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + + if (cs->watchpoint_hit) { + if (cs->watchpoint_hit->flags & BP_CPU) { + cs->watchpoint_hit = 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 = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + CPUBreakpoint *bp; + target_ulong ctrl; + target_ulong pc; + int i; + + QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { + for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { + ctrl = env->trigger_type2[i].mcontrol; + pc = env->trigger_type2[i].maddress; + + if ((ctrl & TYPE2_EXEC) && (bp->pc == 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 = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + target_ulong ctrl; + target_ulong addr; + int flags; + int i; + + for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { + ctrl = env->trigger_type2[i].mcontrol; + addr = env->trigger_type2[i].maddress; + flags = 0; + + if (ctrl & TYPE2_LOAD) { + flags |= BP_MEM_READ; + } + if (ctrl & TYPE2_STORE) { + flags |= BP_MEM_WRITE; + } + + if ((wp->flags & flags) && (wp->vaddr == addr)) { + /* check U/S/M bit against current privilege level */ + if ((ctrl >> 3) & BIT(env->priv)) { + return true; + } + } + } + + return false; +} From patchwork Wed Jan 5 03:01:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BRQvLtIk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDp2450tz9sSs for ; Wed, 5 Jan 2022 14:03:38 +1100 (AEDT) Received: from localhost ([::1]:56670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4waO-0008A8-7K for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:03:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYg-0007dw-Ct; Tue, 04 Jan 2022 22:01:50 -0500 Received: from [2607:f8b0:4864:20::52f] (port=45758 helo=mail-pg1-x52f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYe-0007Pu-Sa; Tue, 04 Jan 2022 22:01:50 -0500 Received: by mail-pg1-x52f.google.com with SMTP id f5so4955457pgk.12; Tue, 04 Jan 2022 19:01:47 -0800 (PST) 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=b5NAdpMm2U58lIzwIEChXRECAvMzIUZbnYwnZLt4VXI=; b=BRQvLtIk6W6NWIWXISMotoQaD4dxwkUY1kTLuyaExOUq/JL/+oOhR8dGvr1KacEylK cNRhieAKsr+/L+YxFwZy11/xDQQ/s6QEA76g300YvPsDhUnR7xhB5eELE6nCvTu8tIUJ TWopmQlsZZVF1di0i9Zf3Yz6/FbHzYG7m3dAWnCvrKqSLDlzHofRZ4Zbb2eWM6n8kOrA uZ3znjenbyKtXiwTpWcJSKNHxRw/qE6VUIg2iVOm97XZP03ME8P1q2QVT86YxwHkhSxD akYOSItrlyL8dtYO0EAv2KoG9uVBRDxG5guvjlFSHnMnJtCGBmP/s92ItKSyYKSnI1i3 bQLg== 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=b5NAdpMm2U58lIzwIEChXRECAvMzIUZbnYwnZLt4VXI=; b=xI5oEvU3EFRv1gb5T7DY9PBgUM/PhtpsllqdxBXayofKk9UR2wUPKKqAARTveiOw+K Px87oqSnWwnT/m4ANX4to6fEpajlcgBPkOnsalEm4gfzDebSPOZfAWygV7w6XOeRIFs3 Fj6tRbYtSyy1Q0UpLnaLf/ZGzXK0D9psnmkHyLGgnCAgs+Ej+Wa8XUIXN7KGlgeFLYHi mRs3I+4fq61VMpTSqpTHBPdI+zNCUrF/l7jesiL70ibV7FRE1Usoq9JyhiXS92BvU+5A mqEyFJXOKUKaoDZNGJ0XJSYwq98pbrpqm8OyumiC325gsaTwk7QqNMofuDgGenSo4BCA fKgA== X-Gm-Message-State: AOAM530SOsY0l1p5DGZXRHqEhRu1X+Hgr33r1XcXVtyNsKXq3nYEYz2/ fjV6nt0YtVh9GKPomGUk0ruCDz6eg18b3A== X-Google-Smtp-Source: ABdhPJx4RXcJqeoa3dPkZy7KiLbrCZMNJKiWXV6mUjfv232FtyY0ASb5NMUGEl+liBkvO/9Viq3elA== X-Received: by 2002:a63:b954:: with SMTP id v20mr27457581pgo.302.1641351706550; Tue, 04 Jan 2022 19:01:46 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:46 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 4/7] target/riscv: cpu: Add a config option for native debug Date: Wed, 5 Jan 2022 11:01:23 +0800 Message-Id: <20220105030126.778503-5-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a config option to enable support for native M-mode debug. This is disabled by default and can be enabled with 'debug=true'. 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 | 2 ++ target/riscv/cpu.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0f3b3a4219..35445bbc86 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -75,6 +75,7 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, RISCV_FEATURE_EPMP, + RISCV_FEATURE_DEBUG, RISCV_FEATURE_MISA }; @@ -332,6 +333,7 @@ struct RISCVCPU { bool mmu; bool pmp; bool epmp; + bool debug; uint64_t resetvec; } cfg; }; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 3aa07bc019..d36c31ce9a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -448,6 +448,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } + if (cpu->cfg.debug) { + set_feature(env, RISCV_FEATURE_DEBUG); + } + set_resetvec(env, cpu->cfg.resetvec); /* Validate that MISA_MXL is set properly. */ @@ -634,6 +638,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, 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_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), From patchwork Wed Jan 5 03:01:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=auI7v7F9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDtH36Zrz9sSs for ; Wed, 5 Jan 2022 14:07:19 +1100 (AEDT) Received: from localhost ([::1]:35480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4wdw-0004cN-Rw for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:07:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYi-0007iG-4C; Tue, 04 Jan 2022 22:01:53 -0500 Received: from [2607:f8b0:4864:20::102b] (port=35534 helo=mail-pj1-x102b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYg-0007QJ-96; Tue, 04 Jan 2022 22:01:51 -0500 Received: by mail-pj1-x102b.google.com with SMTP id r16-20020a17090a0ad000b001b276aa3aabso2007452pje.0; Tue, 04 Jan 2022 19:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=s0BFcH5qNbkPwsrn+nasX8ZFuN+u1rgsZzVC1JV1cK4=; b=auI7v7F9blmry7utOvVS/TtwmpEHCrG632z0ohhMZ0r8DT8+qxkaUF8rsiy4GP3xyG Kot8tPQhZSPBfg9AVcW4xUal2kQQgqVw6JovGGDY3zNqvM9TQ4rPvc9Ctl7FiJ9jEXEA jWl4SK8L3wp+JNy5RnatrgGvqKaNJjzre3LzCEZF3K/gTfZo8m54aobl5kJupYxWUAgc MrTKBr9hN/QGeOf9/kuAeAqXk8CB5ETCOoKZQr6hj3iYKlZxK6NoFOSjYUFcAyvFNjfO d2RrfAfHrdu2uVgjYyOAE/crvEnHTidmQBK+xYUAcKMorKa1nssG0qgS6se1v0zzbfyl dUGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s0BFcH5qNbkPwsrn+nasX8ZFuN+u1rgsZzVC1JV1cK4=; b=wkzVjiVg053/Kj8pAdczPvykopIgCJjbw/54hudrCbSxc2F7zjlUXhTG/hgvvgofDt Fq0kakHJ59bc6xU5KSt/R1GhobDFSm65ckQTihypLNz4JmFfwKYQkg1P5zmh+qEJD9ZP RqzcIpno8wsptnCl497l7THg6z9kDS5zZjLzkcNh/I747A5wpWgiyaFQXGfz2t3cbjuK jCuAkuOjxnwfjFLI6U6vy84mWPJQF6Y63J4pdiW6jJ+XJyBPx7RinScfEFyT75HQw23B UJWqGhENrtfOvPZf0s83blslszmLAo3ESsgJpSU7tDqsJqVo9cOoJVKY7DsidBvDjl2X 9d8A== X-Gm-Message-State: AOAM5312uIFHFWCuaDd7XgLAQ9ezaUPAZ7LK3tPhlwrAXOSjDbNMyNv2 FkBOA3pbyCmyvK5IuoeOj3n7rKfFEXRYfw== X-Google-Smtp-Source: ABdhPJy0totMTc3xFeA7gSTcHG8geEko+nR5AtcuJpOdzn8AygPTn8YD/iyiBla25CQpQrWA/0OUeg== X-Received: by 2002:a17:90b:4017:: with SMTP id ie23mr1668327pjb.109.1641351708674; Tue, 04 Jan 2022 19:01:48 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:48 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 5/7] target/riscv: csr: Hook debug CSR read/write Date: Wed, 5 Jan 2022 11:01:24 +0800 Message-Id: <20220105030126.778503-6-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102b (failed) 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: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This adds debug CSR read/write support to the RISC-V CSR RW table. Signed-off-by: Bin Meng --- Changes in v3: - add riscv_trigger_init(), moved from patch #1 to this patch target/riscv/debug.h | 2 ++ target/riscv/cpu.c | 6 +++++ target/riscv/csr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ target/riscv/debug.c | 27 +++++++++++++++++++++ 4 files changed, 92 insertions(+) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index d0f63e2414..f4da2db35d 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); +void riscv_trigger_init(CPURISCVState *env); + #endif /* RISCV_DEBUG_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d36c31ce9a..17dcc3c14f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -575,6 +575,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) riscv_cpu_register_gdb_regs_for_features(cs); +#ifndef CONFIG_USER_ONLY + if (riscv_feature(env, RISCV_FEATURE_DEBUG)) { + riscv_trigger_init(env); + } +#endif + qemu_init_vcpu(cs); cpu_reset(cs); diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 146447eac5..189b9cc8c6 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -220,6 +220,15 @@ static RISCVException epmp(CPURISCVState *env, int csrno) 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 /* User Floating-Point CSRs */ @@ -1464,6 +1473,48 @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static RISCVException read_tselect(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = 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 >= TRIGGER_NUM && csrno == CSR_TDATA1) { + *val = 0; + return RISCV_EXCP_NONE; + } + + if (!tdata_available(env, csrno - CSR_TDATA1)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + *val = 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 @@ -1962,6 +2013,12 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_PMPADDR14] = { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR15] = { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr }, + /* Debug CSRs */ + [CSR_TSELECT] = { "tselect", debug, read_tselect, write_tselect }, + [CSR_TDATA1] = { "tdata1", debug, read_tdata, write_tdata }, + [CSR_TDATA2] = { "tdata2", debug, read_tdata, write_tdata }, + [CSR_TDATA3] = { "tdata3", debug, read_tdata, write_tdata }, + /* User Pointer Masking */ [CSR_UMTE] = { "umte", pointer_masking, read_umte, write_umte }, [CSR_UPMMASK] = { "upmmask", pointer_masking, read_upmmask, write_upmmask }, diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 7760c4611f..041a0d3a89 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -412,3 +412,30 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) return false; } + +void riscv_trigger_init(CPURISCVState *env) +{ + target_ulong type2 = trigger_type(env, TRIGGER_TYPE_AD_MATCH); + int i; + + /* type 2 triggers */ + for (i = 0; i < TRIGGER_TYPE2_NUM; i++) { + /* + * type = TRIGGER_TYPE_AD_MATCH + * dmode = 0 (both debug and M-mode can write tdata) + * maskmax = 0 (unimplemented, always 0) + * sizehi = 0 (match against any size, RV64 only) + * hit = 0 (unimplemented, always 0) + * select = 0 (always 0, perform match on address) + * timing = 0 (always 0, trigger before instruction) + * sizelo = 0 (match against any size) + * action = 0 (always 0, raise a breakpoint exception) + * chain = 0 (unimplemented, always 0) + * match = 0 (always 0, when any compare value equals tdata2) + */ + env->trigger_type2[i].mcontrol = type2; + env->trigger_type2[i].maddress = 0; + env->trigger_type2[i].bp = NULL; + env->trigger_type2[i].wp = NULL; + } +} From patchwork Wed Jan 5 03:01:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=S8I2n8o+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTDz24JqXz9sSs for ; Wed, 5 Jan 2022 14:11:26 +1100 (AEDT) Received: from localhost ([::1]:40668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4whv-0008GA-Qp for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:11:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYl-0007l6-Jf; Tue, 04 Jan 2022 22:01:55 -0500 Received: from [2607:f8b0:4864:20::535] (port=44717 helo=mail-pg1-x535.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYi-0007Qu-4V; Tue, 04 Jan 2022 22:01:54 -0500 Received: by mail-pg1-x535.google.com with SMTP id y9so5809157pgr.11; Tue, 04 Jan 2022 19:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JHwHfuV9hmWrxQ5VW+DQoxoqfBUBj55UNvF+Xci6R6M=; b=S8I2n8o+RfNnWvQMdrWAKVuvNZVYgK11tO4c7DoOu1MG5/9qlarxSRdrIvYEmahjzj MYMNwsxlrXwrmXdpjyTxosrZy8uwGp6SGvdggKblassCw0ZMJPMTHkarDJnsWgRjGko0 Hn/TRSbROBIibok6Ta5/zz2/FPu9RLV7DnZU/RpVaGWTbn4rt+/eQihF0B+WCaEncCgF /2g4WzswMh3Dpsa2n9mhUO9F4e5Mqk9JebqDbN1eqPcwCCNnS9/O0UHpz4fZreIDFowC HUT9KN9OirnNVhSVCxXEF9WTtAWO1XB8E0xUfiS01FqzYxfXT0MMhvvvyrY3lSTcjyhO f+Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JHwHfuV9hmWrxQ5VW+DQoxoqfBUBj55UNvF+Xci6R6M=; b=tBHn6hCtTR61REw19NWic3PvZzeBrya2VEcT6h4vFCO/QKTrmEBydsvf/B0Cvur1l/ 5p89K6F80J/R3tmzq76RLtjPWlKKHBKm8MHySmdjwR246OyY7bBcHgpMMz/HSE5VxG5t +8pwFIeeXr4KdgcMBpJrpJDNwD0TJINZT1UvoaHOarJrcGOPhQiazJqFmMBCJZcm8hsn SymUB2RBaF0QT2hkoffju+iwIuG3fzAWVKvs7s4E2DQbtcPC10SaSxtMKR6/Z0ZD3Iq7 nCVuvyMMVgmOI/wN5DOSrKJxqYUWaN7jdc9ICtDKia43XSlNXQJYfuZef+ZfaKNTD5Hf DMIw== X-Gm-Message-State: AOAM531A4+DAnu1LHwW/V6rj5ybLhFns/OZuh4Vs1knCu36pR0hR2WZc b5G7Mu8PFjufm2RevTeBwCS4aVVRTP9yJA== X-Google-Smtp-Source: ABdhPJyYrxjdl1BMImyElA06pYYmJMbIN+NDi5X9xUpTmGqtx78+XfnFf/hlg6/vP71HJxmLADf4AA== X-Received: by 2002:a62:83c3:0:b0:4ba:bb14:4bf7 with SMTP id h186-20020a6283c3000000b004babb144bf7mr53275627pfe.32.1641351710507; Tue, 04 Jan 2022 19:01:50 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:50 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 6/7] target/riscv: cpu: Enable native debug feature Date: Wed, 5 Jan 2022 11:01:25 +0800 Message-Id: <20220105030126.778503-7-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::535 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Turn on native debug feature by default for all CPUs. Signed-off-by: Bin Meng --- 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 17dcc3c14f..17444b458f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -644,7 +644,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, 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), DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), From patchwork Wed Jan 5 03:01:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1575444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Qf6MWi6z; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTF2z0gLxz9sSs for ; Wed, 5 Jan 2022 14:14:51 +1100 (AEDT) Received: from localhost ([::1]:47860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4wlC-0004m4-8e for incoming@patchwork.ozlabs.org; Tue, 04 Jan 2022 22:14:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4wYp-0007pF-4E; Tue, 04 Jan 2022 22:02:02 -0500 Received: from [2607:f8b0:4864:20::42c] (port=45629 helo=mail-pf1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4wYl-0007RF-Jt; Tue, 04 Jan 2022 22:01:58 -0500 Received: by mail-pf1-x42c.google.com with SMTP id u20so33906632pfi.12; Tue, 04 Jan 2022 19:01:53 -0800 (PST) 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=5bL+vAVfqamThQbeWL59vSKO++Z8CFNPuWObUfqmti4=; b=Qf6MWi6zCBhvZotZHxY2ZiZUa87X4lpf0ohnyoOmgZeYlOC5UXOsVxq7Nf4S1AZax9 xNSUhIDnd+dBczTL0y7u4iXvVz96u7z/eCKl40K0vd+eSuV37TfcxzjGLBABLTV3R5Tt ppjxHLRHriRwqVFsRjF9smc980SDf1+uM8lilTNy5Ug6Nm4kb+sFFQpC2T1xBW/BpbiW ZzDngrTvV7ACyKWJ0LpNFkUrYsnyDHptU6P9kr5DMOiQz3xH4bP9DAGtUKrcAhsSQ8Ok UE28hwNHfaCNeB4xSdf5sgU0S7gZNXyley8NkmXmIl1eja7v7yDzKGFQGeiBBCx/WmyF WcNQ== 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=5bL+vAVfqamThQbeWL59vSKO++Z8CFNPuWObUfqmti4=; b=rV5iyoXBH+3y17N7cOmN9oCuwlGT067OxdnfgIZqxt9TX67rA6L5wLc6nbBKEOjcw+ e+/KbLsFUdLg/VPuj02MOYK9cKXRkEPeq+kKqZWatkhkMP6kbc8TLVgiFgghiwcgXjIo aukTV+FRHwjE3EXsTEtGjpSPFaCP8GuGsZYEpHp6jzVcmlftKU8LT/8wv29h4ZN0TJEe 97CM+FVuc5ZWzovssUG1uzxhUqCfk1Nqn0xJRWDIAJSSNvg2OShVkuTWQNSwyOMqZo3s hiJW0PVLTR11n2zQnMf2DILm5oawp0uAEjZU9XvR2n8FBHvPzPqCmbP9hh8PwZXDtz/C oBQw== X-Gm-Message-State: AOAM533vYvNR+8yDNsi5HkZ/IDxEcUj7LT03axd2p8/vg+Yo5fyiKrzV Ddd+eurVYloT+QfH7bXHqJ8= X-Google-Smtp-Source: ABdhPJxJyhot7qV/EDoSfvQtyfryk7aeT41e0hYX8WfCbR+B0kzkmVymBJlNH86tMr+6HvFV15bnLQ== X-Received: by 2002:aa7:91c3:0:b0:4b0:eebe:49c0 with SMTP id z3-20020aa791c3000000b004b0eebe49c0mr53931672pfa.6.1641351713126; Tue, 04 Jan 2022 19:01:53 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id nu14sm23011pjb.17.2022.01.04.19.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 19:01:52 -0800 (PST) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 7/7] hw/core: tcg-cpu-ops.h: Update comments of debug_check_watchpoint() Date: Wed, 5 Jan 2022 11:01:26 +0800 Message-Id: <20220105030126.778503-8-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220105030126.778503-1-bin.meng@windriver.com> References: <20220105030126.778503-1-bin.meng@windriver.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Alistair Francis , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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);