Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1087057rwb; Fri, 13 Jan 2023 07:47:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYdIO3fL0xN1h4uYdHRdmqE6ah6YaZd+El9171JIuU9E9BgJ4GCVXS1kk35QySoaFvaYlt X-Received: by 2002:a05:6a20:d695:b0:a2:c1f4:3c70 with SMTP id it21-20020a056a20d69500b000a2c1f43c70mr94007114pzb.8.1673624864844; Fri, 13 Jan 2023 07:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673624864; cv=none; d=google.com; s=arc-20160816; b=tabbPFaMg8cBxZJt058vvccaJIFxmnDqjS3/XDM5yT8DAtl6tsAFHeRFaG5vjrci9c 8La5YktOCaAL4EUq1r9X6v5vNOmRSMwLrbU4X/nIwIyTrGcu+gpMfer/cAZEBx84T80D aXwwqljVqoNFtDJ42NUltMwzQArTDELgVxBaaj388q5iyI4xjeWYSO+/ZSmnI2etPBdg jnm/U46u8FWBpBWNHaPmc/BQfbpT7Bv61Cd7YWiQ2gj+2DfSiqQGxHWdDoegQaJZcNmK 7J9ZV3E3fqkMo0xpaqKVn9hyKlmAotXtYSnY6nmQ3ACMM3qTpK/hftTtZ8ZzO70urfL8 QOtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D86nBkvUZ84VLH/j7cKVdH+IOTmWhuI7JTXC3aUc9WQ=; b=ql2T2YCs64VEEZ/b0K0ZGF8ZFH4CqGv+lPxj6puSLmHDsmvLroAmWVsY/iujrUZCJF Pw6DBXbFos79kY8762bnDkSnyhdnO2SdmVNG0/U/t5JmegRRjCkepCO3oojwxSKI6r64 Q7IgbW088qaK73K3uXxGKvHk7FVyhMtQuQcpbxU+JwXAdlsWco5C8ah25MCm9iEdc7pg KBs9s5QRuUW9UKOA5pwBOp7OMF3GXu/dyNp60Pd5FcoVdfo50x7iGVxMp6QkQiKk23ig eI6PrY/RzMODRQByuz7PSDSx8MEc2JLz3sjCEdn25RmR8AO3wJbzvZZLAWPtY47GKjgw 63Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vNB4FYpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a63fd4b000000b00478bec2850asi19788839pgj.425.2023.01.13.07.47.38; Fri, 13 Jan 2023 07:47:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vNB4FYpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbjAMO7l (ORCPT + 51 others); Fri, 13 Jan 2023 09:59:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjAMO6g (ORCPT ); Fri, 13 Jan 2023 09:58:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A21E77AE8 for ; Fri, 13 Jan 2023 06:46:14 -0800 (PST) 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 E97EB61FC3 for ; Fri, 13 Jan 2023 14:46:13 +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?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 -- 2.37.2