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
);
74 int hppa_instruction_nullified (void);
76 /* Handle 32/64-bit struct return conventions. */
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
)
83 if (TYPE_LENGTH (type
) <= 2 * 4)
85 /* The value always lives in the right hand end of the register
86 (or register pair)? */
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
96 regcache_cooked_read_part (regcache
, reg
, 4 - part
,
99 regcache_cooked_write_part (regcache
, reg
, 4 - part
,
103 /* Now transfer the remaining register values. */
104 for (b
= part
; b
< TYPE_LENGTH (type
); b
+= 4)
107 regcache_cooked_read (regcache
, reg
, (char *) readbuf
+ b
);
108 if (writebuf
!= NULL
)
109 regcache_cooked_write (regcache
, reg
, (const char *) writebuf
+ b
);
112 return RETURN_VALUE_REGISTER_CONVENTION
;
115 return RETURN_VALUE_STRUCT_CONVENTION
;
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
)
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)
130 /* Floats are right aligned? */
131 int offset
= register_size (gdbarch
, HPPA_FP4_REGNUM
) - TYPE_LENGTH (type
);
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
;
140 else if (TYPE_LENGTH (type
) <= 8 && is_integral_type (type
))
142 /* Integrals are right aligned. */
143 int offset
= register_size (gdbarch
, HPPA_FP4_REGNUM
) - TYPE_LENGTH (type
);
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
;
152 else if (TYPE_LENGTH (type
) <= 2 * 8)
154 /* Composite values are left aligned. */
156 for (b
= 0; b
< TYPE_LENGTH (type
); b
+= 8)
158 int part
= min (8, TYPE_LENGTH (type
) - b
);
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
);
166 return RETURN_VALUE_REGISTER_CONVENTION
;
169 return RETURN_VALUE_STRUCT_CONVENTION
;
172 /* Routines to extract various sized constants out of hppa
175 /* This assumes that no garbage lies outside of the lower bits of
179 hppa_sign_extend (unsigned val
, unsigned bits
)
181 return (int) (val
>> (bits
- 1) ? (-1 << bits
) | val
: val
);
184 /* For many immediate values the sign bit is the low bit! */
187 hppa_low_hppa_sign_extend (unsigned val
, unsigned bits
)
189 return (int) ((val
& 0x1 ? (-1 << (bits
- 1)) : 0) | val
>> 1);
192 /* Extract the bits at positions between FROM and TO, using HP's numbering
196 hppa_get_field (unsigned word
, int from
, int to
)
198 return ((word
) >> (31 - (to
)) & ((1 << ((to
) - (from
) + 1)) - 1));
201 /* extract the immediate field from a ld{bhw}s instruction */
204 hppa_extract_5_load (unsigned word
)
206 return hppa_low_hppa_sign_extend (word
>> 16 & MASK_5
, 5);
209 /* extract the immediate field from a break instruction */
212 hppa_extract_5r_store (unsigned word
)
214 return (word
& MASK_5
);
217 /* extract the immediate field from a {sr}sm instruction */
220 hppa_extract_5R_store (unsigned word
)
222 return (word
>> 16 & MASK_5
);
225 /* extract a 14 bit immediate field */
228 hppa_extract_14 (unsigned word
)
230 return hppa_low_hppa_sign_extend (word
& MASK_14
, 14);
233 /* extract a 21 bit constant */
236 hppa_extract_21 (unsigned word
)
242 val
= hppa_get_field (word
, 20, 20);
244 val
|= hppa_get_field (word
, 9, 19);
246 val
|= hppa_get_field (word
, 5, 6);
248 val
|= hppa_get_field (word
, 0, 4);
250 val
|= hppa_get_field (word
, 7, 8);
251 return hppa_sign_extend (val
, 21) << 11;
254 /* extract a 17 bit constant from branch instructions, returning the
255 19 bit signed value. */
258 hppa_extract_17 (unsigned word
)
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;
267 hppa_symbol_address(const char *sym
)
269 struct minimal_symbol
*minsym
;
271 minsym
= lookup_minimal_symbol (sym
, NULL
, NULL
);
273 return SYMBOL_VALUE_ADDRESS (minsym
);
275 return (CORE_ADDR
)-1;
279 /* Compare the start address for two unwind entries returning 1 if
280 the first address is larger than the second, -1 if the second is
281 larger than the first, and zero if they are equal. */
284 compare_unwind_entries (const void *arg1
, const void *arg2
)
286 const struct unwind_table_entry
*a
= arg1
;
287 const struct unwind_table_entry
*b
= arg2
;
289 if (a
->region_start
> b
->region_start
)
291 else if (a
->region_start
< b
->region_start
)
298 record_text_segment_lowaddr (bfd
*abfd
, asection
*section
, void *data
)
300 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
))
301 == (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
))
303 bfd_vma value
= section
->vma
- section
->filepos
;
304 CORE_ADDR
*low_text_segment_address
= (CORE_ADDR
*)data
;
306 if (value
< *low_text_segment_address
)
307 *low_text_segment_address
= value
;
312 internalize_unwinds (struct objfile
*objfile
, struct unwind_table_entry
*table
,
313 asection
*section
, unsigned int entries
, unsigned int size
,
314 CORE_ADDR text_offset
)
316 /* We will read the unwind entries into temporary memory, then
317 fill in the actual unwind table. */
323 char *buf
= alloca (size
);
324 CORE_ADDR low_text_segment_address
;
326 /* For ELF targets, then unwinds are supposed to
327 be segment relative offsets instead of absolute addresses.
329 Note that when loading a shared library (text_offset != 0) the
330 unwinds are already relative to the text_offset that will be
332 if (gdbarch_tdep (current_gdbarch
)->is_elf
&& text_offset
== 0)
334 low_text_segment_address
= -1;
336 bfd_map_over_sections (objfile
->obfd
,
337 record_text_segment_lowaddr
,
338 &low_text_segment_address
);
340 text_offset
= low_text_segment_address
;
343 bfd_get_section_contents (objfile
->obfd
, section
, buf
, 0, size
);
345 /* Now internalize the information being careful to handle host/target
347 for (i
= 0; i
< entries
; i
++)
349 table
[i
].region_start
= bfd_get_32 (objfile
->obfd
,
351 table
[i
].region_start
+= text_offset
;
353 table
[i
].region_end
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) buf
);
354 table
[i
].region_end
+= text_offset
;
356 tmp
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) buf
);
358 table
[i
].Cannot_unwind
= (tmp
>> 31) & 0x1;
359 table
[i
].Millicode
= (tmp
>> 30) & 0x1;
360 table
[i
].Millicode_save_sr0
= (tmp
>> 29) & 0x1;
361 table
[i
].Region_description
= (tmp
>> 27) & 0x3;
362 table
[i
].reserved1
= (tmp
>> 26) & 0x1;
363 table
[i
].Entry_SR
= (tmp
>> 25) & 0x1;
364 table
[i
].Entry_FR
= (tmp
>> 21) & 0xf;
365 table
[i
].Entry_GR
= (tmp
>> 16) & 0x1f;
366 table
[i
].Args_stored
= (tmp
>> 15) & 0x1;
367 table
[i
].Variable_Frame
= (tmp
>> 14) & 0x1;
368 table
[i
].Separate_Package_Body
= (tmp
>> 13) & 0x1;
369 table
[i
].Frame_Extension_Millicode
= (tmp
>> 12) & 0x1;
370 table
[i
].Stack_Overflow_Check
= (tmp
>> 11) & 0x1;
371 table
[i
].Two_Instruction_SP_Increment
= (tmp
>> 10) & 0x1;
372 table
[i
].Ada_Region
= (tmp
>> 9) & 0x1;
373 table
[i
].cxx_info
= (tmp
>> 8) & 0x1;
374 table
[i
].cxx_try_catch
= (tmp
>> 7) & 0x1;
375 table
[i
].sched_entry_seq
= (tmp
>> 6) & 0x1;
376 table
[i
].reserved2
= (tmp
>> 5) & 0x1;
377 table
[i
].Save_SP
= (tmp
>> 4) & 0x1;
378 table
[i
].Save_RP
= (tmp
>> 3) & 0x1;
379 table
[i
].Save_MRP_in_frame
= (tmp
>> 2) & 0x1;
380 table
[i
].extn_ptr_defined
= (tmp
>> 1) & 0x1;
381 table
[i
].Cleanup_defined
= tmp
& 0x1;
382 tmp
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) buf
);
384 table
[i
].MPE_XL_interrupt_marker
= (tmp
>> 31) & 0x1;
385 table
[i
].HP_UX_interrupt_marker
= (tmp
>> 30) & 0x1;
386 table
[i
].Large_frame
= (tmp
>> 29) & 0x1;
387 table
[i
].Pseudo_SP_Set
= (tmp
>> 28) & 0x1;
388 table
[i
].reserved4
= (tmp
>> 27) & 0x1;
389 table
[i
].Total_frame_size
= tmp
& 0x7ffffff;
391 /* Stub unwinds are handled elsewhere. */
392 table
[i
].stub_unwind
.stub_type
= 0;
393 table
[i
].stub_unwind
.padding
= 0;
398 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
399 the object file. This info is used mainly by find_unwind_entry() to find
400 out the stack frame size and frame pointer used by procedures. We put
401 everything on the psymbol obstack in the objfile so that it automatically
402 gets freed when the objfile is destroyed. */
405 read_unwind_info (struct objfile
*objfile
)
407 asection
*unwind_sec
, *stub_unwind_sec
;
408 unsigned unwind_size
, stub_unwind_size
, total_size
;
409 unsigned index
, unwind_entries
;
410 unsigned stub_entries
, total_entries
;
411 CORE_ADDR text_offset
;
412 struct hppa_unwind_info
*ui
;
413 struct hppa_objfile_private
*obj_private
;
415 text_offset
= ANOFFSET (objfile
->section_offsets
, 0);
416 ui
= (struct hppa_unwind_info
*) obstack_alloc (&objfile
->objfile_obstack
,
417 sizeof (struct hppa_unwind_info
));
423 /* For reasons unknown the HP PA64 tools generate multiple unwinder
424 sections in a single executable. So we just iterate over every
425 section in the BFD looking for unwinder sections intead of trying
426 to do a lookup with bfd_get_section_by_name.
428 First determine the total size of the unwind tables so that we
429 can allocate memory in a nice big hunk. */
431 for (unwind_sec
= objfile
->obfd
->sections
;
433 unwind_sec
= unwind_sec
->next
)
435 if (strcmp (unwind_sec
->name
, "$UNWIND_START$") == 0
436 || strcmp (unwind_sec
->name
, ".PARISC.unwind") == 0)
438 unwind_size
= bfd_section_size (objfile
->obfd
, unwind_sec
);
439 unwind_entries
= unwind_size
/ UNWIND_ENTRY_SIZE
;
441 total_entries
+= unwind_entries
;
445 /* Now compute the size of the stub unwinds. Note the ELF tools do not
446 use stub unwinds at the curren time. */
447 stub_unwind_sec
= bfd_get_section_by_name (objfile
->obfd
, "$UNWIND_END$");
451 stub_unwind_size
= bfd_section_size (objfile
->obfd
, stub_unwind_sec
);
452 stub_entries
= stub_unwind_size
/ STUB_UNWIND_ENTRY_SIZE
;
456 stub_unwind_size
= 0;
460 /* Compute total number of unwind entries and their total size. */
461 total_entries
+= stub_entries
;
462 total_size
= total_entries
* sizeof (struct unwind_table_entry
);
464 /* Allocate memory for the unwind table. */
465 ui
->table
= (struct unwind_table_entry
*)
466 obstack_alloc (&objfile
->objfile_obstack
, total_size
);
467 ui
->last
= total_entries
- 1;
469 /* Now read in each unwind section and internalize the standard unwind
472 for (unwind_sec
= objfile
->obfd
->sections
;
474 unwind_sec
= unwind_sec
->next
)
476 if (strcmp (unwind_sec
->name
, "$UNWIND_START$") == 0
477 || strcmp (unwind_sec
->name
, ".PARISC.unwind") == 0)
479 unwind_size
= bfd_section_size (objfile
->obfd
, unwind_sec
);
480 unwind_entries
= unwind_size
/ UNWIND_ENTRY_SIZE
;
482 internalize_unwinds (objfile
, &ui
->table
[index
], unwind_sec
,
483 unwind_entries
, unwind_size
, text_offset
);
484 index
+= unwind_entries
;
488 /* Now read in and internalize the stub unwind entries. */
489 if (stub_unwind_size
> 0)
492 char *buf
= alloca (stub_unwind_size
);
494 /* Read in the stub unwind entries. */
495 bfd_get_section_contents (objfile
->obfd
, stub_unwind_sec
, buf
,
496 0, stub_unwind_size
);
498 /* Now convert them into regular unwind entries. */
499 for (i
= 0; i
< stub_entries
; i
++, index
++)
501 /* Clear out the next unwind entry. */
502 memset (&ui
->table
[index
], 0, sizeof (struct unwind_table_entry
));
504 /* Convert offset & size into region_start and region_end.
505 Stuff away the stub type into "reserved" fields. */
506 ui
->table
[index
].region_start
= bfd_get_32 (objfile
->obfd
,
508 ui
->table
[index
].region_start
+= text_offset
;
510 ui
->table
[index
].stub_unwind
.stub_type
= bfd_get_8 (objfile
->obfd
,
513 ui
->table
[index
].region_end
514 = ui
->table
[index
].region_start
+ 4 *
515 (bfd_get_16 (objfile
->obfd
, (bfd_byte
*) buf
) - 1);
521 /* Unwind table needs to be kept sorted. */
522 qsort (ui
->table
, total_entries
, sizeof (struct unwind_table_entry
),
523 compare_unwind_entries
);
525 /* Keep a pointer to the unwind information. */
526 obj_private
= (struct hppa_objfile_private
*)
527 objfile_data (objfile
, hppa_objfile_priv_data
);
528 if (obj_private
== NULL
)
530 obj_private
= (struct hppa_objfile_private
*)
531 obstack_alloc (&objfile
->objfile_obstack
,
532 sizeof (struct hppa_objfile_private
));
533 set_objfile_data (objfile
, hppa_objfile_priv_data
, obj_private
);
534 obj_private
->unwind_info
= NULL
;
535 obj_private
->so_info
= NULL
;
538 obj_private
->unwind_info
= ui
;
541 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
542 of the objfiles seeking the unwind table entry for this PC. Each objfile
543 contains a sorted list of struct unwind_table_entry. Since we do a binary
544 search of the unwind tables, we depend upon them to be sorted. */
546 struct unwind_table_entry
*
547 find_unwind_entry (CORE_ADDR pc
)
549 int first
, middle
, last
;
550 struct objfile
*objfile
;
551 struct hppa_objfile_private
*priv
;
554 fprintf_unfiltered (gdb_stdlog
, "{ find_unwind_entry 0x%s -> ",
557 /* A function at address 0? Not in HP-UX! */
558 if (pc
== (CORE_ADDR
) 0)
561 fprintf_unfiltered (gdb_stdlog
, "NULL }\n");
565 ALL_OBJFILES (objfile
)
567 struct hppa_unwind_info
*ui
;
569 priv
= objfile_data (objfile
, hppa_objfile_priv_data
);
571 ui
= ((struct hppa_objfile_private
*) priv
)->unwind_info
;
575 read_unwind_info (objfile
);
576 priv
= objfile_data (objfile
, hppa_objfile_priv_data
);
578 error ("Internal error reading unwind information.");
579 ui
= ((struct hppa_objfile_private
*) priv
)->unwind_info
;
582 /* First, check the cache */
585 && pc
>= ui
->cache
->region_start
586 && pc
<= ui
->cache
->region_end
)
589 fprintf_unfiltered (gdb_stdlog
, "0x%s (cached) }\n",
590 paddr_nz ((CORE_ADDR
) ui
->cache
));
594 /* Not in the cache, do a binary search */
599 while (first
<= last
)
601 middle
= (first
+ last
) / 2;
602 if (pc
>= ui
->table
[middle
].region_start
603 && pc
<= ui
->table
[middle
].region_end
)
605 ui
->cache
= &ui
->table
[middle
];
607 fprintf_unfiltered (gdb_stdlog
, "0x%s }\n",
608 paddr_nz ((CORE_ADDR
) ui
->cache
));
609 return &ui
->table
[middle
];
612 if (pc
< ui
->table
[middle
].region_start
)
617 } /* ALL_OBJFILES() */
620 fprintf_unfiltered (gdb_stdlog
, "NULL (not found) }\n");
625 static const unsigned char *
626 hppa_breakpoint_from_pc (CORE_ADDR
*pc
, int *len
)
628 static const unsigned char breakpoint
[] = {0x00, 0x01, 0x00, 0x04};
629 (*len
) = sizeof (breakpoint
);
633 /* Return the name of a register. */
636 hppa32_register_name (int i
)
638 static char *names
[] = {
639 "flags", "r1", "rp", "r3",
640 "r4", "r5", "r6", "r7",
641 "r8", "r9", "r10", "r11",
642 "r12", "r13", "r14", "r15",
643 "r16", "r17", "r18", "r19",
644 "r20", "r21", "r22", "r23",
645 "r24", "r25", "r26", "dp",
646 "ret0", "ret1", "sp", "r31",
647 "sar", "pcoqh", "pcsqh", "pcoqt",
648 "pcsqt", "eiem", "iir", "isr",
649 "ior", "ipsw", "goto", "sr4",
650 "sr0", "sr1", "sr2", "sr3",
651 "sr5", "sr6", "sr7", "cr0",
652 "cr8", "cr9", "ccr", "cr12",
653 "cr13", "cr24", "cr25", "cr26",
654 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
655 "fpsr", "fpe1", "fpe2", "fpe3",
656 "fpe4", "fpe5", "fpe6", "fpe7",
657 "fr4", "fr4R", "fr5", "fr5R",
658 "fr6", "fr6R", "fr7", "fr7R",
659 "fr8", "fr8R", "fr9", "fr9R",
660 "fr10", "fr10R", "fr11", "fr11R",
661 "fr12", "fr12R", "fr13", "fr13R",
662 "fr14", "fr14R", "fr15", "fr15R",
663 "fr16", "fr16R", "fr17", "fr17R",
664 "fr18", "fr18R", "fr19", "fr19R",
665 "fr20", "fr20R", "fr21", "fr21R",
666 "fr22", "fr22R", "fr23", "fr23R",
667 "fr24", "fr24R", "fr25", "fr25R",
668 "fr26", "fr26R", "fr27", "fr27R",
669 "fr28", "fr28R", "fr29", "fr29R",
670 "fr30", "fr30R", "fr31", "fr31R"
672 if (i
< 0 || i
>= (sizeof (names
) / sizeof (*names
)))
679 hppa64_register_name (int i
)
681 static char *names
[] = {
682 "flags", "r1", "rp", "r3",
683 "r4", "r5", "r6", "r7",
684 "r8", "r9", "r10", "r11",
685 "r12", "r13", "r14", "r15",
686 "r16", "r17", "r18", "r19",
687 "r20", "r21", "r22", "r23",
688 "r24", "r25", "r26", "dp",
689 "ret0", "ret1", "sp", "r31",
690 "sar", "pcoqh", "pcsqh", "pcoqt",
691 "pcsqt", "eiem", "iir", "isr",
692 "ior", "ipsw", "goto", "sr4",
693 "sr0", "sr1", "sr2", "sr3",
694 "sr5", "sr6", "sr7", "cr0",
695 "cr8", "cr9", "ccr", "cr12",
696 "cr13", "cr24", "cr25", "cr26",
697 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
698 "fpsr", "fpe1", "fpe2", "fpe3",
699 "fr4", "fr5", "fr6", "fr7",
700 "fr8", "fr9", "fr10", "fr11",
701 "fr12", "fr13", "fr14", "fr15",
702 "fr16", "fr17", "fr18", "fr19",
703 "fr20", "fr21", "fr22", "fr23",
704 "fr24", "fr25", "fr26", "fr27",
705 "fr28", "fr29", "fr30", "fr31"
707 if (i
< 0 || i
>= (sizeof (names
) / sizeof (*names
)))
713 /* This function pushes a stack frame with arguments as part of the
714 inferior function calling mechanism.
716 This is the version of the function for the 32-bit PA machines, in
717 which later arguments appear at lower addresses. (The stack always
718 grows towards higher addresses.)
720 We simply allocate the appropriate amount of stack space and put
721 arguments into their proper slots. */
724 hppa32_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
725 struct regcache
*regcache
, CORE_ADDR bp_addr
,
726 int nargs
, struct value
**args
, CORE_ADDR sp
,
727 int struct_return
, CORE_ADDR struct_addr
)
729 /* Stack base address at which any pass-by-reference parameters are
731 CORE_ADDR struct_end
= 0;
732 /* Stack base address at which the first parameter is stored. */
733 CORE_ADDR param_end
= 0;
735 /* The inner most end of the stack after all the parameters have
737 CORE_ADDR new_sp
= 0;
739 /* Two passes. First pass computes the location of everything,
740 second pass writes the bytes out. */
743 /* Global pointer (r19) of the function we are trying to call. */
746 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
748 for (write_pass
= 0; write_pass
< 2; write_pass
++)
750 CORE_ADDR struct_ptr
= 0;
751 /* The first parameter goes into sp-36, each stack slot is 4-bytes.
752 struct_ptr is adjusted for each argument below, so the first
753 argument will end up at sp-36. */
754 CORE_ADDR param_ptr
= 32;
756 int small_struct
= 0;
758 for (i
= 0; i
< nargs
; i
++)
760 struct value
*arg
= args
[i
];
761 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
762 /* The corresponding parameter that is pushed onto the
763 stack, and [possibly] passed in a register. */
766 memset (param_val
, 0, sizeof param_val
);
767 if (TYPE_LENGTH (type
) > 8)
769 /* Large parameter, pass by reference. Store the value
770 in "struct" area and then pass its address. */
772 struct_ptr
+= align_up (TYPE_LENGTH (type
), 8);
774 write_memory (struct_end
- struct_ptr
, VALUE_CONTENTS (arg
),
776 store_unsigned_integer (param_val
, 4, struct_end
- struct_ptr
);
778 else if (TYPE_CODE (type
) == TYPE_CODE_INT
779 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
781 /* Integer value store, right aligned. "unpack_long"
782 takes care of any sign-extension problems. */
783 param_len
= align_up (TYPE_LENGTH (type
), 4);
784 store_unsigned_integer (param_val
, param_len
,
786 VALUE_CONTENTS (arg
)));
788 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
790 /* Floating point value store, right aligned. */
791 param_len
= align_up (TYPE_LENGTH (type
), 4);
792 memcpy (param_val
, VALUE_CONTENTS (arg
), param_len
);
796 param_len
= align_up (TYPE_LENGTH (type
), 4);
798 /* Small struct value are stored right-aligned. */
799 memcpy (param_val
+ param_len
- TYPE_LENGTH (type
),
800 VALUE_CONTENTS (arg
), TYPE_LENGTH (type
));
802 /* Structures of size 5, 6 and 7 bytes are special in that
803 the higher-ordered word is stored in the lower-ordered
804 argument, and even though it is a 8-byte quantity the
805 registers need not be 8-byte aligned. */
806 if (param_len
> 4 && param_len
< 8)
810 param_ptr
+= param_len
;
811 if (param_len
== 8 && !small_struct
)
812 param_ptr
= align_up (param_ptr
, 8);
814 /* First 4 non-FP arguments are passed in gr26-gr23.
815 First 4 32-bit FP arguments are passed in fr4L-fr7L.
816 First 2 64-bit FP arguments are passed in fr5 and fr7.
818 The rest go on the stack, starting at sp-36, towards lower
819 addresses. 8-byte arguments must be aligned to a 8-byte
823 write_memory (param_end
- param_ptr
, param_val
, param_len
);
825 /* There are some cases when we don't know the type
826 expected by the callee (e.g. for variadic functions), so
827 pass the parameters in both general and fp regs. */
830 int grreg
= 26 - (param_ptr
- 36) / 4;
831 int fpLreg
= 72 + (param_ptr
- 36) / 4 * 2;
832 int fpreg
= 74 + (param_ptr
- 32) / 8 * 4;
834 regcache_cooked_write (regcache
, grreg
, param_val
);
835 regcache_cooked_write (regcache
, fpLreg
, param_val
);
839 regcache_cooked_write (regcache
, grreg
+ 1,
842 regcache_cooked_write (regcache
, fpreg
, param_val
);
843 regcache_cooked_write (regcache
, fpreg
+ 1,
850 /* Update the various stack pointers. */
853 struct_end
= sp
+ align_up (struct_ptr
, 64);
854 /* PARAM_PTR already accounts for all the arguments passed
855 by the user. However, the ABI mandates minimum stack
856 space allocations for outgoing arguments. The ABI also
857 mandates minimum stack alignments which we must
859 param_end
= struct_end
+ align_up (param_ptr
, 64);
863 /* If a structure has to be returned, set up register 28 to hold its
866 write_register (28, struct_addr
);
868 gp
= tdep
->find_global_pointer (function
);
871 write_register (19, gp
);
873 /* Set the return address. */
874 regcache_cooked_write_unsigned (regcache
, HPPA_RP_REGNUM
, bp_addr
);
876 /* Update the Stack Pointer. */
877 regcache_cooked_write_unsigned (regcache
, HPPA_SP_REGNUM
, param_end
);
882 /* This function pushes a stack frame with arguments as part of the
883 inferior function calling mechanism.
885 This is the version for the PA64, in which later arguments appear
886 at higher addresses. (The stack always grows towards higher
889 We simply allocate the appropriate amount of stack space and put
890 arguments into their proper slots.
892 This ABI also requires that the caller provide an argument pointer
893 to the callee, so we do that too. */
896 hppa64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
897 struct regcache
*regcache
, CORE_ADDR bp_addr
,
898 int nargs
, struct value
**args
, CORE_ADDR sp
,
899 int struct_return
, CORE_ADDR struct_addr
)
901 /* NOTE: cagney/2004-02-27: This is a guess - its implemented by
902 reverse engineering testsuite failures. */
904 /* Stack base address at which any pass-by-reference parameters are
906 CORE_ADDR struct_end
= 0;
907 /* Stack base address at which the first parameter is stored. */
908 CORE_ADDR param_end
= 0;
910 /* The inner most end of the stack after all the parameters have
912 CORE_ADDR new_sp
= 0;
914 /* Two passes. First pass computes the location of everything,
915 second pass writes the bytes out. */
917 for (write_pass
= 0; write_pass
< 2; write_pass
++)
919 CORE_ADDR struct_ptr
= 0;
920 CORE_ADDR param_ptr
= 0;
922 for (i
= 0; i
< nargs
; i
++)
924 struct value
*arg
= args
[i
];
925 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
926 if ((TYPE_CODE (type
) == TYPE_CODE_INT
927 || TYPE_CODE (type
) == TYPE_CODE_ENUM
)
928 && TYPE_LENGTH (type
) <= 8)
930 /* Integer value store, right aligned. "unpack_long"
931 takes care of any sign-extension problems. */
935 ULONGEST val
= unpack_long (type
, VALUE_CONTENTS (arg
));
936 int reg
= 27 - param_ptr
/ 8;
937 write_memory_unsigned_integer (param_end
- param_ptr
,
940 regcache_cooked_write_unsigned (regcache
, reg
, val
);
945 /* Small struct value, store left aligned? */
947 if (TYPE_LENGTH (type
) > 8)
949 param_ptr
= align_up (param_ptr
, 16);
950 reg
= 26 - param_ptr
/ 8;
951 param_ptr
+= align_up (TYPE_LENGTH (type
), 16);
955 param_ptr
= align_up (param_ptr
, 8);
956 reg
= 26 - param_ptr
/ 8;
957 param_ptr
+= align_up (TYPE_LENGTH (type
), 8);
962 write_memory (param_end
- param_ptr
, VALUE_CONTENTS (arg
),
964 for (byte
= 0; byte
< TYPE_LENGTH (type
); byte
+= 8)
968 int len
= min (8, TYPE_LENGTH (type
) - byte
);
969 regcache_cooked_write_part (regcache
, reg
, 0, len
,
970 VALUE_CONTENTS (arg
) + byte
);
977 /* Update the various stack pointers. */
980 struct_end
= sp
+ struct_ptr
;
981 /* PARAM_PTR already accounts for all the arguments passed
982 by the user. However, the ABI mandates minimum stack
983 space allocations for outgoing arguments. The ABI also
984 mandates minimum stack alignments which we must
986 param_end
= struct_end
+ max (align_up (param_ptr
, 16), 64);
990 /* If a structure has to be returned, set up register 28 to hold its
993 write_register (28, struct_addr
);
995 /* Set the return address. */
996 regcache_cooked_write_unsigned (regcache
, HPPA_RP_REGNUM
, bp_addr
);
998 /* Update the Stack Pointer. */
999 regcache_cooked_write_unsigned (regcache
, HPPA_SP_REGNUM
, param_end
+ 64);
1001 /* The stack will have 32 bytes of additional space for a frame marker. */
1002 return param_end
+ 64;
1006 hppa32_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
1008 struct target_ops
*targ
)
1015 target_read_memory(plabel
, (char *)&addr
, 4);
1022 hppa32_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1024 /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_
1026 return align_up (addr
, 64);
1029 /* Force all frames to 16-byte alignment. Better safe than sorry. */
1032 hppa64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1034 /* Just always 16-byte align. */
1035 return align_up (addr
, 16);
1039 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
1043 hppa_target_read_pc (ptid_t ptid
)
1045 int flags
= read_register_pid (HPPA_FLAGS_REGNUM
, ptid
);
1047 /* The following test does not belong here. It is OS-specific, and belongs
1049 /* Test SS_INSYSCALL */
1051 return read_register_pid (31, ptid
) & ~0x3;
1053 return read_register_pid (HPPA_PCOQ_HEAD_REGNUM
, ptid
) & ~0x3;
1056 /* Write out the PC. If currently in a syscall, then also write the new
1057 PC value into %r31. */
1060 hppa_target_write_pc (CORE_ADDR v
, ptid_t ptid
)
1062 int flags
= read_register_pid (HPPA_FLAGS_REGNUM
, ptid
);
1064 /* The following test does not belong here. It is OS-specific, and belongs
1066 /* If in a syscall, then set %r31. Also make sure to get the
1067 privilege bits set correctly. */
1068 /* Test SS_INSYSCALL */
1070 write_register_pid (31, v
| 0x3, ptid
);
1072 write_register_pid (HPPA_PCOQ_HEAD_REGNUM
, v
, ptid
);
1073 write_register_pid (HPPA_PCOQ_TAIL_REGNUM
, v
+ 4, ptid
);
1076 /* return the alignment of a type in bytes. Structures have the maximum
1077 alignment required by their fields. */
1080 hppa_alignof (struct type
*type
)
1082 int max_align
, align
, i
;
1083 CHECK_TYPEDEF (type
);
1084 switch (TYPE_CODE (type
))
1089 return TYPE_LENGTH (type
);
1090 case TYPE_CODE_ARRAY
:
1091 return hppa_alignof (TYPE_FIELD_TYPE (type
, 0));
1092 case TYPE_CODE_STRUCT
:
1093 case TYPE_CODE_UNION
:
1095 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
1097 /* Bit fields have no real alignment. */
1098 /* if (!TYPE_FIELD_BITPOS (type, i)) */
1099 if (!TYPE_FIELD_BITSIZE (type
, i
)) /* elz: this should be bitsize */
1101 align
= hppa_alignof (TYPE_FIELD_TYPE (type
, i
));
1102 max_align
= max (max_align
, align
);
1111 /* For the given instruction (INST), return any adjustment it makes
1112 to the stack pointer or zero for no adjustment.
1114 This only handles instructions commonly found in prologues. */
1117 prologue_inst_adjust_sp (unsigned long inst
)
1119 /* This must persist across calls. */
1120 static int save_high21
;
1122 /* The most common way to perform a stack adjustment ldo X(sp),sp */
1123 if ((inst
& 0xffffc000) == 0x37de0000)
1124 return hppa_extract_14 (inst
);
1127 if ((inst
& 0xffe00000) == 0x6fc00000)
1128 return hppa_extract_14 (inst
);
1130 /* std,ma X,D(sp) */
1131 if ((inst
& 0xffe00008) == 0x73c00008)
1132 return (inst
& 0x1 ? -1 << 13 : 0) | (((inst
>> 4) & 0x3ff) << 3);
1134 /* addil high21,%r1; ldo low11,(%r1),%r30)
1135 save high bits in save_high21 for later use. */
1136 if ((inst
& 0xffe00000) == 0x28200000)
1138 save_high21
= hppa_extract_21 (inst
);
1142 if ((inst
& 0xffff0000) == 0x343e0000)
1143 return save_high21
+ hppa_extract_14 (inst
);
1145 /* fstws as used by the HP compilers. */
1146 if ((inst
& 0xffffffe0) == 0x2fd01220)
1147 return hppa_extract_5_load (inst
);
1149 /* No adjustment. */
1153 /* Return nonzero if INST is a branch of some kind, else return zero. */
1156 is_branch (unsigned long inst
)
1185 /* Return the register number for a GR which is saved by INST or
1186 zero it INST does not save a GR. */
1189 inst_saves_gr (unsigned long inst
)
1191 /* Does it look like a stw? */
1192 if ((inst
>> 26) == 0x1a || (inst
>> 26) == 0x1b
1193 || (inst
>> 26) == 0x1f
1194 || ((inst
>> 26) == 0x1f
1195 && ((inst
>> 6) == 0xa)))
1196 return hppa_extract_5R_store (inst
);
1198 /* Does it look like a std? */
1199 if ((inst
>> 26) == 0x1c
1200 || ((inst
>> 26) == 0x03
1201 && ((inst
>> 6) & 0xf) == 0xb))
1202 return hppa_extract_5R_store (inst
);
1204 /* Does it look like a stwm? GCC & HPC may use this in prologues. */
1205 if ((inst
>> 26) == 0x1b)
1206 return hppa_extract_5R_store (inst
);
1208 /* Does it look like sth or stb? HPC versions 9.0 and later use these
1210 if ((inst
>> 26) == 0x19 || (inst
>> 26) == 0x18
1211 || ((inst
>> 26) == 0x3
1212 && (((inst
>> 6) & 0xf) == 0x8
1213 || (inst
>> 6) & 0xf) == 0x9))
1214 return hppa_extract_5R_store (inst
);
1219 /* Return the register number for a FR which is saved by INST or
1220 zero it INST does not save a FR.
1222 Note we only care about full 64bit register stores (that's the only
1223 kind of stores the prologue will use).
1225 FIXME: What about argument stores with the HP compiler in ANSI mode? */
1228 inst_saves_fr (unsigned long inst
)
1230 /* is this an FSTD ? */
1231 if ((inst
& 0xfc00dfc0) == 0x2c001200)
1232 return hppa_extract_5r_store (inst
);
1233 if ((inst
& 0xfc000002) == 0x70000002)
1234 return hppa_extract_5R_store (inst
);
1235 /* is this an FSTW ? */
1236 if ((inst
& 0xfc00df80) == 0x24001200)
1237 return hppa_extract_5r_store (inst
);
1238 if ((inst
& 0xfc000002) == 0x7c000000)
1239 return hppa_extract_5R_store (inst
);
1243 /* Advance PC across any function entry prologue instructions
1244 to reach some "real" code.
1246 Use information in the unwind table to determine what exactly should
1247 be in the prologue. */
1251 skip_prologue_hard_way (CORE_ADDR pc
)
1254 CORE_ADDR orig_pc
= pc
;
1255 unsigned long inst
, stack_remaining
, save_gr
, save_fr
, save_rp
, save_sp
;
1256 unsigned long args_stored
, status
, i
, restart_gr
, restart_fr
;
1257 struct unwind_table_entry
*u
;
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 /* Loop until we find everything of interest or hit a branch.
1303 For unoptimized GCC code and for any HP CC code this will never ever
1304 examine any user instructions.
1306 For optimzied GCC code we're faced with problems. GCC will schedule
1307 its prologue and make prologue instructions available for delay slot
1308 filling. The end result is user code gets mixed in with the prologue
1309 and a prologue instruction may be in the delay slot of the first branch
1312 Some unexpected things are expected with debugging optimized code, so
1313 we allow this routine to walk past user instructions in optimized
1315 while (save_gr
|| save_fr
|| save_rp
|| save_sp
|| stack_remaining
> 0
1318 unsigned int reg_num
;
1319 unsigned long old_stack_remaining
, old_save_gr
, old_save_fr
;
1320 unsigned long old_save_rp
, old_save_sp
, next_inst
;
1322 /* Save copies of all the triggers so we can compare them later
1324 old_save_gr
= save_gr
;
1325 old_save_fr
= save_fr
;
1326 old_save_rp
= save_rp
;
1327 old_save_sp
= save_sp
;
1328 old_stack_remaining
= stack_remaining
;
1330 status
= deprecated_read_memory_nobpt (pc
, buf
, 4);
1331 inst
= extract_unsigned_integer (buf
, 4);
1337 /* Note the interesting effects of this instruction. */
1338 stack_remaining
-= prologue_inst_adjust_sp (inst
);
1340 /* There are limited ways to store the return pointer into the
1342 if (inst
== 0x6bc23fd9 || inst
== 0x0fc212c1)
1345 /* These are the only ways we save SP into the stack. At this time
1346 the HP compilers never bother to save SP into the stack. */
1347 if ((inst
& 0xffffc000) == 0x6fc10000
1348 || (inst
& 0xffffc00c) == 0x73c10008)
1351 /* Are we loading some register with an offset from the argument
1353 if ((inst
& 0xffe00000) == 0x37a00000
1354 || (inst
& 0xffffffe0) == 0x081d0240)
1360 /* Account for general and floating-point register saves. */
1361 reg_num
= inst_saves_gr (inst
);
1362 save_gr
&= ~(1 << reg_num
);
1364 /* Ugh. Also account for argument stores into the stack.
1365 Unfortunately args_stored only tells us that some arguments
1366 where stored into the stack. Not how many or what kind!
1368 This is a kludge as on the HP compiler sets this bit and it
1369 never does prologue scheduling. So once we see one, skip past
1370 all of them. We have similar code for the fp arg stores below.
1372 FIXME. Can still die if we have a mix of GR and FR argument
1374 if (reg_num
>= (TARGET_PTR_BIT
== 64 ? 19 : 23) && reg_num
<= 26)
1376 while (reg_num
>= (TARGET_PTR_BIT
== 64 ? 19 : 23) && reg_num
<= 26)
1379 status
= deprecated_read_memory_nobpt (pc
, buf
, 4);
1380 inst
= extract_unsigned_integer (buf
, 4);
1383 reg_num
= inst_saves_gr (inst
);
1389 reg_num
= inst_saves_fr (inst
);
1390 save_fr
&= ~(1 << reg_num
);
1392 status
= deprecated_read_memory_nobpt (pc
+ 4, buf
, 4);
1393 next_inst
= extract_unsigned_integer (buf
, 4);
1399 /* We've got to be read to handle the ldo before the fp register
1401 if ((inst
& 0xfc000000) == 0x34000000
1402 && inst_saves_fr (next_inst
) >= 4
1403 && inst_saves_fr (next_inst
) <= (TARGET_PTR_BIT
== 64 ? 11 : 7))
1405 /* So we drop into the code below in a reasonable state. */
1406 reg_num
= inst_saves_fr (next_inst
);
1410 /* Ugh. Also account for argument stores into the stack.
1411 This is a kludge as on the HP compiler sets this bit and it
1412 never does prologue scheduling. So once we see one, skip past
1414 if (reg_num
>= 4 && reg_num
<= (TARGET_PTR_BIT
== 64 ? 11 : 7))
1416 while (reg_num
>= 4 && reg_num
<= (TARGET_PTR_BIT
== 64 ? 11 : 7))
1419 status
= deprecated_read_memory_nobpt (pc
, buf
, 4);
1420 inst
= extract_unsigned_integer (buf
, 4);
1423 if ((inst
& 0xfc000000) != 0x34000000)
1425 status
= deprecated_read_memory_nobpt (pc
+ 4, buf
, 4);
1426 next_inst
= extract_unsigned_integer (buf
, 4);
1429 reg_num
= inst_saves_fr (next_inst
);
1435 /* Quit if we hit any kind of branch. This can happen if a prologue
1436 instruction is in the delay slot of the first call/branch. */
1437 if (is_branch (inst
))
1440 /* What a crock. The HP compilers set args_stored even if no
1441 arguments were stored into the stack (boo hiss). This could
1442 cause this code to then skip a bunch of user insns (up to the
1445 To combat this we try to identify when args_stored was bogusly
1446 set and clear it. We only do this when args_stored is nonzero,
1447 all other resources are accounted for, and nothing changed on
1450 && !(save_gr
|| save_fr
|| save_rp
|| save_sp
|| stack_remaining
> 0)
1451 && old_save_gr
== save_gr
&& old_save_fr
== save_fr
1452 && old_save_rp
== save_rp
&& old_save_sp
== save_sp
1453 && old_stack_remaining
== stack_remaining
)
1460 /* We've got a tenative location for the end of the prologue. However
1461 because of limitations in the unwind descriptor mechanism we may
1462 have went too far into user code looking for the save of a register
1463 that does not exist. So, if there registers we expected to be saved
1464 but never were, mask them out and restart.
1466 This should only happen in optimized code, and should be very rare. */
1467 if (save_gr
|| (save_fr
&& !(restart_fr
|| restart_gr
)))
1470 restart_gr
= save_gr
;
1471 restart_fr
= save_fr
;
1479 /* Return the address of the PC after the last prologue instruction if
1480 we can determine it from the debug symbols. Else return zero. */
1483 after_prologue (CORE_ADDR pc
)
1485 struct symtab_and_line sal
;
1486 CORE_ADDR func_addr
, func_end
;
1489 /* If we can not find the symbol in the partial symbol table, then
1490 there is no hope we can determine the function's start address
1492 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
1495 /* Get the line associated with FUNC_ADDR. */
1496 sal
= find_pc_line (func_addr
, 0);
1498 /* There are only two cases to consider. First, the end of the source line
1499 is within the function bounds. In that case we return the end of the
1500 source line. Second is the end of the source line extends beyond the
1501 bounds of the current function. We need to use the slow code to
1502 examine instructions in that case.
1504 Anything else is simply a bug elsewhere. Fixing it here is absolutely
1505 the wrong thing to do. In fact, it should be entirely possible for this
1506 function to always return zero since the slow instruction scanning code
1507 is supposed to *always* work. If it does not, then it is a bug. */
1508 if (sal
.end
< func_end
)
1514 /* To skip prologues, I use this predicate. Returns either PC itself
1515 if the code at PC does not look like a function prologue; otherwise
1516 returns an address that (if we're lucky) follows the prologue. If
1517 LENIENT, then we must skip everything which is involved in setting
1518 up the frame (it's OK to skip more, just so long as we don't skip
1519 anything which might clobber the registers which are being saved.
1520 Currently we must not skip more on the alpha, but we might the lenient
1524 hppa_skip_prologue (CORE_ADDR pc
)
1528 CORE_ADDR post_prologue_pc
;
1531 /* See if we can determine the end of the prologue via the symbol table.
1532 If so, then return either PC, or the PC after the prologue, whichever
1535 post_prologue_pc
= after_prologue (pc
);
1537 /* If after_prologue returned a useful address, then use it. Else
1538 fall back on the instruction skipping code.
1540 Some folks have claimed this causes problems because the breakpoint
1541 may be the first instruction of the prologue. If that happens, then
1542 the instruction skipping code has a bug that needs to be fixed. */
1543 if (post_prologue_pc
!= 0)
1544 return max (pc
, post_prologue_pc
);
1546 return (skip_prologue_hard_way (pc
));
1549 struct hppa_frame_cache
1552 struct trad_frame_saved_reg
*saved_regs
;
1555 static struct hppa_frame_cache
*
1556 hppa_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
1558 struct hppa_frame_cache
*cache
;
1563 struct unwind_table_entry
*u
;
1564 CORE_ADDR prologue_end
;
1568 fprintf_unfiltered (gdb_stdlog
, "{ hppa_frame_cache (frame=%d) -> ",
1569 frame_relative_level(next_frame
));
1571 if ((*this_cache
) != NULL
)
1574 fprintf_unfiltered (gdb_stdlog
, "base=0x%s (cached) }",
1575 paddr_nz (((struct hppa_frame_cache
*)*this_cache
)->base
));
1576 return (*this_cache
);
1578 cache
= FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache
);
1579 (*this_cache
) = cache
;
1580 cache
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1583 u
= find_unwind_entry (frame_pc_unwind (next_frame
));
1587 fprintf_unfiltered (gdb_stdlog
, "base=NULL (no unwind entry) }");
1588 return (*this_cache
);
1591 /* Turn the Entry_GR field into a bitmask. */
1593 for (i
= 3; i
< u
->Entry_GR
+ 3; i
++)
1595 /* Frame pointer gets saved into a special location. */
1596 if (u
->Save_SP
&& i
== HPPA_FP_REGNUM
)
1599 saved_gr_mask
|= (1 << i
);
1602 /* Turn the Entry_FR field into a bitmask too. */
1604 for (i
= 12; i
< u
->Entry_FR
+ 12; i
++)
1605 saved_fr_mask
|= (1 << i
);
1607 /* Loop until we find everything of interest or hit a branch.
1609 For unoptimized GCC code and for any HP CC code this will never ever
1610 examine any user instructions.
1612 For optimized GCC code we're faced with problems. GCC will schedule
1613 its prologue and make prologue instructions available for delay slot
1614 filling. The end result is user code gets mixed in with the prologue
1615 and a prologue instruction may be in the delay slot of the first branch
1618 Some unexpected things are expected with debugging optimized code, so
1619 we allow this routine to walk past user instructions in optimized
1622 int final_iteration
= 0;
1623 CORE_ADDR pc
, end_pc
;
1624 int looking_for_sp
= u
->Save_SP
;
1625 int looking_for_rp
= u
->Save_RP
;
1628 /* We have to use hppa_skip_prologue instead of just
1629 skip_prologue_using_sal, in case we stepped into a function without
1630 symbol information. hppa_skip_prologue also bounds the returned
1631 pc by the passed in pc, so it will not return a pc in the next
1634 /* We used to use frame_func_unwind () to locate the beginning of the
1635 function to pass to skip_prologue (). However, when objects are
1636 compiled without debug symbols, frame_func_unwind can return the wrong
1637 function (or 0). We can do better than that by using unwind records. */
1639 prologue_end
= hppa_skip_prologue (u
->region_start
);
1640 end_pc
= frame_pc_unwind (next_frame
);
1642 if (prologue_end
!= 0 && end_pc
> prologue_end
)
1643 end_pc
= prologue_end
;
1647 for (pc
= u
->region_start
;
1648 ((saved_gr_mask
|| saved_fr_mask
1649 || looking_for_sp
|| looking_for_rp
1650 || frame_size
< (u
->Total_frame_size
<< 3))
1658 if (!safe_frame_unwind_memory (next_frame
, pc
, buf4
,
1661 error ("Cannot read instruction at 0x%s\n", paddr_nz (pc
));
1662 return (*this_cache
);
1665 inst
= extract_unsigned_integer (buf4
, sizeof buf4
);
1667 /* Note the interesting effects of this instruction. */
1668 frame_size
+= prologue_inst_adjust_sp (inst
);
1670 /* There are limited ways to store the return pointer into the
1672 if (inst
== 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
1675 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
= -20;
1677 else if (inst
== 0x6bc23fd1) /* stw rp,-0x18(sr0,sp) */
1680 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
= -24;
1682 else if (inst
== 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
1685 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
= -16;
1688 /* Check to see if we saved SP into the stack. This also
1689 happens to indicate the location of the saved frame
1691 if ((inst
& 0xffffc000) == 0x6fc10000 /* stw,ma r1,N(sr0,sp) */
1692 || (inst
& 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
1695 cache
->saved_regs
[HPPA_FP_REGNUM
].addr
= 0;
1698 /* Account for general and floating-point register saves. */
1699 reg
= inst_saves_gr (inst
);
1700 if (reg
>= 3 && reg
<= 18
1701 && (!u
->Save_SP
|| reg
!= HPPA_FP_REGNUM
))
1703 saved_gr_mask
&= ~(1 << reg
);
1704 if ((inst
>> 26) == 0x1b && hppa_extract_14 (inst
) >= 0)
1705 /* stwm with a positive displacement is a _post_
1707 cache
->saved_regs
[reg
].addr
= 0;
1708 else if ((inst
& 0xfc00000c) == 0x70000008)
1709 /* A std has explicit post_modify forms. */
1710 cache
->saved_regs
[reg
].addr
= 0;
1715 if ((inst
>> 26) == 0x1c)
1716 offset
= (inst
& 0x1 ? -1 << 13 : 0) | (((inst
>> 4) & 0x3ff) << 3);
1717 else if ((inst
>> 26) == 0x03)
1718 offset
= hppa_low_hppa_sign_extend (inst
& 0x1f, 5);
1720 offset
= hppa_extract_14 (inst
);
1722 /* Handle code with and without frame pointers. */
1724 cache
->saved_regs
[reg
].addr
= offset
;
1726 cache
->saved_regs
[reg
].addr
= (u
->Total_frame_size
<< 3) + offset
;
1730 /* GCC handles callee saved FP regs a little differently.
1732 It emits an instruction to put the value of the start of
1733 the FP store area into %r1. It then uses fstds,ma with a
1734 basereg of %r1 for the stores.
1736 HP CC emits them at the current stack pointer modifying the
1737 stack pointer as it stores each register. */
1739 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
1740 if ((inst
& 0xffffc000) == 0x34610000
1741 || (inst
& 0xffffc000) == 0x37c10000)
1742 fp_loc
= hppa_extract_14 (inst
);
1744 reg
= inst_saves_fr (inst
);
1745 if (reg
>= 12 && reg
<= 21)
1747 /* Note +4 braindamage below is necessary because the FP
1748 status registers are internally 8 registers rather than
1749 the expected 4 registers. */
1750 saved_fr_mask
&= ~(1 << reg
);
1753 /* 1st HP CC FP register store. After this
1754 instruction we've set enough state that the GCC and
1755 HPCC code are both handled in the same manner. */
1756 cache
->saved_regs
[reg
+ HPPA_FP4_REGNUM
+ 4].addr
= 0;
1761 cache
->saved_regs
[reg
+ HPPA_FP0_REGNUM
+ 4].addr
= fp_loc
;
1766 /* Quit if we hit any kind of branch the previous iteration. */
1767 if (final_iteration
)
1769 /* We want to look precisely one instruction beyond the branch
1770 if we have not found everything yet. */
1771 if (is_branch (inst
))
1772 final_iteration
= 1;
1777 /* The frame base always represents the value of %sp at entry to
1778 the current function (and is thus equivalent to the "saved"
1780 CORE_ADDR this_sp
= frame_unwind_register_unsigned (next_frame
, HPPA_SP_REGNUM
);
1784 fprintf_unfiltered (gdb_stdlog
, " (this_sp=0x%s, pc=0x%s, "
1785 "prologue_end=0x%s) ",
1787 paddr_nz (frame_pc_unwind (next_frame
)),
1788 paddr_nz (prologue_end
));
1790 /* Check to see if a frame pointer is available, and use it for
1791 frame unwinding if it is.
1793 There are some situations where we need to rely on the frame
1794 pointer to do stack unwinding. For example, if a function calls
1795 alloca (), the stack pointer can get adjusted inside the body of
1796 the function. In this case, the ABI requires that the compiler
1797 maintain a frame pointer for the function.
1799 The unwind record has a flag (alloca_frame) that indicates that
1800 a function has a variable frame; unfortunately, gcc/binutils
1801 does not set this flag. Instead, whenever a frame pointer is used
1802 and saved on the stack, the Save_SP flag is set. We use this to
1803 decide whether to use the frame pointer for unwinding.
1805 fp may be zero if it is not available in an inner frame because
1806 it has been modified by not yet saved.
1808 TODO: For the HP compiler, maybe we should use the alloca_frame flag
1809 instead of Save_SP. */
1811 fp
= frame_unwind_register_unsigned (next_frame
, HPPA_FP_REGNUM
);
1813 if (frame_pc_unwind (next_frame
) >= prologue_end
1814 && u
->Save_SP
&& fp
!= 0)
1819 fprintf_unfiltered (gdb_stdlog
, " (base=0x%s) [frame pointer] }",
1820 paddr_nz (cache
->base
));
1823 && trad_frame_addr_p (cache
->saved_regs
, HPPA_SP_REGNUM
))
1825 /* Both we're expecting the SP to be saved and the SP has been
1826 saved. The entry SP value is saved at this frame's SP
1828 cache
->base
= read_memory_integer (this_sp
, TARGET_PTR_BIT
/ 8);
1831 fprintf_unfiltered (gdb_stdlog
, " (base=0x%s) [saved] }",
1832 paddr_nz (cache
->base
));
1836 /* The prologue has been slowly allocating stack space. Adjust
1838 cache
->base
= this_sp
- frame_size
;
1840 fprintf_unfiltered (gdb_stdlog
, " (base=0x%s) [unwind adjust] } ",
1841 paddr_nz (cache
->base
));
1844 trad_frame_set_value (cache
->saved_regs
, HPPA_SP_REGNUM
, cache
->base
);
1847 /* The PC is found in the "return register", "Millicode" uses "r31"
1848 as the return register while normal code uses "rp". */
1851 if (trad_frame_addr_p (cache
->saved_regs
, 31))
1852 cache
->saved_regs
[HPPA_PCOQ_HEAD_REGNUM
] = cache
->saved_regs
[31];
1855 ULONGEST r31
= frame_unwind_register_unsigned (next_frame
, 31);
1856 trad_frame_set_value (cache
->saved_regs
, HPPA_PCOQ_HEAD_REGNUM
, r31
);
1861 if (trad_frame_addr_p (cache
->saved_regs
, HPPA_RP_REGNUM
))
1862 cache
->saved_regs
[HPPA_PCOQ_HEAD_REGNUM
] = cache
->saved_regs
[HPPA_RP_REGNUM
];
1865 ULONGEST rp
= frame_unwind_register_unsigned (next_frame
, HPPA_RP_REGNUM
);
1866 trad_frame_set_value (cache
->saved_regs
, HPPA_PCOQ_HEAD_REGNUM
, rp
);
1870 /* If the frame pointer was not saved in this frame, but we should be saving
1871 it, set it to an invalid value so that another frame will not pick up the
1872 wrong frame pointer. This can happen if we start unwinding after the
1873 frame pointer has been modified, but before we've saved it to the
1875 if (u
->Save_SP
&& !trad_frame_addr_p (cache
->saved_regs
, HPPA_FP_REGNUM
))
1876 trad_frame_set_value (cache
->saved_regs
, HPPA_FP_REGNUM
, 0);
1879 /* Convert all the offsets into addresses. */
1881 for (reg
= 0; reg
< NUM_REGS
; reg
++)
1883 if (trad_frame_addr_p (cache
->saved_regs
, reg
))
1884 cache
->saved_regs
[reg
].addr
+= cache
->base
;
1889 fprintf_unfiltered (gdb_stdlog
, "base=0x%s }",
1890 paddr_nz (((struct hppa_frame_cache
*)*this_cache
)->base
));
1891 return (*this_cache
);
1895 hppa_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
1896 struct frame_id
*this_id
)
1898 struct hppa_frame_cache
*info
;
1899 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1900 struct unwind_table_entry
*u
;
1902 info
= hppa_frame_cache (next_frame
, this_cache
);
1903 u
= find_unwind_entry (pc
);
1905 (*this_id
) = frame_id_build (info
->base
, u
->region_start
);
1909 hppa_frame_prev_register (struct frame_info
*next_frame
,
1911 int regnum
, int *optimizedp
,
1912 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1913 int *realnump
, void *valuep
)
1915 struct hppa_frame_cache
*info
= hppa_frame_cache (next_frame
, this_cache
);
1916 hppa_frame_prev_register_helper (next_frame
, info
->saved_regs
, regnum
,
1917 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
1920 static const struct frame_unwind hppa_frame_unwind
=
1924 hppa_frame_prev_register
1927 static const struct frame_unwind
*
1928 hppa_frame_unwind_sniffer (struct frame_info
*next_frame
)
1930 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1932 if (find_unwind_entry (pc
))
1933 return &hppa_frame_unwind
;
1938 /* This is a generic fallback frame unwinder that kicks in if we fail all
1939 the other ones. Normally we would expect the stub and regular unwinder
1940 to work, but in some cases we might hit a function that just doesn't
1941 have any unwind information available. In this case we try to do
1942 unwinding solely based on code reading. This is obviously going to be
1943 slow, so only use this as a last resort. Currently this will only
1944 identify the stack and pc for the frame. */
1946 static struct hppa_frame_cache
*
1947 hppa_fallback_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
1949 struct hppa_frame_cache
*cache
;
1950 unsigned int frame_size
;
1952 CORE_ADDR pc
, start_pc
, end_pc
, cur_pc
;
1955 fprintf_unfiltered (gdb_stdlog
, "{ hppa_fallback_frame_cache (frame=%d)-> ",
1956 frame_relative_level(next_frame
));
1958 cache
= FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache
);
1959 (*this_cache
) = cache
;
1960 cache
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1962 pc
= frame_func_unwind (next_frame
);
1963 cur_pc
= frame_pc_unwind (next_frame
);
1967 find_pc_partial_function (pc
, NULL
, &start_pc
, &end_pc
);
1969 if (start_pc
== 0 || end_pc
== 0)
1971 error ("Cannot find bounds of current function (@0x%s), unwinding will "
1972 "fail.", paddr_nz (pc
));
1976 if (end_pc
> cur_pc
)
1979 for (pc
= start_pc
; pc
< end_pc
; pc
+= 4)
1983 insn
= read_memory_unsigned_integer (pc
, 4);
1985 frame_size
+= prologue_inst_adjust_sp (insn
);
1987 /* There are limited ways to store the return pointer into the
1989 if (insn
== 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
1991 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
= -20;
1994 else if (insn
== 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
1996 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
= -16;
2002 fprintf_unfiltered (gdb_stdlog
, " frame_size = %d, found_rp = %d }\n",
2003 frame_size
, found_rp
);
2005 cache
->base
= frame_unwind_register_unsigned (next_frame
, HPPA_SP_REGNUM
) - frame_size
;
2006 trad_frame_set_value (cache
->saved_regs
, HPPA_SP_REGNUM
, cache
->base
);
2008 if (trad_frame_addr_p (cache
->saved_regs
, HPPA_RP_REGNUM
))
2010 cache
->saved_regs
[HPPA_RP_REGNUM
].addr
+= cache
->base
;
2011 cache
->saved_regs
[HPPA_PCOQ_HEAD_REGNUM
] = cache
->saved_regs
[HPPA_RP_REGNUM
];
2015 ULONGEST rp
= frame_unwind_register_unsigned (next_frame
, HPPA_RP_REGNUM
);
2016 trad_frame_set_value (cache
->saved_regs
, HPPA_PCOQ_HEAD_REGNUM
, rp
);
2023 hppa_fallback_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
2024 struct frame_id
*this_id
)
2026 struct hppa_frame_cache
*info
=
2027 hppa_fallback_frame_cache (next_frame
, this_cache
);
2028 (*this_id
) = frame_id_build (info
->base
, frame_func_unwind (next_frame
));
2032 hppa_fallback_frame_prev_register (struct frame_info
*next_frame
,
2034 int regnum
, int *optimizedp
,
2035 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
2036 int *realnump
, void *valuep
)
2038 struct hppa_frame_cache
*info
=
2039 hppa_fallback_frame_cache (next_frame
, this_cache
);
2040 hppa_frame_prev_register_helper (next_frame
, info
->saved_regs
, regnum
,
2041 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
2044 static const struct frame_unwind hppa_fallback_frame_unwind
=
2047 hppa_fallback_frame_this_id
,
2048 hppa_fallback_frame_prev_register
2051 static const struct frame_unwind
*
2052 hppa_fallback_unwind_sniffer (struct frame_info
*next_frame
)
2054 return &hppa_fallback_frame_unwind
;
2057 /* Stub frames, used for all kinds of call stubs. */
2058 struct hppa_stub_unwind_cache
2061 struct trad_frame_saved_reg
*saved_regs
;
2064 static struct hppa_stub_unwind_cache
*
2065 hppa_stub_frame_unwind_cache (struct frame_info
*next_frame
,
2068 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
2069 struct hppa_stub_unwind_cache
*info
;
2070 struct unwind_table_entry
*u
;
2075 info
= FRAME_OBSTACK_ZALLOC (struct hppa_stub_unwind_cache
);
2077 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
2079 info
->base
= frame_unwind_register_unsigned (next_frame
, HPPA_SP_REGNUM
);
2081 if (gdbarch_osabi (gdbarch
) == GDB_OSABI_HPUX_SOM
)
2083 /* HPUX uses export stubs in function calls; the export stub clobbers
2084 the return value of the caller, and, later restores it from the
2086 u
= find_unwind_entry (frame_pc_unwind (next_frame
));
2088 if (u
&& u
->stub_unwind
.stub_type
== EXPORT
)
2090 info
->saved_regs
[HPPA_PCOQ_HEAD_REGNUM
].addr
= info
->base
- 24;
2096 /* By default we assume that stubs do not change the rp. */
2097 info
->saved_regs
[HPPA_PCOQ_HEAD_REGNUM
].realreg
= HPPA_RP_REGNUM
;
2103 hppa_stub_frame_this_id (struct frame_info
*next_frame
,
2104 void **this_prologue_cache
,
2105 struct frame_id
*this_id
)
2107 struct hppa_stub_unwind_cache
*info
2108 = hppa_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
2109 *this_id
= frame_id_build (info
->base
, frame_pc_unwind (next_frame
));
2113 hppa_stub_frame_prev_register (struct frame_info
*next_frame
,
2114 void **this_prologue_cache
,
2115 int regnum
, int *optimizedp
,
2116 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
2117 int *realnump
, void *valuep
)
2119 struct hppa_stub_unwind_cache
*info
2120 = hppa_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
2121 hppa_frame_prev_register_helper (next_frame
, info
->saved_regs
, regnum
,
2122 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
2125 static const struct frame_unwind hppa_stub_frame_unwind
= {
2127 hppa_stub_frame_this_id
,
2128 hppa_stub_frame_prev_register
2131 static const struct frame_unwind
*
2132 hppa_stub_unwind_sniffer (struct frame_info
*next_frame
)
2134 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
2135 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
2136 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2139 || (tdep
->in_solib_call_trampoline
!= NULL
2140 && tdep
->in_solib_call_trampoline (pc
, NULL
))
2141 || IN_SOLIB_RETURN_TRAMPOLINE (pc
, NULL
))
2142 return &hppa_stub_frame_unwind
;
2146 static struct frame_id
2147 hppa_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2149 return frame_id_build (frame_unwind_register_unsigned (next_frame
,
2151 frame_pc_unwind (next_frame
));
2155 hppa_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2157 return frame_unwind_register_signed (next_frame
, HPPA_PCOQ_HEAD_REGNUM
) & ~3;
2160 /* Instead of this nasty cast, add a method pvoid() that prints out a
2161 host VOID data type (remember %p isn't portable). */
2164 hppa_pointer_to_address_hack (void *ptr
)
2166 gdb_assert (sizeof (ptr
) == TYPE_LENGTH (builtin_type_void_data_ptr
));
2167 return POINTER_TO_ADDRESS (builtin_type_void_data_ptr
, &ptr
);
2171 unwind_command (char *exp
, int from_tty
)
2174 struct unwind_table_entry
*u
;
2176 /* If we have an expression, evaluate it and use it as the address. */
2178 if (exp
!= 0 && *exp
!= 0)
2179 address
= parse_and_eval_address (exp
);
2183 u
= find_unwind_entry (address
);
2187 printf_unfiltered ("Can't find unwind table entry for %s\n", exp
);
2191 printf_unfiltered ("unwind_table_entry (0x%s):\n",
2192 paddr_nz (hppa_pointer_to_address_hack (u
)));
2194 printf_unfiltered ("\tregion_start = ");
2195 print_address (u
->region_start
, gdb_stdout
);
2196 gdb_flush (gdb_stdout
);
2198 printf_unfiltered ("\n\tregion_end = ");
2199 print_address (u
->region_end
, gdb_stdout
);
2200 gdb_flush (gdb_stdout
);
2202 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
2204 printf_unfiltered ("\n\tflags =");
2205 pif (Cannot_unwind
);
2207 pif (Millicode_save_sr0
);
2210 pif (Variable_Frame
);
2211 pif (Separate_Package_Body
);
2212 pif (Frame_Extension_Millicode
);
2213 pif (Stack_Overflow_Check
);
2214 pif (Two_Instruction_SP_Increment
);
2218 pif (Save_MRP_in_frame
);
2219 pif (extn_ptr_defined
);
2220 pif (Cleanup_defined
);
2221 pif (MPE_XL_interrupt_marker
);
2222 pif (HP_UX_interrupt_marker
);
2225 putchar_unfiltered ('\n');
2227 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
2229 pin (Region_description
);
2232 pin (Total_frame_size
);
2236 hppa_skip_permanent_breakpoint (void)
2238 /* To step over a breakpoint instruction on the PA takes some
2239 fiddling with the instruction address queue.
2241 When we stop at a breakpoint, the IA queue front (the instruction
2242 we're executing now) points at the breakpoint instruction, and
2243 the IA queue back (the next instruction to execute) points to
2244 whatever instruction we would execute after the breakpoint, if it
2245 were an ordinary instruction. This is the case even if the
2246 breakpoint is in the delay slot of a branch instruction.
2248 Clearly, to step past the breakpoint, we need to set the queue
2249 front to the back. But what do we put in the back? What
2250 instruction comes after that one? Because of the branch delay
2251 slot, the next insn is always at the back + 4. */
2252 write_register (HPPA_PCOQ_HEAD_REGNUM
, read_register (HPPA_PCOQ_TAIL_REGNUM
));
2253 write_register (HPPA_PCSQ_HEAD_REGNUM
, read_register (HPPA_PCSQ_TAIL_REGNUM
));
2255 write_register (HPPA_PCOQ_TAIL_REGNUM
, read_register (HPPA_PCOQ_TAIL_REGNUM
) + 4);
2256 /* We can leave the tail's space the same, since there's no jump. */
2260 hppa_pc_requires_run_before_use (CORE_ADDR pc
)
2262 /* Sometimes we may pluck out a minimal symbol that has a negative address.
2264 An example of this occurs when an a.out is linked against a foo.sl.
2265 The foo.sl defines a global bar(), and the a.out declares a signature
2266 for bar(). However, the a.out doesn't directly call bar(), but passes
2267 its address in another call.
2269 If you have this scenario and attempt to "break bar" before running,
2270 gdb will find a minimal symbol for bar() in the a.out. But that
2271 symbol's address will be negative. What this appears to denote is
2272 an index backwards from the base of the procedure linkage table (PLT)
2273 into the data linkage table (DLT), the end of which is contiguous
2274 with the start of the PLT. This is clearly not a valid address for
2275 us to set a breakpoint on.
2277 Note that one must be careful in how one checks for a negative address.
2278 0xc0000000 is a legitimate address of something in a shared text
2279 segment, for example. Since I don't know what the possible range
2280 is of these "really, truly negative" addresses that come from the
2281 minimal symbols, I'm resorting to the gross hack of checking the
2282 top byte of the address for all 1's. Sigh. */
2284 return (!target_has_stack
&& (pc
& 0xFF000000));
2288 hppa_instruction_nullified (void)
2290 /* brobecker 2002/11/07: Couldn't we use a ULONGEST here? It would
2291 avoid the type cast. I'm leaving it as is for now as I'm doing
2292 semi-mechanical multiarching-related changes. */
2293 const int ipsw
= (int) read_register (HPPA_IPSW_REGNUM
);
2294 const int flags
= (int) read_register (HPPA_FLAGS_REGNUM
);
2296 return ((ipsw
& 0x00200000) && !(flags
& 0x2));
2299 /* Return the GDB type object for the "standard" data type of data
2302 static struct type
*
2303 hppa32_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
2305 if (reg_nr
< HPPA_FP4_REGNUM
)
2306 return builtin_type_uint32
;
2308 return builtin_type_ieee_single_big
;
2311 /* Return the GDB type object for the "standard" data type of data
2312 in register N. hppa64 version. */
2314 static struct type
*
2315 hppa64_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
2317 if (reg_nr
< HPPA_FP4_REGNUM
)
2318 return builtin_type_uint64
;
2320 return builtin_type_ieee_double_big
;
2323 /* Return True if REGNUM is not a register available to the user
2324 through ptrace(). */
2327 hppa_cannot_store_register (int regnum
)
2330 || regnum
== HPPA_PCSQ_HEAD_REGNUM
2331 || (regnum
>= HPPA_PCSQ_TAIL_REGNUM
&& regnum
< HPPA_IPSW_REGNUM
)
2332 || (regnum
> HPPA_IPSW_REGNUM
&& regnum
< HPPA_FP4_REGNUM
));
2337 hppa_smash_text_address (CORE_ADDR addr
)
2339 /* The low two bits of the PC on the PA contain the privilege level.
2340 Some genius implementing a (non-GCC) compiler apparently decided
2341 this means that "addresses" in a text section therefore include a
2342 privilege level, and thus symbol tables should contain these bits.
2343 This seems like a bonehead thing to do--anyway, it seems to work
2344 for our purposes to just ignore those bits. */
2346 return (addr
&= ~0x3);
2349 /* Get the ith function argument for the current function. */
2351 hppa_fetch_pointer_argument (struct frame_info
*frame
, int argi
,
2355 get_frame_register (frame
, HPPA_R0_REGNUM
+ 26 - argi
, &addr
);
2360 hppa_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
2361 int regnum
, void *buf
)
2365 regcache_raw_read_unsigned (regcache
, regnum
, &tmp
);
2366 if (regnum
== HPPA_PCOQ_HEAD_REGNUM
|| regnum
== HPPA_PCOQ_TAIL_REGNUM
)
2368 store_unsigned_integer (buf
, sizeof(tmp
), tmp
);
2372 hppa_find_global_pointer (struct value
*function
)
2378 hppa_frame_prev_register_helper (struct frame_info
*next_frame
,
2379 struct trad_frame_saved_reg saved_regs
[],
2380 int regnum
, int *optimizedp
,
2381 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
2382 int *realnump
, void *valuep
)
2384 if (regnum
== HPPA_PCOQ_TAIL_REGNUM
)
2390 trad_frame_get_prev_register (next_frame
, saved_regs
,
2391 HPPA_PCOQ_HEAD_REGNUM
, optimizedp
,
2392 lvalp
, addrp
, realnump
, valuep
);
2394 pc
= extract_unsigned_integer (valuep
, 4);
2395 store_unsigned_integer (valuep
, 4, pc
+ 4);
2398 /* It's a computed value. */
2406 trad_frame_get_prev_register (next_frame
, saved_regs
, regnum
,
2407 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
2411 /* Here is a table of C type sizes on hppa with various compiles
2412 and options. I measured this on PA 9000/800 with HP-UX 11.11
2413 and these compilers:
2415 /usr/ccs/bin/cc HP92453-01 A.11.01.21
2416 /opt/ansic/bin/cc HP92453-01 B.11.11.28706.GP
2417 /opt/aCC/bin/aCC B3910B A.03.45
2418 gcc gcc 3.3.2 native hppa2.0w-hp-hpux11.11
2420 cc : 1 2 4 4 8 : 4 8 -- : 4 4
2421 ansic +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
2422 ansic +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
2423 ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2424 acc +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
2425 acc +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
2426 acc +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
2427 gcc : 1 2 4 4 8 : 4 8 16 : 4 4
2431 compiler and options
2432 char, short, int, long, long long
2433 float, double, long double
2436 So all these compilers use either ILP32 or LP64 model.
2437 TODO: gcc has more options so it needs more investigation.
2439 For floating point types, see:
2441 http://docs.hp.com/hpux/pdf/B3906-90006.pdf
2442 HP-UX floating-point guide, hpux 11.00
2444 -- chastain 2003-12-18 */
2446 static struct gdbarch
*
2447 hppa_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2449 struct gdbarch_tdep
*tdep
;
2450 struct gdbarch
*gdbarch
;
2452 /* Try to determine the ABI of the object we are loading. */
2453 if (info
.abfd
!= NULL
&& info
.osabi
== GDB_OSABI_UNKNOWN
)
2455 /* If it's a SOM file, assume it's HP/UX SOM. */
2456 if (bfd_get_flavour (info
.abfd
) == bfd_target_som_flavour
)
2457 info
.osabi
= GDB_OSABI_HPUX_SOM
;
2460 /* find a candidate among the list of pre-declared architectures. */
2461 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2463 return (arches
->gdbarch
);
2465 /* If none found, then allocate and initialize one. */
2466 tdep
= XZALLOC (struct gdbarch_tdep
);
2467 gdbarch
= gdbarch_alloc (&info
, tdep
);
2469 /* Determine from the bfd_arch_info structure if we are dealing with
2470 a 32 or 64 bits architecture. If the bfd_arch_info is not available,
2471 then default to a 32bit machine. */
2472 if (info
.bfd_arch_info
!= NULL
)
2473 tdep
->bytes_per_address
=
2474 info
.bfd_arch_info
->bits_per_address
/ info
.bfd_arch_info
->bits_per_byte
;
2476 tdep
->bytes_per_address
= 4;
2478 tdep
->find_global_pointer
= hppa_find_global_pointer
;
2480 /* Some parts of the gdbarch vector depend on whether we are running
2481 on a 32 bits or 64 bits target. */
2482 switch (tdep
->bytes_per_address
)
2485 set_gdbarch_num_regs (gdbarch
, hppa32_num_regs
);
2486 set_gdbarch_register_name (gdbarch
, hppa32_register_name
);
2487 set_gdbarch_register_type (gdbarch
, hppa32_register_type
);
2490 set_gdbarch_num_regs (gdbarch
, hppa64_num_regs
);
2491 set_gdbarch_register_name (gdbarch
, hppa64_register_name
);
2492 set_gdbarch_register_type (gdbarch
, hppa64_register_type
);
2495 internal_error (__FILE__
, __LINE__
, "Unsupported address size: %d",
2496 tdep
->bytes_per_address
);
2499 set_gdbarch_long_bit (gdbarch
, tdep
->bytes_per_address
* TARGET_CHAR_BIT
);
2500 set_gdbarch_ptr_bit (gdbarch
, tdep
->bytes_per_address
* TARGET_CHAR_BIT
);
2502 /* The following gdbarch vector elements are the same in both ILP32
2503 and LP64, but might show differences some day. */
2504 set_gdbarch_long_long_bit (gdbarch
, 64);
2505 set_gdbarch_long_double_bit (gdbarch
, 128);
2506 set_gdbarch_long_double_format (gdbarch
, &floatformat_ia64_quad_big
);
2508 /* The following gdbarch vector elements do not depend on the address
2509 size, or in any other gdbarch element previously set. */
2510 set_gdbarch_skip_prologue (gdbarch
, hppa_skip_prologue
);
2511 set_gdbarch_inner_than (gdbarch
, core_addr_greaterthan
);
2512 set_gdbarch_sp_regnum (gdbarch
, HPPA_SP_REGNUM
);
2513 set_gdbarch_fp0_regnum (gdbarch
, HPPA_FP0_REGNUM
);
2514 set_gdbarch_cannot_store_register (gdbarch
, hppa_cannot_store_register
);
2515 set_gdbarch_cannot_fetch_register (gdbarch
, hppa_cannot_store_register
);
2516 set_gdbarch_addr_bits_remove (gdbarch
, hppa_smash_text_address
);
2517 set_gdbarch_smash_text_address (gdbarch
, hppa_smash_text_address
);
2518 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
2519 set_gdbarch_read_pc (gdbarch
, hppa_target_read_pc
);
2520 set_gdbarch_write_pc (gdbarch
, hppa_target_write_pc
);
2522 /* Helper for function argument information. */
2523 set_gdbarch_fetch_pointer_argument (gdbarch
, hppa_fetch_pointer_argument
);
2525 set_gdbarch_print_insn (gdbarch
, print_insn_hppa
);
2527 /* When a hardware watchpoint triggers, we'll move the inferior past
2528 it by removing all eventpoints; stepping past the instruction
2529 that caused the trigger; reinserting eventpoints; and checking
2530 whether any watched location changed. */
2531 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
2533 /* Inferior function call methods. */
2534 switch (tdep
->bytes_per_address
)
2537 set_gdbarch_push_dummy_call (gdbarch
, hppa32_push_dummy_call
);
2538 set_gdbarch_frame_align (gdbarch
, hppa32_frame_align
);
2539 set_gdbarch_convert_from_func_ptr_addr
2540 (gdbarch
, hppa32_convert_from_func_ptr_addr
);
2543 set_gdbarch_push_dummy_call (gdbarch
, hppa64_push_dummy_call
);
2544 set_gdbarch_frame_align (gdbarch
, hppa64_frame_align
);
2547 internal_error (__FILE__
, __LINE__
, "bad switch");
2550 /* Struct return methods. */
2551 switch (tdep
->bytes_per_address
)
2554 set_gdbarch_return_value (gdbarch
, hppa32_return_value
);
2557 set_gdbarch_return_value (gdbarch
, hppa64_return_value
);
2560 internal_error (__FILE__
, __LINE__
, "bad switch");
2563 set_gdbarch_breakpoint_from_pc (gdbarch
, hppa_breakpoint_from_pc
);
2564 set_gdbarch_pseudo_register_read (gdbarch
, hppa_pseudo_register_read
);
2566 /* Frame unwind methods. */
2567 set_gdbarch_unwind_dummy_id (gdbarch
, hppa_unwind_dummy_id
);
2568 set_gdbarch_unwind_pc (gdbarch
, hppa_unwind_pc
);
2570 /* Hook in ABI-specific overrides, if they have been registered. */
2571 gdbarch_init_osabi (info
, gdbarch
);
2573 /* Hook in the default unwinders. */
2574 frame_unwind_append_sniffer (gdbarch
, hppa_stub_unwind_sniffer
);
2575 frame_unwind_append_sniffer (gdbarch
, hppa_frame_unwind_sniffer
);
2576 frame_unwind_append_sniffer (gdbarch
, hppa_fallback_unwind_sniffer
);
2582 hppa_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
2584 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
2586 fprintf_unfiltered (file
, "bytes_per_address = %d\n",
2587 tdep
->bytes_per_address
);
2588 fprintf_unfiltered (file
, "elf = %s\n", tdep
->is_elf
? "yes" : "no");
2592 _initialize_hppa_tdep (void)
2594 struct cmd_list_element
*c
;
2595 void break_at_finish_command (char *arg
, int from_tty
);
2596 void tbreak_at_finish_command (char *arg
, int from_tty
);
2597 void break_at_finish_at_depth_command (char *arg
, int from_tty
);
2599 gdbarch_register (bfd_arch_hppa
, hppa_gdbarch_init
, hppa_dump_tdep
);
2601 hppa_objfile_priv_data
= register_objfile_data ();
2603 add_cmd ("unwind", class_maintenance
, unwind_command
,
2604 "Print unwind table entry at given address.",
2605 &maintenanceprintlist
);
2607 deprecate_cmd (add_com ("xbreak", class_breakpoint
,
2608 break_at_finish_command
,
2609 concat ("Set breakpoint at procedure exit. \n\
2610 Argument may be function name, or \"*\" and an address.\n\
2611 If function is specified, break at end of code for that function.\n\
2612 If an address is specified, break at the end of the function that contains \n\
2613 that exact address.\n",
2614 "With no arg, uses current execution address of selected stack frame.\n\
2615 This is useful for breaking on return to a stack frame.\n\
2617 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2619 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
)), NULL
);
2620 deprecate_cmd (add_com_alias ("xb", "xbreak", class_breakpoint
, 1), NULL
);
2621 deprecate_cmd (add_com_alias ("xbr", "xbreak", class_breakpoint
, 1), NULL
);
2622 deprecate_cmd (add_com_alias ("xbre", "xbreak", class_breakpoint
, 1), NULL
);
2623 deprecate_cmd (add_com_alias ("xbrea", "xbreak", class_breakpoint
, 1), NULL
);
2625 deprecate_cmd (c
= add_com ("txbreak", class_breakpoint
,
2626 tbreak_at_finish_command
,
2627 "Set temporary breakpoint at procedure exit. Either there should\n\
2628 be no argument or the argument must be a depth.\n"), NULL
);
2629 set_cmd_completer (c
, location_completer
);
2632 deprecate_cmd (add_com ("bx", class_breakpoint
,
2633 break_at_finish_at_depth_command
,
2634 "Set breakpoint at procedure exit. Either there should\n\
2635 be no argument or the argument must be a depth.\n"), NULL
);
2637 /* Debug this files internals. */
2638 add_setshow_boolean_cmd ("hppa", class_maintenance
, &hppa_debug
, "\
2639 Set whether hppa target specific debugging information should be displayed.", "\
2640 Show whether hppa target specific debugging information is displayed.", "\
2641 This flag controls whether hppa target specific debugging information is\n\
2642 displayed. This information is particularly useful for debugging frame\n\
2643 unwinding problems.", "hppa debug flag is %s.",
2644 NULL
, NULL
, &setdebuglist
, &showdebuglist
);