Add support for single register window model on SPARC
[deliverable/binutils-gdb.git] / gdb / sparc-tdep.c
index ff2feecb86fa10a30426e521c4252eda521708bf..faa7b3a4adc6a9848e2d9b2b3431be725f326e1d 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for SPARC.
 
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -63,7 +63,7 @@ struct regset;
    sparc64-tdep.c; don't add any here.  */
 
 /* The SPARC Floating-Point Quad-Precision format is similar to
-   big-endian IA-64 Quad-recision format.  */
+   big-endian IA-64 Quad-Precision format.  */
 #define floatformats_sparc_quad floatformats_ia64_quad
 
 /* The stack pointer is offset from the stack frame by a BIAS of 2047
@@ -145,15 +145,16 @@ sparc_is_unimp_insn (CORE_ADDR pc)
 
    More information on StackGuard can be found on in:
 
-   Mike Frantzen and Mike Shuey. "StackGhost: Hardware Facilitated
+   Mike Frantzen and Mike Shuey.  "StackGhost: Hardware Facilitated
    Stack Protection."  2001.  Published in USENIX Security Symposium
    '01.  */
 
 /* Fetch StackGhost Per-Process XOR cookie.  */
 
 ULONGEST
-sparc_fetch_wcookie (void)
+sparc_fetch_wcookie (struct gdbarch *gdbarch)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct target_ops *ops = &current_target;
   gdb_byte buf[8];
   int len;
@@ -165,7 +166,7 @@ sparc_fetch_wcookie (void)
   /* We should have either an 32-bit or an 64-bit cookie.  */
   gdb_assert (len == 4 || len == 8);
 
-  return extract_unsigned_integer (buf, len);
+  return extract_unsigned_integer (buf, len, byte_order);
 }
 \f
 
@@ -220,7 +221,11 @@ sparc_floating_p (const struct type *type)
   return 0;
 }
 
-/* Check whether TYPE is "Structure or Union".  */
+/* Check whether TYPE is "Structure or Union".
+
+   In terms of Ada subprogram calls, arrays are treated the same as
+   struct and union types.  So this function also returns non-zero
+   for array types.  */
 
 static int
 sparc_structure_or_union_p (const struct type *type)
@@ -229,6 +234,7 @@ sparc_structure_or_union_p (const struct type *type)
     {
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
+    case TYPE_CODE_ARRAY:
       return 1;
     default:
       break;
@@ -283,85 +289,104 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
   return NULL;
 }
 \f
+/* Construct types for ISA-specific registers.  */
 
-/* Type for %psr.  */
-struct type *sparc_psr_type;
+static struct type *
+sparc_psr_type (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-/* Type for %fsr.  */
-struct type *sparc_fsr_type;
+  if (!tdep->sparc_psr_type)
+    {
+      struct type *type;
 
-/* Construct types for ISA-specific registers.  */
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 4);
+      append_flags_type_flag (type, 5, "ET");
+      append_flags_type_flag (type, 6, "PS");
+      append_flags_type_flag (type, 7, "S");
+      append_flags_type_flag (type, 12, "EF");
+      append_flags_type_flag (type, 13, "EC");
 
-static void
-sparc_init_types (void)
+      tdep->sparc_psr_type = type;
+    }
+
+  return tdep->sparc_psr_type;
+}
+
+static struct type *
+sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  struct type *type;
-
-  type = init_flags_type ("builtin_type_sparc_psr", 4);
-  append_flags_type_flag (type, 5, "ET");
-  append_flags_type_flag (type, 6, "PS");
-  append_flags_type_flag (type, 7, "S");
-  append_flags_type_flag (type, 12, "EF");
-  append_flags_type_flag (type, 13, "EC");
-  sparc_psr_type = type;
-
-  type = init_flags_type ("builtin_type_sparc_fsr", 4);
-  append_flags_type_flag (type, 0, "NXA");
-  append_flags_type_flag (type, 1, "DZA");
-  append_flags_type_flag (type, 2, "UFA");
-  append_flags_type_flag (type, 3, "OFA");
-  append_flags_type_flag (type, 4, "NVA");
-  append_flags_type_flag (type, 5, "NXC");
-  append_flags_type_flag (type, 6, "DZC");
-  append_flags_type_flag (type, 7, "UFC");
-  append_flags_type_flag (type, 8, "OFC");
-  append_flags_type_flag (type, 9, "NVC");
-  append_flags_type_flag (type, 22, "NS");
-  append_flags_type_flag (type, 23, "NXM");
-  append_flags_type_flag (type, 24, "DZM");
-  append_flags_type_flag (type, 25, "UFM");
-  append_flags_type_flag (type, 26, "OFM");
-  append_flags_type_flag (type, 27, "NVM");
-  sparc_fsr_type = type;
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->sparc_fsr_type)
+    {
+      struct type *type;
+
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 4);
+      append_flags_type_flag (type, 0, "NXA");
+      append_flags_type_flag (type, 1, "DZA");
+      append_flags_type_flag (type, 2, "UFA");
+      append_flags_type_flag (type, 3, "OFA");
+      append_flags_type_flag (type, 4, "NVA");
+      append_flags_type_flag (type, 5, "NXC");
+      append_flags_type_flag (type, 6, "DZC");
+      append_flags_type_flag (type, 7, "UFC");
+      append_flags_type_flag (type, 8, "OFC");
+      append_flags_type_flag (type, 9, "NVC");
+      append_flags_type_flag (type, 22, "NS");
+      append_flags_type_flag (type, 23, "NXM");
+      append_flags_type_flag (type, 24, "DZM");
+      append_flags_type_flag (type, 25, "UFM");
+      append_flags_type_flag (type, 26, "OFM");
+      append_flags_type_flag (type, 27, "NVM");
+
+      tdep->sparc_fsr_type = type;
+    }
+
+  return tdep->sparc_fsr_type;
 }
 
 /* Return the GDB type object for the "standard" data type of data in
-   register REGNUM. */
+   register REGNUM.  */
 
 static struct type *
 sparc32_register_type (struct gdbarch *gdbarch, int regnum)
 {
   if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
-    return builtin_type_float;
+    return builtin_type (gdbarch)->builtin_float;
 
   if (regnum >= SPARC32_D0_REGNUM && regnum <= SPARC32_D30_REGNUM)
-    return builtin_type_double;
+    return builtin_type (gdbarch)->builtin_double;
 
   if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
-    return builtin_type_void_data_ptr;
+    return builtin_type (gdbarch)->builtin_data_ptr;
 
   if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM)
-    return builtin_type_void_func_ptr;
+    return builtin_type (gdbarch)->builtin_func_ptr;
 
   if (regnum == SPARC32_PSR_REGNUM)
-    return sparc_psr_type;
+    return sparc_psr_type (gdbarch);
 
   if (regnum == SPARC32_FSR_REGNUM)
-    return sparc_fsr_type;
+    return sparc_fsr_type (gdbarch);
 
-  return builtin_type_int32;
+  return builtin_type (gdbarch)->builtin_int32;
 }
 
-static void
+static enum register_status
 sparc32_pseudo_register_read (struct gdbarch *gdbarch,
                              struct regcache *regcache,
                              int regnum, gdb_byte *buf)
 {
+  enum register_status status;
+
   gdb_assert (regnum >= SPARC32_D0_REGNUM && regnum <= SPARC32_D30_REGNUM);
 
   regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC32_D0_REGNUM);
-  regcache_raw_read (regcache, regnum, buf);
-  regcache_raw_read (regcache, regnum + 1, buf + 4);
+  status = regcache_raw_read (regcache, regnum, buf);
+  if (status == REG_VALID)
+    status = regcache_raw_read (regcache, regnum + 1, buf + 4);
+  return status;
 }
 
 static void
@@ -377,6 +402,13 @@ sparc32_pseudo_register_write (struct gdbarch *gdbarch,
 }
 \f
 
+static CORE_ADDR
+sparc32_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
+{
+  /* The ABI requires double-word alignment.  */
+  return address & ~0x7;
+}
+
 static CORE_ADDR
 sparc32_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
                         CORE_ADDR funcaddr,
@@ -385,15 +417,18 @@ sparc32_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
                         CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
                         struct regcache *regcache)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   *bp_addr = sp - 4;
   *real_pc = funcaddr;
 
-  if (using_struct_return (NULL, value_type))
+  if (using_struct_return (gdbarch, NULL, value_type))
     {
       gdb_byte buf[4];
 
       /* This is an UNIMP instruction.  */
-      store_unsigned_integer (buf, 4, TYPE_LENGTH (value_type) & 0x1fff);
+      store_unsigned_integer (buf, 4, byte_order,
+                             TYPE_LENGTH (value_type) & 0x1fff);
       write_memory (sp - 8, buf, 4);
       return sp - 8;
     }
@@ -406,6 +441,8 @@ sparc32_store_arguments (struct regcache *regcache, int nargs,
                         struct value **args, CORE_ADDR sp,
                         int struct_return, CORE_ADDR struct_addr)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   /* Number of words in the "parameter array".  */
   int num_elements = 0;
   int element = 0;
@@ -442,7 +479,8 @@ sparc32_store_arguments (struct regcache *regcache, int nargs,
          gdb_assert (sparc_integral_or_pointer_p (type));
 
          if (len < 4)
-           args[i] = value_cast (builtin_type_int32, args[i]);
+           args[i] = value_cast (builtin_type (gdbarch)->builtin_int32,
+                                 args[i]);
          num_elements += ((len + 3) / 4);
        }
     }
@@ -487,7 +525,7 @@ sparc32_store_arguments (struct regcache *regcache, int nargs,
     {
       gdb_byte buf[4];
 
-      store_unsigned_integer (buf, 4, struct_addr);
+      store_unsigned_integer (buf, 4, byte_order, struct_addr);
       write_memory (sp, buf, 4);
     }
 
@@ -554,7 +592,9 @@ sparc_alloc_frame_cache (void)
 
   /* Frameless until proven otherwise.  */
   cache->frameless_p = 1;
-
+  cache->frame_offset = 0;
+  cache->saved_regs_mask = 0;
+  cache->copied_regs_mask = 0;
   cache->struct_return_p = 0;
 
   return cache;
@@ -571,19 +611,46 @@ sparc_skip_stack_check (const CORE_ADDR start_pc)
   CORE_ADDR pc = start_pc;
   unsigned long insn;
   int offset_stack_checking_sequence = 0;
+  int probing_loop = 0;
 
   /* With GCC, all stack checking sequences begin with the same two
-     instructions.  */
+     instructions, plus an optional one in the case of a probing loop:
+
+         sethi <some immediate>, %g1
+         sub %sp, %g1, %g1
+
+     or:
+
+         sethi <some immediate>, %g1
+         sethi <some immediate>, %g4
+         sub %sp, %g1, %g1
+
+     or:
+
+         sethi <some immediate>, %g1
+         sub %sp, %g1, %g1
+         sethi <some immediate>, %g4
+
+     If the optional instruction is found (setting g4), assume that a
+     probing loop will follow.  */
 
-  /* sethi <some immediate>,%g1 */
+  /* sethi <some immediate>, %g1 */
   insn = sparc_fetch_instruction (pc);
   pc = pc + 4;
   if (!(X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 1))
     return start_pc;
 
-  /* sub %sp, %g1, %g1 */
+  /* optional: sethi <some immediate>, %g4 */
   insn = sparc_fetch_instruction (pc);
   pc = pc + 4;
+  if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4)
+    {
+      probing_loop = 1;
+      insn = sparc_fetch_instruction (pc);
+      pc = pc + 4;
+    }
+
+  /* sub %sp, %g1, %g1 */
   if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn)
         && X_RD (insn) == 1 && X_RS1 (insn) == 14 && X_RS2 (insn) == 1))
     return start_pc;
@@ -591,6 +658,14 @@ sparc_skip_stack_check (const CORE_ADDR start_pc)
   insn = sparc_fetch_instruction (pc);
   pc = pc + 4;
 
+  /* optional: sethi <some immediate>, %g4 */
+  if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4)
+    {
+      probing_loop = 1;
+      insn = sparc_fetch_instruction (pc);
+      pc = pc + 4;
+    }
+
   /* First possible sequence:
          [first two instructions above]
          clr [%g1 - some immediate]  */
@@ -642,22 +717,21 @@ sparc_skip_stack_check (const CORE_ADDR start_pc)
     }
   
   /* Third sequence: A probing loop.
-         [first two instructions above]
-         sethi  <some immediate>, %g4
+         [first three instructions above]
          sub  %g1, %g4, %g4
          cmp  %g1, %g4
          be  <disp>
          add  %g1, -<some immediate>, %g1
          ba  <disp>
          clr  [%g1]
+
+     And an optional last probe for the remainder:
+
          clr [%g4 - some immediate]  */
 
-  /* sethi  <some immediate>, %g4 */
-  else if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4)
+  if (probing_loop)
     {
       /* sub  %g1, %g4, %g4 */
-      insn = sparc_fetch_instruction (pc);
-      pc = pc + 4;
       if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn)
             && X_RD (insn) == 4 && X_RS1 (insn) == 1 && X_RS2 (insn) == 4))
         return start_pc;
@@ -688,28 +762,55 @@ sparc_skip_stack_check (const CORE_ADDR start_pc)
       if (!(X_OP (insn) == 0 && X_COND (insn) == 0x8))
         return start_pc;
 
-      /* clr  [%g1] */
+      /* clr  [%g1] (st %g0, [%g1] or st %g0, [%g1+0]) */
       insn = sparc_fetch_instruction (pc);
       pc = pc + 4;
-      if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && !X_I(insn)
-            && X_RD (insn) == 0 && X_RS1 (insn) == 1))
+      if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4
+            && X_RD (insn) == 0 && X_RS1 (insn) == 1
+           && (!X_I(insn) || X_SIMM13 (insn) == 0)))
         return start_pc;
 
-      /* clr [%g4 - some immediate]  */
+      /* We found a valid stack-check sequence, return the new PC.  */
+
+      /* optional: clr [%g4 - some immediate]  */
       insn = sparc_fetch_instruction (pc);
       pc = pc + 4;
       if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && X_I(insn)
             && X_RS1 (insn) == 4 && X_RD (insn) == 0))
-        return start_pc;
-
-      /* We found a valid stack-check sequence, return the new PC.  */
-      return pc;
+        return pc - 4;
+      else
+       return pc;
     }
 
   /* No stack check code in our prologue, return the start_pc.  */
   return start_pc;
 }
 
+/* Record the effect of a SAVE instruction on CACHE.  */
+
+void
+sparc_record_save_insn (struct sparc_frame_cache *cache)
+{
+  /* The frame is set up.  */
+  cache->frameless_p = 0;
+
+  /* The frame pointer contains the CFA.  */
+  cache->frame_offset = 0;
+
+  /* The `local' and `in' registers are all saved.  */
+  cache->saved_regs_mask = 0xffff;
+
+  /* The `out' registers are all renamed.  */
+  cache->copied_regs_mask = 0xff;
+}
+
+/* Do a full analysis of the prologue at PC and update CACHE accordingly.
+   Bail out early if CURRENT_PC is reached.  Return the address where
+   the analysis stopped.
+
+   We handle both the traditional register window model and the single
+   register window (aka flat) model.  */
+
 CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
                        CORE_ADDR current_pc, struct sparc_frame_cache *cache)
@@ -739,13 +840,40 @@ sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 
   insn = sparc_fetch_instruction (pc);
 
+  /* Recognize store insns and record their sources.  */
+  while (X_OP (insn) == 3
+        && (X_OP3 (insn) == 0x4     /* stw */
+            || X_OP3 (insn) == 0x7  /* std */
+            || X_OP3 (insn) == 0xe) /* stx */
+        && X_RS1 (insn) == SPARC_SP_REGNUM)
+    {
+      int regnum = X_RD (insn);
+
+      /* Recognize stores into the corresponding stack slots.  */
+      if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
+         && ((X_I (insn)
+              && X_SIMM13 (insn) == (X_OP3 (insn) == 0xe
+                                     ? (regnum - SPARC_L0_REGNUM) * 8 + BIAS
+                                     : (regnum - SPARC_L0_REGNUM) * 4))
+             || (!X_I (insn) && regnum == SPARC_L0_REGNUM)))
+       {
+         cache->saved_regs_mask |= (1 << (regnum - SPARC_L0_REGNUM));
+         if (X_OP3 (insn) == 0x7)
+           cache->saved_regs_mask |= (1 << (regnum + 1 - SPARC_L0_REGNUM));
+       }
+
+      offset += 4;
+
+      insn = sparc_fetch_instruction (pc + offset);
+    }
+
   /* Recognize a SETHI insn and record its destination.  */
   if (X_OP (insn) == 0 && X_OP2 (insn) == 0x04)
     {
       dest = X_RD (insn);
       offset += 4;
 
-      insn = sparc_fetch_instruction (pc + 4);
+      insn = sparc_fetch_instruction (pc + offset);
     }
 
   /* Allow for an arithmetic operation on DEST or %g1.  */
@@ -754,14 +882,62 @@ sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
     {
       offset += 4;
 
-      insn = sparc_fetch_instruction (pc + 8);
+      insn = sparc_fetch_instruction (pc + offset);
     }
 
   /* Check for the SAVE instruction that sets up the frame.  */
   if (X_OP (insn) == 2 && X_OP3 (insn) == 0x3c)
     {
-      cache->frameless_p = 0;
-      return pc + offset + 4;
+      sparc_record_save_insn (cache);
+      offset += 4;
+      return pc + offset;
+    }
+
+  /* Check for an arithmetic operation on %sp.  */
+  if (X_OP (insn) == 2
+      && (X_OP3 (insn) == 0 || X_OP3 (insn) == 0x4)
+      && X_RS1 (insn) == SPARC_SP_REGNUM
+      && X_RD (insn) == SPARC_SP_REGNUM)
+    {
+      if (X_I (insn))
+       {
+         cache->frame_offset = X_SIMM13 (insn);
+         if (X_OP3 (insn) == 0)
+           cache->frame_offset = -cache->frame_offset;
+       }
+      offset += 4;
+
+      insn = sparc_fetch_instruction (pc + offset);
+
+      /* Check for an arithmetic operation that sets up the frame.  */
+      if (X_OP (insn) == 2
+         && (X_OP3 (insn) == 0 || X_OP3 (insn) == 0x4)
+         && X_RS1 (insn) == SPARC_SP_REGNUM
+         && X_RD (insn) == SPARC_FP_REGNUM)
+       {
+         cache->frameless_p = 0;
+         cache->frame_offset = 0;
+         /* We could check that the amount subtracted to %sp above is the
+            same as the one added here, but this seems superfluous.  */
+         cache->copied_regs_mask |= 0x40;
+         offset += 4;
+
+         insn = sparc_fetch_instruction (pc + offset);
+       }
+
+      /* Check for a move (or) operation that copies the return register.  */
+      if (X_OP (insn) == 2
+         && X_OP3 (insn) == 0x2
+         && !X_I (insn)
+         && X_RS1 (insn) == SPARC_G0_REGNUM
+         && X_RS2 (insn) == SPARC_O7_REGNUM
+         && X_RD (insn) == SPARC_I7_REGNUM)
+       {
+          cache->copied_regs_mask |= 0x80;
+          offset += 4;
+       }
+
+      return pc + offset;
     }
 
   return pc;
@@ -804,21 +980,36 @@ sparc32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
      indeed what GCC seems to be doing.  In that case GCC will
      generate debug information that points to the stack slots instead
      of the registers, so we should consider the instructions that
-     write out these incoming arguments onto the stack.  Of course we
-     only need to do this if we have a stack frame.  */
+     write out these incoming arguments onto the stack.  */
 
-  while (!cache.frameless_p)
+  while (1)
     {
       unsigned long insn = sparc_fetch_instruction (start_pc);
 
-      /* Recognize instructions that store incoming arguments in
-         %i0...%i5 into the corresponding stack slot.  */
-      if (X_OP (insn) == 3 && (X_OP3 (insn) & 0x3c) == 0x04 && X_I (insn)
-         && (X_RD (insn) >= 24 && X_RD (insn) <= 29) && X_RS1 (insn) == 30
-         && X_SIMM13 (insn) == 68 + (X_RD (insn) - 24) * 4)
+      /* Recognize instructions that store incoming arguments into the
+        corresponding stack slots.  */
+      if (X_OP (insn) == 3 && (X_OP3 (insn) & 0x3c) == 0x04
+         && X_I (insn) && X_RS1 (insn) == SPARC_FP_REGNUM)
        {
-         start_pc += 4;
-         continue;
+         int regnum = X_RD (insn);
+
+         /* Case of arguments still in %o[0..5].  */
+         if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O5_REGNUM
+             && !(cache.copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM)))
+             && X_SIMM13 (insn) == 68 + (regnum - SPARC_O0_REGNUM) * 4)
+           {
+             start_pc += 4;
+             continue;
+           }
+
+         /* Case of arguments copied into %i[0..5].  */
+         if (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I5_REGNUM
+             && (cache.copied_regs_mask & (1 << (regnum - SPARC_I0_REGNUM)))
+             && X_SIMM13 (insn) == 68 + (regnum - SPARC_I0_REGNUM) * 4)
+           {
+             start_pc += 4;
+             continue;
+           }
        }
 
       break;
@@ -861,6 +1052,8 @@ sparc_frame_cache (struct frame_info *this_frame, void **this_cache)
        get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
     }
 
+  cache->base += cache->frame_offset;
+
   if (cache->base & 1)
     cache->base += BIAS;
 
@@ -909,7 +1102,8 @@ sparc32_frame_cache (struct frame_info *this_frame, void **this_cache)
          an "unimp" instruction.  If it is, then it is a struct-return
          function.  */
       CORE_ADDR pc;
-      int regnum = cache->frameless_p ? SPARC_O7_REGNUM : SPARC_I7_REGNUM;
+      int regnum =
+       (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
 
       pc = get_frame_register_unsigned (this_frame, regnum) + 8;
       if (sparc_is_unimp_insn (pc))
@@ -937,6 +1131,7 @@ static struct value *
 sparc32_frame_prev_register (struct frame_info *this_frame,
                             void **this_cache, int regnum)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
   struct sparc_frame_cache *cache =
     sparc32_frame_cache (this_frame, this_cache);
 
@@ -950,14 +1145,15 @@ sparc32_frame_prev_register (struct frame_info *this_frame,
       if (cache->struct_return_p)
        pc += 4;
 
-      regnum = cache->frameless_p ? SPARC_O7_REGNUM : SPARC_I7_REGNUM;
+      regnum =
+       (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
       pc += get_frame_register_unsigned (this_frame, regnum) + 8;
       return frame_unwind_got_constant (this_frame, regnum, pc);
     }
 
   /* Handle StackGhost.  */
   {
-    ULONGEST wcookie = sparc_fetch_wcookie ();
+    ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
 
     if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
       {
@@ -970,20 +1166,20 @@ sparc32_frame_prev_register (struct frame_info *this_frame,
       }
   }
 
-  /* The previous frame's `local' and `in' registers have been saved
+  /* The previous frame's `local' and `in' registers may have been saved
      in the register save area.  */
-  if (!cache->frameless_p
-      && regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM)
+  if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
+      && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
     {
       CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 4;
 
       return frame_unwind_got_memory (this_frame, regnum, addr);
     }
 
-  /* The previous frame's `out' registers are accessible as the
-     current frame's `in' registers.  */
-  if (!cache->frameless_p
-      && regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
+  /* The previous frame's `out' registers may be accessible as the current
+     frame's `in' registers.  */
+  if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
+      && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
     regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
 
   return frame_unwind_got_register (this_frame, regnum, regnum);
@@ -992,6 +1188,7 @@ sparc32_frame_prev_register (struct frame_info *this_frame,
 static const struct frame_unwind sparc32_frame_unwind =
 {
   NORMAL_FRAME,
+  default_frame_unwind_stop_reason,
   sparc32_frame_this_id,
   sparc32_frame_prev_register,
   NULL,
@@ -1082,6 +1279,7 @@ sparc32_store_return_value (struct type *type, struct regcache *regcache,
 
   gdb_assert (!sparc_structure_or_union_p (type));
   gdb_assert (!(sparc_floating_p (type) && len == 16));
+  gdb_assert (len <= 8);
 
   if (sparc_floating_p (type))
     {
@@ -1116,6 +1314,8 @@ sparc32_return_value (struct gdbarch *gdbarch, struct type *func_type,
                      struct type *type, struct regcache *regcache,
                      gdb_byte *readbuf, const gdb_byte *writebuf)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   /* The psABI says that "...every stack frame reserves the word at
      %fp+64.  If a function returns a structure, union, or
      quad-precision value, this word should hold the address of the
@@ -1132,7 +1332,7 @@ sparc32_return_value (struct gdbarch *gdbarch, struct type *func_type,
          CORE_ADDR addr;
 
          regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
-         addr = read_memory_unsigned_integer (sp + 64, 4);
+         addr = read_memory_unsigned_integer (sp + 64, 4, byte_order);
          read_memory (addr, readbuf, TYPE_LENGTH (type));
        }
 
@@ -1287,6 +1487,7 @@ sparc_software_single_step (struct frame_info *frame)
 {
   struct gdbarch *arch = get_frame_arch (frame);
   struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
+  struct address_space *aspace = get_frame_address_space (frame);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1297,10 +1498,10 @@ sparc_software_single_step (struct frame_info *frame)
   /* Analyze the instruction at PC.  */
   nnpc = sparc_analyze_control_transfer (frame, pc, &npc);
   if (npc != 0)
-    insert_single_step_breakpoint (npc);
+    insert_single_step_breakpoint (arch, aspace, npc);
 
   if (nnpc != 0)
-    insert_single_step_breakpoint (nnpc);
+    insert_single_step_breakpoint (arch, aspace, nnpc);
 
   /* Assert that we have set at least one breakpoint, and that
      they're not set at the same spot - unless we're going
@@ -1324,7 +1525,7 @@ sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 /* Return the appropriate register set for the core section identified
    by SECT_NAME and SECT_SIZE.  */
 
-const struct regset *
+static const struct regset *
 sparc_regset_from_core_section (struct gdbarch *gdbarch,
                                const char *sect_name, size_t sect_size)
 {
@@ -1352,16 +1553,11 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     return arches->gdbarch;
 
   /* Allocate space for the new architecture.  */
-  tdep = XMALLOC (struct gdbarch_tdep);
+  tdep = XZALLOC (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   tdep->pc_regnum = SPARC32_PC_REGNUM;
   tdep->npc_regnum = SPARC32_NPC_REGNUM;
-  tdep->gregset = NULL;
-  tdep->sizeof_gregset = 0;
-  tdep->fpregset = NULL;
-  tdep->sizeof_fpregset = 0;
-  tdep->plt_entry_size = 0;
   tdep->step_trap = sparc_step_trap;
 
   set_gdbarch_long_double_bit (gdbarch, 128);
@@ -1380,6 +1576,7 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_fp0_regnum (gdbarch, SPARC_F0_REGNUM); /* %f0 */
 
   /* Call dummy code.  */
+  set_gdbarch_frame_align (gdbarch, sparc32_frame_align);
   set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
   set_gdbarch_push_dummy_code (gdbarch, sparc32_push_dummy_code);
   set_gdbarch_push_dummy_call (gdbarch, sparc32_push_dummy_call);
@@ -1431,6 +1628,8 @@ sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 void
 sparc_supply_rwindow (struct regcache *regcache, CORE_ADDR sp, int regnum)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int offset = 0;
   gdb_byte buf[8];
   int i;
@@ -1449,10 +1648,12 @@ sparc_supply_rwindow (struct regcache *regcache, CORE_ADDR sp, int regnum)
              /* Handle StackGhost.  */
              if (i == SPARC_I7_REGNUM)
                {
-                 ULONGEST wcookie = sparc_fetch_wcookie ();
-                 ULONGEST i7 = extract_unsigned_integer (buf + offset, 8);
+                 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
+                 ULONGEST i7;
 
-                 store_unsigned_integer (buf + offset, 8, i7 ^ wcookie);
+                 i7 = extract_unsigned_integer (buf + offset, 8, byte_order);
+                 store_unsigned_integer (buf + offset, 8, byte_order,
+                                         i7 ^ wcookie);
                }
 
              regcache_raw_supply (regcache, i, buf);
@@ -1483,10 +1684,12 @@ sparc_supply_rwindow (struct regcache *regcache, CORE_ADDR sp, int regnum)
              /* Handle StackGhost.  */
              if (i == SPARC_I7_REGNUM)
                {
-                 ULONGEST wcookie = sparc_fetch_wcookie ();
-                 ULONGEST i7 = extract_unsigned_integer (buf + offset, 4);
+                 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
+                 ULONGEST i7;
 
-                 store_unsigned_integer (buf + offset, 4, i7 ^ wcookie);
+                 i7 = extract_unsigned_integer (buf + offset, 4, byte_order);
+                 store_unsigned_integer (buf + offset, 4, byte_order,
+                                         i7 ^ wcookie);
                }
 
              regcache_raw_supply (regcache, i, buf);
@@ -1499,6 +1702,8 @@ void
 sparc_collect_rwindow (const struct regcache *regcache,
                       CORE_ADDR sp, int regnum)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int offset = 0;
   gdb_byte buf[8];
   int i;
@@ -1517,10 +1722,11 @@ sparc_collect_rwindow (const struct regcache *regcache,
              /* Handle StackGhost.  */
              if (i == SPARC_I7_REGNUM)
                {
-                 ULONGEST wcookie = sparc_fetch_wcookie ();
-                 ULONGEST i7 = extract_unsigned_integer (buf + offset, 8);
+                 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
+                 ULONGEST i7;
 
-                 store_unsigned_integer (buf, 8, i7 ^ wcookie);
+                 i7 = extract_unsigned_integer (buf + offset, 8, byte_order);
+                 store_unsigned_integer (buf, 8, byte_order, i7 ^ wcookie);
                }
 
              target_write_memory (sp + ((i - SPARC_L0_REGNUM) * 8), buf, 8);
@@ -1546,10 +1752,12 @@ sparc_collect_rwindow (const struct regcache *regcache,
              /* Handle StackGhost.  */
              if (i == SPARC_I7_REGNUM)
                {
-                 ULONGEST wcookie = sparc_fetch_wcookie ();
-                 ULONGEST i7 = extract_unsigned_integer (buf + offset, 4);
+                 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
+                 ULONGEST i7;
 
-                 store_unsigned_integer (buf + offset, 4, i7 ^ wcookie);
+                 i7 = extract_unsigned_integer (buf + offset, 4, byte_order);
+                 store_unsigned_integer (buf + offset, 4, byte_order,
+                                         i7 ^ wcookie);
                }
 
              target_write_memory (sp + ((i - SPARC_L0_REGNUM) * 4),
@@ -1567,6 +1775,7 @@ sparc32_supply_gregset (const struct sparc_gregset *gregset,
                        int regnum, const void *gregs)
 {
   const gdb_byte *regs = gregs;
+  gdb_byte zero[4] = { 0 };
   int i;
 
   if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
@@ -1586,7 +1795,7 @@ sparc32_supply_gregset (const struct sparc_gregset *gregset,
                         regs + gregset->r_y_offset);
 
   if (regnum == SPARC_G0_REGNUM || regnum == -1)
-    regcache_raw_supply (regcache, SPARC_G0_REGNUM, NULL);
+    regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero);
 
   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
     {
@@ -1738,7 +1947,4 @@ void
 _initialize_sparc_tdep (void)
 {
   register_gdbarch_init (bfd_arch_sparc, sparc32_gdbarch_init);
-
-  /* Initialize the SPARC-specific register types.  */
-  sparc_init_types();
 }
This page took 0.035847 seconds and 4 git commands to generate.