2010-04-04 Stan Shebs <stan@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / hppa-tdep.c
index 6d70c6d068081a69d40757e51302bc2df44c4b50..a0665efdd210899854d2c7562b80b74c19cafe9c 100644 (file)
@@ -1,7 +1,7 @@
 /* Target-dependent code for the HP PA-RISC architecture.
 
    Copyright (C) 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
@@ -540,6 +540,7 @@ find_unwind_entry (CORE_ADDR pc)
 static int
 hppa_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long status;
   unsigned int inst;
   char buf[4];
@@ -549,7 +550,7 @@ hppa_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
   if (status != 0)
     return 0;
 
-  inst = extract_unsigned_integer (buf, 4);
+  inst = extract_unsigned_integer (buf, 4, byte_order);
 
   /* The most common way to perform a stack adjustment ldo X(sp),sp 
      We are destroying a stack frame if the offset is negative.  */
@@ -690,6 +691,8 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                        int nargs, struct value **args, CORE_ADDR sp,
                        int struct_return, CORE_ADDR struct_addr)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   /* Stack base address at which any pass-by-reference parameters are
      stored.  */
   CORE_ADDR struct_end = 0;
@@ -737,7 +740,8 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
              if (write_pass)
                write_memory (struct_end - struct_ptr, value_contents (arg),
                              TYPE_LENGTH (type));
-             store_unsigned_integer (param_val, 4, struct_end - struct_ptr);
+             store_unsigned_integer (param_val, 4, byte_order,
+                                     struct_end - struct_ptr);
            }
          else if (TYPE_CODE (type) == TYPE_CODE_INT
                   || TYPE_CODE (type) == TYPE_CODE_ENUM)
@@ -745,7 +749,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
              /* Integer value store, right aligned.  "unpack_long"
                 takes care of any sign-extension problems.  */
              param_len = align_up (TYPE_LENGTH (type), 4);
-             store_unsigned_integer (param_val, param_len,
+             store_unsigned_integer (param_val, param_len, byte_order,
                                      unpack_long (type,
                                                   value_contents (arg)));
            }
@@ -898,8 +902,9 @@ hppa64_floating_p (const struct type *type)
    function descriptor and return its address instead.  If CODE is not a
    function entry address, then just return it unchanged.  */
 static CORE_ADDR
-hppa64_convert_code_addr_to_fptr (CORE_ADDR code)
+hppa64_convert_code_addr_to_fptr (struct gdbarch *gdbarch, CORE_ADDR code)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *sec, *opd;
 
   sec = find_pc_section (code);
@@ -930,7 +935,7 @@ hppa64_convert_code_addr_to_fptr (CORE_ADDR code)
 
          if (target_read_memory (addr, tmp, sizeof (tmp)))
              break;
-         opdaddr = extract_unsigned_integer (tmp, sizeof (tmp));
+         opdaddr = extract_unsigned_integer (tmp, sizeof (tmp), byte_order);
 
          if (opdaddr == code)
            return addr - 16;
@@ -947,6 +952,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                        int struct_return, CORE_ADDR struct_addr)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
 
@@ -1044,8 +1050,9 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
          ULONGEST codeptr, fptr;
 
          codeptr = unpack_long (type, value_contents (arg));
-         fptr = hppa64_convert_code_addr_to_fptr (codeptr);
-         store_unsigned_integer (fptrbuf, TYPE_LENGTH (type), fptr);
+         fptr = hppa64_convert_code_addr_to_fptr (gdbarch, codeptr);
+         store_unsigned_integer (fptrbuf, TYPE_LENGTH (type), byte_order,
+                                 fptr);
          valbuf = fptrbuf;
        }
       else
@@ -1298,41 +1305,6 @@ hppa_write_pc (struct regcache *regcache, CORE_ADDR pc)
   regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pc + 4);
 }
 
-/* return the alignment of a type in bytes. Structures have the maximum
-   alignment required by their fields. */
-
-static int
-hppa_alignof (struct type *type)
-{
-  int max_align, align, i;
-  CHECK_TYPEDEF (type);
-  switch (TYPE_CODE (type))
-    {
-    case TYPE_CODE_PTR:
-    case TYPE_CODE_INT:
-    case TYPE_CODE_FLT:
-      return TYPE_LENGTH (type);
-    case TYPE_CODE_ARRAY:
-      return hppa_alignof (TYPE_INDEX_TYPE (type));
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      max_align = 1;
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
-       {
-         /* Bit fields have no real alignment. */
-         /* if (!TYPE_FIELD_BITPOS (type, i)) */
-         if (!TYPE_FIELD_BITSIZE (type, i))    /* elz: this should be bitsize */
-           {
-             align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
-             max_align = max (max_align, align);
-           }
-       }
-      return max_align;
-    default:
-      return 4;
-    }
-}
-
 /* For the given instruction (INST), return any adjustment it makes
    to the stack pointer or zero for no adjustment. 
 
@@ -1476,6 +1448,7 @@ static CORE_ADDR
 skip_prologue_hard_way (struct gdbarch *gdbarch, CORE_ADDR pc,
                        int stop_before_branch)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   char buf[4];
   CORE_ADDR orig_pc = pc;
   unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
@@ -1557,7 +1530,7 @@ restart:
       old_stack_remaining = stack_remaining;
 
       status = target_read_memory (pc, buf, 4);
-      inst = extract_unsigned_integer (buf, 4);
+      inst = extract_unsigned_integer (buf, 4, byte_order);
 
       /* Yow! */
       if (status != 0)
@@ -1608,7 +1581,7 @@ restart:
            {
              pc += 4;
              status = target_read_memory (pc, buf, 4);
-             inst = extract_unsigned_integer (buf, 4);
+             inst = extract_unsigned_integer (buf, 4, byte_order);
              if (status != 0)
                return pc;
              reg_num = inst_saves_gr (inst);
@@ -1621,7 +1594,7 @@ restart:
       save_fr &= ~(1 << reg_num);
 
       status = target_read_memory (pc + 4, buf, 4);
-      next_inst = extract_unsigned_integer (buf, 4);
+      next_inst = extract_unsigned_integer (buf, 4, byte_order);
 
       /* Yow! */
       if (status != 0)
@@ -1652,13 +1625,13 @@ restart:
            {
              pc += 8;
              status = target_read_memory (pc, buf, 4);
-             inst = extract_unsigned_integer (buf, 4);
+             inst = extract_unsigned_integer (buf, 4, byte_order);
              if (status != 0)
                return pc;
              if ((inst & 0xfc000000) != 0x34000000)
                break;
              status = target_read_memory (pc + 4, buf, 4);
-             next_inst = extract_unsigned_integer (buf, 4);
+             next_inst = extract_unsigned_integer (buf, 4, byte_order);
              if (status != 0)
                return pc;
              reg_num = inst_saves_fr (next_inst);
@@ -1816,6 +1789,8 @@ static struct hppa_frame_cache *
 hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   struct hppa_frame_cache *cache;
   long saved_gr_mask;
   long saved_fr_mask;
@@ -1940,7 +1915,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
            return (*this_cache);
          }
 
-       inst = extract_unsigned_integer (buf4, sizeof buf4);
+       inst = extract_unsigned_integer (buf4, sizeof buf4, byte_order);
 
        /* Note the interesting effects of this instruction.  */
        frame_size += prologue_inst_adjust_sp (inst);
@@ -2109,8 +2084,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
             /* Both we're expecting the SP to be saved and the SP has been
               saved.  The entry SP value is saved at this frame's SP
               address.  */
-            cache->base = read_memory_integer
-                           (this_sp, gdbarch_ptr_bit (gdbarch) / 8);
+            cache->base = read_memory_integer (this_sp, word_size, byte_order);
 
            if (hppa_debug)
              fprintf_unfiltered (gdb_stdlog, " (base=%s) [saved]",
@@ -2265,6 +2239,8 @@ static const struct frame_unwind hppa_frame_unwind =
 static struct hppa_frame_cache *
 hppa_fallback_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct hppa_frame_cache *cache;
   unsigned int frame_size = 0;
   int found_rp = 0;
@@ -2289,7 +2265,7 @@ hppa_fallback_frame_cache (struct frame_info *this_frame, void **this_cache)
        {
          unsigned int insn;
 
-         insn = read_memory_unsigned_integer (pc, 4);
+         insn = read_memory_unsigned_integer (pc, 4, byte_order);
          frame_size += prologue_inst_adjust_sp (insn);
 
          /* There are limited ways to store the return pointer into the
@@ -2416,8 +2392,6 @@ hppa_stub_frame_this_id (struct frame_info *this_frame,
 
   if (info)
     *this_id = frame_id_build (info->base, get_frame_func (this_frame));
-  else
-    *this_id = null_frame_id;
 }
 
 static struct value *
@@ -2444,7 +2418,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
-         && tdep->in_solib_call_trampoline (pc, NULL))
+         && tdep->in_solib_call_trampoline (gdbarch, pc, NULL))
       || gdbarch_in_solib_return_trampoline (gdbarch, pc, NULL))
     return 1;
   return 0;
@@ -2690,12 +2664,13 @@ static void
 hppa_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
                           int regnum, gdb_byte *buf)
 {
+    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
     ULONGEST tmp;
 
     regcache_raw_read_unsigned (regcache, regnum, &tmp);
     if (regnum == HPPA_PCOQ_HEAD_REGNUM || regnum == HPPA_PCOQ_TAIL_REGNUM)
       tmp &= ~0x3;
-    store_unsigned_integer (buf, sizeof tmp, tmp);
+    store_unsigned_integer (buf, sizeof tmp, byte_order, tmp);
 }
 
 static CORE_ADDR
@@ -2710,6 +2685,7 @@ hppa_frame_prev_register_helper (struct frame_info *this_frame,
                                 int regnum)
 {
   struct gdbarch *arch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (arch);
 
   if (regnum == HPPA_PCOQ_TAIL_REGNUM)
     {
@@ -2719,7 +2695,8 @@ hppa_frame_prev_register_helper (struct frame_info *this_frame,
         trad_frame_get_prev_register (this_frame, saved_regs,
                                       HPPA_PCOQ_HEAD_REGNUM);
 
-      pc = extract_unsigned_integer (value_contents_all (pcoq_val), size);
+      pc = extract_unsigned_integer (value_contents_all (pcoq_val),
+                                    size, byte_order);
       return frame_unwind_got_constant (this_frame, regnum, pc + 4);
     }
 
@@ -2817,9 +2794,10 @@ static struct insn_pattern hppa_sigtramp[] = {
    matched.  */
 
 static int
-hppa_match_insns (CORE_ADDR pc, struct insn_pattern *pattern,
-                 unsigned int *insn)
+hppa_match_insns (struct gdbarch *gdbarch, CORE_ADDR pc,
+                 struct insn_pattern *pattern, unsigned int *insn)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR npc = pc;
   int i;
 
@@ -2828,7 +2806,7 @@ hppa_match_insns (CORE_ADDR pc, struct insn_pattern *pattern,
       gdb_byte buf[HPPA_INSN_SIZE];
 
       target_read_memory (npc, buf, HPPA_INSN_SIZE);
-      insn[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE);
+      insn[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE, byte_order);
       if ((insn[i] & pattern[i].mask) == pattern[i].data)
         npc += 4;
       else
@@ -2843,8 +2821,8 @@ hppa_match_insns (CORE_ADDR pc, struct insn_pattern *pattern,
    instruction scheme.  */
 
 static int
-hppa_match_insns_relaxed (CORE_ADDR pc, struct insn_pattern *pattern,
-                         unsigned int *insn)
+hppa_match_insns_relaxed (struct gdbarch *gdbarch, CORE_ADDR pc,
+                         struct insn_pattern *pattern, unsigned int *insn)
 {
   int offset, len = 0;
 
@@ -2852,7 +2830,8 @@ hppa_match_insns_relaxed (CORE_ADDR pc, struct insn_pattern *pattern,
     len++;
 
   for (offset = 0; offset < len; offset++)
-    if (hppa_match_insns (pc - offset * HPPA_INSN_SIZE, pattern, insn))
+    if (hppa_match_insns (gdbarch, pc - offset * HPPA_INSN_SIZE,
+                         pattern, insn))
       return 1;
 
   return 0;
@@ -2871,7 +2850,8 @@ hppa_in_dyncall (CORE_ADDR pc)
 }
 
 int
-hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name)
+hppa_in_solib_call_trampoline (struct gdbarch *gdbarch,
+                              CORE_ADDR pc, char *name)
 {
   unsigned int insn[HPPA_MAX_INSN_PATTERN_LEN];
   struct unwind_table_entry *u;
@@ -2887,10 +2867,12 @@ hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name)
   if (u != NULL)
     return 0;
 
-  return (hppa_match_insns_relaxed (pc, hppa_import_stub, insn)
-         || hppa_match_insns_relaxed (pc, hppa_import_pic_stub, insn)
-         || hppa_match_insns_relaxed (pc, hppa_long_branch_stub, insn)
-         || hppa_match_insns_relaxed (pc, hppa_long_branch_pic_stub, insn));
+  return
+    (hppa_match_insns_relaxed (gdbarch, pc, hppa_import_stub, insn)
+     || hppa_match_insns_relaxed (gdbarch, pc, hppa_import_pic_stub, insn)
+     || hppa_match_insns_relaxed (gdbarch, pc, hppa_long_branch_stub, insn)
+     || hppa_match_insns_relaxed (gdbarch, pc,
+                                 hppa_long_branch_pic_stub, insn));
 }
 
 /* This code skips several kind of "trampolines" used on PA-RISC
@@ -2917,8 +2899,8 @@ hppa_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
       return pc;
     }
 
-  dp_rel = hppa_match_insns (pc, hppa_import_stub, insn);
-  if (dp_rel || hppa_match_insns (pc, hppa_import_pic_stub, insn))
+  dp_rel = hppa_match_insns (gdbarch, pc, hppa_import_stub, insn);
+  if (dp_rel || hppa_match_insns (gdbarch, pc, hppa_import_pic_stub, insn))
     {
       /* Extract the target address from the addil/ldw sequence.  */
       pc = hppa_extract_21 (insn[0]) + hppa_extract_14 (insn[1]);
@@ -2940,7 +2922,7 @@ hppa_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
       if (in_plt_section (pc, NULL))
        {
          /* Sanity check: are we pointing to the PLT stub?  */
-         if (!hppa_match_insns (pc, hppa_plt_stub, insn))
+         if (!hppa_match_insns (gdbarch, pc, hppa_plt_stub, insn))
            {
              warning (_("Cannot resolve PLT stub at %s."),
                       paddress (gdbarch, pc));
This page took 0.029517 seconds and 4 git commands to generate.