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