gdb/rs6000-tdep.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for GDB, the GNU debugger.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "inferior.h"
  17. #include "infrun.h"
  18. #include "symtab.h"
  19. #include "target.h"
  20. #include "gdbcore.h"
  21. #include "gdbcmd.h"
  22. #include "objfiles.h"
  23. #include "arch-utils.h"
  24. #include "regcache.h"
  25. #include "regset.h"
  26. #include "doublest.h"
  27. #include "value.h"
  28. #include "parser-defs.h"
  29. #include "osabi.h"
  30. #include "infcall.h"
  31. #include "sim-regno.h"
  32. #include "gdb/sim-ppc.h"
  33. #include "reggroups.h"
  34. #include "dwarf2-frame.h"
  35. #include "target-descriptions.h"
  36. #include "user-regs.h"

  37. #include "libbfd.h"                /* for bfd_default_set_arch_mach */
  38. #include "coff/internal.h"        /* for libcoff.h */
  39. #include "libcoff.h"                /* for xcoff_data */
  40. #include "coff/xcoff.h"
  41. #include "libxcoff.h"

  42. #include "elf-bfd.h"
  43. #include "elf/ppc.h"
  44. #include "elf/ppc64.h"

  45. #include "solib-svr4.h"
  46. #include "ppc-tdep.h"
  47. #include "ppc-ravenscar-thread.h"

  48. #include "dis-asm.h"

  49. #include "trad-frame.h"
  50. #include "frame-unwind.h"
  51. #include "frame-base.h"

  52. #include "features/rs6000/powerpc-32.c"
  53. #include "features/rs6000/powerpc-altivec32.c"
  54. #include "features/rs6000/powerpc-vsx32.c"
  55. #include "features/rs6000/powerpc-403.c"
  56. #include "features/rs6000/powerpc-403gc.c"
  57. #include "features/rs6000/powerpc-405.c"
  58. #include "features/rs6000/powerpc-505.c"
  59. #include "features/rs6000/powerpc-601.c"
  60. #include "features/rs6000/powerpc-602.c"
  61. #include "features/rs6000/powerpc-603.c"
  62. #include "features/rs6000/powerpc-604.c"
  63. #include "features/rs6000/powerpc-64.c"
  64. #include "features/rs6000/powerpc-altivec64.c"
  65. #include "features/rs6000/powerpc-vsx64.c"
  66. #include "features/rs6000/powerpc-7400.c"
  67. #include "features/rs6000/powerpc-750.c"
  68. #include "features/rs6000/powerpc-860.c"
  69. #include "features/rs6000/powerpc-e500.c"
  70. #include "features/rs6000/rs6000.c"

  71. /* Determine if regnum is an SPE pseudo-register.  */
  72. #define IS_SPE_PSEUDOREG(tdep, regnum) ((tdep)->ppc_ev0_regnum >= 0 \
  73.     && (regnum) >= (tdep)->ppc_ev0_regnum \
  74.     && (regnum) < (tdep)->ppc_ev0_regnum + 32)

  75. /* Determine if regnum is a decimal float pseudo-register.  */
  76. #define IS_DFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_dl0_regnum >= 0 \
  77.     && (regnum) >= (tdep)->ppc_dl0_regnum \
  78.     && (regnum) < (tdep)->ppc_dl0_regnum + 16)

  79. /* Determine if regnum is a POWER7 VSX register.  */
  80. #define IS_VSX_PSEUDOREG(tdep, regnum) ((tdep)->ppc_vsr0_regnum >= 0 \
  81.     && (regnum) >= (tdep)->ppc_vsr0_regnum \
  82.     && (regnum) < (tdep)->ppc_vsr0_regnum + ppc_num_vsrs)

  83. /* Determine if regnum is a POWER7 Extended FP register.  */
  84. #define IS_EFP_PSEUDOREG(tdep, regnum) ((tdep)->ppc_efpr0_regnum >= 0 \
  85.     && (regnum) >= (tdep)->ppc_efpr0_regnum \
  86.     && (regnum) < (tdep)->ppc_efpr0_regnum + ppc_num_efprs)

  87. /* The list of available "set powerpc ..." and "show powerpc ..."
  88.    commands.  */
  89. static struct cmd_list_element *setpowerpccmdlist = NULL;
  90. static struct cmd_list_element *showpowerpccmdlist = NULL;

  91. static enum auto_boolean powerpc_soft_float_global = AUTO_BOOLEAN_AUTO;

  92. /* The vector ABI to use.  Keep this in sync with powerpc_vector_abi.  */
  93. static const char *const powerpc_vector_strings[] =
  94. {
  95.   "auto",
  96.   "generic",
  97.   "altivec",
  98.   "spe",
  99.   NULL
  100. };

  101. /* A variable that can be configured by the user.  */
  102. static enum powerpc_vector_abi powerpc_vector_abi_global = POWERPC_VEC_AUTO;
  103. static const char *powerpc_vector_abi_string = "auto";

  104. /* To be used by skip_prologue.  */

  105. struct rs6000_framedata
  106.   {
  107.     int offset;                        /* total size of frame --- the distance
  108.                                    by which we decrement sp to allocate
  109.                                    the frame */
  110.     int saved_gpr;                /* smallest # of saved gpr */
  111.     unsigned int gpr_mask;        /* Each bit is an individual saved GPR.  */
  112.     int saved_fpr;                /* smallest # of saved fpr */
  113.     int saved_vr;               /* smallest # of saved vr */
  114.     int saved_ev;               /* smallest # of saved ev */
  115.     int alloca_reg;                /* alloca register number (frame ptr) */
  116.     char frameless;                /* true if frameless functions.  */
  117.     char nosavedpc;                /* true if pc not saved.  */
  118.     char used_bl;                /* true if link register clobbered */
  119.     int gpr_offset;                /* offset of saved gprs from prev sp */
  120.     int fpr_offset;                /* offset of saved fprs from prev sp */
  121.     int vr_offset;              /* offset of saved vrs from prev sp */
  122.     int ev_offset;              /* offset of saved evs from prev sp */
  123.     int lr_offset;                /* offset of saved lr */
  124.     int lr_register;                /* register of saved lr, if trustworthy */
  125.     int cr_offset;                /* offset of saved cr */
  126.     int vrsave_offset;          /* offset of saved vrsave register */
  127.   };


  128. /* Is REGNO a VSX register? Return 1 if so, 0 otherwise.  */
  129. int
  130. vsx_register_p (struct gdbarch *gdbarch, int regno)
  131. {
  132.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  133.   if (tdep->ppc_vsr0_regnum < 0)
  134.     return 0;
  135.   else
  136.     return (regno >= tdep->ppc_vsr0_upper_regnum && regno
  137.             <= tdep->ppc_vsr0_upper_regnum + 31);
  138. }

  139. /* Is REGNO an AltiVec register?  Return 1 if so, 0 otherwise.  */
  140. int
  141. altivec_register_p (struct gdbarch *gdbarch, int regno)
  142. {
  143.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  144.   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
  145.     return 0;
  146.   else
  147.     return (regno >= tdep->ppc_vr0_regnum && regno <= tdep->ppc_vrsave_regnum);
  148. }


  149. /* Return true if REGNO is an SPE register, false otherwise.  */
  150. int
  151. spe_register_p (struct gdbarch *gdbarch, int regno)
  152. {
  153.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  154.   /* Is it a reference to EV0 -- EV31, and do we have those?  */
  155.   if (IS_SPE_PSEUDOREG (tdep, regno))
  156.     return 1;

  157.   /* Is it a reference to one of the raw upper GPR halves?  */
  158.   if (tdep->ppc_ev0_upper_regnum >= 0
  159.       && tdep->ppc_ev0_upper_regnum <= regno
  160.       && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
  161.     return 1;

  162.   /* Is it a reference to the 64-bit accumulator, and do we have that?  */
  163.   if (tdep->ppc_acc_regnum >= 0
  164.       && tdep->ppc_acc_regnum == regno)
  165.     return 1;

  166.   /* Is it a reference to the SPE floating-point status and control register,
  167.      and do we have that?  */
  168.   if (tdep->ppc_spefscr_regnum >= 0
  169.       && tdep->ppc_spefscr_regnum == regno)
  170.     return 1;

  171.   return 0;
  172. }


  173. /* Return non-zero if the architecture described by GDBARCH has
  174.    floating-point registers (f0 --- f31 and fpscr).  */
  175. int
  176. ppc_floating_point_unit_p (struct gdbarch *gdbarch)
  177. {
  178.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  179.   return (tdep->ppc_fp0_regnum >= 0
  180.           && tdep->ppc_fpscr_regnum >= 0);
  181. }

  182. /* Return non-zero if the architecture described by GDBARCH has
  183.    VSX registers (vsr0 --- vsr63).  */
  184. static int
  185. ppc_vsx_support_p (struct gdbarch *gdbarch)
  186. {
  187.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  188.   return tdep->ppc_vsr0_regnum >= 0;
  189. }

  190. /* Return non-zero if the architecture described by GDBARCH has
  191.    Altivec registers (vr0 --- vr31, vrsave and vscr).  */
  192. int
  193. ppc_altivec_support_p (struct gdbarch *gdbarch)
  194. {
  195.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  196.   return (tdep->ppc_vr0_regnum >= 0
  197.           && tdep->ppc_vrsave_regnum >= 0);
  198. }

  199. /* Check that TABLE[GDB_REGNO] is not already initialized, and then
  200.    set it to SIM_REGNO.

  201.    This is a helper function for init_sim_regno_table, constructing
  202.    the table mapping GDB register numbers to sim register numbers; we
  203.    initialize every element in that table to -1 before we start
  204.    filling it in.  */
  205. static void
  206. set_sim_regno (int *table, int gdb_regno, int sim_regno)
  207. {
  208.   /* Make sure we don't try to assign any given GDB register a sim
  209.      register number more than once.  */
  210.   gdb_assert (table[gdb_regno] == -1);
  211.   table[gdb_regno] = sim_regno;
  212. }


  213. /* Initialize ARCH->tdep->sim_regno, the table mapping GDB register
  214.    numbers to simulator register numbers, based on the values placed
  215.    in the ARCH->tdep->ppc_foo_regnum members.  */
  216. static void
  217. init_sim_regno_table (struct gdbarch *arch)
  218. {
  219.   struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
  220.   int total_regs = gdbarch_num_regs (arch);
  221.   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
  222.   int i;
  223.   static const char *const segment_regs[] = {
  224.     "sr0", "sr1", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
  225.     "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15"
  226.   };

  227.   /* Presume that all registers not explicitly mentioned below are
  228.      unavailable from the sim.  */
  229.   for (i = 0; i < total_regs; i++)
  230.     sim_regno[i] = -1;

  231.   /* General-purpose registers.  */
  232.   for (i = 0; i < ppc_num_gprs; i++)
  233.     set_sim_regno (sim_regno, tdep->ppc_gp0_regnum + i, sim_ppc_r0_regnum + i);

  234.   /* Floating-point registers.  */
  235.   if (tdep->ppc_fp0_regnum >= 0)
  236.     for (i = 0; i < ppc_num_fprs; i++)
  237.       set_sim_regno (sim_regno,
  238.                      tdep->ppc_fp0_regnum + i,
  239.                      sim_ppc_f0_regnum + i);
  240.   if (tdep->ppc_fpscr_regnum >= 0)
  241.     set_sim_regno (sim_regno, tdep->ppc_fpscr_regnum, sim_ppc_fpscr_regnum);

  242.   set_sim_regno (sim_regno, gdbarch_pc_regnum (arch), sim_ppc_pc_regnum);
  243.   set_sim_regno (sim_regno, tdep->ppc_ps_regnum, sim_ppc_ps_regnum);
  244.   set_sim_regno (sim_regno, tdep->ppc_cr_regnum, sim_ppc_cr_regnum);

  245.   /* Segment registers.  */
  246.   for (i = 0; i < ppc_num_srs; i++)
  247.     {
  248.       int gdb_regno;

  249.       gdb_regno = user_reg_map_name_to_regnum (arch, segment_regs[i], -1);
  250.       if (gdb_regno >= 0)
  251.         set_sim_regno (sim_regno, gdb_regno, sim_ppc_sr0_regnum + i);
  252.     }

  253.   /* Altivec registers.  */
  254.   if (tdep->ppc_vr0_regnum >= 0)
  255.     {
  256.       for (i = 0; i < ppc_num_vrs; i++)
  257.         set_sim_regno (sim_regno,
  258.                        tdep->ppc_vr0_regnum + i,
  259.                        sim_ppc_vr0_regnum + i);

  260.       /* FIXME: jimb/2004-07-15: when we have tdep->ppc_vscr_regnum,
  261.          we can treat this more like the other cases.  */
  262.       set_sim_regno (sim_regno,
  263.                      tdep->ppc_vr0_regnum + ppc_num_vrs,
  264.                      sim_ppc_vscr_regnum);
  265.     }
  266.   /* vsave is a special-purpose register, so the code below handles it.  */

  267.   /* SPE APU (E500) registers.  */
  268.   if (tdep->ppc_ev0_upper_regnum >= 0)
  269.     for (i = 0; i < ppc_num_gprs; i++)
  270.       set_sim_regno (sim_regno,
  271.                      tdep->ppc_ev0_upper_regnum + i,
  272.                      sim_ppc_rh0_regnum + i);
  273.   if (tdep->ppc_acc_regnum >= 0)
  274.     set_sim_regno (sim_regno, tdep->ppc_acc_regnum, sim_ppc_acc_regnum);
  275.   /* spefscr is a special-purpose register, so the code below handles it.  */

  276. #ifdef WITH_SIM
  277.   /* Now handle all special-purpose registers.  Verify that they
  278.      haven't mistakenly been assigned numbers by any of the above
  279.      code.  */
  280.   for (i = 0; i < sim_ppc_num_sprs; i++)
  281.     {
  282.       const char *spr_name = sim_spr_register_name (i);
  283.       int gdb_regno = -1;

  284.       if (spr_name != NULL)
  285.         gdb_regno = user_reg_map_name_to_regnum (arch, spr_name, -1);

  286.       if (gdb_regno != -1)
  287.         set_sim_regno (sim_regno, gdb_regno, sim_ppc_spr0_regnum + i);
  288.     }
  289. #endif

  290.   /* Drop the initialized array into place.  */
  291.   tdep->sim_regno = sim_regno;
  292. }


  293. /* Given a GDB register number REG, return the corresponding SIM
  294.    register number.  */
  295. static int
  296. rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
  297. {
  298.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  299.   int sim_regno;

  300.   if (tdep->sim_regno == NULL)
  301.     init_sim_regno_table (gdbarch);

  302.   gdb_assert (0 <= reg
  303.               && reg <= gdbarch_num_regs (gdbarch)
  304.                         + gdbarch_num_pseudo_regs (gdbarch));
  305.   sim_regno = tdep->sim_regno[reg];

  306.   if (sim_regno >= 0)
  307.     return sim_regno;
  308.   else
  309.     return LEGACY_SIM_REGNO_IGNORE;
  310. }



  311. /* Register set support functions.  */

  312. /* REGS + OFFSET contains register REGNUM in a field REGSIZE wide.
  313.    Write the register to REGCACHE.  */

  314. void
  315. ppc_supply_reg (struct regcache *regcache, int regnum,
  316.                 const gdb_byte *regs, size_t offset, int regsize)
  317. {
  318.   if (regnum != -1 && offset != -1)
  319.     {
  320.       if (regsize > 4)
  321.         {
  322.           struct gdbarch *gdbarch = get_regcache_arch (regcache);
  323.           int gdb_regsize = register_size (gdbarch, regnum);
  324.           if (gdb_regsize < regsize
  325.               && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  326.             offset += regsize - gdb_regsize;
  327.         }
  328.       regcache_raw_supply (regcache, regnum, regs + offset);
  329.     }
  330. }

  331. /* Read register REGNUM from REGCACHE and store to REGS + OFFSET
  332.    in a field REGSIZE wide.  Zero pad as necessary.  */

  333. void
  334. ppc_collect_reg (const struct regcache *regcache, int regnum,
  335.                  gdb_byte *regs, size_t offset, int regsize)
  336. {
  337.   if (regnum != -1 && offset != -1)
  338.     {
  339.       if (regsize > 4)
  340.         {
  341.           struct gdbarch *gdbarch = get_regcache_arch (regcache);
  342.           int gdb_regsize = register_size (gdbarch, regnum);
  343.           if (gdb_regsize < regsize)
  344.             {
  345.               if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  346.                 {
  347.                   memset (regs + offset, 0, regsize - gdb_regsize);
  348.                   offset += regsize - gdb_regsize;
  349.                 }
  350.               else
  351.                 memset (regs + offset + regsize - gdb_regsize, 0,
  352.                         regsize - gdb_regsize);
  353.             }
  354.         }
  355.       regcache_raw_collect (regcache, regnum, regs + offset);
  356.     }
  357. }

  358. static int
  359. ppc_greg_offset (struct gdbarch *gdbarch,
  360.                  struct gdbarch_tdep *tdep,
  361.                  const struct ppc_reg_offsets *offsets,
  362.                  int regnum,
  363.                  int *regsize)
  364. {
  365.   *regsize = offsets->gpr_size;
  366.   if (regnum >= tdep->ppc_gp0_regnum
  367.       && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
  368.     return (offsets->r0_offset
  369.             + (regnum - tdep->ppc_gp0_regnum) * offsets->gpr_size);

  370.   if (regnum == gdbarch_pc_regnum (gdbarch))
  371.     return offsets->pc_offset;

  372.   if (regnum == tdep->ppc_ps_regnum)
  373.     return offsets->ps_offset;

  374.   if (regnum == tdep->ppc_lr_regnum)
  375.     return offsets->lr_offset;

  376.   if (regnum == tdep->ppc_ctr_regnum)
  377.     return offsets->ctr_offset;

  378.   *regsize = offsets->xr_size;
  379.   if (regnum == tdep->ppc_cr_regnum)
  380.     return offsets->cr_offset;

  381.   if (regnum == tdep->ppc_xer_regnum)
  382.     return offsets->xer_offset;

  383.   if (regnum == tdep->ppc_mq_regnum)
  384.     return offsets->mq_offset;

  385.   return -1;
  386. }

  387. static int
  388. ppc_fpreg_offset (struct gdbarch_tdep *tdep,
  389.                   const struct ppc_reg_offsets *offsets,
  390.                   int regnum)
  391. {
  392.   if (regnum >= tdep->ppc_fp0_regnum
  393.       && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
  394.     return offsets->f0_offset + (regnum - tdep->ppc_fp0_regnum) * 8;

  395.   if (regnum == tdep->ppc_fpscr_regnum)
  396.     return offsets->fpscr_offset;

  397.   return -1;
  398. }

  399. static int
  400. ppc_vrreg_offset (struct gdbarch_tdep *tdep,
  401.                   const struct ppc_reg_offsets *offsets,
  402.                   int regnum)
  403. {
  404.   if (regnum >= tdep->ppc_vr0_regnum
  405.       && regnum < tdep->ppc_vr0_regnum + ppc_num_vrs)
  406.     return offsets->vr0_offset + (regnum - tdep->ppc_vr0_regnum) * 16;

  407.   if (regnum == tdep->ppc_vrsave_regnum - 1)
  408.     return offsets->vscr_offset;

  409.   if (regnum == tdep->ppc_vrsave_regnum)
  410.     return offsets->vrsave_offset;

  411.   return -1;
  412. }

  413. /* Supply register REGNUM in the general-purpose register set REGSET
  414.    from the buffer specified by GREGS and LEN to register cache
  415.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  416. void
  417. ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
  418.                     int regnum, const void *gregs, size_t len)
  419. {
  420.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  421.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  422.   const struct ppc_reg_offsets *offsets = regset->regmap;
  423.   size_t offset;
  424.   int regsize;

  425.   if (regnum == -1)
  426.     {
  427.       int i;
  428.       int gpr_size = offsets->gpr_size;

  429.       for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
  430.            i < tdep->ppc_gp0_regnum + ppc_num_gprs;
  431.            i++, offset += gpr_size)
  432.         ppc_supply_reg (regcache, i, gregs, offset, gpr_size);

  433.       ppc_supply_reg (regcache, gdbarch_pc_regnum (gdbarch),
  434.                       gregs, offsets->pc_offset, gpr_size);
  435.       ppc_supply_reg (regcache, tdep->ppc_ps_regnum,
  436.                       gregs, offsets->ps_offset, gpr_size);
  437.       ppc_supply_reg (regcache, tdep->ppc_lr_regnum,
  438.                       gregs, offsets->lr_offset, gpr_size);
  439.       ppc_supply_reg (regcache, tdep->ppc_ctr_regnum,
  440.                       gregs, offsets->ctr_offset, gpr_size);
  441.       ppc_supply_reg (regcache, tdep->ppc_cr_regnum,
  442.                       gregs, offsets->cr_offset, offsets->xr_size);
  443.       ppc_supply_reg (regcache, tdep->ppc_xer_regnum,
  444.                       gregs, offsets->xer_offset, offsets->xr_size);
  445.       ppc_supply_reg (regcache, tdep->ppc_mq_regnum,
  446.                       gregs, offsets->mq_offset, offsets->xr_size);
  447.       return;
  448.     }

  449.   offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
  450.   ppc_supply_reg (regcache, regnum, gregs, offset, regsize);
  451. }

  452. /* Supply register REGNUM in the floating-point register set REGSET
  453.    from the buffer specified by FPREGS and LEN to register cache
  454.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  455. void
  456. ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
  457.                      int regnum, const void *fpregs, size_t len)
  458. {
  459.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  460.   struct gdbarch_tdep *tdep;
  461.   const struct ppc_reg_offsets *offsets;
  462.   size_t offset;

  463.   if (!ppc_floating_point_unit_p (gdbarch))
  464.     return;

  465.   tdep = gdbarch_tdep (gdbarch);
  466.   offsets = regset->regmap;
  467.   if (regnum == -1)
  468.     {
  469.       int i;

  470.       for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
  471.            i < tdep->ppc_fp0_regnum + ppc_num_fprs;
  472.            i++, offset += 8)
  473.         ppc_supply_reg (regcache, i, fpregs, offset, 8);

  474.       ppc_supply_reg (regcache, tdep->ppc_fpscr_regnum,
  475.                       fpregs, offsets->fpscr_offset, offsets->fpscr_size);
  476.       return;
  477.     }

  478.   offset = ppc_fpreg_offset (tdep, offsets, regnum);
  479.   ppc_supply_reg (regcache, regnum, fpregs, offset,
  480.                   regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
  481. }

  482. /* Supply register REGNUM in the VSX register set REGSET
  483.    from the buffer specified by VSXREGS and LEN to register cache
  484.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  485. void
  486. ppc_supply_vsxregset (const struct regset *regset, struct regcache *regcache,
  487.                      int regnum, const void *vsxregs, size_t len)
  488. {
  489.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  490.   struct gdbarch_tdep *tdep;

  491.   if (!ppc_vsx_support_p (gdbarch))
  492.     return;

  493.   tdep = gdbarch_tdep (gdbarch);

  494.   if (regnum == -1)
  495.     {
  496.       int i;

  497.       for (i = tdep->ppc_vsr0_upper_regnum;
  498.            i < tdep->ppc_vsr0_upper_regnum + 32;
  499.            i++)
  500.         ppc_supply_reg (regcache, i, vsxregs, 0, 8);

  501.       return;
  502.     }
  503.   else
  504.     ppc_supply_reg (regcache, regnum, vsxregs, 0, 8);
  505. }

  506. /* Supply register REGNUM in the Altivec register set REGSET
  507.    from the buffer specified by VRREGS and LEN to register cache
  508.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  509. void
  510. ppc_supply_vrregset (const struct regset *regset, struct regcache *regcache,
  511.                      int regnum, const void *vrregs, size_t len)
  512. {
  513.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  514.   struct gdbarch_tdep *tdep;
  515.   const struct ppc_reg_offsets *offsets;
  516.   size_t offset;

  517.   if (!ppc_altivec_support_p (gdbarch))
  518.     return;

  519.   tdep = gdbarch_tdep (gdbarch);
  520.   offsets = regset->regmap;
  521.   if (regnum == -1)
  522.     {
  523.       int i;

  524.       for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
  525.            i < tdep->ppc_vr0_regnum + ppc_num_vrs;
  526.            i++, offset += 16)
  527.         ppc_supply_reg (regcache, i, vrregs, offset, 16);

  528.       ppc_supply_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
  529.                       vrregs, offsets->vscr_offset, 4);

  530.       ppc_supply_reg (regcache, tdep->ppc_vrsave_regnum,
  531.                       vrregs, offsets->vrsave_offset, 4);
  532.       return;
  533.     }

  534.   offset = ppc_vrreg_offset (tdep, offsets, regnum);
  535.   if (regnum != tdep->ppc_vrsave_regnum
  536.       && regnum != tdep->ppc_vrsave_regnum - 1)
  537.     ppc_supply_reg (regcache, regnum, vrregs, offset, 16);
  538.   else
  539.     ppc_supply_reg (regcache, regnum,
  540.                     vrregs, offset, 4);
  541. }

  542. /* Collect register REGNUM in the general-purpose register set
  543.    REGSET from register cache REGCACHE into the buffer specified by
  544.    GREGS and LEN.  If REGNUM is -1, do this for all registers in
  545.    REGSET.  */

  546. void
  547. ppc_collect_gregset (const struct regset *regset,
  548.                      const struct regcache *regcache,
  549.                      int regnum, void *gregs, size_t len)
  550. {
  551.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  552.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  553.   const struct ppc_reg_offsets *offsets = regset->regmap;
  554.   size_t offset;
  555.   int regsize;

  556.   if (regnum == -1)
  557.     {
  558.       int i;
  559.       int gpr_size = offsets->gpr_size;

  560.       for (i = tdep->ppc_gp0_regnum, offset = offsets->r0_offset;
  561.            i < tdep->ppc_gp0_regnum + ppc_num_gprs;
  562.            i++, offset += gpr_size)
  563.         ppc_collect_reg (regcache, i, gregs, offset, gpr_size);

  564.       ppc_collect_reg (regcache, gdbarch_pc_regnum (gdbarch),
  565.                        gregs, offsets->pc_offset, gpr_size);
  566.       ppc_collect_reg (regcache, tdep->ppc_ps_regnum,
  567.                        gregs, offsets->ps_offset, gpr_size);
  568.       ppc_collect_reg (regcache, tdep->ppc_lr_regnum,
  569.                        gregs, offsets->lr_offset, gpr_size);
  570.       ppc_collect_reg (regcache, tdep->ppc_ctr_regnum,
  571.                        gregs, offsets->ctr_offset, gpr_size);
  572.       ppc_collect_reg (regcache, tdep->ppc_cr_regnum,
  573.                        gregs, offsets->cr_offset, offsets->xr_size);
  574.       ppc_collect_reg (regcache, tdep->ppc_xer_regnum,
  575.                        gregs, offsets->xer_offset, offsets->xr_size);
  576.       ppc_collect_reg (regcache, tdep->ppc_mq_regnum,
  577.                        gregs, offsets->mq_offset, offsets->xr_size);
  578.       return;
  579.     }

  580.   offset = ppc_greg_offset (gdbarch, tdep, offsets, regnum, &regsize);
  581.   ppc_collect_reg (regcache, regnum, gregs, offset, regsize);
  582. }

  583. /* Collect register REGNUM in the floating-point register set
  584.    REGSET from register cache REGCACHE into the buffer specified by
  585.    FPREGS and LEN.  If REGNUM is -1, do this for all registers in
  586.    REGSET.  */

  587. void
  588. ppc_collect_fpregset (const struct regset *regset,
  589.                       const struct regcache *regcache,
  590.                       int regnum, void *fpregs, size_t len)
  591. {
  592.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  593.   struct gdbarch_tdep *tdep;
  594.   const struct ppc_reg_offsets *offsets;
  595.   size_t offset;

  596.   if (!ppc_floating_point_unit_p (gdbarch))
  597.     return;

  598.   tdep = gdbarch_tdep (gdbarch);
  599.   offsets = regset->regmap;
  600.   if (regnum == -1)
  601.     {
  602.       int i;

  603.       for (i = tdep->ppc_fp0_regnum, offset = offsets->f0_offset;
  604.            i < tdep->ppc_fp0_regnum + ppc_num_fprs;
  605.            i++, offset += 8)
  606.         ppc_collect_reg (regcache, i, fpregs, offset, 8);

  607.       ppc_collect_reg (regcache, tdep->ppc_fpscr_regnum,
  608.                        fpregs, offsets->fpscr_offset, offsets->fpscr_size);
  609.       return;
  610.     }

  611.   offset = ppc_fpreg_offset (tdep, offsets, regnum);
  612.   ppc_collect_reg (regcache, regnum, fpregs, offset,
  613.                    regnum == tdep->ppc_fpscr_regnum ? offsets->fpscr_size : 8);
  614. }

  615. /* Collect register REGNUM in the VSX register set
  616.    REGSET from register cache REGCACHE into the buffer specified by
  617.    VSXREGS and LEN.  If REGNUM is -1, do this for all registers in
  618.    REGSET.  */

  619. void
  620. ppc_collect_vsxregset (const struct regset *regset,
  621.                       const struct regcache *regcache,
  622.                       int regnum, void *vsxregs, size_t len)
  623. {
  624.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  625.   struct gdbarch_tdep *tdep;

  626.   if (!ppc_vsx_support_p (gdbarch))
  627.     return;

  628.   tdep = gdbarch_tdep (gdbarch);

  629.   if (regnum == -1)
  630.     {
  631.       int i;

  632.       for (i = tdep->ppc_vsr0_upper_regnum;
  633.            i < tdep->ppc_vsr0_upper_regnum + 32;
  634.            i++)
  635.         ppc_collect_reg (regcache, i, vsxregs, 0, 8);

  636.       return;
  637.     }
  638.   else
  639.     ppc_collect_reg (regcache, regnum, vsxregs, 0, 8);
  640. }


  641. /* Collect register REGNUM in the Altivec register set
  642.    REGSET from register cache REGCACHE into the buffer specified by
  643.    VRREGS and LEN.  If REGNUM is -1, do this for all registers in
  644.    REGSET.  */

  645. void
  646. ppc_collect_vrregset (const struct regset *regset,
  647.                       const struct regcache *regcache,
  648.                       int regnum, void *vrregs, size_t len)
  649. {
  650.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  651.   struct gdbarch_tdep *tdep;
  652.   const struct ppc_reg_offsets *offsets;
  653.   size_t offset;

  654.   if (!ppc_altivec_support_p (gdbarch))
  655.     return;

  656.   tdep = gdbarch_tdep (gdbarch);
  657.   offsets = regset->regmap;
  658.   if (regnum == -1)
  659.     {
  660.       int i;

  661.       for (i = tdep->ppc_vr0_regnum, offset = offsets->vr0_offset;
  662.            i < tdep->ppc_vr0_regnum + ppc_num_vrs;
  663.            i++, offset += 16)
  664.         ppc_collect_reg (regcache, i, vrregs, offset, 16);

  665.       ppc_collect_reg (regcache, (tdep->ppc_vrsave_regnum - 1),
  666.                        vrregs, offsets->vscr_offset, 4);

  667.       ppc_collect_reg (regcache, tdep->ppc_vrsave_regnum,
  668.                        vrregs, offsets->vrsave_offset, 4);
  669.       return;
  670.     }

  671.   offset = ppc_vrreg_offset (tdep, offsets, regnum);
  672.   if (regnum != tdep->ppc_vrsave_regnum
  673.       && regnum != tdep->ppc_vrsave_regnum - 1)
  674.     ppc_collect_reg (regcache, regnum, vrregs, offset, 16);
  675.   else
  676.     ppc_collect_reg (regcache, regnum,
  677.                     vrregs, offset, 4);
  678. }


  679. static int
  680. insn_changes_sp_or_jumps (unsigned long insn)
  681. {
  682.   int opcode = (insn >> 26) & 0x03f;
  683.   int sd = (insn >> 21) & 0x01f;
  684.   int a = (insn >> 16) & 0x01f;
  685.   int subcode = (insn >> 1) & 0x3ff;

  686.   /* Changes the stack pointer.  */

  687.   /* NOTE: There are many ways to change the value of a given register.
  688.            The ways below are those used when the register is R1, the SP,
  689.            in a funtion's epilogue.  */

  690.   if (opcode == 31 && subcode == 444 && a == 1)
  691.     return 1/* mr R1,Rn */
  692.   if (opcode == 14 && sd == 1)
  693.     return 1/* addi R1,Rn,simm */
  694.   if (opcode == 58 && sd == 1)
  695.     return 1/* ld R1,ds(Rn) */

  696.   /* Transfers control.  */

  697.   if (opcode == 18)
  698.     return 1/* b */
  699.   if (opcode == 16)
  700.     return 1/* bc */
  701.   if (opcode == 19 && subcode == 16)
  702.     return 1/* bclr */
  703.   if (opcode == 19 && subcode == 528)
  704.     return 1/* bcctr */

  705.   return 0;
  706. }

  707. /* Return true if we are in the function's epilogue, i.e. after the
  708.    instruction that destroyed the function's stack frame.

  709.    1) scan forward from the point of execution:
  710.        a) If you find an instruction that modifies the stack pointer
  711.           or transfers control (except a return), execution is not in
  712.           an epilogue, return.
  713.        b) Stop scanning if you find a return instruction or reach the
  714.           end of the function or reach the hard limit for the size of
  715.           an epilogue.
  716.    2) scan backward from the point of execution:
  717.         a) If you find an instruction that modifies the stack pointer,
  718.             execution *is* in an epilogue, return.
  719.         b) Stop scanning if you reach an instruction that transfers
  720.            control or the beginning of the function or reach the hard
  721.            limit for the size of an epilogue.  */

  722. static int
  723. rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  724. {
  725.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  726.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  727.   bfd_byte insn_buf[PPC_INSN_SIZE];
  728.   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
  729.   unsigned long insn;
  730.   struct frame_info *curfrm;

  731.   /* Find the search limits based on function boundaries and hard limit.  */

  732.   if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
  733.     return 0;

  734.   epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
  735.   if (epilogue_start < func_start) epilogue_start = func_start;

  736.   epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE;
  737.   if (epilogue_end > func_end) epilogue_end = func_end;

  738.   curfrm = get_current_frame ();

  739.   /* Scan forward until next 'blr'.  */

  740.   for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE)
  741.     {
  742.       if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
  743.         return 0;
  744.       insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order);
  745.       if (insn == 0x4e800020)
  746.         break;
  747.       /* Assume a bctr is a tail call unless it points strictly within
  748.          this function.  */
  749.       if (insn == 0x4e800420)
  750.         {
  751.           CORE_ADDR ctr = get_frame_register_unsigned (curfrm,
  752.                                                        tdep->ppc_ctr_regnum);
  753.           if (ctr > func_start && ctr < func_end)
  754.             return 0;
  755.           else
  756.             break;
  757.         }
  758.       if (insn_changes_sp_or_jumps (insn))
  759.         return 0;
  760.     }

  761.   /* Scan backward until adjustment to stack pointer (R1).  */

  762.   for (scan_pc = pc - PPC_INSN_SIZE;
  763.        scan_pc >= epilogue_start;
  764.        scan_pc -= PPC_INSN_SIZE)
  765.     {
  766.       if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE))
  767.         return 0;
  768.       insn = extract_unsigned_integer (insn_buf, PPC_INSN_SIZE, byte_order);
  769.       if (insn_changes_sp_or_jumps (insn))
  770.         return 1;
  771.     }

  772.   return 0;
  773. }

  774. /* Get the ith function argument for the current function.  */
  775. static CORE_ADDR
  776. rs6000_fetch_pointer_argument (struct frame_info *frame, int argi,
  777.                                struct type *type)
  778. {
  779.   return get_frame_register_unsigned (frame, 3 + argi);
  780. }

  781. /* Sequence of bytes for breakpoint instruction.  */

  782. static const unsigned char *
  783. rs6000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *bp_addr,
  784.                            int *bp_size)
  785. {
  786.   static unsigned char big_breakpoint[] = { 0x7d, 0x82, 0x10, 0x08 };
  787.   static unsigned char little_breakpoint[] = { 0x08, 0x10, 0x82, 0x7d };
  788.   *bp_size = 4;
  789.   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  790.     return big_breakpoint;
  791.   else
  792.     return little_breakpoint;
  793. }

  794. /* Instruction masks for displaced stepping.  */
  795. #define BRANCH_MASK 0xfc000000
  796. #define BP_MASK 0xFC0007FE
  797. #define B_INSN 0x48000000
  798. #define BC_INSN 0x40000000
  799. #define BXL_INSN 0x4c000000
  800. #define BP_INSN 0x7C000008

  801. /* Fix up the state of registers and memory after having single-stepped
  802.    a displaced instruction.  */
  803. static void
  804. ppc_displaced_step_fixup (struct gdbarch *gdbarch,
  805.                           struct displaced_step_closure *closure,
  806.                           CORE_ADDR from, CORE_ADDR to,
  807.                           struct regcache *regs)
  808. {
  809.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  810.   /* Since we use simple_displaced_step_copy_insn, our closure is a
  811.      copy of the instruction.  */
  812.   ULONGEST insn  = extract_unsigned_integer ((gdb_byte *) closure,
  813.                                               PPC_INSN_SIZE, byte_order);
  814.   ULONGEST opcode = 0;
  815.   /* Offset for non PC-relative instructions.  */
  816.   LONGEST offset = PPC_INSN_SIZE;

  817.   opcode = insn & BRANCH_MASK;

  818.   if (debug_displaced)
  819.     fprintf_unfiltered (gdb_stdlog,
  820.                         "displaced: (ppc) fixup (%s, %s)\n",
  821.                         paddress (gdbarch, from), paddress (gdbarch, to));


  822.   /* Handle PC-relative branch instructions.  */
  823.   if (opcode == B_INSN || opcode == BC_INSN || opcode == BXL_INSN)
  824.     {
  825.       ULONGEST current_pc;

  826.       /* Read the current PC value after the instruction has been executed
  827.          in a displaced location.  Calculate the offset to be applied to the
  828.          original PC value before the displaced stepping.  */
  829.       regcache_cooked_read_unsigned (regs, gdbarch_pc_regnum (gdbarch),
  830.                                       &current_pc);
  831.       offset = current_pc - to;

  832.       if (opcode != BXL_INSN)
  833.         {
  834.           /* Check for AA bit indicating whether this is an absolute
  835.              addressing or PC-relative (1: absolute, 0: relative).  */
  836.           if (!(insn & 0x2))
  837.             {
  838.               /* PC-relative addressing is being used in the branch.  */
  839.               if (debug_displaced)
  840.                 fprintf_unfiltered
  841.                   (gdb_stdlog,
  842.                    "displaced: (ppc) branch instruction: %s\n"
  843.                    "displaced: (ppc) adjusted PC from %s to %s\n",
  844.                    paddress (gdbarch, insn), paddress (gdbarch, current_pc),
  845.                    paddress (gdbarch, from + offset));

  846.               regcache_cooked_write_unsigned (regs,
  847.                                               gdbarch_pc_regnum (gdbarch),
  848.                                               from + offset);
  849.             }
  850.         }
  851.       else
  852.         {
  853.           /* If we're here, it means we have a branch to LR or CTR.  If the
  854.              branch was taken, the offset is probably greater than 4 (the next
  855.              instruction), so it's safe to assume that an offset of 4 means we
  856.              did not take the branch.  */
  857.           if (offset == PPC_INSN_SIZE)
  858.             regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch),
  859.                                             from + PPC_INSN_SIZE);
  860.         }

  861.       /* Check for LK bit indicating whether we should set the link
  862.          register to point to the next instruction
  863.          (1: Set, 0: Don't set).  */
  864.       if (insn & 0x1)
  865.         {
  866.           /* Link register needs to be set to the next instruction's PC.  */
  867.           regcache_cooked_write_unsigned (regs,
  868.                                           gdbarch_tdep (gdbarch)->ppc_lr_regnum,
  869.                                           from + PPC_INSN_SIZE);
  870.           if (debug_displaced)
  871.                 fprintf_unfiltered (gdb_stdlog,
  872.                                     "displaced: (ppc) adjusted LR to %s\n",
  873.                                     paddress (gdbarch, from + PPC_INSN_SIZE));

  874.         }
  875.     }
  876.   /* Check for breakpoints in the inferior.  If we've found one, place the PC
  877.      right at the breakpoint instruction.  */
  878.   else if ((insn & BP_MASK) == BP_INSN)
  879.     regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), from);
  880.   else
  881.   /* Handle any other instructions that do not fit in the categories above.  */
  882.     regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch),
  883.                                     from + offset);
  884. }

  885. /* Always use hardware single-stepping to execute the
  886.    displaced instruction.  */
  887. static int
  888. ppc_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
  889.                                   struct displaced_step_closure *closure)
  890. {
  891.   return 1;
  892. }

  893. /* Instruction masks used during single-stepping of atomic sequences.  */
  894. #define LWARX_MASK 0xfc0007fe
  895. #define LWARX_INSTRUCTION 0x7c000028
  896. #define LDARX_INSTRUCTION 0x7c0000A8
  897. #define STWCX_MASK 0xfc0007ff
  898. #define STWCX_INSTRUCTION 0x7c00012d
  899. #define STDCX_INSTRUCTION 0x7c0001ad

  900. /* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX
  901.    instruction and ending with a STWCX/STDCX instruction.  If such a sequence
  902.    is found, attempt to step through it.  A breakpoint is placed at the end of
  903.    the sequence.  */

  904. int
  905. ppc_deal_with_atomic_sequence (struct frame_info *frame)
  906. {
  907.   struct gdbarch *gdbarch = get_frame_arch (frame);
  908.   struct address_space *aspace = get_frame_address_space (frame);
  909.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  910.   CORE_ADDR pc = get_frame_pc (frame);
  911.   CORE_ADDR breaks[2] = {-1, -1};
  912.   CORE_ADDR loc = pc;
  913.   CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence.  */
  914.   int insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);
  915.   int insn_count;
  916.   int index;
  917.   int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */
  918.   const int atomic_sequence_length = 16; /* Instruction sequence length.  */
  919.   int opcode; /* Branch instruction's OPcode.  */
  920.   int bc_insn_count = 0; /* Conditional branch instruction count.  */

  921.   /* Assume all atomic sequences start with a lwarx/ldarx instruction.  */
  922.   if ((insn & LWARX_MASK) != LWARX_INSTRUCTION
  923.       && (insn & LWARX_MASK) != LDARX_INSTRUCTION)
  924.     return 0;

  925.   /* Assume that no atomic sequence is longer than "atomic_sequence_length"
  926.      instructions.  */
  927.   for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
  928.     {
  929.       loc += PPC_INSN_SIZE;
  930.       insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);

  931.       /* Assume that there is at most one conditional branch in the atomic
  932.          sequence.  If a conditional branch is found, put a breakpoint in
  933.          its destination address.  */
  934.       if ((insn & BRANCH_MASK) == BC_INSN)
  935.         {
  936.           int immediate = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
  937.           int absolute = insn & 2;

  938.           if (bc_insn_count >= 1)
  939.             return 0; /* More than one conditional branch found, fallback
  940.                          to the standard single-step code.  */

  941.           if (absolute)
  942.             breaks[1] = immediate;
  943.           else
  944.             breaks[1] = loc + immediate;

  945.           bc_insn_count++;
  946.           last_breakpoint++;
  947.         }

  948.       if ((insn & STWCX_MASK) == STWCX_INSTRUCTION
  949.           || (insn & STWCX_MASK) == STDCX_INSTRUCTION)
  950.         break;
  951.     }

  952.   /* Assume that the atomic sequence ends with a stwcx/stdcx instruction.  */
  953.   if ((insn & STWCX_MASK) != STWCX_INSTRUCTION
  954.       && (insn & STWCX_MASK) != STDCX_INSTRUCTION)
  955.     return 0;

  956.   closing_insn = loc;
  957.   loc += PPC_INSN_SIZE;
  958.   insn = read_memory_integer (loc, PPC_INSN_SIZE, byte_order);

  959.   /* Insert a breakpoint right after the end of the atomic sequence.  */
  960.   breaks[0] = loc;

  961.   /* Check for duplicated breakpoints.  Check also for a breakpoint
  962.      placed (branch instruction's destination) anywhere in sequence.  */
  963.   if (last_breakpoint
  964.       && (breaks[1] == breaks[0]
  965.           || (breaks[1] >= pc && breaks[1] <= closing_insn)))
  966.     last_breakpoint = 0;

  967.   /* Effectively inserts the breakpoints.  */
  968.   for (index = 0; index <= last_breakpoint; index++)
  969.     insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);

  970.   return 1;
  971. }


  972. #define SIGNED_SHORT(x)                                                 \
  973.   ((sizeof (short) == 2)                                                \
  974.    ? ((int)(short)(x))                                                        \
  975.    : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))

  976. #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)

  977. /* Limit the number of skipped non-prologue instructions, as the examining
  978.    of the prologue is expensive.  */
  979. static int max_skip_non_prologue_insns = 10;

  980. /* Return nonzero if the given instruction OP can be part of the prologue
  981.    of a function and saves a parameter on the stack.  FRAMEP should be
  982.    set if one of the previous instructions in the function has set the
  983.    Frame Pointer.  */

  984. static int
  985. store_param_on_stack_p (unsigned long op, int framep, int *r0_contains_arg)
  986. {
  987.   /* Move parameters from argument registers to temporary register.  */
  988.   if ((op & 0xfc0007fe) == 0x7c000378)         /* mr(.)  Rx,Ry */
  989.     {
  990.       /* Rx must be scratch register r0.  */
  991.       const int rx_regno = (op >> 16) & 31;
  992.       /* Ry: Only r3 - r10 are used for parameter passing.  */
  993.       const int ry_regno = GET_SRC_REG (op);

  994.       if (rx_regno == 0 && ry_regno >= 3 && ry_regno <= 10)
  995.         {
  996.           *r0_contains_arg = 1;
  997.           return 1;
  998.         }
  999.       else
  1000.         return 0;
  1001.     }

  1002.   /* Save a General Purpose Register on stack.  */

  1003.   if ((op & 0xfc1f0003) == 0xf8010000 ||       /* std  Rx,NUM(r1) */
  1004.       (op & 0xfc1f0000) == 0xd8010000)         /* stfd Rx,NUM(r1) */
  1005.     {
  1006.       /* Rx: Only r3 - r10 are used for parameter passing.  */
  1007.       const int rx_regno = GET_SRC_REG (op);

  1008.       return (rx_regno >= 3 && rx_regno <= 10);
  1009.     }

  1010.   /* Save a General Purpose Register on stack via the Frame Pointer.  */

  1011.   if (framep &&
  1012.       ((op & 0xfc1f0000) == 0x901f0000 ||     /* st rx,NUM(r31) */
  1013.        (op & 0xfc1f0000) == 0x981f0000 ||     /* stb Rx,NUM(r31) */
  1014.        (op & 0xfc1f0000) == 0xd81f0000))      /* stfd Rx,NUM(r31) */
  1015.     {
  1016.       /* Rx: Usually, only r3 - r10 are used for parameter passing.
  1017.          However, the compiler sometimes uses r0 to hold an argument.  */
  1018.       const int rx_regno = GET_SRC_REG (op);

  1019.       return ((rx_regno >= 3 && rx_regno <= 10)
  1020.               || (rx_regno == 0 && *r0_contains_arg));
  1021.     }

  1022.   if ((op & 0xfc1f0000) == 0xfc010000)         /* frsp, fp?,NUM(r1) */
  1023.     {
  1024.       /* Only f2 - f8 are used for parameter passing.  */
  1025.       const int src_regno = GET_SRC_REG (op);

  1026.       return (src_regno >= 2 && src_regno <= 8);
  1027.     }

  1028.   if (framep && ((op & 0xfc1f0000) == 0xfc1f0000))  /* frsp, fp?,NUM(r31) */
  1029.     {
  1030.       /* Only f2 - f8 are used for parameter passing.  */
  1031.       const int src_regno = GET_SRC_REG (op);

  1032.       return (src_regno >= 2 && src_regno <= 8);
  1033.     }

  1034.   /* Not an insn that saves a parameter on stack.  */
  1035.   return 0;
  1036. }

  1037. /* Assuming that INSN is a "bl" instruction located at PC, return
  1038.    nonzero if the destination of the branch is a "blrl" instruction.

  1039.    This sequence is sometimes found in certain function prologues.
  1040.    It allows the function to load the LR register with a value that
  1041.    they can use to access PIC data using PC-relative offsets.  */

  1042. static int
  1043. bl_to_blrl_insn_p (CORE_ADDR pc, int insn, enum bfd_endian byte_order)
  1044. {
  1045.   CORE_ADDR dest;
  1046.   int immediate;
  1047.   int absolute;
  1048.   int dest_insn;

  1049.   absolute = (int) ((insn >> 1) & 1);
  1050.   immediate = ((insn & ~3) << 6) >> 6;
  1051.   if (absolute)
  1052.     dest = immediate;
  1053.   else
  1054.     dest = pc + immediate;

  1055.   dest_insn = read_memory_integer (dest, 4, byte_order);
  1056.   if ((dest_insn & 0xfc00ffff) == 0x4c000021) /* blrl */
  1057.     return 1;

  1058.   return 0;
  1059. }

  1060. /* Masks for decoding a branch-and-link (bl) instruction.

  1061.    BL_MASK and BL_INSTRUCTION are used in combination with each other.
  1062.    The former is anded with the opcode in question; if the result of
  1063.    this masking operation is equal to BL_INSTRUCTION, then the opcode in
  1064.    question is a ``bl'' instruction.

  1065.    BL_DISPLACMENT_MASK is anded with the opcode in order to extract
  1066.    the branch displacement.  */

  1067. #define BL_MASK 0xfc000001
  1068. #define BL_INSTRUCTION 0x48000001
  1069. #define BL_DISPLACEMENT_MASK 0x03fffffc

  1070. static unsigned long
  1071. rs6000_fetch_instruction (struct gdbarch *gdbarch, const CORE_ADDR pc)
  1072. {
  1073.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1074.   gdb_byte buf[4];
  1075.   unsigned long op;

  1076.   /* Fetch the instruction and convert it to an integer.  */
  1077.   if (target_read_memory (pc, buf, 4))
  1078.     return 0;
  1079.   op = extract_unsigned_integer (buf, 4, byte_order);

  1080.   return op;
  1081. }

  1082. /* GCC generates several well-known sequences of instructions at the begining
  1083.    of each function prologue when compiling with -fstack-check.  If one of
  1084.    such sequences starts at START_PC, then return the address of the
  1085.    instruction immediately past this sequence.  Otherwise, return START_PC.  */

  1086. static CORE_ADDR
  1087. rs6000_skip_stack_check (struct gdbarch *gdbarch, const CORE_ADDR start_pc)
  1088. {
  1089.   CORE_ADDR pc = start_pc;
  1090.   unsigned long op = rs6000_fetch_instruction (gdbarch, pc);

  1091.   /* First possible sequence: A small number of probes.
  1092.          stw 0, -<some immediate>(1)
  1093.          [repeat this instruction any (small) number of times].  */

  1094.   if ((op & 0xffff0000) == 0x90010000)
  1095.     {
  1096.       while ((op & 0xffff0000) == 0x90010000)
  1097.         {
  1098.           pc = pc + 4;
  1099.           op = rs6000_fetch_instruction (gdbarch, pc);
  1100.         }
  1101.       return pc;
  1102.     }

  1103.   /* Second sequence: A probing loop.
  1104.          addi 12,1,-<some immediate>
  1105.          lis 0,-<some immediate>
  1106.          [possibly ori 0,0,<some immediate>]
  1107.          add 0,12,0
  1108.          cmpw 0,12,0
  1109.          beq 0,<disp>
  1110.          addi 12,12,-<some immediate>
  1111.          stw 0,0(12)
  1112.          b <disp>
  1113.          [possibly one last probe: stw 0,<some immediate>(12)].  */

  1114.   while (1)
  1115.     {
  1116.       /* addi 12,1,-<some immediate> */
  1117.       if ((op & 0xffff0000) != 0x39810000)
  1118.         break;

  1119.       /* lis 0,-<some immediate> */
  1120.       pc = pc + 4;
  1121.       op = rs6000_fetch_instruction (gdbarch, pc);
  1122.       if ((op & 0xffff0000) != 0x3c000000)
  1123.         break;

  1124.       pc = pc + 4;
  1125.       op = rs6000_fetch_instruction (gdbarch, pc);
  1126.       /* [possibly ori 0,0,<some immediate>] */
  1127.       if ((op & 0xffff0000) == 0x60000000)
  1128.         {
  1129.           pc = pc + 4;
  1130.           op = rs6000_fetch_instruction (gdbarch, pc);
  1131.         }
  1132.       /* add 0,12,0 */
  1133.       if (op != 0x7c0c0214)
  1134.         break;

  1135.       /* cmpw 0,12,0 */
  1136.       pc = pc + 4;
  1137.       op = rs6000_fetch_instruction (gdbarch, pc);
  1138.       if (op != 0x7c0c0000)
  1139.         break;

  1140.       /* beq 0,<disp> */
  1141.       pc = pc + 4;
  1142.       op = rs6000_fetch_instruction (gdbarch, pc);
  1143.       if ((op & 0xff9f0001) != 0x41820000)
  1144.         break;

  1145.       /* addi 12,12,-<some immediate> */
  1146.       pc = pc + 4;
  1147.       op = rs6000_fetch_instruction (gdbarch, pc);
  1148.       if ((op & 0xffff0000) != 0x398c0000)
  1149.         break;

  1150.       /* stw 0,0(12) */
  1151.       pc = pc + 4;
  1152.       op = rs6000_fetch_instruction (gdbarch, pc);
  1153.       if (op != 0x900c0000)
  1154.         break;

  1155.       /* b <disp> */
  1156.       pc = pc + 4;
  1157.       op = rs6000_fetch_instruction (gdbarch, pc);
  1158.       if ((op & 0xfc000001) != 0x48000000)
  1159.         break;

  1160.       /* [possibly one last probe: stw 0,<some immediate>(12)].  */
  1161.       pc = pc + 4;
  1162.       op = rs6000_fetch_instruction (gdbarch, pc);
  1163.       if ((op & 0xffff0000) == 0x900c0000)
  1164.         {
  1165.           pc = pc + 4;
  1166.           op = rs6000_fetch_instruction (gdbarch, pc);
  1167.         }

  1168.       /* We found a valid stack-check sequence, return the new PC.  */
  1169.       return pc;
  1170.     }

  1171.   /* Third sequence: No probe; instead, a comparizon between the stack size
  1172.      limit (saved in a run-time global variable) and the current stack
  1173.      pointer:

  1174.         addi 0,1,-<some immediate>
  1175.         lis 12,__gnat_stack_limit@ha
  1176.         lwz 12,__gnat_stack_limit@l(12)
  1177.         twllt 0,12

  1178.      or, with a small variant in the case of a bigger stack frame:
  1179.         addis 0,1,<some immediate>
  1180.         addic 0,0,-<some immediate>
  1181.         lis 12,__gnat_stack_limit@ha
  1182.         lwz 12,__gnat_stack_limit@l(12)
  1183.         twllt 0,12
  1184.   */
  1185.   while (1)
  1186.     {
  1187.       /* addi 0,1,-<some immediate> */
  1188.       if ((op & 0xffff0000) != 0x38010000)
  1189.         {
  1190.           /* small stack frame variant not recognized; try the
  1191.              big stack frame variant: */

  1192.           /* addis 0,1,<some immediate> */
  1193.           if ((op & 0xffff0000) != 0x3c010000)
  1194.             break;

  1195.           /* addic 0,0,-<some immediate> */
  1196.           pc = pc + 4;
  1197.           op = rs6000_fetch_instruction (gdbarch, pc);
  1198.           if ((op & 0xffff0000) != 0x30000000)
  1199.             break;
  1200.         }

  1201.       /* lis 12,<some immediate> */
  1202.       pc = pc + 4;
  1203.       op = rs6000_fetch_instruction (gdbarch, pc);
  1204.       if ((op & 0xffff0000) != 0x3d800000)
  1205.         break;

  1206.       /* lwz 12,<some immediate>(12) */
  1207.       pc = pc + 4;
  1208.       op = rs6000_fetch_instruction (gdbarch, pc);
  1209.       if ((op & 0xffff0000) != 0x818c0000)
  1210.         break;

  1211.       /* twllt 0,12 */
  1212.       pc = pc + 4;
  1213.       op = rs6000_fetch_instruction (gdbarch, pc);
  1214.       if ((op & 0xfffffffe) != 0x7c406008)
  1215.         break;

  1216.       /* We found a valid stack-check sequence, return the new PC.  */
  1217.       return pc;
  1218.     }

  1219.   /* No stack check code in our prologue, return the start_pc.  */
  1220.   return start_pc;
  1221. }

  1222. /* return pc value after skipping a function prologue and also return
  1223.    information about a function frame.

  1224.    in struct rs6000_framedata fdata:
  1225.    - frameless is TRUE, if function does not have a frame.
  1226.    - nosavedpc is TRUE, if function does not save %pc value in its frame.
  1227.    - offset is the initial size of this stack frame --- the amount by
  1228.    which we decrement the sp to allocate the frame.
  1229.    - saved_gpr is the number of the first saved gpr.
  1230.    - saved_fpr is the number of the first saved fpr.
  1231.    - saved_vr is the number of the first saved vr.
  1232.    - saved_ev is the number of the first saved ev.
  1233.    - alloca_reg is the number of the register used for alloca() handling.
  1234.    Otherwise -1.
  1235.    - gpr_offset is the offset of the first saved gpr from the previous frame.
  1236.    - fpr_offset is the offset of the first saved fpr from the previous frame.
  1237.    - vr_offset is the offset of the first saved vr from the previous frame.
  1238.    - ev_offset is the offset of the first saved ev from the previous frame.
  1239.    - lr_offset is the offset of the saved lr
  1240.    - cr_offset is the offset of the saved cr
  1241.    - vrsave_offset is the offset of the saved vrsave register.  */

  1242. static CORE_ADDR
  1243. skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
  1244.                struct rs6000_framedata *fdata)
  1245. {
  1246.   CORE_ADDR orig_pc = pc;
  1247.   CORE_ADDR last_prologue_pc = pc;
  1248.   CORE_ADDR li_found_pc = 0;
  1249.   gdb_byte buf[4];
  1250.   unsigned long op;
  1251.   long offset = 0;
  1252.   long vr_saved_offset = 0;
  1253.   int lr_reg = -1;
  1254.   int cr_reg = -1;
  1255.   int vr_reg = -1;
  1256.   int ev_reg = -1;
  1257.   long ev_offset = 0;
  1258.   int vrsave_reg = -1;
  1259.   int reg;
  1260.   int framep = 0;
  1261.   int minimal_toc_loaded = 0;
  1262.   int prev_insn_was_prologue_insn = 1;
  1263.   int num_skip_non_prologue_insns = 0;
  1264.   int r0_contains_arg = 0;
  1265.   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
  1266.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  1267.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  1268.   memset (fdata, 0, sizeof (struct rs6000_framedata));
  1269.   fdata->saved_gpr = -1;
  1270.   fdata->saved_fpr = -1;
  1271.   fdata->saved_vr = -1;
  1272.   fdata->saved_ev = -1;
  1273.   fdata->alloca_reg = -1;
  1274.   fdata->frameless = 1;
  1275.   fdata->nosavedpc = 1;
  1276.   fdata->lr_register = -1;

  1277.   pc = rs6000_skip_stack_check (gdbarch, pc);
  1278.   if (pc >= lim_pc)
  1279.     pc = lim_pc;

  1280.   for (;; pc += 4)
  1281.     {
  1282.       /* Sometimes it isn't clear if an instruction is a prologue
  1283.          instruction or not.  When we encounter one of these ambiguous
  1284.          cases, we'll set prev_insn_was_prologue_insn to 0 (false).
  1285.          Otherwise, we'll assume that it really is a prologue instruction.  */
  1286.       if (prev_insn_was_prologue_insn)
  1287.         last_prologue_pc = pc;

  1288.       /* Stop scanning if we've hit the limit.  */
  1289.       if (pc >= lim_pc)
  1290.         break;

  1291.       prev_insn_was_prologue_insn = 1;

  1292.       /* Fetch the instruction and convert it to an integer.  */
  1293.       if (target_read_memory (pc, buf, 4))
  1294.         break;
  1295.       op = extract_unsigned_integer (buf, 4, byte_order);

  1296.       if ((op & 0xfc1fffff) == 0x7c0802a6)
  1297.         {                        /* mflr Rx */
  1298.           /* Since shared library / PIC code, which needs to get its
  1299.              address at runtime, can appear to save more than one link
  1300.              register vis:

  1301.              *INDENT-OFF*
  1302.              stwu r1,-304(r1)
  1303.              mflr r3
  1304.              bl 0xff570d0 (blrl)
  1305.              stw r30,296(r1)
  1306.              mflr r30
  1307.              stw r31,300(r1)
  1308.              stw r3,308(r1);
  1309.              ...
  1310.              *INDENT-ON*

  1311.              remember just the first one, but skip over additional
  1312.              ones.  */
  1313.           if (lr_reg == -1)
  1314.             lr_reg = (op & 0x03e00000) >> 21;
  1315.           if (lr_reg == 0)
  1316.             r0_contains_arg = 0;
  1317.           continue;
  1318.         }
  1319.       else if ((op & 0xfc1fffff) == 0x7c000026)
  1320.         {                        /* mfcr Rx */
  1321.           cr_reg = (op & 0x03e00000);
  1322.           if (cr_reg == 0)
  1323.             r0_contains_arg = 0;
  1324.           continue;

  1325.         }
  1326.       else if ((op & 0xfc1f0000) == 0xd8010000)
  1327.         {                        /* stfd Rx,NUM(r1) */
  1328.           reg = GET_SRC_REG (op);
  1329.           if (fdata->saved_fpr == -1 || fdata->saved_fpr > reg)
  1330.             {
  1331.               fdata->saved_fpr = reg;
  1332.               fdata->fpr_offset = SIGNED_SHORT (op) + offset;
  1333.             }
  1334.           continue;

  1335.         }
  1336.       else if (((op & 0xfc1f0000) == 0xbc010000) ||        /* stm Rx, NUM(r1) */
  1337.                (((op & 0xfc1f0000) == 0x90010000 ||        /* st rx,NUM(r1) */
  1338.                  (op & 0xfc1f0003) == 0xf8010000) &&        /* std rx,NUM(r1) */
  1339.                 (op & 0x03e00000) >= 0x01a00000))        /* rx >= r13 */
  1340.         {

  1341.           reg = GET_SRC_REG (op);
  1342.           if ((op & 0xfc1f0000) == 0xbc010000)
  1343.             fdata->gpr_mask |= ~((1U << reg) - 1);
  1344.           else
  1345.             fdata->gpr_mask |= 1U << reg;
  1346.           if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg)
  1347.             {
  1348.               fdata->saved_gpr = reg;
  1349.               if ((op & 0xfc1f0003) == 0xf8010000)
  1350.                 op &= ~3UL;
  1351.               fdata->gpr_offset = SIGNED_SHORT (op) + offset;
  1352.             }
  1353.           continue;

  1354.         }
  1355.       else if ((op & 0xffff0000) == 0x3c4c0000
  1356.                || (op & 0xffff0000) == 0x3c400000
  1357.                || (op & 0xffff0000) == 0x38420000)
  1358.         {
  1359.           /* .        0:        addis 2,12,.TOC.-0b@ha
  1360.              .                addi 2,2,.TOC.-0b@l
  1361.              or
  1362.              .                lis 2,.TOC.@ha
  1363.              .                addi 2,2,.TOC.@l
  1364.              used by ELFv2 global entry points to set up r2.  */
  1365.           continue;
  1366.         }
  1367.       else if (op == 0x60000000)
  1368.         {
  1369.           /* nop */
  1370.           /* Allow nops in the prologue, but do not consider them to
  1371.              be part of the prologue unless followed by other prologue
  1372.              instructions.  */
  1373.           prev_insn_was_prologue_insn = 0;
  1374.           continue;

  1375.         }
  1376.       else if ((op & 0xffff0000) == 0x3c000000)
  1377.         {                        /* addis 0,0,NUM, used for >= 32k frames */
  1378.           fdata->offset = (op & 0x0000ffff) << 16;
  1379.           fdata->frameless = 0;
  1380.           r0_contains_arg = 0;
  1381.           continue;

  1382.         }
  1383.       else if ((op & 0xffff0000) == 0x60000000)
  1384.         {                        /* ori 0,0,NUM, 2nd half of >= 32k frames */
  1385.           fdata->offset |= (op & 0x0000ffff);
  1386.           fdata->frameless = 0;
  1387.           r0_contains_arg = 0;
  1388.           continue;

  1389.         }
  1390.       else if (lr_reg >= 0 &&
  1391.                /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
  1392.                (((op & 0xffff0000) == (lr_reg | 0xf8010000)) ||
  1393.                 /* stw Rx, NUM(r1) */
  1394.                 ((op & 0xffff0000) == (lr_reg | 0x90010000)) ||
  1395.                 /* stwu Rx, NUM(r1) */
  1396.                 ((op & 0xffff0000) == (lr_reg | 0x94010000))))
  1397.         {        /* where Rx == lr */
  1398.           fdata->lr_offset = offset;
  1399.           fdata->nosavedpc = 0;
  1400.           /* Invalidate lr_reg, but don't set it to -1.
  1401.              That would mean that it had never been set.  */
  1402.           lr_reg = -2;
  1403.           if ((op & 0xfc000003) == 0xf8000000 ||        /* std */
  1404.               (op & 0xfc000000) == 0x90000000)                /* stw */
  1405.             {
  1406.               /* Does not update r1, so add displacement to lr_offset.  */
  1407.               fdata->lr_offset += SIGNED_SHORT (op);
  1408.             }
  1409.           continue;

  1410.         }
  1411.       else if (cr_reg >= 0 &&
  1412.                /* std Rx, NUM(r1) || stdu Rx, NUM(r1) */
  1413.                (((op & 0xffff0000) == (cr_reg | 0xf8010000)) ||
  1414.                 /* stw Rx, NUM(r1) */
  1415.                 ((op & 0xffff0000) == (cr_reg | 0x90010000)) ||
  1416.                 /* stwu Rx, NUM(r1) */
  1417.                 ((op & 0xffff0000) == (cr_reg | 0x94010000))))
  1418.         {        /* where Rx == cr */
  1419.           fdata->cr_offset = offset;
  1420.           /* Invalidate cr_reg, but don't set it to -1.
  1421.              That would mean that it had never been set.  */
  1422.           cr_reg = -2;
  1423.           if ((op & 0xfc000003) == 0xf8000000 ||
  1424.               (op & 0xfc000000) == 0x90000000)
  1425.             {
  1426.               /* Does not update r1, so add displacement to cr_offset.  */
  1427.               fdata->cr_offset += SIGNED_SHORT (op);
  1428.             }
  1429.           continue;

  1430.         }
  1431.       else if ((op & 0xfe80ffff) == 0x42800005 && lr_reg != -1)
  1432.         {
  1433.           /* bcl 20,xx,.+4 is used to get the current PC, with or without
  1434.              prediction bits.  If the LR has already been saved, we can
  1435.              skip it.  */
  1436.           continue;
  1437.         }
  1438.       else if (op == 0x48000005)
  1439.         {                        /* bl .+4 used in
  1440.                                    -mrelocatable */
  1441.           fdata->used_bl = 1;
  1442.           continue;

  1443.         }
  1444.       else if (op == 0x48000004)
  1445.         {                        /* b .+4 (xlc) */
  1446.           break;

  1447.         }
  1448.       else if ((op & 0xffff0000) == 0x3fc00000 ||  /* addis 30,0,foo@ha, used
  1449.                                                       in V.4 -mminimal-toc */
  1450.                (op & 0xffff0000) == 0x3bde0000)
  1451.         {                        /* addi 30,30,foo@l */
  1452.           continue;

  1453.         }
  1454.       else if ((op & 0xfc000001) == 0x48000001)
  1455.         {                        /* bl foo,
  1456.                                    to save fprs???  */

  1457.           fdata->frameless = 0;

  1458.           /* If the return address has already been saved, we can skip
  1459.              calls to blrl (for PIC).  */
  1460.           if (lr_reg != -1 && bl_to_blrl_insn_p (pc, op, byte_order))
  1461.             {
  1462.               fdata->used_bl = 1;
  1463.               continue;
  1464.             }

  1465.           /* Don't skip over the subroutine call if it is not within
  1466.              the first three instructions of the prologue and either
  1467.              we have no line table information or the line info tells
  1468.              us that the subroutine call is not part of the line
  1469.              associated with the prologue.  */
  1470.           if ((pc - orig_pc) > 8)
  1471.             {
  1472.               struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0);
  1473.               struct symtab_and_line this_sal = find_pc_line (pc, 0);

  1474.               if ((prologue_sal.line == 0)
  1475.                   || (prologue_sal.line != this_sal.line))
  1476.                 break;
  1477.             }

  1478.           op = read_memory_integer (pc + 4, 4, byte_order);

  1479.           /* At this point, make sure this is not a trampoline
  1480.              function (a function that simply calls another functions,
  1481.              and nothing else).  If the next is not a nop, this branch
  1482.              was part of the function prologue.  */

  1483.           if (op == 0x4def7b82 || op == 0)        /* crorc 15, 15, 15 */
  1484.             break;                /* Don't skip over
  1485.                                    this branch.  */

  1486.           fdata->used_bl = 1;
  1487.           continue;
  1488.         }
  1489.       /* update stack pointer */
  1490.       else if ((op & 0xfc1f0000) == 0x94010000)
  1491.         {                /* stu rX,NUM(r1) ||  stwu rX,NUM(r1) */
  1492.           fdata->frameless = 0;
  1493.           fdata->offset = SIGNED_SHORT (op);
  1494.           offset = fdata->offset;
  1495.           continue;
  1496.         }
  1497.       else if ((op & 0xfc1f016a) == 0x7c01016e)
  1498.         {                        /* stwux rX,r1,rY */
  1499.           /* No way to figure out what r1 is going to be.  */
  1500.           fdata->frameless = 0;
  1501.           offset = fdata->offset;
  1502.           continue;
  1503.         }
  1504.       else if ((op & 0xfc1f0003) == 0xf8010001)
  1505.         {                        /* stdu rX,NUM(r1) */
  1506.           fdata->frameless = 0;
  1507.           fdata->offset = SIGNED_SHORT (op & ~3UL);
  1508.           offset = fdata->offset;
  1509.           continue;
  1510.         }
  1511.       else if ((op & 0xfc1f016a) == 0x7c01016a)
  1512.         {                        /* stdux rX,r1,rY */
  1513.           /* No way to figure out what r1 is going to be.  */
  1514.           fdata->frameless = 0;
  1515.           offset = fdata->offset;
  1516.           continue;
  1517.         }
  1518.       else if ((op & 0xffff0000) == 0x38210000)
  1519.          {                        /* addi r1,r1,SIMM */
  1520.            fdata->frameless = 0;
  1521.            fdata->offset += SIGNED_SHORT (op);
  1522.            offset = fdata->offset;
  1523.            continue;
  1524.          }
  1525.       /* Load up minimal toc pointer.  Do not treat an epilogue restore
  1526.          of r31 as a minimal TOC load.  */
  1527.       else if (((op >> 22) == 0x20f        ||        /* l r31,... or l r30,...  */
  1528.                (op >> 22) == 0x3af)                /* ld r31,... or ld r30,...  */
  1529.                && !framep
  1530.                && !minimal_toc_loaded)
  1531.         {
  1532.           minimal_toc_loaded = 1;
  1533.           continue;

  1534.           /* move parameters from argument registers to local variable
  1535.              registers */
  1536.          }
  1537.       else if ((op & 0xfc0007fe) == 0x7c000378 &&        /* mr(.)  Rx,Ry */
  1538.                (((op >> 21) & 31) >= 3) &&              /* R3 >= Ry >= R10 */
  1539.                (((op >> 21) & 31) <= 10) &&
  1540.                ((long) ((op >> 16) & 31)
  1541.                 >= fdata->saved_gpr)) /* Rx: local var reg */
  1542.         {
  1543.           continue;

  1544.           /* store parameters in stack */
  1545.         }
  1546.       /* Move parameters from argument registers to temporary register.  */
  1547.       else if (store_param_on_stack_p (op, framep, &r0_contains_arg))
  1548.         {
  1549.           continue;

  1550.           /* Set up frame pointer */
  1551.         }
  1552.       else if (op == 0x603d0000)       /* oril r29, r1, 0x0 */
  1553.         {
  1554.           fdata->frameless = 0;
  1555.           framep = 1;
  1556.           fdata->alloca_reg = (tdep->ppc_gp0_regnum + 29);
  1557.           continue;

  1558.           /* Another way to set up the frame pointer.  */
  1559.         }
  1560.       else if (op == 0x603f0000        /* oril r31, r1, 0x0 */
  1561.                || op == 0x7c3f0b78)
  1562.         {                        /* mr r31, r1 */
  1563.           fdata->frameless = 0;
  1564.           framep = 1;
  1565.           fdata->alloca_reg = (tdep->ppc_gp0_regnum + 31);
  1566.           continue;

  1567.           /* Another way to set up the frame pointer.  */
  1568.         }
  1569.       else if ((op & 0xfc1fffff) == 0x38010000)
  1570.         {                        /* addi rX, r1, 0x0 */
  1571.           fdata->frameless = 0;
  1572.           framep = 1;
  1573.           fdata->alloca_reg = (tdep->ppc_gp0_regnum
  1574.                                + ((op & ~0x38010000) >> 21));
  1575.           continue;
  1576.         }
  1577.       /* AltiVec related instructions.  */
  1578.       /* Store the vrsave register (spr 256) in another register for
  1579.          later manipulation, or load a register into the vrsave
  1580.          register.  2 instructions are used: mfvrsave and
  1581.          mtvrsave.  They are shorthand notation for mfspr Rn, SPR256
  1582.          and mtspr SPR256, Rn.  */
  1583.       /* mfspr Rn SPR256 == 011111 nnnnn 0000001000 01010100110
  1584.          mtspr SPR256 Rn == 011111 nnnnn 0000001000 01110100110  */
  1585.       else if ((op & 0xfc1fffff) == 0x7c0042a6)    /* mfvrsave Rn */
  1586.         {
  1587.           vrsave_reg = GET_SRC_REG (op);
  1588.           continue;
  1589.         }
  1590.       else if ((op & 0xfc1fffff) == 0x7c0043a6)     /* mtvrsave Rn */
  1591.         {
  1592.           continue;
  1593.         }
  1594.       /* Store the register where vrsave was saved to onto the stack:
  1595.          rS is the register where vrsave was stored in a previous
  1596.          instruction.  */
  1597.       /* 100100 sssss 00001 dddddddd dddddddd */
  1598.       else if ((op & 0xfc1f0000) == 0x90010000)     /* stw rS, d(r1) */
  1599.         {
  1600.           if (vrsave_reg == GET_SRC_REG (op))
  1601.             {
  1602.               fdata->vrsave_offset = SIGNED_SHORT (op) + offset;
  1603.               vrsave_reg = -1;
  1604.             }
  1605.           continue;
  1606.         }
  1607.       /* Compute the new value of vrsave, by modifying the register
  1608.          where vrsave was saved to.  */
  1609.       else if (((op & 0xfc000000) == 0x64000000)    /* oris Ra, Rs, UIMM */
  1610.                || ((op & 0xfc000000) == 0x60000000))/* ori Ra, Rs, UIMM */
  1611.         {
  1612.           continue;
  1613.         }
  1614.       /* li r0, SIMM (short for addi r0, 0, SIMM).  This is the first
  1615.          in a pair of insns to save the vector registers on the
  1616.          stack.  */
  1617.       /* 001110 00000 00000 iiii iiii iiii iiii  */
  1618.       /* 001110 01110 00000 iiii iiii iiii iiii  */
  1619.       else if ((op & 0xffff0000) == 0x38000000         /* li r0, SIMM */
  1620.                || (op & 0xffff0000) == 0x39c00000)     /* li r14, SIMM */
  1621.         {
  1622.           if ((op & 0xffff0000) == 0x38000000)
  1623.             r0_contains_arg = 0;
  1624.           li_found_pc = pc;
  1625.           vr_saved_offset = SIGNED_SHORT (op);

  1626.           /* This insn by itself is not part of the prologue, unless
  1627.              if part of the pair of insns mentioned above.  So do not
  1628.              record this insn as part of the prologue yet.  */
  1629.           prev_insn_was_prologue_insn = 0;
  1630.         }
  1631.       /* Store vector register S at (r31+r0) aligned to 16 bytes.  */
  1632.       /* 011111 sssss 11111 00000 00111001110 */
  1633.       else if ((op & 0xfc1fffff) == 0x7c1f01ce)   /* stvx Vs, R31, R0 */
  1634.         {
  1635.           if (pc == (li_found_pc + 4))
  1636.             {
  1637.               vr_reg = GET_SRC_REG (op);
  1638.               /* If this is the first vector reg to be saved, or if
  1639.                  it has a lower number than others previously seen,
  1640.                  reupdate the frame info.  */
  1641.               if (fdata->saved_vr == -1 || fdata->saved_vr > vr_reg)
  1642.                 {
  1643.                   fdata->saved_vr = vr_reg;
  1644.                   fdata->vr_offset = vr_saved_offset + offset;
  1645.                 }
  1646.               vr_saved_offset = -1;
  1647.               vr_reg = -1;
  1648.               li_found_pc = 0;
  1649.             }
  1650.         }
  1651.       /* End AltiVec related instructions.  */

  1652.       /* Start BookE related instructions.  */
  1653.       /* Store gen register S at (r31+uimm).
  1654.          Any register less than r13 is volatile, so we don't care.  */
  1655.       /* 000100 sssss 11111 iiiii 01100100001 */
  1656.       else if (arch_info->mach == bfd_mach_ppc_e500
  1657.                && (op & 0xfc1f07ff) == 0x101f0321)    /* evstdd Rs,uimm(R31) */
  1658.         {
  1659.           if ((op & 0x03e00000) >= 0x01a00000)        /* Rs >= r13 */
  1660.             {
  1661.               unsigned int imm;
  1662.               ev_reg = GET_SRC_REG (op);
  1663.               imm = (op >> 11) & 0x1f;
  1664.               ev_offset = imm * 8;
  1665.               /* If this is the first vector reg to be saved, or if
  1666.                  it has a lower number than others previously seen,
  1667.                  reupdate the frame info.  */
  1668.               if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
  1669.                 {
  1670.                   fdata->saved_ev = ev_reg;
  1671.                   fdata->ev_offset = ev_offset + offset;
  1672.                 }
  1673.             }
  1674.           continue;
  1675.         }
  1676.       /* Store gen register rS at (r1+rB).  */
  1677.       /* 000100 sssss 00001 bbbbb 01100100000 */
  1678.       else if (arch_info->mach == bfd_mach_ppc_e500
  1679.                && (op & 0xffe007ff) == 0x13e00320)     /* evstddx RS,R1,Rb */
  1680.         {
  1681.           if (pc == (li_found_pc + 4))
  1682.             {
  1683.               ev_reg = GET_SRC_REG (op);
  1684.               /* If this is the first vector reg to be saved, or if
  1685.                  it has a lower number than others previously seen,
  1686.                  reupdate the frame info.  */
  1687.               /* We know the contents of rB from the previous instruction.  */
  1688.               if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
  1689.                 {
  1690.                   fdata->saved_ev = ev_reg;
  1691.                   fdata->ev_offset = vr_saved_offset + offset;
  1692.                 }
  1693.               vr_saved_offset = -1;
  1694.               ev_reg = -1;
  1695.               li_found_pc = 0;
  1696.             }
  1697.           continue;
  1698.         }
  1699.       /* Store gen register r31 at (rA+uimm).  */
  1700.       /* 000100 11111 aaaaa iiiii 01100100001 */
  1701.       else if (arch_info->mach == bfd_mach_ppc_e500
  1702.                && (op & 0xffe007ff) == 0x13e00321)   /* evstdd R31,Ra,UIMM */
  1703.         {
  1704.           /* Wwe know that the source register is 31 already, but
  1705.              it can't hurt to compute it.  */
  1706.           ev_reg = GET_SRC_REG (op);
  1707.           ev_offset = ((op >> 11) & 0x1f) * 8;
  1708.           /* If this is the first vector reg to be saved, or if
  1709.              it has a lower number than others previously seen,
  1710.              reupdate the frame info.  */
  1711.           if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
  1712.             {
  1713.               fdata->saved_ev = ev_reg;
  1714.               fdata->ev_offset = ev_offset + offset;
  1715.             }

  1716.           continue;
  1717.               }
  1718.       /* Store gen register S at (r31+r0).
  1719.          Store param on stack when offset from SP bigger than 4 bytes.  */
  1720.       /* 000100 sssss 11111 00000 01100100000 */
  1721.       else if (arch_info->mach == bfd_mach_ppc_e500
  1722.                && (op & 0xfc1fffff) == 0x101f0320)     /* evstddx Rs,R31,R0 */
  1723.         {
  1724.           if (pc == (li_found_pc + 4))
  1725.             {
  1726.               if ((op & 0x03e00000) >= 0x01a00000)
  1727.                 {
  1728.                   ev_reg = GET_SRC_REG (op);
  1729.                   /* If this is the first vector reg to be saved, or if
  1730.                      it has a lower number than others previously seen,
  1731.                      reupdate the frame info.  */
  1732.                   /* We know the contents of r0 from the previous
  1733.                      instruction.  */
  1734.                   if (fdata->saved_ev == -1 || fdata->saved_ev > ev_reg)
  1735.                     {
  1736.                       fdata->saved_ev = ev_reg;
  1737.                       fdata->ev_offset = vr_saved_offset + offset;
  1738.                     }
  1739.                   ev_reg = -1;
  1740.                 }
  1741.               vr_saved_offset = -1;
  1742.               li_found_pc = 0;
  1743.               continue;
  1744.             }
  1745.         }
  1746.       /* End BookE related instructions.  */

  1747.       else
  1748.         {
  1749.           unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);

  1750.           /* Not a recognized prologue instruction.
  1751.              Handle optimizer code motions into the prologue by continuing
  1752.              the search if we have no valid frame yet or if the return
  1753.              address is not yet saved in the frame.  Also skip instructions
  1754.              if some of the GPRs expected to be saved are not yet saved.  */
  1755.           if (fdata->frameless == 0 && fdata->nosavedpc == 0
  1756.               && (fdata->gpr_mask & all_mask) == all_mask)
  1757.             break;

  1758.           if (op == 0x4e800020                /* blr */
  1759.               || op == 0x4e800420)        /* bctr */
  1760.             /* Do not scan past epilogue in frameless functions or
  1761.                trampolines.  */
  1762.             break;
  1763.           if ((op & 0xf4000000) == 0x40000000) /* bxx */
  1764.             /* Never skip branches.  */
  1765.             break;

  1766.           if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns)
  1767.             /* Do not scan too many insns, scanning insns is expensive with
  1768.                remote targets.  */
  1769.             break;

  1770.           /* Continue scanning.  */
  1771.           prev_insn_was_prologue_insn = 0;
  1772.           continue;
  1773.         }
  1774.     }

  1775. #if 0
  1776. /* I have problems with skipping over __main() that I need to address
  1777. * sometime.  Previously, I used to use misc_function_vector which
  1778. * didn't work as well as I wanted to be.  -MGO */

  1779.   /* If the first thing after skipping a prolog is a branch to a function,
  1780.      this might be a call to an initializer in main(), introduced by gcc2.
  1781.      We'd like to skip over it as well.  Fortunately, xlc does some extra
  1782.      work before calling a function right after a prologue, thus we can
  1783.      single out such gcc2 behaviour.  */


  1784.   if ((op & 0xfc000001) == 0x48000001)
  1785.     {                                /* bl foo, an initializer function?  */
  1786.       op = read_memory_integer (pc + 4, 4, byte_order);

  1787.       if (op == 0x4def7b82)
  1788.         {                        /* cror 0xf, 0xf, 0xf (nop) */

  1789.           /* Check and see if we are in main.  If so, skip over this
  1790.              initializer function as well.  */

  1791.           tmp = find_pc_misc_function (pc);
  1792.           if (tmp >= 0
  1793.               && strcmp (misc_function_vector[tmp].name, main_name ()) == 0)
  1794.             return pc + 8;
  1795.         }
  1796.     }
  1797. #endif /* 0 */

  1798.   if (pc == lim_pc && lr_reg >= 0)
  1799.     fdata->lr_register = lr_reg;

  1800.   fdata->offset = -fdata->offset;
  1801.   return last_prologue_pc;
  1802. }

  1803. static CORE_ADDR
  1804. rs6000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  1805. {
  1806.   struct rs6000_framedata frame;
  1807.   CORE_ADDR limit_pc, func_addr, func_end_addr = 0;

  1808.   /* See if we can determine the end of the prologue via the symbol table.
  1809.      If so, then return either PC, or the PC after the prologue, whichever
  1810.      is greater.  */
  1811.   if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr))
  1812.     {
  1813.       CORE_ADDR post_prologue_pc
  1814.         = skip_prologue_using_sal (gdbarch, func_addr);
  1815.       if (post_prologue_pc != 0)
  1816.         return max (pc, post_prologue_pc);
  1817.     }

  1818.   /* Can't determine prologue from the symbol table, need to examine
  1819.      instructions.  */

  1820.   /* Find an upper limit on the function prologue using the debug
  1821.      information.  If the debug information could not be used to provide
  1822.      that bound, then use an arbitrary large number as the upper bound.  */
  1823.   limit_pc = skip_prologue_using_sal (gdbarch, pc);
  1824.   if (limit_pc == 0)
  1825.     limit_pc = pc + 100;          /* Magic.  */

  1826.   /* Do not allow limit_pc to be past the function end, if we know
  1827.      where that end is...  */
  1828.   if (func_end_addr && limit_pc > func_end_addr)
  1829.     limit_pc = func_end_addr;

  1830.   pc = skip_prologue (gdbarch, pc, limit_pc, &frame);
  1831.   return pc;
  1832. }

  1833. /* When compiling for EABI, some versions of GCC emit a call to __eabi
  1834.    in the prologue of main().

  1835.    The function below examines the code pointed at by PC and checks to
  1836.    see if it corresponds to a call to __eabi.  If so, it returns the
  1837.    address of the instruction following that call.  Otherwise, it simply
  1838.    returns PC.  */

  1839. static CORE_ADDR
  1840. rs6000_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  1841. {
  1842.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1843.   gdb_byte buf[4];
  1844.   unsigned long op;

  1845.   if (target_read_memory (pc, buf, 4))
  1846.     return pc;
  1847.   op = extract_unsigned_integer (buf, 4, byte_order);

  1848.   if ((op & BL_MASK) == BL_INSTRUCTION)
  1849.     {
  1850.       CORE_ADDR displ = op & BL_DISPLACEMENT_MASK;
  1851.       CORE_ADDR call_dest = pc + 4 + displ;
  1852.       struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);

  1853.       /* We check for ___eabi (three leading underscores) in addition
  1854.          to __eabi in case the GCC option "-fleading-underscore" was
  1855.          used to compile the program.  */
  1856.       if (s.minsym != NULL
  1857.           && MSYMBOL_LINKAGE_NAME (s.minsym) != NULL
  1858.           && (strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "__eabi") == 0
  1859.               || strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "___eabi") == 0))
  1860.         pc += 4;
  1861.     }
  1862.   return pc;
  1863. }

  1864. /* All the ABI's require 16 byte alignment.  */
  1865. static CORE_ADDR
  1866. rs6000_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
  1867. {
  1868.   return (addr & -16);
  1869. }

  1870. /* Return whether handle_inferior_event() should proceed through code
  1871.    starting at PC in function NAME when stepping.

  1872.    The AIX -bbigtoc linker option generates functions @FIX0, @FIX1, etc. to
  1873.    handle memory references that are too distant to fit in instructions
  1874.    generated by the compiler.  For example, if 'foo' in the following
  1875.    instruction:

  1876.      lwz r9,foo(r2)

  1877.    is greater than 32767, the linker might replace the lwz with a branch to
  1878.    somewhere in @FIX1 that does the load in 2 instructions and then branches
  1879.    back to where execution should continue.

  1880.    GDB should silently step over @FIX code, just like AIX dbx does.
  1881.    Unfortunately, the linker uses the "b" instruction for the
  1882.    branches, meaning that the link register doesn't get set.
  1883.    Therefore, GDB's usual step_over_function () mechanism won't work.

  1884.    Instead, use the gdbarch_skip_trampoline_code and
  1885.    gdbarch_skip_trampoline_code hooks in handle_inferior_event() to skip past
  1886.    @FIX code.  */

  1887. static int
  1888. rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch,
  1889.                                    CORE_ADDR pc, const char *name)
  1890. {
  1891.   return name && !strncmp (name, "@FIX", 4);
  1892. }

  1893. /* Skip code that the user doesn't want to see when stepping:

  1894.    1. Indirect function calls use a piece of trampoline code to do context
  1895.    switching, i.e. to set the new TOC table.  Skip such code if we are on
  1896.    its first instruction (as when we have single-stepped to here).

  1897.    2. Skip shared library trampoline code (which is different from
  1898.    indirect function call trampolines).

  1899.    3. Skip bigtoc fixup code.

  1900.    Result is desired PC to step until, or NULL if we are not in
  1901.    code that should be skipped.  */

  1902. static CORE_ADDR
  1903. rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  1904. {
  1905.   struct gdbarch *gdbarch = get_frame_arch (frame);
  1906.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  1907.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1908.   unsigned int ii, op;
  1909.   int rel;
  1910.   CORE_ADDR solib_target_pc;
  1911.   struct bound_minimal_symbol msymbol;

  1912.   static unsigned trampoline_code[] =
  1913.   {
  1914.     0x800b0000,                        /*     l   r0,0x0(r11)  */
  1915.     0x90410014,                        /*    st   r2,0x14(r1)  */
  1916.     0x7c0903a6,                        /* mtctr   r0           */
  1917.     0x804b0004,                        /*     l   r2,0x4(r11)  */
  1918.     0x816b0008,                        /*     l  r11,0x8(r11)  */
  1919.     0x4e800420,                        /*  bctr                */
  1920.     0x4e800020,                        /*    br                */
  1921.     0
  1922.   };

  1923.   /* Check for bigtoc fixup code.  */
  1924.   msymbol = lookup_minimal_symbol_by_pc (pc);
  1925.   if (msymbol.minsym
  1926.       && rs6000_in_solib_return_trampoline (gdbarch, pc,
  1927.                                             MSYMBOL_LINKAGE_NAME (msymbol.minsym)))
  1928.     {
  1929.       /* Double-check that the third instruction from PC is relative "b".  */
  1930.       op = read_memory_integer (pc + 8, 4, byte_order);
  1931.       if ((op & 0xfc000003) == 0x48000000)
  1932.         {
  1933.           /* Extract bits 6-29 as a signed 24-bit relative word address and
  1934.              add it to the containing PC.  */
  1935.           rel = ((int)(op << 6) >> 6);
  1936.           return pc + 8 + rel;
  1937.         }
  1938.     }

  1939.   /* If pc is in a shared library trampoline, return its target.  */
  1940.   solib_target_pc = find_solib_trampoline_target (frame, pc);
  1941.   if (solib_target_pc)
  1942.     return solib_target_pc;

  1943.   for (ii = 0; trampoline_code[ii]; ++ii)
  1944.     {
  1945.       op = read_memory_integer (pc + (ii * 4), 4, byte_order);
  1946.       if (op != trampoline_code[ii])
  1947.         return 0;
  1948.     }
  1949.   ii = get_frame_register_unsigned (frame, 11);        /* r11 holds destination
  1950.                                                    addr.  */
  1951.   pc = read_memory_unsigned_integer (ii, tdep->wordsize, byte_order);
  1952.   return pc;
  1953. }

  1954. /* ISA-specific vector types.  */

  1955. static struct type *
  1956. rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
  1957. {
  1958.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  1959.   if (!tdep->ppc_builtin_type_vec64)
  1960.     {
  1961.       const struct builtin_type *bt = builtin_type (gdbarch);

  1962.       /* The type we're building is this: */
  1963. #if 0
  1964.       union __gdb_builtin_type_vec64
  1965.         {
  1966.           int64_t uint64;
  1967.           float v2_float[2];
  1968.           int32_t v2_int32[2];
  1969.           int16_t v4_int16[4];
  1970.           int8_t v8_int8[8];
  1971.         };
  1972. #endif

  1973.       struct type *t;

  1974.       t = arch_composite_type (gdbarch,
  1975.                                "__ppc_builtin_type_vec64", TYPE_CODE_UNION);
  1976.       append_composite_type_field (t, "uint64", bt->builtin_int64);
  1977.       append_composite_type_field (t, "v2_float",
  1978.                                    init_vector_type (bt->builtin_float, 2));
  1979.       append_composite_type_field (t, "v2_int32",
  1980.                                    init_vector_type (bt->builtin_int32, 2));
  1981.       append_composite_type_field (t, "v4_int16",
  1982.                                    init_vector_type (bt->builtin_int16, 4));
  1983.       append_composite_type_field (t, "v8_int8",
  1984.                                    init_vector_type (bt->builtin_int8, 8));

  1985.       TYPE_VECTOR (t) = 1;
  1986.       TYPE_NAME (t) = "ppc_builtin_type_vec64";
  1987.       tdep->ppc_builtin_type_vec64 = t;
  1988.     }

  1989.   return tdep->ppc_builtin_type_vec64;
  1990. }

  1991. /* Vector 128 type.  */

  1992. static struct type *
  1993. rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
  1994. {
  1995.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  1996.   if (!tdep->ppc_builtin_type_vec128)
  1997.     {
  1998.       const struct builtin_type *bt = builtin_type (gdbarch);

  1999.       /* The type we're building is this

  2000.          type = union __ppc_builtin_type_vec128 {
  2001.              uint128_t uint128;
  2002.              double v2_double[2];
  2003.              float v4_float[4];
  2004.              int32_t v4_int32[4];
  2005.              int16_t v8_int16[8];
  2006.              int8_t v16_int8[16];
  2007.          }
  2008.       */

  2009.       struct type *t;

  2010.       t = arch_composite_type (gdbarch,
  2011.                                "__ppc_builtin_type_vec128", TYPE_CODE_UNION);
  2012.       append_composite_type_field (t, "uint128", bt->builtin_uint128);
  2013.       append_composite_type_field (t, "v2_double",
  2014.                                    init_vector_type (bt->builtin_double, 2));
  2015.       append_composite_type_field (t, "v4_float",
  2016.                                    init_vector_type (bt->builtin_float, 4));
  2017.       append_composite_type_field (t, "v4_int32",
  2018.                                    init_vector_type (bt->builtin_int32, 4));
  2019.       append_composite_type_field (t, "v8_int16",
  2020.                                    init_vector_type (bt->builtin_int16, 8));
  2021.       append_composite_type_field (t, "v16_int8",
  2022.                                    init_vector_type (bt->builtin_int8, 16));

  2023.       TYPE_VECTOR (t) = 1;
  2024.       TYPE_NAME (t) = "ppc_builtin_type_vec128";
  2025.       tdep->ppc_builtin_type_vec128 = t;
  2026.     }

  2027.   return tdep->ppc_builtin_type_vec128;
  2028. }

  2029. /* Return the name of register number REGNO, or the empty string if it
  2030.    is an anonymous register.  */

  2031. static const char *
  2032. rs6000_register_name (struct gdbarch *gdbarch, int regno)
  2033. {
  2034.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2035.   /* The upper half "registers" have names in the XML description,
  2036.      but we present only the low GPRs and the full 64-bit registers
  2037.      to the user.  */
  2038.   if (tdep->ppc_ev0_upper_regnum >= 0
  2039.       && tdep->ppc_ev0_upper_regnum <= regno
  2040.       && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
  2041.     return "";

  2042.   /* Hide the upper halves of the vs0~vs31 registers.  */
  2043.   if (tdep->ppc_vsr0_regnum >= 0
  2044.       && tdep->ppc_vsr0_upper_regnum <= regno
  2045.       && regno < tdep->ppc_vsr0_upper_regnum + ppc_num_gprs)
  2046.     return "";

  2047.   /* Check if the SPE pseudo registers are available.  */
  2048.   if (IS_SPE_PSEUDOREG (tdep, regno))
  2049.     {
  2050.       static const char *const spe_regnames[] = {
  2051.         "ev0", "ev1", "ev2", "ev3", "ev4", "ev5", "ev6", "ev7",
  2052.         "ev8", "ev9", "ev10", "ev11", "ev12", "ev13", "ev14", "ev15",
  2053.         "ev16", "ev17", "ev18", "ev19", "ev20", "ev21", "ev22", "ev23",
  2054.         "ev24", "ev25", "ev26", "ev27", "ev28", "ev29", "ev30", "ev31",
  2055.       };
  2056.       return spe_regnames[regno - tdep->ppc_ev0_regnum];
  2057.     }

  2058.   /* Check if the decimal128 pseudo-registers are available.  */
  2059.   if (IS_DFP_PSEUDOREG (tdep, regno))
  2060.     {
  2061.       static const char *const dfp128_regnames[] = {
  2062.         "dl0", "dl1", "dl2", "dl3",
  2063.         "dl4", "dl5", "dl6", "dl7",
  2064.         "dl8", "dl9", "dl10", "dl11",
  2065.         "dl12", "dl13", "dl14", "dl15"
  2066.       };
  2067.       return dfp128_regnames[regno - tdep->ppc_dl0_regnum];
  2068.     }

  2069.   /* Check if this is a VSX pseudo-register.  */
  2070.   if (IS_VSX_PSEUDOREG (tdep, regno))
  2071.     {
  2072.       static const char *const vsx_regnames[] = {
  2073.         "vs0", "vs1", "vs2", "vs3", "vs4", "vs5", "vs6", "vs7",
  2074.         "vs8", "vs9", "vs10", "vs11", "vs12", "vs13", "vs14",
  2075.         "vs15", "vs16", "vs17", "vs18", "vs19", "vs20", "vs21",
  2076.         "vs22", "vs23", "vs24", "vs25", "vs26", "vs27", "vs28",
  2077.         "vs29", "vs30", "vs31", "vs32", "vs33", "vs34", "vs35",
  2078.         "vs36", "vs37", "vs38", "vs39", "vs40", "vs41", "vs42",
  2079.         "vs43", "vs44", "vs45", "vs46", "vs47", "vs48", "vs49",
  2080.         "vs50", "vs51", "vs52", "vs53", "vs54", "vs55", "vs56",
  2081.         "vs57", "vs58", "vs59", "vs60", "vs61", "vs62", "vs63"
  2082.       };
  2083.       return vsx_regnames[regno - tdep->ppc_vsr0_regnum];
  2084.     }

  2085.   /* Check if the this is a Extended FP pseudo-register.  */
  2086.   if (IS_EFP_PSEUDOREG (tdep, regno))
  2087.     {
  2088.       static const char *const efpr_regnames[] = {
  2089.         "f32", "f33", "f34", "f35", "f36", "f37", "f38",
  2090.         "f39", "f40", "f41", "f42", "f43", "f44", "f45",
  2091.         "f46", "f47", "f48", "f49", "f50", "f51",
  2092.         "f52", "f53", "f54", "f55", "f56", "f57",
  2093.         "f58", "f59", "f60", "f61", "f62", "f63"
  2094.       };
  2095.       return efpr_regnames[regno - tdep->ppc_efpr0_regnum];
  2096.     }

  2097.   return tdesc_register_name (gdbarch, regno);
  2098. }

  2099. /* Return the GDB type object for the "standard" data type of data in
  2100.    register N.  */

  2101. static struct type *
  2102. rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
  2103. {
  2104.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2105.   /* These are the only pseudo-registers we support.  */
  2106.   gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum)
  2107.               || IS_DFP_PSEUDOREG (tdep, regnum)
  2108.               || IS_VSX_PSEUDOREG (tdep, regnum)
  2109.               || IS_EFP_PSEUDOREG (tdep, regnum));

  2110.   /* These are the e500 pseudo-registers.  */
  2111.   if (IS_SPE_PSEUDOREG (tdep, regnum))
  2112.     return rs6000_builtin_type_vec64 (gdbarch);
  2113.   else if (IS_DFP_PSEUDOREG (tdep, regnum))
  2114.     /* PPC decimal128 pseudo-registers.  */
  2115.     return builtin_type (gdbarch)->builtin_declong;
  2116.   else if (IS_VSX_PSEUDOREG (tdep, regnum))
  2117.     /* POWER7 VSX pseudo-registers.  */
  2118.     return rs6000_builtin_type_vec128 (gdbarch);
  2119.   else
  2120.     /* POWER7 Extended FP pseudo-registers.  */
  2121.     return builtin_type (gdbarch)->builtin_double;
  2122. }

  2123. /* Is REGNUM a member of REGGROUP?  */
  2124. static int
  2125. rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  2126.                                    struct reggroup *group)
  2127. {
  2128.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2129.   /* These are the only pseudo-registers we support.  */
  2130.   gdb_assert (IS_SPE_PSEUDOREG (tdep, regnum)
  2131.               || IS_DFP_PSEUDOREG (tdep, regnum)
  2132.               || IS_VSX_PSEUDOREG (tdep, regnum)
  2133.               || IS_EFP_PSEUDOREG (tdep, regnum));

  2134.   /* These are the e500 pseudo-registers or the POWER7 VSX registers.  */
  2135.   if (IS_SPE_PSEUDOREG (tdep, regnum) || IS_VSX_PSEUDOREG (tdep, regnum))
  2136.     return group == all_reggroup || group == vector_reggroup;
  2137.   else
  2138.     /* PPC decimal128 or Extended FP pseudo-registers.  */
  2139.     return group == all_reggroup || group == float_reggroup;
  2140. }

  2141. /* The register format for RS/6000 floating point registers is always
  2142.    double, we need a conversion if the memory format is float.  */

  2143. static int
  2144. rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
  2145.                            struct type *type)
  2146. {
  2147.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2148.   return (tdep->ppc_fp0_regnum >= 0
  2149.           && regnum >= tdep->ppc_fp0_regnum
  2150.           && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs
  2151.           && TYPE_CODE (type) == TYPE_CODE_FLT
  2152.           && TYPE_LENGTH (type)
  2153.              != TYPE_LENGTH (builtin_type (gdbarch)->builtin_double));
  2154. }

  2155. static int
  2156. rs6000_register_to_value (struct frame_info *frame,
  2157.                           int regnum,
  2158.                           struct type *type,
  2159.                           gdb_byte *to,
  2160.                           int *optimizedp, int *unavailablep)
  2161. {
  2162.   struct gdbarch *gdbarch = get_frame_arch (frame);
  2163.   gdb_byte from[MAX_REGISTER_SIZE];

  2164.   gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);

  2165.   if (!get_frame_register_bytes (frame, regnum, 0,
  2166.                                  register_size (gdbarch, regnum),
  2167.                                  from, optimizedp, unavailablep))
  2168.     return 0;

  2169.   convert_typed_floating (from, builtin_type (gdbarch)->builtin_double,
  2170.                           to, type);
  2171.   *optimizedp = *unavailablep = 0;
  2172.   return 1;
  2173. }

  2174. static void
  2175. rs6000_value_to_register (struct frame_info *frame,
  2176.                           int regnum,
  2177.                           struct type *type,
  2178.                           const gdb_byte *from)
  2179. {
  2180.   struct gdbarch *gdbarch = get_frame_arch (frame);
  2181.   gdb_byte to[MAX_REGISTER_SIZE];

  2182.   gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);

  2183.   convert_typed_floating (from, type,
  2184.                           to, builtin_type (gdbarch)->builtin_double);
  2185.   put_frame_register (frame, regnum, to);
  2186. }

  2187. /* The type of a function that moves the value of REG between CACHE
  2188.     or BUF --- in either direction.  */
  2189. typedef enum register_status (*move_ev_register_func) (struct regcache *,
  2190.                                                        int, void *);

  2191. /* Move SPE vector register values between a 64-bit buffer and the two
  2192.    32-bit raw register halves in a regcache.  This function handles
  2193.    both splitting a 64-bit value into two 32-bit halves, and joining
  2194.    two halves into a whole 64-bit value, depending on the function
  2195.    passed as the MOVE argument.

  2196.    EV_REG must be the number of an SPE evN vector register --- a
  2197.    pseudoregister.  REGCACHE must be a regcache, and BUFFER must be a
  2198.    64-bit buffer.

  2199.    Call MOVE once for each 32-bit half of that register, passing
  2200.    REGCACHE, the number of the raw register corresponding to that
  2201.    half, and the address of the appropriate half of BUFFER.

  2202.    For example, passing 'regcache_raw_read' as the MOVE function will
  2203.    fill BUFFER with the full 64-bit contents of EV_REG.  Or, passing
  2204.    'regcache_raw_supply' will supply the contents of BUFFER to the
  2205.    appropriate pair of raw registers in REGCACHE.

  2206.    You may need to cast away some 'const' qualifiers when passing
  2207.    MOVE, since this function can't tell at compile-time which of
  2208.    REGCACHE or BUFFER is acting as the source of the data.  If C had
  2209.    co-variant type qualifiers, ...  */

  2210. static enum register_status
  2211. e500_move_ev_register (move_ev_register_func move,
  2212.                        struct regcache *regcache, int ev_reg, void *buffer)
  2213. {
  2214.   struct gdbarch *arch = get_regcache_arch (regcache);
  2215.   struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
  2216.   int reg_index;
  2217.   gdb_byte *byte_buffer = buffer;
  2218.   enum register_status status;

  2219.   gdb_assert (IS_SPE_PSEUDOREG (tdep, ev_reg));

  2220.   reg_index = ev_reg - tdep->ppc_ev0_regnum;

  2221.   if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
  2222.     {
  2223.       status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index,
  2224.                      byte_buffer);
  2225.       if (status == REG_VALID)
  2226.         status = move (regcache, tdep->ppc_gp0_regnum + reg_index,
  2227.                        byte_buffer + 4);
  2228.     }
  2229.   else
  2230.     {
  2231.       status = move (regcache, tdep->ppc_gp0_regnum + reg_index, byte_buffer);
  2232.       if (status == REG_VALID)
  2233.         status = move (regcache, tdep->ppc_ev0_upper_regnum + reg_index,
  2234.                        byte_buffer + 4);
  2235.     }

  2236.   return status;
  2237. }

  2238. static enum register_status
  2239. do_regcache_raw_read (struct regcache *regcache, int regnum, void *buffer)
  2240. {
  2241.   return regcache_raw_read (regcache, regnum, buffer);
  2242. }

  2243. static enum register_status
  2244. do_regcache_raw_write (struct regcache *regcache, int regnum, void *buffer)
  2245. {
  2246.   regcache_raw_write (regcache, regnum, buffer);

  2247.   return REG_VALID;
  2248. }

  2249. static enum register_status
  2250. e500_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
  2251.                            int reg_nr, gdb_byte *buffer)
  2252. {
  2253.   return e500_move_ev_register (do_regcache_raw_read, regcache, reg_nr, buffer);
  2254. }

  2255. static void
  2256. e500_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  2257.                             int reg_nr, const gdb_byte *buffer)
  2258. {
  2259.   e500_move_ev_register (do_regcache_raw_write, regcache,
  2260.                          reg_nr, (void *) buffer);
  2261. }

  2262. /* Read method for DFP pseudo-registers.  */
  2263. static enum register_status
  2264. dfp_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
  2265.                            int reg_nr, gdb_byte *buffer)
  2266. {
  2267.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2268.   int reg_index = reg_nr - tdep->ppc_dl0_regnum;
  2269.   enum register_status status;

  2270.   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  2271.     {
  2272.       /* Read two FP registers to form a whole dl register.  */
  2273.       status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2274.                                   2 * reg_index, buffer);
  2275.       if (status == REG_VALID)
  2276.         status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2277.                                     2 * reg_index + 1, buffer + 8);
  2278.     }
  2279.   else
  2280.     {
  2281.       status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2282.                                   2 * reg_index + 1, buffer);
  2283.       if (status == REG_VALID)
  2284.         status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2285.                                     2 * reg_index, buffer + 8);
  2286.     }

  2287.   return status;
  2288. }

  2289. /* Write method for DFP pseudo-registers.  */
  2290. static void
  2291. dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  2292.                             int reg_nr, const gdb_byte *buffer)
  2293. {
  2294.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2295.   int reg_index = reg_nr - tdep->ppc_dl0_regnum;

  2296.   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  2297.     {
  2298.       /* Write each half of the dl register into a separate
  2299.       FP register.  */
  2300.       regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2301.                           2 * reg_index, buffer);
  2302.       regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2303.                           2 * reg_index + 1, buffer + 8);
  2304.     }
  2305.   else
  2306.     {
  2307.       regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2308.                           2 * reg_index + 1, buffer);
  2309.       regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2310.                           2 * reg_index, buffer + 8);
  2311.     }
  2312. }

  2313. /* Read method for POWER7 VSX pseudo-registers.  */
  2314. static enum register_status
  2315. vsx_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
  2316.                            int reg_nr, gdb_byte *buffer)
  2317. {
  2318.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2319.   int reg_index = reg_nr - tdep->ppc_vsr0_regnum;
  2320.   enum register_status status;

  2321.   /* Read the portion that overlaps the VMX registers.  */
  2322.   if (reg_index > 31)
  2323.     status = regcache_raw_read (regcache, tdep->ppc_vr0_regnum +
  2324.                                 reg_index - 32, buffer);
  2325.   else
  2326.     /* Read the portion that overlaps the FPR registers.  */
  2327.     if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  2328.       {
  2329.         status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2330.                                     reg_index, buffer);
  2331.         if (status == REG_VALID)
  2332.           status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum +
  2333.                                       reg_index, buffer + 8);
  2334.       }
  2335.     else
  2336.       {
  2337.         status = regcache_raw_read (regcache, tdep->ppc_fp0_regnum +
  2338.                                     reg_index, buffer + 8);
  2339.         if (status == REG_VALID)
  2340.           status = regcache_raw_read (regcache, tdep->ppc_vsr0_upper_regnum +
  2341.                                       reg_index, buffer);
  2342.       }

  2343.   return status;
  2344. }

  2345. /* Write method for POWER7 VSX pseudo-registers.  */
  2346. static void
  2347. vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  2348.                             int reg_nr, const gdb_byte *buffer)
  2349. {
  2350.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2351.   int reg_index = reg_nr - tdep->ppc_vsr0_regnum;

  2352.   /* Write the portion that overlaps the VMX registers.  */
  2353.   if (reg_index > 31)
  2354.     regcache_raw_write (regcache, tdep->ppc_vr0_regnum +
  2355.                         reg_index - 32, buffer);
  2356.   else
  2357.     /* Write the portion that overlaps the FPR registers.  */
  2358.     if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  2359.       {
  2360.         regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2361.                         reg_index, buffer);
  2362.         regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum +
  2363.                         reg_index, buffer + 8);
  2364.       }
  2365.     else
  2366.       {
  2367.         regcache_raw_write (regcache, tdep->ppc_fp0_regnum +
  2368.                         reg_index, buffer + 8);
  2369.         regcache_raw_write (regcache, tdep->ppc_vsr0_upper_regnum +
  2370.                         reg_index, buffer);
  2371.       }
  2372. }

  2373. /* Read method for POWER7 Extended FP pseudo-registers.  */
  2374. static enum register_status
  2375. efpr_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
  2376.                            int reg_nr, gdb_byte *buffer)
  2377. {
  2378.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2379.   int reg_index = reg_nr - tdep->ppc_efpr0_regnum;
  2380.   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;

  2381.   /* Read the portion that overlaps the VMX register.  */
  2382.   return regcache_raw_read_part (regcache, tdep->ppc_vr0_regnum + reg_index,
  2383.                                  offset, register_size (gdbarch, reg_nr),
  2384.                                  buffer);
  2385. }

  2386. /* Write method for POWER7 Extended FP pseudo-registers.  */
  2387. static void
  2388. efpr_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  2389.                             int reg_nr, const gdb_byte *buffer)
  2390. {
  2391.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2392.   int reg_index = reg_nr - tdep->ppc_efpr0_regnum;
  2393.   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;

  2394.   /* Write the portion that overlaps the VMX register.  */
  2395.   regcache_raw_write_part (regcache, tdep->ppc_vr0_regnum + reg_index,
  2396.                            offset, register_size (gdbarch, reg_nr),
  2397.                            buffer);
  2398. }

  2399. static enum register_status
  2400. rs6000_pseudo_register_read (struct gdbarch *gdbarch,
  2401.                              struct regcache *regcache,
  2402.                              int reg_nr, gdb_byte *buffer)
  2403. {
  2404.   struct gdbarch *regcache_arch = get_regcache_arch (regcache);
  2405.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2406.   gdb_assert (regcache_arch == gdbarch);

  2407.   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
  2408.     return e500_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
  2409.   else if (IS_DFP_PSEUDOREG (tdep, reg_nr))
  2410.     return dfp_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
  2411.   else if (IS_VSX_PSEUDOREG (tdep, reg_nr))
  2412.     return vsx_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
  2413.   else if (IS_EFP_PSEUDOREG (tdep, reg_nr))
  2414.     return efpr_pseudo_register_read (gdbarch, regcache, reg_nr, buffer);
  2415.   else
  2416.     internal_error (__FILE__, __LINE__,
  2417.                     _("rs6000_pseudo_register_read: "
  2418.                     "called on unexpected register '%s' (%d)"),
  2419.                     gdbarch_register_name (gdbarch, reg_nr), reg_nr);
  2420. }

  2421. static void
  2422. rs6000_pseudo_register_write (struct gdbarch *gdbarch,
  2423.                               struct regcache *regcache,
  2424.                               int reg_nr, const gdb_byte *buffer)
  2425. {
  2426.   struct gdbarch *regcache_arch = get_regcache_arch (regcache);
  2427.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2428.   gdb_assert (regcache_arch == gdbarch);

  2429.   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
  2430.     e500_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
  2431.   else if (IS_DFP_PSEUDOREG (tdep, reg_nr))
  2432.     dfp_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
  2433.   else if (IS_VSX_PSEUDOREG (tdep, reg_nr))
  2434.     vsx_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
  2435.   else if (IS_EFP_PSEUDOREG (tdep, reg_nr))
  2436.     efpr_pseudo_register_write (gdbarch, regcache, reg_nr, buffer);
  2437.   else
  2438.     internal_error (__FILE__, __LINE__,
  2439.                     _("rs6000_pseudo_register_write: "
  2440.                     "called on unexpected register '%s' (%d)"),
  2441.                     gdbarch_register_name (gdbarch, reg_nr), reg_nr);
  2442. }

  2443. /* Convert a DBX STABS register number to a GDB register number.  */
  2444. static int
  2445. rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
  2446. {
  2447.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2448.   if (0 <= num && num <= 31)
  2449.     return tdep->ppc_gp0_regnum + num;
  2450.   else if (32 <= num && num <= 63)
  2451.     /* FIXME: jimb/2004-05-05: What should we do when the debug info
  2452.        specifies registers the architecture doesn't have?  Our
  2453.        callers don't check the value we return.  */
  2454.     return tdep->ppc_fp0_regnum + (num - 32);
  2455.   else if (77 <= num && num <= 108)
  2456.     return tdep->ppc_vr0_regnum + (num - 77);
  2457.   else if (1200 <= num && num < 1200 + 32)
  2458.     return tdep->ppc_ev0_upper_regnum + (num - 1200);
  2459.   else
  2460.     switch (num)
  2461.       {
  2462.       case 64:
  2463.         return tdep->ppc_mq_regnum;
  2464.       case 65:
  2465.         return tdep->ppc_lr_regnum;
  2466.       case 66:
  2467.         return tdep->ppc_ctr_regnum;
  2468.       case 76:
  2469.         return tdep->ppc_xer_regnum;
  2470.       case 109:
  2471.         return tdep->ppc_vrsave_regnum;
  2472.       case 110:
  2473.         return tdep->ppc_vrsave_regnum - 1; /* vscr */
  2474.       case 111:
  2475.         return tdep->ppc_acc_regnum;
  2476.       case 112:
  2477.         return tdep->ppc_spefscr_regnum;
  2478.       default:
  2479.         return num;
  2480.       }
  2481. }


  2482. /* Convert a Dwarf 2 register number to a GDB register number.  */
  2483. static int
  2484. rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
  2485. {
  2486.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2487.   if (0 <= num && num <= 31)
  2488.     return tdep->ppc_gp0_regnum + num;
  2489.   else if (32 <= num && num <= 63)
  2490.     /* FIXME: jimb/2004-05-05: What should we do when the debug info
  2491.        specifies registers the architecture doesn't have?  Our
  2492.        callers don't check the value we return.  */
  2493.     return tdep->ppc_fp0_regnum + (num - 32);
  2494.   else if (1124 <= num && num < 1124 + 32)
  2495.     return tdep->ppc_vr0_regnum + (num - 1124);
  2496.   else if (1200 <= num && num < 1200 + 32)
  2497.     return tdep->ppc_ev0_upper_regnum + (num - 1200);
  2498.   else
  2499.     switch (num)
  2500.       {
  2501.       case 64:
  2502.         return tdep->ppc_cr_regnum;
  2503.       case 67:
  2504.         return tdep->ppc_vrsave_regnum - 1; /* vscr */
  2505.       case 99:
  2506.         return tdep->ppc_acc_regnum;
  2507.       case 100:
  2508.         return tdep->ppc_mq_regnum;
  2509.       case 101:
  2510.         return tdep->ppc_xer_regnum;
  2511.       case 108:
  2512.         return tdep->ppc_lr_regnum;
  2513.       case 109:
  2514.         return tdep->ppc_ctr_regnum;
  2515.       case 356:
  2516.         return tdep->ppc_vrsave_regnum;
  2517.       case 612:
  2518.         return tdep->ppc_spefscr_regnum;
  2519.       default:
  2520.         return num;
  2521.       }
  2522. }

  2523. /* Translate a .eh_frame register to DWARF register, or adjust a
  2524.    .debug_frame register.  */

  2525. static int
  2526. rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
  2527. {
  2528.   /* GCC releases before 3.4 use GCC internal register numbering in
  2529.      .debug_frame (and .debug_info, et cetera).  The numbering is
  2530.      different from the standard SysV numbering for everything except
  2531.      for GPRs and FPRs.  We can not detect this problem in most cases
  2532.      - to get accurate debug info for variables living in lr, ctr, v0,
  2533.      et cetera, use a newer version of GCC.  But we must detect
  2534.      one important case - lr is in column 65 in .debug_frame output,
  2535.      instead of 108.

  2536.      GCC 3.4, and the "hammer" branch, have a related problem.  They
  2537.      record lr register saves in .debug_frame as 108, but still record
  2538.      the return column as 65.  We fix that up too.

  2539.      We can do this because 65 is assigned to fpsr, and GCC never
  2540.      generates debug info referring to it.  To add support for
  2541.      handwritten debug info that restores fpsr, we would need to add a
  2542.      producer version check to this.  */
  2543.   if (!eh_frame_p)
  2544.     {
  2545.       if (num == 65)
  2546.         return 108;
  2547.       else
  2548.         return num;
  2549.     }

  2550.   /* .eh_frame is GCC specific.  For binary compatibility, it uses GCC
  2551.      internal register numbering; translate that to the standard DWARF2
  2552.      register numbering.  */
  2553.   if (0 <= num && num <= 63)        /* r0-r31,fp0-fp31 */
  2554.     return num;
  2555.   else if (68 <= num && num <= 75) /* cr0-cr8 */
  2556.     return num - 68 + 86;
  2557.   else if (77 <= num && num <= 108) /* vr0-vr31 */
  2558.     return num - 77 + 1124;
  2559.   else
  2560.     switch (num)
  2561.       {
  2562.       case 64: /* mq */
  2563.         return 100;
  2564.       case 65: /* lr */
  2565.         return 108;
  2566.       case 66: /* ctr */
  2567.         return 109;
  2568.       case 76: /* xer */
  2569.         return 101;
  2570.       case 109: /* vrsave */
  2571.         return 356;
  2572.       case 110: /* vscr */
  2573.         return 67;
  2574.       case 111: /* spe_acc */
  2575.         return 99;
  2576.       case 112: /* spefscr */
  2577.         return 612;
  2578.       default:
  2579.         return num;
  2580.       }
  2581. }


  2582. /* Handling the various POWER/PowerPC variants.  */

  2583. /* Information about a particular processor variant.  */

  2584. struct variant
  2585.   {
  2586.     /* Name of this variant.  */
  2587.     char *name;

  2588.     /* English description of the variant.  */
  2589.     char *description;

  2590.     /* bfd_arch_info.arch corresponding to variant.  */
  2591.     enum bfd_architecture arch;

  2592.     /* bfd_arch_info.mach corresponding to variant.  */
  2593.     unsigned long mach;

  2594.     /* Target description for this variant.  */
  2595.     struct target_desc **tdesc;
  2596.   };

  2597. static struct variant variants[] =
  2598. {
  2599.   {"powerpc", "PowerPC user-level", bfd_arch_powerpc,
  2600.    bfd_mach_ppc, &tdesc_powerpc_altivec32},
  2601.   {"power", "POWER user-level", bfd_arch_rs6000,
  2602.    bfd_mach_rs6k, &tdesc_rs6000},
  2603.   {"403", "IBM PowerPC 403", bfd_arch_powerpc,
  2604.    bfd_mach_ppc_403, &tdesc_powerpc_403},
  2605.   {"405", "IBM PowerPC 405", bfd_arch_powerpc,
  2606.    bfd_mach_ppc_405, &tdesc_powerpc_405},
  2607.   {"601", "Motorola PowerPC 601", bfd_arch_powerpc,
  2608.    bfd_mach_ppc_601, &tdesc_powerpc_601},
  2609.   {"602", "Motorola PowerPC 602", bfd_arch_powerpc,
  2610.    bfd_mach_ppc_602, &tdesc_powerpc_602},
  2611.   {"603", "Motorola/IBM PowerPC 603 or 603e", bfd_arch_powerpc,
  2612.    bfd_mach_ppc_603, &tdesc_powerpc_603},
  2613.   {"604", "Motorola PowerPC 604 or 604e", bfd_arch_powerpc,
  2614.    604, &tdesc_powerpc_604},
  2615.   {"403GC", "IBM PowerPC 403GC", bfd_arch_powerpc,
  2616.    bfd_mach_ppc_403gc, &tdesc_powerpc_403gc},
  2617.   {"505", "Motorola PowerPC 505", bfd_arch_powerpc,
  2618.    bfd_mach_ppc_505, &tdesc_powerpc_505},
  2619.   {"860", "Motorola PowerPC 860 or 850", bfd_arch_powerpc,
  2620.    bfd_mach_ppc_860, &tdesc_powerpc_860},
  2621.   {"750", "Motorola/IBM PowerPC 750 or 740", bfd_arch_powerpc,
  2622.    bfd_mach_ppc_750, &tdesc_powerpc_750},
  2623.   {"7400", "Motorola/IBM PowerPC 7400 (G4)", bfd_arch_powerpc,
  2624.    bfd_mach_ppc_7400, &tdesc_powerpc_7400},
  2625.   {"e500", "Motorola PowerPC e500", bfd_arch_powerpc,
  2626.    bfd_mach_ppc_e500, &tdesc_powerpc_e500},

  2627.   /* 64-bit */
  2628.   {"powerpc64", "PowerPC 64-bit user-level", bfd_arch_powerpc,
  2629.    bfd_mach_ppc64, &tdesc_powerpc_altivec64},
  2630.   {"620", "Motorola PowerPC 620", bfd_arch_powerpc,
  2631.    bfd_mach_ppc_620, &tdesc_powerpc_64},
  2632.   {"630", "Motorola PowerPC 630", bfd_arch_powerpc,
  2633.    bfd_mach_ppc_630, &tdesc_powerpc_64},
  2634.   {"a35", "PowerPC A35", bfd_arch_powerpc,
  2635.    bfd_mach_ppc_a35, &tdesc_powerpc_64},
  2636.   {"rs64ii", "PowerPC rs64ii", bfd_arch_powerpc,
  2637.    bfd_mach_ppc_rs64ii, &tdesc_powerpc_64},
  2638.   {"rs64iii", "PowerPC rs64iii", bfd_arch_powerpc,
  2639.    bfd_mach_ppc_rs64iii, &tdesc_powerpc_64},

  2640.   /* FIXME: I haven't checked the register sets of the following.  */
  2641.   {"rs1", "IBM POWER RS1", bfd_arch_rs6000,
  2642.    bfd_mach_rs6k_rs1, &tdesc_rs6000},
  2643.   {"rsc", "IBM POWER RSC", bfd_arch_rs6000,
  2644.    bfd_mach_rs6k_rsc, &tdesc_rs6000},
  2645.   {"rs2", "IBM POWER RS2", bfd_arch_rs6000,
  2646.    bfd_mach_rs6k_rs2, &tdesc_rs6000},

  2647.   {0, 0, 0, 0, 0}
  2648. };

  2649. /* Return the variant corresponding to architecture ARCH and machine number
  2650.    MACH.  If no such variant exists, return null.  */

  2651. static const struct variant *
  2652. find_variant_by_arch (enum bfd_architecture arch, unsigned long mach)
  2653. {
  2654.   const struct variant *v;

  2655.   for (v = variants; v->name; v++)
  2656.     if (arch == v->arch && mach == v->mach)
  2657.       return v;

  2658.   return NULL;
  2659. }

  2660. static int
  2661. gdb_print_insn_powerpc (bfd_vma memaddr, disassemble_info *info)
  2662. {
  2663.   if (info->endian == BFD_ENDIAN_BIG)
  2664.     return print_insn_big_powerpc (memaddr, info);
  2665.   else
  2666.     return print_insn_little_powerpc (memaddr, info);
  2667. }

  2668. static CORE_ADDR
  2669. rs6000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  2670. {
  2671.   return frame_unwind_register_unsigned (next_frame,
  2672.                                          gdbarch_pc_regnum (gdbarch));
  2673. }

  2674. static struct frame_id
  2675. rs6000_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  2676. {
  2677.   return frame_id_build (get_frame_register_unsigned
  2678.                           (this_frame, gdbarch_sp_regnum (gdbarch)),
  2679.                          get_frame_pc (this_frame));
  2680. }

  2681. struct rs6000_frame_cache
  2682. {
  2683.   CORE_ADDR base;
  2684.   CORE_ADDR initial_sp;
  2685.   struct trad_frame_saved_reg *saved_regs;
  2686. };

  2687. static struct rs6000_frame_cache *
  2688. rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
  2689. {
  2690.   struct rs6000_frame_cache *cache;
  2691.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2692.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  2693.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2694.   struct rs6000_framedata fdata;
  2695.   int wordsize = tdep->wordsize;
  2696.   CORE_ADDR func, pc;

  2697.   if ((*this_cache) != NULL)
  2698.     return (*this_cache);
  2699.   cache = FRAME_OBSTACK_ZALLOC (struct rs6000_frame_cache);
  2700.   (*this_cache) = cache;
  2701.   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);

  2702.   func = get_frame_func (this_frame);
  2703.   pc = get_frame_pc (this_frame);
  2704.   skip_prologue (gdbarch, func, pc, &fdata);

  2705.   /* Figure out the parent's stack pointer.  */

  2706.   /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
  2707.      address of the current frame.  Things might be easier if the
  2708.      ->frame pointed to the outer-most address of the frame.  In
  2709.      the mean time, the address of the prev frame is used as the
  2710.      base address of this frame.  */
  2711.   cache->base = get_frame_register_unsigned
  2712.                 (this_frame, gdbarch_sp_regnum (gdbarch));

  2713.   /* If the function appears to be frameless, check a couple of likely
  2714.      indicators that we have simply failed to find the frame setup.
  2715.      Two common cases of this are missing symbols (i.e.
  2716.      get_frame_func returns the wrong address or 0), and assembly
  2717.      stubs which have a fast exit path but set up a frame on the slow
  2718.      path.

  2719.      If the LR appears to return to this function, then presume that
  2720.      we have an ABI compliant frame that we failed to find.  */
  2721.   if (fdata.frameless && fdata.lr_offset == 0)
  2722.     {
  2723.       CORE_ADDR saved_lr;
  2724.       int make_frame = 0;

  2725.       saved_lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum);
  2726.       if (func == 0 && saved_lr == pc)
  2727.         make_frame = 1;
  2728.       else if (func != 0)
  2729.         {
  2730.           CORE_ADDR saved_func = get_pc_function_start (saved_lr);
  2731.           if (func == saved_func)
  2732.             make_frame = 1;
  2733.         }

  2734.       if (make_frame)
  2735.         {
  2736.           fdata.frameless = 0;
  2737.           fdata.lr_offset = tdep->lr_frame_offset;
  2738.         }
  2739.     }

  2740.   if (!fdata.frameless)
  2741.     {
  2742.       /* Frameless really means stackless.  */
  2743.       LONGEST backchain;

  2744.       if (safe_read_memory_integer (cache->base, wordsize,
  2745.                                     byte_order, &backchain))
  2746.         cache->base = (CORE_ADDR) backchain;
  2747.     }

  2748.   trad_frame_set_value (cache->saved_regs,
  2749.                         gdbarch_sp_regnum (gdbarch), cache->base);

  2750.   /* if != -1, fdata.saved_fpr is the smallest number of saved_fpr.
  2751.      All fpr's from saved_fpr to fp31 are saved.  */

  2752.   if (fdata.saved_fpr >= 0)
  2753.     {
  2754.       int i;
  2755.       CORE_ADDR fpr_addr = cache->base + fdata.fpr_offset;

  2756.       /* If skip_prologue says floating-point registers were saved,
  2757.          but the current architecture has no floating-point registers,
  2758.          then that's strange.  But we have no indices to even record
  2759.          the addresses under, so we just ignore it.  */
  2760.       if (ppc_floating_point_unit_p (gdbarch))
  2761.         for (i = fdata.saved_fpr; i < ppc_num_fprs; i++)
  2762.           {
  2763.             cache->saved_regs[tdep->ppc_fp0_regnum + i].addr = fpr_addr;
  2764.             fpr_addr += 8;
  2765.           }
  2766.     }

  2767.   /* if != -1, fdata.saved_gpr is the smallest number of saved_gpr.
  2768.      All gpr's from saved_gpr to gpr31 are saved (except during the
  2769.      prologue).  */

  2770.   if (fdata.saved_gpr >= 0)
  2771.     {
  2772.       int i;
  2773.       CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset;
  2774.       for (i = fdata.saved_gpr; i < ppc_num_gprs; i++)
  2775.         {
  2776.           if (fdata.gpr_mask & (1U << i))
  2777.             cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
  2778.           gpr_addr += wordsize;
  2779.         }
  2780.     }

  2781.   /* if != -1, fdata.saved_vr is the smallest number of saved_vr.
  2782.      All vr's from saved_vr to vr31 are saved.  */
  2783.   if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
  2784.     {
  2785.       if (fdata.saved_vr >= 0)
  2786.         {
  2787.           int i;
  2788.           CORE_ADDR vr_addr = cache->base + fdata.vr_offset;
  2789.           for (i = fdata.saved_vr; i < 32; i++)
  2790.             {
  2791.               cache->saved_regs[tdep->ppc_vr0_regnum + i].addr = vr_addr;
  2792.               vr_addr += register_size (gdbarch, tdep->ppc_vr0_regnum);
  2793.             }
  2794.         }
  2795.     }

  2796.   /* if != -1, fdata.saved_ev is the smallest number of saved_ev.
  2797.      All vr's from saved_ev to ev31 are saved. ?????  */
  2798.   if (tdep->ppc_ev0_regnum != -1)
  2799.     {
  2800.       if (fdata.saved_ev >= 0)
  2801.         {
  2802.           int i;
  2803.           CORE_ADDR ev_addr = cache->base + fdata.ev_offset;
  2804.           CORE_ADDR off = (byte_order == BFD_ENDIAN_BIG ? 4 : 0);

  2805.           for (i = fdata.saved_ev; i < ppc_num_gprs; i++)
  2806.             {
  2807.               cache->saved_regs[tdep->ppc_ev0_regnum + i].addr = ev_addr;
  2808.               cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = ev_addr + off;
  2809.               ev_addr += register_size (gdbarch, tdep->ppc_ev0_regnum);
  2810.             }
  2811.         }
  2812.     }

  2813.   /* If != 0, fdata.cr_offset is the offset from the frame that
  2814.      holds the CR.  */
  2815.   if (fdata.cr_offset != 0)
  2816.     cache->saved_regs[tdep->ppc_cr_regnum].addr
  2817.       = cache->base + fdata.cr_offset;

  2818.   /* If != 0, fdata.lr_offset is the offset from the frame that
  2819.      holds the LR.  */
  2820.   if (fdata.lr_offset != 0)
  2821.     cache->saved_regs[tdep->ppc_lr_regnum].addr
  2822.       = cache->base + fdata.lr_offset;
  2823.   else if (fdata.lr_register != -1)
  2824.     cache->saved_regs[tdep->ppc_lr_regnum].realreg = fdata.lr_register;
  2825.   /* The PC is found in the link register.  */
  2826.   cache->saved_regs[gdbarch_pc_regnum (gdbarch)] =
  2827.     cache->saved_regs[tdep->ppc_lr_regnum];

  2828.   /* If != 0, fdata.vrsave_offset is the offset from the frame that
  2829.      holds the VRSAVE.  */
  2830.   if (fdata.vrsave_offset != 0)
  2831.     cache->saved_regs[tdep->ppc_vrsave_regnum].addr
  2832.       = cache->base + fdata.vrsave_offset;

  2833.   if (fdata.alloca_reg < 0)
  2834.     /* If no alloca register used, then fi->frame is the value of the
  2835.        %sp for this frame, and it is good enough.  */
  2836.     cache->initial_sp
  2837.       = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
  2838.   else
  2839.     cache->initial_sp
  2840.       = get_frame_register_unsigned (this_frame, fdata.alloca_reg);

  2841.   return cache;
  2842. }

  2843. static void
  2844. rs6000_frame_this_id (struct frame_info *this_frame, void **this_cache,
  2845.                       struct frame_id *this_id)
  2846. {
  2847.   struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
  2848.                                                         this_cache);
  2849.   /* This marks the outermost frame.  */
  2850.   if (info->base == 0)
  2851.     return;

  2852.   (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
  2853. }

  2854. static struct value *
  2855. rs6000_frame_prev_register (struct frame_info *this_frame,
  2856.                             void **this_cache, int regnum)
  2857. {
  2858.   struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
  2859.                                                         this_cache);
  2860.   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  2861. }

  2862. static const struct frame_unwind rs6000_frame_unwind =
  2863. {
  2864.   NORMAL_FRAME,
  2865.   default_frame_unwind_stop_reason,
  2866.   rs6000_frame_this_id,
  2867.   rs6000_frame_prev_register,
  2868.   NULL,
  2869.   default_frame_sniffer
  2870. };


  2871. static CORE_ADDR
  2872. rs6000_frame_base_address (struct frame_info *this_frame, void **this_cache)
  2873. {
  2874.   struct rs6000_frame_cache *info = rs6000_frame_cache (this_frame,
  2875.                                                         this_cache);
  2876.   return info->initial_sp;
  2877. }

  2878. static const struct frame_base rs6000_frame_base = {
  2879.   &rs6000_frame_unwind,
  2880.   rs6000_frame_base_address,
  2881.   rs6000_frame_base_address,
  2882.   rs6000_frame_base_address
  2883. };

  2884. static const struct frame_base *
  2885. rs6000_frame_base_sniffer (struct frame_info *this_frame)
  2886. {
  2887.   return &rs6000_frame_base;
  2888. }

  2889. /* DWARF-2 frame support.  Used to handle the detection of
  2890.   clobbered registers during function calls.  */

  2891. static void
  2892. ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
  2893.                             struct dwarf2_frame_state_reg *reg,
  2894.                             struct frame_info *this_frame)
  2895. {
  2896.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  2897.   /* PPC32 and PPC64 ABI's are the same regarding volatile and
  2898.      non-volatile registers.  We will use the same code for both.  */

  2899.   /* Call-saved GP registers.  */
  2900.   if ((regnum >= tdep->ppc_gp0_regnum + 14
  2901.       && regnum <= tdep->ppc_gp0_regnum + 31)
  2902.       || (regnum == tdep->ppc_gp0_regnum + 1))
  2903.     reg->how = DWARF2_FRAME_REG_SAME_VALUE;

  2904.   /* Call-clobbered GP registers.  */
  2905.   if ((regnum >= tdep->ppc_gp0_regnum + 3
  2906.       && regnum <= tdep->ppc_gp0_regnum + 12)
  2907.       || (regnum == tdep->ppc_gp0_regnum))
  2908.     reg->how = DWARF2_FRAME_REG_UNDEFINED;

  2909.   /* Deal with FP registers, if supported.  */
  2910.   if (tdep->ppc_fp0_regnum >= 0)
  2911.     {
  2912.       /* Call-saved FP registers.  */
  2913.       if ((regnum >= tdep->ppc_fp0_regnum + 14
  2914.           && regnum <= tdep->ppc_fp0_regnum + 31))
  2915.         reg->how = DWARF2_FRAME_REG_SAME_VALUE;

  2916.       /* Call-clobbered FP registers.  */
  2917.       if ((regnum >= tdep->ppc_fp0_regnum
  2918.           && regnum <= tdep->ppc_fp0_regnum + 13))
  2919.         reg->how = DWARF2_FRAME_REG_UNDEFINED;
  2920.     }

  2921.   /* Deal with ALTIVEC registers, if supported.  */
  2922.   if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0)
  2923.     {
  2924.       /* Call-saved Altivec registers.  */
  2925.       if ((regnum >= tdep->ppc_vr0_regnum + 20
  2926.           && regnum <= tdep->ppc_vr0_regnum + 31)
  2927.           || regnum == tdep->ppc_vrsave_regnum)
  2928.         reg->how = DWARF2_FRAME_REG_SAME_VALUE;

  2929.       /* Call-clobbered Altivec registers.  */
  2930.       if ((regnum >= tdep->ppc_vr0_regnum
  2931.           && regnum <= tdep->ppc_vr0_regnum + 19))
  2932.         reg->how = DWARF2_FRAME_REG_UNDEFINED;
  2933.     }

  2934.   /* Handle PC register and Stack Pointer correctly.  */
  2935.   if (regnum == gdbarch_pc_regnum (gdbarch))
  2936.     reg->how = DWARF2_FRAME_REG_RA;
  2937.   else if (regnum == gdbarch_sp_regnum (gdbarch))
  2938.     reg->how = DWARF2_FRAME_REG_CFA;
  2939. }


  2940. /* Return true if a .gnu_attributes section exists in BFD and it
  2941.    indicates we are using SPE extensions OR if a .PPC.EMB.apuinfo
  2942.    section exists in BFD and it indicates that SPE extensions are in
  2943.    use.  Check the .gnu.attributes section first, as the binary might be
  2944.    compiled for SPE, but not actually using SPE instructions.  */

  2945. static int
  2946. bfd_uses_spe_extensions (bfd *abfd)
  2947. {
  2948.   asection *sect;
  2949.   gdb_byte *contents = NULL;
  2950.   bfd_size_type size;
  2951.   gdb_byte *ptr;
  2952.   int success = 0;
  2953.   int vector_abi;

  2954.   if (!abfd)
  2955.     return 0;

  2956. #ifdef HAVE_ELF
  2957.   /* Using Tag_GNU_Power_ABI_Vector here is a bit of a hack, as the user
  2958.      could be using the SPE vector abi without actually using any spe
  2959.      bits whatsoever.  But it's close enough for now.  */
  2960.   vector_abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_GNU,
  2961.                                          Tag_GNU_Power_ABI_Vector);
  2962.   if (vector_abi == 3)
  2963.     return 1;
  2964. #endif

  2965.   sect = bfd_get_section_by_name (abfd, ".PPC.EMB.apuinfo");
  2966.   if (!sect)
  2967.     return 0;

  2968.   size = bfd_get_section_size (sect);
  2969.   contents = xmalloc (size);
  2970.   if (!bfd_get_section_contents (abfd, sect, contents, 0, size))
  2971.     {
  2972.       xfree (contents);
  2973.       return 0;
  2974.     }

  2975.   /* Parse the .PPC.EMB.apuinfo section.  The layout is as follows:

  2976.      struct {
  2977.        uint32 name_len;
  2978.        uint32 data_len;
  2979.        uint32 type;
  2980.        char name[name_len rounded up to 4-byte alignment];
  2981.        char data[data_len];
  2982.      };

  2983.      Technically, there's only supposed to be one such structure in a
  2984.      given apuinfo section, but the linker is not always vigilant about
  2985.      merging apuinfo sections from input files.  Just go ahead and parse
  2986.      them all, exiting early when we discover the binary uses SPE
  2987.      insns.

  2988.      It's not specified in what endianness the information in this
  2989.      section is stored.  Assume that it's the endianness of the BFD.  */
  2990.   ptr = contents;
  2991.   while (1)
  2992.     {
  2993.       unsigned int name_len;
  2994.       unsigned int data_len;
  2995.       unsigned int type;

  2996.       /* If we can't read the first three fields, we're done.  */
  2997.       if (size < 12)
  2998.         break;

  2999.       name_len = bfd_get_32 (abfd, ptr);
  3000.       name_len = (name_len + 3) & ~3U; /* Round to 4 bytes.  */
  3001.       data_len = bfd_get_32 (abfd, ptr + 4);
  3002.       type = bfd_get_32 (abfd, ptr + 8);
  3003.       ptr += 12;

  3004.       /* The name must be "APUinfo\0".  */
  3005.       if (name_len != 8
  3006.           && strcmp ((const char *) ptr, "APUinfo") != 0)
  3007.         break;
  3008.       ptr += name_len;

  3009.       /* The type must be 2.  */
  3010.       if (type != 2)
  3011.         break;

  3012.       /* The data is stored as a series of uint32.  The upper half of
  3013.          each uint32 indicates the particular APU used and the lower
  3014.          half indicates the revision of that APU.  We just care about
  3015.          the upper half.  */

  3016.       /* Not 4-byte quantities.  */
  3017.       if (data_len & 3U)
  3018.         break;

  3019.       while (data_len)
  3020.         {
  3021.           unsigned int apuinfo = bfd_get_32 (abfd, ptr);
  3022.           unsigned int apu = apuinfo >> 16;
  3023.           ptr += 4;
  3024.           data_len -= 4;

  3025.           /* The SPE APU is 0x100; the SPEFP APU is 0x101.  Accept
  3026.              either.  */
  3027.           if (apu == 0x100 || apu == 0x101)
  3028.             {
  3029.               success = 1;
  3030.               data_len = 0;
  3031.             }
  3032.         }

  3033.       if (success)
  3034.         break;
  3035.     }

  3036.   xfree (contents);
  3037.   return success;
  3038. }

  3039. /* Initialize the current architecture based on INFO.  If possible, re-use an
  3040.    architecture from ARCHES, which is a list of architectures already created
  3041.    during this debugging session.

  3042.    Called e.g. at program startup, when reading a core file, and when reading
  3043.    a binary file.  */

  3044. static struct gdbarch *
  3045. rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  3046. {
  3047.   struct gdbarch *gdbarch;
  3048.   struct gdbarch_tdep *tdep;
  3049.   int wordsize, from_xcoff_exec, from_elf_exec;
  3050.   enum bfd_architecture arch;
  3051.   unsigned long mach;
  3052.   bfd abfd;
  3053.   enum auto_boolean soft_float_flag = powerpc_soft_float_global;
  3054.   int soft_float;
  3055.   enum powerpc_vector_abi vector_abi = powerpc_vector_abi_global;
  3056.   enum powerpc_elf_abi elf_abi = POWERPC_ELF_AUTO;
  3057.   int have_fpu = 1, have_spe = 0, have_mq = 0, have_altivec = 0, have_dfp = 0,
  3058.       have_vsx = 0;
  3059.   int tdesc_wordsize = -1;
  3060.   const struct target_desc *tdesc = info.target_desc;
  3061.   struct tdesc_arch_data *tdesc_data = NULL;
  3062.   int num_pseudoregs = 0;
  3063.   int cur_reg;

  3064.   /* INFO may refer to a binary that is not of the PowerPC architecture,
  3065.      e.g. when debugging a stand-alone SPE executable on a Cell/B.E. system.
  3066.      In this case, we must not attempt to infer properties of the (PowerPC
  3067.      side) of the target system from properties of that executable.  Trust
  3068.      the target description instead.  */
  3069.   if (info.abfd
  3070.       && bfd_get_arch (info.abfd) != bfd_arch_powerpc
  3071.       && bfd_get_arch (info.abfd) != bfd_arch_rs6000)
  3072.     info.abfd = NULL;

  3073.   from_xcoff_exec = info.abfd && info.abfd->format == bfd_object &&
  3074.     bfd_get_flavour (info.abfd) == bfd_target_xcoff_flavour;

  3075.   from_elf_exec = info.abfd && info.abfd->format == bfd_object &&
  3076.     bfd_get_flavour (info.abfd) == bfd_target_elf_flavour;

  3077.   /* Check word size.  If INFO is from a binary file, infer it from
  3078.      that, else choose a likely default.  */
  3079.   if (from_xcoff_exec)
  3080.     {
  3081.       if (bfd_xcoff_is_xcoff64 (info.abfd))
  3082.         wordsize = 8;
  3083.       else
  3084.         wordsize = 4;
  3085.     }
  3086.   else if (from_elf_exec)
  3087.     {
  3088.       if (elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
  3089.         wordsize = 8;
  3090.       else
  3091.         wordsize = 4;
  3092.     }
  3093.   else if (tdesc_has_registers (tdesc))
  3094.     wordsize = -1;
  3095.   else
  3096.     {
  3097.       if (info.bfd_arch_info != NULL && info.bfd_arch_info->bits_per_word != 0)
  3098.         wordsize = info.bfd_arch_info->bits_per_word /
  3099.           info.bfd_arch_info->bits_per_byte;
  3100.       else
  3101.         wordsize = 4;
  3102.     }

  3103.   /* Get the architecture and machine from the BFD.  */
  3104.   arch = info.bfd_arch_info->arch;
  3105.   mach = info.bfd_arch_info->mach;

  3106.   /* For e500 executables, the apuinfo section is of help here.  Such
  3107.      section contains the identifier and revision number of each
  3108.      Application-specific Processing Unit that is present on the
  3109.      chip.  The content of the section is determined by the assembler
  3110.      which looks at each instruction and determines which unit (and
  3111.      which version of it) can execute it.  Grovel through the section
  3112.      looking for relevant e500 APUs.  */

  3113.   if (bfd_uses_spe_extensions (info.abfd))
  3114.     {
  3115.       arch = info.bfd_arch_info->arch;
  3116.       mach = bfd_mach_ppc_e500;
  3117.       bfd_default_set_arch_mach (&abfd, arch, mach);
  3118.       info.bfd_arch_info = bfd_get_arch_info (&abfd);
  3119.     }

  3120.   /* Find a default target description which describes our register
  3121.      layout, if we do not already have one.  */
  3122.   if (! tdesc_has_registers (tdesc))
  3123.     {
  3124.       const struct variant *v;

  3125.       /* Choose variant.  */
  3126.       v = find_variant_by_arch (arch, mach);
  3127.       if (!v)
  3128.         return NULL;

  3129.       tdesc = *v->tdesc;
  3130.     }

  3131.   gdb_assert (tdesc_has_registers (tdesc));

  3132.   /* Check any target description for validity.  */
  3133.   if (tdesc_has_registers (tdesc))
  3134.     {
  3135.       static const char *const gprs[] = {
  3136.         "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  3137.         "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  3138.         "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  3139.         "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
  3140.       };
  3141.       const struct tdesc_feature *feature;
  3142.       int i, valid_p;
  3143.       static const char *const msr_names[] = { "msr", "ps" };
  3144.       static const char *const cr_names[] = { "cr", "cnd" };
  3145.       static const char *const ctr_names[] = { "ctr", "cnt" };

  3146.       feature = tdesc_find_feature (tdesc,
  3147.                                     "org.gnu.gdb.power.core");
  3148.       if (feature == NULL)
  3149.         return NULL;

  3150.       tdesc_data = tdesc_data_alloc ();

  3151.       valid_p = 1;
  3152.       for (i = 0; i < ppc_num_gprs; i++)
  3153.         valid_p &= tdesc_numbered_register (feature, tdesc_data, i, gprs[i]);
  3154.       valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_PC_REGNUM,
  3155.                                           "pc");
  3156.       valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_LR_REGNUM,
  3157.                                           "lr");
  3158.       valid_p &= tdesc_numbered_register (feature, tdesc_data, PPC_XER_REGNUM,
  3159.                                           "xer");

  3160.       /* Allow alternate names for these registers, to accomodate GDB's
  3161.          historic naming.  */
  3162.       valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
  3163.                                                   PPC_MSR_REGNUM, msr_names);
  3164.       valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
  3165.                                                   PPC_CR_REGNUM, cr_names);
  3166.       valid_p &= tdesc_numbered_register_choices (feature, tdesc_data,
  3167.                                                   PPC_CTR_REGNUM, ctr_names);

  3168.       if (!valid_p)
  3169.         {
  3170.           tdesc_data_cleanup (tdesc_data);
  3171.           return NULL;
  3172.         }

  3173.       have_mq = tdesc_numbered_register (feature, tdesc_data, PPC_MQ_REGNUM,
  3174.                                          "mq");

  3175.       tdesc_wordsize = tdesc_register_size (feature, "pc") / 8;
  3176.       if (wordsize == -1)
  3177.         wordsize = tdesc_wordsize;

  3178.       feature = tdesc_find_feature (tdesc,
  3179.                                     "org.gnu.gdb.power.fpu");
  3180.       if (feature != NULL)
  3181.         {
  3182.           static const char *const fprs[] = {
  3183.             "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  3184.             "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  3185.             "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  3186.             "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
  3187.           };
  3188.           valid_p = 1;
  3189.           for (i = 0; i < ppc_num_fprs; i++)
  3190.             valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3191.                                                 PPC_F0_REGNUM + i, fprs[i]);
  3192.           valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3193.                                               PPC_FPSCR_REGNUM, "fpscr");

  3194.           if (!valid_p)
  3195.             {
  3196.               tdesc_data_cleanup (tdesc_data);
  3197.               return NULL;
  3198.             }
  3199.           have_fpu = 1;
  3200.         }
  3201.       else
  3202.         have_fpu = 0;

  3203.       /* The DFP pseudo-registers will be available when there are floating
  3204.          point registers.  */
  3205.       have_dfp = have_fpu;

  3206.       feature = tdesc_find_feature (tdesc,
  3207.                                     "org.gnu.gdb.power.altivec");
  3208.       if (feature != NULL)
  3209.         {
  3210.           static const char *const vector_regs[] = {
  3211.             "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
  3212.             "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
  3213.             "vr16", "vr17", "vr18", "vr19", "vr20", "vr21", "vr22", "vr23",
  3214.             "vr24", "vr25", "vr26", "vr27", "vr28", "vr29", "vr30", "vr31"
  3215.           };

  3216.           valid_p = 1;
  3217.           for (i = 0; i < ppc_num_gprs; i++)
  3218.             valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3219.                                                 PPC_VR0_REGNUM + i,
  3220.                                                 vector_regs[i]);
  3221.           valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3222.                                               PPC_VSCR_REGNUM, "vscr");
  3223.           valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3224.                                               PPC_VRSAVE_REGNUM, "vrsave");

  3225.           if (have_spe || !valid_p)
  3226.             {
  3227.               tdesc_data_cleanup (tdesc_data);
  3228.               return NULL;
  3229.             }
  3230.           have_altivec = 1;
  3231.         }
  3232.       else
  3233.         have_altivec = 0;

  3234.       /* Check for POWER7 VSX registers support.  */
  3235.       feature = tdesc_find_feature (tdesc,
  3236.                                     "org.gnu.gdb.power.vsx");

  3237.       if (feature != NULL)
  3238.         {
  3239.           static const char *const vsx_regs[] = {
  3240.             "vs0h", "vs1h", "vs2h", "vs3h", "vs4h", "vs5h",
  3241.             "vs6h", "vs7h", "vs8h", "vs9h", "vs10h", "vs11h",
  3242.             "vs12h", "vs13h", "vs14h", "vs15h", "vs16h", "vs17h",
  3243.             "vs18h", "vs19h", "vs20h", "vs21h", "vs22h", "vs23h",
  3244.             "vs24h", "vs25h", "vs26h", "vs27h", "vs28h", "vs29h",
  3245.             "vs30h", "vs31h"
  3246.           };

  3247.           valid_p = 1;

  3248.           for (i = 0; i < ppc_num_vshrs; i++)
  3249.             valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3250.                                                 PPC_VSR0_UPPER_REGNUM + i,
  3251.                                                 vsx_regs[i]);
  3252.           if (!valid_p)
  3253.             {
  3254.               tdesc_data_cleanup (tdesc_data);
  3255.               return NULL;
  3256.             }

  3257.           have_vsx = 1;
  3258.         }
  3259.       else
  3260.         have_vsx = 0;

  3261.       /* On machines supporting the SPE APU, the general-purpose registers
  3262.          are 64 bits long.  There are SIMD vector instructions to treat them
  3263.          as pairs of floats, but the rest of the instruction set treats them
  3264.          as 32-bit registers, and only operates on their lower halves.

  3265.          In the GDB regcache, we treat their high and low halves as separate
  3266.          registers.  The low halves we present as the general-purpose
  3267.          registers, and then we have pseudo-registers that stitch together
  3268.          the upper and lower halves and present them as pseudo-registers.

  3269.          Thus, the target description is expected to supply the upper
  3270.          halves separately.  */

  3271.       feature = tdesc_find_feature (tdesc,
  3272.                                     "org.gnu.gdb.power.spe");
  3273.       if (feature != NULL)
  3274.         {
  3275.           static const char *const upper_spe[] = {
  3276.             "ev0h", "ev1h", "ev2h", "ev3h",
  3277.             "ev4h", "ev5h", "ev6h", "ev7h",
  3278.             "ev8h", "ev9h", "ev10h", "ev11h",
  3279.             "ev12h", "ev13h", "ev14h", "ev15h",
  3280.             "ev16h", "ev17h", "ev18h", "ev19h",
  3281.             "ev20h", "ev21h", "ev22h", "ev23h",
  3282.             "ev24h", "ev25h", "ev26h", "ev27h",
  3283.             "ev28h", "ev29h", "ev30h", "ev31h"
  3284.           };

  3285.           valid_p = 1;
  3286.           for (i = 0; i < ppc_num_gprs; i++)
  3287.             valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3288.                                                 PPC_SPE_UPPER_GP0_REGNUM + i,
  3289.                                                 upper_spe[i]);
  3290.           valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3291.                                               PPC_SPE_ACC_REGNUM, "acc");
  3292.           valid_p &= tdesc_numbered_register (feature, tdesc_data,
  3293.                                               PPC_SPE_FSCR_REGNUM, "spefscr");

  3294.           if (have_mq || have_fpu || !valid_p)
  3295.             {
  3296.               tdesc_data_cleanup (tdesc_data);
  3297.               return NULL;
  3298.             }
  3299.           have_spe = 1;
  3300.         }
  3301.       else
  3302.         have_spe = 0;
  3303.     }

  3304.   /* If we have a 64-bit binary on a 32-bit target, complain.  Also
  3305.      complain for a 32-bit binary on a 64-bit target; we do not yet
  3306.      support that.  For instance, the 32-bit ABI routines expect
  3307.      32-bit GPRs.

  3308.      As long as there isn't an explicit target description, we'll
  3309.      choose one based on the BFD architecture and get a word size
  3310.      matching the binary (probably powerpc:common or
  3311.      powerpc:common64).  So there is only trouble if a 64-bit target
  3312.      supplies a 64-bit description while debugging a 32-bit
  3313.      binary.  */
  3314.   if (tdesc_wordsize != -1 && tdesc_wordsize != wordsize)
  3315.     {
  3316.       tdesc_data_cleanup (tdesc_data);
  3317.       return NULL;
  3318.     }

  3319. #ifdef HAVE_ELF
  3320.   if (from_elf_exec)
  3321.     {
  3322.       switch (elf_elfheader (info.abfd)->e_flags & EF_PPC64_ABI)
  3323.         {
  3324.         case 1:
  3325.           elf_abi = POWERPC_ELF_V1;
  3326.           break;
  3327.         case 2:
  3328.           elf_abi = POWERPC_ELF_V2;
  3329.           break;
  3330.         default:
  3331.           break;
  3332.         }
  3333.     }

  3334.   if (soft_float_flag == AUTO_BOOLEAN_AUTO && from_elf_exec)
  3335.     {
  3336.       switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
  3337.                                         Tag_GNU_Power_ABI_FP))
  3338.         {
  3339.         case 1:
  3340.           soft_float_flag = AUTO_BOOLEAN_FALSE;
  3341.           break;
  3342.         case 2:
  3343.           soft_float_flag = AUTO_BOOLEAN_TRUE;
  3344.           break;
  3345.         default:
  3346.           break;
  3347.         }
  3348.     }

  3349.   if (vector_abi == POWERPC_VEC_AUTO && from_elf_exec)
  3350.     {
  3351.       switch (bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
  3352.                                         Tag_GNU_Power_ABI_Vector))
  3353.         {
  3354.         case 1:
  3355.           vector_abi = POWERPC_VEC_GENERIC;
  3356.           break;
  3357.         case 2:
  3358.           vector_abi = POWERPC_VEC_ALTIVEC;
  3359.           break;
  3360.         case 3:
  3361.           vector_abi = POWERPC_VEC_SPE;
  3362.           break;
  3363.         default:
  3364.           break;
  3365.         }
  3366.     }
  3367. #endif

  3368.   /* At this point, the only supported ELF-based 64-bit little-endian
  3369.      operating system is GNU/Linux, and this uses the ELFv2 ABI by
  3370.      default.  All other supported ELF-based operating systems use the
  3371.      ELFv1 ABI by default.  Therefore, if the ABI marker is missing,
  3372.      e.g. because we run a legacy binary, or have attached to a process
  3373.      and have not found any associated binary file, set the default
  3374.      according to this heuristic.  */
  3375.   if (elf_abi == POWERPC_ELF_AUTO)
  3376.     {
  3377.       if (wordsize == 8 && info.byte_order == BFD_ENDIAN_LITTLE)
  3378.         elf_abi = POWERPC_ELF_V2;
  3379.       else
  3380.         elf_abi = POWERPC_ELF_V1;
  3381.     }

  3382.   if (soft_float_flag == AUTO_BOOLEAN_TRUE)
  3383.     soft_float = 1;
  3384.   else if (soft_float_flag == AUTO_BOOLEAN_FALSE)
  3385.     soft_float = 0;
  3386.   else
  3387.     soft_float = !have_fpu;

  3388.   /* If we have a hard float binary or setting but no floating point
  3389.      registers, downgrade to soft float anyway.  We're still somewhat
  3390.      useful in this scenario.  */
  3391.   if (!soft_float && !have_fpu)
  3392.     soft_float = 1;

  3393.   /* Similarly for vector registers.  */
  3394.   if (vector_abi == POWERPC_VEC_ALTIVEC && !have_altivec)
  3395.     vector_abi = POWERPC_VEC_GENERIC;

  3396.   if (vector_abi == POWERPC_VEC_SPE && !have_spe)
  3397.     vector_abi = POWERPC_VEC_GENERIC;

  3398.   if (vector_abi == POWERPC_VEC_AUTO)
  3399.     {
  3400.       if (have_altivec)
  3401.         vector_abi = POWERPC_VEC_ALTIVEC;
  3402.       else if (have_spe)
  3403.         vector_abi = POWERPC_VEC_SPE;
  3404.       else
  3405.         vector_abi = POWERPC_VEC_GENERIC;
  3406.     }

  3407.   /* Do not limit the vector ABI based on available hardware, since we
  3408.      do not yet know what hardware we'll decide we have.  Yuck!  FIXME!  */

  3409.   /* Find a candidate among extant architectures.  */
  3410.   for (arches = gdbarch_list_lookup_by_info (arches, &info);
  3411.        arches != NULL;
  3412.        arches = gdbarch_list_lookup_by_info (arches->next, &info))
  3413.     {
  3414.       /* Word size in the various PowerPC bfd_arch_info structs isn't
  3415.          meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
  3416.          separate word size check.  */
  3417.       tdep = gdbarch_tdep (arches->gdbarch);
  3418.       if (tdep && tdep->elf_abi != elf_abi)
  3419.         continue;
  3420.       if (tdep && tdep->soft_float != soft_float)
  3421.         continue;
  3422.       if (tdep && tdep->vector_abi != vector_abi)
  3423.         continue;
  3424.       if (tdep && tdep->wordsize == wordsize)
  3425.         {
  3426.           if (tdesc_data != NULL)
  3427.             tdesc_data_cleanup (tdesc_data);
  3428.           return arches->gdbarch;
  3429.         }
  3430.     }

  3431.   /* None found, create a new architecture from INFO, whose bfd_arch_info
  3432.      validity depends on the source:
  3433.        - executable                useless
  3434.        - rs6000_host_arch()        good
  3435.        - core file                good
  3436.        - "set arch"                trust blindly
  3437.        - GDB startup                useless but harmless */

  3438.   tdep = XCNEW (struct gdbarch_tdep);
  3439.   tdep->wordsize = wordsize;
  3440.   tdep->elf_abi = elf_abi;
  3441.   tdep->soft_float = soft_float;
  3442.   tdep->vector_abi = vector_abi;

  3443.   gdbarch = gdbarch_alloc (&info, tdep);

  3444.   tdep->ppc_gp0_regnum = PPC_R0_REGNUM;
  3445.   tdep->ppc_toc_regnum = PPC_R0_REGNUM + 2;
  3446.   tdep->ppc_ps_regnum = PPC_MSR_REGNUM;
  3447.   tdep->ppc_cr_regnum = PPC_CR_REGNUM;
  3448.   tdep->ppc_lr_regnum = PPC_LR_REGNUM;
  3449.   tdep->ppc_ctr_regnum = PPC_CTR_REGNUM;
  3450.   tdep->ppc_xer_regnum = PPC_XER_REGNUM;
  3451.   tdep->ppc_mq_regnum = have_mq ? PPC_MQ_REGNUM : -1;

  3452.   tdep->ppc_fp0_regnum = have_fpu ? PPC_F0_REGNUM : -1;
  3453.   tdep->ppc_fpscr_regnum = have_fpu ? PPC_FPSCR_REGNUM : -1;
  3454.   tdep->ppc_vsr0_upper_regnum = have_vsx ? PPC_VSR0_UPPER_REGNUM : -1;
  3455.   tdep->ppc_vr0_regnum = have_altivec ? PPC_VR0_REGNUM : -1;
  3456.   tdep->ppc_vrsave_regnum = have_altivec ? PPC_VRSAVE_REGNUM : -1;
  3457.   tdep->ppc_ev0_upper_regnum = have_spe ? PPC_SPE_UPPER_GP0_REGNUM : -1;
  3458.   tdep->ppc_acc_regnum = have_spe ? PPC_SPE_ACC_REGNUM : -1;
  3459.   tdep->ppc_spefscr_regnum = have_spe ? PPC_SPE_FSCR_REGNUM : -1;

  3460.   set_gdbarch_pc_regnum (gdbarch, PPC_PC_REGNUM);
  3461.   set_gdbarch_sp_regnum (gdbarch, PPC_R0_REGNUM + 1);
  3462.   set_gdbarch_deprecated_fp_regnum (gdbarch, PPC_R0_REGNUM + 1);
  3463.   set_gdbarch_fp0_regnum (gdbarch, tdep->ppc_fp0_regnum);
  3464.   set_gdbarch_register_sim_regno (gdbarch, rs6000_register_sim_regno);

  3465.   /* The XML specification for PowerPC sensibly calls the MSR "msr".
  3466.      GDB traditionally called it "ps", though, so let GDB add an
  3467.      alias.  */
  3468.   set_gdbarch_ps_regnum (gdbarch, tdep->ppc_ps_regnum);

  3469.   if (wordsize == 8)
  3470.     set_gdbarch_return_value (gdbarch, ppc64_sysv_abi_return_value);
  3471.   else
  3472.     set_gdbarch_return_value (gdbarch, ppc_sysv_abi_return_value);

  3473.   /* Set lr_frame_offset.  */
  3474.   if (wordsize == 8)
  3475.     tdep->lr_frame_offset = 16;
  3476.   else
  3477.     tdep->lr_frame_offset = 4;

  3478.   if (have_spe || have_dfp || have_vsx)
  3479.     {
  3480.       set_gdbarch_pseudo_register_read (gdbarch, rs6000_pseudo_register_read);
  3481.       set_gdbarch_pseudo_register_write (gdbarch,
  3482.                                          rs6000_pseudo_register_write);
  3483.     }

  3484.   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);

  3485.   /* Select instruction printer.  */
  3486.   if (arch == bfd_arch_rs6000)
  3487.     set_gdbarch_print_insn (gdbarch, print_insn_rs6000);
  3488.   else
  3489.     set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);

  3490.   set_gdbarch_num_regs (gdbarch, PPC_NUM_REGS);

  3491.   if (have_spe)
  3492.     num_pseudoregs += 32;
  3493.   if (have_dfp)
  3494.     num_pseudoregs += 16;
  3495.   if (have_vsx)
  3496.     /* Include both VSX and Extended FP registers.  */
  3497.     num_pseudoregs += 96;

  3498.   set_gdbarch_num_pseudo_regs (gdbarch, num_pseudoregs);

  3499.   set_gdbarch_ptr_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
  3500.   set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
  3501.   set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
  3502.   set_gdbarch_long_bit (gdbarch, wordsize * TARGET_CHAR_BIT);
  3503.   set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
  3504.   set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
  3505.   set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
  3506.   set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
  3507.   set_gdbarch_char_signed (gdbarch, 0);

  3508.   set_gdbarch_frame_align (gdbarch, rs6000_frame_align);
  3509.   if (wordsize == 8)
  3510.     /* PPC64 SYSV.  */
  3511.     set_gdbarch_frame_red_zone_size (gdbarch, 288);

  3512.   set_gdbarch_convert_register_p (gdbarch, rs6000_convert_register_p);
  3513.   set_gdbarch_register_to_value (gdbarch, rs6000_register_to_value);
  3514.   set_gdbarch_value_to_register (gdbarch, rs6000_value_to_register);

  3515.   set_gdbarch_stab_reg_to_regnum (gdbarch, rs6000_stab_reg_to_regnum);
  3516.   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, rs6000_dwarf2_reg_to_regnum);

  3517.   if (wordsize == 4)
  3518.     set_gdbarch_push_dummy_call (gdbarch, ppc_sysv_abi_push_dummy_call);
  3519.   else if (wordsize == 8)
  3520.     set_gdbarch_push_dummy_call (gdbarch, ppc64_sysv_abi_push_dummy_call);

  3521.   set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue);
  3522.   set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p);
  3523.   set_gdbarch_skip_main_prologue (gdbarch, rs6000_skip_main_prologue);

  3524.   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  3525.   set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);

  3526.   /* The value of symbols of type N_SO and N_FUN maybe null when
  3527.      it shouldn't be.  */
  3528.   set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);

  3529.   /* Handles single stepping of atomic sequences.  */
  3530.   set_gdbarch_software_single_step (gdbarch, ppc_deal_with_atomic_sequence);

  3531.   /* Not sure on this.  FIXMEmgo */
  3532.   set_gdbarch_frame_args_skip (gdbarch, 8);

  3533.   /* Helpers for function argument information.  */
  3534.   set_gdbarch_fetch_pointer_argument (gdbarch, rs6000_fetch_pointer_argument);

  3535.   /* Trampoline.  */
  3536.   set_gdbarch_in_solib_return_trampoline
  3537.     (gdbarch, rs6000_in_solib_return_trampoline);
  3538.   set_gdbarch_skip_trampoline_code (gdbarch, rs6000_skip_trampoline_code);

  3539.   /* Hook in the DWARF CFI frame unwinder.  */
  3540.   dwarf2_append_unwinders (gdbarch);
  3541.   dwarf2_frame_set_adjust_regnum (gdbarch, rs6000_adjust_frame_regnum);

  3542.   /* Frame handling.  */
  3543.   dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);

  3544.   /* Setup displaced stepping.  */
  3545.   set_gdbarch_displaced_step_copy_insn (gdbarch,
  3546.                                         simple_displaced_step_copy_insn);
  3547.   set_gdbarch_displaced_step_hw_singlestep (gdbarch,
  3548.                                             ppc_displaced_step_hw_singlestep);
  3549.   set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup);
  3550.   set_gdbarch_displaced_step_free_closure (gdbarch,
  3551.                                            simple_displaced_step_free_closure);
  3552.   set_gdbarch_displaced_step_location (gdbarch,
  3553.                                        displaced_step_at_entry_point);

  3554.   set_gdbarch_max_insn_length (gdbarch, PPC_INSN_SIZE);

  3555.   /* Hook in ABI-specific overrides, if they have been registered.  */
  3556.   info.target_desc = tdesc;
  3557.   info.tdep_info = (void *) tdesc_data;
  3558.   gdbarch_init_osabi (info, gdbarch);

  3559.   switch (info.osabi)
  3560.     {
  3561.     case GDB_OSABI_LINUX:
  3562.     case GDB_OSABI_NETBSD_AOUT:
  3563.     case GDB_OSABI_NETBSD_ELF:
  3564.     case GDB_OSABI_UNKNOWN:
  3565.       set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
  3566.       frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
  3567.       set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
  3568.       frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
  3569.       break;
  3570.     default:
  3571.       set_gdbarch_believe_pcc_promotion (gdbarch, 1);

  3572.       set_gdbarch_unwind_pc (gdbarch, rs6000_unwind_pc);
  3573.       frame_unwind_append_unwinder (gdbarch, &rs6000_frame_unwind);
  3574.       set_gdbarch_dummy_id (gdbarch, rs6000_dummy_id);
  3575.       frame_base_append_sniffer (gdbarch, rs6000_frame_base_sniffer);
  3576.     }

  3577.   set_tdesc_pseudo_register_type (gdbarch, rs6000_pseudo_register_type);
  3578.   set_tdesc_pseudo_register_reggroup_p (gdbarch,
  3579.                                         rs6000_pseudo_register_reggroup_p);
  3580.   tdesc_use_registers (gdbarch, tdesc, tdesc_data);

  3581.   /* Override the normal target description method to make the SPE upper
  3582.      halves anonymous.  */
  3583.   set_gdbarch_register_name (gdbarch, rs6000_register_name);

  3584.   /* Choose register numbers for all supported pseudo-registers.  */
  3585.   tdep->ppc_ev0_regnum = -1;
  3586.   tdep->ppc_dl0_regnum = -1;
  3587.   tdep->ppc_vsr0_regnum = -1;
  3588.   tdep->ppc_efpr0_regnum = -1;

  3589.   cur_reg = gdbarch_num_regs (gdbarch);

  3590.   if (have_spe)
  3591.     {
  3592.       tdep->ppc_ev0_regnum = cur_reg;
  3593.       cur_reg += 32;
  3594.     }
  3595.   if (have_dfp)
  3596.     {
  3597.       tdep->ppc_dl0_regnum = cur_reg;
  3598.       cur_reg += 16;
  3599.     }
  3600.   if (have_vsx)
  3601.     {
  3602.       tdep->ppc_vsr0_regnum = cur_reg;
  3603.       cur_reg += 64;
  3604.       tdep->ppc_efpr0_regnum = cur_reg;
  3605.       cur_reg += 32;
  3606.     }

  3607.   gdb_assert (gdbarch_num_regs (gdbarch)
  3608.               + gdbarch_num_pseudo_regs (gdbarch) == cur_reg);

  3609.   /* Register the ravenscar_arch_ops.  */
  3610.   if (mach == bfd_mach_ppc_e500)
  3611.     register_e500_ravenscar_ops (gdbarch);
  3612.   else
  3613.     register_ppc_ravenscar_ops (gdbarch);

  3614.   return gdbarch;
  3615. }

  3616. static void
  3617. rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
  3618. {
  3619.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  3620.   if (tdep == NULL)
  3621.     return;

  3622.   /* FIXME: Dump gdbarch_tdep.  */
  3623. }

  3624. /* PowerPC-specific commands.  */

  3625. static void
  3626. set_powerpc_command (char *args, int from_tty)
  3627. {
  3628.   printf_unfiltered (_("\
  3629. \"set powerpc\" must be followed by an appropriate subcommand.\n"));
  3630.   help_list (setpowerpccmdlist, "set powerpc ", all_commands, gdb_stdout);
  3631. }

  3632. static void
  3633. show_powerpc_command (char *args, int from_tty)
  3634. {
  3635.   cmd_show_list (showpowerpccmdlist, from_tty, "");
  3636. }

  3637. static void
  3638. powerpc_set_soft_float (char *args, int from_tty,
  3639.                         struct cmd_list_element *c)
  3640. {
  3641.   struct gdbarch_info info;

  3642.   /* Update the architecture.  */
  3643.   gdbarch_info_init (&info);
  3644.   if (!gdbarch_update_p (info))
  3645.     internal_error (__FILE__, __LINE__, _("could not update architecture"));
  3646. }

  3647. static void
  3648. powerpc_set_vector_abi (char *args, int from_tty,
  3649.                         struct cmd_list_element *c)
  3650. {
  3651.   struct gdbarch_info info;
  3652.   enum powerpc_vector_abi vector_abi;

  3653.   for (vector_abi = POWERPC_VEC_AUTO;
  3654.        vector_abi != POWERPC_VEC_LAST;
  3655.        vector_abi++)
  3656.     if (strcmp (powerpc_vector_abi_string,
  3657.                 powerpc_vector_strings[vector_abi]) == 0)
  3658.       {
  3659.         powerpc_vector_abi_global = vector_abi;
  3660.         break;
  3661.       }

  3662.   if (vector_abi == POWERPC_VEC_LAST)
  3663.     internal_error (__FILE__, __LINE__, _("Invalid vector ABI accepted: %s."),
  3664.                     powerpc_vector_abi_string);

  3665.   /* Update the architecture.  */
  3666.   gdbarch_info_init (&info);
  3667.   if (!gdbarch_update_p (info))
  3668.     internal_error (__FILE__, __LINE__, _("could not update architecture"));
  3669. }

  3670. /* Show the current setting of the exact watchpoints flag.  */

  3671. static void
  3672. show_powerpc_exact_watchpoints (struct ui_file *file, int from_tty,
  3673.                                 struct cmd_list_element *c,
  3674.                                 const char *value)
  3675. {
  3676.   fprintf_filtered (file, _("Use of exact watchpoints is %s.\n"), value);
  3677. }

  3678. /* Read a PPC instruction from memory.  */

  3679. static unsigned int
  3680. read_insn (struct frame_info *frame, CORE_ADDR pc)
  3681. {
  3682.   struct gdbarch *gdbarch = get_frame_arch (frame);
  3683.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  3684.   return read_memory_unsigned_integer (pc, 4, byte_order);
  3685. }

  3686. /* Return non-zero if the instructions at PC match the series
  3687.    described in PATTERN, or zero otherwise.  PATTERN is an array of
  3688.    'struct ppc_insn_pattern' objects, terminated by an entry whose
  3689.    mask is zero.

  3690.    When the match is successful, fill INSN[i] with what PATTERN[i]
  3691.    matched.  If PATTERN[i] is optional, and the instruction wasn't
  3692.    present, set INSN[i] to 0 (which is not a valid PPC instruction).
  3693.    INSN should have as many elements as PATTERN.  Note that, if
  3694.    PATTERN contains optional instructions which aren't present in
  3695.    memory, then INSN will have holes, so INSN[i] isn't necessarily the
  3696.    i'th instruction in memory.  */

  3697. int
  3698. ppc_insns_match_pattern (struct frame_info *frame, CORE_ADDR pc,
  3699.                          struct ppc_insn_pattern *pattern,
  3700.                          unsigned int *insns)
  3701. {
  3702.   int i;
  3703.   unsigned int insn;

  3704.   for (i = 0, insn = 0; pattern[i].mask; i++)
  3705.     {
  3706.       if (insn == 0)
  3707.         insn = read_insn (frame, pc);
  3708.       insns[i] = 0;
  3709.       if ((insn & pattern[i].mask) == pattern[i].data)
  3710.         {
  3711.           insns[i] = insn;
  3712.           pc += 4;
  3713.           insn = 0;
  3714.         }
  3715.       else if (!pattern[i].optional)
  3716.         return 0;
  3717.     }

  3718.   return 1;
  3719. }

  3720. /* Return the 'd' field of the d-form instruction INSN, properly
  3721.    sign-extended.  */

  3722. CORE_ADDR
  3723. ppc_insn_d_field (unsigned int insn)
  3724. {
  3725.   return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000);
  3726. }

  3727. /* Return the 'ds' field of the ds-form instruction INSN, with the two
  3728.    zero bits concatenated at the right, and properly
  3729.    sign-extended.  */

  3730. CORE_ADDR
  3731. ppc_insn_ds_field (unsigned int insn)
  3732. {
  3733.   return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000);
  3734. }

  3735. /* Initialization code.  */

  3736. /* -Wmissing-prototypes */
  3737. extern initialize_file_ftype _initialize_rs6000_tdep;

  3738. void
  3739. _initialize_rs6000_tdep (void)
  3740. {
  3741.   gdbarch_register (bfd_arch_rs6000, rs6000_gdbarch_init, rs6000_dump_tdep);
  3742.   gdbarch_register (bfd_arch_powerpc, rs6000_gdbarch_init, rs6000_dump_tdep);

  3743.   /* Initialize the standard target descriptions.  */
  3744.   initialize_tdesc_powerpc_32 ();
  3745.   initialize_tdesc_powerpc_altivec32 ();
  3746.   initialize_tdesc_powerpc_vsx32 ();
  3747.   initialize_tdesc_powerpc_403 ();
  3748.   initialize_tdesc_powerpc_403gc ();
  3749.   initialize_tdesc_powerpc_405 ();
  3750.   initialize_tdesc_powerpc_505 ();
  3751.   initialize_tdesc_powerpc_601 ();
  3752.   initialize_tdesc_powerpc_602 ();
  3753.   initialize_tdesc_powerpc_603 ();
  3754.   initialize_tdesc_powerpc_604 ();
  3755.   initialize_tdesc_powerpc_64 ();
  3756.   initialize_tdesc_powerpc_altivec64 ();
  3757.   initialize_tdesc_powerpc_vsx64 ();
  3758.   initialize_tdesc_powerpc_7400 ();
  3759.   initialize_tdesc_powerpc_750 ();
  3760.   initialize_tdesc_powerpc_860 ();
  3761.   initialize_tdesc_powerpc_e500 ();
  3762.   initialize_tdesc_rs6000 ();

  3763.   /* Add root prefix command for all "set powerpc"/"show powerpc"
  3764.      commands.  */
  3765.   add_prefix_cmd ("powerpc", no_class, set_powerpc_command,
  3766.                   _("Various PowerPC-specific commands."),
  3767.                   &setpowerpccmdlist, "set powerpc ", 0, &setlist);

  3768.   add_prefix_cmd ("powerpc", no_class, show_powerpc_command,
  3769.                   _("Various PowerPC-specific commands."),
  3770.                   &showpowerpccmdlist, "show powerpc ", 0, &showlist);

  3771.   /* Add a command to allow the user to force the ABI.  */
  3772.   add_setshow_auto_boolean_cmd ("soft-float", class_support,
  3773.                                 &powerpc_soft_float_global,
  3774.                                 _("Set whether to use a soft-float ABI."),
  3775.                                 _("Show whether to use a soft-float ABI."),
  3776.                                 NULL,
  3777.                                 powerpc_set_soft_float, NULL,
  3778.                                 &setpowerpccmdlist, &showpowerpccmdlist);

  3779.   add_setshow_enum_cmd ("vector-abi", class_support, powerpc_vector_strings,
  3780.                         &powerpc_vector_abi_string,
  3781.                         _("Set the vector ABI."),
  3782.                         _("Show the vector ABI."),
  3783.                         NULL, powerpc_set_vector_abi, NULL,
  3784.                         &setpowerpccmdlist, &showpowerpccmdlist);

  3785.   add_setshow_boolean_cmd ("exact-watchpoints", class_support,
  3786.                            &target_exact_watchpoints,
  3787.                            _("\
  3788. Set whether to use just one debug register for watchpoints on scalars."),
  3789.                            _("\
  3790. Show whether to use just one debug register for watchpoints on scalars."),
  3791.                            _("\
  3792. If true, GDB will use only one debug register when watching a variable of\n\
  3793. scalar type, thus assuming that the variable is accessed through the address\n\
  3794. of its first byte."),
  3795.                            NULL, show_powerpc_exact_watchpoints,
  3796.                            &setpowerpccmdlist, &showpowerpccmdlist);
  3797. }