From nobody Tue Nov 26 22:13:17 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=1703155277; cv=none; d=zohomail.com; s=zohoarc; b=aqbVYW//ZRdlKHpkwiybNOzpCwYVys3Trt+BD+HlXQoaLKbTYyQLfzg/Q02A1fHLln0CeKbpg5u3ns7Rz2wDIDpjP8gI6VDplDZhPUA31wNwb02VEFfrOu51oV4DjE4fOc1/r151qxvm+31HeOGb9uebIMypbLNG7lCVijaGx2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703155277; 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=FwU2j/Fkn6+iNb2KVnrbflh02JWle+UT8rc6ujs9EYI=; b=f4EULUaWDqhVPbf0LMfR98CQQq4JQlmL5YRKnMErKq7iiBg7Bno4/BF480mv2ywQoXy62i7Thp5tVPedl8iqK9DGApKYDeTbgM5vhEP6XRipuqYpbQQtYKnEJDn/2YA4dbSTksp3x03TiWEijUBnjKcU5hFFNo5kplW5Wifvzmo= 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 1703155277516576.1000928738579; Thu, 21 Dec 2023 02:41:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUJ-0001Dd-Gg; Thu, 21 Dec 2023 05:41:11 -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 1rGGUG-0000ko-0k; Thu, 21 Dec 2023 05:41:08 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGU5-0004xq-Pr; Thu, 21 Dec 2023 05:41:07 -0500 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33687627ad0so433900f8f.2; Thu, 21 Dec 2023 02:40:56 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155255; x=1703760055; 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=FwU2j/Fkn6+iNb2KVnrbflh02JWle+UT8rc6ujs9EYI=; b=G5JvWM3TLoObTK5rGpANB/QJXBunXEtpQjF4p/o3nn+SsmY2e15XLRWM+kehCa4DI1 89YRc2f1xgoTb2Z3c8NCLZdtGqmr5o82q6QnoPvJYs+MarO5O0RsV7lbizSZ1e+0eI2c Iew4h6p2WapciJlwwgK9WNddrtci7ubhqJRE8BwFafjqVugtztU0s9J+sr4/F2Qlz9O2 thiA+t1N4SLxEBb20qtp4wXXbzVpy2Z9mSsL+Q9SEhlA6y0STZLR9QYlqNKNcNusrcDQ P77nLbKsUCAuC4Fop2BwMbfh0PtFVGAqB2qBLh4kioVi9CJhBtznNCV7wgqxDsZAGEoU pwjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155255; x=1703760055; 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=FwU2j/Fkn6+iNb2KVnrbflh02JWle+UT8rc6ujs9EYI=; b=mR/JisZyFe9ZgKqvny3sLSY+GM4YMkYTK2Od071VycGoaJZjsS8sw23QYmxkGmwmUR JaJ7/TIjVOo5VP2HkGy54AzaCbk7F78SbHevPMflimIvpRDt8VzQEQwE+wRObSTuorIc aUGSmMWFzwYUN/fsDm3/U8A9AMP8kuBsFAOp+vH2WqOHW8uziPQmQnDTW2h59mdoy8z8 rhtdGtfcQp2aebkwMgJID/5uQj5zHWrGj27D7CyaVpeKOQ8L4E7kx/tRlDkrHObIe2go DdwJtaHxecWqo6Ouyaj2GqjR3uYGVRevqoY/bIMblJr5YZqWKsp1f+Ew/40qNKXKxPRW AAwQ== X-Gm-Message-State: AOJu0Yxp1w8mqrgIdcDtYDA/J2AilTfvsukgyT84jnP/vZ9o2RQpW4xS DWYh26O4E4rIqgp2+LSQbjc= X-Google-Smtp-Source: AGHT+IH0R6wT3ipe3cioPniXot5abECDwSnjCu/kutVCass7efZbnAJWJKM1UnnnYGbpQNQtQOp9Xg== X-Received: by 2002:a05:600c:3f85:b0:40d:3bd1:3dca with SMTP id fs5-20020a05600c3f8500b0040d3bd13dcamr556305wmb.157.1703155255335; Thu, 21 Dec 2023 02:40:55 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 1/6] target/riscv: Remove obsolete pointer masking extension code. Date: Thu, 21 Dec 2023 10:40:30 +0000 Message-Id: <20231221104035.1287244-2-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::435; envelope-from=baturo.alexey@gmail.com; helo=mail-wr1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155278590100001 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Zjpm v0.8 is almost frozen and it's much simplier compared to the existing = one: The newer version doesn't allow to specify custom mask or base for masking. Instead it allows only certain options for masking top bits. Signed-off-by: Alexey Baturo --- target/riscv/cpu.c | 10 -- target/riscv/cpu.h | 32 +--- target/riscv/cpu_bits.h | 82 --------- target/riscv/cpu_helper.c | 52 ------ target/riscv/csr.c | 326 ----------------------------------- target/riscv/machine.c | 9 - target/riscv/translate.c | 27 +-- target/riscv/vector_helper.c | 2 +- 8 files changed, 10 insertions(+), 530 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 83c7c0cf07..1e6571ce99 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -710,13 +710,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) { @@ -891,8 +884,6 @@ static void riscv_cpu_reset_hold(Object *obj) } i++; } - /* mmte is supposed to have pm.current hardwired to 1 */ - env->mmte |=3D (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); =20 /* * Clear mseccfg and unlock all the PMP entries upon reset. @@ -906,7 +897,6 @@ static void riscv_cpu_reset_hold(Object *obj) pmp_unlock_entries(env); #endif 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); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d74b361be6..73f7004936 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -374,18 +374,7 @@ 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; - - /* CSRs for execution environment configuration */ + /* CSRs for execution enviornment configuration */ uint64_t menvcfg; uint64_t mstateen[SMSTATEEN_MAX_COUNT]; uint64_t hstateen[SMSTATEEN_MAX_COUNT]; @@ -393,8 +382,6 @@ struct CPUArchState { target_ulong senvcfg; 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 */ @@ -543,17 +530,14 @@ FIELD(TB_FLAGS, VILL, 14, 1) FIELD(TB_FLAGS, VSTART_EQ_ZERO, 15, 1) /* The combination of MXL/SXL/UXL that applies to the current cpu mode. */ 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) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) @@ -680,8 +664,6 @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, ta= rget_ulong vtype) 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); - 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_bits.h b/target/riscv/cpu_bits.h index ebd7917d49..3f9415d68d 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -491,37 +491,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 */ @@ -778,57 +747,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 e7e23b34f4..a3d477d226 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -135,61 +135,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 /* @@ -721,7 +670,6 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulon= g newpriv) /* 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 fde7ce1a53..ea4e1ac6ef 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -483,16 +483,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 int aia_hmode(CPURISCVState *env, int csrno) { if (!riscv_cpu_cfg(env)->ext_ssaia) { @@ -1355,7 +1345,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 @@ -3900,302 +3889,6 @@ static RISCVException read_tinfo(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 */ @@ -4800,25 +4493,6 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_TDATA3] =3D { "tdata3", debug, read_tdata, write_tdata }, [CSR_TINFO] =3D { "tinfo", debug, read_tinfo, write_ignore }, =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 fdde243e04..860fe56d43 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -164,14 +164,6 @@ static const VMStateDescription vmstate_pointermasking= =3D { .minimum_version_id =3D 1, .needed =3D pointermasking_needed, .fields =3D (VMStateField[]) { - VMSTATE_UINTTL(env.mmte, RISCVCPU), - VMSTATE_UINTTL(env.mpmmask, RISCVCPU), - VMSTATE_UINTTL(env.mpmbase, RISCVCPU), - VMSTATE_UINTTL(env.spmmask, RISCVCPU), - VMSTATE_UINTTL(env.spmbase, RISCVCPU), - VMSTATE_UINTTL(env.upmmask, RISCVCPU), - VMSTATE_UINTTL(env.upmbase, RISCVCPU), - VMSTATE_END_OF_LIST() } }; @@ -267,7 +259,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/translate.c b/target/riscv/translate.c index f0be79bb16..6b4b9a671c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -42,9 +42,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, @@ -106,9 +103,6 @@ typedef struct DisasContext { bool vl_eq_vlmax; CPUState *cs; TCGv zero; - /* PointerMasking extension */ - bool pm_mask_enabled; - bool pm_base_enabled; /* Use icount trigger for native debug */ bool itrigger; /* FRM is known to contain a valid value. */ @@ -582,14 +576,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; } @@ -601,14 +590,9 @@ 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 (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 @@ -1192,8 +1176,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->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->zero =3D tcg_constant_tl(0); ctx->virt_inst_excp =3D false; @@ -1325,9 +1307,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 c1c3a4d1ea..8e7a8e80a0 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -94,7 +94,7 @@ static inline uint32_t vext_max_elems(uint32_t desc, uint= 32_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.34.1 From nobody Tue Nov 26 22:13:17 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 1703155496613289.5177053078345; Thu, 21 Dec 2023 02:44:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUL-0001V6-VQ; Thu, 21 Dec 2023 05:41:14 -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 1rGGUH-0000uW-0K; Thu, 21 Dec 2023 05:41:09 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGU7-0004yK-1J; Thu, 21 Dec 2023 05:41:08 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40d12b56a38so6550405e9.2; Thu, 21 Dec 2023 02:40:58 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155257; x=1703760057; 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=7GeOvpjAL4V2JfV6wh8tisZDsYubCnYS1vsZ9qapy/s=; b=VMnQsSjp7YRL1IGFk9edDVyqYL0/xEcL6ZUD7cr5+IgylIFV2VHN9IZeT4Jr6cFs4M DB9YwgP7yZVsvcK/b6Ok6pK2d/RA49HnlBKonWpFcbtF5pFClEU5ukS2HhGDken9cJKA I8jn9eywlmajKisVOq0gBNpD1hQSszWxZUIhoKOh7qbVhD46ivHzzywD4KpsOF4ML2W9 7oAhuBtorz00KVqIlZuozVPe10mCa/berGfo2N7ETAr74ODS9fpT2DmSlm62YbHP3J2U /QBM6QwHtA0w6HPi2NUJZ/H0hDpOCmo1ccwWortRWec05tHZn5bvt8ukhoVqMEGJJVyY DQXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155257; x=1703760057; 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=7GeOvpjAL4V2JfV6wh8tisZDsYubCnYS1vsZ9qapy/s=; b=Jqr03xWITIqq7+Qwa9pgB54rxJuOZBxKb75gSiTG5X1pxLUHC81jjeFTeeOywQuVyq OW0N8uRgg3QAWFcza94VK/ePUN9yrUAxucYM0UbokDLXR1LSRiUGGluhZV6N9okEln0W iLkZBHSEYg/mNzfE4lMTYvWZUPSN006mPbSHjMN2KnYOrBd6V10sRs7ibnRhKl6zofdq Wa16OjZVe2kdqmWi9d+INtVNIDBvft/6wGi7fhD2MZL3x/el7OGLVhx3tjANONGS6duq zBI2xdS+Jq5hy+cFpfnW0UDa+wEqhDr6xFuiYisvJfYJy49Tv903k2/eYpXxMp5d3WLo RaNQ== X-Gm-Message-State: AOJu0YybE59rOcJCFLRWGhJhkuybiMkc/iaq+MppUHlxg7wimDUpbP1h Z+03RIWmC1jgKbJHxm1qcJI= X-Google-Smtp-Source: AGHT+IHLmzfoRDK/x8f3vjPq4vBS5s8nP+v/xgE16W+nH1ERgmMvod/RKPlwPv0AYRzOcDcx4k9zhg== X-Received: by 2002:a05:600c:1c8b:b0:40b:5e22:2d3 with SMTP id k11-20020a05600c1c8b00b0040b5e2202d3mr321025wms.63.1703155256967; Thu, 21 Dec 2023 02:40:56 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 2/6] target/riscv: Add new CSR fields for S{sn, mn, m}pm extensions as part of Zjpm v0.8 Date: Thu, 21 Dec 2023 10:40:31 +0000 Message-Id: <20231221104035.1287244-3-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::330; envelope-from=baturo.alexey@gmail.com; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155497567100003 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 8 ++++++++ target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu_cfg.h | 3 +++ target/riscv/csr.c | 11 +++++++++++ target/riscv/machine.c | 6 ++++-- target/riscv/pmp.c | 13 ++++++++++--- target/riscv/pmp.h | 11 ++++++----- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 73f7004936..f49d4aa52c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -102,6 +102,14 @@ typedef enum { EXT_STATUS_DIRTY, } RISCVExtStatus; =20 +/* Enum holds PMM field values for Zjpm v0.8 extension */ +enum { + PMM_FIELD_DISABLED =3D 0, + PMM_FIELD_RESERVED =3D 1, + PMM_FIELD_PMLEN7 =3D 2, + PMM_FIELD_PMLEN16 =3D 3, +}; + #define MMU_USER_IDX 3 =20 #define MAX_RISCV_PMPS (16) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 3f9415d68d..fcbbdc21c5 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -720,6 +720,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) @@ -733,11 +734,13 @@ 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_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 f4605fb190..201f8af6ae 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -113,6 +113,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; =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ea4e1ac6ef..a67ba30494 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -527,6 +527,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; } @@ -2030,6 +2033,10 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, (cfg->ext_sstc ? MENVCFG_STCE : 0) | (cfg->ext_svadu ? MENVCFG_ADUE : 0); } + /* Update PMM field only if the value is valid according to Zjpm v0.8 = */ + if (((val & MENVCFG_PMM) >> 32) !=3D PMM_FIELD_RESERVED) { + mask |=3D MENVCFG_PMM; + } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 return RISCV_EXCP_NONE; @@ -2074,6 +2081,10 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, target_ulong val) { uint64_t mask =3D SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCF= G_CBZE; + /* Update PMM field only if the value is valid according to Zjpm v0.8 = */ + if (((val & SENVCFG_PMM) >> 32) !=3D PMM_FIELD_RESERVED) { + mask |=3D SENVCFG_PMM; + } RISCVException ret; =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 860fe56d43..5e9c5b43ab 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -153,9 +153,8 @@ static const VMStateDescription vmstate_vector =3D { static bool pointermasking_needed(void *opaque) { RISCVCPU *cpu =3D opaque; - CPURISCVState *env =3D &cpu->env; =20 - return riscv_has_ext(env, RVJ); + return cpu->cfg.ext_ssnpm || cpu->cfg.ext_smnpm || cpu->cfg.ext_smmpm; } =20 static const VMStateDescription vmstate_pointermasking =3D { @@ -164,6 +163,9 @@ static const VMStateDescription vmstate_pointermasking = =3D { .minimum_version_id =3D 1, .needed =3D pointermasking_needed, .fields =3D (VMStateField[]) { + VMSTATE_UINTTL(env.mseccfg, RISCVCPU), + VMSTATE_UINTTL(env.senvcfg, RISCVCPU), + VMSTATE_UINTTL(env.menvcfg, RISCVCPU), VMSTATE_END_OF_LIST() } }; diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 162e88a90a..893ccd58d8 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -576,6 +576,12 @@ 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 v0.8 = */ + if (((val & MSECCFG_PMM) >> 32) !=3D PMM_FIELD_RESERVED) { + mask |=3D MSECCFG_PMM; + } =20 trace_mseccfg_csr_write(env->mhartid, val); =20 @@ -591,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 env->mseccfg =3D val; diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index 9af8614cd4..b3ca51c26d 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -40,11 +40,12 @@ typedef enum { } pmp_am_t; =20 typedef enum { - MSECCFG_MML =3D 1 << 0, - MSECCFG_MMWP =3D 1 << 1, - MSECCFG_RLB =3D 1 << 2, - MSECCFG_USEED =3D 1 << 8, - MSECCFG_SSEED =3D 1 << 9 + MSECCFG_MML =3D 1 << 0, + MSECCFG_MMWP =3D 1 << 1, + MSECCFG_RLB =3D 1 << 2, + MSECCFG_USEED =3D 1 << 8, + MSECCFG_SSEED =3D 1 << 9, + MSECCFG_PMM =3D 3UL << 32, } mseccfg_field_t; =20 typedef struct { --=20 2.34.1 From nobody Tue Nov 26 22:13:17 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=1703155501; cv=none; d=zohomail.com; s=zohoarc; b=kWZJASTO1Vxx1PZv6zw/sgOPK1xqCGc3hgFTanPj3w/RWsaT0W08HXhhSiKgAUDw/rczdSQVzound/Zc/rHHv8bpvVNbH4cL2850US2fa8yXWSHvBVER5n/gyxonbU64cI9Vu+j+VLKyIYbGhoV12JH71Ag0qQ73M9aAYkp5608= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703155501; 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=jRDEQh1JkAlYBSiLzwHd6WKlB2tHlxIi9rObWqcFdBQ=; b=b/YNqVm8zpX25pLgGNX/Yz82HrlI6XGhjDNIQHLZVmw1xGV8o72UuGS9GX/VQeGKY7PCjpDyH1tO7ntIQXauqBZf48TIQzw+jTE+IKXdOUmut2uKAXoDGMM/UYKudSVDxtqn2PzEOH8Znkjg+hq/1zUYcn9NvQACt8J8KI45ALU= 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 1703155501749257.6341850772061; Thu, 21 Dec 2023 02:45:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUO-0001mH-Ip; Thu, 21 Dec 2023 05:41: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 1rGGUH-0000yB-JR; Thu, 21 Dec 2023 05:41:09 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGUA-0004yZ-5E; Thu, 21 Dec 2023 05:41:09 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3368d1c7b23so42317f8f.0; Thu, 21 Dec 2023 02:41:00 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155259; x=1703760059; 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=jRDEQh1JkAlYBSiLzwHd6WKlB2tHlxIi9rObWqcFdBQ=; b=T3tzKDEn9w8jbNTP7GSYqUy4Q3WD1qdSM+5/C4+Vpj+zGGopDfL6bY6x01O3Uqskxz CJXd/fuKfe9e5jIapKYPPGD0D7Cj6KYx3J69K3gtotf1rVKMLNe0L2UmstZ6xqQs4kmM Dcll4UCip9KFMk9TOJY1s0luOXeoNbAGvlzsTY3KWg+BDpu06OHP+Io+uAwlvH27iY8R K6zV1TkWPpc3xpezyBid4mygcq/jHhK/hUDXV+JTMVPwN1LB1JvcGnKrx/6oTBdBEyMi qWS6RM6UZS6ne0DBUjB9Lux+lXGbOWoFVTcPSms8StXVt5R0zpHfSg7l1mkfVs+e6rWL ajVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155259; x=1703760059; 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=jRDEQh1JkAlYBSiLzwHd6WKlB2tHlxIi9rObWqcFdBQ=; b=EpdRPxaHo+K0mI+f4b9tfkaEyDoDsy01oi90Lm4Ip8VXwlMtIMjFFpUM5oBs0Oy1VF ojzejkDSAAkyGQXUXJoGIcKaNR6g7X7khU3lVG24SfXkn6MLtNkpjnfm1uP7ePd8+KVC kBs/vk+hFX18dSmbpIlzgNAI4TrtZeARQpVQd9lTQdoWsnVNmOr0CIycIGjtgKSO2WSY HPSAkd4HuoVOCjT7ya6KGzAWqALwR83827YoTOtHh5jioOq7VfafNn2a7oi9fO2KHo0U uFlhg5YmrlQ37Dmf0QgR69iDHriII0ip12VkW8BGi13wURIK3djSMtC+d2Z+gWQeZH5d NFFg== X-Gm-Message-State: AOJu0YwSRliBeatX++6R1Jrm65N59Ckn6vXS3STv7VIJBQPIZehXco2o 0g2EcJKWBAK/0j00Iq3zp3U= X-Google-Smtp-Source: AGHT+IEEgaKPH1f/CHCA77RpfqnHueISatT3LoVm8Ul3bW29nFl3gF4cV10YbozFxuueRufcWBqMuQ== X-Received: by 2002:a05:600c:6985:b0:40d:1467:3d84 with SMTP id fp5-20020a05600c698500b0040d14673d84mr598759wmb.118.1703155258912; Thu, 21 Dec 2023 02:40:58 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 3/6] target/riscv: Add pointer masking tb flags Date: Thu, 21 Dec 2023 10:40:32 +0000 Message-Id: <20231221104035.1287244-4-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::429; envelope-from=baturo.alexey@gmail.com; helo=mail-wr1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155503576100004 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 19 +++++++++++++------ target/riscv/cpu_helper.c | 4 ++++ target/riscv/translate.c | 10 ++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f49d4aa52c..2099168950 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -390,6 +390,10 @@ struct CPUArchState { target_ulong senvcfg; uint64_t henvcfg; #endif + /* current number of masked top bits by pointer masking */ + target_ulong pm_pmlen; + /* if pointer masking should do sign extension */ + bool pm_signext; =20 /* Fields from here on are preserved across CPU reset. */ QEMUTimer *stimer; /* Internal timer for S-mode interrupt */ @@ -538,14 +542,17 @@ FIELD(TB_FLAGS, VILL, 14, 1) FIELD(TB_FLAGS, VSTART_EQ_ZERO, 15, 1) /* The combination of MXL/SXL/UXL that applies to the current cpu mode. */ FIELD(TB_FLAGS, XL, 16, 2) -FIELD(TB_FLAGS, VTA, 18, 1) -FIELD(TB_FLAGS, VMA, 19, 1) +/* If pointer masking should be applied and address sign extended */ +FIELD(TB_FLAGS, PM_ENABLED, 18, 1) +FIELD(TB_FLAGS, PM_SIGNEXTEND, 19, 1) +FIELD(TB_FLAGS, VTA, 20, 1) +FIELD(TB_FLAGS, VMA, 21, 1) /* Native debug itrigger */ -FIELD(TB_FLAGS, ITRIGGER, 20, 1) +FIELD(TB_FLAGS, ITRIGGER, 22, 1) /* Virtual mode enabled */ -FIELD(TB_FLAGS, VIRT_ENABLED, 21, 1) -FIELD(TB_FLAGS, PRIV, 22, 2) -FIELD(TB_FLAGS, AXL, 24, 2) +FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) +FIELD(TB_FLAGS, PRIV, 24, 2) +FIELD(TB_FLAGS, AXL, 25, 2) =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 a3d477d226..79cddbd930 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -135,6 +135,10 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, 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->pm_pmlen !=3D 0) { + flags =3D FIELD_DP32(flags, TB_FLAGS, PM_ENABLED, 1); + } + flags =3D FIELD_DP32(flags, TB_FLAGS, PM_SIGNEXTEND, env->pm_signext); =20 *pflags =3D flags; } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 6b4b9a671c..4c0d526b58 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -42,6 +42,8 @@ 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; +/* number of top masked address bits by pointer masking extension */ +static TCGv pm_pmlen; =20 /* * If an operation is being performed on less than TARGET_LONG_BITS, @@ -103,6 +105,9 @@ typedef struct DisasContext { bool vl_eq_vlmax; CPUState *cs; TCGv zero; + /* pointer masking extension */ + bool pm_enabled; + bool pm_signext; /* Use icount trigger for native debug */ bool itrigger; /* FRM is known to contain a valid value. */ @@ -1176,6 +1181,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->pm_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_ENABLED); + ctx->pm_signext =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND); ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->zero =3D tcg_constant_tl(0); ctx->virt_inst_excp =3D false; @@ -1307,4 +1314,7 @@ void riscv_translate_init(void) "load_res"); load_val =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= val), "load_val"); + /* Assign var with number of pointer masking masked bits to tcg global= */ + pm_pmlen =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, pm_pm= len), + "pmlen"); } --=20 2.34.1 From nobody Tue Nov 26 22:13:17 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=1703155491; cv=none; d=zohomail.com; s=zohoarc; b=IH1uFyZvL6KA5fiw8bE1IOIu/spF6GDPNp/CFMrDD6vIYDapvkz7NR4oodiC6Rf5SDeFzkeq63idT6gyVkM7XqbUyP8rXopGdeclReugdhzeTrkLyIL7Eqr2O4BlwS6kKdku8jGvTpogPapHdCXj1qjnSNrRPwsntol94grnV4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703155491; 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=oN1psNxcDgJFhm/E3XNz0g2xCbvEoEyEGFOivuneCyU=; b=TynWp/mymvb5cuhSdeZd6BtrmfNjtZTbY6XDGNos8QLVyfrzwybFF9qWsVQylYe55PtZuV8Wj3irfkyO/9xpdGoRbetMaQWoMrvxBpk9kqTXPTaKYiPOFDWKs18k8YztQSjs7A3F7l8I2hyeLbDWawtS2myRdWKVgEE2xWvdnJs= 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 1703155491753495.95267742614976; Thu, 21 Dec 2023 02:44:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUN-0001gl-KU; Thu, 21 Dec 2023 05:41:15 -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 1rGGUK-0001JY-0c; Thu, 21 Dec 2023 05:41:12 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGUC-00050l-11; Thu, 21 Dec 2023 05:41:11 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40d3dfcc1a4so4100075e9.2; Thu, 21 Dec 2023 02:41:02 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:40:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155260; x=1703760060; 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=oN1psNxcDgJFhm/E3XNz0g2xCbvEoEyEGFOivuneCyU=; b=h74GrxaccqoI5lqxsRJhpvnEMGSuterge5NnO9zo6HFr+1g+l3F+IrAg7g978j2jey T1BhLgyngf5VRfBqT9duLB2YlY9d+LjVUrcO2nhwTJIivZ5PwUBFM+vYi1Fx7yuohHpx 5uHuXOEjUXLJjh1+XHdVleOZr1JlYhu4tz7DyxmzKWey/n5r/rOXe7XusOkn5sh/nCRs FxMvOJZS3oA4iOe/D3bdOBPRcPHy734QOzmCr6h2HaNF4QKE3yf6IqgpR6oE+wfBPZF1 SbraNuaoHQt55JuFGeVyKEdIElyQw8Cr9rCi86qCX31d38lpiiKDRP4Ey+24KnR3zGwV ZVsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155260; x=1703760060; 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=oN1psNxcDgJFhm/E3XNz0g2xCbvEoEyEGFOivuneCyU=; b=LTy5IUJ/l9Cr69UHco739BpF0Y3RyoW4GVblYncACqIpPuTPKtmR+cLBsY9eGuLiia l5N8jR7G8T2hE8LT3HrnUn+KlAhkZ5REPixLrLrS/VgfXWQsBipoJb1Fjp7vlxPwXlfr mz8KY3ZozTBDq68cd7vUODWhZPH81To67+6xfyUXtJHpXGFVGQrV/QNcmts0Pnf560Lt JkOvxvlwTRNUhKH6OM5SVbrwqTnAahsOHW5orxS5IlSydVjAE2q8Bz9aJ0fAhcN56YX8 tgze94ZY5eERqLk4cz5g2fi2UXoeGhJkw4u+dquHAkrlnxDb+b9nxPpO7sQPorCI5RfI S7aQ== X-Gm-Message-State: AOJu0YwuqUvsxYn42HzUn0V5EStsG9XPpfoGGyf7vltrzlfUaqkUFL73 QHjckHOJCR62altu8gHFuR4= X-Google-Smtp-Source: AGHT+IFCRwXxGMNn1v1EJLqFVFBIACOwUkz51HM9xuwyCvCKxTfcAiKXtGR3y8zSF4opYRN7Z/Du1g== X-Received: by 2002:a05:600c:3c85:b0:40b:5e1e:b3af with SMTP id bg5-20020a05600c3c8500b0040b5e1eb3afmr665879wmb.45.1703155260593; Thu, 21 Dec 2023 02:41:00 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 4/6] target/riscv: Add functions to calculate current number of masked bits for pointer masking Date: Thu, 21 Dec 2023 10:40:33 +0000 Message-Id: <20231221104035.1287244-5-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::32c; envelope-from=baturo.alexey@gmail.com; helo=mail-wm1-x32c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155493479100005 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2099168950..9a8e5bc022 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -679,6 +679,8 @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, ta= rget_ulong vtype) 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); + 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 79cddbd930..8e2751fef4 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -143,6 +143,55 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, *pflags =3D flags; } =20 +void riscv_cpu_update_mask(CPURISCVState *env) +{ +#ifndef CONFIG_USER_ONLY + int priv_mode =3D cpu_address_mode(env); + int pmm =3D 0; + int pmlen =3D 0; + int satp_mode =3D 0; + 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); + } + /* Get current PMM field */ + switch (priv_mode) { + case PRV_M: + pmm =3D riscv_cpu_cfg(env)->ext_smmpm ? + get_field(env->mseccfg, MSECCFG_PMM) : PMM_FIELD_DISABLE= D; + break; + case PRV_S: + pmm =3D riscv_cpu_cfg(env)->ext_smnpm ? + get_field(env->menvcfg, MENVCFG_PMM) : PMM_FIELD_DISABLE= D; + break; + case PRV_U: + pmm =3D riscv_cpu_cfg(env)->ext_ssnpm ? + get_field(env->senvcfg, SENVCFG_PMM) : PMM_FIELD_DISABLE= D; + break; + default: + g_assert_not_reached(); + } + /* Get pmlen from PMM field */ + switch (pmm) { + case PMM_FIELD_DISABLED: + pmlen =3D 0; + break; + case PMM_FIELD_PMLEN7: + pmlen =3D 7; + break; + case PMM_FIELD_PMLEN16: + pmlen =3D 16; + break; + default: + g_assert_not_reached(); + } + /* in bare mode address is not sign extended */ + env->pm_signext =3D (satp_mode !=3D VM_1_10_MBARE); + env->pm_pmlen =3D pmlen; +#endif +} + #ifndef CONFIG_USER_ONLY =20 /* --=20 2.34.1 From nobody Tue Nov 26 22:13:17 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=1703155466; cv=none; d=zohomail.com; s=zohoarc; b=UJ3l/lgnAg1n3f9ugYFrE4mvoczm1giTEpClDr5TFTfr+GLFXf44i2Ap2HIXk6m5u5w0plSEtCEr/LlgQI6K+rvsgCzji5P3fuxAPfMabiBQTVSPUZhdxBzqz5HJ23AxwK7j8brQb9QUh1jQsgye8hJTbO9uOVVNnbQzISQgn1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703155466; 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=0pUzfr9ANEUcGoT5fPK11uZ48vY9h+mrrIb4ttUNNJI=; b=ndFkG6Qh/z4eg4RddxMoEL4/TWBdFdrCTr15WfPMK0NXsSc/0oeHuqFvfvX6SWv4DBF3KLJP5X3vC+sOFtgk27Ob4pQKMYnLNCPZVv+PAEdttj7bs44BN4b3Efidvtmga4S5LyuXXrMy48PWcnZweJgYqT5oGWoAylzo85wXCqY= 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 1703155466987805.860394493502; Thu, 21 Dec 2023 02:44:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUQ-00021X-76; Thu, 21 Dec 2023 05:41: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 1rGGUK-0001Ln-H1; Thu, 21 Dec 2023 05:41:12 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGUC-00051D-7m; Thu, 21 Dec 2023 05:41:12 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40c339d2b88so6398785e9.3; Thu, 21 Dec 2023 02:41:03 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155262; x=1703760062; 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=0pUzfr9ANEUcGoT5fPK11uZ48vY9h+mrrIb4ttUNNJI=; b=lsdRztdMSOWRG64mpAQmcCY0Sc6AVtJdXzMANPsnscgks4Ov8DdRtfdKxbWNo+B48S ScWoQ57G3uxAYgFy/RVHnHKbgBV1g/5DtK/Ztsp4EY9YHMnpTysX/Htx1Q3p+H/mrFP+ 3JVkIAcZ1vaix/DMRElfgDduIVAEsCmkmArPyYL30XSjUF/hWOnHOvrdE/XJ/LcsxlaO H8umlypSP9ZiKF45dcVTfrpND/pxJF9aVM/X5Knsma1RYvKbZTfnkxmktF/QTzjPY3s2 SEs4ldrPomSr7Nd1g5YhBDZAsXRenjJMcZwl6skPdenv5DvydEzIcw/2QH/j0NR/tKfK qQAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155262; x=1703760062; 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=0pUzfr9ANEUcGoT5fPK11uZ48vY9h+mrrIb4ttUNNJI=; b=GbsiX27VJYhh4UGdWzL3YcXKh21rE/5kpa5nbHpMhIKUecAWy2yVQGQPdy+5aUkNRb nMQ741Ead+9QxSDaQFC6kk316hw86ujAtVdkfC0jsoFeDnuu3LylvcQys9HmElP2A3yD wgquBlW9ebdy6S19D0+H1fxu6lcsP5seRq6L2GWsiJ6UdkR1V3gDeOVfbprYxhOLCW7p Mwv8/JYAalo2AO8bxdDQPGUWFr75AW5vSWXhM5EnOjbW6WM2YxX7NR+gwmVLVkcUZ2pb SXRcQ9SU49ow41TPFYvgbiGmeNrsz+NZYJUe+Gi5cntGQGPy3vhzzGeOKB4jyQl9xRRH j91Q== X-Gm-Message-State: AOJu0YxPyptObC6zcVMxUA0ByCsmhvy/0ITsS/SWSyIi6mn1kvT/KX+h HR2CTzIXBQLMBe+kvgyjWok= X-Google-Smtp-Source: AGHT+IEHNprdXxCisd4RoXp9LlJ/YoFR+oLNsbTo8AO1mDUFwqOXrC04LxSWxfakumtldpsrRJ3g4g== X-Received: by 2002:a05:600c:3f94:b0:40c:316b:f6e2 with SMTP id fs20-20020a05600c3f9400b0040c316bf6e2mr601008wmb.97.1703155262196; Thu, 21 Dec 2023 02:41:02 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 5/6] target/riscv: Update address modify functions to take into account pointer masking Date: Thu, 21 Dec 2023 10:40:34 +0000 Message-Id: <20231221104035.1287244-6-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::32c; envelope-from=baturo.alexey@gmail.com; helo=mail-wm1-x32c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155467290100001 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/translate.c | 21 +++++++++++++++++++-- target/riscv/vector_helper.c | 7 +++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 4c0d526b58..70bbead73b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -581,7 +581,15 @@ 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) { + if (ctx->pm_enabled) { + tcg_gen_shl_tl(addr, addr, pm_pmlen); + /* sign extend address by first non-masked bit otherwise zero exte= nd */ + if (ctx->pm_signext) { + tcg_gen_sar_tl(addr, addr, pm_pmlen); + } else { + tcg_gen_shr_tl(addr, addr, pm_pmlen); + } + } else if (get_address_xl(ctx) =3D=3D MXL_RV32) { tcg_gen_ext32u_tl(addr, addr); } =20 @@ -595,7 +603,16 @@ 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) { + /* sign extend address by first non-masked bit */ + if (ctx->pm_enabled) { + tcg_gen_shl_tl(addr, addr, pm_pmlen); + /* sign extend address by first non-masked bit otherwise zero exte= nd */ + if (ctx->pm_signext) { + tcg_gen_sar_tl(addr, addr, pm_pmlen); + } else { + tcg_gen_shr_tl(addr, addr, pm_pmlen); + } + } else if (get_xl(ctx) =3D=3D MXL_RV32) { tcg_gen_ext32u_tl(addr, addr); } return addr; diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 8e7a8e80a0..d91bdcbbc0 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -94,6 +94,13 @@ static inline uint32_t vext_max_elems(uint32_t desc, uin= t32_t log2_esz) =20 static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) { + addr =3D addr << env->pm_pmlen; + /* sign/zero extend masked address by N-1 bit */ + if (env->pm_signext) { + addr =3D (target_long)addr >> env->pm_pmlen; + } else { + addr =3D addr >> env->pm_pmlen; + } return addr; } =20 --=20 2.34.1 From nobody Tue Nov 26 22:13:17 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=1703155400; cv=none; d=zohomail.com; s=zohoarc; b=n+8CGZoi6yZfR/xM0iKFAjxiZ2Q0dEI3yVgw8iq5ooAlJzvtG1r2EK5MV6DsKopAvlqa79rgZ89bt1bnZma1xaWjnxDx92gncUdlJVG2Ni0bR4f9ilNGXIlGRYpn+LN0SW9LR6RgW8WV1vyEVOM40swX091DC9CjTt76JAVaCiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703155400; 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=rye7SEwEpHGno4AHmNtYhB26rqF5AqoDV8mljGrNQW0=; b=Vo55MZChIw7eGSVb7rtNm6MVRtbpNXi1TVVymbjVitQ6nOtoHb680eAzCFMYcF6/49zy91MFceuJxxIswTAuQYd+TcXLedpn/U3ewBCyVMt3zynXb+f+CfE7xGAZOJVR/CSi20bYSzbcbPhLzOLBYWHJcQKQe8gGbklm42HNlno= 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 170315540065779.72663341292684; Thu, 21 Dec 2023 02:43:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGGUQ-00023f-Jl; Thu, 21 Dec 2023 05:41: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 1rGGUM-0001VA-Sm; Thu, 21 Dec 2023 05:41:14 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rGGUF-00055K-G8; Thu, 21 Dec 2023 05:41:13 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40d22d3e751so10253485e9.1; Thu, 21 Dec 2023 02:41:04 -0800 (PST) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id bh20-20020a05600c3d1400b0040d15dcb77asm10633674wmb.23.2023.12.21.02.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:41:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703155264; x=1703760064; 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=rye7SEwEpHGno4AHmNtYhB26rqF5AqoDV8mljGrNQW0=; b=Ct56OjSI5CAJI772Fnos3badUHM0/QTm2DxjyciUhIf2fug6rNv8+CLbU+MCPfoVRI jBbBl3+OAJaxqvXAQp77sEw1A0s/cF/IHJtUuCU/jhX5JUivHlr7b4mRqT6t272K/RVe gGscgK3PGdTzsscqRSZ/g+fjOq0uVIRKgp5ijQiiOGMpThGn38SbvjzvwOTkqXD+LLQv e/Siv4hYV5b/4SNo1Vti791KT/+zOMP0iL00hQ7cAnvREMHB8DYSebIkBUkBZMQtMDF3 iSdFyf6EeFLUJwdQ54QghWWXIs7yqTOtxp7sNHJWY54h0gkvTf0gJc/B+CbX8/nzG3Gu 5o5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703155264; x=1703760064; 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=rye7SEwEpHGno4AHmNtYhB26rqF5AqoDV8mljGrNQW0=; b=kjs9DApjgFUN0FvUgJTpcNW7Uu1mVe0NOXIXHACEKnJUboWGdmVt4EsPTMo1whNyOW eUaYOjE+DDylkfKXS0iU3khkFWZ6tRxBOig98zWbXh9llgxXkXhIuKv0fPEgZ4pL+AF2 TYVrydYY7PDZ1M985+75flJ8a44R5mDUmrCm3RPsE/uSGgwnRZ86PwsPWFP8HblbbB8a H0jtZDbcJZR1gckcWFNzD8QvEc8/P0+7OYIY+g4S+odk7J6mcRVsdXcS8IoUOlECZaTf DGzSLJsQ087p4Yt7CJay6PP/qPGdrK7NwlgO4VvR53rZDBz9XFvyFmk2D3US6BQbmN2s Qkwg== X-Gm-Message-State: AOJu0Yzjkqv9eGlrVeluamr0a1tYVR9PdXIFH//dXxk/QHrNmhHqh6PU Nbf4Ob4LB64FPtKjYkbp6dw= X-Google-Smtp-Source: AGHT+IHCYpMLR4kTnXjmv1/IJMHedM1hfae13cgStTMXjZNM9TdBPTBLQbT3JrlgK6JKERobCG6WrA== X-Received: by 2002:a7b:ca5a:0:b0:40b:5e4a:234c with SMTP id m26-20020a7bca5a000000b0040b5e4a234cmr345177wml.78.1703155263878; Thu, 21 Dec 2023 02:41:03 -0800 (PST) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.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 6/6] target/riscv: Enable updates for pointer masking variables and thus enable pointer masking extension Date: Thu, 21 Dec 2023 10:40:35 +0000 Message-Id: <20231221104035.1287244-7-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221104035.1287244-1-me@deliversmonkey.space> References: <20231221104035.1287244-1-me@deliversmonkey.space> 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::332; envelope-from=baturo.alexey@gmail.com; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703155402867100003 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.c | 9 +++++++++ target/riscv/cpu_helper.c | 1 + target/riscv/csr.c | 4 ++++ target/riscv/machine.c | 1 + target/riscv/pmp.c | 1 + 5 files changed, 16 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1e6571ce99..1d20e6a978 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -153,6 +153,9 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt), + ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_12_0, ext_ssnpm), + ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_12_0, ext_smnpm), + ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_12_0, ext_smmpm), ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba), ISA_EXT_DATA_ENTRY(xtheadbb, PRIV_VERSION_1_11_0, ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs), @@ -897,6 +900,7 @@ static void riscv_cpu_reset_hold(Object *obj) pmp_unlock_entries(env); #endif 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); @@ -1337,6 +1341,11 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { =20 MULTI_EXT_CFG_BOOL("zmmul", ext_zmmul, false), =20 + /* Zjpm v0.8 extensions */ + MULTI_EXT_CFG_BOOL("ssnpm", ext_ssnpm, false), + MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false), + MULTI_EXT_CFG_BOOL("smmpm", ext_smmpm, false), + MULTI_EXT_CFG_BOOL("zca", ext_zca, false), MULTI_EXT_CFG_BOOL("zcb", ext_zcb, false), MULTI_EXT_CFG_BOOL("zcd", ext_zcd, false), diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 8e2751fef4..c2bc737dd7 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -723,6 +723,7 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulon= g newpriv) /* 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 a67ba30494..5336d91dd8 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1348,6 +1348,7 @@ 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 @@ -2039,6 +2040,7 @@ static RISCVException write_menvcfg(CPURISCVState *en= v, int csrno, } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 + riscv_cpu_update_mask(env); return RISCV_EXCP_NONE; } =20 @@ -2093,6 +2095,8 @@ static RISCVException write_senvcfg(CPURISCVState *en= v, int csrno, } =20 env->senvcfg =3D (env->senvcfg & ~mask) | (val & mask); + + riscv_cpu_update_mask(env); return RISCV_EXCP_NONE; } =20 diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 5e9c5b43ab..41ad30c8e1 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -261,6 +261,7 @@ 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/pmp.c b/target/riscv/pmp.c index 893ccd58d8..2cc08e58c5 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -607,6 +607,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong= val) } =20 env->mseccfg =3D val; + riscv_cpu_update_mask(env); } =20 /* --=20 2.34.1