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