* hppa-tdep.h (find_global_pointer): Add gdbarch as parameter.
[deliverable/binutils-gdb.git] / gdb / hppa-hpux-tdep.c
index ba2390cd6b03ae82250a4c7f04a65f4a084e347c..0c469b9597df5abeb119df61cfd121d61c77bd58 100644 (file)
@@ -1,12 +1,13 @@
 /* Target-dependent code for HP-UX on PA-RISC.
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -15,9 +16,7 @@
    GNU General Public License for more details.
 
    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., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "arch-utils.h"
@@ -299,8 +298,9 @@ hppa_hpux_in_solib_return_trampoline (CORE_ADDR pc, char *name)
    used in dynamic executables.  */
 
 static CORE_ADDR
-hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
+hppa_hpux_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
+  struct gdbarch *gdbarch = get_frame_arch (frame);
   long orig_pc = pc;
   long prev_inst, curr_inst, loc;
   struct minimal_symbol *msym;
@@ -310,21 +310,23 @@ hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
      of the function.  So we may have to do something special.  */
   if (pc == hppa_symbol_address("$$dyncall"))
     {
-      pc = (CORE_ADDR) read_register (22);
+      pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
 
       /* If bit 30 (counting from the left) is on, then pc is the address of
          the PLT entry for this function, not the address of the function
          itself.  Bit 31 has meaning too, but only for MPE.  */
       if (pc & 0x2)
-       pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
+       pc = (CORE_ADDR) read_memory_integer
+                          (pc & ~0x3, gdbarch_ptr_bit (gdbarch) / 8);
     }
   if (pc == hppa_symbol_address("$$dyncall_external"))
     {
-      pc = (CORE_ADDR) read_register (22);
-      pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
+      pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
+      pc = (CORE_ADDR) read_memory_integer
+                        (pc & ~0x3, gdbarch_ptr_bit (gdbarch) / 8);
     }
   else if (pc == hppa_symbol_address("_sr4export"))
-    pc = (CORE_ADDR) (read_register (22));
+    pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
 
   /* Get the unwind descriptor corresponding to PC, return zero
      if no unwind was found.  */
@@ -374,7 +376,8 @@ hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
          ALL_MSYMBOLS (objfile, msymbol)
          {
            if (MSYMBOL_TYPE (msymbol) == mst_text
-               && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym)))
+               && strcmp (DEPRECATED_SYMBOL_NAME (msymbol),
+                           DEPRECATED_SYMBOL_NAME (msym)) == 0)
              {
                function_found = 1;
                break;
@@ -498,8 +501,11 @@ hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
          /* Yup.  See if the previous instruction loaded
             rp from sp - 8.  */
          if (prev_inst == 0x4bc23ff1)
-           return (read_memory_integer
-                   (read_register (HPPA_SP_REGNUM) - 8, 4)) & ~0x3;
+           {
+             CORE_ADDR sp;
+             sp = get_frame_register_unsigned (frame, HPPA_SP_REGNUM);
+             return read_memory_integer (sp - 8, 4) & ~0x3;
+           }
          else
            {
              warning (_("Unable to find restore of %%rp before bv (%%rp)."));
@@ -513,7 +519,8 @@ hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
       else if ((curr_inst & 0xffe0f000) == 0xe840d000)
        {
          return (read_memory_integer
-                 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
+                 (get_frame_register_unsigned (frame, HPPA_SP_REGNUM) - 24,
+                  gdbarch_ptr_bit (gdbarch) / 8)) & ~0x3;
        }
 
       /* What about be,n 0(sr0,%rp)?  It's just another way we return to
@@ -525,7 +532,8 @@ hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
             I guess we could check for the previous instruction being
             mtsp %r1,%sr0 if we want to do sanity checking.  */
          return (read_memory_integer
-                 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
+                 (get_frame_register_unsigned (frame, HPPA_SP_REGNUM) - 24,
+                  gdbarch_ptr_bit (gdbarch) / 8)) & ~0x3;
        }
 
       /* Haven't found the branch yet, but we're still in the stub.
@@ -733,7 +741,8 @@ hppa_hpux_sigtramp_unwind_sniffer (struct frame_info *next_frame)
 }
 
 static CORE_ADDR
-hppa32_hpux_find_global_pointer (struct value *function)
+hppa32_hpux_find_global_pointer (struct gdbarch *gdbarch,
+                                struct value *function)
 {
   CORE_ADDR faddr;
   
@@ -752,11 +761,12 @@ hppa32_hpux_find_global_pointer (struct value *function)
        return extract_unsigned_integer (buf, sizeof (buf));
     }
 
-  return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
+  return gdbarch_tdep (gdbarch)->solib_get_got_by_pc (faddr);
 }
 
 static CORE_ADDR
-hppa64_hpux_find_global_pointer (struct value *function)
+hppa64_hpux_find_global_pointer (struct gdbarch *gdbarch,
+                                struct value *function)
 {
   CORE_ADDR faddr;
   char buf[32];
@@ -770,7 +780,7 @@ hppa64_hpux_find_global_pointer (struct value *function)
     }
   else
     {
-      return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
+      return gdbarch_tdep (gdbarch)->solib_get_got_by_pc (faddr);
     }
 }
 
@@ -1023,11 +1033,11 @@ hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr)
 }
 
 static int
-hppa_hpux_sr_for_addr (CORE_ADDR addr)
+hppa_hpux_sr_for_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   int sr;
   /* The space register to use is encoded in the top 2 bits of the address.  */
-  sr = addr >> (gdbarch_tdep (current_gdbarch)->bytes_per_address * 8 - 2);
+  sr = addr >> (gdbarch_tdep (gdbarch)->bytes_per_address * 8 - 2);
   return sr + 4;
 }
 
@@ -1087,10 +1097,11 @@ hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr)
 
 static CORE_ADDR
 hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
-                          CORE_ADDR funcaddr, int using_gcc,
+                          CORE_ADDR funcaddr,
                           struct value **args, int nargs,
                           struct type *value_type,
-                          CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
+                          CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
+                          struct regcache *regcache)
 {
   CORE_ADDR pc, stubaddr;
   int argreg = 0;
@@ -1103,12 +1114,13 @@ hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
 
   /* The simple case is where we call a function in the same space that we are
      currently in; in that case we don't really need to do anything.  */
-  if (hppa_hpux_sr_for_addr (pc) == hppa_hpux_sr_for_addr (funcaddr))
+  if (hppa_hpux_sr_for_addr (gdbarch, pc)
+      == hppa_hpux_sr_for_addr (gdbarch, funcaddr))
     {
       /* Intraspace call.  */
       *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
       *real_pc = funcaddr;
-      regcache_cooked_write_unsigned (current_regcache, HPPA_RP_REGNUM, *bp_addr);
+      regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, *bp_addr);
 
       return sp;
     }
@@ -1186,18 +1198,18 @@ hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
       if (stubaddr == 0)
         error (_("Cannot call external function not referenced by application "
               "(no import stub).\n"));
-      regcache_cooked_write_unsigned (current_regcache, 22, stubaddr);
+      regcache_cooked_write_unsigned (regcache, 22, stubaddr);
 
       write_memory (sp, (char *)&hppa32_tramp, sizeof (hppa32_tramp));
 
       *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
-      regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
+      regcache_cooked_write_unsigned (regcache, 31, *bp_addr);
 
       *real_pc = hppa32_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
       if (*real_pc == 0)
         error (_("Cannot make interspace call from here."));
 
-      regcache_cooked_write_unsigned (current_regcache, argreg, sp);
+      regcache_cooked_write_unsigned (regcache, argreg, sp);
 
       sp += sizeof (hppa32_tramp);
     }
@@ -1213,17 +1225,17 @@ hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
 
       /* for hppa64, we don't need to call through a stub; all functions
          return via a bve.  */
-      regcache_cooked_write_unsigned (current_regcache, 22, funcaddr);
+      regcache_cooked_write_unsigned (regcache, 22, funcaddr);
       write_memory (sp, (char *)&hppa64_tramp, sizeof (hppa64_tramp));
 
       *bp_addr = pc - 4;
-      regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
+      regcache_cooked_write_unsigned (regcache, 31, *bp_addr);
 
       *real_pc = hppa64_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
       if (*real_pc == 0)
         error (_("Cannot make interspace call from here."));
 
-      regcache_cooked_write_unsigned (current_regcache, argreg, sp);
+      regcache_cooked_write_unsigned (regcache, argreg, sp);
 
       sp += sizeof (hppa64_tramp);
     }
@@ -1364,29 +1376,33 @@ hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch,
 #define HPPA_HPUX_SS_INSYSCALL 0x02
 
 static CORE_ADDR
-hppa_hpux_read_pc (ptid_t ptid)
+hppa_hpux_read_pc (struct regcache *regcache)
 {
   ULONGEST flags;
 
   /* If we're currently in a system call return the contents of %r31.  */
-  flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
+  regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags);
   if (flags & HPPA_HPUX_SS_INSYSCALL)
-    return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3;
+    {
+      ULONGEST pc;
+      regcache_cooked_read_unsigned (regcache, HPPA_R31_REGNUM, &pc);
+      return pc & ~0x3;
+    }
 
-  return hppa_read_pc (ptid);
+  return hppa_read_pc (regcache);
 }
 
 static void
-hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid)
+hppa_hpux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   ULONGEST flags;
 
   /* If we're currently in a system call also write PC into %r31.  */
-  flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
+  regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags);
   if (flags & HPPA_HPUX_SS_INSYSCALL)
-    write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid);
+    regcache_cooked_write_unsigned (regcache, HPPA_R31_REGNUM, pc | 0x3);
 
-  return hppa_write_pc (pc, ptid);
+  return hppa_write_pc (regcache, pc);
 }
 
 static CORE_ADDR
@@ -1412,6 +1428,7 @@ static void
 hppa_hpux_unwind_adjust_stub (struct frame_info *next_frame, CORE_ADDR base,
                              struct trad_frame_saved_reg *saved_regs)
 {
+  struct gdbarch *gdbarch = get_frame_arch (next_frame);
   int optimized, realreg;
   enum lval_type lval;
   CORE_ADDR addr;
@@ -1430,13 +1447,15 @@ hppa_hpux_unwind_adjust_stub (struct frame_info *next_frame, CORE_ADDR base,
   u = find_unwind_entry (val);
   if (u && u->stub_unwind.stub_type == EXPORT)
     {
-      stubpc = read_memory_integer (base - 24, TARGET_PTR_BIT / 8);
+      stubpc = read_memory_integer
+                (base - 24, gdbarch_ptr_bit (gdbarch) / 8);
       trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
     }
   else if (hppa_symbol_address ("__gcc_plt_call") 
            == get_pc_function_start (val))
     {
-      stubpc = read_memory_integer (base - 8, TARGET_PTR_BIT / 8);
+      stubpc = read_memory_integer
+                (base - 8, gdbarch_ptr_bit (gdbarch) / 8);
       trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
     }
 }
@@ -1482,7 +1501,7 @@ hppa_hpux_som_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->find_global_pointer = hppa32_hpux_find_global_pointer;
 
   hppa_hpux_init_abi (info, gdbarch);
-  som_solib_select (tdep);
+  som_solib_select (gdbarch);
 }
 
 static void
@@ -1494,7 +1513,7 @@ hppa_hpux_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->find_global_pointer = hppa64_hpux_find_global_pointer;
 
   hppa_hpux_init_abi (info, gdbarch);
-  pa64_solib_select (tdep);
+  pa64_solib_select (gdbarch);
 }
 
 static enum gdb_osabi
This page took 0.028048 seconds and 4 git commands to generate.