From patchwork Sun Nov 6 21:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033592 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 41443C433FE for ; Sun, 6 Nov 2022 21:30:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCU-0005Lq-AR; Sun, 06 Nov 2022 16:29:06 -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 1ornCS-0005LK-I0 for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:04 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCQ-0004FE-Sq for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:04 -0500 Received: by mail-pf1-x42f.google.com with SMTP id z26so8975665pff.1 for ; Sun, 06 Nov 2022 13:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=gqX80AVODcxG/RhHKynAet5XMKQZScZhVL1xtE8ALDQ=; b=L5vnkJJWpzrROp0UGHSIv4JPL7/HaKTguRboWdf9IJqA/1XbxpqrhXqNQLBJ6CQ7Iq jjKbZry/2FH2CIm5dBUPLN5Us9JfXo0R/la/PepmyCMMJliaIi3/4SYXjg0IsM1e6BtM ejgqXEqXrbL5cxQfHsAfUL4TkgqgKjzs23aDAnUcTTjjaTPp3yUuZ4d4ukxcXViaYsZZ QnEgQnpsirDx8Qzc9agGEftLCujORo0aaKuolC5JKdwDHzqVmZl1kozFk9i5fwAAiWq2 RRszNejZMAjQqThpCTuD4KRuceGExXFlciJ69Wv3AugYpvY1GPUCAhwXb7FdFC4YyCeT EDig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=gqX80AVODcxG/RhHKynAet5XMKQZScZhVL1xtE8ALDQ=; b=8FSXhwLHcGnO2bqvuH0jHtd7S+qbmrK09GXE2tMx5LwcpUGxkeBrP9g+29fciSG5oW 3M9FPkumhnYWZ453ab8YqQhrmJlWUbxzvwjVEG6D40XpVzY+RRLeqKVtW5cNeMVZZ5l0 9ZhGlIhZA7fFxgF5Tcy7nG3WtyXrcSfKx9y3RDRg1vodPKD0OuPKwz6VEtQPCEdYTwLE TRoX+Ah77cMGbjtHnnebCdVHG37ZH/9k1hpI3d7DdqzBs4gQ6AwsYwbE8gYMtmJg9slc zcbBPyR6l53iF/GvlRJsb/8AbzcGe+zVlYHsKl1cXNpwEXZEgQ5BgjZTR8NsDowHDRQ9 0HrA== X-Gm-Message-State: ACrzQf3RfrAw427VwRvHaOkj6z1PfVviRxyMu34jFz3cxz3XQhPXzw9e bADs7Kg8pbl0xRBHlr8QhuChZpgvbwoigCPX X-Google-Smtp-Source: AMsMyM4g7lPu1448AvrqE64y6h1qp3acxaOoyU8PlKZxQgOhCiFsTAv/CYShXx78MY+ZVc5GME/SjQ== X-Received: by 2002:a05:6a00:1749:b0:56e:47b2:f0b with SMTP id j9-20020a056a00174900b0056e47b20f0bmr20219641pfc.68.1667770141611; Sun, 06 Nov 2022 13:29:01 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 1/6] disas/nanomips: Move setjmp into nanomips_dis Date: Mon, 7 Nov 2022 08:28:47 +1100 Message-Id: <20221106212852.152384-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reduce the number of local variables within the scope of the setjmp by moving it to the existing helper. The actual length returned from Disassemble is not used, because we have already determined the length while reading bytes. Fixes: nanomips.c: In function ‘print_insn_nanomips’: nanomips.c:21925:14: error: variable ‘insn1’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] nanomips.c:21925:25: error: variable ‘insn2’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] nanomips.c:21925:36: error: variable ‘insn3’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] nanomips.c:21926:22: error: variable ‘buf’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- disas/nanomips.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/disas/nanomips.c b/disas/nanomips.c index 9647f1a8e3..ea3e9202ac 100644 --- a/disas/nanomips.c +++ b/disas/nanomips.c @@ -21905,22 +21905,24 @@ static const Pool MAJOR[2] = { 0x0 }, /* P16 */ }; -static int nanomips_dis(char **buf, - Dis_info *info, - unsigned short one, - unsigned short two, - unsigned short three) +static bool nanomips_dis(char **buf, Dis_info *info, + unsigned short one, + unsigned short two, + unsigned short three) { uint16 bits[3] = {one, two, three}; - TABLE_ENTRY_TYPE type; - int size = Disassemble(bits, buf, &type, MAJOR, 2, info); - return size; + + /* Handle runtime errors. */ + if (unlikely(sigsetjmp(info->buf, 0) != 0)) { + return false; + } + return Disassemble(bits, buf, &type, MAJOR, ARRAY_SIZE(MAJOR), info) >= 0; } int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) { - int status; + int status, length; bfd_byte buffer[2]; uint16_t insn1 = 0, insn2 = 0, insn3 = 0; g_autofree char *buf = NULL; @@ -21950,6 +21952,7 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } else { insn1 = bfd_getl16(buffer); } + length = 2; (*info->fprintf_func)(info->stream, "%04x ", insn1); /* Handle 32-bit opcodes. */ @@ -21965,6 +21968,7 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } else { insn2 = bfd_getl16(buffer); } + length = 4; (*info->fprintf_func)(info->stream, "%04x ", insn2); } else { (*info->fprintf_func)(info->stream, " "); @@ -21982,27 +21986,15 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } else { insn3 = bfd_getl16(buffer); } + length = 6; (*info->fprintf_func)(info->stream, "%04x ", insn3); } else { (*info->fprintf_func)(info->stream, " "); } - /* Handle runtime errors. */ - if (sigsetjmp(disassm_info.buf, 0) != 0) { - info->insn_type = dis_noninsn; - return insn3 ? 6 : insn2 ? 4 : 2; + if (nanomips_dis(&buf, &disassm_info, insn1, insn2, insn3)) { + (*info->fprintf_func) (info->stream, "%s", buf); } - int length = nanomips_dis(&buf, &disassm_info, insn1, insn2, insn3); - - /* FIXME: Should probably use a hash table on the major opcode here. */ - - (*info->fprintf_func) (info->stream, "%s", buf); - if (length > 0) { - return length / 8; - } - - info->insn_type = dis_noninsn; - - return insn3 ? 6 : insn2 ? 4 : 2; + return length; } From patchwork Sun Nov 6 21:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033595 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 5FECBC433FE for ; Sun, 6 Nov 2022 21:30:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCY-0005NK-5m; Sun, 06 Nov 2022 16:29:10 -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 1ornCV-0005N9-Lk for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:07 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCT-0004FZ-Vu for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:07 -0500 Received: by mail-pf1-x42c.google.com with SMTP id q9so8959184pfg.5 for ; Sun, 06 Nov 2022 13:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=TEJwA4/1nvvScgj1A3FZC/cPQjc5wW51x5R4pumobJc=; b=XwwJC0Ahu9dW82bAQBKGuE2Gd1/stUT4CNZSv6aM5toXTuXaGGkaiodzHdN5yv1L/w uZ2OOQBpSjTrlRUqeNMNomIQJRHqqxTlp1yeLVZRRhmscypcar6IngxpRITZDjsUztRJ HTCFdTquHKUiphoJ6kULl+H9o+53pJMg39Imv+SoccOjrr8tpVeP8zM/TsZHSmNO65ER 1fWl+BYqPoYZa2dBgGGMc5kzzqkHla9x1SQd6nIE35/Kv1SZNVkVjqWBhdjtYQ71xKzS itqtUQY0q1JBFF4BklfjYB0lJ7uA5IJvA6/ojO2lBZgcGZmjiscYCUkSJZGj+WIcq9FF 3Z3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=TEJwA4/1nvvScgj1A3FZC/cPQjc5wW51x5R4pumobJc=; b=SU0+7/PSQjciakC+fIaK2NEHznXFHC6+E/Ik8Y2XxzInOAwnOT/1T8xqskRl0sMUL1 +d/8l0pLp2M3y/jW842otbVsQxsikjKcmi0q6+4VYBqIsAVCx8EQFiwyYeMGSCbNXsPL opeCS56+ySFN6iMMUqfM6sVlKz52tlgLc6+hrL5gB4hQcXw9+eCMXl2wvF8JLwkmFP2P de6I4U0nypCFMnBBn2L0y287Qbs+h4IRdD6YuQQG27WspdLgeFH/UVhnRAmERjrmJrxZ fyZ9lNpXOqb8zuK0lOIianbBq6V9x5IexZ+f9985ZPs5VzIvM02coUUw/lRyJG4inGbB NdAQ== X-Gm-Message-State: ANoB5pmyaByoZfjyxKk0F3PDt0R79/ntLBzAqVqKVw797j28/V03gtuO gPOQ9tymiNvsYi8qX9u0SObntz1/W7DY6pKd X-Google-Smtp-Source: AA0mqf72I5ytKFrYeQfi1txbsApj3Gj5MHzbcC2vdABU/0l5VuyKZ1uJfXDikSflGWgNAz12nUUdcQ== X-Received: by 2002:a63:550a:0:b0:470:71e2:132f with SMTP id j10-20020a63550a000000b0047071e2132fmr2763539pgb.614.1667770144637; Sun, 06 Nov 2022 13:29:04 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:04 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 2/6] disas/nanomips: Merge insn{1,2,3} into words[3] Date: Mon, 7 Nov 2022 08:28:48 +1100 Message-Id: <20221106212852.152384-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Since Disassemble wants the data in this format, collect it that way. This allows using a loop to print the bytes. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- disas/nanomips.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/disas/nanomips.c b/disas/nanomips.c index ea3e9202ac..1645d6d7aa 100644 --- a/disas/nanomips.c +++ b/disas/nanomips.c @@ -21905,26 +21905,22 @@ static const Pool MAJOR[2] = { 0x0 }, /* P16 */ }; -static bool nanomips_dis(char **buf, Dis_info *info, - unsigned short one, - unsigned short two, - unsigned short three) +static bool nanomips_dis(const uint16_t *data, char **buf, Dis_info *info) { - uint16 bits[3] = {one, two, three}; TABLE_ENTRY_TYPE type; /* Handle runtime errors. */ if (unlikely(sigsetjmp(info->buf, 0) != 0)) { return false; } - return Disassemble(bits, buf, &type, MAJOR, ARRAY_SIZE(MAJOR), info) >= 0; + return Disassemble(data, buf, &type, MAJOR, ARRAY_SIZE(MAJOR), info) >= 0; } int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) { int status, length; bfd_byte buffer[2]; - uint16_t insn1 = 0, insn2 = 0, insn3 = 0; + uint16_t words[3] = { }; g_autofree char *buf = NULL; info->bytes_per_chunk = 2; @@ -21948,15 +21944,14 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } if (info->endian == BFD_ENDIAN_BIG) { - insn1 = bfd_getb16(buffer); + words[0] = bfd_getb16(buffer); } else { - insn1 = bfd_getl16(buffer); + words[0] = bfd_getl16(buffer); } length = 2; - (*info->fprintf_func)(info->stream, "%04x ", insn1); /* Handle 32-bit opcodes. */ - if ((insn1 & 0x1000) == 0) { + if ((words[0] & 0x1000) == 0) { status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info); if (status != 0) { (*info->memory_error_func)(status, memaddr + 2, info); @@ -21964,17 +21959,15 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } if (info->endian == BFD_ENDIAN_BIG) { - insn2 = bfd_getb16(buffer); + words[1] = bfd_getb16(buffer); } else { - insn2 = bfd_getl16(buffer); + words[1] = bfd_getl16(buffer); } length = 4; - (*info->fprintf_func)(info->stream, "%04x ", insn2); - } else { - (*info->fprintf_func)(info->stream, " "); } + /* Handle 48-bit opcodes. */ - if ((insn1 >> 10) == 0x18) { + if ((words[0] >> 10) == 0x18) { status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info); if (status != 0) { (*info->memory_error_func)(status, memaddr + 4, info); @@ -21982,17 +21975,22 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) } if (info->endian == BFD_ENDIAN_BIG) { - insn3 = bfd_getb16(buffer); + words[2] = bfd_getb16(buffer); } else { - insn3 = bfd_getl16(buffer); + words[2] = bfd_getl16(buffer); } length = 6; - (*info->fprintf_func)(info->stream, "%04x ", insn3); - } else { - (*info->fprintf_func)(info->stream, " "); } - if (nanomips_dis(&buf, &disassm_info, insn1, insn2, insn3)) { + for (int i = 0; i < ARRAY_SIZE(words); i++) { + if (i * 2 < length) { + (*info->fprintf_func)(info->stream, "%04x ", words[i]); + } else { + (*info->fprintf_func)(info->stream, " "); + } + } + + if (nanomips_dis(words, &buf, &disassm_info)) { (*info->fprintf_func) (info->stream, "%s", buf); } From patchwork Sun Nov 6 21:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033593 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 66A1AC433FE for ; Sun, 6 Nov 2022 21:30:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCZ-0005No-TY; Sun, 06 Nov 2022 16:29:11 -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 1ornCY-0005Ng-Kg for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:10 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCX-0004Gq-1u for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:10 -0500 Received: by mail-pg1-x530.google.com with SMTP id q71so8816324pgq.8 for ; Sun, 06 Nov 2022 13:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=nk8lCwSmvBcjlSVkJj4h966ydBsW/gSF/eHtEZq0kPc=; b=hMJEoVgbZgClGshFsdYRkhdBv1qcspafZHSCdvuewqM/rWLjaCuYIqdC+zK3CEncPr 7WlHsFcpsbpkqQHTGaf8qJbGxbR9Uu7m4P4Zb8+Mehh3JZjoSNqtkk8cVQyN7N7lIB0s 1A801UJtyrjnRyTxgfcvxCyutnasnVL7KY9XqgEHRm99FbhglyYl6qPv6/XOOtTu7APW wqMxCZHzBbVoluzAJLLiBpbzAuD9TZjF/8hwzpUHSSXym20IHQykh+Fsp4A1cNGyg8Y8 WW9hyi5atXTE9l6IW2UbOgo46FWdrOgtp5/FWo2TyUWTHXrR94vTDgs8XALA2cRxyevN fPig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=nk8lCwSmvBcjlSVkJj4h966ydBsW/gSF/eHtEZq0kPc=; b=gZgGGZRbPR+NP4SH335wwb7CAegbT4pHh2VbNvtcbplmg+OprfzNWe0X5F80GQgZdG YU7ARxeQtRwiU1TLcK+B001f1hHyeD9FyPIBNS1L7TS0iPpWiMZksM5ePv5k+tnGU937 O8UCi1/PtblWjgbRlPihkpuVyzg9IlldyrcI5g9zL7oELzMoroKAkGPOL37xAFOAXU5I q2fRZr5OjMPVSZgFiS6xVJxQhXCAkbvB92/8fHVEkKuHFd+f1+fth9bvJgO+soZ5vqpN grB06aiXNmmeam7qYBRvcN20cNf/Rxc4oupxJO22V9Y9pEYJV+24o8dbWAjkk0rTZX0D stTw== X-Gm-Message-State: ACrzQf0nOd4RLW3ppOI/+Qr6FEAAe1keHkMXJ32fBmieoU5mvWSQq5E0 +mg0oV7J48Qq5nB0k02QrIRw2hQq3AwYVoKm X-Google-Smtp-Source: AMsMyM78MHMib8dpQMSbm5ZEvCsht6DnfZsP8UcQhMZz08zCak9kYyTLTcZZdX4EMhUoycVK8AXAZg== X-Received: by 2002:a65:6a0f:0:b0:46e:f67c:bcee with SMTP id m15-20020a656a0f000000b0046ef67cbceemr40587576pgu.38.1667770147558; Sun, 06 Nov 2022 13:29:07 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 3/6] disas/nanomips: Split out read_u16 Date: Mon, 7 Nov 2022 08:28:49 +1100 Message-Id: <20221106212852.152384-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Split out a helper function for reading a uint16_t with the correct endianness. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- disas/nanomips.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/disas/nanomips.c b/disas/nanomips.c index 1645d6d7aa..717fafb739 100644 --- a/disas/nanomips.c +++ b/disas/nanomips.c @@ -21916,10 +21916,24 @@ static bool nanomips_dis(const uint16_t *data, char **buf, Dis_info *info) return Disassemble(data, buf, &type, MAJOR, ARRAY_SIZE(MAJOR), info) >= 0; } +static bool read_u16(uint16_t *ret, bfd_vma memaddr, + struct disassemble_info *info) +{ + int status = (*info->read_memory_func)(memaddr, (bfd_byte *)ret, 2, info); + if (status != 0) { + (*info->memory_error_func)(status, memaddr, info); + return false; + } + + if ((info->endian == BFD_ENDIAN_BIG) != HOST_BIG_ENDIAN) { + bswap16s(ret); + } + return true; +} + int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) { - int status, length; - bfd_byte buffer[2]; + int length; uint16_t words[3] = { }; g_autofree char *buf = NULL; @@ -21937,48 +21951,24 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) disassm_info.fprintf_func = info->fprintf_func; disassm_info.stream = info->stream; - status = (*info->read_memory_func)(memaddr, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr, info); + if (!read_u16(&words[0], memaddr, info)) { return -1; } - - if (info->endian == BFD_ENDIAN_BIG) { - words[0] = bfd_getb16(buffer); - } else { - words[0] = bfd_getl16(buffer); - } length = 2; /* Handle 32-bit opcodes. */ if ((words[0] & 0x1000) == 0) { - status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr + 2, info); + if (!read_u16(&words[1], memaddr + 2, info)) { return -1; } - - if (info->endian == BFD_ENDIAN_BIG) { - words[1] = bfd_getb16(buffer); - } else { - words[1] = bfd_getl16(buffer); - } length = 4; } /* Handle 48-bit opcodes. */ if ((words[0] >> 10) == 0x18) { - status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr + 4, info); + if (!read_u16(&words[1], memaddr + 4, info)) { return -1; } - - if (info->endian == BFD_ENDIAN_BIG) { - words[2] = bfd_getb16(buffer); - } else { - words[2] = bfd_getl16(buffer); - } length = 6; } From patchwork Sun Nov 6 21:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033594 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 85763C4332F for ; Sun, 6 Nov 2022 21:30:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCc-0005OE-FX; Sun, 06 Nov 2022 16:29:14 -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 1ornCb-0005O5-9Q for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:13 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCZ-0004H2-Q5 for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:13 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 64so8833354pgc.5 for ; Sun, 06 Nov 2022 13:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=3Bsi7O4XbopriKhsn7dvJD59smiar5hTpndzOsD1Z28=; b=XCoCn7KPVr5DYq4coICw+BUCJI40y5m281F81X9xr+3XMjIkzuwLmT1qWYsz/EdQ5e TJy5HSLLBYoetiIyAOo/3hnVqWqfZzHzbLCd4STx2t+q5SRiNG4XZAES7VLW8VTaZtVW INOaKeZFlglvmUsbN2KEMR3eFLLNW2uObuYNiuohmBo263qnldZXjittwywW8vtlSJ37 ZmOVahmdQP/D9GAVMk5+z4gs/uTHIYI83FKOCV+Wd0pz2BwfVPBjPZasORztSrkhv8rT oXQ1JR/ifrKwB4GEhtXQxsaczWlz2D2tyG4/HQpP6IcGm/BQCGFtZCnSGhtM8ZwzQFdr B6VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3Bsi7O4XbopriKhsn7dvJD59smiar5hTpndzOsD1Z28=; b=UKsegaZByIoYVfVexwEgZybLVsBkVfyftrRjxJYTdKqBeOyeM6rtubJLkr3y992q/P U5x/NzoQ0b5roWFBwfdz6K/GG97cl+odM9m0eMYrWCqeiHyV3GAZOBklJl4hvhZ3xl5N 9CXUEwj3VqoJwq0so/XBkggOQjvq//j4hbtNWQ1Kl3/HUlNJ5Lzkyu6PdKoswG2xWuhg sEw7GUOU1wDlY2uBeu2e12PIZBqHGJ1nzK9oqPCgY1cQ7I9IZwyRexEsKAilkbDsrBJB MocOEp2en2ublVs2udVv2UNJS9LHoCjgryuR72VP8ZMdsfW9F4Qme7qk74y9dkpCmzZo 0W1g== X-Gm-Message-State: ACrzQf03wP2L1kKg/GWhCDG3YxxACUj1ZNXnhhVmvbztAp9FGA7VIXz9 iLx8IZ22I5AjnFVfe4ld02zdHRx0B31v5cyf X-Google-Smtp-Source: AMsMyM7os/cl2oU0ZzWhlloSw/x8KLYvQqZs9sJqJ4DlNGpRCacWKxG37kVABLstYUrRNWWY3JJc3A== X-Received: by 2002:a63:6b88:0:b0:46a:ff3c:b64a with SMTP id g130-20020a636b88000000b0046aff3cb64amr40019025pgc.196.1667770150520; Sun, 06 Nov 2022 13:29:10 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 4/6] disas/nanomips: Tidy read for 48-bit opcodes Date: Mon, 7 Nov 2022 08:28:50 +1100 Message-Id: <20221106212852.152384-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There is no point in looking for a 48-bit opcode if we've not read the second word for a 32-bit opcode. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- disas/nanomips.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/disas/nanomips.c b/disas/nanomips.c index 717fafb739..abc78ae165 100644 --- a/disas/nanomips.c +++ b/disas/nanomips.c @@ -21962,14 +21962,14 @@ int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) return -1; } length = 4; - } - /* Handle 48-bit opcodes. */ - if ((words[0] >> 10) == 0x18) { - if (!read_u16(&words[1], memaddr + 4, info)) { - return -1; + /* Handle 48-bit opcodes. */ + if ((words[0] >> 10) == 0x18) { + if (!read_u16(&words[1], memaddr + 4, info)) { + return -1; + } + length = 6; } - length = 6; } for (int i = 0; i < ARRAY_SIZE(words); i++) { From patchwork Sun Nov 6 21:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033596 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 950D9C4332F for ; Sun, 6 Nov 2022 21:30:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCi-0005Om-9J; Sun, 06 Nov 2022 16:29:20 -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 1ornCe-0005Oa-GP for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:16 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCc-0004HE-WA for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:16 -0500 Received: by mail-pj1-x102f.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so7942612pjs.4 for ; Sun, 06 Nov 2022 13:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=FPCwCw8NIdnDIzeLfwT3RMHDD1OYAbg9lFHMIclkLr0=; b=xsxD81F3co6t1744wLuAImhxF2P5jUTDyzKXYmVBhkWuwPk7ZeY0U4pz/wKoiHOpij PN5cvRZzBOM759ndi6WHEnnsG9m+mFcZAp9XKoZOxyg9CZpcsAbscjlxyDWsdfflmbhd vrdGxAq8xV4pirYmPgN0omw5baUYhqM3+ggXAfkLCe28Rgtn8Y5IQgU0xvM7dLwbGz4p YIPYawy/N3MvYT5NGA7YmQ/2AKGIfVkBIGCDVtjSzTLmrXfeMtKEO9mDmz5mfJkYJjWb hG9vmN7XHMSkvdllMTtpGJAWLDHLUkVPOi9KfMd8r949trMldEIIzoWgdaHWyjt/VBdY ehaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=FPCwCw8NIdnDIzeLfwT3RMHDD1OYAbg9lFHMIclkLr0=; b=I5y99v7POB2KGMtzj/FeX00B1NebL4TbdrdytJGikEUl5JIDPHgdaKxQz31qxQT90b wHxzqGkCD5ov5X5xPEfr7ueHBtKNCjv4TJ8S5Z2DJNCFCJkWQqGh/jaCxr4ffiTcf2Ki wPwRFr/72yeXtB1Nq2Xq6S1QDEPAm1T4yuoxAPsZO4KWJFlU9Oa9fCSZVY1m+cAjHqv2 8hslEOI4a4l3YqBDRSgyETPxPeWQzgh2j5fcNIty3Js5e1YCZELoblC9xUN+R1C7L5mf T7rpMuKqY+I0T45D0jdTAjhMBZZjvFOfdY1yTRFDHubu/uQaO7UIeSQ4QFWpOf5PeQLQ qE6A== X-Gm-Message-State: ACrzQf3y6lFkwfwfzKgwMHx1bALWa24rzT9/uu2DcPgU+GAh/a7qSZGH /ayuh0JZQr/XbMYVgchcMoTCeaaTExrLpnPi X-Google-Smtp-Source: AMsMyM6XeHRcLN5k6WaTMWaVU9mEZK7Q8Sib1oCSF8SaHf0Vf5i2gkfaYBUOUeVqf7at7MrXO00mjw== X-Received: by 2002:a17:902:f60b:b0:178:6a49:d4e3 with SMTP id n11-20020a170902f60b00b001786a49d4e3mr47640232plg.75.1667770153660; Sun, 06 Nov 2022 13:29:13 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 5/6] tcg: Move TCG_TARGET_HAS_direct_jump init to tb_gen_code Date: Mon, 7 Nov 2022 08:28:51 +1100 Message-Id: <20221106212852.152384-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 10 ---------- tcg/tcg.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 921944a5ab..9ee21f7f52 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -821,16 +821,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, trace_translate_block(tb, pc, tb->tc.ptr); /* generate machine code */ - tb->jmp_reset_offset[0] = TB_JMP_RESET_OFFSET_INVALID; - tb->jmp_reset_offset[1] = TB_JMP_RESET_OFFSET_INVALID; - tcg_ctx->tb_jmp_reset_offset = tb->jmp_reset_offset; - if (TCG_TARGET_HAS_direct_jump) { - tcg_ctx->tb_jmp_insn_offset = tb->jmp_target_arg; - tcg_ctx->tb_jmp_target_addr = NULL; - } else { - tcg_ctx->tb_jmp_insn_offset = NULL; - tcg_ctx->tb_jmp_target_addr = tb->jmp_target_arg; - } #ifdef CONFIG_PROFILER qatomic_set(&prof->tb_count, prof->tb_count + 1); diff --git a/tcg/tcg.c b/tcg/tcg.c index b43b6a7981..436fcf6ebd 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -4228,6 +4228,18 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start) } #endif + /* Initialize goto_tb jump offsets. */ + tb->jmp_reset_offset[0] = TB_JMP_RESET_OFFSET_INVALID; + tb->jmp_reset_offset[1] = TB_JMP_RESET_OFFSET_INVALID; + tcg_ctx->tb_jmp_reset_offset = tb->jmp_reset_offset; + if (TCG_TARGET_HAS_direct_jump) { + tcg_ctx->tb_jmp_insn_offset = tb->jmp_target_arg; + tcg_ctx->tb_jmp_target_addr = NULL; + } else { + tcg_ctx->tb_jmp_insn_offset = NULL; + tcg_ctx->tb_jmp_target_addr = tb->jmp_target_arg; + } + tcg_reg_alloc_start(s); /* From patchwork Sun Nov 6 21:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13033591 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 522D0C43217 for ; Sun, 6 Nov 2022 21:30:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ornCk-0005PK-PZ; Sun, 06 Nov 2022 16:29:22 -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 1ornCh-0005Or-Hh for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:20 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ornCf-0004HV-W2 for qemu-devel@nongnu.org; Sun, 06 Nov 2022 16:29:19 -0500 Received: by mail-pj1-x1033.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso12770700pjg.5 for ; Sun, 06 Nov 2022 13:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=ThIdcirnoAwmtpHe6z2EOBTDBtvtEBFVSHhE8OUgyu8=; b=l4++2rv8XoZogRWLSfdBHoELULz8zS57aTyDAQLFrKz1Mk5EC958E5eAg8KT21TVJ1 ry4u06edvo2PgYxHMMXZd17u2n/VEtd8/LtiNAKtzH5FmnJpOHaJvovq3lDY/qchshkN F9VpibntI3GGD8/OuhW0aGnvEVf5Z4m9F2MbBB3IwA8GkHTSId02TuZu+lrfx7B7rslk G/T0T94zVcK8IbnycYI7w/V/lS+RqtQp2tvV0OqcTmCY5x7bHQ8wtAL2FwZPqf2SaOwB 9txbClTDBR/Dlo765Bvrnh9bnietMr+/M3kuLbxCy72Yu94vpdjEGs48DVh8vmh67mXR ECnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ThIdcirnoAwmtpHe6z2EOBTDBtvtEBFVSHhE8OUgyu8=; b=SoNQK/1m7ZK/gx+ulVYLEyRB0zAjGTyZ4/tkT02aWN7iS2kk/T/59BR+PjIGa8+SF5 +cAWynDpgMa4XWDrmS90Gpm+i0k4nGnvjgJGE2Z4ktH1z+9ADMOO4AlzOWSf3y+99hf0 I7mXv4wTCKMNfqWDFAcAie65SRZnpt8Yc8UBU8efmSPomtp+jN22SJqfeZ/EfO2vrKPC UN22gIsqhz+Dziqv16qXFXF7nYw6YUq96wAY0usIkcoWCdQp1xyC5Ak5EC/zwdA1Ovln N3Vq7+TEyUOSSCceOwNlfpPNfq5xgnWSfCgPZO5o06A1zBYkIQwRZs0uILO+Ohk8XwMr 10DQ== X-Gm-Message-State: ACrzQf2gno8mPOkAQtWOgZa85bxCeLMf7NciU5tmPDvqWln8uwOS7PCm En0Q8ObMKb8ieCDliS+22GBWszXzl6KuOvMN X-Google-Smtp-Source: AMsMyM5uxR4hxGhIZQtztaif2mmAN2f7rDDFiuDueMjZi39RrbiWhSJV2EuZOjpw0OJ5WYN6XOaegQ== X-Received: by 2002:a17:90a:b00d:b0:212:f91d:88c7 with SMTP id x13-20020a17090ab00d00b00212f91d88c7mr48346462pjq.112.1667770156725; Sun, 06 Nov 2022 13:29:16 -0800 (PST) Received: from localhost.localdomain ([2001:8003:d918:7a00:f28:fa55:3b51:3624]) by smtp.gmail.com with ESMTPSA id 20-20020a621914000000b00563ce1905f4sm2998746pfz.5.2022.11.06.13.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 13:29:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: balaton@eik.bme.hu, philmd@linaro.org, sw@weilnetz.de Subject: [PATCH v2 6/6] accel/tcg: Split out setjmp_gen_code Date: Mon, 7 Nov 2022 08:28:52 +1100 Message-Id: <20221106212852.152384-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106212852.152384-1-richard.henderson@linaro.org> References: <20221106212852.152384-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Isolate the code protected by setjmp. Fixes: translate-all.c: In function ‘tb_gen_code’: translate-all.c:748:51: error: argument ‘cflags’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 58 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 9ee21f7f52..ac3ee3740c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -742,6 +742,37 @@ void page_collection_unlock(struct page_collection *set) #endif /* !CONFIG_USER_ONLY */ +/* + * Isolate the portion of code gen which can setjmp/longjmp. + * Return the size of the generated code, or negative on error. + */ +static int setjmp_gen_code(CPUArchState *env, TranslationBlock *tb, + target_ulong pc, void *host_pc, + int *max_insns, int64_t *ti) +{ + int ret = sigsetjmp(tcg_ctx->jmp_trans, 0); + if (unlikely(ret != 0)) { + return ret; + } + + tcg_func_start(tcg_ctx); + + tcg_ctx->cpu = env_cpu(env); + gen_intermediate_code(env_cpu(env), tb, *max_insns, pc, host_pc); + assert(tb->size != 0); + tcg_ctx->cpu = NULL; + *max_insns = tb->icount; + +#ifdef CONFIG_PROFILER + qatomic_set(&tcg_ctx->prof.tb_count, tcg_ctx->prof.tb_count + 1); + qatomic_set(&tcg_ctx->prof.interm_time, + tcg_ctx->prof.interm_time + profile_getclock() - *ti); + *ti = profile_getclock(); +#endif + + return tcg_gen_code(tcg_ctx, tb, pc); +} + /* Called with mmap_lock held for user mode emulation. */ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -754,8 +785,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, int gen_code_size, search_size, max_insns; #ifdef CONFIG_PROFILER TCGProfile *prof = &tcg_ctx->prof; - int64_t ti; #endif + int64_t ti; void *host_pc; assert_memory_lock(); @@ -805,33 +836,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti = profile_getclock(); #endif - gen_code_size = sigsetjmp(tcg_ctx->jmp_trans, 0); - if (unlikely(gen_code_size != 0)) { - goto error_return; - } - - tcg_func_start(tcg_ctx); - - tcg_ctx->cpu = env_cpu(env); - gen_intermediate_code(cpu, tb, max_insns, pc, host_pc); - assert(tb->size != 0); - tcg_ctx->cpu = NULL; - max_insns = tb->icount; - trace_translate_block(tb, pc, tb->tc.ptr); - /* generate machine code */ - -#ifdef CONFIG_PROFILER - qatomic_set(&prof->tb_count, prof->tb_count + 1); - qatomic_set(&prof->interm_time, - prof->interm_time + profile_getclock() - ti); - ti = profile_getclock(); -#endif - - gen_code_size = tcg_gen_code(tcg_ctx, tb, pc); + gen_code_size = setjmp_gen_code(env, tb, pc, host_pc, &max_insns, &ti); if (unlikely(gen_code_size < 0)) { - error_return: switch (gen_code_size) { case -1: /*