GDB (API)
/home/stan/gdb/src/gdb/alpha-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
00002 
00003    Copyright (C) 1993-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "doublest.h"
00022 #include "frame.h"
00023 #include "frame-unwind.h"
00024 #include "frame-base.h"
00025 #include "dwarf2-frame.h"
00026 #include "inferior.h"
00027 #include "symtab.h"
00028 #include "value.h"
00029 #include "gdbcmd.h"
00030 #include "gdbcore.h"
00031 #include "dis-asm.h"
00032 #include "symfile.h"
00033 #include "objfiles.h"
00034 #include "gdb_string.h"
00035 #include "linespec.h"
00036 #include "regcache.h"
00037 #include "reggroups.h"
00038 #include "arch-utils.h"
00039 #include "osabi.h"
00040 #include "block.h"
00041 #include "infcall.h"
00042 #include "trad-frame.h"
00043 
00044 #include "elf-bfd.h"
00045 
00046 #include "alpha-tdep.h"
00047 
00048 /* Instruction decoding.  The notations for registers, immediates and
00049    opcodes are the same as the one used in Compaq's Alpha architecture
00050    handbook.  */
00051 
00052 #define INSN_OPCODE(insn) ((insn & 0xfc000000) >> 26)
00053 
00054 /* Memory instruction format */
00055 #define MEM_RA(insn) ((insn & 0x03e00000) >> 21)
00056 #define MEM_RB(insn) ((insn & 0x001f0000) >> 16)
00057 #define MEM_DISP(insn) \
00058   (((insn & 0x8000) == 0) ? (insn & 0xffff) : -((-insn) & 0xffff))
00059 
00060 static const int lda_opcode = 0x08;
00061 static const int stq_opcode = 0x2d;
00062 
00063 /* Branch instruction format */
00064 #define BR_RA(insn) MEM_RA(insn)
00065 
00066 static const int br_opcode = 0x30;
00067 static const int bne_opcode = 0x3d;
00068 
00069 /* Operate instruction format */
00070 #define OPR_FUNCTION(insn) ((insn & 0xfe0) >> 5)
00071 #define OPR_HAS_IMMEDIATE(insn) ((insn & 0x1000) == 0x1000)
00072 #define OPR_RA(insn) MEM_RA(insn)
00073 #define OPR_RC(insn) ((insn & 0x1f))
00074 #define OPR_LIT(insn) ((insn & 0x1fe000) >> 13)
00075 
00076 static const int subq_opcode = 0x10;
00077 static const int subq_function = 0x29;
00078 
00079 
00080 /* Return the name of the REGNO register.
00081 
00082    An empty name corresponds to a register number that used to
00083    be used for a virtual register.  That virtual register has
00084    been removed, but the index is still reserved to maintain
00085    compatibility with existing remote alpha targets.  */
00086 
00087 static const char *
00088 alpha_register_name (struct gdbarch *gdbarch, int regno)
00089 {
00090   static const char * const register_names[] =
00091   {
00092     "v0",   "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",
00093     "t7",   "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "fp",
00094     "a0",   "a1",   "a2",   "a3",   "a4",   "a5",   "t8",   "t9",
00095     "t10",  "t11",  "ra",   "t12",  "at",   "gp",   "sp",   "zero",
00096     "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
00097     "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
00098     "f16",  "f17",  "f18",  "f19",  "f20",  "f21",  "f22",  "f23",
00099     "f24",  "f25",  "f26",  "f27",  "f28",  "f29",  "f30",  "fpcr",
00100     "pc",   "",     "unique"
00101   };
00102 
00103   if (regno < 0)
00104     return NULL;
00105   if (regno >= ARRAY_SIZE(register_names))
00106     return NULL;
00107   return register_names[regno];
00108 }
00109 
00110 static int
00111 alpha_cannot_fetch_register (struct gdbarch *gdbarch, int regno)
00112 {
00113   return (strlen (alpha_register_name (gdbarch, regno)) == 0);
00114 }
00115 
00116 static int
00117 alpha_cannot_store_register (struct gdbarch *gdbarch, int regno)
00118 {
00119   return (regno == ALPHA_ZERO_REGNUM
00120           || strlen (alpha_register_name (gdbarch, regno)) == 0);
00121 }
00122 
00123 static struct type *
00124 alpha_register_type (struct gdbarch *gdbarch, int regno)
00125 {
00126   if (regno == ALPHA_SP_REGNUM || regno == ALPHA_GP_REGNUM)
00127     return builtin_type (gdbarch)->builtin_data_ptr;
00128   if (regno == ALPHA_PC_REGNUM)
00129     return builtin_type (gdbarch)->builtin_func_ptr;
00130 
00131   /* Don't need to worry about little vs big endian until 
00132      some jerk tries to port to alpha-unicosmk.  */
00133   if (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31)
00134     return builtin_type (gdbarch)->builtin_double;
00135 
00136   return builtin_type (gdbarch)->builtin_int64;
00137 }
00138 
00139 /* Is REGNUM a member of REGGROUP?  */
00140 
00141 static int
00142 alpha_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
00143                            struct reggroup *group)
00144 {
00145   /* Filter out any registers eliminated, but whose regnum is 
00146      reserved for backward compatibility, e.g. the vfp.  */
00147   if (gdbarch_register_name (gdbarch, regnum) == NULL
00148       || *gdbarch_register_name (gdbarch, regnum) == '\0')
00149     return 0;
00150 
00151   if (group == all_reggroup)
00152     return 1;
00153 
00154   /* Zero should not be saved or restored.  Technically it is a general
00155      register (just as $f31 would be a float if we represented it), but
00156      there's no point displaying it during "info regs", so leave it out
00157      of all groups except for "all".  */
00158   if (regnum == ALPHA_ZERO_REGNUM)
00159     return 0;
00160 
00161   /* All other registers are saved and restored.  */
00162   if (group == save_reggroup || group == restore_reggroup)
00163     return 1;
00164 
00165   /* All other groups are non-overlapping.  */
00166 
00167   /* Since this is really a PALcode memory slot...  */
00168   if (regnum == ALPHA_UNIQUE_REGNUM)
00169     return group == system_reggroup;
00170 
00171   /* Force the FPCR to be considered part of the floating point state.  */
00172   if (regnum == ALPHA_FPCR_REGNUM)
00173     return group == float_reggroup;
00174 
00175   if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 31)
00176     return group == float_reggroup;
00177   else
00178     return group == general_reggroup;
00179 }
00180 
00181 /* The following represents exactly the conversion performed by
00182    the LDS instruction.  This applies to both single-precision
00183    floating point and 32-bit integers.  */
00184 
00185 static void
00186 alpha_lds (struct gdbarch *gdbarch, void *out, const void *in)
00187 {
00188   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00189   ULONGEST mem     = extract_unsigned_integer (in, 4, byte_order);
00190   ULONGEST frac    = (mem >>  0) & 0x7fffff;
00191   ULONGEST sign    = (mem >> 31) & 1;
00192   ULONGEST exp_msb = (mem >> 30) & 1;
00193   ULONGEST exp_low = (mem >> 23) & 0x7f;
00194   ULONGEST exp, reg;
00195 
00196   exp = (exp_msb << 10) | exp_low;
00197   if (exp_msb)
00198     {
00199       if (exp_low == 0x7f)
00200         exp = 0x7ff;
00201     }
00202   else
00203     {
00204       if (exp_low != 0x00)
00205         exp |= 0x380;
00206     }
00207 
00208   reg = (sign << 63) | (exp << 52) | (frac << 29);
00209   store_unsigned_integer (out, 8, byte_order, reg);
00210 }
00211 
00212 /* Similarly, this represents exactly the conversion performed by
00213    the STS instruction.  */
00214 
00215 static void
00216 alpha_sts (struct gdbarch *gdbarch, void *out, const void *in)
00217 {
00218   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00219   ULONGEST reg, mem;
00220 
00221   reg = extract_unsigned_integer (in, 8, byte_order);
00222   mem = ((reg >> 32) & 0xc0000000) | ((reg >> 29) & 0x3fffffff);
00223   store_unsigned_integer (out, 4, byte_order, mem);
00224 }
00225 
00226 /* The alpha needs a conversion between register and memory format if the
00227    register is a floating point register and memory format is float, as the
00228    register format must be double or memory format is an integer with 4
00229    bytes or less, as the representation of integers in floating point
00230    registers is different.  */
00231 
00232 static int
00233 alpha_convert_register_p (struct gdbarch *gdbarch, int regno,
00234                           struct type *type)
00235 {
00236   return (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31
00237           && TYPE_LENGTH (type) != 8);
00238 }
00239 
00240 static int
00241 alpha_register_to_value (struct frame_info *frame, int regnum,
00242                          struct type *valtype, gdb_byte *out,
00243                         int *optimizedp, int *unavailablep)
00244 {
00245   struct gdbarch *gdbarch = get_frame_arch (frame);
00246   gdb_byte in[MAX_REGISTER_SIZE];
00247 
00248   /* Convert to TYPE.  */
00249   if (!get_frame_register_bytes (frame, regnum, 0,
00250                                  register_size (gdbarch, regnum),
00251                                  in, optimizedp, unavailablep))
00252     return 0;
00253 
00254   if (TYPE_LENGTH (valtype) == 4)
00255     {
00256       alpha_sts (gdbarch, out, in);
00257       *optimizedp = *unavailablep = 0;
00258       return 1;
00259     }
00260 
00261   error (_("Cannot retrieve value from floating point register"));
00262 }
00263 
00264 static void
00265 alpha_value_to_register (struct frame_info *frame, int regnum,
00266                          struct type *valtype, const gdb_byte *in)
00267 {
00268   gdb_byte out[MAX_REGISTER_SIZE];
00269 
00270   switch (TYPE_LENGTH (valtype))
00271     {
00272     case 4:
00273       alpha_lds (get_frame_arch (frame), out, in);
00274       break;
00275     default:
00276       error (_("Cannot store value in floating point register"));
00277     }
00278   put_frame_register (frame, regnum, out);
00279 }
00280 
00281 
00282 /* The alpha passes the first six arguments in the registers, the rest on
00283    the stack.  The register arguments are stored in ARG_REG_BUFFER, and
00284    then moved into the register file; this simplifies the passing of a
00285    large struct which extends from the registers to the stack, plus avoids
00286    three ptrace invocations per word.
00287 
00288    We don't bother tracking which register values should go in integer
00289    regs or fp regs; we load the same values into both.
00290 
00291    If the called function is returning a structure, the address of the
00292    structure to be returned is passed as a hidden first argument.  */
00293 
00294 static CORE_ADDR
00295 alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00296                        struct regcache *regcache, CORE_ADDR bp_addr,
00297                        int nargs, struct value **args, CORE_ADDR sp,
00298                        int struct_return, CORE_ADDR struct_addr)
00299 {
00300   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00301   int i;
00302   int accumulate_size = struct_return ? 8 : 0;
00303   struct alpha_arg
00304     {
00305       const gdb_byte *contents;
00306       int len;
00307       int offset;
00308     };
00309   struct alpha_arg *alpha_args
00310     = (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
00311   struct alpha_arg *m_arg;
00312   gdb_byte arg_reg_buffer[ALPHA_REGISTER_SIZE * ALPHA_NUM_ARG_REGS];
00313   int required_arg_regs;
00314   CORE_ADDR func_addr = find_function_addr (function, NULL);
00315 
00316   /* The ABI places the address of the called function in T12.  */
00317   regcache_cooked_write_signed (regcache, ALPHA_T12_REGNUM, func_addr);
00318 
00319   /* Set the return address register to point to the entry point
00320      of the program, where a breakpoint lies in wait.  */
00321   regcache_cooked_write_signed (regcache, ALPHA_RA_REGNUM, bp_addr);
00322 
00323   /* Lay out the arguments in memory.  */
00324   for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
00325     {
00326       struct value *arg = args[i];
00327       struct type *arg_type = check_typedef (value_type (arg));
00328 
00329       /* Cast argument to long if necessary as the compiler does it too.  */
00330       switch (TYPE_CODE (arg_type))
00331         {
00332         case TYPE_CODE_INT:
00333         case TYPE_CODE_BOOL:
00334         case TYPE_CODE_CHAR:
00335         case TYPE_CODE_RANGE:
00336         case TYPE_CODE_ENUM:
00337           if (TYPE_LENGTH (arg_type) == 4)
00338             {
00339               /* 32-bit values must be sign-extended to 64 bits
00340                  even if the base data type is unsigned.  */
00341               arg_type = builtin_type (gdbarch)->builtin_int32;
00342               arg = value_cast (arg_type, arg);
00343             }
00344           if (TYPE_LENGTH (arg_type) < ALPHA_REGISTER_SIZE)
00345             {
00346               arg_type = builtin_type (gdbarch)->builtin_int64;
00347               arg = value_cast (arg_type, arg);
00348             }
00349           break;
00350 
00351         case TYPE_CODE_FLT:
00352           /* "float" arguments loaded in registers must be passed in
00353              register format, aka "double".  */
00354           if (accumulate_size < sizeof (arg_reg_buffer)
00355               && TYPE_LENGTH (arg_type) == 4)
00356             {
00357               arg_type = builtin_type (gdbarch)->builtin_double;
00358               arg = value_cast (arg_type, arg);
00359             }
00360           /* Tru64 5.1 has a 128-bit long double, and passes this by
00361              invisible reference.  No one else uses this data type.  */
00362           else if (TYPE_LENGTH (arg_type) == 16)
00363             {
00364               /* Allocate aligned storage.  */
00365               sp = (sp & -16) - 16;
00366 
00367               /* Write the real data into the stack.  */
00368               write_memory (sp, value_contents (arg), 16);
00369 
00370               /* Construct the indirection.  */
00371               arg_type = lookup_pointer_type (arg_type);
00372               arg = value_from_pointer (arg_type, sp);
00373             }
00374           break;
00375 
00376         case TYPE_CODE_COMPLEX:
00377           /* ??? The ABI says that complex values are passed as two
00378              separate scalar values.  This distinction only matters
00379              for complex float.  However, GCC does not implement this.  */
00380 
00381           /* Tru64 5.1 has a 128-bit long double, and passes this by
00382              invisible reference.  */
00383           if (TYPE_LENGTH (arg_type) == 32)
00384             {
00385               /* Allocate aligned storage.  */
00386               sp = (sp & -16) - 16;
00387 
00388               /* Write the real data into the stack.  */
00389               write_memory (sp, value_contents (arg), 32);
00390 
00391               /* Construct the indirection.  */
00392               arg_type = lookup_pointer_type (arg_type);
00393               arg = value_from_pointer (arg_type, sp);
00394             }
00395           break;
00396 
00397         default:
00398           break;
00399         }
00400       m_arg->len = TYPE_LENGTH (arg_type);
00401       m_arg->offset = accumulate_size;
00402       accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
00403       m_arg->contents = value_contents (arg);
00404     }
00405 
00406   /* Determine required argument register loads, loading an argument register
00407      is expensive as it uses three ptrace calls.  */
00408   required_arg_regs = accumulate_size / 8;
00409   if (required_arg_regs > ALPHA_NUM_ARG_REGS)
00410     required_arg_regs = ALPHA_NUM_ARG_REGS;
00411 
00412   /* Make room for the arguments on the stack.  */
00413   if (accumulate_size < sizeof(arg_reg_buffer))
00414     accumulate_size = 0;
00415   else
00416     accumulate_size -= sizeof(arg_reg_buffer);
00417   sp -= accumulate_size;
00418 
00419   /* Keep sp aligned to a multiple of 16 as the ABI requires.  */
00420   sp &= ~15;
00421 
00422   /* `Push' arguments on the stack.  */
00423   for (i = nargs; m_arg--, --i >= 0;)
00424     {
00425       const gdb_byte *contents = m_arg->contents;
00426       int offset = m_arg->offset;
00427       int len = m_arg->len;
00428 
00429       /* Copy the bytes destined for registers into arg_reg_buffer.  */
00430       if (offset < sizeof(arg_reg_buffer))
00431         {
00432           if (offset + len <= sizeof(arg_reg_buffer))
00433             {
00434               memcpy (arg_reg_buffer + offset, contents, len);
00435               continue;
00436             }
00437           else
00438             {
00439               int tlen = sizeof(arg_reg_buffer) - offset;
00440               memcpy (arg_reg_buffer + offset, contents, tlen);
00441               offset += tlen;
00442               contents += tlen;
00443               len -= tlen;
00444             }
00445         }
00446 
00447       /* Everything else goes to the stack.  */
00448       write_memory (sp + offset - sizeof(arg_reg_buffer), contents, len);
00449     }
00450   if (struct_return)
00451     store_unsigned_integer (arg_reg_buffer, ALPHA_REGISTER_SIZE,
00452                             byte_order, struct_addr);
00453 
00454   /* Load the argument registers.  */
00455   for (i = 0; i < required_arg_regs; i++)
00456     {
00457       regcache_cooked_write (regcache, ALPHA_A0_REGNUM + i,
00458                              arg_reg_buffer + i*ALPHA_REGISTER_SIZE);
00459       regcache_cooked_write (regcache, ALPHA_FPA0_REGNUM + i,
00460                              arg_reg_buffer + i*ALPHA_REGISTER_SIZE);
00461     }
00462 
00463   /* Finally, update the stack pointer.  */
00464   regcache_cooked_write_signed (regcache, ALPHA_SP_REGNUM, sp);
00465 
00466   return sp;
00467 }
00468 
00469 /* Extract from REGCACHE the value about to be returned from a function
00470    and copy it into VALBUF.  */
00471 
00472 static void
00473 alpha_extract_return_value (struct type *valtype, struct regcache *regcache,
00474                             gdb_byte *valbuf)
00475 {
00476   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00477   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00478   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
00479   ULONGEST l;
00480 
00481   switch (TYPE_CODE (valtype))
00482     {
00483     case TYPE_CODE_FLT:
00484       switch (TYPE_LENGTH (valtype))
00485         {
00486         case 4:
00487           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, raw_buffer);
00488           alpha_sts (gdbarch, valbuf, raw_buffer);
00489           break;
00490 
00491         case 8:
00492           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
00493           break;
00494 
00495         case 16:
00496           regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
00497           read_memory (l, valbuf, 16);
00498           break;
00499 
00500         default:
00501           internal_error (__FILE__, __LINE__,
00502                           _("unknown floating point width"));
00503         }
00504       break;
00505 
00506     case TYPE_CODE_COMPLEX:
00507       switch (TYPE_LENGTH (valtype))
00508         {
00509         case 8:
00510           /* ??? This isn't correct wrt the ABI, but it's what GCC does.  */
00511           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
00512           break;
00513 
00514         case 16:
00515           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf);
00516           regcache_cooked_read (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8);
00517           break;
00518 
00519         case 32:
00520           regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
00521           read_memory (l, valbuf, 32);
00522           break;
00523 
00524         default:
00525           internal_error (__FILE__, __LINE__,
00526                           _("unknown floating point width"));
00527         }
00528       break;
00529 
00530     default:
00531       /* Assume everything else degenerates to an integer.  */
00532       regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l);
00533       store_unsigned_integer (valbuf, TYPE_LENGTH (valtype), byte_order, l);
00534       break;
00535     }
00536 }
00537 
00538 /* Insert the given value into REGCACHE as if it was being 
00539    returned by a function.  */
00540 
00541 static void
00542 alpha_store_return_value (struct type *valtype, struct regcache *regcache,
00543                           const gdb_byte *valbuf)
00544 {
00545   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00546   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
00547   ULONGEST l;
00548 
00549   switch (TYPE_CODE (valtype))
00550     {
00551     case TYPE_CODE_FLT:
00552       switch (TYPE_LENGTH (valtype))
00553         {
00554         case 4:
00555           alpha_lds (gdbarch, raw_buffer, valbuf);
00556           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, raw_buffer);
00557           break;
00558 
00559         case 8:
00560           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
00561           break;
00562 
00563         case 16:
00564           /* FIXME: 128-bit long doubles are returned like structures:
00565              by writing into indirect storage provided by the caller
00566              as the first argument.  */
00567           error (_("Cannot set a 128-bit long double return value."));
00568 
00569         default:
00570           internal_error (__FILE__, __LINE__,
00571                           _("unknown floating point width"));
00572         }
00573       break;
00574 
00575     case TYPE_CODE_COMPLEX:
00576       switch (TYPE_LENGTH (valtype))
00577         {
00578         case 8:
00579           /* ??? This isn't correct wrt the ABI, but it's what GCC does.  */
00580           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
00581           break;
00582 
00583         case 16:
00584           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf);
00585           regcache_cooked_write (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8);
00586           break;
00587 
00588         case 32:
00589           /* FIXME: 128-bit long doubles are returned like structures:
00590              by writing into indirect storage provided by the caller
00591              as the first argument.  */
00592           error (_("Cannot set a 128-bit long double return value."));
00593 
00594         default:
00595           internal_error (__FILE__, __LINE__,
00596                           _("unknown floating point width"));
00597         }
00598       break;
00599 
00600     default:
00601       /* Assume everything else degenerates to an integer.  */
00602       /* 32-bit values must be sign-extended to 64 bits
00603          even if the base data type is unsigned.  */
00604       if (TYPE_LENGTH (valtype) == 4)
00605         valtype = builtin_type (gdbarch)->builtin_int32;
00606       l = unpack_long (valtype, valbuf);
00607       regcache_cooked_write_unsigned (regcache, ALPHA_V0_REGNUM, l);
00608       break;
00609     }
00610 }
00611 
00612 static enum return_value_convention
00613 alpha_return_value (struct gdbarch *gdbarch, struct value *function,
00614                     struct type *type, struct regcache *regcache,
00615                     gdb_byte *readbuf, const gdb_byte *writebuf)
00616 {
00617   enum type_code code = TYPE_CODE (type);
00618 
00619   if ((code == TYPE_CODE_STRUCT
00620        || code == TYPE_CODE_UNION
00621        || code == TYPE_CODE_ARRAY)
00622       && gdbarch_tdep (gdbarch)->return_in_memory (type))
00623     {
00624       if (readbuf)
00625         {
00626           ULONGEST addr;
00627           regcache_raw_read_unsigned (regcache, ALPHA_V0_REGNUM, &addr);
00628           read_memory (addr, readbuf, TYPE_LENGTH (type));
00629         }
00630 
00631       return RETURN_VALUE_ABI_RETURNS_ADDRESS;
00632     }
00633 
00634   if (readbuf)
00635     alpha_extract_return_value (type, regcache, readbuf);
00636   if (writebuf)
00637     alpha_store_return_value (type, regcache, writebuf);
00638 
00639   return RETURN_VALUE_REGISTER_CONVENTION;
00640 }
00641 
00642 static int
00643 alpha_return_in_memory_always (struct type *type)
00644 {
00645   return 1;
00646 }
00647 
00648 static const gdb_byte *
00649 alpha_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
00650 {
00651   static const gdb_byte break_insn[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */
00652 
00653   *len = sizeof(break_insn);
00654   return break_insn;
00655 }
00656 
00657 
00658 /* This returns the PC of the first insn after the prologue.
00659    If we can't find the prologue, then return 0.  */
00660 
00661 CORE_ADDR
00662 alpha_after_prologue (CORE_ADDR pc)
00663 {
00664   struct symtab_and_line sal;
00665   CORE_ADDR func_addr, func_end;
00666 
00667   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
00668     return 0;
00669 
00670   sal = find_pc_line (func_addr, 0);
00671   if (sal.end < func_end)
00672     return sal.end;
00673 
00674   /* The line after the prologue is after the end of the function.  In this
00675      case, tell the caller to find the prologue the hard way.  */
00676   return 0;
00677 }
00678 
00679 /* Read an instruction from memory at PC, looking through breakpoints.  */
00680 
00681 unsigned int
00682 alpha_read_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
00683 {
00684   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00685   gdb_byte buf[ALPHA_INSN_SIZE];
00686   int status;
00687 
00688   status = target_read_memory (pc, buf, sizeof (buf));
00689   if (status)
00690     memory_error (status, pc);
00691   return extract_unsigned_integer (buf, sizeof (buf), byte_order);
00692 }
00693 
00694 /* To skip prologues, I use this predicate.  Returns either PC itself
00695    if the code at PC does not look like a function prologue; otherwise
00696    returns an address that (if we're lucky) follows the prologue.  If
00697    LENIENT, then we must skip everything which is involved in setting
00698    up the frame (it's OK to skip more, just so long as we don't skip
00699    anything which might clobber the registers which are being saved.  */
00700 
00701 static CORE_ADDR
00702 alpha_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
00703 {
00704   unsigned long inst;
00705   int offset;
00706   CORE_ADDR post_prologue_pc;
00707   gdb_byte buf[ALPHA_INSN_SIZE];
00708 
00709   /* Silently return the unaltered pc upon memory errors.
00710      This could happen on OSF/1 if decode_line_1 tries to skip the
00711      prologue for quickstarted shared library functions when the
00712      shared library is not yet mapped in.
00713      Reading target memory is slow over serial lines, so we perform
00714      this check only if the target has shared libraries (which all
00715      Alpha targets do).  */
00716   if (target_read_memory (pc, buf, sizeof (buf)))
00717     return pc;
00718 
00719   /* See if we can determine the end of the prologue via the symbol table.
00720      If so, then return either PC, or the PC after the prologue, whichever
00721      is greater.  */
00722 
00723   post_prologue_pc = alpha_after_prologue (pc);
00724   if (post_prologue_pc != 0)
00725     return max (pc, post_prologue_pc);
00726 
00727   /* Can't determine prologue from the symbol table, need to examine
00728      instructions.  */
00729 
00730   /* Skip the typical prologue instructions.  These are the stack adjustment
00731      instruction and the instructions that save registers on the stack
00732      or in the gcc frame.  */
00733   for (offset = 0; offset < 100; offset += ALPHA_INSN_SIZE)
00734     {
00735       inst = alpha_read_insn (gdbarch, pc + offset);
00736 
00737       if ((inst & 0xffff0000) == 0x27bb0000)    /* ldah $gp,n($t12) */
00738         continue;
00739       if ((inst & 0xffff0000) == 0x23bd0000)    /* lda $gp,n($gp) */
00740         continue;
00741       if ((inst & 0xffff0000) == 0x23de0000)    /* lda $sp,n($sp) */
00742         continue;
00743       if ((inst & 0xffe01fff) == 0x43c0153e)    /* subq $sp,n,$sp */
00744         continue;
00745 
00746       if (((inst & 0xfc1f0000) == 0xb41e0000            /* stq reg,n($sp) */
00747            || (inst & 0xfc1f0000) == 0x9c1e0000)        /* stt reg,n($sp) */
00748           && (inst & 0x03e00000) != 0x03e00000)         /* reg != $zero */
00749         continue;
00750 
00751       if (inst == 0x47de040f)                   /* bis sp,sp,fp */
00752         continue;
00753       if (inst == 0x47fe040f)                   /* bis zero,sp,fp */
00754         continue;
00755 
00756       break;
00757     }
00758   return pc + offset;
00759 }
00760 
00761 
00762 static const int ldl_l_opcode = 0x2a;
00763 static const int ldq_l_opcode = 0x2b;
00764 static const int stl_c_opcode = 0x2e;
00765 static const int stq_c_opcode = 0x2f;
00766 
00767 /* Checks for an atomic sequence of instructions beginning with a LDL_L/LDQ_L
00768    instruction and ending with a STL_C/STQ_C instruction.  If such a sequence
00769    is found, attempt to step through it.  A breakpoint is placed at the end of 
00770    the sequence.  */
00771 
00772 static int 
00773 alpha_deal_with_atomic_sequence (struct frame_info *frame)
00774 {
00775   struct gdbarch *gdbarch = get_frame_arch (frame);
00776   struct address_space *aspace = get_frame_address_space (frame);
00777   CORE_ADDR pc = get_frame_pc (frame);
00778   CORE_ADDR breaks[2] = {-1, -1};
00779   CORE_ADDR loc = pc;
00780   CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence.  */
00781   unsigned int insn = alpha_read_insn (gdbarch, loc);
00782   int insn_count;
00783   int index;
00784   int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */  
00785   const int atomic_sequence_length = 16; /* Instruction sequence length.  */
00786   int bc_insn_count = 0; /* Conditional branch instruction count.  */
00787 
00788   /* Assume all atomic sequences start with a LDL_L/LDQ_L instruction.  */
00789   if (INSN_OPCODE (insn) != ldl_l_opcode
00790       && INSN_OPCODE (insn) != ldq_l_opcode)
00791     return 0;
00792 
00793   /* Assume that no atomic sequence is longer than "atomic_sequence_length" 
00794      instructions.  */
00795   for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
00796     {
00797       loc += ALPHA_INSN_SIZE;
00798       insn = alpha_read_insn (gdbarch, loc);
00799 
00800       /* Assume that there is at most one branch in the atomic
00801          sequence.  If a branch is found, put a breakpoint in 
00802          its destination address.  */
00803       if (INSN_OPCODE (insn) >= br_opcode)
00804         {
00805           int immediate = (insn & 0x001fffff) << 2;
00806 
00807           immediate = (immediate ^ 0x400000) - 0x400000;
00808 
00809           if (bc_insn_count >= 1)
00810             return 0; /* More than one branch found, fallback 
00811                          to the standard single-step code.  */
00812 
00813           breaks[1] = loc + ALPHA_INSN_SIZE + immediate;
00814 
00815           bc_insn_count++;
00816           last_breakpoint++;
00817         }
00818 
00819       if (INSN_OPCODE (insn) == stl_c_opcode
00820           || INSN_OPCODE (insn) == stq_c_opcode)
00821         break;
00822     }
00823 
00824   /* Assume that the atomic sequence ends with a STL_C/STQ_C instruction.  */
00825   if (INSN_OPCODE (insn) != stl_c_opcode
00826       && INSN_OPCODE (insn) != stq_c_opcode)
00827     return 0;
00828 
00829   closing_insn = loc;
00830   loc += ALPHA_INSN_SIZE;
00831 
00832   /* Insert a breakpoint right after the end of the atomic sequence.  */
00833   breaks[0] = loc;
00834 
00835   /* Check for duplicated breakpoints.  Check also for a breakpoint
00836      placed (branch instruction's destination) anywhere in sequence.  */ 
00837   if (last_breakpoint
00838       && (breaks[1] == breaks[0]
00839           || (breaks[1] >= pc && breaks[1] <= closing_insn)))
00840     last_breakpoint = 0;
00841 
00842   /* Effectively inserts the breakpoints.  */
00843   for (index = 0; index <= last_breakpoint; index++)
00844     insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);
00845 
00846   return 1;
00847 }
00848 
00849 
00850 /* Figure out where the longjmp will land.
00851    We expect the first arg to be a pointer to the jmp_buf structure from
00852    which we extract the PC (JB_PC) that we will land at.  The PC is copied
00853    into the "pc".  This routine returns true on success.  */
00854 
00855 static int
00856 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
00857 {
00858   struct gdbarch *gdbarch = get_frame_arch (frame);
00859   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00860   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00861   CORE_ADDR jb_addr;
00862   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
00863 
00864   jb_addr = get_frame_register_unsigned (frame, ALPHA_A0_REGNUM);
00865 
00866   if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size),
00867                           raw_buffer, tdep->jb_elt_size))
00868     return 0;
00869 
00870   *pc = extract_unsigned_integer (raw_buffer, tdep->jb_elt_size, byte_order);
00871   return 1;
00872 }
00873 
00874 
00875 /* Frame unwinder for signal trampolines.  We use alpha tdep bits that
00876    describe the location and shape of the sigcontext structure.  After
00877    that, all registers are in memory, so it's easy.  */
00878 /* ??? Shouldn't we be able to do this generically, rather than with
00879    OSABI data specific to Alpha?  */
00880 
00881 struct alpha_sigtramp_unwind_cache
00882 {
00883   CORE_ADDR sigcontext_addr;
00884 };
00885 
00886 static struct alpha_sigtramp_unwind_cache *
00887 alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
00888                                    void **this_prologue_cache)
00889 {
00890   struct alpha_sigtramp_unwind_cache *info;
00891   struct gdbarch_tdep *tdep;
00892 
00893   if (*this_prologue_cache)
00894     return *this_prologue_cache;
00895 
00896   info = FRAME_OBSTACK_ZALLOC (struct alpha_sigtramp_unwind_cache);
00897   *this_prologue_cache = info;
00898 
00899   tdep = gdbarch_tdep (get_frame_arch (this_frame));
00900   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
00901 
00902   return info;
00903 }
00904 
00905 /* Return the address of REGNUM in a sigtramp frame.  Since this is
00906    all arithmetic, it doesn't seem worthwhile to cache it.  */
00907 
00908 static CORE_ADDR
00909 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
00910                                  CORE_ADDR sigcontext_addr, int regnum)
00911 { 
00912   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00913 
00914   if (regnum >= 0 && regnum < 32)
00915     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
00916   else if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 32)
00917     return sigcontext_addr + tdep->sc_fpregs_offset + regnum * 8;
00918   else if (regnum == ALPHA_PC_REGNUM)
00919     return sigcontext_addr + tdep->sc_pc_offset; 
00920 
00921   return 0;
00922 }
00923 
00924 /* Given a GDB frame, determine the address of the calling function's
00925    frame.  This will be used to create a new GDB frame struct.  */
00926 
00927 static void
00928 alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
00929                               void **this_prologue_cache,
00930                               struct frame_id *this_id)
00931 {
00932   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00933   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00934   struct alpha_sigtramp_unwind_cache *info
00935     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
00936   CORE_ADDR stack_addr, code_addr;
00937 
00938   /* If the OSABI couldn't locate the sigcontext, give up.  */
00939   if (info->sigcontext_addr == 0)
00940     return;
00941 
00942   /* If we have dynamic signal trampolines, find their start.
00943      If we do not, then we must assume there is a symbol record
00944      that can provide the start address.  */
00945   if (tdep->dynamic_sigtramp_offset)
00946     {
00947       int offset;
00948       code_addr = get_frame_pc (this_frame);
00949       offset = tdep->dynamic_sigtramp_offset (gdbarch, code_addr);
00950       if (offset >= 0)
00951         code_addr -= offset;
00952       else
00953         code_addr = 0;
00954     }
00955   else
00956     code_addr = get_frame_func (this_frame);
00957 
00958   /* The stack address is trivially read from the sigcontext.  */
00959   stack_addr = alpha_sigtramp_register_address (gdbarch, info->sigcontext_addr,
00960                                                 ALPHA_SP_REGNUM);
00961   stack_addr = get_frame_memory_unsigned (this_frame, stack_addr,
00962                                           ALPHA_REGISTER_SIZE);
00963 
00964   *this_id = frame_id_build (stack_addr, code_addr);
00965 }
00966 
00967 /* Retrieve the value of REGNUM in FRAME.  Don't give up!  */
00968 
00969 static struct value *
00970 alpha_sigtramp_frame_prev_register (struct frame_info *this_frame,
00971                                     void **this_prologue_cache, int regnum)
00972 {
00973   struct alpha_sigtramp_unwind_cache *info
00974     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
00975   CORE_ADDR addr;
00976 
00977   if (info->sigcontext_addr != 0)
00978     {
00979       /* All integer and fp registers are stored in memory.  */
00980       addr = alpha_sigtramp_register_address (get_frame_arch (this_frame),
00981                                               info->sigcontext_addr, regnum);
00982       if (addr != 0)
00983         return frame_unwind_got_memory (this_frame, regnum, addr);
00984     }
00985 
00986   /* This extra register may actually be in the sigcontext, but our
00987      current description of it in alpha_sigtramp_frame_unwind_cache
00988      doesn't include it.  Too bad.  Fall back on whatever's in the
00989      outer frame.  */
00990   return frame_unwind_got_register (this_frame, regnum, regnum);
00991 }
00992 
00993 static int
00994 alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
00995                               struct frame_info *this_frame,
00996                               void **this_prologue_cache)
00997 {
00998   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00999   CORE_ADDR pc = get_frame_pc (this_frame);
01000   const char *name;
01001 
01002   /* NOTE: cagney/2004-04-30: Do not copy/clone this code.  Instead
01003      look at tramp-frame.h and other simplier per-architecture
01004      sigtramp unwinders.  */
01005 
01006   /* We shouldn't even bother to try if the OSABI didn't register a
01007      sigcontext_addr handler or pc_in_sigtramp hander.  */
01008   if (gdbarch_tdep (gdbarch)->sigcontext_addr == NULL)
01009     return 0;
01010   if (gdbarch_tdep (gdbarch)->pc_in_sigtramp == NULL)
01011     return 0;
01012 
01013   /* Otherwise we should be in a signal frame.  */
01014   find_pc_partial_function (pc, &name, NULL, NULL);
01015   if (gdbarch_tdep (gdbarch)->pc_in_sigtramp (gdbarch, pc, name))
01016     return 1;
01017 
01018   return 0;
01019 }
01020 
01021 static const struct frame_unwind alpha_sigtramp_frame_unwind = {
01022   SIGTRAMP_FRAME,
01023   default_frame_unwind_stop_reason,
01024   alpha_sigtramp_frame_this_id,
01025   alpha_sigtramp_frame_prev_register,
01026   NULL,
01027   alpha_sigtramp_frame_sniffer
01028 };
01029 
01030 
01031 
01032 /* Heuristic_proc_start may hunt through the text section for a long
01033    time across a 2400 baud serial line.  Allows the user to limit this
01034    search.  */
01035 static int heuristic_fence_post = 0;
01036 
01037 /* Attempt to locate the start of the function containing PC.  We assume that
01038    the previous function ends with an about_to_return insn.  Not foolproof by
01039    any means, since gcc is happy to put the epilogue in the middle of a
01040    function.  But we're guessing anyway...  */
01041 
01042 static CORE_ADDR
01043 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
01044 {
01045   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01046   CORE_ADDR last_non_nop = pc;
01047   CORE_ADDR fence = pc - heuristic_fence_post;
01048   CORE_ADDR orig_pc = pc;
01049   CORE_ADDR func;
01050   struct inferior *inf;
01051 
01052   if (pc == 0)
01053     return 0;
01054 
01055   /* First see if we can find the start of the function from minimal
01056      symbol information.  This can succeed with a binary that doesn't
01057      have debug info, but hasn't been stripped.  */
01058   func = get_pc_function_start (pc);
01059   if (func)
01060     return func;
01061 
01062   if (heuristic_fence_post == -1
01063       || fence < tdep->vm_min_address)
01064     fence = tdep->vm_min_address;
01065 
01066   /* Search back for previous return; also stop at a 0, which might be
01067      seen for instance before the start of a code section.  Don't include
01068      nops, since this usually indicates padding between functions.  */
01069   for (pc -= ALPHA_INSN_SIZE; pc >= fence; pc -= ALPHA_INSN_SIZE)
01070     {
01071       unsigned int insn = alpha_read_insn (gdbarch, pc);
01072       switch (insn)
01073         {
01074         case 0:                 /* invalid insn */
01075         case 0x6bfa8001:        /* ret $31,($26),1 */
01076           return last_non_nop;
01077 
01078         case 0x2ffe0000:        /* unop: ldq_u $31,0($30) */
01079         case 0x47ff041f:        /* nop: bis $31,$31,$31 */
01080           break;
01081 
01082         default:
01083           last_non_nop = pc;
01084           break;
01085         }
01086     }
01087 
01088   inf = current_inferior ();
01089 
01090   /* It's not clear to me why we reach this point when stopping quietly,
01091      but with this test, at least we don't print out warnings for every
01092      child forked (eg, on decstation).  22apr93 rich@cygnus.com.  */
01093   if (inf->control.stop_soon == NO_STOP_QUIETLY)
01094     {
01095       static int blurb_printed = 0;
01096 
01097       if (fence == tdep->vm_min_address)
01098         warning (_("Hit beginning of text section without finding \
01099 enclosing function for address %s"), paddress (gdbarch, orig_pc));
01100       else
01101         warning (_("Hit heuristic-fence-post without finding \
01102 enclosing function for address %s"), paddress (gdbarch, orig_pc));
01103 
01104       if (!blurb_printed)
01105         {
01106           printf_filtered (_("\
01107 This warning occurs if you are debugging a function without any symbols\n\
01108 (for example, in a stripped executable).  In that case, you may wish to\n\
01109 increase the size of the search with the `set heuristic-fence-post' command.\n\
01110 \n\
01111 Otherwise, you told GDB there was a function where there isn't one, or\n\
01112 (more likely) you have encountered a bug in GDB.\n"));
01113           blurb_printed = 1;
01114         }
01115     }
01116 
01117   return 0;
01118 }
01119 
01120 /* Fallback alpha frame unwinder.  Uses instruction scanning and knows
01121    something about the traditional layout of alpha stack frames.  */
01122 
01123 struct alpha_heuristic_unwind_cache
01124 { 
01125   CORE_ADDR vfp;
01126   CORE_ADDR start_pc;
01127   struct trad_frame_saved_reg *saved_regs;
01128   int return_reg;
01129 };
01130 
01131 /* If a probing loop sequence starts at PC, simulate it and compute
01132    FRAME_SIZE and PC after its execution.  Otherwise, return with PC and
01133    FRAME_SIZE unchanged.  */
01134 
01135 static void
01136 alpha_heuristic_analyze_probing_loop (struct gdbarch *gdbarch, CORE_ADDR *pc,
01137                                       int *frame_size)
01138 {
01139   CORE_ADDR cur_pc = *pc;
01140   int cur_frame_size = *frame_size;
01141   int nb_of_iterations, reg_index, reg_probe;
01142   unsigned int insn;
01143 
01144   /* The following pattern is recognized as a probing loop:
01145 
01146         lda     REG_INDEX,NB_OF_ITERATIONS
01147         lda     REG_PROBE,<immediate>(sp)
01148 
01149      LOOP_START:
01150         stq     zero,<immediate>(REG_PROBE)
01151         subq    REG_INDEX,0x1,REG_INDEX
01152         lda     REG_PROBE,<immediate>(REG_PROBE)
01153         bne     REG_INDEX, LOOP_START
01154  
01155         lda     sp,<immediate>(REG_PROBE)
01156 
01157      If anything different is found, the function returns without
01158      changing PC and FRAME_SIZE.  Otherwise, PC will point immediately
01159      after this sequence, and FRAME_SIZE will be updated.  */
01160 
01161   /* lda     REG_INDEX,NB_OF_ITERATIONS */
01162 
01163   insn = alpha_read_insn (gdbarch, cur_pc);
01164   if (INSN_OPCODE (insn) != lda_opcode)
01165     return;
01166   reg_index = MEM_RA (insn);
01167   nb_of_iterations = MEM_DISP (insn);
01168 
01169   /* lda     REG_PROBE,<immediate>(sp) */
01170 
01171   cur_pc += ALPHA_INSN_SIZE;
01172   insn = alpha_read_insn (gdbarch, cur_pc);
01173   if (INSN_OPCODE (insn) != lda_opcode
01174       || MEM_RB (insn) != ALPHA_SP_REGNUM)
01175     return;
01176   reg_probe = MEM_RA (insn);
01177   cur_frame_size -= MEM_DISP (insn);
01178 
01179   /* stq     zero,<immediate>(REG_PROBE) */
01180   
01181   cur_pc += ALPHA_INSN_SIZE;
01182   insn = alpha_read_insn (gdbarch, cur_pc);
01183   if (INSN_OPCODE (insn) != stq_opcode
01184       || MEM_RA (insn) != 0x1f
01185       || MEM_RB (insn) != reg_probe)
01186     return;
01187   
01188   /* subq    REG_INDEX,0x1,REG_INDEX */
01189 
01190   cur_pc += ALPHA_INSN_SIZE;
01191   insn = alpha_read_insn (gdbarch, cur_pc);
01192   if (INSN_OPCODE (insn) != subq_opcode
01193       || !OPR_HAS_IMMEDIATE (insn)
01194       || OPR_FUNCTION (insn) != subq_function
01195       || OPR_LIT(insn) != 1
01196       || OPR_RA (insn) != reg_index
01197       || OPR_RC (insn) != reg_index)
01198     return;
01199   
01200   /* lda     REG_PROBE,<immediate>(REG_PROBE) */
01201   
01202   cur_pc += ALPHA_INSN_SIZE;
01203   insn = alpha_read_insn (gdbarch, cur_pc);
01204   if (INSN_OPCODE (insn) != lda_opcode
01205       || MEM_RA (insn) != reg_probe
01206       || MEM_RB (insn) != reg_probe)
01207     return;
01208   cur_frame_size -= MEM_DISP (insn) * nb_of_iterations;
01209 
01210   /* bne     REG_INDEX, LOOP_START */
01211 
01212   cur_pc += ALPHA_INSN_SIZE;
01213   insn = alpha_read_insn (gdbarch, cur_pc);
01214   if (INSN_OPCODE (insn) != bne_opcode
01215       || MEM_RA (insn) != reg_index)
01216     return;
01217 
01218   /* lda     sp,<immediate>(REG_PROBE) */
01219 
01220   cur_pc += ALPHA_INSN_SIZE;
01221   insn = alpha_read_insn (gdbarch, cur_pc);
01222   if (INSN_OPCODE (insn) != lda_opcode
01223       || MEM_RA (insn) != ALPHA_SP_REGNUM
01224       || MEM_RB (insn) != reg_probe)
01225     return;
01226   cur_frame_size -= MEM_DISP (insn);
01227 
01228   *pc = cur_pc;
01229   *frame_size = cur_frame_size;
01230 }
01231 
01232 static struct alpha_heuristic_unwind_cache *
01233 alpha_heuristic_frame_unwind_cache (struct frame_info *this_frame,
01234                                     void **this_prologue_cache,
01235                                     CORE_ADDR start_pc)
01236 {
01237   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01238   struct alpha_heuristic_unwind_cache *info;
01239   ULONGEST val;
01240   CORE_ADDR limit_pc, cur_pc;
01241   int frame_reg, frame_size, return_reg, reg;
01242 
01243   if (*this_prologue_cache)
01244     return *this_prologue_cache;
01245 
01246   info = FRAME_OBSTACK_ZALLOC (struct alpha_heuristic_unwind_cache);
01247   *this_prologue_cache = info;
01248   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
01249 
01250   limit_pc = get_frame_pc (this_frame);
01251   if (start_pc == 0)
01252     start_pc = alpha_heuristic_proc_start (gdbarch, limit_pc);
01253   info->start_pc = start_pc;
01254 
01255   frame_reg = ALPHA_SP_REGNUM;
01256   frame_size = 0;
01257   return_reg = -1;
01258 
01259   /* If we've identified a likely place to start, do code scanning.  */
01260   if (start_pc != 0)
01261     {
01262       /* Limit the forward search to 50 instructions.  */
01263       if (start_pc + 200 < limit_pc)
01264         limit_pc = start_pc + 200;
01265 
01266       for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += ALPHA_INSN_SIZE)
01267         {
01268           unsigned int word = alpha_read_insn (gdbarch, cur_pc);
01269 
01270           if ((word & 0xffff0000) == 0x23de0000)        /* lda $sp,n($sp) */
01271             {
01272               if (word & 0x8000)
01273                 {
01274                   /* Consider only the first stack allocation instruction
01275                      to contain the static size of the frame.  */
01276                   if (frame_size == 0)
01277                     frame_size = (-word) & 0xffff;
01278                 }
01279               else
01280                 {
01281                   /* Exit loop if a positive stack adjustment is found, which
01282                      usually means that the stack cleanup code in the function
01283                      epilogue is reached.  */
01284                   break;
01285                 }
01286             }
01287           else if ((word & 0xfc1f0000) == 0xb41e0000)   /* stq reg,n($sp) */
01288             {
01289               reg = (word & 0x03e00000) >> 21;
01290 
01291               /* Ignore this instruction if we have already encountered
01292                  an instruction saving the same register earlier in the
01293                  function code.  The current instruction does not tell
01294                  us where the original value upon function entry is saved.
01295                  All it says is that the function we are scanning reused
01296                  that register for some computation of its own, and is now
01297                  saving its result.  */
01298               if (trad_frame_addr_p(info->saved_regs, reg))
01299                 continue;
01300 
01301               if (reg == 31)
01302                 continue;
01303 
01304               /* Do not compute the address where the register was saved yet,
01305                  because we don't know yet if the offset will need to be
01306                  relative to $sp or $fp (we can not compute the address
01307                  relative to $sp if $sp is updated during the execution of
01308                  the current subroutine, for instance when doing some alloca).
01309                  So just store the offset for the moment, and compute the
01310                  address later when we know whether this frame has a frame
01311                  pointer or not.  */
01312               /* Hack: temporarily add one, so that the offset is non-zero
01313                  and we can tell which registers have save offsets below.  */
01314               info->saved_regs[reg].addr = (word & 0xffff) + 1;
01315 
01316               /* Starting with OSF/1-3.2C, the system libraries are shipped
01317                  without local symbols, but they still contain procedure
01318                  descriptors without a symbol reference. GDB is currently
01319                  unable to find these procedure descriptors and uses
01320                  heuristic_proc_desc instead.
01321                  As some low level compiler support routines (__div*, __add*)
01322                  use a non-standard return address register, we have to
01323                  add some heuristics to determine the return address register,
01324                  or stepping over these routines will fail.
01325                  Usually the return address register is the first register
01326                  saved on the stack, but assembler optimization might
01327                  rearrange the register saves.
01328                  So we recognize only a few registers (t7, t9, ra) within
01329                  the procedure prologue as valid return address registers.
01330                  If we encounter a return instruction, we extract the
01331                  return address register from it.
01332 
01333                  FIXME: Rewriting GDB to access the procedure descriptors,
01334                  e.g. via the minimal symbol table, might obviate this
01335                  hack.  */
01336               if (return_reg == -1
01337                   && cur_pc < (start_pc + 80)
01338                   && (reg == ALPHA_T7_REGNUM
01339                       || reg == ALPHA_T9_REGNUM
01340                       || reg == ALPHA_RA_REGNUM))
01341                 return_reg = reg;
01342             }
01343           else if ((word & 0xffe0ffff) == 0x6be08001)   /* ret zero,reg,1 */
01344             return_reg = (word >> 16) & 0x1f;
01345           else if (word == 0x47de040f)                  /* bis sp,sp,fp */
01346             frame_reg = ALPHA_GCC_FP_REGNUM;
01347           else if (word == 0x47fe040f)                  /* bis zero,sp,fp */
01348             frame_reg = ALPHA_GCC_FP_REGNUM;
01349 
01350           alpha_heuristic_analyze_probing_loop (gdbarch, &cur_pc, &frame_size);
01351         }
01352 
01353       /* If we haven't found a valid return address register yet, keep
01354          searching in the procedure prologue.  */
01355       if (return_reg == -1)
01356         {
01357           while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
01358             {
01359               unsigned int word = alpha_read_insn (gdbarch, cur_pc);
01360 
01361               if ((word & 0xfc1f0000) == 0xb41e0000)    /* stq reg,n($sp) */
01362                 {
01363                   reg = (word & 0x03e00000) >> 21;
01364                   if (reg == ALPHA_T7_REGNUM
01365                       || reg == ALPHA_T9_REGNUM
01366                       || reg == ALPHA_RA_REGNUM)
01367                     {
01368                       return_reg = reg;
01369                       break;
01370                     }
01371                 }
01372               else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
01373                 {
01374                   return_reg = (word >> 16) & 0x1f;
01375                   break;
01376                 }
01377 
01378               cur_pc += ALPHA_INSN_SIZE;
01379             }
01380         }
01381     }
01382 
01383   /* Failing that, do default to the customary RA.  */
01384   if (return_reg == -1)
01385     return_reg = ALPHA_RA_REGNUM;
01386   info->return_reg = return_reg;
01387 
01388   val = get_frame_register_unsigned (this_frame, frame_reg);
01389   info->vfp = val + frame_size;
01390 
01391   /* Convert offsets to absolute addresses.  See above about adding
01392      one to the offsets to make all detected offsets non-zero.  */
01393   for (reg = 0; reg < ALPHA_NUM_REGS; ++reg)
01394     if (trad_frame_addr_p(info->saved_regs, reg))
01395       info->saved_regs[reg].addr += val - 1;
01396 
01397   /* The stack pointer of the previous frame is computed by popping
01398      the current stack frame.  */
01399   if (!trad_frame_addr_p (info->saved_regs, ALPHA_SP_REGNUM))
01400    trad_frame_set_value (info->saved_regs, ALPHA_SP_REGNUM, info->vfp);
01401 
01402   return info;
01403 }
01404 
01405 /* Given a GDB frame, determine the address of the calling function's
01406    frame.  This will be used to create a new GDB frame struct.  */
01407 
01408 static void
01409 alpha_heuristic_frame_this_id (struct frame_info *this_frame,
01410                                void **this_prologue_cache,
01411                                struct frame_id *this_id)
01412 {
01413   struct alpha_heuristic_unwind_cache *info
01414     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);
01415 
01416   *this_id = frame_id_build (info->vfp, info->start_pc);
01417 }
01418 
01419 /* Retrieve the value of REGNUM in FRAME.  Don't give up!  */
01420 
01421 static struct value *
01422 alpha_heuristic_frame_prev_register (struct frame_info *this_frame,
01423                                      void **this_prologue_cache, int regnum)
01424 {
01425   struct alpha_heuristic_unwind_cache *info
01426     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);
01427 
01428   /* The PC of the previous frame is stored in the link register of
01429      the current frame.  Frob regnum so that we pull the value from
01430      the correct place.  */
01431   if (regnum == ALPHA_PC_REGNUM)
01432     regnum = info->return_reg;
01433   
01434   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
01435 }
01436 
01437 static const struct frame_unwind alpha_heuristic_frame_unwind = {
01438   NORMAL_FRAME,
01439   default_frame_unwind_stop_reason,
01440   alpha_heuristic_frame_this_id,
01441   alpha_heuristic_frame_prev_register,
01442   NULL,
01443   default_frame_sniffer
01444 };
01445 
01446 static CORE_ADDR
01447 alpha_heuristic_frame_base_address (struct frame_info *this_frame,
01448                                     void **this_prologue_cache)
01449 {
01450   struct alpha_heuristic_unwind_cache *info
01451     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);
01452 
01453   return info->vfp;
01454 }
01455 
01456 static const struct frame_base alpha_heuristic_frame_base = {
01457   &alpha_heuristic_frame_unwind,
01458   alpha_heuristic_frame_base_address,
01459   alpha_heuristic_frame_base_address,
01460   alpha_heuristic_frame_base_address
01461 };
01462 
01463 /* Just like reinit_frame_cache, but with the right arguments to be
01464    callable as an sfunc.  Used by the "set heuristic-fence-post" command.  */
01465 
01466 static void
01467 reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
01468 {
01469   reinit_frame_cache ();
01470 }
01471 
01472 
01473 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
01474    dummy frame.  The frame ID's base needs to match the TOS value
01475    saved by save_dummy_frame_tos(), and the PC match the dummy frame's
01476    breakpoint.  */
01477 
01478 static struct frame_id
01479 alpha_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
01480 {
01481   ULONGEST base;
01482   base = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
01483   return frame_id_build (base, get_frame_pc (this_frame));
01484 }
01485 
01486 static CORE_ADDR
01487 alpha_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
01488 {
01489   ULONGEST pc;
01490   pc = frame_unwind_register_unsigned (next_frame, ALPHA_PC_REGNUM);
01491   return pc;
01492 }
01493 
01494 
01495 /* Helper routines for alpha*-nat.c files to move register sets to and
01496    from core files.  The UNIQUE pointer is allowed to be NULL, as most
01497    targets don't supply this value in their core files.  */
01498 
01499 void
01500 alpha_supply_int_regs (struct regcache *regcache, int regno,
01501                        const void *r0_r30, const void *pc, const void *unique)
01502 {
01503   const gdb_byte *regs = r0_r30;
01504   int i;
01505 
01506   for (i = 0; i < 31; ++i)
01507     if (regno == i || regno == -1)
01508       regcache_raw_supply (regcache, i, regs + i * 8);
01509 
01510   if (regno == ALPHA_ZERO_REGNUM || regno == -1)
01511     {
01512       const gdb_byte zero[8] = { 0 };
01513 
01514       regcache_raw_supply (regcache, ALPHA_ZERO_REGNUM, zero);
01515     }
01516 
01517   if (regno == ALPHA_PC_REGNUM || regno == -1)
01518     regcache_raw_supply (regcache, ALPHA_PC_REGNUM, pc);
01519 
01520   if (regno == ALPHA_UNIQUE_REGNUM || regno == -1)
01521     regcache_raw_supply (regcache, ALPHA_UNIQUE_REGNUM, unique);
01522 }
01523 
01524 void
01525 alpha_fill_int_regs (const struct regcache *regcache,
01526                      int regno, void *r0_r30, void *pc, void *unique)
01527 {
01528   gdb_byte *regs = r0_r30;
01529   int i;
01530 
01531   for (i = 0; i < 31; ++i)
01532     if (regno == i || regno == -1)
01533       regcache_raw_collect (regcache, i, regs + i * 8);
01534 
01535   if (regno == ALPHA_PC_REGNUM || regno == -1)
01536     regcache_raw_collect (regcache, ALPHA_PC_REGNUM, pc);
01537 
01538   if (unique && (regno == ALPHA_UNIQUE_REGNUM || regno == -1))
01539     regcache_raw_collect (regcache, ALPHA_UNIQUE_REGNUM, unique);
01540 }
01541 
01542 void
01543 alpha_supply_fp_regs (struct regcache *regcache, int regno,
01544                       const void *f0_f30, const void *fpcr)
01545 {
01546   const gdb_byte *regs = f0_f30;
01547   int i;
01548 
01549   for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i)
01550     if (regno == i || regno == -1)
01551       regcache_raw_supply (regcache, i,
01552                            regs + (i - ALPHA_FP0_REGNUM) * 8);
01553 
01554   if (regno == ALPHA_FPCR_REGNUM || regno == -1)
01555     regcache_raw_supply (regcache, ALPHA_FPCR_REGNUM, fpcr);
01556 }
01557 
01558 void
01559 alpha_fill_fp_regs (const struct regcache *regcache,
01560                     int regno, void *f0_f30, void *fpcr)
01561 {
01562   gdb_byte *regs = f0_f30;
01563   int i;
01564 
01565   for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i)
01566     if (regno == i || regno == -1)
01567       regcache_raw_collect (regcache, i,
01568                             regs + (i - ALPHA_FP0_REGNUM) * 8);
01569 
01570   if (regno == ALPHA_FPCR_REGNUM || regno == -1)
01571     regcache_raw_collect (regcache, ALPHA_FPCR_REGNUM, fpcr);
01572 }
01573 
01574 
01575 
01576 /* Return nonzero if the G_floating register value in REG is equal to
01577    zero for FP control instructions.  */
01578    
01579 static int
01580 fp_register_zero_p (LONGEST reg)
01581 {
01582   /* Check that all bits except the sign bit are zero.  */
01583   const LONGEST zero_mask = ((LONGEST) 1 << 63) ^ -1;
01584 
01585   return ((reg & zero_mask) == 0);
01586 }
01587 
01588 /* Return the value of the sign bit for the G_floating register
01589    value held in REG.  */
01590 
01591 static int
01592 fp_register_sign_bit (LONGEST reg)
01593 {
01594   const LONGEST sign_mask = (LONGEST) 1 << 63;
01595 
01596   return ((reg & sign_mask) != 0);
01597 }
01598 
01599 /* alpha_software_single_step() is called just before we want to resume
01600    the inferior, if we want to single-step it but there is no hardware
01601    or kernel single-step support (NetBSD on Alpha, for example).  We find
01602    the target of the coming instruction and breakpoint it.  */
01603 
01604 static CORE_ADDR
01605 alpha_next_pc (struct frame_info *frame, CORE_ADDR pc)
01606 {
01607   struct gdbarch *gdbarch = get_frame_arch (frame);
01608   unsigned int insn;
01609   unsigned int op;
01610   int regno;
01611   int offset;
01612   LONGEST rav;
01613 
01614   insn = alpha_read_insn (gdbarch, pc);
01615 
01616   /* Opcode is top 6 bits.  */
01617   op = (insn >> 26) & 0x3f;
01618 
01619   if (op == 0x1a)
01620     {
01621       /* Jump format: target PC is:
01622          RB & ~3  */
01623       return (get_frame_register_unsigned (frame, (insn >> 16) & 0x1f) & ~3);
01624     }
01625 
01626   if ((op & 0x30) == 0x30)
01627     {
01628       /* Branch format: target PC is:
01629          (new PC) + (4 * sext(displacement))  */
01630       if (op == 0x30            /* BR */
01631           || op == 0x34)        /* BSR */
01632         {
01633  branch_taken:
01634           offset = (insn & 0x001fffff);
01635           if (offset & 0x00100000)
01636             offset  |= 0xffe00000;
01637           offset *= ALPHA_INSN_SIZE;
01638           return (pc + ALPHA_INSN_SIZE + offset);
01639         }
01640 
01641       /* Need to determine if branch is taken; read RA.  */
01642       regno = (insn >> 21) & 0x1f;
01643       switch (op)
01644         {
01645           case 0x31:              /* FBEQ */
01646           case 0x36:              /* FBGE */
01647           case 0x37:              /* FBGT */
01648           case 0x33:              /* FBLE */
01649           case 0x32:              /* FBLT */
01650           case 0x35:              /* FBNE */
01651             regno += gdbarch_fp0_regnum (gdbarch);
01652         }
01653       
01654       rav = get_frame_register_signed (frame, regno);
01655 
01656       switch (op)
01657         {
01658         case 0x38:              /* BLBC */
01659           if ((rav & 1) == 0)
01660             goto branch_taken;
01661           break;
01662         case 0x3c:              /* BLBS */
01663           if (rav & 1)
01664             goto branch_taken;
01665           break;
01666         case 0x39:              /* BEQ */
01667           if (rav == 0)
01668             goto branch_taken;
01669           break;
01670         case 0x3d:              /* BNE */
01671           if (rav != 0)
01672             goto branch_taken;
01673           break;
01674         case 0x3a:              /* BLT */
01675           if (rav < 0)
01676             goto branch_taken;
01677           break;
01678         case 0x3b:              /* BLE */
01679           if (rav <= 0)
01680             goto branch_taken;
01681           break;
01682         case 0x3f:              /* BGT */
01683           if (rav > 0)
01684             goto branch_taken;
01685           break;
01686         case 0x3e:              /* BGE */
01687           if (rav >= 0)
01688             goto branch_taken;
01689           break;
01690 
01691         /* Floating point branches.  */
01692         
01693         case 0x31:              /* FBEQ */
01694           if (fp_register_zero_p (rav))
01695             goto branch_taken;
01696           break;
01697         case 0x36:              /* FBGE */
01698           if (fp_register_sign_bit (rav) == 0 || fp_register_zero_p (rav))
01699             goto branch_taken;
01700           break;
01701         case 0x37:              /* FBGT */
01702           if (fp_register_sign_bit (rav) == 0 && ! fp_register_zero_p (rav))
01703             goto branch_taken;
01704           break;
01705         case 0x33:              /* FBLE */
01706           if (fp_register_sign_bit (rav) == 1 || fp_register_zero_p (rav))
01707             goto branch_taken;
01708           break;
01709         case 0x32:              /* FBLT */
01710           if (fp_register_sign_bit (rav) == 1 && ! fp_register_zero_p (rav))
01711             goto branch_taken;
01712           break;
01713         case 0x35:              /* FBNE */
01714           if (! fp_register_zero_p (rav))
01715             goto branch_taken;
01716           break;
01717         }
01718     }
01719 
01720   /* Not a branch or branch not taken; target PC is:
01721      pc + 4  */
01722   return (pc + ALPHA_INSN_SIZE);
01723 }
01724 
01725 int
01726 alpha_software_single_step (struct frame_info *frame)
01727 {
01728   struct gdbarch *gdbarch = get_frame_arch (frame);
01729   struct address_space *aspace = get_frame_address_space (frame);
01730   CORE_ADDR pc, next_pc;
01731 
01732   pc = get_frame_pc (frame);
01733   next_pc = alpha_next_pc (frame, pc);
01734 
01735   insert_single_step_breakpoint (gdbarch, aspace, next_pc);
01736   return 1;
01737 }
01738 
01739 
01740 /* Initialize the current architecture based on INFO.  If possible, re-use an
01741    architecture from ARCHES, which is a list of architectures already created
01742    during this debugging session.
01743 
01744    Called e.g. at program startup, when reading a core file, and when reading
01745    a binary file.  */
01746 
01747 static struct gdbarch *
01748 alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
01749 {
01750   struct gdbarch_tdep *tdep;
01751   struct gdbarch *gdbarch;
01752 
01753   /* Try to determine the ABI of the object we are loading.  */
01754   if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
01755     {
01756       /* If it's an ECOFF file, assume it's OSF/1.  */
01757       if (bfd_get_flavour (info.abfd) == bfd_target_ecoff_flavour)
01758         info.osabi = GDB_OSABI_OSF1;
01759     }
01760 
01761   /* Find a candidate among extant architectures.  */
01762   arches = gdbarch_list_lookup_by_info (arches, &info);
01763   if (arches != NULL)
01764     return arches->gdbarch;
01765 
01766   tdep = xmalloc (sizeof (struct gdbarch_tdep));
01767   gdbarch = gdbarch_alloc (&info, tdep);
01768 
01769   /* Lowest text address.  This is used by heuristic_proc_start()
01770      to decide when to stop looking.  */
01771   tdep->vm_min_address = (CORE_ADDR) 0x120000000LL;
01772 
01773   tdep->dynamic_sigtramp_offset = NULL;
01774   tdep->sigcontext_addr = NULL;
01775   tdep->sc_pc_offset = 2 * 8;
01776   tdep->sc_regs_offset = 4 * 8;
01777   tdep->sc_fpregs_offset = tdep->sc_regs_offset + 32 * 8 + 8;
01778 
01779   tdep->jb_pc = -1;     /* longjmp support not enabled by default.  */
01780 
01781   tdep->return_in_memory = alpha_return_in_memory_always;
01782 
01783   /* Type sizes */
01784   set_gdbarch_short_bit (gdbarch, 16);
01785   set_gdbarch_int_bit (gdbarch, 32);
01786   set_gdbarch_long_bit (gdbarch, 64);
01787   set_gdbarch_long_long_bit (gdbarch, 64);
01788   set_gdbarch_float_bit (gdbarch, 32);
01789   set_gdbarch_double_bit (gdbarch, 64);
01790   set_gdbarch_long_double_bit (gdbarch, 64);
01791   set_gdbarch_ptr_bit (gdbarch, 64);
01792 
01793   /* Register info */
01794   set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS);
01795   set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM);
01796   set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM);
01797   set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM);
01798 
01799   set_gdbarch_register_name (gdbarch, alpha_register_name);
01800   set_gdbarch_register_type (gdbarch, alpha_register_type);
01801 
01802   set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register);
01803   set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register);
01804 
01805   set_gdbarch_convert_register_p (gdbarch, alpha_convert_register_p);
01806   set_gdbarch_register_to_value (gdbarch, alpha_register_to_value);
01807   set_gdbarch_value_to_register (gdbarch, alpha_value_to_register);
01808 
01809   set_gdbarch_register_reggroup_p (gdbarch, alpha_register_reggroup_p);
01810 
01811   /* Prologue heuristics.  */
01812   set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue);
01813 
01814   /* Disassembler.  */
01815   set_gdbarch_print_insn (gdbarch, print_insn_alpha);
01816 
01817   /* Call info.  */
01818 
01819   set_gdbarch_return_value (gdbarch, alpha_return_value);
01820 
01821   /* Settings for calling functions in the inferior.  */
01822   set_gdbarch_push_dummy_call (gdbarch, alpha_push_dummy_call);
01823 
01824   /* Methods for saving / extracting a dummy frame's ID.  */
01825   set_gdbarch_dummy_id (gdbarch, alpha_dummy_id);
01826 
01827   /* Return the unwound PC value.  */
01828   set_gdbarch_unwind_pc (gdbarch, alpha_unwind_pc);
01829 
01830   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
01831   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
01832 
01833   set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc);
01834   set_gdbarch_decr_pc_after_break (gdbarch, ALPHA_INSN_SIZE);
01835   set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
01836 
01837   /* Handles single stepping of atomic sequences.  */
01838   set_gdbarch_software_single_step (gdbarch, alpha_deal_with_atomic_sequence);
01839 
01840   /* Hook in ABI-specific overrides, if they have been registered.  */
01841   gdbarch_init_osabi (info, gdbarch);
01842 
01843   /* Now that we have tuned the configuration, set a few final things
01844      based on what the OS ABI has told us.  */
01845 
01846   if (tdep->jb_pc >= 0)
01847     set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target);
01848 
01849   frame_unwind_append_unwinder (gdbarch, &alpha_sigtramp_frame_unwind);
01850   frame_unwind_append_unwinder (gdbarch, &alpha_heuristic_frame_unwind);
01851 
01852   frame_base_set_default (gdbarch, &alpha_heuristic_frame_base);
01853 
01854   return gdbarch;
01855 }
01856 
01857 void
01858 alpha_dwarf2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
01859 {
01860   dwarf2_append_unwinders (gdbarch);
01861   frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
01862 }
01863 
01864 extern initialize_file_ftype _initialize_alpha_tdep; /* -Wmissing-prototypes */
01865 
01866 void
01867 _initialize_alpha_tdep (void)
01868 {
01869   struct cmd_list_element *c;
01870 
01871   gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, NULL);
01872 
01873   /* Let the user set the fence post for heuristic_proc_start.  */
01874 
01875   /* We really would like to have both "0" and "unlimited" work, but
01876      command.c doesn't deal with that.  So make it a var_zinteger
01877      because the user can always use "999999" or some such for unlimited.  */
01878   /* We need to throw away the frame cache when we set this, since it
01879      might change our ability to get backtraces.  */
01880   add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
01881                             &heuristic_fence_post, _("\
01882 Set the distance searched for the start of a function."), _("\
01883 Show the distance searched for the start of a function."), _("\
01884 If you are debugging a stripped executable, GDB needs to search through the\n\
01885 program for the start of a function.  This command sets the distance of the\n\
01886 search.  The only need to set it is when debugging a stripped executable."),
01887                             reinit_frame_cache_sfunc,
01888                             NULL, /* FIXME: i18n: The distance searched for
01889                                      the start of a function is \"%d\".  */
01890                             &setlist, &showlist);
01891 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines