From patchwork Fri Mar 9 04:12:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10269635 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 1DE28605CE for ; Fri, 9 Mar 2018 04:19:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1448C29BE3 for ; Fri, 9 Mar 2018 04:19:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0947A29C18; Fri, 9 Mar 2018 04:19:10 +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 9A5C129BE8 for ; Fri, 9 Mar 2018 04:19:09 +0000 (UTC) Received: from localhost ([::1]:43114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu9Uq-0007ct-OO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Mar 2018 23:19:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu9QW-00049e-F5 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eu9QT-0006wt-8O for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:40 -0500 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:39667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eu9QT-0006wb-35 for qemu-devel@nongnu.org; Thu, 08 Mar 2018 23:14:37 -0500 Received: by mail-pl0-x243.google.com with SMTP id s13-v6so4604024plq.6 for ; Thu, 08 Mar 2018 20:14:37 -0800 (PST) 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=Rt+5EDskjhlvX3XLPo5a7vXgNZHhmZAu5XzRT1pZgakSVrPoWep0g7YZO4mz2BjLCw QERha/3R+yYWevQ6ISlSwWwWm5eyaY1D2nZk2gV9PbIYHWiD7kYljcv3JoqKo3NotX3Z pdGHwo/c5zUL0M4Ww/DScmgRvvd42ZgYHbc0vpbXbE+kfhltK1pTMEuCkTf6jQytWtny 59yig96e8dWTn9dYl/5O/43mMzBJMM2UwYmdfWaR5VagBI/OAeQRw7KuLz7TTKsnPZhT z6q3okPBExlDUhz1/5RZ7FN43x58ZmcI8tMiDAGbFl5xyI6lMfA0jeDhjL2tMtdRsIPe dDfg== 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=ZR5P1J2apAeG1jh51vadv4Z9Pcy433rs9Cw2sHd/vSSm51/CTiv3nC+5f3xmeGL8NW MOY47oaS6rm4sV/1xVqljT/SAyw89pR7DslWhY5/BjUeqldW1iTRYfp+3kqRQadZPgFT PC0yGR4As1JdoQJ0TmrSVL80kjhJD2+qKe6envdbLHgIF1WX4KHj9mmi9AiVRqtOthnj ttqlhrhnViNok5zda9cz/dP2PkanapJK4HIk9/0IrH8XH3uVcHljO98oSmLz0Nf+zvk2 rRRWhU/8mOQzkcqIPQR8ojkc1XAWNKxeqGpQ7+P//Jax8x0eejTJqAhIhxHq6qGujkmU z+dw== X-Gm-Message-State: AElRT7EcEWdBplN/HP0y8gQ0tB9Gy1WGH9jrF89InqTQAlNFsNO6InJb 3F00bHJhY7qivpYefH5CesNdJyoW5Ks= X-Google-Smtp-Source: AG47ELsMOUgxQEySvGhGqi6iB1Rlp6euKpuz+GuxUYErjJ0z6YMfqkNEsqNMrkB09dXaHJ+mlCvWtA== X-Received: by 2002:a17:902:8341:: with SMTP id z1-v6mr2875219pln.386.1520568876108; Thu, 08 Mar 2018 20:14:36 -0800 (PST) Received: from localhost.localdomain (125-237-39-90-fibre.bb.spark.co.nz. [125.237.39.90]) by smtp.gmail.com with ESMTPSA id h15sm334141pfi.56.2018.03.08.20.14.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Mar 2018 20:14:35 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Fri, 9 Mar 2018 17:12:31 +1300 Message-Id: <1520568765-58189-10-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1520568765-58189-1-git-send-email-mjc@sifive.com> References: <1520568765-58189-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:c01::243 Subject: [Qemu-devel] [PATCH v2 09/23] 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: Bastian Koppelmann , Michael Clark , Palmer Dabbelt , Sagar Karandikar 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);