From patchwork Mon Mar 19 21:18:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10295221 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 92431602C2 for ; Mon, 19 Mar 2018 21:27:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8105D28503 for ; Mon, 19 Mar 2018 21:27:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 755EE28541; Mon, 19 Mar 2018 21:27:53 +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 C98F028503 for ; Mon, 19 Mar 2018 21:27:52 +0000 (UTC) Received: from localhost ([::1]:44019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ey2Jr-0000F9-Lp for patchwork-qemu-devel@patchwork.kernel.org; Mon, 19 Mar 2018 17:27:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ey2C8-0001Lq-0g for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ey2C5-0002d6-N9 for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:51 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:44798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ey2C5-0002cf-HA for qemu-devel@nongnu.org; Mon, 19 Mar 2018 17:19:49 -0400 Received: by mail-pl0-x243.google.com with SMTP id 9-v6so11041186ple.11 for ; Mon, 19 Mar 2018 14:19:49 -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=ZMCnOeSvrIWHNKVUdDoVss6J/c2tZseccPQIBgJAXM1gBxd+N/mqrBKLa2ye8z68OS cOfJ1QMbwIUvW1Wkiz/u69d2N+EBKrR5n02sVjS4r7p5qjLfkqyyffN1u64B8xeAnCWN yg6GTQ0SWUGWekXNwhb5hE0kVZudrNlvCV+osZH7mH4YcvjB6QlAkOO8ni2PwmKGmeph 3sIwfvaKeowe8JdLC3JkqqyHa9h4xrbK4FSGQvpaOKZ0SUq5CAlPBewK6TJSGj98c3kv cvMrx4a+1NpQytjVZPP1vu7dfIjWlbVXAR/3pu6rGSoz5u7qyYxk6ToMsxn+QueQAfNS jPog== 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=nGQfNDBZDmDyTveBUqYwSoPAM9k/cC5o+HO0tGIesacYP9nhpRGGe3mjZxm2I4MpYS hHaRTjw1O2+IUA64PxN4hsUPQkDBWJMi/R9kqyePuKGCz1XQfSO6KijZ6xw7jj3xFQUm a2KUEyVQN4DCLosRFvs+6gaCzVB5CzeUaOfmiadTJY6VQAeBDW+opRCQk9GvCZUkm2nE 81/YX7q4PVJz7G6sBAcgr0FXIer7kmOyn2mxKakHIbMtZCMHZ21IECeJwKbQaSopH3fB 1tjGsHwvsk65pYx3RYiciRhw5o5KiC+Iysg86j7CVVRPAdWhts2WgEuKaaKHjL7TtRXB Qfbg== X-Gm-Message-State: AElRT7GTc3xQw71+OLAnLcVffD1DAcB9kjDdYQ2642oabyU0MU4k3sbO oqWS95HMh1wUp2KEKbAXI23PgDzAYa4= X-Google-Smtp-Source: AG47ELvY6u2Ed1kahvCovW+RD+w5Ay/1Ft1b5dbFdvE8GW6IjcDHg8gXATTzELfPKwbo9wyTyKz1pw== X-Received: by 2002:a17:902:b704:: with SMTP id d4-v6mr14093173pls.406.1521494388702; Mon, 19 Mar 2018 14:19:48 -0700 (PDT) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id i127sm120500pfc.136.2018.03.19.14.19.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Mar 2018 14:19:48 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2018 14:18:32 -0700 Message-Id: <1521494329-19546-10-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1521494329-19546-1-git-send-email-mjc@sifive.com> References: <1521494329-19546-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 v4 09/26] 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);