1 /* Target-dependent code for the HP PA architecture, for GDB.
3 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
7 Contributed by the Center for Software Science at the
8 University of Utah (pa-gdb-bugs@cs.utah.edu).
10 This file is part of GDB.
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.
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.
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. */
31 #include "completer.h"
33 #include "gdb_assert.h"
34 #include "arch-utils.h"
35 /* For argument passing to the inferior */
38 #include "trad-frame.h"
39 #include "frame-unwind.h"
40 #include "frame-base.h"
45 #include "hppa-tdep.h"
47 static int hppa_debug = 0;
49 /* Some local constants. */
50 static const int hppa32_num_regs = 128;
51 static const int hppa64_num_regs = 96;
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;
61 /* Get at various relevent fields of an instruction word. */
64 #define MASK_14 0x3fff
65 #define MASK_21 0x1fffff
67 /* Sizes (in bytes) of the native unwind entries. */
68 #define UNWIND_ENTRY_SIZE 16
69 #define STUB_UNWIND_ENTRY_SIZE 8
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);
75 /* Handle 32/64-bit struct return conventions. */
77 static enum return_value_convention
78 hppa32_return_value (struct gdbarch *gdbarch,
79 struct type *type, struct regcache *regcache,
80 void *readbuf, const void *writebuf)
82 if (TYPE_LENGTH (type) <= 2 * 4)
84 /* The value always lives in the right hand end of the register
85 (or register pair)? */
87 int reg = TYPE_CODE (type) == TYPE_CODE_FLT ? HPPA_FP4_REGNUM : 28;
88 int part = TYPE_LENGTH (type) % 4;
89 /* The left hand register contains only part of the value,
90 transfer that first so that the rest can be xfered as entire
95 regcache_cooked_read_part (regcache, reg, 4 - part,
98 regcache_cooked_write_part (regcache, reg, 4 - part,
102 /* Now transfer the remaining register values. */
103 for (b = part; b < TYPE_LENGTH (type); b += 4)
106 regcache_cooked_read (regcache, reg, (char *) readbuf + b);
107 if (writebuf != NULL)
108 regcache_cooked_write (regcache, reg, (const char *) writebuf + b);
111 return RETURN_VALUE_REGISTER_CONVENTION;
114 return RETURN_VALUE_STRUCT_CONVENTION;
117 static enum return_value_convention
118 hppa64_return_value (struct gdbarch *gdbarch,
119 struct type *type, struct regcache *regcache,
120 void *readbuf, const void *writebuf)
122 /* RM: Floats are returned in FR4R, doubles in FR4. Integral values
123 are in r28, padded on the left. Aggregates less that 65 bits are
124 in r28, right padded. Aggregates upto 128 bits are in r28 and
125 r29, right padded. */
126 if (TYPE_CODE (type) == TYPE_CODE_FLT
127 && TYPE_LENGTH (type) <= 8)
129 /* Floats are right aligned? */
130 int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type);
132 regcache_cooked_read_part (regcache, HPPA_FP4_REGNUM, offset,
133 TYPE_LENGTH (type), readbuf);
134 if (writebuf != NULL)
135 regcache_cooked_write_part (regcache, HPPA_FP4_REGNUM, offset,
136 TYPE_LENGTH (type), writebuf);
137 return RETURN_VALUE_REGISTER_CONVENTION;
139 else if (TYPE_LENGTH (type) <= 8 && is_integral_type (type))
141 /* Integrals are right aligned. */
142 int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type);
144 regcache_cooked_read_part (regcache, 28, offset,
145 TYPE_LENGTH (type), readbuf);
146 if (writebuf != NULL)
147 regcache_cooked_write_part (regcache, 28, offset,
148 TYPE_LENGTH (type), writebuf);
149 return RETURN_VALUE_REGISTER_CONVENTION;
151 else if (TYPE_LENGTH (type) <= 2 * 8)
153 /* Composite values are left aligned. */
155 for (b = 0; b < TYPE_LENGTH (type); b += 8)
157 int part = min (8, TYPE_LENGTH (type) - b);
159 regcache_cooked_read_part (regcache, 28 + b / 8, 0, part,
160 (char *) readbuf + b);
161 if (writebuf != NULL)
162 regcache_cooked_write_part (regcache, 28 + b / 8, 0, part,
163 (const char *) writebuf + b);
165 return RETURN_VALUE_REGISTER_CONVENTION;
168 return RETURN_VALUE_STRUCT_CONVENTION;
171 /* Routines to extract various sized constants out of hppa
174 /* This assumes that no garbage lies outside of the lower bits of
178 hppa_sign_extend (unsigned val, unsigned bits)
180 return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
183 /* For many immediate values the sign bit is the low bit! */
186 hppa_low_hppa_sign_extend (unsigned val, unsigned bits)
188 return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
191 /* Extract the bits at positions between FROM and TO, using HP's numbering
195 hppa_get_field (unsigned word, int from, int to)
197 return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
200 /* extract the immediate field from a ld{bhw}s instruction */
203 hppa_extract_5_load (unsigned word)
205 return hppa_low_hppa_sign_extend (word >> 16 & MASK_5, 5);
208 /* extract the immediate field from a break instruction */
211 hppa_extract_5r_store (unsigned word)
213 return (word & MASK_5);
216 /* extract the immediate field from a {sr}sm instruction */
219 hppa_extract_5R_store (unsigned word)
221 return (word >> 16 & MASK_5);
224 /* extract a 14 bit immediate field */
227 hppa_extract_14 (unsigned word)
229 return hppa_low_hppa_sign_extend (word & MASK_14, 14);
232 /* extract a 21 bit constant */
235 hppa_extract_21 (unsigned word)
241 val = hppa_get_field (word, 20, 20);
243 val |= hppa_get_field (word, 9, 19);
245 val |= hppa_get_field (word, 5, 6);
247 val |= hppa_get_field (word, 0, 4);
249 val |= hppa_get_field (word, 7, 8);
250 return hppa_sign_extend (val, 21) << 11;
253 /* extract a 17 bit constant from branch instructions, returning the
254 19 bit signed value. */
257 hppa_extract_17 (unsigned word)
259 return hppa_sign_extend (hppa_get_field (word, 19, 28) |
260 hppa_get_field (word, 29, 29) << 10 |
261 hppa_get_field (word, 11, 15) << 11 |
262 (word & 0x1) << 16, 17) << 2;
266 hppa_symbol_address(const char *sym)
268 struct minimal_symbol *minsym;
270 minsym = lookup_minimal_symbol (sym, NULL, NULL);
272 return SYMBOL_VALUE_ADDRESS (minsym);
274 return (CORE_ADDR)-1;
278 /* Compare the start address for two unwind entries returning 1 if
279 the first address is larger than the second, -1 if the second is
280 larger than the first, and zero if they are equal. */
283 compare_unwind_entries (const void *arg1, const void *arg2)
285 const struct unwind_table_entry *a = arg1;
286 const struct unwind_table_entry *b = arg2;
288 if (a->region_start > b->region_start)
290 else if (a->region_start < b->region_start)
297 record_text_segment_lowaddr (bfd *abfd, asection *section, void *data)
299 if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
300 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
302 bfd_vma value = section->vma - section->filepos;
303 CORE_ADDR *low_text_segment_address = (CORE_ADDR *)data;
305 if (value < *low_text_segment_address)
306 *low_text_segment_address = value;
311 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
312 asection *section, unsigned int entries, unsigned int size,
313 CORE_ADDR text_offset)
315 /* We will read the unwind entries into temporary memory, then
316 fill in the actual unwind table. */
322 char *buf = alloca (size);
323 CORE_ADDR low_text_segment_address;
325 /* For ELF targets, then unwinds are supposed to
326 be segment relative offsets instead of absolute addresses.
328 Note that when loading a shared library (text_offset != 0) the
329 unwinds are already relative to the text_offset that will be
331 if (gdbarch_tdep (current_gdbarch)->is_elf && text_offset == 0)
333 low_text_segment_address = -1;
335 bfd_map_over_sections (objfile->obfd,
336 record_text_segment_lowaddr,
337 &low_text_segment_address);
339 text_offset = low_text_segment_address;
342 bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
344 /* Now internalize the information being careful to handle host/target
346 for (i = 0; i < entries; i++)
348 table[i].region_start = bfd_get_32 (objfile->obfd,
350 table[i].region_start += text_offset;
352 table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
353 table[i].region_end += text_offset;
355 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
357 table[i].Cannot_unwind = (tmp >> 31) & 0x1;
358 table[i].Millicode = (tmp >> 30) & 0x1;
359 table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
360 table[i].Region_description = (tmp >> 27) & 0x3;
361 table[i].reserved1 = (tmp >> 26) & 0x1;
362 table[i].Entry_SR = (tmp >> 25) & 0x1;
363 table[i].Entry_FR = (tmp >> 21) & 0xf;
364 table[i].Entry_GR = (tmp >> 16) & 0x1f;
365 table[i].Args_stored = (tmp >> 15) & 0x1;
366 table[i].Variable_Frame = (tmp >> 14) & 0x1;
367 table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
368 table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
369 table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
370 table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
371 table[i].Ada_Region = (tmp >> 9) & 0x1;
372 table[i].cxx_info = (tmp >> 8) & 0x1;
373 table[i].cxx_try_catch = (tmp >> 7) & 0x1;
374 table[i].sched_entry_seq = (tmp >> 6) & 0x1;
375 table[i].reserved2 = (tmp >> 5) & 0x1;
376 table[i].Save_SP = (tmp >> 4) & 0x1;
377 table[i].Save_RP = (tmp >> 3) & 0x1;
378 table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
379 table[i].extn_ptr_defined = (tmp >> 1) & 0x1;
380 table[i].Cleanup_defined = tmp & 0x1;
381 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
383 table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
384 table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
385 table[i].Large_frame = (tmp >> 29) & 0x1;
386 table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1;
387 table[i].reserved4 = (tmp >> 27) & 0x1;
388 table[i].Total_frame_size = tmp & 0x7ffffff;
390 /* Stub unwinds are handled elsewhere. */
391 table[i].stub_unwind.stub_type = 0;
392 table[i].stub_unwind.padding = 0;
397 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
398 the object file. This info is used mainly by find_unwind_entry() to find
399 out the stack frame size and frame pointer used by procedures. We put
400 everything on the psymbol obstack in the objfile so that it automatically
401 gets freed when the objfile is destroyed. */
404 read_unwind_info (struct objfile *objfile)
406 asection *unwind_sec, *stub_unwind_sec;
407 unsigned unwind_size, stub_unwind_size, total_size;
408 unsigned index, unwind_entries;
409 unsigned stub_entries, total_entries;
410 CORE_ADDR text_offset;
411 struct hppa_unwind_info *ui;
412 struct hppa_objfile_private *obj_private;
414 text_offset = ANOFFSET (objfile->section_offsets, 0);
415 ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
416 sizeof (struct hppa_unwind_info));
422 /* For reasons unknown the HP PA64 tools generate multiple unwinder
423 sections in a single executable. So we just iterate over every
424 section in the BFD looking for unwinder sections intead of trying
425 to do a lookup with bfd_get_section_by_name.
427 First determine the total size of the unwind tables so that we
428 can allocate memory in a nice big hunk. */
430 for (unwind_sec = objfile->obfd->sections;
432 unwind_sec = unwind_sec->next)
434 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
435 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
437 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
438 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
440 total_entries += unwind_entries;
444 /* Now compute the size of the stub unwinds. Note the ELF tools do not
445 use stub unwinds at the curren time. */
446 stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
450 stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
451 stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
455 stub_unwind_size = 0;
459 /* Compute total number of unwind entries and their total size. */
460 total_entries += stub_entries;
461 total_size = total_entries * sizeof (struct unwind_table_entry);
463 /* Allocate memory for the unwind table. */
464 ui->table = (struct unwind_table_entry *)
465 obstack_alloc (&objfile->objfile_obstack, total_size);
466 ui->last = total_entries - 1;
468 /* Now read in each unwind section and internalize the standard unwind
471 for (unwind_sec = objfile->obfd->sections;
473 unwind_sec = unwind_sec->next)
475 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
476 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
478 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
479 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
481 internalize_unwinds (objfile, &ui->table[index], unwind_sec,
482 unwind_entries, unwind_size, text_offset);
483 index += unwind_entries;
487 /* Now read in and internalize the stub unwind entries. */
488 if (stub_unwind_size > 0)
491 char *buf = alloca (stub_unwind_size);
493 /* Read in the stub unwind entries. */
494 bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
495 0, stub_unwind_size);
497 /* Now convert them into regular unwind entries. */
498 for (i = 0; i < stub_entries; i++, index++)
500 /* Clear out the next unwind entry. */
501 memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
503 /* Convert offset & size into region_start and region_end.
504 Stuff away the stub type into "reserved" fields. */
505 ui->table[index].region_start = bfd_get_32 (objfile->obfd,
507 ui->table[index].region_start += text_offset;
509 ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
512 ui->table[index].region_end
513 = ui->table[index].region_start + 4 *
514 (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
520 /* Unwind table needs to be kept sorted. */
521 qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
522 compare_unwind_entries);
524 /* Keep a pointer to the unwind information. */
525 obj_private = (struct hppa_objfile_private *)
526 objfile_data (objfile, hppa_objfile_priv_data);
527 if (obj_private == NULL)
529 obj_private = (struct hppa_objfile_private *)
530 obstack_alloc (&objfile->objfile_obstack,
531 sizeof (struct hppa_objfile_private));
532 set_objfile_data (objfile, hppa_objfile_priv_data, obj_private);
533 obj_private->unwind_info = NULL;
534 obj_private->so_info = NULL;
537 obj_private->unwind_info = ui;
540 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
541 of the objfiles seeking the unwind table entry for this PC. Each objfile
542 contains a sorted list of struct unwind_table_entry. Since we do a binary
543 search of the unwind tables, we depend upon them to be sorted. */
545 struct unwind_table_entry *
546 find_unwind_entry (CORE_ADDR pc)
548 int first, middle, last;
549 struct objfile *objfile;
550 struct hppa_objfile_private *priv;
553 fprintf_unfiltered (gdb_stdlog, "{ find_unwind_entry 0x%s -> ",
556 /* A function at address 0? Not in HP-UX! */
557 if (pc == (CORE_ADDR) 0)
560 fprintf_unfiltered (gdb_stdlog, "NULL }\n");
564 ALL_OBJFILES (objfile)
566 struct hppa_unwind_info *ui;
568 priv = objfile_data (objfile, hppa_objfile_priv_data);
570 ui = ((struct hppa_objfile_private *) priv)->unwind_info;
574 read_unwind_info (objfile);
575 priv = objfile_data (objfile, hppa_objfile_priv_data);
577 error ("Internal error reading unwind information.");
578 ui = ((struct hppa_objfile_private *) priv)->unwind_info;
581 /* First, check the cache */
584 && pc >= ui->cache->region_start
585 && pc <= ui->cache->region_end)
588 fprintf_unfiltered (gdb_stdlog, "0x%s (cached) }\n",
589 paddr_nz ((CORE_ADDR) ui->cache));
593 /* Not in the cache, do a binary search */
598 while (first <= last)
600 middle = (first + last) / 2;
601 if (pc >= ui->table[middle].region_start
602 && pc <= ui->table[middle].region_end)
604 ui->cache = &ui->table[middle];
606 fprintf_unfiltered (gdb_stdlog, "0x%s }\n",
607 paddr_nz ((CORE_ADDR) ui->cache));
608 return &ui->table[middle];
611 if (pc < ui->table[middle].region_start)
616 } /* ALL_OBJFILES() */
619 fprintf_unfiltered (gdb_stdlog, "NULL (not found) }\n");
624 static const unsigned char *
625 hppa_breakpoint_from_pc (CORE_ADDR *pc, int *len)
627 static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
628 (*len) = sizeof (breakpoint);
632 /* Return the name of a register. */
635 hppa32_register_name (int i)
637 static char *names[] = {
638 "flags", "r1", "rp", "r3",
639 "r4", "r5", "r6", "r7",
640 "r8", "r9", "r10", "r11",
641 "r12", "r13", "r14", "r15",
642 "r16", "r17", "r18", "r19",
643 "r20", "r21", "r22", "r23",
644 "r24", "r25", "r26", "dp",
645 "ret0", "ret1", "sp", "r31",
646 "sar", "pcoqh", "pcsqh", "pcoqt",
647 "pcsqt", "eiem", "iir", "isr",
648 "ior", "ipsw", "goto", "sr4",
649 "sr0", "sr1", "sr2", "sr3",
650 "sr5", "sr6", "sr7", "cr0",
651 "cr8", "cr9", "ccr", "cr12",
652 "cr13", "cr24", "cr25", "cr26",
653 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
654 "fpsr", "fpe1", "fpe2", "fpe3",
655 "fpe4", "fpe5", "fpe6", "fpe7",
656 "fr4", "fr4R", "fr5", "fr5R",
657 "fr6", "fr6R", "fr7", "fr7R",
658 "fr8", "fr8R", "fr9", "fr9R",
659 "fr10", "fr10R", "fr11", "fr11R",
660 "fr12", "fr12R", "fr13", "fr13R",
661 "fr14", "fr14R", "fr15", "fr15R",
662 "fr16", "fr16R", "fr17", "fr17R",
663 "fr18", "fr18R", "fr19", "fr19R",
664 "fr20", "fr20R", "fr21", "fr21R",
665 "fr22", "fr22R", "fr23", "fr23R",
666 "fr24", "fr24R", "fr25", "fr25R",
667 "fr26", "fr26R", "fr27", "fr27R",
668 "fr28", "fr28R", "fr29", "fr29R",
669 "fr30", "fr30R", "fr31", "fr31R"
671 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
678 hppa64_register_name (int i)
680 static char *names[] = {
681 "flags", "r1", "rp", "r3",
682 "r4", "r5", "r6", "r7",
683 "r8", "r9", "r10", "r11",
684 "r12", "r13", "r14", "r15",
685 "r16", "r17", "r18", "r19",
686 "r20", "r21", "r22", "r23",
687 "r24", "r25", "r26", "dp",
688 "ret0", "ret1", "sp", "r31",
689 "sar", "pcoqh", "pcsqh", "pcoqt",
690 "pcsqt", "eiem", "iir", "isr",
691 "ior", "ipsw", "goto", "sr4",
692 "sr0", "sr1", "sr2", "sr3",
693 "sr5", "sr6", "sr7", "cr0",
694 "cr8", "cr9", "ccr", "cr12",
695 "cr13", "cr24", "cr25", "cr26",
696 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
697 "fpsr", "fpe1", "fpe2", "fpe3",
698 "fr4", "fr5", "fr6", "fr7",
699 "fr8", "fr9", "fr10", "fr11",
700 "fr12", "fr13", "fr14", "fr15",
701 "fr16", "fr17", "fr18", "fr19",
702 "fr20", "fr21", "fr22", "fr23",
703 "fr24", "fr25", "fr26", "fr27",
704 "fr28", "fr29", "fr30", "fr31"
706 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
712 /* This function pushes a stack frame with arguments as part of the
713 inferior function calling mechanism.
715 This is the version of the function for the 32-bit PA machines, in
716 which later arguments appear at lower addresses. (The stack always
717 grows towards higher addresses.)
719 We simply allocate the appropriate amount of stack space and put
720 arguments into their proper slots. */
723 hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
724 struct regcache *regcache, CORE_ADDR bp_addr,
725 int nargs, struct value **args, CORE_ADDR sp,
726 int struct_return, CORE_ADDR struct_addr)
728 /* Stack base address at which any pass-by-reference parameters are
730 CORE_ADDR struct_end = 0;
731 /* Stack base address at which the first parameter is stored. */
732 CORE_ADDR param_end = 0;
734 /* The inner most end of the stack after all the parameters have
736 CORE_ADDR new_sp = 0;
738 /* Two passes. First pass computes the location of everything,
739 second pass writes the bytes out. */
742 /* Global pointer (r19) of the function we are trying to call. */
745 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
747 for (write_pass = 0; write_pass < 2; write_pass++)
749 CORE_ADDR struct_ptr = 0;
750 /* The first parameter goes into sp-36, each stack slot is 4-bytes.
751 struct_ptr is adjusted for each argument below, so the first
752 argument will end up at sp-36. */
753 CORE_ADDR param_ptr = 32;
755 int small_struct = 0;
757 for (i = 0; i < nargs; i++)
759 struct value *arg = args[i];
760 struct type *type = check_typedef (value_type (arg));
761 /* The corresponding parameter that is pushed onto the
762 stack, and [possibly] passed in a register. */
765 memset (param_val, 0, sizeof param_val);
766 if (TYPE_LENGTH (type) > 8)
768 /* Large parameter, pass by reference. Store the value
769 in "struct" area and then pass its address. */
771 struct_ptr += align_up (TYPE_LENGTH (type), 8);
773 write_memory (struct_end - struct_ptr, VALUE_CONTENTS (arg),
775 store_unsigned_integer (param_val, 4, struct_end - struct_ptr);
777 else if (TYPE_CODE (type) == TYPE_CODE_INT
778 || TYPE_CODE (type) == TYPE_CODE_ENUM)
780 /* Integer value store, right aligned. "unpack_long"
781 takes care of any sign-extension problems. */
782 param_len = align_up (TYPE_LENGTH (type), 4);
783 store_unsigned_integer (param_val, param_len,
785 VALUE_CONTENTS (arg)));
787 else if (TYPE_CODE (type) == TYPE_CODE_FLT)
789 /* Floating point value store, right aligned. */
790 param_len = align_up (TYPE_LENGTH (type), 4);
791 memcpy (param_val, VALUE_CONTENTS (arg), param_len);
795 param_len = align_up (TYPE_LENGTH (type), 4);
797 /* Small struct value are stored right-aligned. */
798 memcpy (param_val + param_len - TYPE_LENGTH (type),
799 VALUE_CONTENTS (arg), TYPE_LENGTH (type));
801 /* Structures of size 5, 6 and 7 bytes are special in that
802 the higher-ordered word is stored in the lower-ordered
803 argument, and even though it is a 8-byte quantity the
804 registers need not be 8-byte aligned. */
805 if (param_len > 4 && param_len < 8)
809 param_ptr += param_len;
810 if (param_len == 8 && !small_struct)
811 param_ptr = align_up (param_ptr, 8);
813 /* First 4 non-FP arguments are passed in gr26-gr23.
814 First 4 32-bit FP arguments are passed in fr4L-fr7L.
815 First 2 64-bit FP arguments are passed in fr5 and fr7.
817 The rest go on the stack, starting at sp-36, towards lower
818 addresses. 8-byte arguments must be aligned to a 8-byte
822 write_memory (param_end - param_ptr, param_val, param_len);
824 /* There are some cases when we don't know the type
825 expected by the callee (e.g. for variadic functions), so
826 pass the parameters in both general and fp regs. */
829 int grreg = 26 - (param_ptr - 36) / 4;
830 int fpLreg = 72 + (param_ptr - 36) / 4 * 2;
831 int fpreg = 74 + (param_ptr - 32) / 8 * 4;
833 regcache_cooked_write (regcache, grreg, param_val);
834 regcache_cooked_write (regcache, fpLreg, param_val);
838 regcache_cooked_write (regcache, grreg + 1,
841 regcache_cooked_write (regcache, fpreg, param_val);
842 regcache_cooked_write (regcache, fpreg + 1,
849 /* Update the various stack pointers. */
852 struct_end = sp + align_up (struct_ptr, 64);
853 /* PARAM_PTR already accounts for all the arguments passed
854 by the user. However, the ABI mandates minimum stack
855 space allocations for outgoing arguments. The ABI also
856 mandates minimum stack alignments which we must
858 param_end = struct_end + align_up (param_ptr, 64);
862 /* If a structure has to be returned, set up register 28 to hold its
865 write_register (28, struct_addr);
867 gp = tdep->find_global_pointer (function);
870 write_register (19, gp);
872 /* Set the return address. */
873 regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
875 /* Update the Stack Pointer. */
876 regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end);
881 /* This function pushes a stack frame with arguments as part of the
882 inferior function calling mechanism.
884 This is the version for the PA64, in which later arguments appear
885 at higher addresses. (The stack always grows towards higher
888 We simply allocate the appropriate amount of stack space and put
889 arguments into their proper slots.
891 This ABI also requires that the caller provide an argument pointer
892 to the callee, so we do that too. */
895 hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
896 struct regcache *regcache, CORE_ADDR bp_addr,
897 int nargs, struct value **args, CORE_ADDR sp,
898 int struct_return, CORE_ADDR struct_addr)
900 /* NOTE: cagney/2004-02-27: This is a guess - its implemented by
901 reverse engineering testsuite failures. */
903 /* Stack base address at which any pass-by-reference parameters are
905 CORE_ADDR struct_end = 0;
906 /* Stack base address at which the first parameter is stored. */
907 CORE_ADDR param_end = 0;
909 /* The inner most end of the stack after all the parameters have
911 CORE_ADDR new_sp = 0;
913 /* Two passes. First pass computes the location of everything,
914 second pass writes the bytes out. */
916 for (write_pass = 0; write_pass < 2; write_pass++)
918 CORE_ADDR struct_ptr = 0;
919 CORE_ADDR param_ptr = 0;
921 for (i = 0; i < nargs; i++)
923 struct value *arg = args[i];
924 struct type *type = check_typedef (value_type (arg));
925 if ((TYPE_CODE (type) == TYPE_CODE_INT
926 || TYPE_CODE (type) == TYPE_CODE_ENUM)
927 && TYPE_LENGTH (type) <= 8)
929 /* Integer value store, right aligned. "unpack_long"
930 takes care of any sign-extension problems. */
934 ULONGEST val = unpack_long (type, VALUE_CONTENTS (arg));
935 int reg = 27 - param_ptr / 8;
936 write_memory_unsigned_integer (param_end - param_ptr,
939 regcache_cooked_write_unsigned (regcache, reg, val);
944 /* Small struct value, store left aligned? */
946 if (TYPE_LENGTH (type) > 8)
948 param_ptr = align_up (param_ptr, 16);
949 reg = 26 - param_ptr / 8;
950 param_ptr += align_up (TYPE_LENGTH (type), 16);
954 param_ptr = align_up (param_ptr, 8);
955 reg = 26 - param_ptr / 8;
956 param_ptr += align_up (TYPE_LENGTH (type), 8);
961 write_memory (param_end - param_ptr, VALUE_CONTENTS (arg),
963 for (byte = 0; byte < TYPE_LENGTH (type); byte += 8)
967 int len = min (8, TYPE_LENGTH (type) - byte);
968 regcache_cooked_write_part (regcache, reg, 0, len,
969 VALUE_CONTENTS (arg) + byte);
976 /* Update the various stack pointers. */
979 struct_end = sp + struct_ptr;
980 /* PARAM_PTR already accounts for all the arguments passed
981 by the user. However, the ABI mandates minimum stack
982 space allocations for outgoing arguments. The ABI also
983 mandates minimum stack alignments which we must
985 param_end = struct_end + max (align_up (param_ptr, 16), 64);
989 /* If a structure has to be returned, set up register 28 to hold its
992 write_register (28, struct_addr);
994 /* Set the return address. */
995 regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
997 /* Update the Stack Pointer. */
998 regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end + 64);
1000 /* The stack will have 32 bytes of additional space for a frame marker. */
1001 return param_end + 64;
1005 hppa32_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
1007 struct target_ops *targ)
1014 target_read_memory(plabel, (char *)&addr, 4);
1021 hppa32_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1023 /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_
1025 return align_up (addr, 64);
1028 /* Force all frames to 16-byte alignment. Better safe than sorry. */
1031 hppa64_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1033 /* Just always 16-byte align. */
1034 return align_up (addr, 16);
1038 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
1042 hppa_target_read_pc (ptid_t ptid)
1044 int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1046 /* The following test does not belong here. It is OS-specific, and belongs
1048 /* Test SS_INSYSCALL */
1050 return read_register_pid (31, ptid) & ~0x3;
1052 return read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid) & ~0x3;
1055 /* Write out the PC. If currently in a syscall, then also write the new
1056 PC value into %r31. */
1059 hppa_target_write_pc (CORE_ADDR v, ptid_t ptid)
1061 int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1063 /* The following test does not belong here. It is OS-specific, and belongs
1065 /* If in a syscall, then set %r31. Also make sure to get the
1066 privilege bits set correctly. */
1067 /* Test SS_INSYSCALL */
1069 write_register_pid (31, v | 0x3, ptid);
1071 write_register_pid (HPPA_PCOQ_HEAD_REGNUM, v, ptid);
1072 write_register_pid (HPPA_PCOQ_TAIL_REGNUM, v + 4, ptid);
1075 /* return the alignment of a type in bytes. Structures have the maximum
1076 alignment required by their fields. */
1079 hppa_alignof (struct type *type)
1081 int max_align, align, i;
1082 CHECK_TYPEDEF (type);
1083 switch (TYPE_CODE (type))
1088 return TYPE_LENGTH (type);
1089 case TYPE_CODE_ARRAY:
1090 return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
1091 case TYPE_CODE_STRUCT:
1092 case TYPE_CODE_UNION:
1094 for (i = 0; i < TYPE_NFIELDS (type); i++)
1096 /* Bit fields have no real alignment. */
1097 /* if (!TYPE_FIELD_BITPOS (type, i)) */
1098 if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */
1100 align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
1101 max_align = max (max_align, align);
1110 /* For the given instruction (INST), return any adjustment it makes
1111 to the stack pointer or zero for no adjustment.
1113 This only handles instructions commonly found in prologues. */
1116 prologue_inst_adjust_sp (unsigned long inst)
1118 /* This must persist across calls. */
1119 static int save_high21;
1121 /* The most common way to perform a stack adjustment ldo X(sp),sp */
1122 if ((inst & 0xffffc000) == 0x37de0000)
1123 return hppa_extract_14 (inst);
1126 if ((inst & 0xffe00000) == 0x6fc00000)
1127 return hppa_extract_14 (inst);
1129 /* std,ma X,D(sp) */
1130 if ((inst & 0xffe00008) == 0x73c00008)
1131 return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
1133 /* addil high21,%r1; ldo low11,(%r1),%r30)
1134 save high bits in save_high21 for later use. */
1135 if ((inst & 0xffe00000) == 0x28200000)
1137 save_high21 = hppa_extract_21 (inst);
1141 if ((inst & 0xffff0000) == 0x343e0000)
1142 return save_high21 + hppa_extract_14 (inst);
1144 /* fstws as used by the HP compilers. */
1145 if ((inst & 0xffffffe0) == 0x2fd01220)
1146 return hppa_extract_5_load (inst);
1148 /* No adjustment. */
1152 /* Return nonzero if INST is a branch of some kind, else return zero. */
1155 is_branch (unsigned long inst)
1184 /* Return the register number for a GR which is saved by INST or
1185 zero it INST does not save a GR. */
1188 inst_saves_gr (unsigned long inst)
1190 /* Does it look like a stw? */
1191 if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
1192 || (inst >> 26) == 0x1f
1193 || ((inst >> 26) == 0x1f
1194 && ((inst >> 6) == 0xa)))
1195 return hppa_extract_5R_store (inst);
1197 /* Does it look like a std? */
1198 if ((inst >> 26) == 0x1c
1199 || ((inst >> 26) == 0x03
1200 && ((inst >> 6) & 0xf) == 0xb))
1201 return hppa_extract_5R_store (inst);
1203 /* Does it look like a stwm? GCC & HPC may use this in prologues. */
1204 if ((inst >> 26) == 0x1b)
1205 return hppa_extract_5R_store (inst);
1207 /* Does it look like sth or stb? HPC versions 9.0 and later use these
1209 if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
1210 || ((inst >> 26) == 0x3
1211 && (((inst >> 6) & 0xf) == 0x8
1212 || (inst >> 6) & 0xf) == 0x9))
1213 return hppa_extract_5R_store (inst);
1218 /* Return the register number for a FR which is saved by INST or
1219 zero it INST does not save a FR.
1221 Note we only care about full 64bit register stores (that's the only
1222 kind of stores the prologue will use).
1224 FIXME: What about argument stores with the HP compiler in ANSI mode? */
1227 inst_saves_fr (unsigned long inst)
1229 /* is this an FSTD ? */
1230 if ((inst & 0xfc00dfc0) == 0x2c001200)
1231 return hppa_extract_5r_store (inst);
1232 if ((inst & 0xfc000002) == 0x70000002)
1233 return hppa_extract_5R_store (inst);
1234 /* is this an FSTW ? */
1235 if ((inst & 0xfc00df80) == 0x24001200)
1236 return hppa_extract_5r_store (inst);
1237 if ((inst & 0xfc000002) == 0x7c000000)
1238 return hppa_extract_5R_store (inst);
1242 /* Advance PC across any function entry prologue instructions
1243 to reach some "real" code.
1245 Use information in the unwind table to determine what exactly should
1246 be in the prologue. */
1250 skip_prologue_hard_way (CORE_ADDR pc, int stop_before_branch)
1253 CORE_ADDR orig_pc = pc;
1254 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
1255 unsigned long args_stored, status, i, restart_gr, restart_fr;
1256 struct unwind_table_entry *u;
1257 int final_iteration;
1263 u = find_unwind_entry (pc);
1267 /* If we are not at the beginning of a function, then return now. */
1268 if ((pc & ~0x3) != u->region_start)
1271 /* This is how much of a frame adjustment we need to account for. */
1272 stack_remaining = u->Total_frame_size << 3;
1274 /* Magic register saves we want to know about. */
1275 save_rp = u->Save_RP;
1276 save_sp = u->Save_SP;
1278 /* An indication that args may be stored into the stack. Unfortunately
1279 the HPUX compilers tend to set this in cases where no args were
1283 /* Turn the Entry_GR field into a bitmask. */
1285 for (i = 3; i < u->Entry_GR + 3; i++)
1287 /* Frame pointer gets saved into a special location. */
1288 if (u->Save_SP && i == HPPA_FP_REGNUM)
1291 save_gr |= (1 << i);
1293 save_gr &= ~restart_gr;
1295 /* Turn the Entry_FR field into a bitmask too. */
1297 for (i = 12; i < u->Entry_FR + 12; i++)
1298 save_fr |= (1 << i);
1299 save_fr &= ~restart_fr;
1301 final_iteration = 0;
1303 /* Loop until we find everything of interest or hit a branch.
1305 For unoptimized GCC code and for any HP CC code this will never ever
1306 examine any user instructions.
1308 For optimzied GCC code we're faced with problems. GCC will schedule
1309 its prologue and make prologue instructions available for delay slot
1310 filling. The end result is user code gets mixed in with the prologue
1311 and a prologue instruction may be in the delay slot of the first branch
1314 Some unexpected things are expected with debugging optimized code, so
1315 we allow this routine to walk past user instructions in optimized
1317 while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
1320 unsigned int reg_num;
1321 unsigned long old_stack_remaining, old_save_gr, old_save_fr;
1322 unsigned long old_save_rp, old_save_sp, next_inst;
1324 /* Save copies of all the triggers so we can compare them later
1326 old_save_gr = save_gr;
1327 old_save_fr = save_fr;
1328 old_save_rp = save_rp;
1329 old_save_sp = save_sp;
1330 old_stack_remaining = stack_remaining;
1332 status = deprecated_read_memory_nobpt (pc, buf, 4);
1333 inst = extract_unsigned_integer (buf, 4);
1339 /* Note the interesting effects of this instruction. */
1340 stack_remaining -= prologue_inst_adjust_sp (inst);
1342 /* There are limited ways to store the return pointer into the
1344 if (inst == 0x6bc23fd9 || inst == 0x0fc212c1)
1347 /* These are the only ways we save SP into the stack. At this time
1348 the HP compilers never bother to save SP into the stack. */
1349 if ((inst & 0xffffc000) == 0x6fc10000
1350 || (inst & 0xffffc00c) == 0x73c10008)
1353 /* Are we loading some register with an offset from the argument
1355 if ((inst & 0xffe00000) == 0x37a00000
1356 || (inst & 0xffffffe0) == 0x081d0240)
1362 /* Account for general and floating-point register saves. */
1363 reg_num = inst_saves_gr (inst);
1364 save_gr &= ~(1 << reg_num);
1366 /* Ugh. Also account for argument stores into the stack.
1367 Unfortunately args_stored only tells us that some arguments
1368 where stored into the stack. Not how many or what kind!
1370 This is a kludge as on the HP compiler sets this bit and it
1371 never does prologue scheduling. So once we see one, skip past
1372 all of them. We have similar code for the fp arg stores below.
1374 FIXME. Can still die if we have a mix of GR and FR argument
1376 if (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
1378 while (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
1381 status = deprecated_read_memory_nobpt (pc, buf, 4);
1382 inst = extract_unsigned_integer (buf, 4);
1385 reg_num = inst_saves_gr (inst);
1391 reg_num = inst_saves_fr (inst);
1392 save_fr &= ~(1 << reg_num);
1394 status = deprecated_read_memory_nobpt (pc + 4, buf, 4);
1395 next_inst = extract_unsigned_integer (buf, 4);
1401 /* We've got to be read to handle the ldo before the fp register
1403 if ((inst & 0xfc000000) == 0x34000000
1404 && inst_saves_fr (next_inst) >= 4
1405 && inst_saves_fr (next_inst) <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1407 /* So we drop into the code below in a reasonable state. */
1408 reg_num = inst_saves_fr (next_inst);
1412 /* Ugh. Also account for argument stores into the stack.
1413 This is a kludge as on the HP compiler sets this bit and it
1414 never does prologue scheduling. So once we see one, skip past
1416 if (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1418 while (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
1421 status = deprecated_read_memory_nobpt (pc, buf, 4);
1422 inst = extract_unsigned_integer (buf, 4);
1425 if ((inst & 0xfc000000) != 0x34000000)
1427 status = deprecated_read_memory_nobpt (pc + 4, buf, 4);
1428 next_inst = extract_unsigned_integer (buf, 4);
1431 reg_num = inst_saves_fr (next_inst);
1437 /* Quit if we hit any kind of branch. This can happen if a prologue
1438 instruction is in the delay slot of the first call/branch. */
1439 if (is_branch (inst) && stop_before_branch)
1442 /* What a crock. The HP compilers set args_stored even if no
1443 arguments were stored into the stack (boo hiss). This could
1444 cause this code to then skip a bunch of user insns (up to the
1447 To combat this we try to identify when args_stored was bogusly
1448 set and clear it. We only do this when args_stored is nonzero,
1449 all other resources are accounted for, and nothing changed on
1452 && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
1453 && old_save_gr == save_gr && old_save_fr == save_fr
1454 && old_save_rp == save_rp && old_save_sp == save_sp
1455 && old_stack_remaining == stack_remaining)
1461 /* !stop_before_branch, so also look at the insn in the delay slot
1463 if (final_iteration)
1465 if (is_branch (inst))
1466 final_iteration = 1;
1469 /* We've got a tenative location for the end of the prologue. However
1470 because of limitations in the unwind descriptor mechanism we may
1471 have went too far into user code looking for the save of a register
1472 that does not exist. So, if there registers we expected to be saved
1473 but never were, mask them out and restart.
1475 This should only happen in optimized code, and should be very rare. */
1476 if (save_gr || (save_fr && !(restart_fr || restart_gr)))
1479 restart_gr = save_gr;
1480 restart_fr = save_fr;
1488 /* Return the address of the PC after the last prologue instruction if
1489 we can determine it from the debug symbols. Else return zero. */
1492 after_prologue (CORE_ADDR pc)
1494 struct symtab_and_line sal;
1495 CORE_ADDR func_addr, func_end;
1498 /* If we can not find the symbol in the partial symbol table, then
1499 there is no hope we can determine the function's start address
1501 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1504 /* Get the line associated with FUNC_ADDR. */
1505 sal = find_pc_line (func_addr, 0);
1507 /* There are only two cases to consider. First, the end of the source line
1508 is within the function bounds. In that case we return the end of the
1509 source line. Second is the end of the source line extends beyond the
1510 bounds of the current function. We need to use the slow code to
1511 examine instructions in that case.
1513 Anything else is simply a bug elsewhere. Fixing it here is absolutely
1514 the wrong thing to do. In fact, it should be entirely possible for this
1515 function to always return zero since the slow instruction scanning code
1516 is supposed to *always* work. If it does not, then it is a bug. */
1517 if (sal.end < func_end)
1523 /* To skip prologues, I use this predicate. Returns either PC itself
1524 if the code at PC does not look like a function prologue; otherwise
1525 returns an address that (if we're lucky) follows the prologue.
1527 hppa_skip_prologue is called by gdb to place a breakpoint in a function.
1528 It doesn't necessarily skips all the insns in the prologue. In fact
1529 we might not want to skip all the insns because a prologue insn may
1530 appear in the delay slot of the first branch, and we don't want to
1531 skip over the branch in that case. */
1534 hppa_skip_prologue (CORE_ADDR pc)
1538 CORE_ADDR post_prologue_pc;
1541 /* See if we can determine the end of the prologue via the symbol table.
1542 If so, then return either PC, or the PC after the prologue, whichever
1545 post_prologue_pc = after_prologue (pc);
1547 /* If after_prologue returned a useful address, then use it. Else
1548 fall back on the instruction skipping code.
1550 Some folks have claimed this causes problems because the breakpoint
1551 may be the first instruction of the prologue. If that happens, then
1552 the instruction skipping code has a bug that needs to be fixed. */
1553 if (post_prologue_pc != 0)
1554 return max (pc, post_prologue_pc);
1556 return (skip_prologue_hard_way (pc, 1));
1559 struct hppa_frame_cache
1562 struct trad_frame_saved_reg *saved_regs;
1565 static struct hppa_frame_cache *
1566 hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
1568 struct hppa_frame_cache *cache;
1573 struct unwind_table_entry *u;
1574 CORE_ADDR prologue_end;
1579 fprintf_unfiltered (gdb_stdlog, "{ hppa_frame_cache (frame=%d) -> ",
1580 frame_relative_level(next_frame));
1582 if ((*this_cache) != NULL)
1585 fprintf_unfiltered (gdb_stdlog, "base=0x%s (cached) }",
1586 paddr_nz (((struct hppa_frame_cache *)*this_cache)->base));
1587 return (*this_cache);
1589 cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
1590 (*this_cache) = cache;
1591 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1594 u = find_unwind_entry (frame_pc_unwind (next_frame));
1598 fprintf_unfiltered (gdb_stdlog, "base=NULL (no unwind entry) }");
1599 return (*this_cache);
1602 /* Turn the Entry_GR field into a bitmask. */
1604 for (i = 3; i < u->Entry_GR + 3; i++)
1606 /* Frame pointer gets saved into a special location. */
1607 if (u->Save_SP && i == HPPA_FP_REGNUM)
1610 saved_gr_mask |= (1 << i);
1613 /* Turn the Entry_FR field into a bitmask too. */
1615 for (i = 12; i < u->Entry_FR + 12; i++)
1616 saved_fr_mask |= (1 << i);
1618 /* Loop until we find everything of interest or hit a branch.
1620 For unoptimized GCC code and for any HP CC code this will never ever
1621 examine any user instructions.
1623 For optimized GCC code we're faced with problems. GCC will schedule
1624 its prologue and make prologue instructions available for delay slot
1625 filling. The end result is user code gets mixed in with the prologue
1626 and a prologue instruction may be in the delay slot of the first branch
1629 Some unexpected things are expected with debugging optimized code, so
1630 we allow this routine to walk past user instructions in optimized
1633 int final_iteration = 0;
1634 CORE_ADDR pc, end_pc;
1635 int looking_for_sp = u->Save_SP;
1636 int looking_for_rp = u->Save_RP;
1639 /* We have to use skip_prologue_hard_way instead of just
1640 skip_prologue_using_sal, in case we stepped into a function without
1641 symbol information. hppa_skip_prologue also bounds the returned
1642 pc by the passed in pc, so it will not return a pc in the next
1645 We used to call hppa_skip_prologue to find the end of the prologue,
1646 but if some non-prologue instructions get scheduled into the prologue,
1647 and the program is compiled with debug information, the "easy" way
1648 in hppa_skip_prologue will return a prologue end that is too early
1649 for us to notice any potential frame adjustments. */
1651 /* We used to use frame_func_unwind () to locate the beginning of the
1652 function to pass to skip_prologue (). However, when objects are
1653 compiled without debug symbols, frame_func_unwind can return the wrong
1654 function (or 0). We can do better than that by using unwind records. */
1656 prologue_end = skip_prologue_hard_way (u->region_start, 0);
1657 end_pc = frame_pc_unwind (next_frame);
1659 if (prologue_end != 0 && end_pc > prologue_end)
1660 end_pc = prologue_end;
1664 for (pc = u->region_start;
1665 ((saved_gr_mask || saved_fr_mask
1666 || looking_for_sp || looking_for_rp
1667 || frame_size < (u->Total_frame_size << 3))
1675 if (!safe_frame_unwind_memory (next_frame, pc, buf4,
1678 error ("Cannot read instruction at 0x%s\n", paddr_nz (pc));
1679 return (*this_cache);
1682 inst = extract_unsigned_integer (buf4, sizeof buf4);
1684 /* Note the interesting effects of this instruction. */
1685 frame_size += prologue_inst_adjust_sp (inst);
1687 /* There are limited ways to store the return pointer into the
1689 if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
1692 cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
1694 else if (inst == 0x6bc23fd1) /* stw rp,-0x18(sr0,sp) */
1697 cache->saved_regs[HPPA_RP_REGNUM].addr = -24;
1699 else if (inst == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
1702 cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
1705 /* Check to see if we saved SP into the stack. This also
1706 happens to indicate the location of the saved frame
1708 if ((inst & 0xffffc000) == 0x6fc10000 /* stw,ma r1,N(sr0,sp) */
1709 || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
1712 cache->saved_regs[HPPA_FP_REGNUM].addr = 0;
1714 else if (inst == 0x08030241) /* copy %r3, %r1 */
1719 /* Account for general and floating-point register saves. */
1720 reg = inst_saves_gr (inst);
1721 if (reg >= 3 && reg <= 18
1722 && (!u->Save_SP || reg != HPPA_FP_REGNUM))
1724 saved_gr_mask &= ~(1 << reg);
1725 if ((inst >> 26) == 0x1b && hppa_extract_14 (inst) >= 0)
1726 /* stwm with a positive displacement is a _post_
1728 cache->saved_regs[reg].addr = 0;
1729 else if ((inst & 0xfc00000c) == 0x70000008)
1730 /* A std has explicit post_modify forms. */
1731 cache->saved_regs[reg].addr = 0;
1736 if ((inst >> 26) == 0x1c)
1737 offset = (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
1738 else if ((inst >> 26) == 0x03)
1739 offset = hppa_low_hppa_sign_extend (inst & 0x1f, 5);
1741 offset = hppa_extract_14 (inst);
1743 /* Handle code with and without frame pointers. */
1745 cache->saved_regs[reg].addr = offset;
1747 cache->saved_regs[reg].addr = (u->Total_frame_size << 3) + offset;
1751 /* GCC handles callee saved FP regs a little differently.
1753 It emits an instruction to put the value of the start of
1754 the FP store area into %r1. It then uses fstds,ma with a
1755 basereg of %r1 for the stores.
1757 HP CC emits them at the current stack pointer modifying the
1758 stack pointer as it stores each register. */
1760 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
1761 if ((inst & 0xffffc000) == 0x34610000
1762 || (inst & 0xffffc000) == 0x37c10000)
1763 fp_loc = hppa_extract_14 (inst);
1765 reg = inst_saves_fr (inst);
1766 if (reg >= 12 && reg <= 21)
1768 /* Note +4 braindamage below is necessary because the FP
1769 status registers are internally 8 registers rather than
1770 the expected 4 registers. */
1771 saved_fr_mask &= ~(1 << reg);
1774 /* 1st HP CC FP register store. After this
1775 instruction we've set enough state that the GCC and
1776 HPCC code are both handled in the same manner. */
1777 cache->saved_regs[reg + HPPA_FP4_REGNUM + 4].addr = 0;
1782 cache->saved_regs[reg + HPPA_FP0_REGNUM + 4].addr = fp_loc;
1787 /* Quit if we hit any kind of branch the previous iteration. */
1788 if (final_iteration)
1790 /* We want to look precisely one instruction beyond the branch
1791 if we have not found everything yet. */
1792 if (is_branch (inst))
1793 final_iteration = 1;
1798 /* The frame base always represents the value of %sp at entry to
1799 the current function (and is thus equivalent to the "saved"
1801 CORE_ADDR this_sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1805 fprintf_unfiltered (gdb_stdlog, " (this_sp=0x%s, pc=0x%s, "
1806 "prologue_end=0x%s) ",
1808 paddr_nz (frame_pc_unwind (next_frame)),
1809 paddr_nz (prologue_end));
1811 /* Check to see if a frame pointer is available, and use it for
1812 frame unwinding if it is.
1814 There are some situations where we need to rely on the frame
1815 pointer to do stack unwinding. For example, if a function calls
1816 alloca (), the stack pointer can get adjusted inside the body of
1817 the function. In this case, the ABI requires that the compiler
1818 maintain a frame pointer for the function.
1820 The unwind record has a flag (alloca_frame) that indicates that
1821 a function has a variable frame; unfortunately, gcc/binutils
1822 does not set this flag. Instead, whenever a frame pointer is used
1823 and saved on the stack, the Save_SP flag is set. We use this to
1824 decide whether to use the frame pointer for unwinding.
1826 TODO: For the HP compiler, maybe we should use the alloca_frame flag
1827 instead of Save_SP. */
1829 fp = frame_unwind_register_unsigned (next_frame, HPPA_FP_REGNUM);
1831 if (frame_pc_unwind (next_frame) >= prologue_end
1832 && u->Save_SP && fp != 0)
1837 fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [frame pointer] }",
1838 paddr_nz (cache->base));
1841 && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM))
1843 /* Both we're expecting the SP to be saved and the SP has been
1844 saved. The entry SP value is saved at this frame's SP
1846 cache->base = read_memory_integer (this_sp, TARGET_PTR_BIT / 8);
1849 fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [saved] }",
1850 paddr_nz (cache->base));
1854 /* The prologue has been slowly allocating stack space. Adjust
1856 cache->base = this_sp - frame_size;
1858 fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [unwind adjust] } ",
1859 paddr_nz (cache->base));
1862 trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
1865 /* The PC is found in the "return register", "Millicode" uses "r31"
1866 as the return register while normal code uses "rp". */
1869 if (trad_frame_addr_p (cache->saved_regs, 31))
1870 cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[31];
1873 ULONGEST r31 = frame_unwind_register_unsigned (next_frame, 31);
1874 trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, r31);
1879 if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
1880 cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM];
1883 ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM);
1884 trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
1888 /* If Save_SP is set, then we expect the frame pointer to be saved in the
1889 frame. However, there is a one-insn window where we haven't saved it
1890 yet, but we've already clobbered it. Detect this case and fix it up.
1892 The prologue sequence for frame-pointer functions is:
1893 0: stw %rp, -20(%sp)
1896 c: stw,ma %r1, XX(%sp)
1898 So if we are at offset c, the r3 value that we want is not yet saved
1899 on the stack, but it's been overwritten. The prologue analyzer will
1900 set fp_in_r1 when it sees the copy insn so we know to get the value
1902 if (u->Save_SP && !trad_frame_addr_p (cache->saved_regs, HPPA_FP_REGNUM)
1905 ULONGEST r1 = frame_unwind_register_unsigned (next_frame, 1);
1906 trad_frame_set_value (cache->saved_regs, HPPA_FP_REGNUM, r1);
1910 /* Convert all the offsets into addresses. */
1912 for (reg = 0; reg < NUM_REGS; reg++)
1914 if (trad_frame_addr_p (cache->saved_regs, reg))
1915 cache->saved_regs[reg].addr += cache->base;
1920 fprintf_unfiltered (gdb_stdlog, "base=0x%s }",
1921 paddr_nz (((struct hppa_frame_cache *)*this_cache)->base));
1922 return (*this_cache);
1926 hppa_frame_this_id (struct frame_info *next_frame, void **this_cache,
1927 struct frame_id *this_id)
1929 struct hppa_frame_cache *info;
1930 CORE_ADDR pc = frame_pc_unwind (next_frame);
1931 struct unwind_table_entry *u;
1933 info = hppa_frame_cache (next_frame, this_cache);
1934 u = find_unwind_entry (pc);
1936 (*this_id) = frame_id_build (info->base, u->region_start);
1940 hppa_frame_prev_register (struct frame_info *next_frame,
1942 int regnum, int *optimizedp,
1943 enum lval_type *lvalp, CORE_ADDR *addrp,
1944 int *realnump, void *valuep)
1946 struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache);
1947 hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
1948 optimizedp, lvalp, addrp, realnump, valuep);
1951 static const struct frame_unwind hppa_frame_unwind =
1955 hppa_frame_prev_register
1958 static const struct frame_unwind *
1959 hppa_frame_unwind_sniffer (struct frame_info *next_frame)
1961 CORE_ADDR pc = frame_pc_unwind (next_frame);
1963 if (find_unwind_entry (pc))
1964 return &hppa_frame_unwind;
1969 /* This is a generic fallback frame unwinder that kicks in if we fail all
1970 the other ones. Normally we would expect the stub and regular unwinder
1971 to work, but in some cases we might hit a function that just doesn't
1972 have any unwind information available. In this case we try to do
1973 unwinding solely based on code reading. This is obviously going to be
1974 slow, so only use this as a last resort. Currently this will only
1975 identify the stack and pc for the frame. */
1977 static struct hppa_frame_cache *
1978 hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache)
1980 struct hppa_frame_cache *cache;
1981 unsigned int frame_size;
1983 CORE_ADDR pc, start_pc, end_pc, cur_pc;
1986 fprintf_unfiltered (gdb_stdlog, "{ hppa_fallback_frame_cache (frame=%d)-> ",
1987 frame_relative_level(next_frame));
1989 cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
1990 (*this_cache) = cache;
1991 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1993 pc = frame_func_unwind (next_frame);
1994 cur_pc = frame_pc_unwind (next_frame);
1998 find_pc_partial_function (pc, NULL, &start_pc, &end_pc);
2000 if (start_pc == 0 || end_pc == 0)
2002 error ("Cannot find bounds of current function (@0x%s), unwinding will "
2003 "fail.", paddr_nz (pc));
2007 if (end_pc > cur_pc)
2010 for (pc = start_pc; pc < end_pc; pc += 4)
2014 insn = read_memory_unsigned_integer (pc, 4);
2016 frame_size += prologue_inst_adjust_sp (insn);
2018 /* There are limited ways to store the return pointer into the
2020 if (insn == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
2022 cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
2025 else if (insn == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
2027 cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
2033 fprintf_unfiltered (gdb_stdlog, " frame_size = %d, found_rp = %d }\n",
2034 frame_size, found_rp);
2036 cache->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM) - frame_size;
2037 trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
2039 if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
2041 cache->saved_regs[HPPA_RP_REGNUM].addr += cache->base;
2042 cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM];
2046 ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM);
2047 trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp);
2054 hppa_fallback_frame_this_id (struct frame_info *next_frame, void **this_cache,
2055 struct frame_id *this_id)
2057 struct hppa_frame_cache *info =
2058 hppa_fallback_frame_cache (next_frame, this_cache);
2059 (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
2063 hppa_fallback_frame_prev_register (struct frame_info *next_frame,
2065 int regnum, int *optimizedp,
2066 enum lval_type *lvalp, CORE_ADDR *addrp,
2067 int *realnump, void *valuep)
2069 struct hppa_frame_cache *info =
2070 hppa_fallback_frame_cache (next_frame, this_cache);
2071 hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
2072 optimizedp, lvalp, addrp, realnump, valuep);
2075 static const struct frame_unwind hppa_fallback_frame_unwind =
2078 hppa_fallback_frame_this_id,
2079 hppa_fallback_frame_prev_register
2082 static const struct frame_unwind *
2083 hppa_fallback_unwind_sniffer (struct frame_info *next_frame)
2085 return &hppa_fallback_frame_unwind;
2088 /* Stub frames, used for all kinds of call stubs. */
2089 struct hppa_stub_unwind_cache
2092 struct trad_frame_saved_reg *saved_regs;
2095 static struct hppa_stub_unwind_cache *
2096 hppa_stub_frame_unwind_cache (struct frame_info *next_frame,
2099 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2100 struct hppa_stub_unwind_cache *info;
2101 struct unwind_table_entry *u;
2106 info = FRAME_OBSTACK_ZALLOC (struct hppa_stub_unwind_cache);
2108 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2110 info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
2112 if (gdbarch_osabi (gdbarch) == GDB_OSABI_HPUX_SOM)
2114 /* HPUX uses export stubs in function calls; the export stub clobbers
2115 the return value of the caller, and, later restores it from the
2117 u = find_unwind_entry (frame_pc_unwind (next_frame));
2119 if (u && u->stub_unwind.stub_type == EXPORT)
2121 info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].addr = info->base - 24;
2127 /* By default we assume that stubs do not change the rp. */
2128 info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM;
2134 hppa_stub_frame_this_id (struct frame_info *next_frame,
2135 void **this_prologue_cache,
2136 struct frame_id *this_id)
2138 struct hppa_stub_unwind_cache *info
2139 = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache);
2140 *this_id = frame_id_build (info->base, frame_pc_unwind (next_frame));
2144 hppa_stub_frame_prev_register (struct frame_info *next_frame,
2145 void **this_prologue_cache,
2146 int regnum, int *optimizedp,
2147 enum lval_type *lvalp, CORE_ADDR *addrp,
2148 int *realnump, void *valuep)
2150 struct hppa_stub_unwind_cache *info
2151 = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache);
2152 hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
2153 optimizedp, lvalp, addrp, realnump, valuep);
2156 static const struct frame_unwind hppa_stub_frame_unwind = {
2158 hppa_stub_frame_this_id,
2159 hppa_stub_frame_prev_register
2162 static const struct frame_unwind *
2163 hppa_stub_unwind_sniffer (struct frame_info *next_frame)
2165 CORE_ADDR pc = frame_pc_unwind (next_frame);
2166 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2167 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2170 || (tdep->in_solib_call_trampoline != NULL
2171 && tdep->in_solib_call_trampoline (pc, NULL))
2172 || IN_SOLIB_RETURN_TRAMPOLINE (pc, NULL))
2173 return &hppa_stub_frame_unwind;
2177 static struct frame_id
2178 hppa_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2180 return frame_id_build (frame_unwind_register_unsigned (next_frame,
2182 frame_pc_unwind (next_frame));
2186 hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2188 return frame_unwind_register_signed (next_frame, HPPA_PCOQ_HEAD_REGNUM) & ~3;
2191 /* Instead of this nasty cast, add a method pvoid() that prints out a
2192 host VOID data type (remember %p isn't portable). */
2195 hppa_pointer_to_address_hack (void *ptr)
2197 gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
2198 return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
2202 unwind_command (char *exp, int from_tty)
2205 struct unwind_table_entry *u;
2207 /* If we have an expression, evaluate it and use it as the address. */
2209 if (exp != 0 && *exp != 0)
2210 address = parse_and_eval_address (exp);
2214 u = find_unwind_entry (address);
2218 printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
2222 printf_unfiltered ("unwind_table_entry (0x%s):\n",
2223 paddr_nz (hppa_pointer_to_address_hack (u)));
2225 printf_unfiltered ("\tregion_start = ");
2226 print_address (u->region_start, gdb_stdout);
2227 gdb_flush (gdb_stdout);
2229 printf_unfiltered ("\n\tregion_end = ");
2230 print_address (u->region_end, gdb_stdout);
2231 gdb_flush (gdb_stdout);
2233 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
2235 printf_unfiltered ("\n\tflags =");
2236 pif (Cannot_unwind);
2238 pif (Millicode_save_sr0);
2241 pif (Variable_Frame);
2242 pif (Separate_Package_Body);
2243 pif (Frame_Extension_Millicode);
2244 pif (Stack_Overflow_Check);
2245 pif (Two_Instruction_SP_Increment);
2249 pif (Save_MRP_in_frame);
2250 pif (extn_ptr_defined);
2251 pif (Cleanup_defined);
2252 pif (MPE_XL_interrupt_marker);
2253 pif (HP_UX_interrupt_marker);
2256 putchar_unfiltered ('\n');
2258 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
2260 pin (Region_description);
2263 pin (Total_frame_size);
2267 hppa_pc_requires_run_before_use (CORE_ADDR pc)
2269 /* Sometimes we may pluck out a minimal symbol that has a negative address.
2271 An example of this occurs when an a.out is linked against a foo.sl.
2272 The foo.sl defines a global bar(), and the a.out declares a signature
2273 for bar(). However, the a.out doesn't directly call bar(), but passes
2274 its address in another call.
2276 If you have this scenario and attempt to "break bar" before running,
2277 gdb will find a minimal symbol for bar() in the a.out. But that
2278 symbol's address will be negative. What this appears to denote is
2279 an index backwards from the base of the procedure linkage table (PLT)
2280 into the data linkage table (DLT), the end of which is contiguous
2281 with the start of the PLT. This is clearly not a valid address for
2282 us to set a breakpoint on.
2284 Note that one must be careful in how one checks for a negative address.
2285 0xc0000000 is a legitimate address of something in a shared text
2286 segment, for example. Since I don't know what the possible range
2287 is of these "really, truly negative" addresses that come from the
2288 minimal symbols, I'm resorting to the gross hack of checking the
2289 top byte of the address for all 1's. Sigh. */
2291 return (!target_has_stack && (pc & 0xFF000000));
2295 hppa_instruction_nullified (struct gdbarch *gdbarch, struct regcache *regcache)
2297 ULONGEST tmp, ipsw, flags;
2299 regcache_cooked_read (regcache, HPPA_IPSW_REGNUM, &tmp);
2300 ipsw = extract_unsigned_integer (&tmp,
2301 register_size (gdbarch, HPPA_IPSW_REGNUM));
2303 regcache_cooked_read (regcache, HPPA_FLAGS_REGNUM, &tmp);
2304 flags = extract_unsigned_integer (&tmp,
2305 register_size (gdbarch, HPPA_FLAGS_REGNUM));
2307 return ((ipsw & 0x00200000) && !(flags & 0x2));
2310 /* Return the GDB type object for the "standard" data type of data
2313 static struct type *
2314 hppa32_register_type (struct gdbarch *gdbarch, int reg_nr)
2316 if (reg_nr < HPPA_FP4_REGNUM)
2317 return builtin_type_uint32;
2319 return builtin_type_ieee_single_big;
2322 /* Return the GDB type object for the "standard" data type of data
2323 in register N. hppa64 version. */
2325 static struct type *
2326 hppa64_register_type (struct gdbarch *gdbarch, int reg_nr)
2328 if (reg_nr < HPPA_FP4_REGNUM)
2329 return builtin_type_uint64;
2331 return builtin_type_ieee_double_big;
2334 /* Return True if REGNUM is not a register available to the user
2335 through ptrace(). */
2338 hppa_cannot_store_register (int regnum)
2341 || regnum == HPPA_PCSQ_HEAD_REGNUM
2342 || (regnum >= HPPA_PCSQ_TAIL_REGNUM && regnum < HPPA_IPSW_REGNUM)
2343 || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA_FP4_REGNUM));
2348 hppa_smash_text_address (CORE_ADDR addr)
2350 /* The low two bits of the PC on the PA contain the privilege level.
2351 Some genius implementing a (non-GCC) compiler apparently decided
2352 this means that "addresses" in a text section therefore include a
2353 privilege level, and thus symbol tables should contain these bits.
2354 This seems like a bonehead thing to do--anyway, it seems to work
2355 for our purposes to just ignore those bits. */
2357 return (addr &= ~0x3);
2360 /* Get the ith function argument for the current function. */
2362 hppa_fetch_pointer_argument (struct frame_info *frame, int argi,
2366 get_frame_register (frame, HPPA_R0_REGNUM + 26 - argi, &addr);
2371 hppa_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2372 int regnum, void *buf)
2376 regcache_raw_read_unsigned (regcache, regnum, &tmp);
2377 if (regnum == HPPA_PCOQ_HEAD_REGNUM || regnum == HPPA_PCOQ_TAIL_REGNUM)
2379 store_unsigned_integer (buf, sizeof(tmp), tmp);
2383 hppa_find_global_pointer (struct value *function)
2389 hppa_frame_prev_register_helper (struct frame_info *next_frame,
2390 struct trad_frame_saved_reg saved_regs[],
2391 int regnum, int *optimizedp,
2392 enum lval_type *lvalp, CORE_ADDR *addrp,
2393 int *realnump, void *valuep)
2395 if (regnum == HPPA_PCOQ_TAIL_REGNUM)
2401 trad_frame_get_prev_register (next_frame, saved_regs,
2402 HPPA_PCOQ_HEAD_REGNUM, optimizedp,
2403 lvalp, addrp, realnump, valuep);
2405 pc = extract_unsigned_integer (valuep, 4);
2406 store_unsigned_integer (valuep, 4, pc + 4);
2409 /* It's a computed value. */
2417 trad_frame_get_prev_register (next_frame, saved_regs, regnum,
2418 optimizedp, lvalp, addrp, realnump, valuep);
2422 /* Here is a table of C type sizes on hppa with various compiles
2423 and options. I measured this on PA 9000/800 with HP-UX 11.11
2424 and these compilers:
2426 /usr/ccs/bin/cc HP92453-01 A.11.01.21
2427 /opt/ansic/bin/cc HP92453-01 B.11.11.28706.GP
2428 /opt/aCC/bin/aCC B3910B A.03.45
2429 gcc gcc 3.3.2 native hppa2.0w-hp-hpux11.11
2431 cc : 1 2 4 4 8 : 4 8 -- : 4 4
2432 ansic +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
2433 ansic +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
2434 ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2435 acc +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
2436 acc +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
2437 acc +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2438 gcc : 1 2 4 4 8 : 4 8 16 : 4 4
2442 compiler and options
2443 char, short, int, long, long long
2444 float, double, long double
2447 So all these compilers use either ILP32 or LP64 model.
2448 TODO: gcc has more options so it needs more investigation.
2450 For floating point types, see:
2452 http://docs.hp.com/hpux/pdf/B3906-90006.pdf
2453 HP-UX floating-point guide, hpux 11.00
2455 -- chastain 2003-12-18 */
2457 static struct gdbarch *
2458 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2460 struct gdbarch_tdep *tdep;
2461 struct gdbarch *gdbarch;
2463 /* Try to determine the ABI of the object we are loading. */
2464 if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
2466 /* If it's a SOM file, assume it's HP/UX SOM. */
2467 if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour)
2468 info.osabi = GDB_OSABI_HPUX_SOM;
2471 /* find a candidate among the list of pre-declared architectures. */
2472 arches = gdbarch_list_lookup_by_info (arches, &info);
2474 return (arches->gdbarch);
2476 /* If none found, then allocate and initialize one. */
2477 tdep = XZALLOC (struct gdbarch_tdep);
2478 gdbarch = gdbarch_alloc (&info, tdep);
2480 /* Determine from the bfd_arch_info structure if we are dealing with
2481 a 32 or 64 bits architecture. If the bfd_arch_info is not available,
2482 then default to a 32bit machine. */
2483 if (info.bfd_arch_info != NULL)
2484 tdep->bytes_per_address =
2485 info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
2487 tdep->bytes_per_address = 4;
2489 tdep->find_global_pointer = hppa_find_global_pointer;
2491 /* Some parts of the gdbarch vector depend on whether we are running
2492 on a 32 bits or 64 bits target. */
2493 switch (tdep->bytes_per_address)
2496 set_gdbarch_num_regs (gdbarch, hppa32_num_regs);
2497 set_gdbarch_register_name (gdbarch, hppa32_register_name);
2498 set_gdbarch_register_type (gdbarch, hppa32_register_type);
2501 set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
2502 set_gdbarch_register_name (gdbarch, hppa64_register_name);
2503 set_gdbarch_register_type (gdbarch, hppa64_register_type);
2506 internal_error (__FILE__, __LINE__, "Unsupported address size: %d",
2507 tdep->bytes_per_address);
2510 set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
2511 set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
2513 /* The following gdbarch vector elements are the same in both ILP32
2514 and LP64, but might show differences some day. */
2515 set_gdbarch_long_long_bit (gdbarch, 64);
2516 set_gdbarch_long_double_bit (gdbarch, 128);
2517 set_gdbarch_long_double_format (gdbarch, &floatformat_ia64_quad_big);
2519 /* The following gdbarch vector elements do not depend on the address
2520 size, or in any other gdbarch element previously set. */
2521 set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue);
2522 set_gdbarch_inner_than (gdbarch, core_addr_greaterthan);
2523 set_gdbarch_sp_regnum (gdbarch, HPPA_SP_REGNUM);
2524 set_gdbarch_fp0_regnum (gdbarch, HPPA_FP0_REGNUM);
2525 set_gdbarch_cannot_store_register (gdbarch, hppa_cannot_store_register);
2526 set_gdbarch_cannot_fetch_register (gdbarch, hppa_cannot_store_register);
2527 set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address);
2528 set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address);
2529 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2530 set_gdbarch_read_pc (gdbarch, hppa_target_read_pc);
2531 set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
2533 /* Helper for function argument information. */
2534 set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
2536 set_gdbarch_print_insn (gdbarch, print_insn_hppa);
2538 /* When a hardware watchpoint triggers, we'll move the inferior past
2539 it by removing all eventpoints; stepping past the instruction
2540 that caused the trigger; reinserting eventpoints; and checking
2541 whether any watched location changed. */
2542 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
2544 /* Inferior function call methods. */
2545 switch (tdep->bytes_per_address)
2548 set_gdbarch_push_dummy_call (gdbarch, hppa32_push_dummy_call);
2549 set_gdbarch_frame_align (gdbarch, hppa32_frame_align);
2550 set_gdbarch_convert_from_func_ptr_addr
2551 (gdbarch, hppa32_convert_from_func_ptr_addr);
2554 set_gdbarch_push_dummy_call (gdbarch, hppa64_push_dummy_call);
2555 set_gdbarch_frame_align (gdbarch, hppa64_frame_align);
2558 internal_error (__FILE__, __LINE__, "bad switch");
2561 /* Struct return methods. */
2562 switch (tdep->bytes_per_address)
2565 set_gdbarch_return_value (gdbarch, hppa32_return_value);
2568 set_gdbarch_return_value (gdbarch, hppa64_return_value);
2571 internal_error (__FILE__, __LINE__, "bad switch");
2574 set_gdbarch_breakpoint_from_pc (gdbarch, hppa_breakpoint_from_pc);
2575 set_gdbarch_pseudo_register_read (gdbarch, hppa_pseudo_register_read);
2576 set_gdbarch_instruction_nullified (gdbarch, hppa_instruction_nullified);
2578 /* Frame unwind methods. */
2579 set_gdbarch_unwind_dummy_id (gdbarch, hppa_unwind_dummy_id);
2580 set_gdbarch_unwind_pc (gdbarch, hppa_unwind_pc);
2582 /* Hook in ABI-specific overrides, if they have been registered. */
2583 gdbarch_init_osabi (info, gdbarch);
2585 /* Hook in the default unwinders. */
2586 frame_unwind_append_sniffer (gdbarch, hppa_stub_unwind_sniffer);
2587 frame_unwind_append_sniffer (gdbarch, hppa_frame_unwind_sniffer);
2588 frame_unwind_append_sniffer (gdbarch, hppa_fallback_unwind_sniffer);
2594 hppa_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
2596 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2598 fprintf_unfiltered (file, "bytes_per_address = %d\n",
2599 tdep->bytes_per_address);
2600 fprintf_unfiltered (file, "elf = %s\n", tdep->is_elf ? "yes" : "no");
2604 _initialize_hppa_tdep (void)
2606 struct cmd_list_element *c;
2608 gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
2610 hppa_objfile_priv_data = register_objfile_data ();
2612 add_cmd ("unwind", class_maintenance, unwind_command,
2613 "Print unwind table entry at given address.",
2614 &maintenanceprintlist);
2616 /* Debug this files internals. */
2617 add_setshow_boolean_cmd ("hppa", class_maintenance, &hppa_debug, "\
2618 Set whether hppa target specific debugging information should be displayed.", "\
2619 Show whether hppa target specific debugging information is displayed.", "\
2620 This flag controls whether hppa target specific debugging information is\n\
2621 displayed. This information is particularly useful for debugging frame\n\
2622 unwinding problems.", "hppa debug flag is %s.",
2623 NULL, NULL, &setdebuglist, &showdebuglist);