gdb/alpha-tdep.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.

  2.    Copyright (C) 1993-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 "doublest.h"
  16. #include "frame.h"
  17. #include "frame-unwind.h"
  18. #include "frame-base.h"
  19. #include "dwarf2-frame.h"
  20. #include "inferior.h"
  21. #include "symtab.h"
  22. #include "value.h"
  23. #include "gdbcmd.h"
  24. #include "gdbcore.h"
  25. #include "dis-asm.h"
  26. #include "symfile.h"
  27. #include "objfiles.h"
  28. #include "linespec.h"
  29. #include "regcache.h"
  30. #include "reggroups.h"
  31. #include "arch-utils.h"
  32. #include "osabi.h"
  33. #include "block.h"
  34. #include "infcall.h"
  35. #include "trad-frame.h"

  36. #include "elf-bfd.h"

  37. #include "alpha-tdep.h"

  38. /* Instruction decoding.  The notations for registers, immediates and
  39.    opcodes are the same as the one used in Compaq's Alpha architecture
  40.    handbook.  */

  41. #define INSN_OPCODE(insn) ((insn & 0xfc000000) >> 26)

  42. /* Memory instruction format */
  43. #define MEM_RA(insn) ((insn & 0x03e00000) >> 21)
  44. #define MEM_RB(insn) ((insn & 0x001f0000) >> 16)
  45. #define MEM_DISP(insn) \
  46.   (((insn & 0x8000) == 0) ? (insn & 0xffff) : -((-insn) & 0xffff))

  47. static const int lda_opcode = 0x08;
  48. static const int stq_opcode = 0x2d;

  49. /* Branch instruction format */
  50. #define BR_RA(insn) MEM_RA(insn)

  51. static const int br_opcode = 0x30;
  52. static const int bne_opcode = 0x3d;

  53. /* Operate instruction format */
  54. #define OPR_FUNCTION(insn) ((insn & 0xfe0) >> 5)
  55. #define OPR_HAS_IMMEDIATE(insn) ((insn & 0x1000) == 0x1000)
  56. #define OPR_RA(insn) MEM_RA(insn)
  57. #define OPR_RC(insn) ((insn & 0x1f))
  58. #define OPR_LIT(insn) ((insn & 0x1fe000) >> 13)

  59. static const int subq_opcode = 0x10;
  60. static const int subq_function = 0x29;


  61. /* Return the name of the REGNO register.

  62.    An empty name corresponds to a register number that used to
  63.    be used for a virtual register.  That virtual register has
  64.    been removed, but the index is still reserved to maintain
  65.    compatibility with existing remote alpha targets.  */

  66. static const char *
  67. alpha_register_name (struct gdbarch *gdbarch, int regno)
  68. {
  69.   static const char * const register_names[] =
  70.   {
  71.     "v0",   "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",
  72.     "t7",   "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "fp",
  73.     "a0",   "a1",   "a2",   "a3",   "a4",   "a5",   "t8",   "t9",
  74.     "t10""t11""ra",   "t12""at",   "gp",   "sp",   "zero",
  75.     "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
  76.     "f8",   "f9",   "f10""f11""f12""f13""f14""f15",
  77.     "f16""f17""f18""f19""f20""f21""f22""f23",
  78.     "f24""f25""f26""f27""f28""f29""f30""fpcr",
  79.     "pc",   "",     "unique"
  80.   };

  81.   if (regno < 0)
  82.     return NULL;
  83.   if (regno >= ARRAY_SIZE(register_names))
  84.     return NULL;
  85.   return register_names[regno];
  86. }

  87. static int
  88. alpha_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
  89. {
  90.   return (strlen (alpha_register_name (gdbarch, regno)) == 0);
  91. }

  92. static int
  93. alpha_cannot_store_register (struct gdbarch *gdbarch, int regno)
  94. {
  95.   return (regno == ALPHA_ZERO_REGNUM
  96.           || strlen (alpha_register_name (gdbarch, regno)) == 0);
  97. }

  98. static struct type *
  99. alpha_register_type (struct gdbarch *gdbarch, int regno)
  100. {
  101.   if (regno == ALPHA_SP_REGNUM || regno == ALPHA_GP_REGNUM)
  102.     return builtin_type (gdbarch)->builtin_data_ptr;
  103.   if (regno == ALPHA_PC_REGNUM)
  104.     return builtin_type (gdbarch)->builtin_func_ptr;

  105.   /* Don't need to worry about little vs big endian until
  106.      some jerk tries to port to alpha-unicosmk.  */
  107.   if (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31)
  108.     return builtin_type (gdbarch)->builtin_double;

  109.   return builtin_type (gdbarch)->builtin_int64;
  110. }

  111. /* Is REGNUM a member of REGGROUP?  */

  112. static int
  113. alpha_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  114.                            struct reggroup *group)
  115. {
  116.   /* Filter out any registers eliminated, but whose regnum is
  117.      reserved for backward compatibility, e.g. the vfp.  */
  118.   if (gdbarch_register_name (gdbarch, regnum) == NULL
  119.       || *gdbarch_register_name (gdbarch, regnum) == '\0')
  120.     return 0;

  121.   if (group == all_reggroup)
  122.     return 1;

  123.   /* Zero should not be saved or restored.  Technically it is a general
  124.      register (just as $f31 would be a float if we represented it), but
  125.      there's no point displaying it during "info regs", so leave it out
  126.      of all groups except for "all".  */
  127.   if (regnum == ALPHA_ZERO_REGNUM)
  128.     return 0;

  129.   /* All other registers are saved and restored.  */
  130.   if (group == save_reggroup || group == restore_reggroup)
  131.     return 1;

  132.   /* All other groups are non-overlapping.  */

  133.   /* Since this is really a PALcode memory slot...  */
  134.   if (regnum == ALPHA_UNIQUE_REGNUM)
  135.     return group == system_reggroup;

  136.   /* Force the FPCR to be considered part of the floating point state.  */
  137.   if (regnum == ALPHA_FPCR_REGNUM)
  138.     return group == float_reggroup;

  139.   if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 31)
  140.     return group == float_reggroup;
  141.   else
  142.     return group == general_reggroup;
  143. }

  144. /* The following represents exactly the conversion performed by
  145.    the LDS instruction.  This applies to both single-precision
  146.    floating point and 32-bit integers.  */

  147. static void
  148. alpha_lds (struct gdbarch *gdbarch, void *out, const void *in)
  149. {
  150.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  151.   ULONGEST mem     = extract_unsigned_integer (in, 4, byte_order);
  152.   ULONGEST frac    = (mem >>  0) & 0x7fffff;
  153.   ULONGEST sign    = (mem >> 31) & 1;
  154.   ULONGEST exp_msb = (mem >> 30) & 1;
  155.   ULONGEST exp_low = (mem >> 23) & 0x7f;
  156.   ULONGEST exp, reg;

  157.   exp = (exp_msb << 10) | exp_low;
  158.   if (exp_msb)
  159.     {
  160.       if (exp_low == 0x7f)
  161.         exp = 0x7ff;
  162.     }
  163.   else
  164.     {
  165.       if (exp_low != 0x00)
  166.         exp |= 0x380;
  167.     }

  168.   reg = (sign << 63) | (exp << 52) | (frac << 29);
  169.   store_unsigned_integer (out, 8, byte_order, reg);
  170. }

  171. /* Similarly, this represents exactly the conversion performed by
  172.    the STS instruction.  */

  173. static void
  174. alpha_sts (struct gdbarch *gdbarch, void *out, const void *in)
  175. {
  176.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  177.   ULONGEST reg, mem;

  178.   reg = extract_unsigned_integer (in, 8, byte_order);
  179.   mem = ((reg >> 32) & 0xc0000000) | ((reg >> 29) & 0x3fffffff);
  180.   store_unsigned_integer (out, 4, byte_order, mem);
  181. }

  182. /* The alpha needs a conversion between register and memory format if the
  183.    register is a floating point register and memory format is float, as the
  184.    register format must be double or memory format is an integer with 4
  185.    bytes or less, as the representation of integers in floating point
  186.    registers is different.  */

  187. static int
  188. alpha_convert_register_p (struct gdbarch *gdbarch, int regno,
  189.                           struct type *type)
  190. {
  191.   return (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31
  192.           && TYPE_LENGTH (type) != 8);
  193. }

  194. static int
  195. alpha_register_to_value (struct frame_info *frame, int regnum,
  196.                          struct type *valtype, gdb_byte *out,
  197.                         int *optimizedp, int *unavailablep)
  198. {
  199.   struct gdbarch *gdbarch = get_frame_arch (frame);
  200.   gdb_byte in[MAX_REGISTER_SIZE];

  201.   /* Convert to TYPE.  */
  202.   if (!get_frame_register_bytes (frame, regnum, 0,
  203.                                  register_size (gdbarch, regnum),
  204.                                  in, optimizedp, unavailablep))
  205.     return 0;

  206.   if (TYPE_LENGTH (valtype) == 4)
  207.     {
  208.       alpha_sts (gdbarch, out, in);
  209.       *optimizedp = *unavailablep = 0;
  210.       return 1;
  211.     }

  212.   error (_("Cannot retrieve value from floating point register"));
  213. }

  214. static void
  215. alpha_value_to_register (struct frame_info *frame, int regnum,
  216.                          struct type *valtype, const gdb_byte *in)
  217. {
  218.   gdb_byte out[MAX_REGISTER_SIZE];

  219.   switch (TYPE_LENGTH (valtype))
  220.     {
  221.     case 4:
  222.       alpha_lds (get_frame_arch (frame), out, in);
  223.       break;
  224.     default:
  225.       error (_("Cannot store value in floating point register"));
  226.     }
  227.   put_frame_register (frame, regnum, out);
  228. }


  229. /* The alpha passes the first six arguments in the registers, the rest on
  230.    the stack.  The register arguments are stored in ARG_REG_BUFFER, and
  231.    then moved into the register file; this simplifies the passing of a
  232.    large struct which extends from the registers to the stack, plus avoids
  233.    three ptrace invocations per word.

  234.    We don't bother tracking which register values should go in integer
  235.    regs or fp regs; we load the same values into both.

  236.    If the called function is returning a structure, the address of the
  237.    structure to be returned is passed as a hidden first argument.  */

  238. static CORE_ADDR
  239. alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  240.                        struct regcache *regcache, CORE_ADDR bp_addr,
  241.                        int nargs, struct value **args, CORE_ADDR sp,
  242.                        int struct_return, CORE_ADDR struct_addr)
  243. {
  244.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  245.   int i;
  246.   int accumulate_size = struct_return ? 8 : 0;
  247.   struct alpha_arg
  248.     {
  249.       const gdb_byte *contents;
  250.       int len;
  251.       int offset;
  252.     };
  253.   struct alpha_arg *alpha_args
  254.     = (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
  255.   struct alpha_arg *m_arg;
  256.   gdb_byte arg_reg_buffer[ALPHA_REGISTER_SIZE * ALPHA_NUM_ARG_REGS];
  257.   int required_arg_regs;
  258.   CORE_ADDR func_addr = find_function_addr (function, NULL);

  259.   /* The ABI places the address of the called function in T12.  */
  260.   regcache_cooked_write_signed (regcache, ALPHA_T12_REGNUM, func_addr);

  261.   /* Set the return address register to point to the entry point
  262.      of the program, where a breakpoint lies in wait.  */
  263.   regcache_cooked_write_signed (regcache, ALPHA_RA_REGNUM, bp_addr);

  264.   /* Lay out the arguments in memory.  */
  265.   for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
  266.     {
  267.       struct value *arg = args[i];
  268.       struct type *arg_type = check_typedef (value_type (arg));

  269.       /* Cast argument to long if necessary as the compiler does it too.  */
  270.       switch (TYPE_CODE (arg_type))
  271.         {
  272.         case TYPE_CODE_INT:
  273.         case TYPE_CODE_BOOL:
  274.         case TYPE_CODE_CHAR:
  275.         case TYPE_CODE_RANGE:
  276.         case TYPE_CODE_ENUM:
  277.           if (TYPE_LENGTH (arg_type) == 4)
  278.             {
  279.               /* 32-bit values must be sign-extended to 64 bits
  280.                  even if the base data type is unsigned.  */
  281.               arg_type = builtin_type (gdbarch)->builtin_int32;
  282.               arg = value_cast (arg_type, arg);
  283.             }
  284.           if (TYPE_LENGTH (arg_type) < ALPHA_REGISTER_SIZE)
  285.             {
  286.               arg_type = builtin_type (gdbarch)->builtin_int64;
  287.               arg = value_cast (arg_type, arg);
  288.             }
  289.           break;

  290.         case TYPE_CODE_FLT:
  291.           /* "float" arguments loaded in registers must be passed in
  292.              register format, aka "double".  */
  293.           if (accumulate_size < sizeof (arg_reg_buffer)
  294.               && TYPE_LENGTH (arg_type) == 4)
  295.             {
  296.               arg_type = builtin_type (gdbarch)->builtin_double;
  297.               arg = value_cast (arg_type, arg);
  298.             }
  299.           /* Tru64 5.1 has a 128-bit long double, and passes this by
  300.              invisible reference.  No one else uses this data type.  */
  301.           else if (TYPE_LENGTH (arg_type) == 16)
  302.             {
  303.               /* Allocate aligned storage.  */
  304.               sp = (sp & -16) - 16;

  305.               /* Write the real data into the stack.  */
  306.               write_memory (sp, value_contents (arg), 16);

  307.               /* Construct the indirection.  */
  308.               arg_type = lookup_pointer_type (arg_type);
  309.               arg = value_from_pointer (arg_type, sp);
  310.             }
  311.           break;

  312.         case TYPE_CODE_COMPLEX:
  313.           /* ??? The ABI says that complex values are passed as two
  314.              separate scalar values.  This distinction only matters
  315.              for complex float.  However, GCC does not implement this.  */

  316.           /* Tru64 5.1 has a 128-bit long double, and passes this by
  317.              invisible reference.  */
  318.           if (TYPE_LENGTH (arg_type) == 32)
  319.             {
  320.               /* Allocate aligned storage.  */
  321.               sp = (sp & -16) - 16;

  322.               /* Write the real data into the stack.  */
  323.               write_memory (sp, value_contents (arg), 32);

  324.               /* Construct the indirection.  */
  325.               arg_type = lookup_pointer_type (arg_type);
  326.               arg = value_from_pointer (arg_type, sp);
  327.             }
  328.           break;

  329.         default:
  330.           break;
  331.         }
  332.       m_arg->len = TYPE_LENGTH (arg_type);
  333.       m_arg->offset = accumulate_size;
  334.       accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
  335.       m_arg->contents = value_contents (arg);
  336.     }

  337.   /* Determine required argument register loads, loading an argument register
  338.      is expensive as it uses three ptrace calls.  */
  339.   required_arg_regs = accumulate_size / 8;
  340.   if (required_arg_regs > ALPHA_NUM_ARG_REGS)
  341.     required_arg_regs = ALPHA_NUM_ARG_REGS;

  342.   /* Make room for the arguments on the stack.  */
  343.   if (accumulate_size < sizeof(arg_reg_buffer))
  344.     accumulate_size = 0;
  345.   else
  346.     accumulate_size -= sizeof(arg_reg_buffer);
  347.   sp -= accumulate_size;

  348.   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
  349.   sp &= ~15;

  350.   /* `Push' arguments on the stack.  */
  351.   for (i = nargs; m_arg--, --i >= 0;)
  352.     {
  353.       const gdb_byte *contents = m_arg->contents;
  354.       int offset = m_arg->offset;
  355.       int len = m_arg->len;

  356.       /* Copy the bytes destined for registers into arg_reg_buffer.  */
  357.       if (offset < sizeof(arg_reg_buffer))
  358.         {
  359.           if (offset + len <= sizeof(arg_reg_buffer))
  360.             {
  361.               memcpy (arg_reg_buffer + offset, contents, len);
  362.               continue;
  363.             }
  364.           else
  365.             {
  366.               int tlen = sizeof(arg_reg_buffer) - offset;
  367.               memcpy (arg_reg_buffer + offset, contents, tlen);
  368.               offset += tlen;
  369.               contents += tlen;
  370.               len -= tlen;
  371.             }
  372.         }

  373.       /* Everything else goes to the stack.  */
  374.       write_memory (sp + offset - sizeof(arg_reg_buffer), contents, len);
  375.     }
  376.   if (struct_return)
  377.     store_unsigned_integer (arg_reg_buffer, ALPHA_REGISTER_SIZE,
  378.                             byte_order, struct_addr);

  379.   /* Load the argument registers.  */
  380.   for (i = 0; i < required_arg_regs; i++)
  381.     {
  382.       regcache_cooked_write (regcache, ALPHA_A0_REGNUM + i,
  383.                              arg_reg_buffer + i*ALPHA_REGISTER_SIZE);
  384.       regcache_cooked_write (regcache, ALPHA_FPA0_REGNUM + i,
  385.                              arg_reg_buffer + i*ALPHA_REGISTER_SIZE);
  386.     }

  387.   /* Finally, update the stack pointer.  */
  388.   regcache_cooked_write_signed (regcache, ALPHA_SP_REGNUM, sp);

  389.   return sp;
  390. }

  391. /* Extract from REGCACHE the value about to be returned from a function
  392.    and copy it into VALBUF.  */

  393. static void
  394. alpha_extract_return_value (struct type *valtype, struct regcache *regcache,
  395.                             gdb_byte *valbuf)
  396. {
  397.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  398.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  399.   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
  400.   ULONGEST l;

  401.   switch (TYPE_CODE (valtype))
  402.     {
  403.     case TYPE_CODE_FLT:
  404.       switch (TYPE_LENGTH (valtype))
  405.         {
  406.         case 4:
  407.           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, raw_buffer);
  408.           alpha_sts (gdbarch, valbuf, raw_buffer);
  409.           break;

  410.         case 8:
  411.           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
  412.           break;

  413.         case 16:
  414.           regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
  415.           read_memory (l, valbuf, 16);
  416.           break;

  417.         default:
  418.           internal_error (__FILE__, __LINE__,
  419.                           _("unknown floating point width"));
  420.         }
  421.       break;

  422.     case TYPE_CODE_COMPLEX:
  423.       switch (TYPE_LENGTH (valtype))
  424.         {
  425.         case 8:
  426.           /* ??? This isn't correct wrt the ABI, but it's what GCC does.  */
  427.           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
  428.           break;

  429.         case 16:
  430.           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
  431.           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8);
  432.           break;

  433.         case 32:
  434.           regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
  435.           read_memory (l, valbuf, 32);
  436.           break;

  437.         default:
  438.           internal_error (__FILE__, __LINE__,
  439.                           _("unknown floating point width"));
  440.         }
  441.       break;

  442.     default:
  443.       /* Assume everything else degenerates to an integer.  */
  444.       regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
  445.       store_unsigned_integer (valbuf, TYPE_LENGTH (valtype), byte_order, l);
  446.       break;
  447.     }
  448. }

  449. /* Insert the given value into REGCACHE as if it was being
  450.    returned by a function.  */

  451. static void
  452. alpha_store_return_value (struct type *valtype, struct regcache *regcache,
  453.                           const gdb_byte *valbuf)
  454. {
  455.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  456.   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
  457.   ULONGEST l;

  458.   switch (TYPE_CODE (valtype))
  459.     {
  460.     case TYPE_CODE_FLT:
  461.       switch (TYPE_LENGTH (valtype))
  462.         {
  463.         case 4:
  464.           alpha_lds (gdbarch, raw_buffer, valbuf);
  465.           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, raw_buffer);
  466.           break;

  467.         case 8:
  468.           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
  469.           break;

  470.         case 16:
  471.           /* FIXME: 128-bit long doubles are returned like structures:
  472.              by writing into indirect storage provided by the caller
  473.              as the first argument.  */
  474.           error (_("Cannot set a 128-bit long double return value."));

  475.         default:
  476.           internal_error (__FILE__, __LINE__,
  477.                           _("unknown floating point width"));
  478.         }
  479.       break;

  480.     case TYPE_CODE_COMPLEX:
  481.       switch (TYPE_LENGTH (valtype))
  482.         {
  483.         case 8:
  484.           /* ??? This isn't correct wrt the ABI, but it's what GCC does.  */
  485.           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
  486.           break;

  487.         case 16:
  488.           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
  489.           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8);
  490.           break;

  491.         case 32:
  492.           /* FIXME: 128-bit long doubles are returned like structures:
  493.              by writing into indirect storage provided by the caller
  494.              as the first argument.  */
  495.           error (_("Cannot set a 128-bit long double return value."));

  496.         default:
  497.           internal_error (__FILE__, __LINE__,
  498.                           _("unknown floating point width"));
  499.         }
  500.       break;

  501.     default:
  502.       /* Assume everything else degenerates to an integer.  */
  503.       /* 32-bit values must be sign-extended to 64 bits
  504.          even if the base data type is unsigned.  */
  505.       if (TYPE_LENGTH (valtype) == 4)
  506.         valtype = builtin_type (gdbarch)->builtin_int32;
  507.       l = unpack_long (valtype, valbuf);
  508.       regcache_cooked_write_unsigned (regcache, ALPHA_V0_REGNUM, l);
  509.       break;
  510.     }
  511. }

  512. static enum return_value_convention
  513. alpha_return_value (struct gdbarch *gdbarch, struct value *function,
  514.                     struct type *type, struct regcache *regcache,
  515.                     gdb_byte *readbuf, const gdb_byte *writebuf)
  516. {
  517.   enum type_code code = TYPE_CODE (type);

  518.   if ((code == TYPE_CODE_STRUCT
  519.        || code == TYPE_CODE_UNION
  520.        || code == TYPE_CODE_ARRAY)
  521.       && gdbarch_tdep (gdbarch)->return_in_memory (type))
  522.     {
  523.       if (readbuf)
  524.         {
  525.           ULONGEST addr;
  526.           regcache_raw_read_unsigned (regcache, ALPHA_V0_REGNUM, &addr);
  527.           read_memory (addr, readbuf, TYPE_LENGTH (type));
  528.         }

  529.       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  530.     }

  531.   if (readbuf)
  532.     alpha_extract_return_value (type, regcache, readbuf);
  533.   if (writebuf)
  534.     alpha_store_return_value (type, regcache, writebuf);

  535.   return RETURN_VALUE_REGISTER_CONVENTION;
  536. }

  537. static int
  538. alpha_return_in_memory_always (struct type *type)
  539. {
  540.   return 1;
  541. }

  542. static const gdb_byte *
  543. alpha_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
  544. {
  545.   static const gdb_byte break_insn[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */

  546.   *len = sizeof(break_insn);
  547.   return break_insn;
  548. }


  549. /* This returns the PC of the first insn after the prologue.
  550.    If we can't find the prologue, then return 0.  */

  551. CORE_ADDR
  552. alpha_after_prologue (CORE_ADDR pc)
  553. {
  554.   struct symtab_and_line sal;
  555.   CORE_ADDR func_addr, func_end;

  556.   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  557.     return 0;

  558.   sal = find_pc_line (func_addr, 0);
  559.   if (sal.end < func_end)
  560.     return sal.end;

  561.   /* The line after the prologue is after the end of the function.  In this
  562.      case, tell the caller to find the prologue the hard way.  */
  563.   return 0;
  564. }

  565. /* Read an instruction from memory at PC, looking through breakpoints.  */

  566. unsigned int
  567. alpha_read_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
  568. {
  569.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  570.   gdb_byte buf[ALPHA_INSN_SIZE];
  571.   int status;

  572.   status = target_read_memory (pc, buf, sizeof (buf));
  573.   if (status)
  574.     memory_error (status, pc);
  575.   return extract_unsigned_integer (buf, sizeof (buf), byte_order);
  576. }

  577. /* To skip prologues, I use this predicate.  Returns either PC itself
  578.    if the code at PC does not look like a function prologue; otherwise
  579.    returns an address that (if we're lucky) follows the prologue.  If
  580.    LENIENT, then we must skip everything which is involved in setting
  581.    up the frame (it's OK to skip more, just so long as we don't skip
  582.    anything which might clobber the registers which are being saved.  */

  583. static CORE_ADDR
  584. alpha_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  585. {
  586.   unsigned long inst;
  587.   int offset;
  588.   CORE_ADDR post_prologue_pc;
  589.   gdb_byte buf[ALPHA_INSN_SIZE];

  590.   /* Silently return the unaltered pc upon memory errors.
  591.      This could happen on OSF/1 if decode_line_1 tries to skip the
  592.      prologue for quickstarted shared library functions when the
  593.      shared library is not yet mapped in.
  594.      Reading target memory is slow over serial lines, so we perform
  595.      this check only if the target has shared libraries (which all
  596.      Alpha targets do).  */
  597.   if (target_read_memory (pc, buf, sizeof (buf)))
  598.     return pc;

  599.   /* See if we can determine the end of the prologue via the symbol table.
  600.      If so, then return either PC, or the PC after the prologue, whichever
  601.      is greater.  */

  602.   post_prologue_pc = alpha_after_prologue (pc);
  603.   if (post_prologue_pc != 0)
  604.     return max (pc, post_prologue_pc);

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

  607.   /* Skip the typical prologue instructions.  These are the stack adjustment
  608.      instruction and the instructions that save registers on the stack
  609.      or in the gcc frame.  */
  610.   for (offset = 0; offset < 100; offset += ALPHA_INSN_SIZE)
  611.     {
  612.       inst = alpha_read_insn (gdbarch, pc + offset);

  613.       if ((inst & 0xffff0000) == 0x27bb0000)        /* ldah $gp,n($t12) */
  614.         continue;
  615.       if ((inst & 0xffff0000) == 0x23bd0000)        /* lda $gp,n($gp) */
  616.         continue;
  617.       if ((inst & 0xffff0000) == 0x23de0000)        /* lda $sp,n($sp) */
  618.         continue;
  619.       if ((inst & 0xffe01fff) == 0x43c0153e)        /* subq $sp,n,$sp */
  620.         continue;

  621.       if (((inst & 0xfc1f0000) == 0xb41e0000                /* stq reg,n($sp) */
  622.            || (inst & 0xfc1f0000) == 0x9c1e0000)        /* stt reg,n($sp) */
  623.           && (inst & 0x03e00000) != 0x03e00000)                /* reg != $zero */
  624.         continue;

  625.       if (inst == 0x47de040f)                        /* bis sp,sp,fp */
  626.         continue;
  627.       if (inst == 0x47fe040f)                        /* bis zero,sp,fp */
  628.         continue;

  629.       break;
  630.     }
  631.   return pc + offset;
  632. }


  633. static const int ldl_l_opcode = 0x2a;
  634. static const int ldq_l_opcode = 0x2b;
  635. static const int stl_c_opcode = 0x2e;
  636. static const int stq_c_opcode = 0x2f;

  637. /* Checks for an atomic sequence of instructions beginning with a LDL_L/LDQ_L
  638.    instruction and ending with a STL_C/STQ_C instruction.  If such a sequence
  639.    is found, attempt to step through it.  A breakpoint is placed at the end of
  640.    the sequence.  */

  641. static int
  642. alpha_deal_with_atomic_sequence (struct frame_info *frame)
  643. {
  644.   struct gdbarch *gdbarch = get_frame_arch (frame);
  645.   struct address_space *aspace = get_frame_address_space (frame);
  646.   CORE_ADDR pc = get_frame_pc (frame);
  647.   CORE_ADDR breaks[2] = {-1, -1};
  648.   CORE_ADDR loc = pc;
  649.   CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence.  */
  650.   unsigned int insn = alpha_read_insn (gdbarch, loc);
  651.   int insn_count;
  652.   int index;
  653.   int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */
  654.   const int atomic_sequence_length = 16; /* Instruction sequence length.  */
  655.   int bc_insn_count = 0; /* Conditional branch instruction count.  */

  656.   /* Assume all atomic sequences start with a LDL_L/LDQ_L instruction.  */
  657.   if (INSN_OPCODE (insn) != ldl_l_opcode
  658.       && INSN_OPCODE (insn) != ldq_l_opcode)
  659.     return 0;

  660.   /* Assume that no atomic sequence is longer than "atomic_sequence_length"
  661.      instructions.  */
  662.   for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
  663.     {
  664.       loc += ALPHA_INSN_SIZE;
  665.       insn = alpha_read_insn (gdbarch, loc);

  666.       /* Assume that there is at most one branch in the atomic
  667.          sequence.  If a branch is found, put a breakpoint in
  668.          its destination address.  */
  669.       if (INSN_OPCODE (insn) >= br_opcode)
  670.         {
  671.           int immediate = (insn & 0x001fffff) << 2;

  672.           immediate = (immediate ^ 0x400000) - 0x400000;

  673.           if (bc_insn_count >= 1)
  674.             return 0; /* More than one branch found, fallback
  675.                          to the standard single-step code.  */

  676.           breaks[1] = loc + ALPHA_INSN_SIZE + immediate;

  677.           bc_insn_count++;
  678.           last_breakpoint++;
  679.         }

  680.       if (INSN_OPCODE (insn) == stl_c_opcode
  681.           || INSN_OPCODE (insn) == stq_c_opcode)
  682.         break;
  683.     }

  684.   /* Assume that the atomic sequence ends with a STL_C/STQ_C instruction.  */
  685.   if (INSN_OPCODE (insn) != stl_c_opcode
  686.       && INSN_OPCODE (insn) != stq_c_opcode)
  687.     return 0;

  688.   closing_insn = loc;
  689.   loc += ALPHA_INSN_SIZE;

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

  692.   /* Check for duplicated breakpoints.  Check also for a breakpoint
  693.      placed (branch instruction's destination) anywhere in sequence.  */
  694.   if (last_breakpoint
  695.       && (breaks[1] == breaks[0]
  696.           || (breaks[1] >= pc && breaks[1] <= closing_insn)))
  697.     last_breakpoint = 0;

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

  701.   return 1;
  702. }


  703. /* Figure out where the longjmp will land.
  704.    We expect the first arg to be a pointer to the jmp_buf structure from
  705.    which we extract the PC (JB_PC) that we will land at.  The PC is copied
  706.    into the "pc".  This routine returns true on success.  */

  707. static int
  708. alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  709. {
  710.   struct gdbarch *gdbarch = get_frame_arch (frame);
  711.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  712.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  713.   CORE_ADDR jb_addr;
  714.   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];

  715.   jb_addr = get_frame_register_unsigned (frame, ALPHA_A0_REGNUM);

  716.   if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size),
  717.                           raw_buffer, tdep->jb_elt_size))
  718.     return 0;

  719.   *pc = extract_unsigned_integer (raw_buffer, tdep->jb_elt_size, byte_order);
  720.   return 1;
  721. }


  722. /* Frame unwinder for signal trampolines.  We use alpha tdep bits that
  723.    describe the location and shape of the sigcontext structure.  After
  724.    that, all registers are in memory, so it's easy.  */
  725. /* ??? Shouldn't we be able to do this generically, rather than with
  726.    OSABI data specific to Alpha?  */

  727. struct alpha_sigtramp_unwind_cache
  728. {
  729.   CORE_ADDR sigcontext_addr;
  730. };

  731. static struct alpha_sigtramp_unwind_cache *
  732. alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
  733.                                    void **this_prologue_cache)
  734. {
  735.   struct alpha_sigtramp_unwind_cache *info;
  736.   struct gdbarch_tdep *tdep;

  737.   if (*this_prologue_cache)
  738.     return *this_prologue_cache;

  739.   info = FRAME_OBSTACK_ZALLOC (struct alpha_sigtramp_unwind_cache);
  740.   *this_prologue_cache = info;

  741.   tdep = gdbarch_tdep (get_frame_arch (this_frame));
  742.   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);

  743.   return info;
  744. }

  745. /* Return the address of REGNUM in a sigtramp frame.  Since this is
  746.    all arithmetic, it doesn't seem worthwhile to cache it.  */

  747. static CORE_ADDR
  748. alpha_sigtramp_register_address (struct gdbarch *gdbarch,
  749.                                  CORE_ADDR sigcontext_addr, int regnum)
  750. {
  751.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  752.   if (regnum >= 0 && regnum < 32)
  753.     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
  754.   else if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 32)
  755.     return sigcontext_addr + tdep->sc_fpregs_offset + regnum * 8;
  756.   else if (regnum == ALPHA_PC_REGNUM)
  757.     return sigcontext_addr + tdep->sc_pc_offset;

  758.   return 0;
  759. }

  760. /* Given a GDB frame, determine the address of the calling function's
  761.    frame.  This will be used to create a new GDB frame struct.  */

  762. static void
  763. alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
  764.                               void **this_prologue_cache,
  765.                               struct frame_id *this_id)
  766. {
  767.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  768.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  769.   struct alpha_sigtramp_unwind_cache *info
  770.     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
  771.   CORE_ADDR stack_addr, code_addr;

  772.   /* If the OSABI couldn't locate the sigcontext, give up.  */
  773.   if (info->sigcontext_addr == 0)
  774.     return;

  775.   /* If we have dynamic signal trampolines, find their start.
  776.      If we do not, then we must assume there is a symbol record
  777.      that can provide the start address.  */
  778.   if (tdep->dynamic_sigtramp_offset)
  779.     {
  780.       int offset;
  781.       code_addr = get_frame_pc (this_frame);
  782.       offset = tdep->dynamic_sigtramp_offset (gdbarch, code_addr);
  783.       if (offset >= 0)
  784.         code_addr -= offset;
  785.       else
  786.         code_addr = 0;
  787.     }
  788.   else
  789.     code_addr = get_frame_func (this_frame);

  790.   /* The stack address is trivially read from the sigcontext.  */
  791.   stack_addr = alpha_sigtramp_register_address (gdbarch, info->sigcontext_addr,
  792.                                                 ALPHA_SP_REGNUM);
  793.   stack_addr = get_frame_memory_unsigned (this_frame, stack_addr,
  794.                                           ALPHA_REGISTER_SIZE);

  795.   *this_id = frame_id_build (stack_addr, code_addr);
  796. }

  797. /* Retrieve the value of REGNUM in FRAME.  Don't give up!  */

  798. static struct value *
  799. alpha_sigtramp_frame_prev_register (struct frame_info *this_frame,
  800.                                     void **this_prologue_cache, int regnum)
  801. {
  802.   struct alpha_sigtramp_unwind_cache *info
  803.     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
  804.   CORE_ADDR addr;

  805.   if (info->sigcontext_addr != 0)
  806.     {
  807.       /* All integer and fp registers are stored in memory.  */
  808.       addr = alpha_sigtramp_register_address (get_frame_arch (this_frame),
  809.                                               info->sigcontext_addr, regnum);
  810.       if (addr != 0)
  811.         return frame_unwind_got_memory (this_frame, regnum, addr);
  812.     }

  813.   /* This extra register may actually be in the sigcontext, but our
  814.      current description of it in alpha_sigtramp_frame_unwind_cache
  815.      doesn't include it.  Too bad.  Fall back on whatever's in the
  816.      outer frame.  */
  817.   return frame_unwind_got_register (this_frame, regnum, regnum);
  818. }

  819. static int
  820. alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
  821.                               struct frame_info *this_frame,
  822.                               void **this_prologue_cache)
  823. {
  824.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  825.   CORE_ADDR pc = get_frame_pc (this_frame);
  826.   const char *name;

  827.   /* NOTE: cagney/2004-04-30: Do not copy/clone this code.  Instead
  828.      look at tramp-frame.h and other simplier per-architecture
  829.      sigtramp unwinders.  */

  830.   /* We shouldn't even bother to try if the OSABI didn't register a
  831.      sigcontext_addr handler or pc_in_sigtramp hander.  */
  832.   if (gdbarch_tdep (gdbarch)->sigcontext_addr == NULL)
  833.     return 0;
  834.   if (gdbarch_tdep (gdbarch)->pc_in_sigtramp == NULL)
  835.     return 0;

  836.   /* Otherwise we should be in a signal frame.  */
  837.   find_pc_partial_function (pc, &name, NULL, NULL);
  838.   if (gdbarch_tdep (gdbarch)->pc_in_sigtramp (gdbarch, pc, name))
  839.     return 1;

  840.   return 0;
  841. }

  842. static const struct frame_unwind alpha_sigtramp_frame_unwind = {
  843.   SIGTRAMP_FRAME,
  844.   default_frame_unwind_stop_reason,
  845.   alpha_sigtramp_frame_this_id,
  846.   alpha_sigtramp_frame_prev_register,
  847.   NULL,
  848.   alpha_sigtramp_frame_sniffer
  849. };



  850. /* Heuristic_proc_start may hunt through the text section for a long
  851.    time across a 2400 baud serial line.  Allows the user to limit this
  852.    search.  */
  853. static int heuristic_fence_post = 0;

  854. /* Attempt to locate the start of the function containing PC.  We assume that
  855.    the previous function ends with an about_to_return insn.  Not foolproof by
  856.    any means, since gcc is happy to put the epilogue in the middle of a
  857.    function.  But we're guessing anyway...  */

  858. static CORE_ADDR
  859. alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
  860. {
  861.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  862.   CORE_ADDR last_non_nop = pc;
  863.   CORE_ADDR fence = pc - heuristic_fence_post;
  864.   CORE_ADDR orig_pc = pc;
  865.   CORE_ADDR func;
  866.   struct inferior *inf;

  867.   if (pc == 0)
  868.     return 0;

  869.   /* First see if we can find the start of the function from minimal
  870.      symbol information.  This can succeed with a binary that doesn't
  871.      have debug info, but hasn't been stripped.  */
  872.   func = get_pc_function_start (pc);
  873.   if (func)
  874.     return func;

  875.   if (heuristic_fence_post == -1
  876.       || fence < tdep->vm_min_address)
  877.     fence = tdep->vm_min_address;

  878.   /* Search back for previous return; also stop at a 0, which might be
  879.      seen for instance before the start of a code section.  Don't include
  880.      nops, since this usually indicates padding between functions.  */
  881.   for (pc -= ALPHA_INSN_SIZE; pc >= fence; pc -= ALPHA_INSN_SIZE)
  882.     {
  883.       unsigned int insn = alpha_read_insn (gdbarch, pc);
  884.       switch (insn)
  885.         {
  886.         case 0:                        /* invalid insn */
  887.         case 0x6bfa8001:        /* ret $31,($26),1 */
  888.           return last_non_nop;

  889.         case 0x2ffe0000:        /* unop: ldq_u $31,0($30) */
  890.         case 0x47ff041f:        /* nop: bis $31,$31,$31 */
  891.           break;

  892.         default:
  893.           last_non_nop = pc;
  894.           break;
  895.         }
  896.     }

  897.   inf = current_inferior ();

  898.   /* It's not clear to me why we reach this point when stopping quietly,
  899.      but with this test, at least we don't print out warnings for every
  900.      child forked (eg, on decstation).  22apr93 rich@cygnus.com.  */
  901.   if (inf->control.stop_soon == NO_STOP_QUIETLY)
  902.     {
  903.       static int blurb_printed = 0;

  904.       if (fence == tdep->vm_min_address)
  905.         warning (_("Hit beginning of text section without finding \
  906. enclosing function for address %s"), paddress (gdbarch, orig_pc));
  907.       else
  908.         warning (_("Hit heuristic-fence-post without finding \
  909. enclosing function for address %s"), paddress (gdbarch, orig_pc));

  910.       if (!blurb_printed)
  911.         {
  912.           printf_filtered (_("\
  913. This warning occurs if you are debugging a function without any symbols\n\
  914. (for example, in a stripped executable).  In that case, you may wish to\n\
  915. increase the size of the search with the `set heuristic-fence-post' command.\n\
  916. \n\
  917. Otherwise, you told GDB there was a function where there isn't one, or\n\
  918. (more likely) you have encountered a bug in GDB.\n"));
  919.           blurb_printed = 1;
  920.         }
  921.     }

  922.   return 0;
  923. }

  924. /* Fallback alpha frame unwinder.  Uses instruction scanning and knows
  925.    something about the traditional layout of alpha stack frames.  */

  926. struct alpha_heuristic_unwind_cache
  927. {
  928.   CORE_ADDR vfp;
  929.   CORE_ADDR start_pc;
  930.   struct trad_frame_saved_reg *saved_regs;
  931.   int return_reg;
  932. };

  933. /* If a probing loop sequence starts at PC, simulate it and compute
  934.    FRAME_SIZE and PC after its execution.  Otherwise, return with PC and
  935.    FRAME_SIZE unchanged.  */

  936. static void
  937. alpha_heuristic_analyze_probing_loop (struct gdbarch *gdbarch, CORE_ADDR *pc,
  938.                                       int *frame_size)
  939. {
  940.   CORE_ADDR cur_pc = *pc;
  941.   int cur_frame_size = *frame_size;
  942.   int nb_of_iterations, reg_index, reg_probe;
  943.   unsigned int insn;

  944.   /* The following pattern is recognized as a probing loop:

  945.         lda     REG_INDEX,NB_OF_ITERATIONS
  946.         lda     REG_PROBE,<immediate>(sp)

  947.      LOOP_START:
  948.         stq     zero,<immediate>(REG_PROBE)
  949.         subq    REG_INDEX,0x1,REG_INDEX
  950.         lda     REG_PROBE,<immediate>(REG_PROBE)
  951.         bne     REG_INDEX, LOOP_START

  952.         lda     sp,<immediate>(REG_PROBE)

  953.      If anything different is found, the function returns without
  954.      changing PC and FRAME_SIZE.  Otherwise, PC will point immediately
  955.      after this sequence, and FRAME_SIZE will be updated.  */

  956.   /* lda     REG_INDEX,NB_OF_ITERATIONS */

  957.   insn = alpha_read_insn (gdbarch, cur_pc);
  958.   if (INSN_OPCODE (insn) != lda_opcode)
  959.     return;
  960.   reg_index = MEM_RA (insn);
  961.   nb_of_iterations = MEM_DISP (insn);

  962.   /* lda     REG_PROBE,<immediate>(sp) */

  963.   cur_pc += ALPHA_INSN_SIZE;
  964.   insn = alpha_read_insn (gdbarch, cur_pc);
  965.   if (INSN_OPCODE (insn) != lda_opcode
  966.       || MEM_RB (insn) != ALPHA_SP_REGNUM)
  967.     return;
  968.   reg_probe = MEM_RA (insn);
  969.   cur_frame_size -= MEM_DISP (insn);

  970.   /* stq     zero,<immediate>(REG_PROBE) */

  971.   cur_pc += ALPHA_INSN_SIZE;
  972.   insn = alpha_read_insn (gdbarch, cur_pc);
  973.   if (INSN_OPCODE (insn) != stq_opcode
  974.       || MEM_RA (insn) != 0x1f
  975.       || MEM_RB (insn) != reg_probe)
  976.     return;

  977.   /* subq    REG_INDEX,0x1,REG_INDEX */

  978.   cur_pc += ALPHA_INSN_SIZE;
  979.   insn = alpha_read_insn (gdbarch, cur_pc);
  980.   if (INSN_OPCODE (insn) != subq_opcode
  981.       || !OPR_HAS_IMMEDIATE (insn)
  982.       || OPR_FUNCTION (insn) != subq_function
  983.       || OPR_LIT(insn) != 1
  984.       || OPR_RA (insn) != reg_index
  985.       || OPR_RC (insn) != reg_index)
  986.     return;

  987.   /* lda     REG_PROBE,<immediate>(REG_PROBE) */

  988.   cur_pc += ALPHA_INSN_SIZE;
  989.   insn = alpha_read_insn (gdbarch, cur_pc);
  990.   if (INSN_OPCODE (insn) != lda_opcode
  991.       || MEM_RA (insn) != reg_probe
  992.       || MEM_RB (insn) != reg_probe)
  993.     return;
  994.   cur_frame_size -= MEM_DISP (insn) * nb_of_iterations;

  995.   /* bne     REG_INDEX, LOOP_START */

  996.   cur_pc += ALPHA_INSN_SIZE;
  997.   insn = alpha_read_insn (gdbarch, cur_pc);
  998.   if (INSN_OPCODE (insn) != bne_opcode
  999.       || MEM_RA (insn) != reg_index)
  1000.     return;

  1001.   /* lda     sp,<immediate>(REG_PROBE) */

  1002.   cur_pc += ALPHA_INSN_SIZE;
  1003.   insn = alpha_read_insn (gdbarch, cur_pc);
  1004.   if (INSN_OPCODE (insn) != lda_opcode
  1005.       || MEM_RA (insn) != ALPHA_SP_REGNUM
  1006.       || MEM_RB (insn) != reg_probe)
  1007.     return;
  1008.   cur_frame_size -= MEM_DISP (insn);

  1009.   *pc = cur_pc;
  1010.   *frame_size = cur_frame_size;
  1011. }

  1012. static struct alpha_heuristic_unwind_cache *
  1013. alpha_heuristic_frame_unwind_cache (struct frame_info *this_frame,
  1014.                                     void **this_prologue_cache,
  1015.                                     CORE_ADDR start_pc)
  1016. {
  1017.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1018.   struct alpha_heuristic_unwind_cache *info;
  1019.   ULONGEST val;
  1020.   CORE_ADDR limit_pc, cur_pc;
  1021.   int frame_reg, frame_size, return_reg, reg;

  1022.   if (*this_prologue_cache)
  1023.     return *this_prologue_cache;

  1024.   info = FRAME_OBSTACK_ZALLOC (struct alpha_heuristic_unwind_cache);
  1025.   *this_prologue_cache = info;
  1026.   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);

  1027.   limit_pc = get_frame_pc (this_frame);
  1028.   if (start_pc == 0)
  1029.     start_pc = alpha_heuristic_proc_start (gdbarch, limit_pc);
  1030.   info->start_pc = start_pc;

  1031.   frame_reg = ALPHA_SP_REGNUM;
  1032.   frame_size = 0;
  1033.   return_reg = -1;

  1034.   /* If we've identified a likely place to start, do code scanning.  */
  1035.   if (start_pc != 0)
  1036.     {
  1037.       /* Limit the forward search to 50 instructions.  */
  1038.       if (start_pc + 200 < limit_pc)
  1039.         limit_pc = start_pc + 200;

  1040.       for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += ALPHA_INSN_SIZE)
  1041.         {
  1042.           unsigned int word = alpha_read_insn (gdbarch, cur_pc);

  1043.           if ((word & 0xffff0000) == 0x23de0000)        /* lda $sp,n($sp) */
  1044.             {
  1045.               if (word & 0x8000)
  1046.                 {
  1047.                   /* Consider only the first stack allocation instruction
  1048.                      to contain the static size of the frame.  */
  1049.                   if (frame_size == 0)
  1050.                     frame_size = (-word) & 0xffff;
  1051.                 }
  1052.               else
  1053.                 {
  1054.                   /* Exit loop if a positive stack adjustment is found, which
  1055.                      usually means that the stack cleanup code in the function
  1056.                      epilogue is reached.  */
  1057.                   break;
  1058.                 }
  1059.             }
  1060.           else if ((word & 0xfc1f0000) == 0xb41e0000)        /* stq reg,n($sp) */
  1061.             {
  1062.               reg = (word & 0x03e00000) >> 21;

  1063.               /* Ignore this instruction if we have already encountered
  1064.                  an instruction saving the same register earlier in the
  1065.                  function code.  The current instruction does not tell
  1066.                  us where the original value upon function entry is saved.
  1067.                  All it says is that the function we are scanning reused
  1068.                  that register for some computation of its own, and is now
  1069.                  saving its result.  */
  1070.               if (trad_frame_addr_p(info->saved_regs, reg))
  1071.                 continue;

  1072.               if (reg == 31)
  1073.                 continue;

  1074.               /* Do not compute the address where the register was saved yet,
  1075.                  because we don't know yet if the offset will need to be
  1076.                  relative to $sp or $fp (we can not compute the address
  1077.                  relative to $sp if $sp is updated during the execution of
  1078.                  the current subroutine, for instance when doing some alloca).
  1079.                  So just store the offset for the moment, and compute the
  1080.                  address later when we know whether this frame has a frame
  1081.                  pointer or not.  */
  1082.               /* Hack: temporarily add one, so that the offset is non-zero
  1083.                  and we can tell which registers have save offsets below.  */
  1084.               info->saved_regs[reg].addr = (word & 0xffff) + 1;

  1085.               /* Starting with OSF/1-3.2C, the system libraries are shipped
  1086.                  without local symbols, but they still contain procedure
  1087.                  descriptors without a symbol reference. GDB is currently
  1088.                  unable to find these procedure descriptors and uses
  1089.                  heuristic_proc_desc instead.
  1090.                  As some low level compiler support routines (__div*, __add*)
  1091.                  use a non-standard return address register, we have to
  1092.                  add some heuristics to determine the return address register,
  1093.                  or stepping over these routines will fail.
  1094.                  Usually the return address register is the first register
  1095.                  saved on the stack, but assembler optimization might
  1096.                  rearrange the register saves.
  1097.                  So we recognize only a few registers (t7, t9, ra) within
  1098.                  the procedure prologue as valid return address registers.
  1099.                  If we encounter a return instruction, we extract the
  1100.                  return address register from it.

  1101.                  FIXME: Rewriting GDB to access the procedure descriptors,
  1102.                  e.g. via the minimal symbol table, might obviate this
  1103.                  hack.  */
  1104.               if (return_reg == -1
  1105.                   && cur_pc < (start_pc + 80)
  1106.                   && (reg == ALPHA_T7_REGNUM
  1107.                       || reg == ALPHA_T9_REGNUM
  1108.                       || reg == ALPHA_RA_REGNUM))
  1109.                 return_reg = reg;
  1110.             }
  1111.           else if ((word & 0xffe0ffff) == 0x6be08001)        /* ret zero,reg,1 */
  1112.             return_reg = (word >> 16) & 0x1f;
  1113.           else if (word == 0x47de040f)                        /* bis sp,sp,fp */
  1114.             frame_reg = ALPHA_GCC_FP_REGNUM;
  1115.           else if (word == 0x47fe040f)                        /* bis zero,sp,fp */
  1116.             frame_reg = ALPHA_GCC_FP_REGNUM;

  1117.           alpha_heuristic_analyze_probing_loop (gdbarch, &cur_pc, &frame_size);
  1118.         }

  1119.       /* If we haven't found a valid return address register yet, keep
  1120.          searching in the procedure prologue.  */
  1121.       if (return_reg == -1)
  1122.         {
  1123.           while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
  1124.             {
  1125.               unsigned int word = alpha_read_insn (gdbarch, cur_pc);

  1126.               if ((word & 0xfc1f0000) == 0xb41e0000)        /* stq reg,n($sp) */
  1127.                 {
  1128.                   reg = (word & 0x03e00000) >> 21;
  1129.                   if (reg == ALPHA_T7_REGNUM
  1130.                       || reg == ALPHA_T9_REGNUM
  1131.                       || reg == ALPHA_RA_REGNUM)
  1132.                     {
  1133.                       return_reg = reg;
  1134.                       break;
  1135.                     }
  1136.                 }
  1137.               else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
  1138.                 {
  1139.                   return_reg = (word >> 16) & 0x1f;
  1140.                   break;
  1141.                 }

  1142.               cur_pc += ALPHA_INSN_SIZE;
  1143.             }
  1144.         }
  1145.     }

  1146.   /* Failing that, do default to the customary RA.  */
  1147.   if (return_reg == -1)
  1148.     return_reg = ALPHA_RA_REGNUM;
  1149.   info->return_reg = return_reg;

  1150.   val = get_frame_register_unsigned (this_frame, frame_reg);
  1151.   info->vfp = val + frame_size;

  1152.   /* Convert offsets to absolute addresses.  See above about adding
  1153.      one to the offsets to make all detected offsets non-zero.  */
  1154.   for (reg = 0; reg < ALPHA_NUM_REGS; ++reg)
  1155.     if (trad_frame_addr_p(info->saved_regs, reg))
  1156.       info->saved_regs[reg].addr += val - 1;

  1157.   /* The stack pointer of the previous frame is computed by popping
  1158.      the current stack frame.  */
  1159.   if (!trad_frame_addr_p (info->saved_regs, ALPHA_SP_REGNUM))
  1160.    trad_frame_set_value (info->saved_regs, ALPHA_SP_REGNUM, info->vfp);

  1161.   return info;
  1162. }

  1163. /* Given a GDB frame, determine the address of the calling function's
  1164.    frame.  This will be used to create a new GDB frame struct.  */

  1165. static void
  1166. alpha_heuristic_frame_this_id (struct frame_info *this_frame,
  1167.                                void **this_prologue_cache,
  1168.                                struct frame_id *this_id)
  1169. {
  1170.   struct alpha_heuristic_unwind_cache *info
  1171.     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);

  1172.   *this_id = frame_id_build (info->vfp, info->start_pc);
  1173. }

  1174. /* Retrieve the value of REGNUM in FRAME.  Don't give up!  */

  1175. static struct value *
  1176. alpha_heuristic_frame_prev_register (struct frame_info *this_frame,
  1177.                                      void **this_prologue_cache, int regnum)
  1178. {
  1179.   struct alpha_heuristic_unwind_cache *info
  1180.     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);

  1181.   /* The PC of the previous frame is stored in the link register of
  1182.      the current frame.  Frob regnum so that we pull the value from
  1183.      the correct place.  */
  1184.   if (regnum == ALPHA_PC_REGNUM)
  1185.     regnum = info->return_reg;

  1186.   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  1187. }

  1188. static const struct frame_unwind alpha_heuristic_frame_unwind = {
  1189.   NORMAL_FRAME,
  1190.   default_frame_unwind_stop_reason,
  1191.   alpha_heuristic_frame_this_id,
  1192.   alpha_heuristic_frame_prev_register,
  1193.   NULL,
  1194.   default_frame_sniffer
  1195. };

  1196. static CORE_ADDR
  1197. alpha_heuristic_frame_base_address (struct frame_info *this_frame,
  1198.                                     void **this_prologue_cache)
  1199. {
  1200.   struct alpha_heuristic_unwind_cache *info
  1201.     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);

  1202.   return info->vfp;
  1203. }

  1204. static const struct frame_base alpha_heuristic_frame_base = {
  1205.   &alpha_heuristic_frame_unwind,
  1206.   alpha_heuristic_frame_base_address,
  1207.   alpha_heuristic_frame_base_address,
  1208.   alpha_heuristic_frame_base_address
  1209. };

  1210. /* Just like reinit_frame_cache, but with the right arguments to be
  1211.    callable as an sfunc.  Used by the "set heuristic-fence-post" command.  */

  1212. static void
  1213. reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
  1214. {
  1215.   reinit_frame_cache ();
  1216. }


  1217. /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
  1218.    dummy frame.  The frame ID's base needs to match the TOS value
  1219.    saved by save_dummy_frame_tos(), and the PC match the dummy frame's
  1220.    breakpoint.  */

  1221. static struct frame_id
  1222. alpha_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  1223. {
  1224.   ULONGEST base;
  1225.   base = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
  1226.   return frame_id_build (base, get_frame_pc (this_frame));
  1227. }

  1228. static CORE_ADDR
  1229. alpha_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  1230. {
  1231.   ULONGEST pc;
  1232.   pc = frame_unwind_register_unsigned (next_frame, ALPHA_PC_REGNUM);
  1233.   return pc;
  1234. }


  1235. /* Helper routines for alpha*-nat.c files to move register sets to and
  1236.    from core files.  The UNIQUE pointer is allowed to be NULL, as most
  1237.    targets don't supply this value in their core files.  */

  1238. void
  1239. alpha_supply_int_regs (struct regcache *regcache, int regno,
  1240.                        const void *r0_r30, const void *pc, const void *unique)
  1241. {
  1242.   const gdb_byte *regs = r0_r30;
  1243.   int i;

  1244.   for (i = 0; i < 31; ++i)
  1245.     if (regno == i || regno == -1)
  1246.       regcache_raw_supply (regcache, i, regs + i * 8);

  1247.   if (regno == ALPHA_ZERO_REGNUM || regno == -1)
  1248.     {
  1249.       const gdb_byte zero[8] = { 0 };

  1250.       regcache_raw_supply (regcache, ALPHA_ZERO_REGNUM, zero);
  1251.     }

  1252.   if (regno == ALPHA_PC_REGNUM || regno == -1)
  1253.     regcache_raw_supply (regcache, ALPHA_PC_REGNUM, pc);

  1254.   if (regno == ALPHA_UNIQUE_REGNUM || regno == -1)
  1255.     regcache_raw_supply (regcache, ALPHA_UNIQUE_REGNUM, unique);
  1256. }

  1257. void
  1258. alpha_fill_int_regs (const struct regcache *regcache,
  1259.                      int regno, void *r0_r30, void *pc, void *unique)
  1260. {
  1261.   gdb_byte *regs = r0_r30;
  1262.   int i;

  1263.   for (i = 0; i < 31; ++i)
  1264.     if (regno == i || regno == -1)
  1265.       regcache_raw_collect (regcache, i, regs + i * 8);

  1266.   if (regno == ALPHA_PC_REGNUM || regno == -1)
  1267.     regcache_raw_collect (regcache, ALPHA_PC_REGNUM, pc);

  1268.   if (unique && (regno == ALPHA_UNIQUE_REGNUM || regno == -1))
  1269.     regcache_raw_collect (regcache, ALPHA_UNIQUE_REGNUM, unique);
  1270. }

  1271. void
  1272. alpha_supply_fp_regs (struct regcache *regcache, int regno,
  1273.                       const void *f0_f30, const void *fpcr)
  1274. {
  1275.   const gdb_byte *regs = f0_f30;
  1276.   int i;

  1277.   for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i)
  1278.     if (regno == i || regno == -1)
  1279.       regcache_raw_supply (regcache, i,
  1280.                            regs + (i - ALPHA_FP0_REGNUM) * 8);

  1281.   if (regno == ALPHA_FPCR_REGNUM || regno == -1)
  1282.     regcache_raw_supply (regcache, ALPHA_FPCR_REGNUM, fpcr);
  1283. }

  1284. void
  1285. alpha_fill_fp_regs (const struct regcache *regcache,
  1286.                     int regno, void *f0_f30, void *fpcr)
  1287. {
  1288.   gdb_byte *regs = f0_f30;
  1289.   int i;

  1290.   for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i)
  1291.     if (regno == i || regno == -1)
  1292.       regcache_raw_collect (regcache, i,
  1293.                             regs + (i - ALPHA_FP0_REGNUM) * 8);

  1294.   if (regno == ALPHA_FPCR_REGNUM || regno == -1)
  1295.     regcache_raw_collect (regcache, ALPHA_FPCR_REGNUM, fpcr);
  1296. }



  1297. /* Return nonzero if the G_floating register value in REG is equal to
  1298.    zero for FP control instructions.  */

  1299. static int
  1300. fp_register_zero_p (LONGEST reg)
  1301. {
  1302.   /* Check that all bits except the sign bit are zero.  */
  1303.   const LONGEST zero_mask = ((LONGEST) 1 << 63) ^ -1;

  1304.   return ((reg & zero_mask) == 0);
  1305. }

  1306. /* Return the value of the sign bit for the G_floating register
  1307.    value held in REG.  */

  1308. static int
  1309. fp_register_sign_bit (LONGEST reg)
  1310. {
  1311.   const LONGEST sign_mask = (LONGEST) 1 << 63;

  1312.   return ((reg & sign_mask) != 0);
  1313. }

  1314. /* alpha_software_single_step() is called just before we want to resume
  1315.    the inferior, if we want to single-step it but there is no hardware
  1316.    or kernel single-step support (NetBSD on Alpha, for example).  We find
  1317.    the target of the coming instruction and breakpoint it.  */

  1318. static CORE_ADDR
  1319. alpha_next_pc (struct frame_info *frame, CORE_ADDR pc)
  1320. {
  1321.   struct gdbarch *gdbarch = get_frame_arch (frame);
  1322.   unsigned int insn;
  1323.   unsigned int op;
  1324.   int regno;
  1325.   int offset;
  1326.   LONGEST rav;

  1327.   insn = alpha_read_insn (gdbarch, pc);

  1328.   /* Opcode is top 6 bits.  */
  1329.   op = (insn >> 26) & 0x3f;

  1330.   if (op == 0x1a)
  1331.     {
  1332.       /* Jump format: target PC is:
  1333.          RB & ~3  */
  1334.       return (get_frame_register_unsigned (frame, (insn >> 16) & 0x1f) & ~3);
  1335.     }

  1336.   if ((op & 0x30) == 0x30)
  1337.     {
  1338.       /* Branch format: target PC is:
  1339.          (new PC) + (4 * sext(displacement))  */
  1340.       if (op == 0x30                /* BR */
  1341.           || op == 0x34)        /* BSR */
  1342.         {
  1343. branch_taken:
  1344.           offset = (insn & 0x001fffff);
  1345.           if (offset & 0x00100000)
  1346.             offset  |= 0xffe00000;
  1347.           offset *= ALPHA_INSN_SIZE;
  1348.           return (pc + ALPHA_INSN_SIZE + offset);
  1349.         }

  1350.       /* Need to determine if branch is taken; read RA.  */
  1351.       regno = (insn >> 21) & 0x1f;
  1352.       switch (op)
  1353.         {
  1354.           case 0x31:              /* FBEQ */
  1355.           case 0x36:              /* FBGE */
  1356.           case 0x37:              /* FBGT */
  1357.           case 0x33:              /* FBLE */
  1358.           case 0x32:              /* FBLT */
  1359.           case 0x35:              /* FBNE */
  1360.             regno += gdbarch_fp0_regnum (gdbarch);
  1361.         }

  1362.       rav = get_frame_register_signed (frame, regno);

  1363.       switch (op)
  1364.         {
  1365.         case 0x38:                /* BLBC */
  1366.           if ((rav & 1) == 0)
  1367.             goto branch_taken;
  1368.           break;
  1369.         case 0x3c:                /* BLBS */
  1370.           if (rav & 1)
  1371.             goto branch_taken;
  1372.           break;
  1373.         case 0x39:                /* BEQ */
  1374.           if (rav == 0)
  1375.             goto branch_taken;
  1376.           break;
  1377.         case 0x3d:                /* BNE */
  1378.           if (rav != 0)
  1379.             goto branch_taken;
  1380.           break;
  1381.         case 0x3a:                /* BLT */
  1382.           if (rav < 0)
  1383.             goto branch_taken;
  1384.           break;
  1385.         case 0x3b:                /* BLE */
  1386.           if (rav <= 0)
  1387.             goto branch_taken;
  1388.           break;
  1389.         case 0x3f:                /* BGT */
  1390.           if (rav > 0)
  1391.             goto branch_taken;
  1392.           break;
  1393.         case 0x3e:                /* BGE */
  1394.           if (rav >= 0)
  1395.             goto branch_taken;
  1396.           break;

  1397.         /* Floating point branches.  */

  1398.         case 0x31:              /* FBEQ */
  1399.           if (fp_register_zero_p (rav))
  1400.             goto branch_taken;
  1401.           break;
  1402.         case 0x36:              /* FBGE */
  1403.           if (fp_register_sign_bit (rav) == 0 || fp_register_zero_p (rav))
  1404.             goto branch_taken;
  1405.           break;
  1406.         case 0x37:              /* FBGT */
  1407.           if (fp_register_sign_bit (rav) == 0 && ! fp_register_zero_p (rav))
  1408.             goto branch_taken;
  1409.           break;
  1410.         case 0x33:              /* FBLE */
  1411.           if (fp_register_sign_bit (rav) == 1 || fp_register_zero_p (rav))
  1412.             goto branch_taken;
  1413.           break;
  1414.         case 0x32:              /* FBLT */
  1415.           if (fp_register_sign_bit (rav) == 1 && ! fp_register_zero_p (rav))
  1416.             goto branch_taken;
  1417.           break;
  1418.         case 0x35:              /* FBNE */
  1419.           if (! fp_register_zero_p (rav))
  1420.             goto branch_taken;
  1421.           break;
  1422.         }
  1423.     }

  1424.   /* Not a branch or branch not taken; target PC is:
  1425.      pc + 4  */
  1426.   return (pc + ALPHA_INSN_SIZE);
  1427. }

  1428. int
  1429. alpha_software_single_step (struct frame_info *frame)
  1430. {
  1431.   struct gdbarch *gdbarch = get_frame_arch (frame);
  1432.   struct address_space *aspace = get_frame_address_space (frame);
  1433.   CORE_ADDR pc, next_pc;

  1434.   pc = get_frame_pc (frame);
  1435.   next_pc = alpha_next_pc (frame, pc);

  1436.   insert_single_step_breakpoint (gdbarch, aspace, next_pc);
  1437.   return 1;
  1438. }


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

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

  1444. static struct gdbarch *
  1445. alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  1446. {
  1447.   struct gdbarch_tdep *tdep;
  1448.   struct gdbarch *gdbarch;

  1449.   /* Find a candidate among extant architectures.  */
  1450.   arches = gdbarch_list_lookup_by_info (arches, &info);
  1451.   if (arches != NULL)
  1452.     return arches->gdbarch;

  1453.   tdep = xmalloc (sizeof (struct gdbarch_tdep));
  1454.   gdbarch = gdbarch_alloc (&info, tdep);

  1455.   /* Lowest text address.  This is used by heuristic_proc_start()
  1456.      to decide when to stop looking.  */
  1457.   tdep->vm_min_address = (CORE_ADDR) 0x120000000LL;

  1458.   tdep->dynamic_sigtramp_offset = NULL;
  1459.   tdep->sigcontext_addr = NULL;
  1460.   tdep->sc_pc_offset = 2 * 8;
  1461.   tdep->sc_regs_offset = 4 * 8;
  1462.   tdep->sc_fpregs_offset = tdep->sc_regs_offset + 32 * 8 + 8;

  1463.   tdep->jb_pc = -1;        /* longjmp support not enabled by default.  */

  1464.   tdep->return_in_memory = alpha_return_in_memory_always;

  1465.   /* Type sizes */
  1466.   set_gdbarch_short_bit (gdbarch, 16);
  1467.   set_gdbarch_int_bit (gdbarch, 32);
  1468.   set_gdbarch_long_bit (gdbarch, 64);
  1469.   set_gdbarch_long_long_bit (gdbarch, 64);
  1470.   set_gdbarch_float_bit (gdbarch, 32);
  1471.   set_gdbarch_double_bit (gdbarch, 64);
  1472.   set_gdbarch_long_double_bit (gdbarch, 64);
  1473.   set_gdbarch_ptr_bit (gdbarch, 64);

  1474.   /* Register info */
  1475.   set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS);
  1476.   set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM);
  1477.   set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM);
  1478.   set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM);

  1479.   set_gdbarch_register_name (gdbarch, alpha_register_name);
  1480.   set_gdbarch_register_type (gdbarch, alpha_register_type);

  1481.   set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register);
  1482.   set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register);

  1483.   set_gdbarch_convert_register_p (gdbarch, alpha_convert_register_p);
  1484.   set_gdbarch_register_to_value (gdbarch, alpha_register_to_value);
  1485.   set_gdbarch_value_to_register (gdbarch, alpha_value_to_register);

  1486.   set_gdbarch_register_reggroup_p (gdbarch, alpha_register_reggroup_p);

  1487.   /* Prologue heuristics.  */
  1488.   set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue);

  1489.   /* Disassembler.  */
  1490.   set_gdbarch_print_insn (gdbarch, print_insn_alpha);

  1491.   /* Call info.  */

  1492.   set_gdbarch_return_value (gdbarch, alpha_return_value);

  1493.   /* Settings for calling functions in the inferior.  */
  1494.   set_gdbarch_push_dummy_call (gdbarch, alpha_push_dummy_call);

  1495.   /* Methods for saving / extracting a dummy frame's ID.  */
  1496.   set_gdbarch_dummy_id (gdbarch, alpha_dummy_id);

  1497.   /* Return the unwound PC value.  */
  1498.   set_gdbarch_unwind_pc (gdbarch, alpha_unwind_pc);

  1499.   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  1500.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);

  1501.   set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc);
  1502.   set_gdbarch_decr_pc_after_break (gdbarch, ALPHA_INSN_SIZE);
  1503.   set_gdbarch_cannot_step_breakpoint (gdbarch, 1);

  1504.   /* Handles single stepping of atomic sequences.  */
  1505.   set_gdbarch_software_single_step (gdbarch, alpha_deal_with_atomic_sequence);

  1506.   /* Hook in ABI-specific overrides, if they have been registered.  */
  1507.   gdbarch_init_osabi (info, gdbarch);

  1508.   /* Now that we have tuned the configuration, set a few final things
  1509.      based on what the OS ABI has told us.  */

  1510.   if (tdep->jb_pc >= 0)
  1511.     set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target);

  1512.   frame_unwind_append_unwinder (gdbarch, &alpha_sigtramp_frame_unwind);
  1513.   frame_unwind_append_unwinder (gdbarch, &alpha_heuristic_frame_unwind);

  1514.   frame_base_set_default (gdbarch, &alpha_heuristic_frame_base);

  1515.   return gdbarch;
  1516. }

  1517. void
  1518. alpha_dwarf2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  1519. {
  1520.   dwarf2_append_unwinders (gdbarch);
  1521.   frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
  1522. }

  1523. extern initialize_file_ftype _initialize_alpha_tdep; /* -Wmissing-prototypes */

  1524. void
  1525. _initialize_alpha_tdep (void)
  1526. {
  1527.   struct cmd_list_element *c;

  1528.   gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, NULL);

  1529.   /* Let the user set the fence post for heuristic_proc_start.  */

  1530.   /* We really would like to have both "0" and "unlimited" work, but
  1531.      command.c doesn't deal with that.  So make it a var_zinteger
  1532.      because the user can always use "999999" or some such for unlimited.  */
  1533.   /* We need to throw away the frame cache when we set this, since it
  1534.      might change our ability to get backtraces.  */
  1535.   add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
  1536.                             &heuristic_fence_post, _("\
  1537. Set the distance searched for the start of a function."), _("\
  1538. Show the distance searched for the start of a function."), _("\
  1539. If you are debugging a stripped executable, GDB needs to search through the\n\
  1540. program for the start of a function.  This command sets the distance of the\n\
  1541. search.  The only need to set it is when debugging a stripped executable."),
  1542.                             reinit_frame_cache_sfunc,
  1543.                             NULL, /* FIXME: i18n: The distance searched for
  1544.                                      the start of a function is \"%d\".  */
  1545.                             &setlist, &showlist);
  1546. }