From patchwork Wed Apr 25 23:45:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10364381 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 8EB2260249 for ; Wed, 25 Apr 2018 23:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EDFB28E38 for ; Wed, 25 Apr 2018 23:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73B7828FC2; Wed, 25 Apr 2018 23:54:37 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 EC03928E38 for ; Wed, 25 Apr 2018 23:54:36 +0000 (UTC) Received: from localhost ([::1]:39583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBUFA-0002JI-4G for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 19:54:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBU8I-0004cv-QC for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBU8H-0004rl-BQ for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:47:30 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:38688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBU8H-0004rP-4k for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:47:29 -0400 Received: by mail-pg0-x243.google.com with SMTP id n9so1676077pgq.5 for ; Wed, 25 Apr 2018 16:47:28 -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=+gQDe54xbeQIlSTVCU8aoj7idznrE6YbfBy5zus04hQ=; b=QbNJ0zBF+gq6ax6HTbLrRDtHJj/pcVQ/m+ljq0TuSK/CQO2dHiYP2FXLGVEs14WlOq QCw5oBfa/IQ37G5Pn6f/rsHUqTR1XI7FUknsZgu+kkGkmABkq5m0BgOuAPd5Ba4hYseF bO0qFvEiEQ8H9y4v5+eeXw3Vyjbad7O/Z/YwBWkHlHkAIa6Up1gClTjVXmSHgqZwvprU 2K4D7ZWCFV5zoq/EybGpIgdIVR1URcnCofroiWiihXIq/hzftsD2+ybnnVP1K7FIEO5T UQlLdyO2738e9cL0kA8HDmXo7UqMWXh4j77QnbQPDbYbL95m6/adY7XM8169bqBJ5jlP bHmw== 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=+gQDe54xbeQIlSTVCU8aoj7idznrE6YbfBy5zus04hQ=; b=Vp1y+QczPkJiNwLl8neT4ecUZ/knwYv6834oFlh6Crp1lQwS9lNR+SmLmu8OdpkyRT FwOKBgAM1I/s/RSSIX4v7zoIm+AaqAQ/UYQIOS35xMTKhPfg1bX+ZlIyGM3PpPCXmZEe kBZkR8EP8qgeG/O913SQVpYQtqVMsJL15LFvBWmOXkD88Mcyy7Ij7n+DXmjeXZ8cxrpe p8SeDAOFJBwPK+aG/jD2OXz3komm6EGeIjSSiWAOYQ1u5M7uqM5BixfROxAJyu3XWeKa ZH+2ydcGDU4+d+BEwxMbD6Pi2IXpM91gZr8UN/diS34BCrtod+/0UnwV7mVeYgSUwv5U gBMw== X-Gm-Message-State: ALQs6tAlafWYAUeyWnI365AP3KaCNHaMqEj6Ek6S5whV4HO225LZEbcn iRKf31Vupj60dQVwZgvtAH63JgNGHoo= X-Google-Smtp-Source: AIpwx4/OTSZ9jddt1pfj0mH48dBs2q9yeyofEnNN5xBWyG2Z47rQeAhAhDycLmN67M18fjCHSx+87w== X-Received: by 2002:a17:902:67c2:: with SMTP id g2-v6mr31199784pln.93.1524700048074; Wed, 25 Apr 2018 16:47:28 -0700 (PDT) Received: from localhost.localdomain (122-58-167-38-fibre.bb.spark.co.nz. [122.58.167.38]) by smtp.gmail.com with ESMTPSA id e10sm29577549pfn.67.2018.04.25.16.47.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:47:27 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 11:45:09 +1200 Message-Id: <1524699938-6764-7-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1524699938-6764-1-git-send-email-mjc@sifive.com> References: <1524699938-6764-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::243 Subject: [Qemu-devel] [PATCH v8 06/35] RISC-V: Include instruction 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é Reviewed-by: Alistair Francis --- disas/riscv.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index 74ad16e..2cecf0d 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);