From nobody Fri Dec 27 14:40:11 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397838; cv=none; d=zohomail.com; s=zohoarc; b=XsNClvv37knpUP9FsFTqqRfJLi/CBW6mSKbX9S4qztT28XmHnjI6jSCK4yHeSyu6QClRwxJ9cBTTEusPiIFurcN+NfmQ6FoCHhhXvtrVDm5g473mHgJavck1t4zkyt9t5BSD7z1SslUcwEvYMOEcYPg8WsmlyVezCUoIhaO7/TM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397838; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=GTg/K46MLnKp7nhrnpIYs1ZUXvWcbNGy29uSK71Bh3c=; b=isETkMLTdqNsOrHZnZ1H2+5mqcc54kaoGB1Xxd2IL2TqYYYJ+/6AQHg1e7Rf0A9I10Zc+f4OeFQrzc5BwfJiDTMrQivJ8HE+XooRISSafzbyoVOuyexn7OxF4Kc/AgOuSfv8MOZD09p0zl309hw8loQQz8ZprOqXE/CwiD+IIyo= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173339783890359.35062233689746; Thu, 5 Dec 2024 03:23:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9wy-0008FP-Is; Thu, 05 Dec 2024 06:23:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9ww-0008Er-Kv; Thu, 05 Dec 2024 06:23:14 -0500 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9wt-0005IJ-Eb; Thu, 05 Dec 2024 06:23:14 -0500 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-53de852a287so856526e87.2; Thu, 05 Dec 2024 03:23:10 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397789; x=1734002589; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GTg/K46MLnKp7nhrnpIYs1ZUXvWcbNGy29uSK71Bh3c=; b=A0ka/4HoF2nnt1yRb8CJr4XJ9mKhIrc7QDHgqy5MIAzdZvDECxlmo0AFbATHqcj6tM YjTwiXucvXZA4gFRfVadnZyz9wMwc3Fyf6w4YEmL5RdCHlCT8TFhhUm0dUFyeAueXRt0 R69sFBI1hRRr6Z2BJZRumfKzqfkdKTkAUXWnZGyrZYKtcQYj5PfEw1V5n+ebYqpyIo4t NMY2P4WmK5Tcg9kVDKXLGUYAJ9/581RixKEcGLynh8GY/bzHzMFLBgIyWgjCcYU4VtQy GClCEPzzht8ex9KoHoH59gUgtXnl6xwKQMQ5O5hgu5jivX/UJgLT5oHxbhw1PLKnyZwj Ux2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397789; x=1734002589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GTg/K46MLnKp7nhrnpIYs1ZUXvWcbNGy29uSK71Bh3c=; b=Gwk9ZTndsQdjDKo/ZjbfLmFuuOPdP+DIQvEkUHO5H64oVmCqrWxv9bydkjUmxF9B8V QtBhoZXZHmeqzOm4CrlD4Gtvm2QClxnE0pVZEUbVnida3iz0wTTi3bf8obfhh8w0pI0+ T1JhT4yXzNXiGlofnr1aaD2cqhUi28OHnlCpnaasHNHcP+ppwx27bPUuaqRevlohYh8g /3gCssgjGh/zykIUvJaRs9JLkA3JrhgSggtVtVKc9Af8Bog3j/DVJpkOMrBqm8oyHSyu vwc0/3JUV9797fTxRK0MNEBfDqY8Dqa8yrFsu+xDA+gdVWwDflMtbvaShjNJrVyncoDa /90w== X-Forwarded-Encrypted: i=1; AJvYcCUDU9i0pa3DtSZgAj97WsU8+gpj20TTu6yAd77glrm9QFjZmAcQpnjr+13RGpyMhIxmGLm5oZmOdzzo@nongnu.org, AJvYcCUzEOJMgKtQp6MlSyNZworfr/hSIc4oA/EXGt2zp6QI/MrwlJXwBHDy+H8U+7jUky7YWRIPCsVVT+sC1A==@nongnu.org X-Gm-Message-State: AOJu0YwQaahVzKyZXF5+9mF0OUhd4ThjAz6EFiRWZ08GCCeu5J4sKbMA 0XsZsXjXiqv2EzMSAI39nl//xHrU9aj6292IZIepeCQdcYGFjxZQ X-Gm-Gg: ASbGncuPTT4poxTgSW2y5eStCWDOh1scJQZtC6GSBnDSmtZZ4jTXqQ1ZuMV6InNJRc/ yRtQ3DqjG84ZC78w5Vi3CLa0BK+8EUJu65PbAmEi1Oqpsfgpk02J8hf1mbCmtL3B7p80X0QFWSz ks6mC3RwbSLAepNbM+y5Gu+MHR9Q/UheFadZeF0EF1KsqKTUe7WN4vQhjRisdm7fZh8PCuxhaT+ 2H2aFTiqJQ8ztrDlSFPXib42ckLfJ12umOEWYV4NqUErz+3zscrDsY= X-Google-Smtp-Source: AGHT+IGOl7sPmVmR17pZwPs3pkeiA7PHIzAoY6d9eAA05jnRq4W6DckmaxtJC79OZy10q4kBzfeTwA== X-Received: by 2002:a05:6512:3087:b0:53d:ed89:d78d with SMTP id 2adb3069b0e04-53e1b8785eamr3006369e87.5.1733397789186; Thu, 05 Dec 2024 03:23:09 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Alistair Francis Subject: [PATCH v12 1/7] target/riscv: Remove obsolete pointer masking extension code. Date: Thu, 5 Dec 2024 14:22:58 +0300 Message-Id: <20241205112304.593204-2-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::12e; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x12e.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397840329116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Zjpm extension is finally ratified. And it's much simplier compared to the = experimental one. The newer version doesn't allow to specify custom mask or base for pointer = masking. Instead it allows only certain options for masking top bits. Signed-off-by: Alexey Baturo Acked-by: Alistair Francis --- target/riscv/cpu.c | 13 +- target/riscv/cpu.h | 33 +--- target/riscv/cpu_bits.h | 87 ---------- target/riscv/cpu_helper.c | 52 ------ target/riscv/csr.c | 326 ----------------------------------- target/riscv/machine.c | 17 +- target/riscv/tcg/tcg-cpu.c | 5 +- target/riscv/translate.c | 28 +-- target/riscv/vector_helper.c | 2 +- 9 files changed, 19 insertions(+), 544 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f219f0c3b5..4e80dcd2e6 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -42,7 +42,7 @@ /* RISC-V CPU definitions */ static const char riscv_single_letter_exts[] =3D "IEMAFDQCBPVH"; const uint32_t misa_bits[] =3D {RVI, RVE, RVM, RVA, RVF, RVD, RVV, - RVC, RVS, RVU, RVH, RVJ, RVG, RVB, 0}; + RVC, RVS, RVU, RVH, RVG, RVB, 0}; =20 /* * From vector_helper.c @@ -793,13 +793,6 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f= , int flags) CSR_MSCRATCH, CSR_SSCRATCH, CSR_SATP, - CSR_MMTE, - CSR_UPMBASE, - CSR_UPMMASK, - CSR_SPMBASE, - CSR_SPMMASK, - CSR_MPMBASE, - CSR_MPMMASK, }; =20 for (i =3D 0; i < ARRAY_SIZE(dump_csrs); ++i) { @@ -985,8 +978,6 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) } i++; } - /* mmte is supposed to have pm.current hardwired to 1 */ - env->mmte |=3D (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); =20 /* * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor @@ -1018,7 +1009,6 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTy= pe type) env->ssp =3D 0; =20 env->xl =3D riscv_cpu_mxl(env); - riscv_cpu_update_mask(env); cs->exception_index =3D RISCV_EXCP_NONE; env->load_res =3D -1; set_default_nan_mode(1, &env->fp_status); @@ -1406,7 +1396,6 @@ static const MISAExtInfo misa_ext_info_arr[] =3D { MISA_EXT_INFO(RVS, "s", "Supervisor-level instructions"), MISA_EXT_INFO(RVU, "u", "User-level instructions"), MISA_EXT_INFO(RVH, "h", "Hypervisor"), - MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), MISA_EXT_INFO(RVV, "v", "Vector operations"), MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 284b112821..e11264231d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -71,7 +71,6 @@ typedef struct CPUArchState CPURISCVState; #define RVS RV('S') #define RVU RV('U') #define RVH RV('H') -#define RVJ RV('J') #define RVG RV('G') #define RVB RV('B') =20 @@ -451,24 +450,11 @@ struct CPUArchState { /* True if in debugger mode. */ bool debugger; =20 - /* - * 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; - uint64_t mstateen[SMSTATEEN_MAX_COUNT]; uint64_t hstateen[SMSTATEEN_MAX_COUNT]; uint64_t sstateen[SMSTATEEN_MAX_COUNT]; uint64_t henvcfg; #endif - target_ulong cur_pmmask; - target_ulong cur_pmbase; =20 /* Fields from here on are preserved across CPU reset. */ QEMUTimer *stimer; /* Internal timer for S-mode interrupt */ @@ -624,19 +610,19 @@ FIELD(TB_FLAGS, XL, 16, 2) /* If PointerMasking should be applied */ FIELD(TB_FLAGS, PM_MASK_ENABLED, 18, 1) FIELD(TB_FLAGS, PM_BASE_ENABLED, 19, 1) -FIELD(TB_FLAGS, VTA, 20, 1) -FIELD(TB_FLAGS, VMA, 21, 1) +FIELD(TB_FLAGS, VTA, 18, 1) +FIELD(TB_FLAGS, VMA, 19, 1) /* Native debug itrigger */ -FIELD(TB_FLAGS, ITRIGGER, 22, 1) +FIELD(TB_FLAGS, ITRIGGER, 20, 1) /* Virtual mode enabled */ -FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) -FIELD(TB_FLAGS, PRIV, 24, 2) -FIELD(TB_FLAGS, AXL, 26, 2) +FIELD(TB_FLAGS, VIRT_ENABLED, 21, 1) +FIELD(TB_FLAGS, PRIV, 22, 2) +FIELD(TB_FLAGS, AXL, 24, 2) /* zicfilp needs a TB flag to track indirect branches */ -FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1) -FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1) +FIELD(TB_FLAGS, FCFI_ENABLED, 26, 1) +FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 27, 1) /* zicfiss needs a TB flag so that correct TB is located based on tb flags= */ -FIELD(TB_FLAGS, BCFI_ENABLED, 30, 1) +FIELD(TB_FLAGS, BCFI_ENABLED, 28, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) @@ -772,7 +758,6 @@ static inline uint32_t vext_get_vlmax(uint32_t vlenb, u= int32_t vsew, void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags); =20 -void riscv_cpu_update_mask(CPURISCVState *env); bool riscv_cpu_is_32bit(RISCVCPU *cpu); =20 RISCVException riscv_csrr(CPURISCVState *env, int csrno, diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 385a2c67c2..2a6aff63ed 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -497,37 +497,6 @@ #define CSR_MHPMCOUNTER30H 0xb9e #define CSR_MHPMCOUNTER31H 0xb9f =20 -/* - * 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 #define CSR_SCOUNTOVF 0xda0 =20 /* Crypto Extension */ @@ -758,11 +727,6 @@ typedef enum RISCVException { #define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) #define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) =20 -/* General PointerMasking CSR bits */ -#define PM_ENABLE 0x00000001ULL -#define PM_CURRENT 0x00000002ULL -#define PM_INSN 0x00000004ULL - /* Execution environment configuration bits */ #define MENVCFG_FIOM BIT(0) #define MENVCFG_LPE BIT(2) /* zicfilp */ @@ -801,57 +765,6 @@ typedef enum RISCVException { #define HENVCFGH_PBMTE MENVCFGH_PBMTE #define HENVCFGH_STCE MENVCFGH_STCE =20 -/* 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 (EXT_STATUS_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_INS= N | \ - MMTE_S_PM_ENABLE | MMTE_S_PM_CURRENT | MMTE_S_PM_INS= N | \ - MMTE_M_PM_ENABLE | MMTE_M_PM_CURRENT | MMTE_M_PM_INS= N | \ - 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_INS= N | \ - SMTE_S_PM_ENABLE | SMTE_S_PM_CURRENT | SMTE_S_PM_INS= N | \ - 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_IN= SN) - /* MISELECT, SISELECT, and VSISELECT bits (AIA) */ #define ISELECT_IPRIO0 0x30 #define ISELECT_IPRIO15 0x3f diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 45806f5ab0..dba04851d5 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -210,61 +210,10 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *= pc, flags =3D FIELD_DP32(flags, TB_FLAGS, VS, vs); flags =3D FIELD_DP32(flags, TB_FLAGS, XL, env->xl); flags =3D FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env)); - if (env->cur_pmmask !=3D 0) { - flags =3D FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1); - } - if (env->cur_pmbase !=3D 0) { - flags =3D FIELD_DP32(flags, TB_FLAGS, PM_BASE_ENABLED, 1); - } =20 *pflags =3D flags; } =20 -void riscv_cpu_update_mask(CPURISCVState *env) -{ - target_ulong mask =3D 0, base =3D 0; - RISCVMXL xl =3D env->xl; - /* - * TODO: Current RVJ spec does not specify - * how the extension interacts with XLEN. - */ -#ifndef CONFIG_USER_ONLY - int mode =3D cpu_address_mode(env); - xl =3D cpu_get_xl(env, mode); - if (riscv_has_ext(env, RVJ)) { - switch (mode) { - case PRV_M: - if (env->mmte & M_PM_ENABLE) { - mask =3D env->mpmmask; - base =3D env->mpmbase; - } - break; - case PRV_S: - if (env->mmte & S_PM_ENABLE) { - mask =3D env->spmmask; - base =3D env->spmbase; - } - break; - case PRV_U: - if (env->mmte & U_PM_ENABLE) { - mask =3D env->upmmask; - base =3D env->upmbase; - } - break; - default: - g_assert_not_reached(); - } - } -#endif - if (xl =3D=3D MXL_RV32) { - env->cur_pmmask =3D mask & UINT32_MAX; - env->cur_pmbase =3D base & UINT32_MAX; - } else { - env->cur_pmmask =3D mask; - env->cur_pmbase =3D base; - } -} - #ifndef CONFIG_USER_ONLY =20 /* @@ -786,7 +735,6 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulon= g newpriv, bool virt_en) /* tlb_flush is unnecessary as mode is contained in mmu_idx */ env->priv =3D newpriv; env->xl =3D cpu_recompute_xl(env); - riscv_cpu_update_mask(env); =20 /* * Clear the load reservation - otherwise a reservation placed in one diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9846770820..941c9691da 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -531,16 +531,6 @@ static RISCVException hgatp(CPURISCVState *env, int cs= rno) return hmode(env, csrno); } =20 -/* 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 aia_hmode(CPURISCVState *env, int csrno) { if (!riscv_cpu_cfg(env)->ext_ssaia) { @@ -1648,7 +1638,6 @@ static RISCVException write_mstatus(CPURISCVState *en= v, int csrno, env->xl =3D cpu_recompute_xl(env); } =20 - riscv_cpu_update_mask(env); return RISCV_EXCP_NONE; } =20 @@ -4351,302 +4340,6 @@ static RISCVException write_mcontext(CPURISCVState = *env, int csrno, return RISCV_EXCP_NONE; } =20 -/* - * 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 =3D get_field(csrno, 0x300); - int pm_current; - - if (env->debugger) { - return false; - } - /* - * If priv lvls differ that means we're accessing csr from higher priv= lvl, - * so allow the access - */ - if (env->priv !=3D csr_priv) { - return false; - } - switch (env->priv) { - case PRV_M: - pm_current =3D get_field(env->mmte, M_PM_CURRENT); - break; - case PRV_S: - pm_current =3D get_field(env->mmte, S_PM_CURRENT); - break; - case PRV_U: - pm_current =3D 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=3D= =3D1 */ - return !pm_current; -} - -static RISCVException read_mmte(CPURISCVState *env, int csrno, - target_ulong *val) -{ - *val =3D 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 =3D val & MMTE_MASK; - - if (val !=3D wpri_val) { - qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" - TARGET_FMT_lx "\n", "MMTE: WPRI violation written 0x= ", - val, "vs expected 0x", wpri_val); - } - /* for machine mode pm.current is hardwired to 1 */ - wpri_val |=3D MMTE_M_PM_CURRENT; - - /* hardwiring pm.instruction bit to 0, since it's not supported yet */ - wpri_val &=3D ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN); - env->mmte =3D wpri_val | EXT_STATUS_DIRTY; - riscv_cpu_update_mask(env); - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->mmte & SMTE_MASK; - return RISCV_EXCP_NONE; -} - -static RISCVException write_smte(CPURISCVState *env, int csrno, - target_ulong val) -{ - target_ulong wpri_val =3D val & SMTE_MASK; - - if (val !=3D wpri_val) { - qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" - TARGET_FMT_lx "\n", "SMTE: WPRI violation written 0x= ", - val, "vs expected 0x", wpri_val); - } - - /* if pm.current=3D=3D0 we can't modify current PM CSRs */ - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - - wpri_val |=3D (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 =3D env->mmte & UMTE_MASK; - return RISCV_EXCP_NONE; -} - -static RISCVException write_umte(CPURISCVState *env, int csrno, - target_ulong val) -{ - target_ulong wpri_val =3D val & UMTE_MASK; - - if (val !=3D wpri_val) { - qemu_log_mask(LOG_GUEST_ERROR, "%s" TARGET_FMT_lx " %s" - TARGET_FMT_lx "\n", "UMTE: WPRI violation written 0x= ", - val, "vs expected 0x", wpri_val); - } - - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - - wpri_val |=3D (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 =3D env->mpmmask; - return RISCV_EXCP_NONE; -} - -static RISCVException write_mpmmask(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - env->mpmmask =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_M) && (env->mmte & M_PM_ENABLE))= { - env->cur_pmmask =3D val; - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->spmmask; - return RISCV_EXCP_NONE; -} - -static RISCVException write_spmmask(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - /* if pm.current=3D=3D0 we can't modify current PM CSRs */ - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - env->spmmask =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_S) && (env->mmte & S_PM_ENABLE))= { - env->cur_pmmask =3D val; - if (cpu_get_xl(env, PRV_S) =3D=3D MXL_RV32) { - env->cur_pmmask &=3D UINT32_MAX; - } - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->upmmask; - return RISCV_EXCP_NONE; -} - -static RISCVException write_upmmask(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - /* if pm.current=3D=3D0 we can't modify current PM CSRs */ - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - env->upmmask =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_U) && (env->mmte & U_PM_ENABLE))= { - env->cur_pmmask =3D val; - if (cpu_get_xl(env, PRV_U) =3D=3D MXL_RV32) { - env->cur_pmmask &=3D UINT32_MAX; - } - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->mpmbase; - return RISCV_EXCP_NONE; -} - -static RISCVException write_mpmbase(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - env->mpmbase =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_M) && (env->mmte & M_PM_ENABLE))= { - env->cur_pmbase =3D val; - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->spmbase; - return RISCV_EXCP_NONE; -} - -static RISCVException write_spmbase(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - /* if pm.current=3D=3D0 we can't modify current PM CSRs */ - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - env->spmbase =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_S) && (env->mmte & S_PM_ENABLE))= { - env->cur_pmbase =3D val; - if (cpu_get_xl(env, PRV_S) =3D=3D MXL_RV32) { - env->cur_pmbase &=3D UINT32_MAX; - } - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D 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 =3D env->upmbase; - return RISCV_EXCP_NONE; -} - -static RISCVException write_upmbase(CPURISCVState *env, int csrno, - target_ulong val) -{ - uint64_t mstatus; - - /* if pm.current=3D=3D0 we can't modify current PM CSRs */ - if (check_pm_current_disabled(env, csrno)) { - return RISCV_EXCP_NONE; - } - env->upmbase =3D val; - if ((cpu_address_mode(env) =3D=3D PRV_U) && (env->mmte & U_PM_ENABLE))= { - env->cur_pmbase =3D val; - if (cpu_get_xl(env, PRV_U) =3D=3D MXL_RV32) { - env->cur_pmbase &=3D UINT32_MAX; - } - } - env->mmte |=3D EXT_STATUS_DIRTY; - - /* Set XS and SD bits, since PM CSRs are dirty */ - mstatus =3D env->mstatus | MSTATUS_XS; - write_mstatus(env, csrno, mstatus); - return RISCV_EXCP_NONE; -} - #endif =20 /* Crypto Extension */ @@ -5316,25 +5009,6 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_TINFO] =3D { "tinfo", debug, read_tinfo, write_ignore = }, [CSR_MCONTEXT] =3D { "mcontext", debug, read_mcontext, write_mcontex= t }, =20 - /* User Pointer Masking */ - [CSR_UMTE] =3D { "umte", pointer_masking, read_umte, write_u= mte }, - [CSR_UPMMASK] =3D { "upmmask", pointer_masking, read_upmmask, - write_upmmask = }, - [CSR_UPMBASE] =3D { "upmbase", pointer_masking, read_upmbase, - write_upmbase = }, - /* Machine Pointer Masking */ - [CSR_MMTE] =3D { "mmte", pointer_masking, read_mmte, write_m= mte }, - [CSR_MPMMASK] =3D { "mpmmask", pointer_masking, read_mpmmask, - write_mpmmask = }, - [CSR_MPMBASE] =3D { "mpmbase", pointer_masking, read_mpmbase, - write_mpmbase = }, - /* Supervisor Pointer Masking */ - [CSR_SMTE] =3D { "smte", pointer_masking, read_smte, write_s= mte }, - [CSR_SPMMASK] =3D { "spmmask", pointer_masking, read_spmmask, - write_spmmask = }, - [CSR_SPMBASE] =3D { "spmbase", pointer_masking, read_spmbase, - write_spmbase = }, - /* Performance Counters */ [CSR_HPMCOUNTER3] =3D { "hpmcounter3", ctr, read_hpmcounter }, [CSR_HPMCOUNTER4] =3D { "hpmcounter4", ctr, read_hpmcounter }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 99f0af5077..e40dc73994 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -152,25 +152,15 @@ static const VMStateDescription vmstate_vector =3D { =20 static bool pointermasking_needed(void *opaque) { - RISCVCPU *cpu =3D opaque; - CPURISCVState *env =3D &cpu->env; - - return riscv_has_ext(env, RVJ); + return false; } =20 static const VMStateDescription vmstate_pointermasking =3D { .name =3D "cpu/pointer_masking", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .needed =3D pointermasking_needed, .fields =3D (const 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), =20 VMSTATE_END_OF_LIST() } @@ -266,7 +256,6 @@ static int riscv_cpu_post_load(void *opaque, int versio= n_id) CPURISCVState *env =3D &cpu->env; =20 env->xl =3D cpu_recompute_xl(env); - riscv_cpu_update_mask(env); return 0; } =20 diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index c62c221696..179428f3f0 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -1086,7 +1086,6 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = =3D { MISA_CFG(RVS, true), MISA_CFG(RVU, true), MISA_CFG(RVH, true), - MISA_CFG(RVJ, false), MISA_CFG(RVV, false), MISA_CFG(RVG, false), MISA_CFG(RVB, false), @@ -1373,8 +1372,8 @@ static void riscv_init_max_cpu_extensions(Object *obj) CPURISCVState *env =3D &cpu->env; const RISCVCPUMultiExtConfig *prop; =20 - /* Enable RVG, RVJ and RVV that are disabled by default */ - riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); + /* Enable RVG and RVV that are disabled by default */ + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVV); =20 for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { isa_ext_update_enabled(cpu, prop->offset, true); diff --git a/target/riscv/translate.c b/target/riscv/translate.c index bccaf8e89a..018be5504f 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -41,9 +41,6 @@ static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cp= u_vstart; 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; -static TCGv pm_base; =20 /* * If an operation is being performed on less than TARGET_LONG_BITS, @@ -105,9 +102,6 @@ typedef struct DisasContext { bool vl_eq_vlmax; CPUState *cs; TCGv zero; - /* PointerMasking extension */ - bool pm_mask_enabled; - bool pm_base_enabled; /* Ztso */ bool ztso; /* Use icount trigger for native debug */ @@ -591,14 +585,9 @@ static TCGv get_address(DisasContext *ctx, int rs1, in= t imm) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_addi_tl(addr, src1, imm); - if (ctx->pm_mask_enabled) { - tcg_gen_andc_tl(addr, addr, pm_mask); - } else if (get_address_xl(ctx) =3D=3D MXL_RV32) { + if (get_address_xl(ctx) =3D=3D MXL_RV32) { tcg_gen_ext32u_tl(addr, addr); } - if (ctx->pm_base_enabled) { - tcg_gen_or_tl(addr, addr, pm_base); - } =20 return addr; } @@ -610,14 +599,10 @@ static TCGv get_address_indexed(DisasContext *ctx, in= t rs1, TCGv offs) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_add_tl(addr, src1, offs); - if (ctx->pm_mask_enabled) { - tcg_gen_andc_tl(addr, addr, pm_mask); - } else if (get_xl(ctx) =3D=3D MXL_RV32) { + if (get_xl(ctx) =3D=3D MXL_RV32) { tcg_gen_ext32u_tl(addr, addr); } - if (ctx->pm_base_enabled) { - tcg_gen_or_tl(addr, addr, pm_base); - } + return addr; } =20 @@ -1245,8 +1230,6 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->xl =3D FIELD_EX32(tb_flags, TB_FLAGS, XL); ctx->address_xl =3D FIELD_EX32(tb_flags, TB_FLAGS, AXL); ctx->cs =3D cs; - ctx->pm_mask_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_MASK_ENABLE= D); - ctx->pm_base_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLE= D); ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->bcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); @@ -1385,9 +1368,4 @@ void riscv_translate_init(void) "load_res"); load_val =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= val), "load_val"); - /* Assign PM CSRs to tcg globals */ - pm_mask =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, cur_pm= mask), - "pmmask"); - pm_base =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, cur_pm= base), - "pmbase"); } diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index a85dd1d200..3589e3ef28 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -107,7 +107,7 @@ static inline uint32_t vext_max_elems(uint32_t desc, ui= nt32_t log2_esz) =20 static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) { - return (addr & ~env->cur_pmmask) | env->cur_pmbase; + return addr; } =20 /* --=20 2.39.5 From nobody Fri Dec 27 14:40:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397875836438.44001047044355; Thu, 5 Dec 2024 03:24:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x3-0008Ig-Ir; Thu, 05 Dec 2024 06:23:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9wy-0008FG-Rk; Thu, 05 Dec 2024 06:23:16 -0500 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9wv-0005Ia-7S; Thu, 05 Dec 2024 06:23:15 -0500 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2ffc016f301so6543751fa.1; Thu, 05 Dec 2024 03:23:12 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397791; x=1734002591; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vrCdLZ8Ddyr2Q8mjwb19Axqv6cumMVuY8X4Ma76BPPk=; b=c6otVEggvMqb2yMP/sWZ+DPVwIyTy/lSrG8U3xPeYZ59YcpCDy76V7YOs0l4Pw05mw YD1rNUeLQ9nFA8Dl00LLyfV6Qq+nVKNiuZ7G4RVhJ135SDMVidwacE6bro4w1RIfMpM1 u/15toVmKm0pMJ12V/XFJbOXc5ZUo4hECRezG2hM3jn3CAij5LgtRyxHcC6V04dfXLcP HXQxsrtbU1hJ6sNDbvZq9lea/i+0Dqa/i8nB8Ds4uJdG7Haeb0V/rkdPGaAQIQOqUKzI 1inI5cdvS1datdOTCrPs0GbkOHgy2dpETdugSi2VQkFiScyUYva3zDO8vYqEZbu7rLqG Fbxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397791; x=1734002591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vrCdLZ8Ddyr2Q8mjwb19Axqv6cumMVuY8X4Ma76BPPk=; b=sXapG5rzokMH1aEbAWypVM0tANSqdozlsIZa+JtqOGAoGQ6rkrD7xKBOTCqdrUr4B1 dA/JPQPL6D2YUC1KejS7FAZfdUZQQ7rycI8Sam2sZKc9Lk/pXXUR7sQnrG6wS1bVxJks 9Vg5T9TiPmH3BEPe0ziCru4mEEIE7C1VIo0Bp2UDhwwLTEQgw2OBsA7xc5FO2RN703V+ OEGvFb+EX6Idgp8vpnP0O6MFLyBfbVaqlkXzvvrLRE5GfGJSeN9i8ZTtZ33pGIguWvdT 7ZOQJcm/LBh6ufzKLy4CiyQdVCV7IM42W5eDwFFGIf8U+Ri6jXeOp1jSqsvAe7KS967b wAQA== X-Forwarded-Encrypted: i=1; AJvYcCUMmewgq+aBCceOig9yKyvvTsP7B5x6wmjx5K4TV4iThWk1ENrPtprEzudo/Sdb6cPHe545HPpiwx9Q@nongnu.org, AJvYcCXApxY0M21tDSrOZACXC5C7MwRMwdNlVKJ2IV4PRvZ4x/GbcGwhovybJzN9yD/V8bKYVy5yuhurYW2c9Q==@nongnu.org X-Gm-Message-State: AOJu0YzQg2nw0tRknQbG/sLMhc6del8aJIJ8h14uGYSaezzZPOfpQ230 qhi70VwCuXKSHx1019j3woL/RrPyfrE3ALQsTsBXUBUitvTa+VxL X-Gm-Gg: ASbGncsFAJIT7pQ+gbRUhLmOT0IC8VuGP88egQv0vyFkRad1v2JSSXTIynfP53RvCcc CYhg8Xl2x8NWQClD9nb7YpmGmVamRLQBqavYcCHXrjJuTcCMD+cbSqGQE5Mz64lFO6fLh94HWDx 5iINvdpjby4U05WMb6CFMxVcN7YWQqyVn2P6D+FQqVyXU5JELbODLOQVXvvVEcATKzZky8NRO7R wa1v/yW8IT8RyfbYSE507D/TXCC5IDM23s2g/WGB/zllz20WFAakYo= X-Google-Smtp-Source: AGHT+IHbtNKvuP2sHQaI5gaU2itz9evG90JA6wm3rbVkUUQ8dOfPGGFUnLMD+qSsdOckfjlTji80Ng== X-Received: by 2002:a05:6512:3c82:b0:53e:28b7:332a with SMTP id 2adb3069b0e04-53e28b733e6mr74526e87.44.1733397790935; Thu, 05 Dec 2024 03:23:10 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v12 2/7] target/riscv: Add new CSR fields for S{sn, mn, m}pm extensions as part of Zjpm v1.0 Date: Thu, 5 Dec 2024 14:22:59 +0300 Message-Id: <20241205112304.593204-3-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::231; envelope-from=baturo.alexey@gmail.com; helo=mail-lj1-x231.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1733397877923116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo Reviewed-by: Daniel Henrique Barboza --- target/riscv/cpu.h | 8 ++++++++ target/riscv/cpu_bits.h | 4 ++++ target/riscv/cpu_cfg.h | 3 +++ target/riscv/csr.c | 31 ++++++++++++++++++++++++++++++- target/riscv/pmp.c | 14 +++++++++++--- target/riscv/pmp.h | 1 + 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e11264231d..417ff45544 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -128,6 +128,14 @@ typedef enum { EXT_STATUS_DIRTY, } RISCVExtStatus; =20 +/* Enum holds PMM field values for Zjpm v1.0 extension */ +typedef enum { + PMM_FIELD_DISABLED =3D 0, + PMM_FIELD_RESERVED =3D 1, + PMM_FIELD_PMLEN7 =3D 2, + PMM_FIELD_PMLEN16 =3D 3, +} RISCVPmPmm; + typedef struct riscv_cpu_implied_exts_rule { #ifndef CONFIG_USER_ONLY /* diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 2a6aff63ed..d8f9bc68e3 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -574,6 +574,7 @@ typedef enum { #define HSTATUS_VTW 0x00200000 #define HSTATUS_VTSR 0x00400000 #define HSTATUS_VSXL 0x300000000 +#define HSTATUS_HUPMM 0x3000000000000 =20 #define HSTATUS32_WPRI 0xFF8FF87E #define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL @@ -734,6 +735,7 @@ typedef enum RISCVException { #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) +#define MENVCFG_PMM (3ULL << 32) #define MENVCFG_ADUE (1ULL << 61) #define MENVCFG_PBMTE (1ULL << 62) #define MENVCFG_STCE (1ULL << 63) @@ -749,6 +751,7 @@ typedef enum RISCVException { #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE +#define SENVCFG_PMM MENVCFG_PMM =20 #define HENVCFG_FIOM MENVCFG_FIOM #define HENVCFG_LPE MENVCFG_LPE @@ -756,6 +759,7 @@ typedef enum RISCVException { #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE +#define HENVCFG_PMM MENVCFG_PMM #define HENVCFG_ADUE MENVCFG_ADUE #define HENVCFG_PBMTE MENVCFG_PBMTE #define HENVCFG_STCE MENVCFG_STCE diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 59d6fc445d..79a114eb07 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -128,6 +128,9 @@ struct RISCVCPUConfig { bool ext_ssaia; bool ext_sscofpmf; bool ext_smepmp; + bool ext_ssnpm; + bool ext_smnpm; + bool ext_smmpm; bool rvv_ta_all_1s; bool rvv_ma_all_1s; bool rvv_vl_half_avl; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 941c9691da..5389ccb983 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -575,6 +575,9 @@ static RISCVException have_mseccfg(CPURISCVState *env, = int csrno) if (riscv_cpu_cfg(env)->ext_zkr) { return RISCV_EXCP_NONE; } + if (riscv_cpu_cfg(env)->ext_smmpm) { + return RISCV_EXCP_NONE; + } =20 return RISCV_EXCP_ILLEGAL_INST; } @@ -2379,6 +2382,12 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, if (env_archcpu(env)->cfg.ext_zicfiss) { mask |=3D MENVCFG_SSE; } + + /* Update PMM field only if the value is valid according to Zjpm v= 1.0 */ + if (env_archcpu(env)->cfg.ext_smnpm && + get_field(val, MENVCFG_PMM) !=3D PMM_FIELD_RESERVED) { + mask |=3D MENVCFG_PMM; + } } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2425,6 +2434,12 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, { uint64_t mask =3D SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCF= G_CBZE; RISCVException ret; + /* Update PMM field only if the value is valid according to Zjpm v1.0 = */ + if (env_archcpu(env)->cfg.ext_ssnpm && + riscv_cpu_mxl(env) =3D=3D MXL_RV64 && + get_field(val, SENVCFG_PMM) !=3D PMM_FIELD_RESERVED) { + mask |=3D SENVCFG_PMM; + } =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); if (ret !=3D RISCV_EXCP_NONE) { @@ -2489,6 +2504,12 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, get_field(env->menvcfg, MENVCFG_SSE)) { mask |=3D HENVCFG_SSE; } + + /* Update PMM field only if the value is valid according to Zjpm v= 1.0 */ + if (env_archcpu(env)->cfg.ext_ssnpm && + get_field(val, HENVCFG_PMM) !=3D PMM_FIELD_RESERVED) { + mask |=3D HENVCFG_PMM; + } } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -3525,7 +3546,15 @@ static RISCVException read_hstatus(CPURISCVState *en= v, int csrno, static RISCVException write_hstatus(CPURISCVState *env, int csrno, target_ulong val) { - env->hstatus =3D val; + uint64_t mask =3D (target_ulong)-1; + /* Update PMM field only if the value is valid according to Zjpm v1.0 = */ + if (!env_archcpu(env)->cfg.ext_ssnpm || + riscv_cpu_mxl(env) !=3D MXL_RV64 || + get_field(val, HSTATUS_HUPMM) =3D=3D PMM_FIELD_RESERVED) { + mask &=3D ~HSTATUS_HUPMM; + } + env->hstatus =3D (env->hstatus & ~mask) | (val & mask); + if (riscv_cpu_mxl(env) !=3D MXL_RV32 && get_field(val, HSTATUS_VSXL) != =3D 2) { qemu_log_mask(LOG_UNIMP, "QEMU does not support mixed HSXLEN options."); diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index a1b36664fc..a185c246d6 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -575,6 +575,13 @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint= 32_t addr_index) void mseccfg_csr_write(CPURISCVState *env, target_ulong val) { int i; + uint64_t mask =3D MSECCFG_MMWP | MSECCFG_MML; + /* Update PMM field only if the value is valid according to Zjpm v1.0 = */ + if (riscv_cpu_cfg(env)->ext_smmpm && + riscv_cpu_mxl(env) =3D=3D MXL_RV64 && + get_field(val, MSECCFG_PMM) !=3D PMM_FIELD_RESERVED) { + mask |=3D MSECCFG_PMM; + } =20 trace_mseccfg_csr_write(env->mhartid, val); =20 @@ -590,12 +597,13 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulo= ng val) =20 if (riscv_cpu_cfg(env)->ext_smepmp) { /* Sticky bits */ - val |=3D (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML)); - if ((val ^ env->mseccfg) & (MSECCFG_MMWP | MSECCFG_MML)) { + val |=3D (env->mseccfg & mask); + if ((val ^ env->mseccfg) & mask) { tlb_flush(env_cpu(env)); } } else { - val &=3D ~(MSECCFG_MMWP | MSECCFG_MML | MSECCFG_RLB); + mask |=3D MSECCFG_RLB; + val &=3D ~(mask); } =20 /* M-mode forward cfi to be enabled if cfi extension is implemented */ diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index e0530a17a3..271cf24169 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -46,6 +46,7 @@ typedef enum { MSECCFG_USEED =3D 1 << 8, MSECCFG_SSEED =3D 1 << 9, MSECCFG_MLPE =3D 1 << 10, + MSECCFG_PMM =3D 3ULL << 32, } mseccfg_field_t; =20 typedef struct { --=20 2.39.5 From nobody Fri Dec 27 14:40:11 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397899; cv=none; d=zohomail.com; s=zohoarc; b=bRV5FTo6A/GIi8D0bhP5cy6loTnWunuxVTK9xSQr1dzmOttMOHW4UEt/vwqpkmI9bT7iqpWaH/fA/lxR4NlTBjKV4cZwAz/jZIkNisBlG0R3RWkF6mqVD9dcDmTgAmdg1NhqUbKqy0c17AMPg7xrBgmLeZPZzMtVYAPSGAdBF0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397899; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=T9lGZHXWqJDLPSDknYMJV5oSWnSKjVJ6tDAfkPQT3C8=; b=fNv3W5AEqp8ZzZ0zBZCFCRuX3ksM7kl+BXW0KbAQUsVGf1eS1LDBph3CNAeeBfXg0tPiCDK3/LCD4J4oToG0SB/zSTfzVwrYtxH+RD1ZpNIk+VFOmkIQ1PZhVKI1b1YJwFIbnGiygTvh5rnq+L3iil+5beI8HLky0qZ5TEG/fLc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397899440867.2407448094198; Thu, 5 Dec 2024 03:24:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x0-0008Ge-1G; Thu, 05 Dec 2024 06:23:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9wy-0008FY-CX; Thu, 05 Dec 2024 06:23:16 -0500 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9ww-0005Iq-N2; Thu, 05 Dec 2024 06:23:16 -0500 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-53de6b7da14so871492e87.0; Thu, 05 Dec 2024 03:23:14 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397792; x=1734002592; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T9lGZHXWqJDLPSDknYMJV5oSWnSKjVJ6tDAfkPQT3C8=; b=V+yyu2hAZOuWaoGaDei3ANoDocu7/2HXyFyYDymjwUw6NPfT0ev63NaaBHI2ZHe7/q iMYLmJMH2jd7fGc+30pgQyLPipqrtYFClu9xpsNfWl5eL3C9u4TS+hdRusoTKm8iECzT 2nISRNUqc2XTwQO1x3XsJv7TdrIV337KaJSWrB2Ey0c19II2aPw8bIsbNg+TOx6TSsMD TyqOo29+SwtXzp8vE3XqwS5Jk6L3xqOavmsw5S/HwmMNM3g5cKI6JIdUX4Ikfr8KVDiO 1OKCzpobypvb/ExL5awgXKRw5YWHyekl5Rm+woiEO35u3TQrJviCpQps85/fgFmR7ALQ /51Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397792; x=1734002592; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T9lGZHXWqJDLPSDknYMJV5oSWnSKjVJ6tDAfkPQT3C8=; b=gJdnCZdBaZXd1gijIFp1XMJiSCXWeRAIOdQjdq0O89N3z/Vu+fXjZwloODly9iRGss pniwaQp4UrFnzmIvFdaDSrfFkvIKO4tiIipAVjnlSIwWIz/i6d92pCyQRPSMfrseXq23 SmQYU8XedgucYnj9AP9oNJzimJ6fFHouCItdvFeaECioSBy+7sAXrSXJn5h8Fezh42Ts wrRsurSxUPd2BVhBcSBxRSWg5ShhVeV3BMx3i/fDtMDReT3buM7Pa6zLaNRnn+qA8Ted GhnWeAQY2ereCGZb+SjUCEc04HsBBSMeFrz8ucIwg5eyoyR4eIhcFRws8n8UmzQUZGb2 I5UA== X-Forwarded-Encrypted: i=1; AJvYcCUbNXZPF/bjVqkLRJ782MWHn1LObshSD4AZeyJAHpsxv2BIUtm9QRDWvhIR5ssurEYn/fLU/T3mbiF6@nongnu.org, AJvYcCWUTTAWTLpS9Ucfj2eNtYRf12L/IuVzQ14eptI+5E/5K+P5izTiJ6Llg9QcRdLG+tzOEnjP+sd+X7rXOg==@nongnu.org X-Gm-Message-State: AOJu0Yy18/z8q9GPFdlW5TqyqqzsEGb8Lw2i6mHfoVzP4VFFOOBqeS/s WAEEYxnYpBBPvh2THS3SY+zciPH9lrW2HCruhc+oeZkGgusMQeje X-Gm-Gg: ASbGnctBjmh3qocUHaIMaLrQhUY3LdgMZeFh5PBXCUA8NYWdw63CjZx0Ao0tVOuCMv+ Rm5FWepc1qDbXMl+45yKpgxDolm/QccWkU5y+lvS7SuEEjfFrUvJ5sms0HBq1EYmf4KZg6dkzVP k78HbFzHvNrc5upvIl+Vn1xzQyIHHiB3m5sdtNbyFGmdhMNG8rgdcjQ0Y3ZmxC9FvynsiDqGD3t A6dplNdNLwhF9yXHLF8fr9x411l/Q2jN/PBMUcoVOTq6FEXTdT9eLc= X-Google-Smtp-Source: AGHT+IHzXQkZmFTRlVb2oAsa7KrJ2rRXmKUBbU9CefOt5mKCsqzbvo7y1sZ7OhMkbKoxbPhFqFJpmQ== X-Received: by 2002:a05:6512:398f:b0:52f:ca2b:1d33 with SMTP id 2adb3069b0e04-53e1b88579cmr3023209e87.20.1733397792382; Thu, 05 Dec 2024 03:23:12 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v12 3/7] target/riscv: Add helper functions to calculate current number of masked bits for pointer masking Date: Thu, 5 Dec 2024 14:23:00 +0300 Message-Id: <20241205112304.593204-4-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::129; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x129.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397899839116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 5 +++ target/riscv/cpu_helper.c | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 417ff45544..74d7076f5a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -768,8 +768,13 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, =20 bool riscv_cpu_is_32bit(RISCVCPU *cpu); =20 +bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); +int riscv_pm_get_pmlen(RISCVPmPmm pmm); + RISCVException riscv_csrr(CPURISCVState *env, int csrno, target_ulong *ret_value); + RISCVException riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask= ); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index dba04851d5..2558f869f2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -214,6 +214,80 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, *pflags =3D flags; } =20 +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env) +{ + RISCVPmPmm pmm =3D PMM_FIELD_DISABLED; +#ifndef CONFIG_USER_ONLY + if (get_field(env->mstatus, MSTATUS_MPRV) && + get_field(env->mstatus, MSTATUS_MXR)) { + return pmm; + } + int priv_mode =3D cpu_address_mode(env); + /* Get current PMM field */ + switch (priv_mode) { + case PRV_M: + if (riscv_cpu_cfg(env)->ext_smmpm) { + pmm =3D get_field(env->mseccfg, MSECCFG_PMM); + } + break; + case PRV_S: + if (riscv_cpu_cfg(env)->ext_smnpm) { + if (get_field(env->mstatus, MSTATUS_MPV)) { + pmm =3D get_field(env->henvcfg, HENVCFG_PMM); + } else { + pmm =3D get_field(env->menvcfg, MENVCFG_PMM); + } + } + break; + case PRV_U: + if (riscv_has_ext(env, RVS)) { + if (riscv_cpu_cfg(env)->ext_ssnpm) { + pmm =3D get_field(env->senvcfg, SENVCFG_PMM); + } + } else { + if (riscv_cpu_cfg(env)->ext_smnpm) { + pmm =3D get_field(env->menvcfg, MENVCFG_PMM); + } + } + break; + default: + g_assert_not_reached(); + } +#endif + return pmm; +} + +bool riscv_cpu_virt_mem_enabled(CPURISCVState *env) +{ + bool virt_mem_en =3D false; +#ifndef CONFIG_USER_ONLY + int satp_mode =3D 0; + int priv_mode =3D cpu_address_mode(env); + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + satp_mode =3D get_field(env->satp, SATP32_MODE); + } else { + satp_mode =3D get_field(env->satp, SATP64_MODE); + } + virt_mem_en =3D ((satp_mode !=3D VM_1_10_MBARE) && (priv_mode !=3D PRV= _M)); +#endif + return virt_mem_en; +} + +int riscv_pm_get_pmlen(RISCVPmPmm pmm) +{ + switch (pmm) { + case PMM_FIELD_DISABLED: + return 0; + case PMM_FIELD_PMLEN7: + return 7; + case PMM_FIELD_PMLEN16: + return 16; + default: + g_assert_not_reached(); + } + return -1; +} + #ifndef CONFIG_USER_ONLY =20 /* --=20 2.39.5 From nobody Fri Dec 27 14:40:11 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397899; cv=none; d=zohomail.com; s=zohoarc; b=LrkQRP3q70S2964BlAl6voTRFpYSIrmA+DRmah3lVZf68NiLgg3VXSkwqVe3ipa9o4ZWyEpy3s6hhKI2uEshN4Q6bxF50K+z9O5YR5UACcKgWfCJvHYC256RLD43Velm81w4dOL0VwTodc4TdOLCNr2Ou2KhV9hu9FCg+uA9FhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397899; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=tbTJYxklDAqq9Y2xWT7MmbzmhWEgrNx262KNeoyxuTk=; b=JWC/3i+4sNsMhdo77Gq9WIjcDRnX0q7UZcl612RhALzlnXGB8PUFNkivO8FlvHorLvIs3ngPrgNGmcBz33p/8YeBvWpewHVXS+Ix/qYCJ0myKIKJsZN/Bp0ZwwKIljaUrGBSuKfld7ZBGM9wehEgYOtUZdMigwe72+cGNWjLXAc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397899696522.5528273006503; Thu, 5 Dec 2024 03:24:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x1-0008Hb-Dy; Thu, 05 Dec 2024 06:23:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9x0-0008Gf-0p; Thu, 05 Dec 2024 06:23:18 -0500 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9wy-0005J8-62; Thu, 05 Dec 2024 06:23:17 -0500 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53e1f673ca8so919494e87.3; Thu, 05 Dec 2024 03:23:15 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397794; x=1734002594; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tbTJYxklDAqq9Y2xWT7MmbzmhWEgrNx262KNeoyxuTk=; b=WA2DoZjHQisIrS6UD5LbzWZpL6hbAET/2J8zAyAB34n4nbH4h4yqdDw/O676THz+Hv yUqWsBJ7FSLqEvq/+hSdy5aj9+4mF+WQkBWFFurufmaJ0PM6esT0I9C4P6GN44Yq2mjf P3pkETTUwT/GGXZ+L5s6GBLe7pBHrn5shIUG7W3TqT0Q4sP6FQ/x6tCDz4wUkoUJAISL tmpVndwuuc4+3BAaRWzyXiDW8e4S0xOrdxeC7IlN9hG9n8bPVXkPMpzIzE/IQMYrwf3E 7C+r4se8jdOOV5uOiah/KsLyqxbLKJzDOC9NiXH6Pnc0nel0lVN5KcpexjSAzfqDng1f wPYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397794; x=1734002594; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tbTJYxklDAqq9Y2xWT7MmbzmhWEgrNx262KNeoyxuTk=; b=mN9VlzEByQBTSlggWI1HT31yMZTh6O4jNGYWEZLmp1eGTO1LpMTx+8EL8cxcNyefF5 n7gvCoNJ1oSknKo0Mg8+oaDCe5jDz5p28e22RVggUJfB7rw7AYn2xB8mNuxeu7APmfxM XeNY1ll0aUVIT5Pt+YEt7wsw/GSRntw+mQibBBVpd0lpkhajghspEbJkRTv+9nbopqGK PHKPgGH1eK7WLP8jm88uDAIxmbEd55cMuiebGWBfQlsF09FSjMAYzjK+ho7nF+7M8Tv/ vAoeETnkd0yuxuFoKoiJczZgusup7gcv41MbssYvKJyaHj6VcAgX4xuyoPpk/SkBgI8z RFfQ== X-Forwarded-Encrypted: i=1; AJvYcCWSwJMtttGY+mrn1Uz2+xaW+8SssnfUBmks1NJ8uvO1nVeLGrcWKqKWreEV3LsBdRpFUt9W1egepids2w==@nongnu.org, AJvYcCXbMioAQIoMVwGC5hHQ3WobzRq/LNO+KI2fKE712d5erQdOovyCsVePIfGxwQQ1HKFE21tuiUpaKC9F@nongnu.org X-Gm-Message-State: AOJu0YxMPDczN8VbtC57W48qyvOVzxOjX/9oiXolg+ipNoKeH/xT9UTK 3wdxoQaK6kFErD+9BKX+tSYEDvhZuhKOcX6oWD/T3EQD3VygY/1n X-Gm-Gg: ASbGncuH/4USe+tdynBflcpzYR561peImBkH0DI6kf8/StQOQ43E4Ad7FOhsQrPF6RP CM69OLtYew1vOMOcrpaDQDahOxmZUQAPAMZ7vNok4fPfpLHIZpXd+V9eA+P7OnvY9wtDtGns9TE x07kGlcgKrCTA9+an72Nbnew4/baxyZYCnp2zPZ8AE9Q96G11CANfaxa8EtEcUKRQ7WCI3a6Mp1 qqf+ZwICV8gkhmoQ1ibpTa6gpigvmgFgZSbLiUT40suLVq42q9B1JQ= X-Google-Smtp-Source: AGHT+IEjaHTlclq4cx9BswYMhsFYxLdVHvW/CWjp1bapnCPgjdP/ve961YKDeDbM1cOXviGqD+XYXg== X-Received: by 2002:a05:6512:224b:b0:53e:1ead:e33a with SMTP id 2adb3069b0e04-53e1eade521mr2019617e87.49.1733397793929; Thu, 05 Dec 2024 03:23:13 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Alistair Francis Subject: [PATCH v12 4/7] target/riscv: Add pointer masking tb flags Date: Thu, 5 Dec 2024 14:23:01 +0300 Message-Id: <20241205112304.593204-5-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::12d; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x12d.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397901851116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei --- target/riscv/cpu.h | 3 +++ target/riscv/cpu_helper.c | 3 +++ target/riscv/translate.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 74d7076f5a..11e3a6d647 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -631,6 +631,9 @@ FIELD(TB_FLAGS, FCFI_ENABLED, 26, 1) FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 27, 1) /* zicfiss needs a TB flag so that correct TB is located based on tb flags= */ FIELD(TB_FLAGS, BCFI_ENABLED, 28, 1) +/* If pointer masking should be applied and address sign extended */ +FIELD(TB_FLAGS, PM_PMM, 29, 2) +FIELD(TB_FLAGS, PM_SIGNEXTEND, 31, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 2558f869f2..ea342fde18 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -126,6 +126,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, RISCVCPU *cpu =3D env_archcpu(env); RISCVExtStatus fs, vs; uint32_t flags =3D 0; + bool pm_signext =3D riscv_cpu_virt_mem_enabled(env); =20 *pc =3D env->xl =3D=3D MXL_RV32 ? env->pc & UINT32_MAX : env->pc; *cs_base =3D 0; @@ -210,6 +211,8 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, flags =3D FIELD_DP32(flags, TB_FLAGS, VS, vs); flags =3D FIELD_DP32(flags, TB_FLAGS, XL, env->xl); flags =3D FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env)); + flags =3D FIELD_DP32(flags, TB_FLAGS, PM_PMM, riscv_pm_get_pmm(env)); + flags =3D FIELD_DP32(flags, TB_FLAGS, PM_SIGNEXTEND, pm_signext); =20 *pflags =3D flags; } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 018be5504f..bb92f36ba1 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -102,6 +102,9 @@ typedef struct DisasContext { bool vl_eq_vlmax; CPUState *cs; TCGv zero; + /* actual address width */ + uint8_t addr_xl; + bool addr_signed; /* Ztso */ bool ztso; /* Use icount trigger for native debug */ @@ -1230,6 +1233,8 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->xl =3D FIELD_EX32(tb_flags, TB_FLAGS, XL); ctx->address_xl =3D FIELD_EX32(tb_flags, TB_FLAGS, AXL); ctx->cs =3D cs; + ctx->addr_xl =3D 0; + ctx->addr_signed =3D false; ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->bcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); --=20 2.39.5 From nobody Fri Dec 27 14:40:11 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397926; cv=none; d=zohomail.com; s=zohoarc; b=YyPK6/XPla3kNCqC7945Vlyr/vIO0dHit5fpBL+BYpSXZXZeqjEmkiVZ43uDcMaAPzrhaQjNHeIEgOsTFTqD/Ahv46OQPlmv+TVudKeM6dVI+gh/7yiUzFn7VOT+vK1ITzU+zcU0u1hRt9zb5hSbXDDrO+1eRXzBVYbx9FFM4DE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397926; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=9qAcbYEnRS7o9rC9jvNDK3zjAtJ9uEReZ4ErtbZMdWc=; b=bJW8qhsFa92+KUopDPmg2mUNLketibl/ICXZKck5y8DHkPi+D7Cr52ea1Tm1t8ywLhLEGdR8kuBdrgG9bCMq0Q2UftyfPZDVAhwEaP93F+9KhIUooCktxMtkN/WSyAzb3LoJh9wHSqQkNyAeXmSyfTS5WBiMaoymKIxiQ/nf1V4= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397926572959.1273453932433; Thu, 5 Dec 2024 03:25:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x4-0008J6-AS; Thu, 05 Dec 2024 06:23:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9x1-0008Hi-PT; Thu, 05 Dec 2024 06:23:19 -0500 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9x0-0005JU-1a; Thu, 05 Dec 2024 06:23:19 -0500 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-3001e7d41c5so6374921fa.2; Thu, 05 Dec 2024 03:23:17 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397796; x=1734002596; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9qAcbYEnRS7o9rC9jvNDK3zjAtJ9uEReZ4ErtbZMdWc=; b=I0a5VoFOaMYxmmz6MuoU4JS6tAvDWu2PFZugbda4JXhQeC3mka0itwNg1EIpeSV39m wL+2mVGrXIFuyq90VoTEYavpPc63Fqd3VWJL/+9T2ekmoJWJTWeCptRP+gCm9rxI4a/A ZnDWoTXXRVkDysoRzsxQt23NeSrbsCaLGyzrmuQqC5araRT/v3me/ASCsiVPEshxhbFA C/sLYu13nL4Cwr8HLlB9WvM4YaQTC6h5xDQhztBGtBAk5VUpgYyNjtb2k08A01hnz7SM SNpSAD9nkdWzfNg6gRG6YyQiZhq96Lj4M7X4m/39zH4xKQ1Uv3UC2I+Qbd6OI7bF1D7Z cXHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397796; x=1734002596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9qAcbYEnRS7o9rC9jvNDK3zjAtJ9uEReZ4ErtbZMdWc=; b=nvaFWH+kzskoESDWlt2xxb9z1aRfTp9SZySDgGMBGFiOA+axFCFXjrMyLc1eR1TjsY gG/9uAHLjd6rrRFzd8R4s/yNdjKKqIGjKp4keGaKO4WuOCfVTNCvarMGFVZENe5vzO/B 7iRPEb+GdVDMLnuiG0UBmx/Koaw9CoYDFntlc3eQ4mY73Ml9hJQXIlscuYXKvjOd7/e6 YVEn9rjAISeZk6z486etG0wPCGX8W5diBTn5bB7Mo8ATFvMj1n49yxNGnzyjPsLd50B2 p8NevJP5vJD7tem9ue3HOwerqwLHRXu7lBaaLXKlwSSq4Bw4IqvyiejHMCxJ64WnblzD Ei8g== X-Forwarded-Encrypted: i=1; AJvYcCVAdVu4WSTSj9h8h3C27ZNoBLMV3FvLBeZtWdpem5GiNDo+9cYtWY5BUtwwh0S3nH2XUmnegVqJew1RMg==@nongnu.org, AJvYcCXZwZd6ILpxGiub+8k48zhAr0nk115fdudjpXT/n6G/yUtwCwwWkXHJSCqvKInDKrx9jbNyu1MI9m1j@nongnu.org X-Gm-Message-State: AOJu0YynNIHOn/5XE4tiq2Lo9q91cw1O1KLHZDpmKYH133chLDdNCful 64wdYWSSIL9lGcY0QNkWzs6SNY+2rU/ocwuoWuYRKbRwGAZ/YXT+ X-Gm-Gg: ASbGncueybfPagdlbYxns0Ws6ULb95tu5hR9Nasrkas4YhqyEUZwG6mHD/RpRStP6n5 FgFWWFNSCMw4H+AT5Gjxgne3FvGFJ6ofdW0gO7xUov4ZeWKHNbXePhGf0YVUe9fsg5o6hW/YLPn dfuUvlct4FwrF2+Y9zexJFbV/1gJoLqciLHIddKX5m4Mk4eGt7430Xi7wD2gX9zuzsBSBjzvnwo uOx8WnEyHRu4qtXsV2jdtpFfdWFSwHOqcVIE45r+r5MjtI/1agXAEk= X-Google-Smtp-Source: AGHT+IGMz1O8/H3fYlkqNWcQw1+xLHH4qFMw5z+olc/Mb+yaDkpzoE6ehin8wzWntZKaRfku7sVGJw== X-Received: by 2002:a05:6512:3b12:b0:53d:f095:ffee with SMTP id 2adb3069b0e04-53e129f2a18mr5848034e87.17.1733397795601; Thu, 05 Dec 2024 03:23:15 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Alistair Francis Subject: [PATCH v12 5/7] target/riscv: Update address modify functions to take into account pointer masking Date: Thu, 5 Dec 2024 14:23:02 +0300 Message-Id: <20241205112304.593204-6-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::232; envelope-from=baturo.alexey@gmail.com; helo=mail-lj1-x232.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397928107116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/translate.c | 22 ++++++++++++++++------ target/riscv/vector_helper.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index bb92f36ba1..32df295123 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -588,8 +588,10 @@ static TCGv get_address(DisasContext *ctx, int rs1, in= t imm) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_addi_tl(addr, src1, imm); - if (get_address_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); } =20 return addr; @@ -602,8 +604,10 @@ static TCGv get_address_indexed(DisasContext *ctx, int= rs1, TCGv offs) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_add_tl(addr, src1, offs); - if (get_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); } =20 return addr; @@ -1233,8 +1237,14 @@ static void riscv_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->xl =3D FIELD_EX32(tb_flags, TB_FLAGS, XL); ctx->address_xl =3D FIELD_EX32(tb_flags, TB_FLAGS, AXL); ctx->cs =3D cs; - ctx->addr_xl =3D 0; - ctx->addr_signed =3D false; + if (get_xl(ctx) =3D=3D MXL_RV32) { + ctx->addr_xl =3D 32; + ctx->addr_signed =3D false; + } else { + int pm_pmm =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_PMM); + ctx->addr_xl =3D 64 - riscv_pm_get_pmlen(pm_pmm); + ctx->addr_signed =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND); + } ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->bcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 3589e3ef28..37c6c198a5 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -107,6 +107,22 @@ static inline uint32_t vext_max_elems(uint32_t desc, u= int32_t log2_esz) =20 static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) { + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + return addr; + } + RISCVPmPmm pmm =3D riscv_pm_get_pmm(env); + if (pmm =3D=3D PMM_FIELD_DISABLED) { + return addr; + } + int pmlen =3D riscv_pm_get_pmlen(pmm); + bool signext =3D riscv_cpu_virt_mem_enabled(env); + addr =3D addr << pmlen; + /* sign/zero extend masked address by N-1 bit */ + if (signext) { + addr =3D (target_long)addr >> pmlen; + } else { + addr =3D addr >> pmlen; + } return addr; } =20 --=20 2.39.5 From nobody Fri Dec 27 14:40:11 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397848; cv=none; d=zohomail.com; s=zohoarc; b=E/sy7KsfJUDioG73QHinjwTQeIWrVQosSr2kUabVS+yqJPd94Q/MOKSDoZfNeZC6zSiLgtoahqADBRIbpQbqckGlL+BgvZAyDoh3VO+JmHUeFGO9KokcnQwnpISEhnV8qSk4qf/vk8tN9Nwcd4UqgOB8MNuL3Dccluu7oLAwFnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397848; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=94fSHaUGyassQGMKDG6ZXhg6oLNmXhLz5E8Njs+vBcE=; b=EBFOvMfjB8ra28oF9+7UF1jGtRINy2gg+9pQ5yTkvxOlsGFfjFukHaxTDBE0gwGsbQaAPpJ68IIBm+J8QDyd0PSBeprAKNOgY5YVLqdZFGbvl00U8NSamGXPPruRplUXNrklk0WR78/siEu9KPPkOrpyZjwhJxkJBzgnNVpY3DM= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397848113363.86384018006504; Thu, 5 Dec 2024 03:24:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x6-0008KB-RF; Thu, 05 Dec 2024 06:23:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9x3-0008Is-NF; Thu, 05 Dec 2024 06:23:21 -0500 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9x1-0005Jm-No; Thu, 05 Dec 2024 06:23:21 -0500 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-53de6b7da14so871575e87.0; Thu, 05 Dec 2024 03:23:18 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397797; x=1734002597; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=94fSHaUGyassQGMKDG6ZXhg6oLNmXhLz5E8Njs+vBcE=; b=g9Kz5LKMLxAkeLRtbryVl5/KscjrUWge+Vhkay+mHboKXwfGrUZ+cldVzJMrKbFsYG AzsKHKSHkN/lWprkhXLDxiCucTphQt64baZh61kInYDXDFJ1pPFRUBfpSJnWeBnGApTm exF9yN4unsHn5nvK83nGd4zGJT+k7ZbVPMGS+fJ1vvi1SMFVkAFQOvOIRoSD1KgdkqjC iUcQaBLEXUWNlfnDIvKQ6T2Mcv9d0EmW4TRfsEv6+ODFqsccpKM6f1I5GhjOASCd4uN5 QO0v4KWBHWSSy+pKERzwMfBs7lppuuDwIeOeaexYoYwNeIPwcgnrJlnSTag2aehxEUkH 7Hxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397797; x=1734002597; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=94fSHaUGyassQGMKDG6ZXhg6oLNmXhLz5E8Njs+vBcE=; b=vhU2NVa+zRIYxlE//EAdcnPoqyl5Kbi/OIagJUehQ50FzlwLTuhDxrRzIWLNyPCTfa UArF33YFSKv08m491R309l+CX4A9BtBdYcGNewllvNPfK/BUhUmWNDdvmzvcYwl/3uWc kJiJ31122Q7N+fEUFYUoRGoJ5G46koohYFgDZRG2anlW8Eyd2xOmbPOzJvaCwghID08h SzpGU52NzQVpXeRSOv/stbmyLT3IO2SMkRagleLKHKenIRu7isUoNvI87JMHhL6J7kX5 lumPyE6r2G3VWX5jwI4jYlz+lygjH1XaDIf4QJ8s91szbGb0dgY+AmH+rppYnT7OSX9I Zdpg== X-Forwarded-Encrypted: i=1; AJvYcCXSpeBfLS46LoOPnHkwRcEUOi7eVyGjFMI0x+uI+f1ggvZT484eNSl+daKF1dd/F5gWwgr6nXV/NMCA0A==@nongnu.org, AJvYcCXecydBIFpTlej+5JhZyuqsoV/JjAfcuk7sp3c0mpp8O7q9oTvBPrNiv2L4Ru8RTOaZLmO8beQENLel@nongnu.org X-Gm-Message-State: AOJu0Yx3YmX2J2uJ0rDEvnAoDNgzhIDK8iw//nC5u2DJBcRY4302mmyb ZnC2wd+iQStdX6i0cy0NmVpCZRV78+m5o6PVlcRBSdIMz+D4Nav4 X-Gm-Gg: ASbGncuOw/a34ELT8Inily+OxgrM89kvG+LRrcTO1VS9LaFxp1cWBhzmdNEiZLn/cCY uwQSNUKBdow5wfqqkuRnKIrKbwstw6ZRVYv16yZHWVl1W51eVTVWsVPosB4U6DihWOFPPK7D7Xm 2C3J43upND6BZePwKfRcEMw5vz+z1Ydc0DVDm1hN5z/lo6g6lktqHiAHYk0rfSD4OOAVQ3YR6q7 QaK8G53xHVmfcCP40kwRmIwwiSIA0QGVC1+W79IVhuTc8m+89RHVrs= X-Google-Smtp-Source: AGHT+IFlkCtOP1eBR6uBShfYzMu8xxUy3jSotuELXuD8kqX8eJKwGSjA615zcG7mDFcVd3ab9z1xaQ== X-Received: by 2002:a05:6512:2821:b0:53e:1b6a:60f2 with SMTP id 2adb3069b0e04-53e1b88ff93mr2939621e87.24.1733397797169; Thu, 05 Dec 2024 03:23:17 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v12 6/7] target/riscv: Apply pointer masking for virtualized memory accesses Date: Thu, 5 Dec 2024 14:23:03 +0300 Message-Id: <20241205112304.593204-7-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::12a; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x12a.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397849840116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 18 +++++++++++++++ target/riscv/internals.h | 44 ++++++++++++++++++++++++++++++++++++ target/riscv/op_helper.c | 16 ++++++------- target/riscv/vector_helper.c | 21 ----------------- 5 files changed, 71 insertions(+), 29 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 11e3a6d647..2d27c804d5 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -773,6 +773,7 @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu); =20 bool riscv_cpu_virt_mem_enabled(CPURISCVState *env); RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env); int riscv_pm_get_pmlen(RISCVPmPmm pmm); =20 RISCVException riscv_csrr(CPURISCVState *env, int csrno, diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index ea342fde18..1f2cca82e8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -260,6 +260,24 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env) return pmm; } =20 +RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env) +{ + RISCVPmPmm pmm =3D PMM_FIELD_DISABLED; +#ifndef CONFIG_USER_ONLY + int priv_mode =3D cpu_address_mode(env); + if (priv_mode =3D=3D PRV_U) { + pmm =3D get_field(env->hstatus, HSTATUS_HUPMM); + } else { + if (get_field(env->hstatus, HSTATUS_SPVP)) { + pmm =3D get_field(env->henvcfg, HENVCFG_PMM); + } else { + pmm =3D get_field(env->senvcfg, SENVCFG_PMM); + } + } +#endif + return pmm; +} + bool riscv_cpu_virt_mem_enabled(CPURISCVState *env) { bool virt_mem_en =3D false; diff --git a/target/riscv/internals.h b/target/riscv/internals.h index ddbdee885b..bc0f892f8a 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -142,4 +142,48 @@ static inline float16 check_nanbox_h(CPURISCVState *en= v, uint64_t f) /* Our implementation of CPUClass::has_work */ bool riscv_cpu_has_work(CPUState *cs); =20 +/* Zjpm addr masking routine */ +static inline target_ulong adjust_addr_body(CPURISCVState *env, + target_ulong addr, + bool is_virt) +{ + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + return addr; + } + RISCVPmPmm pmm =3D PMM_FIELD_DISABLED; + if (is_virt) { + pmm =3D riscv_pm_get_virt_pmm(env); + } else { + pmm =3D riscv_pm_get_pmm(env); + } + if (pmm =3D=3D PMM_FIELD_DISABLED) { + return addr; + } + int pmlen =3D riscv_pm_get_pmlen(pmm); + bool signext =3D false; + if (!is_virt) { + signext =3D riscv_cpu_virt_mem_enabled(env); + } + addr =3D addr << pmlen; + /* sign/zero extend masked address by N-1 bit */ + if (signext) { + addr =3D (target_long)addr >> pmlen; + } else { + addr =3D addr >> pmlen; + } + return addr; +} + +static inline target_ulong adjust_addr(CPURISCVState *env, + target_ulong addr) +{ + return adjust_addr_body(env, addr, false); +} + +static inline target_ulong adjust_addr_virt(CPURISCVState *env, + target_ulong addr) +{ + return adjust_addr_body(env, addr, true); +} + #endif diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index eddedacf4b..20e5bd5088 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -472,7 +472,7 @@ target_ulong helper_hyp_hlv_bu(CPURISCVState *env, targ= et_ulong addr) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_UB, mmu_idx); =20 - return cpu_ldb_mmu(env, addr, oi, ra); + return cpu_ldb_mmu(env, adjust_addr_virt(env, addr), oi, ra); } =20 target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr) @@ -481,7 +481,7 @@ target_ulong helper_hyp_hlv_hu(CPURISCVState *env, targ= et_ulong addr) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUW, mmu_idx); =20 - return cpu_ldw_mmu(env, addr, oi, ra); + return cpu_ldw_mmu(env, adjust_addr_virt(env, addr), oi, ra); } =20 target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr) @@ -490,7 +490,7 @@ target_ulong helper_hyp_hlv_wu(CPURISCVState *env, targ= et_ulong addr) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUL, mmu_idx); =20 - return cpu_ldl_mmu(env, addr, oi, ra); + return cpu_ldl_mmu(env, adjust_addr_virt(env, addr), oi, ra); } =20 target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr) @@ -499,7 +499,7 @@ target_ulong helper_hyp_hlv_d(CPURISCVState *env, targe= t_ulong addr) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUQ, mmu_idx); =20 - return cpu_ldq_mmu(env, addr, oi, ra); + return cpu_ldq_mmu(env, adjust_addr_virt(env, addr), oi, ra); } =20 void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong = val) @@ -508,7 +508,7 @@ void helper_hyp_hsv_b(CPURISCVState *env, target_ulong = addr, target_ulong val) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_UB, mmu_idx); =20 - cpu_stb_mmu(env, addr, val, oi, ra); + cpu_stb_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); } =20 void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong = val) @@ -517,7 +517,7 @@ void helper_hyp_hsv_h(CPURISCVState *env, target_ulong = addr, target_ulong val) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUW, mmu_idx); =20 - cpu_stw_mmu(env, addr, val, oi, ra); + cpu_stw_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); } =20 void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong = val) @@ -526,7 +526,7 @@ void helper_hyp_hsv_w(CPURISCVState *env, target_ulong = addr, target_ulong val) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUL, mmu_idx); =20 - cpu_stl_mmu(env, addr, val, oi, ra); + cpu_stl_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); } =20 void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong = val) @@ -535,7 +535,7 @@ void helper_hyp_hsv_d(CPURISCVState *env, target_ulong = addr, target_ulong val) int mmu_idx =3D check_access_hlsv(env, false, ra); MemOpIdx oi =3D make_memop_idx(MO_TEUQ, mmu_idx); =20 - cpu_stq_mmu(env, addr, val, oi, ra); + cpu_stq_mmu(env, adjust_addr_virt(env, addr), val, oi, ra); } =20 /* diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 37c6c198a5..a0093bcc9c 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -105,27 +105,6 @@ static inline uint32_t vext_max_elems(uint32_t desc, u= int32_t log2_esz) return scale < 0 ? vlenb >> -scale : vlenb << scale; } =20 -static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) -{ - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - return addr; - } - RISCVPmPmm pmm =3D riscv_pm_get_pmm(env); - if (pmm =3D=3D PMM_FIELD_DISABLED) { - return addr; - } - int pmlen =3D riscv_pm_get_pmlen(pmm); - bool signext =3D riscv_cpu_virt_mem_enabled(env); - addr =3D addr << pmlen; - /* sign/zero extend masked address by N-1 bit */ - if (signext) { - addr =3D (target_long)addr >> pmlen; - } else { - addr =3D addr >> pmlen; - } - return addr; -} - /* * This function checks watchpoint before real load operation. * --=20 2.39.5 From nobody Fri Dec 27 14:40:12 2024 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733397941; cv=none; d=zohomail.com; s=zohoarc; b=UJiCLPCrXkJ6hqUs3AH2RGcUwQuEfGA/CzDzQpVMCCLleSj2bL0ZtQ2UHwU0TO+hroxELRTsu1nQp29EKgfyOaSbd6j5w+oTD4aadjOoHnuPyQggktBRx4UDUWxwvHcj+M9DnwtxNvfanp5L6uSifotg1Bc5OuFVptJyZJkYk7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733397941; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=5y1XlOG6HQ68XRyS1PvaWBt+8Ja5xTcf4QFaElkAjVs=; b=NKbS45TD6epO7WqOtzr6TW+1Qh3uZvi6viP53fYSUa9ERNC6htT+Ym5yRvjM6Qfwz9+ZydOmCA8TGrDBexfBBclZ0FzwfjZswBri0BAcS9V35WFv5dAAot/sQ/nL4VgpohRNIIYBe7cKBN7pw9myVqxQRx/qgQvCjVBj8zrVd/E= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1733397941375721.8329446960519; Thu, 5 Dec 2024 03:25:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9x5-0008JR-2E; Thu, 05 Dec 2024 06:23:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9x4-0008J7-Ag; Thu, 05 Dec 2024 06:23:22 -0500 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9x2-0005K1-R2; Thu, 05 Dec 2024 06:23:22 -0500 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-53de8ecafeeso953444e87.1; Thu, 05 Dec 2024 03:23:20 -0800 (PST) Received: from vmdev.asgard ([81.200.11.243]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53e229744efsm209942e87.102.2024.12.05.03.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:23:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733397799; x=1734002599; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5y1XlOG6HQ68XRyS1PvaWBt+8Ja5xTcf4QFaElkAjVs=; b=EyIOAUzAsTyAuKh7A3WLTIwMJ0YmJZj5XMF6dkXxopzIPz7ar46gJ7YHYeHmbVO4KA uB8y2l9CHzNGusITgmDc0IzDWI6M7JFHnnjkWPe+we0EDBmi+m6di5YcVYD4n95k/N4W BqHpjHQK4oYtHpbK9tuSlsQuLaRqz0/iKX2xUG/ayUnySiLfZnNvsYWqUJiK06JWuWXi QtRKw3cK6lgfCqoGwwjj1Z9a7WUoYB6zgYpK2PhxH/CA1ZWzILcaRC1gWvz4cDPXRYWS p8GuUNp28OtSu7MQita6z5PTaCb4xLnbAk6wJxQIfIZqC9WqaK8GckuaM9uCqHvex951 mSAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397799; x=1734002599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5y1XlOG6HQ68XRyS1PvaWBt+8Ja5xTcf4QFaElkAjVs=; b=GMLB+uyjav4VnCJ79v6LdjZMs2dWGSDwbuUJLYRO3cIRVpP1t7EU/mplB9J2QyAcKk gAilHi5H7RP5mb40vhUbMCpM9bB4ok6W3HNJFPON8pWOEUtSS3A2uLz+X3NZJd5TcFBW jd1Rdd+7hDYVSVIdDBUI3sif91lkB8MWSL+gllyaFRG84fDlKgaZ3Ex5bTA0HNNCM2v1 2x334O36RLRe1Nrh/SBnY10QtjwA6Eg5MviuUajskBkqwp/zwVaVJiUcQn9heF19kVu0 CWAjtJC5+OzKK2ZVe9blln2S3hwIBUt8j2whvkGYR3bVdwCB9UifZ5T/N7PMS6dhzEz7 jr7Q== X-Forwarded-Encrypted: i=1; AJvYcCVgeTwzcm2txIuqVS4dB2RvO5qq1CYyZ8r7LR6Ct6UzQy2h2rI3HEhiReeSbAXr4Chsx3WiBKVc5gDr@nongnu.org, AJvYcCX6hO6GPp7VrgjRe+DADOEt14gGtvq8qiNuLrv+OYx8Tcwq9KcAU5Bl1VT+jKRpRgWy17ToHLvOv5HPBw==@nongnu.org X-Gm-Message-State: AOJu0YyoBjfg1TGSIECxSW6DzervroKOLCOD6mVfGDeyIn/ze85qCIpj 9yLIiTJZHR/x4TwCmfxFfjXpS94zMq3qWlHnF18p8UuDW1ObX6Wa X-Gm-Gg: ASbGncs+p8lAYbqzmafFHaWfEfRdr07IP/Jwcnj6gbmHHWNANCmMeizQscAyu44wnKH YEfS0uxq+xzAAFhtHXEnfjTKgridAeGZibjx9eHHoOonhTWzYlm7+mz7wywCGWtzD9Ro28XFa+7 NZog9CkzFwIaE/SfkO/RZxck2BiDAGzZwrL0UZOxBHRiUguTQa4RQBX+PyJCrVmcEHFo37dg21Y KdkTHNm6xG0K+xWrAuNrZlHasVzVmLjfqiT8Zlq4AbTACQ0W46QRQk= X-Google-Smtp-Source: AGHT+IGVsvI0Du9IUYVt/G9wToPsDtm7XaPMN8TaYvC6Ro0UJXiZ8jEAd+Og0bacC8K5bjQjMdnCAw== X-Received: by 2002:a05:6512:3b9e:b0:53d:a24b:db0f with SMTP id 2adb3069b0e04-53e12a392ebmr4332734e87.57.1733397798684; Thu, 05 Dec 2024 03:23:18 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Alistair Francis Subject: [PATCH v12 7/7] target/riscv: Enable updates for pointer masking variables and thus enable pointer masking extension Date: Thu, 5 Dec 2024 14:23:04 +0300 Message-Id: <20241205112304.593204-8-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241205112304.593204-1-baturo.alexey@gmail.com> References: <20241205112304.593204-1-baturo.alexey@gmail.com> 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=2a00:1450:4864:20::12a; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x12a.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733397942001116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4e80dcd2e6..fd3ea9ce76 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -186,11 +186,14 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), + ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm), + ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm), ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), + ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), @@ -1490,9 +1493,12 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false), MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), + MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false), =20 MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false), MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false), + MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false), + MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false), MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), MULTI_EXT_CFG_BOOL("ssaia", ext_ssaia, false), MULTI_EXT_CFG_BOOL("svade", ext_svade, false), --=20 2.39.5