From nobody Tue Nov 26 14:30:06 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=1706869001; cv=none; d=zohomail.com; s=zohoarc; b=BnLJ80Bww0fn3oiTZ5C5anRNHodNJsLtg5L3YO/hQaP5u2sDVXpxpyB8GRmpen7SOO2XNhap24ajwvBPtscjIRm0AtrcBmxKgstvhPvi0DxS/SxJ74C3ENs/3aNgvP6Vp0Wrdjznq+kt4P6ozyeUCS2ttCNFKT+eZ2kB4eH8mGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706869001; 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=lxIvZiWXY9IKLbJ7U7yyTRtTaqakCCJzBMTW0m/QIuA=; b=LNLTfhKajmyeKoZdTEBBJQxrmvUaP/dbWphfPDcJ92/BWv4h1tsj1Vq954fmGZJtECia7q+6XXWGITGVHP0T+YujBrurW7cxyMBweYJvTPoLiz1a/JO2hmAct9vr42y7QrdIbl6dqJQ5SieQR2xGgvXptjIuNNTDb9bjAIf0AQw= 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 1706869001118442.2946379907123; Fri, 2 Feb 2024 02:16:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVqZf-0001Q6-HI; Fri, 02 Feb 2024 05:15:07 -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 1rVqZd-0001Od-Bm; Fri, 02 Feb 2024 05:15:05 -0500 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVqZb-00045Z-N5; Fri, 02 Feb 2024 05:15:05 -0500 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-5113a841810so111606e87.0; Fri, 02 Feb 2024 02:15: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 ll5-20020a170907190500b00a36fe6fe976sm579722ejc.190.2024.02.02.02.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706868901; x=1707473701; 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=lxIvZiWXY9IKLbJ7U7yyTRtTaqakCCJzBMTW0m/QIuA=; b=lmtbHE5aEFJw08sdiXNOs46r+MCcD5R+I28bvhTBMwCWO7awmOi5TGFXgWFqCpcfWt YLADHUVtbFk+x1WbNYduyoe8knJxhzne5/uvrF8vbB+GkIhgLwLidfGPYVSZ+8/dTYWR xAwP5zHgZ2wHUKqVsmnb2L8HaD40zwn95q1enLMHvygmr6hzUP7Bx6ArA6QB/oTJiSYY NZccFh6wKIRVkDz4/wCITGx9pY2hl975z93YeG2M5G/3sP105SLynGNwQjIVKdyXPdpl YaGhmJGU3kJVndMMygUglSz3NNh2edFt/9ylYehRXVpvQgu2Itz1sBGhYVf/6mYJtOZT rZgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706868901; x=1707473701; 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=lxIvZiWXY9IKLbJ7U7yyTRtTaqakCCJzBMTW0m/QIuA=; b=r5wSo4/hQYndVNsLfP3zVigEMUy47McATo++thsYOv2vDDxvO+JB5GuVtSoIJTlJCb RICmzWeyLv9NIFdMUYhnfCJTxkx7Cgq+3kMT97dJAmvEu9CVkYP3d5qjr7Uebgxy8n50 lsCsWGyfiu0HMJ2mlfWE6SoXwvhbAAivHnqbrprKTbcQL4ZBuac30WqRO09k795Whuv8 5NO18uy6HwahJlE1ZsFnZzdis0YcDGZbHqp95rwQ4Miqze/2U+Q4OfnuTskksnz+acdp dQTEMhbfCOswPOUHtcaeU2eMY/DzeKF8cyKrvl+u25wKvonfMvrRk55rhqiJVI9XMziU n38g== X-Gm-Message-State: AOJu0YwDFa5fdM5iMsXAHjbwyttFwCrOgpVnROtYAsnrMnHQ+IP4wYWF WOsNbj0eyDm3cCxSdzC3poS4VIPjz60A11cVHaXA1C3RUim/ZPsJ X-Google-Smtp-Source: AGHT+IFL7B0UBicSzEGTBJUwAxjvVI6mqfrv6XH+8PaVw/MysJRdIa39ZK9rvcbCmXAiWumkdSLAnA== X-Received: by 2002:ac2:4343:0:b0:511:3a8a:9fde with SMTP id o3-20020ac24343000000b005113a8a9fdemr171475lfl.0.1706868901513; Fri, 02 Feb 2024 02:15:01 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW6IaaSpInblOuXXFZJVCL1d6gKk8oV3q3H9NRWnNjGVk2dV+SxKqc+W9bmCM9X/b/IdQcfe1/JSQUD+oCkVTazrc11UZ4zZqrLgOw4CW/YICZhWabFt4EZe5oALFaiFS4Cs2igEigvr9kmL1cW+BllQEPM+KE6PBi8l1UdfV2T/jnjYK5yaAbDs+xujJPSYtEmJloU60hoVmbbGPAll5SL5lGPq8iDy2MCkZeC42hBss0weDaigEQ/bq+kr7aLgoqY+T4nYSa8hT/pjsIgfZgsLsdZWJHMwWFxa1YJFuV2NbUE64iVUbmvDw4EZMd+YHnH4Xmg5XZ5ugbWDYJZULSpgSH0/rfVCsSsCweaLvQx7QlF2HoxVq8ZpP4= 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, Alistair Francis Subject: [PATCH v7 5/6] target/riscv: Update address modify functions to take into account pointer masking Date: Fri, 2 Feb 2024 10:14:38 +0000 Message-Id: <20240202101439.3714106-6-me@deliversmonkey.space> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202101439.3714106-1-me@deliversmonkey.space> References: <20240202101439.3714106-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::12b; envelope-from=baturo.alexey@gmail.com; helo=mail-lf1-x12b.google.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.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, TVD_PH_BODY_ACCOUNTS_POST=0.693, TVD_PH_BODY_META_ALL=2.546, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1706869002414100005 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 6bc338bd1f..89f10744a2 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -579,8 +579,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; @@ -593,8 +595,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; } @@ -1180,8 +1184,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->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->zero =3D tcg_constant_tl(0); ctx->virt_inst_excp =3D false; diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index f6be88dcf0..9d1d627d64 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -105,6 +105,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