Split breakpoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
[deliverable/binutils-gdb.git] / gdb / sh64-tdep.c
index f751b296d096c48a6abc4d47308340e4ba6db37c..97e5a587f1eadb533a30ffaf5ec124c040461244 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for Renesas Super-H, for GDB.
 
-   Copyright (C) 1993-2015 Free Software Foundation, Inc.
+   Copyright (C) 1993-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -45,6 +45,7 @@
 #include "gdb/sim-sh.h"
 #include "language.h"
 #include "sh64-tdep.h"
+#include <algorithm>
 
 /* Information that is dependent on the processor variant.  */
 enum sh_abi
@@ -252,11 +253,24 @@ pc_is_isa32 (bfd_vma memaddr)
     return 0;
 }
 
-static const unsigned char *
-sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
-                        CORE_ADDR *pcptr, int *lenptr)
+static int
+sh64_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  /* The BRK instruction for shmedia is 
+  if (pc_is_isa32 (*pcptr))
+    {
+      *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
+      return 4;
+    }
+  else
+    return 2;
+}
+
+static const gdb_byte *
+sh64_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+  *size = kind;
+
+  /* The BRK instruction for shmedia is
      01101111 11110101 11111111 11110000
      which translates in big endian mode to 0x6f, 0xf5, 0xff, 0xf0
      and in little endian mode to 0xf0, 0xff, 0xf5, 0x6f */
@@ -266,44 +280,34 @@ sh64_breakpoint_from_pc (struct gdbarch *gdbarch,
      which translates in big endian mode to 0x0, 0x3b
      and in little endian mode to 0x3b, 0x0 */
 
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+  if (kind == 4)
     {
-      if (pc_is_isa32 (*pcptr))
-       {
-         static unsigned char big_breakpoint_media[] = {
-           0x6f, 0xf5, 0xff, 0xf0
-         };
-         *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-         *lenptr = sizeof (big_breakpoint_media);
-         return big_breakpoint_media;
-       }
+      static unsigned char big_breakpoint_media[] = {
+       0x6f, 0xf5, 0xff, 0xf0
+      };
+      static unsigned char little_breakpoint_media[] = {
+       0xf0, 0xff, 0xf5, 0x6f
+      };
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+       return big_breakpoint_media;
       else
-       {
-         static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
-         *lenptr = sizeof (big_breakpoint_compact);
-         return big_breakpoint_compact;
-       }
+       return little_breakpoint_media;
     }
   else
     {
-      if (pc_is_isa32 (*pcptr))
-       {
-         static unsigned char little_breakpoint_media[] = {
-           0xf0, 0xff, 0xf5, 0x6f
-         };
-         *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
-         *lenptr = sizeof (little_breakpoint_media);
-         return little_breakpoint_media;
-       }
+      static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
+      static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
+
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+       return big_breakpoint_compact;
       else
-       {
-         static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
-         *lenptr = sizeof (little_breakpoint_compact);
-         return little_breakpoint_compact;
-       }
+       return little_breakpoint_compact;
     }
 }
 
+GDBARCH_BREAKPOINT_FROM_PC (sh64)
+
 /* Prologue looks like
    [mov.l       <regs>,@-r15]...
    [sts.l       pr,@-r15]
@@ -685,7 +689,7 @@ sh64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
   /* If after_prologue returned a useful address, then use it.  Else
      fall back on the instruction skipping code.  */
   if (post_prologue_pc != 0)
-    return max (pc, post_prologue_pc);
+    return std::max (pc, post_prologue_pc);
   else
     return sh64_skip_prologue_hard_way (gdbarch, pc);
 }
@@ -861,9 +865,6 @@ sh64_analyze_prologue (struct gdbarch *gdbarch,
   int insn;
   int r0_val = 0;
   int insn_size;
-  int gdb_register_number;
-  int register_number;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   
   cache->sp_offset = 0;
@@ -904,8 +905,11 @@ sh64_analyze_prologue (struct gdbarch *gdbarch,
            }
 
          else if (IS_MOV_R14 (insn))
-           cache->saved_regs[MEDIA_FP_REGNUM] =
-             cache->sp_offset - ((((insn & 0xf) ^ 0x8) - 0x8) << 2);
+           {
+             cache->saved_regs[MEDIA_FP_REGNUM] =
+               cache->sp_offset - ((((insn & 0xf) ^ 0x8) - 0x8) << 2);
+             cache->uses_fp = 1;
+           }
 
          else if (IS_MOV_R0 (insn))
            {
@@ -934,6 +938,7 @@ sh64_analyze_prologue (struct gdbarch *gdbarch,
              /* Store R14 at r0_val-4 from SP.  Decrement r0 by 4.  */
              cache->saved_regs[MEDIA_FP_REGNUM] = cache->sp_offset
                                                   - (r0_val - 4);
+             cache->uses_fp = 1;
              r0_val -= 4;
            }
 
@@ -960,22 +965,25 @@ sh64_analyze_prologue (struct gdbarch *gdbarch,
                                                 9) << 2);
 
          else if (IS_STQ_R14_R15 (insn))
-           cache->saved_regs[MEDIA_FP_REGNUM]
-             = cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10,
-                                                9) << 3);
+           {
+             cache->saved_regs[MEDIA_FP_REGNUM]
+               = cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10,
+                                                  9) << 3);
+             cache->uses_fp = 1;
+           }
 
          else if (IS_STL_R14_R15 (insn))
-           cache->saved_regs[MEDIA_FP_REGNUM]
-             = cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10,
-                                                9) << 2);
+           {
+             cache->saved_regs[MEDIA_FP_REGNUM]
+               = cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10,
+                                                  9) << 2);
+             cache->uses_fp = 1;
+           }
 
          else if (IS_MOV_SP_FP_MEDIA (insn))
            break;
        }
     }
-
-  if (cache->saved_regs[MEDIA_FP_REGNUM] >= 0)
-    cache->uses_fp = 1;
 }
 
 static CORE_ADDR
@@ -1058,8 +1066,6 @@ sh64_push_dummy_call (struct gdbarch *gdbarch,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int stack_offset, stack_alloc;
   int int_argreg;
-  int float_argreg;
-  int double_argreg;
   int float_arg_index = 0;
   int double_arg_index = 0;
   int argnum;
@@ -1093,8 +1099,6 @@ sh64_push_dummy_call (struct gdbarch *gdbarch,
      in eight registers available.  Loop thru args from first to last.  */
 
   int_argreg = ARG0_REGNUM;
-  float_argreg = gdbarch_fp0_regnum (gdbarch);
-  double_argreg = DR0_REGNUM;
 
   for (argnum = 0, stack_offset = 0; argnum < nargs; argnum++)
     {
@@ -1225,7 +1229,6 @@ sh64_extract_return_value (struct type *type, struct regcache *regcache,
                           gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
@@ -1919,7 +1922,6 @@ sh64_do_fp_register (struct gdbarch *gdbarch, struct ui_file *file,
   unsigned char *raw_buffer;
   double flt;  /* Double extracted from raw hex data.  */
   int inv;
-  int j;
 
   /* Allocate space for the float.  */
   raw_buffer = (unsigned char *)
@@ -2411,7 +2413,7 @@ sh64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
   set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
 
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh64_breakpoint_from_pc);
+  SET_GDBARCH_BREAKPOINT_MANIPULATION (sh64);
 
   set_gdbarch_print_insn (gdbarch, print_insn_sh);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
This page took 0.028857 seconds and 4 git commands to generate.