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