This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to change ARM register name set


Hi Guys,

  Does anyone have any comments on the patch below ?  It changes the
  ARM disassembler so that by default it uses the APCS register naming
  scheme, rather than the ISA register naming scheme.  It also
  introduces a new command line switch to objdump: -M or --target-data,
  which takes an argument which can be processed in a target specific
  manner.  If the target is the ARM then the text of the -M switch is
  checked to see if it is a register name set selector
  ("standard_names" or "apcs_names") and if so it chooses the
  appropriate name set. 

Cheers
	Nick

--ChangeLog for opcodes------------------------------------------------

1999-06-14  Nick Clifton  <nickc@cygnus.com> & Drew Mosley <dmoseley@cygnus.com>

	* arm-dis.c (arm_regnames): Turn into a pointer to either
	arm_regnames_arm_standard or arm_regnames_arm_apcs.
	(arm_regnames_arm_standard): New variable: Array of ARM register
	names according to ARM instruction nomenclature.
	(arm_regnames_arm_apcs): New variable: Array of ARM register names
	according to ARM Procedure Call Standard.
	(ar_toggle_regnames): New function: Toggle the chosen register set
	naming scheme.

	* disassemble.c (disassembler2): New function: Allow target
	specific data to override selection of disassembler function.

--ChangeLog for include------------------------------------------------

1999-06-14  Nick Clifton  <nickc@cygnus.com>

	* dis-asm.h (arm_toggle_regnames): New prototype.
	(disassembler2): New prototype.

--ChangeLog for binutils------------------------------------------------

1999-06-14  Nick Clifton  <nickc@cygnus.com>

	* objdump.c (target_data): New variable.
	(usage): Add -M/--target-data option.
	(long_options): Add --target-data.
	(disassemble_data): Call diassembler2().
	(main): Add parsing of -M option.
	
	* binutils.texi: Document new command line switch to objdump.

	* NEWS: Describe new command line switch to objdump.

Index: opcodes/arm-dis.c
===================================================================
RCS file: /cvs/binutils/binutils/opcodes/arm-dis.c,v
retrieving revision 1.2
diff -p -r1.2 arm-dis.c
*** arm-dis.c	1999/06/04 07:14:10	1.2
--- arm-dis.c	1999/06/14 14:06:42
***************
*** 1,5 ****
  /* Instruction printing code for the ARM
!    Copyright (C) 1994, 95, 96, 97, 1998 Free Software Foundation, Inc. 
     Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
     Modification by James G. Smith (jsmith@cygnus.co.uk)
  
--- 1,5 ----
  /* Instruction printing code for the ARM
!    Copyright (C) 1994, 95, 96, 97, 1998, 1999 Free Software Foundation, Inc. 
     Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
     Modification by James G. Smith (jsmith@cygnus.co.uk)
  
*************** static char *arm_conditional[] =
*** 35,44 ****
  {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
   "hi", "ls", "ge", "lt", "gt", "le", "", "nv"};
  
! static char *arm_regnames[] =
  {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
!  "r8", "r9", "sl", "fp", "ip", "sp", "lr", "pc"};
  
  static char *arm_fp_const[] =
  {"0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0"};
  
--- 35,51 ----
  {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
   "hi", "ls", "ge", "lt", "gt", "le", "", "nv"};
  
! static char *arm_regnames_arm_standard[] =
  {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
!  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc"};
  
+ static char *arm_regnames_arm_apcs[] =
+ {"a1", "a2", "a3", "a4", "v1", "v2", "v3", "v4",
+  "v5", "v6", "sl", "fp", "ip", "sp", "lr", "pc"};
+ 
+ /* Choose which register name set to use.  */
+ static char **arm_regnames = arm_regnames_arm_apcs;
+ 
  static char *arm_fp_const[] =
  {"0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0"};
  
*************** print_insn_little_arm (pc, info)
*** 888,891 ****
--- 895,911 ----
      }
  
    return status;
+ }
+ 
+ /* Select a different register name set.
+    Returns true if the name set selected is the APCS name set.  */
+ int
+ arm_toggle_regnames ()
+ {
+   if (arm_regnames == arm_regnames_arm_standard)
+     arm_regnames = arm_regnames_arm_apcs;
+   else
+     arm_regnames = arm_regnames_arm_standard;
+ 
+   return arm_regnames == arm_regnames_arm_apcs;
  }

Index: opcodes/disassemble.c
===================================================================
RCS file: /cvs/binutils/binutils/opcodes/disassemble.c,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 disassemble.c
*** disassemble.c	1999/05/03 07:28:59	1.1.1.1
--- disassemble.c	1999/06/14 14:06:55
*************** disassembler (abfd)
*** 246,248 ****
--- 246,286 ----
    return disassemble;
  }
  
+ 
+ void
+ disassembler2 (abfd, disassembler, target_data)
+      bfd * abfd;
+      disassembler_ftype * disassembler;
+      char * target_data;
+ {
+   enum bfd_architecture a = bfd_get_arch (abfd);
+ 
+   switch (a)
+     {
+ #ifdef ARCH_arm
+     case bfd_arch_arm:
+       if (target_data == NULL)
+ 	break;
+       
+       if (strcmp (target_data, "-s") == 0
+ 	  || strcmp (target_data, "standard_names") == 0)
+ 	{
+ 	  if (arm_toggle_regnames ())
+ 	    arm_toggle_regnames ();
+ 	}
+       else if (strcmp (target_data, "-a") == 0
+ 	       || strcmp (target_data, "apcs_names") == 0)
+ 	{
+ 	  if (! arm_toggle_regnames ())
+ 	    arm_toggle_regnames ();
+ 	}
+       else
+ 	fprintf (stderr, "Unrecognised target_data data: %s\n", target_data);
+       break;
+ #endif
+     default:
+       break;
+     }
+ 
+   return;
+ }

Index: include/dis-asm.h
===================================================================
RCS file: /cvs/binutils/binutils/include/dis-asm.h,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 dis-asm.h
*** dis-asm.h	1999/05/03 07:29:01	1.1.1.1
--- dis-asm.h	1999/06/14 14:07:05
*************** extern int print_insn_tic30		PARAMS ((bf
*** 181,188 ****
--- 181,196 ----
  extern int print_insn_vax		PARAMS ((bfd_vma, disassemble_info*));
  extern int print_insn_tic80		PARAMS ((bfd_vma, disassemble_info*));
  
+ extern int arm_toggle_regnames          PARAMS ((void));
+ 
  /* Fetch the disassembler for a given BFD, if that support is available.  */
  extern disassembler_ftype disassembler	PARAMS ((bfd *));
+ 
+ /* Extended version of disassembler() function.  Takes two extra parameters,
+    the disassembler currently selected, so that it can be overridden if necessary,
+    and a string which can be interpreted on a per-target basis.  Objdump uses this
+    to pass the contents of the -M command line option (if given).  */
+ extern void disassembler2		PARAMS ((bfd *, disassembler_ftype *, char *));
  
  
  /* This block of definitions is for particular callers who read instructions

Index: binutils/objdump.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/objdump.c,v
retrieving revision 1.4
diff -p -r1.4 objdump.c
*** objdump.c	1999/06/13 19:02:25	1.4
--- objdump.c	1999/06/14 14:07:18
*************** struct objdump_disasm_info {
*** 83,88 ****
--- 83,91 ----
  /* Architecture to disassemble for, or default if NULL.  */
  static char *machine = (char *) NULL;
  
+ /* Target specific command line data.  Interpreted via a call to disassembler2().  */
+ static char *target_data = (char *) NULL;
+ 
  /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN.  */
  static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
  
*************** usage (stream, status)
*** 217,223 ****
       int status;
  {
    fprintf (stream, _("\
! Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
         [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
         [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\
         [--section-headers] [--headers]\n\
--- 220,227 ----
       int status;
  {
    fprintf (stream, _("\
! Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] \n\
!        [-j section-name] [-M target-data]\n\
         [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
         [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\
         [--section-headers] [--headers]\n\
*************** static struct option long_options[]=
*** 277,282 ****
--- 281,287 ----
    {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
    {"syms", no_argument, NULL, 't'},
    {"target", required_argument, NULL, 'b'},
+   {"target-data", required_argument, NULL, 'M'},
    {"version", no_argument, &show_version, 1},
    {"wide", no_argument, &wide_output, 'w'},
    {0, no_argument, 0, 0}
*************** disassemble_data (abfd)
*** 1561,1566 ****
--- 1566,1575 ----
        return;
      }
  
+   /* Allow the target to override the selected disassembler based on
+      data provided by the command line switch -M.  */
+   disassembler2 (abfd, & disassemble_fn, target_data);
+   
    disasm_info.flavour = bfd_get_flavour (abfd);
    disasm_info.arch = bfd_get_arch (abfd);
    disasm_info.mach = bfd_get_mach (abfd);
*************** main (argc, argv)
*** 2694,2700 ****
    bfd_init ();
    set_default_bfd_target ();
  
!   while ((c = getopt_long (argc, argv, "pib:m:VCdDlfahrRtTxsSj:wE:",
  			   long_options, (int *) 0))
  	 != EOF)
      {
--- 2703,2709 ----
    bfd_init ();
    set_default_bfd_target ();
  
!   while ((c = getopt_long (argc, argv, "pib:m:M:VCdDlfahrRtTxsSj:wE:",
  			   long_options, (int *) 0))
  	 != EOF)
      {
*************** main (argc, argv)
*** 2706,2711 ****
--- 2715,2723 ----
  	  break;		/* we've been given a long option */
  	case 'm':
  	  machine = optarg;
+ 	  break;
+ 	case 'M':
+ 	  target_data = optarg;
  	  break;
  	case 'j':
  	  only = optarg;

Index: binutils/binutils.texi
===================================================================
RCS file: /cvs/binutils/binutils/binutils/binutils.texi,v
retrieving revision 1.4
diff -p -r1.4 binutils.texi
*** binutils.texi	1999/06/14 01:30:17	1.4
--- binutils.texi	1999/06/14 14:07:31
*************** objdump [ -a | --archive-headers ] 
*** 1137,1142 ****
--- 1137,1143 ----
          [ -j @var{section} | --section=@var{section} ]
          [ -l | --line-numbers ] [ -S | --source ]
          [ -m @var{machine} | --architecture=@var{machine} ]
+         [ -M @var{target_data} | --target_data=@var{target_data}]
          [ -p | --private-headers ]
          [ -r | --reloc ] [ -R | --dynamic-reloc ]
          [ -s | --full-contents ]  [ --stabs ]
*************** Specify the architecture to use when dis
*** 1294,1299 ****
--- 1295,1312 ----
  can be useful when disassembling object files which do not describe
  architecture information, such as S-records.  You can list the available
  architectures with the @samp{-i} option.
+ 
+ @item -M @var{target_data}
+ @itemx --target-data=@var{target_data}
+ Pass target specific information tot he disassembler.  Only support on
+ some targets.
+ 
+ If the target is an ARM architecture then this switch can be used to
+ select which register name set is used during disassembler.  Specifying
+ @samp{--target-data=standard_names} will select the register names as
+ used in ARM's instruction set documentation.  Specifying
+ @samp{--target-data=apcs_names} (the default) will select the name set
+ used by the ARM Procedure Call Standard.
  
  @item -p
  @itemx --private-headers

Index: binutils/NEWS
===================================================================
RCS file: /cvs/binutils/binutils/binutils/NEWS,v
retrieving revision 1.3
diff -p -r1.3 NEWS
*** NEWS	1999/06/12 15:42:04	1.3
--- NEWS	1999/06/14 14:07:43
***************
*** 2,7 ****
--- 2,12 ----
  
  Changes in binutils 2.10:
  
+ * New command line switch to objdump -M (or --target-data) which takes a
+   parameter which is then interpreted on a per-target basis.  Used by ARM
+   targets to select register name sets (standard_names or apcs_names) when
+   displaying disassembly.
+   
  * objdump support for -mi386:intel which causes disassembly to be displayed
    with intel syntax.
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]