From patchwork Wed Mar 21 20:46:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10300385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D0A2602B3 for ; Wed, 21 Mar 2018 20:55:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65E962842B for ; Wed, 21 Mar 2018 20:55:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5ACE429791; Wed, 21 Mar 2018 20:55:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C04CA2842B for ; Wed, 21 Mar 2018 20:55:21 +0000 (UTC) Received: from localhost ([::1]:57389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyklV-0000Wt-33 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 21 Mar 2018 16:55:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eykeN-00020z-Uu for qemu-devel@nongnu.org; Wed, 21 Mar 2018 16:48:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eykeM-00025o-Hc for qemu-devel@nongnu.org; Wed, 21 Mar 2018 16:47:59 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35550) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eykeM-00025T-BQ for qemu-devel@nongnu.org; Wed, 21 Mar 2018 16:47:58 -0400 Received: by mail-pg0-x244.google.com with SMTP id d1so2407409pgv.2 for ; Wed, 21 Mar 2018 13:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7CfZNEeH8cK/kvjsiUVLVgvJ07eCOI0ZWWcN6NTeFP4=; b=XcqcoDSDVMo8i6VZnk/gsTWC+BzLxzGAqBcg8EdUug0hIOA2ftLcJAc+IOV8oCgDWj St6p98WLdgzVfkFFMAJRK/leOUq6gPEBgRa18v8Fg+W5T4rI3mSwkasBM20IMxN1HEOz O8PdDSpE3caxFbpJg0J+g+maYUTs69HO5kjxT+sF/Jj2nmlQSz19p/tohk1bcVulcLOM 7IYjTqPveXrU4r5r0QQv7/G7zasVnLs7Gp9QvjfgUob/2tYaUYjV/OlWjJYFT+FIS3Gh zXkbMIJlil/ywBwyWl+/wBiRDMOl+qqb1y8noqLW+nrl8TtAiGNzEYbj2WjADtxUFN3T THag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7CfZNEeH8cK/kvjsiUVLVgvJ07eCOI0ZWWcN6NTeFP4=; b=WSLcNVshInIH3fEXpbK6X25vh40G88CzXNyDD8ol5Eykq6bS5LUlIjBKv4Yfd8QRV5 Zyk6X0vBch2pmpYaLpOqT9GX50tqI03D9gtcShaJo+CLjgzHlf12Q8kisulNDwrxpqPH UbAhVf3Imxzj1BHYl9uJbLMJ76e1MZNdrJbA/FCtgzAusSjlzxLTCLbX3O2ZA0cQtWCm CjTZLUtebzdR/018jG9KgvDkdrovd10RbGtU1nHsN+JRY8P9/3FZ6yEZIv6MBDqQVtaa 6/tqFqp2jDLkUAg58KxAtH1rID3B2inrwu1oRHLUdgyBOxMCRq3ZWrp6TNfrXteXR/95 i6Xg== X-Gm-Message-State: AElRT7HPOPK/S/1O2/uHSDDfbqIxCHK24roSquCxRHKO1tCG0W9y+M+Y wWwgvLiJp7iurWa3OZ6UFMYNFfO7NG8= X-Google-Smtp-Source: AG47ELsCvJ1ZHLIoz3RKo2MpVQIMYfi37h4YVzR4/dq4MuD/9vvN7k7hFatbPT2PtvPz7HT7nMdTdw== X-Received: by 10.101.71.202 with SMTP id f10mr15550132pgs.366.1521665277261; Wed, 21 Mar 2018 13:47:57 -0700 (PDT) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id w10sm8244499pgr.57.2018.03.21.13.47.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 13:47:56 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2018 13:46:45 -0700 Message-Id: <1521665220-3869-10-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1521665220-3869-1-git-send-email-mjc@sifive.com> References: <1521665220-3869-1-git-send-email-mjc@sifive.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PULL 09/24] RISC-V: Include intruction hex in disassembly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@groups.riscv.org, Michael Clark , Palmer Dabbelt , Sagar Karandikar , Bastian Koppelmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This was added to help debug issues using -d in_asm. It is useful to see the instruction bytes, as one can detect if one is trying to execute ASCII or device-tree magic. Cc: Sagar Karandikar Cc: Bastian Koppelmann Signed-off-by: Michael Clark Signed-off-by: Palmer Dabbelt Reviewed-by: Philippe Mathieu-Daudé --- disas/riscv.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index 3c17501..4580308 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -2769,25 +2769,6 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec) char tmp[64]; const char *fmt; - if (dec->op == rv_op_illegal) { - size_t len = inst_length(dec->inst); - switch (len) { - case 2: - snprintf(buf, buflen, "(0x%04" PRIx64 ")", dec->inst); - break; - case 4: - snprintf(buf, buflen, "(0x%08" PRIx64 ")", dec->inst); - break; - case 6: - snprintf(buf, buflen, "(0x%012" PRIx64 ")", dec->inst); - break; - default: - snprintf(buf, buflen, "(0x%016" PRIx64 ")", dec->inst); - break; - } - return; - } - fmt = opcode_data[dec->op].format; while (*fmt) { switch (*fmt) { @@ -3004,6 +2985,11 @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst) format_inst(buf, buflen, 16, &dec); } +#define INST_FMT_2 "%04" PRIx64 " " +#define INST_FMT_4 "%08" PRIx64 " " +#define INST_FMT_6 "%012" PRIx64 " " +#define INST_FMT_8 "%016" PRIx64 " " + static int print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) { @@ -3031,6 +3017,21 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) } } + switch (len) { + case 2: + (*info->fprintf_func)(info->stream, INST_FMT_2, inst); + break; + case 4: + (*info->fprintf_func)(info->stream, INST_FMT_4, inst); + break; + case 6: + (*info->fprintf_func)(info->stream, INST_FMT_6, inst); + break; + default: + (*info->fprintf_func)(info->stream, INST_FMT_8, inst); + break; + } + disasm_inst(buf, sizeof(buf), isa, memaddr, inst); (*info->fprintf_func)(info->stream, "%s", buf);