OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [alpha-tdep.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
/* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
   Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
   Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "frame.h"
#include "frame.h"
#include "inferior.h"
#include "inferior.h"
#include "symtab.h"
#include "symtab.h"
#include "value.h"
#include "value.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "gdbcore.h"
#include "gdbcore.h"
#include "dis-asm.h"
#include "dis-asm.h"
#include "symfile.h"
#include "symfile.h"
#include "objfiles.h"
#include "objfiles.h"
#include "gdb_string.h"
#include "gdb_string.h"
 
 
/* FIXME: Some of this code should perhaps be merged with mips-tdep.c.  */
/* FIXME: Some of this code should perhaps be merged with mips-tdep.c.  */
 
 
/* Prototypes for local functions. */
/* Prototypes for local functions. */
 
 
static alpha_extra_func_info_t push_sigtramp_desc PARAMS ((CORE_ADDR low_addr));
static alpha_extra_func_info_t push_sigtramp_desc PARAMS ((CORE_ADDR low_addr));
 
 
static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
 
 
static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
 
 
static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR,
static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR,
                                                            CORE_ADDR,
                                                            CORE_ADDR,
                                                      struct frame_info *));
                                                      struct frame_info *));
 
 
static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR,
static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR,
                                                       struct frame_info *));
                                                       struct frame_info *));
 
 
#if 0
#if 0
static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
#endif
#endif
 
 
static void reinit_frame_cache_sfunc PARAMS ((char *, int,
static void reinit_frame_cache_sfunc PARAMS ((char *, int,
                                              struct cmd_list_element *));
                                              struct cmd_list_element *));
 
 
static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
                                         alpha_extra_func_info_t proc_desc));
                                         alpha_extra_func_info_t proc_desc));
 
 
static int alpha_in_prologue PARAMS ((CORE_ADDR pc,
static int alpha_in_prologue PARAMS ((CORE_ADDR pc,
                                      alpha_extra_func_info_t proc_desc));
                                      alpha_extra_func_info_t proc_desc));
 
 
static int alpha_about_to_return PARAMS ((CORE_ADDR pc));
static int alpha_about_to_return PARAMS ((CORE_ADDR pc));
 
 
void _initialize_alpha_tdep PARAMS ((void));
void _initialize_alpha_tdep PARAMS ((void));
 
 
/* Heuristic_proc_start may hunt through the text section for a long
/* Heuristic_proc_start may hunt through the text section for a long
   time across a 2400 baud serial line.  Allows the user to limit this
   time across a 2400 baud serial line.  Allows the user to limit this
   search.  */
   search.  */
static unsigned int heuristic_fence_post = 0;
static unsigned int heuristic_fence_post = 0;
/* *INDENT-OFF* */
/* *INDENT-OFF* */
/* Layout of a stack frame on the alpha:
/* Layout of a stack frame on the alpha:
 
 
                |                               |
                |                               |
 pdr members:   |  7th ... nth arg,             |
 pdr members:   |  7th ... nth arg,             |
                |  `pushed' by caller.          |
                |  `pushed' by caller.          |
                |                               |
                |                               |
----------------|-------------------------------|<--  old_sp == vfp
----------------|-------------------------------|<--  old_sp == vfp
   ^  ^  ^  ^   |                               |
   ^  ^  ^  ^   |                               |
   |  |  |  |   |                               |
   |  |  |  |   |                               |
   |  |localoff |  Copies of 1st .. 6th         |
   |  |localoff |  Copies of 1st .. 6th         |
   |  |  |  |   |  argument if necessary.       |
   |  |  |  |   |  argument if necessary.       |
   |  |  |  v   |                               |
   |  |  |  v   |                               |
   |  |  |  --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
   |  |  |  --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
   |  |  |      |                               |
   |  |  |      |                               |
   |  |  |      |  Locals and temporaries.      |
   |  |  |      |  Locals and temporaries.      |
   |  |  |      |                               |
   |  |  |      |                               |
   |  |  |      |-------------------------------|
   |  |  |      |-------------------------------|
   |  |  |      |                               |
   |  |  |      |                               |
   |-fregoffset |  Saved float registers.       |
   |-fregoffset |  Saved float registers.       |
   |  |  |      |  F9                           |
   |  |  |      |  F9                           |
   |  |  |      |   .                           |
   |  |  |      |   .                           |
   |  |  |      |   .                           |
   |  |  |      |   .                           |
   |  |  |      |  F2                           |
   |  |  |      |  F2                           |
   |  |  v      |                               |
   |  |  v      |                               |
   |  |  -------|-------------------------------|
   |  |  -------|-------------------------------|
   |  |         |                               |
   |  |         |                               |
   |  |         |  Saved registers.             |
   |  |         |  Saved registers.             |
   |  |         |  S6                           |
   |  |         |  S6                           |
   |-regoffset  |   .                           |
   |-regoffset  |   .                           |
   |  |         |   .                           |
   |  |         |   .                           |
   |  |         |  S0                           |
   |  |         |  S0                           |
   |  |         |  pdr.pcreg                    |
   |  |         |  pdr.pcreg                    |
   |  v         |                               |
   |  v         |                               |
   |  ----------|-------------------------------|
   |  ----------|-------------------------------|
   |            |                               |
   |            |                               |
 frameoffset    |  Argument build area, gets    |
 frameoffset    |  Argument build area, gets    |
   |            |  7th ... nth arg for any      |
   |            |  7th ... nth arg for any      |
   |            |  called procedure.            |
   |            |  called procedure.            |
   v            |                               |
   v            |                               |
   -------------|-------------------------------|<-- sp
   -------------|-------------------------------|<-- sp
                |                               |
                |                               |
*/
*/
/* *INDENT-ON* */
/* *INDENT-ON* */
 
 
 
 
 
 
#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)   /* least address */
#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)   /* least address */
/* These next two fields are kind of being hijacked.  I wonder if
/* These next two fields are kind of being hijacked.  I wonder if
   iline is too small for the values it needs to hold, if GDB is
   iline is too small for the values it needs to hold, if GDB is
   running on a 32-bit host.  */
   running on a 32-bit host.  */
#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline)        /* upper address bound */
#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline)        /* upper address bound */
#define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset)       /*CALL_DUMMY frame */
#define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset)       /*CALL_DUMMY frame */
#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
#define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
#define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
#define _PROC_MAGIC_ 0x0F0F0F0F
#define _PROC_MAGIC_ 0x0F0F0F0F
#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
 
 
struct linked_proc_info
struct linked_proc_info
  {
  {
    struct alpha_extra_func_info info;
    struct alpha_extra_func_info info;
    struct linked_proc_info *next;
    struct linked_proc_info *next;
  }
  }
 *linked_proc_desc_table = NULL;
 *linked_proc_desc_table = NULL;


 
 
/* Under GNU/Linux, signal handler invocations can be identified by the
/* Under GNU/Linux, signal handler invocations can be identified by the
   designated code sequence that is used to return from a signal
   designated code sequence that is used to return from a signal
   handler.  In particular, the return address of a signal handler
   handler.  In particular, the return address of a signal handler
   points to the following sequence (the first instruction is quadword
   points to the following sequence (the first instruction is quadword
   aligned):
   aligned):
 
 
   bis $30,$30,$16
   bis $30,$30,$16
   addq $31,0x67,$0
   addq $31,0x67,$0
   call_pal callsys
   call_pal callsys
 
 
   Each instruction has a unique encoding, so we simply attempt to
   Each instruction has a unique encoding, so we simply attempt to
   match the instruction the pc is pointing to with any of the above
   match the instruction the pc is pointing to with any of the above
   instructions.  If there is a hit, we know the offset to the start
   instructions.  If there is a hit, we know the offset to the start
   of the designated sequence and can then check whether we really are
   of the designated sequence and can then check whether we really are
   executing in a designated sequence.  If not, -1 is returned,
   executing in a designated sequence.  If not, -1 is returned,
   otherwise the offset from the start of the desingated sequence is
   otherwise the offset from the start of the desingated sequence is
   returned.
   returned.
 
 
   There is a slight chance of false hits: code could jump into the
   There is a slight chance of false hits: code could jump into the
   middle of the designated sequence, in which case there is no
   middle of the designated sequence, in which case there is no
   guarantee that we are in the middle of a sigreturn syscall.  Don't
   guarantee that we are in the middle of a sigreturn syscall.  Don't
   think this will be a problem in praxis, though.
   think this will be a problem in praxis, though.
 */
 */
 
 
#ifndef TM_LINUXALPHA_H
#ifndef TM_LINUXALPHA_H
/* HACK: Provide a prototype when compiling this file for non
/* HACK: Provide a prototype when compiling this file for non
   linuxalpha targets. */
   linuxalpha targets. */
long alpha_linux_sigtramp_offset PARAMS ((CORE_ADDR pc));
long alpha_linux_sigtramp_offset PARAMS ((CORE_ADDR pc));
#endif
#endif
long
long
alpha_linux_sigtramp_offset (pc)
alpha_linux_sigtramp_offset (pc)
     CORE_ADDR pc;
     CORE_ADDR pc;
{
{
  unsigned int i[3], w;
  unsigned int i[3], w;
  long off;
  long off;
 
 
  if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
  if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
    return -1;
    return -1;
 
 
  off = -1;
  off = -1;
  switch (w)
  switch (w)
    {
    {
    case 0x47de0410:
    case 0x47de0410:
      off = 0;
      off = 0;
      break;                    /* bis $30,$30,$16 */
      break;                    /* bis $30,$30,$16 */
    case 0x43ecf400:
    case 0x43ecf400:
      off = 4;
      off = 4;
      break;                    /* addq $31,0x67,$0 */
      break;                    /* addq $31,0x67,$0 */
    case 0x00000083:
    case 0x00000083:
      off = 8;
      off = 8;
      break;                    /* call_pal callsys */
      break;                    /* call_pal callsys */
    default:
    default:
      return -1;
      return -1;
    }
    }
  pc -= off;
  pc -= off;
  if (pc & 0x7)
  if (pc & 0x7)
    {
    {
      /* designated sequence is not quadword aligned */
      /* designated sequence is not quadword aligned */
      return -1;
      return -1;
    }
    }
 
 
  if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
  if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
    return -1;
    return -1;
 
 
  if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
  if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
    return off;
    return off;
 
 
  return -1;
  return -1;
}
}


 
 
/* Under OSF/1, the __sigtramp routine is frameless and has a frame
/* Under OSF/1, the __sigtramp routine is frameless and has a frame
   size of zero, but we are able to backtrace through it.  */
   size of zero, but we are able to backtrace through it.  */
CORE_ADDR
CORE_ADDR
alpha_osf_skip_sigtramp_frame (frame, pc)
alpha_osf_skip_sigtramp_frame (frame, pc)
     struct frame_info *frame;
     struct frame_info *frame;
     CORE_ADDR pc;
     CORE_ADDR pc;
{
{
  char *name;
  char *name;
  find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
  find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
  if (IN_SIGTRAMP (pc, name))
  if (IN_SIGTRAMP (pc, name))
    return frame->frame;
    return frame->frame;
  else
  else
    return 0;
    return 0;
}
}


 
 
/* Dynamically create a signal-handler caller procedure descriptor for
/* Dynamically create a signal-handler caller procedure descriptor for
   the signal-handler return code starting at address LOW_ADDR.  The
   the signal-handler return code starting at address LOW_ADDR.  The
   descriptor is added to the linked_proc_desc_table.  */
   descriptor is added to the linked_proc_desc_table.  */
 
 
static alpha_extra_func_info_t
static alpha_extra_func_info_t
push_sigtramp_desc (low_addr)
push_sigtramp_desc (low_addr)
     CORE_ADDR low_addr;
     CORE_ADDR low_addr;
{
{
  struct linked_proc_info *link;
  struct linked_proc_info *link;
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
 
 
  link = (struct linked_proc_info *)
  link = (struct linked_proc_info *)
    xmalloc (sizeof (struct linked_proc_info));
    xmalloc (sizeof (struct linked_proc_info));
  link->next = linked_proc_desc_table;
  link->next = linked_proc_desc_table;
  linked_proc_desc_table = link;
  linked_proc_desc_table = link;
 
 
  proc_desc = &link->info;
  proc_desc = &link->info;
 
 
  proc_desc->numargs = 0;
  proc_desc->numargs = 0;
  PROC_LOW_ADDR (proc_desc) = low_addr;
  PROC_LOW_ADDR (proc_desc) = low_addr;
  PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
  PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
  PROC_DUMMY_FRAME (proc_desc) = 0;
  PROC_DUMMY_FRAME (proc_desc) = 0;
  PROC_FRAME_OFFSET (proc_desc) = 0x298;        /* sizeof(struct sigcontext_struct) */
  PROC_FRAME_OFFSET (proc_desc) = 0x298;        /* sizeof(struct sigcontext_struct) */
  PROC_FRAME_REG (proc_desc) = SP_REGNUM;
  PROC_FRAME_REG (proc_desc) = SP_REGNUM;
  PROC_REG_MASK (proc_desc) = 0xffff;
  PROC_REG_MASK (proc_desc) = 0xffff;
  PROC_FREG_MASK (proc_desc) = 0xffff;
  PROC_FREG_MASK (proc_desc) = 0xffff;
  PROC_PC_REG (proc_desc) = 26;
  PROC_PC_REG (proc_desc) = 26;
  PROC_LOCALOFF (proc_desc) = 0;
  PROC_LOCALOFF (proc_desc) = 0;
  SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
  SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
  return (proc_desc);
  return (proc_desc);
}
}


 
 
/* Guaranteed to set frame->saved_regs to some values (it never leaves it
/* Guaranteed to set frame->saved_regs to some values (it never leaves it
   NULL).  */
   NULL).  */
 
 
void
void
alpha_find_saved_regs (frame)
alpha_find_saved_regs (frame)
     struct frame_info *frame;
     struct frame_info *frame;
{
{
  int ireg;
  int ireg;
  CORE_ADDR reg_position;
  CORE_ADDR reg_position;
  unsigned long mask;
  unsigned long mask;
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
  int returnreg;
  int returnreg;
 
 
  frame_saved_regs_zalloc (frame);
  frame_saved_regs_zalloc (frame);
 
 
  /* If it is the frame for __sigtramp, the saved registers are located
  /* If it is the frame for __sigtramp, the saved registers are located
     in a sigcontext structure somewhere on the stack. __sigtramp
     in a sigcontext structure somewhere on the stack. __sigtramp
     passes a pointer to the sigcontext structure on the stack.
     passes a pointer to the sigcontext structure on the stack.
     If the stack layout for __sigtramp changes, or if sigcontext offsets
     If the stack layout for __sigtramp changes, or if sigcontext offsets
     change, we might have to update this code.  */
     change, we might have to update this code.  */
#ifndef SIGFRAME_PC_OFF
#ifndef SIGFRAME_PC_OFF
#define SIGFRAME_PC_OFF         (2 * 8)
#define SIGFRAME_PC_OFF         (2 * 8)
#define SIGFRAME_REGSAVE_OFF    (4 * 8)
#define SIGFRAME_REGSAVE_OFF    (4 * 8)
#define SIGFRAME_FPREGSAVE_OFF  (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
#define SIGFRAME_FPREGSAVE_OFF  (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
#endif
#endif
  if (frame->signal_handler_caller)
  if (frame->signal_handler_caller)
    {
    {
      CORE_ADDR sigcontext_addr;
      CORE_ADDR sigcontext_addr;
 
 
      sigcontext_addr = SIGCONTEXT_ADDR (frame);
      sigcontext_addr = SIGCONTEXT_ADDR (frame);
      for (ireg = 0; ireg < 32; ireg++)
      for (ireg = 0; ireg < 32; ireg++)
        {
        {
          reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
          reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
          frame->saved_regs[ireg] = reg_position;
          frame->saved_regs[ireg] = reg_position;
        }
        }
      for (ireg = 0; ireg < 32; ireg++)
      for (ireg = 0; ireg < 32; ireg++)
        {
        {
          reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
          reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
          frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
          frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
        }
        }
      frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
      frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
      return;
      return;
    }
    }
 
 
  proc_desc = frame->proc_desc;
  proc_desc = frame->proc_desc;
  if (proc_desc == NULL)
  if (proc_desc == NULL)
    /* I'm not sure how/whether this can happen.  Normally when we can't
    /* I'm not sure how/whether this can happen.  Normally when we can't
       find a proc_desc, we "synthesize" one using heuristic_proc_desc
       find a proc_desc, we "synthesize" one using heuristic_proc_desc
       and set the saved_regs right away.  */
       and set the saved_regs right away.  */
    return;
    return;
 
 
  /* Fill in the offsets for the registers which gen_mask says
  /* Fill in the offsets for the registers which gen_mask says
     were saved.  */
     were saved.  */
 
 
  reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
  reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
  mask = PROC_REG_MASK (proc_desc);
  mask = PROC_REG_MASK (proc_desc);
 
 
  returnreg = PROC_PC_REG (proc_desc);
  returnreg = PROC_PC_REG (proc_desc);
 
 
  /* Note that RA is always saved first, regardless of its actual
  /* Note that RA is always saved first, regardless of its actual
     register number.  */
     register number.  */
  if (mask & (1 << returnreg))
  if (mask & (1 << returnreg))
    {
    {
      frame->saved_regs[returnreg] = reg_position;
      frame->saved_regs[returnreg] = reg_position;
      reg_position += 8;
      reg_position += 8;
      mask &= ~(1 << returnreg);        /* Clear bit for RA so we
      mask &= ~(1 << returnreg);        /* Clear bit for RA so we
                                           don't save again later. */
                                           don't save again later. */
    }
    }
 
 
  for (ireg = 0; ireg <= 31; ++ireg)
  for (ireg = 0; ireg <= 31; ++ireg)
    if (mask & (1 << ireg))
    if (mask & (1 << ireg))
      {
      {
        frame->saved_regs[ireg] = reg_position;
        frame->saved_regs[ireg] = reg_position;
        reg_position += 8;
        reg_position += 8;
      }
      }
 
 
  /* Fill in the offsets for the registers which float_mask says
  /* Fill in the offsets for the registers which float_mask says
     were saved.  */
     were saved.  */
 
 
  reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
  reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
  mask = PROC_FREG_MASK (proc_desc);
  mask = PROC_FREG_MASK (proc_desc);
 
 
  for (ireg = 0; ireg <= 31; ++ireg)
  for (ireg = 0; ireg <= 31; ++ireg)
    if (mask & (1 << ireg))
    if (mask & (1 << ireg))
      {
      {
        frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
        frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
        reg_position += 8;
        reg_position += 8;
      }
      }
 
 
  frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
  frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
}
}
 
 
static CORE_ADDR
static CORE_ADDR
read_next_frame_reg (fi, regno)
read_next_frame_reg (fi, regno)
     struct frame_info *fi;
     struct frame_info *fi;
     int regno;
     int regno;
{
{
  for (; fi; fi = fi->next)
  for (; fi; fi = fi->next)
    {
    {
      /* We have to get the saved sp from the sigcontext
      /* We have to get the saved sp from the sigcontext
         if it is a signal handler frame.  */
         if it is a signal handler frame.  */
      if (regno == SP_REGNUM && !fi->signal_handler_caller)
      if (regno == SP_REGNUM && !fi->signal_handler_caller)
        return fi->frame;
        return fi->frame;
      else
      else
        {
        {
          if (fi->saved_regs == NULL)
          if (fi->saved_regs == NULL)
            alpha_find_saved_regs (fi);
            alpha_find_saved_regs (fi);
          if (fi->saved_regs[regno])
          if (fi->saved_regs[regno])
            return read_memory_integer (fi->saved_regs[regno], 8);
            return read_memory_integer (fi->saved_regs[regno], 8);
        }
        }
    }
    }
  return read_register (regno);
  return read_register (regno);
}
}
 
 
CORE_ADDR
CORE_ADDR
alpha_frame_saved_pc (frame)
alpha_frame_saved_pc (frame)
     struct frame_info *frame;
     struct frame_info *frame;
{
{
  alpha_extra_func_info_t proc_desc = frame->proc_desc;
  alpha_extra_func_info_t proc_desc = frame->proc_desc;
  /* We have to get the saved pc from the sigcontext
  /* We have to get the saved pc from the sigcontext
     if it is a signal handler frame.  */
     if it is a signal handler frame.  */
  int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
  int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
 
 
  if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
  if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
    return read_memory_integer (frame->frame - 8, 8);
    return read_memory_integer (frame->frame - 8, 8);
 
 
  return read_next_frame_reg (frame, pcreg);
  return read_next_frame_reg (frame, pcreg);
}
}
 
 
CORE_ADDR
CORE_ADDR
alpha_saved_pc_after_call (frame)
alpha_saved_pc_after_call (frame)
     struct frame_info *frame;
     struct frame_info *frame;
{
{
  CORE_ADDR pc = frame->pc;
  CORE_ADDR pc = frame->pc;
  CORE_ADDR tmp;
  CORE_ADDR tmp;
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
  int pcreg;
  int pcreg;
 
 
  /* Skip over shared library trampoline if necessary.  */
  /* Skip over shared library trampoline if necessary.  */
  tmp = SKIP_TRAMPOLINE_CODE (pc);
  tmp = SKIP_TRAMPOLINE_CODE (pc);
  if (tmp != 0)
  if (tmp != 0)
    pc = tmp;
    pc = tmp;
 
 
  proc_desc = find_proc_desc (pc, frame->next);
  proc_desc = find_proc_desc (pc, frame->next);
  pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
  pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
 
 
  if (frame->signal_handler_caller)
  if (frame->signal_handler_caller)
    return alpha_frame_saved_pc (frame);
    return alpha_frame_saved_pc (frame);
  else
  else
    return read_register (pcreg);
    return read_register (pcreg);
}
}
 
 
 
 
static struct alpha_extra_func_info temp_proc_desc;
static struct alpha_extra_func_info temp_proc_desc;
static struct frame_saved_regs temp_saved_regs;
static struct frame_saved_regs temp_saved_regs;
 
 
/* Nonzero if instruction at PC is a return instruction.  "ret
/* Nonzero if instruction at PC is a return instruction.  "ret
   $zero,($ra),1" on alpha. */
   $zero,($ra),1" on alpha. */
 
 
static int
static int
alpha_about_to_return (pc)
alpha_about_to_return (pc)
     CORE_ADDR pc;
     CORE_ADDR pc;
{
{
  return read_memory_integer (pc, 4) == 0x6bfa8001;
  return read_memory_integer (pc, 4) == 0x6bfa8001;
}
}
 
 
 
 
 
 
/* This fencepost looks highly suspicious to me.  Removing it also
/* This fencepost looks highly suspicious to me.  Removing it also
   seems suspicious as it could affect remote debugging across serial
   seems suspicious as it could affect remote debugging across serial
   lines.  */
   lines.  */
 
 
static CORE_ADDR
static CORE_ADDR
heuristic_proc_start (pc)
heuristic_proc_start (pc)
     CORE_ADDR pc;
     CORE_ADDR pc;
{
{
  CORE_ADDR start_pc = pc;
  CORE_ADDR start_pc = pc;
  CORE_ADDR fence = start_pc - heuristic_fence_post;
  CORE_ADDR fence = start_pc - heuristic_fence_post;
 
 
  if (start_pc == 0)
  if (start_pc == 0)
    return 0;
    return 0;
 
 
  if (heuristic_fence_post == UINT_MAX
  if (heuristic_fence_post == UINT_MAX
      || fence < VM_MIN_ADDRESS)
      || fence < VM_MIN_ADDRESS)
    fence = VM_MIN_ADDRESS;
    fence = VM_MIN_ADDRESS;
 
 
  /* search back for previous return */
  /* search back for previous return */
  for (start_pc -= 4;; start_pc -= 4)
  for (start_pc -= 4;; start_pc -= 4)
    if (start_pc < fence)
    if (start_pc < fence)
      {
      {
        /* It's not clear to me why we reach this point when
        /* It's not clear to me why we reach this point when
           stop_soon_quietly, but with this test, at least we
           stop_soon_quietly, but with this test, at least we
           don't print out warnings for every child forked (eg, on
           don't print out warnings for every child forked (eg, on
           decstation).  22apr93 rich@cygnus.com.  */
           decstation).  22apr93 rich@cygnus.com.  */
        if (!stop_soon_quietly)
        if (!stop_soon_quietly)
          {
          {
            static int blurb_printed = 0;
            static int blurb_printed = 0;
 
 
            if (fence == VM_MIN_ADDRESS)
            if (fence == VM_MIN_ADDRESS)
              warning ("Hit beginning of text section without finding");
              warning ("Hit beginning of text section without finding");
            else
            else
              warning ("Hit heuristic-fence-post without finding");
              warning ("Hit heuristic-fence-post without finding");
 
 
            warning ("enclosing function for address 0x%s", paddr_nz (pc));
            warning ("enclosing function for address 0x%s", paddr_nz (pc));
            if (!blurb_printed)
            if (!blurb_printed)
              {
              {
                printf_filtered ("\
                printf_filtered ("\
This warning occurs if you are debugging a function without any symbols\n\
This warning occurs if you are debugging a function without any symbols\n\
(for example, in a stripped executable).  In that case, you may wish to\n\
(for example, in a stripped executable).  In that case, you may wish to\n\
increase the size of the search with the `set heuristic-fence-post' command.\n\
increase the size of the search with the `set heuristic-fence-post' command.\n\
\n\
\n\
Otherwise, you told GDB there was a function where there isn't one, or\n\
Otherwise, you told GDB there was a function where there isn't one, or\n\
(more likely) you have encountered a bug in GDB.\n");
(more likely) you have encountered a bug in GDB.\n");
                blurb_printed = 1;
                blurb_printed = 1;
              }
              }
          }
          }
 
 
        return 0;
        return 0;
      }
      }
    else if (alpha_about_to_return (start_pc))
    else if (alpha_about_to_return (start_pc))
      break;
      break;
 
 
  start_pc += 4;                /* skip return */
  start_pc += 4;                /* skip return */
  return start_pc;
  return start_pc;
}
}
 
 
static alpha_extra_func_info_t
static alpha_extra_func_info_t
heuristic_proc_desc (start_pc, limit_pc, next_frame)
heuristic_proc_desc (start_pc, limit_pc, next_frame)
     CORE_ADDR start_pc, limit_pc;
     CORE_ADDR start_pc, limit_pc;
     struct frame_info *next_frame;
     struct frame_info *next_frame;
{
{
  CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
  CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
  CORE_ADDR cur_pc;
  CORE_ADDR cur_pc;
  int frame_size;
  int frame_size;
  int has_frame_reg = 0;
  int has_frame_reg = 0;
  unsigned long reg_mask = 0;
  unsigned long reg_mask = 0;
  int pcreg = -1;
  int pcreg = -1;
 
 
  if (start_pc == 0)
  if (start_pc == 0)
    return NULL;
    return NULL;
  memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
  memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
  memset (&temp_saved_regs, '\0', sizeof (struct frame_saved_regs));
  memset (&temp_saved_regs, '\0', sizeof (struct frame_saved_regs));
  PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
  PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
 
 
  if (start_pc + 200 < limit_pc)
  if (start_pc + 200 < limit_pc)
    limit_pc = start_pc + 200;
    limit_pc = start_pc + 200;
  frame_size = 0;
  frame_size = 0;
  for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
  for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
    {
    {
      char buf[4];
      char buf[4];
      unsigned long word;
      unsigned long word;
      int status;
      int status;
 
 
      status = read_memory_nobpt (cur_pc, buf, 4);
      status = read_memory_nobpt (cur_pc, buf, 4);
      if (status)
      if (status)
        memory_error (status, cur_pc);
        memory_error (status, cur_pc);
      word = extract_unsigned_integer (buf, 4);
      word = extract_unsigned_integer (buf, 4);
 
 
      if ((word & 0xffff0000) == 0x23de0000)    /* lda $sp,n($sp) */
      if ((word & 0xffff0000) == 0x23de0000)    /* lda $sp,n($sp) */
        {
        {
          if (word & 0x8000)
          if (word & 0x8000)
            frame_size += (-word) & 0xffff;
            frame_size += (-word) & 0xffff;
          else
          else
            /* Exit loop if a positive stack adjustment is found, which
            /* Exit loop if a positive stack adjustment is found, which
               usually means that the stack cleanup code in the function
               usually means that the stack cleanup code in the function
               epilogue is reached.  */
               epilogue is reached.  */
            break;
            break;
        }
        }
      else if ((word & 0xfc1f0000) == 0xb41e0000        /* stq reg,n($sp) */
      else if ((word & 0xfc1f0000) == 0xb41e0000        /* stq reg,n($sp) */
               && (word & 0xffff0000) != 0xb7fe0000)    /* reg != $zero */
               && (word & 0xffff0000) != 0xb7fe0000)    /* reg != $zero */
        {
        {
          int reg = (word & 0x03e00000) >> 21;
          int reg = (word & 0x03e00000) >> 21;
          reg_mask |= 1 << reg;
          reg_mask |= 1 << reg;
          temp_saved_regs.regs[reg] = sp + (short) word;
          temp_saved_regs.regs[reg] = sp + (short) word;
 
 
          /* Starting with OSF/1-3.2C, the system libraries are shipped
          /* Starting with OSF/1-3.2C, the system libraries are shipped
             without local symbols, but they still contain procedure
             without local symbols, but they still contain procedure
             descriptors without a symbol reference. GDB is currently
             descriptors without a symbol reference. GDB is currently
             unable to find these procedure descriptors and uses
             unable to find these procedure descriptors and uses
             heuristic_proc_desc instead.
             heuristic_proc_desc instead.
             As some low level compiler support routines (__div*, __add*)
             As some low level compiler support routines (__div*, __add*)
             use a non-standard return address register, we have to
             use a non-standard return address register, we have to
             add some heuristics to determine the return address register,
             add some heuristics to determine the return address register,
             or stepping over these routines will fail.
             or stepping over these routines will fail.
             Usually the return address register is the first register
             Usually the return address register is the first register
             saved on the stack, but assembler optimization might
             saved on the stack, but assembler optimization might
             rearrange the register saves.
             rearrange the register saves.
             So we recognize only a few registers (t7, t9, ra) within
             So we recognize only a few registers (t7, t9, ra) within
             the procedure prologue as valid return address registers.
             the procedure prologue as valid return address registers.
             If we encounter a return instruction, we extract the
             If we encounter a return instruction, we extract the
             the return address register from it.
             the return address register from it.
 
 
             FIXME: Rewriting GDB to access the procedure descriptors,
             FIXME: Rewriting GDB to access the procedure descriptors,
             e.g. via the minimal symbol table, might obviate this hack.  */
             e.g. via the minimal symbol table, might obviate this hack.  */
          if (pcreg == -1
          if (pcreg == -1
              && cur_pc < (start_pc + 80)
              && cur_pc < (start_pc + 80)
              && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
              && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
            pcreg = reg;
            pcreg = reg;
        }
        }
      else if ((word & 0xffe0ffff) == 0x6be08001)       /* ret zero,reg,1 */
      else if ((word & 0xffe0ffff) == 0x6be08001)       /* ret zero,reg,1 */
        pcreg = (word >> 16) & 0x1f;
        pcreg = (word >> 16) & 0x1f;
      else if (word == 0x47de040f)      /* bis sp,sp fp */
      else if (word == 0x47de040f)      /* bis sp,sp fp */
        has_frame_reg = 1;
        has_frame_reg = 1;
    }
    }
  if (pcreg == -1)
  if (pcreg == -1)
    {
    {
      /* If we haven't found a valid return address register yet,
      /* If we haven't found a valid return address register yet,
         keep searching in the procedure prologue.  */
         keep searching in the procedure prologue.  */
      while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
      while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
        {
        {
          char buf[4];
          char buf[4];
          unsigned long word;
          unsigned long word;
 
 
          if (read_memory_nobpt (cur_pc, buf, 4))
          if (read_memory_nobpt (cur_pc, buf, 4))
            break;
            break;
          cur_pc += 4;
          cur_pc += 4;
          word = extract_unsigned_integer (buf, 4);
          word = extract_unsigned_integer (buf, 4);
 
 
          if ((word & 0xfc1f0000) == 0xb41e0000         /* stq reg,n($sp) */
          if ((word & 0xfc1f0000) == 0xb41e0000         /* stq reg,n($sp) */
              && (word & 0xffff0000) != 0xb7fe0000)     /* reg != $zero */
              && (word & 0xffff0000) != 0xb7fe0000)     /* reg != $zero */
            {
            {
              int reg = (word & 0x03e00000) >> 21;
              int reg = (word & 0x03e00000) >> 21;
              if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
              if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
                {
                {
                  pcreg = reg;
                  pcreg = reg;
                  break;
                  break;
                }
                }
            }
            }
          else if ((word & 0xffe0ffff) == 0x6be08001)   /* ret zero,reg,1 */
          else if ((word & 0xffe0ffff) == 0x6be08001)   /* ret zero,reg,1 */
            {
            {
              pcreg = (word >> 16) & 0x1f;
              pcreg = (word >> 16) & 0x1f;
              break;
              break;
            }
            }
        }
        }
    }
    }
 
 
  if (has_frame_reg)
  if (has_frame_reg)
    PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
    PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
  else
  else
    PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
    PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
  PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
  PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
  PROC_REG_MASK (&temp_proc_desc) = reg_mask;
  PROC_REG_MASK (&temp_proc_desc) = reg_mask;
  PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
  PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
  PROC_LOCALOFF (&temp_proc_desc) = 0;   /* XXX - bogus */
  PROC_LOCALOFF (&temp_proc_desc) = 0;   /* XXX - bogus */
  return &temp_proc_desc;
  return &temp_proc_desc;
}
}
 
 
/* This returns the PC of the first inst after the prologue.  If we can't
/* This returns the PC of the first inst after the prologue.  If we can't
   find the prologue, then return 0.  */
   find the prologue, then return 0.  */
 
 
static CORE_ADDR
static CORE_ADDR
after_prologue (pc, proc_desc)
after_prologue (pc, proc_desc)
     CORE_ADDR pc;
     CORE_ADDR pc;
     alpha_extra_func_info_t proc_desc;
     alpha_extra_func_info_t proc_desc;
{
{
  struct symtab_and_line sal;
  struct symtab_and_line sal;
  CORE_ADDR func_addr, func_end;
  CORE_ADDR func_addr, func_end;
 
 
  if (!proc_desc)
  if (!proc_desc)
    proc_desc = find_proc_desc (pc, NULL);
    proc_desc = find_proc_desc (pc, NULL);
 
 
  if (proc_desc)
  if (proc_desc)
    {
    {
      if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
      if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
        return PROC_LOW_ADDR (proc_desc);       /* "prologue" is in kernel */
        return PROC_LOW_ADDR (proc_desc);       /* "prologue" is in kernel */
 
 
      /* If function is frameless, then we need to do it the hard way.  I
      /* If function is frameless, then we need to do it the hard way.  I
         strongly suspect that frameless always means prologueless... */
         strongly suspect that frameless always means prologueless... */
      if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
      if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
          && PROC_FRAME_OFFSET (proc_desc) == 0)
          && PROC_FRAME_OFFSET (proc_desc) == 0)
        return 0;
        return 0;
    }
    }
 
 
  if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
    return 0;                    /* Unknown */
    return 0;                    /* Unknown */
 
 
  sal = find_pc_line (func_addr, 0);
  sal = find_pc_line (func_addr, 0);
 
 
  if (sal.end < func_end)
  if (sal.end < func_end)
    return sal.end;
    return sal.end;
 
 
  /* The line after the prologue is after the end of the function.  In this
  /* The line after the prologue is after the end of the function.  In this
     case, tell the caller to find the prologue the hard way.  */
     case, tell the caller to find the prologue the hard way.  */
 
 
  return 0;
  return 0;
}
}
 
 
/* Return non-zero if we *might* be in a function prologue.  Return zero if we
/* Return non-zero if we *might* be in a function prologue.  Return zero if we
   are definitively *not* in a function prologue.  */
   are definitively *not* in a function prologue.  */
 
 
static int
static int
alpha_in_prologue (pc, proc_desc)
alpha_in_prologue (pc, proc_desc)
     CORE_ADDR pc;
     CORE_ADDR pc;
     alpha_extra_func_info_t proc_desc;
     alpha_extra_func_info_t proc_desc;
{
{
  CORE_ADDR after_prologue_pc;
  CORE_ADDR after_prologue_pc;
 
 
  after_prologue_pc = after_prologue (pc, proc_desc);
  after_prologue_pc = after_prologue (pc, proc_desc);
 
 
  if (after_prologue_pc == 0
  if (after_prologue_pc == 0
      || pc < after_prologue_pc)
      || pc < after_prologue_pc)
    return 1;
    return 1;
  else
  else
    return 0;
    return 0;
}
}
 
 
static alpha_extra_func_info_t
static alpha_extra_func_info_t
find_proc_desc (pc, next_frame)
find_proc_desc (pc, next_frame)
     CORE_ADDR pc;
     CORE_ADDR pc;
     struct frame_info *next_frame;
     struct frame_info *next_frame;
{
{
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
  struct block *b;
  struct block *b;
  struct symbol *sym;
  struct symbol *sym;
  CORE_ADDR startaddr;
  CORE_ADDR startaddr;
 
 
  /* Try to get the proc_desc from the linked call dummy proc_descs
  /* Try to get the proc_desc from the linked call dummy proc_descs
     if the pc is in the call dummy.
     if the pc is in the call dummy.
     This is hairy. In the case of nested dummy calls we have to find the
     This is hairy. In the case of nested dummy calls we have to find the
     right proc_desc, but we might not yet know the frame for the dummy
     right proc_desc, but we might not yet know the frame for the dummy
     as it will be contained in the proc_desc we are searching for.
     as it will be contained in the proc_desc we are searching for.
     So we have to find the proc_desc whose frame is closest to the current
     So we have to find the proc_desc whose frame is closest to the current
     stack pointer.  */
     stack pointer.  */
 
 
  if (PC_IN_CALL_DUMMY (pc, 0, 0))
  if (PC_IN_CALL_DUMMY (pc, 0, 0))
    {
    {
      struct linked_proc_info *link;
      struct linked_proc_info *link;
      CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
      CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
      alpha_extra_func_info_t found_proc_desc = NULL;
      alpha_extra_func_info_t found_proc_desc = NULL;
      long min_distance = LONG_MAX;
      long min_distance = LONG_MAX;
 
 
      for (link = linked_proc_desc_table; link; link = link->next)
      for (link = linked_proc_desc_table; link; link = link->next)
        {
        {
          long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
          long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
          if (distance > 0 && distance < min_distance)
          if (distance > 0 && distance < min_distance)
            {
            {
              min_distance = distance;
              min_distance = distance;
              found_proc_desc = &link->info;
              found_proc_desc = &link->info;
            }
            }
        }
        }
      if (found_proc_desc != NULL)
      if (found_proc_desc != NULL)
        return found_proc_desc;
        return found_proc_desc;
    }
    }
 
 
  b = block_for_pc (pc);
  b = block_for_pc (pc);
 
 
  find_pc_partial_function (pc, NULL, &startaddr, NULL);
  find_pc_partial_function (pc, NULL, &startaddr, NULL);
  if (b == NULL)
  if (b == NULL)
    sym = NULL;
    sym = NULL;
  else
  else
    {
    {
      if (startaddr > BLOCK_START (b))
      if (startaddr > BLOCK_START (b))
        /* This is the "pathological" case referred to in a comment in
        /* This is the "pathological" case referred to in a comment in
           print_frame_info.  It might be better to move this check into
           print_frame_info.  It might be better to move this check into
           symbol reading.  */
           symbol reading.  */
        sym = NULL;
        sym = NULL;
      else
      else
        sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
        sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
                             0, NULL);
                             0, NULL);
    }
    }
 
 
  /* If we never found a PDR for this function in symbol reading, then
  /* If we never found a PDR for this function in symbol reading, then
     examine prologues to find the information.  */
     examine prologues to find the information.  */
  if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
  if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
    sym = NULL;
    sym = NULL;
 
 
  if (sym)
  if (sym)
    {
    {
      /* IF this is the topmost frame AND
      /* IF this is the topmost frame AND
       * (this proc does not have debugging information OR
       * (this proc does not have debugging information OR
       * the PC is in the procedure prologue)
       * the PC is in the procedure prologue)
       * THEN create a "heuristic" proc_desc (by analyzing
       * THEN create a "heuristic" proc_desc (by analyzing
       * the actual code) to replace the "official" proc_desc.
       * the actual code) to replace the "official" proc_desc.
       */
       */
      proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
      proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
      if (next_frame == NULL)
      if (next_frame == NULL)
        {
        {
          if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
          if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
            {
            {
              alpha_extra_func_info_t found_heuristic =
              alpha_extra_func_info_t found_heuristic =
              heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
              heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
                                   pc, next_frame);
                                   pc, next_frame);
              if (found_heuristic)
              if (found_heuristic)
                {
                {
                  PROC_LOCALOFF (found_heuristic) =
                  PROC_LOCALOFF (found_heuristic) =
                    PROC_LOCALOFF (proc_desc);
                    PROC_LOCALOFF (proc_desc);
                  PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
                  PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
                  proc_desc = found_heuristic;
                  proc_desc = found_heuristic;
                }
                }
            }
            }
        }
        }
    }
    }
  else
  else
    {
    {
      long offset;
      long offset;
 
 
      /* Is linked_proc_desc_table really necessary?  It only seems to be used
      /* Is linked_proc_desc_table really necessary?  It only seems to be used
         by procedure call dummys.  However, the procedures being called ought
         by procedure call dummys.  However, the procedures being called ought
         to have their own proc_descs, and even if they don't,
         to have their own proc_descs, and even if they don't,
         heuristic_proc_desc knows how to create them! */
         heuristic_proc_desc knows how to create them! */
 
 
      register struct linked_proc_info *link;
      register struct linked_proc_info *link;
      for (link = linked_proc_desc_table; link; link = link->next)
      for (link = linked_proc_desc_table; link; link = link->next)
        if (PROC_LOW_ADDR (&link->info) <= pc
        if (PROC_LOW_ADDR (&link->info) <= pc
            && PROC_HIGH_ADDR (&link->info) > pc)
            && PROC_HIGH_ADDR (&link->info) > pc)
          return &link->info;
          return &link->info;
 
 
      /* If PC is inside a dynamically generated sigtramp handler,
      /* If PC is inside a dynamically generated sigtramp handler,
         create and push a procedure descriptor for that code: */
         create and push a procedure descriptor for that code: */
      offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
      offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
      if (offset >= 0)
      if (offset >= 0)
        return push_sigtramp_desc (pc - offset);
        return push_sigtramp_desc (pc - offset);
 
 
      /* If heuristic_fence_post is non-zero, determine the procedure
      /* If heuristic_fence_post is non-zero, determine the procedure
         start address by examining the instructions.
         start address by examining the instructions.
         This allows us to find the start address of static functions which
         This allows us to find the start address of static functions which
         have no symbolic information, as startaddr would have been set to
         have no symbolic information, as startaddr would have been set to
         the preceding global function start address by the
         the preceding global function start address by the
         find_pc_partial_function call above.  */
         find_pc_partial_function call above.  */
      if (startaddr == 0 || heuristic_fence_post != 0)
      if (startaddr == 0 || heuristic_fence_post != 0)
        startaddr = heuristic_proc_start (pc);
        startaddr = heuristic_proc_start (pc);
 
 
      proc_desc =
      proc_desc =
        heuristic_proc_desc (startaddr, pc, next_frame);
        heuristic_proc_desc (startaddr, pc, next_frame);
    }
    }
  return proc_desc;
  return proc_desc;
}
}
 
 
alpha_extra_func_info_t cached_proc_desc;
alpha_extra_func_info_t cached_proc_desc;
 
 
CORE_ADDR
CORE_ADDR
alpha_frame_chain (frame)
alpha_frame_chain (frame)
     struct frame_info *frame;
     struct frame_info *frame;
{
{
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
  CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
  CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
 
 
  if (saved_pc == 0 || inside_entry_file (saved_pc))
  if (saved_pc == 0 || inside_entry_file (saved_pc))
    return 0;
    return 0;
 
 
  proc_desc = find_proc_desc (saved_pc, frame);
  proc_desc = find_proc_desc (saved_pc, frame);
  if (!proc_desc)
  if (!proc_desc)
    return 0;
    return 0;
 
 
  cached_proc_desc = proc_desc;
  cached_proc_desc = proc_desc;
 
 
  /* Fetch the frame pointer for a dummy frame from the procedure
  /* Fetch the frame pointer for a dummy frame from the procedure
     descriptor.  */
     descriptor.  */
  if (PROC_DESC_IS_DUMMY (proc_desc))
  if (PROC_DESC_IS_DUMMY (proc_desc))
    return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
    return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
 
 
  /* If no frame pointer and frame size is zero, we must be at end
  /* If no frame pointer and frame size is zero, we must be at end
     of stack (or otherwise hosed).  If we don't check frame size,
     of stack (or otherwise hosed).  If we don't check frame size,
     we loop forever if we see a zero size frame.  */
     we loop forever if we see a zero size frame.  */
  if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
  if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
      && PROC_FRAME_OFFSET (proc_desc) == 0
      && PROC_FRAME_OFFSET (proc_desc) == 0
  /* The previous frame from a sigtramp frame might be frameless
  /* The previous frame from a sigtramp frame might be frameless
     and have frame size zero.  */
     and have frame size zero.  */
      && !frame->signal_handler_caller)
      && !frame->signal_handler_caller)
    return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
    return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
  else
  else
    return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
    return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
      + PROC_FRAME_OFFSET (proc_desc);
      + PROC_FRAME_OFFSET (proc_desc);
}
}
 
 
void
void
init_extra_frame_info (frame)
init_extra_frame_info (frame)
     struct frame_info *frame;
     struct frame_info *frame;
{
{
  /* Use proc_desc calculated in frame_chain */
  /* Use proc_desc calculated in frame_chain */
  alpha_extra_func_info_t proc_desc =
  alpha_extra_func_info_t proc_desc =
  frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
  frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
 
 
  frame->saved_regs = NULL;
  frame->saved_regs = NULL;
  frame->localoff = 0;
  frame->localoff = 0;
  frame->pc_reg = RA_REGNUM;
  frame->pc_reg = RA_REGNUM;
  frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
  frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
  if (proc_desc)
  if (proc_desc)
    {
    {
      /* Get the locals offset and the saved pc register from the
      /* Get the locals offset and the saved pc register from the
         procedure descriptor, they are valid even if we are in the
         procedure descriptor, they are valid even if we are in the
         middle of the prologue.  */
         middle of the prologue.  */
      frame->localoff = PROC_LOCALOFF (proc_desc);
      frame->localoff = PROC_LOCALOFF (proc_desc);
      frame->pc_reg = PROC_PC_REG (proc_desc);
      frame->pc_reg = PROC_PC_REG (proc_desc);
 
 
      /* Fixup frame-pointer - only needed for top frame */
      /* Fixup frame-pointer - only needed for top frame */
 
 
      /* Fetch the frame pointer for a dummy frame from the procedure
      /* Fetch the frame pointer for a dummy frame from the procedure
         descriptor.  */
         descriptor.  */
      if (PROC_DESC_IS_DUMMY (proc_desc))
      if (PROC_DESC_IS_DUMMY (proc_desc))
        frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
        frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
 
 
      /* This may not be quite right, if proc has a real frame register.
      /* This may not be quite right, if proc has a real frame register.
         Get the value of the frame relative sp, procedure might have been
         Get the value of the frame relative sp, procedure might have been
         interrupted by a signal at it's very start.  */
         interrupted by a signal at it's very start.  */
      else if (frame->pc == PROC_LOW_ADDR (proc_desc)
      else if (frame->pc == PROC_LOW_ADDR (proc_desc)
               && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
               && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
        frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
        frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
      else
      else
        frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
        frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
          + PROC_FRAME_OFFSET (proc_desc);
          + PROC_FRAME_OFFSET (proc_desc);
 
 
      if (proc_desc == &temp_proc_desc)
      if (proc_desc == &temp_proc_desc)
        {
        {
          char *name;
          char *name;
 
 
          /* Do not set the saved registers for a sigtramp frame,
          /* Do not set the saved registers for a sigtramp frame,
             alpha_find_saved_registers will do that for us.
             alpha_find_saved_registers will do that for us.
             We can't use frame->signal_handler_caller, it is not yet set.  */
             We can't use frame->signal_handler_caller, it is not yet set.  */
          find_pc_partial_function (frame->pc, &name,
          find_pc_partial_function (frame->pc, &name,
                                    (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
                                    (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
          if (!IN_SIGTRAMP (frame->pc, name))
          if (!IN_SIGTRAMP (frame->pc, name))
            {
            {
              frame->saved_regs = (CORE_ADDR *)
              frame->saved_regs = (CORE_ADDR *)
                frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
                frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
              memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
              memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
              frame->saved_regs[PC_REGNUM]
              frame->saved_regs[PC_REGNUM]
                = frame->saved_regs[RA_REGNUM];
                = frame->saved_regs[RA_REGNUM];
            }
            }
        }
        }
    }
    }
}
}
 
 
/* ALPHA stack frames are almost impenetrable.  When execution stops,
/* ALPHA stack frames are almost impenetrable.  When execution stops,
   we basically have to look at symbol information for the function
   we basically have to look at symbol information for the function
   that we stopped in, which tells us *which* register (if any) is
   that we stopped in, which tells us *which* register (if any) is
   the base of the frame pointer, and what offset from that register
   the base of the frame pointer, and what offset from that register
   the frame itself is at.
   the frame itself is at.
 
 
   This presents a problem when trying to examine a stack in memory
   This presents a problem when trying to examine a stack in memory
   (that isn't executing at the moment), using the "frame" command.  We
   (that isn't executing at the moment), using the "frame" command.  We
   don't have a PC, nor do we have any registers except SP.
   don't have a PC, nor do we have any registers except SP.
 
 
   This routine takes two arguments, SP and PC, and tries to make the
   This routine takes two arguments, SP and PC, and tries to make the
   cached frames look as if these two arguments defined a frame on the
   cached frames look as if these two arguments defined a frame on the
   cache.  This allows the rest of info frame to extract the important
   cache.  This allows the rest of info frame to extract the important
   arguments without difficulty.  */
   arguments without difficulty.  */
 
 
struct frame_info *
struct frame_info *
setup_arbitrary_frame (argc, argv)
setup_arbitrary_frame (argc, argv)
     int argc;
     int argc;
     CORE_ADDR *argv;
     CORE_ADDR *argv;
{
{
  if (argc != 2)
  if (argc != 2)
    error ("ALPHA frame specifications require two arguments: sp and pc");
    error ("ALPHA frame specifications require two arguments: sp and pc");
 
 
  return create_new_frame (argv[0], argv[1]);
  return create_new_frame (argv[0], argv[1]);
}
}
 
 
/* The alpha passes the first six arguments in the registers, the rest on
/* The alpha passes the first six arguments in the registers, the rest on
   the stack. The register arguments are eventually transferred to the
   the stack. The register arguments are eventually transferred to the
   argument transfer area immediately below the stack by the called function
   argument transfer area immediately below the stack by the called function
   anyway. So we `push' at least six arguments on the stack, `reload' the
   anyway. So we `push' at least six arguments on the stack, `reload' the
   argument registers and then adjust the stack pointer to point past the
   argument registers and then adjust the stack pointer to point past the
   sixth argument. This algorithm simplifies the passing of a large struct
   sixth argument. This algorithm simplifies the passing of a large struct
   which extends from the registers to the stack.
   which extends from the registers to the stack.
   If the called function is returning a structure, the address of the
   If the called function is returning a structure, the address of the
   structure to be returned is passed as a hidden first argument.  */
   structure to be returned is passed as a hidden first argument.  */
 
 
CORE_ADDR
CORE_ADDR
alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
     int nargs;
     int nargs;
     value_ptr *args;
     value_ptr *args;
     CORE_ADDR sp;
     CORE_ADDR sp;
     int struct_return;
     int struct_return;
     CORE_ADDR struct_addr;
     CORE_ADDR struct_addr;
{
{
  int i;
  int i;
  int accumulate_size = struct_return ? 8 : 0;
  int accumulate_size = struct_return ? 8 : 0;
  int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
  int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
  struct alpha_arg
  struct alpha_arg
    {
    {
      char *contents;
      char *contents;
      int len;
      int len;
      int offset;
      int offset;
    };
    };
  struct alpha_arg *alpha_args =
  struct alpha_arg *alpha_args =
  (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
  (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
  register struct alpha_arg *m_arg;
  register struct alpha_arg *m_arg;
  char raw_buffer[sizeof (CORE_ADDR)];
  char raw_buffer[sizeof (CORE_ADDR)];
  int required_arg_regs;
  int required_arg_regs;
 
 
  for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
  for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
    {
    {
      value_ptr arg = args[i];
      value_ptr arg = args[i];
      struct type *arg_type = check_typedef (VALUE_TYPE (arg));
      struct type *arg_type = check_typedef (VALUE_TYPE (arg));
      /* Cast argument to long if necessary as the compiler does it too.  */
      /* Cast argument to long if necessary as the compiler does it too.  */
      switch (TYPE_CODE (arg_type))
      switch (TYPE_CODE (arg_type))
        {
        {
        case TYPE_CODE_INT:
        case TYPE_CODE_INT:
        case TYPE_CODE_BOOL:
        case TYPE_CODE_BOOL:
        case TYPE_CODE_CHAR:
        case TYPE_CODE_CHAR:
        case TYPE_CODE_RANGE:
        case TYPE_CODE_RANGE:
        case TYPE_CODE_ENUM:
        case TYPE_CODE_ENUM:
          if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
          if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
            {
            {
              arg_type = builtin_type_long;
              arg_type = builtin_type_long;
              arg = value_cast (arg_type, arg);
              arg = value_cast (arg_type, arg);
            }
            }
          break;
          break;
        default:
        default:
          break;
          break;
        }
        }
      m_arg->len = TYPE_LENGTH (arg_type);
      m_arg->len = TYPE_LENGTH (arg_type);
      m_arg->offset = accumulate_size;
      m_arg->offset = accumulate_size;
      accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
      accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
      m_arg->contents = VALUE_CONTENTS (arg);
      m_arg->contents = VALUE_CONTENTS (arg);
    }
    }
 
 
  /* Determine required argument register loads, loading an argument register
  /* Determine required argument register loads, loading an argument register
     is expensive as it uses three ptrace calls.  */
     is expensive as it uses three ptrace calls.  */
  required_arg_regs = accumulate_size / 8;
  required_arg_regs = accumulate_size / 8;
  if (required_arg_regs > ALPHA_NUM_ARG_REGS)
  if (required_arg_regs > ALPHA_NUM_ARG_REGS)
    required_arg_regs = ALPHA_NUM_ARG_REGS;
    required_arg_regs = ALPHA_NUM_ARG_REGS;
 
 
  /* Make room for the arguments on the stack.  */
  /* Make room for the arguments on the stack.  */
  if (accumulate_size < arg_regs_size)
  if (accumulate_size < arg_regs_size)
    accumulate_size = arg_regs_size;
    accumulate_size = arg_regs_size;
  sp -= accumulate_size;
  sp -= accumulate_size;
 
 
  /* Keep sp aligned to a multiple of 16 as the compiler does it too.  */
  /* Keep sp aligned to a multiple of 16 as the compiler does it too.  */
  sp &= ~15;
  sp &= ~15;
 
 
  /* `Push' arguments on the stack.  */
  /* `Push' arguments on the stack.  */
  for (i = nargs; m_arg--, --i >= 0;)
  for (i = nargs; m_arg--, --i >= 0;)
    write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
    write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
  if (struct_return)
  if (struct_return)
    {
    {
      store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
      store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
      write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
      write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
    }
    }
 
 
  /* Load the argument registers.  */
  /* Load the argument registers.  */
  for (i = 0; i < required_arg_regs; i++)
  for (i = 0; i < required_arg_regs; i++)
    {
    {
      LONGEST val;
      LONGEST val;
 
 
      val = read_memory_integer (sp + i * 8, 8);
      val = read_memory_integer (sp + i * 8, 8);
      write_register (A0_REGNUM + i, val);
      write_register (A0_REGNUM + i, val);
      write_register (FPA0_REGNUM + i, val);
      write_register (FPA0_REGNUM + i, val);
    }
    }
 
 
  return sp + arg_regs_size;
  return sp + arg_regs_size;
}
}
 
 
void
void
alpha_push_dummy_frame ()
alpha_push_dummy_frame ()
{
{
  int ireg;
  int ireg;
  struct linked_proc_info *link;
  struct linked_proc_info *link;
  alpha_extra_func_info_t proc_desc;
  alpha_extra_func_info_t proc_desc;
  CORE_ADDR sp = read_register (SP_REGNUM);
  CORE_ADDR sp = read_register (SP_REGNUM);
  CORE_ADDR save_address;
  CORE_ADDR save_address;
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
  unsigned long mask;
  unsigned long mask;
 
 
  link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
  link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
  link->next = linked_proc_desc_table;
  link->next = linked_proc_desc_table;
  linked_proc_desc_table = link;
  linked_proc_desc_table = link;
 
 
  proc_desc = &link->info;
  proc_desc = &link->info;
 
 
  /*
  /*
   * The registers we must save are all those not preserved across
   * The registers we must save are all those not preserved across
   * procedure calls.
   * procedure calls.
   * In addition, we must save the PC and RA.
   * In addition, we must save the PC and RA.
   *
   *
   * Dummy frame layout:
   * Dummy frame layout:
   *  (high memory)
   *  (high memory)
   *    Saved PC
   *    Saved PC
   *    Saved F30
   *    Saved F30
   *    ...
   *    ...
   *    Saved F0
   *    Saved F0
   *    Saved R29
   *    Saved R29
   *    ...
   *    ...
   *    Saved R0
   *    Saved R0
   *    Saved R26 (RA)
   *    Saved R26 (RA)
   *    Parameter build area
   *    Parameter build area
   *  (low memory)
   *  (low memory)
   */
   */
 
 
/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
#define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
#define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
#define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
#define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
#define GEN_REG_SAVE_COUNT 24
#define GEN_REG_SAVE_COUNT 24
#define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
#define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
#define FLOAT_REG_SAVE_COUNT 23
#define FLOAT_REG_SAVE_COUNT 23
  /* The special register is the PC as we have no bit for it in the save masks.
  /* The special register is the PC as we have no bit for it in the save masks.
     alpha_frame_saved_pc knows where the pc is saved in a dummy frame.  */
     alpha_frame_saved_pc knows where the pc is saved in a dummy frame.  */
#define SPECIAL_REG_SAVE_COUNT 1
#define SPECIAL_REG_SAVE_COUNT 1
 
 
  PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
  PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
  PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
  PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
  /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
  /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
     but keep SP aligned to a multiple of 16.  */
     but keep SP aligned to a multiple of 16.  */
  PROC_REG_OFFSET (proc_desc) =
  PROC_REG_OFFSET (proc_desc) =
    -((8 * (SPECIAL_REG_SAVE_COUNT
    -((8 * (SPECIAL_REG_SAVE_COUNT
            + GEN_REG_SAVE_COUNT
            + GEN_REG_SAVE_COUNT
            + FLOAT_REG_SAVE_COUNT)
            + FLOAT_REG_SAVE_COUNT)
       + 15) & ~15);
       + 15) & ~15);
  PROC_FREG_OFFSET (proc_desc) =
  PROC_FREG_OFFSET (proc_desc) =
    PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
    PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
 
 
  /* Save general registers.
  /* Save general registers.
     The return address register is the first saved register, all other
     The return address register is the first saved register, all other
     registers follow in ascending order.
     registers follow in ascending order.
     The PC is saved immediately below the SP.  */
     The PC is saved immediately below the SP.  */
  save_address = sp + PROC_REG_OFFSET (proc_desc);
  save_address = sp + PROC_REG_OFFSET (proc_desc);
  store_address (raw_buffer, 8, read_register (RA_REGNUM));
  store_address (raw_buffer, 8, read_register (RA_REGNUM));
  write_memory (save_address, raw_buffer, 8);
  write_memory (save_address, raw_buffer, 8);
  save_address += 8;
  save_address += 8;
  mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
  mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
  for (ireg = 0; mask; ireg++, mask >>= 1)
  for (ireg = 0; mask; ireg++, mask >>= 1)
    if (mask & 1)
    if (mask & 1)
      {
      {
        if (ireg == RA_REGNUM)
        if (ireg == RA_REGNUM)
          continue;
          continue;
        store_address (raw_buffer, 8, read_register (ireg));
        store_address (raw_buffer, 8, read_register (ireg));
        write_memory (save_address, raw_buffer, 8);
        write_memory (save_address, raw_buffer, 8);
        save_address += 8;
        save_address += 8;
      }
      }
 
 
  store_address (raw_buffer, 8, read_register (PC_REGNUM));
  store_address (raw_buffer, 8, read_register (PC_REGNUM));
  write_memory (sp - 8, raw_buffer, 8);
  write_memory (sp - 8, raw_buffer, 8);
 
 
  /* Save floating point registers.  */
  /* Save floating point registers.  */
  save_address = sp + PROC_FREG_OFFSET (proc_desc);
  save_address = sp + PROC_FREG_OFFSET (proc_desc);
  mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
  mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
  for (ireg = 0; mask; ireg++, mask >>= 1)
  for (ireg = 0; mask; ireg++, mask >>= 1)
    if (mask & 1)
    if (mask & 1)
      {
      {
        store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
        store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
        write_memory (save_address, raw_buffer, 8);
        write_memory (save_address, raw_buffer, 8);
        save_address += 8;
        save_address += 8;
      }
      }
 
 
  /* Set and save the frame address for the dummy.
  /* Set and save the frame address for the dummy.
     This is tricky. The only registers that are suitable for a frame save
     This is tricky. The only registers that are suitable for a frame save
     are those that are preserved across procedure calls (s0-s6). But if
     are those that are preserved across procedure calls (s0-s6). But if
     a read system call is interrupted and then a dummy call is made
     a read system call is interrupted and then a dummy call is made
     (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
     (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
     is satisfied. Then it returns with the s0-s6 registers set to the values
     is satisfied. Then it returns with the s0-s6 registers set to the values
     on entry to the read system call and our dummy frame pointer would be
     on entry to the read system call and our dummy frame pointer would be
     destroyed. So we save the dummy frame in the proc_desc and handle the
     destroyed. So we save the dummy frame in the proc_desc and handle the
     retrieval of the frame pointer of a dummy specifically. The frame register
     retrieval of the frame pointer of a dummy specifically. The frame register
     is set to the virtual frame (pseudo) register, it's value will always
     is set to the virtual frame (pseudo) register, it's value will always
     be read as zero and will help us to catch any errors in the dummy frame
     be read as zero and will help us to catch any errors in the dummy frame
     retrieval code.  */
     retrieval code.  */
  PROC_DUMMY_FRAME (proc_desc) = sp;
  PROC_DUMMY_FRAME (proc_desc) = sp;
  PROC_FRAME_REG (proc_desc) = FP_REGNUM;
  PROC_FRAME_REG (proc_desc) = FP_REGNUM;
  PROC_FRAME_OFFSET (proc_desc) = 0;
  PROC_FRAME_OFFSET (proc_desc) = 0;
  sp += PROC_REG_OFFSET (proc_desc);
  sp += PROC_REG_OFFSET (proc_desc);
  write_register (SP_REGNUM, sp);
  write_register (SP_REGNUM, sp);
 
 
  PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
  PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
  PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
  PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
 
 
  SET_PROC_DESC_IS_DUMMY (proc_desc);
  SET_PROC_DESC_IS_DUMMY (proc_desc);
  PROC_PC_REG (proc_desc) = RA_REGNUM;
  PROC_PC_REG (proc_desc) = RA_REGNUM;
}
}
 
 
void
void
alpha_pop_frame ()
alpha_pop_frame ()
{
{
  register int regnum;
  register int regnum;
  struct frame_info *frame = get_current_frame ();
  struct frame_info *frame = get_current_frame ();
  CORE_ADDR new_sp = frame->frame;
  CORE_ADDR new_sp = frame->frame;
 
 
  alpha_extra_func_info_t proc_desc = frame->proc_desc;
  alpha_extra_func_info_t proc_desc = frame->proc_desc;
 
 
  /* we need proc_desc to know how to restore the registers;
  /* we need proc_desc to know how to restore the registers;
     if it is NULL, construct (a temporary) one */
     if it is NULL, construct (a temporary) one */
  if (proc_desc == NULL)
  if (proc_desc == NULL)
    proc_desc = find_proc_desc (frame->pc, frame->next);
    proc_desc = find_proc_desc (frame->pc, frame->next);
 
 
  /* Question: should we copy this proc_desc and save it in
  /* Question: should we copy this proc_desc and save it in
     frame->proc_desc?  If we do, who will free it?
     frame->proc_desc?  If we do, who will free it?
     For now, we don't save a copy... */
     For now, we don't save a copy... */
 
 
  write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
  write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
  if (frame->saved_regs == NULL)
  if (frame->saved_regs == NULL)
    alpha_find_saved_regs (frame);
    alpha_find_saved_regs (frame);
  if (proc_desc)
  if (proc_desc)
    {
    {
      for (regnum = 32; --regnum >= 0;)
      for (regnum = 32; --regnum >= 0;)
        if (PROC_REG_MASK (proc_desc) & (1 << regnum))
        if (PROC_REG_MASK (proc_desc) & (1 << regnum))
          write_register (regnum,
          write_register (regnum,
                          read_memory_integer (frame->saved_regs[regnum],
                          read_memory_integer (frame->saved_regs[regnum],
                                               8));
                                               8));
      for (regnum = 32; --regnum >= 0;)
      for (regnum = 32; --regnum >= 0;)
        if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
        if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
          write_register (regnum + FP0_REGNUM,
          write_register (regnum + FP0_REGNUM,
           read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
           read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
    }
    }
  write_register (SP_REGNUM, new_sp);
  write_register (SP_REGNUM, new_sp);
  flush_cached_frames ();
  flush_cached_frames ();
 
 
  if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
  if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
                    || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
                    || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
    {
    {
      struct linked_proc_info *pi_ptr, *prev_ptr;
      struct linked_proc_info *pi_ptr, *prev_ptr;
 
 
      for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
      for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
           pi_ptr != NULL;
           pi_ptr != NULL;
           prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
           prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
        {
        {
          if (&pi_ptr->info == proc_desc)
          if (&pi_ptr->info == proc_desc)
            break;
            break;
        }
        }
 
 
      if (pi_ptr == NULL)
      if (pi_ptr == NULL)
        error ("Can't locate dummy extra frame info\n");
        error ("Can't locate dummy extra frame info\n");
 
 
      if (prev_ptr != NULL)
      if (prev_ptr != NULL)
        prev_ptr->next = pi_ptr->next;
        prev_ptr->next = pi_ptr->next;
      else
      else
        linked_proc_desc_table = pi_ptr->next;
        linked_proc_desc_table = pi_ptr->next;
 
 
      free (pi_ptr);
      free (pi_ptr);
    }
    }
}
}


/* To skip prologues, I use this predicate.  Returns either PC itself
/* To skip prologues, I use this predicate.  Returns either PC itself
   if the code at PC does not look like a function prologue; otherwise
   if the code at PC does not look like a function prologue; otherwise
   returns an address that (if we're lucky) follows the prologue.  If
   returns an address that (if we're lucky) follows the prologue.  If
   LENIENT, then we must skip everything which is involved in setting
   LENIENT, then we must skip everything which is involved in setting
   up the frame (it's OK to skip more, just so long as we don't skip
   up the frame (it's OK to skip more, just so long as we don't skip
   anything which might clobber the registers which are being saved.
   anything which might clobber the registers which are being saved.
   Currently we must not skip more on the alpha, but we might the lenient
   Currently we must not skip more on the alpha, but we might the lenient
   stuff some day.  */
   stuff some day.  */
 
 
CORE_ADDR
CORE_ADDR
alpha_skip_prologue (pc, lenient)
alpha_skip_prologue (pc, lenient)
     CORE_ADDR pc;
     CORE_ADDR pc;
     int lenient;
     int lenient;
{
{
  unsigned long inst;
  unsigned long inst;
  int offset;
  int offset;
  CORE_ADDR post_prologue_pc;
  CORE_ADDR post_prologue_pc;
  char buf[4];
  char buf[4];
 
 
#ifdef GDB_TARGET_HAS_SHARED_LIBS
#ifdef GDB_TARGET_HAS_SHARED_LIBS
  /* Silently return the unaltered pc upon memory errors.
  /* Silently return the unaltered pc upon memory errors.
     This could happen on OSF/1 if decode_line_1 tries to skip the
     This could happen on OSF/1 if decode_line_1 tries to skip the
     prologue for quickstarted shared library functions when the
     prologue for quickstarted shared library functions when the
     shared library is not yet mapped in.
     shared library is not yet mapped in.
     Reading target memory is slow over serial lines, so we perform
     Reading target memory is slow over serial lines, so we perform
     this check only if the target has shared libraries.  */
     this check only if the target has shared libraries.  */
  if (target_read_memory (pc, buf, 4))
  if (target_read_memory (pc, buf, 4))
    return pc;
    return pc;
#endif
#endif
 
 
  /* See if we can determine the end of the prologue via the symbol table.
  /* See if we can determine the end of the prologue via the symbol table.
     If so, then return either PC, or the PC after the prologue, whichever
     If so, then return either PC, or the PC after the prologue, whichever
     is greater.  */
     is greater.  */
 
 
  post_prologue_pc = after_prologue (pc, NULL);
  post_prologue_pc = after_prologue (pc, NULL);
 
 
  if (post_prologue_pc != 0)
  if (post_prologue_pc != 0)
    return max (pc, post_prologue_pc);
    return max (pc, post_prologue_pc);
 
 
  /* Can't determine prologue from the symbol table, need to examine
  /* Can't determine prologue from the symbol table, need to examine
     instructions.  */
     instructions.  */
 
 
  /* Skip the typical prologue instructions. These are the stack adjustment
  /* Skip the typical prologue instructions. These are the stack adjustment
     instruction and the instructions that save registers on the stack
     instruction and the instructions that save registers on the stack
     or in the gcc frame.  */
     or in the gcc frame.  */
  for (offset = 0; offset < 100; offset += 4)
  for (offset = 0; offset < 100; offset += 4)
    {
    {
      int status;
      int status;
 
 
      status = read_memory_nobpt (pc + offset, buf, 4);
      status = read_memory_nobpt (pc + offset, buf, 4);
      if (status)
      if (status)
        memory_error (status, pc + offset);
        memory_error (status, pc + offset);
      inst = extract_unsigned_integer (buf, 4);
      inst = extract_unsigned_integer (buf, 4);
 
 
      /* The alpha has no delay slots. But let's keep the lenient stuff,
      /* The alpha has no delay slots. But let's keep the lenient stuff,
         we might need it for something else in the future.  */
         we might need it for something else in the future.  */
      if (lenient && 0)
      if (lenient && 0)
        continue;
        continue;
 
 
      if ((inst & 0xffff0000) == 0x27bb0000)    /* ldah $gp,n($t12) */
      if ((inst & 0xffff0000) == 0x27bb0000)    /* ldah $gp,n($t12) */
        continue;
        continue;
      if ((inst & 0xffff0000) == 0x23bd0000)    /* lda $gp,n($gp) */
      if ((inst & 0xffff0000) == 0x23bd0000)    /* lda $gp,n($gp) */
        continue;
        continue;
      if ((inst & 0xffff0000) == 0x23de0000)    /* lda $sp,n($sp) */
      if ((inst & 0xffff0000) == 0x23de0000)    /* lda $sp,n($sp) */
        continue;
        continue;
      if ((inst & 0xffe01fff) == 0x43c0153e)    /* subq $sp,n,$sp */
      if ((inst & 0xffe01fff) == 0x43c0153e)    /* subq $sp,n,$sp */
        continue;
        continue;
 
 
      if ((inst & 0xfc1f0000) == 0xb41e0000
      if ((inst & 0xfc1f0000) == 0xb41e0000
          && (inst & 0xffff0000) != 0xb7fe0000)
          && (inst & 0xffff0000) != 0xb7fe0000)
        continue;               /* stq reg,n($sp) */
        continue;               /* stq reg,n($sp) */
      /* reg != $zero */
      /* reg != $zero */
      if ((inst & 0xfc1f0000) == 0x9c1e0000
      if ((inst & 0xfc1f0000) == 0x9c1e0000
          && (inst & 0xffff0000) != 0x9ffe0000)
          && (inst & 0xffff0000) != 0x9ffe0000)
        continue;               /* stt reg,n($sp) */
        continue;               /* stt reg,n($sp) */
      /* reg != $zero */
      /* reg != $zero */
      if (inst == 0x47de040f)   /* bis sp,sp,fp */
      if (inst == 0x47de040f)   /* bis sp,sp,fp */
        continue;
        continue;
 
 
      break;
      break;
    }
    }
  return pc + offset;
  return pc + offset;
}
}
 
 
#if 0
#if 0
/* Is address PC in the prologue (loosely defined) for function at
/* Is address PC in the prologue (loosely defined) for function at
   STARTADDR?  */
   STARTADDR?  */
 
 
static int
static int
alpha_in_lenient_prologue (startaddr, pc)
alpha_in_lenient_prologue (startaddr, pc)
     CORE_ADDR startaddr;
     CORE_ADDR startaddr;
     CORE_ADDR pc;
     CORE_ADDR pc;
{
{
  CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
  CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
  return pc >= startaddr && pc < end_prologue;
  return pc >= startaddr && pc < end_prologue;
}
}
#endif
#endif
 
 
/* The alpha needs a conversion between register and memory format if
/* The alpha needs a conversion between register and memory format if
   the register is a floating point register and
   the register is a floating point register and
   memory format is float, as the register format must be double
   memory format is float, as the register format must be double
   or
   or
   memory format is an integer with 4 bytes or less, as the representation
   memory format is an integer with 4 bytes or less, as the representation
   of integers in floating point registers is different. */
   of integers in floating point registers is different. */
void
void
alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
     int regnum;
     int regnum;
     struct type *valtype;
     struct type *valtype;
     char *raw_buffer;
     char *raw_buffer;
     char *virtual_buffer;
     char *virtual_buffer;
{
{
  if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
  if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
    {
    {
      memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
      memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
      return;
      return;
    }
    }
 
 
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
    {
    {
      double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
      double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
      store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
      store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
    }
    }
  else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
  else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
    {
    {
      ULONGEST l;
      ULONGEST l;
      l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
      l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
      l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
      l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
      store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
      store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
    }
    }
  else
  else
    error ("Cannot retrieve value from floating point register");
    error ("Cannot retrieve value from floating point register");
}
}
 
 
void
void
alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
     struct type *valtype;
     struct type *valtype;
     int regnum;
     int regnum;
     char *virtual_buffer;
     char *virtual_buffer;
     char *raw_buffer;
     char *raw_buffer;
{
{
  if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
  if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
    {
    {
      memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
      memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
      return;
      return;
    }
    }
 
 
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
    {
    {
      double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
      double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
      store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
      store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
    }
    }
  else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
  else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
    {
    {
      ULONGEST l;
      ULONGEST l;
      if (TYPE_UNSIGNED (valtype))
      if (TYPE_UNSIGNED (valtype))
        l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
        l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
      else
      else
        l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
        l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
      l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
      l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
      store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
      store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
    }
    }
  else
  else
    error ("Cannot store value in floating point register");
    error ("Cannot store value in floating point register");
}
}
 
 
/* Given a return value in `regbuf' with a type `valtype',
/* Given a return value in `regbuf' with a type `valtype',
   extract and copy its value into `valbuf'.  */
   extract and copy its value into `valbuf'.  */
 
 
void
void
alpha_extract_return_value (valtype, regbuf, valbuf)
alpha_extract_return_value (valtype, regbuf, valbuf)
     struct type *valtype;
     struct type *valtype;
     char regbuf[REGISTER_BYTES];
     char regbuf[REGISTER_BYTES];
     char *valbuf;
     char *valbuf;
{
{
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
    alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
    alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
                                       regbuf + REGISTER_BYTE (FP0_REGNUM),
                                       regbuf + REGISTER_BYTE (FP0_REGNUM),
                                       valbuf);
                                       valbuf);
  else
  else
    memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
    memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
}
}
 
 
/* Given a return value in `regbuf' with a type `valtype',
/* Given a return value in `regbuf' with a type `valtype',
   write its value into the appropriate register.  */
   write its value into the appropriate register.  */
 
 
void
void
alpha_store_return_value (valtype, valbuf)
alpha_store_return_value (valtype, valbuf)
     struct type *valtype;
     struct type *valtype;
     char *valbuf;
     char *valbuf;
{
{
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
  char raw_buffer[MAX_REGISTER_RAW_SIZE];
  int regnum = V0_REGNUM;
  int regnum = V0_REGNUM;
  int length = TYPE_LENGTH (valtype);
  int length = TYPE_LENGTH (valtype);
 
 
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
  if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
    {
    {
      regnum = FP0_REGNUM;
      regnum = FP0_REGNUM;
      length = REGISTER_RAW_SIZE (regnum);
      length = REGISTER_RAW_SIZE (regnum);
      alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
      alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
    }
    }
  else
  else
    memcpy (raw_buffer, valbuf, length);
    memcpy (raw_buffer, valbuf, length);
 
 
  write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
  write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
}
}
 
 
/* Just like reinit_frame_cache, but with the right arguments to be
/* Just like reinit_frame_cache, but with the right arguments to be
   callable as an sfunc.  */
   callable as an sfunc.  */
 
 
static void
static void
reinit_frame_cache_sfunc (args, from_tty, c)
reinit_frame_cache_sfunc (args, from_tty, c)
     char *args;
     char *args;
     int from_tty;
     int from_tty;
     struct cmd_list_element *c;
     struct cmd_list_element *c;
{
{
  reinit_frame_cache ();
  reinit_frame_cache ();
}
}
 
 
/* This is the definition of CALL_DUMMY_ADDRESS.  It's a heuristic that is used
/* This is the definition of CALL_DUMMY_ADDRESS.  It's a heuristic that is used
   to find a convenient place in the text segment to stick a breakpoint to
   to find a convenient place in the text segment to stick a breakpoint to
   detect the completion of a target function call (ala call_function_by_hand).
   detect the completion of a target function call (ala call_function_by_hand).
 */
 */
 
 
CORE_ADDR
CORE_ADDR
alpha_call_dummy_address ()
alpha_call_dummy_address ()
{
{
  CORE_ADDR entry;
  CORE_ADDR entry;
  struct minimal_symbol *sym;
  struct minimal_symbol *sym;
 
 
  entry = entry_point_address ();
  entry = entry_point_address ();
 
 
  if (entry != 0)
  if (entry != 0)
    return entry;
    return entry;
 
 
  sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
  sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
 
 
  if (!sym || MSYMBOL_TYPE (sym) != mst_text)
  if (!sym || MSYMBOL_TYPE (sym) != mst_text)
    return 0;
    return 0;
  else
  else
    return SYMBOL_VALUE_ADDRESS (sym) + 4;
    return SYMBOL_VALUE_ADDRESS (sym) + 4;
}
}
 
 
void
void
_initialize_alpha_tdep ()
_initialize_alpha_tdep ()
{
{
  struct cmd_list_element *c;
  struct cmd_list_element *c;
 
 
  tm_print_insn = print_insn_alpha;
  tm_print_insn = print_insn_alpha;
 
 
  /* Let the user set the fence post for heuristic_proc_start.  */
  /* Let the user set the fence post for heuristic_proc_start.  */
 
 
  /* We really would like to have both "0" and "unlimited" work, but
  /* We really would like to have both "0" and "unlimited" work, but
     command.c doesn't deal with that.  So make it a var_zinteger
     command.c doesn't deal with that.  So make it a var_zinteger
     because the user can always use "999999" or some such for unlimited.  */
     because the user can always use "999999" or some such for unlimited.  */
  c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
  c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
                   (char *) &heuristic_fence_post,
                   (char *) &heuristic_fence_post,
                   "\
                   "\
Set the distance searched for the start of a function.\n\
Set the distance searched for the start of a function.\n\
If you are debugging a stripped executable, GDB needs to search through the\n\
If you are debugging a stripped executable, GDB needs to search through the\n\
program for the start of a function.  This command sets the distance of the\n\
program for the start of a function.  This command sets the distance of the\n\
search.  The only need to set it is when debugging a stripped executable.",
search.  The only need to set it is when debugging a stripped executable.",
                   &setlist);
                   &setlist);
  /* We need to throw away the frame cache when we set this, since it
  /* We need to throw away the frame cache when we set this, since it
     might change our ability to get backtraces.  */
     might change our ability to get backtraces.  */
  c->function.sfunc = reinit_frame_cache_sfunc;
  c->function.sfunc = reinit_frame_cache_sfunc;
  add_show_from_set (c, &showlist);
  add_show_from_set (c, &showlist);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.