From patchwork Fri Jan 13 14:45:52 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: 13100882 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 C2EE8C54EBE for ; Fri, 13 Jan 2023 14:46:27 +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=BHZb7nv1e8NWmtrEh8Tlk85vPkas8FvuLejpW/LBW9U=; b=v+2cuD87nX3QNt ZHeO9/un6IsuOXyygP2ZdU6RPXT8FuWtaGlo/wCpISP7x6pY420IgMdMZSIafFjqD9TZA1+5+0izI eAzbXFgaGJWvW9mbFWUuDZnbUvPZtFepelWHwBA8yp3MwJdFVcjsMvsKeadYhs8IDSNiFdcnHVoZZ Dh4zv/3JPNH01A3QVRsPdUbX6E4CiF3wxjamunWZ9U2Y7i/NZnAUA//uLae+q57z+FfEkgOgd3llT K/0yY4u6kedn1DmzDlB9ux7H3tzYT2RWfODYRVNNGszZ8xcM5OvjkfFs+vwl8/Bc63KccAdX7Mqei iXKCZDO1hM5JQEbMdW1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGLK0-0032Gk-9s; Fri, 13 Jan 2023 14:46:20 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGLJw-0032ES-72 for linux-riscv@lists.infradead.org; Fri, 13 Jan 2023 14:46:18 +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 ams.source.kernel.org (Postfix) with ESMTPS id B9716B820C9; Fri, 13 Jan 2023 14:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7B87C433D2; Fri, 13 Jan 2023 14:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673621173; bh=uVNiYN015zOKGYAR63hxg0e1aLPV1U+u9Ab5GMB5AGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vNB4FYpN1R5PNtOd0/xoHymyzhJfoSvNDyhNH6pomXpBHz6C5FA5rYzkMEgM2qolb PP3FcgRXKYfCReSGva3gI983FKqej3Y3C16Lq71ULLpXFZTqds0vPVPwckIp/oGRC/ Tc06UIHS4zVhWoWLu/oZ1ppLnvAISGUdi1rNvJ4aK4XKKAa+r8+SWg9TaQx7ZFg789 QWagfHjInlSw+xruSyI9Fsfdo0uVi/99jSR+yJDgTtEsWeLh4Z67btkwlapRRZlx9X i4WEam9AWc6O79NFg+yi9QpxuCXSt8gefltBDwjxl37y4sLrQiq2yTGL5pjykZRNkZ DspERoJ/E7rqw== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] scripts/decodecode: Add support for RISC-V Date: Fri, 13 Jan 2023 15:45:52 +0100 Message-Id: <20230113144552.138081-3-bjorn@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113144552.138081-1-bjorn@kernel.org> References: <20230113144552.138081-1-bjorn@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230113_064616_609757_49F80D22 X-CRM114-Status: GOOD ( 13.26 ) 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 .byte 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: 64 c9 29 a0 17 d4 1f 01 13 04 44 b8 93 92 38 00 16 94 00 60 <02> 94 aa e8' | \ AFLAGS="-march=rv64imac_zicbom_zihintpause" \ ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./scripts/decodecode Code: 64 c9 29 a0 17 d4 1f 01 13 04 44 b8 93 92 38 00 16 94 00 60 <02> 94 aa e8 All code ======== 0: c964 c.sw s1,84(a0) 2: a029 c.j c <.text+0xc> 4: 011fd417 auipc s0,0x11fd 8: b8440413 addi s0,s0,-1148 # 11fcb88 <.text+0x11fcb88> c: 00389293 slli t0,a7,0x3 10: 9416 c.add s0,t0 12: 6000 c.ld s0,0(s0) 14:* 9402 c.jalr s0 <-- trapping instruction 16: e8aa c.sdsp a0,80(sp) Code starting with the faulting instruction =========================================== 0: 9402 c.jalr s0 2: e8aa c.sdsp a0,80(sp) [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