OSDN Git Service

d219429b2b77f4078f206be005d84739eaf6fe51
[pf3gnuchains/pf3gnuchains3x.git] / gdb / hppa-tdep.c
1 /* Target-dependent code for the HP PA architecture, for GDB.
2
3    Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4    1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5    Foundation, Inc.
6
7    Contributed by the Center for Software Science at the
8    University of Utah (pa-gdb-bugs@cs.utah.edu).
9
10    This file is part of GDB.
11
12    This program is free software; you can redistribute it and/or modify
13    it under the terms of the GNU General Public License as published by
14    the Free Software Foundation; either version 2 of the License, or
15    (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330,
25    Boston, MA 02111-1307, USA.  */
26
27 #include "defs.h"
28 #include "bfd.h"
29 #include "inferior.h"
30 #include "regcache.h"
31 #include "completer.h"
32 #include "osabi.h"
33 #include "gdb_assert.h"
34 #include "arch-utils.h"
35 /* For argument passing to the inferior */
36 #include "symtab.h"
37 #include "dis-asm.h"
38 #include "trad-frame.h"
39 #include "frame-unwind.h"
40 #include "frame-base.h"
41
42 #include "gdbcore.h"
43 #include "gdbcmd.h"
44 #include "objfiles.h"
45 #include "hppa-tdep.h"
46
47 static int hppa_debug = 0;
48
49 /* Some local constants.  */
50 static const int hppa32_num_regs = 128;
51 static const int hppa64_num_regs = 96;
52
53 /* hppa-specific object data -- unwind and solib info.
54    TODO/maybe: think about splitting this into two parts; the unwind data is 
55    common to all hppa targets, but is only used in this file; we can register 
56    that separately and make this static. The solib data is probably hpux-
57    specific, so we can create a separate extern objfile_data that is registered
58    by hppa-hpux-tdep.c and shared with pa64solib.c and somsolib.c.  */
59 const struct objfile_data *hppa_objfile_priv_data = NULL;
60
61 /* Get at various relevent fields of an instruction word. */
62 #define MASK_5 0x1f
63 #define MASK_11 0x7ff
64 #define MASK_14 0x3fff
65 #define MASK_21 0x1fffff
66
67 /* Sizes (in bytes) of the native unwind entries.  */
68 #define UNWIND_ENTRY_SIZE 16
69 #define STUB_UNWIND_ENTRY_SIZE 8
70
71 /* FIXME: brobecker 2002-11-07: We will likely be able to make the
72    following functions static, once we hppa is partially multiarched.  */
73 int hppa_pc_requires_run_before_use (CORE_ADDR pc);
74 int hppa_instruction_nullified (void);
75
76 /* Handle 32/64-bit struct return conventions.  */
77
78 static enum return_value_convention
79 hppa32_return_value (struct gdbarch *gdbarch,
80                      struct type *type, struct regcache *regcache,
81                      void *readbuf, const void *writebuf)
82 {
83   if (TYPE_LENGTH (type) <= 2 * 4)
84     {
85       /* The value always lives in the right hand end of the register
86          (or register pair)?  */
87       int b;
88       int reg = TYPE_CODE (type) == TYPE_CODE_FLT ? HPPA_FP4_REGNUM : 28;
89       int part = TYPE_LENGTH (type) % 4;
90       /* The left hand register contains only part of the value,
91          transfer that first so that the rest can be xfered as entire
92          4-byte registers.  */
93       if (part > 0)
94         {
95           if (readbuf != NULL)
96             regcache_cooked_read_part (regcache, reg, 4 - part,
97                                        part, readbuf);
98           if (writebuf != NULL)
99             regcache_cooked_write_part (regcache, reg, 4 - part,
100                                         part, writebuf);
101           reg++;
102         }
103       /* Now transfer the remaining register values.  */
104       for (b = part; b < TYPE_LENGTH (type); b += 4)
105         {
106           if (readbuf != NULL)
107             regcache_cooked_read (regcache, reg, (char *) readbuf + b);
108           if (writebuf != NULL)
109             regcache_cooked_write (regcache, reg, (const char *) writebuf + b);
110           reg++;
111         }
112       return RETURN_VALUE_REGISTER_CONVENTION;
113     }
114   else
115     return RETURN_VALUE_STRUCT_CONVENTION;
116 }
117
118 static enum return_value_convention
119 hppa64_return_value (struct gdbarch *gdbarch,
120                      struct type *type, struct regcache *regcache,
121                      void *readbuf, const void *writebuf)
122 {
123   /* RM: Floats are returned in FR4R, doubles in FR4.  Integral values
124      are in r28, padded on the left.  Aggregates less that 65 bits are
125      in r28, right padded.  Aggregates upto 128 bits are in r28 and
126      r29, right padded.  */ 
127   if (TYPE_CODE (type) == TYPE_CODE_FLT
128       && TYPE_LENGTH (type) <= 8)
129     {
130       /* Floats are right aligned?  */
131       int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type);
132       if (readbuf != NULL)
133         regcache_cooked_read_part (regcache, HPPA_FP4_REGNUM, offset,
134                                    TYPE_LENGTH (type), readbuf);
135       if (writebuf != NULL)
136         regcache_cooked_write_part (regcache, HPPA_FP4_REGNUM, offset,
137                                     TYPE_LENGTH (type), writebuf);
138       return RETURN_VALUE_REGISTER_CONVENTION;
139     }
140   else if (TYPE_LENGTH (type) <= 8 && is_integral_type (type))
141     {
142       /* Integrals are right aligned.  */
143       int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type);
144       if (readbuf != NULL)
145         regcache_cooked_read_part (regcache, 28, offset,
146                                    TYPE_LENGTH (type), readbuf);
147       if (writebuf != NULL)
148         regcache_cooked_write_part (regcache, 28, offset,
149                                     TYPE_LENGTH (type), writebuf);
150       return RETURN_VALUE_REGISTER_CONVENTION;
151     }
152   else if (TYPE_LENGTH (type) <= 2 * 8)
153     {
154       /* Composite values are left aligned.  */
155       int b;
156       for (b = 0; b < TYPE_LENGTH (type); b += 8)
157         {
158           int part = min (8, TYPE_LENGTH (type) - b);
159           if (readbuf != NULL)
160             regcache_cooked_read_part (regcache, 28 + b / 8, 0, part,
161                                        (char *) readbuf + b);
162           if (writebuf != NULL)
163             regcache_cooked_write_part (regcache, 28 + b / 8, 0, part,
164                                         (const char *) writebuf + b);
165         }
166       return RETURN_VALUE_REGISTER_CONVENTION;
167     }
168   else
169     return RETURN_VALUE_STRUCT_CONVENTION;
170 }
171
172 /* Routines to extract various sized constants out of hppa 
173    instructions. */
174
175 /* This assumes that no garbage lies outside of the lower bits of 
176    value. */
177
178 int
179 hppa_sign_extend (unsigned val, unsigned bits)
180 {
181   return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
182 }
183
184 /* For many immediate values the sign bit is the low bit! */
185
186 int
187 hppa_low_hppa_sign_extend (unsigned val, unsigned bits)
188 {
189   return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
190 }
191
192 /* Extract the bits at positions between FROM and TO, using HP's numbering
193    (MSB = 0). */
194
195 int
196 hppa_get_field (unsigned word, int from, int to)
197 {
198   return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
199 }
200
201 /* extract the immediate field from a ld{bhw}s instruction */
202
203 int
204 hppa_extract_5_load (unsigned word)
205 {
206   return hppa_low_hppa_sign_extend (word >> 16 & MASK_5, 5);
207 }
208
209 /* extract the immediate field from a break instruction */
210
211 unsigned
212 hppa_extract_5r_store (unsigned word)
213 {
214   return (word & MASK_5);
215 }
216
217 /* extract the immediate field from a {sr}sm instruction */
218
219 unsigned
220 hppa_extract_5R_store (unsigned word)
221 {
222   return (word >> 16 & MASK_5);
223 }
224
225 /* extract a 14 bit immediate field */
226
227 int
228 hppa_extract_14 (unsigned word)
229 {
230   return hppa_low_hppa_sign_extend (word & MASK_14, 14);
231 }
232
233 /* extract a 21 bit constant */
234
235 int
236 hppa_extract_21 (unsigned word)
237 {
238   int val;
239
240   word &= MASK_21;
241   word <<= 11;
242   val = hppa_get_field (word, 20, 20);
243   val <<= 11;
244   val |= hppa_get_field (word, 9, 19);
245   val <<= 2;
246   val |= hppa_get_field (word, 5, 6);
247   val <<= 5;
248   val |= hppa_get_field (word, 0, 4);
249   val <<= 2;
250   val |= hppa_get_field (word, 7, 8);
251   return hppa_sign_extend (val, 21) << 11;
252 }
253
254 /* extract a 17 bit constant from branch instructions, returning the
255    19 bit signed value. */
256
257 int
258 hppa_extract_17 (unsigned word)
259 {
260   return hppa_sign_extend (hppa_get_field (word, 19, 28) |
261                       hppa_get_field (word, 29, 29) << 10 |
262                       hppa_get_field (word, 11, 15) << 11 |
263                       (word & 0x1) << 16, 17) << 2;
264 }
265 \f
266
267 /* Compare the start address for two unwind entries returning 1 if 
268    the first address is larger than the second, -1 if the second is
269    larger than the first, and zero if they are equal.  */
270
271 static int
272 compare_unwind_entries (const void *arg1, const void *arg2)
273 {
274   const struct unwind_table_entry *a = arg1;
275   const struct unwind_table_entry *b = arg2;
276
277   if (a->region_start > b->region_start)
278     return 1;
279   else if (a->region_start < b->region_start)
280     return -1;
281   else
282     return 0;
283 }
284
285 static void
286 record_text_segment_lowaddr (bfd *abfd, asection *section, void *data)
287 {
288   if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
289        == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
290     {
291       bfd_vma value = section->vma - section->filepos;
292       CORE_ADDR *low_text_segment_address = (CORE_ADDR *)data;
293
294       if (value < *low_text_segment_address)
295           *low_text_segment_address = value;
296     }
297 }
298
299 static void
300 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
301                      asection *section, unsigned int entries, unsigned int size,
302                      CORE_ADDR text_offset)
303 {
304   /* We will read the unwind entries into temporary memory, then
305      fill in the actual unwind table.  */
306
307   if (size > 0)
308     {
309       unsigned long tmp;
310       unsigned i;
311       char *buf = alloca (size);
312       CORE_ADDR low_text_segment_address;
313
314       /* For ELF targets, then unwinds are supposed to
315          be segment relative offsets instead of absolute addresses. 
316
317          Note that when loading a shared library (text_offset != 0) the
318          unwinds are already relative to the text_offset that will be
319          passed in.  */
320       if (gdbarch_tdep (current_gdbarch)->is_elf && text_offset == 0)
321         {
322           low_text_segment_address = -1;
323
324           bfd_map_over_sections (objfile->obfd,
325                                  record_text_segment_lowaddr, 
326                                  &low_text_segment_address);
327
328           text_offset = low_text_segment_address;
329         }
330
331       bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
332
333       /* Now internalize the information being careful to handle host/target
334          endian issues.  */
335       for (i = 0; i < entries; i++)
336         {
337           table[i].region_start = bfd_get_32 (objfile->obfd,
338                                               (bfd_byte *) buf);
339           table[i].region_start += text_offset;
340           buf += 4;
341           table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
342           table[i].region_end += text_offset;
343           buf += 4;
344           tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
345           buf += 4;
346           table[i].Cannot_unwind = (tmp >> 31) & 0x1;
347           table[i].Millicode = (tmp >> 30) & 0x1;
348           table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
349           table[i].Region_description = (tmp >> 27) & 0x3;
350           table[i].reserved1 = (tmp >> 26) & 0x1;
351           table[i].Entry_SR = (tmp >> 25) & 0x1;
352           table[i].Entry_FR = (tmp >> 21) & 0xf;
353           table[i].Entry_GR = (tmp >> 16) & 0x1f;
354           table[i].Args_stored = (tmp >> 15) & 0x1;
355           table[i].Variable_Frame = (tmp >> 14) & 0x1;
356           table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
357           table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
358           table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
359           table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
360           table[i].Ada_Region = (tmp >> 9) & 0x1;
361           table[i].cxx_info = (tmp >> 8) & 0x1;
362           table[i].cxx_try_catch = (tmp >> 7) & 0x1;
363           table[i].sched_entry_seq = (tmp >> 6) & 0x1;
364           table[i].reserved2 = (tmp >> 5) & 0x1;
365           table[i].Save_SP = (tmp >> 4) & 0x1;
366           table[i].Save_RP = (tmp >> 3) & 0x1;
367           table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
368           table[i].extn_ptr_defined = (tmp >> 1) & 0x1;
369           table[i].Cleanup_defined = tmp & 0x1;
370           tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
371           buf += 4;
372           table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
373           table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
374           table[i].Large_frame = (tmp >> 29) & 0x1;
375           table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1;
376           table[i].reserved4 = (tmp >> 27) & 0x1;
377           table[i].Total_frame_size = tmp & 0x7ffffff;
378
379           /* Stub unwinds are handled elsewhere. */
380           table[i].stub_unwind.stub_type = 0;
381           table[i].stub_unwind.padding = 0;
382         }
383     }
384 }
385
386 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
387    the object file.  This info is used mainly by find_unwind_entry() to find
388    out the stack frame size and frame pointer used by procedures.  We put
389    everything on the psymbol obstack in the objfile so that it automatically
390    gets freed when the objfile is destroyed.  */
391
392 static void
393 read_unwind_info (struct objfile *objfile)
394 {
395   asection *unwind_sec, *stub_unwind_sec;
396   unsigned unwind_size, stub_unwind_size, total_size;
397   unsigned index, unwind_entries;
398   unsigned stub_entries, total_entries;
399   CORE_ADDR text_offset;
400   struct hppa_unwind_info *ui;
401   struct hppa_objfile_private *obj_private;
402
403   text_offset = ANOFFSET (objfile->section_offsets, 0);
404   ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
405                                            sizeof (struct hppa_unwind_info));
406
407   ui->table = NULL;
408   ui->cache = NULL;
409   ui->last = -1;
410
411   /* For reasons unknown the HP PA64 tools generate multiple unwinder
412      sections in a single executable.  So we just iterate over every
413      section in the BFD looking for unwinder sections intead of trying
414      to do a lookup with bfd_get_section_by_name. 
415
416      First determine the total size of the unwind tables so that we
417      can allocate memory in a nice big hunk.  */
418   total_entries = 0;
419   for (unwind_sec = objfile->obfd->sections;
420        unwind_sec;
421        unwind_sec = unwind_sec->next)
422     {
423       if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
424           || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
425         {
426           unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
427           unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
428
429           total_entries += unwind_entries;
430         }
431     }
432
433   /* Now compute the size of the stub unwinds.  Note the ELF tools do not
434      use stub unwinds at the curren time.  */
435   stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
436
437   if (stub_unwind_sec)
438     {
439       stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
440       stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
441     }
442   else
443     {
444       stub_unwind_size = 0;
445       stub_entries = 0;
446     }
447
448   /* Compute total number of unwind entries and their total size.  */
449   total_entries += stub_entries;
450   total_size = total_entries * sizeof (struct unwind_table_entry);
451
452   /* Allocate memory for the unwind table.  */
453   ui->table = (struct unwind_table_entry *)
454     obstack_alloc (&objfile->objfile_obstack, total_size);
455   ui->last = total_entries - 1;
456
457   /* Now read in each unwind section and internalize the standard unwind
458      entries.  */
459   index = 0;
460   for (unwind_sec = objfile->obfd->sections;
461        unwind_sec;
462        unwind_sec = unwind_sec->next)
463     {
464       if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
465           || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
466         {
467           unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
468           unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
469
470           internalize_unwinds (objfile, &ui->table[index], unwind_sec,
471                                unwind_entries, unwind_size, text_offset);
472           index += unwind_entries;
473         }
474     }
475
476   /* Now read in and internalize the stub unwind entries.  */
477   if (stub_unwind_size > 0)
478     {
479       unsigned int i;
480       char *buf = alloca (stub_unwind_size);
481
482       /* Read in the stub unwind entries.  */
483       bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
484                                 0, stub_unwind_size);
485
486       /* Now convert them into regular unwind entries.  */
487       for (i = 0; i < stub_entries; i++, index++)
488         {
489           /* Clear out the next unwind entry.  */
490           memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
491
492           /* Convert offset & size into region_start and region_end.  
493              Stuff away the stub type into "reserved" fields.  */
494           ui->table[index].region_start = bfd_get_32 (objfile->obfd,
495                                                       (bfd_byte *) buf);
496           ui->table[index].region_start += text_offset;
497           buf += 4;
498           ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
499                                                           (bfd_byte *) buf);
500           buf += 2;
501           ui->table[index].region_end
502             = ui->table[index].region_start + 4 *
503             (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
504           buf += 2;
505         }
506
507     }
508
509   /* Unwind table needs to be kept sorted.  */
510   qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
511          compare_unwind_entries);
512
513   /* Keep a pointer to the unwind information.  */
514   obj_private = (struct hppa_objfile_private *) 
515                 objfile_data (objfile, hppa_objfile_priv_data);
516   if (obj_private == NULL)
517     {
518       obj_private = (struct hppa_objfile_private *)
519         obstack_alloc (&objfile->objfile_obstack, 
520                        sizeof (struct hppa_objfile_private));
521       set_objfile_data (objfile, hppa_objfile_priv_data, obj_private);
522       obj_private->unwind_info = NULL;
523       obj_private->so_info = NULL;
524       obj_private->dp = 0;
525     }
526   obj_private->unwind_info = ui;
527 }
528
529 /* Lookup the unwind (stack backtrace) info for the given PC.  We search all
530    of the objfiles seeking the unwind table entry for this PC.  Each objfile
531    contains a sorted list of struct unwind_table_entry.  Since we do a binary
532    search of the unwind tables, we depend upon them to be sorted.  */
533
534 struct unwind_table_entry *
535 find_unwind_entry (CORE_ADDR pc)
536 {
537   int first, middle, last;
538   struct objfile *objfile;
539   struct hppa_objfile_private *priv;
540
541   if (hppa_debug)
542     fprintf_unfiltered (gdb_stdlog, "{ find_unwind_entry 0x%s -> ",
543                         paddr_nz (pc));
544
545   /* A function at address 0?  Not in HP-UX! */
546   if (pc == (CORE_ADDR) 0)
547     {
548       if (hppa_debug)
549         fprintf_unfiltered (gdb_stdlog, "NULL }\n");
550       return NULL;
551     }
552
553   ALL_OBJFILES (objfile)
554   {
555     struct hppa_unwind_info *ui;
556     ui = NULL;
557     priv = objfile_data (objfile, hppa_objfile_priv_data);
558     if (priv)
559       ui = ((struct hppa_objfile_private *) priv)->unwind_info;
560
561     if (!ui)
562       {
563         read_unwind_info (objfile);
564         priv = objfile_data (objfile, hppa_objfile_priv_data);
565         if (priv == NULL)
566           error ("Internal error reading unwind information.");
567         ui = ((struct hppa_objfile_private *) priv)->unwind_info;
568       }
569
570     /* First, check the cache */
571
572     if (ui->cache
573         && pc >= ui->cache->region_start
574         && pc <= ui->cache->region_end)
575       {
576         if (hppa_debug)
577           fprintf_unfiltered (gdb_stdlog, "0x%s (cached) }\n",
578             paddr_nz ((CORE_ADDR) ui->cache));
579         return ui->cache;
580       }
581
582     /* Not in the cache, do a binary search */
583
584     first = 0;
585     last = ui->last;
586
587     while (first <= last)
588       {
589         middle = (first + last) / 2;
590         if (pc >= ui->table[middle].region_start
591             && pc <= ui->table[middle].region_end)
592           {
593             ui->cache = &ui->table[middle];
594             if (hppa_debug)
595               fprintf_unfiltered (gdb_stdlog, "0x%s }\n",
596                 paddr_nz ((CORE_ADDR) ui->cache));
597             return &ui->table[middle];
598           }
599
600         if (pc < ui->table[middle].region_start)
601           last = middle - 1;
602         else
603           first = middle + 1;
604       }
605   }                             /* ALL_OBJFILES() */
606
607   if (hppa_debug)
608     fprintf_unfiltered (gdb_stdlog, "NULL (not found) }\n");
609
610   return NULL;
611 }
612
613 static const unsigned char *
614 hppa_breakpoint_from_pc (CORE_ADDR *pc, int *len)
615 {
616   static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
617   (*len) = sizeof (breakpoint);
618   return breakpoint;
619 }
620
621 /* Return the name of a register.  */
622
623 const char *
624 hppa32_register_name (int i)
625 {
626   static char *names[] = {
627     "flags",  "r1",      "rp",     "r3",
628     "r4",     "r5",      "r6",     "r7",
629     "r8",     "r9",      "r10",    "r11",
630     "r12",    "r13",     "r14",    "r15",
631     "r16",    "r17",     "r18",    "r19",
632     "r20",    "r21",     "r22",    "r23",
633     "r24",    "r25",     "r26",    "dp",
634     "ret0",   "ret1",    "sp",     "r31",
635     "sar",    "pcoqh",   "pcsqh",  "pcoqt",
636     "pcsqt",  "eiem",    "iir",    "isr",
637     "ior",    "ipsw",    "goto",   "sr4",
638     "sr0",    "sr1",     "sr2",    "sr3",
639     "sr5",    "sr6",     "sr7",    "cr0",
640     "cr8",    "cr9",     "ccr",    "cr12",
641     "cr13",   "cr24",    "cr25",   "cr26",
642     "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
643     "fpsr",    "fpe1",   "fpe2",   "fpe3",
644     "fpe4",   "fpe5",    "fpe6",   "fpe7",
645     "fr4",     "fr4R",   "fr5",    "fr5R",
646     "fr6",    "fr6R",    "fr7",    "fr7R",
647     "fr8",     "fr8R",   "fr9",    "fr9R",
648     "fr10",   "fr10R",   "fr11",   "fr11R",
649     "fr12",    "fr12R",  "fr13",   "fr13R",
650     "fr14",   "fr14R",   "fr15",   "fr15R",
651     "fr16",    "fr16R",  "fr17",   "fr17R",
652     "fr18",   "fr18R",   "fr19",   "fr19R",
653     "fr20",    "fr20R",  "fr21",   "fr21R",
654     "fr22",   "fr22R",   "fr23",   "fr23R",
655     "fr24",    "fr24R",  "fr25",   "fr25R",
656     "fr26",   "fr26R",   "fr27",   "fr27R",
657     "fr28",    "fr28R",  "fr29",   "fr29R",
658     "fr30",   "fr30R",   "fr31",   "fr31R"
659   };
660   if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
661     return NULL;
662   else
663     return names[i];
664 }
665
666 const char *
667 hppa64_register_name (int i)
668 {
669   static char *names[] = {
670     "flags",  "r1",      "rp",     "r3",
671     "r4",     "r5",      "r6",     "r7",
672     "r8",     "r9",      "r10",    "r11",
673     "r12",    "r13",     "r14",    "r15",
674     "r16",    "r17",     "r18",    "r19",
675     "r20",    "r21",     "r22",    "r23",
676     "r24",    "r25",     "r26",    "dp",
677     "ret0",   "ret1",    "sp",     "r31",
678     "sar",    "pcoqh",   "pcsqh",  "pcoqt",
679     "pcsqt",  "eiem",    "iir",    "isr",
680     "ior",    "ipsw",    "goto",   "sr4",
681     "sr0",    "sr1",     "sr2",    "sr3",
682     "sr5",    "sr6",     "sr7",    "cr0",
683     "cr8",    "cr9",     "ccr",    "cr12",
684     "cr13",   "cr24",    "cr25",   "cr26",
685     "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
686     "fpsr",    "fpe1",   "fpe2",   "fpe3",
687     "fr4",    "fr5",     "fr6",    "fr7",
688     "fr8",     "fr9",    "fr10",   "fr11",
689     "fr12",   "fr13",    "fr14",   "fr15",
690     "fr16",    "fr17",   "fr18",   "fr19",
691     "fr20",   "fr21",    "fr22",   "fr23",
692     "fr24",    "fr25",   "fr26",   "fr27",
693     "fr28",  "fr29",    "fr30",   "fr31"
694   };
695   if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
696     return NULL;
697   else
698     return names[i];
699 }
700
701 /* This function pushes a stack frame with arguments as part of the
702    inferior function calling mechanism.
703
704    This is the version of the function for the 32-bit PA machines, in
705    which later arguments appear at lower addresses.  (The stack always
706    grows towards higher addresses.)
707
708    We simply allocate the appropriate amount of stack space and put
709    arguments into their proper slots.  */
710    
711 CORE_ADDR
712 hppa32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
713                         struct regcache *regcache, CORE_ADDR bp_addr,
714                         int nargs, struct value **args, CORE_ADDR sp,
715                         int struct_return, CORE_ADDR struct_addr)
716 {
717   /* Stack base address at which any pass-by-reference parameters are
718      stored.  */
719   CORE_ADDR struct_end = 0;
720   /* Stack base address at which the first parameter is stored.  */
721   CORE_ADDR param_end = 0;
722
723   /* The inner most end of the stack after all the parameters have
724      been pushed.  */
725   CORE_ADDR new_sp = 0;
726
727   /* Two passes.  First pass computes the location of everything,
728      second pass writes the bytes out.  */
729   int write_pass;
730   for (write_pass = 0; write_pass < 2; write_pass++)
731     {
732       CORE_ADDR struct_ptr = 0;
733       /* The first parameter goes into sp-36, each stack slot is 4-bytes.  
734          struct_ptr is adjusted for each argument below, so the first
735          argument will end up at sp-36.  */
736       CORE_ADDR param_ptr = 32;
737       int i;
738       int small_struct = 0;
739
740       for (i = 0; i < nargs; i++)
741         {
742           struct value *arg = args[i];
743           struct type *type = check_typedef (VALUE_TYPE (arg));
744           /* The corresponding parameter that is pushed onto the
745              stack, and [possibly] passed in a register.  */
746           char param_val[8];
747           int param_len;
748           memset (param_val, 0, sizeof param_val);
749           if (TYPE_LENGTH (type) > 8)
750             {
751               /* Large parameter, pass by reference.  Store the value
752                  in "struct" area and then pass its address.  */
753               param_len = 4;
754               struct_ptr += align_up (TYPE_LENGTH (type), 8);
755               if (write_pass)
756                 write_memory (struct_end - struct_ptr, VALUE_CONTENTS (arg),
757                               TYPE_LENGTH (type));
758               store_unsigned_integer (param_val, 4, struct_end - struct_ptr);
759             }
760           else if (TYPE_CODE (type) == TYPE_CODE_INT
761                    || TYPE_CODE (type) == TYPE_CODE_ENUM)
762             {
763               /* Integer value store, right aligned.  "unpack_long"
764                  takes care of any sign-extension problems.  */
765               param_len = align_up (TYPE_LENGTH (type), 4);
766               store_unsigned_integer (param_val, param_len,
767                                       unpack_long (type,
768                                                    VALUE_CONTENTS (arg)));
769             }
770           else if (TYPE_CODE (type) == TYPE_CODE_FLT)
771             {
772               /* Floating point value store, right aligned.  */
773               param_len = align_up (TYPE_LENGTH (type), 4);
774               memcpy (param_val, VALUE_CONTENTS (arg), param_len);
775             }
776           else
777             {
778               param_len = align_up (TYPE_LENGTH (type), 4);
779
780               /* Small struct value are stored right-aligned.  */
781               memcpy (param_val + param_len - TYPE_LENGTH (type),
782                       VALUE_CONTENTS (arg), TYPE_LENGTH (type));
783
784               /* Structures of size 5, 6 and 7 bytes are special in that
785                  the higher-ordered word is stored in the lower-ordered
786                  argument, and even though it is a 8-byte quantity the
787                  registers need not be 8-byte aligned.  */
788               if (param_len > 4 && param_len < 8)
789                 small_struct = 1;
790             }
791
792           param_ptr += param_len;
793           if (param_len == 8 && !small_struct)
794             param_ptr = align_up (param_ptr, 8);
795
796           /* First 4 non-FP arguments are passed in gr26-gr23.
797              First 4 32-bit FP arguments are passed in fr4L-fr7L.
798              First 2 64-bit FP arguments are passed in fr5 and fr7.
799
800              The rest go on the stack, starting at sp-36, towards lower
801              addresses.  8-byte arguments must be aligned to a 8-byte
802              stack boundary.  */
803           if (write_pass)
804             {
805               write_memory (param_end - param_ptr, param_val, param_len);
806
807               /* There are some cases when we don't know the type
808                  expected by the callee (e.g. for variadic functions), so 
809                  pass the parameters in both general and fp regs.  */
810               if (param_ptr <= 48)
811                 {
812                   int grreg = 26 - (param_ptr - 36) / 4;
813                   int fpLreg = 72 + (param_ptr - 36) / 4 * 2;
814                   int fpreg = 74 + (param_ptr - 32) / 8 * 4;
815
816                   regcache_cooked_write (regcache, grreg, param_val);
817                   regcache_cooked_write (regcache, fpLreg, param_val);
818
819                   if (param_len > 4)
820                     {
821                       regcache_cooked_write (regcache, grreg + 1, 
822                                              param_val + 4);
823
824                       regcache_cooked_write (regcache, fpreg, param_val);
825                       regcache_cooked_write (regcache, fpreg + 1, 
826                                              param_val + 4);
827                     }
828                 }
829             }
830         }
831
832       /* Update the various stack pointers.  */
833       if (!write_pass)
834         {
835           struct_end = sp + align_up (struct_ptr, 64);
836           /* PARAM_PTR already accounts for all the arguments passed
837              by the user.  However, the ABI mandates minimum stack
838              space allocations for outgoing arguments.  The ABI also
839              mandates minimum stack alignments which we must
840              preserve.  */
841           param_end = struct_end + align_up (param_ptr, 64);
842         }
843     }
844
845   /* If a structure has to be returned, set up register 28 to hold its
846      address */
847   if (struct_return)
848     write_register (28, struct_addr);
849
850   /* Set the return address.  */
851   regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
852
853   /* Update the Stack Pointer.  */
854   regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end);
855
856   return param_end;
857 }
858
859 /* This function pushes a stack frame with arguments as part of the
860    inferior function calling mechanism.
861
862    This is the version for the PA64, in which later arguments appear
863    at higher addresses.  (The stack always grows towards higher
864    addresses.)
865
866    We simply allocate the appropriate amount of stack space and put
867    arguments into their proper slots.
868
869    This ABI also requires that the caller provide an argument pointer
870    to the callee, so we do that too.  */
871    
872 CORE_ADDR
873 hppa64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
874                         struct regcache *regcache, CORE_ADDR bp_addr,
875                         int nargs, struct value **args, CORE_ADDR sp,
876                         int struct_return, CORE_ADDR struct_addr)
877 {
878   /* NOTE: cagney/2004-02-27: This is a guess - its implemented by
879      reverse engineering testsuite failures.  */
880
881   /* Stack base address at which any pass-by-reference parameters are
882      stored.  */
883   CORE_ADDR struct_end = 0;
884   /* Stack base address at which the first parameter is stored.  */
885   CORE_ADDR param_end = 0;
886
887   /* The inner most end of the stack after all the parameters have
888      been pushed.  */
889   CORE_ADDR new_sp = 0;
890
891   /* Two passes.  First pass computes the location of everything,
892      second pass writes the bytes out.  */
893   int write_pass;
894   for (write_pass = 0; write_pass < 2; write_pass++)
895     {
896       CORE_ADDR struct_ptr = 0;
897       CORE_ADDR param_ptr = 0;
898       int i;
899       for (i = 0; i < nargs; i++)
900         {
901           struct value *arg = args[i];
902           struct type *type = check_typedef (VALUE_TYPE (arg));
903           if ((TYPE_CODE (type) == TYPE_CODE_INT
904                || TYPE_CODE (type) == TYPE_CODE_ENUM)
905               && TYPE_LENGTH (type) <= 8)
906             {
907               /* Integer value store, right aligned.  "unpack_long"
908                  takes care of any sign-extension problems.  */
909               param_ptr += 8;
910               if (write_pass)
911                 {
912                   ULONGEST val = unpack_long (type, VALUE_CONTENTS (arg));
913                   int reg = 27 - param_ptr / 8;
914                   write_memory_unsigned_integer (param_end - param_ptr,
915                                                  val, 8);
916                   if (reg >= 19)
917                     regcache_cooked_write_unsigned (regcache, reg, val);
918                 }
919             }
920           else
921             {
922               /* Small struct value, store left aligned?  */
923               int reg;
924               if (TYPE_LENGTH (type) > 8)
925                 {
926                   param_ptr = align_up (param_ptr, 16);
927                   reg = 26 - param_ptr / 8;
928                   param_ptr += align_up (TYPE_LENGTH (type), 16);
929                 }
930               else
931                 {
932                   param_ptr = align_up (param_ptr, 8);
933                   reg = 26 - param_ptr / 8;
934                   param_ptr += align_up (TYPE_LENGTH (type), 8);
935                 }
936               if (write_pass)
937                 {
938                   int byte;
939                   write_memory (param_end - param_ptr, VALUE_CONTENTS (arg),
940                                 TYPE_LENGTH (type));
941                   for (byte = 0; byte < TYPE_LENGTH (type); byte += 8)
942                     {
943                       if (reg >= 19)
944                         {
945                           int len = min (8, TYPE_LENGTH (type) - byte);
946                           regcache_cooked_write_part (regcache, reg, 0, len,
947                                                       VALUE_CONTENTS (arg) + byte);
948                         }
949                       reg--;
950                     }
951                 }
952             }
953         }
954       /* Update the various stack pointers.  */
955       if (!write_pass)
956         {
957           struct_end = sp + struct_ptr;
958           /* PARAM_PTR already accounts for all the arguments passed
959              by the user.  However, the ABI mandates minimum stack
960              space allocations for outgoing arguments.  The ABI also
961              mandates minimum stack alignments which we must
962              preserve.  */
963           param_end = struct_end + max (align_up (param_ptr, 16), 64);
964         }
965     }
966
967   /* If a structure has to be returned, set up register 28 to hold its
968      address */
969   if (struct_return)
970     write_register (28, struct_addr);
971
972   /* Set the return address.  */
973   regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
974
975   /* Update the Stack Pointer.  */
976   regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end + 64);
977
978   /* The stack will have 32 bytes of additional space for a frame marker.  */
979   return param_end + 64;
980 }
981
982 static CORE_ADDR
983 hppa32_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
984 {
985   /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_
986      and not _bit_)!  */
987   return align_up (addr, 64);
988 }
989
990 /* Force all frames to 16-byte alignment.  Better safe than sorry.  */
991
992 static CORE_ADDR
993 hppa64_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
994 {
995   /* Just always 16-byte align.  */
996   return align_up (addr, 16);
997 }
998
999
1000 /* Get the PC from %r31 if currently in a syscall.  Also mask out privilege
1001    bits.  */
1002
1003 static CORE_ADDR
1004 hppa_target_read_pc (ptid_t ptid)
1005 {
1006   int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1007
1008   /* The following test does not belong here.  It is OS-specific, and belongs
1009      in native code.  */
1010   /* Test SS_INSYSCALL */
1011   if (flags & 2)
1012     return read_register_pid (31, ptid) & ~0x3;
1013
1014   return read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid) & ~0x3;
1015 }
1016
1017 /* Write out the PC.  If currently in a syscall, then also write the new
1018    PC value into %r31.  */
1019
1020 static void
1021 hppa_target_write_pc (CORE_ADDR v, ptid_t ptid)
1022 {
1023   int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1024
1025   /* The following test does not belong here.  It is OS-specific, and belongs
1026      in native code.  */
1027   /* If in a syscall, then set %r31.  Also make sure to get the 
1028      privilege bits set correctly.  */
1029   /* Test SS_INSYSCALL */
1030   if (flags & 2)
1031     write_register_pid (31, v | 0x3, ptid);
1032
1033   write_register_pid (HPPA_PCOQ_HEAD_REGNUM, v, ptid);
1034   write_register_pid (HPPA_PCOQ_TAIL_REGNUM, v + 4, ptid);
1035 }
1036
1037 /* return the alignment of a type in bytes. Structures have the maximum
1038    alignment required by their fields. */
1039
1040 static int
1041 hppa_alignof (struct type *type)
1042 {
1043   int max_align, align, i;
1044   CHECK_TYPEDEF (type);
1045   switch (TYPE_CODE (type))
1046     {
1047     case TYPE_CODE_PTR:
1048     case TYPE_CODE_INT:
1049     case TYPE_CODE_FLT:
1050       return TYPE_LENGTH (type);
1051     case TYPE_CODE_ARRAY:
1052       return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
1053     case TYPE_CODE_STRUCT:
1054     case TYPE_CODE_UNION:
1055       max_align = 1;
1056       for (i = 0; i < TYPE_NFIELDS (type); i++)
1057         {
1058           /* Bit fields have no real alignment. */
1059           /* if (!TYPE_FIELD_BITPOS (type, i)) */
1060           if (!TYPE_FIELD_BITSIZE (type, i))    /* elz: this should be bitsize */
1061             {
1062               align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
1063               max_align = max (max_align, align);
1064             }
1065         }
1066       return max_align;
1067     default:
1068       return 4;
1069     }
1070 }
1071
1072 /* For the given instruction (INST), return any adjustment it makes
1073    to the stack pointer or zero for no adjustment. 
1074
1075    This only handles instructions commonly found in prologues.  */
1076
1077 static int
1078 prologue_inst_adjust_sp (unsigned long inst)
1079 {
1080   /* This must persist across calls.  */
1081   static int save_high21;
1082
1083   /* The most common way to perform a stack adjustment ldo X(sp),sp */
1084   if ((inst & 0xffffc000) == 0x37de0000)
1085     return hppa_extract_14 (inst);
1086
1087   /* stwm X,D(sp) */
1088   if ((inst & 0xffe00000) == 0x6fc00000)
1089     return hppa_extract_14 (inst);
1090
1091   /* std,ma X,D(sp) */
1092   if ((inst & 0xffe00008) == 0x73c00008)
1093     return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
1094
1095   /* addil high21,%r1; ldo low11,(%r1),%r30)
1096      save high bits in save_high21 for later use.  */
1097   if ((inst & 0xffe00000) == 0x28200000)
1098     {
1099       save_high21 = hppa_extract_21 (inst);
1100       return 0;
1101     }
1102
1103   if ((inst & 0xffff0000) == 0x343e0000)
1104     return save_high21 + hppa_extract_14 (inst);
1105
1106   /* fstws as used by the HP compilers.  */
1107   if ((inst & 0xffffffe0) == 0x2fd01220)
1108     return hppa_extract_5_load (inst);
1109
1110   /* No adjustment.  */
1111   return 0;
1112 }
1113
1114 /* Return nonzero if INST is a branch of some kind, else return zero.  */
1115
1116 static int
1117 is_branch (unsigned long inst)
1118 {
1119   switch (inst >> 26)
1120     {
1121     case 0x20:
1122     case 0x21:
1123     case 0x22:
1124     case 0x23:
1125     case 0x27:
1126     case 0x28:
1127     case 0x29:
1128     case 0x2a:
1129     case 0x2b:
1130     case 0x2f:
1131     case 0x30:
1132     case 0x31:
1133     case 0x32:
1134     case 0x33:
1135     case 0x38:
1136     case 0x39:
1137     case 0x3a:
1138     case 0x3b:
1139       return 1;
1140
1141     default:
1142       return 0;
1143     }
1144 }
1145
1146 /* Return the register number for a GR which is saved by INST or
1147    zero it INST does not save a GR.  */
1148
1149 static int
1150 inst_saves_gr (unsigned long inst)
1151 {
1152   /* Does it look like a stw?  */
1153   if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
1154       || (inst >> 26) == 0x1f
1155       || ((inst >> 26) == 0x1f
1156           && ((inst >> 6) == 0xa)))
1157     return hppa_extract_5R_store (inst);
1158
1159   /* Does it look like a std?  */
1160   if ((inst >> 26) == 0x1c
1161       || ((inst >> 26) == 0x03
1162           && ((inst >> 6) & 0xf) == 0xb))
1163     return hppa_extract_5R_store (inst);
1164
1165   /* Does it look like a stwm?  GCC & HPC may use this in prologues. */
1166   if ((inst >> 26) == 0x1b)
1167     return hppa_extract_5R_store (inst);
1168
1169   /* Does it look like sth or stb?  HPC versions 9.0 and later use these
1170      too.  */
1171   if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
1172       || ((inst >> 26) == 0x3
1173           && (((inst >> 6) & 0xf) == 0x8
1174               || (inst >> 6) & 0xf) == 0x9))
1175     return hppa_extract_5R_store (inst);
1176
1177   return 0;
1178 }
1179
1180 /* Return the register number for a FR which is saved by INST or
1181    zero it INST does not save a FR.
1182
1183    Note we only care about full 64bit register stores (that's the only
1184    kind of stores the prologue will use).
1185
1186    FIXME: What about argument stores with the HP compiler in ANSI mode? */
1187
1188 static int
1189 inst_saves_fr (unsigned long inst)
1190 {
1191   /* is this an FSTD ? */
1192   if ((inst & 0xfc00dfc0) == 0x2c001200)
1193     return hppa_extract_5r_store (inst);
1194   if ((inst & 0xfc000002) == 0x70000002)
1195     return hppa_extract_5R_store (inst);
1196   /* is this an FSTW ? */
1197   if ((inst & 0xfc00df80) == 0x24001200)
1198     return hppa_extract_5r_store (inst);
1199   if ((inst & 0xfc000002) == 0x7c000000)
1200     return hppa_extract_5R_store (inst);
1201   return 0;
1202 }
1203
1204 /* Advance PC across any function entry prologue instructions
1205    to reach some "real" code. 
1206
1207    Use information in the unwind table to determine what exactly should
1208    be in the prologue.  */
1209
1210
1211 CORE_ADDR
1212 skip_prologue_hard_way (CORE_ADDR pc)
1213 {
1214   char buf[4];
1215   CORE_ADDR orig_pc = pc;
1216   unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
1217   unsigned long args_stored, status, i, restart_gr, restart_fr;
1218   struct unwind_table_entry *u;
1219
1220   restart_gr = 0;
1221   restart_fr = 0;
1222
1223 restart:
1224   u = find_unwind_entry (pc);
1225   if (!u)
1226     return pc;
1227
1228   /* If we are not at the beginning of a function, then return now. */
1229   if ((pc & ~0x3) != u->region_start)
1230     return pc;
1231
1232   /* This is how much of a frame adjustment we need to account for.  */
1233   stack_remaining = u->Total_frame_size << 3;
1234
1235   /* Magic register saves we want to know about.  */
1236   save_rp = u->Save_RP;
1237   save_sp = u->Save_SP;
1238
1239   /* An indication that args may be stored into the stack.  Unfortunately
1240      the HPUX compilers tend to set this in cases where no args were
1241      stored too!.  */
1242   args_stored = 1;
1243
1244   /* Turn the Entry_GR field into a bitmask.  */
1245   save_gr = 0;
1246   for (i = 3; i < u->Entry_GR + 3; i++)
1247     {
1248       /* Frame pointer gets saved into a special location.  */
1249       if (u->Save_SP && i == HPPA_FP_REGNUM)
1250         continue;
1251
1252       save_gr |= (1 << i);
1253     }
1254   save_gr &= ~restart_gr;
1255
1256   /* Turn the Entry_FR field into a bitmask too.  */
1257   save_fr = 0;
1258   for (i = 12; i < u->Entry_FR + 12; i++)
1259     save_fr |= (1 << i);
1260   save_fr &= ~restart_fr;
1261
1262   /* Loop until we find everything of interest or hit a branch.
1263
1264      For unoptimized GCC code and for any HP CC code this will never ever
1265      examine any user instructions.
1266
1267      For optimzied GCC code we're faced with problems.  GCC will schedule
1268      its prologue and make prologue instructions available for delay slot
1269      filling.  The end result is user code gets mixed in with the prologue
1270      and a prologue instruction may be in the delay slot of the first branch
1271      or call.
1272
1273      Some unexpected things are expected with debugging optimized code, so
1274      we allow this routine to walk past user instructions in optimized
1275      GCC code.  */
1276   while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
1277          || args_stored)
1278     {
1279       unsigned int reg_num;
1280       unsigned long old_stack_remaining, old_save_gr, old_save_fr;
1281       unsigned long old_save_rp, old_save_sp, next_inst;
1282
1283       /* Save copies of all the triggers so we can compare them later
1284          (only for HPC).  */
1285       old_save_gr = save_gr;
1286       old_save_fr = save_fr;
1287       old_save_rp = save_rp;
1288       old_save_sp = save_sp;
1289       old_stack_remaining = stack_remaining;
1290
1291       status = read_memory_nobpt (pc, buf, 4);
1292       inst = extract_unsigned_integer (buf, 4);
1293
1294       /* Yow! */
1295       if (status != 0)
1296         return pc;
1297
1298       /* Note the interesting effects of this instruction.  */
1299       stack_remaining -= prologue_inst_adjust_sp (inst);
1300
1301       /* There are limited ways to store the return pointer into the
1302          stack.  */
1303       if (inst == 0x6bc23fd9 || inst == 0x0fc212c1)
1304         save_rp = 0;
1305
1306       /* These are the only ways we save SP into the stack.  At this time
1307          the HP compilers never bother to save SP into the stack.  */
1308       if ((inst & 0xffffc000) == 0x6fc10000
1309           || (inst & 0xffffc00c) == 0x73c10008)
1310         save_sp = 0;
1311
1312       /* Are we loading some register with an offset from the argument
1313          pointer?  */
1314       if ((inst & 0xffe00000) == 0x37a00000
1315           || (inst & 0xffffffe0) == 0x081d0240)
1316         {
1317           pc += 4;
1318           continue;
1319         }
1320
1321       /* Account for general and floating-point register saves.  */
1322       reg_num = inst_saves_gr (inst);
1323       save_gr &= ~(1 << reg_num);
1324
1325       /* Ugh.  Also account for argument stores into the stack.
1326          Unfortunately args_stored only tells us that some arguments
1327          where stored into the stack.  Not how many or what kind!
1328
1329          This is a kludge as on the HP compiler sets this bit and it
1330          never does prologue scheduling.  So once we see one, skip past
1331          all of them.   We have similar code for the fp arg stores below.
1332
1333          FIXME.  Can still die if we have a mix of GR and FR argument
1334          stores!  */
1335       if (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
1336         {
1337           while (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
1338             {
1339               pc += 4;
1340               status = read_memory_nobpt (pc, buf, 4);
1341               inst = extract_unsigned_integer (buf, 4);
1342               if (status != 0)
1343                 return pc;
1344               reg_num = inst_saves_gr (inst);
1345             }
1346           args_stored = 0;
1347           continue;
1348         }
1349
1350       reg_num = inst_saves_fr (inst);
1351       save_fr &= ~(1 << reg_num);
1352
1353       status = read_memory_nobpt (pc + 4, buf, 4);
1354       next_inst = extract_unsigned_integer (buf, 4);
1355
1356       /* Yow! */
1357       if (status != 0)
1358         return pc;
1359
1360       /* We've got to be read to handle the ldo before the fp register
1361          save.  */
1362       if ((inst & 0xfc000000) == 0x34000000
1363           && inst_saves_fr (next_inst) >= 4
1364           && inst_saves_fr (next_inst) <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1365         {
1366           /* So we drop into the code below in a reasonable state.  */
1367           reg_num = inst_saves_fr (next_inst);
1368           pc -= 4;
1369         }
1370
1371       /* Ugh.  Also account for argument stores into the stack.
1372          This is a kludge as on the HP compiler sets this bit and it
1373          never does prologue scheduling.  So once we see one, skip past
1374          all of them.  */
1375       if (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1376         {
1377           while (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1378             {
1379               pc += 8;
1380               status = read_memory_nobpt (pc, buf, 4);
1381               inst = extract_unsigned_integer (buf, 4);
1382               if (status != 0)
1383                 return pc;
1384               if ((inst & 0xfc000000) != 0x34000000)
1385                 break;
1386               status = read_memory_nobpt (pc + 4, buf, 4);
1387               next_inst = extract_unsigned_integer (buf, 4);
1388               if (status != 0)
1389                 return pc;
1390               reg_num = inst_saves_fr (next_inst);
1391             }
1392           args_stored = 0;
1393           continue;
1394         }
1395
1396       /* Quit if we hit any kind of branch.  This can happen if a prologue
1397          instruction is in the delay slot of the first call/branch.  */
1398       if (is_branch (inst))
1399         break;
1400
1401       /* What a crock.  The HP compilers set args_stored even if no
1402          arguments were stored into the stack (boo hiss).  This could
1403          cause this code to then skip a bunch of user insns (up to the
1404          first branch).
1405
1406          To combat this we try to identify when args_stored was bogusly
1407          set and clear it.   We only do this when args_stored is nonzero,
1408          all other resources are accounted for, and nothing changed on
1409          this pass.  */
1410       if (args_stored
1411        && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
1412           && old_save_gr == save_gr && old_save_fr == save_fr
1413           && old_save_rp == save_rp && old_save_sp == save_sp
1414           && old_stack_remaining == stack_remaining)
1415         break;
1416
1417       /* Bump the PC.  */
1418       pc += 4;
1419     }
1420
1421   /* We've got a tenative location for the end of the prologue.  However
1422      because of limitations in the unwind descriptor mechanism we may
1423      have went too far into user code looking for the save of a register
1424      that does not exist.  So, if there registers we expected to be saved
1425      but never were, mask them out and restart.
1426
1427      This should only happen in optimized code, and should be very rare.  */
1428   if (save_gr || (save_fr && !(restart_fr || restart_gr)))
1429     {
1430       pc = orig_pc;
1431       restart_gr = save_gr;
1432       restart_fr = save_fr;
1433       goto restart;
1434     }
1435
1436   return pc;
1437 }
1438
1439
1440 /* Return the address of the PC after the last prologue instruction if
1441    we can determine it from the debug symbols.  Else return zero.  */
1442
1443 static CORE_ADDR
1444 after_prologue (CORE_ADDR pc)
1445 {
1446   struct symtab_and_line sal;
1447   CORE_ADDR func_addr, func_end;
1448   struct symbol *f;
1449
1450   /* If we can not find the symbol in the partial symbol table, then
1451      there is no hope we can determine the function's start address
1452      with this code.  */
1453   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1454     return 0;
1455
1456   /* Get the line associated with FUNC_ADDR.  */
1457   sal = find_pc_line (func_addr, 0);
1458
1459   /* There are only two cases to consider.  First, the end of the source line
1460      is within the function bounds.  In that case we return the end of the
1461      source line.  Second is the end of the source line extends beyond the
1462      bounds of the current function.  We need to use the slow code to
1463      examine instructions in that case. 
1464
1465      Anything else is simply a bug elsewhere.  Fixing it here is absolutely
1466      the wrong thing to do.  In fact, it should be entirely possible for this
1467      function to always return zero since the slow instruction scanning code
1468      is supposed to *always* work.  If it does not, then it is a bug.  */
1469   if (sal.end < func_end)
1470     return sal.end;
1471   else
1472     return 0;
1473 }
1474
1475 /* To skip prologues, I use this predicate.  Returns either PC itself
1476    if the code at PC does not look like a function prologue; otherwise
1477    returns an address that (if we're lucky) follows the prologue.  If
1478    LENIENT, then we must skip everything which is involved in setting
1479    up the frame (it's OK to skip more, just so long as we don't skip
1480    anything which might clobber the registers which are being saved.
1481    Currently we must not skip more on the alpha, but we might the lenient
1482    stuff some day.  */
1483
1484 static CORE_ADDR
1485 hppa_skip_prologue (CORE_ADDR pc)
1486 {
1487   unsigned long inst;
1488   int offset;
1489   CORE_ADDR post_prologue_pc;
1490   char buf[4];
1491
1492   /* See if we can determine the end of the prologue via the symbol table.
1493      If so, then return either PC, or the PC after the prologue, whichever
1494      is greater.  */
1495
1496   post_prologue_pc = after_prologue (pc);
1497
1498   /* If after_prologue returned a useful address, then use it.  Else
1499      fall back on the instruction skipping code.
1500
1501      Some folks have claimed this causes problems because the breakpoint
1502      may be the first instruction of the prologue.  If that happens, then
1503      the instruction skipping code has a bug that needs to be fixed.  */
1504   if (post_prologue_pc != 0)
1505     return max (pc, post_prologue_pc);
1506   else
1507     return (skip_prologue_hard_way (pc));
1508 }
1509
1510 struct hppa_frame_cache
1511 {
1512   CORE_ADDR base;
1513   struct trad_frame_saved_reg *saved_regs;
1514 };
1515
1516 static struct hppa_frame_cache *
1517 hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
1518 {
1519   struct hppa_frame_cache *cache;
1520   long saved_gr_mask;
1521   long saved_fr_mask;
1522   CORE_ADDR this_sp;
1523   long frame_size;
1524   struct unwind_table_entry *u;
1525   CORE_ADDR prologue_end;
1526   int i;
1527
1528   if (hppa_debug)
1529     fprintf_unfiltered (gdb_stdlog, "{ hppa_frame_cache (frame=%d) -> ",
1530       frame_relative_level(next_frame));
1531
1532   if ((*this_cache) != NULL)
1533     {
1534       if (hppa_debug)
1535         fprintf_unfiltered (gdb_stdlog, "base=0x%s (cached) }", 
1536           paddr_nz (((struct hppa_frame_cache *)*this_cache)->base));
1537       return (*this_cache);
1538     }
1539   cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
1540   (*this_cache) = cache;
1541   cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1542
1543   /* Yow! */
1544   u = find_unwind_entry (frame_func_unwind (next_frame));
1545   if (!u)
1546     {
1547       if (hppa_debug)
1548         fprintf_unfiltered (gdb_stdlog, "base=NULL (no unwind entry) }");
1549       return (*this_cache);
1550     }
1551
1552   /* Turn the Entry_GR field into a bitmask.  */
1553   saved_gr_mask = 0;
1554   for (i = 3; i < u->Entry_GR + 3; i++)
1555     {
1556       /* Frame pointer gets saved into a special location.  */
1557       if (u->Save_SP && i == HPPA_FP_REGNUM)
1558         continue;
1559         
1560       saved_gr_mask |= (1 << i);
1561     }
1562
1563   /* Turn the Entry_FR field into a bitmask too.  */
1564   saved_fr_mask = 0;
1565   for (i = 12; i < u->Entry_FR + 12; i++)
1566     saved_fr_mask |= (1 << i);
1567
1568   /* Loop until we find everything of interest or hit a branch.
1569
1570      For unoptimized GCC code and for any HP CC code this will never ever
1571      examine any user instructions.
1572
1573      For optimized GCC code we're faced with problems.  GCC will schedule
1574      its prologue and make prologue instructions available for delay slot
1575      filling.  The end result is user code gets mixed in with the prologue
1576      and a prologue instruction may be in the delay slot of the first branch
1577      or call.
1578
1579      Some unexpected things are expected with debugging optimized code, so
1580      we allow this routine to walk past user instructions in optimized
1581      GCC code.  */
1582   {
1583     int final_iteration = 0;
1584     CORE_ADDR pc, end_pc;
1585     int looking_for_sp = u->Save_SP;
1586     int looking_for_rp = u->Save_RP;
1587     int fp_loc = -1;
1588
1589     /* We have to use hppa_skip_prologue instead of just 
1590        skip_prologue_using_sal, in case we stepped into a function without
1591        symbol information.  hppa_skip_prologue also bounds the returned
1592        pc by the passed in pc, so it will not return a pc in the next
1593        function.  */
1594     prologue_end = hppa_skip_prologue (frame_func_unwind (next_frame));
1595     end_pc = frame_pc_unwind (next_frame);
1596
1597     if (prologue_end != 0 && end_pc > prologue_end)
1598       end_pc = prologue_end;
1599
1600     frame_size = 0;
1601
1602     for (pc = frame_func_unwind (next_frame);
1603          ((saved_gr_mask || saved_fr_mask
1604            || looking_for_sp || looking_for_rp
1605            || frame_size < (u->Total_frame_size << 3))
1606           && pc < end_pc);
1607          pc += 4)
1608       {
1609         int reg;
1610         char buf4[4];
1611         long status = read_memory_nobpt (pc, buf4, sizeof buf4);
1612         long inst = extract_unsigned_integer (buf4, sizeof buf4);
1613
1614         /* Note the interesting effects of this instruction.  */
1615         frame_size += prologue_inst_adjust_sp (inst);
1616         
1617         /* There are limited ways to store the return pointer into the
1618            stack.  */
1619         if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
1620           {
1621             looking_for_rp = 0;
1622             cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
1623           }
1624         else if (inst == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
1625           {
1626             looking_for_rp = 0;
1627             cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
1628           }
1629         
1630         /* Check to see if we saved SP into the stack.  This also
1631            happens to indicate the location of the saved frame
1632            pointer.  */
1633         if ((inst & 0xffffc000) == 0x6fc10000  /* stw,ma r1,N(sr0,sp) */
1634             || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
1635           {
1636             looking_for_sp = 0;
1637             cache->saved_regs[HPPA_FP_REGNUM].addr = 0;
1638           }
1639         
1640         /* Account for general and floating-point register saves.  */
1641         reg = inst_saves_gr (inst);
1642         if (reg >= 3 && reg <= 18
1643             && (!u->Save_SP || reg != HPPA_FP_REGNUM))
1644           {
1645             saved_gr_mask &= ~(1 << reg);
1646             if ((inst >> 26) == 0x1b && hppa_extract_14 (inst) >= 0)
1647               /* stwm with a positive displacement is a _post_
1648                  _modify_.  */
1649               cache->saved_regs[reg].addr = 0;
1650             else if ((inst & 0xfc00000c) == 0x70000008)
1651               /* A std has explicit post_modify forms.  */
1652               cache->saved_regs[reg].addr = 0;
1653             else
1654               {
1655                 CORE_ADDR offset;
1656                 
1657                 if ((inst >> 26) == 0x1c)
1658                   offset = (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
1659                 else if ((inst >> 26) == 0x03)
1660                   offset = hppa_low_hppa_sign_extend (inst & 0x1f, 5);
1661                 else
1662                   offset = hppa_extract_14 (inst);
1663                 
1664                 /* Handle code with and without frame pointers.  */
1665                 if (u->Save_SP)
1666                   cache->saved_regs[reg].addr = offset;
1667                 else
1668                   cache->saved_regs[reg].addr = (u->Total_frame_size << 3) + offset;
1669               }
1670           }
1671
1672         /* GCC handles callee saved FP regs a little differently.  
1673            
1674            It emits an instruction to put the value of the start of
1675            the FP store area into %r1.  It then uses fstds,ma with a
1676            basereg of %r1 for the stores.
1677
1678            HP CC emits them at the current stack pointer modifying the
1679            stack pointer as it stores each register.  */
1680         
1681         /* ldo X(%r3),%r1 or ldo X(%r30),%r1.  */
1682         if ((inst & 0xffffc000) == 0x34610000
1683             || (inst & 0xffffc000) == 0x37c10000)
1684           fp_loc = hppa_extract_14 (inst);
1685         
1686         reg = inst_saves_fr (inst);
1687         if (reg >= 12 && reg <= 21)
1688           {
1689             /* Note +4 braindamage below is necessary because the FP
1690                status registers are internally 8 registers rather than
1691                the expected 4 registers.  */
1692             saved_fr_mask &= ~(1 << reg);
1693             if (fp_loc == -1)
1694               {
1695                 /* 1st HP CC FP register store.  After this
1696                    instruction we've set enough state that the GCC and
1697                    HPCC code are both handled in the same manner.  */
1698                 cache->saved_regs[reg + HPPA_FP4_REGNUM + 4].addr = 0;
1699                 fp_loc = 8;
1700               }
1701             else
1702               {
1703                 cache->saved_regs[reg + HPPA_FP0_REGNUM + 4].addr = fp_loc;
1704                 fp_loc += 8;
1705               }
1706           }
1707         
1708         /* Quit if we hit any kind of branch the previous iteration. */
1709         if (final_iteration)
1710           break;
1711         /* We want to look precisely one instruction beyond the branch
1712            if we have not found everything yet.  */
1713         if (is_branch (inst))
1714           final_iteration = 1;
1715       }
1716   }
1717
1718   {
1719     /* The frame base always represents the value of %sp at entry to
1720        the current function (and is thus equivalent to the "saved"
1721        stack pointer.  */
1722     CORE_ADDR this_sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1723     CORE_ADDR fp;
1724
1725     if (hppa_debug)
1726       fprintf_unfiltered (gdb_stdlog, " (this_sp=0x%s, pc=0x%s, "
1727                           "prologue_end=0x%s) ",
1728                           paddr_nz (this_sp),
1729                           paddr_nz (frame_pc_unwind (next_frame)),
1730                           paddr_nz (prologue_end));
1731
1732      /* Check to see if a frame pointer is available, and use it for
1733         frame unwinding if it is.
1734  
1735         There are some situations where we need to rely on the frame
1736         pointer to do stack unwinding.  For example, if a function calls
1737         alloca (), the stack pointer can get adjusted inside the body of
1738         the function.  In this case, the ABI requires that the compiler
1739         maintain a frame pointer for the function.
1740  
1741         The unwind record has a flag (alloca_frame) that indicates that
1742         a function has a variable frame; unfortunately, gcc/binutils 
1743         does not set this flag.  Instead, whenever a frame pointer is used
1744         and saved on the stack, the Save_SP flag is set.  We use this to
1745         decide whether to use the frame pointer for unwinding.
1746         
1747         fp should never be zero here; checking just in case. 
1748         
1749         TODO: For the HP compiler, maybe we should use the alloca_frame flag 
1750         instead of Save_SP.  */
1751  
1752      fp = frame_unwind_register_unsigned (next_frame, HPPA_FP_REGNUM);
1753  
1754      if (frame_pc_unwind (next_frame) >= prologue_end
1755          && u->Save_SP && fp != 0)
1756       {
1757         cache->base = fp;
1758  
1759         if (hppa_debug)
1760           fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [frame pointer] }",
1761             paddr_nz (cache->base));
1762       }
1763      else if (frame_pc_unwind (next_frame) >= prologue_end)
1764       {
1765         if (u->Save_SP && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM))
1766           {
1767             /* Both we're expecting the SP to be saved and the SP has been
1768                saved.  The entry SP value is saved at this frame's SP
1769                address.  */
1770             cache->base = read_memory_integer (this_sp, TARGET_PTR_BIT / 8);
1771
1772             if (hppa_debug)
1773               fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [saved] }",
1774                                   paddr_nz (cache->base));
1775           }
1776         else
1777           {
1778             /* The prologue has been slowly allocating stack space.  Adjust
1779              the SP back.  */
1780             cache->base = this_sp - frame_size;
1781             if (hppa_debug)
1782               fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [unwind adjust] } ",
1783                                   paddr_nz (cache->base));
1784
1785           }
1786       }
1787     else
1788       {
1789         /* This frame has not yet been created. */
1790         cache->base = this_sp;
1791
1792         if (hppa_debug)
1793           fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [before prologue] } ",
1794                               paddr_nz (cache->base));
1795
1796       }
1797
1798     trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
1799   }
1800
1801   /* The PC is found in the "return register", "Millicode" uses "r31"
1802      as the return register while normal code uses "rp".  */
1803   if (u->Millicode)
1804     {
1805       if (trad_frame_addr_p (cache->saved_regs, 31))
1806         cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[31];
1807       else
1808         {
1809           ULONGEST r31 = frame_unwind_register_unsigned (next_frame, 31);
1810           trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, r31);
1811         }
1812     }
1813   else
1814     {
1815       if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
1816         cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM];
1817       else
1818         {
1819           ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM);
1820           trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
1821         }
1822     }
1823
1824   {
1825     /* Convert all the offsets into addresses.  */
1826     int reg;
1827     for (reg = 0; reg < NUM_REGS; reg++)
1828       {
1829         if (trad_frame_addr_p (cache->saved_regs, reg))
1830           cache->saved_regs[reg].addr += cache->base;
1831       }
1832   }
1833
1834   if (hppa_debug)
1835     fprintf_unfiltered (gdb_stdlog, "base=0x%s }", 
1836       paddr_nz (((struct hppa_frame_cache *)*this_cache)->base));
1837   return (*this_cache);
1838 }
1839
1840 static void
1841 hppa_frame_this_id (struct frame_info *next_frame, void **this_cache,
1842                            struct frame_id *this_id)
1843 {
1844   struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache);
1845   (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
1846 }
1847
1848 static void
1849 hppa_frame_prev_register (struct frame_info *next_frame,
1850                           void **this_cache,
1851                           int regnum, int *optimizedp,
1852                           enum lval_type *lvalp, CORE_ADDR *addrp,
1853                           int *realnump, void *valuep)
1854 {
1855   struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache);
1856   hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
1857                                    optimizedp, lvalp, addrp, realnump, valuep);
1858 }
1859
1860 static const struct frame_unwind hppa_frame_unwind =
1861 {
1862   NORMAL_FRAME,
1863   hppa_frame_this_id,
1864   hppa_frame_prev_register
1865 };
1866
1867 static const struct frame_unwind *
1868 hppa_frame_unwind_sniffer (struct frame_info *next_frame)
1869 {
1870   CORE_ADDR pc = frame_pc_unwind (next_frame);
1871
1872   if (find_unwind_entry (pc))
1873     return &hppa_frame_unwind;
1874
1875   return NULL;
1876 }
1877
1878 /* This is a generic fallback frame unwinder that kicks in if we fail all
1879    the other ones.  Normally we would expect the stub and regular unwinder
1880    to work, but in some cases we might hit a function that just doesn't
1881    have any unwind information available.  In this case we try to do
1882    unwinding solely based on code reading.  This is obviously going to be
1883    slow, so only use this as a last resort.  Currently this will only
1884    identify the stack and pc for the frame.  */
1885
1886 static struct hppa_frame_cache *
1887 hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache)
1888 {
1889   struct hppa_frame_cache *cache;
1890   unsigned int frame_size;
1891   CORE_ADDR pc, start_pc, end_pc, cur_pc;
1892
1893   cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
1894   (*this_cache) = cache;
1895   cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1896
1897   pc = frame_func_unwind (next_frame);
1898   cur_pc = frame_pc_unwind (next_frame);
1899   frame_size = 0;
1900
1901   find_pc_partial_function (pc, NULL, &start_pc, &end_pc);
1902
1903   if (start_pc == 0 || end_pc == 0)
1904     {
1905       error ("Cannot find bounds of current function (@0x%s), unwinding will "
1906              "fail.", paddr_nz (pc));
1907       return cache;
1908     }
1909
1910   if (end_pc > cur_pc)
1911     end_pc = cur_pc;
1912
1913   for (pc = start_pc; pc < end_pc; pc += 4)
1914     {
1915       unsigned int insn;
1916
1917       insn = read_memory_unsigned_integer (pc, 4);
1918
1919       frame_size += prologue_inst_adjust_sp (insn);
1920
1921       /* There are limited ways to store the return pointer into the
1922          stack.  */
1923       if (insn == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
1924          cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
1925       else if (insn == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
1926          cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
1927     }
1928
1929   cache->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM) - frame_size;
1930   trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
1931
1932   if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
1933     {
1934       cache->saved_regs[HPPA_RP_REGNUM].addr += cache->base;
1935       cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM];
1936     }
1937   else
1938     {
1939       ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM);
1940       trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
1941     }
1942
1943   return cache;
1944 }
1945
1946 static void
1947 hppa_fallback_frame_this_id (struct frame_info *next_frame, void **this_cache,
1948                              struct frame_id *this_id)
1949 {
1950   struct hppa_frame_cache *info = 
1951     hppa_fallback_frame_cache (next_frame, this_cache);
1952   (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
1953 }
1954
1955 static void
1956 hppa_fallback_frame_prev_register (struct frame_info *next_frame,
1957                           void **this_cache,
1958                           int regnum, int *optimizedp,
1959                           enum lval_type *lvalp, CORE_ADDR *addrp,
1960                           int *realnump, void *valuep)
1961 {
1962   struct hppa_frame_cache *info = 
1963     hppa_fallback_frame_cache (next_frame, this_cache);
1964   hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
1965                                    optimizedp, lvalp, addrp, realnump, valuep);
1966 }
1967
1968 static const struct frame_unwind hppa_fallback_frame_unwind =
1969 {
1970   NORMAL_FRAME,
1971   hppa_fallback_frame_this_id,
1972   hppa_fallback_frame_prev_register
1973 };
1974
1975 static const struct frame_unwind *
1976 hppa_fallback_unwind_sniffer (struct frame_info *next_frame)
1977 {
1978   return &hppa_fallback_frame_unwind;
1979 }
1980
1981 static CORE_ADDR
1982 hppa_frame_base_address (struct frame_info *next_frame,
1983                                 void **this_cache)
1984 {
1985   struct hppa_frame_cache *info = hppa_frame_cache (next_frame,
1986                                                            this_cache);
1987   return info->base;
1988 }
1989
1990 static const struct frame_base hppa_frame_base = {
1991   &hppa_frame_unwind,
1992   hppa_frame_base_address,
1993   hppa_frame_base_address,
1994   hppa_frame_base_address
1995 };
1996
1997 static const struct frame_base *
1998 hppa_frame_base_sniffer (struct frame_info *next_frame)
1999 {
2000   return &hppa_frame_base;
2001 }
2002
2003 /* Stub frames, used for all kinds of call stubs.  */
2004 struct hppa_stub_unwind_cache
2005 {
2006   CORE_ADDR base;
2007   struct trad_frame_saved_reg *saved_regs;
2008 };
2009
2010 static struct hppa_stub_unwind_cache *
2011 hppa_stub_frame_unwind_cache (struct frame_info *next_frame,
2012                               void **this_cache)
2013 {
2014   struct gdbarch *gdbarch = get_frame_arch (next_frame);
2015   struct hppa_stub_unwind_cache *info;
2016   struct unwind_table_entry *u;
2017
2018   if (*this_cache)
2019     return *this_cache;
2020
2021   info = FRAME_OBSTACK_ZALLOC (struct hppa_stub_unwind_cache);
2022   *this_cache = info;
2023   info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2024
2025   info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
2026
2027   if (gdbarch_osabi (gdbarch) == GDB_OSABI_HPUX_SOM)
2028     {
2029       /* HPUX uses export stubs in function calls; the export stub clobbers
2030          the return value of the caller, and, later restores it from the
2031          stack.  */
2032       u = find_unwind_entry (frame_pc_unwind (next_frame));
2033
2034       if (u && u->stub_unwind.stub_type == EXPORT)
2035         {
2036           info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].addr = info->base - 24;
2037
2038           return info;
2039         }
2040     }
2041
2042   /* By default we assume that stubs do not change the rp.  */
2043   info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM;
2044
2045   return info;
2046 }
2047
2048 static void
2049 hppa_stub_frame_this_id (struct frame_info *next_frame,
2050                          void **this_prologue_cache,
2051                          struct frame_id *this_id)
2052 {
2053   struct hppa_stub_unwind_cache *info
2054     = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache);
2055   *this_id = frame_id_build (info->base, frame_pc_unwind (next_frame));
2056 }
2057
2058 static void
2059 hppa_stub_frame_prev_register (struct frame_info *next_frame,
2060                                void **this_prologue_cache,
2061                                int regnum, int *optimizedp,
2062                                enum lval_type *lvalp, CORE_ADDR *addrp,
2063                                int *realnump, void *valuep)
2064 {
2065   struct hppa_stub_unwind_cache *info
2066     = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache);
2067   hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
2068                                    optimizedp, lvalp, addrp, realnump, valuep);
2069 }
2070
2071 static const struct frame_unwind hppa_stub_frame_unwind = {
2072   NORMAL_FRAME,
2073   hppa_stub_frame_this_id,
2074   hppa_stub_frame_prev_register
2075 };
2076
2077 static const struct frame_unwind *
2078 hppa_stub_unwind_sniffer (struct frame_info *next_frame)
2079 {
2080   CORE_ADDR pc = frame_pc_unwind (next_frame);
2081
2082   if (pc == 0
2083       || IN_SOLIB_CALL_TRAMPOLINE (pc, NULL)
2084       || IN_SOLIB_RETURN_TRAMPOLINE (pc, NULL))
2085     return &hppa_stub_frame_unwind;
2086   return NULL;
2087 }
2088
2089 static struct frame_id
2090 hppa_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2091 {
2092   return frame_id_build (frame_unwind_register_unsigned (next_frame,
2093                                                          HPPA_SP_REGNUM),
2094                          frame_pc_unwind (next_frame));
2095 }
2096
2097 static CORE_ADDR
2098 hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2099 {
2100   return frame_unwind_register_signed (next_frame, HPPA_PCOQ_HEAD_REGNUM) & ~3;
2101 }
2102
2103 /* Instead of this nasty cast, add a method pvoid() that prints out a
2104    host VOID data type (remember %p isn't portable).  */
2105
2106 static CORE_ADDR
2107 hppa_pointer_to_address_hack (void *ptr)
2108 {
2109   gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
2110   return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
2111 }
2112
2113 static void
2114 unwind_command (char *exp, int from_tty)
2115 {
2116   CORE_ADDR address;
2117   struct unwind_table_entry *u;
2118
2119   /* If we have an expression, evaluate it and use it as the address.  */
2120
2121   if (exp != 0 && *exp != 0)
2122     address = parse_and_eval_address (exp);
2123   else
2124     return;
2125
2126   u = find_unwind_entry (address);
2127
2128   if (!u)
2129     {
2130       printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
2131       return;
2132     }
2133
2134   printf_unfiltered ("unwind_table_entry (0x%s):\n",
2135                      paddr_nz (hppa_pointer_to_address_hack (u)));
2136
2137   printf_unfiltered ("\tregion_start = ");
2138   print_address (u->region_start, gdb_stdout);
2139
2140   printf_unfiltered ("\n\tregion_end = ");
2141   print_address (u->region_end, gdb_stdout);
2142
2143 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
2144
2145   printf_unfiltered ("\n\tflags =");
2146   pif (Cannot_unwind);
2147   pif (Millicode);
2148   pif (Millicode_save_sr0);
2149   pif (Entry_SR);
2150   pif (Args_stored);
2151   pif (Variable_Frame);
2152   pif (Separate_Package_Body);
2153   pif (Frame_Extension_Millicode);
2154   pif (Stack_Overflow_Check);
2155   pif (Two_Instruction_SP_Increment);
2156   pif (Ada_Region);
2157   pif (Save_SP);
2158   pif (Save_RP);
2159   pif (Save_MRP_in_frame);
2160   pif (extn_ptr_defined);
2161   pif (Cleanup_defined);
2162   pif (MPE_XL_interrupt_marker);
2163   pif (HP_UX_interrupt_marker);
2164   pif (Large_frame);
2165
2166   putchar_unfiltered ('\n');
2167
2168 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
2169
2170   pin (Region_description);
2171   pin (Entry_FR);
2172   pin (Entry_GR);
2173   pin (Total_frame_size);
2174 }
2175
2176 void
2177 hppa_skip_permanent_breakpoint (void)
2178 {
2179   /* To step over a breakpoint instruction on the PA takes some
2180      fiddling with the instruction address queue.
2181
2182      When we stop at a breakpoint, the IA queue front (the instruction
2183      we're executing now) points at the breakpoint instruction, and
2184      the IA queue back (the next instruction to execute) points to
2185      whatever instruction we would execute after the breakpoint, if it
2186      were an ordinary instruction.  This is the case even if the
2187      breakpoint is in the delay slot of a branch instruction.
2188
2189      Clearly, to step past the breakpoint, we need to set the queue
2190      front to the back.  But what do we put in the back?  What
2191      instruction comes after that one?  Because of the branch delay
2192      slot, the next insn is always at the back + 4.  */
2193   write_register (HPPA_PCOQ_HEAD_REGNUM, read_register (HPPA_PCOQ_TAIL_REGNUM));
2194   write_register (HPPA_PCSQ_HEAD_REGNUM, read_register (HPPA_PCSQ_TAIL_REGNUM));
2195
2196   write_register (HPPA_PCOQ_TAIL_REGNUM, read_register (HPPA_PCOQ_TAIL_REGNUM) + 4);
2197   /* We can leave the tail's space the same, since there's no jump.  */
2198 }
2199
2200 int
2201 hppa_pc_requires_run_before_use (CORE_ADDR pc)
2202 {
2203   /* Sometimes we may pluck out a minimal symbol that has a negative address.
2204   
2205      An example of this occurs when an a.out is linked against a foo.sl.
2206      The foo.sl defines a global bar(), and the a.out declares a signature
2207      for bar().  However, the a.out doesn't directly call bar(), but passes
2208      its address in another call.
2209   
2210      If you have this scenario and attempt to "break bar" before running,
2211      gdb will find a minimal symbol for bar() in the a.out.  But that
2212      symbol's address will be negative.  What this appears to denote is
2213      an index backwards from the base of the procedure linkage table (PLT)
2214      into the data linkage table (DLT), the end of which is contiguous
2215      with the start of the PLT.  This is clearly not a valid address for
2216      us to set a breakpoint on.
2217   
2218      Note that one must be careful in how one checks for a negative address.
2219      0xc0000000 is a legitimate address of something in a shared text
2220      segment, for example.  Since I don't know what the possible range
2221      is of these "really, truly negative" addresses that come from the
2222      minimal symbols, I'm resorting to the gross hack of checking the
2223      top byte of the address for all 1's.  Sigh.  */
2224
2225   return (!target_has_stack && (pc & 0xFF000000));
2226 }
2227
2228 int
2229 hppa_instruction_nullified (void)
2230 {
2231   /* brobecker 2002/11/07: Couldn't we use a ULONGEST here? It would
2232      avoid the type cast.  I'm leaving it as is for now as I'm doing
2233      semi-mechanical multiarching-related changes.  */
2234   const int ipsw = (int) read_register (HPPA_IPSW_REGNUM);
2235   const int flags = (int) read_register (HPPA_FLAGS_REGNUM);
2236
2237   return ((ipsw & 0x00200000) && !(flags & 0x2));
2238 }
2239
2240 /* Return the GDB type object for the "standard" data type of data
2241    in register N.  */
2242
2243 static struct type *
2244 hppa32_register_type (struct gdbarch *gdbarch, int reg_nr)
2245 {
2246    if (reg_nr < HPPA_FP4_REGNUM)
2247      return builtin_type_uint32;
2248    else
2249      return builtin_type_ieee_single_big;
2250 }
2251
2252 /* Return the GDB type object for the "standard" data type of data
2253    in register N.  hppa64 version.  */
2254
2255 static struct type *
2256 hppa64_register_type (struct gdbarch *gdbarch, int reg_nr)
2257 {
2258    if (reg_nr < HPPA_FP4_REGNUM)
2259      return builtin_type_uint64;
2260    else
2261      return builtin_type_ieee_double_big;
2262 }
2263
2264 /* Return True if REGNUM is not a register available to the user
2265    through ptrace().  */
2266
2267 static int
2268 hppa_cannot_store_register (int regnum)
2269 {
2270   return (regnum == 0
2271           || regnum == HPPA_PCSQ_HEAD_REGNUM
2272           || (regnum >= HPPA_PCSQ_TAIL_REGNUM && regnum < HPPA_IPSW_REGNUM)
2273           || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA_FP4_REGNUM));
2274
2275 }
2276
2277 static CORE_ADDR
2278 hppa_smash_text_address (CORE_ADDR addr)
2279 {
2280   /* The low two bits of the PC on the PA contain the privilege level.
2281      Some genius implementing a (non-GCC) compiler apparently decided
2282      this means that "addresses" in a text section therefore include a
2283      privilege level, and thus symbol tables should contain these bits.
2284      This seems like a bonehead thing to do--anyway, it seems to work
2285      for our purposes to just ignore those bits.  */
2286
2287   return (addr &= ~0x3);
2288 }
2289
2290 /* Get the ith function argument for the current function.  */
2291 CORE_ADDR
2292 hppa_fetch_pointer_argument (struct frame_info *frame, int argi, 
2293                              struct type *type)
2294 {
2295   CORE_ADDR addr;
2296   get_frame_register (frame, HPPA_R0_REGNUM + 26 - argi, &addr);
2297   return addr;
2298 }
2299
2300 static void
2301 hppa_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2302                            int regnum, void *buf)
2303 {
2304     ULONGEST tmp;
2305
2306     regcache_raw_read_unsigned (regcache, regnum, &tmp);
2307     if (regnum == HPPA_PCOQ_HEAD_REGNUM || regnum == HPPA_PCOQ_TAIL_REGNUM)
2308       tmp &= ~0x3;
2309     store_unsigned_integer (buf, sizeof(tmp), tmp);
2310 }
2311
2312 void
2313 hppa_frame_prev_register_helper (struct frame_info *next_frame,
2314                                  struct trad_frame_saved_reg saved_regs[],
2315                                  int regnum, int *optimizedp,
2316                                  enum lval_type *lvalp, CORE_ADDR *addrp,
2317                                  int *realnump, void *valuep)
2318 {
2319   if (regnum == HPPA_PCOQ_TAIL_REGNUM)
2320     {
2321       if (valuep)
2322         {
2323           CORE_ADDR pc;
2324
2325           trad_frame_prev_register (next_frame, saved_regs,
2326                                     HPPA_PCOQ_HEAD_REGNUM, optimizedp,
2327                                     lvalp, addrp, realnump, valuep);
2328
2329           pc = extract_unsigned_integer (valuep, 4);
2330           store_unsigned_integer (valuep, 4, pc + 4);
2331         }
2332
2333       /* It's a computed value.  */
2334       *optimizedp = 0;
2335       *lvalp = not_lval;
2336       *addrp = 0;
2337       *realnump = -1;
2338       return;
2339     }
2340
2341   trad_frame_prev_register (next_frame, saved_regs, regnum,
2342                             optimizedp, lvalp, addrp, realnump, valuep);
2343 }
2344 \f
2345
2346 /* Here is a table of C type sizes on hppa with various compiles
2347    and options.  I measured this on PA 9000/800 with HP-UX 11.11
2348    and these compilers:
2349
2350      /usr/ccs/bin/cc    HP92453-01 A.11.01.21
2351      /opt/ansic/bin/cc  HP92453-01 B.11.11.28706.GP
2352      /opt/aCC/bin/aCC   B3910B A.03.45
2353      gcc                gcc 3.3.2 native hppa2.0w-hp-hpux11.11
2354
2355      cc            : 1 2 4 4 8 : 4 8 -- : 4 4
2356      ansic +DA1.1  : 1 2 4 4 8 : 4 8 16 : 4 4
2357      ansic +DA2.0  : 1 2 4 4 8 : 4 8 16 : 4 4
2358      ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2359      acc   +DA1.1  : 1 2 4 4 8 : 4 8 16 : 4 4
2360      acc   +DA2.0  : 1 2 4 4 8 : 4 8 16 : 4 4
2361      acc   +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2362      gcc           : 1 2 4 4 8 : 4 8 16 : 4 4
2363
2364    Each line is:
2365
2366      compiler and options
2367      char, short, int, long, long long
2368      float, double, long double
2369      char *, void (*)()
2370
2371    So all these compilers use either ILP32 or LP64 model.
2372    TODO: gcc has more options so it needs more investigation.
2373
2374    For floating point types, see:
2375
2376      http://docs.hp.com/hpux/pdf/B3906-90006.pdf
2377      HP-UX floating-point guide, hpux 11.00
2378
2379    -- chastain 2003-12-18  */
2380
2381 static struct gdbarch *
2382 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2383 {
2384   struct gdbarch_tdep *tdep;
2385   struct gdbarch *gdbarch;
2386   
2387   /* Try to determine the ABI of the object we are loading.  */
2388   if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
2389     {
2390       /* If it's a SOM file, assume it's HP/UX SOM.  */
2391       if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour)
2392         info.osabi = GDB_OSABI_HPUX_SOM;
2393     }
2394
2395   /* find a candidate among the list of pre-declared architectures.  */
2396   arches = gdbarch_list_lookup_by_info (arches, &info);
2397   if (arches != NULL)
2398     return (arches->gdbarch);
2399
2400   /* If none found, then allocate and initialize one.  */
2401   tdep = XZALLOC (struct gdbarch_tdep);
2402   gdbarch = gdbarch_alloc (&info, tdep);
2403
2404   /* Determine from the bfd_arch_info structure if we are dealing with
2405      a 32 or 64 bits architecture.  If the bfd_arch_info is not available,
2406      then default to a 32bit machine.  */
2407   if (info.bfd_arch_info != NULL)
2408     tdep->bytes_per_address =
2409       info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
2410   else
2411     tdep->bytes_per_address = 4;
2412
2413   /* Some parts of the gdbarch vector depend on whether we are running
2414      on a 32 bits or 64 bits target.  */
2415   switch (tdep->bytes_per_address)
2416     {
2417       case 4:
2418         set_gdbarch_num_regs (gdbarch, hppa32_num_regs);
2419         set_gdbarch_register_name (gdbarch, hppa32_register_name);
2420         set_gdbarch_register_type (gdbarch, hppa32_register_type);
2421         break;
2422       case 8:
2423         set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
2424         set_gdbarch_register_name (gdbarch, hppa64_register_name);
2425         set_gdbarch_register_type (gdbarch, hppa64_register_type);
2426         break;
2427       default:
2428         internal_error (__FILE__, __LINE__, "Unsupported address size: %d",
2429                         tdep->bytes_per_address);
2430     }
2431
2432   set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
2433   set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
2434
2435   /* The following gdbarch vector elements are the same in both ILP32
2436      and LP64, but might show differences some day.  */
2437   set_gdbarch_long_long_bit (gdbarch, 64);
2438   set_gdbarch_long_double_bit (gdbarch, 128);
2439   set_gdbarch_long_double_format (gdbarch, &floatformat_ia64_quad_big);
2440
2441   /* The following gdbarch vector elements do not depend on the address
2442      size, or in any other gdbarch element previously set.  */
2443   set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue);
2444   set_gdbarch_inner_than (gdbarch, core_addr_greaterthan);
2445   set_gdbarch_sp_regnum (gdbarch, HPPA_SP_REGNUM);
2446   set_gdbarch_fp0_regnum (gdbarch, HPPA_FP0_REGNUM);
2447   set_gdbarch_cannot_store_register (gdbarch, hppa_cannot_store_register);
2448   set_gdbarch_cannot_fetch_register (gdbarch, hppa_cannot_store_register);
2449   set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address);
2450   set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address);
2451   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2452   set_gdbarch_read_pc (gdbarch, hppa_target_read_pc);
2453   set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
2454
2455   /* Helper for function argument information.  */
2456   set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
2457
2458   set_gdbarch_print_insn (gdbarch, print_insn_hppa);
2459
2460   /* When a hardware watchpoint triggers, we'll move the inferior past
2461      it by removing all eventpoints; stepping past the instruction
2462      that caused the trigger; reinserting eventpoints; and checking
2463      whether any watched location changed.  */
2464   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
2465
2466   /* Inferior function call methods.  */
2467   switch (tdep->bytes_per_address)
2468     {
2469     case 4:
2470       set_gdbarch_push_dummy_call (gdbarch, hppa32_push_dummy_call);
2471       set_gdbarch_frame_align (gdbarch, hppa32_frame_align);
2472       break;
2473     case 8:
2474       set_gdbarch_push_dummy_call (gdbarch, hppa64_push_dummy_call);
2475       set_gdbarch_frame_align (gdbarch, hppa64_frame_align);
2476       break;
2477     default:
2478       internal_error (__FILE__, __LINE__, "bad switch");
2479     }
2480       
2481   /* Struct return methods.  */
2482   switch (tdep->bytes_per_address)
2483     {
2484     case 4:
2485       set_gdbarch_return_value (gdbarch, hppa32_return_value);
2486       break;
2487     case 8:
2488       set_gdbarch_return_value (gdbarch, hppa64_return_value);
2489       break;
2490     default:
2491       internal_error (__FILE__, __LINE__, "bad switch");
2492     }
2493       
2494   set_gdbarch_breakpoint_from_pc (gdbarch, hppa_breakpoint_from_pc);
2495   set_gdbarch_pseudo_register_read (gdbarch, hppa_pseudo_register_read);
2496
2497   /* Frame unwind methods.  */
2498   set_gdbarch_unwind_dummy_id (gdbarch, hppa_unwind_dummy_id);
2499   set_gdbarch_unwind_pc (gdbarch, hppa_unwind_pc);
2500
2501   /* Hook in ABI-specific overrides, if they have been registered.  */
2502   gdbarch_init_osabi (info, gdbarch);
2503
2504   /* Hook in the default unwinders.  */
2505   frame_unwind_append_sniffer (gdbarch, hppa_stub_unwind_sniffer);
2506   frame_unwind_append_sniffer (gdbarch, hppa_frame_unwind_sniffer);
2507   frame_unwind_append_sniffer (gdbarch, hppa_fallback_unwind_sniffer);
2508   frame_base_append_sniffer (gdbarch, hppa_frame_base_sniffer);
2509
2510   return gdbarch;
2511 }
2512
2513 static void
2514 hppa_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
2515 {
2516   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2517
2518   fprintf_unfiltered (file, "bytes_per_address = %d\n", 
2519                       tdep->bytes_per_address);
2520   fprintf_unfiltered (file, "elf = %s\n", tdep->is_elf ? "yes" : "no");
2521 }
2522
2523 void
2524 _initialize_hppa_tdep (void)
2525 {
2526   struct cmd_list_element *c;
2527   void break_at_finish_command (char *arg, int from_tty);
2528   void tbreak_at_finish_command (char *arg, int from_tty);
2529   void break_at_finish_at_depth_command (char *arg, int from_tty);
2530
2531   gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
2532
2533   hppa_objfile_priv_data = register_objfile_data ();
2534
2535   add_cmd ("unwind", class_maintenance, unwind_command,
2536            "Print unwind table entry at given address.",
2537            &maintenanceprintlist);
2538
2539   deprecate_cmd (add_com ("xbreak", class_breakpoint, 
2540                           break_at_finish_command,
2541                           concat ("Set breakpoint at procedure exit. \n\
2542 Argument may be function name, or \"*\" and an address.\n\
2543 If function is specified, break at end of code for that function.\n\
2544 If an address is specified, break at the end of the function that contains \n\
2545 that exact address.\n",
2546                    "With no arg, uses current execution address of selected stack frame.\n\
2547 This is useful for breaking on return to a stack frame.\n\
2548 \n\
2549 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2550 \n\
2551 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)), NULL);
2552   deprecate_cmd (add_com_alias ("xb", "xbreak", class_breakpoint, 1), NULL);
2553   deprecate_cmd (add_com_alias ("xbr", "xbreak", class_breakpoint, 1), NULL);
2554   deprecate_cmd (add_com_alias ("xbre", "xbreak", class_breakpoint, 1), NULL);
2555   deprecate_cmd (add_com_alias ("xbrea", "xbreak", class_breakpoint, 1), NULL);
2556
2557   deprecate_cmd (c = add_com ("txbreak", class_breakpoint, 
2558                               tbreak_at_finish_command,
2559 "Set temporary breakpoint at procedure exit.  Either there should\n\
2560 be no argument or the argument must be a depth.\n"), NULL);
2561   set_cmd_completer (c, location_completer);
2562   
2563   if (xdb_commands)
2564     deprecate_cmd (add_com ("bx", class_breakpoint, 
2565                             break_at_finish_at_depth_command,
2566 "Set breakpoint at procedure exit.  Either there should\n\
2567 be no argument or the argument must be a depth.\n"), NULL);
2568
2569   /* Debug this files internals. */
2570   add_show_from_set (add_set_cmd ("hppa", class_maintenance, var_zinteger,
2571                                   &hppa_debug, "Set hppa debugging.\n\
2572 When non-zero, hppa specific debugging is enabled.", &setdebuglist), &showdebuglist);
2573 }