From patchwork Fri Mar 15 10:26:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chih-Min Chao X-Patchwork-Id: 10854721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4EFA17EF for ; Fri, 15 Mar 2019 13:16:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1E312A971 for ; Fri, 15 Mar 2019 13:16:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9421C2A9AC; Fri, 15 Mar 2019 13:16:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 06EDF2A971 for ; Fri, 15 Mar 2019 13:16:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:54879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4mhY-0007Io-8q for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Mar 2019 09:16:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4mTs-0002xT-Nq for qemu-devel@nongnu.org; Fri, 15 Mar 2019 09:02:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4mIi-0002Fn-1D for qemu-devel@nongnu.org; Fri, 15 Mar 2019 08:51:05 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4mIh-0002FI-K7 for qemu-devel@nongnu.org; Fri, 15 Mar 2019 08:51:03 -0400 Received: by mail-pf1-x443.google.com with SMTP id y124so6287217pfy.7 for ; Fri, 15 Mar 2019 05:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p6d0GA99LAXC7XnfUodoVRLVgpyVio+21sLk2vfOc6Q=; b=ivWugT+YFCE28S+caPx7XlCIH4qc/vIvfJBuJ7vYnqtam+hSY/FZciHa72+xOOuEk0 BmpcmRxMWDOa+28PaLXb/975Ddd4cyK/PrzboxFu7IksWAxSRhQDJhwYpsTqRYnRLLT2 RDDdd8ccOawCi2zCjb3EmXLb5BixCzZWwdB3cQZ9hOYpSu6ItMOlABt0TbE/R2xWlZEy tFlyRrU/6b9GF+vLy402x0fv9hpFdjUAEgdRWX7vPp11ymxWdu7y+8IYhGbh7sKJoJMe Iiss1pG5BnfXD/HtAbH5OlwMvvz17qId8abgDyqpiALOCOaEMV+urSkwi9fQX4XDXXTk BQgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p6d0GA99LAXC7XnfUodoVRLVgpyVio+21sLk2vfOc6Q=; b=oyvTQtPCoqQ7q6s2yiCVKt+nbC6sw0egqv0sx4zDwx2v9dbYhFN/hSZY0JAf0sdNLb V9IGS3CYlxbzfdJKvl/7ycHyNh4ZOt5fS6Wfc0t457MJRdrP8nVC1AKDQX4dXA8lp1F7 +NvaKonGDrJQDLky5b+4GmQfpxQbi/NFcYZ3KChuZSJxgUm3Tqj31qNn/Q+grVBsNDxu OFRW+7g8C8uEgkQ9NyrH+OPX85AXFL3PRbtnvSiJJSdHzQoHzGikJAYl/kNJ4wKRXGBc BZ3zxrtX9FAda/SfNYnAaVZrwLGiZsWSJqk29A7p5RkwKFVT66QhCRd1M57T2S1xwoIk 1L8Q== X-Gm-Message-State: APjAAAXP7re9S3mttAHnLcl+GURWf7kmP31VlV31AvDGiYNFsNG3AfR1 AwDVHg5YM8sOOsEm4+xWwya6LE1Gw2tdyQ== X-Google-Smtp-Source: APXvYqxLBjZvuOLM8RaMTpffZnQPZqYqAUkbRR2DDw2Bi++MkQtJRLOJYWubuUoxJGYt9I6IhdE3ig== X-Received: by 2002:a63:fe0d:: with SMTP id p13mr2589493pgh.366.1552645668877; Fri, 15 Mar 2019 03:27:48 -0700 (PDT) Received: from gamma06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id f15sm2225401pfa.11.2019.03.15.03.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Mar 2019 03:27:48 -0700 (PDT) From: Chih-Min Chao To: qemu-devel@nongnu.org Date: Fri, 15 Mar 2019 03:26:58 -0700 Message-Id: <1552645619-18244-5-git-send-email-chihmin.chao@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552645619-18244-1-git-send-email-chihmin.chao@sifive.com> References: <1552645619-18244-1-git-send-email-chihmin.chao@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v5 4/5] RISC-V: Add debug support for accessing CSRs. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Alistair Francis , Jim Wilson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jim Wilson Add a debugger field to CPURISCVState. Add riscv_csrrw_debug function to set it. Disable mode checks when debugger field true. Signed-off-by: Jim Wilson Reviewed-by: Alistair Francis Message-Id: <20190212230903.9215-1-jimw@sifive.com> --- target/riscv/cpu.h | 5 +++++ target/riscv/csr.c | 32 +++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 5c2aebf..4c5de30 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -172,6 +172,9 @@ struct CPURISCVState { /* physical memory protection */ pmp_table_t pmp_state; + + /* True if in debugger mode. */ + bool debugger; #endif float_status fp_status; @@ -293,6 +296,8 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); +int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask); static inline void riscv_csr_write(CPURISCVState *env, int csrno, target_ulong val) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 960d2b0..9a40b4c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -46,7 +46,7 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) static int fs(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } #endif @@ -92,7 +92,7 @@ static int pmp(CPURISCVState *env, int csrno) static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } #endif @@ -103,7 +103,7 @@ static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } env->mstatus |= MSTATUS_FS; @@ -115,7 +115,7 @@ static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) static int read_frm(CPURISCVState *env, int csrno, target_ulong *val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } #endif @@ -126,7 +126,7 @@ static int read_frm(CPURISCVState *env, int csrno, target_ulong *val) static int write_frm(CPURISCVState *env, int csrno, target_ulong val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } env->mstatus |= MSTATUS_FS; @@ -138,7 +138,7 @@ static int write_frm(CPURISCVState *env, int csrno, target_ulong val) static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } #endif @@ -150,7 +150,7 @@ static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) { #if !defined(CONFIG_USER_ONLY) - if (!(env->mstatus & MSTATUS_FS)) { + if (!env->debugger && !(env->mstatus & MSTATUS_FS)) { return -1; } env->mstatus |= MSTATUS_FS; @@ -827,6 +827,24 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, return 0; } +/* + * Debugger support. If not in user mode, set env->debugger before the + * riscv_csrrw call and clear it after the call. + */ +int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) +{ + int ret; +#if !defined(CONFIG_USER_ONLY) + env->debugger = true; +#endif + ret = riscv_csrrw(env, csrno, ret_value, new_value, write_mask); +#if !defined(CONFIG_USER_ONLY) + env->debugger = false; +#endif + return ret; +} + /* Control and Status Register function table */ static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* User Floating-Point CSRs */