* alpha-tdep.c (alpha_skip_prologue_internal): Remove
[deliverable/binutils-gdb.git] / gdb / alpha-tdep.c
1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "symtab.h"
26 #include "value.h"
27 #include "gdbcmd.h"
28 #include "gdbcore.h"
29 #include "dis-asm.h"
30 #include "symfile.h"
31 #include "objfiles.h"
32 #include "gdb_string.h"
33 #include "linespec.h"
34 #include "regcache.h"
35 #include "doublest.h"
36 #include "arch-utils.h"
37
38 #include "elf-bfd.h"
39
40 #include "alpha-tdep.h"
41
42 static gdbarch_init_ftype alpha_gdbarch_init;
43
44 static gdbarch_register_name_ftype alpha_register_name;
45 static gdbarch_register_raw_size_ftype alpha_register_raw_size;
46 static gdbarch_register_virtual_size_ftype alpha_register_virtual_size;
47 static gdbarch_register_virtual_type_ftype alpha_register_virtual_type;
48 static gdbarch_register_byte_ftype alpha_register_byte;
49 static gdbarch_cannot_fetch_register_ftype alpha_cannot_fetch_register;
50 static gdbarch_cannot_store_register_ftype alpha_cannot_store_register;
51 static gdbarch_register_convertible_ftype alpha_register_convertible;
52 static gdbarch_register_convert_to_virtual_ftype
53 alpha_register_convert_to_virtual;
54 static gdbarch_register_convert_to_raw_ftype alpha_register_convert_to_raw;
55 static gdbarch_store_struct_return_ftype alpha_store_struct_return;
56 static gdbarch_extract_return_value_ftype alpha_extract_return_value;
57 static gdbarch_store_return_value_ftype alpha_store_return_value;
58 static gdbarch_extract_struct_value_address_ftype
59 alpha_extract_struct_value_address;
60 static gdbarch_use_struct_convention_ftype alpha_use_struct_convention;
61
62 static gdbarch_breakpoint_from_pc_ftype alpha_breakpoint_from_pc;
63
64 static gdbarch_frame_args_address_ftype alpha_frame_args_address;
65 static gdbarch_frame_locals_address_ftype alpha_frame_locals_address;
66
67 static gdbarch_skip_prologue_ftype alpha_skip_prologue;
68 static gdbarch_get_saved_register_ftype alpha_get_saved_register;
69 static gdbarch_saved_pc_after_call_ftype alpha_saved_pc_after_call;
70 static gdbarch_frame_chain_ftype alpha_frame_chain;
71 static gdbarch_frame_saved_pc_ftype alpha_frame_saved_pc;
72 static gdbarch_frame_init_saved_regs_ftype alpha_frame_init_saved_regs;
73
74 static gdbarch_push_arguments_ftype alpha_push_arguments;
75 static gdbarch_push_dummy_frame_ftype alpha_push_dummy_frame;
76 static gdbarch_pop_frame_ftype alpha_pop_frame;
77 static gdbarch_fix_call_dummy_ftype alpha_fix_call_dummy;
78 static gdbarch_init_frame_pc_first_ftype alpha_init_frame_pc_first;
79 static gdbarch_init_extra_frame_info_ftype alpha_init_extra_frame_info;
80
81 static gdbarch_get_longjmp_target_ftype alpha_get_longjmp_target;
82
83 struct frame_extra_info
84 {
85 alpha_extra_func_info_t proc_desc;
86 int localoff;
87 int pc_reg;
88 };
89
90 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
91
92 /* Prototypes for local functions. */
93
94 static void alpha_find_saved_regs (struct frame_info *);
95
96 static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
97
98 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
99
100 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
101
102 static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
103 CORE_ADDR,
104 struct frame_info *);
105
106 static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
107 struct frame_info *);
108
109 #if 0
110 static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
111 #endif
112
113 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
114
115 static CORE_ADDR after_prologue (CORE_ADDR pc,
116 alpha_extra_func_info_t proc_desc);
117
118 static int alpha_in_prologue (CORE_ADDR pc,
119 alpha_extra_func_info_t proc_desc);
120
121 static int alpha_about_to_return (CORE_ADDR pc);
122
123 void _initialize_alpha_tdep (void);
124
125 /* Heuristic_proc_start may hunt through the text section for a long
126 time across a 2400 baud serial line. Allows the user to limit this
127 search. */
128 static unsigned int heuristic_fence_post = 0;
129 /* *INDENT-OFF* */
130 /* Layout of a stack frame on the alpha:
131
132 | |
133 pdr members: | 7th ... nth arg, |
134 | `pushed' by caller. |
135 | |
136 ----------------|-------------------------------|<-- old_sp == vfp
137 ^ ^ ^ ^ | |
138 | | | | | |
139 | |localoff | Copies of 1st .. 6th |
140 | | | | | argument if necessary. |
141 | | | v | |
142 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
143 | | | | |
144 | | | | Locals and temporaries. |
145 | | | | |
146 | | | |-------------------------------|
147 | | | | |
148 |-fregoffset | Saved float registers. |
149 | | | | F9 |
150 | | | | . |
151 | | | | . |
152 | | | | F2 |
153 | | v | |
154 | | -------|-------------------------------|
155 | | | |
156 | | | Saved registers. |
157 | | | S6 |
158 |-regoffset | . |
159 | | | . |
160 | | | S0 |
161 | | | pdr.pcreg |
162 | v | |
163 | ----------|-------------------------------|
164 | | |
165 frameoffset | Argument build area, gets |
166 | | 7th ... nth arg for any |
167 | | called procedure. |
168 v | |
169 -------------|-------------------------------|<-- sp
170 | |
171 */
172 /* *INDENT-ON* */
173
174 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
175 /* These next two fields are kind of being hijacked. I wonder if
176 iline is too small for the values it needs to hold, if GDB is
177 running on a 32-bit host. */
178 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
179 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
180 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
181 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
182 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
183 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
184 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
185 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
186 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
187 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
188 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
189 #define _PROC_MAGIC_ 0x0F0F0F0F
190 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
191 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
192
193 struct linked_proc_info
194 {
195 struct alpha_extra_func_info info;
196 struct linked_proc_info *next;
197 }
198 *linked_proc_desc_table = NULL;
199 \f
200 static CORE_ADDR
201 alpha_frame_past_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc)
202 {
203 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
204
205 if (tdep->skip_sigtramp_frame != NULL)
206 return (tdep->skip_sigtramp_frame (frame, pc));
207
208 return (0);
209 }
210
211 static LONGEST
212 alpha_dynamic_sigtramp_offset (CORE_ADDR pc)
213 {
214 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
215
216 /* Must be provided by OS/ABI variant code if supported. */
217 if (tdep->dynamic_sigtramp_offset != NULL)
218 return (tdep->dynamic_sigtramp_offset (pc));
219
220 return (-1);
221 }
222
223 #define ALPHA_PROC_SIGTRAMP_MAGIC 0x0e0f0f0f
224
225 /* Return TRUE if the procedure descriptor PROC is a procedure
226 descriptor that refers to a dynamically generated signal
227 trampoline routine. */
228 static int
229 alpha_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc)
230 {
231 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
232
233 if (tdep->dynamic_sigtramp_offset != NULL)
234 return (proc->pdr.isym == ALPHA_PROC_SIGTRAMP_MAGIC);
235
236 return (0);
237 }
238
239 static void
240 alpha_set_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc)
241 {
242 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
243
244 if (tdep->dynamic_sigtramp_offset != NULL)
245 proc->pdr.isym = ALPHA_PROC_SIGTRAMP_MAGIC;
246 }
247
248 /* Dynamically create a signal-handler caller procedure descriptor for
249 the signal-handler return code starting at address LOW_ADDR. The
250 descriptor is added to the linked_proc_desc_table. */
251
252 static alpha_extra_func_info_t
253 push_sigtramp_desc (CORE_ADDR low_addr)
254 {
255 struct linked_proc_info *link;
256 alpha_extra_func_info_t proc_desc;
257
258 link = (struct linked_proc_info *)
259 xmalloc (sizeof (struct linked_proc_info));
260 link->next = linked_proc_desc_table;
261 linked_proc_desc_table = link;
262
263 proc_desc = &link->info;
264
265 proc_desc->numargs = 0;
266 PROC_LOW_ADDR (proc_desc) = low_addr;
267 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
268 PROC_DUMMY_FRAME (proc_desc) = 0;
269 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
270 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
271 PROC_REG_MASK (proc_desc) = 0xffff;
272 PROC_FREG_MASK (proc_desc) = 0xffff;
273 PROC_PC_REG (proc_desc) = 26;
274 PROC_LOCALOFF (proc_desc) = 0;
275 alpha_set_proc_desc_is_dyn_sigtramp (proc_desc);
276 return (proc_desc);
277 }
278 \f
279
280 static char *
281 alpha_register_name (int regno)
282 {
283 static char *register_names[] =
284 {
285 "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
286 "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
287 "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
288 "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero",
289 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
290 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
291 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
292 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr",
293 "pc", "vfp",
294 };
295
296 if (regno < 0)
297 return (NULL);
298 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
299 return (NULL);
300 return (register_names[regno]);
301 }
302
303 static int
304 alpha_cannot_fetch_register (int regno)
305 {
306 return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM);
307 }
308
309 static int
310 alpha_cannot_store_register (int regno)
311 {
312 return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM);
313 }
314
315 static int
316 alpha_register_convertible (int regno)
317 {
318 return (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31);
319 }
320
321 static struct type *
322 alpha_register_virtual_type (int regno)
323 {
324 return ((regno >= FP0_REGNUM && regno < (FP0_REGNUM+31))
325 ? builtin_type_double : builtin_type_long);
326 }
327
328 static int
329 alpha_register_byte (int regno)
330 {
331 return (regno * 8);
332 }
333
334 static int
335 alpha_register_raw_size (int regno)
336 {
337 return 8;
338 }
339
340 static int
341 alpha_register_virtual_size (int regno)
342 {
343 return 8;
344 }
345 \f
346
347 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
348 NULL). */
349
350 static void
351 alpha_find_saved_regs (struct frame_info *frame)
352 {
353 int ireg;
354 CORE_ADDR reg_position;
355 unsigned long mask;
356 alpha_extra_func_info_t proc_desc;
357 int returnreg;
358
359 frame_saved_regs_zalloc (frame);
360
361 /* If it is the frame for __sigtramp, the saved registers are located
362 in a sigcontext structure somewhere on the stack. __sigtramp
363 passes a pointer to the sigcontext structure on the stack.
364 If the stack layout for __sigtramp changes, or if sigcontext offsets
365 change, we might have to update this code. */
366 #ifndef SIGFRAME_PC_OFF
367 #define SIGFRAME_PC_OFF (2 * 8)
368 #define SIGFRAME_REGSAVE_OFF (4 * 8)
369 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
370 #endif
371 if (frame->signal_handler_caller)
372 {
373 CORE_ADDR sigcontext_addr;
374
375 sigcontext_addr = SIGCONTEXT_ADDR (frame);
376 for (ireg = 0; ireg < 32; ireg++)
377 {
378 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
379 frame->saved_regs[ireg] = reg_position;
380 }
381 for (ireg = 0; ireg < 32; ireg++)
382 {
383 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
384 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
385 }
386 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
387 return;
388 }
389
390 proc_desc = frame->extra_info->proc_desc;
391 if (proc_desc == NULL)
392 /* I'm not sure how/whether this can happen. Normally when we can't
393 find a proc_desc, we "synthesize" one using heuristic_proc_desc
394 and set the saved_regs right away. */
395 return;
396
397 /* Fill in the offsets for the registers which gen_mask says
398 were saved. */
399
400 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
401 mask = PROC_REG_MASK (proc_desc);
402
403 returnreg = PROC_PC_REG (proc_desc);
404
405 /* Note that RA is always saved first, regardless of its actual
406 register number. */
407 if (mask & (1 << returnreg))
408 {
409 frame->saved_regs[returnreg] = reg_position;
410 reg_position += 8;
411 mask &= ~(1 << returnreg); /* Clear bit for RA so we
412 don't save again later. */
413 }
414
415 for (ireg = 0; ireg <= 31; ++ireg)
416 if (mask & (1 << ireg))
417 {
418 frame->saved_regs[ireg] = reg_position;
419 reg_position += 8;
420 }
421
422 /* Fill in the offsets for the registers which float_mask says
423 were saved. */
424
425 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
426 mask = PROC_FREG_MASK (proc_desc);
427
428 for (ireg = 0; ireg <= 31; ++ireg)
429 if (mask & (1 << ireg))
430 {
431 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
432 reg_position += 8;
433 }
434
435 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
436 }
437
438 static void
439 alpha_frame_init_saved_regs (struct frame_info *fi)
440 {
441 if (fi->saved_regs == NULL)
442 alpha_find_saved_regs (fi);
443 fi->saved_regs[SP_REGNUM] = fi->frame;
444 }
445
446 static void
447 alpha_init_frame_pc_first (int fromleaf, struct frame_info *prev)
448 {
449 prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) :
450 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
451 }
452
453 static CORE_ADDR
454 read_next_frame_reg (struct frame_info *fi, int regno)
455 {
456 for (; fi; fi = fi->next)
457 {
458 /* We have to get the saved sp from the sigcontext
459 if it is a signal handler frame. */
460 if (regno == SP_REGNUM && !fi->signal_handler_caller)
461 return fi->frame;
462 else
463 {
464 if (fi->saved_regs == NULL)
465 alpha_find_saved_regs (fi);
466 if (fi->saved_regs[regno])
467 return read_memory_integer (fi->saved_regs[regno], 8);
468 }
469 }
470 return read_register (regno);
471 }
472
473 static CORE_ADDR
474 alpha_frame_saved_pc (struct frame_info *frame)
475 {
476 alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc;
477 /* We have to get the saved pc from the sigcontext
478 if it is a signal handler frame. */
479 int pcreg = frame->signal_handler_caller ? PC_REGNUM
480 : frame->extra_info->pc_reg;
481
482 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
483 return read_memory_integer (frame->frame - 8, 8);
484
485 return read_next_frame_reg (frame, pcreg);
486 }
487
488 static void
489 alpha_get_saved_register (char *raw_buffer,
490 int *optimized,
491 CORE_ADDR *addrp,
492 struct frame_info *frame,
493 int regnum,
494 enum lval_type *lval)
495 {
496 CORE_ADDR addr;
497
498 if (!target_has_registers)
499 error ("No registers.");
500
501 /* Normal systems don't optimize out things with register numbers. */
502 if (optimized != NULL)
503 *optimized = 0;
504 addr = find_saved_register (frame, regnum);
505 if (addr != 0)
506 {
507 if (lval != NULL)
508 *lval = lval_memory;
509 if (regnum == SP_REGNUM)
510 {
511 if (raw_buffer != NULL)
512 {
513 /* Put it back in target format. */
514 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
515 (LONGEST) addr);
516 }
517 if (addrp != NULL)
518 *addrp = 0;
519 return;
520 }
521 if (raw_buffer != NULL)
522 target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
523 }
524 else
525 {
526 if (lval != NULL)
527 *lval = lval_register;
528 addr = REGISTER_BYTE (regnum);
529 if (raw_buffer != NULL)
530 read_register_gen (regnum, raw_buffer);
531 }
532 if (addrp != NULL)
533 *addrp = addr;
534 }
535
536 static CORE_ADDR
537 alpha_saved_pc_after_call (struct frame_info *frame)
538 {
539 CORE_ADDR pc = frame->pc;
540 CORE_ADDR tmp;
541 alpha_extra_func_info_t proc_desc;
542 int pcreg;
543
544 /* Skip over shared library trampoline if necessary. */
545 tmp = SKIP_TRAMPOLINE_CODE (pc);
546 if (tmp != 0)
547 pc = tmp;
548
549 proc_desc = find_proc_desc (pc, frame->next);
550 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : ALPHA_RA_REGNUM;
551
552 if (frame->signal_handler_caller)
553 return alpha_frame_saved_pc (frame);
554 else
555 return read_register (pcreg);
556 }
557
558
559 static struct alpha_extra_func_info temp_proc_desc;
560 static CORE_ADDR temp_saved_regs[ALPHA_NUM_REGS];
561
562 /* Nonzero if instruction at PC is a return instruction. "ret
563 $zero,($ra),1" on alpha. */
564
565 static int
566 alpha_about_to_return (CORE_ADDR pc)
567 {
568 return read_memory_integer (pc, 4) == 0x6bfa8001;
569 }
570
571
572
573 /* This fencepost looks highly suspicious to me. Removing it also
574 seems suspicious as it could affect remote debugging across serial
575 lines. */
576
577 static CORE_ADDR
578 heuristic_proc_start (CORE_ADDR pc)
579 {
580 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
581 CORE_ADDR start_pc = pc;
582 CORE_ADDR fence = start_pc - heuristic_fence_post;
583
584 if (start_pc == 0)
585 return 0;
586
587 if (heuristic_fence_post == UINT_MAX
588 || fence < tdep->vm_min_address)
589 fence = tdep->vm_min_address;
590
591 /* search back for previous return */
592 for (start_pc -= 4;; start_pc -= 4)
593 if (start_pc < fence)
594 {
595 /* It's not clear to me why we reach this point when
596 stop_soon_quietly, but with this test, at least we
597 don't print out warnings for every child forked (eg, on
598 decstation). 22apr93 rich@cygnus.com. */
599 if (!stop_soon_quietly)
600 {
601 static int blurb_printed = 0;
602
603 if (fence == tdep->vm_min_address)
604 warning ("Hit beginning of text section without finding");
605 else
606 warning ("Hit heuristic-fence-post without finding");
607
608 warning ("enclosing function for address 0x%s", paddr_nz (pc));
609 if (!blurb_printed)
610 {
611 printf_filtered ("\
612 This warning occurs if you are debugging a function without any symbols\n\
613 (for example, in a stripped executable). In that case, you may wish to\n\
614 increase the size of the search with the `set heuristic-fence-post' command.\n\
615 \n\
616 Otherwise, you told GDB there was a function where there isn't one, or\n\
617 (more likely) you have encountered a bug in GDB.\n");
618 blurb_printed = 1;
619 }
620 }
621
622 return 0;
623 }
624 else if (alpha_about_to_return (start_pc))
625 break;
626
627 start_pc += 4; /* skip return */
628 return start_pc;
629 }
630
631 static alpha_extra_func_info_t
632 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
633 struct frame_info *next_frame)
634 {
635 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
636 CORE_ADDR cur_pc;
637 int frame_size;
638 int has_frame_reg = 0;
639 unsigned long reg_mask = 0;
640 int pcreg = -1;
641
642 if (start_pc == 0)
643 return NULL;
644 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
645 memset (&temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
646 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
647
648 if (start_pc + 200 < limit_pc)
649 limit_pc = start_pc + 200;
650 frame_size = 0;
651 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
652 {
653 char buf[4];
654 unsigned long word;
655 int status;
656
657 status = read_memory_nobpt (cur_pc, buf, 4);
658 if (status)
659 memory_error (status, cur_pc);
660 word = extract_unsigned_integer (buf, 4);
661
662 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
663 {
664 if (word & 0x8000)
665 frame_size += (-word) & 0xffff;
666 else
667 /* Exit loop if a positive stack adjustment is found, which
668 usually means that the stack cleanup code in the function
669 epilogue is reached. */
670 break;
671 }
672 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
673 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
674 {
675 int reg = (word & 0x03e00000) >> 21;
676 reg_mask |= 1 << reg;
677 temp_saved_regs[reg] = sp + (short) word;
678
679 /* Starting with OSF/1-3.2C, the system libraries are shipped
680 without local symbols, but they still contain procedure
681 descriptors without a symbol reference. GDB is currently
682 unable to find these procedure descriptors and uses
683 heuristic_proc_desc instead.
684 As some low level compiler support routines (__div*, __add*)
685 use a non-standard return address register, we have to
686 add some heuristics to determine the return address register,
687 or stepping over these routines will fail.
688 Usually the return address register is the first register
689 saved on the stack, but assembler optimization might
690 rearrange the register saves.
691 So we recognize only a few registers (t7, t9, ra) within
692 the procedure prologue as valid return address registers.
693 If we encounter a return instruction, we extract the
694 the return address register from it.
695
696 FIXME: Rewriting GDB to access the procedure descriptors,
697 e.g. via the minimal symbol table, might obviate this hack. */
698 if (pcreg == -1
699 && cur_pc < (start_pc + 80)
700 && (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM
701 || reg == ALPHA_RA_REGNUM))
702 pcreg = reg;
703 }
704 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
705 pcreg = (word >> 16) & 0x1f;
706 else if (word == 0x47de040f) /* bis sp,sp fp */
707 has_frame_reg = 1;
708 }
709 if (pcreg == -1)
710 {
711 /* If we haven't found a valid return address register yet,
712 keep searching in the procedure prologue. */
713 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
714 {
715 char buf[4];
716 unsigned long word;
717
718 if (read_memory_nobpt (cur_pc, buf, 4))
719 break;
720 cur_pc += 4;
721 word = extract_unsigned_integer (buf, 4);
722
723 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
724 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
725 {
726 int reg = (word & 0x03e00000) >> 21;
727 if (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM
728 || reg == ALPHA_RA_REGNUM)
729 {
730 pcreg = reg;
731 break;
732 }
733 }
734 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
735 {
736 pcreg = (word >> 16) & 0x1f;
737 break;
738 }
739 }
740 }
741
742 if (has_frame_reg)
743 PROC_FRAME_REG (&temp_proc_desc) = ALPHA_GCC_FP_REGNUM;
744 else
745 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
746 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
747 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
748 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? ALPHA_RA_REGNUM : pcreg;
749 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
750 return &temp_proc_desc;
751 }
752
753 /* This returns the PC of the first inst after the prologue. If we can't
754 find the prologue, then return 0. */
755
756 static CORE_ADDR
757 after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
758 {
759 struct symtab_and_line sal;
760 CORE_ADDR func_addr, func_end;
761
762 if (!proc_desc)
763 proc_desc = find_proc_desc (pc, NULL);
764
765 if (proc_desc)
766 {
767 if (alpha_proc_desc_is_dyn_sigtramp (proc_desc))
768 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
769
770 /* If function is frameless, then we need to do it the hard way. I
771 strongly suspect that frameless always means prologueless... */
772 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
773 && PROC_FRAME_OFFSET (proc_desc) == 0)
774 return 0;
775 }
776
777 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
778 return 0; /* Unknown */
779
780 sal = find_pc_line (func_addr, 0);
781
782 if (sal.end < func_end)
783 return sal.end;
784
785 /* The line after the prologue is after the end of the function. In this
786 case, tell the caller to find the prologue the hard way. */
787
788 return 0;
789 }
790
791 /* Return non-zero if we *might* be in a function prologue. Return zero if we
792 are definitively *not* in a function prologue. */
793
794 static int
795 alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
796 {
797 CORE_ADDR after_prologue_pc;
798
799 after_prologue_pc = after_prologue (pc, proc_desc);
800
801 if (after_prologue_pc == 0
802 || pc < after_prologue_pc)
803 return 1;
804 else
805 return 0;
806 }
807
808 static alpha_extra_func_info_t
809 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame)
810 {
811 alpha_extra_func_info_t proc_desc;
812 struct block *b;
813 struct symbol *sym;
814 CORE_ADDR startaddr;
815
816 /* Try to get the proc_desc from the linked call dummy proc_descs
817 if the pc is in the call dummy.
818 This is hairy. In the case of nested dummy calls we have to find the
819 right proc_desc, but we might not yet know the frame for the dummy
820 as it will be contained in the proc_desc we are searching for.
821 So we have to find the proc_desc whose frame is closest to the current
822 stack pointer. */
823
824 if (PC_IN_CALL_DUMMY (pc, 0, 0))
825 {
826 struct linked_proc_info *link;
827 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
828 alpha_extra_func_info_t found_proc_desc = NULL;
829 long min_distance = LONG_MAX;
830
831 for (link = linked_proc_desc_table; link; link = link->next)
832 {
833 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
834 if (distance > 0 && distance < min_distance)
835 {
836 min_distance = distance;
837 found_proc_desc = &link->info;
838 }
839 }
840 if (found_proc_desc != NULL)
841 return found_proc_desc;
842 }
843
844 b = block_for_pc (pc);
845
846 find_pc_partial_function (pc, NULL, &startaddr, NULL);
847 if (b == NULL)
848 sym = NULL;
849 else
850 {
851 if (startaddr > BLOCK_START (b))
852 /* This is the "pathological" case referred to in a comment in
853 print_frame_info. It might be better to move this check into
854 symbol reading. */
855 sym = NULL;
856 else
857 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
858 0, NULL);
859 }
860
861 /* If we never found a PDR for this function in symbol reading, then
862 examine prologues to find the information. */
863 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
864 sym = NULL;
865
866 if (sym)
867 {
868 /* IF this is the topmost frame AND
869 * (this proc does not have debugging information OR
870 * the PC is in the procedure prologue)
871 * THEN create a "heuristic" proc_desc (by analyzing
872 * the actual code) to replace the "official" proc_desc.
873 */
874 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
875 if (next_frame == NULL)
876 {
877 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
878 {
879 alpha_extra_func_info_t found_heuristic =
880 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
881 pc, next_frame);
882 if (found_heuristic)
883 {
884 PROC_LOCALOFF (found_heuristic) =
885 PROC_LOCALOFF (proc_desc);
886 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
887 proc_desc = found_heuristic;
888 }
889 }
890 }
891 }
892 else
893 {
894 long offset;
895
896 /* Is linked_proc_desc_table really necessary? It only seems to be used
897 by procedure call dummys. However, the procedures being called ought
898 to have their own proc_descs, and even if they don't,
899 heuristic_proc_desc knows how to create them! */
900
901 register struct linked_proc_info *link;
902 for (link = linked_proc_desc_table; link; link = link->next)
903 if (PROC_LOW_ADDR (&link->info) <= pc
904 && PROC_HIGH_ADDR (&link->info) > pc)
905 return &link->info;
906
907 /* If PC is inside a dynamically generated sigtramp handler,
908 create and push a procedure descriptor for that code: */
909 offset = alpha_dynamic_sigtramp_offset (pc);
910 if (offset >= 0)
911 return push_sigtramp_desc (pc - offset);
912
913 /* If heuristic_fence_post is non-zero, determine the procedure
914 start address by examining the instructions.
915 This allows us to find the start address of static functions which
916 have no symbolic information, as startaddr would have been set to
917 the preceding global function start address by the
918 find_pc_partial_function call above. */
919 if (startaddr == 0 || heuristic_fence_post != 0)
920 startaddr = heuristic_proc_start (pc);
921
922 proc_desc =
923 heuristic_proc_desc (startaddr, pc, next_frame);
924 }
925 return proc_desc;
926 }
927
928 alpha_extra_func_info_t cached_proc_desc;
929
930 static CORE_ADDR
931 alpha_frame_chain (struct frame_info *frame)
932 {
933 alpha_extra_func_info_t proc_desc;
934 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
935
936 if (saved_pc == 0 || inside_entry_file (saved_pc))
937 return 0;
938
939 proc_desc = find_proc_desc (saved_pc, frame);
940 if (!proc_desc)
941 return 0;
942
943 cached_proc_desc = proc_desc;
944
945 /* Fetch the frame pointer for a dummy frame from the procedure
946 descriptor. */
947 if (PROC_DESC_IS_DUMMY (proc_desc))
948 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
949
950 /* If no frame pointer and frame size is zero, we must be at end
951 of stack (or otherwise hosed). If we don't check frame size,
952 we loop forever if we see a zero size frame. */
953 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
954 && PROC_FRAME_OFFSET (proc_desc) == 0
955 /* The previous frame from a sigtramp frame might be frameless
956 and have frame size zero. */
957 && !frame->signal_handler_caller)
958 return alpha_frame_past_sigtramp_frame (frame, saved_pc);
959 else
960 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
961 + PROC_FRAME_OFFSET (proc_desc);
962 }
963
964 void
965 alpha_print_extra_frame_info (struct frame_info *fi)
966 {
967 if (fi
968 && fi->extra_info
969 && fi->extra_info->proc_desc
970 && fi->extra_info->proc_desc->pdr.framereg < NUM_REGS)
971 printf_filtered (" frame pointer is at %s+%s\n",
972 REGISTER_NAME (fi->extra_info->proc_desc->pdr.framereg),
973 paddr_d (fi->extra_info->proc_desc->pdr.frameoffset));
974 }
975
976 static void
977 alpha_init_extra_frame_info (int fromleaf, struct frame_info *frame)
978 {
979 /* Use proc_desc calculated in frame_chain */
980 alpha_extra_func_info_t proc_desc =
981 frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
982
983 frame->extra_info = (struct frame_extra_info *)
984 frame_obstack_alloc (sizeof (struct frame_extra_info));
985
986 frame->saved_regs = NULL;
987 frame->extra_info->localoff = 0;
988 frame->extra_info->pc_reg = ALPHA_RA_REGNUM;
989 frame->extra_info->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
990 if (proc_desc)
991 {
992 /* Get the locals offset and the saved pc register from the
993 procedure descriptor, they are valid even if we are in the
994 middle of the prologue. */
995 frame->extra_info->localoff = PROC_LOCALOFF (proc_desc);
996 frame->extra_info->pc_reg = PROC_PC_REG (proc_desc);
997
998 /* Fixup frame-pointer - only needed for top frame */
999
1000 /* Fetch the frame pointer for a dummy frame from the procedure
1001 descriptor. */
1002 if (PROC_DESC_IS_DUMMY (proc_desc))
1003 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
1004
1005 /* This may not be quite right, if proc has a real frame register.
1006 Get the value of the frame relative sp, procedure might have been
1007 interrupted by a signal at it's very start. */
1008 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
1009 && !alpha_proc_desc_is_dyn_sigtramp (proc_desc))
1010 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
1011 else
1012 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
1013 + PROC_FRAME_OFFSET (proc_desc);
1014
1015 if (proc_desc == &temp_proc_desc)
1016 {
1017 char *name;
1018
1019 /* Do not set the saved registers for a sigtramp frame,
1020 alpha_find_saved_registers will do that for us.
1021 We can't use frame->signal_handler_caller, it is not yet set. */
1022 find_pc_partial_function (frame->pc, &name,
1023 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
1024 if (!PC_IN_SIGTRAMP (frame->pc, name))
1025 {
1026 frame->saved_regs = (CORE_ADDR *)
1027 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
1028 memcpy (frame->saved_regs, temp_saved_regs,
1029 SIZEOF_FRAME_SAVED_REGS);
1030 frame->saved_regs[PC_REGNUM]
1031 = frame->saved_regs[ALPHA_RA_REGNUM];
1032 }
1033 }
1034 }
1035 }
1036
1037 static CORE_ADDR
1038 alpha_frame_locals_address (struct frame_info *fi)
1039 {
1040 return (fi->frame - fi->extra_info->localoff);
1041 }
1042
1043 static CORE_ADDR
1044 alpha_frame_args_address (struct frame_info *fi)
1045 {
1046 return (fi->frame - (ALPHA_NUM_ARG_REGS * 8));
1047 }
1048
1049 /* ALPHA stack frames are almost impenetrable. When execution stops,
1050 we basically have to look at symbol information for the function
1051 that we stopped in, which tells us *which* register (if any) is
1052 the base of the frame pointer, and what offset from that register
1053 the frame itself is at.
1054
1055 This presents a problem when trying to examine a stack in memory
1056 (that isn't executing at the moment), using the "frame" command. We
1057 don't have a PC, nor do we have any registers except SP.
1058
1059 This routine takes two arguments, SP and PC, and tries to make the
1060 cached frames look as if these two arguments defined a frame on the
1061 cache. This allows the rest of info frame to extract the important
1062 arguments without difficulty. */
1063
1064 struct frame_info *
1065 alpha_setup_arbitrary_frame (int argc, CORE_ADDR *argv)
1066 {
1067 if (argc != 2)
1068 error ("ALPHA frame specifications require two arguments: sp and pc");
1069
1070 return create_new_frame (argv[0], argv[1]);
1071 }
1072
1073 /* The alpha passes the first six arguments in the registers, the rest on
1074 the stack. The register arguments are eventually transferred to the
1075 argument transfer area immediately below the stack by the called function
1076 anyway. So we `push' at least six arguments on the stack, `reload' the
1077 argument registers and then adjust the stack pointer to point past the
1078 sixth argument. This algorithm simplifies the passing of a large struct
1079 which extends from the registers to the stack.
1080 If the called function is returning a structure, the address of the
1081 structure to be returned is passed as a hidden first argument. */
1082
1083 static CORE_ADDR
1084 alpha_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1085 int struct_return, CORE_ADDR struct_addr)
1086 {
1087 int i;
1088 int accumulate_size = struct_return ? 8 : 0;
1089 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
1090 struct alpha_arg
1091 {
1092 char *contents;
1093 int len;
1094 int offset;
1095 };
1096 struct alpha_arg *alpha_args =
1097 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
1098 register struct alpha_arg *m_arg;
1099 char raw_buffer[sizeof (CORE_ADDR)];
1100 int required_arg_regs;
1101
1102 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
1103 {
1104 struct value *arg = args[i];
1105 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1106 /* Cast argument to long if necessary as the compiler does it too. */
1107 switch (TYPE_CODE (arg_type))
1108 {
1109 case TYPE_CODE_INT:
1110 case TYPE_CODE_BOOL:
1111 case TYPE_CODE_CHAR:
1112 case TYPE_CODE_RANGE:
1113 case TYPE_CODE_ENUM:
1114 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
1115 {
1116 arg_type = builtin_type_long;
1117 arg = value_cast (arg_type, arg);
1118 }
1119 break;
1120 default:
1121 break;
1122 }
1123 m_arg->len = TYPE_LENGTH (arg_type);
1124 m_arg->offset = accumulate_size;
1125 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
1126 m_arg->contents = VALUE_CONTENTS (arg);
1127 }
1128
1129 /* Determine required argument register loads, loading an argument register
1130 is expensive as it uses three ptrace calls. */
1131 required_arg_regs = accumulate_size / 8;
1132 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
1133 required_arg_regs = ALPHA_NUM_ARG_REGS;
1134
1135 /* Make room for the arguments on the stack. */
1136 if (accumulate_size < arg_regs_size)
1137 accumulate_size = arg_regs_size;
1138 sp -= accumulate_size;
1139
1140 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
1141 sp &= ~15;
1142
1143 /* `Push' arguments on the stack. */
1144 for (i = nargs; m_arg--, --i >= 0;)
1145 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
1146 if (struct_return)
1147 {
1148 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
1149 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
1150 }
1151
1152 /* Load the argument registers. */
1153 for (i = 0; i < required_arg_regs; i++)
1154 {
1155 LONGEST val;
1156
1157 val = read_memory_integer (sp + i * 8, 8);
1158 write_register (ALPHA_A0_REGNUM + i, val);
1159 write_register (ALPHA_FPA0_REGNUM + i, val);
1160 }
1161
1162 return sp + arg_regs_size;
1163 }
1164
1165 static void
1166 alpha_push_dummy_frame (void)
1167 {
1168 int ireg;
1169 struct linked_proc_info *link;
1170 alpha_extra_func_info_t proc_desc;
1171 CORE_ADDR sp = read_register (SP_REGNUM);
1172 CORE_ADDR save_address;
1173 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
1174 unsigned long mask;
1175
1176 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
1177 link->next = linked_proc_desc_table;
1178 linked_proc_desc_table = link;
1179
1180 proc_desc = &link->info;
1181
1182 /*
1183 * The registers we must save are all those not preserved across
1184 * procedure calls.
1185 * In addition, we must save the PC and RA.
1186 *
1187 * Dummy frame layout:
1188 * (high memory)
1189 * Saved PC
1190 * Saved F30
1191 * ...
1192 * Saved F0
1193 * Saved R29
1194 * ...
1195 * Saved R0
1196 * Saved R26 (RA)
1197 * Parameter build area
1198 * (low memory)
1199 */
1200
1201 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1202 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1203 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1204 #define GEN_REG_SAVE_COUNT 24
1205 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1206 #define FLOAT_REG_SAVE_COUNT 23
1207 /* The special register is the PC as we have no bit for it in the save masks.
1208 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1209 #define SPECIAL_REG_SAVE_COUNT 1
1210
1211 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1212 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
1213 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1214 but keep SP aligned to a multiple of 16. */
1215 PROC_REG_OFFSET (proc_desc) =
1216 -((8 * (SPECIAL_REG_SAVE_COUNT
1217 + GEN_REG_SAVE_COUNT
1218 + FLOAT_REG_SAVE_COUNT)
1219 + 15) & ~15);
1220 PROC_FREG_OFFSET (proc_desc) =
1221 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1222
1223 /* Save general registers.
1224 The return address register is the first saved register, all other
1225 registers follow in ascending order.
1226 The PC is saved immediately below the SP. */
1227 save_address = sp + PROC_REG_OFFSET (proc_desc);
1228 store_address (raw_buffer, 8, read_register (ALPHA_RA_REGNUM));
1229 write_memory (save_address, raw_buffer, 8);
1230 save_address += 8;
1231 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
1232 for (ireg = 0; mask; ireg++, mask >>= 1)
1233 if (mask & 1)
1234 {
1235 if (ireg == ALPHA_RA_REGNUM)
1236 continue;
1237 store_address (raw_buffer, 8, read_register (ireg));
1238 write_memory (save_address, raw_buffer, 8);
1239 save_address += 8;
1240 }
1241
1242 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1243 write_memory (sp - 8, raw_buffer, 8);
1244
1245 /* Save floating point registers. */
1246 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1247 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
1248 for (ireg = 0; mask; ireg++, mask >>= 1)
1249 if (mask & 1)
1250 {
1251 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1252 write_memory (save_address, raw_buffer, 8);
1253 save_address += 8;
1254 }
1255
1256 /* Set and save the frame address for the dummy.
1257 This is tricky. The only registers that are suitable for a frame save
1258 are those that are preserved across procedure calls (s0-s6). But if
1259 a read system call is interrupted and then a dummy call is made
1260 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1261 is satisfied. Then it returns with the s0-s6 registers set to the values
1262 on entry to the read system call and our dummy frame pointer would be
1263 destroyed. So we save the dummy frame in the proc_desc and handle the
1264 retrieval of the frame pointer of a dummy specifically. The frame register
1265 is set to the virtual frame (pseudo) register, it's value will always
1266 be read as zero and will help us to catch any errors in the dummy frame
1267 retrieval code. */
1268 PROC_DUMMY_FRAME (proc_desc) = sp;
1269 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1270 PROC_FRAME_OFFSET (proc_desc) = 0;
1271 sp += PROC_REG_OFFSET (proc_desc);
1272 write_register (SP_REGNUM, sp);
1273
1274 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1275 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
1276
1277 SET_PROC_DESC_IS_DUMMY (proc_desc);
1278 PROC_PC_REG (proc_desc) = ALPHA_RA_REGNUM;
1279 }
1280
1281 static void
1282 alpha_pop_frame (void)
1283 {
1284 register int regnum;
1285 struct frame_info *frame = get_current_frame ();
1286 CORE_ADDR new_sp = frame->frame;
1287
1288 alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc;
1289
1290 /* we need proc_desc to know how to restore the registers;
1291 if it is NULL, construct (a temporary) one */
1292 if (proc_desc == NULL)
1293 proc_desc = find_proc_desc (frame->pc, frame->next);
1294
1295 /* Question: should we copy this proc_desc and save it in
1296 frame->proc_desc? If we do, who will free it?
1297 For now, we don't save a copy... */
1298
1299 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1300 if (frame->saved_regs == NULL)
1301 alpha_find_saved_regs (frame);
1302 if (proc_desc)
1303 {
1304 for (regnum = 32; --regnum >= 0;)
1305 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
1306 write_register (regnum,
1307 read_memory_integer (frame->saved_regs[regnum],
1308 8));
1309 for (regnum = 32; --regnum >= 0;)
1310 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
1311 write_register (regnum + FP0_REGNUM,
1312 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1313 }
1314 write_register (SP_REGNUM, new_sp);
1315 flush_cached_frames ();
1316
1317 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
1318 || alpha_proc_desc_is_dyn_sigtramp (proc_desc)))
1319 {
1320 struct linked_proc_info *pi_ptr, *prev_ptr;
1321
1322 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1323 pi_ptr != NULL;
1324 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1325 {
1326 if (&pi_ptr->info == proc_desc)
1327 break;
1328 }
1329
1330 if (pi_ptr == NULL)
1331 error ("Can't locate dummy extra frame info\n");
1332
1333 if (prev_ptr != NULL)
1334 prev_ptr->next = pi_ptr->next;
1335 else
1336 linked_proc_desc_table = pi_ptr->next;
1337
1338 xfree (pi_ptr);
1339 }
1340 }
1341 \f
1342 /* To skip prologues, I use this predicate. Returns either PC itself
1343 if the code at PC does not look like a function prologue; otherwise
1344 returns an address that (if we're lucky) follows the prologue. If
1345 LENIENT, then we must skip everything which is involved in setting
1346 up the frame (it's OK to skip more, just so long as we don't skip
1347 anything which might clobber the registers which are being saved.
1348 Currently we must not skip more on the alpha, but we might need the
1349 lenient stuff some day. */
1350
1351 static CORE_ADDR
1352 alpha_skip_prologue_internal (CORE_ADDR pc, int lenient)
1353 {
1354 unsigned long inst;
1355 int offset;
1356 CORE_ADDR post_prologue_pc;
1357 char buf[4];
1358
1359 /* Silently return the unaltered pc upon memory errors.
1360 This could happen on OSF/1 if decode_line_1 tries to skip the
1361 prologue for quickstarted shared library functions when the
1362 shared library is not yet mapped in.
1363 Reading target memory is slow over serial lines, so we perform
1364 this check only if the target has shared libraries (which all
1365 Alpha targets do). */
1366 if (target_read_memory (pc, buf, 4))
1367 return pc;
1368
1369 /* See if we can determine the end of the prologue via the symbol table.
1370 If so, then return either PC, or the PC after the prologue, whichever
1371 is greater. */
1372
1373 post_prologue_pc = after_prologue (pc, NULL);
1374
1375 if (post_prologue_pc != 0)
1376 return max (pc, post_prologue_pc);
1377
1378 /* Can't determine prologue from the symbol table, need to examine
1379 instructions. */
1380
1381 /* Skip the typical prologue instructions. These are the stack adjustment
1382 instruction and the instructions that save registers on the stack
1383 or in the gcc frame. */
1384 for (offset = 0; offset < 100; offset += 4)
1385 {
1386 int status;
1387
1388 status = read_memory_nobpt (pc + offset, buf, 4);
1389 if (status)
1390 memory_error (status, pc + offset);
1391 inst = extract_unsigned_integer (buf, 4);
1392
1393 /* The alpha has no delay slots. But let's keep the lenient stuff,
1394 we might need it for something else in the future. */
1395 if (lenient && 0)
1396 continue;
1397
1398 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1399 continue;
1400 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1401 continue;
1402 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1403 continue;
1404 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1405 continue;
1406
1407 if ((inst & 0xfc1f0000) == 0xb41e0000
1408 && (inst & 0xffff0000) != 0xb7fe0000)
1409 continue; /* stq reg,n($sp) */
1410 /* reg != $zero */
1411 if ((inst & 0xfc1f0000) == 0x9c1e0000
1412 && (inst & 0xffff0000) != 0x9ffe0000)
1413 continue; /* stt reg,n($sp) */
1414 /* reg != $zero */
1415 if (inst == 0x47de040f) /* bis sp,sp,fp */
1416 continue;
1417
1418 break;
1419 }
1420 return pc + offset;
1421 }
1422
1423 static CORE_ADDR
1424 alpha_skip_prologue (CORE_ADDR addr)
1425 {
1426 return (alpha_skip_prologue_internal (addr, 0));
1427 }
1428
1429 #if 0
1430 /* Is address PC in the prologue (loosely defined) for function at
1431 STARTADDR? */
1432
1433 static int
1434 alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc)
1435 {
1436 CORE_ADDR end_prologue = alpha_skip_prologue_internal (startaddr, 1);
1437 return pc >= startaddr && pc < end_prologue;
1438 }
1439 #endif
1440
1441 /* The alpha needs a conversion between register and memory format if
1442 the register is a floating point register and
1443 memory format is float, as the register format must be double
1444 or
1445 memory format is an integer with 4 bytes or less, as the representation
1446 of integers in floating point registers is different. */
1447 static void
1448 alpha_register_convert_to_virtual (int regnum, struct type *valtype,
1449 char *raw_buffer, char *virtual_buffer)
1450 {
1451 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1452 {
1453 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1454 return;
1455 }
1456
1457 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1458 {
1459 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1460 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1461 }
1462 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1463 {
1464 ULONGEST l;
1465 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1466 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1467 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1468 }
1469 else
1470 error ("Cannot retrieve value from floating point register");
1471 }
1472
1473 static void
1474 alpha_register_convert_to_raw (struct type *valtype, int regnum,
1475 char *virtual_buffer, char *raw_buffer)
1476 {
1477 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1478 {
1479 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1480 return;
1481 }
1482
1483 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1484 {
1485 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1486 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1487 }
1488 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1489 {
1490 ULONGEST l;
1491 if (TYPE_UNSIGNED (valtype))
1492 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1493 else
1494 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1495 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1496 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1497 }
1498 else
1499 error ("Cannot store value in floating point register");
1500 }
1501
1502 static const unsigned char *
1503 alpha_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1504 {
1505 static const unsigned char alpha_breakpoint[] =
1506 { 0x80, 0, 0, 0 }; /* call_pal bpt */
1507
1508 *lenptr = sizeof(alpha_breakpoint);
1509 return (alpha_breakpoint);
1510 }
1511
1512 /* Given a return value in `regbuf' with a type `valtype',
1513 extract and copy its value into `valbuf'. */
1514
1515 static void
1516 alpha_extract_return_value (struct type *valtype,
1517 char regbuf[REGISTER_BYTES], char *valbuf)
1518 {
1519 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1520 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1521 regbuf + REGISTER_BYTE (FP0_REGNUM),
1522 valbuf);
1523 else
1524 memcpy (valbuf, regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM),
1525 TYPE_LENGTH (valtype));
1526 }
1527
1528 /* Given a return value in `regbuf' with a type `valtype',
1529 write its value into the appropriate register. */
1530
1531 static void
1532 alpha_store_return_value (struct type *valtype, char *valbuf)
1533 {
1534 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
1535 int regnum = ALPHA_V0_REGNUM;
1536 int length = TYPE_LENGTH (valtype);
1537
1538 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1539 {
1540 regnum = FP0_REGNUM;
1541 length = REGISTER_RAW_SIZE (regnum);
1542 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1543 }
1544 else
1545 memcpy (raw_buffer, valbuf, length);
1546
1547 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1548 }
1549
1550 /* Just like reinit_frame_cache, but with the right arguments to be
1551 callable as an sfunc. */
1552
1553 static void
1554 reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
1555 {
1556 reinit_frame_cache ();
1557 }
1558
1559 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1560 to find a convenient place in the text segment to stick a breakpoint to
1561 detect the completion of a target function call (ala call_function_by_hand).
1562 */
1563
1564 CORE_ADDR
1565 alpha_call_dummy_address (void)
1566 {
1567 CORE_ADDR entry;
1568 struct minimal_symbol *sym;
1569
1570 entry = entry_point_address ();
1571
1572 if (entry != 0)
1573 return entry;
1574
1575 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1576
1577 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1578 return 0;
1579 else
1580 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1581 }
1582
1583 static void
1584 alpha_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1585 struct value **args, struct type *type, int gcc_p)
1586 {
1587 CORE_ADDR bp_address = CALL_DUMMY_ADDRESS ();
1588
1589 if (bp_address == 0)
1590 error ("no place to put call");
1591 write_register (ALPHA_RA_REGNUM, bp_address);
1592 write_register (ALPHA_T12_REGNUM, fun);
1593 }
1594
1595 /* On the Alpha, the call dummy code is nevery copied to user space
1596 (see alpha_fix_call_dummy() above). The contents of this do not
1597 matter. */
1598 LONGEST alpha_call_dummy_words[] = { 0 };
1599
1600 static int
1601 alpha_use_struct_convention (int gcc_p, struct type *type)
1602 {
1603 /* Structures are returned by ref in extra arg0. */
1604 return 1;
1605 }
1606
1607 static void
1608 alpha_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1609 {
1610 /* Store the address of the place in which to copy the structure the
1611 subroutine will return. Handled by alpha_push_arguments. */
1612 }
1613
1614 static CORE_ADDR
1615 alpha_extract_struct_value_address (char *regbuf)
1616 {
1617 return (extract_address (regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM),
1618 REGISTER_RAW_SIZE (ALPHA_V0_REGNUM)));
1619 }
1620
1621 /* Figure out where the longjmp will land.
1622 We expect the first arg to be a pointer to the jmp_buf structure from
1623 which we extract the PC (JB_PC) that we will land at. The PC is copied
1624 into the "pc". This routine returns true on success. */
1625
1626 static int
1627 alpha_get_longjmp_target (CORE_ADDR *pc)
1628 {
1629 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1630 CORE_ADDR jb_addr;
1631 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
1632
1633 jb_addr = read_register (ALPHA_A0_REGNUM);
1634
1635 if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size),
1636 raw_buffer, tdep->jb_elt_size))
1637 return 0;
1638
1639 *pc = extract_address (raw_buffer, tdep->jb_elt_size);
1640 return 1;
1641 }
1642
1643 /* alpha_software_single_step() is called just before we want to resume
1644 the inferior, if we want to single-step it but there is no hardware
1645 or kernel single-step support (NetBSD on Alpha, for example). We find
1646 the target of the coming instruction and breakpoint it.
1647
1648 single_step is also called just after the inferior stops. If we had
1649 set up a simulated single-step, we undo our damage. */
1650
1651 static CORE_ADDR
1652 alpha_next_pc (CORE_ADDR pc)
1653 {
1654 unsigned int insn;
1655 unsigned int op;
1656 int offset;
1657 LONGEST rav;
1658
1659 insn = read_memory_unsigned_integer (pc, sizeof (insn));
1660
1661 /* Opcode is top 6 bits. */
1662 op = (insn >> 26) & 0x3f;
1663
1664 if (op == 0x1a)
1665 {
1666 /* Jump format: target PC is:
1667 RB & ~3 */
1668 return (read_register ((insn >> 16) & 0x1f) & ~3);
1669 }
1670
1671 if ((op & 0x30) == 0x30)
1672 {
1673 /* Branch format: target PC is:
1674 (new PC) + (4 * sext(displacement)) */
1675 if (op == 0x30 || /* BR */
1676 op == 0x34) /* BSR */
1677 {
1678 branch_taken:
1679 offset = (insn & 0x001fffff);
1680 if (offset & 0x00100000)
1681 offset |= 0xffe00000;
1682 offset *= 4;
1683 return (pc + 4 + offset);
1684 }
1685
1686 /* Need to determine if branch is taken; read RA. */
1687 rav = (LONGEST) read_register ((insn >> 21) & 0x1f);
1688 switch (op)
1689 {
1690 case 0x38: /* BLBC */
1691 if ((rav & 1) == 0)
1692 goto branch_taken;
1693 break;
1694 case 0x3c: /* BLBS */
1695 if (rav & 1)
1696 goto branch_taken;
1697 break;
1698 case 0x39: /* BEQ */
1699 if (rav == 0)
1700 goto branch_taken;
1701 break;
1702 case 0x3d: /* BNE */
1703 if (rav != 0)
1704 goto branch_taken;
1705 break;
1706 case 0x3a: /* BLT */
1707 if (rav < 0)
1708 goto branch_taken;
1709 break;
1710 case 0x3b: /* BLE */
1711 if (rav <= 0)
1712 goto branch_taken;
1713 break;
1714 case 0x3f: /* BGT */
1715 if (rav > 0)
1716 goto branch_taken;
1717 break;
1718 case 0x3e: /* BGE */
1719 if (rav >= 0)
1720 goto branch_taken;
1721 break;
1722 }
1723 }
1724
1725 /* Not a branch or branch not taken; target PC is:
1726 pc + 4 */
1727 return (pc + 4);
1728 }
1729
1730 void
1731 alpha_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1732 {
1733 static CORE_ADDR next_pc;
1734 typedef char binsn_quantum[BREAKPOINT_MAX];
1735 static binsn_quantum break_mem;
1736 CORE_ADDR pc;
1737
1738 if (insert_breakpoints_p)
1739 {
1740 pc = read_pc ();
1741 next_pc = alpha_next_pc (pc);
1742
1743 target_insert_breakpoint (next_pc, break_mem);
1744 }
1745 else
1746 {
1747 target_remove_breakpoint (next_pc, break_mem);
1748 write_pc (next_pc);
1749 }
1750 }
1751
1752 \f
1753 /* This table matches the indices assigned to enum alpha_abi. Keep
1754 them in sync. */
1755 static const char * const alpha_abi_names[] =
1756 {
1757 "<unknown>",
1758 "OSF/1",
1759 "GNU/Linux",
1760 "FreeBSD",
1761 "NetBSD",
1762 NULL
1763 };
1764
1765 static void
1766 process_note_abi_tag_sections (bfd *abfd, asection *sect, void *obj)
1767 {
1768 enum alpha_abi *os_ident_ptr = obj;
1769 const char *name;
1770 unsigned int sectsize;
1771
1772 name = bfd_get_section_name (abfd, sect);
1773 sectsize = bfd_section_size (abfd, sect);
1774
1775 if (strcmp (name, ".note.ABI-tag") == 0 && sectsize > 0)
1776 {
1777 unsigned int name_length, data_length, note_type;
1778 char *note;
1779
1780 /* If the section is larger than this, it's probably not what we are
1781 looking for. */
1782 if (sectsize > 128)
1783 sectsize = 128;
1784
1785 note = alloca (sectsize);
1786
1787 bfd_get_section_contents (abfd, sect, note,
1788 (file_ptr) 0, (bfd_size_type) sectsize);
1789
1790 name_length = bfd_h_get_32 (abfd, note);
1791 data_length = bfd_h_get_32 (abfd, note + 4);
1792 note_type = bfd_h_get_32 (abfd, note + 8);
1793
1794 if (name_length == 4 && data_length == 16 && note_type == 1
1795 && strcmp (note + 12, "GNU") == 0)
1796 {
1797 int os_number = bfd_h_get_32 (abfd, note + 16);
1798
1799 /* The case numbers are from abi-tags in glibc. */
1800 switch (os_number)
1801 {
1802 case 0 :
1803 *os_ident_ptr = ALPHA_ABI_LINUX;
1804 break;
1805
1806 case 1 :
1807 internal_error
1808 (__FILE__, __LINE__,
1809 "process_note_abi_sections: Hurd objects not supported");
1810 break;
1811
1812 case 2 :
1813 internal_error
1814 (__FILE__, __LINE__,
1815 "process_note_abi_sections: Solaris objects not supported");
1816 break;
1817
1818 default :
1819 internal_error
1820 (__FILE__, __LINE__,
1821 "process_note_abi_sections: unknown OS number %d",
1822 os_number);
1823 break;
1824 }
1825 }
1826 }
1827 /* NetBSD uses a similar trick. */
1828 else if (strcmp (name, ".note.netbsd.ident") == 0 && sectsize > 0)
1829 {
1830 unsigned int name_length, desc_length, note_type;
1831 char *note;
1832
1833 /* If the section is larger than this, it's probably not what we are
1834 looking for. */
1835 if (sectsize > 128)
1836 sectsize = 128;
1837
1838 note = alloca (sectsize);
1839
1840 bfd_get_section_contents (abfd, sect, note,
1841 (file_ptr) 0, (bfd_size_type) sectsize);
1842
1843 name_length = bfd_h_get_32 (abfd, note);
1844 desc_length = bfd_h_get_32 (abfd, note + 4);
1845 note_type = bfd_h_get_32 (abfd, note + 8);
1846
1847 if (name_length == 7 && desc_length == 4 && note_type == 1
1848 && strcmp (note + 12, "NetBSD") == 0)
1849 /* XXX Should we check the version here?
1850 Probably not necessary yet. */
1851 *os_ident_ptr = ALPHA_ABI_NETBSD;
1852 }
1853 }
1854
1855 static int
1856 get_elfosabi (bfd *abfd)
1857 {
1858 int elfosabi;
1859 enum alpha_abi alpha_abi = ALPHA_ABI_UNKNOWN;
1860
1861 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
1862
1863 /* When elfosabi is 0 (ELFOSABI_NONE), this is supposed to indicate
1864 what we're on a SYSV system. However, GNU/Linux uses a note section
1865 to record OS/ABI info, but leaves e_ident[EI_OSABI] zero. So we
1866 have to check the note sections too. */
1867 if (elfosabi == 0)
1868 {
1869 bfd_map_over_sections (abfd,
1870 process_note_abi_tag_sections,
1871 &alpha_abi);
1872 }
1873
1874 if (alpha_abi != ALPHA_ABI_UNKNOWN)
1875 return alpha_abi;
1876
1877 switch (elfosabi)
1878 {
1879 case ELFOSABI_NONE:
1880 /* Leave it as unknown. */
1881 break;
1882
1883 case ELFOSABI_NETBSD:
1884 return ALPHA_ABI_NETBSD;
1885
1886 case ELFOSABI_FREEBSD:
1887 return ALPHA_ABI_FREEBSD;
1888
1889 case ELFOSABI_LINUX:
1890 return ALPHA_ABI_LINUX;
1891 }
1892
1893 return ALPHA_ABI_UNKNOWN;
1894 }
1895
1896 struct alpha_abi_handler
1897 {
1898 struct alpha_abi_handler *next;
1899 enum alpha_abi abi;
1900 void (*init_abi)(struct gdbarch_info, struct gdbarch *);
1901 };
1902
1903 struct alpha_abi_handler *alpha_abi_handler_list = NULL;
1904
1905 void
1906 alpha_gdbarch_register_os_abi (enum alpha_abi abi,
1907 void (*init_abi)(struct gdbarch_info,
1908 struct gdbarch *))
1909 {
1910 struct alpha_abi_handler **handler_p;
1911
1912 for (handler_p = &alpha_abi_handler_list; *handler_p != NULL;
1913 handler_p = &(*handler_p)->next)
1914 {
1915 if ((*handler_p)->abi == abi)
1916 {
1917 internal_error
1918 (__FILE__, __LINE__,
1919 "alpha_gdbarch_register_os_abi: A handler for this ABI variant "
1920 "(%d) has already been registered", (int) abi);
1921 /* If user wants to continue, override previous definition. */
1922 (*handler_p)->init_abi = init_abi;
1923 return;
1924 }
1925 }
1926
1927 (*handler_p)
1928 = (struct alpha_abi_handler *) xmalloc (sizeof (struct alpha_abi_handler));
1929 (*handler_p)->next = NULL;
1930 (*handler_p)->abi = abi;
1931 (*handler_p)->init_abi = init_abi;
1932 }
1933
1934 /* Initialize the current architecture based on INFO. If possible, re-use an
1935 architecture from ARCHES, which is a list of architectures already created
1936 during this debugging session.
1937
1938 Called e.g. at program startup, when reading a core file, and when reading
1939 a binary file. */
1940
1941 static struct gdbarch *
1942 alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1943 {
1944 struct gdbarch_tdep *tdep;
1945 struct gdbarch *gdbarch;
1946 enum alpha_abi alpha_abi = ALPHA_ABI_UNKNOWN;
1947 struct alpha_abi_handler *abi_handler;
1948
1949 /* Try to determine the ABI of the object we are loading. */
1950
1951 if (info.abfd != NULL)
1952 {
1953 switch (bfd_get_flavour (info.abfd))
1954 {
1955 case bfd_target_elf_flavour:
1956 alpha_abi = get_elfosabi (info.abfd);
1957 break;
1958
1959 case bfd_target_ecoff_flavour:
1960 /* Assume it's OSF/1. */
1961 alpha_abi = ALPHA_ABI_OSF1;
1962 break;
1963
1964 default:
1965 /* Not sure what to do here, leave the ABI as unknown. */
1966 break;
1967 }
1968 }
1969
1970 /* Find a candidate among extant architectures. */
1971 for (arches = gdbarch_list_lookup_by_info (arches, &info);
1972 arches != NULL;
1973 arches = gdbarch_list_lookup_by_info (arches->next, &info))
1974 {
1975 /* Make sure the ABI selection matches. */
1976 tdep = gdbarch_tdep (arches->gdbarch);
1977 if (tdep && tdep->alpha_abi == alpha_abi)
1978 return arches->gdbarch;
1979 }
1980
1981 tdep = xmalloc (sizeof (struct gdbarch_tdep));
1982 gdbarch = gdbarch_alloc (&info, tdep);
1983
1984 tdep->alpha_abi = alpha_abi;
1985 if (alpha_abi < ALPHA_ABI_INVALID)
1986 tdep->abi_name = alpha_abi_names[alpha_abi];
1987 else
1988 {
1989 internal_error (__FILE__, __LINE__, "Invalid setting of alpha_abi %d",
1990 (int) alpha_abi);
1991 tdep->abi_name = "<invalid>";
1992 }
1993
1994 /* Lowest text address. This is used by heuristic_proc_start() to
1995 decide when to stop looking. */
1996 tdep->vm_min_address = (CORE_ADDR) 0x120000000;
1997
1998 tdep->dynamic_sigtramp_offset = NULL;
1999 tdep->skip_sigtramp_frame = NULL;
2000
2001 tdep->jb_pc = -1; /* longjmp support not enabled by default */
2002
2003 /* Type sizes */
2004 set_gdbarch_short_bit (gdbarch, 16);
2005 set_gdbarch_int_bit (gdbarch, 32);
2006 set_gdbarch_long_bit (gdbarch, 64);
2007 set_gdbarch_long_long_bit (gdbarch, 64);
2008 set_gdbarch_float_bit (gdbarch, 32);
2009 set_gdbarch_double_bit (gdbarch, 64);
2010 set_gdbarch_long_double_bit (gdbarch, 64);
2011 set_gdbarch_ptr_bit (gdbarch, 64);
2012
2013 /* Register info */
2014 set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS);
2015 set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM);
2016 set_gdbarch_fp_regnum (gdbarch, ALPHA_FP_REGNUM);
2017 set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM);
2018 set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM);
2019
2020 set_gdbarch_register_name (gdbarch, alpha_register_name);
2021 set_gdbarch_register_size (gdbarch, ALPHA_REGISTER_SIZE);
2022 set_gdbarch_register_bytes (gdbarch, ALPHA_REGISTER_BYTES);
2023 set_gdbarch_register_byte (gdbarch, alpha_register_byte);
2024 set_gdbarch_register_raw_size (gdbarch, alpha_register_raw_size);
2025 set_gdbarch_max_register_raw_size (gdbarch, ALPHA_MAX_REGISTER_RAW_SIZE);
2026 set_gdbarch_register_virtual_size (gdbarch, alpha_register_virtual_size);
2027 set_gdbarch_max_register_virtual_size (gdbarch,
2028 ALPHA_MAX_REGISTER_VIRTUAL_SIZE);
2029 set_gdbarch_register_virtual_type (gdbarch, alpha_register_virtual_type);
2030
2031 set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register);
2032 set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register);
2033
2034 set_gdbarch_register_convertible (gdbarch, alpha_register_convertible);
2035 set_gdbarch_register_convert_to_virtual (gdbarch,
2036 alpha_register_convert_to_virtual);
2037 set_gdbarch_register_convert_to_raw (gdbarch, alpha_register_convert_to_raw);
2038
2039 set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue);
2040
2041 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
2042 set_gdbarch_frameless_function_invocation (gdbarch,
2043 generic_frameless_function_invocation_not);
2044
2045 set_gdbarch_saved_pc_after_call (gdbarch, alpha_saved_pc_after_call);
2046
2047 set_gdbarch_frame_chain (gdbarch, alpha_frame_chain);
2048 set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
2049 set_gdbarch_frame_saved_pc (gdbarch, alpha_frame_saved_pc);
2050
2051 set_gdbarch_frame_init_saved_regs (gdbarch, alpha_frame_init_saved_regs);
2052 set_gdbarch_get_saved_register (gdbarch, alpha_get_saved_register);
2053
2054 set_gdbarch_use_struct_convention (gdbarch, alpha_use_struct_convention);
2055 set_gdbarch_extract_return_value (gdbarch, alpha_extract_return_value);
2056
2057 set_gdbarch_store_struct_return (gdbarch, alpha_store_struct_return);
2058 set_gdbarch_store_return_value (gdbarch, alpha_store_return_value);
2059 set_gdbarch_extract_struct_value_address (gdbarch,
2060 alpha_extract_struct_value_address);
2061
2062 /* Settings for calling functions in the inferior. */
2063 set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
2064 set_gdbarch_call_dummy_length (gdbarch, 0);
2065 set_gdbarch_push_arguments (gdbarch, alpha_push_arguments);
2066 set_gdbarch_pop_frame (gdbarch, alpha_pop_frame);
2067
2068 /* On the Alpha, the call dummy code is never copied to user space,
2069 stopping the user call is achieved via a bp_call_dummy breakpoint.
2070 But we need a fake CALL_DUMMY definition to enable the proper
2071 call_function_by_hand and to avoid zero length array warnings. */
2072 set_gdbarch_call_dummy_p (gdbarch, 1);
2073 set_gdbarch_call_dummy_words (gdbarch, alpha_call_dummy_words);
2074 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
2075 set_gdbarch_frame_args_address (gdbarch, alpha_frame_args_address);
2076 set_gdbarch_frame_locals_address (gdbarch, alpha_frame_locals_address);
2077 set_gdbarch_init_extra_frame_info (gdbarch, alpha_init_extra_frame_info);
2078
2079 /* Alpha OSF/1 inhibits execution of code on the stack. But there is
2080 no need for a dummy on the Alpha. PUSH_ARGUMENTS takes care of all
2081 argument handling and bp_call_dummy takes care of stopping the dummy. */
2082 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
2083 set_gdbarch_call_dummy_address (gdbarch, alpha_call_dummy_address);
2084 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
2085 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
2086 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
2087 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point);
2088 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
2089 set_gdbarch_push_dummy_frame (gdbarch, alpha_push_dummy_frame);
2090 set_gdbarch_fix_call_dummy (gdbarch, alpha_fix_call_dummy);
2091 set_gdbarch_init_frame_pc (gdbarch, init_frame_pc_noop);
2092 set_gdbarch_init_frame_pc_first (gdbarch, alpha_init_frame_pc_first);
2093
2094 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2095 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
2096
2097 /* Floats are always passed as doubles. */
2098 set_gdbarch_coerce_float_to_double (gdbarch,
2099 standard_coerce_float_to_double);
2100
2101 set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc);
2102 set_gdbarch_decr_pc_after_break (gdbarch, 4);
2103
2104 set_gdbarch_function_start_offset (gdbarch, 0);
2105 set_gdbarch_frame_args_skip (gdbarch, 0);
2106
2107 /* Hook in ABI-specific overrides, if they have been registered. */
2108 if (alpha_abi == ALPHA_ABI_UNKNOWN)
2109 {
2110 /* Don't complain about not knowing the ABI variant if we don't
2111 have an inferior. */
2112 if (info.abfd)
2113 fprintf_filtered
2114 (gdb_stderr, "GDB doesn't recognize the ABI of the inferior. "
2115 "Attempting to continue with the default Alpha settings");
2116 }
2117 else
2118 {
2119 for (abi_handler = alpha_abi_handler_list; abi_handler != NULL;
2120 abi_handler = abi_handler->next)
2121 if (abi_handler->abi == alpha_abi)
2122 break;
2123
2124 if (abi_handler)
2125 abi_handler->init_abi (info, gdbarch);
2126 else
2127 {
2128 /* We assume that if GDB_MULTI_ARCH is less than
2129 GDB_MULTI_ARCH_TM that an ABI variant can be supported by
2130 overriding definitions in this file. */
2131 if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL)
2132 fprintf_filtered
2133 (gdb_stderr,
2134 "A handler for the ABI variant \"%s\" is not built into this "
2135 "configuration of GDB. "
2136 "Attempting to continue with the default Alpha settings",
2137 alpha_abi_names[alpha_abi]);
2138 }
2139 }
2140
2141 /* Now that we have tuned the configuration, set a few final things
2142 based on what the OS ABI has told us. */
2143
2144 if (tdep->jb_pc >= 0)
2145 set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target);
2146
2147 return gdbarch;
2148 }
2149
2150 static void
2151 alpha_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
2152 {
2153 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2154
2155 if (tdep == NULL)
2156 return;
2157
2158 if (tdep->abi_name != NULL)
2159 fprintf_unfiltered (file, "alpha_dump_tdep: ABI = %s\n", tdep->abi_name);
2160 else
2161 internal_error (__FILE__, __LINE__,
2162 "alpha_dump_tdep: illegal setting of tdep->alpha_abi (%d)",
2163 (int) tdep->alpha_abi);
2164
2165 fprintf_unfiltered (file,
2166 "alpha_dump_tdep: vm_min_address = 0x%lx\n",
2167 (long) tdep->vm_min_address);
2168
2169 fprintf_unfiltered (file,
2170 "alpha_dump_tdep: jb_pc = %d\n",
2171 tdep->jb_pc);
2172 fprintf_unfiltered (file,
2173 "alpha_dump_tdep: jb_elt_size = %ld\n",
2174 (long) tdep->jb_elt_size);
2175 }
2176
2177 void
2178 _initialize_alpha_tdep (void)
2179 {
2180 struct cmd_list_element *c;
2181
2182 gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, alpha_dump_tdep);
2183
2184 tm_print_insn = print_insn_alpha;
2185
2186 /* Let the user set the fence post for heuristic_proc_start. */
2187
2188 /* We really would like to have both "0" and "unlimited" work, but
2189 command.c doesn't deal with that. So make it a var_zinteger
2190 because the user can always use "999999" or some such for unlimited. */
2191 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
2192 (char *) &heuristic_fence_post,
2193 "\
2194 Set the distance searched for the start of a function.\n\
2195 If you are debugging a stripped executable, GDB needs to search through the\n\
2196 program for the start of a function. This command sets the distance of the\n\
2197 search. The only need to set it is when debugging a stripped executable.",
2198 &setlist);
2199 /* We need to throw away the frame cache when we set this, since it
2200 might change our ability to get backtraces. */
2201 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
2202 add_show_from_set (c, &showlist);
2203 }
This page took 0.18231 seconds and 5 git commands to generate.