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