From nobody Sat Nov 15 16:09:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1595311480; cv=none; d=zohomail.com; s=zohoarc; b=Nq9VHDKBeqXmVgWPq/z86ZCdyqO3Jw8Arj6Z+L+f4G4Q+ytQejNMI3PDUjkKj01DYfpMq3PCM6SXmwTUOYiISU47Vn4UjMJ0Bx01Sh8qvg9hwtcnjPFpqV00r0Fqka5Ei6h66hRMPXI7AB8VjfkqU/5WjGqcUWMySsyGsuCnRho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595311480; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lyivCZnqzhrumKaf1cp2AkSGdgwxSM8kTqrAaI6ADt8=; b=TYU319qLJO3kkGNUUXMOE2tr78NIi5BMs2UxkE0QpsGEE5sOCVSs7a4n+U+RnCMwyphqmOUTAUTWNJ4LDMLXtihdv719sFpbFa4/O/MfUFzDz3o6XmOW6a2Tk1rc7vYySjT3DhPF0LIBv/sWwToIbbp73rbPCnao9AUZc4bOm+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595311480314841.4319321584518; Mon, 20 Jul 2020 23:04:40 -0700 (PDT) Received: from localhost ([::1]:48348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jxlOJ-0002Wi-3n for importer@patchew.org; Tue, 21 Jul 2020 02:04:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxlNM-0001Am-Ob for qemu-devel@nongnu.org; Tue, 21 Jul 2020 02:03:40 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:37761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jxlNK-00007N-J3 for qemu-devel@nongnu.org; Tue, 21 Jul 2020 02:03:40 -0400 Received: by mail-pl1-x642.google.com with SMTP id p1so9792260pls.4 for ; Mon, 20 Jul 2020 23:03:38 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id 66sm19724068pfa.92.2020.07.20.23.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 23:03:36 -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 :mime-version:content-transfer-encoding; bh=lyivCZnqzhrumKaf1cp2AkSGdgwxSM8kTqrAaI6ADt8=; b=RHuHE3Imopzm5mW2p7jbbHbavo9I6mlzfL0hBxmMQSPr9wkaMTkIsFct99x0WAA/tJ 9sRlAMYu6W8Qst/POIVYj1fAfrSRk8hJYhl8LpVUonXRuWtPdekb7DSN6p5/fAgXDRiP l3k/uKYOzjvtDNbrh/vvfRM2TpKOMXALP/hSPu8HEzZitInHfVQBQYCwH2K2/bE+fNi9 MD2nZSOuPCeNEIuWns70+nMxrYPkgWgkVlv8J+/+m1xmWzubiM40LiRXklIYM2Yu2wVS +LoKHJAP+vYHxyowRAdrHPAzBPMrjJ7AntJIJsCov9AhOK+kHxrpCJ62SbXaBn5vgSEH pTug== 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:mime-version:content-transfer-encoding; bh=lyivCZnqzhrumKaf1cp2AkSGdgwxSM8kTqrAaI6ADt8=; b=jLp6ZwMcNvCJquVYEpC2azbJ/ezxznqXSZp/SgxveZp2AhZwNb7GqHdOTPWD1y7FmL PsiCH5SNvvg2DZWITDfix2CAasc+DZIOxLZD5puTGJM/nV+aNMqsRtgdUq08Q1ODdOln Qsq/umCW14hsrubD4jX3niKeRmtbBeTfLD22VlJcwaRQoA9xC/SUPInn9MsijKhALgBu FsBPgpisYPpFRr1EUznxNpRQObQZAVQB4/mx20le+4hMTOwQwq/dVHE8zbekGPziTL1s bUPtBxNVu2VXMfJdF9HOTja/b6SEtGmOoA1aHIePIkkAcHyJS9WRcpxLD2AOVjnhT0+i DSoA== X-Gm-Message-State: AOAM532igachRurSeU0+Q2vqrh4QmE0GnUS9eCk8WAZzMCcCVOGv8lNk BYHJQOi6UJ/BWyvHBzl3qTcolQ== X-Google-Smtp-Source: ABdhPJzq5axPOHtmLGWH8vv4GRgKNzWaqJGdgTRGtUq0mzmsYSG5StiqamC0Y6DqTa9a8ZdunaRv5w== X-Received: by 2002:a17:902:988b:: with SMTP id s11mr20001668plp.229.1595311417279; Mon, 20 Jul 2020 23:03:37 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 2/2] target/riscv/pmp.c: Fix the index offset on RV64 Date: Tue, 21 Jul 2020 14:03:28 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=zong.li@sifive.com; helo=mail-pl1-x642.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Zong Li Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sifive.com) Content-Type: text/plain; charset="utf-8" On RV64, the reg_index is 2 (pmpcfg2 CSR) after the seventh pmp entry, it is not 1 (pmpcfg1 CSR) like RV32. In the original implementation, the second parameter of pmp_write_cfg is "reg_index * sizeof(target_ulong)", and we get the the result which is started from 16 if reg_index is 2, but we expect that it should be started from 8. Separate the implementation for RV32 and RV64 respectively. Changed in v2: - Move out the shifting operation from loop. Suggested by Bin Meng Signed-off-by: Zong Li --- target/riscv/pmp.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 2a2b9f5363..3de6535fbd 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -309,6 +309,7 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_= index, { int i; uint8_t cfg_val; + uint32_t pmp_entry_base; =20 trace_pmpcfg_csr_write(env->mhartid, reg_index, val); =20 @@ -318,10 +319,15 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t re= g_index, return; } =20 +#if defined(TARGET_RISCV32) + pmp_entry_base =3D (reg_index * sizeof(target_ulong)); +#elif defined(TARGET_RISCV64) + pmp_entry_base =3D (reg_index >> 1) * sizeof(target_ulong); +#endif + for (i =3D 0; i < sizeof(target_ulong); i++) { cfg_val =3D (val >> 8 * i) & 0xff; - pmp_write_cfg(env, (reg_index * sizeof(target_ulong)) + i, - cfg_val); + pmp_write_cfg(env, pmp_entry_base + i, cfg_val); } } =20 @@ -332,11 +338,18 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t re= g_index, target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index) { int i; + uint32_t pmp_entry_base; target_ulong cfg_val =3D 0; target_ulong val =3D 0; =20 +#if defined(TARGET_RISCV32) + pmp_entry_base =3D (reg_index * sizeof(target_ulong)); +#elif defined(TARGET_RISCV64) + pmp_entry_base =3D (reg_index >> 1) * sizeof(target_ulong); +#endif + for (i =3D 0; i < sizeof(target_ulong); i++) { - val =3D pmp_read_cfg(env, (reg_index * sizeof(target_ulong)) + i); + val =3D pmp_read_cfg(env, pmp_entry_base + i); cfg_val |=3D (val << (i * 8)); } trace_pmpcfg_csr_read(env->mhartid, reg_index, cfg_val); --=20 2.27.0