From nobody Fri Dec 19 19:16:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1572046619; cv=none; d=zoho.com; s=zohoarc; b=TWmK1z0i3q9AwGefXN96C8I4T3ni0Yn3DKevkzOI2tNnFRIauJrWB9ihJPDzXqM7IvCw5GF7YynpftKNizGOfQh9fcQ1aS6ghceJzUkVv/QbGjsDHWEboeG2aXfCQxYQqcaM3hs/hlrhfzWyynfp9cFo+T+Zt4SeDv75klh9n1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572046619; 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=VSwn0gvjNhGNCB5fKSv2w2qKTZOnJ3MF9mbX1baik9I=; b=bGHxnJormDeBbQ04uwqA2FWJUAivyjPfh3BOoucAFyPpAwltVGgI6Z8hX3y04XADEcxaBAR7CgVU2opYnDuAUPWS09IuGJR2rn6wHWTECKfTpGNdbVIEwlvivBN3sl1qARzK8Eg1T58z+SN9AnN2/oLiTJtIOAVLQRLA9tqp88w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1572046619645595.0951568642239; Fri, 25 Oct 2019 16:36:59 -0700 (PDT) Received: from localhost ([::1]:37014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO98a-0005J2-Se for importer@patchew.org; Fri, 25 Oct 2019 19:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49581) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO90q-00051t-1i for qemu-devel@nongnu.org; Fri, 25 Oct 2019 19:28:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO90n-0004Ch-5f for qemu-devel@nongnu.org; Fri, 25 Oct 2019 19:28:54 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:10429) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iO90m-0004C1-UF; Fri, 25 Oct 2019 19:28:53 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2019 07:28:13 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 16:23:39 -0700 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.157.58]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Oct 2019 16:28:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1572046132; x=1603582132; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yMWZbTyS09Qj9dioNQRewgxpX8PPPn2TTEBKlAiR5HI=; b=fF/B/hj7SnPxNb61bJzASYuGEi2mhy0wJTJvE483YJo1fhUT16rUkA5A o7DNV8DTsLkMVZADZEDLtv+UMVMROq8HSim9rgOu+WT8mtwsmHIjKqD2J hnje6cxd1V/pCOHsuONsX6f4AZyM1EPeakYgzrtoLE5s5g2tQmENxDk9d Bug6K5kM13DIIhvHFt+xaHFKUlB8YwR0LPUhnSOjBZjMHkrn9Zp1bJ4YU /G2/xMSGFE9E7exRWp5uEVUz1qAsnDV6x7g1iXV6Fd3ek9lZEdn7rmLz6 A8tEHK5T36ZB77PZsFxB95BVL+kQc34UMpk1W5isDG5o5CpV8E6U9DG7F A==; IronPort-SDR: 8FWcOQDcoCPbNRTL4bbp9C9RHBZZEZc5npsBQ8ADftSRJuOjnCirJ8eC6R9fyqEAQi8vk2Ewog KnK/4x4T8AFpDmTk0rjQxIoSTMhbnM6AgciwU+RoKH+LSRda9G4dkqyAluSE6QNtQMJiDbLBuF +JQfyzknOMzlmONG7P1jUxR5ppB09rDeqoQv0cBAKsYXuAvz+uWpVrD4wLU4NFeXMsx6Yy8h7Q gvsGsTat0wRHn7mHCuiwPlEb+N016lCOE5uU5zsLi59JCF0pVZ69QENyq3vmNF3fHoOpdU9O3Q dJg= X-IronPort-AV: E=Sophos;i="5.68,230,1569254400"; d="scan'208";a="228520387" IronPort-SDR: XzBPCxNWHEQsu+jCuPNsHIh6+ZDNeCYBxaoesD+jOEw77Op8vC5nogp2yx68rIWMaen4t6ZJrE c/19H+ud7VKDckZE9jODn+4on/3ZskczznRxULC5TsHnWrHkKgVc0d97ZPo5NSoaA5DxneTEl5 JQz2HTUIXpQNItJjt4ZBeurkIq9A5P9Ub/X6Tp1YGxFnbaoX+IcZkgPArPiZes10Ib2JdmzETN K07BZhddUSQwW65b6b7v3Z9j05uxLi+PejgX46ftC9hBTa4ebRDf73Y7+vR84E2+6VCebruqRp 3Gbw7VrxH0CYTUdDQM8ofwXL IronPort-SDR: tlC+dNYdKDHL+jfN0iplGcHaTSZq50UZtIokMMO5W5NxvV77ITayQSdsREaUEM9YdpvwZPZX6l 1HikYpTPGJnodHk3gw0gX51IK/VOCTXnaPZ4Xu03/xmFu4MhmE+mb+wmxPA8zV/o715QUfUNBW /hKpkXLI5F5qGDYYLzuRTHmq8/f+6IUmAwp08Obyh2vw/1CuFs0T+3ih7UBIimgIMv5y5KR7L0 4tEj+SZX5frsm+vOobwfQEU4C1Dy5qBNAFmxGWziLuNFMQdQvMo2Fk7IfkfTO0vATCwCIRLaaP 6Vs= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 03/27] target/riscv: Add the virtulisation mode Date: Fri, 25 Oct 2019 16:23:18 -0700 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 68.232.141.245 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: alistair23@gmail.com, palmer@sifive.com, alistair.francis@wdc.com 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" Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 4 ++++ target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu_helper.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 91e1c56fc4..469dcbd1c0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -117,6 +117,8 @@ struct CPURISCVState { =20 #ifndef CONFIG_USER_ONLY target_ulong priv; + /* This contains QEMU specific information about the virt state. */ + target_ulong virt; target_ulong resetvec; =20 target_ulong mhartid; @@ -248,6 +250,8 @@ int riscv_cpu_gdb_read_register(CPUState *cpu, uint8_t = *buf, int reg); int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); bool riscv_cpu_fp_enabled(CPURISCVState *env); +bool riscv_cpu_virt_enabled(CPURISCVState *env); +void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch); hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index e99834856c..b4119cc002 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -422,6 +422,9 @@ #define PRV_H 2 /* Reserved */ #define PRV_M 3 =20 +/* Virtulisation Register Fields */ +#define VIRT_ONOFF 1 + /* RV32 satp CSR field masks */ #define SATP32_MODE 0x80000000 #define SATP32_ASID 0x7fc00000 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 31f553efb9..0306f3181d 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -82,6 +82,24 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env) return false; } =20 +bool riscv_cpu_virt_enabled(CPURISCVState *env) +{ + if (!riscv_has_ext(env, RVH)) { + return false; + } + + return get_field(env->virt, VIRT_ONOFF); +} + +void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) +{ + if (!riscv_has_ext(env, RVH)) { + return; + } + + env->virt =3D set_field(env->virt, VIRT_ONOFF, enable); +} + int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts) { CPURISCVState *env =3D &cpu->env; --=20 2.23.0