1f0b3d061911e05c676ce7fdd573911d9098bc4c
[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 Free Software Foundation, Inc.
5
6 Contributed by the Center for Software Science at the
7 University of Utah (pa-gdb-bugs@cs.utah.edu).
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
25
26 #include "defs.h"
27 #include "frame.h"
28 #include "bfd.h"
29 #include "inferior.h"
30 #include "value.h"
31 #include "regcache.h"
32 #include "completer.h"
33 #include "language.h"
34 #include "osabi.h"
35 #include "gdb_assert.h"
36 #include "infttrace.h"
37 /* For argument passing to the inferior */
38 #include "symtab.h"
39 #include "infcall.h"
40
41 #ifdef USG
42 #include <sys/types.h>
43 #endif
44
45 #include <dl.h>
46 #include <sys/param.h>
47 #include <signal.h>
48
49 #include <sys/ptrace.h>
50 #include <machine/save_state.h>
51
52 #ifdef COFF_ENCAPSULATE
53 #include "a.out.encap.h"
54 #else
55 #endif
56
57 /*#include <sys/user.h> After a.out.h */
58 #include <sys/file.h>
59 #include "gdb_stat.h"
60 #include "gdb_wait.h"
61
62 #include "gdbcore.h"
63 #include "gdbcmd.h"
64 #include "target.h"
65 #include "symfile.h"
66 #include "objfiles.h"
67 #include "hppa-tdep.h"
68
69 /* Some local constants. */
70 static const int hppa32_num_regs = 128;
71 static const int hppa64_num_regs = 96;
72
73 static const int hppa64_call_dummy_breakpoint_offset = 22 * 4;
74
75 /* DEPRECATED_CALL_DUMMY_LENGTH is computed based on the size of a
76 word on the target machine, not the size of an instruction. Since
77 a word on this target holds two instructions we have to divide the
78 instruction size by two to get the word size of the dummy. */
79 static const int hppa32_call_dummy_length = INSTRUCTION_SIZE * 28;
80 static const int hppa64_call_dummy_length = INSTRUCTION_SIZE * 26 / 2;
81
82 /* Get at various relevent fields of an instruction word. */
83 #define MASK_5 0x1f
84 #define MASK_11 0x7ff
85 #define MASK_14 0x3fff
86 #define MASK_21 0x1fffff
87
88 /* Define offsets into the call dummy for the target function address.
89 See comments related to CALL_DUMMY for more info. */
90 #define FUNC_LDIL_OFFSET (INSTRUCTION_SIZE * 9)
91 #define FUNC_LDO_OFFSET (INSTRUCTION_SIZE * 10)
92
93 /* Define offsets into the call dummy for the _sr4export address.
94 See comments related to CALL_DUMMY for more info. */
95 #define SR4EXPORT_LDIL_OFFSET (INSTRUCTION_SIZE * 12)
96 #define SR4EXPORT_LDO_OFFSET (INSTRUCTION_SIZE * 13)
97
98 /* To support detection of the pseudo-initial frame
99 that threads have. */
100 #define THREAD_INITIAL_FRAME_SYMBOL "__pthread_exit"
101 #define THREAD_INITIAL_FRAME_SYM_LEN sizeof(THREAD_INITIAL_FRAME_SYMBOL)
102
103 /* Sizes (in bytes) of the native unwind entries. */
104 #define UNWIND_ENTRY_SIZE 16
105 #define STUB_UNWIND_ENTRY_SIZE 8
106
107 static int get_field (unsigned word, int from, int to);
108
109 static int extract_5_load (unsigned int);
110
111 static unsigned extract_5R_store (unsigned int);
112
113 static unsigned extract_5r_store (unsigned int);
114
115 static void find_dummy_frame_regs (struct frame_info *, CORE_ADDR *);
116
117 static int find_proc_framesize (CORE_ADDR);
118
119 static int find_return_regnum (CORE_ADDR);
120
121 struct unwind_table_entry *find_unwind_entry (CORE_ADDR);
122
123 static int extract_17 (unsigned int);
124
125 static unsigned deposit_21 (unsigned int, unsigned int);
126
127 static int extract_21 (unsigned);
128
129 static unsigned deposit_14 (int, unsigned int);
130
131 static int extract_14 (unsigned);
132
133 static void unwind_command (char *, int);
134
135 static int low_sign_extend (unsigned int, unsigned int);
136
137 static int sign_extend (unsigned int, unsigned int);
138
139 static int restore_pc_queue (CORE_ADDR *);
140
141 static int hppa_alignof (struct type *);
142
143 static int prologue_inst_adjust_sp (unsigned long);
144
145 static int is_branch (unsigned long);
146
147 static int inst_saves_gr (unsigned long);
148
149 static int inst_saves_fr (unsigned long);
150
151 static int pc_in_interrupt_handler (CORE_ADDR);
152
153 static int pc_in_linker_stub (CORE_ADDR);
154
155 static int compare_unwind_entries (const void *, const void *);
156
157 static void read_unwind_info (struct objfile *);
158
159 static void internalize_unwinds (struct objfile *,
160 struct unwind_table_entry *,
161 asection *, unsigned int,
162 unsigned int, CORE_ADDR);
163 static void pa_print_registers (char *, int, int);
164 static void pa_strcat_registers (char *, int, int, struct ui_file *);
165 static void pa_register_look_aside (char *, int, long *);
166 static void pa_print_fp_reg (int);
167 static void pa_strcat_fp_reg (int, struct ui_file *, enum precision_type);
168 static void record_text_segment_lowaddr (bfd *, asection *, void *);
169 /* FIXME: brobecker 2002-11-07: We will likely be able to make the
170 following functions static, once we hppa is partially multiarched. */
171 int hppa_reg_struct_has_addr (int gcc_p, struct type *type);
172 CORE_ADDR hppa_skip_prologue (CORE_ADDR pc);
173 CORE_ADDR hppa_skip_trampoline_code (CORE_ADDR pc);
174 int hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name);
175 int hppa_in_solib_return_trampoline (CORE_ADDR pc, char *name);
176 CORE_ADDR hppa_saved_pc_after_call (struct frame_info *frame);
177 int hppa_inner_than (CORE_ADDR lhs, CORE_ADDR rhs);
178 CORE_ADDR hppa32_stack_align (CORE_ADDR sp);
179 CORE_ADDR hppa64_stack_align (CORE_ADDR sp);
180 int hppa_pc_requires_run_before_use (CORE_ADDR pc);
181 int hppa_instruction_nullified (void);
182 int hppa_register_raw_size (int reg_nr);
183 int hppa_register_byte (int reg_nr);
184 struct type * hppa32_register_virtual_type (int reg_nr);
185 struct type * hppa64_register_virtual_type (int reg_nr);
186 void hppa_store_struct_return (CORE_ADDR addr, CORE_ADDR sp);
187 void hppa32_extract_return_value (struct type *type, char *regbuf,
188 char *valbuf);
189 void hppa64_extract_return_value (struct type *type, char *regbuf,
190 char *valbuf);
191 int hppa32_use_struct_convention (int gcc_p, struct type *type);
192 int hppa64_use_struct_convention (int gcc_p, struct type *type);
193 void hppa32_store_return_value (struct type *type, char *valbuf);
194 void hppa64_store_return_value (struct type *type, char *valbuf);
195 CORE_ADDR hppa_extract_struct_value_address (char *regbuf);
196 int hppa_cannot_store_register (int regnum);
197 void hppa_init_extra_frame_info (int fromleaf, struct frame_info *frame);
198 CORE_ADDR hppa_frame_chain (struct frame_info *frame);
199 int hppa_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe);
200 int hppa_frameless_function_invocation (struct frame_info *frame);
201 CORE_ADDR hppa_frame_saved_pc (struct frame_info *frame);
202 CORE_ADDR hppa_frame_args_address (struct frame_info *fi);
203 int hppa_frame_num_args (struct frame_info *frame);
204 void hppa_push_dummy_frame (void);
205 void hppa_pop_frame (void);
206 CORE_ADDR hppa_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun,
207 int nargs, struct value **args,
208 struct type *type, int gcc_p);
209 CORE_ADDR hppa_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
210 int struct_return, CORE_ADDR struct_addr);
211 CORE_ADDR hppa_smash_text_address (CORE_ADDR addr);
212 CORE_ADDR hppa_target_read_pc (ptid_t ptid);
213 void hppa_target_write_pc (CORE_ADDR v, ptid_t ptid);
214 CORE_ADDR hppa_target_read_fp (void);
215
216 typedef struct
217 {
218 struct minimal_symbol *msym;
219 CORE_ADDR solib_handle;
220 CORE_ADDR return_val;
221 }
222 args_for_find_stub;
223
224 static int cover_find_stub_with_shl_get (void *);
225
226 static int is_pa_2 = 0; /* False */
227
228 /* This is declared in symtab.c; set to 1 in hp-symtab-read.c */
229 extern int hp_som_som_object_present;
230
231 /* In breakpoint.c */
232 extern int exception_catchpoints_are_fragile;
233
234 /* Should call_function allocate stack space for a struct return? */
235
236 int
237 hppa32_use_struct_convention (int gcc_p, struct type *type)
238 {
239 return (TYPE_LENGTH (type) > 2 * DEPRECATED_REGISTER_SIZE);
240 }
241
242 /* Same as hppa32_use_struct_convention() for the PA64 ABI. */
243
244 int
245 hppa64_use_struct_convention (int gcc_p, struct type *type)
246 {
247 /* RM: struct upto 128 bits are returned in registers */
248 return TYPE_LENGTH (type) > 16;
249 }
250
251 /* Routines to extract various sized constants out of hppa
252 instructions. */
253
254 /* This assumes that no garbage lies outside of the lower bits of
255 value. */
256
257 static int
258 sign_extend (unsigned val, unsigned bits)
259 {
260 return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
261 }
262
263 /* For many immediate values the sign bit is the low bit! */
264
265 static int
266 low_sign_extend (unsigned val, unsigned bits)
267 {
268 return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
269 }
270
271 /* Extract the bits at positions between FROM and TO, using HP's numbering
272 (MSB = 0). */
273
274 static int
275 get_field (unsigned word, int from, int to)
276 {
277 return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
278 }
279
280 /* extract the immediate field from a ld{bhw}s instruction */
281
282 static int
283 extract_5_load (unsigned word)
284 {
285 return low_sign_extend (word >> 16 & MASK_5, 5);
286 }
287
288 /* extract the immediate field from a break instruction */
289
290 static unsigned
291 extract_5r_store (unsigned word)
292 {
293 return (word & MASK_5);
294 }
295
296 /* extract the immediate field from a {sr}sm instruction */
297
298 static unsigned
299 extract_5R_store (unsigned word)
300 {
301 return (word >> 16 & MASK_5);
302 }
303
304 /* extract a 14 bit immediate field */
305
306 static int
307 extract_14 (unsigned word)
308 {
309 return low_sign_extend (word & MASK_14, 14);
310 }
311
312 /* deposit a 14 bit constant in a word */
313
314 static unsigned
315 deposit_14 (int opnd, unsigned word)
316 {
317 unsigned sign = (opnd < 0 ? 1 : 0);
318
319 return word | ((unsigned) opnd << 1 & MASK_14) | sign;
320 }
321
322 /* extract a 21 bit constant */
323
324 static int
325 extract_21 (unsigned word)
326 {
327 int val;
328
329 word &= MASK_21;
330 word <<= 11;
331 val = get_field (word, 20, 20);
332 val <<= 11;
333 val |= get_field (word, 9, 19);
334 val <<= 2;
335 val |= get_field (word, 5, 6);
336 val <<= 5;
337 val |= get_field (word, 0, 4);
338 val <<= 2;
339 val |= get_field (word, 7, 8);
340 return sign_extend (val, 21) << 11;
341 }
342
343 /* deposit a 21 bit constant in a word. Although 21 bit constants are
344 usually the top 21 bits of a 32 bit constant, we assume that only
345 the low 21 bits of opnd are relevant */
346
347 static unsigned
348 deposit_21 (unsigned opnd, unsigned word)
349 {
350 unsigned val = 0;
351
352 val |= get_field (opnd, 11 + 14, 11 + 18);
353 val <<= 2;
354 val |= get_field (opnd, 11 + 12, 11 + 13);
355 val <<= 2;
356 val |= get_field (opnd, 11 + 19, 11 + 20);
357 val <<= 11;
358 val |= get_field (opnd, 11 + 1, 11 + 11);
359 val <<= 1;
360 val |= get_field (opnd, 11 + 0, 11 + 0);
361 return word | val;
362 }
363
364 /* extract a 17 bit constant from branch instructions, returning the
365 19 bit signed value. */
366
367 static int
368 extract_17 (unsigned word)
369 {
370 return sign_extend (get_field (word, 19, 28) |
371 get_field (word, 29, 29) << 10 |
372 get_field (word, 11, 15) << 11 |
373 (word & 0x1) << 16, 17) << 2;
374 }
375 \f
376
377 /* Compare the start address for two unwind entries returning 1 if
378 the first address is larger than the second, -1 if the second is
379 larger than the first, and zero if they are equal. */
380
381 static int
382 compare_unwind_entries (const void *arg1, const void *arg2)
383 {
384 const struct unwind_table_entry *a = arg1;
385 const struct unwind_table_entry *b = arg2;
386
387 if (a->region_start > b->region_start)
388 return 1;
389 else if (a->region_start < b->region_start)
390 return -1;
391 else
392 return 0;
393 }
394
395 static CORE_ADDR low_text_segment_address;
396
397 static void
398 record_text_segment_lowaddr (bfd *abfd, asection *section, void *ignored)
399 {
400 if (((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
401 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
402 && section->vma < low_text_segment_address)
403 low_text_segment_address = section->vma;
404 }
405
406 static void
407 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
408 asection *section, unsigned int entries, unsigned int size,
409 CORE_ADDR text_offset)
410 {
411 /* We will read the unwind entries into temporary memory, then
412 fill in the actual unwind table. */
413 if (size > 0)
414 {
415 unsigned long tmp;
416 unsigned i;
417 char *buf = alloca (size);
418
419 low_text_segment_address = -1;
420
421 /* If addresses are 64 bits wide, then unwinds are supposed to
422 be segment relative offsets instead of absolute addresses.
423
424 Note that when loading a shared library (text_offset != 0) the
425 unwinds are already relative to the text_offset that will be
426 passed in. */
427 if (TARGET_PTR_BIT == 64 && text_offset == 0)
428 {
429 bfd_map_over_sections (objfile->obfd,
430 record_text_segment_lowaddr, NULL);
431
432 /* ?!? Mask off some low bits. Should this instead subtract
433 out the lowest section's filepos or something like that?
434 This looks very hokey to me. */
435 low_text_segment_address &= ~0xfff;
436 text_offset += low_text_segment_address;
437 }
438
439 bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
440
441 /* Now internalize the information being careful to handle host/target
442 endian issues. */
443 for (i = 0; i < entries; i++)
444 {
445 table[i].region_start = bfd_get_32 (objfile->obfd,
446 (bfd_byte *) buf);
447 table[i].region_start += text_offset;
448 buf += 4;
449 table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
450 table[i].region_end += text_offset;
451 buf += 4;
452 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
453 buf += 4;
454 table[i].Cannot_unwind = (tmp >> 31) & 0x1;
455 table[i].Millicode = (tmp >> 30) & 0x1;
456 table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
457 table[i].Region_description = (tmp >> 27) & 0x3;
458 table[i].reserved1 = (tmp >> 26) & 0x1;
459 table[i].Entry_SR = (tmp >> 25) & 0x1;
460 table[i].Entry_FR = (tmp >> 21) & 0xf;
461 table[i].Entry_GR = (tmp >> 16) & 0x1f;
462 table[i].Args_stored = (tmp >> 15) & 0x1;
463 table[i].Variable_Frame = (tmp >> 14) & 0x1;
464 table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
465 table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
466 table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
467 table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
468 table[i].Ada_Region = (tmp >> 9) & 0x1;
469 table[i].cxx_info = (tmp >> 8) & 0x1;
470 table[i].cxx_try_catch = (tmp >> 7) & 0x1;
471 table[i].sched_entry_seq = (tmp >> 6) & 0x1;
472 table[i].reserved2 = (tmp >> 5) & 0x1;
473 table[i].Save_SP = (tmp >> 4) & 0x1;
474 table[i].Save_RP = (tmp >> 3) & 0x1;
475 table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
476 table[i].extn_ptr_defined = (tmp >> 1) & 0x1;
477 table[i].Cleanup_defined = tmp & 0x1;
478 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
479 buf += 4;
480 table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
481 table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
482 table[i].Large_frame = (tmp >> 29) & 0x1;
483 table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1;
484 table[i].reserved4 = (tmp >> 27) & 0x1;
485 table[i].Total_frame_size = tmp & 0x7ffffff;
486
487 /* Stub unwinds are handled elsewhere. */
488 table[i].stub_unwind.stub_type = 0;
489 table[i].stub_unwind.padding = 0;
490 }
491 }
492 }
493
494 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
495 the object file. This info is used mainly by find_unwind_entry() to find
496 out the stack frame size and frame pointer used by procedures. We put
497 everything on the psymbol obstack in the objfile so that it automatically
498 gets freed when the objfile is destroyed. */
499
500 static void
501 read_unwind_info (struct objfile *objfile)
502 {
503 asection *unwind_sec, *stub_unwind_sec;
504 unsigned unwind_size, stub_unwind_size, total_size;
505 unsigned index, unwind_entries;
506 unsigned stub_entries, total_entries;
507 CORE_ADDR text_offset;
508 struct obj_unwind_info *ui;
509 obj_private_data_t *obj_private;
510
511 text_offset = ANOFFSET (objfile->section_offsets, 0);
512 ui = (struct obj_unwind_info *) obstack_alloc (&objfile->psymbol_obstack,
513 sizeof (struct obj_unwind_info));
514
515 ui->table = NULL;
516 ui->cache = NULL;
517 ui->last = -1;
518
519 /* For reasons unknown the HP PA64 tools generate multiple unwinder
520 sections in a single executable. So we just iterate over every
521 section in the BFD looking for unwinder sections intead of trying
522 to do a lookup with bfd_get_section_by_name.
523
524 First determine the total size of the unwind tables so that we
525 can allocate memory in a nice big hunk. */
526 total_entries = 0;
527 for (unwind_sec = objfile->obfd->sections;
528 unwind_sec;
529 unwind_sec = unwind_sec->next)
530 {
531 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
532 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
533 {
534 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
535 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
536
537 total_entries += unwind_entries;
538 }
539 }
540
541 /* Now compute the size of the stub unwinds. Note the ELF tools do not
542 use stub unwinds at the curren time. */
543 stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
544
545 if (stub_unwind_sec)
546 {
547 stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
548 stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
549 }
550 else
551 {
552 stub_unwind_size = 0;
553 stub_entries = 0;
554 }
555
556 /* Compute total number of unwind entries and their total size. */
557 total_entries += stub_entries;
558 total_size = total_entries * sizeof (struct unwind_table_entry);
559
560 /* Allocate memory for the unwind table. */
561 ui->table = (struct unwind_table_entry *)
562 obstack_alloc (&objfile->psymbol_obstack, total_size);
563 ui->last = total_entries - 1;
564
565 /* Now read in each unwind section and internalize the standard unwind
566 entries. */
567 index = 0;
568 for (unwind_sec = objfile->obfd->sections;
569 unwind_sec;
570 unwind_sec = unwind_sec->next)
571 {
572 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
573 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
574 {
575 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
576 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
577
578 internalize_unwinds (objfile, &ui->table[index], unwind_sec,
579 unwind_entries, unwind_size, text_offset);
580 index += unwind_entries;
581 }
582 }
583
584 /* Now read in and internalize the stub unwind entries. */
585 if (stub_unwind_size > 0)
586 {
587 unsigned int i;
588 char *buf = alloca (stub_unwind_size);
589
590 /* Read in the stub unwind entries. */
591 bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
592 0, stub_unwind_size);
593
594 /* Now convert them into regular unwind entries. */
595 for (i = 0; i < stub_entries; i++, index++)
596 {
597 /* Clear out the next unwind entry. */
598 memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
599
600 /* Convert offset & size into region_start and region_end.
601 Stuff away the stub type into "reserved" fields. */
602 ui->table[index].region_start = bfd_get_32 (objfile->obfd,
603 (bfd_byte *) buf);
604 ui->table[index].region_start += text_offset;
605 buf += 4;
606 ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
607 (bfd_byte *) buf);
608 buf += 2;
609 ui->table[index].region_end
610 = ui->table[index].region_start + 4 *
611 (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
612 buf += 2;
613 }
614
615 }
616
617 /* Unwind table needs to be kept sorted. */
618 qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
619 compare_unwind_entries);
620
621 /* Keep a pointer to the unwind information. */
622 if (objfile->obj_private == NULL)
623 {
624 obj_private = (obj_private_data_t *)
625 obstack_alloc (&objfile->psymbol_obstack,
626 sizeof (obj_private_data_t));
627 obj_private->unwind_info = NULL;
628 obj_private->so_info = NULL;
629 obj_private->dp = 0;
630
631 objfile->obj_private = obj_private;
632 }
633 obj_private = (obj_private_data_t *) objfile->obj_private;
634 obj_private->unwind_info = ui;
635 }
636
637 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
638 of the objfiles seeking the unwind table entry for this PC. Each objfile
639 contains a sorted list of struct unwind_table_entry. Since we do a binary
640 search of the unwind tables, we depend upon them to be sorted. */
641
642 struct unwind_table_entry *
643 find_unwind_entry (CORE_ADDR pc)
644 {
645 int first, middle, last;
646 struct objfile *objfile;
647
648 /* A function at address 0? Not in HP-UX! */
649 if (pc == (CORE_ADDR) 0)
650 return NULL;
651
652 ALL_OBJFILES (objfile)
653 {
654 struct obj_unwind_info *ui;
655 ui = NULL;
656 if (objfile->obj_private)
657 ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info;
658
659 if (!ui)
660 {
661 read_unwind_info (objfile);
662 if (objfile->obj_private == NULL)
663 error ("Internal error reading unwind information.");
664 ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info;
665 }
666
667 /* First, check the cache */
668
669 if (ui->cache
670 && pc >= ui->cache->region_start
671 && pc <= ui->cache->region_end)
672 return ui->cache;
673
674 /* Not in the cache, do a binary search */
675
676 first = 0;
677 last = ui->last;
678
679 while (first <= last)
680 {
681 middle = (first + last) / 2;
682 if (pc >= ui->table[middle].region_start
683 && pc <= ui->table[middle].region_end)
684 {
685 ui->cache = &ui->table[middle];
686 return &ui->table[middle];
687 }
688
689 if (pc < ui->table[middle].region_start)
690 last = middle - 1;
691 else
692 first = middle + 1;
693 }
694 } /* ALL_OBJFILES() */
695 return NULL;
696 }
697
698 const unsigned char *
699 hppa_breakpoint_from_pc (CORE_ADDR *pc, int *len)
700 {
701 static const char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
702 (*len) = sizeof (breakpoint);
703 return breakpoint;
704 }
705
706 /* Return the name of a register. */
707
708 const char *
709 hppa32_register_name (int i)
710 {
711 static char *names[] = {
712 "flags", "r1", "rp", "r3",
713 "r4", "r5", "r6", "r7",
714 "r8", "r9", "r10", "r11",
715 "r12", "r13", "r14", "r15",
716 "r16", "r17", "r18", "r19",
717 "r20", "r21", "r22", "r23",
718 "r24", "r25", "r26", "dp",
719 "ret0", "ret1", "sp", "r31",
720 "sar", "pcoqh", "pcsqh", "pcoqt",
721 "pcsqt", "eiem", "iir", "isr",
722 "ior", "ipsw", "goto", "sr4",
723 "sr0", "sr1", "sr2", "sr3",
724 "sr5", "sr6", "sr7", "cr0",
725 "cr8", "cr9", "ccr", "cr12",
726 "cr13", "cr24", "cr25", "cr26",
727 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
728 "fpsr", "fpe1", "fpe2", "fpe3",
729 "fpe4", "fpe5", "fpe6", "fpe7",
730 "fr4", "fr4R", "fr5", "fr5R",
731 "fr6", "fr6R", "fr7", "fr7R",
732 "fr8", "fr8R", "fr9", "fr9R",
733 "fr10", "fr10R", "fr11", "fr11R",
734 "fr12", "fr12R", "fr13", "fr13R",
735 "fr14", "fr14R", "fr15", "fr15R",
736 "fr16", "fr16R", "fr17", "fr17R",
737 "fr18", "fr18R", "fr19", "fr19R",
738 "fr20", "fr20R", "fr21", "fr21R",
739 "fr22", "fr22R", "fr23", "fr23R",
740 "fr24", "fr24R", "fr25", "fr25R",
741 "fr26", "fr26R", "fr27", "fr27R",
742 "fr28", "fr28R", "fr29", "fr29R",
743 "fr30", "fr30R", "fr31", "fr31R"
744 };
745 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
746 return NULL;
747 else
748 return names[i];
749 }
750
751 const char *
752 hppa64_register_name (int i)
753 {
754 static char *names[] = {
755 "flags", "r1", "rp", "r3",
756 "r4", "r5", "r6", "r7",
757 "r8", "r9", "r10", "r11",
758 "r12", "r13", "r14", "r15",
759 "r16", "r17", "r18", "r19",
760 "r20", "r21", "r22", "r23",
761 "r24", "r25", "r26", "dp",
762 "ret0", "ret1", "sp", "r31",
763 "sar", "pcoqh", "pcsqh", "pcoqt",
764 "pcsqt", "eiem", "iir", "isr",
765 "ior", "ipsw", "goto", "sr4",
766 "sr0", "sr1", "sr2", "sr3",
767 "sr5", "sr6", "sr7", "cr0",
768 "cr8", "cr9", "ccr", "cr12",
769 "cr13", "cr24", "cr25", "cr26",
770 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
771 "fpsr", "fpe1", "fpe2", "fpe3",
772 "fr4", "fr5", "fr6", "fr7",
773 "fr8", "fr9", "fr10", "fr11",
774 "fr12", "fr13", "fr14", "fr15",
775 "fr16", "fr17", "fr18", "fr19",
776 "fr20", "fr21", "fr22", "fr23",
777 "fr24", "fr25", "fr26", "fr27",
778 "fr28", "fr29", "fr30", "fr31"
779 };
780 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
781 return NULL;
782 else
783 return names[i];
784 }
785
786
787
788 /* Return the adjustment necessary to make for addresses on the stack
789 as presented by hpread.c.
790
791 This is necessary because of the stack direction on the PA and the
792 bizarre way in which someone (?) decided they wanted to handle
793 frame pointerless code in GDB. */
794 int
795 hpread_adjust_stack_address (CORE_ADDR func_addr)
796 {
797 struct unwind_table_entry *u;
798
799 u = find_unwind_entry (func_addr);
800 if (!u)
801 return 0;
802 else
803 return u->Total_frame_size << 3;
804 }
805
806 /* Called to determine if PC is in an interrupt handler of some
807 kind. */
808
809 static int
810 pc_in_interrupt_handler (CORE_ADDR pc)
811 {
812 struct unwind_table_entry *u;
813 struct minimal_symbol *msym_us;
814
815 u = find_unwind_entry (pc);
816 if (!u)
817 return 0;
818
819 /* Oh joys. HPUX sets the interrupt bit for _sigreturn even though
820 its frame isn't a pure interrupt frame. Deal with this. */
821 msym_us = lookup_minimal_symbol_by_pc (pc);
822
823 return (u->HP_UX_interrupt_marker
824 && !PC_IN_SIGTRAMP (pc, DEPRECATED_SYMBOL_NAME (msym_us)));
825 }
826
827 /* Called when no unwind descriptor was found for PC. Returns 1 if it
828 appears that PC is in a linker stub.
829
830 ?!? Need to handle stubs which appear in PA64 code. */
831
832 static int
833 pc_in_linker_stub (CORE_ADDR pc)
834 {
835 int found_magic_instruction = 0;
836 int i;
837 char buf[4];
838
839 /* If unable to read memory, assume pc is not in a linker stub. */
840 if (target_read_memory (pc, buf, 4) != 0)
841 return 0;
842
843 /* We are looking for something like
844
845 ; $$dyncall jams RP into this special spot in the frame (RP')
846 ; before calling the "call stub"
847 ldw -18(sp),rp
848
849 ldsid (rp),r1 ; Get space associated with RP into r1
850 mtsp r1,sp ; Move it into space register 0
851 be,n 0(sr0),rp) ; back to your regularly scheduled program */
852
853 /* Maximum known linker stub size is 4 instructions. Search forward
854 from the given PC, then backward. */
855 for (i = 0; i < 4; i++)
856 {
857 /* If we hit something with an unwind, stop searching this direction. */
858
859 if (find_unwind_entry (pc + i * 4) != 0)
860 break;
861
862 /* Check for ldsid (rp),r1 which is the magic instruction for a
863 return from a cross-space function call. */
864 if (read_memory_integer (pc + i * 4, 4) == 0x004010a1)
865 {
866 found_magic_instruction = 1;
867 break;
868 }
869 /* Add code to handle long call/branch and argument relocation stubs
870 here. */
871 }
872
873 if (found_magic_instruction != 0)
874 return 1;
875
876 /* Now look backward. */
877 for (i = 0; i < 4; i++)
878 {
879 /* If we hit something with an unwind, stop searching this direction. */
880
881 if (find_unwind_entry (pc - i * 4) != 0)
882 break;
883
884 /* Check for ldsid (rp),r1 which is the magic instruction for a
885 return from a cross-space function call. */
886 if (read_memory_integer (pc - i * 4, 4) == 0x004010a1)
887 {
888 found_magic_instruction = 1;
889 break;
890 }
891 /* Add code to handle long call/branch and argument relocation stubs
892 here. */
893 }
894 return found_magic_instruction;
895 }
896
897 static int
898 find_return_regnum (CORE_ADDR pc)
899 {
900 struct unwind_table_entry *u;
901
902 u = find_unwind_entry (pc);
903
904 if (!u)
905 return RP_REGNUM;
906
907 if (u->Millicode)
908 return 31;
909
910 return RP_REGNUM;
911 }
912
913 /* Return size of frame, or -1 if we should use a frame pointer. */
914 static int
915 find_proc_framesize (CORE_ADDR pc)
916 {
917 struct unwind_table_entry *u;
918 struct minimal_symbol *msym_us;
919
920 /* This may indicate a bug in our callers... */
921 if (pc == (CORE_ADDR) 0)
922 return -1;
923
924 u = find_unwind_entry (pc);
925
926 if (!u)
927 {
928 if (pc_in_linker_stub (pc))
929 /* Linker stubs have a zero size frame. */
930 return 0;
931 else
932 return -1;
933 }
934
935 msym_us = lookup_minimal_symbol_by_pc (pc);
936
937 /* If Save_SP is set, and we're not in an interrupt or signal caller,
938 then we have a frame pointer. Use it. */
939 if (u->Save_SP
940 && !pc_in_interrupt_handler (pc)
941 && msym_us
942 && !PC_IN_SIGTRAMP (pc, DEPRECATED_SYMBOL_NAME (msym_us)))
943 return -1;
944
945 return u->Total_frame_size << 3;
946 }
947
948 /* Return offset from sp at which rp is saved, or 0 if not saved. */
949 static int rp_saved (CORE_ADDR);
950
951 static int
952 rp_saved (CORE_ADDR pc)
953 {
954 struct unwind_table_entry *u;
955
956 /* A function at, and thus a return PC from, address 0? Not in HP-UX! */
957 if (pc == (CORE_ADDR) 0)
958 return 0;
959
960 u = find_unwind_entry (pc);
961
962 if (!u)
963 {
964 if (pc_in_linker_stub (pc))
965 /* This is the so-called RP'. */
966 return -24;
967 else
968 return 0;
969 }
970
971 if (u->Save_RP)
972 return (TARGET_PTR_BIT == 64 ? -16 : -20);
973 else if (u->stub_unwind.stub_type != 0)
974 {
975 switch (u->stub_unwind.stub_type)
976 {
977 case EXPORT:
978 case IMPORT:
979 return -24;
980 case PARAMETER_RELOCATION:
981 return -8;
982 default:
983 return 0;
984 }
985 }
986 else
987 return 0;
988 }
989 \f
990 int
991 hppa_frameless_function_invocation (struct frame_info *frame)
992 {
993 struct unwind_table_entry *u;
994
995 u = find_unwind_entry (get_frame_pc (frame));
996
997 if (u == 0)
998 return 0;
999
1000 return (u->Total_frame_size == 0 && u->stub_unwind.stub_type == 0);
1001 }
1002
1003 /* Immediately after a function call, return the saved pc.
1004 Can't go through the frames for this because on some machines
1005 the new frame is not set up until the new function executes
1006 some instructions. */
1007
1008 CORE_ADDR
1009 hppa_saved_pc_after_call (struct frame_info *frame)
1010 {
1011 int ret_regnum;
1012 CORE_ADDR pc;
1013 struct unwind_table_entry *u;
1014
1015 ret_regnum = find_return_regnum (get_frame_pc (frame));
1016 pc = read_register (ret_regnum) & ~0x3;
1017
1018 /* If PC is in a linker stub, then we need to dig the address
1019 the stub will return to out of the stack. */
1020 u = find_unwind_entry (pc);
1021 if (u && u->stub_unwind.stub_type != 0)
1022 return DEPRECATED_FRAME_SAVED_PC (frame);
1023 else
1024 return pc;
1025 }
1026 \f
1027 CORE_ADDR
1028 hppa_frame_saved_pc (struct frame_info *frame)
1029 {
1030 CORE_ADDR pc = get_frame_pc (frame);
1031 struct unwind_table_entry *u;
1032 CORE_ADDR old_pc = 0;
1033 int spun_around_loop = 0;
1034 int rp_offset = 0;
1035
1036 /* BSD, HPUX & OSF1 all lay out the hardware state in the same manner
1037 at the base of the frame in an interrupt handler. Registers within
1038 are saved in the exact same order as GDB numbers registers. How
1039 convienent. */
1040 if (pc_in_interrupt_handler (pc))
1041 return read_memory_integer (get_frame_base (frame) + PC_REGNUM * 4,
1042 TARGET_PTR_BIT / 8) & ~0x3;
1043
1044 if ((get_frame_pc (frame) >= get_frame_base (frame)
1045 && (get_frame_pc (frame)
1046 <= (get_frame_base (frame)
1047 /* A call dummy is sized in words, but it is actually a
1048 series of instructions. Account for that scaling
1049 factor. */
1050 + ((DEPRECATED_REGISTER_SIZE / INSTRUCTION_SIZE)
1051 * DEPRECATED_CALL_DUMMY_LENGTH)
1052 /* Similarly we have to account for 64bit wide register
1053 saves. */
1054 + (32 * DEPRECATED_REGISTER_SIZE)
1055 /* We always consider FP regs 8 bytes long. */
1056 + (NUM_REGS - FP0_REGNUM) * 8
1057 /* Similarly we have to account for 64bit wide register
1058 saves. */
1059 + (6 * DEPRECATED_REGISTER_SIZE)))))
1060 {
1061 return read_memory_integer ((get_frame_base (frame)
1062 + (TARGET_PTR_BIT == 64 ? -16 : -20)),
1063 TARGET_PTR_BIT / 8) & ~0x3;
1064 }
1065
1066 #ifdef FRAME_SAVED_PC_IN_SIGTRAMP
1067 /* Deal with signal handler caller frames too. */
1068 if ((get_frame_type (frame) == SIGTRAMP_FRAME))
1069 {
1070 CORE_ADDR rp;
1071 FRAME_SAVED_PC_IN_SIGTRAMP (frame, &rp);
1072 return rp & ~0x3;
1073 }
1074 #endif
1075
1076 if (hppa_frameless_function_invocation (frame))
1077 {
1078 int ret_regnum;
1079
1080 ret_regnum = find_return_regnum (pc);
1081
1082 /* If the next frame is an interrupt frame or a signal
1083 handler caller, then we need to look in the saved
1084 register area to get the return pointer (the values
1085 in the registers may not correspond to anything useful). */
1086 if (get_next_frame (frame)
1087 && ((get_frame_type (get_next_frame (frame)) == SIGTRAMP_FRAME)
1088 || pc_in_interrupt_handler (get_frame_pc (get_next_frame (frame)))))
1089 {
1090 CORE_ADDR *saved_regs;
1091 hppa_frame_init_saved_regs (get_next_frame (frame));
1092 saved_regs = get_frame_saved_regs (get_next_frame (frame));
1093 if (read_memory_integer (saved_regs[FLAGS_REGNUM],
1094 TARGET_PTR_BIT / 8) & 0x2)
1095 {
1096 pc = read_memory_integer (saved_regs[31],
1097 TARGET_PTR_BIT / 8) & ~0x3;
1098
1099 /* Syscalls are really two frames. The syscall stub itself
1100 with a return pointer in %rp and the kernel call with
1101 a return pointer in %r31. We return the %rp variant
1102 if %r31 is the same as frame->pc. */
1103 if (pc == get_frame_pc (frame))
1104 pc = read_memory_integer (saved_regs[RP_REGNUM],
1105 TARGET_PTR_BIT / 8) & ~0x3;
1106 }
1107 else
1108 pc = read_memory_integer (saved_regs[RP_REGNUM],
1109 TARGET_PTR_BIT / 8) & ~0x3;
1110 }
1111 else
1112 pc = read_register (ret_regnum) & ~0x3;
1113 }
1114 else
1115 {
1116 spun_around_loop = 0;
1117 old_pc = pc;
1118
1119 restart:
1120 rp_offset = rp_saved (pc);
1121
1122 /* Similar to code in frameless function case. If the next
1123 frame is a signal or interrupt handler, then dig the right
1124 information out of the saved register info. */
1125 if (rp_offset == 0
1126 && get_next_frame (frame)
1127 && ((get_frame_type (get_next_frame (frame)) == SIGTRAMP_FRAME)
1128 || pc_in_interrupt_handler (get_frame_pc (get_next_frame (frame)))))
1129 {
1130 CORE_ADDR *saved_regs;
1131 hppa_frame_init_saved_regs (get_next_frame (frame));
1132 saved_regs = get_frame_saved_regs (get_next_frame (frame));
1133 if (read_memory_integer (saved_regs[FLAGS_REGNUM],
1134 TARGET_PTR_BIT / 8) & 0x2)
1135 {
1136 pc = read_memory_integer (saved_regs[31],
1137 TARGET_PTR_BIT / 8) & ~0x3;
1138
1139 /* Syscalls are really two frames. The syscall stub itself
1140 with a return pointer in %rp and the kernel call with
1141 a return pointer in %r31. We return the %rp variant
1142 if %r31 is the same as frame->pc. */
1143 if (pc == get_frame_pc (frame))
1144 pc = read_memory_integer (saved_regs[RP_REGNUM],
1145 TARGET_PTR_BIT / 8) & ~0x3;
1146 }
1147 else
1148 pc = read_memory_integer (saved_regs[RP_REGNUM],
1149 TARGET_PTR_BIT / 8) & ~0x3;
1150 }
1151 else if (rp_offset == 0)
1152 {
1153 old_pc = pc;
1154 pc = read_register (RP_REGNUM) & ~0x3;
1155 }
1156 else
1157 {
1158 old_pc = pc;
1159 pc = read_memory_integer (get_frame_base (frame) + rp_offset,
1160 TARGET_PTR_BIT / 8) & ~0x3;
1161 }
1162 }
1163
1164 /* If PC is inside a linker stub, then dig out the address the stub
1165 will return to.
1166
1167 Don't do this for long branch stubs. Why? For some unknown reason
1168 _start is marked as a long branch stub in hpux10. */
1169 u = find_unwind_entry (pc);
1170 if (u && u->stub_unwind.stub_type != 0
1171 && u->stub_unwind.stub_type != LONG_BRANCH)
1172 {
1173 unsigned int insn;
1174
1175 /* If this is a dynamic executable, and we're in a signal handler,
1176 then the call chain will eventually point us into the stub for
1177 _sigreturn. Unlike most cases, we'll be pointed to the branch
1178 to the real sigreturn rather than the code after the real branch!.
1179
1180 Else, try to dig the address the stub will return to in the normal
1181 fashion. */
1182 insn = read_memory_integer (pc, 4);
1183 if ((insn & 0xfc00e000) == 0xe8000000)
1184 return (pc + extract_17 (insn) + 8) & ~0x3;
1185 else
1186 {
1187 if (old_pc == pc)
1188 spun_around_loop++;
1189
1190 if (spun_around_loop > 1)
1191 {
1192 /* We're just about to go around the loop again with
1193 no more hope of success. Die. */
1194 error ("Unable to find return pc for this frame");
1195 }
1196 else
1197 goto restart;
1198 }
1199 }
1200
1201 return pc;
1202 }
1203 \f
1204 /* We need to correct the PC and the FP for the outermost frame when we are
1205 in a system call. */
1206
1207 void
1208 hppa_init_extra_frame_info (int fromleaf, struct frame_info *frame)
1209 {
1210 int flags;
1211 int framesize;
1212
1213 if (get_next_frame (frame) && !fromleaf)
1214 return;
1215
1216 /* If the next frame represents a frameless function invocation then
1217 we have to do some adjustments that are normally done by
1218 DEPRECATED_FRAME_CHAIN. (DEPRECATED_FRAME_CHAIN is not called in
1219 this case.) */
1220 if (fromleaf)
1221 {
1222 /* Find the framesize of *this* frame without peeking at the PC
1223 in the current frame structure (it isn't set yet). */
1224 framesize = find_proc_framesize (DEPRECATED_FRAME_SAVED_PC (get_next_frame (frame)));
1225
1226 /* Now adjust our base frame accordingly. If we have a frame pointer
1227 use it, else subtract the size of this frame from the current
1228 frame. (we always want frame->frame to point at the lowest address
1229 in the frame). */
1230 if (framesize == -1)
1231 deprecated_update_frame_base_hack (frame, deprecated_read_fp ());
1232 else
1233 deprecated_update_frame_base_hack (frame, get_frame_base (frame) - framesize);
1234 return;
1235 }
1236
1237 flags = read_register (FLAGS_REGNUM);
1238 if (flags & 2) /* In system call? */
1239 deprecated_update_frame_pc_hack (frame, read_register (31) & ~0x3);
1240
1241 /* The outermost frame is always derived from PC-framesize
1242
1243 One might think frameless innermost frames should have
1244 a frame->frame that is the same as the parent's frame->frame.
1245 That is wrong; frame->frame in that case should be the *high*
1246 address of the parent's frame. It's complicated as hell to
1247 explain, but the parent *always* creates some stack space for
1248 the child. So the child actually does have a frame of some
1249 sorts, and its base is the high address in its parent's frame. */
1250 framesize = find_proc_framesize (get_frame_pc (frame));
1251 if (framesize == -1)
1252 deprecated_update_frame_base_hack (frame, deprecated_read_fp ());
1253 else
1254 deprecated_update_frame_base_hack (frame, read_register (SP_REGNUM) - framesize);
1255 }
1256 \f
1257 /* Given a GDB frame, determine the address of the calling function's
1258 frame. This will be used to create a new GDB frame struct, and
1259 then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC
1260 will be called for the new frame.
1261
1262 This may involve searching through prologues for several functions
1263 at boundaries where GCC calls HP C code, or where code which has
1264 a frame pointer calls code without a frame pointer. */
1265
1266 CORE_ADDR
1267 hppa_frame_chain (struct frame_info *frame)
1268 {
1269 int my_framesize, caller_framesize;
1270 struct unwind_table_entry *u;
1271 CORE_ADDR frame_base;
1272 struct frame_info *tmp_frame;
1273
1274 /* A frame in the current frame list, or zero. */
1275 struct frame_info *saved_regs_frame = 0;
1276 /* Where the registers were saved in saved_regs_frame. If
1277 saved_regs_frame is zero, this is garbage. */
1278 CORE_ADDR *saved_regs = NULL;
1279
1280 CORE_ADDR caller_pc;
1281
1282 struct minimal_symbol *min_frame_symbol;
1283 struct symbol *frame_symbol;
1284 char *frame_symbol_name;
1285
1286 /* If this is a threaded application, and we see the
1287 routine "__pthread_exit", treat it as the stack root
1288 for this thread. */
1289 min_frame_symbol = lookup_minimal_symbol_by_pc (get_frame_pc (frame));
1290 frame_symbol = find_pc_function (get_frame_pc (frame));
1291
1292 if ((min_frame_symbol != 0) /* && (frame_symbol == 0) */ )
1293 {
1294 /* The test above for "no user function name" would defend
1295 against the slim likelihood that a user might define a
1296 routine named "__pthread_exit" and then try to debug it.
1297
1298 If it weren't commented out, and you tried to debug the
1299 pthread library itself, you'd get errors.
1300
1301 So for today, we don't make that check. */
1302 frame_symbol_name = DEPRECATED_SYMBOL_NAME (min_frame_symbol);
1303 if (frame_symbol_name != 0)
1304 {
1305 if (0 == strncmp (frame_symbol_name,
1306 THREAD_INITIAL_FRAME_SYMBOL,
1307 THREAD_INITIAL_FRAME_SYM_LEN))
1308 {
1309 /* Pretend we've reached the bottom of the stack. */
1310 return (CORE_ADDR) 0;
1311 }
1312 }
1313 } /* End of hacky code for threads. */
1314
1315 /* Handle HPUX, BSD, and OSF1 style interrupt frames first. These
1316 are easy; at *sp we have a full save state strucutre which we can
1317 pull the old stack pointer from. Also see frame_saved_pc for
1318 code to dig a saved PC out of the save state structure. */
1319 if (pc_in_interrupt_handler (get_frame_pc (frame)))
1320 frame_base = read_memory_integer (get_frame_base (frame) + SP_REGNUM * 4,
1321 TARGET_PTR_BIT / 8);
1322 #ifdef FRAME_BASE_BEFORE_SIGTRAMP
1323 else if ((get_frame_type (frame) == SIGTRAMP_FRAME))
1324 {
1325 FRAME_BASE_BEFORE_SIGTRAMP (frame, &frame_base);
1326 }
1327 #endif
1328 else
1329 frame_base = get_frame_base (frame);
1330
1331 /* Get frame sizes for the current frame and the frame of the
1332 caller. */
1333 my_framesize = find_proc_framesize (get_frame_pc (frame));
1334 caller_pc = DEPRECATED_FRAME_SAVED_PC (frame);
1335
1336 /* If we can't determine the caller's PC, then it's not likely we can
1337 really determine anything meaningful about its frame. We'll consider
1338 this to be stack bottom. */
1339 if (caller_pc == (CORE_ADDR) 0)
1340 return (CORE_ADDR) 0;
1341
1342 caller_framesize = find_proc_framesize (DEPRECATED_FRAME_SAVED_PC (frame));
1343
1344 /* If caller does not have a frame pointer, then its frame
1345 can be found at current_frame - caller_framesize. */
1346 if (caller_framesize != -1)
1347 {
1348 return frame_base - caller_framesize;
1349 }
1350 /* Both caller and callee have frame pointers and are GCC compiled
1351 (SAVE_SP bit in unwind descriptor is on for both functions.
1352 The previous frame pointer is found at the top of the current frame. */
1353 if (caller_framesize == -1 && my_framesize == -1)
1354 {
1355 return read_memory_integer (frame_base, TARGET_PTR_BIT / 8);
1356 }
1357 /* Caller has a frame pointer, but callee does not. This is a little
1358 more difficult as GCC and HP C lay out locals and callee register save
1359 areas very differently.
1360
1361 The previous frame pointer could be in a register, or in one of
1362 several areas on the stack.
1363
1364 Walk from the current frame to the innermost frame examining
1365 unwind descriptors to determine if %r3 ever gets saved into the
1366 stack. If so return whatever value got saved into the stack.
1367 If it was never saved in the stack, then the value in %r3 is still
1368 valid, so use it.
1369
1370 We use information from unwind descriptors to determine if %r3
1371 is saved into the stack (Entry_GR field has this information). */
1372
1373 for (tmp_frame = frame; tmp_frame; tmp_frame = get_next_frame (tmp_frame))
1374 {
1375 u = find_unwind_entry (get_frame_pc (tmp_frame));
1376
1377 if (!u)
1378 {
1379 /* We could find this information by examining prologues. I don't
1380 think anyone has actually written any tools (not even "strip")
1381 which leave them out of an executable, so maybe this is a moot
1382 point. */
1383 /* ??rehrauer: Actually, it's quite possible to stepi your way into
1384 code that doesn't have unwind entries. For example, stepping into
1385 the dynamic linker will give you a PC that has none. Thus, I've
1386 disabled this warning. */
1387 #if 0
1388 warning ("Unable to find unwind for PC 0x%x -- Help!", get_frame_pc (tmp_frame));
1389 #endif
1390 return (CORE_ADDR) 0;
1391 }
1392
1393 if (u->Save_SP
1394 || (get_frame_type (tmp_frame) == SIGTRAMP_FRAME)
1395 || pc_in_interrupt_handler (get_frame_pc (tmp_frame)))
1396 break;
1397
1398 /* Entry_GR specifies the number of callee-saved general registers
1399 saved in the stack. It starts at %r3, so %r3 would be 1. */
1400 if (u->Entry_GR >= 1)
1401 {
1402 /* The unwind entry claims that r3 is saved here. However,
1403 in optimized code, GCC often doesn't actually save r3.
1404 We'll discover this if we look at the prologue. */
1405 hppa_frame_init_saved_regs (tmp_frame);
1406 saved_regs = get_frame_saved_regs (tmp_frame);
1407 saved_regs_frame = tmp_frame;
1408
1409 /* If we have an address for r3, that's good. */
1410 if (saved_regs[DEPRECATED_FP_REGNUM])
1411 break;
1412 }
1413 }
1414
1415 if (tmp_frame)
1416 {
1417 /* We may have walked down the chain into a function with a frame
1418 pointer. */
1419 if (u->Save_SP
1420 && !(get_frame_type (tmp_frame) == SIGTRAMP_FRAME)
1421 && !pc_in_interrupt_handler (get_frame_pc (tmp_frame)))
1422 {
1423 return read_memory_integer (get_frame_base (tmp_frame), TARGET_PTR_BIT / 8);
1424 }
1425 /* %r3 was saved somewhere in the stack. Dig it out. */
1426 else
1427 {
1428 /* Sick.
1429
1430 For optimization purposes many kernels don't have the
1431 callee saved registers into the save_state structure upon
1432 entry into the kernel for a syscall; the optimization
1433 is usually turned off if the process is being traced so
1434 that the debugger can get full register state for the
1435 process.
1436
1437 This scheme works well except for two cases:
1438
1439 * Attaching to a process when the process is in the
1440 kernel performing a system call (debugger can't get
1441 full register state for the inferior process since
1442 the process wasn't being traced when it entered the
1443 system call).
1444
1445 * Register state is not complete if the system call
1446 causes the process to core dump.
1447
1448
1449 The following heinous code is an attempt to deal with
1450 the lack of register state in a core dump. It will
1451 fail miserably if the function which performs the
1452 system call has a variable sized stack frame. */
1453
1454 if (tmp_frame != saved_regs_frame)
1455 {
1456 hppa_frame_init_saved_regs (tmp_frame);
1457 saved_regs = get_frame_saved_regs (tmp_frame);
1458 }
1459
1460 /* Abominable hack. */
1461 if (current_target.to_has_execution == 0
1462 && ((saved_regs[FLAGS_REGNUM]
1463 && (read_memory_integer (saved_regs[FLAGS_REGNUM],
1464 TARGET_PTR_BIT / 8)
1465 & 0x2))
1466 || (saved_regs[FLAGS_REGNUM] == 0
1467 && read_register (FLAGS_REGNUM) & 0x2)))
1468 {
1469 u = find_unwind_entry (DEPRECATED_FRAME_SAVED_PC (frame));
1470 if (!u)
1471 {
1472 return read_memory_integer (saved_regs[DEPRECATED_FP_REGNUM],
1473 TARGET_PTR_BIT / 8);
1474 }
1475 else
1476 {
1477 return frame_base - (u->Total_frame_size << 3);
1478 }
1479 }
1480
1481 return read_memory_integer (saved_regs[DEPRECATED_FP_REGNUM],
1482 TARGET_PTR_BIT / 8);
1483 }
1484 }
1485 else
1486 {
1487 /* Get the innermost frame. */
1488 tmp_frame = frame;
1489 while (get_next_frame (tmp_frame) != NULL)
1490 tmp_frame = get_next_frame (tmp_frame);
1491
1492 if (tmp_frame != saved_regs_frame)
1493 {
1494 hppa_frame_init_saved_regs (tmp_frame);
1495 saved_regs = get_frame_saved_regs (tmp_frame);
1496 }
1497
1498 /* Abominable hack. See above. */
1499 if (current_target.to_has_execution == 0
1500 && ((saved_regs[FLAGS_REGNUM]
1501 && (read_memory_integer (saved_regs[FLAGS_REGNUM],
1502 TARGET_PTR_BIT / 8)
1503 & 0x2))
1504 || (saved_regs[FLAGS_REGNUM] == 0
1505 && read_register (FLAGS_REGNUM) & 0x2)))
1506 {
1507 u = find_unwind_entry (DEPRECATED_FRAME_SAVED_PC (frame));
1508 if (!u)
1509 {
1510 return read_memory_integer (saved_regs[DEPRECATED_FP_REGNUM],
1511 TARGET_PTR_BIT / 8);
1512 }
1513 else
1514 {
1515 return frame_base - (u->Total_frame_size << 3);
1516 }
1517 }
1518
1519 /* The value in %r3 was never saved into the stack (thus %r3 still
1520 holds the value of the previous frame pointer). */
1521 return deprecated_read_fp ();
1522 }
1523 }
1524 \f
1525
1526 /* To see if a frame chain is valid, see if the caller looks like it
1527 was compiled with gcc. */
1528
1529 int
1530 hppa_frame_chain_valid (CORE_ADDR chain, struct frame_info *thisframe)
1531 {
1532 struct minimal_symbol *msym_us;
1533 struct minimal_symbol *msym_start;
1534 struct unwind_table_entry *u, *next_u = NULL;
1535 struct frame_info *next;
1536
1537 u = find_unwind_entry (get_frame_pc (thisframe));
1538
1539 if (u == NULL)
1540 return 1;
1541
1542 /* We can't just check that the same of msym_us is "_start", because
1543 someone idiotically decided that they were going to make a Ltext_end
1544 symbol with the same address. This Ltext_end symbol is totally
1545 indistinguishable (as nearly as I can tell) from the symbol for a function
1546 which is (legitimately, since it is in the user's namespace)
1547 named Ltext_end, so we can't just ignore it. */
1548 msym_us = lookup_minimal_symbol_by_pc (DEPRECATED_FRAME_SAVED_PC (thisframe));
1549 msym_start = lookup_minimal_symbol ("_start", NULL, NULL);
1550 if (msym_us
1551 && msym_start
1552 && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
1553 return 0;
1554
1555 /* Grrrr. Some new idiot decided that they don't want _start for the
1556 PRO configurations; $START$ calls main directly.... Deal with it. */
1557 msym_start = lookup_minimal_symbol ("$START$", NULL, NULL);
1558 if (msym_us
1559 && msym_start
1560 && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
1561 return 0;
1562
1563 next = get_next_frame (thisframe);
1564 if (next)
1565 next_u = find_unwind_entry (get_frame_pc (next));
1566
1567 /* If this frame does not save SP, has no stack, isn't a stub,
1568 and doesn't "call" an interrupt routine or signal handler caller,
1569 then its not valid. */
1570 if (u->Save_SP || u->Total_frame_size || u->stub_unwind.stub_type != 0
1571 || (get_next_frame (thisframe) && (get_frame_type (get_next_frame (thisframe)) == SIGTRAMP_FRAME))
1572 || (next_u && next_u->HP_UX_interrupt_marker))
1573 return 1;
1574
1575 if (pc_in_linker_stub (get_frame_pc (thisframe)))
1576 return 1;
1577
1578 return 0;
1579 }
1580
1581 /* These functions deal with saving and restoring register state
1582 around a function call in the inferior. They keep the stack
1583 double-word aligned; eventually, on an hp700, the stack will have
1584 to be aligned to a 64-byte boundary. */
1585
1586 void
1587 hppa_push_dummy_frame (void)
1588 {
1589 CORE_ADDR sp, pc, pcspace;
1590 register int regnum;
1591 CORE_ADDR int_buffer;
1592 double freg_buffer;
1593
1594 pc = hppa_target_read_pc (inferior_ptid);
1595 int_buffer = read_register (FLAGS_REGNUM);
1596 if (int_buffer & 0x2)
1597 {
1598 const unsigned int sid = (pc >> 30) & 0x3;
1599 if (sid == 0)
1600 pcspace = read_register (SR4_REGNUM);
1601 else
1602 pcspace = read_register (SR4_REGNUM + 4 + sid);
1603 }
1604 else
1605 pcspace = read_register (PCSQ_HEAD_REGNUM);
1606
1607 /* Space for "arguments"; the RP goes in here. */
1608 sp = read_register (SP_REGNUM) + 48;
1609 int_buffer = read_register (RP_REGNUM) | 0x3;
1610
1611 /* The 32bit and 64bit ABIs save the return pointer into different
1612 stack slots. */
1613 if (DEPRECATED_REGISTER_SIZE == 8)
1614 write_memory (sp - 16, (char *) &int_buffer, DEPRECATED_REGISTER_SIZE);
1615 else
1616 write_memory (sp - 20, (char *) &int_buffer, DEPRECATED_REGISTER_SIZE);
1617
1618 int_buffer = deprecated_read_fp ();
1619 write_memory (sp, (char *) &int_buffer, DEPRECATED_REGISTER_SIZE);
1620
1621 write_register (DEPRECATED_FP_REGNUM, sp);
1622
1623 sp += 2 * DEPRECATED_REGISTER_SIZE;
1624
1625 for (regnum = 1; regnum < 32; regnum++)
1626 if (regnum != RP_REGNUM && regnum != DEPRECATED_FP_REGNUM)
1627 sp = push_word (sp, read_register (regnum));
1628
1629 /* This is not necessary for the 64bit ABI. In fact it is dangerous. */
1630 if (DEPRECATED_REGISTER_SIZE != 8)
1631 sp += 4;
1632
1633 for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++)
1634 {
1635 deprecated_read_register_bytes (REGISTER_BYTE (regnum),
1636 (char *) &freg_buffer, 8);
1637 sp = push_bytes (sp, (char *) &freg_buffer, 8);
1638 }
1639 sp = push_word (sp, read_register (IPSW_REGNUM));
1640 sp = push_word (sp, read_register (SAR_REGNUM));
1641 sp = push_word (sp, pc);
1642 sp = push_word (sp, pcspace);
1643 sp = push_word (sp, pc + 4);
1644 sp = push_word (sp, pcspace);
1645 write_register (SP_REGNUM, sp);
1646 }
1647
1648 static void
1649 find_dummy_frame_regs (struct frame_info *frame,
1650 CORE_ADDR frame_saved_regs[])
1651 {
1652 CORE_ADDR fp = get_frame_base (frame);
1653 int i;
1654
1655 /* The 32bit and 64bit ABIs save RP into different locations. */
1656 if (DEPRECATED_REGISTER_SIZE == 8)
1657 frame_saved_regs[RP_REGNUM] = (fp - 16) & ~0x3;
1658 else
1659 frame_saved_regs[RP_REGNUM] = (fp - 20) & ~0x3;
1660
1661 frame_saved_regs[DEPRECATED_FP_REGNUM] = fp;
1662
1663 frame_saved_regs[1] = fp + (2 * DEPRECATED_REGISTER_SIZE);
1664
1665 for (fp += 3 * DEPRECATED_REGISTER_SIZE, i = 3; i < 32; i++)
1666 {
1667 if (i != DEPRECATED_FP_REGNUM)
1668 {
1669 frame_saved_regs[i] = fp;
1670 fp += DEPRECATED_REGISTER_SIZE;
1671 }
1672 }
1673
1674 /* This is not necessary or desirable for the 64bit ABI. */
1675 if (DEPRECATED_REGISTER_SIZE != 8)
1676 fp += 4;
1677
1678 for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8)
1679 frame_saved_regs[i] = fp;
1680
1681 frame_saved_regs[IPSW_REGNUM] = fp;
1682 frame_saved_regs[SAR_REGNUM] = fp + DEPRECATED_REGISTER_SIZE;
1683 frame_saved_regs[PCOQ_HEAD_REGNUM] = fp + 2 * DEPRECATED_REGISTER_SIZE;
1684 frame_saved_regs[PCSQ_HEAD_REGNUM] = fp + 3 * DEPRECATED_REGISTER_SIZE;
1685 frame_saved_regs[PCOQ_TAIL_REGNUM] = fp + 4 * DEPRECATED_REGISTER_SIZE;
1686 frame_saved_regs[PCSQ_TAIL_REGNUM] = fp + 5 * DEPRECATED_REGISTER_SIZE;
1687 }
1688
1689 void
1690 hppa_pop_frame (void)
1691 {
1692 register struct frame_info *frame = get_current_frame ();
1693 register CORE_ADDR fp, npc, target_pc;
1694 register int regnum;
1695 CORE_ADDR *fsr;
1696 double freg_buffer;
1697
1698 fp = get_frame_base (frame);
1699 hppa_frame_init_saved_regs (frame);
1700 fsr = get_frame_saved_regs (frame);
1701
1702 #ifndef NO_PC_SPACE_QUEUE_RESTORE
1703 if (fsr[IPSW_REGNUM]) /* Restoring a call dummy frame */
1704 restore_pc_queue (fsr);
1705 #endif
1706
1707 for (regnum = 31; regnum > 0; regnum--)
1708 if (fsr[regnum])
1709 write_register (regnum, read_memory_integer (fsr[regnum],
1710 DEPRECATED_REGISTER_SIZE));
1711
1712 for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM; regnum--)
1713 if (fsr[regnum])
1714 {
1715 read_memory (fsr[regnum], (char *) &freg_buffer, 8);
1716 deprecated_write_register_bytes (REGISTER_BYTE (regnum),
1717 (char *) &freg_buffer, 8);
1718 }
1719
1720 if (fsr[IPSW_REGNUM])
1721 write_register (IPSW_REGNUM,
1722 read_memory_integer (fsr[IPSW_REGNUM],
1723 DEPRECATED_REGISTER_SIZE));
1724
1725 if (fsr[SAR_REGNUM])
1726 write_register (SAR_REGNUM,
1727 read_memory_integer (fsr[SAR_REGNUM],
1728 DEPRECATED_REGISTER_SIZE));
1729
1730 /* If the PC was explicitly saved, then just restore it. */
1731 if (fsr[PCOQ_TAIL_REGNUM])
1732 {
1733 npc = read_memory_integer (fsr[PCOQ_TAIL_REGNUM],
1734 DEPRECATED_REGISTER_SIZE);
1735 write_register (PCOQ_TAIL_REGNUM, npc);
1736 }
1737 /* Else use the value in %rp to set the new PC. */
1738 else
1739 {
1740 npc = read_register (RP_REGNUM);
1741 write_pc (npc);
1742 }
1743
1744 write_register (DEPRECATED_FP_REGNUM, read_memory_integer (fp, DEPRECATED_REGISTER_SIZE));
1745
1746 if (fsr[IPSW_REGNUM]) /* call dummy */
1747 write_register (SP_REGNUM, fp - 48);
1748 else
1749 write_register (SP_REGNUM, fp);
1750
1751 /* The PC we just restored may be inside a return trampoline. If so
1752 we want to restart the inferior and run it through the trampoline.
1753
1754 Do this by setting a momentary breakpoint at the location the
1755 trampoline returns to.
1756
1757 Don't skip through the trampoline if we're popping a dummy frame. */
1758 target_pc = SKIP_TRAMPOLINE_CODE (npc & ~0x3) & ~0x3;
1759 if (target_pc && !fsr[IPSW_REGNUM])
1760 {
1761 struct symtab_and_line sal;
1762 struct breakpoint *breakpoint;
1763 struct cleanup *old_chain;
1764
1765 /* Set up our breakpoint. Set it to be silent as the MI code
1766 for "return_command" will print the frame we returned to. */
1767 sal = find_pc_line (target_pc, 0);
1768 sal.pc = target_pc;
1769 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_finish);
1770 breakpoint->silent = 1;
1771
1772 /* So we can clean things up. */
1773 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1774
1775 /* Start up the inferior. */
1776 clear_proceed_status ();
1777 proceed_to_finish = 1;
1778 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1779
1780 /* Perform our cleanups. */
1781 do_cleanups (old_chain);
1782 }
1783 flush_cached_frames ();
1784 }
1785
1786 /* After returning to a dummy on the stack, restore the instruction
1787 queue space registers. */
1788
1789 static int
1790 restore_pc_queue (CORE_ADDR *fsr)
1791 {
1792 CORE_ADDR pc = read_pc ();
1793 CORE_ADDR new_pc = read_memory_integer (fsr[PCOQ_HEAD_REGNUM],
1794 TARGET_PTR_BIT / 8);
1795 struct target_waitstatus w;
1796 int insn_count;
1797
1798 /* Advance past break instruction in the call dummy. */
1799 write_register (PCOQ_HEAD_REGNUM, pc + 4);
1800 write_register (PCOQ_TAIL_REGNUM, pc + 8);
1801
1802 /* HPUX doesn't let us set the space registers or the space
1803 registers of the PC queue through ptrace. Boo, hiss.
1804 Conveniently, the call dummy has this sequence of instructions
1805 after the break:
1806 mtsp r21, sr0
1807 ble,n 0(sr0, r22)
1808
1809 So, load up the registers and single step until we are in the
1810 right place. */
1811
1812 write_register (21, read_memory_integer (fsr[PCSQ_HEAD_REGNUM],
1813 DEPRECATED_REGISTER_SIZE));
1814 write_register (22, new_pc);
1815
1816 for (insn_count = 0; insn_count < 3; insn_count++)
1817 {
1818 /* FIXME: What if the inferior gets a signal right now? Want to
1819 merge this into wait_for_inferior (as a special kind of
1820 watchpoint? By setting a breakpoint at the end? Is there
1821 any other choice? Is there *any* way to do this stuff with
1822 ptrace() or some equivalent?). */
1823 resume (1, 0);
1824 target_wait (inferior_ptid, &w);
1825
1826 if (w.kind == TARGET_WAITKIND_SIGNALLED)
1827 {
1828 stop_signal = w.value.sig;
1829 terminal_ours_for_output ();
1830 printf_unfiltered ("\nProgram terminated with signal %s, %s.\n",
1831 target_signal_to_name (stop_signal),
1832 target_signal_to_string (stop_signal));
1833 gdb_flush (gdb_stdout);
1834 return 0;
1835 }
1836 }
1837 target_terminal_ours ();
1838 target_fetch_registers (-1);
1839 return 1;
1840 }
1841
1842
1843 #ifdef PA20W_CALLING_CONVENTIONS
1844
1845 /* This function pushes a stack frame with arguments as part of the
1846 inferior function calling mechanism.
1847
1848 This is the version for the PA64, in which later arguments appear
1849 at higher addresses. (The stack always grows towards higher
1850 addresses.)
1851
1852 We simply allocate the appropriate amount of stack space and put
1853 arguments into their proper slots. The call dummy code will copy
1854 arguments into registers as needed by the ABI.
1855
1856 This ABI also requires that the caller provide an argument pointer
1857 to the callee, so we do that too. */
1858
1859 CORE_ADDR
1860 hppa_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1861 int struct_return, CORE_ADDR struct_addr)
1862 {
1863 /* array of arguments' offsets */
1864 int *offset = (int *) alloca (nargs * sizeof (int));
1865
1866 /* array of arguments' lengths: real lengths in bytes, not aligned to
1867 word size */
1868 int *lengths = (int *) alloca (nargs * sizeof (int));
1869
1870 /* The value of SP as it was passed into this function after
1871 aligning. */
1872 CORE_ADDR orig_sp = STACK_ALIGN (sp);
1873
1874 /* The number of stack bytes occupied by the current argument. */
1875 int bytes_reserved;
1876
1877 /* The total number of bytes reserved for the arguments. */
1878 int cum_bytes_reserved = 0;
1879
1880 /* Similarly, but aligned. */
1881 int cum_bytes_aligned = 0;
1882 int i;
1883
1884 /* Iterate over each argument provided by the user. */
1885 for (i = 0; i < nargs; i++)
1886 {
1887 struct type *arg_type = VALUE_TYPE (args[i]);
1888
1889 /* Integral scalar values smaller than a register are padded on
1890 the left. We do this by promoting them to full-width,
1891 although the ABI says to pad them with garbage. */
1892 if (is_integral_type (arg_type)
1893 && TYPE_LENGTH (arg_type) < DEPRECATED_REGISTER_SIZE)
1894 {
1895 args[i] = value_cast ((TYPE_UNSIGNED (arg_type)
1896 ? builtin_type_unsigned_long
1897 : builtin_type_long),
1898 args[i]);
1899 arg_type = VALUE_TYPE (args[i]);
1900 }
1901
1902 lengths[i] = TYPE_LENGTH (arg_type);
1903
1904 /* Align the size of the argument to the word size for this
1905 target. */
1906 bytes_reserved = (lengths[i] + DEPRECATED_REGISTER_SIZE - 1) & -DEPRECATED_REGISTER_SIZE;
1907
1908 offset[i] = cum_bytes_reserved;
1909
1910 /* Aggregates larger than eight bytes (the only types larger
1911 than eight bytes we have) are aligned on a 16-byte boundary,
1912 possibly padded on the right with garbage. This may leave an
1913 empty word on the stack, and thus an unused register, as per
1914 the ABI. */
1915 if (bytes_reserved > 8)
1916 {
1917 /* Round up the offset to a multiple of two slots. */
1918 int new_offset = ((offset[i] + 2*DEPRECATED_REGISTER_SIZE-1)
1919 & -(2*DEPRECATED_REGISTER_SIZE));
1920
1921 /* Note the space we've wasted, if any. */
1922 bytes_reserved += new_offset - offset[i];
1923 offset[i] = new_offset;
1924 }
1925
1926 cum_bytes_reserved += bytes_reserved;
1927 }
1928
1929 /* CUM_BYTES_RESERVED already accounts for all the arguments
1930 passed by the user. However, the ABIs mandate minimum stack space
1931 allocations for outgoing arguments.
1932
1933 The ABIs also mandate minimum stack alignments which we must
1934 preserve. */
1935 cum_bytes_aligned = STACK_ALIGN (cum_bytes_reserved);
1936 sp += max (cum_bytes_aligned, REG_PARM_STACK_SPACE);
1937
1938 /* Now write each of the args at the proper offset down the stack. */
1939 for (i = 0; i < nargs; i++)
1940 write_memory (orig_sp + offset[i], VALUE_CONTENTS (args[i]), lengths[i]);
1941
1942 /* If a structure has to be returned, set up register 28 to hold its
1943 address */
1944 if (struct_return)
1945 write_register (28, struct_addr);
1946
1947 /* For the PA64 we must pass a pointer to the outgoing argument list.
1948 The ABI mandates that the pointer should point to the first byte of
1949 storage beyond the register flushback area.
1950
1951 However, the call dummy expects the outgoing argument pointer to
1952 be passed in register %r4. */
1953 write_register (4, orig_sp + REG_PARM_STACK_SPACE);
1954
1955 /* ?!? This needs further work. We need to set up the global data
1956 pointer for this procedure. This assumes the same global pointer
1957 for every procedure. The call dummy expects the dp value to
1958 be passed in register %r6. */
1959 write_register (6, read_register (27));
1960
1961 /* The stack will have 64 bytes of additional space for a frame marker. */
1962 return sp + 64;
1963 }
1964
1965 #else
1966
1967 /* This function pushes a stack frame with arguments as part of the
1968 inferior function calling mechanism.
1969
1970 This is the version of the function for the 32-bit PA machines, in
1971 which later arguments appear at lower addresses. (The stack always
1972 grows towards higher addresses.)
1973
1974 We simply allocate the appropriate amount of stack space and put
1975 arguments into their proper slots. The call dummy code will copy
1976 arguments into registers as needed by the ABI. */
1977
1978 CORE_ADDR
1979 hppa_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1980 int struct_return, CORE_ADDR struct_addr)
1981 {
1982 /* array of arguments' offsets */
1983 int *offset = (int *) alloca (nargs * sizeof (int));
1984
1985 /* array of arguments' lengths: real lengths in bytes, not aligned to
1986 word size */
1987 int *lengths = (int *) alloca (nargs * sizeof (int));
1988
1989 /* The number of stack bytes occupied by the current argument. */
1990 int bytes_reserved;
1991
1992 /* The total number of bytes reserved for the arguments. */
1993 int cum_bytes_reserved = 0;
1994
1995 /* Similarly, but aligned. */
1996 int cum_bytes_aligned = 0;
1997 int i;
1998
1999 /* Iterate over each argument provided by the user. */
2000 for (i = 0; i < nargs; i++)
2001 {
2002 lengths[i] = TYPE_LENGTH (VALUE_TYPE (args[i]));
2003
2004 /* Align the size of the argument to the word size for this
2005 target. */
2006 bytes_reserved = (lengths[i] + DEPRECATED_REGISTER_SIZE - 1) & -DEPRECATED_REGISTER_SIZE;
2007
2008 offset[i] = (cum_bytes_reserved
2009 + (lengths[i] > 4 ? bytes_reserved : lengths[i]));
2010
2011 /* If the argument is a double word argument, then it needs to be
2012 double word aligned. */
2013 if ((bytes_reserved == 2 * DEPRECATED_REGISTER_SIZE)
2014 && (offset[i] % 2 * DEPRECATED_REGISTER_SIZE))
2015 {
2016 int new_offset = 0;
2017 /* BYTES_RESERVED is already aligned to the word, so we put
2018 the argument at one word more down the stack.
2019
2020 This will leave one empty word on the stack, and one unused
2021 register as mandated by the ABI. */
2022 new_offset = ((offset[i] + 2 * DEPRECATED_REGISTER_SIZE - 1)
2023 & -(2 * DEPRECATED_REGISTER_SIZE));
2024
2025 if ((new_offset - offset[i]) >= 2 * DEPRECATED_REGISTER_SIZE)
2026 {
2027 bytes_reserved += DEPRECATED_REGISTER_SIZE;
2028 offset[i] += DEPRECATED_REGISTER_SIZE;
2029 }
2030 }
2031
2032 cum_bytes_reserved += bytes_reserved;
2033
2034 }
2035
2036 /* CUM_BYTES_RESERVED already accounts for all the arguments passed
2037 by the user. However, the ABI mandates minimum stack space
2038 allocations for outgoing arguments.
2039
2040 The ABI also mandates minimum stack alignments which we must
2041 preserve. */
2042 cum_bytes_aligned = STACK_ALIGN (cum_bytes_reserved);
2043 sp += max (cum_bytes_aligned, REG_PARM_STACK_SPACE);
2044
2045 /* Now write each of the args at the proper offset down the stack.
2046 ?!? We need to promote values to a full register instead of skipping
2047 words in the stack. */
2048 for (i = 0; i < nargs; i++)
2049 write_memory (sp - offset[i], VALUE_CONTENTS (args[i]), lengths[i]);
2050
2051 /* If a structure has to be returned, set up register 28 to hold its
2052 address */
2053 if (struct_return)
2054 write_register (28, struct_addr);
2055
2056 /* The stack will have 32 bytes of additional space for a frame marker. */
2057 return sp + 32;
2058 }
2059
2060 #endif
2061
2062 /* elz: this function returns a value which is built looking at the given address.
2063 It is called from call_function_by_hand, in case we need to return a
2064 value which is larger than 64 bits, and it is stored in the stack rather than
2065 in the registers r28 and r29 or fr4.
2066 This function does the same stuff as value_being_returned in values.c, but
2067 gets the value from the stack rather than from the buffer where all the
2068 registers were saved when the function called completed. */
2069 struct value *
2070 hppa_value_returned_from_stack (register struct type *valtype, CORE_ADDR addr)
2071 {
2072 register struct value *val;
2073
2074 val = allocate_value (valtype);
2075 CHECK_TYPEDEF (valtype);
2076 target_read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (valtype));
2077
2078 return val;
2079 }
2080
2081
2082
2083 /* elz: Used to lookup a symbol in the shared libraries.
2084 This function calls shl_findsym, indirectly through a
2085 call to __d_shl_get. __d_shl_get is in end.c, which is always
2086 linked in by the hp compilers/linkers.
2087 The call to shl_findsym cannot be made directly because it needs
2088 to be active in target address space.
2089 inputs: - minimal symbol pointer for the function we want to look up
2090 - address in target space of the descriptor for the library
2091 where we want to look the symbol up.
2092 This address is retrieved using the
2093 som_solib_get_solib_by_pc function (somsolib.c).
2094 output: - real address in the library of the function.
2095 note: the handle can be null, in which case shl_findsym will look for
2096 the symbol in all the loaded shared libraries.
2097 files to look at if you need reference on this stuff:
2098 dld.c, dld_shl_findsym.c
2099 end.c
2100 man entry for shl_findsym */
2101
2102 CORE_ADDR
2103 find_stub_with_shl_get (struct minimal_symbol *function, CORE_ADDR handle)
2104 {
2105 struct symbol *get_sym, *symbol2;
2106 struct minimal_symbol *buff_minsym, *msymbol;
2107 struct type *ftype;
2108 struct value **args;
2109 struct value *funcval;
2110 struct value *val;
2111
2112 int x, namelen, err_value, tmp = -1;
2113 CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr;
2114 CORE_ADDR stub_addr;
2115
2116
2117 args = alloca (sizeof (struct value *) * 8); /* 6 for the arguments and one null one??? */
2118 funcval = find_function_in_inferior ("__d_shl_get");
2119 get_sym = lookup_symbol ("__d_shl_get", NULL, VAR_DOMAIN, NULL, NULL);
2120 buff_minsym = lookup_minimal_symbol ("__buffer", NULL, NULL);
2121 msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL);
2122 symbol2 = lookup_symbol ("__shldp", NULL, VAR_DOMAIN, NULL, NULL);
2123 endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym);
2124 namelen = strlen (DEPRECATED_SYMBOL_NAME (function));
2125 value_return_addr = endo_buff_addr + namelen;
2126 ftype = check_typedef (SYMBOL_TYPE (get_sym));
2127
2128 /* do alignment */
2129 if ((x = value_return_addr % 64) != 0)
2130 value_return_addr = value_return_addr + 64 - x;
2131
2132 errno_return_addr = value_return_addr + 64;
2133
2134
2135 /* set up stuff needed by __d_shl_get in buffer in end.o */
2136
2137 target_write_memory (endo_buff_addr, DEPRECATED_SYMBOL_NAME (function), namelen);
2138
2139 target_write_memory (value_return_addr, (char *) &tmp, 4);
2140
2141 target_write_memory (errno_return_addr, (char *) &tmp, 4);
2142
2143 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol),
2144 (char *) &handle, 4);
2145
2146 /* now prepare the arguments for the call */
2147
2148 args[0] = value_from_longest (TYPE_FIELD_TYPE (ftype, 0), 12);
2149 args[1] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 1), SYMBOL_VALUE_ADDRESS (msymbol));
2150 args[2] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 2), endo_buff_addr);
2151 args[3] = value_from_longest (TYPE_FIELD_TYPE (ftype, 3), TYPE_PROCEDURE);
2152 args[4] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 4), value_return_addr);
2153 args[5] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 5), errno_return_addr);
2154
2155 /* now call the function */
2156
2157 val = call_function_by_hand (funcval, 6, args);
2158
2159 /* now get the results */
2160
2161 target_read_memory (errno_return_addr, (char *) &err_value, sizeof (err_value));
2162
2163 target_read_memory (value_return_addr, (char *) &stub_addr, sizeof (stub_addr));
2164 if (stub_addr <= 0)
2165 error ("call to __d_shl_get failed, error code is %d", err_value);
2166
2167 return (stub_addr);
2168 }
2169
2170 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
2171 static int
2172 cover_find_stub_with_shl_get (void *args_untyped)
2173 {
2174 args_for_find_stub *args = args_untyped;
2175 args->return_val = find_stub_with_shl_get (args->msym, args->solib_handle);
2176 return 0;
2177 }
2178
2179 /* Insert the specified number of args and function address
2180 into a call sequence of the above form stored at DUMMYNAME.
2181
2182 On the hppa we need to call the stack dummy through $$dyncall.
2183 Therefore our version of DEPRECATED_FIX_CALL_DUMMY takes an extra
2184 argument, real_pc, which is the location where gdb should start up
2185 the inferior to do the function call.
2186
2187 This has to work across several versions of hpux, bsd, osf1. It has to
2188 work regardless of what compiler was used to build the inferior program.
2189 It should work regardless of whether or not end.o is available. It has
2190 to work even if gdb can not call into the dynamic loader in the inferior
2191 to query it for symbol names and addresses.
2192
2193 Yes, all those cases should work. Luckily code exists to handle most
2194 of them. The complexity is in selecting exactly what scheme should
2195 be used to perform the inferior call.
2196
2197 At the current time this routine is known not to handle cases where
2198 the program was linked with HP's compiler without including end.o.
2199
2200 Please contact Jeff Law (law@cygnus.com) before changing this code. */
2201
2202 CORE_ADDR
2203 hppa_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
2204 struct value **args, struct type *type, int gcc_p)
2205 {
2206 CORE_ADDR dyncall_addr;
2207 struct minimal_symbol *msymbol;
2208 struct minimal_symbol *trampoline;
2209 int flags = read_register (FLAGS_REGNUM);
2210 struct unwind_table_entry *u = NULL;
2211 CORE_ADDR new_stub = 0;
2212 CORE_ADDR solib_handle = 0;
2213
2214 /* Nonzero if we will use GCC's PLT call routine. This routine must be
2215 passed an import stub, not a PLABEL. It is also necessary to set %r19
2216 (the PIC register) before performing the call.
2217
2218 If zero, then we are using __d_plt_call (HP's PLT call routine) or we
2219 are calling the target directly. When using __d_plt_call we want to
2220 use a PLABEL instead of an import stub. */
2221 int using_gcc_plt_call = 1;
2222
2223 #ifdef GDB_TARGET_IS_HPPA_20W
2224 /* We currently use completely different code for the PA2.0W inferior
2225 function call sequences. This needs to be cleaned up. */
2226 {
2227 CORE_ADDR pcsqh, pcsqt, pcoqh, pcoqt, sr5;
2228 struct target_waitstatus w;
2229 int inst1, inst2;
2230 char buf[4];
2231 int status;
2232 struct objfile *objfile;
2233
2234 /* We can not modify the PC space queues directly, so we start
2235 up the inferior and execute a couple instructions to set the
2236 space queues so that they point to the call dummy in the stack. */
2237 pcsqh = read_register (PCSQ_HEAD_REGNUM);
2238 sr5 = read_register (SR5_REGNUM);
2239 if (1)
2240 {
2241 pcoqh = read_register (PCOQ_HEAD_REGNUM);
2242 pcoqt = read_register (PCOQ_TAIL_REGNUM);
2243 if (target_read_memory (pcoqh, buf, 4) != 0)
2244 error ("Couldn't modify space queue\n");
2245 inst1 = extract_unsigned_integer (buf, 4);
2246
2247 if (target_read_memory (pcoqt, buf, 4) != 0)
2248 error ("Couldn't modify space queue\n");
2249 inst2 = extract_unsigned_integer (buf, 4);
2250
2251 /* BVE (r1) */
2252 *((int *) buf) = 0xe820d000;
2253 if (target_write_memory (pcoqh, buf, 4) != 0)
2254 error ("Couldn't modify space queue\n");
2255
2256 /* NOP */
2257 *((int *) buf) = 0x08000240;
2258 if (target_write_memory (pcoqt, buf, 4) != 0)
2259 {
2260 *((int *) buf) = inst1;
2261 target_write_memory (pcoqh, buf, 4);
2262 error ("Couldn't modify space queue\n");
2263 }
2264
2265 write_register (1, pc);
2266
2267 /* Single step twice, the BVE instruction will set the space queue
2268 such that it points to the PC value written immediately above
2269 (ie the call dummy). */
2270 resume (1, 0);
2271 target_wait (inferior_ptid, &w);
2272 resume (1, 0);
2273 target_wait (inferior_ptid, &w);
2274
2275 /* Restore the two instructions at the old PC locations. */
2276 *((int *) buf) = inst1;
2277 target_write_memory (pcoqh, buf, 4);
2278 *((int *) buf) = inst2;
2279 target_write_memory (pcoqt, buf, 4);
2280 }
2281
2282 /* The call dummy wants the ultimate destination address initially
2283 in register %r5. */
2284 write_register (5, fun);
2285
2286 /* We need to see if this objfile has a different DP value than our
2287 own (it could be a shared library for example). */
2288 ALL_OBJFILES (objfile)
2289 {
2290 struct obj_section *s;
2291 obj_private_data_t *obj_private;
2292
2293 /* See if FUN is in any section within this shared library. */
2294 for (s = objfile->sections; s < objfile->sections_end; s++)
2295 if (s->addr <= fun && fun < s->endaddr)
2296 break;
2297
2298 if (s >= objfile->sections_end)
2299 continue;
2300
2301 obj_private = (obj_private_data_t *) objfile->obj_private;
2302
2303 /* The DP value may be different for each objfile. But within an
2304 objfile each function uses the same dp value. Thus we do not need
2305 to grope around the opd section looking for dp values.
2306
2307 ?!? This is not strictly correct since we may be in a shared library
2308 and want to call back into the main program. To make that case
2309 work correctly we need to set obj_private->dp for the main program's
2310 objfile, then remove this conditional. */
2311 if (obj_private->dp)
2312 write_register (27, obj_private->dp);
2313 break;
2314 }
2315 return pc;
2316 }
2317 #endif
2318
2319 #ifndef GDB_TARGET_IS_HPPA_20W
2320 /* Prefer __gcc_plt_call over the HP supplied routine because
2321 __gcc_plt_call works for any number of arguments. */
2322 trampoline = NULL;
2323 if (lookup_minimal_symbol ("__gcc_plt_call", NULL, NULL) == NULL)
2324 using_gcc_plt_call = 0;
2325
2326 msymbol = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
2327 if (msymbol == NULL)
2328 error ("Can't find an address for $$dyncall trampoline");
2329
2330 dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol);
2331
2332 /* FUN could be a procedure label, in which case we have to get
2333 its real address and the value of its GOT/DP if we plan to
2334 call the routine via gcc_plt_call. */
2335 if ((fun & 0x2) && using_gcc_plt_call)
2336 {
2337 /* Get the GOT/DP value for the target function. It's
2338 at *(fun+4). Note the call dummy is *NOT* allowed to
2339 trash %r19 before calling the target function. */
2340 write_register (19, read_memory_integer ((fun & ~0x3) + 4,
2341 DEPRECATED_REGISTER_SIZE));
2342
2343 /* Now get the real address for the function we are calling, it's
2344 at *fun. */
2345 fun = (CORE_ADDR) read_memory_integer (fun & ~0x3,
2346 TARGET_PTR_BIT / 8);
2347 }
2348 else
2349 {
2350
2351 #ifndef GDB_TARGET_IS_PA_ELF
2352 /* FUN could be an export stub, the real address of a function, or
2353 a PLABEL. When using gcc's PLT call routine we must call an import
2354 stub rather than the export stub or real function for lazy binding
2355 to work correctly
2356
2357 If we are using the gcc PLT call routine, then we need to
2358 get the import stub for the target function. */
2359 if (using_gcc_plt_call && som_solib_get_got_by_pc (fun))
2360 {
2361 struct objfile *objfile;
2362 struct minimal_symbol *funsymbol, *stub_symbol;
2363 CORE_ADDR newfun = 0;
2364
2365 funsymbol = lookup_minimal_symbol_by_pc (fun);
2366 if (!funsymbol)
2367 error ("Unable to find minimal symbol for target function.\n");
2368
2369 /* Search all the object files for an import symbol with the
2370 right name. */
2371 ALL_OBJFILES (objfile)
2372 {
2373 stub_symbol
2374 = lookup_minimal_symbol_solib_trampoline
2375 (DEPRECATED_SYMBOL_NAME (funsymbol), NULL, objfile);
2376
2377 if (!stub_symbol)
2378 stub_symbol = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (funsymbol),
2379 NULL, objfile);
2380
2381 /* Found a symbol with the right name. */
2382 if (stub_symbol)
2383 {
2384 struct unwind_table_entry *u;
2385 /* It must be a shared library trampoline. */
2386 if (MSYMBOL_TYPE (stub_symbol) != mst_solib_trampoline)
2387 continue;
2388
2389 /* It must also be an import stub. */
2390 u = find_unwind_entry (SYMBOL_VALUE (stub_symbol));
2391 if (u == NULL
2392 || (u->stub_unwind.stub_type != IMPORT
2393 #ifdef GDB_NATIVE_HPUX_11
2394 /* Sigh. The hpux 10.20 dynamic linker will blow
2395 chunks if we perform a call to an unbound function
2396 via the IMPORT_SHLIB stub. The hpux 11.00 dynamic
2397 linker will blow chunks if we do not call the
2398 unbound function via the IMPORT_SHLIB stub.
2399
2400 We currently have no way to select bevahior on just
2401 the target. However, we only support HPUX/SOM in
2402 native mode. So we conditinalize on a native
2403 #ifdef. Ugly. Ugly. Ugly */
2404 && u->stub_unwind.stub_type != IMPORT_SHLIB
2405 #endif
2406 ))
2407 continue;
2408
2409 /* OK. Looks like the correct import stub. */
2410 newfun = SYMBOL_VALUE (stub_symbol);
2411 fun = newfun;
2412
2413 /* If we found an IMPORT stub, then we want to stop
2414 searching now. If we found an IMPORT_SHLIB, we want
2415 to continue the search in the hopes that we will find
2416 an IMPORT stub. */
2417 if (u->stub_unwind.stub_type == IMPORT)
2418 break;
2419 }
2420 }
2421
2422 /* Ouch. We did not find an import stub. Make an attempt to
2423 do the right thing instead of just croaking. Most of the
2424 time this will actually work. */
2425 if (newfun == 0)
2426 write_register (19, som_solib_get_got_by_pc (fun));
2427
2428 u = find_unwind_entry (fun);
2429 if (u
2430 && (u->stub_unwind.stub_type == IMPORT
2431 || u->stub_unwind.stub_type == IMPORT_SHLIB))
2432 trampoline = lookup_minimal_symbol ("__gcc_plt_call", NULL, NULL);
2433
2434 /* If we found the import stub in the shared library, then we have
2435 to set %r19 before we call the stub. */
2436 if (u && u->stub_unwind.stub_type == IMPORT_SHLIB)
2437 write_register (19, som_solib_get_got_by_pc (fun));
2438 }
2439 #endif
2440 }
2441
2442 /* If we are calling into another load module then have sr4export call the
2443 magic __d_plt_call routine which is linked in from end.o.
2444
2445 You can't use _sr4export to make the call as the value in sp-24 will get
2446 fried and you end up returning to the wrong location. You can't call the
2447 target as the code to bind the PLT entry to a function can't return to a
2448 stack address.
2449
2450 Also, query the dynamic linker in the inferior to provide a suitable
2451 PLABEL for the target function. */
2452 if (!using_gcc_plt_call)
2453 {
2454 CORE_ADDR new_fun;
2455
2456 /* Get a handle for the shared library containing FUN. Given the
2457 handle we can query the shared library for a PLABEL. */
2458 solib_handle = som_solib_get_solib_by_pc (fun);
2459
2460 if (solib_handle)
2461 {
2462 struct minimal_symbol *fmsymbol = lookup_minimal_symbol_by_pc (fun);
2463
2464 trampoline = lookup_minimal_symbol ("__d_plt_call", NULL, NULL);
2465
2466 if (trampoline == NULL)
2467 {
2468 error ("Can't find an address for __d_plt_call or __gcc_plt_call trampoline\nSuggest linking executable with -g or compiling with gcc.");
2469 }
2470
2471 /* This is where sr4export will jump to. */
2472 new_fun = SYMBOL_VALUE_ADDRESS (trampoline);
2473
2474 /* If the function is in a shared library, then call __d_shl_get to
2475 get a PLABEL for the target function. */
2476 new_stub = find_stub_with_shl_get (fmsymbol, solib_handle);
2477
2478 if (new_stub == 0)
2479 error ("Can't find an import stub for %s", DEPRECATED_SYMBOL_NAME (fmsymbol));
2480
2481 /* We have to store the address of the stub in __shlib_funcptr. */
2482 msymbol = lookup_minimal_symbol ("__shlib_funcptr", NULL,
2483 (struct objfile *) NULL);
2484
2485 if (msymbol == NULL)
2486 error ("Can't find an address for __shlib_funcptr");
2487 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol),
2488 (char *) &new_stub, 4);
2489
2490 /* We want sr4export to call __d_plt_call, so we claim it is
2491 the final target. Clear trampoline. */
2492 fun = new_fun;
2493 trampoline = NULL;
2494 }
2495 }
2496
2497 /* Store upper 21 bits of function address into ldil. fun will either be
2498 the final target (most cases) or __d_plt_call when calling into a shared
2499 library and __gcc_plt_call is not available. */
2500 store_unsigned_integer
2501 (&dummy[FUNC_LDIL_OFFSET],
2502 INSTRUCTION_SIZE,
2503 deposit_21 (fun >> 11,
2504 extract_unsigned_integer (&dummy[FUNC_LDIL_OFFSET],
2505 INSTRUCTION_SIZE)));
2506
2507 /* Store lower 11 bits of function address into ldo */
2508 store_unsigned_integer
2509 (&dummy[FUNC_LDO_OFFSET],
2510 INSTRUCTION_SIZE,
2511 deposit_14 (fun & MASK_11,
2512 extract_unsigned_integer (&dummy[FUNC_LDO_OFFSET],
2513 INSTRUCTION_SIZE)));
2514 #ifdef SR4EXPORT_LDIL_OFFSET
2515
2516 {
2517 CORE_ADDR trampoline_addr;
2518
2519 /* We may still need sr4export's address too. */
2520
2521 if (trampoline == NULL)
2522 {
2523 msymbol = lookup_minimal_symbol ("_sr4export", NULL, NULL);
2524 if (msymbol == NULL)
2525 error ("Can't find an address for _sr4export trampoline");
2526
2527 trampoline_addr = SYMBOL_VALUE_ADDRESS (msymbol);
2528 }
2529 else
2530 trampoline_addr = SYMBOL_VALUE_ADDRESS (trampoline);
2531
2532
2533 /* Store upper 21 bits of trampoline's address into ldil */
2534 store_unsigned_integer
2535 (&dummy[SR4EXPORT_LDIL_OFFSET],
2536 INSTRUCTION_SIZE,
2537 deposit_21 (trampoline_addr >> 11,
2538 extract_unsigned_integer (&dummy[SR4EXPORT_LDIL_OFFSET],
2539 INSTRUCTION_SIZE)));
2540
2541 /* Store lower 11 bits of trampoline's address into ldo */
2542 store_unsigned_integer
2543 (&dummy[SR4EXPORT_LDO_OFFSET],
2544 INSTRUCTION_SIZE,
2545 deposit_14 (trampoline_addr & MASK_11,
2546 extract_unsigned_integer (&dummy[SR4EXPORT_LDO_OFFSET],
2547 INSTRUCTION_SIZE)));
2548 }
2549 #endif
2550
2551 write_register (22, pc);
2552
2553 /* If we are in a syscall, then we should call the stack dummy
2554 directly. $$dyncall is not needed as the kernel sets up the
2555 space id registers properly based on the value in %r31. In
2556 fact calling $$dyncall will not work because the value in %r22
2557 will be clobbered on the syscall exit path.
2558
2559 Similarly if the current PC is in a shared library. Note however,
2560 this scheme won't work if the shared library isn't mapped into
2561 the same space as the stack. */
2562 if (flags & 2)
2563 return pc;
2564 #ifndef GDB_TARGET_IS_PA_ELF
2565 else if (som_solib_get_got_by_pc (hppa_target_read_pc (inferior_ptid)))
2566 return pc;
2567 #endif
2568 else
2569 return dyncall_addr;
2570 #endif
2571 }
2572
2573 /* If the pid is in a syscall, then the FP register is not readable.
2574 We'll return zero in that case, rather than attempting to read it
2575 and cause a warning. */
2576
2577 CORE_ADDR
2578 hppa_read_fp (int pid)
2579 {
2580 int flags = read_register (FLAGS_REGNUM);
2581
2582 if (flags & 2)
2583 {
2584 return (CORE_ADDR) 0;
2585 }
2586
2587 /* This is the only site that may directly read_register () the FP
2588 register. All others must use deprecated_read_fp (). */
2589 return read_register (DEPRECATED_FP_REGNUM);
2590 }
2591
2592 CORE_ADDR
2593 hppa_target_read_fp (void)
2594 {
2595 return hppa_read_fp (PIDGET (inferior_ptid));
2596 }
2597
2598 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
2599 bits. */
2600
2601 CORE_ADDR
2602 hppa_target_read_pc (ptid_t ptid)
2603 {
2604 int flags = read_register_pid (FLAGS_REGNUM, ptid);
2605
2606 /* The following test does not belong here. It is OS-specific, and belongs
2607 in native code. */
2608 /* Test SS_INSYSCALL */
2609 if (flags & 2)
2610 return read_register_pid (31, ptid) & ~0x3;
2611
2612 return read_register_pid (PC_REGNUM, ptid) & ~0x3;
2613 }
2614
2615 /* Write out the PC. If currently in a syscall, then also write the new
2616 PC value into %r31. */
2617
2618 void
2619 hppa_target_write_pc (CORE_ADDR v, ptid_t ptid)
2620 {
2621 int flags = read_register_pid (FLAGS_REGNUM, ptid);
2622
2623 /* The following test does not belong here. It is OS-specific, and belongs
2624 in native code. */
2625 /* If in a syscall, then set %r31. Also make sure to get the
2626 privilege bits set correctly. */
2627 /* Test SS_INSYSCALL */
2628 if (flags & 2)
2629 write_register_pid (31, v | 0x3, ptid);
2630
2631 write_register_pid (PC_REGNUM, v, ptid);
2632 write_register_pid (NPC_REGNUM, v + 4, ptid);
2633 }
2634
2635 /* return the alignment of a type in bytes. Structures have the maximum
2636 alignment required by their fields. */
2637
2638 static int
2639 hppa_alignof (struct type *type)
2640 {
2641 int max_align, align, i;
2642 CHECK_TYPEDEF (type);
2643 switch (TYPE_CODE (type))
2644 {
2645 case TYPE_CODE_PTR:
2646 case TYPE_CODE_INT:
2647 case TYPE_CODE_FLT:
2648 return TYPE_LENGTH (type);
2649 case TYPE_CODE_ARRAY:
2650 return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
2651 case TYPE_CODE_STRUCT:
2652 case TYPE_CODE_UNION:
2653 max_align = 1;
2654 for (i = 0; i < TYPE_NFIELDS (type); i++)
2655 {
2656 /* Bit fields have no real alignment. */
2657 /* if (!TYPE_FIELD_BITPOS (type, i)) */
2658 if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */
2659 {
2660 align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
2661 max_align = max (max_align, align);
2662 }
2663 }
2664 return max_align;
2665 default:
2666 return 4;
2667 }
2668 }
2669
2670 /* Print the register regnum, or all registers if regnum is -1 */
2671
2672 void
2673 pa_do_registers_info (int regnum, int fpregs)
2674 {
2675 char *raw_regs = alloca (DEPRECATED_REGISTER_BYTES);
2676 int i;
2677
2678 /* Make a copy of gdb's save area (may cause actual
2679 reads from the target). */
2680 for (i = 0; i < NUM_REGS; i++)
2681 frame_register_read (deprecated_selected_frame, i, raw_regs + REGISTER_BYTE (i));
2682
2683 if (regnum == -1)
2684 pa_print_registers (raw_regs, regnum, fpregs);
2685 else if (regnum < FP4_REGNUM)
2686 {
2687 long reg_val[2];
2688
2689 /* Why is the value not passed through "extract_signed_integer"
2690 as in "pa_print_registers" below? */
2691 pa_register_look_aside (raw_regs, regnum, &reg_val[0]);
2692
2693 if (!is_pa_2)
2694 {
2695 printf_unfiltered ("%s %lx\n", REGISTER_NAME (regnum), reg_val[1]);
2696 }
2697 else
2698 {
2699 /* Fancy % formats to prevent leading zeros. */
2700 if (reg_val[0] == 0)
2701 printf_unfiltered ("%s %lx\n", REGISTER_NAME (regnum), reg_val[1]);
2702 else
2703 printf_unfiltered ("%s %lx%8.8lx\n", REGISTER_NAME (regnum),
2704 reg_val[0], reg_val[1]);
2705 }
2706 }
2707 else
2708 /* Note that real floating point values only start at
2709 FP4_REGNUM. FP0 and up are just status and error
2710 registers, which have integral (bit) values. */
2711 pa_print_fp_reg (regnum);
2712 }
2713
2714 /********** new function ********************/
2715 void
2716 pa_do_strcat_registers_info (int regnum, int fpregs, struct ui_file *stream,
2717 enum precision_type precision)
2718 {
2719 char *raw_regs = alloca (DEPRECATED_REGISTER_BYTES);
2720 int i;
2721
2722 /* Make a copy of gdb's save area (may cause actual
2723 reads from the target). */
2724 for (i = 0; i < NUM_REGS; i++)
2725 frame_register_read (deprecated_selected_frame, i, raw_regs + REGISTER_BYTE (i));
2726
2727 if (regnum == -1)
2728 pa_strcat_registers (raw_regs, regnum, fpregs, stream);
2729
2730 else if (regnum < FP4_REGNUM)
2731 {
2732 long reg_val[2];
2733
2734 /* Why is the value not passed through "extract_signed_integer"
2735 as in "pa_print_registers" below? */
2736 pa_register_look_aside (raw_regs, regnum, &reg_val[0]);
2737
2738 if (!is_pa_2)
2739 {
2740 fprintf_unfiltered (stream, "%s %lx", REGISTER_NAME (regnum), reg_val[1]);
2741 }
2742 else
2743 {
2744 /* Fancy % formats to prevent leading zeros. */
2745 if (reg_val[0] == 0)
2746 fprintf_unfiltered (stream, "%s %lx", REGISTER_NAME (regnum),
2747 reg_val[1]);
2748 else
2749 fprintf_unfiltered (stream, "%s %lx%8.8lx", REGISTER_NAME (regnum),
2750 reg_val[0], reg_val[1]);
2751 }
2752 }
2753 else
2754 /* Note that real floating point values only start at
2755 FP4_REGNUM. FP0 and up are just status and error
2756 registers, which have integral (bit) values. */
2757 pa_strcat_fp_reg (regnum, stream, precision);
2758 }
2759
2760 /* If this is a PA2.0 machine, fetch the real 64-bit register
2761 value. Otherwise use the info from gdb's saved register area.
2762
2763 Note that reg_val is really expected to be an array of longs,
2764 with two elements. */
2765 static void
2766 pa_register_look_aside (char *raw_regs, int regnum, long *raw_val)
2767 {
2768 static int know_which = 0; /* False */
2769
2770 int regaddr;
2771 unsigned int offset;
2772 register int i;
2773 int start;
2774
2775
2776 char buf[MAX_REGISTER_SIZE];
2777 long long reg_val;
2778
2779 if (!know_which)
2780 {
2781 if (CPU_PA_RISC2_0 == sysconf (_SC_CPU_VERSION))
2782 {
2783 is_pa_2 = (1 == 1);
2784 }
2785
2786 know_which = 1; /* True */
2787 }
2788
2789 raw_val[0] = 0;
2790 raw_val[1] = 0;
2791
2792 if (!is_pa_2)
2793 {
2794 raw_val[1] = *(long *) (raw_regs + REGISTER_BYTE (regnum));
2795 return;
2796 }
2797
2798 /* Code below copied from hppah-nat.c, with fixes for wide
2799 registers, using different area of save_state, etc. */
2800 if (regnum == FLAGS_REGNUM || regnum >= FP0_REGNUM ||
2801 !HAVE_STRUCT_SAVE_STATE_T || !HAVE_STRUCT_MEMBER_SS_WIDE)
2802 {
2803 /* Use narrow regs area of save_state and default macro. */
2804 offset = U_REGS_OFFSET;
2805 regaddr = register_addr (regnum, offset);
2806 start = 1;
2807 }
2808 else
2809 {
2810 /* Use wide regs area, and calculate registers as 8 bytes wide.
2811
2812 We'd like to do this, but current version of "C" doesn't
2813 permit "offsetof":
2814
2815 offset = offsetof(save_state_t, ss_wide);
2816
2817 Note that to avoid "C" doing typed pointer arithmetic, we
2818 have to cast away the type in our offset calculation:
2819 otherwise we get an offset of 1! */
2820
2821 /* NB: save_state_t is not available before HPUX 9.
2822 The ss_wide field is not available previous to HPUX 10.20,
2823 so to avoid compile-time warnings, we only compile this for
2824 PA 2.0 processors. This control path should only be followed
2825 if we're debugging a PA 2.0 processor, so this should not cause
2826 problems. */
2827
2828 /* #if the following code out so that this file can still be
2829 compiled on older HPUX boxes (< 10.20) which don't have
2830 this structure/structure member. */
2831 #if HAVE_STRUCT_SAVE_STATE_T == 1 && HAVE_STRUCT_MEMBER_SS_WIDE == 1
2832 save_state_t temp;
2833
2834 offset = ((int) &temp.ss_wide) - ((int) &temp);
2835 regaddr = offset + regnum * 8;
2836 start = 0;
2837 #endif
2838 }
2839
2840 for (i = start; i < 2; i++)
2841 {
2842 errno = 0;
2843 raw_val[i] = call_ptrace (PT_RUREGS, PIDGET (inferior_ptid),
2844 (PTRACE_ARG3_TYPE) regaddr, 0);
2845 if (errno != 0)
2846 {
2847 /* Warning, not error, in case we are attached; sometimes the
2848 kernel doesn't let us at the registers. */
2849 char *err = safe_strerror (errno);
2850 char *msg = alloca (strlen (err) + 128);
2851 sprintf (msg, "reading register %s: %s", REGISTER_NAME (regnum), err);
2852 warning (msg);
2853 goto error_exit;
2854 }
2855
2856 regaddr += sizeof (long);
2857 }
2858
2859 if (regnum == PCOQ_HEAD_REGNUM || regnum == PCOQ_TAIL_REGNUM)
2860 raw_val[1] &= ~0x3; /* I think we're masking out space bits */
2861
2862 error_exit:
2863 ;
2864 }
2865
2866 /* "Info all-reg" command */
2867
2868 static void
2869 pa_print_registers (char *raw_regs, int regnum, int fpregs)
2870 {
2871 int i, j;
2872 /* Alas, we are compiled so that "long long" is 32 bits */
2873 long raw_val[2];
2874 long long_val;
2875 int rows = 48, columns = 2;
2876
2877 for (i = 0; i < rows; i++)
2878 {
2879 for (j = 0; j < columns; j++)
2880 {
2881 /* We display registers in column-major order. */
2882 int regnum = i + j * rows;
2883
2884 /* Q: Why is the value passed through "extract_signed_integer",
2885 while above, in "pa_do_registers_info" it isn't?
2886 A: ? */
2887 pa_register_look_aside (raw_regs, regnum, &raw_val[0]);
2888
2889 /* Even fancier % formats to prevent leading zeros
2890 and still maintain the output in columns. */
2891 if (!is_pa_2)
2892 {
2893 /* Being big-endian, on this machine the low bits
2894 (the ones we want to look at) are in the second longword. */
2895 long_val = extract_signed_integer (&raw_val[1], 4);
2896 printf_filtered ("%10.10s: %8lx ",
2897 REGISTER_NAME (regnum), long_val);
2898 }
2899 else
2900 {
2901 /* raw_val = extract_signed_integer(&raw_val, 8); */
2902 if (raw_val[0] == 0)
2903 printf_filtered ("%10.10s: %8lx ",
2904 REGISTER_NAME (regnum), raw_val[1]);
2905 else
2906 printf_filtered ("%10.10s: %8lx%8.8lx ",
2907 REGISTER_NAME (regnum),
2908 raw_val[0], raw_val[1]);
2909 }
2910 }
2911 printf_unfiltered ("\n");
2912 }
2913
2914 if (fpregs)
2915 for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */
2916 pa_print_fp_reg (i);
2917 }
2918
2919 /************* new function ******************/
2920 static void
2921 pa_strcat_registers (char *raw_regs, int regnum, int fpregs,
2922 struct ui_file *stream)
2923 {
2924 int i, j;
2925 long raw_val[2]; /* Alas, we are compiled so that "long long" is 32 bits */
2926 long long_val;
2927 enum precision_type precision;
2928
2929 precision = unspecified_precision;
2930
2931 for (i = 0; i < 18; i++)
2932 {
2933 for (j = 0; j < 4; j++)
2934 {
2935 /* Q: Why is the value passed through "extract_signed_integer",
2936 while above, in "pa_do_registers_info" it isn't?
2937 A: ? */
2938 pa_register_look_aside (raw_regs, i + (j * 18), &raw_val[0]);
2939
2940 /* Even fancier % formats to prevent leading zeros
2941 and still maintain the output in columns. */
2942 if (!is_pa_2)
2943 {
2944 /* Being big-endian, on this machine the low bits
2945 (the ones we want to look at) are in the second longword. */
2946 long_val = extract_signed_integer (&raw_val[1], 4);
2947 fprintf_filtered (stream, "%8.8s: %8lx ",
2948 REGISTER_NAME (i + (j * 18)), long_val);
2949 }
2950 else
2951 {
2952 /* raw_val = extract_signed_integer(&raw_val, 8); */
2953 if (raw_val[0] == 0)
2954 fprintf_filtered (stream, "%8.8s: %8lx ",
2955 REGISTER_NAME (i + (j * 18)), raw_val[1]);
2956 else
2957 fprintf_filtered (stream, "%8.8s: %8lx%8.8lx ",
2958 REGISTER_NAME (i + (j * 18)), raw_val[0],
2959 raw_val[1]);
2960 }
2961 }
2962 fprintf_unfiltered (stream, "\n");
2963 }
2964
2965 if (fpregs)
2966 for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */
2967 pa_strcat_fp_reg (i, stream, precision);
2968 }
2969
2970 static void
2971 pa_print_fp_reg (int i)
2972 {
2973 char raw_buffer[MAX_REGISTER_SIZE];
2974 char virtual_buffer[MAX_REGISTER_SIZE];
2975
2976 /* Get 32bits of data. */
2977 frame_register_read (deprecated_selected_frame, i, raw_buffer);
2978
2979 /* Put it in the buffer. No conversions are ever necessary. */
2980 memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i));
2981
2982 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
2983 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
2984 fputs_filtered ("(single precision) ", gdb_stdout);
2985
2986 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, gdb_stdout, 0,
2987 1, 0, Val_pretty_default);
2988 printf_filtered ("\n");
2989
2990 /* If "i" is even, then this register can also be a double-precision
2991 FP register. Dump it out as such. */
2992 if ((i % 2) == 0)
2993 {
2994 /* Get the data in raw format for the 2nd half. */
2995 frame_register_read (deprecated_selected_frame, i + 1, raw_buffer);
2996
2997 /* Copy it into the appropriate part of the virtual buffer. */
2998 memcpy (virtual_buffer + REGISTER_RAW_SIZE (i), raw_buffer,
2999 REGISTER_RAW_SIZE (i));
3000
3001 /* Dump it as a double. */
3002 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
3003 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
3004 fputs_filtered ("(double precision) ", gdb_stdout);
3005
3006 val_print (builtin_type_double, virtual_buffer, 0, 0, gdb_stdout, 0,
3007 1, 0, Val_pretty_default);
3008 printf_filtered ("\n");
3009 }
3010 }
3011
3012 /*************** new function ***********************/
3013 static void
3014 pa_strcat_fp_reg (int i, struct ui_file *stream, enum precision_type precision)
3015 {
3016 char raw_buffer[MAX_REGISTER_SIZE];
3017 char virtual_buffer[MAX_REGISTER_SIZE];
3018
3019 fputs_filtered (REGISTER_NAME (i), stream);
3020 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), stream);
3021
3022 /* Get 32bits of data. */
3023 frame_register_read (deprecated_selected_frame, i, raw_buffer);
3024
3025 /* Put it in the buffer. No conversions are ever necessary. */
3026 memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i));
3027
3028 if (precision == double_precision && (i % 2) == 0)
3029 {
3030
3031 char raw_buf[MAX_REGISTER_SIZE];
3032
3033 /* Get the data in raw format for the 2nd half. */
3034 frame_register_read (deprecated_selected_frame, i + 1, raw_buf);
3035
3036 /* Copy it into the appropriate part of the virtual buffer. */
3037 memcpy (virtual_buffer + REGISTER_RAW_SIZE (i), raw_buf, REGISTER_RAW_SIZE (i));
3038
3039 val_print (builtin_type_double, virtual_buffer, 0, 0, stream, 0,
3040 1, 0, Val_pretty_default);
3041
3042 }
3043 else
3044 {
3045 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, stream, 0,
3046 1, 0, Val_pretty_default);
3047 }
3048
3049 }
3050
3051 /* Return one if PC is in the call path of a trampoline, else return zero.
3052
3053 Note we return one for *any* call trampoline (long-call, arg-reloc), not
3054 just shared library trampolines (import, export). */
3055
3056 int
3057 hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name)
3058 {
3059 struct minimal_symbol *minsym;
3060 struct unwind_table_entry *u;
3061 static CORE_ADDR dyncall = 0;
3062 static CORE_ADDR sr4export = 0;
3063
3064 #ifdef GDB_TARGET_IS_HPPA_20W
3065 /* PA64 has a completely different stub/trampoline scheme. Is it
3066 better? Maybe. It's certainly harder to determine with any
3067 certainty that we are in a stub because we can not refer to the
3068 unwinders to help.
3069
3070 The heuristic is simple. Try to lookup the current PC value in th
3071 minimal symbol table. If that fails, then assume we are not in a
3072 stub and return.
3073
3074 Then see if the PC value falls within the section bounds for the
3075 section containing the minimal symbol we found in the first
3076 step. If it does, then assume we are not in a stub and return.
3077
3078 Finally peek at the instructions to see if they look like a stub. */
3079 {
3080 struct minimal_symbol *minsym;
3081 asection *sec;
3082 CORE_ADDR addr;
3083 int insn, i;
3084
3085 minsym = lookup_minimal_symbol_by_pc (pc);
3086 if (! minsym)
3087 return 0;
3088
3089 sec = SYMBOL_BFD_SECTION (minsym);
3090
3091 if (sec->vma <= pc
3092 && sec->vma + sec->_cooked_size < pc)
3093 return 0;
3094
3095 /* We might be in a stub. Peek at the instructions. Stubs are 3
3096 instructions long. */
3097 insn = read_memory_integer (pc, 4);
3098
3099 /* Find out where we think we are within the stub. */
3100 if ((insn & 0xffffc00e) == 0x53610000)
3101 addr = pc;
3102 else if ((insn & 0xffffffff) == 0xe820d000)
3103 addr = pc - 4;
3104 else if ((insn & 0xffffc00e) == 0x537b0000)
3105 addr = pc - 8;
3106 else
3107 return 0;
3108
3109 /* Now verify each insn in the range looks like a stub instruction. */
3110 insn = read_memory_integer (addr, 4);
3111 if ((insn & 0xffffc00e) != 0x53610000)
3112 return 0;
3113
3114 /* Now verify each insn in the range looks like a stub instruction. */
3115 insn = read_memory_integer (addr + 4, 4);
3116 if ((insn & 0xffffffff) != 0xe820d000)
3117 return 0;
3118
3119 /* Now verify each insn in the range looks like a stub instruction. */
3120 insn = read_memory_integer (addr + 8, 4);
3121 if ((insn & 0xffffc00e) != 0x537b0000)
3122 return 0;
3123
3124 /* Looks like a stub. */
3125 return 1;
3126 }
3127 #endif
3128
3129 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
3130 new exec file */
3131
3132 /* First see if PC is in one of the two C-library trampolines. */
3133 if (!dyncall)
3134 {
3135 minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
3136 if (minsym)
3137 dyncall = SYMBOL_VALUE_ADDRESS (minsym);
3138 else
3139 dyncall = -1;
3140 }
3141
3142 if (!sr4export)
3143 {
3144 minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
3145 if (minsym)
3146 sr4export = SYMBOL_VALUE_ADDRESS (minsym);
3147 else
3148 sr4export = -1;
3149 }
3150
3151 if (pc == dyncall || pc == sr4export)
3152 return 1;
3153
3154 minsym = lookup_minimal_symbol_by_pc (pc);
3155 if (minsym && strcmp (DEPRECATED_SYMBOL_NAME (minsym), ".stub") == 0)
3156 return 1;
3157
3158 /* Get the unwind descriptor corresponding to PC, return zero
3159 if no unwind was found. */
3160 u = find_unwind_entry (pc);
3161 if (!u)
3162 return 0;
3163
3164 /* If this isn't a linker stub, then return now. */
3165 if (u->stub_unwind.stub_type == 0)
3166 return 0;
3167
3168 /* By definition a long-branch stub is a call stub. */
3169 if (u->stub_unwind.stub_type == LONG_BRANCH)
3170 return 1;
3171
3172 /* The call and return path execute the same instructions within
3173 an IMPORT stub! So an IMPORT stub is both a call and return
3174 trampoline. */
3175 if (u->stub_unwind.stub_type == IMPORT)
3176 return 1;
3177
3178 /* Parameter relocation stubs always have a call path and may have a
3179 return path. */
3180 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
3181 || u->stub_unwind.stub_type == EXPORT)
3182 {
3183 CORE_ADDR addr;
3184
3185 /* Search forward from the current PC until we hit a branch
3186 or the end of the stub. */
3187 for (addr = pc; addr <= u->region_end; addr += 4)
3188 {
3189 unsigned long insn;
3190
3191 insn = read_memory_integer (addr, 4);
3192
3193 /* Does it look like a bl? If so then it's the call path, if
3194 we find a bv or be first, then we're on the return path. */
3195 if ((insn & 0xfc00e000) == 0xe8000000)
3196 return 1;
3197 else if ((insn & 0xfc00e001) == 0xe800c000
3198 || (insn & 0xfc000000) == 0xe0000000)
3199 return 0;
3200 }
3201
3202 /* Should never happen. */
3203 warning ("Unable to find branch in parameter relocation stub.\n");
3204 return 0;
3205 }
3206
3207 /* Unknown stub type. For now, just return zero. */
3208 return 0;
3209 }
3210
3211 /* Return one if PC is in the return path of a trampoline, else return zero.
3212
3213 Note we return one for *any* call trampoline (long-call, arg-reloc), not
3214 just shared library trampolines (import, export). */
3215
3216 int
3217 hppa_in_solib_return_trampoline (CORE_ADDR pc, char *name)
3218 {
3219 struct unwind_table_entry *u;
3220
3221 /* Get the unwind descriptor corresponding to PC, return zero
3222 if no unwind was found. */
3223 u = find_unwind_entry (pc);
3224 if (!u)
3225 return 0;
3226
3227 /* If this isn't a linker stub or it's just a long branch stub, then
3228 return zero. */
3229 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
3230 return 0;
3231
3232 /* The call and return path execute the same instructions within
3233 an IMPORT stub! So an IMPORT stub is both a call and return
3234 trampoline. */
3235 if (u->stub_unwind.stub_type == IMPORT)
3236 return 1;
3237
3238 /* Parameter relocation stubs always have a call path and may have a
3239 return path. */
3240 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
3241 || u->stub_unwind.stub_type == EXPORT)
3242 {
3243 CORE_ADDR addr;
3244
3245 /* Search forward from the current PC until we hit a branch
3246 or the end of the stub. */
3247 for (addr = pc; addr <= u->region_end; addr += 4)
3248 {
3249 unsigned long insn;
3250
3251 insn = read_memory_integer (addr, 4);
3252
3253 /* Does it look like a bl? If so then it's the call path, if
3254 we find a bv or be first, then we're on the return path. */
3255 if ((insn & 0xfc00e000) == 0xe8000000)
3256 return 0;
3257 else if ((insn & 0xfc00e001) == 0xe800c000
3258 || (insn & 0xfc000000) == 0xe0000000)
3259 return 1;
3260 }
3261
3262 /* Should never happen. */
3263 warning ("Unable to find branch in parameter relocation stub.\n");
3264 return 0;
3265 }
3266
3267 /* Unknown stub type. For now, just return zero. */
3268 return 0;
3269
3270 }
3271
3272 /* Figure out if PC is in a trampoline, and if so find out where
3273 the trampoline will jump to. If not in a trampoline, return zero.
3274
3275 Simple code examination probably is not a good idea since the code
3276 sequences in trampolines can also appear in user code.
3277
3278 We use unwinds and information from the minimal symbol table to
3279 determine when we're in a trampoline. This won't work for ELF
3280 (yet) since it doesn't create stub unwind entries. Whether or
3281 not ELF will create stub unwinds or normal unwinds for linker
3282 stubs is still being debated.
3283
3284 This should handle simple calls through dyncall or sr4export,
3285 long calls, argument relocation stubs, and dyncall/sr4export
3286 calling an argument relocation stub. It even handles some stubs
3287 used in dynamic executables. */
3288
3289 CORE_ADDR
3290 hppa_skip_trampoline_code (CORE_ADDR pc)
3291 {
3292 long orig_pc = pc;
3293 long prev_inst, curr_inst, loc;
3294 static CORE_ADDR dyncall = 0;
3295 static CORE_ADDR dyncall_external = 0;
3296 static CORE_ADDR sr4export = 0;
3297 struct minimal_symbol *msym;
3298 struct unwind_table_entry *u;
3299
3300 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
3301 new exec file */
3302
3303 if (!dyncall)
3304 {
3305 msym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
3306 if (msym)
3307 dyncall = SYMBOL_VALUE_ADDRESS (msym);
3308 else
3309 dyncall = -1;
3310 }
3311
3312 if (!dyncall_external)
3313 {
3314 msym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL);
3315 if (msym)
3316 dyncall_external = SYMBOL_VALUE_ADDRESS (msym);
3317 else
3318 dyncall_external = -1;
3319 }
3320
3321 if (!sr4export)
3322 {
3323 msym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
3324 if (msym)
3325 sr4export = SYMBOL_VALUE_ADDRESS (msym);
3326 else
3327 sr4export = -1;
3328 }
3329
3330 /* Addresses passed to dyncall may *NOT* be the actual address
3331 of the function. So we may have to do something special. */
3332 if (pc == dyncall)
3333 {
3334 pc = (CORE_ADDR) read_register (22);
3335
3336 /* If bit 30 (counting from the left) is on, then pc is the address of
3337 the PLT entry for this function, not the address of the function
3338 itself. Bit 31 has meaning too, but only for MPE. */
3339 if (pc & 0x2)
3340 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
3341 }
3342 if (pc == dyncall_external)
3343 {
3344 pc = (CORE_ADDR) read_register (22);
3345 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
3346 }
3347 else if (pc == sr4export)
3348 pc = (CORE_ADDR) (read_register (22));
3349
3350 /* Get the unwind descriptor corresponding to PC, return zero
3351 if no unwind was found. */
3352 u = find_unwind_entry (pc);
3353 if (!u)
3354 return 0;
3355
3356 /* If this isn't a linker stub, then return now. */
3357 /* elz: attention here! (FIXME) because of a compiler/linker
3358 error, some stubs which should have a non zero stub_unwind.stub_type
3359 have unfortunately a value of zero. So this function would return here
3360 as if we were not in a trampoline. To fix this, we go look at the partial
3361 symbol information, which reports this guy as a stub.
3362 (FIXME): Unfortunately, we are not that lucky: it turns out that the
3363 partial symbol information is also wrong sometimes. This is because
3364 when it is entered (somread.c::som_symtab_read()) it can happen that
3365 if the type of the symbol (from the som) is Entry, and the symbol is
3366 in a shared library, then it can also be a trampoline. This would
3367 be OK, except that I believe the way they decide if we are ina shared library
3368 does not work. SOOOO..., even if we have a regular function w/o trampolines
3369 its minimal symbol can be assigned type mst_solib_trampoline.
3370 Also, if we find that the symbol is a real stub, then we fix the unwind
3371 descriptor, and define the stub type to be EXPORT.
3372 Hopefully this is correct most of the times. */
3373 if (u->stub_unwind.stub_type == 0)
3374 {
3375
3376 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
3377 we can delete all the code which appears between the lines */
3378 /*--------------------------------------------------------------------------*/
3379 msym = lookup_minimal_symbol_by_pc (pc);
3380
3381 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
3382 return orig_pc == pc ? 0 : pc & ~0x3;
3383
3384 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
3385 {
3386 struct objfile *objfile;
3387 struct minimal_symbol *msymbol;
3388 int function_found = 0;
3389
3390 /* go look if there is another minimal symbol with the same name as
3391 this one, but with type mst_text. This would happen if the msym
3392 is an actual trampoline, in which case there would be another
3393 symbol with the same name corresponding to the real function */
3394
3395 ALL_MSYMBOLS (objfile, msymbol)
3396 {
3397 if (MSYMBOL_TYPE (msymbol) == mst_text
3398 && STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym)))
3399 {
3400 function_found = 1;
3401 break;
3402 }
3403 }
3404
3405 if (function_found)
3406 /* the type of msym is correct (mst_solib_trampoline), but
3407 the unwind info is wrong, so set it to the correct value */
3408 u->stub_unwind.stub_type = EXPORT;
3409 else
3410 /* the stub type info in the unwind is correct (this is not a
3411 trampoline), but the msym type information is wrong, it
3412 should be mst_text. So we need to fix the msym, and also
3413 get out of this function */
3414 {
3415 MSYMBOL_TYPE (msym) = mst_text;
3416 return orig_pc == pc ? 0 : pc & ~0x3;
3417 }
3418 }
3419
3420 /*--------------------------------------------------------------------------*/
3421 }
3422
3423 /* It's a stub. Search for a branch and figure out where it goes.
3424 Note we have to handle multi insn branch sequences like ldil;ble.
3425 Most (all?) other branches can be determined by examining the contents
3426 of certain registers and the stack. */
3427
3428 loc = pc;
3429 curr_inst = 0;
3430 prev_inst = 0;
3431 while (1)
3432 {
3433 /* Make sure we haven't walked outside the range of this stub. */
3434 if (u != find_unwind_entry (loc))
3435 {
3436 warning ("Unable to find branch in linker stub");
3437 return orig_pc == pc ? 0 : pc & ~0x3;
3438 }
3439
3440 prev_inst = curr_inst;
3441 curr_inst = read_memory_integer (loc, 4);
3442
3443 /* Does it look like a branch external using %r1? Then it's the
3444 branch from the stub to the actual function. */
3445 if ((curr_inst & 0xffe0e000) == 0xe0202000)
3446 {
3447 /* Yup. See if the previous instruction loaded
3448 a value into %r1. If so compute and return the jump address. */
3449 if ((prev_inst & 0xffe00000) == 0x20200000)
3450 return (extract_21 (prev_inst) + extract_17 (curr_inst)) & ~0x3;
3451 else
3452 {
3453 warning ("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1).");
3454 return orig_pc == pc ? 0 : pc & ~0x3;
3455 }
3456 }
3457
3458 /* Does it look like a be 0(sr0,%r21)? OR
3459 Does it look like a be, n 0(sr0,%r21)? OR
3460 Does it look like a bve (r21)? (this is on PA2.0)
3461 Does it look like a bve, n(r21)? (this is also on PA2.0)
3462 That's the branch from an
3463 import stub to an export stub.
3464
3465 It is impossible to determine the target of the branch via
3466 simple examination of instructions and/or data (consider
3467 that the address in the plabel may be the address of the
3468 bind-on-reference routine in the dynamic loader).
3469
3470 So we have try an alternative approach.
3471
3472 Get the name of the symbol at our current location; it should
3473 be a stub symbol with the same name as the symbol in the
3474 shared library.
3475
3476 Then lookup a minimal symbol with the same name; we should
3477 get the minimal symbol for the target routine in the shared
3478 library as those take precedence of import/export stubs. */
3479 if ((curr_inst == 0xe2a00000) ||
3480 (curr_inst == 0xe2a00002) ||
3481 (curr_inst == 0xeaa0d000) ||
3482 (curr_inst == 0xeaa0d002))
3483 {
3484 struct minimal_symbol *stubsym, *libsym;
3485
3486 stubsym = lookup_minimal_symbol_by_pc (loc);
3487 if (stubsym == NULL)
3488 {
3489 warning ("Unable to find symbol for 0x%lx", loc);
3490 return orig_pc == pc ? 0 : pc & ~0x3;
3491 }
3492
3493 libsym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym), NULL, NULL);
3494 if (libsym == NULL)
3495 {
3496 warning ("Unable to find library symbol for %s\n",
3497 DEPRECATED_SYMBOL_NAME (stubsym));
3498 return orig_pc == pc ? 0 : pc & ~0x3;
3499 }
3500
3501 return SYMBOL_VALUE (libsym);
3502 }
3503
3504 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
3505 branch from the stub to the actual function. */
3506 /*elz */
3507 else if ((curr_inst & 0xffe0e000) == 0xe8400000
3508 || (curr_inst & 0xffe0e000) == 0xe8000000
3509 || (curr_inst & 0xffe0e000) == 0xe800A000)
3510 return (loc + extract_17 (curr_inst) + 8) & ~0x3;
3511
3512 /* Does it look like bv (rp)? Note this depends on the
3513 current stack pointer being the same as the stack
3514 pointer in the stub itself! This is a branch on from the
3515 stub back to the original caller. */
3516 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
3517 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
3518 {
3519 /* Yup. See if the previous instruction loaded
3520 rp from sp - 8. */
3521 if (prev_inst == 0x4bc23ff1)
3522 return (read_memory_integer
3523 (read_register (SP_REGNUM) - 8, 4)) & ~0x3;
3524 else
3525 {
3526 warning ("Unable to find restore of %%rp before bv (%%rp).");
3527 return orig_pc == pc ? 0 : pc & ~0x3;
3528 }
3529 }
3530
3531 /* elz: added this case to capture the new instruction
3532 at the end of the return part of an export stub used by
3533 the PA2.0: BVE, n (rp) */
3534 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
3535 {
3536 return (read_memory_integer
3537 (read_register (SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
3538 }
3539
3540 /* What about be,n 0(sr0,%rp)? It's just another way we return to
3541 the original caller from the stub. Used in dynamic executables. */
3542 else if (curr_inst == 0xe0400002)
3543 {
3544 /* The value we jump to is sitting in sp - 24. But that's
3545 loaded several instructions before the be instruction.
3546 I guess we could check for the previous instruction being
3547 mtsp %r1,%sr0 if we want to do sanity checking. */
3548 return (read_memory_integer
3549 (read_register (SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
3550 }
3551
3552 /* Haven't found the branch yet, but we're still in the stub.
3553 Keep looking. */
3554 loc += 4;
3555 }
3556 }
3557
3558
3559 /* For the given instruction (INST), return any adjustment it makes
3560 to the stack pointer or zero for no adjustment.
3561
3562 This only handles instructions commonly found in prologues. */
3563
3564 static int
3565 prologue_inst_adjust_sp (unsigned long inst)
3566 {
3567 /* This must persist across calls. */
3568 static int save_high21;
3569
3570 /* The most common way to perform a stack adjustment ldo X(sp),sp */
3571 if ((inst & 0xffffc000) == 0x37de0000)
3572 return extract_14 (inst);
3573
3574 /* stwm X,D(sp) */
3575 if ((inst & 0xffe00000) == 0x6fc00000)
3576 return extract_14 (inst);
3577
3578 /* std,ma X,D(sp) */
3579 if ((inst & 0xffe00008) == 0x73c00008)
3580 return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
3581
3582 /* addil high21,%r1; ldo low11,(%r1),%r30)
3583 save high bits in save_high21 for later use. */
3584 if ((inst & 0xffe00000) == 0x28200000)
3585 {
3586 save_high21 = extract_21 (inst);
3587 return 0;
3588 }
3589
3590 if ((inst & 0xffff0000) == 0x343e0000)
3591 return save_high21 + extract_14 (inst);
3592
3593 /* fstws as used by the HP compilers. */
3594 if ((inst & 0xffffffe0) == 0x2fd01220)
3595 return extract_5_load (inst);
3596
3597 /* No adjustment. */
3598 return 0;
3599 }
3600
3601 /* Return nonzero if INST is a branch of some kind, else return zero. */
3602
3603 static int
3604 is_branch (unsigned long inst)
3605 {
3606 switch (inst >> 26)
3607 {
3608 case 0x20:
3609 case 0x21:
3610 case 0x22:
3611 case 0x23:
3612 case 0x27:
3613 case 0x28:
3614 case 0x29:
3615 case 0x2a:
3616 case 0x2b:
3617 case 0x2f:
3618 case 0x30:
3619 case 0x31:
3620 case 0x32:
3621 case 0x33:
3622 case 0x38:
3623 case 0x39:
3624 case 0x3a:
3625 case 0x3b:
3626 return 1;
3627
3628 default:
3629 return 0;
3630 }
3631 }
3632
3633 /* Return the register number for a GR which is saved by INST or
3634 zero it INST does not save a GR. */
3635
3636 static int
3637 inst_saves_gr (unsigned long inst)
3638 {
3639 /* Does it look like a stw? */
3640 if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
3641 || (inst >> 26) == 0x1f
3642 || ((inst >> 26) == 0x1f
3643 && ((inst >> 6) == 0xa)))
3644 return extract_5R_store (inst);
3645
3646 /* Does it look like a std? */
3647 if ((inst >> 26) == 0x1c
3648 || ((inst >> 26) == 0x03
3649 && ((inst >> 6) & 0xf) == 0xb))
3650 return extract_5R_store (inst);
3651
3652 /* Does it look like a stwm? GCC & HPC may use this in prologues. */
3653 if ((inst >> 26) == 0x1b)
3654 return extract_5R_store (inst);
3655
3656 /* Does it look like sth or stb? HPC versions 9.0 and later use these
3657 too. */
3658 if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
3659 || ((inst >> 26) == 0x3
3660 && (((inst >> 6) & 0xf) == 0x8
3661 || (inst >> 6) & 0xf) == 0x9))
3662 return extract_5R_store (inst);
3663
3664 return 0;
3665 }
3666
3667 /* Return the register number for a FR which is saved by INST or
3668 zero it INST does not save a FR.
3669
3670 Note we only care about full 64bit register stores (that's the only
3671 kind of stores the prologue will use).
3672
3673 FIXME: What about argument stores with the HP compiler in ANSI mode? */
3674
3675 static int
3676 inst_saves_fr (unsigned long inst)
3677 {
3678 /* is this an FSTD ? */
3679 if ((inst & 0xfc00dfc0) == 0x2c001200)
3680 return extract_5r_store (inst);
3681 if ((inst & 0xfc000002) == 0x70000002)
3682 return extract_5R_store (inst);
3683 /* is this an FSTW ? */
3684 if ((inst & 0xfc00df80) == 0x24001200)
3685 return extract_5r_store (inst);
3686 if ((inst & 0xfc000002) == 0x7c000000)
3687 return extract_5R_store (inst);
3688 return 0;
3689 }
3690
3691 /* Advance PC across any function entry prologue instructions
3692 to reach some "real" code.
3693
3694 Use information in the unwind table to determine what exactly should
3695 be in the prologue. */
3696
3697
3698 CORE_ADDR
3699 skip_prologue_hard_way (CORE_ADDR pc)
3700 {
3701 char buf[4];
3702 CORE_ADDR orig_pc = pc;
3703 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
3704 unsigned long args_stored, status, i, restart_gr, restart_fr;
3705 struct unwind_table_entry *u;
3706
3707 restart_gr = 0;
3708 restart_fr = 0;
3709
3710 restart:
3711 u = find_unwind_entry (pc);
3712 if (!u)
3713 return pc;
3714
3715 /* If we are not at the beginning of a function, then return now. */
3716 if ((pc & ~0x3) != u->region_start)
3717 return pc;
3718
3719 /* This is how much of a frame adjustment we need to account for. */
3720 stack_remaining = u->Total_frame_size << 3;
3721
3722 /* Magic register saves we want to know about. */
3723 save_rp = u->Save_RP;
3724 save_sp = u->Save_SP;
3725
3726 /* An indication that args may be stored into the stack. Unfortunately
3727 the HPUX compilers tend to set this in cases where no args were
3728 stored too!. */
3729 args_stored = 1;
3730
3731 /* Turn the Entry_GR field into a bitmask. */
3732 save_gr = 0;
3733 for (i = 3; i < u->Entry_GR + 3; i++)
3734 {
3735 /* Frame pointer gets saved into a special location. */
3736 if (u->Save_SP && i == DEPRECATED_FP_REGNUM)
3737 continue;
3738
3739 save_gr |= (1 << i);
3740 }
3741 save_gr &= ~restart_gr;
3742
3743 /* Turn the Entry_FR field into a bitmask too. */
3744 save_fr = 0;
3745 for (i = 12; i < u->Entry_FR + 12; i++)
3746 save_fr |= (1 << i);
3747 save_fr &= ~restart_fr;
3748
3749 /* Loop until we find everything of interest or hit a branch.
3750
3751 For unoptimized GCC code and for any HP CC code this will never ever
3752 examine any user instructions.
3753
3754 For optimzied GCC code we're faced with problems. GCC will schedule
3755 its prologue and make prologue instructions available for delay slot
3756 filling. The end result is user code gets mixed in with the prologue
3757 and a prologue instruction may be in the delay slot of the first branch
3758 or call.
3759
3760 Some unexpected things are expected with debugging optimized code, so
3761 we allow this routine to walk past user instructions in optimized
3762 GCC code. */
3763 while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
3764 || args_stored)
3765 {
3766 unsigned int reg_num;
3767 unsigned long old_stack_remaining, old_save_gr, old_save_fr;
3768 unsigned long old_save_rp, old_save_sp, next_inst;
3769
3770 /* Save copies of all the triggers so we can compare them later
3771 (only for HPC). */
3772 old_save_gr = save_gr;
3773 old_save_fr = save_fr;
3774 old_save_rp = save_rp;
3775 old_save_sp = save_sp;
3776 old_stack_remaining = stack_remaining;
3777
3778 status = target_read_memory (pc, buf, 4);
3779 inst = extract_unsigned_integer (buf, 4);
3780
3781 /* Yow! */
3782 if (status != 0)
3783 return pc;
3784
3785 /* Note the interesting effects of this instruction. */
3786 stack_remaining -= prologue_inst_adjust_sp (inst);
3787
3788 /* There are limited ways to store the return pointer into the
3789 stack. */
3790 if (inst == 0x6bc23fd9 || inst == 0x0fc212c1)
3791 save_rp = 0;
3792
3793 /* These are the only ways we save SP into the stack. At this time
3794 the HP compilers never bother to save SP into the stack. */
3795 if ((inst & 0xffffc000) == 0x6fc10000
3796 || (inst & 0xffffc00c) == 0x73c10008)
3797 save_sp = 0;
3798
3799 /* Are we loading some register with an offset from the argument
3800 pointer? */
3801 if ((inst & 0xffe00000) == 0x37a00000
3802 || (inst & 0xffffffe0) == 0x081d0240)
3803 {
3804 pc += 4;
3805 continue;
3806 }
3807
3808 /* Account for general and floating-point register saves. */
3809 reg_num = inst_saves_gr (inst);
3810 save_gr &= ~(1 << reg_num);
3811
3812 /* Ugh. Also account for argument stores into the stack.
3813 Unfortunately args_stored only tells us that some arguments
3814 where stored into the stack. Not how many or what kind!
3815
3816 This is a kludge as on the HP compiler sets this bit and it
3817 never does prologue scheduling. So once we see one, skip past
3818 all of them. We have similar code for the fp arg stores below.
3819
3820 FIXME. Can still die if we have a mix of GR and FR argument
3821 stores! */
3822 if (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
3823 {
3824 while (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
3825 {
3826 pc += 4;
3827 status = target_read_memory (pc, buf, 4);
3828 inst = extract_unsigned_integer (buf, 4);
3829 if (status != 0)
3830 return pc;
3831 reg_num = inst_saves_gr (inst);
3832 }
3833 args_stored = 0;
3834 continue;
3835 }
3836
3837 reg_num = inst_saves_fr (inst);
3838 save_fr &= ~(1 << reg_num);
3839
3840 status = target_read_memory (pc + 4, buf, 4);
3841 next_inst = extract_unsigned_integer (buf, 4);
3842
3843 /* Yow! */
3844 if (status != 0)
3845 return pc;
3846
3847 /* We've got to be read to handle the ldo before the fp register
3848 save. */
3849 if ((inst & 0xfc000000) == 0x34000000
3850 && inst_saves_fr (next_inst) >= 4
3851 && inst_saves_fr (next_inst) <= (TARGET_PTR_BIT == 64 ? 11 : 7))
3852 {
3853 /* So we drop into the code below in a reasonable state. */
3854 reg_num = inst_saves_fr (next_inst);
3855 pc -= 4;
3856 }
3857
3858 /* Ugh. Also account for argument stores into the stack.
3859 This is a kludge as on the HP compiler sets this bit and it
3860 never does prologue scheduling. So once we see one, skip past
3861 all of them. */
3862 if (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
3863 {
3864 while (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
3865 {
3866 pc += 8;
3867 status = target_read_memory (pc, buf, 4);
3868 inst = extract_unsigned_integer (buf, 4);
3869 if (status != 0)
3870 return pc;
3871 if ((inst & 0xfc000000) != 0x34000000)
3872 break;
3873 status = target_read_memory (pc + 4, buf, 4);
3874 next_inst = extract_unsigned_integer (buf, 4);
3875 if (status != 0)
3876 return pc;
3877 reg_num = inst_saves_fr (next_inst);
3878 }
3879 args_stored = 0;
3880 continue;
3881 }
3882
3883 /* Quit if we hit any kind of branch. This can happen if a prologue
3884 instruction is in the delay slot of the first call/branch. */
3885 if (is_branch (inst))
3886 break;
3887
3888 /* What a crock. The HP compilers set args_stored even if no
3889 arguments were stored into the stack (boo hiss). This could
3890 cause this code to then skip a bunch of user insns (up to the
3891 first branch).
3892
3893 To combat this we try to identify when args_stored was bogusly
3894 set and clear it. We only do this when args_stored is nonzero,
3895 all other resources are accounted for, and nothing changed on
3896 this pass. */
3897 if (args_stored
3898 && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
3899 && old_save_gr == save_gr && old_save_fr == save_fr
3900 && old_save_rp == save_rp && old_save_sp == save_sp
3901 && old_stack_remaining == stack_remaining)
3902 break;
3903
3904 /* Bump the PC. */
3905 pc += 4;
3906 }
3907
3908 /* We've got a tenative location for the end of the prologue. However
3909 because of limitations in the unwind descriptor mechanism we may
3910 have went too far into user code looking for the save of a register
3911 that does not exist. So, if there registers we expected to be saved
3912 but never were, mask them out and restart.
3913
3914 This should only happen in optimized code, and should be very rare. */
3915 if (save_gr || (save_fr && !(restart_fr || restart_gr)))
3916 {
3917 pc = orig_pc;
3918 restart_gr = save_gr;
3919 restart_fr = save_fr;
3920 goto restart;
3921 }
3922
3923 return pc;
3924 }
3925
3926
3927 /* Return the address of the PC after the last prologue instruction if
3928 we can determine it from the debug symbols. Else return zero. */
3929
3930 static CORE_ADDR
3931 after_prologue (CORE_ADDR pc)
3932 {
3933 struct symtab_and_line sal;
3934 CORE_ADDR func_addr, func_end;
3935 struct symbol *f;
3936
3937 /* If we can not find the symbol in the partial symbol table, then
3938 there is no hope we can determine the function's start address
3939 with this code. */
3940 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3941 return 0;
3942
3943 /* Get the line associated with FUNC_ADDR. */
3944 sal = find_pc_line (func_addr, 0);
3945
3946 /* There are only two cases to consider. First, the end of the source line
3947 is within the function bounds. In that case we return the end of the
3948 source line. Second is the end of the source line extends beyond the
3949 bounds of the current function. We need to use the slow code to
3950 examine instructions in that case.
3951
3952 Anything else is simply a bug elsewhere. Fixing it here is absolutely
3953 the wrong thing to do. In fact, it should be entirely possible for this
3954 function to always return zero since the slow instruction scanning code
3955 is supposed to *always* work. If it does not, then it is a bug. */
3956 if (sal.end < func_end)
3957 return sal.end;
3958 else
3959 return 0;
3960 }
3961
3962 /* To skip prologues, I use this predicate. Returns either PC itself
3963 if the code at PC does not look like a function prologue; otherwise
3964 returns an address that (if we're lucky) follows the prologue. If
3965 LENIENT, then we must skip everything which is involved in setting
3966 up the frame (it's OK to skip more, just so long as we don't skip
3967 anything which might clobber the registers which are being saved.
3968 Currently we must not skip more on the alpha, but we might the lenient
3969 stuff some day. */
3970
3971 CORE_ADDR
3972 hppa_skip_prologue (CORE_ADDR pc)
3973 {
3974 unsigned long inst;
3975 int offset;
3976 CORE_ADDR post_prologue_pc;
3977 char buf[4];
3978
3979 /* See if we can determine the end of the prologue via the symbol table.
3980 If so, then return either PC, or the PC after the prologue, whichever
3981 is greater. */
3982
3983 post_prologue_pc = after_prologue (pc);
3984
3985 /* If after_prologue returned a useful address, then use it. Else
3986 fall back on the instruction skipping code.
3987
3988 Some folks have claimed this causes problems because the breakpoint
3989 may be the first instruction of the prologue. If that happens, then
3990 the instruction skipping code has a bug that needs to be fixed. */
3991 if (post_prologue_pc != 0)
3992 return max (pc, post_prologue_pc);
3993 else
3994 return (skip_prologue_hard_way (pc));
3995 }
3996
3997 /* Put here the code to store, into the SAVED_REGS, the addresses of
3998 the saved registers of frame described by FRAME_INFO. This
3999 includes special registers such as pc and fp saved in special ways
4000 in the stack frame. sp is even more special: the address we return
4001 for it IS the sp for the next frame. */
4002
4003 void
4004 hppa_frame_find_saved_regs (struct frame_info *frame_info,
4005 CORE_ADDR frame_saved_regs[])
4006 {
4007 CORE_ADDR pc;
4008 struct unwind_table_entry *u;
4009 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
4010 int status, i, reg;
4011 char buf[4];
4012 int fp_loc = -1;
4013 int final_iteration;
4014
4015 /* Zero out everything. */
4016 memset (frame_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
4017
4018 /* Call dummy frames always look the same, so there's no need to
4019 examine the dummy code to determine locations of saved registers;
4020 instead, let find_dummy_frame_regs fill in the correct offsets
4021 for the saved registers. */
4022 if ((get_frame_pc (frame_info) >= get_frame_base (frame_info)
4023 && (get_frame_pc (frame_info)
4024 <= (get_frame_base (frame_info)
4025 /* A call dummy is sized in words, but it is actually a
4026 series of instructions. Account for that scaling
4027 factor. */
4028 + ((DEPRECATED_REGISTER_SIZE / INSTRUCTION_SIZE)
4029 * DEPRECATED_CALL_DUMMY_LENGTH)
4030 /* Similarly we have to account for 64bit wide register
4031 saves. */
4032 + (32 * DEPRECATED_REGISTER_SIZE)
4033 /* We always consider FP regs 8 bytes long. */
4034 + (NUM_REGS - FP0_REGNUM) * 8
4035 /* Similarly we have to account for 64bit wide register
4036 saves. */
4037 + (6 * DEPRECATED_REGISTER_SIZE)))))
4038 find_dummy_frame_regs (frame_info, frame_saved_regs);
4039
4040 /* Interrupt handlers are special too. They lay out the register
4041 state in the exact same order as the register numbers in GDB. */
4042 if (pc_in_interrupt_handler (get_frame_pc (frame_info)))
4043 {
4044 for (i = 0; i < NUM_REGS; i++)
4045 {
4046 /* SP is a little special. */
4047 if (i == SP_REGNUM)
4048 frame_saved_regs[SP_REGNUM]
4049 = read_memory_integer (get_frame_base (frame_info) + SP_REGNUM * 4,
4050 TARGET_PTR_BIT / 8);
4051 else
4052 frame_saved_regs[i] = get_frame_base (frame_info) + i * 4;
4053 }
4054 return;
4055 }
4056
4057 #ifdef FRAME_FIND_SAVED_REGS_IN_SIGTRAMP
4058 /* Handle signal handler callers. */
4059 if ((get_frame_type (frame_info) == SIGTRAMP_FRAME))
4060 {
4061 FRAME_FIND_SAVED_REGS_IN_SIGTRAMP (frame_info, frame_saved_regs);
4062 return;
4063 }
4064 #endif
4065
4066 /* Get the starting address of the function referred to by the PC
4067 saved in frame. */
4068 pc = get_frame_func (frame_info);
4069
4070 /* Yow! */
4071 u = find_unwind_entry (pc);
4072 if (!u)
4073 return;
4074
4075 /* This is how much of a frame adjustment we need to account for. */
4076 stack_remaining = u->Total_frame_size << 3;
4077
4078 /* Magic register saves we want to know about. */
4079 save_rp = u->Save_RP;
4080 save_sp = u->Save_SP;
4081
4082 /* Turn the Entry_GR field into a bitmask. */
4083 save_gr = 0;
4084 for (i = 3; i < u->Entry_GR + 3; i++)
4085 {
4086 /* Frame pointer gets saved into a special location. */
4087 if (u->Save_SP && i == DEPRECATED_FP_REGNUM)
4088 continue;
4089
4090 save_gr |= (1 << i);
4091 }
4092
4093 /* Turn the Entry_FR field into a bitmask too. */
4094 save_fr = 0;
4095 for (i = 12; i < u->Entry_FR + 12; i++)
4096 save_fr |= (1 << i);
4097
4098 /* The frame always represents the value of %sp at entry to the
4099 current function (and is thus equivalent to the "saved" stack
4100 pointer. */
4101 frame_saved_regs[SP_REGNUM] = get_frame_base (frame_info);
4102
4103 /* Loop until we find everything of interest or hit a branch.
4104
4105 For unoptimized GCC code and for any HP CC code this will never ever
4106 examine any user instructions.
4107
4108 For optimized GCC code we're faced with problems. GCC will schedule
4109 its prologue and make prologue instructions available for delay slot
4110 filling. The end result is user code gets mixed in with the prologue
4111 and a prologue instruction may be in the delay slot of the first branch
4112 or call.
4113
4114 Some unexpected things are expected with debugging optimized code, so
4115 we allow this routine to walk past user instructions in optimized
4116 GCC code. */
4117 final_iteration = 0;
4118 while ((save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
4119 && pc <= get_frame_pc (frame_info))
4120 {
4121 status = target_read_memory (pc, buf, 4);
4122 inst = extract_unsigned_integer (buf, 4);
4123
4124 /* Yow! */
4125 if (status != 0)
4126 return;
4127
4128 /* Note the interesting effects of this instruction. */
4129 stack_remaining -= prologue_inst_adjust_sp (inst);
4130
4131 /* There are limited ways to store the return pointer into the
4132 stack. */
4133 if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
4134 {
4135 save_rp = 0;
4136 frame_saved_regs[RP_REGNUM] = get_frame_base (frame_info) - 20;
4137 }
4138 else if (inst == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
4139 {
4140 save_rp = 0;
4141 frame_saved_regs[RP_REGNUM] = get_frame_base (frame_info) - 16;
4142 }
4143
4144 /* Note if we saved SP into the stack. This also happens to indicate
4145 the location of the saved frame pointer. */
4146 if ( (inst & 0xffffc000) == 0x6fc10000 /* stw,ma r1,N(sr0,sp) */
4147 || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
4148 {
4149 frame_saved_regs[DEPRECATED_FP_REGNUM] = get_frame_base (frame_info);
4150 save_sp = 0;
4151 }
4152
4153 /* Account for general and floating-point register saves. */
4154 reg = inst_saves_gr (inst);
4155 if (reg >= 3 && reg <= 18
4156 && (!u->Save_SP || reg != DEPRECATED_FP_REGNUM))
4157 {
4158 save_gr &= ~(1 << reg);
4159
4160 /* stwm with a positive displacement is a *post modify*. */
4161 if ((inst >> 26) == 0x1b
4162 && extract_14 (inst) >= 0)
4163 frame_saved_regs[reg] = get_frame_base (frame_info);
4164 /* A std has explicit post_modify forms. */
4165 else if ((inst & 0xfc00000c0) == 0x70000008)
4166 frame_saved_regs[reg] = get_frame_base (frame_info);
4167 else
4168 {
4169 CORE_ADDR offset;
4170
4171 if ((inst >> 26) == 0x1c)
4172 offset = (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
4173 else if ((inst >> 26) == 0x03)
4174 offset = low_sign_extend (inst & 0x1f, 5);
4175 else
4176 offset = extract_14 (inst);
4177
4178 /* Handle code with and without frame pointers. */
4179 if (u->Save_SP)
4180 frame_saved_regs[reg]
4181 = get_frame_base (frame_info) + offset;
4182 else
4183 frame_saved_regs[reg]
4184 = (get_frame_base (frame_info) + (u->Total_frame_size << 3)
4185 + offset);
4186 }
4187 }
4188
4189
4190 /* GCC handles callee saved FP regs a little differently.
4191
4192 It emits an instruction to put the value of the start of
4193 the FP store area into %r1. It then uses fstds,ma with
4194 a basereg of %r1 for the stores.
4195
4196 HP CC emits them at the current stack pointer modifying
4197 the stack pointer as it stores each register. */
4198
4199 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
4200 if ((inst & 0xffffc000) == 0x34610000
4201 || (inst & 0xffffc000) == 0x37c10000)
4202 fp_loc = extract_14 (inst);
4203
4204 reg = inst_saves_fr (inst);
4205 if (reg >= 12 && reg <= 21)
4206 {
4207 /* Note +4 braindamage below is necessary because the FP status
4208 registers are internally 8 registers rather than the expected
4209 4 registers. */
4210 save_fr &= ~(1 << reg);
4211 if (fp_loc == -1)
4212 {
4213 /* 1st HP CC FP register store. After this instruction
4214 we've set enough state that the GCC and HPCC code are
4215 both handled in the same manner. */
4216 frame_saved_regs[reg + FP4_REGNUM + 4] = get_frame_base (frame_info);
4217 fp_loc = 8;
4218 }
4219 else
4220 {
4221 frame_saved_regs[reg + FP0_REGNUM + 4]
4222 = get_frame_base (frame_info) + fp_loc;
4223 fp_loc += 8;
4224 }
4225 }
4226
4227 /* Quit if we hit any kind of branch the previous iteration. */
4228 if (final_iteration)
4229 break;
4230
4231 /* We want to look precisely one instruction beyond the branch
4232 if we have not found everything yet. */
4233 if (is_branch (inst))
4234 final_iteration = 1;
4235
4236 /* Bump the PC. */
4237 pc += 4;
4238 }
4239 }
4240
4241 /* XXX - deprecated. This is a compatibility function for targets
4242 that do not yet implement DEPRECATED_FRAME_INIT_SAVED_REGS. */
4243 /* Find the addresses in which registers are saved in FRAME. */
4244
4245 void
4246 hppa_frame_init_saved_regs (struct frame_info *frame)
4247 {
4248 if (get_frame_saved_regs (frame) == NULL)
4249 frame_saved_regs_zalloc (frame);
4250 hppa_frame_find_saved_regs (frame, get_frame_saved_regs (frame));
4251 }
4252
4253 /* Exception handling support for the HP-UX ANSI C++ compiler.
4254 The compiler (aCC) provides a callback for exception events;
4255 GDB can set a breakpoint on this callback and find out what
4256 exception event has occurred. */
4257
4258 /* The name of the hook to be set to point to the callback function */
4259 static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook";
4260 /* The name of the function to be used to set the hook value */
4261 static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value";
4262 /* The name of the callback function in end.o */
4263 static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback";
4264 /* Name of function in end.o on which a break is set (called by above) */
4265 static char HP_ACC_EH_break[] = "__d_eh_break";
4266 /* Name of flag (in end.o) that enables catching throws */
4267 static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw";
4268 /* Name of flag (in end.o) that enables catching catching */
4269 static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch";
4270 /* The enum used by aCC */
4271 typedef enum
4272 {
4273 __EH_NOTIFY_THROW,
4274 __EH_NOTIFY_CATCH
4275 }
4276 __eh_notification;
4277
4278 /* Is exception-handling support available with this executable? */
4279 static int hp_cxx_exception_support = 0;
4280 /* Has the initialize function been run? */
4281 int hp_cxx_exception_support_initialized = 0;
4282 /* Similar to above, but imported from breakpoint.c -- non-target-specific */
4283 extern int exception_support_initialized;
4284 /* Address of __eh_notify_hook */
4285 static CORE_ADDR eh_notify_hook_addr = 0;
4286 /* Address of __d_eh_notify_callback */
4287 static CORE_ADDR eh_notify_callback_addr = 0;
4288 /* Address of __d_eh_break */
4289 static CORE_ADDR eh_break_addr = 0;
4290 /* Address of __d_eh_catch_catch */
4291 static CORE_ADDR eh_catch_catch_addr = 0;
4292 /* Address of __d_eh_catch_throw */
4293 static CORE_ADDR eh_catch_throw_addr = 0;
4294 /* Sal for __d_eh_break */
4295 static struct symtab_and_line *break_callback_sal = 0;
4296
4297 /* Code in end.c expects __d_pid to be set in the inferior,
4298 otherwise __d_eh_notify_callback doesn't bother to call
4299 __d_eh_break! So we poke the pid into this symbol
4300 ourselves.
4301 0 => success
4302 1 => failure */
4303 int
4304 setup_d_pid_in_inferior (void)
4305 {
4306 CORE_ADDR anaddr;
4307 struct minimal_symbol *msymbol;
4308 char buf[4]; /* FIXME 32x64? */
4309
4310 /* Slam the pid of the process into __d_pid; failing is only a warning! */
4311 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
4312 if (msymbol == NULL)
4313 {
4314 warning ("Unable to find __d_pid symbol in object file.");
4315 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
4316 return 1;
4317 }
4318
4319 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
4320 store_unsigned_integer (buf, 4, PIDGET (inferior_ptid)); /* FIXME 32x64? */
4321 if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */
4322 {
4323 warning ("Unable to write __d_pid");
4324 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
4325 return 1;
4326 }
4327 return 0;
4328 }
4329
4330 /* Initialize exception catchpoint support by looking for the
4331 necessary hooks/callbacks in end.o, etc., and set the hook value to
4332 point to the required debug function
4333
4334 Return 0 => failure
4335 1 => success */
4336
4337 static int
4338 initialize_hp_cxx_exception_support (void)
4339 {
4340 struct symtabs_and_lines sals;
4341 struct cleanup *old_chain;
4342 struct cleanup *canonical_strings_chain = NULL;
4343 int i;
4344 char *addr_start;
4345 char *addr_end = NULL;
4346 char **canonical = (char **) NULL;
4347 int thread = -1;
4348 struct symbol *sym = NULL;
4349 struct minimal_symbol *msym = NULL;
4350 struct objfile *objfile;
4351 asection *shlib_info;
4352
4353 /* Detect and disallow recursion. On HP-UX with aCC, infinite
4354 recursion is a possibility because finding the hook for exception
4355 callbacks involves making a call in the inferior, which means
4356 re-inserting breakpoints which can re-invoke this code */
4357
4358 static int recurse = 0;
4359 if (recurse > 0)
4360 {
4361 hp_cxx_exception_support_initialized = 0;
4362 exception_support_initialized = 0;
4363 return 0;
4364 }
4365
4366 hp_cxx_exception_support = 0;
4367
4368 /* First check if we have seen any HP compiled objects; if not,
4369 it is very unlikely that HP's idiosyncratic callback mechanism
4370 for exception handling debug support will be available!
4371 This will percolate back up to breakpoint.c, where our callers
4372 will decide to try the g++ exception-handling support instead. */
4373 if (!hp_som_som_object_present)
4374 return 0;
4375
4376 /* We have a SOM executable with SOM debug info; find the hooks */
4377
4378 /* First look for the notify hook provided by aCC runtime libs */
4379 /* If we find this symbol, we conclude that the executable must
4380 have HP aCC exception support built in. If this symbol is not
4381 found, even though we're a HP SOM-SOM file, we may have been
4382 built with some other compiler (not aCC). This results percolates
4383 back up to our callers in breakpoint.c which can decide to
4384 try the g++ style of exception support instead.
4385 If this symbol is found but the other symbols we require are
4386 not found, there is something weird going on, and g++ support
4387 should *not* be tried as an alternative.
4388
4389 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
4390 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
4391
4392 /* libCsup has this hook; it'll usually be non-debuggable */
4393 msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL);
4394 if (msym)
4395 {
4396 eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym);
4397 hp_cxx_exception_support = 1;
4398 }
4399 else
4400 {
4401 warning ("Unable to find exception callback hook (%s).", HP_ACC_EH_notify_hook);
4402 warning ("Executable may not have been compiled debuggable with HP aCC.");
4403 warning ("GDB will be unable to intercept exception events.");
4404 eh_notify_hook_addr = 0;
4405 hp_cxx_exception_support = 0;
4406 return 0;
4407 }
4408
4409 /* Next look for the notify callback routine in end.o */
4410 /* This is always available in the SOM symbol dictionary if end.o is linked in */
4411 msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL);
4412 if (msym)
4413 {
4414 eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym);
4415 hp_cxx_exception_support = 1;
4416 }
4417 else
4418 {
4419 warning ("Unable to find exception callback routine (%s).", HP_ACC_EH_notify_callback);
4420 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
4421 warning ("GDB will be unable to intercept exception events.");
4422 eh_notify_callback_addr = 0;
4423 return 0;
4424 }
4425
4426 #ifndef GDB_TARGET_IS_HPPA_20W
4427 /* Check whether the executable is dynamically linked or archive bound */
4428 /* With an archive-bound executable we can use the raw addresses we find
4429 for the callback function, etc. without modification. For an executable
4430 with shared libraries, we have to do more work to find the plabel, which
4431 can be the target of a call through $$dyncall from the aCC runtime support
4432 library (libCsup) which is linked shared by default by aCC. */
4433 /* This test below was copied from somsolib.c/somread.c. It may not be a very
4434 reliable one to test that an executable is linked shared. pai/1997-07-18 */
4435 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
4436 if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0))
4437 {
4438 /* The minsym we have has the local code address, but that's not the
4439 plabel that can be used by an inter-load-module call. */
4440 /* Find solib handle for main image (which has end.o), and use that
4441 and the min sym as arguments to __d_shl_get() (which does the equivalent
4442 of shl_findsym()) to find the plabel. */
4443
4444 args_for_find_stub args;
4445 static char message[] = "Error while finding exception callback hook:\n";
4446
4447 args.solib_handle = som_solib_get_solib_by_pc (eh_notify_callback_addr);
4448 args.msym = msym;
4449 args.return_val = 0;
4450
4451 recurse++;
4452 catch_errors (cover_find_stub_with_shl_get, &args, message,
4453 RETURN_MASK_ALL);
4454 eh_notify_callback_addr = args.return_val;
4455 recurse--;
4456
4457 exception_catchpoints_are_fragile = 1;
4458
4459 if (!eh_notify_callback_addr)
4460 {
4461 /* We can get here either if there is no plabel in the export list
4462 for the main image, or if something strange happened (?) */
4463 warning ("Couldn't find a plabel (indirect function label) for the exception callback.");
4464 warning ("GDB will not be able to intercept exception events.");
4465 return 0;
4466 }
4467 }
4468 else
4469 exception_catchpoints_are_fragile = 0;
4470 #endif
4471
4472 /* Now, look for the breakpointable routine in end.o */
4473 /* This should also be available in the SOM symbol dict. if end.o linked in */
4474 msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL);
4475 if (msym)
4476 {
4477 eh_break_addr = SYMBOL_VALUE_ADDRESS (msym);
4478 hp_cxx_exception_support = 1;
4479 }
4480 else
4481 {
4482 warning ("Unable to find exception callback routine to set breakpoint (%s).", HP_ACC_EH_break);
4483 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4484 warning ("GDB will be unable to intercept exception events.");
4485 eh_break_addr = 0;
4486 return 0;
4487 }
4488
4489 /* Next look for the catch enable flag provided in end.o */
4490 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
4491 VAR_DOMAIN, 0, (struct symtab **) NULL);
4492 if (sym) /* sometimes present in debug info */
4493 {
4494 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym);
4495 hp_cxx_exception_support = 1;
4496 }
4497 else
4498 /* otherwise look in SOM symbol dict. */
4499 {
4500 msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL);
4501 if (msym)
4502 {
4503 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym);
4504 hp_cxx_exception_support = 1;
4505 }
4506 else
4507 {
4508 warning ("Unable to enable interception of exception catches.");
4509 warning ("Executable may not have been compiled debuggable with HP aCC.");
4510 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4511 return 0;
4512 }
4513 }
4514
4515 /* Next look for the catch enable flag provided end.o */
4516 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
4517 VAR_DOMAIN, 0, (struct symtab **) NULL);
4518 if (sym) /* sometimes present in debug info */
4519 {
4520 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym);
4521 hp_cxx_exception_support = 1;
4522 }
4523 else
4524 /* otherwise look in SOM symbol dict. */
4525 {
4526 msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL);
4527 if (msym)
4528 {
4529 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym);
4530 hp_cxx_exception_support = 1;
4531 }
4532 else
4533 {
4534 warning ("Unable to enable interception of exception throws.");
4535 warning ("Executable may not have been compiled debuggable with HP aCC.");
4536 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4537 return 0;
4538 }
4539 }
4540
4541 /* Set the flags */
4542 hp_cxx_exception_support = 2; /* everything worked so far */
4543 hp_cxx_exception_support_initialized = 1;
4544 exception_support_initialized = 1;
4545
4546 return 1;
4547 }
4548
4549 /* Target operation for enabling or disabling interception of
4550 exception events.
4551 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
4552 ENABLE is either 0 (disable) or 1 (enable).
4553 Return value is NULL if no support found;
4554 -1 if something went wrong,
4555 or a pointer to a symtab/line struct if the breakpointable
4556 address was found. */
4557
4558 struct symtab_and_line *
4559 child_enable_exception_callback (enum exception_event_kind kind, int enable)
4560 {
4561 char buf[4];
4562
4563 if (!exception_support_initialized || !hp_cxx_exception_support_initialized)
4564 if (!initialize_hp_cxx_exception_support ())
4565 return NULL;
4566
4567 switch (hp_cxx_exception_support)
4568 {
4569 case 0:
4570 /* Assuming no HP support at all */
4571 return NULL;
4572 case 1:
4573 /* HP support should be present, but something went wrong */
4574 return (struct symtab_and_line *) -1; /* yuck! */
4575 /* there may be other cases in the future */
4576 }
4577
4578 /* Set the EH hook to point to the callback routine */
4579 store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */
4580 /* pai: (temp) FIXME should there be a pack operation first? */
4581 if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */
4582 {
4583 warning ("Could not write to target memory for exception event callback.");
4584 warning ("Interception of exception events may not work.");
4585 return (struct symtab_and_line *) -1;
4586 }
4587 if (enable)
4588 {
4589 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */
4590 if (PIDGET (inferior_ptid) > 0)
4591 {
4592 if (setup_d_pid_in_inferior ())
4593 return (struct symtab_and_line *) -1;
4594 }
4595 else
4596 {
4597 warning ("Internal error: Invalid inferior pid? Cannot intercept exception events.");
4598 return (struct symtab_and_line *) -1;
4599 }
4600 }
4601
4602 switch (kind)
4603 {
4604 case EX_EVENT_THROW:
4605 store_unsigned_integer (buf, 4, enable ? 1 : 0);
4606 if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */
4607 {
4608 warning ("Couldn't enable exception throw interception.");
4609 return (struct symtab_and_line *) -1;
4610 }
4611 break;
4612 case EX_EVENT_CATCH:
4613 store_unsigned_integer (buf, 4, enable ? 1 : 0);
4614 if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */
4615 {
4616 warning ("Couldn't enable exception catch interception.");
4617 return (struct symtab_and_line *) -1;
4618 }
4619 break;
4620 default:
4621 error ("Request to enable unknown or unsupported exception event.");
4622 }
4623
4624 /* Copy break address into new sal struct, malloc'ing if needed. */
4625 if (!break_callback_sal)
4626 {
4627 break_callback_sal = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
4628 }
4629 init_sal (break_callback_sal);
4630 break_callback_sal->symtab = NULL;
4631 break_callback_sal->pc = eh_break_addr;
4632 break_callback_sal->line = 0;
4633 break_callback_sal->end = eh_break_addr;
4634
4635 return break_callback_sal;
4636 }
4637
4638 /* Record some information about the current exception event */
4639 static struct exception_event_record current_ex_event;
4640 /* Convenience struct */
4641 static struct symtab_and_line null_symtab_and_line =
4642 {NULL, 0, 0, 0};
4643
4644 /* Report current exception event. Returns a pointer to a record
4645 that describes the kind of the event, where it was thrown from,
4646 and where it will be caught. More information may be reported
4647 in the future */
4648 struct exception_event_record *
4649 child_get_current_exception_event (void)
4650 {
4651 CORE_ADDR event_kind;
4652 CORE_ADDR throw_addr;
4653 CORE_ADDR catch_addr;
4654 struct frame_info *fi, *curr_frame;
4655 int level = 1;
4656
4657 curr_frame = get_current_frame ();
4658 if (!curr_frame)
4659 return (struct exception_event_record *) NULL;
4660
4661 /* Go up one frame to __d_eh_notify_callback, because at the
4662 point when this code is executed, there's garbage in the
4663 arguments of __d_eh_break. */
4664 fi = find_relative_frame (curr_frame, &level);
4665 if (level != 0)
4666 return (struct exception_event_record *) NULL;
4667
4668 select_frame (fi);
4669
4670 /* Read in the arguments */
4671 /* __d_eh_notify_callback() is called with 3 arguments:
4672 1. event kind catch or throw
4673 2. the target address if known
4674 3. a flag -- not sure what this is. pai/1997-07-17 */
4675 event_kind = read_register (ARG0_REGNUM);
4676 catch_addr = read_register (ARG1_REGNUM);
4677
4678 /* Now go down to a user frame */
4679 /* For a throw, __d_eh_break is called by
4680 __d_eh_notify_callback which is called by
4681 __notify_throw which is called
4682 from user code.
4683 For a catch, __d_eh_break is called by
4684 __d_eh_notify_callback which is called by
4685 <stackwalking stuff> which is called by
4686 __throw__<stuff> or __rethrow_<stuff> which is called
4687 from user code. */
4688 /* FIXME: Don't use such magic numbers; search for the frames */
4689 level = (event_kind == EX_EVENT_THROW) ? 3 : 4;
4690 fi = find_relative_frame (curr_frame, &level);
4691 if (level != 0)
4692 return (struct exception_event_record *) NULL;
4693
4694 select_frame (fi);
4695 throw_addr = get_frame_pc (fi);
4696
4697 /* Go back to original (top) frame */
4698 select_frame (curr_frame);
4699
4700 current_ex_event.kind = (enum exception_event_kind) event_kind;
4701 current_ex_event.throw_sal = find_pc_line (throw_addr, 1);
4702 current_ex_event.catch_sal = find_pc_line (catch_addr, 1);
4703
4704 return &current_ex_event;
4705 }
4706
4707 /* Instead of this nasty cast, add a method pvoid() that prints out a
4708 host VOID data type (remember %p isn't portable). */
4709
4710 static CORE_ADDR
4711 hppa_pointer_to_address_hack (void *ptr)
4712 {
4713 gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
4714 return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
4715 }
4716
4717 static void
4718 unwind_command (char *exp, int from_tty)
4719 {
4720 CORE_ADDR address;
4721 struct unwind_table_entry *u;
4722
4723 /* If we have an expression, evaluate it and use it as the address. */
4724
4725 if (exp != 0 && *exp != 0)
4726 address = parse_and_eval_address (exp);
4727 else
4728 return;
4729
4730 u = find_unwind_entry (address);
4731
4732 if (!u)
4733 {
4734 printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
4735 return;
4736 }
4737
4738 printf_unfiltered ("unwind_table_entry (0x%s):\n",
4739 paddr_nz (hppa_pointer_to_address_hack (u)));
4740
4741 printf_unfiltered ("\tregion_start = ");
4742 print_address (u->region_start, gdb_stdout);
4743
4744 printf_unfiltered ("\n\tregion_end = ");
4745 print_address (u->region_end, gdb_stdout);
4746
4747 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
4748
4749 printf_unfiltered ("\n\tflags =");
4750 pif (Cannot_unwind);
4751 pif (Millicode);
4752 pif (Millicode_save_sr0);
4753 pif (Entry_SR);
4754 pif (Args_stored);
4755 pif (Variable_Frame);
4756 pif (Separate_Package_Body);
4757 pif (Frame_Extension_Millicode);
4758 pif (Stack_Overflow_Check);
4759 pif (Two_Instruction_SP_Increment);
4760 pif (Ada_Region);
4761 pif (Save_SP);
4762 pif (Save_RP);
4763 pif (Save_MRP_in_frame);
4764 pif (extn_ptr_defined);
4765 pif (Cleanup_defined);
4766 pif (MPE_XL_interrupt_marker);
4767 pif (HP_UX_interrupt_marker);
4768 pif (Large_frame);
4769
4770 putchar_unfiltered ('\n');
4771
4772 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
4773
4774 pin (Region_description);
4775 pin (Entry_FR);
4776 pin (Entry_GR);
4777 pin (Total_frame_size);
4778 }
4779
4780 void
4781 hppa_skip_permanent_breakpoint (void)
4782 {
4783 /* To step over a breakpoint instruction on the PA takes some
4784 fiddling with the instruction address queue.
4785
4786 When we stop at a breakpoint, the IA queue front (the instruction
4787 we're executing now) points at the breakpoint instruction, and
4788 the IA queue back (the next instruction to execute) points to
4789 whatever instruction we would execute after the breakpoint, if it
4790 were an ordinary instruction. This is the case even if the
4791 breakpoint is in the delay slot of a branch instruction.
4792
4793 Clearly, to step past the breakpoint, we need to set the queue
4794 front to the back. But what do we put in the back? What
4795 instruction comes after that one? Because of the branch delay
4796 slot, the next insn is always at the back + 4. */
4797 write_register (PCOQ_HEAD_REGNUM, read_register (PCOQ_TAIL_REGNUM));
4798 write_register (PCSQ_HEAD_REGNUM, read_register (PCSQ_TAIL_REGNUM));
4799
4800 write_register (PCOQ_TAIL_REGNUM, read_register (PCOQ_TAIL_REGNUM) + 4);
4801 /* We can leave the tail's space the same, since there's no jump. */
4802 }
4803
4804 /* Copy the function value from VALBUF into the proper location
4805 for a function return.
4806
4807 Called only in the context of the "return" command. */
4808
4809 void
4810 hppa32_store_return_value (struct type *type, char *valbuf)
4811 {
4812 /* For software floating point, the return value goes into the
4813 integer registers. But we do not have any flag to key this on,
4814 so we always store the value into the integer registers.
4815
4816 If its a float value, then we also store it into the floating
4817 point registers. */
4818 deprecated_write_register_bytes (REGISTER_BYTE (28)
4819 + (TYPE_LENGTH (type) > 4
4820 ? (8 - TYPE_LENGTH (type))
4821 : (4 - TYPE_LENGTH (type))),
4822 valbuf, TYPE_LENGTH (type));
4823 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4824 deprecated_write_register_bytes (REGISTER_BYTE (FP4_REGNUM),
4825 valbuf, TYPE_LENGTH (type));
4826 }
4827
4828 /* Same as hppa32_store_return_value(), but for the PA64 ABI. */
4829
4830 void
4831 hppa64_store_return_value (struct type *type, char *valbuf)
4832 {
4833 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4834 deprecated_write_register_bytes
4835 (REGISTER_BYTE (FP4_REGNUM)
4836 + DEPRECATED_REGISTER_SIZE - TYPE_LENGTH (type),
4837 valbuf, TYPE_LENGTH (type));
4838 else if (is_integral_type(type))
4839 deprecated_write_register_bytes
4840 (REGISTER_BYTE (28)
4841 + DEPRECATED_REGISTER_SIZE - TYPE_LENGTH (type),
4842 valbuf, TYPE_LENGTH (type));
4843 else if (TYPE_LENGTH (type) <= 8)
4844 deprecated_write_register_bytes
4845 (REGISTER_BYTE (28),valbuf, TYPE_LENGTH (type));
4846 else if (TYPE_LENGTH (type) <= 16)
4847 {
4848 deprecated_write_register_bytes (REGISTER_BYTE (28),valbuf, 8);
4849 deprecated_write_register_bytes
4850 (REGISTER_BYTE (29), valbuf + 8, TYPE_LENGTH (type) - 8);
4851 }
4852 }
4853
4854 /* Copy the function's return value into VALBUF.
4855
4856 This function is called only in the context of "target function calls",
4857 ie. when the debugger forces a function to be called in the child, and
4858 when the debugger forces a fucntion to return prematurely via the
4859 "return" command. */
4860
4861 void
4862 hppa32_extract_return_value (struct type *type, char *regbuf, char *valbuf)
4863 {
4864 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4865 memcpy (valbuf, regbuf + REGISTER_BYTE (FP4_REGNUM), TYPE_LENGTH (type));
4866 else
4867 memcpy (valbuf,
4868 (regbuf
4869 + REGISTER_BYTE (28)
4870 + (TYPE_LENGTH (type) > 4
4871 ? (8 - TYPE_LENGTH (type))
4872 : (4 - TYPE_LENGTH (type)))),
4873 TYPE_LENGTH (type));
4874 }
4875
4876 /* Same as hppa32_extract_return_value but for the PA64 ABI case. */
4877
4878 void
4879 hppa64_extract_return_value (struct type *type, char *regbuf, char *valbuf)
4880 {
4881 /* RM: Floats are returned in FR4R, doubles in FR4.
4882 Integral values are in r28, padded on the left.
4883 Aggregates less that 65 bits are in r28, right padded.
4884 Aggregates upto 128 bits are in r28 and r29, right padded. */
4885 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4886 memcpy (valbuf,
4887 regbuf + REGISTER_BYTE (FP4_REGNUM)
4888 + DEPRECATED_REGISTER_SIZE - TYPE_LENGTH (type),
4889 TYPE_LENGTH (type));
4890 else if (is_integral_type(type))
4891 memcpy (valbuf,
4892 regbuf + REGISTER_BYTE (28)
4893 + DEPRECATED_REGISTER_SIZE - TYPE_LENGTH (type),
4894 TYPE_LENGTH (type));
4895 else if (TYPE_LENGTH (type) <= 8)
4896 memcpy (valbuf, regbuf + REGISTER_BYTE (28), TYPE_LENGTH (type));
4897 else if (TYPE_LENGTH (type) <= 16)
4898 {
4899 memcpy (valbuf, regbuf + REGISTER_BYTE (28), 8);
4900 memcpy (valbuf + 8, regbuf + REGISTER_BYTE (29), TYPE_LENGTH (type) - 8);
4901 }
4902 }
4903
4904 int
4905 hppa_reg_struct_has_addr (int gcc_p, struct type *type)
4906 {
4907 /* On the PA, any pass-by-value structure > 8 bytes is actually passed
4908 via a pointer regardless of its type or the compiler used. */
4909 return (TYPE_LENGTH (type) > 8);
4910 }
4911
4912 int
4913 hppa_inner_than (CORE_ADDR lhs, CORE_ADDR rhs)
4914 {
4915 /* Stack grows upward */
4916 return (lhs > rhs);
4917 }
4918
4919 CORE_ADDR
4920 hppa32_stack_align (CORE_ADDR sp)
4921 {
4922 /* elz: adjust the quantity to the next highest value which is
4923 64-bit aligned. This is used in valops.c, when the sp is adjusted.
4924 On hppa the sp must always be kept 64-bit aligned */
4925 return ((sp % 8) ? (sp + 7) & -8 : sp);
4926 }
4927
4928 CORE_ADDR
4929 hppa64_stack_align (CORE_ADDR sp)
4930 {
4931 /* The PA64 ABI mandates a 16 byte stack alignment. */
4932 return ((sp % 16) ? (sp + 15) & -16 : sp);
4933 }
4934
4935 int
4936 hppa_pc_requires_run_before_use (CORE_ADDR pc)
4937 {
4938 /* Sometimes we may pluck out a minimal symbol that has a negative address.
4939
4940 An example of this occurs when an a.out is linked against a foo.sl.
4941 The foo.sl defines a global bar(), and the a.out declares a signature
4942 for bar(). However, the a.out doesn't directly call bar(), but passes
4943 its address in another call.
4944
4945 If you have this scenario and attempt to "break bar" before running,
4946 gdb will find a minimal symbol for bar() in the a.out. But that
4947 symbol's address will be negative. What this appears to denote is
4948 an index backwards from the base of the procedure linkage table (PLT)
4949 into the data linkage table (DLT), the end of which is contiguous
4950 with the start of the PLT. This is clearly not a valid address for
4951 us to set a breakpoint on.
4952
4953 Note that one must be careful in how one checks for a negative address.
4954 0xc0000000 is a legitimate address of something in a shared text
4955 segment, for example. Since I don't know what the possible range
4956 is of these "really, truly negative" addresses that come from the
4957 minimal symbols, I'm resorting to the gross hack of checking the
4958 top byte of the address for all 1's. Sigh. */
4959
4960 return (!target_has_stack && (pc & 0xFF000000));
4961 }
4962
4963 int
4964 hppa_instruction_nullified (void)
4965 {
4966 /* brobecker 2002/11/07: Couldn't we use a ULONGEST here? It would
4967 avoid the type cast. I'm leaving it as is for now as I'm doing
4968 semi-mechanical multiarching-related changes. */
4969 const int ipsw = (int) read_register (IPSW_REGNUM);
4970 const int flags = (int) read_register (FLAGS_REGNUM);
4971
4972 return ((ipsw & 0x00200000) && !(flags & 0x2));
4973 }
4974
4975 int
4976 hppa_register_raw_size (int reg_nr)
4977 {
4978 /* All registers have the same size. */
4979 return DEPRECATED_REGISTER_SIZE;
4980 }
4981
4982 /* Index within the register vector of the first byte of the space i
4983 used for register REG_NR. */
4984
4985 int
4986 hppa_register_byte (int reg_nr)
4987 {
4988 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4989
4990 return reg_nr * tdep->bytes_per_address;
4991 }
4992
4993 /* Return the GDB type object for the "standard" data type of data
4994 in register N. */
4995
4996 struct type *
4997 hppa32_register_virtual_type (int reg_nr)
4998 {
4999 if (reg_nr < FP4_REGNUM)
5000 return builtin_type_int;
5001 else
5002 return builtin_type_float;
5003 }
5004
5005 /* Return the GDB type object for the "standard" data type of data
5006 in register N. hppa64 version. */
5007
5008 struct type *
5009 hppa64_register_virtual_type (int reg_nr)
5010 {
5011 if (reg_nr < FP4_REGNUM)
5012 return builtin_type_unsigned_long_long;
5013 else
5014 return builtin_type_double;
5015 }
5016
5017 /* Store the address of the place in which to copy the structure the
5018 subroutine will return. This is called from call_function. */
5019
5020 void
5021 hppa_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
5022 {
5023 write_register (28, addr);
5024 }
5025
5026 CORE_ADDR
5027 hppa_extract_struct_value_address (char *regbuf)
5028 {
5029 /* Extract from an array REGBUF containing the (raw) register state
5030 the address in which a function should return its structure value,
5031 as a CORE_ADDR (or an expression that can be used as one). */
5032 /* FIXME: brobecker 2002-12-26.
5033 The current implementation is historical, but we should eventually
5034 implement it in a more robust manner as it relies on the fact that
5035 the address size is equal to the size of an int* _on the host_...
5036 One possible implementation that crossed my mind is to use
5037 extract_address. */
5038 return (*(int *)(regbuf + REGISTER_BYTE (28)));
5039 }
5040
5041 /* Return True if REGNUM is not a register available to the user
5042 through ptrace(). */
5043
5044 int
5045 hppa_cannot_store_register (int regnum)
5046 {
5047 return (regnum == 0
5048 || regnum == PCSQ_HEAD_REGNUM
5049 || (regnum >= PCSQ_TAIL_REGNUM && regnum < IPSW_REGNUM)
5050 || (regnum > IPSW_REGNUM && regnum < FP4_REGNUM));
5051
5052 }
5053
5054 CORE_ADDR
5055 hppa_smash_text_address (CORE_ADDR addr)
5056 {
5057 /* The low two bits of the PC on the PA contain the privilege level.
5058 Some genius implementing a (non-GCC) compiler apparently decided
5059 this means that "addresses" in a text section therefore include a
5060 privilege level, and thus symbol tables should contain these bits.
5061 This seems like a bonehead thing to do--anyway, it seems to work
5062 for our purposes to just ignore those bits. */
5063
5064 return (addr &= ~0x3);
5065 }
5066
5067 /* Get the ith function argument for the current function. */
5068 CORE_ADDR
5069 hppa_fetch_pointer_argument (struct frame_info *frame, int argi,
5070 struct type *type)
5071 {
5072 CORE_ADDR addr;
5073 frame_read_register (frame, R0_REGNUM + 26 - argi, &addr);
5074 return addr;
5075 }
5076
5077 static struct gdbarch *
5078 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5079 {
5080 struct gdbarch_tdep *tdep;
5081 struct gdbarch *gdbarch;
5082
5083 /* Try to determine the ABI of the object we are loading. */
5084 if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
5085 {
5086 /* If it's a SOM file, assume it's HP/UX SOM. */
5087 if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour)
5088 info.osabi = GDB_OSABI_HPUX_SOM;
5089 }
5090
5091 /* find a candidate among the list of pre-declared architectures. */
5092 arches = gdbarch_list_lookup_by_info (arches, &info);
5093 if (arches != NULL)
5094 return (arches->gdbarch);
5095
5096 /* If none found, then allocate and initialize one. */
5097 tdep = XMALLOC (struct gdbarch_tdep);
5098 gdbarch = gdbarch_alloc (&info, tdep);
5099
5100 /* Determine from the bfd_arch_info structure if we are dealing with
5101 a 32 or 64 bits architecture. If the bfd_arch_info is not available,
5102 then default to a 32bit machine. */
5103 if (info.bfd_arch_info != NULL)
5104 tdep->bytes_per_address =
5105 info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
5106 else
5107 tdep->bytes_per_address = 4;
5108
5109 /* Some parts of the gdbarch vector depend on whether we are running
5110 on a 32 bits or 64 bits target. */
5111 switch (tdep->bytes_per_address)
5112 {
5113 case 4:
5114 set_gdbarch_num_regs (gdbarch, hppa32_num_regs);
5115 set_gdbarch_register_name (gdbarch, hppa32_register_name);
5116 set_gdbarch_deprecated_register_virtual_type
5117 (gdbarch, hppa32_register_virtual_type);
5118 set_gdbarch_deprecated_call_dummy_length
5119 (gdbarch, hppa32_call_dummy_length);
5120 set_gdbarch_stack_align (gdbarch, hppa32_stack_align);
5121 set_gdbarch_reg_struct_has_addr (gdbarch, hppa_reg_struct_has_addr);
5122 set_gdbarch_deprecated_extract_return_value
5123 (gdbarch, hppa32_extract_return_value);
5124 set_gdbarch_use_struct_convention
5125 (gdbarch, hppa32_use_struct_convention);
5126 set_gdbarch_deprecated_store_return_value
5127 (gdbarch, hppa32_store_return_value);
5128 break;
5129 case 8:
5130 set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
5131 set_gdbarch_register_name (gdbarch, hppa64_register_name);
5132 set_gdbarch_deprecated_register_virtual_type
5133 (gdbarch, hppa64_register_virtual_type);
5134 set_gdbarch_deprecated_call_dummy_breakpoint_offset
5135 (gdbarch, hppa64_call_dummy_breakpoint_offset);
5136 set_gdbarch_deprecated_call_dummy_length
5137 (gdbarch, hppa64_call_dummy_length);
5138 set_gdbarch_stack_align (gdbarch, hppa64_stack_align);
5139 set_gdbarch_deprecated_extract_return_value
5140 (gdbarch, hppa64_extract_return_value);
5141 set_gdbarch_use_struct_convention
5142 (gdbarch, hppa64_use_struct_convention);
5143 set_gdbarch_deprecated_store_return_value
5144 (gdbarch, hppa64_store_return_value);
5145 break;
5146 default:
5147 internal_error (__FILE__, __LINE__, "Unsupported address size: %d",
5148 tdep->bytes_per_address);
5149 }
5150
5151 /* The following gdbarch vector elements depend on other parts of this
5152 vector which have been set above, depending on the ABI. */
5153 set_gdbarch_deprecated_register_bytes
5154 (gdbarch, gdbarch_num_regs (gdbarch) * tdep->bytes_per_address);
5155 set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
5156 set_gdbarch_long_long_bit (gdbarch, 64);
5157 set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
5158
5159 /* The following gdbarch vector elements do not depend on the address
5160 size, or in any other gdbarch element previously set. */
5161 set_gdbarch_function_start_offset (gdbarch, 0);
5162 set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue);
5163 set_gdbarch_skip_trampoline_code (gdbarch, hppa_skip_trampoline_code);
5164 set_gdbarch_in_solib_call_trampoline (gdbarch, hppa_in_solib_call_trampoline);
5165 set_gdbarch_in_solib_return_trampoline (gdbarch,
5166 hppa_in_solib_return_trampoline);
5167 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, hppa_saved_pc_after_call);
5168 set_gdbarch_inner_than (gdbarch, hppa_inner_than);
5169 set_gdbarch_decr_pc_after_break (gdbarch, 0);
5170 set_gdbarch_deprecated_register_size (gdbarch, tdep->bytes_per_address);
5171 set_gdbarch_deprecated_fp_regnum (gdbarch, 3);
5172 set_gdbarch_sp_regnum (gdbarch, 30);
5173 set_gdbarch_fp0_regnum (gdbarch, 64);
5174 set_gdbarch_pc_regnum (gdbarch, PCOQ_HEAD_REGNUM);
5175 set_gdbarch_npc_regnum (gdbarch, PCOQ_TAIL_REGNUM);
5176 set_gdbarch_deprecated_register_raw_size (gdbarch, hppa_register_raw_size);
5177 set_gdbarch_deprecated_register_byte (gdbarch, hppa_register_byte);
5178 set_gdbarch_deprecated_register_virtual_size (gdbarch, hppa_register_raw_size);
5179 set_gdbarch_deprecated_max_register_raw_size (gdbarch, tdep->bytes_per_address);
5180 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5181 set_gdbarch_deprecated_store_struct_return (gdbarch, hppa_store_struct_return);
5182 set_gdbarch_deprecated_extract_struct_value_address
5183 (gdbarch, hppa_extract_struct_value_address);
5184 set_gdbarch_cannot_store_register (gdbarch, hppa_cannot_store_register);
5185 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, hppa_init_extra_frame_info);
5186 set_gdbarch_deprecated_frame_chain (gdbarch, hppa_frame_chain);
5187 set_gdbarch_deprecated_frame_chain_valid (gdbarch, hppa_frame_chain_valid);
5188 set_gdbarch_frameless_function_invocation
5189 (gdbarch, hppa_frameless_function_invocation);
5190 set_gdbarch_deprecated_frame_saved_pc (gdbarch, hppa_frame_saved_pc);
5191 set_gdbarch_frame_args_skip (gdbarch, 0);
5192 set_gdbarch_deprecated_push_dummy_frame (gdbarch, hppa_push_dummy_frame);
5193 set_gdbarch_deprecated_pop_frame (gdbarch, hppa_pop_frame);
5194 /* set_gdbarch_deprecated_fix_call_dummy (gdbarch, hppa_fix_call_dummy); */
5195 set_gdbarch_deprecated_push_arguments (gdbarch, hppa_push_arguments);
5196 set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address);
5197 set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address);
5198 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
5199 set_gdbarch_read_pc (gdbarch, hppa_target_read_pc);
5200 set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
5201 set_gdbarch_deprecated_target_read_fp (gdbarch, hppa_target_read_fp);
5202
5203 /* Helper for function argument information. */
5204 set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
5205
5206 set_gdbarch_print_insn (gdbarch, print_insn_hppa);
5207
5208 /* When a hardware watchpoint triggers, we'll move the inferior past
5209 it by removing all eventpoints; stepping past the instruction
5210 that caused the trigger; reinserting eventpoints; and checking
5211 whether any watched location changed. */
5212 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
5213
5214 /* Hook in ABI-specific overrides, if they have been registered. */
5215 gdbarch_init_osabi (info, gdbarch);
5216
5217 return gdbarch;
5218 }
5219
5220 static void
5221 hppa_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
5222 {
5223 /* Nothing to print for the moment. */
5224 }
5225
5226 void
5227 _initialize_hppa_tdep (void)
5228 {
5229 struct cmd_list_element *c;
5230 void break_at_finish_command (char *arg, int from_tty);
5231 void tbreak_at_finish_command (char *arg, int from_tty);
5232 void break_at_finish_at_depth_command (char *arg, int from_tty);
5233
5234 gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
5235
5236 add_cmd ("unwind", class_maintenance, unwind_command,
5237 "Print unwind table entry at given address.",
5238 &maintenanceprintlist);
5239
5240 deprecate_cmd (add_com ("xbreak", class_breakpoint,
5241 break_at_finish_command,
5242 concat ("Set breakpoint at procedure exit. \n\
5243 Argument may be function name, or \"*\" and an address.\n\
5244 If function is specified, break at end of code for that function.\n\
5245 If an address is specified, break at the end of the function that contains \n\
5246 that exact address.\n",
5247 "With no arg, uses current execution address of selected stack frame.\n\
5248 This is useful for breaking on return to a stack frame.\n\
5249 \n\
5250 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
5251 \n\
5252 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)), NULL);
5253 deprecate_cmd (add_com_alias ("xb", "xbreak", class_breakpoint, 1), NULL);
5254 deprecate_cmd (add_com_alias ("xbr", "xbreak", class_breakpoint, 1), NULL);
5255 deprecate_cmd (add_com_alias ("xbre", "xbreak", class_breakpoint, 1), NULL);
5256 deprecate_cmd (add_com_alias ("xbrea", "xbreak", class_breakpoint, 1), NULL);
5257
5258 deprecate_cmd (c = add_com ("txbreak", class_breakpoint,
5259 tbreak_at_finish_command,
5260 "Set temporary breakpoint at procedure exit. Either there should\n\
5261 be no argument or the argument must be a depth.\n"), NULL);
5262 set_cmd_completer (c, location_completer);
5263
5264 if (xdb_commands)
5265 deprecate_cmd (add_com ("bx", class_breakpoint,
5266 break_at_finish_at_depth_command,
5267 "Set breakpoint at procedure exit. Either there should\n\
5268 be no argument or the argument must be a depth.\n"), NULL);
5269 }
5270
This page took 0.162631 seconds and 4 git commands to generate.