+/* Determines whether the function FI has a frame on the stack or not. */
+
+int
+frameless_function_invocation (fi)
+ struct frame_info *fi;
+{
+ CORE_ADDR func_start;
+ struct rs6000_framedata fdata;
+
+ if (fi->next != NULL)
+ /* Don't even think about framelessness except on the innermost frame. */
+ /* FIXME: Can also be frameless if fi->next->signal_handler_caller (if
+ a signal happens while executing in a frameless function). */
+ return 0;
+
+ func_start = get_pc_function_start (fi->pc) + FUNCTION_START_OFFSET;
+
+ /* If we failed to find the start of the function, it is a mistake
+ to inspect the instructions. */
+
+ if (!func_start)
+ return 0;
+
+ (void) skip_prologue (func_start, &fdata);
+ return fdata.frameless;
+}
+
+/* Return the PC saved in a frame */
+
+unsigned long
+frame_saved_pc (fi)
+ struct frame_info *fi;
+{
+ CORE_ADDR func_start;
+ struct rs6000_framedata fdata;
+ int frameless;
+
+ if (fi->signal_handler_caller)
+ return read_memory_integer (fi->frame + SIG_FRAME_PC_OFFSET, 4);
+
+ func_start = get_pc_function_start (fi->pc) + FUNCTION_START_OFFSET;
+
+ /* If we failed to find the start of the function, it is a mistake
+ to inspect the instructions. */
+ if (!func_start)
+ return 0;
+
+ (void) skip_prologue (func_start, &fdata);
+
+ if (fdata.lr_offset == 0 && fi->next != NULL)
+ return read_memory_integer (rs6000_frame_chain (fi) + DEFAULT_LR_SAVE, 4);
+
+ if (fdata.lr_offset == 0)
+ return read_register (LR_REGNUM);
+
+ return read_memory_integer (rs6000_frame_chain (fi) + fdata.lr_offset, 4);
+}
+
+/* If saved registers of frame FI are not known yet, read and cache them.
+ &FDATAP contains rs6000_framedata; TDATAP can be NULL,
+ in which case the framedata are read. */
+
+static void
+frame_get_cache_fsr (fi, fdatap)
+ struct frame_info *fi;
+ struct rs6000_framedata *fdatap;
+{
+ int ii;
+ CORE_ADDR frame_addr;
+ struct rs6000_framedata work_fdata;
+
+ if (fi->cache_fsr)
+ return;
+
+ if (fdatap == NULL) {
+ fdatap = &work_fdata;
+ (void) skip_prologue (get_pc_function_start (fi->pc), fdatap);
+ }
+
+ fi->cache_fsr = (struct frame_saved_regs *)
+ obstack_alloc (&frame_cache_obstack, sizeof (struct frame_saved_regs));
+ memset (fi->cache_fsr, '\0', sizeof (struct frame_saved_regs));
+
+ if (fi->prev && fi->prev->frame)
+ frame_addr = fi->prev->frame;
+ else
+ frame_addr = read_memory_integer (fi->frame, 4);
+
+ /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
+ All fpr's from saved_fpr to fp31 are saved. */
+
+ if (fdatap->saved_fpr >= 0) {
+ int fpr_offset = frame_addr + fdatap->fpr_offset;
+ for (ii = fdatap->saved_fpr; ii < 32; ii++) {
+ fi->cache_fsr->regs [FP0_REGNUM + ii] = fpr_offset;
+ fpr_offset += 8;
+ }
+ }
+
+ /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
+ All gpr's from saved_gpr to gpr31 are saved. */
+
+ if (fdatap->saved_gpr >= 0) {
+ int gpr_offset = frame_addr + fdatap->gpr_offset;
+ for (ii = fdatap->saved_gpr; ii < 32; ii++) {
+ fi->cache_fsr->regs [ii] = gpr_offset;
+ gpr_offset += 4;
+ }
+ }
+
+ /* If != 0, fdatap->cr_offset is the offset from the frame that holds
+ the CR. */
+ if (fdatap->cr_offset != 0)
+ fi->cache_fsr->regs [CR_REGNUM] = frame_addr + fdatap->cr_offset;
+
+ /* If != 0, fdatap->lr_offset is the offset from the frame that holds
+ the LR. */
+ if (fdatap->lr_offset != 0)
+ fi->cache_fsr->regs [LR_REGNUM] = frame_addr + fdatap->lr_offset;
+}
+
+/* Return the address of a frame. This is the inital %sp value when the frame
+ was first allocated. For functions calling alloca(), it might be saved in
+ an alloca register. */
+
+CORE_ADDR
+frame_initial_stack_address (fi)
+ struct frame_info *fi;
+{
+ CORE_ADDR tmpaddr;
+ struct rs6000_framedata fdata;
+ struct frame_info *callee_fi;
+
+ /* if the initial stack pointer (frame address) of this frame is known,
+ just return it. */
+
+ if (fi->initial_sp)
+ return fi->initial_sp;
+
+ /* find out if this function is using an alloca register.. */
+
+ (void) skip_prologue (get_pc_function_start (fi->pc), &fdata);
+
+ /* if saved registers of this frame are not known yet, read and cache them. */
+
+ if (!fi->cache_fsr)
+ frame_get_cache_fsr (fi, &fdata);
+
+ /* If no alloca register used, then fi->frame is the value of the %sp for
+ this frame, and it is good enough. */
+
+ if (fdata.alloca_reg < 0) {
+ fi->initial_sp = fi->frame;
+ return fi->initial_sp;
+ }
+
+ /* This function has an alloca register. If this is the top-most frame
+ (with the lowest address), the value in alloca register is good. */
+
+ if (!fi->next)
+ return fi->initial_sp = read_register (fdata.alloca_reg);
+
+ /* Otherwise, this is a caller frame. Callee has usually already saved
+ registers, but there are exceptions (such as when the callee
+ has no parameters). Find the address in which caller's alloca
+ register is saved. */
+
+ for (callee_fi = fi->next; callee_fi; callee_fi = callee_fi->next) {
+
+ if (!callee_fi->cache_fsr)
+ frame_get_cache_fsr (callee_fi, NULL);
+
+ /* this is the address in which alloca register is saved. */
+
+ tmpaddr = callee_fi->cache_fsr->regs [fdata.alloca_reg];
+ if (tmpaddr) {
+ fi->initial_sp = read_memory_integer (tmpaddr, 4);
+ return fi->initial_sp;
+ }
+
+ /* Go look into deeper levels of the frame chain to see if any one of
+ the callees has saved alloca register. */
+ }
+
+ /* If alloca register was not saved, by the callee (or any of its callees)
+ then the value in the register is still good. */
+
+ return fi->initial_sp = read_register (fdata.alloca_reg);
+}
+
+CORE_ADDR
+rs6000_frame_chain (thisframe)
+ struct frame_info *thisframe;
+{
+ CORE_ADDR fp;
+ if (inside_entry_file ((thisframe)->pc))
+ return 0;
+ if (thisframe->signal_handler_caller)
+ fp = read_memory_integer (thisframe->frame + SIG_FRAME_FP_OFFSET, 4);
+ else
+ fp = read_memory_integer ((thisframe)->frame, 4);
+
+ return fp;
+}
+\f
+/* Keep an array of load segment information and their TOC table addresses.
+ This info will be useful when calling a shared library function by hand. */
+
+struct loadinfo {
+ CORE_ADDR textorg, dataorg;
+ unsigned long toc_offset;
+};
+
+#define LOADINFOLEN 10
+
+static struct loadinfo *loadinfo = NULL;
+static int loadinfolen = 0;
+static int loadinfotocindex = 0;
+static int loadinfotextindex = 0;
+
+
+void
+xcoff_init_loadinfo ()
+{
+ loadinfotocindex = 0;
+ loadinfotextindex = 0;
+
+ if (loadinfolen == 0) {
+ loadinfo = (struct loadinfo *)
+ xmalloc (sizeof (struct loadinfo) * LOADINFOLEN);
+ loadinfolen = LOADINFOLEN;
+ }
+}
+
+
+/* FIXME -- this is never called! */
+void
+free_loadinfo ()
+{
+ if (loadinfo)
+ free (loadinfo);
+ loadinfo = NULL;
+ loadinfolen = 0;
+ loadinfotocindex = 0;
+ loadinfotextindex = 0;
+}
+
+/* this is called from xcoffread.c */
+
+void
+xcoff_add_toc_to_loadinfo (tocoff)
+ unsigned long tocoff;
+{
+ while (loadinfotocindex >= loadinfolen) {
+ loadinfolen += LOADINFOLEN;
+ loadinfo = (struct loadinfo *)
+ xrealloc (loadinfo, sizeof(struct loadinfo) * loadinfolen);
+ }
+ loadinfo [loadinfotocindex++].toc_offset = tocoff;
+}
+
+void
+add_text_to_loadinfo (textaddr, dataaddr)
+ CORE_ADDR textaddr;
+ CORE_ADDR dataaddr;
+{
+ while (loadinfotextindex >= loadinfolen) {
+ loadinfolen += LOADINFOLEN;
+ loadinfo = (struct loadinfo *)
+ xrealloc (loadinfo, sizeof(struct loadinfo) * loadinfolen);
+ }
+ loadinfo [loadinfotextindex].textorg = textaddr;
+ loadinfo [loadinfotextindex].dataorg = dataaddr;
+ ++loadinfotextindex;
+}
+
+
+/* Note that this assumes that the "textorg" and "dataorg" elements of
+ a member of this array are correlated with the "toc_offset" element
+ of the same member. This is taken care of because the loops which
+ assign the former (in xcoff_relocate_symtab or xcoff_relocate_core)
+ and the latter (in scan_xcoff_symtab, via vmap_symtab, in
+ vmap_ldinfo or xcoff_relocate_core) traverse the same objfiles in
+ the same order. */
+
+static CORE_ADDR
+find_toc_address (pc)
+ CORE_ADDR pc;
+{
+ int ii, toc_entry, tocbase = 0;
+
+ toc_entry = -1;
+ for (ii=0; ii < loadinfotextindex; ++ii)
+ if (pc > loadinfo[ii].textorg && loadinfo[ii].textorg > tocbase) {
+ toc_entry = ii;
+ tocbase = loadinfo[ii].textorg;
+ }
+
+ if (toc_entry == -1)
+ error ("Unable to find TOC entry for pc 0x%x\n", pc);
+ return loadinfo[toc_entry].dataorg + loadinfo[toc_entry].toc_offset;
+}
+
+/* Return nonzero if ADDR (a function pointer) is in the data space and
+ is therefore a special function pointer. */
+
+int
+is_magic_function_pointer (addr)
+ CORE_ADDR addr;
+{
+ struct obj_section *s;
+
+ s = find_pc_section (addr);
+ if (s && s->the_bfd_section->flags & SEC_CODE)
+ return 0;
+ else
+ return 1;
+}
+
+#ifdef GDB_TARGET_POWERPC
+int
+gdb_print_insn_powerpc (memaddr, info)
+ bfd_vma memaddr;
+ disassemble_info *info;
+{
+ if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ return print_insn_big_powerpc (memaddr, info);
+ else
+ return print_insn_little_powerpc (memaddr, info);
+}
+#endif
+
+void
+_initialize_rs6000_tdep ()
+{
+ /* FIXME, this should not be decided via ifdef. */
+#ifdef GDB_TARGET_POWERPC
+ tm_print_insn = gdb_print_insn_powerpc;
+#else
+ tm_print_insn = print_insn_rs6000;
+#endif
+}