GDB (API)
/home/stan/gdb/src/gdb/hppa-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the HP PA-RISC architecture.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by the Center for Software Science at the
00006    University of Utah (pa-gdb-bugs@cs.utah.edu).
00007 
00008    This file is part of GDB.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 3 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00022 
00023 #include "defs.h"
00024 #include "bfd.h"
00025 #include "inferior.h"
00026 #include "regcache.h"
00027 #include "completer.h"
00028 #include "osabi.h"
00029 #include "gdb_assert.h"
00030 #include "arch-utils.h"
00031 /* For argument passing to the inferior.  */
00032 #include "symtab.h"
00033 #include "dis-asm.h"
00034 #include "trad-frame.h"
00035 #include "frame-unwind.h"
00036 #include "frame-base.h"
00037 
00038 #include "gdbcore.h"
00039 #include "gdbcmd.h"
00040 #include "gdbtypes.h"
00041 #include "objfiles.h"
00042 #include "hppa-tdep.h"
00043 
00044 static int hppa_debug = 0;
00045 
00046 /* Some local constants.  */
00047 static const int hppa32_num_regs = 128;
00048 static const int hppa64_num_regs = 96;
00049 
00050 /* hppa-specific object data -- unwind and solib info.
00051    TODO/maybe: think about splitting this into two parts; the unwind data is 
00052    common to all hppa targets, but is only used in this file; we can register 
00053    that separately and make this static. The solib data is probably hpux-
00054    specific, so we can create a separate extern objfile_data that is registered
00055    by hppa-hpux-tdep.c and shared with pa64solib.c and somsolib.c.  */
00056 const struct objfile_data *hppa_objfile_priv_data = NULL;
00057 
00058 /* Get at various relevent fields of an instruction word.  */
00059 #define MASK_5 0x1f
00060 #define MASK_11 0x7ff
00061 #define MASK_14 0x3fff
00062 #define MASK_21 0x1fffff
00063 
00064 /* Sizes (in bytes) of the native unwind entries.  */
00065 #define UNWIND_ENTRY_SIZE 16
00066 #define STUB_UNWIND_ENTRY_SIZE 8
00067 
00068 /* Routines to extract various sized constants out of hppa 
00069    instructions.  */
00070 
00071 /* This assumes that no garbage lies outside of the lower bits of 
00072    value.  */
00073 
00074 static int
00075 hppa_sign_extend (unsigned val, unsigned bits)
00076 {
00077   return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
00078 }
00079 
00080 /* For many immediate values the sign bit is the low bit!  */
00081 
00082 static int
00083 hppa_low_hppa_sign_extend (unsigned val, unsigned bits)
00084 {
00085   return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
00086 }
00087 
00088 /* Extract the bits at positions between FROM and TO, using HP's numbering
00089    (MSB = 0).  */
00090 
00091 int
00092 hppa_get_field (unsigned word, int from, int to)
00093 {
00094   return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
00095 }
00096 
00097 /* Extract the immediate field from a ld{bhw}s instruction.  */
00098 
00099 int
00100 hppa_extract_5_load (unsigned word)
00101 {
00102   return hppa_low_hppa_sign_extend (word >> 16 & MASK_5, 5);
00103 }
00104 
00105 /* Extract the immediate field from a break instruction.  */
00106 
00107 unsigned
00108 hppa_extract_5r_store (unsigned word)
00109 {
00110   return (word & MASK_5);
00111 }
00112 
00113 /* Extract the immediate field from a {sr}sm instruction.  */
00114 
00115 unsigned
00116 hppa_extract_5R_store (unsigned word)
00117 {
00118   return (word >> 16 & MASK_5);
00119 }
00120 
00121 /* Extract a 14 bit immediate field.  */
00122 
00123 int
00124 hppa_extract_14 (unsigned word)
00125 {
00126   return hppa_low_hppa_sign_extend (word & MASK_14, 14);
00127 }
00128 
00129 /* Extract a 21 bit constant.  */
00130 
00131 int
00132 hppa_extract_21 (unsigned word)
00133 {
00134   int val;
00135 
00136   word &= MASK_21;
00137   word <<= 11;
00138   val = hppa_get_field (word, 20, 20);
00139   val <<= 11;
00140   val |= hppa_get_field (word, 9, 19);
00141   val <<= 2;
00142   val |= hppa_get_field (word, 5, 6);
00143   val <<= 5;
00144   val |= hppa_get_field (word, 0, 4);
00145   val <<= 2;
00146   val |= hppa_get_field (word, 7, 8);
00147   return hppa_sign_extend (val, 21) << 11;
00148 }
00149 
00150 /* extract a 17 bit constant from branch instructions, returning the
00151    19 bit signed value.  */
00152 
00153 int
00154 hppa_extract_17 (unsigned word)
00155 {
00156   return hppa_sign_extend (hppa_get_field (word, 19, 28) |
00157                       hppa_get_field (word, 29, 29) << 10 |
00158                       hppa_get_field (word, 11, 15) << 11 |
00159                       (word & 0x1) << 16, 17) << 2;
00160 }
00161 
00162 CORE_ADDR 
00163 hppa_symbol_address(const char *sym)
00164 {
00165   struct minimal_symbol *minsym;
00166 
00167   minsym = lookup_minimal_symbol (sym, NULL, NULL);
00168   if (minsym)
00169     return SYMBOL_VALUE_ADDRESS (minsym);
00170   else
00171     return (CORE_ADDR)-1;
00172 }
00173 
00174 struct hppa_objfile_private *
00175 hppa_init_objfile_priv_data (struct objfile *objfile)
00176 {
00177   struct hppa_objfile_private *priv;
00178 
00179   priv = (struct hppa_objfile_private *)
00180          obstack_alloc (&objfile->objfile_obstack,
00181                         sizeof (struct hppa_objfile_private));
00182   set_objfile_data (objfile, hppa_objfile_priv_data, priv);
00183   memset (priv, 0, sizeof (*priv));
00184 
00185   return priv;
00186 }
00187 
00188 
00189 /* Compare the start address for two unwind entries returning 1 if 
00190    the first address is larger than the second, -1 if the second is
00191    larger than the first, and zero if they are equal.  */
00192 
00193 static int
00194 compare_unwind_entries (const void *arg1, const void *arg2)
00195 {
00196   const struct unwind_table_entry *a = arg1;
00197   const struct unwind_table_entry *b = arg2;
00198 
00199   if (a->region_start > b->region_start)
00200     return 1;
00201   else if (a->region_start < b->region_start)
00202     return -1;
00203   else
00204     return 0;
00205 }
00206 
00207 static void
00208 record_text_segment_lowaddr (bfd *abfd, asection *section, void *data)
00209 {
00210   if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
00211        == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
00212     {
00213       bfd_vma value = section->vma - section->filepos;
00214       CORE_ADDR *low_text_segment_address = (CORE_ADDR *)data;
00215 
00216       if (value < *low_text_segment_address)
00217           *low_text_segment_address = value;
00218     }
00219 }
00220 
00221 static void
00222 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
00223                      asection *section, unsigned int entries,
00224                      unsigned int size, CORE_ADDR text_offset)
00225 {
00226   /* We will read the unwind entries into temporary memory, then
00227      fill in the actual unwind table.  */
00228 
00229   if (size > 0)
00230     {
00231       struct gdbarch *gdbarch = get_objfile_arch (objfile);
00232       unsigned long tmp;
00233       unsigned i;
00234       char *buf = alloca (size);
00235       CORE_ADDR low_text_segment_address;
00236 
00237       /* For ELF targets, then unwinds are supposed to
00238          be segment relative offsets instead of absolute addresses.
00239 
00240          Note that when loading a shared library (text_offset != 0) the
00241          unwinds are already relative to the text_offset that will be
00242          passed in.  */
00243       if (gdbarch_tdep (gdbarch)->is_elf && text_offset == 0)
00244         {
00245           low_text_segment_address = -1;
00246 
00247           bfd_map_over_sections (objfile->obfd,
00248                                  record_text_segment_lowaddr, 
00249                                  &low_text_segment_address);
00250 
00251           text_offset = low_text_segment_address;
00252         }
00253       else if (gdbarch_tdep (gdbarch)->solib_get_text_base)
00254         {
00255           text_offset = gdbarch_tdep (gdbarch)->solib_get_text_base (objfile);
00256         }
00257 
00258       bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
00259 
00260       /* Now internalize the information being careful to handle host/target
00261          endian issues.  */
00262       for (i = 0; i < entries; i++)
00263         {
00264           table[i].region_start = bfd_get_32 (objfile->obfd,
00265                                               (bfd_byte *) buf);
00266           table[i].region_start += text_offset;
00267           buf += 4;
00268           table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
00269           table[i].region_end += text_offset;
00270           buf += 4;
00271           tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
00272           buf += 4;
00273           table[i].Cannot_unwind = (tmp >> 31) & 0x1;
00274           table[i].Millicode = (tmp >> 30) & 0x1;
00275           table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
00276           table[i].Region_description = (tmp >> 27) & 0x3;
00277           table[i].reserved = (tmp >> 26) & 0x1;
00278           table[i].Entry_SR = (tmp >> 25) & 0x1;
00279           table[i].Entry_FR = (tmp >> 21) & 0xf;
00280           table[i].Entry_GR = (tmp >> 16) & 0x1f;
00281           table[i].Args_stored = (tmp >> 15) & 0x1;
00282           table[i].Variable_Frame = (tmp >> 14) & 0x1;
00283           table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
00284           table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
00285           table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
00286           table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
00287           table[i].sr4export = (tmp >> 9) & 0x1;
00288           table[i].cxx_info = (tmp >> 8) & 0x1;
00289           table[i].cxx_try_catch = (tmp >> 7) & 0x1;
00290           table[i].sched_entry_seq = (tmp >> 6) & 0x1;
00291           table[i].reserved1 = (tmp >> 5) & 0x1;
00292           table[i].Save_SP = (tmp >> 4) & 0x1;
00293           table[i].Save_RP = (tmp >> 3) & 0x1;
00294           table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
00295           table[i].save_r19 = (tmp >> 1) & 0x1;
00296           table[i].Cleanup_defined = tmp & 0x1;
00297           tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
00298           buf += 4;
00299           table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
00300           table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
00301           table[i].Large_frame = (tmp >> 29) & 0x1;
00302           table[i].alloca_frame = (tmp >> 28) & 0x1;
00303           table[i].reserved2 = (tmp >> 27) & 0x1;
00304           table[i].Total_frame_size = tmp & 0x7ffffff;
00305 
00306           /* Stub unwinds are handled elsewhere.  */
00307           table[i].stub_unwind.stub_type = 0;
00308           table[i].stub_unwind.padding = 0;
00309         }
00310     }
00311 }
00312 
00313 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
00314    the object file.  This info is used mainly by find_unwind_entry() to find
00315    out the stack frame size and frame pointer used by procedures.  We put
00316    everything on the psymbol obstack in the objfile so that it automatically
00317    gets freed when the objfile is destroyed.  */
00318 
00319 static void
00320 read_unwind_info (struct objfile *objfile)
00321 {
00322   asection *unwind_sec, *stub_unwind_sec;
00323   unsigned unwind_size, stub_unwind_size, total_size;
00324   unsigned index, unwind_entries;
00325   unsigned stub_entries, total_entries;
00326   CORE_ADDR text_offset;
00327   struct hppa_unwind_info *ui;
00328   struct hppa_objfile_private *obj_private;
00329 
00330   text_offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
00331   ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
00332                                            sizeof (struct hppa_unwind_info));
00333 
00334   ui->table = NULL;
00335   ui->cache = NULL;
00336   ui->last = -1;
00337 
00338   /* For reasons unknown the HP PA64 tools generate multiple unwinder
00339      sections in a single executable.  So we just iterate over every
00340      section in the BFD looking for unwinder sections intead of trying
00341      to do a lookup with bfd_get_section_by_name.
00342 
00343      First determine the total size of the unwind tables so that we
00344      can allocate memory in a nice big hunk.  */
00345   total_entries = 0;
00346   for (unwind_sec = objfile->obfd->sections;
00347        unwind_sec;
00348        unwind_sec = unwind_sec->next)
00349     {
00350       if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
00351           || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
00352         {
00353           unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
00354           unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
00355 
00356           total_entries += unwind_entries;
00357         }
00358     }
00359 
00360   /* Now compute the size of the stub unwinds.  Note the ELF tools do not
00361      use stub unwinds at the current time.  */
00362   stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
00363 
00364   if (stub_unwind_sec)
00365     {
00366       stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
00367       stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
00368     }
00369   else
00370     {
00371       stub_unwind_size = 0;
00372       stub_entries = 0;
00373     }
00374 
00375   /* Compute total number of unwind entries and their total size.  */
00376   total_entries += stub_entries;
00377   total_size = total_entries * sizeof (struct unwind_table_entry);
00378 
00379   /* Allocate memory for the unwind table.  */
00380   ui->table = (struct unwind_table_entry *)
00381     obstack_alloc (&objfile->objfile_obstack, total_size);
00382   ui->last = total_entries - 1;
00383 
00384   /* Now read in each unwind section and internalize the standard unwind
00385      entries.  */
00386   index = 0;
00387   for (unwind_sec = objfile->obfd->sections;
00388        unwind_sec;
00389        unwind_sec = unwind_sec->next)
00390     {
00391       if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
00392           || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
00393         {
00394           unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
00395           unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
00396 
00397           internalize_unwinds (objfile, &ui->table[index], unwind_sec,
00398                                unwind_entries, unwind_size, text_offset);
00399           index += unwind_entries;
00400         }
00401     }
00402 
00403   /* Now read in and internalize the stub unwind entries.  */
00404   if (stub_unwind_size > 0)
00405     {
00406       unsigned int i;
00407       char *buf = alloca (stub_unwind_size);
00408 
00409       /* Read in the stub unwind entries.  */
00410       bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
00411                                 0, stub_unwind_size);
00412 
00413       /* Now convert them into regular unwind entries.  */
00414       for (i = 0; i < stub_entries; i++, index++)
00415         {
00416           /* Clear out the next unwind entry.  */
00417           memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
00418 
00419           /* Convert offset & size into region_start and region_end.
00420              Stuff away the stub type into "reserved" fields.  */
00421           ui->table[index].region_start = bfd_get_32 (objfile->obfd,
00422                                                       (bfd_byte *) buf);
00423           ui->table[index].region_start += text_offset;
00424           buf += 4;
00425           ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
00426                                                           (bfd_byte *) buf);
00427           buf += 2;
00428           ui->table[index].region_end
00429             = ui->table[index].region_start + 4 *
00430             (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
00431           buf += 2;
00432         }
00433 
00434     }
00435 
00436   /* Unwind table needs to be kept sorted.  */
00437   qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
00438          compare_unwind_entries);
00439 
00440   /* Keep a pointer to the unwind information.  */
00441   obj_private = (struct hppa_objfile_private *) 
00442                 objfile_data (objfile, hppa_objfile_priv_data);
00443   if (obj_private == NULL)
00444     obj_private = hppa_init_objfile_priv_data (objfile);
00445 
00446   obj_private->unwind_info = ui;
00447 }
00448 
00449 /* Lookup the unwind (stack backtrace) info for the given PC.  We search all
00450    of the objfiles seeking the unwind table entry for this PC.  Each objfile
00451    contains a sorted list of struct unwind_table_entry.  Since we do a binary
00452    search of the unwind tables, we depend upon them to be sorted.  */
00453 
00454 struct unwind_table_entry *
00455 find_unwind_entry (CORE_ADDR pc)
00456 {
00457   int first, middle, last;
00458   struct objfile *objfile;
00459   struct hppa_objfile_private *priv;
00460 
00461   if (hppa_debug)
00462     fprintf_unfiltered (gdb_stdlog, "{ find_unwind_entry %s -> ",
00463                         hex_string (pc));
00464 
00465   /* A function at address 0?  Not in HP-UX!  */
00466   if (pc == (CORE_ADDR) 0)
00467     {
00468       if (hppa_debug)
00469         fprintf_unfiltered (gdb_stdlog, "NULL }\n");
00470       return NULL;
00471     }
00472 
00473   ALL_OBJFILES (objfile)
00474   {
00475     struct hppa_unwind_info *ui;
00476     ui = NULL;
00477     priv = objfile_data (objfile, hppa_objfile_priv_data);
00478     if (priv)
00479       ui = ((struct hppa_objfile_private *) priv)->unwind_info;
00480 
00481     if (!ui)
00482       {
00483         read_unwind_info (objfile);
00484         priv = objfile_data (objfile, hppa_objfile_priv_data);
00485         if (priv == NULL)
00486           error (_("Internal error reading unwind information."));
00487         ui = ((struct hppa_objfile_private *) priv)->unwind_info;
00488       }
00489 
00490     /* First, check the cache.  */
00491 
00492     if (ui->cache
00493         && pc >= ui->cache->region_start
00494         && pc <= ui->cache->region_end)
00495       {
00496         if (hppa_debug)
00497           fprintf_unfiltered (gdb_stdlog, "%s (cached) }\n",
00498             hex_string ((uintptr_t) ui->cache));
00499         return ui->cache;
00500       }
00501 
00502     /* Not in the cache, do a binary search.  */
00503 
00504     first = 0;
00505     last = ui->last;
00506 
00507     while (first <= last)
00508       {
00509         middle = (first + last) / 2;
00510         if (pc >= ui->table[middle].region_start
00511             && pc <= ui->table[middle].region_end)
00512           {
00513             ui->cache = &ui->table[middle];
00514             if (hppa_debug)
00515               fprintf_unfiltered (gdb_stdlog, "%s }\n",
00516                 hex_string ((uintptr_t) ui->cache));
00517             return &ui->table[middle];
00518           }
00519 
00520         if (pc < ui->table[middle].region_start)
00521           last = middle - 1;
00522         else
00523           first = middle + 1;
00524       }
00525   }                             /* ALL_OBJFILES() */
00526 
00527   if (hppa_debug)
00528     fprintf_unfiltered (gdb_stdlog, "NULL (not found) }\n");
00529 
00530   return NULL;
00531 }
00532 
00533 /* The epilogue is defined here as the area either on the `bv' instruction 
00534    itself or an instruction which destroys the function's stack frame.
00535    
00536    We do not assume that the epilogue is at the end of a function as we can
00537    also have return sequences in the middle of a function.  */
00538 static int
00539 hppa_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
00540 {
00541   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00542   unsigned long status;
00543   unsigned int inst;
00544   gdb_byte buf[4];
00545 
00546   status = target_read_memory (pc, buf, 4);
00547   if (status != 0)
00548     return 0;
00549 
00550   inst = extract_unsigned_integer (buf, 4, byte_order);
00551 
00552   /* The most common way to perform a stack adjustment ldo X(sp),sp 
00553      We are destroying a stack frame if the offset is negative.  */
00554   if ((inst & 0xffffc000) == 0x37de0000
00555       && hppa_extract_14 (inst) < 0)
00556     return 1;
00557 
00558   /* ldw,mb D(sp),X or ldd,mb D(sp),X */
00559   if (((inst & 0x0fc010e0) == 0x0fc010e0 
00560        || (inst & 0x0fc010e0) == 0x0fc010e0)
00561       && hppa_extract_14 (inst) < 0)
00562     return 1;
00563 
00564   /* bv %r0(%rp) or bv,n %r0(%rp) */
00565   if (inst == 0xe840c000 || inst == 0xe840c002)
00566     return 1;
00567 
00568   return 0;
00569 }
00570 
00571 static const unsigned char *
00572 hppa_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
00573 {
00574   static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
00575   (*len) = sizeof (breakpoint);
00576   return breakpoint;
00577 }
00578 
00579 /* Return the name of a register.  */
00580 
00581 static const char *
00582 hppa32_register_name (struct gdbarch *gdbarch, int i)
00583 {
00584   static char *names[] = {
00585     "flags",  "r1",      "rp",     "r3",
00586     "r4",     "r5",      "r6",     "r7",
00587     "r8",     "r9",      "r10",    "r11",
00588     "r12",    "r13",     "r14",    "r15",
00589     "r16",    "r17",     "r18",    "r19",
00590     "r20",    "r21",     "r22",    "r23",
00591     "r24",    "r25",     "r26",    "dp",
00592     "ret0",   "ret1",    "sp",     "r31",
00593     "sar",    "pcoqh",   "pcsqh",  "pcoqt",
00594     "pcsqt",  "eiem",    "iir",    "isr",
00595     "ior",    "ipsw",    "goto",   "sr4",
00596     "sr0",    "sr1",     "sr2",    "sr3",
00597     "sr5",    "sr6",     "sr7",    "cr0",
00598     "cr8",    "cr9",     "ccr",    "cr12",
00599     "cr13",   "cr24",    "cr25",   "cr26",
00600     "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
00601     "fpsr",    "fpe1",   "fpe2",   "fpe3",
00602     "fpe4",   "fpe5",    "fpe6",   "fpe7",
00603     "fr4",     "fr4R",   "fr5",    "fr5R",
00604     "fr6",    "fr6R",    "fr7",    "fr7R",
00605     "fr8",     "fr8R",   "fr9",    "fr9R",
00606     "fr10",   "fr10R",   "fr11",   "fr11R",
00607     "fr12",    "fr12R",  "fr13",   "fr13R",
00608     "fr14",   "fr14R",   "fr15",   "fr15R",
00609     "fr16",    "fr16R",  "fr17",   "fr17R",
00610     "fr18",   "fr18R",   "fr19",   "fr19R",
00611     "fr20",    "fr20R",  "fr21",   "fr21R",
00612     "fr22",   "fr22R",   "fr23",   "fr23R",
00613     "fr24",    "fr24R",  "fr25",   "fr25R",
00614     "fr26",   "fr26R",   "fr27",   "fr27R",
00615     "fr28",    "fr28R",  "fr29",   "fr29R",
00616     "fr30",   "fr30R",   "fr31",   "fr31R"
00617   };
00618   if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
00619     return NULL;
00620   else
00621     return names[i];
00622 }
00623 
00624 static const char *
00625 hppa64_register_name (struct gdbarch *gdbarch, int i)
00626 {
00627   static char *names[] = {
00628     "flags",  "r1",      "rp",     "r3",
00629     "r4",     "r5",      "r6",     "r7",
00630     "r8",     "r9",      "r10",    "r11",
00631     "r12",    "r13",     "r14",    "r15",
00632     "r16",    "r17",     "r18",    "r19",
00633     "r20",    "r21",     "r22",    "r23",
00634     "r24",    "r25",     "r26",    "dp",
00635     "ret0",   "ret1",    "sp",     "r31",
00636     "sar",    "pcoqh",   "pcsqh",  "pcoqt",
00637     "pcsqt",  "eiem",    "iir",    "isr",
00638     "ior",    "ipsw",    "goto",   "sr4",
00639     "sr0",    "sr1",     "sr2",    "sr3",
00640     "sr5",    "sr6",     "sr7",    "cr0",
00641     "cr8",    "cr9",     "ccr",    "cr12",
00642     "cr13",   "cr24",    "cr25",   "cr26",
00643     "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
00644     "fpsr",    "fpe1",   "fpe2",   "fpe3",
00645     "fr4",    "fr5",     "fr6",    "fr7",
00646     "fr8",     "fr9",    "fr10",   "fr11",
00647     "fr12",   "fr13",    "fr14",   "fr15",
00648     "fr16",    "fr17",   "fr18",   "fr19",
00649     "fr20",   "fr21",    "fr22",   "fr23",
00650     "fr24",    "fr25",   "fr26",   "fr27",
00651     "fr28",  "fr29",    "fr30",   "fr31"
00652   };
00653   if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
00654     return NULL;
00655   else
00656     return names[i];
00657 }
00658 
00659 /* Map dwarf DBX register numbers to GDB register numbers.  */
00660 static int
00661 hppa64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
00662 {
00663   /* The general registers and the sar are the same in both sets.  */
00664   if (reg <= 32)
00665     return reg;
00666 
00667   /* fr4-fr31 are mapped from 72 in steps of 2.  */
00668   if (reg >= 72 && reg < 72 + 28 * 2 && !(reg & 1))
00669     return HPPA64_FP4_REGNUM + (reg - 72) / 2;
00670 
00671   warning (_("Unmapped DWARF DBX Register #%d encountered."), reg);
00672   return -1;
00673 }
00674 
00675 /* This function pushes a stack frame with arguments as part of the
00676    inferior function calling mechanism.
00677 
00678    This is the version of the function for the 32-bit PA machines, in
00679    which later arguments appear at lower addresses.  (The stack always
00680    grows towards higher addresses.)
00681 
00682    We simply allocate the appropriate amount of stack space and put
00683    arguments into their proper slots.  */
00684    
00685 static CORE_ADDR
00686 hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00687                         struct regcache *regcache, CORE_ADDR bp_addr,
00688                         int nargs, struct value **args, CORE_ADDR sp,
00689                         int struct_return, CORE_ADDR struct_addr)
00690 {
00691   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00692 
00693   /* Stack base address at which any pass-by-reference parameters are
00694      stored.  */
00695   CORE_ADDR struct_end = 0;
00696   /* Stack base address at which the first parameter is stored.  */
00697   CORE_ADDR param_end = 0;
00698 
00699   /* The inner most end of the stack after all the parameters have
00700      been pushed.  */
00701   CORE_ADDR new_sp = 0;
00702 
00703   /* Two passes.  First pass computes the location of everything,
00704      second pass writes the bytes out.  */
00705   int write_pass;
00706 
00707   /* Global pointer (r19) of the function we are trying to call.  */
00708   CORE_ADDR gp;
00709 
00710   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00711 
00712   for (write_pass = 0; write_pass < 2; write_pass++)
00713     {
00714       CORE_ADDR struct_ptr = 0;
00715       /* The first parameter goes into sp-36, each stack slot is 4-bytes.
00716          struct_ptr is adjusted for each argument below, so the first
00717          argument will end up at sp-36.  */
00718       CORE_ADDR param_ptr = 32;
00719       int i;
00720       int small_struct = 0;
00721 
00722       for (i = 0; i < nargs; i++)
00723         {
00724           struct value *arg = args[i];
00725           struct type *type = check_typedef (value_type (arg));
00726           /* The corresponding parameter that is pushed onto the
00727              stack, and [possibly] passed in a register.  */
00728           gdb_byte param_val[8];
00729           int param_len;
00730           memset (param_val, 0, sizeof param_val);
00731           if (TYPE_LENGTH (type) > 8)
00732             {
00733               /* Large parameter, pass by reference.  Store the value
00734                  in "struct" area and then pass its address.  */
00735               param_len = 4;
00736               struct_ptr += align_up (TYPE_LENGTH (type), 8);
00737               if (write_pass)
00738                 write_memory (struct_end - struct_ptr, value_contents (arg),
00739                               TYPE_LENGTH (type));
00740               store_unsigned_integer (param_val, 4, byte_order,
00741                                       struct_end - struct_ptr);
00742             }
00743           else if (TYPE_CODE (type) == TYPE_CODE_INT
00744                    || TYPE_CODE (type) == TYPE_CODE_ENUM)
00745             {
00746               /* Integer value store, right aligned.  "unpack_long"
00747                  takes care of any sign-extension problems.  */
00748               param_len = align_up (TYPE_LENGTH (type), 4);
00749               store_unsigned_integer (param_val, param_len, byte_order,
00750                                       unpack_long (type,
00751                                                    value_contents (arg)));
00752             }
00753           else if (TYPE_CODE (type) == TYPE_CODE_FLT)
00754             {
00755               /* Floating point value store, right aligned.  */
00756               param_len = align_up (TYPE_LENGTH (type), 4);
00757               memcpy (param_val, value_contents (arg), param_len);
00758             }
00759           else
00760             {
00761               param_len = align_up (TYPE_LENGTH (type), 4);
00762 
00763               /* Small struct value are stored right-aligned.  */
00764               memcpy (param_val + param_len - TYPE_LENGTH (type),
00765                       value_contents (arg), TYPE_LENGTH (type));
00766 
00767               /* Structures of size 5, 6 and 7 bytes are special in that
00768                  the higher-ordered word is stored in the lower-ordered
00769                  argument, and even though it is a 8-byte quantity the
00770                  registers need not be 8-byte aligned.  */
00771               if (param_len > 4 && param_len < 8)
00772                 small_struct = 1;
00773             }
00774 
00775           param_ptr += param_len;
00776           if (param_len == 8 && !small_struct)
00777             param_ptr = align_up (param_ptr, 8);
00778 
00779           /* First 4 non-FP arguments are passed in gr26-gr23.
00780              First 4 32-bit FP arguments are passed in fr4L-fr7L.
00781              First 2 64-bit FP arguments are passed in fr5 and fr7.
00782 
00783              The rest go on the stack, starting at sp-36, towards lower
00784              addresses.  8-byte arguments must be aligned to a 8-byte
00785              stack boundary.  */
00786           if (write_pass)
00787             {
00788               write_memory (param_end - param_ptr, param_val, param_len);
00789 
00790               /* There are some cases when we don't know the type
00791                  expected by the callee (e.g. for variadic functions), so 
00792                  pass the parameters in both general and fp regs.  */
00793               if (param_ptr <= 48)
00794                 {
00795                   int grreg = 26 - (param_ptr - 36) / 4;
00796                   int fpLreg = 72 + (param_ptr - 36) / 4 * 2;
00797                   int fpreg = 74 + (param_ptr - 32) / 8 * 4;
00798 
00799                   regcache_cooked_write (regcache, grreg, param_val);
00800                   regcache_cooked_write (regcache, fpLreg, param_val);
00801 
00802                   if (param_len > 4)
00803                     {
00804                       regcache_cooked_write (regcache, grreg + 1, 
00805                                              param_val + 4);
00806 
00807                       regcache_cooked_write (regcache, fpreg, param_val);
00808                       regcache_cooked_write (regcache, fpreg + 1, 
00809                                              param_val + 4);
00810                     }
00811                 }
00812             }
00813         }
00814 
00815       /* Update the various stack pointers.  */
00816       if (!write_pass)
00817         {
00818           struct_end = sp + align_up (struct_ptr, 64);
00819           /* PARAM_PTR already accounts for all the arguments passed
00820              by the user.  However, the ABI mandates minimum stack
00821              space allocations for outgoing arguments.  The ABI also
00822              mandates minimum stack alignments which we must
00823              preserve.  */
00824           param_end = struct_end + align_up (param_ptr, 64);
00825         }
00826     }
00827 
00828   /* If a structure has to be returned, set up register 28 to hold its
00829      address.  */
00830   if (struct_return)
00831     regcache_cooked_write_unsigned (regcache, 28, struct_addr);
00832 
00833   gp = tdep->find_global_pointer (gdbarch, function);
00834 
00835   if (gp != 0)
00836     regcache_cooked_write_unsigned (regcache, 19, gp);
00837 
00838   /* Set the return address.  */
00839   if (!gdbarch_push_dummy_code_p (gdbarch))
00840     regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
00841 
00842   /* Update the Stack Pointer.  */
00843   regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end);
00844 
00845   return param_end;
00846 }
00847 
00848 /* The 64-bit PA-RISC calling conventions are documented in "64-Bit
00849    Runtime Architecture for PA-RISC 2.0", which is distributed as part
00850    as of the HP-UX Software Transition Kit (STK).  This implementation
00851    is based on version 3.3, dated October 6, 1997.  */
00852 
00853 /* Check whether TYPE is an "Integral or Pointer Scalar Type".  */
00854 
00855 static int
00856 hppa64_integral_or_pointer_p (const struct type *type)
00857 {
00858   switch (TYPE_CODE (type))
00859     {
00860     case TYPE_CODE_INT:
00861     case TYPE_CODE_BOOL:
00862     case TYPE_CODE_CHAR:
00863     case TYPE_CODE_ENUM:
00864     case TYPE_CODE_RANGE:
00865       {
00866         int len = TYPE_LENGTH (type);
00867         return (len == 1 || len == 2 || len == 4 || len == 8);
00868       }
00869     case TYPE_CODE_PTR:
00870     case TYPE_CODE_REF:
00871       return (TYPE_LENGTH (type) == 8);
00872     default:
00873       break;
00874     }
00875 
00876   return 0;
00877 }
00878 
00879 /* Check whether TYPE is a "Floating Scalar Type".  */
00880 
00881 static int
00882 hppa64_floating_p (const struct type *type)
00883 {
00884   switch (TYPE_CODE (type))
00885     {
00886     case TYPE_CODE_FLT:
00887       {
00888         int len = TYPE_LENGTH (type);
00889         return (len == 4 || len == 8 || len == 16);
00890       }
00891     default:
00892       break;
00893     }
00894 
00895   return 0;
00896 }
00897 
00898 /* If CODE points to a function entry address, try to look up the corresponding
00899    function descriptor and return its address instead.  If CODE is not a
00900    function entry address, then just return it unchanged.  */
00901 static CORE_ADDR
00902 hppa64_convert_code_addr_to_fptr (struct gdbarch *gdbarch, CORE_ADDR code)
00903 {
00904   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00905   struct obj_section *sec, *opd;
00906 
00907   sec = find_pc_section (code);
00908 
00909   if (!sec)
00910     return code;
00911 
00912   /* If CODE is in a data section, assume it's already a fptr.  */
00913   if (!(sec->the_bfd_section->flags & SEC_CODE))
00914     return code;
00915 
00916   ALL_OBJFILE_OSECTIONS (sec->objfile, opd)
00917     {
00918       if (strcmp (opd->the_bfd_section->name, ".opd") == 0)
00919         break;
00920     }
00921 
00922   if (opd < sec->objfile->sections_end)
00923     {
00924       CORE_ADDR addr;
00925 
00926       for (addr = obj_section_addr (opd);
00927            addr < obj_section_endaddr (opd);
00928            addr += 2 * 8)
00929         {
00930           ULONGEST opdaddr;
00931           gdb_byte tmp[8];
00932 
00933           if (target_read_memory (addr, tmp, sizeof (tmp)))
00934               break;
00935           opdaddr = extract_unsigned_integer (tmp, sizeof (tmp), byte_order);
00936 
00937           if (opdaddr == code)
00938             return addr - 16;
00939         }
00940     }
00941 
00942   return code;
00943 }
00944 
00945 static CORE_ADDR
00946 hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00947                         struct regcache *regcache, CORE_ADDR bp_addr,
00948                         int nargs, struct value **args, CORE_ADDR sp,
00949                         int struct_return, CORE_ADDR struct_addr)
00950 {
00951   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00952   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00953   int i, offset = 0;
00954   CORE_ADDR gp;
00955 
00956   /* "The outgoing parameter area [...] must be aligned at a 16-byte
00957      boundary."  */
00958   sp = align_up (sp, 16);
00959 
00960   for (i = 0; i < nargs; i++)
00961     {
00962       struct value *arg = args[i];
00963       struct type *type = value_type (arg);
00964       int len = TYPE_LENGTH (type);
00965       const bfd_byte *valbuf;
00966       bfd_byte fptrbuf[8];
00967       int regnum;
00968 
00969       /* "Each parameter begins on a 64-bit (8-byte) boundary."  */
00970       offset = align_up (offset, 8);
00971 
00972       if (hppa64_integral_or_pointer_p (type))
00973         {
00974           /* "Integral scalar parameters smaller than 64 bits are
00975              padded on the left (i.e., the value is in the
00976              least-significant bits of the 64-bit storage unit, and
00977              the high-order bits are undefined)."  Therefore we can
00978              safely sign-extend them.  */
00979           if (len < 8)
00980             {
00981               arg = value_cast (builtin_type (gdbarch)->builtin_int64, arg);
00982               len = 8;
00983             }
00984         }
00985       else if (hppa64_floating_p (type))
00986         {
00987           if (len > 8)
00988             {
00989               /* "Quad-precision (128-bit) floating-point scalar
00990                  parameters are aligned on a 16-byte boundary."  */
00991               offset = align_up (offset, 16);
00992 
00993               /* "Double-extended- and quad-precision floating-point
00994                  parameters within the first 64 bytes of the parameter
00995                  list are always passed in general registers."  */
00996             }
00997           else
00998             {
00999               if (len == 4)
01000                 {
01001                   /* "Single-precision (32-bit) floating-point scalar
01002                      parameters are padded on the left with 32 bits of
01003                      garbage (i.e., the floating-point value is in the
01004                      least-significant 32 bits of a 64-bit storage
01005                      unit)."  */
01006                   offset += 4;
01007                 }
01008 
01009               /* "Single- and double-precision floating-point
01010                  parameters in this area are passed according to the
01011                  available formal parameter information in a function
01012                  prototype.  [...]  If no prototype is in scope,
01013                  floating-point parameters must be passed both in the
01014                  corresponding general registers and in the
01015                  corresponding floating-point registers."  */
01016               regnum = HPPA64_FP4_REGNUM + offset / 8;
01017 
01018               if (regnum < HPPA64_FP4_REGNUM + 8)
01019                 {
01020                   /* "Single-precision floating-point parameters, when
01021                      passed in floating-point registers, are passed in
01022                      the right halves of the floating point registers;
01023                      the left halves are unused."  */
01024                   regcache_cooked_write_part (regcache, regnum, offset % 8,
01025                                               len, value_contents (arg));
01026                 }
01027             }
01028         }
01029       else
01030         {
01031           if (len > 8)
01032             {
01033               /* "Aggregates larger than 8 bytes are aligned on a
01034                  16-byte boundary, possibly leaving an unused argument
01035                  slot, which is filled with garbage.  If necessary,
01036                  they are padded on the right (with garbage), to a
01037                  multiple of 8 bytes."  */
01038               offset = align_up (offset, 16);
01039             }
01040         }
01041 
01042       /* If we are passing a function pointer, make sure we pass a function
01043          descriptor instead of the function entry address.  */
01044       if (TYPE_CODE (type) == TYPE_CODE_PTR
01045           && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)
01046         {
01047           ULONGEST codeptr, fptr;
01048 
01049           codeptr = unpack_long (type, value_contents (arg));
01050           fptr = hppa64_convert_code_addr_to_fptr (gdbarch, codeptr);
01051           store_unsigned_integer (fptrbuf, TYPE_LENGTH (type), byte_order,
01052                                   fptr);
01053           valbuf = fptrbuf;
01054         }
01055       else
01056         {
01057           valbuf = value_contents (arg);
01058         }
01059 
01060       /* Always store the argument in memory.  */
01061       write_memory (sp + offset, valbuf, len);
01062 
01063       regnum = HPPA_ARG0_REGNUM - offset / 8;
01064       while (regnum > HPPA_ARG0_REGNUM - 8 && len > 0)
01065         {
01066           regcache_cooked_write_part (regcache, regnum,
01067                                       offset % 8, min (len, 8), valbuf);
01068           offset += min (len, 8);
01069           valbuf += min (len, 8);
01070           len -= min (len, 8);
01071           regnum--;
01072         }
01073 
01074       offset += len;
01075     }
01076 
01077   /* Set up GR29 (%ret1) to hold the argument pointer (ap).  */
01078   regcache_cooked_write_unsigned (regcache, HPPA_RET1_REGNUM, sp + 64);
01079 
01080   /* Allocate the outgoing parameter area.  Make sure the outgoing
01081      parameter area is multiple of 16 bytes in length.  */
01082   sp += max (align_up (offset, 16), 64);
01083 
01084   /* Allocate 32-bytes of scratch space.  The documentation doesn't
01085      mention this, but it seems to be needed.  */
01086   sp += 32;
01087 
01088   /* Allocate the frame marker area.  */
01089   sp += 16;
01090 
01091   /* If a structure has to be returned, set up GR 28 (%ret0) to hold
01092      its address.  */
01093   if (struct_return)
01094     regcache_cooked_write_unsigned (regcache, HPPA_RET0_REGNUM, struct_addr);
01095 
01096   /* Set up GR27 (%dp) to hold the global pointer (gp).  */
01097   gp = tdep->find_global_pointer (gdbarch, function);
01098   if (gp != 0)
01099     regcache_cooked_write_unsigned (regcache, HPPA_DP_REGNUM, gp);
01100 
01101   /* Set up GR2 (%rp) to hold the return pointer (rp).  */
01102   if (!gdbarch_push_dummy_code_p (gdbarch))
01103     regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
01104 
01105   /* Set up GR30 to hold the stack pointer (sp).  */
01106   regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, sp);
01107 
01108   return sp;
01109 }
01110 
01111 
01112 /* Handle 32/64-bit struct return conventions.  */
01113 
01114 static enum return_value_convention
01115 hppa32_return_value (struct gdbarch *gdbarch, struct value *function,
01116                      struct type *type, struct regcache *regcache,
01117                      gdb_byte *readbuf, const gdb_byte *writebuf)
01118 {
01119   if (TYPE_LENGTH (type) <= 2 * 4)
01120     {
01121       /* The value always lives in the right hand end of the register
01122          (or register pair)?  */
01123       int b;
01124       int reg = TYPE_CODE (type) == TYPE_CODE_FLT ? HPPA_FP4_REGNUM : 28;
01125       int part = TYPE_LENGTH (type) % 4;
01126       /* The left hand register contains only part of the value,
01127          transfer that first so that the rest can be xfered as entire
01128          4-byte registers.  */
01129       if (part > 0)
01130         {
01131           if (readbuf != NULL)
01132             regcache_cooked_read_part (regcache, reg, 4 - part,
01133                                        part, readbuf);
01134           if (writebuf != NULL)
01135             regcache_cooked_write_part (regcache, reg, 4 - part,
01136                                         part, writebuf);
01137           reg++;
01138         }
01139       /* Now transfer the remaining register values.  */
01140       for (b = part; b < TYPE_LENGTH (type); b += 4)
01141         {
01142           if (readbuf != NULL)
01143             regcache_cooked_read (regcache, reg, readbuf + b);
01144           if (writebuf != NULL)
01145             regcache_cooked_write (regcache, reg, writebuf + b);
01146           reg++;
01147         }
01148       return RETURN_VALUE_REGISTER_CONVENTION;
01149     }
01150   else
01151     return RETURN_VALUE_STRUCT_CONVENTION;
01152 }
01153 
01154 static enum return_value_convention
01155 hppa64_return_value (struct gdbarch *gdbarch, struct value *function,
01156                      struct type *type, struct regcache *regcache,
01157                      gdb_byte *readbuf, const gdb_byte *writebuf)
01158 {
01159   int len = TYPE_LENGTH (type);
01160   int regnum, offset;
01161 
01162   if (len > 16)
01163     {
01164       /* All return values larget than 128 bits must be aggregate
01165          return values.  */
01166       gdb_assert (!hppa64_integral_or_pointer_p (type));
01167       gdb_assert (!hppa64_floating_p (type));
01168 
01169       /* "Aggregate return values larger than 128 bits are returned in
01170          a buffer allocated by the caller.  The address of the buffer
01171          must be passed in GR 28."  */
01172       return RETURN_VALUE_STRUCT_CONVENTION;
01173     }
01174 
01175   if (hppa64_integral_or_pointer_p (type))
01176     {
01177       /* "Integral return values are returned in GR 28.  Values
01178          smaller than 64 bits are padded on the left (with garbage)."  */
01179       regnum = HPPA_RET0_REGNUM;
01180       offset = 8 - len;
01181     }
01182   else if (hppa64_floating_p (type))
01183     {
01184       if (len > 8)
01185         {
01186           /* "Double-extended- and quad-precision floating-point
01187              values are returned in GRs 28 and 29.  The sign,
01188              exponent, and most-significant bits of the mantissa are
01189              returned in GR 28; the least-significant bits of the
01190              mantissa are passed in GR 29.  For double-extended
01191              precision values, GR 29 is padded on the right with 48
01192              bits of garbage."  */
01193           regnum = HPPA_RET0_REGNUM;
01194           offset = 0;
01195         }
01196       else
01197         {
01198           /* "Single-precision and double-precision floating-point
01199              return values are returned in FR 4R (single precision) or
01200              FR 4 (double-precision)."  */
01201           regnum = HPPA64_FP4_REGNUM;
01202           offset = 8 - len;
01203         }
01204     }
01205   else
01206     {
01207       /* "Aggregate return values up to 64 bits in size are returned
01208          in GR 28.  Aggregates smaller than 64 bits are left aligned
01209          in the register; the pad bits on the right are undefined."
01210 
01211          "Aggregate return values between 65 and 128 bits are returned
01212          in GRs 28 and 29.  The first 64 bits are placed in GR 28, and
01213          the remaining bits are placed, left aligned, in GR 29.  The
01214          pad bits on the right of GR 29 (if any) are undefined."  */
01215       regnum = HPPA_RET0_REGNUM;
01216       offset = 0;
01217     }
01218 
01219   if (readbuf)
01220     {
01221       while (len > 0)
01222         {
01223           regcache_cooked_read_part (regcache, regnum, offset,
01224                                      min (len, 8), readbuf);
01225           readbuf += min (len, 8);
01226           len -= min (len, 8);
01227           regnum++;
01228         }
01229     }
01230 
01231   if (writebuf)
01232     {
01233       while (len > 0)
01234         {
01235           regcache_cooked_write_part (regcache, regnum, offset,
01236                                       min (len, 8), writebuf);
01237           writebuf += min (len, 8);
01238           len -= min (len, 8);
01239           regnum++;
01240         }
01241     }
01242 
01243   return RETURN_VALUE_REGISTER_CONVENTION;
01244 }
01245 
01246 
01247 static CORE_ADDR
01248 hppa32_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr,
01249                                    struct target_ops *targ)
01250 {
01251   if (addr & 2)
01252     {
01253       struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
01254       CORE_ADDR plabel = addr & ~3;
01255       return read_memory_typed_address (plabel, func_ptr_type);
01256     }
01257 
01258   return addr;
01259 }
01260 
01261 static CORE_ADDR
01262 hppa32_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
01263 {
01264   /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_
01265      and not _bit_)!  */
01266   return align_up (addr, 64);
01267 }
01268 
01269 /* Force all frames to 16-byte alignment.  Better safe than sorry.  */
01270 
01271 static CORE_ADDR
01272 hppa64_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
01273 {
01274   /* Just always 16-byte align.  */
01275   return align_up (addr, 16);
01276 }
01277 
01278 CORE_ADDR
01279 hppa_read_pc (struct regcache *regcache)
01280 {
01281   ULONGEST ipsw;
01282   ULONGEST pc;
01283 
01284   regcache_cooked_read_unsigned (regcache, HPPA_IPSW_REGNUM, &ipsw);
01285   regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, &pc);
01286 
01287   /* If the current instruction is nullified, then we are effectively
01288      still executing the previous instruction.  Pretend we are still
01289      there.  This is needed when single stepping; if the nullified
01290      instruction is on a different line, we don't want GDB to think
01291      we've stepped onto that line.  */
01292   if (ipsw & 0x00200000)
01293     pc -= 4;
01294 
01295   return pc & ~0x3;
01296 }
01297 
01298 void
01299 hppa_write_pc (struct regcache *regcache, CORE_ADDR pc)
01300 {
01301   regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pc);
01302   regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pc + 4);
01303 }
01304 
01305 /* For the given instruction (INST), return any adjustment it makes
01306    to the stack pointer or zero for no adjustment.
01307 
01308    This only handles instructions commonly found in prologues.  */
01309 
01310 static int
01311 prologue_inst_adjust_sp (unsigned long inst)
01312 {
01313   /* This must persist across calls.  */
01314   static int save_high21;
01315 
01316   /* The most common way to perform a stack adjustment ldo X(sp),sp */
01317   if ((inst & 0xffffc000) == 0x37de0000)
01318     return hppa_extract_14 (inst);
01319 
01320   /* stwm X,D(sp) */
01321   if ((inst & 0xffe00000) == 0x6fc00000)
01322     return hppa_extract_14 (inst);
01323 
01324   /* std,ma X,D(sp) */
01325   if ((inst & 0xffe00008) == 0x73c00008)
01326     return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
01327 
01328   /* addil high21,%r30; ldo low11,(%r1),%r30)
01329      save high bits in save_high21 for later use.  */
01330   if ((inst & 0xffe00000) == 0x2bc00000)
01331     {
01332       save_high21 = hppa_extract_21 (inst);
01333       return 0;
01334     }
01335 
01336   if ((inst & 0xffff0000) == 0x343e0000)
01337     return save_high21 + hppa_extract_14 (inst);
01338 
01339   /* fstws as used by the HP compilers.  */
01340   if ((inst & 0xffffffe0) == 0x2fd01220)
01341     return hppa_extract_5_load (inst);
01342 
01343   /* No adjustment.  */
01344   return 0;
01345 }
01346 
01347 /* Return nonzero if INST is a branch of some kind, else return zero.  */
01348 
01349 static int
01350 is_branch (unsigned long inst)
01351 {
01352   switch (inst >> 26)
01353     {
01354     case 0x20:
01355     case 0x21:
01356     case 0x22:
01357     case 0x23:
01358     case 0x27:
01359     case 0x28:
01360     case 0x29:
01361     case 0x2a:
01362     case 0x2b:
01363     case 0x2f:
01364     case 0x30:
01365     case 0x31:
01366     case 0x32:
01367     case 0x33:
01368     case 0x38:
01369     case 0x39:
01370     case 0x3a:
01371     case 0x3b:
01372       return 1;
01373 
01374     default:
01375       return 0;
01376     }
01377 }
01378 
01379 /* Return the register number for a GR which is saved by INST or
01380    zero it INST does not save a GR.  */
01381 
01382 static int
01383 inst_saves_gr (unsigned long inst)
01384 {
01385   /* Does it look like a stw?  */
01386   if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
01387       || (inst >> 26) == 0x1f
01388       || ((inst >> 26) == 0x1f
01389           && ((inst >> 6) == 0xa)))
01390     return hppa_extract_5R_store (inst);
01391 
01392   /* Does it look like a std?  */
01393   if ((inst >> 26) == 0x1c
01394       || ((inst >> 26) == 0x03
01395           && ((inst >> 6) & 0xf) == 0xb))
01396     return hppa_extract_5R_store (inst);
01397 
01398   /* Does it look like a stwm?  GCC & HPC may use this in prologues.  */
01399   if ((inst >> 26) == 0x1b)
01400     return hppa_extract_5R_store (inst);
01401 
01402   /* Does it look like sth or stb?  HPC versions 9.0 and later use these
01403      too.  */
01404   if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
01405       || ((inst >> 26) == 0x3
01406           && (((inst >> 6) & 0xf) == 0x8
01407               || (inst >> 6) & 0xf) == 0x9))
01408     return hppa_extract_5R_store (inst);
01409 
01410   return 0;
01411 }
01412 
01413 /* Return the register number for a FR which is saved by INST or
01414    zero it INST does not save a FR.
01415 
01416    Note we only care about full 64bit register stores (that's the only
01417    kind of stores the prologue will use).
01418 
01419    FIXME: What about argument stores with the HP compiler in ANSI mode? */
01420 
01421 static int
01422 inst_saves_fr (unsigned long inst)
01423 {
01424   /* Is this an FSTD?  */
01425   if ((inst & 0xfc00dfc0) == 0x2c001200)
01426     return hppa_extract_5r_store (inst);
01427   if ((inst & 0xfc000002) == 0x70000002)
01428     return hppa_extract_5R_store (inst);
01429   /* Is this an FSTW?  */
01430   if ((inst & 0xfc00df80) == 0x24001200)
01431     return hppa_extract_5r_store (inst);
01432   if ((inst & 0xfc000002) == 0x7c000000)
01433     return hppa_extract_5R_store (inst);
01434   return 0;
01435 }
01436 
01437 /* Advance PC across any function entry prologue instructions
01438    to reach some "real" code.
01439 
01440    Use information in the unwind table to determine what exactly should
01441    be in the prologue.  */
01442 
01443 
01444 static CORE_ADDR
01445 skip_prologue_hard_way (struct gdbarch *gdbarch, CORE_ADDR pc,
01446                         int stop_before_branch)
01447 {
01448   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01449   gdb_byte buf[4];
01450   CORE_ADDR orig_pc = pc;
01451   unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
01452   unsigned long args_stored, status, i, restart_gr, restart_fr;
01453   struct unwind_table_entry *u;
01454   int final_iteration;
01455 
01456   restart_gr = 0;
01457   restart_fr = 0;
01458 
01459 restart:
01460   u = find_unwind_entry (pc);
01461   if (!u)
01462     return pc;
01463 
01464   /* If we are not at the beginning of a function, then return now.  */
01465   if ((pc & ~0x3) != u->region_start)
01466     return pc;
01467 
01468   /* This is how much of a frame adjustment we need to account for.  */
01469   stack_remaining = u->Total_frame_size << 3;
01470 
01471   /* Magic register saves we want to know about.  */
01472   save_rp = u->Save_RP;
01473   save_sp = u->Save_SP;
01474 
01475   /* An indication that args may be stored into the stack.  Unfortunately
01476      the HPUX compilers tend to set this in cases where no args were
01477      stored too!.  */
01478   args_stored = 1;
01479 
01480   /* Turn the Entry_GR field into a bitmask.  */
01481   save_gr = 0;
01482   for (i = 3; i < u->Entry_GR + 3; i++)
01483     {
01484       /* Frame pointer gets saved into a special location.  */
01485       if (u->Save_SP && i == HPPA_FP_REGNUM)
01486         continue;
01487 
01488       save_gr |= (1 << i);
01489     }
01490   save_gr &= ~restart_gr;
01491 
01492   /* Turn the Entry_FR field into a bitmask too.  */
01493   save_fr = 0;
01494   for (i = 12; i < u->Entry_FR + 12; i++)
01495     save_fr |= (1 << i);
01496   save_fr &= ~restart_fr;
01497 
01498   final_iteration = 0;
01499 
01500   /* Loop until we find everything of interest or hit a branch.
01501 
01502      For unoptimized GCC code and for any HP CC code this will never ever
01503      examine any user instructions.
01504 
01505      For optimzied GCC code we're faced with problems.  GCC will schedule
01506      its prologue and make prologue instructions available for delay slot
01507      filling.  The end result is user code gets mixed in with the prologue
01508      and a prologue instruction may be in the delay slot of the first branch
01509      or call.
01510 
01511      Some unexpected things are expected with debugging optimized code, so
01512      we allow this routine to walk past user instructions in optimized
01513      GCC code.  */
01514   while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
01515          || args_stored)
01516     {
01517       unsigned int reg_num;
01518       unsigned long old_stack_remaining, old_save_gr, old_save_fr;
01519       unsigned long old_save_rp, old_save_sp, next_inst;
01520 
01521       /* Save copies of all the triggers so we can compare them later
01522          (only for HPC).  */
01523       old_save_gr = save_gr;
01524       old_save_fr = save_fr;
01525       old_save_rp = save_rp;
01526       old_save_sp = save_sp;
01527       old_stack_remaining = stack_remaining;
01528 
01529       status = target_read_memory (pc, buf, 4);
01530       inst = extract_unsigned_integer (buf, 4, byte_order);
01531 
01532       /* Yow! */
01533       if (status != 0)
01534         return pc;
01535 
01536       /* Note the interesting effects of this instruction.  */
01537       stack_remaining -= prologue_inst_adjust_sp (inst);
01538 
01539       /* There are limited ways to store the return pointer into the
01540          stack.  */
01541       if (inst == 0x6bc23fd9 || inst == 0x0fc212c1 || inst == 0x73c23fe1)
01542         save_rp = 0;
01543 
01544       /* These are the only ways we save SP into the stack.  At this time
01545          the HP compilers never bother to save SP into the stack.  */
01546       if ((inst & 0xffffc000) == 0x6fc10000
01547           || (inst & 0xffffc00c) == 0x73c10008)
01548         save_sp = 0;
01549 
01550       /* Are we loading some register with an offset from the argument
01551          pointer?  */
01552       if ((inst & 0xffe00000) == 0x37a00000
01553           || (inst & 0xffffffe0) == 0x081d0240)
01554         {
01555           pc += 4;
01556           continue;
01557         }
01558 
01559       /* Account for general and floating-point register saves.  */
01560       reg_num = inst_saves_gr (inst);
01561       save_gr &= ~(1 << reg_num);
01562 
01563       /* Ugh.  Also account for argument stores into the stack.
01564          Unfortunately args_stored only tells us that some arguments
01565          where stored into the stack.  Not how many or what kind!
01566 
01567          This is a kludge as on the HP compiler sets this bit and it
01568          never does prologue scheduling.  So once we see one, skip past
01569          all of them.   We have similar code for the fp arg stores below.
01570 
01571          FIXME.  Can still die if we have a mix of GR and FR argument
01572          stores!  */
01573       if (reg_num >= (gdbarch_ptr_bit (gdbarch) == 64 ? 19 : 23)
01574           && reg_num <= 26)
01575         {
01576           while (reg_num >= (gdbarch_ptr_bit (gdbarch) == 64 ? 19 : 23)
01577                  && reg_num <= 26)
01578             {
01579               pc += 4;
01580               status = target_read_memory (pc, buf, 4);
01581               inst = extract_unsigned_integer (buf, 4, byte_order);
01582               if (status != 0)
01583                 return pc;
01584               reg_num = inst_saves_gr (inst);
01585             }
01586           args_stored = 0;
01587           continue;
01588         }
01589 
01590       reg_num = inst_saves_fr (inst);
01591       save_fr &= ~(1 << reg_num);
01592 
01593       status = target_read_memory (pc + 4, buf, 4);
01594       next_inst = extract_unsigned_integer (buf, 4, byte_order);
01595 
01596       /* Yow! */
01597       if (status != 0)
01598         return pc;
01599 
01600       /* We've got to be read to handle the ldo before the fp register
01601          save.  */
01602       if ((inst & 0xfc000000) == 0x34000000
01603           && inst_saves_fr (next_inst) >= 4
01604           && inst_saves_fr (next_inst)
01605                <= (gdbarch_ptr_bit (gdbarch) == 64 ? 11 : 7))
01606         {
01607           /* So we drop into the code below in a reasonable state.  */
01608           reg_num = inst_saves_fr (next_inst);
01609           pc -= 4;
01610         }
01611 
01612       /* Ugh.  Also account for argument stores into the stack.
01613          This is a kludge as on the HP compiler sets this bit and it
01614          never does prologue scheduling.  So once we see one, skip past
01615          all of them.  */
01616       if (reg_num >= 4
01617           && reg_num <= (gdbarch_ptr_bit (gdbarch) == 64 ? 11 : 7))
01618         {
01619           while (reg_num >= 4
01620                  && reg_num
01621                       <= (gdbarch_ptr_bit (gdbarch) == 64 ? 11 : 7))
01622             {
01623               pc += 8;
01624               status = target_read_memory (pc, buf, 4);
01625               inst = extract_unsigned_integer (buf, 4, byte_order);
01626               if (status != 0)
01627                 return pc;
01628               if ((inst & 0xfc000000) != 0x34000000)
01629                 break;
01630               status = target_read_memory (pc + 4, buf, 4);
01631               next_inst = extract_unsigned_integer (buf, 4, byte_order);
01632               if (status != 0)
01633                 return pc;
01634               reg_num = inst_saves_fr (next_inst);
01635             }
01636           args_stored = 0;
01637           continue;
01638         }
01639 
01640       /* Quit if we hit any kind of branch.  This can happen if a prologue
01641          instruction is in the delay slot of the first call/branch.  */
01642       if (is_branch (inst) && stop_before_branch)
01643         break;
01644 
01645       /* What a crock.  The HP compilers set args_stored even if no
01646          arguments were stored into the stack (boo hiss).  This could
01647          cause this code to then skip a bunch of user insns (up to the
01648          first branch).
01649 
01650          To combat this we try to identify when args_stored was bogusly
01651          set and clear it.   We only do this when args_stored is nonzero,
01652          all other resources are accounted for, and nothing changed on
01653          this pass.  */
01654       if (args_stored
01655        && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
01656           && old_save_gr == save_gr && old_save_fr == save_fr
01657           && old_save_rp == save_rp && old_save_sp == save_sp
01658           && old_stack_remaining == stack_remaining)
01659         break;
01660 
01661       /* Bump the PC.  */
01662       pc += 4;
01663 
01664       /* !stop_before_branch, so also look at the insn in the delay slot 
01665          of the branch.  */
01666       if (final_iteration)
01667         break;
01668       if (is_branch (inst))
01669         final_iteration = 1;
01670     }
01671 
01672   /* We've got a tenative location for the end of the prologue.  However
01673      because of limitations in the unwind descriptor mechanism we may
01674      have went too far into user code looking for the save of a register
01675      that does not exist.  So, if there registers we expected to be saved
01676      but never were, mask them out and restart.
01677 
01678      This should only happen in optimized code, and should be very rare.  */
01679   if (save_gr || (save_fr && !(restart_fr || restart_gr)))
01680     {
01681       pc = orig_pc;
01682       restart_gr = save_gr;
01683       restart_fr = save_fr;
01684       goto restart;
01685     }
01686 
01687   return pc;
01688 }
01689 
01690 
01691 /* Return the address of the PC after the last prologue instruction if
01692    we can determine it from the debug symbols.  Else return zero.  */
01693 
01694 static CORE_ADDR
01695 after_prologue (CORE_ADDR pc)
01696 {
01697   struct symtab_and_line sal;
01698   CORE_ADDR func_addr, func_end;
01699 
01700   /* If we can not find the symbol in the partial symbol table, then
01701      there is no hope we can determine the function's start address
01702      with this code.  */
01703   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
01704     return 0;
01705 
01706   /* Get the line associated with FUNC_ADDR.  */
01707   sal = find_pc_line (func_addr, 0);
01708 
01709   /* There are only two cases to consider.  First, the end of the source line
01710      is within the function bounds.  In that case we return the end of the
01711      source line.  Second is the end of the source line extends beyond the
01712      bounds of the current function.  We need to use the slow code to
01713      examine instructions in that case.
01714 
01715      Anything else is simply a bug elsewhere.  Fixing it here is absolutely
01716      the wrong thing to do.  In fact, it should be entirely possible for this
01717      function to always return zero since the slow instruction scanning code
01718      is supposed to *always* work.  If it does not, then it is a bug.  */
01719   if (sal.end < func_end)
01720     return sal.end;
01721   else
01722     return 0;
01723 }
01724 
01725 /* To skip prologues, I use this predicate.  Returns either PC itself
01726    if the code at PC does not look like a function prologue; otherwise
01727    returns an address that (if we're lucky) follows the prologue.
01728    
01729    hppa_skip_prologue is called by gdb to place a breakpoint in a function.
01730    It doesn't necessarily skips all the insns in the prologue.  In fact
01731    we might not want to skip all the insns because a prologue insn may
01732    appear in the delay slot of the first branch, and we don't want to
01733    skip over the branch in that case.  */
01734 
01735 static CORE_ADDR
01736 hppa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
01737 {
01738   CORE_ADDR post_prologue_pc;
01739 
01740   /* See if we can determine the end of the prologue via the symbol table.
01741      If so, then return either PC, or the PC after the prologue, whichever
01742      is greater.  */
01743 
01744   post_prologue_pc = after_prologue (pc);
01745 
01746   /* If after_prologue returned a useful address, then use it.  Else
01747      fall back on the instruction skipping code.
01748 
01749      Some folks have claimed this causes problems because the breakpoint
01750      may be the first instruction of the prologue.  If that happens, then
01751      the instruction skipping code has a bug that needs to be fixed.  */
01752   if (post_prologue_pc != 0)
01753     return max (pc, post_prologue_pc);
01754   else
01755     return (skip_prologue_hard_way (gdbarch, pc, 1));
01756 }
01757 
01758 /* Return an unwind entry that falls within the frame's code block.  */
01759 
01760 static struct unwind_table_entry *
01761 hppa_find_unwind_entry_in_block (struct frame_info *this_frame)
01762 {
01763   CORE_ADDR pc = get_frame_address_in_block (this_frame);
01764 
01765   /* FIXME drow/20070101: Calling gdbarch_addr_bits_remove on the
01766      result of get_frame_address_in_block implies a problem.
01767      The bits should have been removed earlier, before the return
01768      value of gdbarch_unwind_pc.  That might be happening already;
01769      if it isn't, it should be fixed.  Then this call can be
01770      removed.  */
01771   pc = gdbarch_addr_bits_remove (get_frame_arch (this_frame), pc);
01772   return find_unwind_entry (pc);
01773 }
01774 
01775 struct hppa_frame_cache
01776 {
01777   CORE_ADDR base;
01778   struct trad_frame_saved_reg *saved_regs;
01779 };
01780 
01781 static struct hppa_frame_cache *
01782 hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
01783 {
01784   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01785   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01786   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
01787   struct hppa_frame_cache *cache;
01788   long saved_gr_mask;
01789   long saved_fr_mask;
01790   long frame_size;
01791   struct unwind_table_entry *u;
01792   CORE_ADDR prologue_end;
01793   int fp_in_r1 = 0;
01794   int i;
01795 
01796   if (hppa_debug)
01797     fprintf_unfiltered (gdb_stdlog, "{ hppa_frame_cache (frame=%d) -> ",
01798       frame_relative_level(this_frame));
01799 
01800   if ((*this_cache) != NULL)
01801     {
01802       if (hppa_debug)
01803         fprintf_unfiltered (gdb_stdlog, "base=%s (cached) }",
01804           paddress (gdbarch, ((struct hppa_frame_cache *)*this_cache)->base));
01805       return (*this_cache);
01806     }
01807   cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
01808   (*this_cache) = cache;
01809   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
01810 
01811   /* Yow! */
01812   u = hppa_find_unwind_entry_in_block (this_frame);
01813   if (!u)
01814     {
01815       if (hppa_debug)
01816         fprintf_unfiltered (gdb_stdlog, "base=NULL (no unwind entry) }");
01817       return (*this_cache);
01818     }
01819 
01820   /* Turn the Entry_GR field into a bitmask.  */
01821   saved_gr_mask = 0;
01822   for (i = 3; i < u->Entry_GR + 3; i++)
01823     {
01824       /* Frame pointer gets saved into a special location.  */
01825       if (u->Save_SP && i == HPPA_FP_REGNUM)
01826         continue;
01827         
01828       saved_gr_mask |= (1 << i);
01829     }
01830 
01831   /* Turn the Entry_FR field into a bitmask too.  */
01832   saved_fr_mask = 0;
01833   for (i = 12; i < u->Entry_FR + 12; i++)
01834     saved_fr_mask |= (1 << i);
01835 
01836   /* Loop until we find everything of interest or hit a branch.
01837 
01838      For unoptimized GCC code and for any HP CC code this will never ever
01839      examine any user instructions.
01840 
01841      For optimized GCC code we're faced with problems.  GCC will schedule
01842      its prologue and make prologue instructions available for delay slot
01843      filling.  The end result is user code gets mixed in with the prologue
01844      and a prologue instruction may be in the delay slot of the first branch
01845      or call.
01846 
01847      Some unexpected things are expected with debugging optimized code, so
01848      we allow this routine to walk past user instructions in optimized
01849      GCC code.  */
01850   {
01851     int final_iteration = 0;
01852     CORE_ADDR pc, start_pc, end_pc;
01853     int looking_for_sp = u->Save_SP;
01854     int looking_for_rp = u->Save_RP;
01855     int fp_loc = -1;
01856 
01857     /* We have to use skip_prologue_hard_way instead of just 
01858        skip_prologue_using_sal, in case we stepped into a function without
01859        symbol information.  hppa_skip_prologue also bounds the returned
01860        pc by the passed in pc, so it will not return a pc in the next
01861        function.
01862        
01863        We used to call hppa_skip_prologue to find the end of the prologue,
01864        but if some non-prologue instructions get scheduled into the prologue,
01865        and the program is compiled with debug information, the "easy" way
01866        in hppa_skip_prologue will return a prologue end that is too early
01867        for us to notice any potential frame adjustments.  */
01868 
01869     /* We used to use get_frame_func to locate the beginning of the
01870        function to pass to skip_prologue.  However, when objects are
01871        compiled without debug symbols, get_frame_func can return the wrong
01872        function (or 0).  We can do better than that by using unwind records.
01873        This only works if the Region_description of the unwind record
01874        indicates that it includes the entry point of the function.
01875        HP compilers sometimes generate unwind records for regions that
01876        do not include the entry or exit point of a function.  GNU tools
01877        do not do this.  */
01878 
01879     if ((u->Region_description & 0x2) == 0)
01880       start_pc = u->region_start;
01881     else
01882       start_pc = get_frame_func (this_frame);
01883 
01884     prologue_end = skip_prologue_hard_way (gdbarch, start_pc, 0);
01885     end_pc = get_frame_pc (this_frame);
01886 
01887     if (prologue_end != 0 && end_pc > prologue_end)
01888       end_pc = prologue_end;
01889 
01890     frame_size = 0;
01891 
01892     for (pc = start_pc;
01893          ((saved_gr_mask || saved_fr_mask
01894            || looking_for_sp || looking_for_rp
01895            || frame_size < (u->Total_frame_size << 3))
01896           && pc < end_pc);
01897          pc += 4)
01898       {
01899         int reg;
01900         gdb_byte buf4[4];
01901         long inst;
01902 
01903         if (!safe_frame_unwind_memory (this_frame, pc, buf4, sizeof buf4)) 
01904           {
01905             error (_("Cannot read instruction at %s."),
01906                    paddress (gdbarch, pc));
01907             return (*this_cache);
01908           }
01909 
01910         inst = extract_unsigned_integer (buf4, sizeof buf4, byte_order);
01911 
01912         /* Note the interesting effects of this instruction.  */
01913         frame_size += prologue_inst_adjust_sp (inst);
01914         
01915         /* There are limited ways to store the return pointer into the
01916            stack.  */
01917         if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
01918           {
01919             looking_for_rp = 0;
01920             cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
01921           }
01922         else if (inst == 0x6bc23fd1) /* stw rp,-0x18(sr0,sp) */
01923           {
01924             looking_for_rp = 0;
01925             cache->saved_regs[HPPA_RP_REGNUM].addr = -24;
01926           }
01927         else if (inst == 0x0fc212c1 
01928                  || inst == 0x73c23fe1) /* std rp,-0x10(sr0,sp) */
01929           {
01930             looking_for_rp = 0;
01931             cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
01932           }
01933         
01934         /* Check to see if we saved SP into the stack.  This also
01935            happens to indicate the location of the saved frame
01936            pointer.  */
01937         if ((inst & 0xffffc000) == 0x6fc10000  /* stw,ma r1,N(sr0,sp) */
01938             || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
01939           {
01940             looking_for_sp = 0;
01941             cache->saved_regs[HPPA_FP_REGNUM].addr = 0;
01942           }
01943         else if (inst == 0x08030241) /* copy %r3, %r1 */
01944           {
01945             fp_in_r1 = 1;
01946           }
01947         
01948         /* Account for general and floating-point register saves.  */
01949         reg = inst_saves_gr (inst);
01950         if (reg >= 3 && reg <= 18
01951             && (!u->Save_SP || reg != HPPA_FP_REGNUM))
01952           {
01953             saved_gr_mask &= ~(1 << reg);
01954             if ((inst >> 26) == 0x1b && hppa_extract_14 (inst) >= 0)
01955               /* stwm with a positive displacement is a _post_
01956                  _modify_.  */
01957               cache->saved_regs[reg].addr = 0;
01958             else if ((inst & 0xfc00000c) == 0x70000008)
01959               /* A std has explicit post_modify forms.  */
01960               cache->saved_regs[reg].addr = 0;
01961             else
01962               {
01963                 CORE_ADDR offset;
01964                 
01965                 if ((inst >> 26) == 0x1c)
01966                   offset = (inst & 0x1 ? -1 << 13 : 0)
01967                     | (((inst >> 4) & 0x3ff) << 3);
01968                 else if ((inst >> 26) == 0x03)
01969                   offset = hppa_low_hppa_sign_extend (inst & 0x1f, 5);
01970                 else
01971                   offset = hppa_extract_14 (inst);
01972                 
01973                 /* Handle code with and without frame pointers.  */
01974                 if (u->Save_SP)
01975                   cache->saved_regs[reg].addr = offset;
01976                 else
01977                   cache->saved_regs[reg].addr
01978                     = (u->Total_frame_size << 3) + offset;
01979               }
01980           }
01981 
01982         /* GCC handles callee saved FP regs a little differently.  
01983            
01984            It emits an instruction to put the value of the start of
01985            the FP store area into %r1.  It then uses fstds,ma with a
01986            basereg of %r1 for the stores.
01987 
01988            HP CC emits them at the current stack pointer modifying the
01989            stack pointer as it stores each register.  */
01990         
01991         /* ldo X(%r3),%r1 or ldo X(%r30),%r1.  */
01992         if ((inst & 0xffffc000) == 0x34610000
01993             || (inst & 0xffffc000) == 0x37c10000)
01994           fp_loc = hppa_extract_14 (inst);
01995         
01996         reg = inst_saves_fr (inst);
01997         if (reg >= 12 && reg <= 21)
01998           {
01999             /* Note +4 braindamage below is necessary because the FP
02000                status registers are internally 8 registers rather than
02001                the expected 4 registers.  */
02002             saved_fr_mask &= ~(1 << reg);
02003             if (fp_loc == -1)
02004               {
02005                 /* 1st HP CC FP register store.  After this
02006                    instruction we've set enough state that the GCC and
02007                    HPCC code are both handled in the same manner.  */
02008                 cache->saved_regs[reg + HPPA_FP4_REGNUM + 4].addr = 0;
02009                 fp_loc = 8;
02010               }
02011             else
02012               {
02013                 cache->saved_regs[reg + HPPA_FP0_REGNUM + 4].addr = fp_loc;
02014                 fp_loc += 8;
02015               }
02016           }
02017         
02018         /* Quit if we hit any kind of branch the previous iteration.  */
02019         if (final_iteration)
02020           break;
02021         /* We want to look precisely one instruction beyond the branch
02022            if we have not found everything yet.  */
02023         if (is_branch (inst))
02024           final_iteration = 1;
02025       }
02026   }
02027 
02028   {
02029     /* The frame base always represents the value of %sp at entry to
02030        the current function (and is thus equivalent to the "saved"
02031        stack pointer.  */
02032     CORE_ADDR this_sp = get_frame_register_unsigned (this_frame,
02033                                                      HPPA_SP_REGNUM);
02034     CORE_ADDR fp;
02035 
02036     if (hppa_debug)
02037       fprintf_unfiltered (gdb_stdlog, " (this_sp=%s, pc=%s, "
02038                           "prologue_end=%s) ",
02039                           paddress (gdbarch, this_sp),
02040                           paddress (gdbarch, get_frame_pc (this_frame)),
02041                           paddress (gdbarch, prologue_end));
02042 
02043      /* Check to see if a frame pointer is available, and use it for
02044         frame unwinding if it is.
02045  
02046         There are some situations where we need to rely on the frame
02047         pointer to do stack unwinding.  For example, if a function calls
02048         alloca (), the stack pointer can get adjusted inside the body of
02049         the function.  In this case, the ABI requires that the compiler
02050         maintain a frame pointer for the function.
02051  
02052         The unwind record has a flag (alloca_frame) that indicates that
02053         a function has a variable frame; unfortunately, gcc/binutils 
02054         does not set this flag.  Instead, whenever a frame pointer is used
02055         and saved on the stack, the Save_SP flag is set.  We use this to
02056         decide whether to use the frame pointer for unwinding.
02057         
02058         TODO: For the HP compiler, maybe we should use the alloca_frame flag 
02059         instead of Save_SP.  */
02060  
02061      fp = get_frame_register_unsigned (this_frame, HPPA_FP_REGNUM);
02062 
02063      if (u->alloca_frame)
02064        fp -= u->Total_frame_size << 3;
02065  
02066      if (get_frame_pc (this_frame) >= prologue_end
02067          && (u->Save_SP || u->alloca_frame) && fp != 0)
02068       {
02069         cache->base = fp;
02070  
02071         if (hppa_debug)
02072           fprintf_unfiltered (gdb_stdlog, " (base=%s) [frame pointer]",
02073                               paddress (gdbarch, cache->base));
02074       }
02075      else if (u->Save_SP 
02076               && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM))
02077       {
02078             /* Both we're expecting the SP to be saved and the SP has been
02079                saved.  The entry SP value is saved at this frame's SP
02080                address.  */
02081             cache->base = read_memory_integer (this_sp, word_size, byte_order);
02082 
02083             if (hppa_debug)
02084               fprintf_unfiltered (gdb_stdlog, " (base=%s) [saved]",
02085                                   paddress (gdbarch, cache->base));
02086       }
02087     else
02088       {
02089         /* The prologue has been slowly allocating stack space.  Adjust
02090            the SP back.  */
02091         cache->base = this_sp - frame_size;
02092         if (hppa_debug)
02093           fprintf_unfiltered (gdb_stdlog, " (base=%s) [unwind adjust]",
02094                               paddress (gdbarch, cache->base));
02095 
02096       }
02097     trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
02098   }
02099 
02100   /* The PC is found in the "return register", "Millicode" uses "r31"
02101      as the return register while normal code uses "rp".  */
02102   if (u->Millicode)
02103     {
02104       if (trad_frame_addr_p (cache->saved_regs, 31))
02105         {
02106           cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[31];
02107           if (hppa_debug)
02108             fprintf_unfiltered (gdb_stdlog, " (pc=r31) [stack] } ");
02109         }
02110       else
02111         {
02112           ULONGEST r31 = get_frame_register_unsigned (this_frame, 31);
02113           trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, r31);
02114           if (hppa_debug)
02115             fprintf_unfiltered (gdb_stdlog, " (pc=r31) [frame] } ");
02116         }
02117     }
02118   else
02119     {
02120       if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
02121         {
02122           cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = 
02123             cache->saved_regs[HPPA_RP_REGNUM];
02124           if (hppa_debug)
02125             fprintf_unfiltered (gdb_stdlog, " (pc=rp) [stack] } ");
02126         }
02127       else
02128         {
02129           ULONGEST rp = get_frame_register_unsigned (this_frame,
02130                                                      HPPA_RP_REGNUM);
02131           trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
02132           if (hppa_debug)
02133             fprintf_unfiltered (gdb_stdlog, " (pc=rp) [frame] } ");
02134         }
02135     }
02136 
02137   /* If Save_SP is set, then we expect the frame pointer to be saved in the
02138      frame.  However, there is a one-insn window where we haven't saved it
02139      yet, but we've already clobbered it.  Detect this case and fix it up.
02140 
02141      The prologue sequence for frame-pointer functions is:
02142         0: stw %rp, -20(%sp)
02143         4: copy %r3, %r1
02144         8: copy %sp, %r3
02145         c: stw,ma %r1, XX(%sp)
02146 
02147      So if we are at offset c, the r3 value that we want is not yet saved
02148      on the stack, but it's been overwritten.  The prologue analyzer will
02149      set fp_in_r1 when it sees the copy insn so we know to get the value 
02150      from r1 instead.  */
02151   if (u->Save_SP && !trad_frame_addr_p (cache->saved_regs, HPPA_FP_REGNUM)
02152       && fp_in_r1)
02153     {
02154       ULONGEST r1 = get_frame_register_unsigned (this_frame, 1);
02155       trad_frame_set_value (cache->saved_regs, HPPA_FP_REGNUM, r1);
02156     }
02157 
02158   {
02159     /* Convert all the offsets into addresses.  */
02160     int reg;
02161     for (reg = 0; reg < gdbarch_num_regs (gdbarch); reg++)
02162       {
02163         if (trad_frame_addr_p (cache->saved_regs, reg))
02164           cache->saved_regs[reg].addr += cache->base;
02165       }
02166   }
02167 
02168   {
02169     struct gdbarch_tdep *tdep;
02170 
02171     tdep = gdbarch_tdep (gdbarch);
02172 
02173     if (tdep->unwind_adjust_stub)
02174       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
02175   }
02176 
02177   if (hppa_debug)
02178     fprintf_unfiltered (gdb_stdlog, "base=%s }",
02179       paddress (gdbarch, ((struct hppa_frame_cache *)*this_cache)->base));
02180   return (*this_cache);
02181 }
02182 
02183 static void
02184 hppa_frame_this_id (struct frame_info *this_frame, void **this_cache,
02185                     struct frame_id *this_id)
02186 {
02187   struct hppa_frame_cache *info;
02188   CORE_ADDR pc = get_frame_pc (this_frame);
02189   struct unwind_table_entry *u;
02190 
02191   info = hppa_frame_cache (this_frame, this_cache);
02192   u = hppa_find_unwind_entry_in_block (this_frame);
02193 
02194   (*this_id) = frame_id_build (info->base, u->region_start);
02195 }
02196 
02197 static struct value *
02198 hppa_frame_prev_register (struct frame_info *this_frame,
02199                           void **this_cache, int regnum)
02200 {
02201   struct hppa_frame_cache *info = hppa_frame_cache (this_frame, this_cache);
02202 
02203   return hppa_frame_prev_register_helper (this_frame,
02204                                           info->saved_regs, regnum);
02205 }
02206 
02207 static int
02208 hppa_frame_unwind_sniffer (const struct frame_unwind *self,
02209                            struct frame_info *this_frame, void **this_cache)
02210 {
02211   if (hppa_find_unwind_entry_in_block (this_frame))
02212     return 1;
02213 
02214   return 0;
02215 }
02216 
02217 static const struct frame_unwind hppa_frame_unwind =
02218 {
02219   NORMAL_FRAME,
02220   default_frame_unwind_stop_reason,
02221   hppa_frame_this_id,
02222   hppa_frame_prev_register,
02223   NULL,
02224   hppa_frame_unwind_sniffer
02225 };
02226 
02227 /* This is a generic fallback frame unwinder that kicks in if we fail all
02228    the other ones.  Normally we would expect the stub and regular unwinder
02229    to work, but in some cases we might hit a function that just doesn't
02230    have any unwind information available.  In this case we try to do
02231    unwinding solely based on code reading.  This is obviously going to be
02232    slow, so only use this as a last resort.  Currently this will only
02233    identify the stack and pc for the frame.  */
02234 
02235 static struct hppa_frame_cache *
02236 hppa_fallback_frame_cache (struct frame_info *this_frame, void **this_cache)
02237 {
02238   struct gdbarch *gdbarch = get_frame_arch (this_frame);
02239   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
02240   struct hppa_frame_cache *cache;
02241   unsigned int frame_size = 0;
02242   int found_rp = 0;
02243   CORE_ADDR start_pc;
02244 
02245   if (hppa_debug)
02246     fprintf_unfiltered (gdb_stdlog,
02247                         "{ hppa_fallback_frame_cache (frame=%d) -> ",
02248                         frame_relative_level (this_frame));
02249 
02250   cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
02251   (*this_cache) = cache;
02252   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
02253 
02254   start_pc = get_frame_func (this_frame);
02255   if (start_pc)
02256     {
02257       CORE_ADDR cur_pc = get_frame_pc (this_frame);
02258       CORE_ADDR pc;
02259 
02260       for (pc = start_pc; pc < cur_pc; pc += 4)
02261         {
02262           unsigned int insn;
02263 
02264           insn = read_memory_unsigned_integer (pc, 4, byte_order);
02265           frame_size += prologue_inst_adjust_sp (insn);
02266 
02267           /* There are limited ways to store the return pointer into the
02268              stack.  */
02269           if (insn == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
02270             {
02271               cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
02272               found_rp = 1;
02273             }
02274           else if (insn == 0x0fc212c1
02275                    || insn == 0x73c23fe1) /* std rp,-0x10(sr0,sp) */
02276             {
02277               cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
02278               found_rp = 1;
02279             }
02280         }
02281     }
02282 
02283   if (hppa_debug)
02284     fprintf_unfiltered (gdb_stdlog, " frame_size=%d, found_rp=%d }\n",
02285                         frame_size, found_rp);
02286 
02287   cache->base = get_frame_register_unsigned (this_frame, HPPA_SP_REGNUM);
02288   cache->base -= frame_size;
02289   trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
02290 
02291   if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
02292     {
02293       cache->saved_regs[HPPA_RP_REGNUM].addr += cache->base;
02294       cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = 
02295         cache->saved_regs[HPPA_RP_REGNUM];
02296     }
02297   else
02298     {
02299       ULONGEST rp;
02300       rp = get_frame_register_unsigned (this_frame, HPPA_RP_REGNUM);
02301       trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
02302     }
02303 
02304   return cache;
02305 }
02306 
02307 static void
02308 hppa_fallback_frame_this_id (struct frame_info *this_frame, void **this_cache,
02309                              struct frame_id *this_id)
02310 {
02311   struct hppa_frame_cache *info = 
02312     hppa_fallback_frame_cache (this_frame, this_cache);
02313 
02314   (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
02315 }
02316 
02317 static struct value *
02318 hppa_fallback_frame_prev_register (struct frame_info *this_frame,
02319                                    void **this_cache, int regnum)
02320 {
02321   struct hppa_frame_cache *info
02322     = hppa_fallback_frame_cache (this_frame, this_cache);
02323 
02324   return hppa_frame_prev_register_helper (this_frame,
02325                                           info->saved_regs, regnum);
02326 }
02327 
02328 static const struct frame_unwind hppa_fallback_frame_unwind =
02329 {
02330   NORMAL_FRAME,
02331   default_frame_unwind_stop_reason,
02332   hppa_fallback_frame_this_id,
02333   hppa_fallback_frame_prev_register,
02334   NULL,
02335   default_frame_sniffer
02336 };
02337 
02338 /* Stub frames, used for all kinds of call stubs.  */
02339 struct hppa_stub_unwind_cache
02340 {
02341   CORE_ADDR base;
02342   struct trad_frame_saved_reg *saved_regs;
02343 };
02344 
02345 static struct hppa_stub_unwind_cache *
02346 hppa_stub_frame_unwind_cache (struct frame_info *this_frame,
02347                               void **this_cache)
02348 {
02349   struct gdbarch *gdbarch = get_frame_arch (this_frame);
02350   struct hppa_stub_unwind_cache *info;
02351   struct unwind_table_entry *u;
02352 
02353   if (*this_cache)
02354     return *this_cache;
02355 
02356   info = FRAME_OBSTACK_ZALLOC (struct hppa_stub_unwind_cache);
02357   *this_cache = info;
02358   info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
02359 
02360   info->base = get_frame_register_unsigned (this_frame, HPPA_SP_REGNUM);
02361 
02362   if (gdbarch_osabi (gdbarch) == GDB_OSABI_HPUX_SOM)
02363     {
02364       /* HPUX uses export stubs in function calls; the export stub clobbers
02365          the return value of the caller, and, later restores it from the
02366          stack.  */
02367       u = find_unwind_entry (get_frame_pc (this_frame));
02368 
02369       if (u && u->stub_unwind.stub_type == EXPORT)
02370         {
02371           info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].addr = info->base - 24;
02372 
02373           return info;
02374         }
02375     }
02376 
02377   /* By default we assume that stubs do not change the rp.  */
02378   info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM;
02379 
02380   return info;
02381 }
02382 
02383 static void
02384 hppa_stub_frame_this_id (struct frame_info *this_frame,
02385                          void **this_prologue_cache,
02386                          struct frame_id *this_id)
02387 {
02388   struct hppa_stub_unwind_cache *info
02389     = hppa_stub_frame_unwind_cache (this_frame, this_prologue_cache);
02390 
02391   if (info)
02392     *this_id = frame_id_build (info->base, get_frame_func (this_frame));
02393 }
02394 
02395 static struct value *
02396 hppa_stub_frame_prev_register (struct frame_info *this_frame,
02397                                void **this_prologue_cache, int regnum)
02398 {
02399   struct hppa_stub_unwind_cache *info
02400     = hppa_stub_frame_unwind_cache (this_frame, this_prologue_cache);
02401 
02402   if (info == NULL)
02403     error (_("Requesting registers from null frame."));
02404 
02405   return hppa_frame_prev_register_helper (this_frame,
02406                                           info->saved_regs, regnum);
02407 }
02408 
02409 static int
02410 hppa_stub_unwind_sniffer (const struct frame_unwind *self,
02411                           struct frame_info *this_frame,
02412                           void **this_cache)
02413 {
02414   CORE_ADDR pc = get_frame_address_in_block (this_frame);
02415   struct gdbarch *gdbarch = get_frame_arch (this_frame);
02416   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
02417 
02418   if (pc == 0
02419       || (tdep->in_solib_call_trampoline != NULL
02420           && tdep->in_solib_call_trampoline (gdbarch, pc))
02421       || gdbarch_in_solib_return_trampoline (gdbarch, pc, NULL))
02422     return 1;
02423   return 0;
02424 }
02425 
02426 static const struct frame_unwind hppa_stub_frame_unwind = {
02427   NORMAL_FRAME,
02428   default_frame_unwind_stop_reason,
02429   hppa_stub_frame_this_id,
02430   hppa_stub_frame_prev_register,
02431   NULL,
02432   hppa_stub_unwind_sniffer
02433 };
02434 
02435 static struct frame_id
02436 hppa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
02437 {
02438   return frame_id_build (get_frame_register_unsigned (this_frame,
02439                                                       HPPA_SP_REGNUM),
02440                          get_frame_pc (this_frame));
02441 }
02442 
02443 CORE_ADDR
02444 hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
02445 {
02446   ULONGEST ipsw;
02447   CORE_ADDR pc;
02448 
02449   ipsw = frame_unwind_register_unsigned (next_frame, HPPA_IPSW_REGNUM);
02450   pc = frame_unwind_register_unsigned (next_frame, HPPA_PCOQ_HEAD_REGNUM);
02451 
02452   /* If the current instruction is nullified, then we are effectively
02453      still executing the previous instruction.  Pretend we are still
02454      there.  This is needed when single stepping; if the nullified
02455      instruction is on a different line, we don't want GDB to think
02456      we've stepped onto that line.  */
02457   if (ipsw & 0x00200000)
02458     pc -= 4;
02459 
02460   return pc & ~0x3;
02461 }
02462 
02463 /* Return the minimal symbol whose name is NAME and stub type is STUB_TYPE.
02464    Return NULL if no such symbol was found.  */
02465 
02466 struct minimal_symbol *
02467 hppa_lookup_stub_minimal_symbol (const char *name,
02468                                  enum unwind_stub_types stub_type)
02469 {
02470   struct objfile *objfile;
02471   struct minimal_symbol *msym;
02472 
02473   ALL_MSYMBOLS (objfile, msym)
02474     {
02475       if (strcmp (SYMBOL_LINKAGE_NAME (msym), name) == 0)
02476         {
02477           struct unwind_table_entry *u;
02478 
02479           u = find_unwind_entry (SYMBOL_VALUE (msym));
02480           if (u != NULL && u->stub_unwind.stub_type == stub_type)
02481             return msym;
02482         }
02483     }
02484 
02485   return NULL;
02486 }
02487 
02488 static void
02489 unwind_command (char *exp, int from_tty)
02490 {
02491   CORE_ADDR address;
02492   struct unwind_table_entry *u;
02493 
02494   /* If we have an expression, evaluate it and use it as the address.  */
02495 
02496   if (exp != 0 && *exp != 0)
02497     address = parse_and_eval_address (exp);
02498   else
02499     return;
02500 
02501   u = find_unwind_entry (address);
02502 
02503   if (!u)
02504     {
02505       printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
02506       return;
02507     }
02508 
02509   printf_unfiltered ("unwind_table_entry (%s):\n", host_address_to_string (u));
02510 
02511   printf_unfiltered ("\tregion_start = %s\n", hex_string (u->region_start));
02512   gdb_flush (gdb_stdout);
02513 
02514   printf_unfiltered ("\tregion_end = %s\n", hex_string (u->region_end));
02515   gdb_flush (gdb_stdout);
02516 
02517 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
02518 
02519   printf_unfiltered ("\n\tflags =");
02520   pif (Cannot_unwind);
02521   pif (Millicode);
02522   pif (Millicode_save_sr0);
02523   pif (Entry_SR);
02524   pif (Args_stored);
02525   pif (Variable_Frame);
02526   pif (Separate_Package_Body);
02527   pif (Frame_Extension_Millicode);
02528   pif (Stack_Overflow_Check);
02529   pif (Two_Instruction_SP_Increment);
02530   pif (sr4export);
02531   pif (cxx_info);
02532   pif (cxx_try_catch);
02533   pif (sched_entry_seq);
02534   pif (Save_SP);
02535   pif (Save_RP);
02536   pif (Save_MRP_in_frame);
02537   pif (save_r19);
02538   pif (Cleanup_defined);
02539   pif (MPE_XL_interrupt_marker);
02540   pif (HP_UX_interrupt_marker);
02541   pif (Large_frame);
02542   pif (alloca_frame);
02543 
02544   putchar_unfiltered ('\n');
02545 
02546 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
02547 
02548   pin (Region_description);
02549   pin (Entry_FR);
02550   pin (Entry_GR);
02551   pin (Total_frame_size);
02552 
02553   if (u->stub_unwind.stub_type)
02554     {
02555       printf_unfiltered ("\tstub type = ");
02556       switch (u->stub_unwind.stub_type)
02557         {
02558           case LONG_BRANCH:
02559             printf_unfiltered ("long branch\n");
02560             break;
02561           case PARAMETER_RELOCATION:
02562             printf_unfiltered ("parameter relocation\n");
02563             break;
02564           case EXPORT:
02565             printf_unfiltered ("export\n");
02566             break;
02567           case IMPORT:
02568             printf_unfiltered ("import\n");
02569             break;
02570           case IMPORT_SHLIB:
02571             printf_unfiltered ("import shlib\n");
02572             break;
02573           default:
02574             printf_unfiltered ("unknown (%d)\n", u->stub_unwind.stub_type);
02575         }
02576     }
02577 }
02578 
02579 /* Return the GDB type object for the "standard" data type of data in
02580    register REGNUM.  */
02581 
02582 static struct type *
02583 hppa32_register_type (struct gdbarch *gdbarch, int regnum)
02584 {
02585    if (regnum < HPPA_FP4_REGNUM)
02586      return builtin_type (gdbarch)->builtin_uint32;
02587    else
02588      return builtin_type (gdbarch)->builtin_float;
02589 }
02590 
02591 static struct type *
02592 hppa64_register_type (struct gdbarch *gdbarch, int regnum)
02593 {
02594    if (regnum < HPPA64_FP4_REGNUM)
02595      return builtin_type (gdbarch)->builtin_uint64;
02596    else
02597      return builtin_type (gdbarch)->builtin_double;
02598 }
02599 
02600 /* Return non-zero if REGNUM is not a register available to the user
02601    through ptrace/ttrace.  */
02602 
02603 static int
02604 hppa32_cannot_store_register (struct gdbarch *gdbarch, int regnum)
02605 {
02606   return (regnum == 0
02607           || regnum == HPPA_PCSQ_HEAD_REGNUM
02608           || (regnum >= HPPA_PCSQ_TAIL_REGNUM && regnum < HPPA_IPSW_REGNUM)
02609           || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA_FP4_REGNUM));
02610 }
02611 
02612 static int
02613 hppa32_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
02614 {
02615   /* cr26 and cr27 are readable (but not writable) from userspace.  */
02616   if (regnum == HPPA_CR26_REGNUM || regnum == HPPA_CR27_REGNUM)
02617     return 0;
02618   else
02619     return hppa32_cannot_store_register (gdbarch, regnum);
02620 }
02621 
02622 static int
02623 hppa64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
02624 {
02625   return (regnum == 0
02626           || regnum == HPPA_PCSQ_HEAD_REGNUM
02627           || (regnum >= HPPA_PCSQ_TAIL_REGNUM && regnum < HPPA_IPSW_REGNUM)
02628           || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA64_FP4_REGNUM));
02629 }
02630 
02631 static int
02632 hppa64_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
02633 {
02634   /* cr26 and cr27 are readable (but not writable) from userspace.  */
02635   if (regnum == HPPA_CR26_REGNUM || regnum == HPPA_CR27_REGNUM)
02636     return 0;
02637   else
02638     return hppa64_cannot_store_register (gdbarch, regnum);
02639 }
02640 
02641 static CORE_ADDR
02642 hppa_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
02643 {
02644   /* The low two bits of the PC on the PA contain the privilege level.
02645      Some genius implementing a (non-GCC) compiler apparently decided
02646      this means that "addresses" in a text section therefore include a
02647      privilege level, and thus symbol tables should contain these bits.
02648      This seems like a bonehead thing to do--anyway, it seems to work
02649      for our purposes to just ignore those bits.  */
02650 
02651   return (addr &= ~0x3);
02652 }
02653 
02654 /* Get the ARGIth function argument for the current function.  */
02655 
02656 static CORE_ADDR
02657 hppa_fetch_pointer_argument (struct frame_info *frame, int argi, 
02658                              struct type *type)
02659 {
02660   return get_frame_register_unsigned (frame, HPPA_R0_REGNUM + 26 - argi);
02661 }
02662 
02663 static enum register_status
02664 hppa_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
02665                            int regnum, gdb_byte *buf)
02666 {
02667   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
02668   ULONGEST tmp;
02669   enum register_status status;
02670 
02671   status = regcache_raw_read_unsigned (regcache, regnum, &tmp);
02672   if (status == REG_VALID)
02673     {
02674       if (regnum == HPPA_PCOQ_HEAD_REGNUM || regnum == HPPA_PCOQ_TAIL_REGNUM)
02675         tmp &= ~0x3;
02676       store_unsigned_integer (buf, sizeof tmp, byte_order, tmp);
02677     }
02678   return status;
02679 }
02680 
02681 static CORE_ADDR
02682 hppa_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
02683 {
02684   return 0;
02685 }
02686 
02687 struct value *
02688 hppa_frame_prev_register_helper (struct frame_info *this_frame,
02689                                  struct trad_frame_saved_reg saved_regs[],
02690                                  int regnum)
02691 {
02692   struct gdbarch *arch = get_frame_arch (this_frame);
02693   enum bfd_endian byte_order = gdbarch_byte_order (arch);
02694 
02695   if (regnum == HPPA_PCOQ_TAIL_REGNUM)
02696     {
02697       int size = register_size (arch, HPPA_PCOQ_HEAD_REGNUM);
02698       CORE_ADDR pc;
02699       struct value *pcoq_val =
02700         trad_frame_get_prev_register (this_frame, saved_regs,
02701                                       HPPA_PCOQ_HEAD_REGNUM);
02702 
02703       pc = extract_unsigned_integer (value_contents_all (pcoq_val),
02704                                      size, byte_order);
02705       return frame_unwind_got_constant (this_frame, regnum, pc + 4);
02706     }
02707 
02708   /* Make sure the "flags" register is zero in all unwound frames.
02709      The "flags" registers is a HP-UX specific wart, and only the code
02710      in hppa-hpux-tdep.c depends on it.  However, it is easier to deal
02711      with it here.  This shouldn't affect other systems since those
02712      should provide zero for the "flags" register anyway.  */
02713   if (regnum == HPPA_FLAGS_REGNUM)
02714     return frame_unwind_got_constant (this_frame, regnum, 0);
02715 
02716   return trad_frame_get_prev_register (this_frame, saved_regs, regnum);
02717 }
02718 
02719 
02720 /* An instruction to match.  */
02721 struct insn_pattern
02722 {
02723   unsigned int data;            /* See if it matches this....  */
02724   unsigned int mask;            /* ... with this mask.  */
02725 };
02726 
02727 /* See bfd/elf32-hppa.c */
02728 static struct insn_pattern hppa_long_branch_stub[] = {
02729   /* ldil LR'xxx,%r1 */
02730   { 0x20200000, 0xffe00000 },
02731   /* be,n RR'xxx(%sr4,%r1) */
02732   { 0xe0202002, 0xffe02002 }, 
02733   { 0, 0 }
02734 };
02735 
02736 static struct insn_pattern hppa_long_branch_pic_stub[] = {
02737   /* b,l .+8, %r1 */
02738   { 0xe8200000, 0xffe00000 },
02739   /* addil LR'xxx - ($PIC_pcrel$0 - 4), %r1 */
02740   { 0x28200000, 0xffe00000 },
02741   /* be,n RR'xxxx - ($PIC_pcrel$0 - 8)(%sr4, %r1) */
02742   { 0xe0202002, 0xffe02002 }, 
02743   { 0, 0 }
02744 };
02745 
02746 static struct insn_pattern hppa_import_stub[] = {
02747   /* addil LR'xxx, %dp */
02748   { 0x2b600000, 0xffe00000 },
02749   /* ldw RR'xxx(%r1), %r21 */
02750   { 0x48350000, 0xffffb000 },
02751   /* bv %r0(%r21) */
02752   { 0xeaa0c000, 0xffffffff },
02753   /* ldw RR'xxx+4(%r1), %r19 */
02754   { 0x48330000, 0xffffb000 },
02755   { 0, 0 }
02756 };
02757 
02758 static struct insn_pattern hppa_import_pic_stub[] = {
02759   /* addil LR'xxx,%r19 */
02760   { 0x2a600000, 0xffe00000 },
02761   /* ldw RR'xxx(%r1),%r21 */
02762   { 0x48350000, 0xffffb000 },
02763   /* bv %r0(%r21) */
02764   { 0xeaa0c000, 0xffffffff },
02765   /* ldw RR'xxx+4(%r1),%r19 */
02766   { 0x48330000, 0xffffb000 },
02767   { 0, 0 },
02768 };
02769 
02770 static struct insn_pattern hppa_plt_stub[] = {
02771   /* b,l 1b, %r20 - 1b is 3 insns before here */
02772   { 0xea9f1fdd, 0xffffffff },
02773   /* depi 0,31,2,%r20 */
02774   { 0xd6801c1e, 0xffffffff },
02775   { 0, 0 }
02776 };
02777 
02778 static struct insn_pattern hppa_sigtramp[] = {
02779   /* ldi 0, %r25 or ldi 1, %r25 */
02780   { 0x34190000, 0xfffffffd },
02781   /* ldi __NR_rt_sigreturn, %r20 */
02782   { 0x3414015a, 0xffffffff },
02783   /* be,l 0x100(%sr2, %r0), %sr0, %r31 */
02784   { 0xe4008200, 0xffffffff },
02785   /* nop */
02786   { 0x08000240, 0xffffffff },
02787   { 0, 0 }
02788 };
02789 
02790 /* Maximum number of instructions on the patterns above.  */
02791 #define HPPA_MAX_INSN_PATTERN_LEN       4
02792 
02793 /* Return non-zero if the instructions at PC match the series
02794    described in PATTERN, or zero otherwise.  PATTERN is an array of
02795    'struct insn_pattern' objects, terminated by an entry whose mask is
02796    zero.
02797 
02798    When the match is successful, fill INSN[i] with what PATTERN[i]
02799    matched.  */
02800 
02801 static int
02802 hppa_match_insns (struct gdbarch *gdbarch, CORE_ADDR pc,
02803                   struct insn_pattern *pattern, unsigned int *insn)
02804 {
02805   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
02806   CORE_ADDR npc = pc;
02807   int i;
02808 
02809   for (i = 0; pattern[i].mask; i++)
02810     {
02811       gdb_byte buf[HPPA_INSN_SIZE];
02812 
02813       target_read_memory (npc, buf, HPPA_INSN_SIZE);
02814       insn[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE, byte_order);
02815       if ((insn[i] & pattern[i].mask) == pattern[i].data)
02816         npc += 4;
02817       else
02818         return 0;
02819     }
02820 
02821   return 1;
02822 }
02823 
02824 /* This relaxed version of the insstruction matcher allows us to match
02825    from somewhere inside the pattern, by looking backwards in the
02826    instruction scheme.  */
02827 
02828 static int
02829 hppa_match_insns_relaxed (struct gdbarch *gdbarch, CORE_ADDR pc,
02830                           struct insn_pattern *pattern, unsigned int *insn)
02831 {
02832   int offset, len = 0;
02833 
02834   while (pattern[len].mask)
02835     len++;
02836 
02837   for (offset = 0; offset < len; offset++)
02838     if (hppa_match_insns (gdbarch, pc - offset * HPPA_INSN_SIZE,
02839                           pattern, insn))
02840       return 1;
02841 
02842   return 0;
02843 }
02844 
02845 static int
02846 hppa_in_dyncall (CORE_ADDR pc)
02847 {
02848   struct unwind_table_entry *u;
02849 
02850   u = find_unwind_entry (hppa_symbol_address ("$$dyncall"));
02851   if (!u)
02852     return 0;
02853 
02854   return (pc >= u->region_start && pc <= u->region_end);
02855 }
02856 
02857 int
02858 hppa_in_solib_call_trampoline (struct gdbarch *gdbarch, CORE_ADDR pc)
02859 {
02860   unsigned int insn[HPPA_MAX_INSN_PATTERN_LEN];
02861   struct unwind_table_entry *u;
02862 
02863   if (in_plt_section (pc) || hppa_in_dyncall (pc))
02864     return 1;
02865 
02866   /* The GNU toolchain produces linker stubs without unwind
02867      information.  Since the pattern matching for linker stubs can be
02868      quite slow, so bail out if we do have an unwind entry.  */
02869 
02870   u = find_unwind_entry (pc);
02871   if (u != NULL)
02872     return 0;
02873 
02874   return
02875     (hppa_match_insns_relaxed (gdbarch, pc, hppa_import_stub, insn)
02876      || hppa_match_insns_relaxed (gdbarch, pc, hppa_import_pic_stub, insn)
02877      || hppa_match_insns_relaxed (gdbarch, pc, hppa_long_branch_stub, insn)
02878      || hppa_match_insns_relaxed (gdbarch, pc,
02879                                   hppa_long_branch_pic_stub, insn));
02880 }
02881 
02882 /* This code skips several kind of "trampolines" used on PA-RISC
02883    systems: $$dyncall, import stubs and PLT stubs.  */
02884 
02885 CORE_ADDR
02886 hppa_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
02887 {
02888   struct gdbarch *gdbarch = get_frame_arch (frame);
02889   struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
02890 
02891   unsigned int insn[HPPA_MAX_INSN_PATTERN_LEN];
02892   int dp_rel;
02893 
02894   /* $$dyncall handles both PLABELs and direct addresses.  */
02895   if (hppa_in_dyncall (pc))
02896     {
02897       pc = get_frame_register_unsigned (frame, HPPA_R0_REGNUM + 22);
02898 
02899       /* PLABELs have bit 30 set; if it's a PLABEL, then dereference it.  */
02900       if (pc & 0x2)
02901         pc = read_memory_typed_address (pc & ~0x3, func_ptr_type);
02902 
02903       return pc;
02904     }
02905 
02906   dp_rel = hppa_match_insns (gdbarch, pc, hppa_import_stub, insn);
02907   if (dp_rel || hppa_match_insns (gdbarch, pc, hppa_import_pic_stub, insn))
02908     {
02909       /* Extract the target address from the addil/ldw sequence.  */
02910       pc = hppa_extract_21 (insn[0]) + hppa_extract_14 (insn[1]);
02911 
02912       if (dp_rel)
02913         pc += get_frame_register_unsigned (frame, HPPA_DP_REGNUM);
02914       else
02915         pc += get_frame_register_unsigned (frame, HPPA_R0_REGNUM + 19);
02916 
02917       /* fallthrough */
02918     }
02919 
02920   if (in_plt_section (pc))
02921     {
02922       pc = read_memory_typed_address (pc, func_ptr_type);
02923 
02924       /* If the PLT slot has not yet been resolved, the target will be
02925          the PLT stub.  */
02926       if (in_plt_section (pc))
02927         {
02928           /* Sanity check: are we pointing to the PLT stub?  */
02929           if (!hppa_match_insns (gdbarch, pc, hppa_plt_stub, insn))
02930             {
02931               warning (_("Cannot resolve PLT stub at %s."),
02932                        paddress (gdbarch, pc));
02933               return 0;
02934             }
02935 
02936           /* This should point to the fixup routine.  */
02937           pc = read_memory_typed_address (pc + 8, func_ptr_type);
02938         }
02939     }
02940 
02941   return pc;
02942 }
02943 
02944 
02945 /* Here is a table of C type sizes on hppa with various compiles
02946    and options.  I measured this on PA 9000/800 with HP-UX 11.11
02947    and these compilers:
02948 
02949      /usr/ccs/bin/cc    HP92453-01 A.11.01.21
02950      /opt/ansic/bin/cc  HP92453-01 B.11.11.28706.GP
02951      /opt/aCC/bin/aCC   B3910B A.03.45
02952      gcc                gcc 3.3.2 native hppa2.0w-hp-hpux11.11
02953 
02954      cc            : 1 2 4 4 8 : 4 8 -- : 4 4
02955      ansic +DA1.1  : 1 2 4 4 8 : 4 8 16 : 4 4
02956      ansic +DA2.0  : 1 2 4 4 8 : 4 8 16 : 4 4
02957      ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
02958      acc   +DA1.1  : 1 2 4 4 8 : 4 8 16 : 4 4
02959      acc   +DA2.0  : 1 2 4 4 8 : 4 8 16 : 4 4
02960      acc   +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
02961      gcc           : 1 2 4 4 8 : 4 8 16 : 4 4
02962 
02963    Each line is:
02964 
02965      compiler and options
02966      char, short, int, long, long long
02967      float, double, long double
02968      char *, void (*)()
02969 
02970    So all these compilers use either ILP32 or LP64 model.
02971    TODO: gcc has more options so it needs more investigation.
02972 
02973    For floating point types, see:
02974 
02975      http://docs.hp.com/hpux/pdf/B3906-90006.pdf
02976      HP-UX floating-point guide, hpux 11.00
02977 
02978    -- chastain 2003-12-18  */
02979 
02980 static struct gdbarch *
02981 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
02982 {
02983   struct gdbarch_tdep *tdep;
02984   struct gdbarch *gdbarch;
02985   
02986   /* Try to determine the ABI of the object we are loading.  */
02987   if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
02988     {
02989       /* If it's a SOM file, assume it's HP/UX SOM.  */
02990       if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour)
02991         info.osabi = GDB_OSABI_HPUX_SOM;
02992     }
02993 
02994   /* find a candidate among the list of pre-declared architectures.  */
02995   arches = gdbarch_list_lookup_by_info (arches, &info);
02996   if (arches != NULL)
02997     return (arches->gdbarch);
02998 
02999   /* If none found, then allocate and initialize one.  */
03000   tdep = XZALLOC (struct gdbarch_tdep);
03001   gdbarch = gdbarch_alloc (&info, tdep);
03002 
03003   /* Determine from the bfd_arch_info structure if we are dealing with
03004      a 32 or 64 bits architecture.  If the bfd_arch_info is not available,
03005      then default to a 32bit machine.  */
03006   if (info.bfd_arch_info != NULL)
03007     tdep->bytes_per_address =
03008       info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
03009   else
03010     tdep->bytes_per_address = 4;
03011 
03012   tdep->find_global_pointer = hppa_find_global_pointer;
03013 
03014   /* Some parts of the gdbarch vector depend on whether we are running
03015      on a 32 bits or 64 bits target.  */
03016   switch (tdep->bytes_per_address)
03017     {
03018       case 4:
03019         set_gdbarch_num_regs (gdbarch, hppa32_num_regs);
03020         set_gdbarch_register_name (gdbarch, hppa32_register_name);
03021         set_gdbarch_register_type (gdbarch, hppa32_register_type);
03022         set_gdbarch_cannot_store_register (gdbarch,
03023                                            hppa32_cannot_store_register);
03024         set_gdbarch_cannot_fetch_register (gdbarch,
03025                                            hppa32_cannot_fetch_register);
03026         break;
03027       case 8:
03028         set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
03029         set_gdbarch_register_name (gdbarch, hppa64_register_name);
03030         set_gdbarch_register_type (gdbarch, hppa64_register_type);
03031         set_gdbarch_dwarf2_reg_to_regnum (gdbarch, hppa64_dwarf_reg_to_regnum);
03032         set_gdbarch_cannot_store_register (gdbarch,
03033                                            hppa64_cannot_store_register);
03034         set_gdbarch_cannot_fetch_register (gdbarch,
03035                                            hppa64_cannot_fetch_register);
03036         break;
03037       default:
03038         internal_error (__FILE__, __LINE__, _("Unsupported address size: %d"),
03039                         tdep->bytes_per_address);
03040     }
03041 
03042   set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
03043   set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
03044 
03045   /* The following gdbarch vector elements are the same in both ILP32
03046      and LP64, but might show differences some day.  */
03047   set_gdbarch_long_long_bit (gdbarch, 64);
03048   set_gdbarch_long_double_bit (gdbarch, 128);
03049   set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
03050 
03051   /* The following gdbarch vector elements do not depend on the address
03052      size, or in any other gdbarch element previously set.  */
03053   set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue);
03054   set_gdbarch_in_function_epilogue_p (gdbarch,
03055                                       hppa_in_function_epilogue_p);
03056   set_gdbarch_inner_than (gdbarch, core_addr_greaterthan);
03057   set_gdbarch_sp_regnum (gdbarch, HPPA_SP_REGNUM);
03058   set_gdbarch_fp0_regnum (gdbarch, HPPA_FP0_REGNUM);
03059   set_gdbarch_addr_bits_remove (gdbarch, hppa_addr_bits_remove);
03060   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
03061   set_gdbarch_read_pc (gdbarch, hppa_read_pc);
03062   set_gdbarch_write_pc (gdbarch, hppa_write_pc);
03063 
03064   /* Helper for function argument information.  */
03065   set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
03066 
03067   set_gdbarch_print_insn (gdbarch, print_insn_hppa);
03068 
03069   /* When a hardware watchpoint triggers, we'll move the inferior past
03070      it by removing all eventpoints; stepping past the instruction
03071      that caused the trigger; reinserting eventpoints; and checking
03072      whether any watched location changed.  */
03073   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
03074 
03075   /* Inferior function call methods.  */
03076   switch (tdep->bytes_per_address)
03077     {
03078     case 4:
03079       set_gdbarch_push_dummy_call (gdbarch, hppa32_push_dummy_call);
03080       set_gdbarch_frame_align (gdbarch, hppa32_frame_align);
03081       set_gdbarch_convert_from_func_ptr_addr
03082         (gdbarch, hppa32_convert_from_func_ptr_addr);
03083       break;
03084     case 8:
03085       set_gdbarch_push_dummy_call (gdbarch, hppa64_push_dummy_call);
03086       set_gdbarch_frame_align (gdbarch, hppa64_frame_align);
03087       break;
03088     default:
03089       internal_error (__FILE__, __LINE__, _("bad switch"));
03090     }
03091       
03092   /* Struct return methods.  */
03093   switch (tdep->bytes_per_address)
03094     {
03095     case 4:
03096       set_gdbarch_return_value (gdbarch, hppa32_return_value);
03097       break;
03098     case 8:
03099       set_gdbarch_return_value (gdbarch, hppa64_return_value);
03100       break;
03101     default:
03102       internal_error (__FILE__, __LINE__, _("bad switch"));
03103     }
03104       
03105   set_gdbarch_breakpoint_from_pc (gdbarch, hppa_breakpoint_from_pc);
03106   set_gdbarch_pseudo_register_read (gdbarch, hppa_pseudo_register_read);
03107 
03108   /* Frame unwind methods.  */
03109   set_gdbarch_dummy_id (gdbarch, hppa_dummy_id);
03110   set_gdbarch_unwind_pc (gdbarch, hppa_unwind_pc);
03111 
03112   /* Hook in ABI-specific overrides, if they have been registered.  */
03113   gdbarch_init_osabi (info, gdbarch);
03114 
03115   /* Hook in the default unwinders.  */
03116   frame_unwind_append_unwinder (gdbarch, &hppa_stub_frame_unwind);
03117   frame_unwind_append_unwinder (gdbarch, &hppa_frame_unwind);
03118   frame_unwind_append_unwinder (gdbarch, &hppa_fallback_frame_unwind);
03119 
03120   return gdbarch;
03121 }
03122 
03123 static void
03124 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
03125 {
03126   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
03127 
03128   fprintf_unfiltered (file, "bytes_per_address = %d\n", 
03129                       tdep->bytes_per_address);
03130   fprintf_unfiltered (file, "elf = %s\n", tdep->is_elf ? "yes" : "no");
03131 }
03132 
03133 /* Provide a prototype to silence -Wmissing-prototypes.  */
03134 extern initialize_file_ftype _initialize_hppa_tdep;
03135 
03136 void
03137 _initialize_hppa_tdep (void)
03138 {
03139   struct cmd_list_element *c;
03140 
03141   gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
03142 
03143   hppa_objfile_priv_data = register_objfile_data ();
03144 
03145   add_cmd ("unwind", class_maintenance, unwind_command,
03146            _("Print unwind table entry at given address."),
03147            &maintenanceprintlist);
03148 
03149   /* Debug this files internals.  */
03150   add_setshow_boolean_cmd ("hppa", class_maintenance, &hppa_debug, _("\
03151 Set whether hppa target specific debugging information should be displayed."),
03152                            _("\
03153 Show whether hppa target specific debugging information is displayed."), _("\
03154 This flag controls whether hppa target specific debugging information is\n\
03155 displayed.  This information is particularly useful for debugging frame\n\
03156 unwinding problems."),
03157                            NULL,
03158                            NULL, /* FIXME: i18n: hppa debug flag is %s.  */
03159                            &setdebuglist, &showdebuglist);
03160 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines