From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7803) id 4FDF2385840B; Fri, 2 Sep 2022 06:06:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FDF2385840B Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nelson Chu To: bfd-cvs@sourceware.org Subject: [binutils-gdb] RISC-V: Print highest address (-1) on the disassembler X-Act-Checkin: binutils-gdb X-Git-Author: Tsukasa OI X-Git-Refname: refs/heads/master X-Git-Oldrev: 48525554d5222d98953202b9252ff65fdead58a4 X-Git-Newrev: 8fe1be5fabd097a8b9110ab63729e08c0d686660 Message-Id: <20220902060640.4FDF2385840B@sourceware.org> Date: Fri, 2 Sep 2022 06:06:40 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Sep 2022 06:06:40 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8fe1be5fabd0= 97a8b9110ab63729e08c0d686660 commit 8fe1be5fabd097a8b9110ab63729e08c0d686660 Author: Tsukasa OI Date: Sat Aug 27 00:11:01 2022 +0000 RISC-V: Print highest address (-1) on the disassembler =20 This patch makes possible to print the highest address (-1) and the add= resses related to gp which value is -1. This is particularly useful if the hi= ghest address space is used for I/O registers and corresponding symbols are d= efined. Besides, despite that it is very rare to have GP the highest address, i= t would be nice because we enabled highest address printing on regular cases. =20 gas/ChangeLog: =20 * testsuite/gas/riscv/dis-addr-topaddr.s: New test for the top address (-1) printing. * testsuite/gas/riscv/dis-addr-topaddr-32.d: Likewise. * testsuite/gas/riscv/dis-addr-topaddr-64.d: Likewise. * testsuite/gas/riscv/dis-addr-topaddr-gp.s: New test for GP-relative addressing when GP is the highest address (-1). * testsuite/gas/riscv/dis-addr-topaddr-gp-32.d: Likewise. * testsuite/gas/riscv/dis-addr-topaddr-gp-64.d: Likewise. =20 opcodes/ChangeLog: =20 * riscv-dis.c (struct riscv_private_data): Add `to_print_addr' = to enable printing the highest address. (maybe_print_address): Utilize `to_print_addr'. (riscv_disassemble_insn): Likewise. Diff: --- gas/testsuite/gas/riscv/dis-addr-topaddr-32.d | 11 +++++++++++ gas/testsuite/gas/riscv/dis-addr-topaddr-64.d | 11 +++++++++++ gas/testsuite/gas/riscv/dis-addr-topaddr-gp-32.d | 12 ++++++++++++ gas/testsuite/gas/riscv/dis-addr-topaddr-gp-64.d | 12 ++++++++++++ gas/testsuite/gas/riscv/dis-addr-topaddr-gp.s | 15 +++++++++++++++ gas/testsuite/gas/riscv/dis-addr-topaddr.s | 10 ++++++++++ opcodes/riscv-dis.c | 20 ++++++++++++++------ 7 files changed, 85 insertions(+), 6 deletions(-) diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr-32.d b/gas/testsuite/= gas/riscv/dis-addr-topaddr-32.d new file mode 100644 index 00000000000..87854cd58e6 --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr-32.d @@ -0,0 +1,11 @@ +#as: -march=3Drv32ic +#source: dis-addr-topaddr.s +#objdump: -d + +.*: file format elf32-(little|big)riscv + + +Disassembly of section .text: + +0+000 : +[ ]+[0-9a-f]+:[ ]+fff00283[ ]+lb[ ]+t0,-1\(zero\) # ffffffff diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr-64.d b/gas/testsuite/= gas/riscv/dis-addr-topaddr-64.d new file mode 100644 index 00000000000..38f67efdcaf --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr-64.d @@ -0,0 +1,11 @@ +#as: -march=3Drv64ic -defsym rv64=3D1 +#source: dis-addr-topaddr.s +#objdump: -d + +.*: file format elf64-(little|big)riscv + + +Disassembly of section .text: + +0+000 : +[ ]+[0-9a-f]+:[ ]+fff00283[ ]+lb[ ]+t0,-1\(zero\) # ffffffffffffffff= diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr-gp-32.d b/gas/testsui= te/gas/riscv/dis-addr-topaddr-gp-32.d new file mode 100644 index 00000000000..875bfe73189 --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr-gp-32.d @@ -0,0 +1,12 @@ +#as: -march=3Drv32i +#source: dis-addr-topaddr-gp.s +#objdump: -d + +.*: file format elf32-(little|big)riscv + + +Disassembly of section .text: + +0+000 : +[ ]+[0-9a-f]+:[ ]+0051a283[ ]+lw[ ]+t0,5\(gp\) # 4 +[ ]+[0-9a-f]+:[ ]+ffd1a303[ ]+lw[ ]+t1,-3\(gp\) # fffffffc diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr-gp-64.d b/gas/testsui= te/gas/riscv/dis-addr-topaddr-gp-64.d new file mode 100644 index 00000000000..5ac4b52b18d --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr-gp-64.d @@ -0,0 +1,12 @@ +#as: -march=3Drv64i -defsym rv64=3D1 +#source: dis-addr-topaddr-gp.s +#objdump: -d + +.*: file format elf64-(little|big)riscv + + +Disassembly of section .text: + +0+000 : +[ ]+[0-9a-f]+:[ ]+0051a283[ ]+lw[ ]+t0,5\(gp\) # 4 +[ ]+[0-9a-f]+:[ ]+ffd1a303[ ]+lw[ ]+t1,-3\(gp\) # fffffffffffffffc <= addr_rel_gp_neg> diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr-gp.s b/gas/testsuite/= gas/riscv/dis-addr-topaddr-gp.s new file mode 100644 index 00000000000..6ba9fc7a39d --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr-gp.s @@ -0,0 +1,15 @@ +.ifdef rv64 +topbase =3D 0xffffffff00000000 +.else +topbase =3D 0 +.endif + +.set __global_pointer$, topbase + 0xffffffff # -1 +.set addr_rel_gp_pos, 0x00000004 # +4 +.set addr_rel_gp_neg, topbase + 0xfffffffc # -4 + +target: + # Use addresses relative to gp + # (gp is the highest address) + lw t0, +5(gp) + lw t1, -3(gp) diff --git a/gas/testsuite/gas/riscv/dis-addr-topaddr.s b/gas/testsuite/gas= /riscv/dis-addr-topaddr.s new file mode 100644 index 00000000000..b66587f448d --- /dev/null +++ b/gas/testsuite/gas/riscv/dis-addr-topaddr.s @@ -0,0 +1,10 @@ +.ifdef rv64 +topbase =3D 0xffffffff00000000 +.else +topbase =3D 0 +.endif + +.set addr_top, topbase + 0xffffffff # -1 + +target: + lb t0, -1(zero) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index b3ca680e506..160cc40f865 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -52,6 +52,8 @@ struct riscv_private_data bfd_vma gp; bfd_vma print_addr; bfd_vma hi_addr[OP_MASK_RD + 1]; + bool to_print_addr; + bool has_gp; }; =20 /* Used for mapping symbols. */ @@ -177,12 +179,13 @@ maybe_print_address (struct riscv_private_data *pd, i= nt base_reg, int offset, pd->print_addr =3D (base_reg !=3D 0 ? pd->hi_addr[base_reg] : 0) + o= ffset; pd->hi_addr[base_reg] =3D -1; } - else if (base_reg =3D=3D X_GP && pd->gp !=3D (bfd_vma)-1) + else if (base_reg =3D=3D X_GP && pd->has_gp) pd->print_addr =3D pd->gp + offset; else if (base_reg =3D=3D X_TP || base_reg =3D=3D 0) pd->print_addr =3D offset; else return; /* Don't print the address. */ + pd->to_print_addr =3D true; =20 /* Sign-extend a 32-bit value to a 64-bit value. */ if (wide) @@ -601,14 +604,19 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word,= disassemble_info *info) int i; =20 pd =3D info->private_data =3D xcalloc (1, sizeof (struct riscv_priva= te_data)); - pd->gp =3D -1; - pd->print_addr =3D -1; + pd->gp =3D 0; + pd->print_addr =3D 0; for (i =3D 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++) pd->hi_addr[i] =3D -1; + pd->to_print_addr =3D false; + pd->has_gp =3D false; =20 for (i =3D 0; i < info->symtab_size; i++) if (strcmp (bfd_asymbol_name (info->symtab[i]), RISCV_GP_SYMBOL) =3D=3D 0) - pd->gp =3D bfd_asymbol_value (info->symtab[i]); + { + pd->gp =3D bfd_asymbol_value (info->symtab[i]); + pd->has_gp =3D true; + } } else pd =3D info->private_data; @@ -668,13 +676,13 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word,= disassemble_info *info) print_insn_args (op->args, word, memaddr, info); =20 /* Try to disassemble multi-instruction addressing sequences. */ - if (pd->print_addr !=3D (bfd_vma)-1) + if (pd->to_print_addr) { info->target =3D pd->print_addr; (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, " # "); (*info->print_address_func) (info->target, info); - pd->print_addr =3D -1; + pd->to_print_addr =3D false; } =20 /* Finish filling out insn_info fields. */