From patchwork Sat Oct 30 13:55:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0E17C433F5 for ; Sat, 30 Oct 2021 14:01:12 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5BEE36023D for ; Sat, 30 Oct 2021 14:01:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5BEE36023D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:38722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgov1-0007i5-D2 for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 10:01:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopb-0007Z5-6B; Sat, 30 Oct 2021 09:55:40 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:35702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopW-0000ci-88; Sat, 30 Oct 2021 09:55:33 -0400 Received: by mail-pj1-x1036.google.com with SMTP id n11-20020a17090a2bcb00b001a1e7a0a6a6so12865928pje.0; Sat, 30 Oct 2021 06:55:26 -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=t0fMBsVgX54b5FimLbUFM5Y5GG8PsYQTLJ4UUH0xg/0=; b=edtd4gqGyN6eX3zb31ADVEaIRY+25YMZl5Qra/Rslno4uxIzTT52ydAJlXJyq5CWH2 g7cSSUuIvF3ryk1wW9ybJmMj1NNCFjh3jJPLznYUQYE/7u2Pjek8C1hEhqYCT/znGeAQ 6JC0Z4XBeLIwkIshoozZ5cKe0/z2y0w1ZTsrirO2mi707X5qMoMm5KvppHxYNbG8zm+6 6A+9+vl0/5bF/8KDJxfT8G4CBNTV+wnQprwE7334uB8ax11ykvzG8UA2d32kQhRLaXbH bqbnjTfeXV664ekk5J14e8gskPRyAdt2K7vOp3s/EJWd9jhyPvTpBO8OrmnyFkO7oS6k CMwQ== 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=t0fMBsVgX54b5FimLbUFM5Y5GG8PsYQTLJ4UUH0xg/0=; b=h7+EBnuLxyvzbIyVA9bZvyvuc4N1L31KdSYBnRCnGEFCvlMFLeqRoqXxuDwgCCkJfi O8Djjw1v62/vbmCsUZTYgABEfnvnUqdQ712xltDWq8Flzc+2YgbstX/IaFzq9F6wRm1I UIERjreAoOvjIGCjcU6XVuJF+YpWq3lDPkoro2SKlJpO6XISBlfJMTcXfUmt2CH42NxI bb8wa2ve1zAQEyuVMM3V1Tffr/4+Lr/sMCAvul/l3b020dJIce0HT/szoh8A5EDb2FKs fe7pVQqyBkVVvqvc3nPbgq35Gw4+19kqmhTFtOzfPXzeiYb5fQwSqhUE3dhcMCtixoYs z78g== X-Gm-Message-State: AOAM530hlj/6D1Ww4Aa/aFUKKCDEziOL+2yYTZdOVTmRDH+FLgOfr8zW T1eBXPD2CdEkkfcIx8DSxpk= X-Google-Smtp-Source: ABdhPJxRoD6h4+j8h4PzmkaHkqWdO4q50YGov9Y3hDLtIauGi89RK9j/wrDeswr8N7igkXcnUsFL1g== X-Received: by 2002:a17:90b:3b81:: with SMTP id pc1mr2056718pjb.67.1635602124898; Sat, 30 Oct 2021 06:55:24 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:24 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 1/7] target/riscv: Add initial support for native debug Date: Sat, 30 Oct 2021 21:55:07 +0800 Message-Id: <20211030135513.18517-2-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- (no changes since v1) target/riscv/cpu.h | 5 + target/riscv/debug.h | 110 ++++++++++++ target/riscv/debug.c | 366 +++++++++++++++++++++++++++++++++++++++ target/riscv/meson.build | 1 + 4 files changed, 482 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 0760c0af93..1fb13e8b94 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 256 @@ -232,6 +233,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..cb8a6e0024 --- /dev/null +++ b/target/riscv/debug.h @@ -0,0 +1,110 @@ +/* + * QEMU RISC-V Native Debug Support + * + * Copyright (c) 2021 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); + +void riscv_trigger_init(CPURISCVState *env); + +#endif /* RISCV_DEBUG_H */ diff --git a/target/riscv/debug.c b/target/riscv/debug.c new file mode 100644 index 0000000000..9bcca27b72 --- /dev/null +++ b/target/riscv/debug.c @@ -0,0 +1,366 @@ +/* + * QEMU RISC-V Native Debug Support + * + * Copyright (c) 2021 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); +} + +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; + } +} 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 Sat Oct 30 13:55:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 732C9C433EF for ; Sat, 30 Oct 2021 13:57:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F1E1F6023D for ; Sat, 30 Oct 2021 13:57:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F1E1F6023D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:58292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgorD-0001xO-4r for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 09:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopf-0007ZP-67; Sat, 30 Oct 2021 09:55:42 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:43959) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopX-0000eD-Fw; Sat, 30 Oct 2021 09:55:38 -0400 Received: by mail-pg1-x536.google.com with SMTP id b4so5618662pgh.10; Sat, 30 Oct 2021 06:55:27 -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=pmLuHzlvcb9WcoNLmfNdT+VYLFfi+YqVA0HLjJbSjzU=; b=TGAEvS+mR2N/PY11Pzet140i7MLxASlkFQcTC/2rmhEnu1oJqgFPupMyY64ljSrV81 TRuBBBWOw3Mrs+hV7OdkYS+kkSczb8T+aTw6NmHjIYjGmFMS+zH/p33ATJ+KHoOfz4lJ tYenbHvzuprUl7CfgtLsKeXQRZptwHvCM9Sh97ARj5WBluf5P/ZukRXylmJOUSjER8+u QYEs6+OvhviEx9PzGKqFoiERdO2g8UtA2/8PQcBnPS21+oDhtdKfekibDppnxMe6SZhG KD780C4AlUUoaois3L4gDwkSPkEPuDMg12fjHbp6g6a0bPw+1XbIx27ncumb5A9VERFK qSDg== 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=pmLuHzlvcb9WcoNLmfNdT+VYLFfi+YqVA0HLjJbSjzU=; b=eiCGryYMuoFO8jTSWhpUidW4Z0Le1n9wb99HrzJVnhQWUEFdMcEvOpvKCHxkQ4b2by G8ZpRSw+7mfCpt/YRY7dV82ZNfMgjP0XA7px9kq8LFY9NddBh2+MpZO35+vUDGDoH1Dq p9QF+OTBw2ceLf38KCnBAM/ymB0f4xexzzf3pP8FeIKixfmfVYjjivRUKGUNKy/HDrc3 df7OZ9sGT9B27FGrHpkQIYZggWyB8hWI5YY+H53611/GMwdlB8UoNyAi8FTKb/19T4tT kw+ik6y2UPKbN1AWwh339neSSm0OL0hoZXHVnFxBXzLA8Jt12De3j/CYLJbwppcYZGR2 CF/w== X-Gm-Message-State: AOAM533jGCPipCWxusLRMdUMvkXaE4iX4LaHJjMYFJPh2JniYfRQFAtH 2A6U2g/dfiAeyQn6Gvciham6UglUlm4= X-Google-Smtp-Source: ABdhPJwi61T7xbSjMeoy3ZZNnPVh/Jo2alySGef9chh3I4Myl52i7HdTXZXCG7SRk8cuCZ11yoLtfQ== X-Received: by 2002:aa7:96f8:0:b0:47b:eb13:e0b6 with SMTP id i24-20020aa796f8000000b0047beb13e0b6mr17488645pfq.27.1635602127035; Sat, 30 Oct 2021 06:55:27 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:26 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 2/7] target/riscv: machine: Add debug state description Date: Sat, 30 Oct 2021 21:55:08 +0800 Message-Id: <20211030135513.18517-3-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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 --- 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 Sat Oct 30 13:55:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975F3C433F5 for ; Sat, 30 Oct 2021 14:02:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1041C60F55 for ; Sat, 30 Oct 2021 14:02:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1041C60F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:42306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgowQ-0001nW-VE for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 10:02:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopf-0007ZO-0i; Sat, 30 Oct 2021 09:55:42 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:37886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopX-0000eH-Gx; Sat, 30 Oct 2021 09:55:36 -0400 Received: by mail-pl1-x62e.google.com with SMTP id j1so2208193plx.4; Sat, 30 Oct 2021 06:55:30 -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=fHWPFSJTbsCE/6vTsngF6JkT4vnK0upjYRXJ+ujZ4fg=; b=bJwfnVROJPtR8n4Ic1AfKVgR3syyXuBhY1eV7maHnIjBiB5s2KT6A6q541WAogUBEj nwhGtScXptijs+wPVJkPm09Cl3KnncuEpc8xHtsaiyhB3XM5mrXTiqqsEXPtUzu4kCb0 V/6JRS7bGPvPOZlfaeVx0FNe6fXMOLQP1SKyxxFzvbspSdtprgC7EtdyLb7Mvm2qZIb4 MbdAKYHlwQZLSqjcKHxFw0N8SsQtOB+Xz6Uh5707JFV8tuQtXdmXe4rPjLqryQ5BV6Vw 2vUbMjY1+cfvWA6QzNaCZ9WYSEwBgt1SPOz4cD0nD3yRV6ZBvT3M7J3nWfUevKNVvFXF 4WHQ== 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=fHWPFSJTbsCE/6vTsngF6JkT4vnK0upjYRXJ+ujZ4fg=; b=ILo/5179CFXo+cBGGedWv3G3H7lkcT7ZzyDvmgwFyX3OOWXaAdlaHBiCfyrG/TkUy9 keKrQo/t+xBTIH241CZq5wVC7iXIKQxLfoI6+xsZJP5ZG0hGAZIKzJwrZcrlCzWvZXJF mc7laLWtd4PluBQVjPq98olRNV6g0Nis16EKuatnQROr1gEcJ2MX8dWAwsYnWdLqESl5 +EOkEZ5FfVf61tVhhnZsLP/UoguWTx5vezukU8P62bEd4R2RVDVHeq8hyVXkwKqDcXgd 1J1CU5NOJuiSdm5u2tkyzEqZk7Dz02XSBSr3FlNfxcAn6CIc/xTvfShq3TCIZX0R/sIx lPsA== X-Gm-Message-State: AOAM532jUbvV1RIMpIvckh1RQP0VyVpicz6/jelNfukQZgSXIxFi3F8u umoIwvMqKWhIXzkKm/g0g4Hr7Y0NUv0= X-Google-Smtp-Source: ABdhPJyq09KiOmOgZw7CHIyR7Qr3AJwuBpKcz/DmY0NozFYruvGXTeY0xQaB09CBX6OgPqX0qVwivA== X-Received: by 2002:a17:902:d4d0:b0:141:c13d:6c20 with SMTP id o16-20020a170902d4d000b00141c13d6c20mr4352582plg.44.1635602129201; Sat, 30 Oct 2021 06:55:29 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:28 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 3/7] target/riscv: debug: Implement debug related TCGCPUOps Date: Sat, 30 Oct 2021 21:55:09 +0800 Message-Id: <20211030135513.18517-4-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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 --- 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 cb8a6e0024..fddc103650 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -107,4 +107,8 @@ void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val); void riscv_trigger_init(CPURISCVState *env); +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 7d53125dbc..7061ae05fb 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -701,6 +701,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 9bcca27b72..9cb2a6d7ba 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -364,3 +364,78 @@ void riscv_trigger_init(CPURISCVState *env) env->trigger_type2[i].wp = NULL; } } + +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 Sat Oct 30 13:55:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D073C433F5 for ; Sat, 30 Oct 2021 13:58:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0C05960F55 for ; Sat, 30 Oct 2021 13:58:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0C05960F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgosj-0005xa-6O for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 09:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgoph-0007ZT-20; Sat, 30 Oct 2021 09:55:42 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:43914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopb-0000iO-8x; Sat, 30 Oct 2021 09:55:40 -0400 Received: by mail-pl1-x62c.google.com with SMTP id y1so8689897plk.10; Sat, 30 Oct 2021 06:55: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=m/EL/5IeIfZtcKl68A4SvFzBb7yrmJRRf3J6MnZmVv8=; b=ayAoNt1kjIzpaKU7ZFOaZuJyVAu/055zC5Lae+zz4hlsmt0ekX9Khp8Q8QVs4yNK5M CIH9pIT+CAZyysG6iHQxRBfOVyB0ODcrbdtXTlvgcq/60VrHqgI8yhtD5CkQLm7u4q3v iQbKbEYAtw0HKDoZNIaz9LWmc9S1RIBW++d2pR+5shUEPcED3Xj0sNzvNPb/rAT+RQmJ ZT9mP2WnUzlOISYc1mRxHFWUIlF93wpqzK3tW3MVcSsvtkw9gmZdbYvkIF3f4ndCGpdH s6EyGPeRTtWXUEpWTx3rY9meAHz3Fx/YgCW4wU4CC6szZjNAODfDGTFjPKG7crmb0bOQ l/wQ== 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=m/EL/5IeIfZtcKl68A4SvFzBb7yrmJRRf3J6MnZmVv8=; b=QnlXwbRppxQ6gbqUbpHnGM/HR76IW1BrOV09GS8TtsahzLv5T3l1UqXwRBkkgtXUXe 9DIrtI4j6Pw2TV22FxXj3sDj3p+azr8Lkq7zvI8jvhAtm9jWxN8RuEyow4mMJ4dYj53W swlogJyB1ypvwmwmHhvP5H3fPSjl2MCVD/+HmKzlrOpTBahG0BDD39NW7C2eQs3MwAaT jO8VKdz9MtO0igHsmbKqFwf8KlVLPHcvnmQdDBNZGXAt/uAyKy39nhIyvLcRG1HsYjr6 0yuwHTo8yBqilaxQ1+Rhz6uY8ezXlFvYdapb6Surs4aw2IrlhfikmE13gRQykGQpapth O6XA== X-Gm-Message-State: AOAM532an5XZGEl2n8P7YqrjvzQ55gzEt29lxRh0rD928XfZXV0A1nFH YhG8GH8yEnTeuHcFjXMagg4v8wnpr5A= X-Google-Smtp-Source: ABdhPJzvaFiExvLXOfIzlU9b2cqBx+A/DmkmK+Ygb8raD6tlgPiFriCFP8S88sbd6NQ4i/g3GCygiA== X-Received: by 2002:a17:90a:de0b:: with SMTP id m11mr18102021pjv.90.1635602131405; Sat, 30 Oct 2021 06:55:31 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:31 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 4/7] target/riscv: cpu: Add a config option for native debug Date: Sat, 30 Oct 2021 21:55:10 +0800 Message-Id: <20211030135513.18517-5-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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 --- 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 1fb13e8b94..b2301425c2 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 }; @@ -327,6 +328,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 7061ae05fb..84116768ce 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. */ @@ -631,6 +635,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), 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), From patchwork Sat Oct 30 13:55:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDA22C433F5 for ; Sat, 30 Oct 2021 14:04:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6CB5A60F55 for ; Sat, 30 Oct 2021 14:04:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6CB5A60F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:46712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgoxt-0004is-G3 for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 10:04:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopi-0007Zq-J1; Sat, 30 Oct 2021 09:55:44 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:35329) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopb-0000no-80; Sat, 30 Oct 2021 09:55:42 -0400 Received: by mail-pg1-x533.google.com with SMTP id q187so12728408pgq.2; Sat, 30 Oct 2021 06:55:34 -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=2w2rWkWQgxMSRivPeqxiHaIgdJq2xlXTxmXJwyRNbVU=; b=kBuqRk3pFhisJkoLYP3F7OO85R89QnfVoTkgnWAM7I7lV1EWUDkueC7mHfmrpWfHI8 z6f6/VDv7vOUMW1B0YxCdyoP0eQ8aV3HmHBrEsv4o/J8ymJKzC96z86ef1/eXdPyZPi2 6T+ZJyKx05wLEHCAH8wilccDuiLJBdR3C5KrmhFiF9cWpIuUo4TEe6F+8Vbl7oNOe4RW QduQPZv/MmnQPFW+RnllINM4AChLQbj/gLTlunW5ExwhaMm8n/MqzIi5FNvTwAPNWCNY rW+tqoBKr8Bc34Th9CcwWiQtAEu5OuJn1mbNqVRMMCPJjWNReK4n5ythtkfdgTlnl9p8 1iqg== 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=2w2rWkWQgxMSRivPeqxiHaIgdJq2xlXTxmXJwyRNbVU=; b=SzKKTXmbICM05sHGRZnuLlBNcKJr0jo27KrQftF7NFyt/MCPS7fc+DdaSdBKzCmMGU ZpyvjHy6amGb+719GXseS4944zYNS/lgd/XL+URmXFEsNeF+APFpbox3ZIlfTvKiZ9Os TFeG2aOWuCFfdHRnwIsREE6uGeba9uGZYx0kphonwcA6IH02sv+5jhu1zWLhxb49DovM nSSIQvoywSOqHqszKhZlUOm5uXyIGqdHbIHN3umL/JzZpyXUamDjcp/jQWDI9fU77NJG 1fgYROM7RQQe9BZoHJC97I8ohAvLu5q+nSnR3u8UDSps4Y+GWVBsqJMBtfMgVPqjHhx3 uHNg== X-Gm-Message-State: AOAM531gYrMYmgu8x9h93L8chBt7/C85jQiwR4D3cfuGywkrhKZxJQ6U miSJ4p5kSwY5C+hWn23rv8cj9lNJQBk= X-Google-Smtp-Source: ABdhPJxVGzpx/3p5ghsCFzUzFkQlDr0omFRCR2hBdBm1b0KSzY/Hn9hJqw8Q2oPbCK3c1ww6/oM6Jg== X-Received: by 2002:a63:a801:: with SMTP id o1mr13023992pgf.23.1635602133660; Sat, 30 Oct 2021 06:55:33 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:33 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 5/7] target/riscv: csr: Hook debug CSR read/write Date: Sat, 30 Oct 2021 21:55:11 +0800 Message-Id: <20211030135513.18517-6-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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 --- (no changes since v1) target/riscv/cpu.c | 6 +++++ target/riscv/csr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 84116768ce..6f69ef4f50 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 9f41954894..dc47ec8d3b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -219,6 +219,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 */ @@ -1435,6 +1444,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 @@ -1931,6 +1982,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 }, From patchwork Sat Oct 30 13:55:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDB83C433F5 for ; Sat, 30 Oct 2021 13:57:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8CEFF6023D for ; Sat, 30 Oct 2021 13:57:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8CEFF6023D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:59512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgorQ-0002kv-L6 for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 09:57:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopk-0007bN-Px; Sat, 30 Oct 2021 09:55:45 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:35404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopf-0000tC-2d; Sat, 30 Oct 2021 09:55:43 -0400 Received: by mail-pl1-x629.google.com with SMTP id n18so8720521plc.2; Sat, 30 Oct 2021 06:55:36 -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=+5qBDsm0HSeypgcWR5fXXbdqYJxVroc0DuPQz42Qsh4=; b=MzZYKSAjHgaQkcTHe2i79OBrO/X67nZmxpE2OhLUt16yPrLJGHPsWoEgDEK3u0jpCO Mce2Om6937iTJ7SsSkskP/5nqzwCqaBilJULctvxgdEaaWpLTAjJRnu/1rXfr4NOmPUv pfaA7zXhF8KfqvDLMFKWZ1cKNKbpv2mhgM7Z7uFHfvg6KJt40rPg0/L1E9BlEWq7LxyD D2Vnv/xy2TanM3zXyiSo+19vPnQDA6V+BZOei33mqaFIGMt6sIVPLeLlYNwKh6V0oKJV YyCWHLHPZV/P3iVkhrUdEIqNck5uF1BELmUvCPJMfi4ViRPSh+EZ+Fx5joU6wB/amZVL So9w== 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=+5qBDsm0HSeypgcWR5fXXbdqYJxVroc0DuPQz42Qsh4=; b=xGAyzYj53ozoj2tsxQPoQT4oDrlz+B2dmIN3LLwXHvpJgBR0a6Im+T1y40jvCv6Zhh FP/z2ZEqhYK/KFltYqvKnAWRdRPrzJftABBXVVlWoS0tnFCAyi1OsP4m2pIsmj1cUw6V CQK2tAGLdHx6Hcfz0fmByIhxjAfocR6aMHu8vkuXaoEpL9cNUWLu+AL1jj4tpMLCL89y GZ8wm901GmlfJ0ZBy1vjNwmwJKsw9RnYwMOTbv+nYA0du+Teawoxk+kCv+OBnBm6i8Qn v0Ew8GOvQ3aACYjnW7csaU9keR5UnhGjX/J2pMyCNHr25cWZ4GpIellqRKEqaUw1yp7f vl1Q== X-Gm-Message-State: AOAM530JB/r9wPlmoGHlv42sE7QqnWu2JzFczOBLQdxIYX/4foQ22bVO NeZryv52hgfE5obFhODcIK3CnD4urlY= X-Google-Smtp-Source: ABdhPJyn417d0jCPE6w3KMLQNfGQ4mV2NGzGrRV3NCkrfESiPaWDfG6HOjo3VLw+MuGkvoh+0lMBrg== X-Received: by 2002:a17:90b:1e4a:: with SMTP id pi10mr18294138pjb.142.1635602135889; Sat, 30 Oct 2021 06:55:35 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:35 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 6/7] target/riscv: cpu: Enable native debug feature on virt and sifive_u CPUs Date: Sat, 30 Oct 2021 21:55:12 +0800 Message-Id: <20211030135513.18517-7-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Turn on native debug feature on virt and sifive_u CPUs. Signed-off-by: Bin Meng --- Changes in v2: - new patch: enable native debug feature on virt and sifive_u CPUs target/riscv/cpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6f69ef4f50..b4d3c58dea 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -153,6 +153,7 @@ static void rv64_base_cpu_init(Object *obj) CPURISCVState *env = &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, MXL_RV64, 0); + qdev_prop_set_bit(DEVICE(obj), "debug", true); } static void rv64_sifive_u_cpu_init(Object *obj) @@ -160,6 +161,7 @@ static void rv64_sifive_u_cpu_init(Object *obj) CPURISCVState *env = &RISCV_CPU(obj)->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); + qdev_prop_set_bit(DEVICE(obj), "debug", true); } static void rv64_sifive_e_cpu_init(Object *obj) @@ -175,6 +177,7 @@ static void rv32_base_cpu_init(Object *obj) CPURISCVState *env = &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, MXL_RV32, 0); + qdev_prop_set_bit(DEVICE(obj), "debug", true); } static void rv32_sifive_u_cpu_init(Object *obj) @@ -182,6 +185,7 @@ static void rv32_sifive_u_cpu_init(Object *obj) CPURISCVState *env = &RISCV_CPU(obj)->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); + qdev_prop_set_bit(DEVICE(obj), "debug", true); } static void rv32_sifive_e_cpu_init(Object *obj) From patchwork Sat Oct 30 13:55:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12594379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18217C433F5 for ; Sat, 30 Oct 2021 14:03:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BD8D760F55 for ; Sat, 30 Oct 2021 14:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BD8D760F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:44694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgowv-0003Nl-Oh for qemu-devel@archiver.kernel.org; Sat, 30 Oct 2021 10:03:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgopk-0007bM-Pr; Sat, 30 Oct 2021 09:55:45 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:40506) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgopg-000163-Ej; Sat, 30 Oct 2021 09:55:43 -0400 Received: by mail-pl1-x631.google.com with SMTP id v20so8695187plo.7; Sat, 30 Oct 2021 06:55:39 -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=jq/AJG1e94yzZN5jEfbJDx8a9/xfRXa5WXTkgDnhylM=; b=I2GhaNWWEqBf+5XlHKzNMrw1Pq7IHqP/u8MgvazzzKFTstPEPvhLN46Sz+kgaigqvM ESSSn9pPMLg3Wa9F/JqbsBkGZsPNvnw2sB5SttenCi755NlwjVMNoTh9Qm/AI9YyeOkT 0Kdt9N2TztFc0Kn6ROPEwhvXrJndLLDC3t2bw+Gb6IGrlUm1bxP1n9oqsP1ehchO3KCl pkVNXqlyUSB14R7uuKOHOMA91sY1MhQ5r3Lzm40nIH+vcR6OewssnFv3icMwjaeNEsDt UrdmcZSGsNXO41nl+Yg+LjrjoA4Y/2GMkz/MBGDctJ93afEkzLKld+RXvEVxTEY0k3nG IX4Q== 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=jq/AJG1e94yzZN5jEfbJDx8a9/xfRXa5WXTkgDnhylM=; b=yI8jP1xNGc35O835NRp6RBAmfsFn+TPNOA18kljPrtbvo1lC2EnNwYy6vlmYUioQo+ IILwxCDnMcbg6Q6KuPO7k6YPy2xj/UOle9xD9DGPAeYmF6BkOIIMq4aiAZT4uSiUpyCK kd8uiecQ0BNxLBD6CtJYD8zDRiSYgjgkaqBqnaqt0CVyr7Jj4YECdjejmJsyXxvtXovM ObTXxPzi5JhAabGxIeVs+PFqZ10+fXxFMdi/Tgm3vHSQJtYy1ZmrvObHSazaJemvFhMf zsjFzE9y/guf3sKY5mqZZXaXvnLIXHlOF8S2nIh6tuEn1V0vQVhfMeRdEWeYJkxA239u jvhw== X-Gm-Message-State: AOAM532kcZ6aYsWd37AGE1u3oKg9OxQMuf+hAcDYvb6fJstFrt8MGSNd tRilhUUPeGoZx/xgnPQZ21U= X-Google-Smtp-Source: ABdhPJyXlyaEW5pm+BSu6HyWjC6xdGDrbSn1DIHni2dxAAp50CtGFG1WSRhjx0uB4QdYRbpVcr4J/Q== X-Received: by 2002:a17:90b:17d2:: with SMTP id me18mr17850864pjb.98.1635602138202; Sat, 30 Oct 2021 06:55:38 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id f19sm3645911pfc.72.2021.10.30.06.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 06:55:37 -0700 (PDT) From: Bin Meng X-Google-Original-From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 7/7] hw/core: tcg-cpu-ops.h: Update comments of debug_check_watchpoint() Date: Sat, 30 Oct 2021 21:55:13 +0800 Message-Id: <20211030135513.18517-8-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030135513.18517-1-bin.meng@windriver.com> References: <20211030135513.18517-1-bin.meng@windriver.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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 6cbe17f2e6..532c148a80 100644 --- a/include/hw/core/tcg-cpu-ops.h +++ b/include/hw/core/tcg-cpu-ops.h @@ -92,6 +92,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);