1#!/bin/sh 2 3# A tool to disassemble one riscv64 instruction. 4 5if [ "$#" -ne 1 ]; then 6 echo "Usage:" 7 echo " $ riscv64-disasm 0x60469613" 8 echo "0: 60469613 sext.b a2,a3" 9 echo 10 echo " The prefix \"0x\" is optional. Compressed instructions are also allowed." 11 exit 12fi 13 14TEMP="$(mktemp)" 15INSN="0x$(echo $1 | sed -e "s/^0x//")" 16 17echo ".text" > "$TEMP.S" 18echo ".word $INSN" >> "$TEMP.S" 19 20# riscv objdump only understands extensions in elf files, so we cannot 21# disassemble a pure binary. 22# Add needed extensions to march when required. 23riscv64-linux-gnu-as -march=rv64gc_zba_zbb_zbs_v -o "$TEMP.o" "$TEMP.S" 24# Assembler marks .word bytes as data pool ("$d"), and objdump doesn't 25# disassemble such instructions. Strip symbols to force instruction disassembly. 26riscv64-linux-gnu-strip "$TEMP.o" 27riscv64-linux-gnu-objdump -M numeric -d "$TEMP.o" | sed '0,/<.text>/d' 28 29rm "$TEMP.S" "$TEMP.o" 30