From nobody Sat Nov 23 17:50: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=1715422352; cv=none; d=zohomail.com; s=zohoarc; b=JZvvnm7xvSqhTyXHrEYcMfDREOh6oCEKFKNBXmTDA4xYEv1/ovFVEcHeqXUcsgQDRbT0uXmGRMLztfimDCcLa861H0rvxErFfGIbFbtRQZheI2lTFUXJxN/UZYKwg2RtUVBrYHI76O1O3hM+fSZdI/0935F8B6MTGNPA3n/kmU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715422352; 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=NChut3Wu3U+/heFB1RR2XoMpJXwZZWmP15KDXMsEMrE=; b=WUL3aG0dO/Kv5BFthcBrIBEO8uNdHDH1oQkJYNowpUpidNUCAJKsXIJ+iX7f0CHZO2JUd9bALjZb9+AkxwabU+sJO3zH4zkSVtk2ANAmwjHa7J+EnX6lrv+dD0kzRxuBbcnwxEMlRDiGUZ0Wc/ZIxwEXtYMYGLWeT7RQIxazM1k= 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 1715422352423684.4948338338485; Sat, 11 May 2024 03:12:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5jhI-0005VF-N7; Sat, 11 May 2024 06:11:20 -0400 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 1s5jhF-0005TS-M3; Sat, 11 May 2024 06:11:17 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s5jhA-0002AQ-5o; Sat, 11 May 2024 06:11:15 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a5a157a1cd1so703841866b.0; Sat, 11 May 2024 03:11:11 -0700 (PDT) Received: from freya.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a1781d27bsm301687166b.21.2024.05.11.03.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 03:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715422270; x=1716027070; 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=NChut3Wu3U+/heFB1RR2XoMpJXwZZWmP15KDXMsEMrE=; b=Az+Q8f/FFKbNJerkTHZVCPp/xWfayPHyR+maaU0AcyRaARB1GSRspppiXjsvNm4HNP 0Zot4mHDc9jzhiKWRIIbTF04VP0KDjl6pscY913F2yz2E1e1K0+VeA3CKvwISwPZsE1I rE6un5wCvRf1exu0boRDl0EzE/e4KTwfkqE36fbFOUWd9LTiR8KD/d6iJ0wCG1pDUUJD JGZBCcgcn4sP6OwGeU9l5BE7Y9O88Q0kIzm70XoHaPlhFVsont+6cRVRJulitVnjdetH GL+i9PNVUHIudb/DheeC5aGiKpnAxnhJ3squHlHobLOTOhDIK6O2QxzXdvXjrsSIT6/H bCCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715422270; x=1716027070; 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=NChut3Wu3U+/heFB1RR2XoMpJXwZZWmP15KDXMsEMrE=; b=nc/1Oth/2wvvLL1B9zWBabv/QV7dDydgYwUYuiKlJfhf58AdWni52H6It0FCAikVI4 zldVs8HFwLLudB9ygx5yKBrbWzutjwy7DLqL+kDf64Rib3dfxwp084QHIgJF14L80v3b ZUk+EvzV53z6nwhlsa93S2ZCJx74kFewzHo4iWUEeiacUigL9vHs0M+scnygcxloHVxa /nQoZmJvQQe+wcsCrr9xQBvBItAQ01p+zCiUzzuTSvphws/Jtdue2jO+HePD9pu8Ccgb 5y6YwBbEj38qoobxzWKOJv5XJunqM3iyRtqEG9vDpKLqiP2Gg8ZxpMXEsdGspv5wKo4E xX3A== X-Forwarded-Encrypted: i=1; AJvYcCUkJS6qSowkK9ITXnsyTnc5FptYZdj/cgVRpSEDprMdBHy9JhElC41dwbVmMl5g8UMxKo2hZVYTeyegpLuZOwxdWHhKds60lJQh6rwa8P8q0Zguy0O9Tc2HmC9FzA== X-Gm-Message-State: AOJu0YxML0AonAOSqil3MCL7HY9CQUFEB9nIsIfs7ZguRzvSvM03MQ58 HwlrB1Oj4jaAI2rJrxeJ0jyyZqF5NOGM2osAku6dzPjPfXdthJ6B X-Google-Smtp-Source: AGHT+IEl+4bjH/eB2wdq7558gezfPyTy7IojHcKilEbUxFydJuMZsDJQbS5H3MCz/68tLY+lt2lZrw== X-Received: by 2002:a17:906:70c:b0:a59:c28a:7eb4 with SMTP id a640c23a62f3a-a5a2d5d3d2dmr296692166b.44.1715422270505; Sat, 11 May 2024 03:11:10 -0700 (PDT) From: Alexey Baturo X-Google-Original-From: Alexey Baturo To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, space.monkey.delivers@gmail.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Alistair Francis Subject: [PATCH v9 5/6] target/riscv: Update address modify functions to take into account pointer masking Date: Sat, 11 May 2024 13:10:52 +0300 Message-Id: <20240511101053.1875596-6-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240511101053.1875596-1-me@deliversmonkey.space> References: <20240511101053.1875596-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::635; envelope-from=baturo.alexey@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715422352759100008 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/translate.c | 22 ++++++++++++++++------ target/riscv/vector_helper.c | 13 +++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 3f578d6dd8..da46e636f8 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -580,8 +580,10 @@ static TCGv get_address(DisasContext *ctx, int rs1, in= t imm) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_addi_tl(addr, src1, imm); - if (get_address_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_width); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_width); } =20 return addr; @@ -594,8 +596,10 @@ static TCGv get_address_indexed(DisasContext *ctx, int= rs1, TCGv offs) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_add_tl(addr, src1, offs); - if (get_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_width); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_width); } return addr; } @@ -1188,8 +1192,14 @@ static void riscv_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->xl =3D FIELD_EX32(tb_flags, TB_FLAGS, XL); ctx->address_xl =3D FIELD_EX32(tb_flags, TB_FLAGS, AXL); ctx->cs =3D cs; - ctx->addr_width =3D 0; - ctx->addr_signed =3D false; + if (get_xl(ctx) =3D=3D MXL_RV32) { + ctx->addr_width =3D 32; + ctx->addr_signed =3D false; + } else { + int pm_pmm =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_PMM); + ctx->addr_width =3D 64 - riscv_pm_get_pmlen(pm_pmm); + ctx->addr_signed =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND); + } ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->zero =3D tcg_constant_tl(0); diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 39ba2a09dd..28861cc509 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -104,6 +104,19 @@ static inline uint32_t vext_max_elems(uint32_t desc, u= int32_t log2_esz) =20 static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) { + RISCVPmPmm pmm =3D riscv_pm_get_pmm(env); + if (pmm =3D=3D PMM_FIELD_DISABLED) { + return addr; + } + int pmlen =3D riscv_pm_get_pmlen(pmm); + bool signext =3D riscv_cpu_virt_mem_enabled(env); + addr =3D addr << pmlen; + /* sign/zero extend masked address by N-1 bit */ + if (signext) { + addr =3D (target_long)addr >> pmlen; + } else { + addr =3D addr >> pmlen; + } return addr; } =20 --=20 2.34.1