Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp671983rwb; Thu, 19 Jan 2023 00:49:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXufGgq/l8zK6kacbCCvjL3yd4W8iQcE1F2MIJFwYpYT7uGr0hNi2AETIaFQ4xMGLduPLahk X-Received: by 2002:a17:906:4694:b0:86d:c1b2:257b with SMTP id a20-20020a170906469400b0086dc1b2257bmr20607107ejr.19.1674118158445; Thu, 19 Jan 2023 00:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674118158; cv=none; d=google.com; s=arc-20160816; b=L3gZNqUlFRgUWCT5j48XkBjk6k0kr2a0rdVldgDH5Pr6aI6EXbOdoBQ1sB4H57gMvE XlK9ejX+sv71PEyt7ex6JJZ5DZF8dZ07Jd/Xt+Tujjb01R85piVGgrj7NKMfd9bGVUb2 9gZFdAqzOJFAWv6q1dnGqGg9AcCNXl4YJbb+9rJJIgS85OenCGYsZbT8EMSJOtsF4kJi QFWVxVcz0RJKMTflFcXSTEyAmtmHvzmGh47wXafnZ4dwIOfdYwlTsBYCluuCXOdzhu7C q4AuDVmPaYzXRXOHZiJrfdTm25+s3BWB93iW6zCzt+vNFT7AmgueXo9N8G4FhgDMvmWG 0qow== 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=6+u8DAF1w+3pnxqxuJXeWq0Mmzl/CHOTAxv9x3qeBzQ=; b=vxl0+O5KTghbQwCoPUKq6LrUw9UupknWkDvGydMPpxxQAAdGjQ1FbD6Jr0bR6QJiBB uPxygpzlKWZuAQxN+bESIR6yZAXbf/D3IU4/0+clnmH3auqMV82c6MrMg6PcPzqb5osU Yyi+UBT/lCHD0Tj7XHVkcE3T0e977XfqHslL29T0HqA8HWad9UZBn4KHl7H7HxcYfpTw TUQZe9PfY17J6lKczFxfOFH+RSCsSjijVdLgjLeLMn2SC8kidiCFhmv5LT9VmuWciIvV I2j40L6JWKvVcvP91Cu2PFE9JcuGPuqQdLA79kCHyelg7UErTSwKVyl8HBmzUFonf5+S IlzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F+9OmwVL; 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 xa5-20020a170906fd8500b0084d7c8a4bdfsi29531916ejb.276.2023.01.19.00.49.07; Thu, 19 Jan 2023 00:49:18 -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=F+9OmwVL; 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 S230215AbjASHvT (ORCPT + 43 others); Thu, 19 Jan 2023 02:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbjASHuN (ORCPT ); Thu, 19 Jan 2023 02:50:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBDEE689FA for ; Wed, 18 Jan 2023 23:48: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 18C8461BA6 for ; Thu, 19 Jan 2023 07:48:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D94ACC433EF; Thu, 19 Jan 2023 07:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674114493; bh=PBE0PpRXIlt2qCDFtsjgADfP4kD6JxkZrkUXxW7Tmuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+9OmwVL6lX48jOEAysQTK3qhLt3mSeXbLlVru28JnzuovuPCuTdiTQtUoSwjB+ps Wd56KDxsYagdWgG7gH83veEO34aLJf1+lkkB+UiWSJNfo6/PjRS/8mC2UhNxayL4zd IgN54fSBcVNOm9GvIGHQNc93olFcrzVMmY9NNju/K2PCXIGrFao/mbWzEnZNvbYRXx sY+bzGVxz6VFYL4ptncHJMFnLQASifnFjX4RfFyNh//oPXdrR75K8pyaFMAcjPHMhb MknCw6cEnu9oYlXUsnlFTfWIGVxga+Ni5GgCbBg/Jieh2Q2WpeR7nVxD2m+G0goBIe LV5rrCkiwU1bg== 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?= , Andreas Schwab , Geert Uytterhoeven , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] scripts/decodecode: Add support for RISC-V Date: Thu, 19 Jan 2023 08:47:38 +0100 Message-Id: <20230119074738.708301-3-bjorn@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230119074738.708301-1-bjorn@kernel.org> References: <20230119074738.708301-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 .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 -- 2.37.2