gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / ppc64-tdep.c
index b7357e3c43af98a85bedf977b5a9360957406282..583768ccfa7428e8077c407637eb715c79b43a91 100644 (file)
@@ -1,6 +1,6 @@
 /* Common target-dependent code for ppc64 GDB, the GNU debugger.
 
-   Copyright (C) 1986-2016 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    you can use -1 to make masks.  */
 
 #define insn_d(opcd, rts, ra, d)                \
-  ((((opcd) & 0x3f) << 26)                      \
-   | (((rts) & 0x1f) << 21)                     \
-   | (((ra) & 0x1f) << 16)                      \
-   | ((d) & 0xffff))
+  ((((unsigned (opcd)) & 0x3f) << 26)          \
+   | (((unsigned (rts)) & 0x1f) << 21)         \
+   | (((unsigned (ra)) & 0x1f) << 16)          \
+   | ((unsigned (d)) & 0xffff))
 
 #define insn_ds(opcd, rts, ra, d, xo)           \
-  ((((opcd) & 0x3f) << 26)                      \
-   | (((rts) & 0x1f) << 21)                     \
-   | (((ra) & 0x1f) << 16)                      \
-   | ((d) & 0xfffc)                             \
-   | ((xo) & 0x3))
+  ((((unsigned (opcd)) & 0x3f) << 26)                      \
+   | (((unsigned (rts)) & 0x1f) << 21)                     \
+   | (((unsigned (ra)) & 0x1f) << 16)                      \
+   | ((unsigned (d)) & 0xfffc)                             \
+   | ((unsigned (xo)) & 0x3))
 
 #define insn_xfx(opcd, rts, spr, xo)            \
-  ((((opcd) & 0x3f) << 26)                      \
-   | (((rts) & 0x1f) << 21)                     \
-   | (((spr) & 0x1f) << 16)                     \
-   | (((spr) & 0x3e0) << 6)                     \
-   | (((xo) & 0x3ff) << 1))
+  ((((unsigned (opcd)) & 0x3f) << 26)                      \
+   | (((unsigned (rts)) & 0x1f) << 21)                     \
+   | (((unsigned (spr)) & 0x1f) << 16)                     \
+   | (((unsigned (spr)) & 0x3e0) << 6)                     \
+   | (((unsigned (xo)) & 0x3ff) << 1))
 
-/* If PLT is the address of a 64-bit PowerPC PLT entry,
-   return the function's entry point.  */
+/* PLT_OFF is the TOC-relative offset of a 64-bit PowerPC PLT entry.
+   Return the function's entry point.  */
 
 static CORE_ADDR
-ppc64_plt_entry_point (struct gdbarch *gdbarch, CORE_ADDR plt)
+ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
+  struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  CORE_ADDR tocp;
+
+  if (execution_direction == EXEC_REVERSE)
+    {
+      /* If executing in reverse, r2 will have been stored to the stack.  */
+      CORE_ADDR sp = get_frame_register_unsigned (frame,
+                                                 tdep->ppc_gp0_regnum + 1);
+      unsigned int sp_off = tdep->elf_abi == POWERPC_ELF_V1 ? 40 : 24;
+      tocp = read_memory_unsigned_integer (sp + sp_off, 8, byte_order);
+    }
+  else
+    tocp = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2);
+
   /* The first word of the PLT entry is the function entry point.  */
-  return (CORE_ADDR) read_memory_unsigned_integer (plt, 8, byte_order);
+  return read_memory_unsigned_integer (tocp + plt_off, 8, byte_order);
 }
 
 /* Patterns for the standard linkage functions.  These are built by
@@ -65,13 +80,13 @@ ppc64_plt_entry_point (struct gdbarch *gdbarch, CORE_ADDR plt)
 
 /* Old ELFv1 PLT call stub.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage1[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage1[] =
   {
     /* addis r12, r2, <any> */
     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
 
     /* std r2, 40(r1) */
-    { -1, insn_ds (62, 2, 1, 40, 0), 0 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 0 },
 
     /* ld r11, <any>(r12) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
@@ -92,7 +107,7 @@ static struct ppc_insn_pattern ppc64_standard_linkage1[] =
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
 
     /* bctr */
-    { -1, 0x4e800420, 0 },
+    { (unsigned) -1, 0x4e800420, 0 },
 
     { 0, 0, 0 }
   };
@@ -104,16 +119,16 @@ static struct ppc_insn_pattern ppc64_standard_linkage1[] =
    instructions following "cmpldi r2, 0", "bnectr+" and "b <glink_i>",
    but there isn't any need to match them.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage2[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage2[] =
   {
     /* std r2, 40(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
 
     /* addis r12, r2, <any> */
     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
 
     /* std r2, 40(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
 
     /* ld r11, <any>(r12) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 },
@@ -125,10 +140,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage2[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
 
     /* xor r11, r11, r11 <optional> */
-    { -1, 0x7d6b5a78, 1 },
+    { (unsigned) -1, 0x7d6b5a78, 1 },
 
     /* add r12, r12, r11 <optional> */
-    { -1, 0x7d8c5a14, 1 },
+    { (unsigned) -1, 0x7d8c5a14, 1 },
 
     /* ld r2, <any>(r12) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 },
@@ -137,20 +152,20 @@ static struct ppc_insn_pattern ppc64_standard_linkage2[] =
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 1 },
 
     /* bctr <optional> */
-    { -1, 0x4e800420, 1 },
+    { (unsigned) -1, 0x4e800420, 1 },
 
     /* cmpldi r2, 0 <optional> */
-    { -1, 0x28220000, 1 },
+    { (unsigned) -1, 0x28220000, 1 },
 
     { 0, 0, 0 }
   };
 
 /* ELFv1 PLT call stub to access PLT entries within +/- 32k of r2.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage3[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage3[] =
   {
     /* std r2, 40(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
 
     /* ld r11, <any>(r2) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 },
@@ -162,10 +177,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage3[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 },
 
     /* xor r11, r11, r11 <optional> */
-    { -1, 0x7d6b5a78, 1 },
+    { (unsigned) -1, 0x7d6b5a78, 1 },
 
     /* add r2, r2, r11 <optional> */
-    { -1, 0x7c425a14, 1 },
+    { (unsigned) -1, 0x7c425a14, 1 },
 
     /* ld r11, <any>(r2) <optional> */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },
@@ -174,10 +189,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage3[] =
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
 
     /* bctr <optional> */
-    { -1, 0x4e800420, 1 },
+    { (unsigned) -1, 0x4e800420, 1 },
 
     /* cmpldi r2, 0 <optional> */
-    { -1, 0x28220000, 1 },
+    { (unsigned) -1, 0x28220000, 1 },
 
     { 0, 0, 0 }
   };
@@ -186,10 +201,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage3[] =
    A more modern variant of ppc64_standard_linkage2 differing in
    register usage.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage4[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage4[] =
   {
     /* std r2, 40(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
 
     /* addis r11, r2, <any> */
     { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },
@@ -204,10 +219,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage4[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
 
     /* xor r2, r12, r12 <optional> */
-    { -1, 0x7d826278, 1 },
+    { (unsigned) -1, 0x7d826278, 1 },
 
     /* add r11, r11, r2 <optional> */
-    { -1, 0x7d6b1214, 1 },
+    { (unsigned) -1, 0x7d6b1214, 1 },
 
     /* ld r2, <any>(r11) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 11, 0, 0), 0 },
@@ -216,10 +231,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage4[] =
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 11, 0, 0), 1 },
 
     /* bctr <optional> */
-    { -1, 0x4e800420, 1 },
+    { (unsigned) -1, 0x4e800420, 1 },
 
     /* cmpldi r2, 0 <optional> */
-    { -1, 0x28220000, 1 },
+    { (unsigned) -1, 0x28220000, 1 },
 
     { 0, 0, 0 }
   };
@@ -228,10 +243,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage4[] =
    A more modern variant of ppc64_standard_linkage3 differing in
    register usage.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage5[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage5[] =
   {
     /* std r2, 40(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 40, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 40, 0), 1 },
 
     /* ld r12, <any>(r2) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },
@@ -243,10 +258,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage5[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
 
     /* xor r11, r12, r12 <optional> */
-    { -1, 0x7d8b6278, 1 },
+    { (unsigned) -1, 0x7d8b6278, 1 },
 
     /* add r2, r2, r11 <optional> */
-    { -1, 0x7c425a14, 1 },
+    { (unsigned) -1, 0x7c425a14, 1 },
 
     /* ld r11, <any>(r2) <optional> */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 1 },
@@ -255,20 +270,20 @@ static struct ppc_insn_pattern ppc64_standard_linkage5[] =
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 },
 
     /* bctr <optional> */
-    { -1, 0x4e800420, 1 },
+    { (unsigned) -1, 0x4e800420, 1 },
 
     /* cmpldi r2, 0 <optional> */
-    { -1, 0x28220000, 1 },
+    { (unsigned) -1, 0x28220000, 1 },
 
     { 0, 0, 0 }
   };
 
 /* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage6[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage6[] =
   {
     /* std r2, 24(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 24, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
 
     /* addis r11, r2, <any> */
     { insn_d (-1, -1, -1, 0), insn_d (15, 11, 2, 0), 0 },
@@ -280,17 +295,17 @@ static struct ppc_insn_pattern ppc64_standard_linkage6[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
 
     /* bctr */
-    { -1, 0x4e800420, 0 },
+    { (unsigned) -1, 0x4e800420, 0 },
 
     { 0, 0, 0 }
   };
 
 /* ELFv2 PLT call stub to access PLT entries within +/- 32k of r2.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage7[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage7[] =
   {
     /* std r2, 24(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 24, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
 
     /* ld r12, <any>(r2) */
     { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 12, 2, 0, 0), 0 },
@@ -299,7 +314,7 @@ static struct ppc_insn_pattern ppc64_standard_linkage7[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
 
     /* bctr */
-    { -1, 0x4e800420, 0 },
+    { (unsigned) -1, 0x4e800420, 0 },
 
     { 0, 0, 0 }
   };
@@ -307,10 +322,10 @@ static struct ppc_insn_pattern ppc64_standard_linkage7[] =
 /* ELFv2 PLT call stub to access PLT entries more than +/- 32k from r2,
    supporting fusion.  */
 
-static struct ppc_insn_pattern ppc64_standard_linkage8[] =
+static const struct ppc_insn_pattern ppc64_standard_linkage8[] =
   {
     /* std r2, 24(r1) <optional> */
-    { -1, insn_ds (62, 2, 1, 24, 0), 1 },
+    { (unsigned) -1, insn_ds (62, 2, 1, 24, 0), 1 },
 
     /* addis r12, r2, <any> */
     { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 },
@@ -322,7 +337,7 @@ static struct ppc_insn_pattern ppc64_standard_linkage8[] =
     { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 12, 9, 467), 0 },
 
     /* bctr */
-    { -1, 0x4e800420, 0 },
+    { (unsigned) -1, 0x4e800420, 0 },
 
     { 0, 0, 0 }
   };
@@ -377,74 +392,44 @@ static struct ppc_insn_pattern ppc64_standard_linkage8[] =
    the linkage function.  */
 
 /* If the current thread is about to execute a series of instructions
-   at PC matching the ppc64_standard_linkage pattern, and INSN is the result
+   matching the ppc64_standard_linkage pattern, and INSN is the result
    from that pattern match, return the code address to which the
    standard linkage function will send them.  (This doesn't deal with
    dynamic linker lazy symbol resolution stubs.)  */
 
 static CORE_ADDR
-ppc64_standard_linkage1_target (struct frame_info *frame,
-                               CORE_ADDR pc, unsigned int *insn)
+ppc64_standard_linkage1_target (struct frame_info *frame, unsigned int *insn)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  /* The address of the PLT entry this linkage function references.  */
-  CORE_ADDR plt
-    = ((CORE_ADDR) get_frame_register_unsigned (frame,
-                                               tdep->ppc_gp0_regnum + 2)
-       + (ppc_insn_d_field (insn[0]) << 16)
-       + ppc_insn_ds_field (insn[2]));
+  CORE_ADDR plt_off = ((ppc_insn_d_field (insn[0]) << 16)
+                      + ppc_insn_ds_field (insn[2]));
 
-  return ppc64_plt_entry_point (gdbarch, plt);
+  return ppc64_plt_entry_point (frame, plt_off);
 }
 
 static CORE_ADDR
-ppc64_standard_linkage2_target (struct frame_info *frame,
-                               CORE_ADDR pc, unsigned int *insn)
+ppc64_standard_linkage2_target (struct frame_info *frame, unsigned int *insn)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  /* The address of the PLT entry this linkage function references.  */
-  CORE_ADDR plt
-    = ((CORE_ADDR) get_frame_register_unsigned (frame,
-                                               tdep->ppc_gp0_regnum + 2)
-       + (ppc_insn_d_field (insn[1]) << 16)
-       + ppc_insn_ds_field (insn[3]));
+  CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
+                      + ppc_insn_ds_field (insn[3]));
 
-  return ppc64_plt_entry_point (gdbarch, plt);
+  return ppc64_plt_entry_point (frame, plt_off);
 }
 
 static CORE_ADDR
-ppc64_standard_linkage3_target (struct frame_info *frame,
-                               CORE_ADDR pc, unsigned int *insn)
+ppc64_standard_linkage3_target (struct frame_info *frame, unsigned int *insn)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  CORE_ADDR plt_off = ppc_insn_ds_field (insn[1]);
 
-  /* The address of the PLT entry this linkage function references.  */
-  CORE_ADDR plt
-    = ((CORE_ADDR) get_frame_register_unsigned (frame,
-                                               tdep->ppc_gp0_regnum + 2)
-       + ppc_insn_ds_field (insn[1]));
-
-  return ppc64_plt_entry_point (gdbarch, plt);
+  return ppc64_plt_entry_point (frame, plt_off);
 }
 
 static CORE_ADDR
-ppc64_standard_linkage4_target (struct frame_info *frame,
-                               CORE_ADDR pc, unsigned int *insn)
+ppc64_standard_linkage4_target (struct frame_info *frame, unsigned int *insn)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  CORE_ADDR plt
-    = ((CORE_ADDR) get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 2)
-       + (ppc_insn_d_field (insn[1]) << 16)
-       + ppc_insn_ds_field (insn[2]));
+  CORE_ADDR plt_off = ((ppc_insn_d_field (insn[1]) << 16)
+                      + ppc_insn_ds_field (insn[2]));
 
-  return ppc64_plt_entry_point (gdbarch, plt);
+  return ppc64_plt_entry_point (frame, plt_off);
 }
 
 
@@ -480,39 +465,39 @@ ppc64_skip_trampoline_code_1 (struct frame_info *frame, CORE_ADDR pc)
     {
       if (i < ARRAY_SIZE (ppc64_standard_linkage8) - 1
          && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
-       pc = ppc64_standard_linkage4_target (frame, pc, insns);
+       pc = ppc64_standard_linkage4_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage7) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7,
                                           insns))
-       pc = ppc64_standard_linkage3_target (frame, pc, insns);
+       pc = ppc64_standard_linkage3_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage6) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6,
                                           insns))
-       pc = ppc64_standard_linkage4_target (frame, pc, insns);
+       pc = ppc64_standard_linkage4_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage5) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5,
                                           insns)
               && (insns[8] != 0 || insns[9] != 0))
-       pc = ppc64_standard_linkage3_target (frame, pc, insns);
+       pc = ppc64_standard_linkage3_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage4) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4,
                                           insns)
               && (insns[9] != 0 || insns[10] != 0))
-       pc = ppc64_standard_linkage4_target (frame, pc, insns);
+       pc = ppc64_standard_linkage4_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage3) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3,
                                           insns)
               && (insns[8] != 0 || insns[9] != 0))
-       pc = ppc64_standard_linkage3_target (frame, pc, insns);
+       pc = ppc64_standard_linkage3_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage2) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2,
                                           insns)
               && (insns[10] != 0 || insns[11] != 0))
-       pc = ppc64_standard_linkage2_target (frame, pc, insns);
+       pc = ppc64_standard_linkage2_target (frame, insns);
       else if (i < ARRAY_SIZE (ppc64_standard_linkage1) - 1
               && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1,
                                           insns))
-       pc = ppc64_standard_linkage1_target (frame, pc, insns);
+       pc = ppc64_standard_linkage1_target (frame, insns);
       else
        {
          /* Scan backward one more instructions if doesn't match.  */
@@ -608,8 +593,8 @@ ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
                                      s->the_bfd_section,
                                      &buf, addr - s->addr, 8);
       if (res != 0)
-       return extract_unsigned_integer (buf, 8, byte_order)
-               - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr;
+       return (extract_unsigned_integer (buf, 8, byte_order)
+               - bfd_section_vma (s->the_bfd_section) + s->addr);
    }
 
   return addr;
This page took 0.04251 seconds and 4 git commands to generate.