From nobody Sat Nov 23 22:33:09 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=1731045802; cv=none; d=zohomail.com; s=zohoarc; b=SP5o8RBgJ5TQZc5u83pG/XHTB1r4F6lVM4HabvsJH6Kt/7++5ZDxH2wYn8G3egmldWwfO5ZTwT3p71ae7ZAvhMF0Dpe4MzRIi2Bm+9icuRlDCwaU4ag357yNUymroh8wvwZUXTgT1GfENoN8UCHGtyqDVrpaOJsMHkePnvuHA34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731045802; 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=RS8RTNiGNUMOQzg5lnVxUQBkfOK1zeqKc/5lACA0Vtg=; b=XlAMCOXDzxqFfjitl1ZIJSHg6XRnZVMYizWbPBgTQ79s41eZYUufuyER6tTlkbhmfr4f/2HytyNe7b0bd6UFLDxcQFGb96y2/fivp4KRAR6cXfh9EABQoyzqPW+J8LOrDTsZE/mN1cOuQ1FzOIOTVDyIz6xwPn/zWcZzLRN9u0M= 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 1731045802598882.6841601989373; Thu, 7 Nov 2024 22:03:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9I3s-0003oq-SQ; Fri, 08 Nov 2024 01:01:36 -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 1t9I3r-0003na-69; Fri, 08 Nov 2024 01:01:35 -0500 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t9I3p-00083y-DN; Fri, 08 Nov 2024 01:01:34 -0500 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2fb59652cb9so16520431fa.3; Thu, 07 Nov 2024 22:01:32 -0800 (PST) Received: from hades.midgard (broadband-188-255-126-251.ip.moscow.rt.ru. [188.255.126.251]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ff178ee325sm5159001fa.27.2024.11.07.22.01.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Nov 2024 22:01:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731045691; x=1731650491; 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=RS8RTNiGNUMOQzg5lnVxUQBkfOK1zeqKc/5lACA0Vtg=; b=NlQqbJQ72QIUsXMVhPxtaaPOaOCCwEak2+qI9QRY4gYmS/Z0RN/Pk7ppPO/KRPdiVz zjQagFurnyuRldqzS67rgSP4whaVYr+Q51KOEMS+CUUOe7jfLhQDloMkw3Szox+NBpsG 5Fmro8LTn/cJ/5pzqC4Yn8GucCGRHyKY0GBZzeRGAndrmGySrXtBs9iQqSfUKxkqYXWU YN2o2ErG8ijwtCU0cDg4rhDs3r47xK+n+gDiteZuQKQVgN+T4ykb/QecUCYUafvZ0M2F PJhKripdcHRz9JBWH1mo3q2aAVBnUxQOaiIb/vStgFXMGe/aocqz5nUSFB2AvAgsb6DA +Gkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731045691; x=1731650491; 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=RS8RTNiGNUMOQzg5lnVxUQBkfOK1zeqKc/5lACA0Vtg=; b=tDBaX5T0Ycv3WYedPt5YwAXo/9Cw06goCcBO56lUa2yzV+VU5Wq126dsdWsQK37TMz P6ippr/ok+zAO3YANO+w7N6qhQi75CIwArKgOy1wPfQZzJ9U41TMA1alzA5nSwA2gm/U c5sOVmjjRgDubdXzAwzyGBe2krZdSQhjFipeRJiJ+mjjnebfeJ5ljYN5hsKs0yECBCPv 5RdaylQMjP5cCj5cwFOSSJ5QM87QiHyX1dgo0p4jMRgvABAxAq4BLwFaf/GPz4udCe5n BOb9nkmIVyTFLrmmH84BUonoxHSet5WYWiOPwuxhX49MGLU29oyZ/8KssjDTJ6b/hBF6 p1wQ== X-Forwarded-Encrypted: i=1; AJvYcCUPSIQo73Rf1jEpsCf7f06RsCJSeY1JtmIEf9CN8/uEfOLfLK8EW7VLvS/HLeN+VQeXg11XKIh450VX@nongnu.org, AJvYcCV2hEAEnEggq6n5uHsFCVaGzHOg8HDVzvBtJa3ESalFu3ti2xkRdy9pwnpfdeAH2m1Nh57MoqPU+9ltrw==@nongnu.org X-Gm-Message-State: AOJu0YxbU09+H5qy0tXiKu+2LoXhrbwmaFItMHJjLfzNgFJDTjlMTcJW 371rQtoAEa9YmhmWaKvyWSXXJESgDcIBeRNEP5LlhM8fDB2RuN7k X-Google-Smtp-Source: AGHT+IFsuWSnC6fiB3SSL07t36tD7Ds0LqhP9HTCybfASgiLywhPTTyyJjINgiXm00DwJHLuTLqByg== X-Received: by 2002:a2e:a90a:0:b0:2fb:593c:2bf2 with SMTP id 38308e7fff4ca-2ff201e73afmr6777231fa.3.1731045691296; Thu, 07 Nov 2024 22:01:31 -0800 (PST) From: baturo.alexey@gmail.com To: Cc: baturo.alexey@gmail.com, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, dbarboza@ventanamicro.com, liwei1518@gmail.com, alistair23@gmail.com, frank.chang@sifive.com, palmer@dabbelt.com, Alistair.Francis@wdc.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH 5/7] target/riscv: Update address modify functions to take into account pointer masking Date: Fri, 8 Nov 2024 09:01:14 +0300 Message-Id: <20241108060116.37397-6-baturo.alexey@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241108060116.37397-1-baturo.alexey@gmail.com> References: <20241108060116.37397-1-baturo.alexey@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=baturo.alexey@gmail.com; helo=mail-lj1-x233.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: 1731045804871116600 Content-Type: text/plain; charset="utf-8" From: Alexey Baturo Signed-off-by: Alexey Baturo --- target/riscv/translate.c | 22 ++++++++++++++++------ target/riscv/vector_helper.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index bb92f36ba1..32df295123 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -588,8 +588,10 @@ static TCGv get_address(DisasContext *ctx, int rs1, in= t imm) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_addi_tl(addr, src1, imm); - if (get_address_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); } =20 return addr; @@ -602,8 +604,10 @@ static TCGv get_address_indexed(DisasContext *ctx, int= rs1, TCGv offs) TCGv src1 =3D get_gpr(ctx, rs1, EXT_NONE); =20 tcg_gen_add_tl(addr, src1, offs); - if (get_xl(ctx) =3D=3D MXL_RV32) { - tcg_gen_ext32u_tl(addr, addr); + if (ctx->addr_signed) { + tcg_gen_sextract_tl(addr, addr, 0, ctx->addr_xl); + } else { + tcg_gen_extract_tl(addr, addr, 0, ctx->addr_xl); } =20 return addr; @@ -1233,8 +1237,14 @@ static void riscv_tr_init_disas_context(DisasContext= Base *dcbase, CPUState *cs) ctx->xl =3D FIELD_EX32(tb_flags, TB_FLAGS, XL); ctx->address_xl =3D FIELD_EX32(tb_flags, TB_FLAGS, AXL); ctx->cs =3D cs; - ctx->addr_xl =3D 0; - ctx->addr_signed =3D false; + if (get_xl(ctx) =3D=3D MXL_RV32) { + ctx->addr_xl =3D 32; + ctx->addr_signed =3D false; + } else { + int pm_pmm =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_PMM); + ctx->addr_xl =3D 64 - riscv_pm_get_pmlen(pm_pmm); + ctx->addr_signed =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_SIGNEXTEND); + } ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->bcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 4af8d2f035..bb3f68b6cb 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -107,6 +107,22 @@ static inline uint32_t vext_max_elems(uint32_t desc, u= int32_t log2_esz) =20 static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong ad= dr) { + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + return addr; + } + RISCVPmPmm pmm =3D riscv_pm_get_pmm(env); + if (pmm =3D=3D PMM_FIELD_DISABLED) { + return addr; + } + int pmlen =3D riscv_pm_get_pmlen(pmm); + bool signext =3D riscv_cpu_virt_mem_enabled(env); + addr =3D addr << pmlen; + /* sign/zero extend masked address by N-1 bit */ + if (signext) { + addr =3D (target_long)addr >> pmlen; + } else { + addr =3D addr >> pmlen; + } return addr; } =20 --=20 2.39.5