Make Syd Polk principal maintainer.
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
index 5940f8422f7123c6c36d744232518901d21656b5..9bf761d1c9fbf9c901644a57807b15d40705a447 100644 (file)
@@ -33,6 +33,7 @@
 #include "objfiles.h"
 #include "gdbtypes.h"
 #include "target.h"
+#include "arch-utils.h"
 
 #include "opcode/mips.h"
 #include "elf/mips.h"
@@ -45,6 +46,22 @@ struct frame_extra_info
     int num_args;
   };
 
+/* We allow the user to override MIPS_SAVED_REGSIZE, so define
+   the subcommand enum settings allowed. */
+static char saved_gpreg_size_auto[] = "auto";
+static char saved_gpreg_size_32[] = "32";
+static char saved_gpreg_size_64[] = "64";
+
+static char *saved_gpreg_size_enums[] = {
+  saved_gpreg_size_auto,
+  saved_gpreg_size_32,
+  saved_gpreg_size_64,
+  0
+};
+
+/* The current (string) value of saved_gpreg_size. */
+static char *mips_saved_regsize_string = saved_gpreg_size_auto;
+
 /* Some MIPS boards don't support floating point while others only
    support single-precision floating-point operations.  See also
    FP_REGISTER_DOUBLE. */
@@ -63,10 +80,12 @@ static int mips_fpu_type_auto = 1;
 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
 #define MIPS_FPU_TYPE mips_fpu_type
 
-#ifndef MIPS_SAVED_REGSIZE
-#define MIPS_SAVED_REGSIZE MIPS_REGSIZE
+#ifndef MIPS_DEFAULT_SAVED_REGSIZE
+#define MIPS_DEFAULT_SAVED_REGSIZE MIPS_REGSIZE
 #endif
 
+#define MIPS_SAVED_REGSIZE (mips_saved_regsize())
+
 /* Do not use "TARGET_IS_MIPS64" to test the size of floating point registers */
 #ifndef FP_REGISTER_DOUBLE
 #define FP_REGISTER_DOUBLE (REGISTER_VIRTUAL_SIZE(FP0_REGNUM) == 8)
@@ -83,7 +102,7 @@ struct gdbarch_tdep
     enum mips_fpu_type mips_fpu_type;
     int mips_last_arg_regnum;
     int mips_last_fp_arg_regnum;
-    int mips_saved_regsize;
+    int mips_default_saved_regsize;
     int mips_fp_register_double;
   };
 
@@ -108,8 +127,8 @@ struct gdbarch_tdep
 #endif
 
 #if GDB_MULTI_ARCH
-#undef MIPS_SAVED_REGSIZE
-#define MIPS_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_saved_regsize)
+#undef MIPS_DEFAULT_SAVED_REGSIZE
+#define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
 #endif
 
 /* Indicate that the ABI makes use of double-precision registers
@@ -166,6 +185,10 @@ char *tmp_mips_processor_type;
 char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
 char **mips_processor_reg_names = mips_generic_reg_names;
 
+/* The list of available "set mips " and "show mips " commands */
+static struct cmd_list_element *setmipscmdlist = NULL;
+static struct cmd_list_element *showmipscmdlist = NULL;
+
 char *
 mips_register_name (i)
      int i;
@@ -303,6 +326,19 @@ mips_print_extra_frame_info (fi)
                     paddr_d (fi->extra_info->proc_desc->pdr.frameoffset));
 }
 
+/* Return the currently configured (or set) saved register size */
+
+static unsigned int
+mips_saved_regsize ()
+{
+  if (mips_saved_regsize_string == saved_gpreg_size_auto)
+    return MIPS_DEFAULT_SAVED_REGSIZE;
+  else if (mips_saved_regsize_string == saved_gpreg_size_64)
+    return 8;
+  else /* if (mips_saved_regsize_string == saved_gpreg_size_32) */
+    return 4;
+}
+
 /* Convert between RAW and VIRTUAL registers.  The RAW register size
    defines the remote-gdb packet. */
 
@@ -2475,7 +2511,7 @@ do_fp_register_row (regnum)
               regnum + 1, REGISTER_NAME (regnum + 1));
 
       /* copy the two floats into one double, and unpack both */
-      memcpy (dbl_buffer, raw_buffer, sizeof (dbl_buffer));
+      memcpy (dbl_buffer, raw_buffer, 2 * REGISTER_RAW_SIZE (FP0_REGNUM));
       flt1 = unpack_double (builtin_type_float, raw_buffer[HI], &inv1);
       flt2 = unpack_double (builtin_type_float, raw_buffer[LO], &inv2);
       doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
@@ -2493,7 +2529,7 @@ do_fp_register_row (regnum)
     {                          /* eight byte registers: print each one as float AND as double. */
       int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN);
 
-      memcpy (dbl_buffer, raw_buffer[HI], sizeof (dbl_buffer));
+      memcpy (dbl_buffer, raw_buffer[HI], 2 * REGISTER_RAW_SIZE (FP0_REGNUM));
       flt1 = unpack_double (builtin_type_float,
                            &raw_buffer[HI][offset], &inv1);
       doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
@@ -3144,6 +3180,28 @@ in_sigtramp (pc, ignore)
   return (pc >= sigtramp_address && pc < sigtramp_end);
 }
 
+/* Root of all "set mips "/"show mips " commands. This will eventually be
+   used for all MIPS-specific commands.  */
+
+static void show_mips_command PARAMS ((char *, int));
+static void
+show_mips_command (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
+}
+
+static void set_mips_command PARAMS ((char *, int));
+static void
+set_mips_command (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
+  help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
+}
+
 /* Commands to show/set the MIPS FPU type.  */
 
 static void show_mipsfpu_command PARAMS ((char *, int));
@@ -3639,6 +3697,24 @@ mips_call_dummy_address ()
 }
 
 
+/* If the current gcc for for this target does not produce correct debugging
+   information for float parameters, both prototyped and unprototyped, then
+   define this macro.  This forces gdb to  always assume that floats are
+   passed as doubles and then converted in the callee.
+
+   For the mips chip, it appears that the debug info marks the parameters as
+   floats regardless of whether the function is prototyped, but the actual
+   values are passed as doubles for the non-prototyped case and floats for
+   the prototyped case.  Thus we choose to make the non-prototyped case work
+   for C and break the prototyped case, since the non-prototyped case is
+   probably much more common.  (FIXME). */
+
+static int
+mips_coerce_float_to_double (struct type *formal, struct type *actual)
+{
+  return current_language->la_language == language_c;
+}
+
 
 static gdbarch_init_ftype mips_gdbarch_init;
 static struct gdbarch *
@@ -3690,7 +3766,7 @@ mips_gdbarch_init (info, arches)
     case E_MIPS_ABI_O32:
       ef_mips_abi = "o32";
       tdep->mips_eabi = 0;
-      tdep->mips_saved_regsize = 4;
+      tdep->mips_default_saved_regsize = 4;
       tdep->mips_fp_register_double = 0;
       set_gdbarch_long_bit (gdbarch, 32);
       set_gdbarch_ptr_bit (gdbarch, 32);
@@ -3699,7 +3775,7 @@ mips_gdbarch_init (info, arches)
     case E_MIPS_ABI_O64:
       ef_mips_abi = "o64";
       tdep->mips_eabi = 0;
-      tdep->mips_saved_regsize = 8;
+      tdep->mips_default_saved_regsize = 8;
       tdep->mips_fp_register_double = 1;
       set_gdbarch_long_bit (gdbarch, 32);
       set_gdbarch_ptr_bit (gdbarch, 32);
@@ -3708,7 +3784,7 @@ mips_gdbarch_init (info, arches)
     case E_MIPS_ABI_EABI32:
       ef_mips_abi = "eabi32";
       tdep->mips_eabi = 1;
-      tdep->mips_saved_regsize = 4;
+      tdep->mips_default_saved_regsize = 4;
       tdep->mips_fp_register_double = 0;
       set_gdbarch_long_bit (gdbarch, 32);
       set_gdbarch_ptr_bit (gdbarch, 32);
@@ -3717,7 +3793,7 @@ mips_gdbarch_init (info, arches)
     case E_MIPS_ABI_EABI64:
       ef_mips_abi = "eabi64";
       tdep->mips_eabi = 1;
-      tdep->mips_saved_regsize = 8;
+      tdep->mips_default_saved_regsize = 8;
       tdep->mips_fp_register_double = 1;
       set_gdbarch_long_bit (gdbarch, 64);
       set_gdbarch_ptr_bit (gdbarch, 64);
@@ -3726,7 +3802,7 @@ mips_gdbarch_init (info, arches)
     default:
       ef_mips_abi = "default";
       tdep->mips_eabi = 0;
-      tdep->mips_saved_regsize = MIPS_REGSIZE;
+      tdep->mips_default_saved_regsize = MIPS_REGSIZE;
       tdep->mips_fp_register_double = (REGISTER_VIRTUAL_SIZE (FP0_REGNUM) == 8);
       set_gdbarch_long_bit (gdbarch, 32);
       set_gdbarch_ptr_bit (gdbarch, 32);
@@ -3734,6 +3810,27 @@ mips_gdbarch_init (info, arches)
       break;
     }
 
+  /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
+     that could indicate -gp32 BUT gas/config/tc-mips.c contains the
+     comment:
+
+     ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
+     flag in object files because to do so would make it impossible to
+     link with libraries compiled without "-gp32". This is
+     unnecessarily restrictive.
+     We could solve this problem by adding "-gp32" multilibs to gcc,
+     but to set this flag before gcc is built with such multilibs will
+     break too many systems.''
+
+     But even more unhelpfully, the default linker output target for
+     mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
+     for 64-bit programs - you need to change the ABI to change this,
+     and not all gcc targets support that currently. Therefore using
+     this flag to detect 32-bit mode would do the wrong thing given
+     the current gcc - it would make GDB treat these 64-bit programs
+     as 32-bit programs by default. */
+
   /* determine the ISA */
   switch (elf_flags & EF_MIPS_ARCH)
     {
@@ -3835,6 +3932,7 @@ mips_gdbarch_init (info, arches)
   set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
   set_gdbarch_push_arguments (gdbarch, mips_push_arguments);
   set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not);
+  set_gdbarch_coerce_float_to_double (gdbarch, mips_coerce_float_to_double);
 
   set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
   set_gdbarch_get_saved_register (gdbarch, default_get_saved_register);
@@ -3871,8 +3969,8 @@ mips_gdbarch_init (info, arches)
                         : tdep->mips_fpu_type == MIPS_FPU_DOUBLE ? "double"
                           : "???"));
       fprintf_unfiltered (gdb_stderr,
-                      "mips_gdbarch_init: tdep->mips_saved_regsize = %d\n",
-                         tdep->mips_saved_regsize);
+                      "mips_gdbarch_init: tdep->mips_default_saved_regsize = %d\n",
+                         tdep->mips_default_saved_regsize);
       fprintf_unfiltered (gdb_stderr,
             "mips_gdbarch_init: tdep->mips_fp_register_double = %d (%s)\n",
                          tdep->mips_fp_register_double,
@@ -3894,6 +3992,30 @@ _initialize_mips_tdep ()
   if (!tm_print_insn)          /* Someone may have already set it */
     tm_print_insn = gdb_print_insn_mips;
 
+  /* Add root prefix command for all "set mips"/"show mips" commands */
+  add_prefix_cmd ("mips", no_class, set_mips_command,
+                 "Various MIPS specific commands.",
+                 &setmipscmdlist, "set mips ", 0, &setlist);
+
+  add_prefix_cmd ("mips", no_class, show_mips_command,
+                 "Various MIPS specific commands.",
+                 &showmipscmdlist, "show mips ", 0, &showlist);
+
+  /* Allow the user to override the saved register size. */
+  add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
+                                 class_obscure,
+                                 saved_gpreg_size_enums,
+                                 (char *) &mips_saved_regsize_string, "\
+Set size of general purpose registers saved on the stack.\n\
+This option can be set to one of:\n\
+  32    - Force GDB to treat saved GP registers as 32-bit\n\
+  64    - Force GDB to treat saved GP registers as 64-bit\n\
+  auto  - Allow GDB to use the target's default setting or autodetect the\n\
+          saved GP register size from information contained in the executable.\n\
+          (default: auto)",
+                                 &setmipscmdlist),
+                    &showmipscmdlist);
+
   /* Let the user turn off floating point and set the fence post for
      heuristic_proc_start.  */
 
This page took 0.027704 seconds and 4 git commands to generate.