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