-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RISC-V: Add "arch" disassembler option
This commit adds new disassembler option "arch" to override architecture string. Existing implementations is helpful on regular ELF files but for instance, when debugging a binary with OpenOCD + GDB, there's a case where such information is not available. Also, there's a case where changing the architecture to disassemble is helpful, even on ELF files. For instance, Linux kernel is the prime example. On recent Linux kernel on RISC-V, it utilizes "alternatives" feature, which patches the kernel on the fly, depending on the implemented extensions. For instance, it utilizes the 'Zicboz' extension to clear the entire page and the 'Zbb' extension for efficient string handling. Note that those extension uses are determined by the runtime and at least ELF attributes don't have such information. Some of which (uses of 'Zicboz') are even invisible from mapping symbols. This commit enables objdump and GDB to use custom architecture string instead of ELF attributes and mapping symbols (e.g. even if OpenSBI is compiled with -march=rv64gc, we can enable H extension when disassembling OpenSBI by specifying an architecture string: rv64gch). It can be also helpful to test overwrapping encodings (e.g. standard hints). gas/ChangeLog: * testsuite/gas/riscv/dis-arch-override.s: New arch override tests. * testsuite/gas/riscv/dis-arch-override-1.d: Likewise. * testsuite/gas/riscv/dis-arch-override-2.d: Likewise. * testsuite/gas/riscv/dis-arch-override-3.d: Likewise. opcodes/ChangeLog: * riscv-dis.c (is_custom_arch) New. (update_riscv_dis_xlen): Update XLEN precedence rules. (set_default_riscv_dis_options): Initialize "arch". (parse_riscv_dis_option): Add the "arch" option. (riscv_get_map_state): Ignore ISA string from mapping symbols if custom "arch" is specified. (riscv_get_disassembler): Update the architecture depending on the custom "arch" option. (riscv_option_arg_t) Add RISCV_OPTION_ARG_ARCH. (riscv_options): Add the "arch" option. (disassembler_options_riscv): Add the "arch" option.
- Loading branch information
Showing
5 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#as: -march=rv64imfd_zbb | ||
#source: dis-arch-override.s | ||
#objdump: -d | ||
|
||
.*:[ ]+file format .* | ||
|
||
Disassembly of section .text: | ||
|
||
0+000 <target>: | ||
[ ]+[0-9a-f]+:[ ]+00c5f053[ ]+fadd\.s[ ]+ft0,fa1,fa2 | ||
[ ]+[0-9a-f]+:[ ]+02c5f053[ ]+fadd\.d[ ]+ft0,fa1,fa2 | ||
[ ]+[0-9a-f]+:[ ]+30102573[ ]+csrr[ ]+a0,misa | ||
[ ]+[0-9a-f]+:[ ]+0805c53b[ ]+zext\.h[ ]+a0,a1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#as: -march=rv64imfd_zbb | ||
#source: dis-arch-override.s | ||
#objdump: -d -M arch=rv32im_zfinx_zbkb | ||
|
||
.*:[ ]+file format .* | ||
|
||
Disassembly of section .text: | ||
|
||
0+000 <target>: | ||
[ ]+[0-9a-f]+:[ ]+00c5f053[ ]+fadd\.s[ ]+zero,a1,a2 | ||
[ ]+[0-9a-f]+:[ ]+02c5f053[ ]+\.insn[ ]+4, 0x02c5f053 | ||
[ ]+[0-9a-f]+:[ ]+30102573[ ]+csrr[ ]+a0,misa | ||
[ ]+[0-9a-f]+:[ ]+0805c53b[ ]+packw[ ]+a0,a1,zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#as: -march=rv64imfd_zbb | ||
#source: dis-arch-override.s | ||
#objdump: -d -m riscv -M arch=rv32im_zfinx_zbkb,numeric | ||
|
||
.*:[ ]+file format .* | ||
|
||
Disassembly of section .text: | ||
|
||
0+000 <target>: | ||
[ ]+[0-9a-f]+:[ ]+00c5f053[ ]+fadd\.s[ ]+x0,x11,x12 | ||
[ ]+[0-9a-f]+:[ ]+02c5f053[ ]+\.insn[ ]+4, 0x02c5f053 | ||
[ ]+[0-9a-f]+:[ ]+30102573[ ]+csrr[ ]+x10,misa | ||
[ ]+[0-9a-f]+:[ ]+0805c53b[ ]+\.insn[ ]+4, 0x0805c53b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Assembler configuration: | ||
# -march=rv64imfd_zbb | ||
# Disassembler configurations: | ||
# Test 1: -d | ||
# Test 2: -d -M arch=rv32im_zfinx_zbkb | ||
# Test 3: -d -m riscv -M arch=rv32im_zfinx_zbkb,numeric | ||
|
||
target: | ||
# Assembler : fadd.s (F) | ||
# Disassembler (test 2/3) : fadd.s (Zfinx) | ||
# Test that all three operands point to GPRs. | ||
fadd.s ft0, fa1, fa2 | ||
|
||
# Assembler : fadd.d (D) | ||
# Disassembler (test 2/3) : (invalid) | ||
# On disassembler option on test 2, Zdinx is not present. So, | ||
# it should be disassembled as an invalid instruction. | ||
fadd.d ft0, fa1, fa2 | ||
|
||
# Assembler : csrr (Zicsr) | ||
# Disassembler (test 2/3) : csrr (Zicsr) | ||
# When assembling, Zicsr is implied by F. When disassembling, | ||
# Zicsr is implied by Zfinx. On both cases, csrr should be | ||
# disassembled as csrr. | ||
csrr a0, misa | ||
|
||
# Assembler : zext.h (Zbb) | ||
# Disassembler (test 2) : packw (Zbkb) | ||
# Disassembler (test 3) : (invalid) | ||
# Since zext.h specialized instruction does not exist in Zbkb | ||
# and we disassemble the output with Zbkb, this instruction | ||
# should be disassembled as a packw instruction (on RV64). | ||
# | ||
# We specify arch=rv32im_zfinx_zbkb on disassembling on test | ||
# 2 and 3. But, XLEN part of the ISA string is effective | ||
# only if XLEN-neutral machine is specified by `-m riscv' option | ||
# (because we are disassembling 64-bit RISC-V ELF file, BFD | ||
# architecture is set to `riscv:rv64' unless `-m' option | ||
# is specified). | ||
# | ||
# As a result, test 3 (with `-m riscv' option) disassembles with | ||
# RV32 but test 2 (without it) does with RV64. | ||
# It changes the result of disassembling since packw instruction | ||
# is invalid on RV32. | ||
zext.h a0, a1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters