From nobody Sun May 12 17:09:14 2024 Delivered-To: importer@patchew.org Received-SPF: neutral (zoho.com: 209.51.188.17 is neither permitted nor denied by domain of gnu.org) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=neutral (zoho.com: 209.51.188.17 is neither permitted nor denied by domain of gnu.org) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1561996666; cv=none; d=zoho.com; s=zohoarc; b=JuPCbB7nBSXuWNrHp7xmk0TEgA8mCHZw6eWyjRImMSDrtYQFwyVXzzeVqQLZ1hwLecEDM1N74rGxaaXsAjio8iztz0DRF6AOcHJIefZgfl9rrKOiCfoOjwjszVODFhykLlRGa1H34Knx5mobGQ3zl302Utlfj+uYrK4FthGR3Qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561996666; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=lBCHiDL7WNGa2WRZT3RH1NkA3mkdOOmWboMA1YaH7Ak=; b=gDJIFcq4jZJlFfJcUUsDs4pL/b066zxcuyOtO09Dgl1vYgsrY2hP2pEWfh/EOycuo/OPnywCZuXXiDs8B5qXov4kAIKbkRhEfrRT0iF6/MShEKLJjwD00LAenKcRse7r+6P0dN8MkDvrFqbHtOF3Jommw2u6vPHfp46YN7bYfxo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=neutral (zoho.com: 209.51.188.17 is neither permitted nor denied by domain of gnu.org) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561996665925130.32899036179708; Mon, 1 Jul 2019 08:57:45 -0700 (PDT) Received: from localhost ([::1]:60348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhygW-0007K1-0S for importer@patchew.org; Mon, 01 Jul 2019 11:57:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49078) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhyWb-0007ht-6y for qemu-devel@nongnu.org; Mon, 01 Jul 2019 11:47:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhyWa-00064W-9U for qemu-devel@nongnu.org; Mon, 01 Jul 2019 11:47:25 -0400 Received: from rs224.mailgun.us ([209.61.151.224]:11874) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhyWa-0005uM-5N for qemu-devel@nongnu.org; Mon, 01 Jul 2019 11:47:24 -0400 Received: from jonathan-ThinkPad-X1-Carbon.csail.mit.edu (30-9-3.wireless.csail.mit.edu [128.30.9.3]) by mxa.mailgun.org with ESMTP id 5d1a2afc.7fb1ab6aeb70-smtp-out-n01; Mon, 01 Jul 2019 15:47:08 -0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=fintelia.io; q=dns/txt; s=pic; t=1561996030; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=lBCHiDL7WNGa2WRZT3RH1NkA3mkdOOmWboMA1YaH7Ak=; b=TEqhY4qjyNu7mVBPg8wpo9s++jOaaxSPW8LeV+ATHbu50WOQcmAQGCI1a1ZxpZPCquFnueh6 ugWSrJuhGbxAkBC/cGpOj9eX2hMwknFBy5VCI463Np+VJus+oezkTUAF3Vqtri167Kx3IePG SSWMo0Dhknnc/2zgT8yvvIOU8JBUlKRNvq2MgjOqqvxJ0ecH9EGBcQTeMrQ5XCKYwurl09XU h4mF7NjXyWrkELwr7y2oaHEv9In66ABwxMvLbR9eNBRlTEhdZGIuI0bq5TTCgMAe7dD43x5H t5Yxc9uZCxkHIS5/3VxAqR3T83EXqwn/1mGYXbKHALiWvl14WtoOCw== X-Mailgun-Sending-Ip: 209.61.151.224 X-Mailgun-Sid: WyJlMGM5NSIsICJxZW11LWRldmVsQG5vbmdudS5vcmciLCAiOWI0ZTc2Il0= From: jonathan@fintelia.io To: qemu-riscv@nongnu.org Date: Mon, 1 Jul 2019 11:46:17 -0400 Message-Id: <20190701154617.22908-1-jonathan@fintelia.io> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.61.151.224 Subject: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren 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: Sagar Karandikar , Jonathan Behrens , Palmer Dabbelt , "open list:All patches CC here" , Alistair Francis , Bastian Koppelmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jonathan Behrens QEMU currently always triggers an illegal instruction exception when code attempts to read the time CSR. This is valid behavor, but only if the TM bit in mcounteren is hardwired to zero. This change also corrects mcounteren and scounteren CSRs to be 32-bits on both 32-bit and 64-bit targets. Signed-off-by: Jonathan Behrens Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 4 ++-- target/riscv/cpu_bits.h | 5 +++++ target/riscv/csr.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0adb307f32..2d0cbe9c78 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -151,8 +151,8 @@ struct CPURISCVState { target_ulong mcause; target_ulong mtval; /* since: priv-1.10.0 */ =20 - target_ulong scounteren; - target_ulong mcounteren; + uint32_t scounteren; + uint32_t mcounteren; =20 target_ulong sscratch; target_ulong mscratch; diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 11f971ad5d..0ea1e1caf5 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -532,4 +532,9 @@ #define SIP_STIP MIP_STIP #define SIP_SEIP MIP_SEIP =20 +/* mcounteren CSR bits */ +#define MCOUNTEREN_CY 0x1 +#define MCOUNTEREN_TM 0x2 +#define MCOUNTEREN_IR 0x4 + #endif diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e0d4586760..8425a6d2bd 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -473,7 +473,7 @@ static int write_mcounteren(CPURISCVState *env, int csr= no, target_ulong val) if (env->priv_ver < PRIV_VERSION_1_10_0) { return -1; } - env->mcounteren =3D val; + env->mcounteren =3D val & ~MCOUNTEREN_TM; return 0; } =20 --=20 2.22.0