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