From nobody Tue Nov 26 22:18:14 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=1704308344; cv=none; d=zohomail.com; s=zohoarc; b=ZvWc1xlF3MhFNW8bQAgdDMXht19Ptpvlny/yiwutnXyNAQt+ZhLs3NcebkVufd3g+0ea5gb5+bWQMhflytisO9BRQo11Tcg0c9DWQj3aenSmZrzMgnGi/V22f2LFKxf1HdtS1OCBv+tlTBHbFv7dzIoOqUQHbzgRMvIAkvw5piI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704308344; 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=BHX167RE3euJXF9kyocBWZgVJ7RfvoObHUcQLg8ghPc=; b=VyDk0Go0Beo681LwGcDDDkg0kYr28bFH9KOQHESYDIwJo6LWMIK51U89E+4icIO5amU4pAdhU6Et0k6ZvTrXnBiVIrbe1sBchiCr3Qp4AqN07J789DNFIrw8qs268boq3ZK99GXWf4urtesrPOalFESkQwXqASz+l+q+ApBWa1E= 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 1704308344013320.3809676152614; Wed, 3 Jan 2024 10:59:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rL6Qu-0005A1-3A; Wed, 03 Jan 2024 13:57:40 -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 1rL6Qs-00058l-4X; Wed, 03 Jan 2024 13:57:38 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rL6Qp-00042D-Tu; Wed, 03 Jan 2024 13:57:37 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33674f60184so10796442f8f.1; Wed, 03 Jan 2024 10:57:35 -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 ep16-20020a1709069b5000b00a27d5e9b3ebsm3897915ejc.105.2024.01.03.10.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 10:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704308254; x=1704913054; 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=BHX167RE3euJXF9kyocBWZgVJ7RfvoObHUcQLg8ghPc=; b=Ayx4kbiEfe3gDd9xL7Cnw9KSt3T9w9ymx7B7sJuPYjTgx6qqqPt6NCO9OwhaDEdTXQ pqUEGuszwVldd+4pVvyNk5BzatNMDMUuca5zh6Pp7J8VVxT/Nfp1c7bs9UZM4s58uZ+6 H/K7qEloZQXxdPvJD39D6so/AMhYoJG6ba98hX4u04MNv89iSD1PLIWKjAqCSO9DxVAo mYQYt+SRuLUndT0G8JXMTDoyXNshmCUqJ3QnEFvrs2maekQ0iiASncSgAU4D/GcF1Mnx bWvyB5zxXH2+TGl2FzHxofYHMsUEvhoNsfC0R/T8rUtwV5hI5JX5VputZSEBfl+v7Jvr InTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704308254; x=1704913054; 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=BHX167RE3euJXF9kyocBWZgVJ7RfvoObHUcQLg8ghPc=; b=SjQnwbzXIpX9gyo7hgZYuTnoEV3CSJsK0yDt+7/lREBGMpOqGTiAiV3ikdXs7Wula8 iEv6rI694fKWI5eT0bgGJJb2I4P4moBN8DmxSIsnPjracuvtRdZQnOw1/wNTlwo0Kd8Y UZUxC2i04f7E1QI1uodZCHhlnKfGghbKTSBwIj6UmFAvgVJUNq6G9NNg9o7/qIYyydpO vQVHqH/al0x7lcc+Vd5G3d7WiORh28z8Tz0COADZgmUljflmtDQbK9/W1cKhVaduU3mi aJWJR+ezWaPZEXlPkcUK3FUc+kVxkwTN2MQwoEIVni8Ovz34Ck8QrWo3mJhf6MhSsgti s4rA== X-Gm-Message-State: AOJu0Yx7zUPeHMbhIhvpLrIB+dkDrQkBFh4l7LJDYL6nLdIBJn8pMHNa NQxgHaUuPwnEV9T2jy333PE= X-Google-Smtp-Source: AGHT+IGzyC97foEQL1nSzdecqOFjMEJQ9kZEk4DM5k1a6UiCHpRRaK0ptUg29v4PtfJ/GQzpYlgoKA== X-Received: by 2002:a05:600c:3f85:b0:40d:88ca:75ff with SMTP id fs5-20020a05600c3f8500b0040d88ca75ffmr2262743wmb.240.1704308254035; Wed, 03 Jan 2024 10:57:34 -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 v3 3/6] target/riscv: Add helper functions to calculate current number of masked bits for pointer masking Date: Wed, 3 Jan 2024 18:57:13 +0000 Message-Id: <20240103185716.1790546-4-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240103185716.1790546-1-me@deliversmonkey.space> References: <20240103185716.1790546-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::432; envelope-from=baturo.alexey@gmail.com; helo=mail-wr1-x432.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: 1704308344447100001 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/cpu.h | 4 +++ target/riscv/cpu_helper.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index bd379ee653..c607a94bba 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -672,6 +672,10 @@ static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, t= arget_ulong vtype) void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags); =20 +bool riscv_cpu_bare_mode(CPURISCVState *env); +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); +int riscv_pm_get_pmlen(RISCVPmPmm pmm); + 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 a3d477d226..4c34e12ee3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -139,6 +139,60 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, *pflags =3D flags; } =20 +RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env) +{ + int pmm =3D 0; +#ifndef CONFIG_USER_ONLY + int priv_mode =3D cpu_address_mode(env); + /* 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(); + } +#endif + return pmm; +} + +bool riscv_cpu_bare_mode(CPURISCVState *env) +{ + int satp_mode =3D 0; +#ifndef CONFIG_USER_ONLY + 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); + } +#endif + return (satp_mode =3D=3D VM_1_10_MBARE); +} + +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.34.1