From patchwork Fri Mar 16 19:41:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10289969 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 91504601A0 for ; Fri, 16 Mar 2018 19:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7806C29056 for ; Fri, 16 Mar 2018 19:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB1F29069; Fri, 16 Mar 2018 19:49:51 +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 0609729056 for ; Fri, 16 Mar 2018 19:49:51 +0000 (UTC) Received: from localhost ([::1]:59233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewvMM-0005Ct-65 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 16 Mar 2018 15:49:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewvFD-0007PD-73 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 15:42:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewvFC-0003kd-7E for qemu-devel@nongnu.org; Fri, 16 Mar 2018 15:42:27 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:44989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ewvFC-0003kJ-0u for qemu-devel@nongnu.org; Fri, 16 Mar 2018 15:42:26 -0400 Received: by mail-pl0-x244.google.com with SMTP id 9-v6so6503784ple.11 for ; Fri, 16 Mar 2018 12:42:25 -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=gm6LX102yVJ5D6WUBXFQ/+BvyBg7PRafi9xtelu/9D0E/SSb67PVa8ZtIYUXX2Kbzs IUzGTAI3liUeZb6qoYVlOpbnvhV6+baiiinIqYpU1npcNgRckRPVetOobuBLJL20poPs Ym08EvKQMJ+RmDOHQElXWkKAdGXpQnZmfQ8lVFWwQuuRiYssf6IrlFrNBcgMnInSCbgN UZpaEHxexM5nx1gfHVqP8TuqPlIX/PATyz5kXhCrTYlLVDdzAW9+futfsyg4MZ/fRpjx 9Q1Lc6UFpiTtxAJvy0zkaSuaN5JKAP4mUWb9DaYvLKSe56DfJaXEoLTwAfI+KJet9IhJ 4+pg== 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=EDwt6tEwSW7PLsUwetk7PRNftNYEGNwE0Kja7xcOKpZh65jFjIld7ILU+EAO4ogoi9 PP/XymO+XfwtUtYDJaNwfecgfL1ylXekoLhBKu3MXssX57i+gacN04Cl871YFQiL7MFX UQMyV2wHflhfFvu/nS6I4hLppS8VVb5KmKFTRg8R0gzDgy5bS/4Jx2n6mlUyWmiTbL6h W66IUtzAHIltiePUDy3VhhApIX2W95+lcXdv4F5yQIAj7KSu0V0OBD/w9e09Ngf/Ehj/ JKYLYZkEvIu8y2VyxCqI98OQe8iNsc0otHoqeOB7aBgErXmlyXvZENdYG2RvdLnBFCtw QOHQ== X-Gm-Message-State: AElRT7Gmplte2SYcWsigp4BZ3cKTB6R/DIqfcUQYcpRSsj9GclgvvMVK kCZiZkikRwvif/kELQkqukPkauUg7/A= X-Google-Smtp-Source: AG47ELvTl96lUOvsBHBVuAEc/Oa5bu/Y4QPzMzdVacxDXfwzE92sjIxdZBCCabfgJP97LaSQA3E1gw== X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr3323521pli.121.1521229344899; Fri, 16 Mar 2018 12:42:24 -0700 (PDT) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id k24sm13780469pff.77.2018.03.16.12.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Mar 2018 12:42:24 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 12:41:06 -0700 Message-Id: <1521229281-73637-10-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1521229281-73637-1-git-send-email-mjc@sifive.com> References: <1521229281-73637-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::244 Subject: [Qemu-devel] [PATCH v3 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);