From patchwork Tue Aug 22 07:10:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 715683 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp117593wrp; Tue, 22 Aug 2023 00:11:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpUKxYYDWZBneX7guswKVvAHJFkT3wUVLAqmgX/NHgoWzYEophDcb24wC3H8fUsIUoAe0t X-Received: by 2002:a05:620a:951:b0:76c:b527:1e37 with SMTP id w17-20020a05620a095100b0076cb5271e37mr7841832qkw.78.1692688296544; Tue, 22 Aug 2023 00:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692688296; cv=none; d=google.com; s=arc-20160816; b=lnNiaZp3N3YztGmLv+YOy9k0ytwN1ti22Ns3zAv9X57kWvoY/YKR8aTQk1hsGqiw5p dny4YQo7XdnLNZ1YeJSSoehhLb1NCRI/G+wIB3AAx7ThTKRWA37s5slfje5HgGnGzSVw KLZO0K8l8D7Jo/SxWsQNwnPD+U+hlViQiF7h2yFkxOxwWX+DrbQ9EeEuZcYDrtuqZIMC ADBa3+MWH8pZtJRBs286UQaQoyl6KLeqJCrrHteVa0RVTBfROMzwnmVau39S+/GLDt5o JSLfKzqaguSfRrMhrlS+Zl3zu5GLpLnzTUJRxF+V5pD5Vww0JPvP6+AvSS518SFqzV/m Jo7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; fh=NllGK2Pi5KUwrZOc3u651axzgmY4RtLRhAAj1Uta+iI=; b=G4X3tz6khmPVI8oYTe6aePTKoWXknBNeCwWeqfMv2Yqk44X8jVJD61rRaYuKaSKolB ndHQat7UyPNehZo4AY+0aQA7fTxGHD1qQ2FggoZ5XAWyUpWvKA0vA6aeRuckepUGfmh3 L2DCxAka4Q0HvzuUzI5g3Dqyq6WoZF28ouuT9ICIkF14lRsvUxIakIxF2P3Os5kB6zlY 1kndOaCe8i7PafgWHJnn8gutvHKXZSv+wVeE5YE6p4qwTFEeGL9MTi9XsER9v9/kFH5p rIxibxGjDbV4obG4TIxdxgQ5eK/6hajlru4v05qzbGq6+G/PQQsIUV/v/FmX/SBxtvjL tH6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PacZu67N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y14-20020a05620a25ce00b00767d04f2884si5962666qko.625.2023.08.22.00.11.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 00:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PacZu67N; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYLY5-0003uC-06; Tue, 22 Aug 2023 03:11:33 -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 1qYLXt-0003LX-K5 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:27 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYLXo-0002Qt-Ia for qemu-devel@nongnu.org; Tue, 22 Aug 2023 03:11:18 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fe8242fc4dso41086205e9.1 for ; Tue, 22 Aug 2023 00:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692688274; x=1693293074; 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=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; b=PacZu67Nrm8q5JgiHQhA2mZ2Jbz2tdxzEeHbDXStFgxAoln6IqZHA3rDAvmFlG+fAb k2v8AIASlKiD/Da7V1ncbAl+VCWvfPcL+xkvIeJl83WzqY4m9rfgROVq23VWBqtsKJwE KRTiHXf39Kf+YKcBkaQknTjBlZQnw27+XJoYdfArlvFB7O4qXzndamDJX5vaqSBOrSRJ jG+ceW57SH/McuEzARsl2Jl7HtTuHeNEk91SVgXSZmZl8wcqZ65v+L6LB65o3qJrmnCU vEpOlxBEzWIz8VVV0AMQwsHRvP5nPzKQShAyHtoFO65maXJ1ED6VGiNKWUSnUo6Ah+4Q 3EJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692688274; x=1693293074; 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=7qFzQwheFK9AxDde5uR4/WWTrinK6kAcK+JYbJLTxP0=; b=ND9Q5PsA+TaqjNfCDsNu/V4kyOcomRquyykgp400vnctQ75QKVtBLKFoazPJUkB/Rx x1vichmxVeqMPwDbxcs762mp2/OKIt16gf02PdGAc/09hUsQrtR+Q9jElJ3ti3DunVox AFICZRIe9OtFtwc3gyFHEiVqEq0KyFSWy8cObVC23OhyeoCsJ4QUjp8Lo2pLMWoi5YtH S3bX+1D+65bbsCqsrWlmATTy8vu2yj2v2uytlqcqgsCV+w5Mm9j/474bjvXAjoOfpnC1 UP3JZNdm7OZzCa9WkpFr2MP5tQFKJBjzNcdMOv8XASnoqybqaCqhNMp06X9ikkUaJ2P4 GONQ== X-Gm-Message-State: AOJu0YxJqFZjkM/kpw9ADlxH0Lsw20EFnGIXWn/QGLjJyF3zw+hQl3PT oNqLC+iz+UV75fl9f6PGD9ZbQURLC2opu+BahlplxA== X-Received: by 2002:a1c:4b0e:0:b0:3fe:c7fe:206c with SMTP id y14-20020a1c4b0e000000b003fec7fe206cmr6556451wma.23.1692688274783; Tue, 22 Aug 2023 00:11:14 -0700 (PDT) Received: from localhost.localdomain ([37.19.214.4]) by smtp.gmail.com with ESMTPSA id e1-20020adfe7c1000000b0031b2c01f342sm8993223wrn.87.2023.08.22.00.11.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Aug 2023 00:11:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Song Gao Cc: Huacai Chen , Jiajie Chen , Xiaojuan Yang , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v5 09/19] target/loongarch: Truncate high 32 bits of address in VA32 mode Date: Tue, 22 Aug 2023 09:10:02 +0200 Message-ID: <20230822071013.34884-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822071013.34884-1-philmd@linaro.org> References: <20230822071013.34884-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen When running in VA32 mode(!LA64 or VA32L[1-3] matching PLV), virtual address is truncated to 32 bits before address mapping. Signed-off-by: Jiajie Chen Co-authored-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Song Gao Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20230822032724.1353391-6-gaosong@loongson.cn> --- target/loongarch/cpu.h | 6 +++++- target/loongarch/translate.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index e1562695e8..25a0ef7e41 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -445,7 +445,11 @@ static inline bool is_va32(CPULoongArchState *env) static inline void set_pc(CPULoongArchState *env, uint64_t value) { - env->pc = value; + if (is_va32(env)) { + env->pc = (uint32_t)value; + } else { + env->pc = value; + } } /* diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index 8b26555a27..9a23ec786d 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -86,6 +86,10 @@ void generate_exception(DisasContext *ctx, int excp) static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) { + if (ctx->va32) { + dest = (uint32_t) dest; + } + if (translator_use_goto_tb(&ctx->base, dest)) { tcg_gen_goto_tb(n); tcg_gen_movi_tl(cpu_pc, dest); @@ -212,11 +216,17 @@ static TCGv make_address_x(DisasContext *ctx, TCGv base, TCGv addend) { TCGv temp = NULL; - if (addend) { + if (addend || ctx->va32) { temp = tcg_temp_new(); + } + if (addend) { tcg_gen_add_tl(temp, base, addend); base = temp; } + if (ctx->va32) { + tcg_gen_ext32u_tl(temp, base); + base = temp; + } return base; } @@ -262,6 +272,10 @@ static void loongarch_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) } ctx->base.pc_next += 4; + + if (ctx->va32) { + ctx->base.pc_next = (uint32_t)ctx->base.pc_next; + } } static void loongarch_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)