Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j8vlc-0004Am-3a for mharc-qemu-riscv@gnu.org; Mon, 02 Mar 2020 19:50:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45075) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j8vkW-0001em-6p for qemu-riscv@nongnu.org; Mon, 02 Mar 2020 19:49:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j8vkV-0004Jh-3P for qemu-riscv@nongnu.org; Mon, 02 Mar 2020 19:49:28 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:47083) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j8vkU-0004JN-UW for qemu-riscv@nongnu.org; Mon, 02 Mar 2020 19:49:27 -0500 Received: by mail-pf1-x435.google.com with SMTP id o24so538753pfp.13 for ; Mon, 02 Mar 2020 16:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=T6T0TH00iuu/lbxZkL6qr//GeBoSN6TEkkKvvhFc4Gk=; b=Xcir3SV3XYPFIKFfijsp7ob8Eu3Q8lLIJQuIKolDD+jnuzg2V5yQCuWLPJVYBShuIS 3Cy6yrPWe0NLsccLJKDLoV0bnr0rkF/O1vJh+Azv6xwgvKMxqd3vN4QLjBPfQZ+4Yhpc UA33oKwQJasll73LeW1WclzmFoQk5WOKit6wVKBrrVfEgWQBMfjX9oGxHgkeQpvaARGI MwGPDomW70wk3L1IxHM5f3zIt2tVvahdhiKEIGCvnSVL4UhNvSYICYIU5JAFScJ+qmxY YP42rPKtJo78gpv+4khtARg0RbCLM5WYfgmsGp179pIh3NlJ9WZ58vsD2pr9O57uZgGc a3AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=T6T0TH00iuu/lbxZkL6qr//GeBoSN6TEkkKvvhFc4Gk=; b=mVp34Jdaqq3aO1cA4hQUPcn+X10gzSeZy6I+6R2bhazBx+xFHyHFYyL2UKWVOnPZtC VRRVvkbJXj93JKeAM0NlLsUP05sI9mZo6+7XzPeYj+SvKmho+bVDyK+1F6HkmoMEwyt2 ABNqnY1kZzJRpxt1qS9J4j4hmzGciT6MU5cnsK3nMVHCLtomx74FuP9HRs0V1+bNxVq1 KvuE56E5ILqvFbG6BWxYg6nCQGmL7VswP7RP5gnL5LNdETNS0uVSQ6WCGgMQ19VU9+Ot KoBd3Y6ahL9YxVe3Kznk8IeJz9WYazgYPhVI4G0WUKLG18nhQIu5fJQkOgsHXMd6cdhG WAlA== X-Gm-Message-State: ANhLgQ29PwrsNM3kn3N8oj11aqVclU8WIEVIqEYY7sqKLD/sGpKrTTBy IRhv7cG+e6+i0tKvHx2ZAfOEdf5nwtqbrQ== X-Google-Smtp-Source: ADFU+vsMFedByMSjgsn4B1pfm9bu30AF6cPs7U72zXGm93wpWpBacJiVrgqqsfXwMmlgNcsMVMRnBw== X-Received: by 2002:aa7:85d8:: with SMTP id z24mr1675019pfn.202.1583196565535; Mon, 02 Mar 2020 16:49:25 -0800 (PST) Received: from localhost ([2620:0:1000:2514:23a5:d584:6a92:3e3c]) by smtp.gmail.com with ESMTPSA id az17sm108552pjb.18.2020.03.02.16.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 16:49:25 -0800 (PST) Subject: [PULL 16/38] target/riscv: Extend the MIE CSR to support virtulisation Date: Mon, 2 Mar 2020 16:48:26 -0800 Message-Id: <20200303004848.136788-17-palmerdabbelt@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200303004848.136788-1-palmerdabbelt@google.com> References: <20200303004848.136788-1-palmerdabbelt@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Alistair Francis , Palmer Dabbelt From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::435 X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Mar 2020 00:49:29 -0000 From: Alistair Francis Signed-off-by: Alistair Francis Reviewed-by: Palmer Dabbelt Signed-off-by: Palmer Dabbelt --- target/riscv/csr.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index c0e942684d..918678789a 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -244,8 +244,10 @@ static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) #define S_MODE_INTERRUPTS (MIP_SSIP | MIP_STIP | MIP_SEIP) #define VS_MODE_INTERRUPTS (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) -static const target_ulong delegable_ints = S_MODE_INTERRUPTS; -static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS; +static const target_ulong delegable_ints = S_MODE_INTERRUPTS | + VS_MODE_INTERRUPTS; +static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | + VS_MODE_INTERRUPTS; static const target_ulong delegable_excps = (1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | @@ -630,13 +632,27 @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) { - *val = env->mie & env->mideleg; + if (riscv_cpu_virt_enabled(env)) { + /* Tell the guest the VS bits, shifted to the S bit locations */ + *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1; + } else { + *val = env->mie & env->mideleg; + } return 0; } static int write_sie(CPURISCVState *env, int csrno, target_ulong val) { - target_ulong newval = (env->mie & ~env->mideleg) | (val & env->mideleg); + target_ulong newval; + + if (riscv_cpu_virt_enabled(env)) { + /* Shift the guests S bits to VS */ + newval = (env->mie & ~VS_MODE_INTERRUPTS) | + ((val << 1) & VS_MODE_INTERRUPTS); + } else { + newval = (env->mie & ~S_MODE_INTERRUPTS) | (val & S_MODE_INTERRUPTS); + } + return write_mie(env, CSR_MIE, newval); } -- 2.25.0.265.gbab2e86ba0-goog