2002-04-29 Elena Zannoni <ezannoni@redhat.com>
[binutils-gdb.git] / gdb / rs6000-tdep.c
index 70683af25c63e17e88f41a81d0490913e42fbb4c..8ccfb99efe5e9f4e42a381e8ad220b3e7416ef4d 100644 (file)
@@ -280,7 +280,7 @@ branch_dest (int opcode, int instr, CORE_ADDR pc, CORE_ADDR safety)
 #define BIG_BREAKPOINT { 0x7d, 0x82, 0x10, 0x08 }
 #define LITTLE_BREAKPOINT { 0x08, 0x10, 0x82, 0x7d }
 
-static unsigned char *
+const static unsigned char *
 rs6000_breakpoint_from_pc (CORE_ADDR *bp_addr, int *bp_size)
 {
   static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
@@ -301,7 +301,7 @@ rs6000_software_single_step (enum target_signal signal,
 {
   CORE_ADDR dummy;
   int breakp_sz;
-  char *breakp = rs6000_breakpoint_from_pc (&dummy, &breakp_sz);
+  const char *breakp = rs6000_breakpoint_from_pc (&dummy, &breakp_sz);
   int ii, insn;
   CORE_ADDR loc;
   CORE_ADDR breaks[2];
@@ -1144,6 +1144,7 @@ static void
 rs6000_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
 {
   int offset = 0;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
 
   if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
     {
@@ -1165,6 +1166,13 @@ rs6000_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
          memcpy (valbuf, &ff, sizeof (float));
        }
     }
+  else if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY
+           && TYPE_LENGTH (valtype) == 16
+           && TYPE_VECTOR (valtype))
+    {
+      memcpy (valbuf, regbuf + REGISTER_BYTE (tdep->ppc_vr0_regnum + 2),
+             TYPE_LENGTH (valtype));
+    }
   else
     {
       /* return value is copied starting from r3. */
@@ -1319,7 +1327,8 @@ rs6000_frame_saved_pc (struct frame_info *fi)
 {
   CORE_ADDR func_start;
   struct rs6000_framedata fdata;
-  int wordsize = TDEP->wordsize;
+  struct gdbarch_tdep *tdep = TDEP;
+  int wordsize = tdep->wordsize;
 
   if (fi->signal_handler_caller)
     return read_memory_addr (fi->frame + SIG_FRAME_PC_OFFSET, wordsize);
@@ -1342,7 +1351,7 @@ rs6000_frame_saved_pc (struct frame_info *fi)
        return read_memory_addr (fi->next->frame + SIG_FRAME_LR_OFFSET,
                                 wordsize);
       else
-       return read_memory_addr (FRAME_CHAIN (fi) + DEFAULT_LR_SAVE,
+       return read_memory_addr (FRAME_CHAIN (fi) + tdep->lr_frame_offset,
                                 wordsize);
     }
 
@@ -1387,10 +1396,13 @@ frame_get_saved_regs (struct frame_info *fi, struct rs6000_framedata *fdatap)
       && fdatap->cr_offset == 0
       && fdatap->vr_offset == 0)
     frame_addr = 0;
-  else if (fi->prev && fi->prev->frame)
-    frame_addr = fi->prev->frame;
   else
-    frame_addr = read_memory_addr (fi->frame, wordsize);
+    /* NOTE: cagney/2002-04-14: The ->frame points to the inner-most
+       address of the current frame.  Things might be easier if the
+       ->frame pointed to the outer-most address of the frame.  In the
+       mean time, the address of the prev frame is used as the base
+       address of this frame.  */
+    frame_addr = FRAME_CHAIN (fi);
 
   /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
      All fpr's from saved_fpr to fp31 are saved.  */
@@ -1487,41 +1499,22 @@ frame_initial_stack_address (struct frame_info *fi)
       return fi->extra_info->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->extra_info->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->saved_regs)
-       frame_get_saved_regs (callee_fi, NULL);
-
-      /* this is the address in which alloca register is saved. */
-
-      tmpaddr = callee_fi->saved_regs[fdata.alloca_reg];
-      if (tmpaddr)
-       {
-         fi->extra_info->initial_sp =
-           read_memory_addr (tmpaddr, TDEP->wordsize);
-         return fi->extra_info->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. */
-
-  fi->extra_info->initial_sp = read_register (fdata.alloca_reg);
+  /* There is an alloca register, use its value, in the current frame,
+     as the initial stack pointer.  */
+  {
+    char *tmpbuf = alloca (MAX_REGISTER_RAW_SIZE);
+    if (frame_register_read (fi, fdata.alloca_reg, tmpbuf))
+      {
+       fi->extra_info->initial_sp
+         = extract_unsigned_integer (tmpbuf,
+                                     REGISTER_RAW_SIZE (fdata.alloca_reg));
+      }
+    else
+      /* NOTE: cagney/2002-04-17: At present the only time
+         frame_register_read will fail is when the register isn't
+         available.  If that does happen, use the frame.  */
+      fi->extra_info->initial_sp = fi->frame;
+  }
   return fi->extra_info->initial_sp;
 }
 
@@ -1729,7 +1722,7 @@ rs6000_do_altivec_registers (int regnum)
       print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
 
       /* Get the data in raw format.  */
-      if (read_relative_register_raw_bytes (i, raw_buffer))
+      if (!frame_register_read (selected_frame, i, raw_buffer))
         {
           printf_filtered ("*value not available*\n");
           continue;
@@ -1826,7 +1819,7 @@ rs6000_do_registers_info (int regnum, int fpregs)
       print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
 
       /* Get the data in raw format.  */
-      if (read_relative_register_raw_bytes (i, raw_buffer))
+      if (!frame_register_read (selected_frame, i, raw_buffer))
         {
           printf_filtered ("*value not available*\n");
           continue;
@@ -1924,6 +1917,8 @@ rs6000_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
 static void
 rs6000_store_return_value (struct type *type, char *valbuf)
 {
+  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
 
     /* Floating point values are returned starting from FPR1 and up.
@@ -1932,6 +1927,13 @@ rs6000_store_return_value (struct type *type, char *valbuf)
 
     write_register_bytes (REGISTER_BYTE (FP0_REGNUM + 1), valbuf,
                          TYPE_LENGTH (type));
+  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+    {
+      if (TYPE_LENGTH (type) == 16
+          && TYPE_VECTOR (type))
+       write_register_bytes (REGISTER_BYTE (tdep->ppc_vr0_regnum + 2),
+                             valbuf, TYPE_LENGTH (type));
+    }
   else
     /* Everything else is returned in GPR3 and up. */
     write_register_bytes (REGISTER_BYTE (gdbarch_tdep (current_gdbarch)->ppc_gp0_regnum + 3),
@@ -2073,6 +2075,17 @@ rs6000_convert_from_func_ptr_addr (CORE_ADDR addr)
   /* 56 */ F(f24),F(f25),F(f26),F(f27),F(f28),F(f29),F(f30),F(f31), \
   /* 64 */ R(pc), R(ps)
 
+#define COMMON_UISA_NOFP_REGS \
+  /*  0 */ R(r0), R(r1), R(r2), R(r3), R(r4), R(r5), R(r6), R(r7),  \
+  /*  8 */ R(r8), R(r9), R(r10),R(r11),R(r12),R(r13),R(r14),R(r15), \
+  /* 16 */ R(r16),R(r17),R(r18),R(r19),R(r20),R(r21),R(r22),R(r23), \
+  /* 24 */ R(r24),R(r25),R(r26),R(r27),R(r28),R(r29),R(r30),R(r31), \
+  /* 32 */ R0,    R0,    R0,    R0,    R0,    R0,    R0,    R0,     \
+  /* 40 */ R0,    R0,    R0,    R0,    R0,    R0,    R0,    R0,     \
+  /* 48 */ R0,    R0,    R0,    R0,    R0,    R0,    R0,    R0,     \
+  /* 56 */ R0,    R0,    R0,    R0,    R0,    R0,    R0,    R0,     \
+  /* 64 */ R(pc), R(ps)
+
 /* UISA-level SPRs for PowerPC.  */
 #define PPC_UISA_SPRS \
   /* 66 */ R4(cr),  R(lr), R(ctr), R4(xer), R4(fpscr)
@@ -2122,6 +2135,14 @@ static const struct reg registers_powerpc[] =
   PPC_ALTIVEC_REGS
 };
 
+/* PowerPC UISA - a PPC processor as viewed by user-level
+   code, but without floating point registers.  */
+static const struct reg registers_powerpc_nofp[] =
+{
+  COMMON_UISA_NOFP_REGS,
+  PPC_UISA_SPRS
+};
+
 /* IBM PowerPC 403. */
 static const struct reg registers_403[] =
 {
@@ -2585,7 +2606,15 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        break;
       }   
 
-  /* Calculate byte offsets in raw register array. */
+  /* Set lr_frame_offset.  */
+  if (wordsize == 8)
+    tdep->lr_frame_offset = 16;
+  else if (sysv_abi)
+    tdep->lr_frame_offset = 4;
+  else
+    tdep->lr_frame_offset = 8;
+
+  /* Calculate byte offsets in raw register array.  */
   tdep->regoff = xmalloc (v->nregs * sizeof (int));
   for (i = off = 0; i < v->nregs; i++)
     {
@@ -2658,7 +2687,14 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_extract_return_value (gdbarch, rs6000_extract_return_value);
   
-  if (sysv_abi)
+  /* Note: kevinb/2002-04-12: I'm not convinced that rs6000_push_arguments()
+     is correct for the SysV ABI when the wordsize is 8, but I'm also
+     fairly certain that ppc_sysv_abi_push_arguments() will give even
+     worse results since it only works for 32-bit code.  So, for the moment,
+     we're better off calling rs6000_push_arguments() since it works for
+     64-bit code.  At some point in the future, this matter needs to be
+     revisited.  */
+  if (sysv_abi && wordsize == 4)
     set_gdbarch_push_arguments (gdbarch, ppc_sysv_abi_push_arguments);
   else
     set_gdbarch_push_arguments (gdbarch, rs6000_push_arguments);
@@ -2687,7 +2723,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
           || osabi == ELFOSABI_NETBSD
           || osabi == ELFOSABI_FREEBSD)
        set_gdbarch_use_struct_convention (gdbarch,
-                                          generic_use_struct_convention);
+                                          ppc_sysv_abi_broken_use_struct_convention);
       else
        set_gdbarch_use_struct_convention (gdbarch,
                                           ppc_sysv_abi_use_struct_convention);
@@ -2699,7 +2735,9 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     }
 
   set_gdbarch_frame_chain_valid (gdbarch, file_frame_chain_valid);
-  if (osabi == ELFOSABI_LINUX)
+  /* Note: kevinb/2002-04-12: See note above regarding *_push_arguments().
+     The same remarks hold for the methods below.  */
+  if (osabi == ELFOSABI_LINUX && wordsize == 4)
     {
       set_gdbarch_frameless_function_invocation (gdbarch,
        ppc_linux_frameless_function_invocation);
@@ -2725,8 +2763,11 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
       set_gdbarch_frame_init_saved_regs (gdbarch, rs6000_frame_init_saved_regs);
       set_gdbarch_init_extra_frame_info (gdbarch, rs6000_init_extra_frame_info);
-
-      /* Handle RS/6000 function pointers.  */
+    }
+  if (!sysv_abi)
+    {
+      /* Handle RS/6000 function pointers (which are really function
+         descriptors).  */
       set_gdbarch_convert_from_func_ptr_addr (gdbarch,
        rs6000_convert_from_func_ptr_addr);
     }