From nobody Wed Nov 27 00:27:02 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