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: 1057002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="ivWugT+Y"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44LR0n0RCRz9s3l for ; Sat, 16 Mar 2019 00:16:08 +1100 (AEDT) Received: from localhost ([127.0.0.1]:54865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4mgw-00066l-Nw for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2019 09:16:06 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 */