From patchwork Sat Sep 24 22:13:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12987826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43268C07E9D for ; Sat, 24 Sep 2022 22:14:59 +0000 (UTC) Received: from localhost ([::1]:32960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ocDQI-0005hY-22 for qemu-devel@archiver.kernel.org; Sat, 24 Sep 2022 18:14:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocDPJ-0004Z6-Qy for qemu-devel@nongnu.org; Sat, 24 Sep 2022 18:13:57 -0400 Received: from mout.gmx.net ([212.227.17.22]:46055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocDPE-0008OU-V4 for qemu-devel@nongnu.org; Sat, 24 Sep 2022 18:13:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1664057630; bh=glL2oKbyCalCbQdc6Ns11sOFkCFrYp5s1DYoXdmGg5k=; h=X-UI-Sender-Class:Date:From:To:Subject; b=Sjs/BiQPkOAP9WcoTMXy+eIgPYK9SiM6kKQ6dQmzkVYi6dJ5S47uJxcui+ENmOa2R FjGTmHWxsbNnlFmbY+heA0RFzBJsrvMx8uH8PW5iLUYQrRjIp4nkpYHQTp58Ph4mOg FpbmDxY84U6yzaXt+GbSq7GaoeGMXR+DmGarBHZk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100 ([92.116.155.187]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MJVHU-1orgxB3kuO-00JuKO; Sun, 25 Sep 2022 00:13:49 +0200 Date: Sun, 25 Sep 2022 00:13:48 +0200 From: Helge Deller To: richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PATCH] target/hppa: Generate illegal instruction exception for 64-bit instructions Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Provags-ID: V03:K1:fnULbI002Rf4n4x3z76/wa9cO3LHf2S9MmLstxTsZQJCAzs29TF vVVFql4xZDZTz8n0eOT79wse4geWnSDIsUBkpZDiw3KIBMmg4abat7wgV+tHz1tPvwqcPJX sXBt2cQ3q6Rvk8JFSmIWPzCM58R6AWsZTz20QBOdIy/PE9xJEGS2Ni54zhSosHy1ZfEPijC KKEyNSWITX0BGFUbl1wHQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:GcMc6AhAaq8=:RypzgO5kWoLdh1sjy8aTuk s6MouGbU3nNEL2I/xo5HaH8uBxMiLwjU2gZQrV/gQ/UuA1cxmkfgmjJOoR2SCbva4jT1exq0Y nvRYSJ01TP/pFCPGu3pnWP6D1jvYqZ74Dcblnm3xSEUr07Ff9c9Iwn9nDmW2aCTdwIrZelfcV ILSsgWyKD8t7GTYWzkagGNgNRAikBAPoCzUOUFfPy4z7ISOvOI66mGH/2lkh8kdreUb+04P2j Or7ocB3/ZNOzz4gYr/DwvvzHZ68XWbM+ZM+1So8N46v/mHTT+42oJxl58MZ4Je3DxNSqBvcib xebPjrP1FKwsIjmHyFnQlGcrLp8h5nCWHWjcq0Fik/sItH2g8lOMQCj2k6EuOJm9yfUx2vRQa MhfsEpbpJYLdHzRcgperwoPNcPpZwI3cX4FCMODNSpSLdY2P7t1wMXaLRTOMjNpp1n5v8tv34 xv0MBSPJjoQ7tzwH/L7gRQtFOieL8N/+vzLI1MmWkXuReGAQlKymE8QatPmt3sd8XXWmNSOdT OTY3TeUCrO9cWoLKiWG01OSNbZ8CCLcebqangnEbvF7IVl4af9tmolwShCrNp7AjjQwAA6Kfd p3m9LijMIbyu61icYY79+ImicCzo6cx+M6uj3h8gFP+OEKisaS7jvR9x0j41yRxR0qt9Rkr52 us2gkQC3lkFK81u+VlgdK19X8ReExY2CFaBbpyALcTRC7X4XRRgdLRtF4tTExsZOw6G8l0rsk WPqJx/xMKrEYjINxxEDtgULU+6fr07JvtWN8ygqxOrtDpQCd5SbCaNOTKt8WMlPTrKM5Q7v0x APgJE03VC91XDgZ+h6RxWZCIxqpC3sXyQDVc5afkjmt/WObqhnZ78Nv4OJ0MEVkKvVKsNZn1u knUMybjlO2J8JEx0jqc7n4e4bsQQkw4fjwBopgCWhMdrgV7YqXDMMR5sbUCI/t0zxFU2n9LDT OtSWts7yWCyCs0Vr7cyv00npu+dAcW5olY5L6H9X2klQsMT3zABh/jpCbl99gW2mJdRJgEfVR 5SmD2JC6LytJ5tx5SCtoeaxmRWlF8GbGNB0FhCVMuLZk5XqRVGdlmo0bMCDHm1XvFcYSrW9J+ 9myc4lwEetWTLTx3GWC/KecDsH1y/I0eKbvYEaX96PdhYWjSIjsc59kr1Y5td49ICFbMcg7ps pxPNm53vCm0xrBOPGzEqbguhCy Received-SPF: pass client-ip=212.227.17.22; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Qemu currently emulates a 32-bit CPU only, and crashes with this error when it faces a 64-bit load (e.g. "ldd 0(r26),r0") or 64-bit store (e.g. "std r26,0(r26)") instruction in the guest: ERROR:../qemu/tcg/tcg-op.c:2822:tcg_canonicalize_memop: code should not be reached Fix this by adding checks for 64-bit sizes and generate an illegal instruction exception if necessary. Signed-off-by: Helge Deller diff --git a/target/hppa/translate.c b/target/hppa/translate.c index b8dbfee5e9..287cc410cd 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -1568,7 +1568,12 @@ static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, /* Make sure if RT == RB, we see the result of the load. */ dest = get_temp(ctx); } - do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop); + if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) { + gen_illegal(ctx); + dest = tcg_constant_reg(0); + } else { + do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop); + } save_gpr(ctx, rt, dest); return nullify_end(ctx); @@ -1631,7 +1636,11 @@ static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, int modify, MemOp mop) { nullify_over(ctx); - do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); + if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) { + gen_illegal(ctx); + } else { + do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); + } return nullify_end(ctx); }