Re: print_insn_sh cleanup

Elena Zannoni
2002-05-17T13:54:57Z

Joern Rennecke writes:
> Elena Zannoni wrote:
> > We still need a gdb_print_insn_sh function, because the user can
> > set the target endiannes from the command line overwriting the architecture
> > endiannes.
> > So we need to leave in there the check of the TARGET_BYTE_ORDER.
> > I think something like this:
> > gdb_print_insn_sh (bfd_vma address, disassemble_info *info)
> > {
> > if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
> > BFD_ENDIAN_BIG;
> > else
> > info->endian = BFD_ENDIAN_LITTLE;
> > return print_insn_sh (address, info);
> > }
>
> I have used
> info->endian = TARGET_BYTE_ORDER;
> I hope there isn't any hidden problem with that.

I hope not either.
The gdb part is approved. (Of course this should go in after/at the same time
the opcodes are committed).

All we are missing now is a sh disassembly gdb test in gdb.asm.

Elena

>
> --
> --------------------------
> SuperH
> 2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
> T:+44 1454 462330Fri May 17 13:30:50 2002 J"orn Rennecke <joern.rennecke@superh.com>
>
> include:
> * dis-asm.h (print_insn_shl, print_insn_sh64l): Remove prototype.
> gdb:
> * sh-tdep.c (gdb_print_insn_sh64): Delete.
> (gdb_print_insn_sh): Just set info->endian and use print_insn_sh.
> (sh_gdbarch_init): Always use gdb_print_insn_sh.
> opcodes:
> * disassemble.c (disassembler): Just use print_insn_sh for bfd_arch_sh.
> * sh-dis.c (LITTLE_BIT): Delete.
> (print_insn_sh, print_insn_shl): Deleted.
> (print_insn_shx): Renamed to
> (print_insn_sh). No longer static. Handle SHmedia instructions.
> Use info->endian to determine endianness.
> * sh64-dis.c (print_insn_sh64, print_insn_sh64l): Delete.
> (print_insn_sh64x): No longer static. Renamed to
> (print_insn_sh64). Removed pfun_compact and endian arguments.
> If we got an uneven address to indicate SHmedia, adjust it.
> Return -2 for SHcompact instructions.
> sim/sh64:
> * sim-if.c (sh64_disassemble_insn): Use print_insn_sh instead of
> print_insn_shl.
>
> Index: include/dis-asm.h
> ===================================================================
> RCS file: /cvs/src/src/include/dis-asm.h,v
> retrieving revision 1.32
> diff -p -r1.32 dis-asm.h
> *** include/dis-asm.h 8 Feb 2002 05:01:25 -0000 1.32
> --- include/dis-asm.h 15 May 2002 18:38:50 -0000
> *************** extern int print_insn_little_powerpc PAR
> *** 226,232 ****
> extern int print_insn_rs6000 PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_s390 PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_sh PARAMS ((bfd_vma, disassemble_info*));
> - extern int print_insn_shl PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_tic30 PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_tic54x PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_tic80 PARAMS ((bfd_vma, disassemble_info*));
> --- 226,231 ----
> *************** extern int print_insn_vax PARAMS ((bfd_
> *** 235,241 ****
> extern int print_insn_w65 PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_xstormy16 PARAMS ((bfd_vma, disassemble_info*));
> extern int print_insn_sh64 PARAMS ((bfd_vma, disassemble_info *));
> - extern int print_insn_sh64l PARAMS ((bfd_vma, disassemble_info *));
> extern int print_insn_sh64x_media PARAMS ((bfd_vma, disassemble_info *));
>
> extern disassembler_ftype arc_get_disassembler PARAMS ((void *));
> --- 234,239 ----
> Index: gdb/sh-tdep.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/sh-tdep.c,v
> retrieving revision 1.58
> diff -p -r1.58 sh-tdep.c
> *** gdb/sh-tdep.c 10 May 2002 23:59:09 -0000 1.58
> --- gdb/sh-tdep.c 17 May 2002 12:25:42 -0000
> *************** sh_store_struct_return (CORE_ADDR addr,
> *** 906,934 ****
> static int
> gdb_print_insn_sh (bfd_vma memaddr, disassemble_info *info)
> {
> ! if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
> ! return print_insn_sh (memaddr, info);
> ! else
> ! return print_insn_shl (memaddr, info);
> ! }
> !
> ! /* Disassemble an instruction. */
> ! static int
> ! gdb_print_insn_sh64 (bfd_vma memaddr, disassemble_info *info)
> ! {
> ! if (pc_is_isa32 (memaddr))
> ! {
> ! /* Round down the instruction address to the appropriate boundary
> ! before disassembling it. */
> ! return print_insn_sh64x_media (UNMAKE_ISA32_ADDR (memaddr), info);
> ! }
> ! else
> ! {
> ! if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
> ! return print_insn_sh (memaddr, info);
> ! else
> ! return print_insn_shl (memaddr, info);
> ! }
> }
>
> /* Given a GDB frame, determine the address of the calling function's frame.
> --- 906,913 ----
> static int
> gdb_print_insn_sh (bfd_vma memaddr, disassemble_info *info)
> {
> ! info->endian = TARGET_BYTE_ORDER;
> ! return print_insn_sh (memaddr, info);
> }
>
> /* Given a GDB frame, determine the address of the calling function's frame.
> *************** sh_gdbarch_init (struct gdbarch_info inf
> *** 4682,4688 ****
> sh_store_return_value = sh64_store_return_value;
> skip_prologue_hard_way = sh64_skip_prologue_hard_way;
> do_pseudo_register = sh64_do_pseudo_register;
> - set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh64);
> set_gdbarch_register_raw_size (gdbarch, sh_sh64_register_raw_size);
> set_gdbarch_register_virtual_size (gdbarch, sh_sh64_register_raw_size);
> set_gdbarch_register_byte (gdbarch, sh_sh64_register_byte);
> --- 4661,4666 ----
> Index: opcodes/disassemble.c
> ===================================================================
> RCS file: /cvs/src/src/opcodes/disassemble.c,v
> retrieving revision 1.32
> diff -p -r1.32 disassemble.c
> *** opcodes/disassemble.c 8 Feb 2002 05:51:03 -0000 1.32
> --- opcodes/disassemble.c 15 May 2002 18:39:01 -0000
> *************** disassembler (abfd)
> *** 278,297 ****
> #endif
> #ifdef ARCH_sh
> case bfd_arch_sh:
> ! #ifdef INCLUDE_SHMEDIA
> ! if (bfd_get_mach (abfd) == bfd_mach_sh5)
> ! {
> ! if (bfd_big_endian (abfd))
> ! disassemble = print_insn_sh64;
> ! else
> ! disassemble = print_insn_sh64l;
> ! break;
> ! }
> ! #endif
> ! if (bfd_big_endian (abfd))
> ! disassemble = print_insn_sh;
> ! else
> ! disassemble = print_insn_shl;
> break;
> #endif
> #ifdef ARCH_sparc
> --- 278,284 ----
> #endif
> #ifdef ARCH_sh
> case bfd_arch_sh:
> ! disassemble = print_insn_sh;
> break;
> #endif
> #ifdef ARCH_sparc
> Index: opcodes/sh-dis.c
> ===================================================================
> RCS file: /cvs/src/src/opcodes/sh-dis.c,v
> retrieving revision 1.10
> diff -p -r1.10 sh-dis.c
> *** opcodes/sh-dis.c 8 Feb 2002 05:51:03 -0000 1.10
> --- opcodes/sh-dis.c 15 May 2002 18:39:01 -0000
> *************** Foundation, Inc., 59 Temple Place - Suit
> *** 24,37 ****
> #include "sh-opc.h"
> #include "dis-asm.h"
>
> - #define LITTLE_BIT 2
> -
> static void print_movxy
> PARAMS ((sh_opcode_info *, int, int, fprintf_ftype, void *));
> static void print_insn_ddt PARAMS ((int, struct disassemble_info *));
> static void print_dsp_reg PARAMS ((int, fprintf_ftype, void *));
> static void print_insn_ppi PARAMS ((int, struct disassemble_info *));
> - static int print_insn_shx PARAMS ((bfd_vma, struct disassemble_info *));
>
> static void
> print_movxy (op, rn, rm, fprintf_fn, stream)
> --- 24,34 ----
> *************** print_insn_ppi (field_b, info)
> *** 286,293 ****
> fprintf_fn (stream, ".word 0x%x", field_b);
> }
>
> ! static int
> ! print_insn_shx (memaddr, info)
> bfd_vma memaddr;
> struct disassemble_info *info;
> {
> --- 283,290 ----
> fprintf_fn (stream, ".word 0x%x", field_b);
> }
>
> ! int
> ! print_insn_sh (memaddr, info)
> bfd_vma memaddr;
> struct disassemble_info *info;
> {
> *************** print_insn_shx (memaddr, info)
> *** 324,329 ****
> --- 321,331 ----
> target_arch = arch_sh4;
> break;
> case bfd_mach_sh5:
> + #ifdef INCLUDE_SHMEDIA
> + status = print_insn_sh64 (memaddr, info);
> + if (status != -2)
> + return status;
> + #endif
> /* When we get here for sh64, it's because we want to disassemble
> SHcompact, i.e. arch_sh4. */
> target_arch = arch_sh4;
> *************** print_insn_shx (memaddr, info)
> *** 340,346 ****
> return -1;
> }
>
> ! if (info->flags & LITTLE_BIT)
> {
> nibs[0] = (insn[1] >> 4) & 0xf;
> nibs[1] = insn[1] & 0xf;
> --- 342,348 ----
> return -1;
> }
>
> ! if (info->endian == BFD_ENDIAN_LITTLE)
> {
> nibs[0] = (insn[1] >> 4) & 0xf;
> nibs[1] = insn[1] & 0xf;
> *************** print_insn_shx (memaddr, info)
> *** 371,377 ****
> return -1;
> }
>
> ! if (info->flags & LITTLE_BIT)
> field_b = insn[1] << 8 | insn[0];
> else
> field_b = insn[0] << 8 | insn[1];
> --- 373,379 ----
> return -1;
> }
>
> ! if (info->endian == BFD_ENDIAN_LITTLE)
> field_b = insn[1] << 8 | insn[0];
> else
> field_b = insn[0] << 8 | insn[1];
> *************** print_insn_shx (memaddr, info)
> *** 677,683 ****
> {
> info->flags |= 1;
> fprintf_fn (stream, "\t(slot ");
> ! print_insn_shx (memaddr + 2, info);
> info->flags &= ~1;
> fprintf_fn (stream, ")");
> return 4;
> --- 679,685 ----
> {
> info->flags |= 1;
> fprintf_fn (stream, "\t(slot ");
> ! print_insn_sh (memaddr + 2, info);
> info->flags &= ~1;
> fprintf_fn (stream, ")");
> return 4;
> *************** print_insn_shx (memaddr, info)
> *** 700,713 ****
>
> if (size == 2)
> {
> ! if ((info->flags & LITTLE_BIT) != 0)
> val = bfd_getl16 (bytes);
> else
> val = bfd_getb16 (bytes);
> }
> else
> {
> ! if ((info->flags & LITTLE_BIT) != 0)
> val = bfd_getl32 (bytes);
> else
> val = bfd_getb32 (bytes);
> --- 702,715 ----
>
> if (size == 2)
> {
> ! if (info->endian == BFD_ENDIAN_LITTLE)
> val = bfd_getl16 (bytes);
> else
> val = bfd_getb16 (bytes);
> }
> else
> {
> ! if (info->endian == BFD_ENDIAN_LITTLE)
> val = bfd_getl32 (bytes);
> else
> val = bfd_getb32 (bytes);
> *************** print_insn_shx (memaddr, info)
> *** 723,750 ****
> }
> fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
> return 2;
> - }
> -
> - int
> - print_insn_shl (memaddr, info)
> - bfd_vma memaddr;
> - struct disassemble_info *info;
> - {
> - int r;
> -
> - info->flags = LITTLE_BIT;
> - r = print_insn_shx (memaddr, info);
> - return r;
> - }
> -
> - int
> - print_insn_sh (memaddr, info)
> - bfd_vma memaddr;
> - struct disassemble_info *info;
> - {
> - int r;
> -
> - info->flags = 0;
> - r = print_insn_shx (memaddr, info);
> - return r;
> }
> --- 725,728 ----
> Index: opcodes/sh64-dis.c
> ===================================================================
> RCS file: /cvs/src/src/opcodes/sh64-dis.c,v
> retrieving revision 1.1
> diff -p -r1.1 sh64-dis.c
> *** opcodes/sh64-dis.c 8 Feb 2002 05:51:03 -0000 1.1
> --- opcodes/sh64-dis.c 15 May 2002 18:39:01 -0000
> *************** static unsigned long *shmedia_opcode_mas
> *** 55,64 ****
>
> static void initialize_shmedia_opcode_mask_table PARAMS ((void));
> static int print_insn_shmedia PARAMS ((bfd_vma, disassemble_info *));
> - static int print_insn_sh64x
> - PARAMS ((bfd_vma, disassemble_info *,
> - int (*) PARAMS ((bfd_vma, struct disassemble_info *)),
> - enum bfd_endian));
> static const char *creg_name PARAMS ((int));
> static boolean init_sh64_disasm_info PARAMS ((struct disassemble_info *));
> static enum sh64_elf_cr_type sh64_get_contents_type_disasm
> --- 55,60 ----
> *************** print_insn_sh64x_media (memaddr, info)
> *** 555,569 ****
> return print_insn_shmedia (memaddr, info);
> }
>
> ! /* Main entry to disassemble SHcompact or SHmedia insns. */
>
> ! static int
> ! print_insn_sh64x (memaddr, info, pfun_compact, endian)
> bfd_vma memaddr;
> struct disassemble_info *info;
> - int (*pfun_compact) PARAMS ((bfd_vma, struct disassemble_info *));
> - enum bfd_endian endian;
> {
> enum sh64_elf_cr_type cr_type;
>
> if (info->private_data == NULL && ! init_sh64_disasm_info (info))
> --- 551,565 ----
> return print_insn_shmedia (memaddr, info);
> }
>
> ! /* Main entry to disassemble SHmedia insns.
> ! If we see an SHcompact instruction, return -2. */
>
> ! int
> ! print_insn_sh64 (memaddr, info)
> bfd_vma memaddr;
> struct disassemble_info *info;
> {
> + enum bfd_endian endian = info->endian;
> enum sh64_elf_cr_type cr_type;
>
> if (info->private_data == NULL && ! init_sh64_disasm_info (info))
> *************** print_insn_sh64x (memaddr, info, pfun_co
> *** 575,580 ****
> --- 571,580 ----
> int length = 4 - (memaddr % 4);
> info->display_endian = endian;
>
> + /* If we got an uneven address to indicate SHmedia, adjust it. */
> + if (cr_type == CRT_SH5_ISA32 && length == 3)
> + memaddr--, length = 4;
> +
> /* Only disassemble on four-byte boundaries. Addresses that are not
> a multiple of four can happen after a data region. */
> if (cr_type == CRT_SH5_ISA32 && length == 4)
> *************** print_insn_sh64x (memaddr, info, pfun_co
> *** 633,659 ****
> }
> }
>
> ! return (*pfun_compact) (memaddr, info);
> ! }
> !
> ! /* Main entry to disassemble SHcompact or SHmedia insns, big endian. */
> !
> ! int
> ! print_insn_sh64 (memaddr, info)
> ! bfd_vma memaddr;
> ! struct disassemble_info *info;
> ! {
> ! return
> ! print_insn_sh64x (memaddr, info, print_insn_sh, BFD_ENDIAN_BIG);
> ! }
> !
> ! /* Main entry to disassemble SHcompact or SHmedia insns, little endian. */
> !
> ! int
> ! print_insn_sh64l (memaddr, info)
> ! bfd_vma memaddr;
> ! struct disassemble_info *info;
> ! {
> ! return
> ! print_insn_sh64x (memaddr, info, print_insn_shl, BFD_ENDIAN_LITTLE);
> }
> --- 633,638 ----
> }
> }
>
> ! /* SH1 .. SH4 instruction, let caller handle it. */
> ! return -2;
> }
> Index: sim/sh64/sim-if.c
> ===================================================================
> RCS file: /cvs/src/src/sim/sh64/sim-if.c,v
> retrieving revision 1.1
> diff -p -r1.1 sim-if.c
> *** sim/sh64/sim-if.c 1 Feb 2002 11:44:27 -0000 1.1
> --- sim/sh64/sim-if.c 15 May 2002 18:39:01 -0000
> *************** sh64_disassemble_insn (SIM_CPU *cpu, con
> *** 232,246 ****
> if (sh64_h_ism_get (cpu) == ISM_MEDIA)
> print_insn_sh64x_media (pc, &disasm_info);
> else
> ! switch (disasm_info.endian)
> ! {
> ! case BFD_ENDIAN_BIG:
> ! print_insn_sh (pc, &disasm_info);
> ! break;
> ! case BFD_ENDIAN_LITTLE:
> ! print_insn_shl (pc, &disasm_info);
> ! break;
> ! default:
> ! abort();
> ! }
> }
> --- 232,236 ----
> if (sh64_h_ism_get (cpu) == ISM_MEDIA)
> print_insn_sh64x_media (pc, &disasm_info);
> else
> ! print_insn_sh (pc, &disasm_info);
> }