]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/mips-tdep.c
2003-04-08 Elena Zannoni <ezannoni@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / mips-tdep.c
index 506fd1fe7cf889b1fc7835f4e7fdf106d641daef..3e8339b92d0a8c528fed5d470bdf80c88f9de726 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "defs.h"
 #include "gdb_string.h"
+#include "gdb_assert.h"
 #include "frame.h"
 #include "inferior.h"
 #include "symtab.h"
@@ -361,23 +362,57 @@ static struct cmd_list_element *showmipscmdlist = NULL;
 
 /* A set of original names, to be used when restoring back to generic
    registers from a specific set.  */
+static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
 
-char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
-char **mips_processor_reg_names = mips_generic_reg_names;
+/* Integer registers 0 thru 31 are handled explicitly by
+   mips_register_name().  Processor specific registers 32 and above
+   are listed in the sets of register names assigned to
+   mips_processor_reg_names.  */
+static char **mips_processor_reg_names = mips_generic_reg_names;
 
+/* Return the name of the register corresponding to REGNO.  */
 static const char *
-mips_register_name (int i)
-{
-  return mips_processor_reg_names[i];
+mips_register_name (int regno)
+{
+  /* GPR names for all ABIs other than n32/n64.  */
+  static char *mips_gpr_names[] = {
+    "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
+    "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
+    "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
+    "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
+  };
+
+  /* GPR names for n32 and n64 ABIs.  */
+  static char *mips_n32_n64_gpr_names[] = {
+    "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3", 
+    "a4",   "a5",   "a6",   "a7",   "t0",   "t1",   "t2",   "t3", 
+    "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7", 
+    "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra"
+  };
+
+  enum mips_abi abi = mips_abi (current_gdbarch);
+
+  /* The MIPS integer registers are always mapped from 0 to 31.  The
+     names of the registers (which reflects the conventions regarding
+     register use) vary depending on the ABI.  */
+  if (0 <= regno && regno < 32)
+    {
+      if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
+       return mips_n32_n64_gpr_names[regno];
+      else
+       return mips_gpr_names[regno];
+    }
+  else if (32 <= regno && regno < NUM_REGS)
+    return mips_processor_reg_names[regno - 32];
+  else
+    internal_error (__FILE__, __LINE__,
+                   "mips_register_name: bad register number %d", regno);
 }
+
 /* *INDENT-OFF* */
 /* Names of IDT R3041 registers.  */
 
 char *mips_r3041_reg_names[] = {
-       "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
-       "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
-       "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
-       "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
        "sr",   "lo",   "hi",   "bad",  "cause","pc",
        "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
        "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
@@ -391,10 +426,6 @@ char *mips_r3041_reg_names[] = {
 /* Names of IDT R3051 registers.  */
 
 char *mips_r3051_reg_names[] = {
-       "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
-       "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
-       "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
-       "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
        "sr",   "lo",   "hi",   "bad",  "cause","pc",
        "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
        "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
@@ -408,10 +439,6 @@ char *mips_r3051_reg_names[] = {
 /* Names of IDT R3081 registers.  */
 
 char *mips_r3081_reg_names[] = {
-       "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
-       "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
-       "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
-       "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
        "sr",   "lo",   "hi",   "bad",  "cause","pc",
        "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
        "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
@@ -425,10 +452,6 @@ char *mips_r3081_reg_names[] = {
 /* Names of LSI 33k registers.  */
 
 char *mips_lsi33k_reg_names[] = {
-       "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
-       "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
-       "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
-       "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
        "epc",  "hi",   "lo",   "sr",   "cause","badvaddr",
        "dcic", "bpc",  "bda",  "",     "",     "",     "",      "",
        "",     "",     "",     "",     "",     "",     "",      "",
@@ -1795,10 +1818,10 @@ heuristic_proc_start (CORE_ADDR pc)
     if (start_pc < fence)
       {
        /* It's not clear to me why we reach this point when
-          stop_soon_quietly, but with this test, at least we
+          stop_soon, but with this test, at least we
           don't print out warnings for every child forked (eg, on
           decstation).  22apr93 rich@cygnus.com.  */
-       if (!stop_soon_quietly)
+       if (stop_soon == NO_STOP_QUIETLY)
          {
            static int blurb_printed = 0;
 
@@ -4026,154 +4049,126 @@ mips_read_fp_register_double (int regno, char *rare_buffer)
 }
 
 static void
-mips_print_register (int regnum, int all)
-{
-  char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
-
-  /* Get the data in raw format.  */
-  if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
-    {
-      printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
-      return;
-    }
-
-  /* If we have a actual 32-bit floating point register (or we are in
-     32-bit compatibility mode), and the register is even-numbered,
-     also print it as a double (spanning two registers).  */
-  if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
-      && (REGISTER_RAW_SIZE (regnum) == 4
-         || mips2_fp_compat ())
-      && !((regnum - FP0_REGNUM) & 1))
-    {
-      char *dbuffer = alloca (2 * MAX_REGISTER_RAW_SIZE);
-
-      mips_read_fp_register_double (regnum, dbuffer);
-
-      printf_filtered ("(d%d: ", regnum - FP0_REGNUM);
-      val_print (mips_double_register_type (), dbuffer, 0, 0,
-                gdb_stdout, 0, 1, 0, Val_pretty_default);
-      printf_filtered ("); ");
-    }
-  fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
-
-  /* The problem with printing numeric register names (r26, etc.) is that
-     the user can't use them on input.  Probably the best solution is to
-     fix it so that either the numeric or the funky (a2, etc.) names
-     are accepted on input.  */
-  if (regnum < MIPS_NUMREGS)
-    printf_filtered ("(r%d): ", regnum);
-  else
-    printf_filtered (": ");
-
-  /* If virtual format is floating, print it that way.  */
-  if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
-    if (REGISTER_RAW_SIZE (regnum) == 8 && !mips2_fp_compat ())
-      {
-       /* We have a meaningful 64-bit value in this register.  Show
-          it as a 32-bit float and a 64-bit double.  */
-       int offset = 4 * (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG);
-
-       printf_filtered (" (float) ");
-       val_print (mips_float_register_type (), raw_buffer + offset, 0, 0,
-                  gdb_stdout, 0, 1, 0, Val_pretty_default);
-       printf_filtered (", (double) ");
-       val_print (mips_double_register_type (), raw_buffer, 0, 0,
-                  gdb_stdout, 0, 1, 0, Val_pretty_default);
-      }
-    else
-      val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
-                gdb_stdout, 0, 1, 0, Val_pretty_default);
-  /* Else print as integer in hex.  */
-  else
-    {
-      int offset;
-
-      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-        offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
-      else
-       offset = 0;
-
-      print_scalar_formatted (raw_buffer + offset,
-                             REGISTER_VIRTUAL_TYPE (regnum),
-                             'x', 0, gdb_stdout);
-    }
-}
-
-/* Replacement for generic do_registers_info.
-   Print regs in pretty columns.  */
-
-static int
-do_fp_register_row (int regnum)
+mips_print_fp_register (int regnum)
 {                              /* do values for FP (float) regs */
   char *raw_buffer;
   double doub, flt1, flt2;     /* doubles extracted from raw hex data */
-  int inv1, inv2, inv3;
+  int inv1, inv2, namelen;
 
   raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
 
+  printf_filtered ("%s:", REGISTER_NAME (regnum));
+  printf_filtered ("%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), "");
+
   if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
     {
-      /* 4-byte registers: we can fit two registers per row.  */
-      /* Also print every pair of 4-byte regs as an 8-byte double.  */
+      /* 4-byte registers: Print hex and floating.  Also print even
+         numbered registers as doubles.  */
       mips_read_fp_register_single (regnum, raw_buffer);
       flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
 
-      mips_read_fp_register_single (regnum + 1, raw_buffer);
-      flt2 = unpack_double (mips_float_register_type (), raw_buffer, &inv2);
-
-      mips_read_fp_register_double (regnum, raw_buffer);
-      doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
+      print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
+                              gdb_stdout);
 
-      printf_filtered (" %-5s", REGISTER_NAME (regnum));
+      printf_filtered (" flt: ");
       if (inv1)
-       printf_filtered (": <invalid float>");
+       printf_filtered (" <invalid float> ");
       else
        printf_filtered ("%-17.9g", flt1);
 
-      printf_filtered (" %-5s", REGISTER_NAME (regnum + 1));
-      if (inv2)
-       printf_filtered (": <invalid float>");
-      else
-       printf_filtered ("%-17.9g", flt2);
-
-      printf_filtered (" dbl: ");
-      if (inv3)
-       printf_filtered ("<invalid double>");
-      else
-       printf_filtered ("%-24.17g", doub);
-      printf_filtered ("\n");
+      if (regnum % 2 == 0)
+       {
+         mips_read_fp_register_double (regnum, raw_buffer);
+         doub = unpack_double (mips_double_register_type (), raw_buffer,
+                               &inv2);
 
-      /* may want to do hex display here (future enhancement) */
-      regnum += 2;
+         printf_filtered (" dbl: ");
+         if (inv2)
+           printf_filtered ("<invalid double>");
+         else
+           printf_filtered ("%-24.17g", doub);
+       }
     }
   else
     {
-      /* Eight byte registers: print each one as float AND as double.  */
+      /* Eight byte registers: print each one as hex, float and double.  */
       mips_read_fp_register_single (regnum, raw_buffer);
       flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
 
       mips_read_fp_register_double (regnum, raw_buffer);
-      doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
+      doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
+
 
-      printf_filtered (" %-5s: ", REGISTER_NAME (regnum));
+      print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
+                              gdb_stdout);
+
+      printf_filtered (" flt: ");
       if (inv1)
        printf_filtered ("<invalid float>");
       else
-       printf_filtered ("flt: %-17.9g", flt1);
+       printf_filtered ("%-17.9g", flt1);
 
       printf_filtered (" dbl: ");
-      if (inv3)
+      if (inv2)
        printf_filtered ("<invalid double>");
       else
        printf_filtered ("%-24.17g", doub);
+    }
+}
 
-      printf_filtered ("\n");
-      /* may want to do hex display here (future enhancement) */
-      regnum++;
+static void
+mips_print_register (int regnum, int all)
+{
+  char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
+  int offset;
+
+  if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
+    {
+      mips_print_fp_register (regnum);
+      return;
     }
-  return regnum;
+
+  /* Get the data in raw format.  */
+  if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
+    {
+      printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
+      return;
+    }
+
+  fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
+
+  /* The problem with printing numeric register names (r26, etc.) is that
+     the user can't use them on input.  Probably the best solution is to
+     fix it so that either the numeric or the funky (a2, etc.) names
+     are accepted on input.  */
+  if (regnum < MIPS_NUMREGS)
+    printf_filtered ("(r%d): ", regnum);
+  else
+    printf_filtered (": ");
+
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+    offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
+  else
+    offset = 0;
+
+  print_scalar_formatted (raw_buffer + offset,
+                         REGISTER_VIRTUAL_TYPE (regnum),
+                         'x', 0, gdb_stdout);
+}
+
+/* Replacement for generic do_registers_info.
+   Print regs in pretty columns.  */
+
+static int
+do_fp_register_row (int regnum)
+{
+  printf_filtered (" ");
+  mips_print_fp_register (regnum);
+  printf_filtered ("\n");
+  return regnum + 1;
 }
 
+
 /* Print a row's worth of GP (int) registers, with name labels above */
 
 static int
@@ -5550,6 +5545,10 @@ mips_stab_reg_to_regnum (int num)
     return num;
   else if (num >= 38 && num < 70)
     return num + FP0_REGNUM - 38;
+  else if (num == 70)
+    return HI_REGNUM;
+  else if (num == 71)
+    return LO_REGNUM;
   else
     {
       /* This will hopefully (eventually) provoke a warning.  Should
@@ -5568,6 +5567,10 @@ mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
     return num;
   else if (num >= 32 && num < 64)
     return num + FP0_REGNUM - 32;
+  else if (num == 64)
+    return HI_REGNUM;
+  else if (num == 65)
+    return LO_REGNUM;
   else
     {
       /* This will hopefully (eventually) provoke a warning.  Should
@@ -5783,7 +5786,7 @@ mips_gdbarch_init (struct gdbarch_info info,
   switch (mips_abi)
     {
     case MIPS_ABI_O32:
-      set_gdbarch_push_arguments (gdbarch, mips_o32_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_o32_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
       set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
       tdep->mips_default_saved_regsize = 4;
@@ -5802,7 +5805,7 @@ mips_gdbarch_init (struct gdbarch_info info,
                                         mips_o32_use_struct_convention);
       break;
     case MIPS_ABI_O64:
-      set_gdbarch_push_arguments (gdbarch, mips_o64_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_o64_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
       tdep->mips_default_saved_regsize = 8;
@@ -5821,7 +5824,7 @@ mips_gdbarch_init (struct gdbarch_info info,
                                         mips_o32_use_struct_convention);
       break;
     case MIPS_ABI_EABI32:
-      set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
       tdep->mips_default_saved_regsize = 4;
@@ -5840,7 +5843,7 @@ mips_gdbarch_init (struct gdbarch_info info,
                                         mips_eabi_use_struct_convention);
       break;
     case MIPS_ABI_EABI64:
-      set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
       tdep->mips_default_saved_regsize = 8;
@@ -5859,7 +5862,7 @@ mips_gdbarch_init (struct gdbarch_info info,
                                         mips_eabi_use_struct_convention);
       break;
     case MIPS_ABI_N32:
-      set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
       set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
       tdep->mips_default_saved_regsize = 8;
@@ -5890,7 +5893,7 @@ mips_gdbarch_init (struct gdbarch_info info,
                                       mips_n32n64_reg_struct_has_addr);
       break;
     case MIPS_ABI_N64:
-      set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
+      set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
       set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
       set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
       tdep->mips_default_saved_regsize = 8;
@@ -5980,7 +5983,7 @@ mips_gdbarch_init (struct gdbarch_info info,
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
   set_gdbarch_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base.  */
   set_gdbarch_read_sp (gdbarch, mips_read_sp);
-  set_gdbarch_write_sp (gdbarch, generic_target_write_sp);
+  set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
 
   /* Add/remove bits from an address.  The MIPS needs be careful to
      ensure that all 32 bit addresses are sign extended to 64 bits.  */
@@ -6003,19 +6006,13 @@ mips_gdbarch_init (struct gdbarch_info info,
 
   /* MIPS version of CALL_DUMMY */
 
-  set_gdbarch_call_dummy_p (gdbarch, 1);
-  set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
   set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
-  set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
+  set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
   set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
-  set_gdbarch_call_dummy_start_offset (gdbarch, 0);
-  set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
-  set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
-  set_gdbarch_call_dummy_length (gdbarch, 0);
   set_gdbarch_fix_call_dummy (gdbarch, mips_fix_call_dummy);
   set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words);
   set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
-  set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
+  set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
   set_gdbarch_frame_align (gdbarch, mips_frame_align);
   set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
   set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
@@ -6024,7 +6021,7 @@ mips_gdbarch_init (struct gdbarch_info info,
   set_gdbarch_register_convert_to_raw (gdbarch, 
                                       mips_register_convert_to_raw);
 
-  set_gdbarch_frame_chain (gdbarch, mips_frame_chain);
+  set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
   set_gdbarch_frameless_function_invocation (gdbarch, 
                                             generic_frameless_function_invocation_not);
   set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
@@ -6057,7 +6054,7 @@ mips_gdbarch_init (struct gdbarch_info info,
   /* Hook in OS ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);
 
-  set_gdbarch_store_struct_return (gdbarch, mips_store_struct_return);
+  set_gdbarch_deprecated_store_struct_return (gdbarch, mips_store_struct_return);
   set_gdbarch_extract_struct_value_address (gdbarch, 
                                            mips_extract_struct_value_address);