/* Target-dependent code for the HP PA architecture, for GDB.
- Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
Free Software Foundation, Inc.
Contributed by the Center for Software Science at the
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "defs.h"
#include "frame.h"
#include "a.out.encap.h"
#else
#endif
-#ifndef N_SET_MAGIC
-#define N_SET_MAGIC(exec, val) ((exec).a_magic = (val))
-#endif
/*#include <sys/user.h> After a.out.h */
#include <sys/file.h>
-#include <sys/stat.h>
+#include "gdb_stat.h"
#include "wait.h"
#include "gdbcore.h"
#include "symfile.h"
#include "objfiles.h"
+static int extract_5_load PARAMS ((unsigned int));
+
+static unsigned extract_5R_store PARAMS ((unsigned int));
+
+static unsigned extract_5r_store PARAMS ((unsigned int));
+
+static void find_dummy_frame_regs PARAMS ((struct frame_info *,
+ struct frame_saved_regs *));
+
+static int find_proc_framesize PARAMS ((CORE_ADDR));
+
+static int find_return_regnum PARAMS ((CORE_ADDR));
+
+struct unwind_table_entry *find_unwind_entry PARAMS ((CORE_ADDR));
+
+static int extract_17 PARAMS ((unsigned int));
+
+static unsigned deposit_21 PARAMS ((unsigned int, unsigned int));
+
+static int extract_21 PARAMS ((unsigned));
+
+static unsigned deposit_14 PARAMS ((int, unsigned int));
+
+static int extract_14 PARAMS ((unsigned));
+
+static void unwind_command PARAMS ((char *, int));
+
+static int low_sign_extend PARAMS ((unsigned int, unsigned int));
+
+static int sign_extend PARAMS ((unsigned int, unsigned int));
+
static int restore_pc_queue PARAMS ((struct frame_saved_regs *));
static int hppa_alignof PARAMS ((struct type *));
-CORE_ADDR frame_saved_pc PARAMS ((struct frame_info *));
-
static int prologue_inst_adjust_sp PARAMS ((unsigned long));
static int is_branch PARAMS ((unsigned long));
static int pc_in_linker_stub PARAMS ((CORE_ADDR));
-static int compare_unwind_entries PARAMS ((const struct unwind_table_entry *,
- const struct unwind_table_entry *));
+static int compare_unwind_entries PARAMS ((const void *, const void *));
static void read_unwind_info PARAMS ((struct objfile *));
static void pa_print_registers PARAMS ((char *, int, int));
static void pa_print_fp_reg PARAMS ((int));
+
+/* Should call_function allocate stack space for a struct return? */
+int
+hppa_use_struct_convention (gcc_p, type)
+ int gcc_p;
+ struct type *type;
+{
+ return (TYPE_LENGTH (type) > 8);
+}
+
\f
/* Routines to extract various sized constants out of hppa
instructions. */
/* This assumes that no garbage lies outside of the lower bits of
value. */
-int
+static int
sign_extend (val, bits)
unsigned val, bits;
{
- return (int)(val >> bits - 1 ? (-1 << bits) | val : val);
+ return (int)(val >> (bits - 1) ? (-1 << bits) | val : val);
}
/* For many immediate values the sign bit is the low bit! */
-int
+static int
low_sign_extend (val, bits)
unsigned val, bits;
{
return (int)((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
}
+
/* extract the immediate field from a ld{bhw}s instruction */
+#if 0
+
unsigned
get_field (val, from, to)
unsigned val, from, to;
/* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
+int
extract_3 (word)
unsigned word;
{
return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);
}
-
+
+#endif
+
+static int
extract_5_load (word)
unsigned word;
{
return low_sign_extend (word >> 16 & MASK_5, 5);
}
+#if 0
+
/* extract the immediate field from a st{bhw}s instruction */
int
return low_sign_extend (word & MASK_5, 5);
}
+#endif /* 0 */
+
/* extract the immediate field from a break instruction */
-unsigned
+static unsigned
extract_5r_store (word)
unsigned word;
{
/* extract the immediate field from a {sr}sm instruction */
-unsigned
+static unsigned
extract_5R_store (word)
unsigned word;
{
/* extract an 11 bit immediate field */
+#if 0
+
int
extract_11 (word)
unsigned word;
return low_sign_extend (word & MASK_11, 11);
}
+#endif
+
/* extract a 14 bit immediate field */
-int
+static int
extract_14 (word)
unsigned word;
{
/* deposit a 14 bit constant in a word */
-unsigned
+static unsigned
deposit_14 (opnd, word)
int opnd;
unsigned word;
/* extract a 21 bit constant */
-int
+static int
extract_21 (word)
unsigned word;
{
usually the top 21 bits of a 32 bit constant, we assume that only
the low 21 bits of opnd are relevant */
-unsigned
+static unsigned
deposit_21 (opnd, word)
unsigned opnd, word;
{
/* extract a 12 bit constant from branch instructions */
+#if 0
+
int
extract_12 (word)
unsigned word;
return word;
}
+#endif
+
/* extract a 17 bit constant from branch instructions, returning the
19 bit signed value. */
-int
+static int
extract_17 (word)
unsigned word;
{
larger than the first, and zero if they are equal. */
static int
-compare_unwind_entries (a, b)
- const struct unwind_table_entry *a;
- const struct unwind_table_entry *b;
+compare_unwind_entries (arg1, arg2)
+ const void *arg1;
+ const void *arg2;
{
+ const struct unwind_table_entry *a = arg1;
+ const struct unwind_table_entry *b = arg2;
+
if (a->region_start > b->region_start)
return 1;
else if (a->region_start < b->region_start)
contains a sorted list of struct unwind_table_entry. Since we do a binary
search of the unwind tables, we depend upon them to be sorted. */
-static struct unwind_table_entry *
+struct unwind_table_entry *
find_unwind_entry(pc)
CORE_ADDR pc;
{
}
/* Return size of frame, or -1 if we should use a frame pointer. */
-int
+static int
find_proc_framesize (pc)
CORE_ADDR pc;
{
the stub will return to out of the stack. */
u = find_unwind_entry (pc);
if (u && u->stub_type != 0)
- return frame_saved_pc (frame);
+ return FRAME_SAVED_PC (frame);
else
return pc;
}
\f
CORE_ADDR
-frame_saved_pc (frame)
+hppa_frame_saved_pc (frame)
struct frame_info *frame;
{
CORE_ADDR pc = get_frame_pc (frame);
}
/* If PC is inside a linker stub, then dig out the address the stub
- will return to. */
+ will return to.
+
+ Don't do this for long branch stubs. Why? For some unknown reason
+ _start is marked as a long branch stub in hpux10. */
u = find_unwind_entry (pc);
- if (u && u->stub_type != 0)
+ if (u && u->stub_type != 0
+ && u->stub_type != LONG_BRANCH)
{
unsigned int insn;
/* Abominable hack. */
if (current_target.to_has_execution == 0
- && saved_regs.regs[FLAGS_REGNUM]
- && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) & 0x2))
+ && ((saved_regs.regs[FLAGS_REGNUM]
+ && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4)
+ & 0x2))
+ || (saved_regs.regs[FLAGS_REGNUM] == 0
+ && read_register (FLAGS_REGNUM) & 0x2)))
{
u = find_unwind_entry (FRAME_SAVED_PC (frame));
if (!u)
}
else
{
+ struct frame_saved_regs saved_regs;
+
+ /* Get the innermost frame. */
+ tmp_frame = frame;
+ while (tmp_frame->next != NULL)
+ tmp_frame = tmp_frame->next;
+
+ get_frame_saved_regs (tmp_frame, &saved_regs);
+ /* Abominable hack. See above. */
+ if (current_target.to_has_execution == 0
+ && ((saved_regs.regs[FLAGS_REGNUM]
+ && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4)
+ & 0x2))
+ || (saved_regs.regs[FLAGS_REGNUM] == 0
+ && read_register (FLAGS_REGNUM) & 0x2)))
+ {
+ u = find_unwind_entry (FRAME_SAVED_PC (frame));
+ if (!u)
+ return read_memory_integer (saved_regs.regs[FP_REGNUM], 4);
+ else
+ return frame_base - (u->Total_frame_size << 3);
+ }
+
/* The value in %r3 was never saved into the stack (thus %r3 still
holds the value of the previous frame pointer). */
return read_register (FP_REGNUM);
was compiled with gcc. */
int
-frame_chain_valid (chain, thisframe)
+hppa_frame_chain_valid (chain, thisframe)
CORE_ADDR chain;
struct frame_info *thisframe;
{
&& SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
return 0;
+ /* Grrrr. Some new idiot decided that they don't want _start for the
+ PRO configurations; $START$ calls main directly.... Deal with it. */
+ msym_start = lookup_minimal_symbol ("$START$", NULL, NULL);
+ if (msym_us
+ && msym_start
+ && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
+ return 0;
+
next = get_next_frame (thisframe);
if (next)
next_u = find_unwind_entry (next->pc);
write_register (SP_REGNUM, sp);
}
-void
+static void
find_dummy_frame_regs (frame, frame_saved_regs)
struct frame_info *frame;
struct frame_saved_regs *frame_saved_regs;
CORE_ADDR fp = frame->frame;
int i;
- frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3;
+ frame_saved_regs->regs[RP_REGNUM] = (fp - 20) & ~0x3;
frame_saved_regs->regs[FP_REGNUM] = fp;
frame_saved_regs->regs[1] = fp + 8;
else
{
npc = read_register (RP_REGNUM);
- target_write_pc (npc, 0);
+ write_pc (npc);
}
write_register (FP_REGNUM, read_memory_integer (fp, 4));
breakpoint->silent = 1;
/* So we can clean things up. */
- old_chain = make_cleanup (delete_breakpoint, breakpoint);
+ old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
/* Start up the inferior. */
+ clear_proceed_status ();
proceed_to_finish = 1;
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
{
struct unwind_table_entry *u;
/* It must be a shared library trampoline. */
- if (SYMBOL_TYPE (stub_symbol) != mst_solib_trampoline)
+ if (MSYMBOL_TYPE (stub_symbol) != mst_solib_trampoline)
continue;
/* It must also be an import stub. */
target_read_pc (pid)
int pid;
{
- int flags = read_register (FLAGS_REGNUM);
+ int flags = read_register_pid (FLAGS_REGNUM, pid);
- if (flags & 2) {
- return read_register (31) & ~0x3;
- }
- return read_register (PC_REGNUM) & ~0x3;
+ /* The following test does not belong here. It is OS-specific, and belongs
+ in native code. */
+ /* Test SS_INSYSCALL */
+ if (flags & 2)
+ return read_register_pid (31, pid) & ~0x3;
+
+ return read_register_pid (PC_REGNUM, pid) & ~0x3;
}
/* Write out the PC. If currently in a syscall, then also write the new
CORE_ADDR v;
int pid;
{
- int flags = read_register (FLAGS_REGNUM);
+ int flags = read_register_pid (FLAGS_REGNUM, pid);
+ /* The following test does not belong here. It is OS-specific, and belongs
+ in native code. */
/* If in a syscall, then set %r31. Also make sure to get the
privilege bits set correctly. */
+ /* Test SS_INSYSCALL */
if (flags & 2)
- write_register (31, (long) (v | 0x3));
+ write_register_pid (31, v | 0x3, pid);
- write_register (PC_REGNUM, (long) v);
- write_register (NPC_REGNUM, (long) v + 4);
+ write_register_pid (PC_REGNUM, v, pid);
+ write_register_pid (NPC_REGNUM, v + 4, pid);
}
/* return the alignment of a type in bytes. Structures have the maximum
alignment required by their fields. */
static int
-hppa_alignof (arg)
- struct type *arg;
+hppa_alignof (type)
+ struct type *type;
{
int max_align, align, i;
- switch (TYPE_CODE (arg))
+ CHECK_TYPEDEF (type);
+ switch (TYPE_CODE (type))
{
case TYPE_CODE_PTR:
case TYPE_CODE_INT:
case TYPE_CODE_FLT:
- return TYPE_LENGTH (arg);
+ return TYPE_LENGTH (type);
case TYPE_CODE_ARRAY:
- return hppa_alignof (TYPE_FIELD_TYPE (arg, 0));
+ return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- max_align = 2;
- for (i = 0; i < TYPE_NFIELDS (arg); i++)
+ max_align = 1;
+ for (i = 0; i < TYPE_NFIELDS (type); i++)
{
/* Bit fields have no real alignment. */
- if (!TYPE_FIELD_BITPOS (arg, i))
+ if (!TYPE_FIELD_BITPOS (type, i))
{
- align = hppa_alignof (TYPE_FIELD_TYPE (arg, i));
+ align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
max_align = max (max_align, align);
}
}
if (regnum == -1)
pa_print_registers (raw_regs, regnum, fpregs);
else if (regnum < FP0_REGNUM)
- printf_unfiltered ("%s %x\n", reg_names[regnum], *(long *)(raw_regs +
+ printf_unfiltered ("%s %x\n", REGISTER_NAME (regnum), *(long *)(raw_regs +
REGISTER_BYTE (regnum)));
else
pa_print_fp_reg (regnum);
{
val =
extract_signed_integer (raw_regs + REGISTER_BYTE (i+(j*18)), 4);
- printf_unfiltered ("%8.8s: %8x ", reg_names[i+(j*18)], val);
+ printf_unfiltered ("%8.8s: %8x ", REGISTER_NAME (i+(j*18)), val);
}
printf_unfiltered ("\n");
}
/* Put it in the buffer. No conversions are ever necessary. */
memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i));
- fputs_filtered (reg_names[i], gdb_stdout);
- print_spaces_filtered (8 - strlen (reg_names[i]), gdb_stdout);
+ fputs_filtered (REGISTER_NAME (i), gdb_stdout);
+ print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
fputs_filtered ("(single precision) ", gdb_stdout);
- val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, gdb_stdout, 0,
+ val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, gdb_stdout, 0,
1, 0, Val_pretty_default);
printf_filtered ("\n");
REGISTER_RAW_SIZE (i));
/* Dump it as a double. */
- fputs_filtered (reg_names[i], gdb_stdout);
- print_spaces_filtered (8 - strlen (reg_names[i]), gdb_stdout);
+ fputs_filtered (REGISTER_NAME (i), gdb_stdout);
+ print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
fputs_filtered ("(double precision) ", gdb_stdout);
- val_print (builtin_type_double, virtual_buffer, 0, gdb_stdout, 0,
+ val_print (builtin_type_double, virtual_buffer, 0, 0, gdb_stdout, 0,
1, 0, Val_pretty_default);
printf_filtered ("\n");
}
CORE_ADDR pc;
{
char buf[4];
+ CORE_ADDR orig_pc = pc;
unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
- unsigned long args_stored, status, i;
+ unsigned long args_stored, status, i, restart_gr, restart_fr;
struct unwind_table_entry *u;
+ restart_gr = 0;
+ restart_fr = 0;
+
+restart:
u = find_unwind_entry (pc);
if (!u)
return pc;
/* An indication that args may be stored into the stack. Unfortunately
the HPUX compilers tend to set this in cases where no args were
stored too!. */
- args_stored = u->Args_stored;
+ args_stored = 1;
/* Turn the Entry_GR field into a bitmask. */
save_gr = 0;
save_gr |= (1 << i);
}
+ save_gr &= ~restart_gr;
/* Turn the Entry_FR field into a bitmask too. */
save_fr = 0;
for (i = 12; i < u->Entry_FR + 12; i++)
save_fr |= (1 << i);
+ save_fr &= ~restart_fr;
/* Loop until we find everything of interest or hit a branch.
pc += 4;
}
+ /* We've got a tenative location for the end of the prologue. However
+ because of limitations in the unwind descriptor mechanism we may
+ have went too far into user code looking for the save of a register
+ that does not exist. So, if there registers we expected to be saved
+ but never were, mask them out and restart.
+
+ This should only happen in optimized code, and should be very rare. */
+ if (save_gr || (save_fr && ! (restart_fr || restart_gr)))
+ {
+ pc = orig_pc;
+ restart_gr = save_gr;
+ restart_fr = save_fr;
+ goto restart;
+ }
+
return pc;
}