From patchwork Sun Oct 17 17:27:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1224DC433F5 for ; Sun, 17 Oct 2021 17:29:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDE2D60FD8 for ; Sun, 17 Oct 2021 17:29:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BDE2D60FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mc9ya-0004Ge-Ic for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:29:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wi-0001Zd-6J; Sun, 17 Oct 2021 13:27:40 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:35363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wg-0003BE-9i; Sun, 17 Oct 2021 13:27:39 -0400 Received: by mail-ed1-x534.google.com with SMTP id w19so60910810edd.2; Sun, 17 Oct 2021 10:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yAThpzEExEQywLhzKwYqOthFiPfhu8r+HsDpRlEN3LQ=; b=luoBRFez5Ndp0E1jgzYwwwYVSWxQSsZ9AgYC5gfMOgSjId3if4qqrXQdb0WJ5ljNWv nKchpFjKMibnW4T6fBtxr3cCmdfqckeP1C4TRtagkIFeXVPZSOFUs+AV9VGnzPe07U9G vDMQRbIt3mNWlxnRZETODSwerqd/3VVOmGbuDTVQjTNpgohYbxQwx+eeSvnDq1yiU9UX u6MqADeiwtQOwjd2H9PBAFy79DXp5wdwJpGQglP+OX4RFjJS3FsfYJvw6ZNg5nr8TYKE AxFuqrH+HlKJ4FwQbOcxYvfYKlhBKDcTKDURabWb3J+qgZRYBt7dUhjP4t22k2cq5Y43 VGJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yAThpzEExEQywLhzKwYqOthFiPfhu8r+HsDpRlEN3LQ=; b=RQLSSJSrnH5v1knfqxuRPJUG8M43A6V93uqus5NNeCdOUUCD6dlEvCjgusQllglDWv r7uoYE4MwddogxucTq3iSGWJ1u/3SkqEuFQ/qkjEHgrpjZMsrw81wNXzacvfsTw7ZyZ8 1KRWIuIuHohgLIGRKohUKfbOD+OAlIMw5YNkX1Cd+Ki4g4A0IoTkOhurPg/0jqpF+urk qq/K7CM2knQ1XZ5/RskkEYAJOeV9NqbGaZWNKdI58CLUayrkyyYZYPm1arcSSrtBJKbj xjARYs2Y/ixRJcz56Qf0a/cgoK4XPJaprUep44O0vz8/rO9TEajyGOf19+/uuVnhhgPt +0vQ== X-Gm-Message-State: AOAM533wZR0QYyrYmMUIq0HtqH5sxlVALn7EVjUiEJyhV5RT3Az3WEx8 fhe963w+unmFGVmgcoOYdZ4= X-Google-Smtp-Source: ABdhPJz+IWppVVOA59vs2SUweHpWkMQj0H08WL08uAPjd4ARX9q7woXpCRNudTyK4KJcCHKXrAXDYA== X-Received: by 2002:aa7:cb96:: with SMTP id r22mr33551093edt.87.1634491655638; Sun, 17 Oct 2021 10:27:35 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:35 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 1/8] [RISCV_PM] Add J-extension into RISC-V Date: Sun, 17 Oct 2021 20:27:21 +0300 Message-Id: <20211017172728.759687-2-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x534.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com, Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/cpu.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 9e55b2f5b1..3f28dc5f3a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -67,6 +67,7 @@ #define RVS RV('S') #define RVU RV('U') #define RVH RV('H') +#define RVJ RV('J') /* S extension denotes that Supervisor mode exists, however it is possible to have a core that support S mode but does not have an MMU and there @@ -289,6 +290,7 @@ struct RISCVCPU { bool ext_s; bool ext_u; bool ext_h; + bool ext_j; bool ext_v; bool ext_zba; bool ext_zbb; From patchwork Sun Oct 17 17:27:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCFA7C433F5 for ; Sun, 17 Oct 2021 17:29:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E6CC60EE9 for ; Sun, 17 Oct 2021 17:29:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4E6CC60EE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mc9yi-0004SB-8y for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:29:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wj-0001Zw-E5; Sun, 17 Oct 2021 13:27:41 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:41659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wh-0003Bs-62; Sun, 17 Oct 2021 13:27:41 -0400 Received: by mail-ed1-x52a.google.com with SMTP id a25so61169324edx.8; Sun, 17 Oct 2021 10:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nh0iqXUy8y/Ubp2h94AICbKWAgloggmfwv7+BDo9syA=; b=gyUGVFHUUrOdosuNbc6umAEE4oUUC0c8dcjp2s1boCEMTJ9/aOkYeL1e8vlhrU7nXW OaSmtNCflJIMNz6Xa/7H7bHJgPWtZos0jr426tHAISomsP7LYZQFFJveoqQHw0NjPtw7 yMenv7OJghWGtcn/hLMBPKmcqpAQPws/MURbsh2Q/ruVDEa3jE7vBgBU/fn88eLyGnVi cMNQ/rgV+7N5W2d/+gIHWrYVzOPX8z5+kVgyXZ4G0kYsjVRc1i1RCyBY3Mjh4z9iaiNs 6+wJMoX6bdeE6Vejz52o+GrxjUrUf9A/ygnkJfaO8lXt6yz+GgSQsJv/ySRO11aWGz5t IhbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nh0iqXUy8y/Ubp2h94AICbKWAgloggmfwv7+BDo9syA=; b=vEL4+VPiCpgNhv6Mcb68mdnZ7cvpmRnI9NMJDtr5IQbUNoB+PCWVamkZ3HZCplxcp+ TZQIo/P7J1JbUEKyg5UhgNEQz5WioSZGFuYBohhvQNOaUeDKkODiQQlg6C0iyMyUAjOr VLVI5799iEZw1VlhTCkjiI5C3U44dgpPvfoJY3RDtyOhjge8FrJWBqAud2Dwl5Y9W29u zGLlptcm9sNPtEWmneoOwrnjRIISnFnGCszqKleJGGOLZmLvfKIcCjUC3/nvqCP6kznc XuwqZU5HD/j9FhVRgQuDX+asNGurjR4GoMztyyJJQk9LCKGbCVvTk04Qnwd4EvzvSPu8 Q7Pw== X-Gm-Message-State: AOAM532H/vIq0Y97VQiMT0U1RrhiKkv8P7XSfYOGdacWYvs1zL8fw8+u srtZa281Y86Rf1xLQ5dv6zo= X-Google-Smtp-Source: ABdhPJyZwMk63YY5Hexc1SkFA1Fx8B9W1TSCshAcZeem+2foNSFBUJal7uzSaLOvtDdcc3MogjeiRA== X-Received: by 2002:a17:906:f8d0:: with SMTP id lh16mr22416967ejb.367.1634491656794; Sun, 17 Oct 2021 10:27:36 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:36 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 2/8] [RISCV_PM] Add CSR defines for RISC-V PM extension Date: Sun, 17 Oct 2021 20:27:22 +0300 Message-Id: <20211017172728.759687-3-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x52a.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008 autolearn=no 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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 999187a9ee..1a3767804a 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -334,6 +334,38 @@ #define CSR_MHPMCOUNTER30H 0xb9e #define CSR_MHPMCOUNTER31H 0xb9f +/* + * User PointerMasking registers + * NB: actual CSR numbers might be changed in future + */ +#define CSR_UMTE 0x4c0 +#define CSR_UPMMASK 0x4c1 +#define CSR_UPMBASE 0x4c2 + +/* + * Machine PointerMasking registers + * NB: actual CSR numbers might be changed in future + */ +#define CSR_MMTE 0x3c0 +#define CSR_MPMMASK 0x3c1 +#define CSR_MPMBASE 0x3c2 + +/* + * Supervisor PointerMaster registers + * NB: actual CSR numbers might be changed in future + */ +#define CSR_SMTE 0x1c0 +#define CSR_SPMMASK 0x1c1 +#define CSR_SPMBASE 0x1c2 + +/* + * Hypervisor PointerMaster registers + * NB: actual CSR numbers might be changed in future + */ +#define CSR_VSMTE 0x2c0 +#define CSR_VSPMMASK 0x2c1 +#define CSR_VSPMBASE 0x2c2 + /* mstatus CSR bits */ #define MSTATUS_UIE 0x00000001 #define MSTATUS_SIE 0x00000002 @@ -531,4 +563,68 @@ typedef enum RISCVException { #define MIE_UTIE (1 << IRQ_U_TIMER) #define MIE_SSIE (1 << IRQ_S_SOFT) #define MIE_USIE (1 << IRQ_U_SOFT) + +/* General PointerMasking CSR bits*/ +#define PM_ENABLE 0x00000001ULL +#define PM_CURRENT 0x00000002ULL +#define PM_INSN 0x00000004ULL +#define PM_XS_MASK 0x00000003ULL + +/* PointerMasking XS bits values */ +#define PM_EXT_DISABLE 0x00000000ULL +#define PM_EXT_INITIAL 0x00000001ULL +#define PM_EXT_CLEAN 0x00000002ULL +#define PM_EXT_DIRTY 0x00000003ULL + +/* Offsets for every pair of control bits per each priv level */ +#define XS_OFFSET 0ULL +#define U_OFFSET 2ULL +#define S_OFFSET 5ULL +#define M_OFFSET 8ULL + +#define PM_XS_BITS (PM_XS_MASK << XS_OFFSET) +#define U_PM_ENABLE (PM_ENABLE << U_OFFSET) +#define U_PM_CURRENT (PM_CURRENT << U_OFFSET) +#define U_PM_INSN (PM_INSN << U_OFFSET) +#define S_PM_ENABLE (PM_ENABLE << S_OFFSET) +#define S_PM_CURRENT (PM_CURRENT << S_OFFSET) +#define S_PM_INSN (PM_INSN << S_OFFSET) +#define M_PM_ENABLE (PM_ENABLE << M_OFFSET) +#define M_PM_CURRENT (PM_CURRENT << M_OFFSET) +#define M_PM_INSN (PM_INSN << M_OFFSET) + +/* mmte CSR bits */ +#define MMTE_PM_XS_BITS PM_XS_BITS +#define MMTE_U_PM_ENABLE U_PM_ENABLE +#define MMTE_U_PM_CURRENT U_PM_CURRENT +#define MMTE_U_PM_INSN U_PM_INSN +#define MMTE_S_PM_ENABLE S_PM_ENABLE +#define MMTE_S_PM_CURRENT S_PM_CURRENT +#define MMTE_S_PM_INSN S_PM_INSN +#define MMTE_M_PM_ENABLE M_PM_ENABLE +#define MMTE_M_PM_CURRENT M_PM_CURRENT +#define MMTE_M_PM_INSN M_PM_INSN +#define MMTE_MASK (MMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | MMTE_U_PM_INSN | \ + MMTE_S_PM_ENABLE | MMTE_S_PM_CURRENT | MMTE_S_PM_INSN | \ + MMTE_M_PM_ENABLE | MMTE_M_PM_CURRENT | MMTE_M_PM_INSN | \ + MMTE_PM_XS_BITS) + +/* (v)smte CSR bits */ +#define SMTE_PM_XS_BITS PM_XS_BITS +#define SMTE_U_PM_ENABLE U_PM_ENABLE +#define SMTE_U_PM_CURRENT U_PM_CURRENT +#define SMTE_U_PM_INSN U_PM_INSN +#define SMTE_S_PM_ENABLE S_PM_ENABLE +#define SMTE_S_PM_CURRENT S_PM_CURRENT +#define SMTE_S_PM_INSN S_PM_INSN +#define SMTE_MASK (SMTE_U_PM_ENABLE | SMTE_U_PM_CURRENT | SMTE_U_PM_INSN | \ + SMTE_S_PM_ENABLE | SMTE_S_PM_CURRENT | SMTE_S_PM_INSN | \ + SMTE_PM_XS_BITS) + +/* umte CSR bits */ +#define UMTE_U_PM_ENABLE U_PM_ENABLE +#define UMTE_U_PM_CURRENT U_PM_CURRENT +#define UMTE_U_PM_INSN U_PM_INSN +#define UMTE_MASK (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN) + #endif From patchwork Sun Oct 17 17:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B4D0C433F5 for ; Sun, 17 Oct 2021 17:34:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9944560FDC for ; Sun, 17 Oct 2021 17:34:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9944560FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcA3X-00022C-Kq for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:34:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wk-0001at-79; Sun, 17 Oct 2021 13:27:42 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:44855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wh-0003D5-Ij; Sun, 17 Oct 2021 13:27:41 -0400 Received: by mail-ed1-x534.google.com with SMTP id w14so60874938edv.11; Sun, 17 Oct 2021 10:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VBvGkKbx0xudkHXPoXXuXWWauDn1ipAtUgih7B29lJU=; b=ohLn/UufrZXkITANtwVvuEPOYxPz7Y3JorVzNeJAVMEUPTC5uejr5WJoDwmrRZ0nxb T6gL9qEWHOYfidVIsVmsfCMoa+lNXmSSACWPlO0siK9LbAWf8gf+JgwllRyKN7UoXLWb qo9IXiRqcwq+bxMHYHvmOlJnYYsXSxeAbLH/++yauGINWvV0dzs8djipkqJzRSBAaioN yRfkONP1g0i+I/dcK/eJdp7lMdmFvfqU6rmyS88g/Frbpsin/qeC2ZrgzhWe5aLxfb99 M3VJA1ls2NYdukxjnt79N0zFhRG9QZLJw+4kFyr/ksxIt2sSyzD2ngJbpDbpPi+fQ4Ex Tvvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VBvGkKbx0xudkHXPoXXuXWWauDn1ipAtUgih7B29lJU=; b=py1j1u0Kyhy2pFEb3YKxNNqpDPm36+FJ6IXKzB/lM4QCJ6IT1tfMX1jzjc+SpE8Tjh Y7NM7Y7fj6MwsiPlQ83fuJ9GW58SuhCFcnQEkCIORmG6/OY62IzUYnw98dSWrHZkvoIV wOUAUyB3cqkuBUL+sBxYjk/rVIVwOD6IbmXSoAeXnEug7o8dbR1pNjNI+MGawQmPtZAW LKZWONWWT9aZA23xk5gEG7TSMnH9ugtefuKUM6KEZzPeaioFkKbctILaKoas09l8o3A5 xeY6HOSUuOnd3iZlstONSl5dSSnxueAsIABdthSXFxNFywRDqKvbFEIfkVkIpPQgPmq6 D1zg== X-Gm-Message-State: AOAM531XjafoPGoMBCwj0e6PztyBaRJBYg4IM6XOOQj6lQobB4cNRTj8 s8HdXckyxzWHN5oZBFJ+4+4= X-Google-Smtp-Source: ABdhPJzCzCJXaL/h9J+liU4nJu4iHCWwFNzu63xPA0c6S157AKuZ0Wi34753aaH/kxkRgRwH04lcqQ== X-Received: by 2002:a50:da0a:: with SMTP id z10mr36527418edj.95.1634491657890; Sun, 17 Oct 2021 10:27:37 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:37 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 3/8] [RISCV_PM] Support CSRs required for RISC-V PM extension except for the h-mode Date: Sun, 17 Oct 2021 20:27:23 +0300 Message-Id: <20211017172728.759687-4-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x534.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair.Francis@wdc.com, kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 2 + target/riscv/cpu.h | 11 ++ target/riscv/csr.c | 285 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1d69d1887e..75e8b8ca83 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -365,6 +365,8 @@ static void riscv_cpu_reset(DeviceState *dev) env->mcause = 0; env->pc = env->resetvec; env->two_stage_lookup = false; + /* mmte is supposed to have pm.current hardwired to 1 */ + env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT); #endif cs->exception_index = RISCV_EXCP_NONE; env->load_res = -1; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 3f28dc5f3a..acb4ce9d23 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -236,6 +236,17 @@ struct CPURISCVState { /* True if in debugger mode. */ bool debugger; + + /* + * CSRs for PointerMasking extension + */ + target_ulong mmte; + target_ulong mpmmask; + target_ulong mpmbase; + target_ulong spmmask; + target_ulong spmbase; + target_ulong upmmask; + target_ulong upmbase; #endif float_status fp_status; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 23fbbd3216..d563289d37 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -192,6 +192,16 @@ static RISCVException hmode32(CPURISCVState *env, int csrno) } +/* Checks if PointerMasking registers could be accessed */ +static RISCVException pointer_masking(CPURISCVState *env, int csrno) +{ + /* Check if j-ext is present */ + if (riscv_has_ext(env, RVJ)) { + return RISCV_EXCP_NONE; + } + return RISCV_EXCP_ILLEGAL_INST; +} + static RISCVException pmp(CPURISCVState *env, int csrno) { if (riscv_feature(env, RISCV_FEATURE_PMP)) { @@ -1401,6 +1411,268 @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +/* + * Functions to access Pointer Masking feature registers + * We have to check if current priv lvl could modify + * csr in given mode + */ +static bool check_pm_current_disabled(CPURISCVState *env, int csrno) +{ + int csr_priv = get_field(csrno, 0x300); + int pm_current; + + /* + * If priv lvls differ that means we're accessing csr from higher priv lvl, + * so allow the access + */ + if (env->priv != csr_priv) { + return false; + } + switch (env->priv) { + case PRV_M: + pm_current = get_field(env->mmte, M_PM_CURRENT); + break; + case PRV_S: + pm_current = get_field(env->mmte, S_PM_CURRENT); + break; + case PRV_U: + pm_current = get_field(env->mmte, U_PM_CURRENT); + break; + default: + g_assert_not_reached(); + } + /* It's same priv lvl, so we allow to modify csr only if pm.current==1 */ + return !pm_current; +} + +static RISCVException read_mmte(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->mmte & MMTE_MASK; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mmte(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + target_ulong wpri_val = val & MMTE_MASK; + + if (val != wpri_val) { + qemu_log_mask(LOG_GUEST_ERROR, + "MMTE: WPRI violation written 0x%lx vs expected 0x%lx\n", + val, wpri_val); + } + /* for machine mode pm.current is hardwired to 1 */ + wpri_val |= MMTE_M_PM_CURRENT; + + /* hardwiring pm.instruction bit to 0, since it's not supported yet */ + wpri_val &= ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN); + env->mmte = wpri_val | PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_smte(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->mmte & SMTE_MASK; + return RISCV_EXCP_NONE; +} + +static RISCVException write_smte(CPURISCVState *env, int csrno, + target_ulong val) +{ + target_ulong wpri_val = val & SMTE_MASK; + + if (val != wpri_val) { + qemu_log_mask(LOG_GUEST_ERROR, + "SMTE: WPRI violation written 0x%lx vs expected 0x%lx\n", + val, wpri_val); + } + + /* if pm.current==0 we can't modify current PM CSRs */ + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + + wpri_val |= (env->mmte & ~SMTE_MASK); + write_mmte(env, csrno, wpri_val); + return RISCV_EXCP_NONE; +} + +static RISCVException read_umte(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->mmte & UMTE_MASK; + return RISCV_EXCP_NONE; +} + +static RISCVException write_umte(CPURISCVState *env, int csrno, + target_ulong val) +{ + target_ulong wpri_val = val & UMTE_MASK; + + if (val != wpri_val) { + qemu_log_mask(LOG_GUEST_ERROR, + "UMTE: WPRI violation written 0x%lx vs expected 0x%lx\n", + val, wpri_val); + } + + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + + wpri_val |= (env->mmte & ~UMTE_MASK); + write_mmte(env, csrno, wpri_val); + return RISCV_EXCP_NONE; +} + +static RISCVException read_mpmmask(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->mpmmask; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mpmmask(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + env->mpmmask = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_spmmask(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->spmmask; + return RISCV_EXCP_NONE; +} + +static RISCVException write_spmmask(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + /* if pm.current==0 we can't modify current PM CSRs */ + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + env->spmmask = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_upmmask(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->upmmask; + return RISCV_EXCP_NONE; +} + +static RISCVException write_upmmask(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + /* if pm.current==0 we can't modify current PM CSRs */ + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + env->upmmask = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_mpmbase(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->mpmbase; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mpmbase(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + env->mpmbase = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_spmbase(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->spmbase; + return RISCV_EXCP_NONE; +} + +static RISCVException write_spmbase(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + /* if pm.current==0 we can't modify current PM CSRs */ + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + env->spmbase = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + +static RISCVException read_upmbase(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->upmbase; + return RISCV_EXCP_NONE; +} + +static RISCVException write_upmbase(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mstatus; + + /* if pm.current==0 we can't modify current PM CSRs */ + if (check_pm_current_disabled(env, csrno)) { + return RISCV_EXCP_NONE; + } + env->upmbase = val; + env->mmte |= PM_EXT_DIRTY; + + /* Set XS and SD bits, since PM CSRs are dirty */ + mstatus = env->mstatus | MSTATUS_XS; + write_mstatus(env, csrno, mstatus); + return RISCV_EXCP_NONE; +} + #endif /* @@ -1635,6 +1907,19 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_PMPADDR14] = { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR15] = { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr }, + /* User Pointer Masking */ + [CSR_UMTE] = { "umte", pointer_masking, read_umte, write_umte }, + [CSR_UPMMASK] = { "upmmask", pointer_masking, read_upmmask, write_upmmask }, + [CSR_UPMBASE] = { "upmbase", pointer_masking, read_upmbase, write_upmbase }, + /* Machine Pointer Masking */ + [CSR_MMTE] = { "mmte", pointer_masking, read_mmte, write_mmte }, + [CSR_MPMMASK] = { "mpmmask", pointer_masking, read_mpmmask, write_mpmmask }, + [CSR_MPMBASE] = { "mpmbase", pointer_masking, read_mpmbase, write_mpmbase }, + /* Supervisor Pointer Masking */ + [CSR_SMTE] = { "smte", pointer_masking, read_smte, write_smte }, + [CSR_SPMMASK] = { "spmmask", pointer_masking, read_spmmask, write_spmmask }, + [CSR_SPMBASE] = { "spmbase", pointer_masking, read_spmbase, write_spmbase }, + /* Performance Counters */ [CSR_HPMCOUNTER3] = { "hpmcounter3", ctr, read_zero }, [CSR_HPMCOUNTER4] = { "hpmcounter4", ctr, read_zero }, From patchwork Sun Oct 17 17:27:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 829F7C433F5 for ; Sun, 17 Oct 2021 17:38:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2853860F57 for ; Sun, 17 Oct 2021 17:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2853860F57 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcA72-0007rG-7s for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:38:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wl-0001eu-N2; Sun, 17 Oct 2021 13:27:43 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:43573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wi-0003Dz-SQ; Sun, 17 Oct 2021 13:27:43 -0400 Received: by mail-ed1-x529.google.com with SMTP id i20so60222802edj.10; Sun, 17 Oct 2021 10:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zHHTVDAjEJObMtEw9nLPwy8ATzu5O/k8PrPHniLY9Sw=; b=QaLQVM0VZ3b6O0mIgC1INlVyTLLyQF8wqarsKOIp3m0APDAXAmngWf1v29csD9jmUB kQqO/kjAdWpCDNu/xY1v1qB1B62Iay3rE7Edef9z5WRJ31jej9/OJyWh/+1AdDGk3icK y9rF7SJwL8xx9iDVca00d+tJaO0FLTJoWHvb89lNd+Q8yOR+/G6zqIufjnVkXF1jk6Tb KaE0g66iUXtkyY5FAQyrqDjSLY9DKGtybm7qD+aV86S8hSJ+E3rhrUefeY332eA9+TF2 mrkPLwp0hAR6F/srRl00mv8k43sgJHOJZkfMKAq5gj6oQBQQzxq74cxS9NLXY1W+tvXb aMvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zHHTVDAjEJObMtEw9nLPwy8ATzu5O/k8PrPHniLY9Sw=; b=GibM2UMEcTNXnnibl2tmvMq5QA52+iQc05FyiWZGSJEwuti4+YYbHFetzi3IapSTEW 7OKMXvyAegYiIxybenriV1RAsrbViFgNra5DtOLcRZQ3WG0mt3EiwjlfvdG+b0Syucy2 VlP1zHDWlEQOFVCNZQQSFEZ5vOvbYyQUcLswcF6z0gLDzzsDY6MkDz1YH1VaGz0Z198d I58B83t6ahzzzddBIolwVY9iGxXBEVJb/vSCBUUCCPOJLOaenHrQ9jNhLIde2iNHQKEh g27tWCgJinuutM5VZTqMpUuGDJFQlOzNjxZLva6QqWcmXO5Zs7+JYNFpmjiQ3rqFMsz5 OrCQ== X-Gm-Message-State: AOAM530TcLResoMzCHrJrArui93I9JeuVRgW5wU1blLzH1OgXaGgV2eU 6CG3nBQqgNR+dPY5zzpYLmg= X-Google-Smtp-Source: ABdhPJyWHCDIUgjSORF0yGSe1stncYWjOQCDBbY391yOuMqIFuMzbrGZi5WU6T2czPBATLbzFZLccw== X-Received: by 2002:a05:6402:2550:: with SMTP id l16mr37332171edb.229.1634491659074; Sun, 17 Oct 2021 10:27:39 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:38 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 4/8] [RISCV_PM] Add J extension state description Date: Sun, 17 Oct 2021 20:27:24 +0300 Message-Id: <20211017172728.759687-5-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x529.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair.Francis@wdc.com, kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo --- target/riscv/machine.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 16a08302da..4d99880797 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -84,6 +84,14 @@ static bool vector_needed(void *opaque) return riscv_has_ext(env, RVV); } +static bool pointermasking_needed(void *opaque) +{ + RISCVCPU *cpu = opaque; + CPURISCVState *env = &cpu->env; + + return riscv_has_ext(env, RVJ); +} + static const VMStateDescription vmstate_vector = { .name = "cpu/vector", .version_id = 1, @@ -138,6 +146,24 @@ static const VMStateDescription vmstate_hyper = { } }; +static const VMStateDescription vmstate_pointermasking = { + .name = "cpu/pm", + .version_id = 1, + .minimum_version_id = 1, + .needed = pointermasking_needed, + .fields = (VMStateField[]) { + VMSTATE_UINTTL(env.mmte, RISCVCPU), + VMSTATE_UINTTL(env.mpmmask, RISCVCPU), + VMSTATE_UINTTL(env.mpmbase, RISCVCPU), + VMSTATE_UINTTL(env.spmmask, RISCVCPU), + VMSTATE_UINTTL(env.spmbase, RISCVCPU), + VMSTATE_UINTTL(env.upmmask, RISCVCPU), + VMSTATE_UINTTL(env.upmbase, RISCVCPU), + + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu = { .name = "cpu", .version_id = 2, @@ -189,6 +215,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_pmp, &vmstate_hyper, &vmstate_vector, + &vmstate_pointermasking, NULL } }; From patchwork Sun Oct 17 17:27:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0256AC433F5 for ; Sun, 17 Oct 2021 17:29:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AF02A60FD8 for ; Sun, 17 Oct 2021 17:29:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AF02A60FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mc9yq-0004hX-Pj for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:29:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wl-0001eW-KM; Sun, 17 Oct 2021 13:27:43 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:46676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wj-0003Et-RK; Sun, 17 Oct 2021 13:27:43 -0400 Received: by mail-ed1-x52f.google.com with SMTP id z20so61233360edc.13; Sun, 17 Oct 2021 10:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K05JcbwHzwcb6rZL7rDmh7yc1UsvDdWX5/9rOusuP/8=; b=ZdakGVSEFZAMCKfWbWOyw3ALus3Lg6vBTumrBpaGpZEC3ruTXHaMj5+NYLvyKaTPJm kQzuONfffgBd+NWVJm71Y8jCZQIw9tl19Osge/9uHrN/3UHjoLwX7dm0iSNZTazerfOK q2SO9hul2ivN3sEDlZdlUCjPTEjDpIFov789KV8aRlCX7o45BO8NDrkz1skeQZEpR9FG 7mbFeAnyji3/fBFdSSNvVfRItVrFKSWdFC+Kv9qLiHNSqyPSafnwLIdHGSGUAjvJ92YW ohJLlv6s0+Ya47zwn4iCosR2v+CMkWO8WonRURFleHrWbJY9xjlmyJCqAofslca152c0 vMcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K05JcbwHzwcb6rZL7rDmh7yc1UsvDdWX5/9rOusuP/8=; b=mLJaVojdFbsg3lMrZ+h+W2MCdbJCMhO8RpS1JjTG0JNqUha3v7q2obiOwcPpgXAR5f P1yvJyuoS0LouMvVeHXPVbpzR0fE3SIJBtWWj3vSWTvNwiT6fl0QvEG9m2+ouLhyJum9 ottEdn/GOO3halWNc1SiWceiBPN9lEyvrXwjkOqQKKp6TVfBj3tzvxHCItS8oc+gL+OL n3Ff0lLIRrqOdrOU/irZQyutQ5kerr0j6yv0B5dp36T5eq7gYaRu6ilTUuQgSbYeKfm0 vk2hW5XrBsDaVaHFwEAEKpBvsOjuZZw9MDR+EM3DX7iCvtwOPo29GIaZ5lf+oe5NPdar tZ3Q== X-Gm-Message-State: AOAM531xNP1ELyqo7uR1s8vZmZ4FQO5npB3cqbASOxvozLS2hzqSUgUm sTxop/P1FxxrmHNFtpC0RfVXORhlNOUMcWAI4es= X-Google-Smtp-Source: ABdhPJz0AQO+RzURrDueDGXfcRM4Imp+xaSwu9aCZJcMHcUjNAPfvINSR9WKh3VHdDEjSfJuz2WTTA== X-Received: by 2002:a05:6402:370:: with SMTP id s16mr33219010edw.1.1634491660131; Sun, 17 Oct 2021 10:27:40 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:39 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 5/8] [RISCV_PM] Print new PM CSRs in QEMU logs Date: Sun, 17 Oct 2021 20:27:25 +0300 Message-Id: <20211017172728.759687-6-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x52f.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 75e8b8ca83..7f9dde70b7 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -295,6 +295,31 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mscratch", env->mscratch); qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sscratch", env->sscratch); qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "satp ", env->satp); + if (riscv_has_ext(env, RVJ)) { + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mmte ", env->mmte); + switch (env->priv) { + case PRV_U: + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "upmbase ", + env->upmbase); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "upmmask ", + env->upmmask); + break; + case PRV_S: + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "spmbase ", + env->spmbase); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "spmmask ", + env->spmmask); + break; + case PRV_M: + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mpmbase ", + env->mpmbase); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mpmmask ", + env->mpmmask); + break; + default: + g_assert_not_reached(); + } + } #endif for (i = 0; i < 32; i++) { From patchwork Sun Oct 17 17:27:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B325EC433EF for ; Sun, 17 Oct 2021 17:34:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D4C660FDC for ; Sun, 17 Oct 2021 17:34:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2D4C660FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcA3b-0002D4-4m for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wn-0001iq-0p; Sun, 17 Oct 2021 13:27:45 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:34421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wl-0003G6-5e; Sun, 17 Oct 2021 13:27:44 -0400 Received: by mail-ed1-x536.google.com with SMTP id g10so61269111edj.1; Sun, 17 Oct 2021 10:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IhMy1wtSNlrR+WThebIS2yNEL+ESPAJihTsSOi8MDEw=; b=OO0Q7ClfqVAIpjQ2W3dUWyik5iu1EefyVby8suiNN3Kn1JjwRlbGB+zZM28DOlYaID orpQ1mQB3YyhSAaLiQKiOjn+Ne3tS1bTWubycX+bZTpxk7gu6Yd36K+rhOakjFaJmnCv nKg4hmTbgdI+YXYHA26Ls0Wl0IXzsRo+5GrEGCRYPeG4iP4VZbdtUg0zS3Qwtd8gUU72 saWzvgGJlTQ5SI2zjpbPhGS2dj0HdZcUt9eMdLHLQWKNYBTeQMq/dhY3/mwtTT3Zdchx FHAxaAKtEJzjQ/NQDrMsnQcZ36F0jT0Erho1okaFAZ0fekmQ5hYn4Hdt0TxvNvwrGgA+ eixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IhMy1wtSNlrR+WThebIS2yNEL+ESPAJihTsSOi8MDEw=; b=Raf1luinaYsZjm7QIwa9mZqEtSPQjxhkUFqyYrMmHMh4aXId1MAYmthbaZZ5HAvgn9 2J0BfsyPC9g1LJSsSgta0oPf3K5s5ZMr5U3qZRaHGlpy4JlaOqJP6AqxvZRIWjeRrR8A cRJS+oObJruCZ8ioKqMSXG4ESwVYTQ1CuNEl/zAO6iUIlnBYkuRQ88K+4ndj4bpzG6zc OvAMJ4akfLd23AhCXBwL5n/ys1Tg3fHTsWkz0ZLjlu5mUCb3pi99FVkHn1GlHuenqosG KQ4kx0vnKJ99qH4Rcpek1UhtVkKlTxFfkHm6bQs3NfWngCgyeDUl1nXwrXHRQJU2fUGo ZWaw== X-Gm-Message-State: AOAM532q4i0kjFrMCYurq9YcoRjOr/sUoOepBD5h2V7rvguCllU7SZfX xsvwIe5nrtWoWqngtPLGpbE= X-Google-Smtp-Source: ABdhPJwR72YN9WpTFXBgwq5O4ygrfLcr5XjlRLSNSUGWbc2bzDWxr+rEeeC+jBRzVQM7G/U9yiescQ== X-Received: by 2002:a17:907:9687:: with SMTP id hd7mr21896227ejc.535.1634491661371; Sun, 17 Oct 2021 10:27:41 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:41 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 6/8] [RISCV_PM] Support pointer masking for RISC-V for i/c/f/d/a types of instructions Date: Sun, 17 Oct 2021 20:27:26 +0300 Message-Id: <20211017172728.759687-7-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 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, FREEMAIL_FROM=0.001, GAPPY_SUBJECT=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_rva.c.inc | 3 +++ target/riscv/insn_trans/trans_rvd.c.inc | 2 ++ target/riscv/insn_trans/trans_rvf.c.inc | 2 ++ target/riscv/insn_trans/trans_rvi.c.inc | 2 ++ target/riscv/translate.c | 8 ++++++++ 5 files changed, 17 insertions(+) diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc index 6ea07d89b0..40fe132b04 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -25,6 +25,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop) if (a->rl) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); } + src1 = gen_pm_adjust_address(ctx, src1); tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop); if (a->aq) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); @@ -44,6 +45,7 @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop) TCGLabel *l2 = gen_new_label(); src1 = get_gpr(ctx, a->rs1, EXT_ZERO); + src1 = gen_pm_adjust_address(ctx, src1); tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); /* @@ -84,6 +86,7 @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a, TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); + src1 = gen_pm_adjust_address(ctx, src1); func(dest, src1, src2, ctx->mem_idx, mop); gen_set_gpr(ctx, a->rd, dest); diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc index db9ae15755..64fb0046f7 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -31,6 +31,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, MO_TEQ); @@ -51,6 +52,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEQ); diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc index bddbd418d9..b5459249c4 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -37,6 +37,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); dest = cpu_fpr[a->rd]; tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_TEUL); @@ -59,6 +60,7 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUL); diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc index a6a57c94bb..8690c977d5 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -144,6 +144,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); gen_set_gpr(ctx, a->rd, dest); @@ -185,6 +186,7 @@ static bool gen_store(DisasContext *ctx, arg_sb *a, MemOp memop) tcg_gen_addi_tl(temp, addr, a->imm); addr = temp; } + addr = gen_pm_adjust_address(ctx, addr); tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); return true; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 6d7fbca1fa..9e176b8137 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -247,6 +247,14 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) ctx->base.is_jmp = DISAS_NORETURN; } +/* + * Temp stub: generates address adjustment for PointerMasking + */ +static TCGv gen_pm_adjust_address(DisasContext *s, TCGv src) +{ + return src; +} + #ifndef CONFIG_USER_ONLY /* The states of mstatus_fs are: * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty From patchwork Sun Oct 17 17:27:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A27C433F5 for ; Sun, 17 Oct 2021 17:35:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56D4160FD9 for ; Sun, 17 Oct 2021 17:35:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 56D4160FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcA3n-00031D-FO for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wp-0001pR-7P; Sun, 17 Oct 2021 13:27:47 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:40930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wm-0003Gy-45; Sun, 17 Oct 2021 13:27:46 -0400 Received: by mail-ed1-x529.google.com with SMTP id 5so30839651edw.7; Sun, 17 Oct 2021 10:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MMqnqsUUcK1PWEgJODm9TEqM0MGx97DCR5kYwOP0Arg=; b=lP6t6y03I/zgYkdUODtChH4X7ir1crbG3TY0w2ghZX7K1+y42Y18h854tyjBlT+ZfT iFRGUb/b5YKT8lrys/W8xgTtOCmdLkj0twRLGXJM3LoQ7GR+y6ysI3FcF3qzWObwxYsR RP8gBu3oSfR89Z+Z3vMTYWWAovAwFNh00XdBFnNtTjjM5ofQF6F8TG5nYwFbf6AlzB1B sVUx45+xbHSJ7WtbjywkRM4Q5O9B6fxJnQEk8yYrAS9ISpZhYYgeM9LwzxTkVgZnH+tA LB4Jx45oTQbatMwKYrmxMGc6LzfC8BEQk2zWVRSbvMd93FY/FnT1+skCqCwOSlMfuQ1l nn1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MMqnqsUUcK1PWEgJODm9TEqM0MGx97DCR5kYwOP0Arg=; b=TwfWSDucuWq0HPf88RRJ2SMsJ/51UrWdAQT/zNoODF9A5re7zNGcOChb14L3N3a6FL dy2m8PEcH8EiH/2CHhKisl4Ku/5jjMAj/vUKEx+oyd6oKsppggpYCQJndjrcTED74+kY Th4Li6hsoK+F5wjDfaxJAbKPsyb3/CgWMLPR49KzxhXwXfwDqbwgbQZyDnVlKASFxWjU lbBRBFvt4zZdT0CTPc5EQZSfW2ZSjn0cm7lQW8kSUPgo9Zcl8Dbo2awIVvFYRnccUu1y YD2nowmJSIRLHhaTKawz1DAlx8wRlm64x23fnX10p9xdX1Xx88r3MLVWCtGyHF8AAiWR Fl5Q== X-Gm-Message-State: AOAM532Hc0V4/dUe3ldytW3Yv69lQsegw3to99+cxSZL3K0iu8Udx1FV gGd8CfwGKBelAt1W4xzQJhI= X-Google-Smtp-Source: ABdhPJzQbTVRLRQD4QcslzopM9K4WNCK9ue74WRUMUAUwDIITykeEJwEq3XMbMgahK/4/8aNY0I1Ag== X-Received: by 2002:a17:907:7f24:: with SMTP id qf36mr5667609ejc.491.1634491662520; Sun, 17 Oct 2021 10:27:42 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:42 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 7/8] [RISCV_PM] Implement address masking functions required for RISC-V Pointer Masking extension Date: Sun, 17 Oct 2021 20:27:27 +0300 Message-Id: <20211017172728.759687-8-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x529.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Anatoly Parshintsev Signed-off-by: Anatoly Parshintsev Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 20 ++++++++++++++++++++ target/riscv/translate.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index acb4ce9d23..0ae12b9e61 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -407,6 +407,8 @@ FIELD(TB_FLAGS, VILL, 8, 1) /* Is a Hypervisor instruction load/store allowed? */ FIELD(TB_FLAGS, HLSX, 9, 1) FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2) +/* If PointerMasking should be applied */ +FIELD(TB_FLAGS, PM_ENABLED, 10, 1) bool riscv_cpu_is_32bit(CPURISCVState *env); @@ -467,6 +469,24 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS, get_field(env->mstatus_hs, MSTATUS_FS)); } + if (riscv_has_ext(env, RVJ)) { + int priv = flags & TB_FLAGS_PRIV_MMU_MASK; + bool pm_enabled = false; + switch (priv) { + case PRV_U: + pm_enabled = env->mmte & U_PM_ENABLE; + break; + case PRV_S: + pm_enabled = env->mmte & S_PM_ENABLE; + break; + case PRV_M: + pm_enabled = env->mmte & M_PM_ENABLE; + break; + default: + g_assert_not_reached(); + } + flags = FIELD_DP32(flags, TB_FLAGS, PM_ENABLED, pm_enabled); + } #endif *pflags = flags; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 9e176b8137..e1a5725395 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -36,6 +36,9 @@ static TCGv cpu_gpr[32], cpu_pc, cpu_vl; static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ static TCGv load_res; static TCGv load_val; +/* globals for PM CSRs */ +static TCGv pm_mask[4]; +static TCGv pm_base[4]; #include "exec/gen-icount.h" @@ -82,6 +85,10 @@ typedef struct DisasContext { TCGv zero; /* Space for 3 operands plus 1 extra for address computation. */ TCGv temp[4]; + /* PointerMasking extension */ + bool pm_enabled; + TCGv pm_mask; + TCGv pm_base; } DisasContext; static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -248,11 +255,20 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) } /* - * Temp stub: generates address adjustment for PointerMasking + * Generates address adjustment for PointerMasking */ static TCGv gen_pm_adjust_address(DisasContext *s, TCGv src) { - return src; + TCGv temp; + if (!s->pm_enabled) { + /* Load unmodified address */ + return src; + } else { + temp = temp_new(s); + tcg_gen_andc_tl(temp, src, s->pm_mask); + tcg_gen_or_tl(temp, temp, s->pm_base); + return temp; + } } #ifndef CONFIG_USER_ONLY @@ -536,6 +552,10 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->w = false; ctx->ntemp = 0; memset(ctx->temp, 0, sizeof(ctx->temp)); + ctx->pm_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_ENABLED); + int priv = tb_flags & TB_FLAGS_PRIV_MMU_MASK; + ctx->pm_mask = pm_mask[priv]; + ctx->pm_base = pm_base[priv]; ctx->zero = tcg_constant_tl(0); } @@ -649,4 +669,19 @@ void riscv_translate_init(void) "load_res"); load_val = tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, load_val), "load_val"); +#ifndef CONFIG_USER_ONLY + /* Assign PM CSRs to tcg globals */ + pm_mask[PRV_U] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, upmmask), "upmmask"); + pm_base[PRV_U] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, upmbase), "upmbase"); + pm_mask[PRV_S] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, spmmask), "spmmask"); + pm_base[PRV_S] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, spmbase), "spmbase"); + pm_mask[PRV_M] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, mpmmask), "mpmmask"); + pm_base[PRV_M] = + tcg_global_mem_new(cpu_env, offsetof(CPURISCVState, mpmbase), "mpmbase"); +#endif } From patchwork Sun Oct 17 17:27:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Baturo X-Patchwork-Id: 12564507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3BB8C433EF for ; Sun, 17 Oct 2021 17:38:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88F8D60F57 for ; Sun, 17 Oct 2021 17:38:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88F8D60F57 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:36470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcA6x-0007jH-FQ for qemu-devel@archiver.kernel.org; Sun, 17 Oct 2021 13:38:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mc9wo-0001nm-Uf; Sun, 17 Oct 2021 13:27:47 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:46018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mc9wn-0003Ht-EG; Sun, 17 Oct 2021 13:27:46 -0400 Received: by mail-ed1-x535.google.com with SMTP id r18so61200775edv.12; Sun, 17 Oct 2021 10:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WX5XX48DMBcs3sY/O4MWnvihk8w9+6+uzGwdj8DEbnQ=; b=ogAntw5mD4rgmA5hsWn9INRaSM1bxJOtQspAWAcitYNwI+fDaHvPdG1sd8EKjo7uhk JRY6RFAmRFcI5S7Q++eqIAtNdWVyznNtjj65A/igSpcY/LvDQguTwT4CcvhVv5auLF1E bnm3vDUWoFGYg33iTd05ADme616Uu5siPjd8piwc46DXjqLkUQk7TUUggd2PIf+2rU1R K2200Q/q8jBnbxL83QL9Eu2NCLT5VGdADz+cXq813WrLWtnuquckK7+iLgMvE6GTLPpo QXjPNmU1KiSR+mTAURxFY8rl7MT2m/zEbUmw8+O3GkZqbvxLY4EUjwVwnnJQJCfsgSAT +xBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WX5XX48DMBcs3sY/O4MWnvihk8w9+6+uzGwdj8DEbnQ=; b=bMP65Uf/9SUigpKrZvpcRjwDgh2FrvfL1rG+o1GvEOwE6+ah8N0CkAx7U2xoU5PfHK xHpqTNWcOMGNx2gBjnCSc++Cej8A53Jvsd8jOAv+dQMAB9/U7IU9QgL6FZumri/CgTHz PH8EHe3DKJ/p2GCEOFc3oyN8xypMRkiC1GTJT31c6AXtnHHhQv/+czD/RTzi9D6McnKW 95KduUQ6AGrI13VgUBljM5jxPaiPOS7V++uyNnyqrGyTjVuf3E1NRBvDL03Ki+P+V3Ip swTlvfPs/j1Rv/Kx8rTWrP/W7Iy8g/zlShQsOygUeannWbSKqf3gk1eBwTfV++Iv2tQG jzpQ== X-Gm-Message-State: AOAM532mGBbI89Igl+ZQHS14l1Z5/vSChULwnKzgQzNa5KSBLVKPmNUX 9dPe8LK8aKSSdh09IYU1ADM= X-Google-Smtp-Source: ABdhPJx3yzWHr/xQyIrUFpKb0hxCW1dxXSjZuOSLEEltAJ8VyRT20YH9cnf+ccd+uX4Zf6ZjWcqrhQ== X-Received: by 2002:a17:907:3e87:: with SMTP id hs7mr23886026ejc.403.1634491663665; Sun, 17 Oct 2021 10:27:43 -0700 (PDT) Received: from neptune.lab ([46.39.228.224]) by smtp.googlemail.com with ESMTPSA id v19sm7989814ejx.26.2021.10.17.10.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 10:27:43 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Subject: [PATCH v14 8/8] [RISCV_PM] Allow experimental J-ext to be turned on Date: Sun, 17 Oct 2021 20:27:28 +0300 Message-Id: <20211017172728.759687-9-space.monkey.delivers@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017172728.759687-1-space.monkey.delivers@gmail.com> References: <20211017172728.759687-1-space.monkey.delivers@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=baturo.alexey@gmail.com; helo=mail-ed1-x535.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: baturo.alexey@gmail.com, qemu-riscv@nongnu.org, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, richard.henderson@linaro.org, qemu-devel@nongnu.org, space.monkey.delivers@gmail.com, Alistair Francis , kupokupokupopo@gmail.com, palmer@dabbelt.com, Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexey Baturo Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7f9dde70b7..fb08c0ffb8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -558,6 +558,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } set_vext_version(env, vext_version); } + if (cpu->cfg.ext_j) { + target_misa |= RVJ; + } set_misa(env, target_misa); } @@ -624,6 +627,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false), DEFINE_PROP_BOOL("x-zbs", RISCVCPU, cfg.ext_zbs, false), DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false), + DEFINE_PROP_BOOL("x-j", RISCVCPU, cfg.ext_j, false), DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false), DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true), DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),