From patchwork Mon Jan 16 07:38:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13102701 X-Patchwork-Delegate: palmer@dabbelt.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A207CC678D6 for ; Mon, 16 Jan 2023 07:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LvSUjEZxL8Cv22ogiXWCnlfuXgM+FUepV+Pz/zhBCqQ=; b=AXlPs/XkfGQZmg Ur4WbRcKrxBNYqrZlZjbyT6s/pCsrBY5DqL/CeLSmvtt/mf189IU8XOjfmjxAUgNKtNlKjFT6RaIn cad0hZQ78QiuLlO7qhkoGp7deCyQFSIH3zo3ApdoMrdAX3IRUqhMxy/+sd1du6h7HnTQp0gXWAGPF rsqvmjCsSHPdqB6fAmx8bmleivO2p1XGCv6IBXGsKayr2UdiRQI0BHwVYXhxAj3o0SBvrUCtgbvXK TsHk0AO5W5VxT1w9usPKDpsnZZsdxV88P/LSITLpY4IMc2rlG5XiyuFGBp7oOeUJ2LI4aF6K35V93 x8xMK3ioc4itv9WtHPBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHK5C-0090ln-OH; Mon, 16 Jan 2023 07:39:06 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHK59-0090jR-B8 for linux-riscv@lists.infradead.org; Mon, 16 Jan 2023 07:39:04 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E5C260EB6; Mon, 16 Jan 2023 07:39:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D8E5C433EF; Mon, 16 Jan 2023 07:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673854739; bh=PBE0PpRXIlt2qCDFtsjgADfP4kD6JxkZrkUXxW7Tmuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a0KS4Som77Rg8W9H4kxDYF8K/8s1ZXqdHiwy5QKfjFXMKjjnP3Wfj6Mprg6eePZoK kwSWMB6qR4dw8LL3oK7mBpskdaaabxaC3aRc92oh866vejtqph36qGUvLRmh4ZPqTL ShJVLQh1AstWDoVGeqPaydfXBaHcl2zbcDOXuiH6jc7eI0vaY6RjIqb74dyKHWv3ja QnbDoj4hcEljYRDncvDOVhoMLoS3V4o4mfvUSlKQdcaPtE1p7CZwNTzPLzBpft2qy8 Uj4WvlnIBC0OWDtSlrpnKBP0f0ewUYKC8aF2xUKi0JuVKiSxEk6GjQVXNKHUfSWp0T 3/W7lPGAJjL7Q== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Andreas Schwab , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] scripts/decodecode: Add support for RISC-V Date: Mon, 16 Jan 2023 08:38:34 +0100 Message-Id: <20230116073834.333129-3-bjorn@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230116073834.333129-1-bjorn@kernel.org> References: <20230116073834.333129-1-bjorn@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230115_233903_506322_144731AB X-CRM114-Status: GOOD ( 12.90 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Björn Töpel RISC-V has some GNU disassembly quirks, e.g. it requires '-D' to properly disassemble .2byte directives similar to Arm [1]. Further, GNU objdump groups RISC-V instruction by 2 or 4 byte chunks, instead doing byte-for-byte. Add the required switches, and translate from short/word to bytes when ARCH is "riscv". An example how to invoke decodecode for RISC-V: $ echo 'Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7) 6140' | AFLAGS="-march=rv64imac_zicbom_zihintpause" \ ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./scripts/decodecode Code: bf45 f793 1007 f7d9 50ef 37af d541 b7d9 7097 00c8 (80e7) 6140 All code ======== 0: bf45 c.j 0xffffffffffffffb0 2: 1007f793 andi a5,a5,256 6: f7d9 c.bnez a5,0xffffffffffffff94 8: 37af50ef jal ra,0xf5382 c: d541 c.beqz a0,0xffffffffffffff94 e: b7d9 c.j 0xffffffffffffffd4 10: 00c87097 auipc ra,0xc87 14:* 614080e7 jalr ra,1556(ra) # 0xc87624 <-- trapping instruction Code starting with the faulting instruction =========================================== 0: 614080e7 jalr ra,1556(ra) [1] https://sourceware.org/bugzilla/show_bug.cgi?id=10263 Signed-off-by: Björn Töpel --- scripts/decodecode | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/decodecode b/scripts/decodecode index b28fd2686561..8fe71c292381 100755 --- a/scripts/decodecode +++ b/scripts/decodecode @@ -93,6 +93,11 @@ disas() { ${CROSS_COMPILE}strip $t.o fi + if [ "$ARCH" = "riscv" ]; then + OBJDUMPFLAGS="-M no-aliases --section=.text -D" + ${CROSS_COMPILE}strip $t.o + fi + if [ $pc_sub -ne 0 ]; then if [ $PC ]; then adj_vma=$(( $PC - $pc_sub )) @@ -126,8 +131,13 @@ get_substr_opcode_bytes_num() do substr+="$opc" + opcode="$substr" + if [ "$ARCH" = "riscv" ]; then + opcode=$(echo $opcode | tr ' ' '\n' | tac | tr -d '\n') + fi + # return if opcode bytes do not match @opline anymore - if ! echo $opline | grep -q "$substr"; + if ! echo $opline | grep -q "$opcode"; then break fi