Remove GDBARCH_BREAKPOINT_MANIPULATION and SET_GDBARCH_BREAKPOINT_MANIPULATION
[deliverable/binutils-gdb.git] / gdb / sh-tdep.c
index fc462a4a300f1f316b99a9806aa4246f9e6b1469..01a24010514cd5244fc19ceda403c8fca455ae9d 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for Renesas Super-H, for GDB.
 
-   Copyright (C) 1993-2005, 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 1993-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -32,8 +32,6 @@
 #include "value.h"
 #include "dis-asm.h"
 #include "inferior.h"
-#include "gdb_string.h"
-#include "gdb_assert.h"
 #include "arch-utils.h"
 #include "floatformat.h"
 #include "regcache.h"
@@ -54,6 +52,7 @@
 #include "dwarf2.h"
 /* registers numbers shared with the simulator.  */
 #include "gdb/sim-sh.h"
+#include <algorithm>
 
 /* List of "set sh ..." and "show sh ..." commands.  */
 static struct cmd_list_element *setshcmdlist = NULL;
@@ -342,15 +341,16 @@ sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
     /* bank 1 51 - 58 */
     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
+    /* 59 - 66 */
     "", "", "", "", "", "", "", "",
     /* pseudo bank register.  */
     "",
-    /* double precision (pseudo) 59 - 66 */
+    /* double precision (pseudo) 68 - 75 */
     "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
-    /* vectors (pseudo) 67 - 70 */
+    /* vectors (pseudo) 76 - 79 */
     "fv0", "fv4", "fv8", "fv12",
-    /* FIXME: missing XF 71 - 86 */
-    /* FIXME: missing XD 87 - 94 */
+    /* FIXME: missing XF */
+    /* FIXME: missing XD */
   };
   if (reg_nr < 0)
     return NULL;
@@ -379,12 +379,13 @@ sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
     "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
     /* bank 1 51 - 58 */
     "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
+    /* 59 - 66 */
     "", "", "", "", "", "", "", "",
     /* pseudo bank register.  */
     "",
-    /* double precision (pseudo) 59 - 66 -- not for nofpu target */
+    /* double precision (pseudo) 68 - 75 -- not for nofpu target */
     "", "", "", "", "", "", "", "",
-    /* vectors (pseudo) 67 - 70 -- not for nofpu target */
+    /* vectors (pseudo) 76 - 79 -- not for nofpu target */
     "", "", "", "",
   };
   if (reg_nr < 0)
@@ -417,11 +418,20 @@ sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
   return register_names[reg_nr];
 }
 
-static const unsigned char *
-sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
+/* Implement the breakpoint_kind_from_pc gdbarch method.  */
+
+static int
+sh_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 2;
+}
+
+/* Implement the sw_breakpoint_from_kind gdbarch method.  */
+
+static const gdb_byte *
+sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  /* 0xc3c3 is trapa #c3, and it works in big and little endian modes.  */
-  static unsigned char breakpoint[] = { 0xc3, 0xc3 };
+  *size = kind;
 
   /* For remote stub targets, trapa #20 is used.  */
   if (strcmp (target_shortname, "remote") == 0)
@@ -430,19 +440,18 @@ sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
 
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-       {
-         *lenptr = sizeof (big_remote_breakpoint);
-         return big_remote_breakpoint;
-       }
+       return big_remote_breakpoint;
       else
-       {
-         *lenptr = sizeof (little_remote_breakpoint);
-         return little_remote_breakpoint;
-       }
+       return little_remote_breakpoint;
     }
+  else
+    {
+      /* 0xc3c3 is trapa #c3, and it works in big and little endian
+        modes.  */
+      static unsigned char breakpoint[] = { 0xc3, 0xc3 };
 
-  *lenptr = sizeof (breakpoint);
-  return breakpoint;
+      return breakpoint;
+    }
 }
 
 /* Prologue looks like
@@ -654,7 +663,7 @@ sh_analyze_prologue (struct gdbarch *gdbarch,
        {
          pc += 2;
          /* Don't go any further than six more instructions.  */
-         limit_pc = min (limit_pc, pc + (2 * 6));
+         limit_pc = std::min (limit_pc, pc + (2 * 6));
 
          cache->uses_fp = 1;
          /* At this point, only allow argument register moves to other
@@ -728,7 +737,7 @@ sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
     {
       post_prologue_pc = skip_prologue_using_sal (gdbarch, func_addr);
       if (post_prologue_pc != 0)
-        return max (pc, post_prologue_pc);
+        return std::max (pc, post_prologue_pc);
     }
 
   /* Can't determine prologue from the symbol table, need to examine
@@ -745,7 +754,7 @@ sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   /* Do not allow limit_pc to be past the function end, if we know
      where that end is...  */
   if (func_end_addr != 0)
-    limit_pc = min (limit_pc, func_end_addr);
+    limit_pc = std::min (limit_pc, func_end_addr);
 
   cache.sp_offset = -4;
   post_prologue_pc = sh_analyze_prologue (gdbarch, pc, limit_pc, &cache, 0);
@@ -906,22 +915,22 @@ sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
    to R7.  */
 
 /* Helper function to justify value in register according to endianess.  */
-static char *
+static const gdb_byte *
 sh_justify_value_in_reg (struct gdbarch *gdbarch, struct value *val, int len)
 {
-  static char valbuf[4];
+  static gdb_byte valbuf[4];
 
   memset (valbuf, 0, sizeof (valbuf));
   if (len < 4)
     {
       /* value gets right-justified in the register or stack word.  */
       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-       memcpy (valbuf + (4 - len), (char *) value_contents (val), len);
+       memcpy (valbuf + (4 - len), value_contents (val), len);
       else
-       memcpy (valbuf, (char *) value_contents (val), len);
+       memcpy (valbuf, value_contents (val), len);
       return valbuf;
     }
-  return (char *) value_contents (val);
+  return value_contents (val);
 }
 
 /* Helper function to eval number of bytes to allocate on stack.  */
@@ -1066,7 +1075,7 @@ sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
   struct type *func_type = value_type (function);
   struct type *type;
   CORE_ADDR regval;
-  char *val;
+  const gdb_byte *val;
   int len, reg_size = 0;
   int pass_on_stack = 0;
   int treat_as_flt;
@@ -1207,7 +1216,7 @@ sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
   struct type *func_type = value_type (function);
   struct type *type;
   CORE_ADDR regval;
-  char *val;
+  const gdb_byte *val;
   int len, reg_size = 0;
   int pass_on_stack = 0;
   int last_reg_arg = INT_MAX;
@@ -1300,13 +1309,11 @@ sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
    TYPE, and copy that, in virtual format, into VALBUF.  */
 static void
 sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
-                              void *valbuf)
+                              gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int len = TYPE_LENGTH (type);
-  int return_register = R0_REGNUM;
-  int offset;
 
   if (len <= 4)
     {
@@ -1319,7 +1326,7 @@ sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
     {
       int i, regnum = R0_REGNUM;
       for (i = 0; i < len; i += 4)
-       regcache_raw_read (regcache, regnum++, (char *) valbuf + i);
+       regcache_raw_read (regcache, regnum++, valbuf + i);
     }
   else
     error (_("bad size for return value"));
@@ -1327,7 +1334,7 @@ sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
 
 static void
 sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
-                            void *valbuf)
+                            gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   if (sh_treat_as_flt_p (type))
@@ -1337,9 +1344,9 @@ sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
       for (i = 0; i < len; i += 4)
        if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
          regcache_raw_read (regcache, regnum++,
-                            (char *) valbuf + len - 4 - i);
+                            valbuf + len - 4 - i);
        else
-         regcache_raw_read (regcache, regnum++, (char *) valbuf + i);
+         regcache_raw_read (regcache, regnum++, valbuf + i);
     }
   else
     sh_extract_return_value_nofpu (type, regcache, valbuf);
@@ -1353,7 +1360,7 @@ sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
    the result is stored in r0, left-justified.  */
 static void
 sh_store_return_value_nofpu (struct type *type, struct regcache *regcache,
-                            const void *valbuf)
+                            const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
@@ -1369,13 +1376,13 @@ sh_store_return_value_nofpu (struct type *type, struct regcache *regcache,
     {
       int i, regnum = R0_REGNUM;
       for (i = 0; i < len; i += 4)
-       regcache_raw_write (regcache, regnum++, (char *) valbuf + i);
+       regcache_raw_write (regcache, regnum++, valbuf + i);
     }
 }
 
 static void
 sh_store_return_value_fpu (struct type *type, struct regcache *regcache,
-                          const void *valbuf)
+                          const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   if (sh_treat_as_flt_p (type))
@@ -1385,9 +1392,9 @@ sh_store_return_value_fpu (struct type *type, struct regcache *regcache,
       for (i = 0; i < len; i += 4)
        if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
          regcache_raw_write (regcache, regnum++,
-                             (char *) valbuf + len - 4 - i);
+                             valbuf + len - 4 - i);
        else
-         regcache_raw_write (regcache, regnum++, (char *) valbuf + i);
+         regcache_raw_write (regcache, regnum++, valbuf + i);
     }
   else
     sh_store_return_value_nofpu (type, regcache, valbuf);
@@ -1521,16 +1528,16 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 
 /* On the sh4, the DRi pseudo registers are problematic if the target
    is little endian.  When the user writes one of those registers, for
-   instance with 'ser var $dr0=1', we want the double to be stored
+   instance with 'set var $dr0=1', we want the double to be stored
    like this: 
-   fr0 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f 
-   fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
+   fr0 = 0x00 0x00 0xf0 0x3f 
+   fr1 = 0x00 0x00 0x00 0x00 
 
    This corresponds to little endian byte order & big endian word
    order.  However if we let gdb write the register w/o conversion, it
    will write fr0 and fr1 this way:
-   fr0 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
-   fr1 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
+   fr0 = 0x00 0x00 0x00 0x00
+   fr1 = 0x00 0x00 0xf0 0x3f
    because it will consider fr0 and fr1 as a single LE stretch of memory.
    
    To achieve what we want we must force gdb to store things in
@@ -1539,16 +1546,23 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 
    In case the target is big endian, there is no problem, the
    raw bytes will look like:
-   fr0 = 0x3f 0xf0 0x00 0x00 0x00 0x00 0x00
-   fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
+   fr0 = 0x3f 0xf0 0x00 0x00
+   fr1 = 0x00 0x00 0x00 0x00
 
    The other pseudo registers (the FVs) also don't pose a problem
    because they are stored as 4 individual FP elements.  */
 
 static void
-sh_register_convert_to_virtual (int regnum, struct type *type,
-                               char *from, char *to)
+sh_register_convert_to_virtual (struct gdbarch *gdbarch, int regnum,
+                               struct type *type, gdb_byte *from, gdb_byte *to)
 {
+  if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
+    {
+      /* It is a no-op.  */
+      memcpy (to, from, register_size (gdbarch, regnum));
+      return;
+    }
+
   if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
     {
       DOUBLEST val;
@@ -1562,9 +1576,16 @@ sh_register_convert_to_virtual (int regnum, struct type *type,
 }
 
 static void
-sh_register_convert_to_raw (struct type *type, int regnum,
-                           const void *from, void *to)
+sh_register_convert_to_raw (struct gdbarch *gdbarch, struct type *type,
+                           int regnum, const gdb_byte *from, gdb_byte *to)
 {
+  if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
+    {
+      /* It is a no-op.  */
+      memcpy (to, from, register_size (gdbarch, regnum));
+      return;
+    }
+
   if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
     {
       DOUBLEST val = extract_typed_floating (from, type);
@@ -1627,7 +1648,7 @@ sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
                         int reg_nr, gdb_byte *buffer)
 {
   int base_regnum;
-  char temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
   enum register_status status;
 
   if (reg_nr == PSEUDO_BANK_REGNUM)
@@ -1643,7 +1664,7 @@ sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
       if (status == REG_VALID)
        {
          /* We must pay attention to the endiannes. */
-         sh_register_convert_to_virtual (reg_nr,
+         sh_register_convert_to_virtual (gdbarch, reg_nr,
                                          register_type (gdbarch, reg_nr),
                                          temp_buffer, buffer);
        }
@@ -1666,7 +1687,7 @@ sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
                          int reg_nr, const gdb_byte *buffer)
 {
   int base_regnum, portion;
-  char temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
 
   if (reg_nr == PSEUDO_BANK_REGNUM)
     {
@@ -1685,7 +1706,7 @@ sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
       base_regnum = dr_reg_base_num (gdbarch, reg_nr);
 
       /* We must pay attention to the endiannes.  */
-      sh_register_convert_to_raw (register_type (gdbarch, reg_nr),
+      sh_register_convert_to_raw (gdbarch, register_type (gdbarch, reg_nr),
                                  reg_nr, buffer, temp_buffer);
 
       /* Write the real regs for which this one is an alias.  */
@@ -1702,7 +1723,7 @@ sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
       /* Write the real regs for which this one is an alias.  */
       for (portion = 0; portion < 4; portion++)
        regcache_raw_write (regcache, base_regnum + portion,
-                           ((char *) buffer
+                           (buffer
                             + register_size (gdbarch,
                                              base_regnum) * portion));
     }
@@ -1843,7 +1864,7 @@ sh_frame_cache (struct frame_info *this_frame, void **this_cache)
   int i;
 
   if (*this_cache)
-    return *this_cache;
+    return (struct sh_frame_cache *) *this_cache;
 
   cache = sh_alloc_frame_cache ();
   *this_cache = cache;
@@ -2007,7 +2028,7 @@ sh_stub_this_id (struct frame_info *this_frame, void **this_cache,
 
   if (*this_cache == NULL)
     *this_cache = sh_make_stub_cache (this_frame);
-  cache = *this_cache;
+  cache = (struct sh_frame_cache *) *this_cache;
 
   *this_id = frame_id_build (cache->saved_sp, get_frame_pc (this_frame));
 }
@@ -2020,7 +2041,7 @@ sh_stub_unwind_sniffer (const struct frame_unwind *self,
   CORE_ADDR addr_in_block;
 
   addr_in_block = get_frame_address_in_block (this_frame);
-  if (in_plt_section (addr_in_block, NULL))
+  if (in_plt_section (addr_in_block))
     return 1;
 
   return 0;
@@ -2036,11 +2057,14 @@ static const struct frame_unwind sh_stub_unwind =
   sh_stub_unwind_sniffer
 };
 
-/* The epilogue is defined here as the area at the end of a function,
+/* Implement the stack_frame_destroyed_p gdbarch method.
+
+   The epilogue is defined here as the area at the end of a function,
    either on the `ret' instruction itself or after an instruction which
    destroys the function's stack frame.  */
+
 static int
-sh_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
+sh_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR func_addr = 0, func_end = 0;
@@ -2179,33 +2203,33 @@ sh_corefile_collect_regset (const struct regset *regset,
 /* The following two regsets have the same contents, so it is tempting to
    unify them, but they are distiguished by their address, so don't.  */
 
-struct regset sh_corefile_gregset =
+const struct regset sh_corefile_gregset =
 {
   NULL,
   sh_corefile_supply_regset,
   sh_corefile_collect_regset
 };
 
-static struct regset sh_corefile_fpregset =
+static const struct regset sh_corefile_fpregset =
 {
   NULL,
   sh_corefile_supply_regset,
   sh_corefile_collect_regset
 };
 
-static const struct regset *
-sh_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name,
-                            size_t sect_size)
+static void
+sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
+                                iterate_over_regset_sections_cb *cb,
+                                void *cb_data,
+                                const struct regcache *regcache)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  if (tdep->core_gregmap && strcmp (sect_name, ".reg") == 0)
-    return &sh_corefile_gregset;
-
-  if (tdep->core_fpregmap && strcmp (sect_name, ".reg2") == 0)
-    return &sh_corefile_fpregset;
+  if (tdep->core_gregmap != NULL)
+    cb (".reg", tdep->sizeof_gregset, &sh_corefile_gregset, NULL, cb_data);
 
-  return NULL;
+  if (tdep->core_fpregmap != NULL)
+    cb (".reg2", tdep->sizeof_fpregset, &sh_corefile_fpregset, NULL, cb_data);
 }
 
 /* This is the implementation of gdbarch method
@@ -2237,7 +2261,7 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* None found, create a new architecture from the information
      provided.  */
-  tdep = XZALLOC (struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
@@ -2258,7 +2282,8 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_register_type (gdbarch, sh_default_register_type);
   set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch, sh_breakpoint_kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch, sh_sw_breakpoint_from_kind);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
@@ -2280,11 +2305,12 @@ sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_dummy_id (gdbarch, sh_dummy_id);
   frame_base_set_default (gdbarch, &sh_frame_base);
 
-  set_gdbarch_in_function_epilogue_p (gdbarch, sh_in_function_epilogue_p);
+  set_gdbarch_stack_frame_destroyed_p (gdbarch, sh_stack_frame_destroyed_p);
 
   dwarf2_frame_set_init_reg (gdbarch, sh_dwarf2_frame_init_reg);
 
-  set_gdbarch_regset_from_core_section (gdbarch, sh_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, sh_iterate_over_regset_sections);
 
   switch (info.bfd_arch_info->mach)
     {
This page took 0.032588 seconds and 4 git commands to generate.