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.
5 This file is part of GDB.
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.
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.
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. */
32 #include "gdb_string.h"
37 struct frame_extra_info
39 alpha_extra_func_info_t proc_desc;
44 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
46 /* Prototypes for local functions. */
48 static void alpha_find_saved_regs (struct frame_info *);
50 static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
52 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
54 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
56 static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
60 static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
64 static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
67 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
69 static CORE_ADDR after_prologue (CORE_ADDR pc,
70 alpha_extra_func_info_t proc_desc);
72 static int alpha_in_prologue (CORE_ADDR pc,
73 alpha_extra_func_info_t proc_desc);
75 static int alpha_about_to_return (CORE_ADDR pc);
77 void _initialize_alpha_tdep (void);
79 /* Heuristic_proc_start may hunt through the text section for a long
80 time across a 2400 baud serial line. Allows the user to limit this
82 static unsigned int heuristic_fence_post = 0;
84 /* Layout of a stack frame on the alpha:
87 pdr members: | 7th ... nth arg, |
88 | `pushed' by caller. |
90 ----------------|-------------------------------|<-- old_sp == vfp
93 | |localoff | Copies of 1st .. 6th |
94 | | | | | argument if necessary. |
96 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
98 | | | | Locals and temporaries. |
100 | | | |-------------------------------|
102 |-fregoffset | Saved float registers. |
108 | | -------|-------------------------------|
110 | | | Saved registers. |
117 | ----------|-------------------------------|
119 frameoffset | Argument build area, gets |
120 | | 7th ... nth arg for any |
121 | | called procedure. |
123 -------------|-------------------------------|<-- sp
130 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
131 /* These next two fields are kind of being hijacked. I wonder if
132 iline is too small for the values it needs to hold, if GDB is
133 running on a 32-bit host. */
134 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
135 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
136 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
137 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
138 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
139 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
140 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
141 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
142 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
143 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
144 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
145 #define _PROC_MAGIC_ 0x0F0F0F0F
146 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
147 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
149 struct linked_proc_info
151 struct alpha_extra_func_info info;
152 struct linked_proc_info *next;
154 *linked_proc_desc_table = NULL;
157 alpha_osf_in_sigtramp (CORE_ADDR pc, char *func_name)
159 return (func_name != NULL && STREQ ("__sigtramp", func_name));
162 /* Under GNU/Linux, signal handler invocations can be identified by the
163 designated code sequence that is used to return from a signal
164 handler. In particular, the return address of a signal handler
165 points to the following sequence (the first instruction is quadword
172 Each instruction has a unique encoding, so we simply attempt to
173 match the instruction the pc is pointing to with any of the above
174 instructions. If there is a hit, we know the offset to the start
175 of the designated sequence and can then check whether we really are
176 executing in a designated sequence. If not, -1 is returned,
177 otherwise the offset from the start of the desingated sequence is
180 There is a slight chance of false hits: code could jump into the
181 middle of the designated sequence, in which case there is no
182 guarantee that we are in the middle of a sigreturn syscall. Don't
183 think this will be a problem in praxis, though.
186 #ifndef TM_LINUXALPHA_H
187 /* HACK: Provide a prototype when compiling this file for non
188 linuxalpha targets. */
189 long alpha_linux_sigtramp_offset (CORE_ADDR pc);
192 alpha_linux_sigtramp_offset (CORE_ADDR pc)
194 unsigned int i[3], w;
197 if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
205 break; /* bis $30,$30,$16 */
208 break; /* addq $31,0x67,$0 */
211 break; /* call_pal callsys */
218 /* designated sequence is not quadword aligned */
222 if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
225 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
232 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
233 size of zero, but we are able to backtrace through it. */
235 alpha_osf_skip_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc)
238 find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
239 if (IN_SIGTRAMP (pc, name))
246 /* Dynamically create a signal-handler caller procedure descriptor for
247 the signal-handler return code starting at address LOW_ADDR. The
248 descriptor is added to the linked_proc_desc_table. */
250 static alpha_extra_func_info_t
251 push_sigtramp_desc (CORE_ADDR low_addr)
253 struct linked_proc_info *link;
254 alpha_extra_func_info_t proc_desc;
256 link = (struct linked_proc_info *)
257 xmalloc (sizeof (struct linked_proc_info));
258 link->next = linked_proc_desc_table;
259 linked_proc_desc_table = link;
261 proc_desc = &link->info;
263 proc_desc->numargs = 0;
264 PROC_LOW_ADDR (proc_desc) = low_addr;
265 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
266 PROC_DUMMY_FRAME (proc_desc) = 0;
267 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
268 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
269 PROC_REG_MASK (proc_desc) = 0xffff;
270 PROC_FREG_MASK (proc_desc) = 0xffff;
271 PROC_PC_REG (proc_desc) = 26;
272 PROC_LOCALOFF (proc_desc) = 0;
273 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
279 alpha_register_name (int regno)
281 static char *register_names[] =
283 "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
284 "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
285 "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
286 "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero",
287 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
288 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
289 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
290 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr",
296 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
298 return (register_names[regno]);
302 alpha_cannot_fetch_register (int regno)
304 return (regno == FP_REGNUM || regno == ZERO_REGNUM);
308 alpha_cannot_store_register (int regno)
310 return (regno == FP_REGNUM || regno == ZERO_REGNUM);
314 alpha_register_convertible (int regno)
316 return (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31);
320 alpha_register_virtual_type (int regno)
322 return ((regno >= FP0_REGNUM && regno < (FP0_REGNUM+31))
323 ? builtin_type_double : builtin_type_long);
327 alpha_register_byte (int regno)
333 alpha_register_raw_size (int regno)
339 alpha_register_virtual_size (int regno)
345 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
349 alpha_find_saved_regs (struct frame_info *frame)
352 CORE_ADDR reg_position;
354 alpha_extra_func_info_t proc_desc;
357 frame_saved_regs_zalloc (frame);
359 /* If it is the frame for __sigtramp, the saved registers are located
360 in a sigcontext structure somewhere on the stack. __sigtramp
361 passes a pointer to the sigcontext structure on the stack.
362 If the stack layout for __sigtramp changes, or if sigcontext offsets
363 change, we might have to update this code. */
364 #ifndef SIGFRAME_PC_OFF
365 #define SIGFRAME_PC_OFF (2 * 8)
366 #define SIGFRAME_REGSAVE_OFF (4 * 8)
367 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
369 if (frame->signal_handler_caller)
371 CORE_ADDR sigcontext_addr;
373 sigcontext_addr = SIGCONTEXT_ADDR (frame);
374 for (ireg = 0; ireg < 32; ireg++)
376 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
377 frame->saved_regs[ireg] = reg_position;
379 for (ireg = 0; ireg < 32; ireg++)
381 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
382 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
384 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
388 proc_desc = frame->extra_info->proc_desc;
389 if (proc_desc == NULL)
390 /* I'm not sure how/whether this can happen. Normally when we can't
391 find a proc_desc, we "synthesize" one using heuristic_proc_desc
392 and set the saved_regs right away. */
395 /* Fill in the offsets for the registers which gen_mask says
398 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
399 mask = PROC_REG_MASK (proc_desc);
401 returnreg = PROC_PC_REG (proc_desc);
403 /* Note that RA is always saved first, regardless of its actual
405 if (mask & (1 << returnreg))
407 frame->saved_regs[returnreg] = reg_position;
409 mask &= ~(1 << returnreg); /* Clear bit for RA so we
410 don't save again later. */
413 for (ireg = 0; ireg <= 31; ++ireg)
414 if (mask & (1 << ireg))
416 frame->saved_regs[ireg] = reg_position;
420 /* Fill in the offsets for the registers which float_mask says
423 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
424 mask = PROC_FREG_MASK (proc_desc);
426 for (ireg = 0; ireg <= 31; ++ireg)
427 if (mask & (1 << ireg))
429 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
433 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
437 alpha_frame_init_saved_regs (struct frame_info *fi)
439 if (fi->saved_regs == NULL)
440 alpha_find_saved_regs (fi);
441 fi->saved_regs[SP_REGNUM] = fi->frame;
445 alpha_init_frame_pc_first (int fromleaf, struct frame_info *prev)
447 prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) :
448 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
452 read_next_frame_reg (struct frame_info *fi, int regno)
454 for (; fi; fi = fi->next)
456 /* We have to get the saved sp from the sigcontext
457 if it is a signal handler frame. */
458 if (regno == SP_REGNUM && !fi->signal_handler_caller)
462 if (fi->saved_regs == NULL)
463 alpha_find_saved_regs (fi);
464 if (fi->saved_regs[regno])
465 return read_memory_integer (fi->saved_regs[regno], 8);
468 return read_register (regno);
472 alpha_frame_saved_pc (struct frame_info *frame)
474 alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc;
475 /* We have to get the saved pc from the sigcontext
476 if it is a signal handler frame. */
477 int pcreg = frame->signal_handler_caller ? PC_REGNUM
478 : frame->extra_info->pc_reg;
480 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
481 return read_memory_integer (frame->frame - 8, 8);
483 return read_next_frame_reg (frame, pcreg);
487 alpha_saved_pc_after_call (struct frame_info *frame)
489 CORE_ADDR pc = frame->pc;
491 alpha_extra_func_info_t proc_desc;
494 /* Skip over shared library trampoline if necessary. */
495 tmp = SKIP_TRAMPOLINE_CODE (pc);
499 proc_desc = find_proc_desc (pc, frame->next);
500 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
502 if (frame->signal_handler_caller)
503 return alpha_frame_saved_pc (frame);
505 return read_register (pcreg);
509 static struct alpha_extra_func_info temp_proc_desc;
510 static CORE_ADDR temp_saved_regs[NUM_REGS];
512 /* Nonzero if instruction at PC is a return instruction. "ret
513 $zero,($ra),1" on alpha. */
516 alpha_about_to_return (CORE_ADDR pc)
518 return read_memory_integer (pc, 4) == 0x6bfa8001;
523 /* This fencepost looks highly suspicious to me. Removing it also
524 seems suspicious as it could affect remote debugging across serial
528 heuristic_proc_start (CORE_ADDR pc)
530 CORE_ADDR start_pc = pc;
531 CORE_ADDR fence = start_pc - heuristic_fence_post;
536 if (heuristic_fence_post == UINT_MAX
537 || fence < VM_MIN_ADDRESS)
538 fence = VM_MIN_ADDRESS;
540 /* search back for previous return */
541 for (start_pc -= 4;; start_pc -= 4)
542 if (start_pc < fence)
544 /* It's not clear to me why we reach this point when
545 stop_soon_quietly, but with this test, at least we
546 don't print out warnings for every child forked (eg, on
547 decstation). 22apr93 rich@cygnus.com. */
548 if (!stop_soon_quietly)
550 static int blurb_printed = 0;
552 if (fence == VM_MIN_ADDRESS)
553 warning ("Hit beginning of text section without finding");
555 warning ("Hit heuristic-fence-post without finding");
557 warning ("enclosing function for address 0x%s", paddr_nz (pc));
561 This warning occurs if you are debugging a function without any symbols\n\
562 (for example, in a stripped executable). In that case, you may wish to\n\
563 increase the size of the search with the `set heuristic-fence-post' command.\n\
565 Otherwise, you told GDB there was a function where there isn't one, or\n\
566 (more likely) you have encountered a bug in GDB.\n");
573 else if (alpha_about_to_return (start_pc))
576 start_pc += 4; /* skip return */
580 static alpha_extra_func_info_t
581 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
582 struct frame_info *next_frame)
584 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
587 int has_frame_reg = 0;
588 unsigned long reg_mask = 0;
593 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
594 memset (&temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
595 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
597 if (start_pc + 200 < limit_pc)
598 limit_pc = start_pc + 200;
600 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
606 status = read_memory_nobpt (cur_pc, buf, 4);
608 memory_error (status, cur_pc);
609 word = extract_unsigned_integer (buf, 4);
611 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
614 frame_size += (-word) & 0xffff;
616 /* Exit loop if a positive stack adjustment is found, which
617 usually means that the stack cleanup code in the function
618 epilogue is reached. */
621 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
622 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
624 int reg = (word & 0x03e00000) >> 21;
625 reg_mask |= 1 << reg;
626 temp_saved_regs[reg] = sp + (short) word;
628 /* Starting with OSF/1-3.2C, the system libraries are shipped
629 without local symbols, but they still contain procedure
630 descriptors without a symbol reference. GDB is currently
631 unable to find these procedure descriptors and uses
632 heuristic_proc_desc instead.
633 As some low level compiler support routines (__div*, __add*)
634 use a non-standard return address register, we have to
635 add some heuristics to determine the return address register,
636 or stepping over these routines will fail.
637 Usually the return address register is the first register
638 saved on the stack, but assembler optimization might
639 rearrange the register saves.
640 So we recognize only a few registers (t7, t9, ra) within
641 the procedure prologue as valid return address registers.
642 If we encounter a return instruction, we extract the
643 the return address register from it.
645 FIXME: Rewriting GDB to access the procedure descriptors,
646 e.g. via the minimal symbol table, might obviate this hack. */
648 && cur_pc < (start_pc + 80)
649 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
652 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
653 pcreg = (word >> 16) & 0x1f;
654 else if (word == 0x47de040f) /* bis sp,sp fp */
659 /* If we haven't found a valid return address register yet,
660 keep searching in the procedure prologue. */
661 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
666 if (read_memory_nobpt (cur_pc, buf, 4))
669 word = extract_unsigned_integer (buf, 4);
671 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
672 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
674 int reg = (word & 0x03e00000) >> 21;
675 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
681 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
683 pcreg = (word >> 16) & 0x1f;
690 PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
692 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
693 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
694 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
695 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
696 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
697 return &temp_proc_desc;
700 /* This returns the PC of the first inst after the prologue. If we can't
701 find the prologue, then return 0. */
704 after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
706 struct symtab_and_line sal;
707 CORE_ADDR func_addr, func_end;
710 proc_desc = find_proc_desc (pc, NULL);
714 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
715 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
717 /* If function is frameless, then we need to do it the hard way. I
718 strongly suspect that frameless always means prologueless... */
719 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
720 && PROC_FRAME_OFFSET (proc_desc) == 0)
724 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
725 return 0; /* Unknown */
727 sal = find_pc_line (func_addr, 0);
729 if (sal.end < func_end)
732 /* The line after the prologue is after the end of the function. In this
733 case, tell the caller to find the prologue the hard way. */
738 /* Return non-zero if we *might* be in a function prologue. Return zero if we
739 are definitively *not* in a function prologue. */
742 alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
744 CORE_ADDR after_prologue_pc;
746 after_prologue_pc = after_prologue (pc, proc_desc);
748 if (after_prologue_pc == 0
749 || pc < after_prologue_pc)
755 static alpha_extra_func_info_t
756 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame)
758 alpha_extra_func_info_t proc_desc;
763 /* Try to get the proc_desc from the linked call dummy proc_descs
764 if the pc is in the call dummy.
765 This is hairy. In the case of nested dummy calls we have to find the
766 right proc_desc, but we might not yet know the frame for the dummy
767 as it will be contained in the proc_desc we are searching for.
768 So we have to find the proc_desc whose frame is closest to the current
771 if (PC_IN_CALL_DUMMY (pc, 0, 0))
773 struct linked_proc_info *link;
774 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
775 alpha_extra_func_info_t found_proc_desc = NULL;
776 long min_distance = LONG_MAX;
778 for (link = linked_proc_desc_table; link; link = link->next)
780 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
781 if (distance > 0 && distance < min_distance)
783 min_distance = distance;
784 found_proc_desc = &link->info;
787 if (found_proc_desc != NULL)
788 return found_proc_desc;
791 b = block_for_pc (pc);
793 find_pc_partial_function (pc, NULL, &startaddr, NULL);
798 if (startaddr > BLOCK_START (b))
799 /* This is the "pathological" case referred to in a comment in
800 print_frame_info. It might be better to move this check into
804 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
808 /* If we never found a PDR for this function in symbol reading, then
809 examine prologues to find the information. */
810 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
815 /* IF this is the topmost frame AND
816 * (this proc does not have debugging information OR
817 * the PC is in the procedure prologue)
818 * THEN create a "heuristic" proc_desc (by analyzing
819 * the actual code) to replace the "official" proc_desc.
821 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
822 if (next_frame == NULL)
824 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
826 alpha_extra_func_info_t found_heuristic =
827 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
831 PROC_LOCALOFF (found_heuristic) =
832 PROC_LOCALOFF (proc_desc);
833 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
834 proc_desc = found_heuristic;
843 /* Is linked_proc_desc_table really necessary? It only seems to be used
844 by procedure call dummys. However, the procedures being called ought
845 to have their own proc_descs, and even if they don't,
846 heuristic_proc_desc knows how to create them! */
848 register struct linked_proc_info *link;
849 for (link = linked_proc_desc_table; link; link = link->next)
850 if (PROC_LOW_ADDR (&link->info) <= pc
851 && PROC_HIGH_ADDR (&link->info) > pc)
854 /* If PC is inside a dynamically generated sigtramp handler,
855 create and push a procedure descriptor for that code: */
856 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
858 return push_sigtramp_desc (pc - offset);
860 /* If heuristic_fence_post is non-zero, determine the procedure
861 start address by examining the instructions.
862 This allows us to find the start address of static functions which
863 have no symbolic information, as startaddr would have been set to
864 the preceding global function start address by the
865 find_pc_partial_function call above. */
866 if (startaddr == 0 || heuristic_fence_post != 0)
867 startaddr = heuristic_proc_start (pc);
870 heuristic_proc_desc (startaddr, pc, next_frame);
875 alpha_extra_func_info_t cached_proc_desc;
878 alpha_frame_chain (struct frame_info *frame)
880 alpha_extra_func_info_t proc_desc;
881 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
883 if (saved_pc == 0 || inside_entry_file (saved_pc))
886 proc_desc = find_proc_desc (saved_pc, frame);
890 cached_proc_desc = proc_desc;
892 /* Fetch the frame pointer for a dummy frame from the procedure
894 if (PROC_DESC_IS_DUMMY (proc_desc))
895 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
897 /* If no frame pointer and frame size is zero, we must be at end
898 of stack (or otherwise hosed). If we don't check frame size,
899 we loop forever if we see a zero size frame. */
900 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
901 && PROC_FRAME_OFFSET (proc_desc) == 0
902 /* The previous frame from a sigtramp frame might be frameless
903 and have frame size zero. */
904 && !frame->signal_handler_caller)
905 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
907 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
908 + PROC_FRAME_OFFSET (proc_desc);
912 alpha_print_extra_frame_info (struct frame_info *fi)
916 && fi->extra_info->proc_desc
917 && fi->extra_info->proc_desc->pdr.framereg < NUM_REGS)
918 printf_filtered (" frame pointer is at %s+%s\n",
919 REGISTER_NAME (fi->extra_info->proc_desc->pdr.framereg),
920 paddr_d (fi->extra_info->proc_desc->pdr.frameoffset));
924 alpha_init_extra_frame_info (int fromleaf, struct frame_info *frame)
926 /* Use proc_desc calculated in frame_chain */
927 alpha_extra_func_info_t proc_desc =
928 frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
930 frame->extra_info = (struct frame_extra_info *)
931 frame_obstack_alloc (sizeof (struct frame_extra_info));
933 frame->saved_regs = NULL;
934 frame->extra_info->localoff = 0;
935 frame->extra_info->pc_reg = RA_REGNUM;
936 frame->extra_info->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
939 /* Get the locals offset and the saved pc register from the
940 procedure descriptor, they are valid even if we are in the
941 middle of the prologue. */
942 frame->extra_info->localoff = PROC_LOCALOFF (proc_desc);
943 frame->extra_info->pc_reg = PROC_PC_REG (proc_desc);
945 /* Fixup frame-pointer - only needed for top frame */
947 /* Fetch the frame pointer for a dummy frame from the procedure
949 if (PROC_DESC_IS_DUMMY (proc_desc))
950 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
952 /* This may not be quite right, if proc has a real frame register.
953 Get the value of the frame relative sp, procedure might have been
954 interrupted by a signal at it's very start. */
955 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
956 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
957 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
959 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
960 + PROC_FRAME_OFFSET (proc_desc);
962 if (proc_desc == &temp_proc_desc)
966 /* Do not set the saved registers for a sigtramp frame,
967 alpha_find_saved_registers will do that for us.
968 We can't use frame->signal_handler_caller, it is not yet set. */
969 find_pc_partial_function (frame->pc, &name,
970 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
971 if (!IN_SIGTRAMP (frame->pc, name))
973 frame->saved_regs = (CORE_ADDR *)
974 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
975 memcpy (frame->saved_regs, temp_saved_regs,
976 SIZEOF_FRAME_SAVED_REGS);
977 frame->saved_regs[PC_REGNUM]
978 = frame->saved_regs[RA_REGNUM];
985 alpha_frame_locals_address (struct frame_info *fi)
987 return (fi->frame - fi->extra_info->localoff);
991 alpha_frame_args_address (struct frame_info *fi)
993 return (fi->frame - (ALPHA_NUM_ARG_REGS * 8));
996 /* ALPHA stack frames are almost impenetrable. When execution stops,
997 we basically have to look at symbol information for the function
998 that we stopped in, which tells us *which* register (if any) is
999 the base of the frame pointer, and what offset from that register
1000 the frame itself is at.
1002 This presents a problem when trying to examine a stack in memory
1003 (that isn't executing at the moment), using the "frame" command. We
1004 don't have a PC, nor do we have any registers except SP.
1006 This routine takes two arguments, SP and PC, and tries to make the
1007 cached frames look as if these two arguments defined a frame on the
1008 cache. This allows the rest of info frame to extract the important
1009 arguments without difficulty. */
1012 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
1015 error ("ALPHA frame specifications require two arguments: sp and pc");
1017 return create_new_frame (argv[0], argv[1]);
1020 /* The alpha passes the first six arguments in the registers, the rest on
1021 the stack. The register arguments are eventually transferred to the
1022 argument transfer area immediately below the stack by the called function
1023 anyway. So we `push' at least six arguments on the stack, `reload' the
1024 argument registers and then adjust the stack pointer to point past the
1025 sixth argument. This algorithm simplifies the passing of a large struct
1026 which extends from the registers to the stack.
1027 If the called function is returning a structure, the address of the
1028 structure to be returned is passed as a hidden first argument. */
1031 alpha_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1032 int struct_return, CORE_ADDR struct_addr)
1035 int accumulate_size = struct_return ? 8 : 0;
1036 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
1043 struct alpha_arg *alpha_args =
1044 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
1045 register struct alpha_arg *m_arg;
1046 char raw_buffer[sizeof (CORE_ADDR)];
1047 int required_arg_regs;
1049 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
1051 struct value *arg = args[i];
1052 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1053 /* Cast argument to long if necessary as the compiler does it too. */
1054 switch (TYPE_CODE (arg_type))
1057 case TYPE_CODE_BOOL:
1058 case TYPE_CODE_CHAR:
1059 case TYPE_CODE_RANGE:
1060 case TYPE_CODE_ENUM:
1061 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
1063 arg_type = builtin_type_long;
1064 arg = value_cast (arg_type, arg);
1070 m_arg->len = TYPE_LENGTH (arg_type);
1071 m_arg->offset = accumulate_size;
1072 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
1073 m_arg->contents = VALUE_CONTENTS (arg);
1076 /* Determine required argument register loads, loading an argument register
1077 is expensive as it uses three ptrace calls. */
1078 required_arg_regs = accumulate_size / 8;
1079 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
1080 required_arg_regs = ALPHA_NUM_ARG_REGS;
1082 /* Make room for the arguments on the stack. */
1083 if (accumulate_size < arg_regs_size)
1084 accumulate_size = arg_regs_size;
1085 sp -= accumulate_size;
1087 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
1090 /* `Push' arguments on the stack. */
1091 for (i = nargs; m_arg--, --i >= 0;)
1092 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
1095 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
1096 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
1099 /* Load the argument registers. */
1100 for (i = 0; i < required_arg_regs; i++)
1104 val = read_memory_integer (sp + i * 8, 8);
1105 write_register (A0_REGNUM + i, val);
1106 write_register (FPA0_REGNUM + i, val);
1109 return sp + arg_regs_size;
1113 alpha_push_dummy_frame (void)
1116 struct linked_proc_info *link;
1117 alpha_extra_func_info_t proc_desc;
1118 CORE_ADDR sp = read_register (SP_REGNUM);
1119 CORE_ADDR save_address;
1120 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1123 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
1124 link->next = linked_proc_desc_table;
1125 linked_proc_desc_table = link;
1127 proc_desc = &link->info;
1130 * The registers we must save are all those not preserved across
1132 * In addition, we must save the PC and RA.
1134 * Dummy frame layout:
1144 * Parameter build area
1148 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1149 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1150 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1151 #define GEN_REG_SAVE_COUNT 24
1152 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1153 #define FLOAT_REG_SAVE_COUNT 23
1154 /* The special register is the PC as we have no bit for it in the save masks.
1155 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1156 #define SPECIAL_REG_SAVE_COUNT 1
1158 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1159 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
1160 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1161 but keep SP aligned to a multiple of 16. */
1162 PROC_REG_OFFSET (proc_desc) =
1163 -((8 * (SPECIAL_REG_SAVE_COUNT
1164 + GEN_REG_SAVE_COUNT
1165 + FLOAT_REG_SAVE_COUNT)
1167 PROC_FREG_OFFSET (proc_desc) =
1168 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1170 /* Save general registers.
1171 The return address register is the first saved register, all other
1172 registers follow in ascending order.
1173 The PC is saved immediately below the SP. */
1174 save_address = sp + PROC_REG_OFFSET (proc_desc);
1175 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1176 write_memory (save_address, raw_buffer, 8);
1178 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
1179 for (ireg = 0; mask; ireg++, mask >>= 1)
1182 if (ireg == RA_REGNUM)
1184 store_address (raw_buffer, 8, read_register (ireg));
1185 write_memory (save_address, raw_buffer, 8);
1189 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1190 write_memory (sp - 8, raw_buffer, 8);
1192 /* Save floating point registers. */
1193 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1194 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
1195 for (ireg = 0; mask; ireg++, mask >>= 1)
1198 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1199 write_memory (save_address, raw_buffer, 8);
1203 /* Set and save the frame address for the dummy.
1204 This is tricky. The only registers that are suitable for a frame save
1205 are those that are preserved across procedure calls (s0-s6). But if
1206 a read system call is interrupted and then a dummy call is made
1207 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1208 is satisfied. Then it returns with the s0-s6 registers set to the values
1209 on entry to the read system call and our dummy frame pointer would be
1210 destroyed. So we save the dummy frame in the proc_desc and handle the
1211 retrieval of the frame pointer of a dummy specifically. The frame register
1212 is set to the virtual frame (pseudo) register, it's value will always
1213 be read as zero and will help us to catch any errors in the dummy frame
1215 PROC_DUMMY_FRAME (proc_desc) = sp;
1216 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1217 PROC_FRAME_OFFSET (proc_desc) = 0;
1218 sp += PROC_REG_OFFSET (proc_desc);
1219 write_register (SP_REGNUM, sp);
1221 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1222 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
1224 SET_PROC_DESC_IS_DUMMY (proc_desc);
1225 PROC_PC_REG (proc_desc) = RA_REGNUM;
1229 alpha_pop_frame (void)
1231 register int regnum;
1232 struct frame_info *frame = get_current_frame ();
1233 CORE_ADDR new_sp = frame->frame;
1235 alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc;
1237 /* we need proc_desc to know how to restore the registers;
1238 if it is NULL, construct (a temporary) one */
1239 if (proc_desc == NULL)
1240 proc_desc = find_proc_desc (frame->pc, frame->next);
1242 /* Question: should we copy this proc_desc and save it in
1243 frame->proc_desc? If we do, who will free it?
1244 For now, we don't save a copy... */
1246 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1247 if (frame->saved_regs == NULL)
1248 alpha_find_saved_regs (frame);
1251 for (regnum = 32; --regnum >= 0;)
1252 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
1253 write_register (regnum,
1254 read_memory_integer (frame->saved_regs[regnum],
1256 for (regnum = 32; --regnum >= 0;)
1257 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
1258 write_register (regnum + FP0_REGNUM,
1259 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1261 write_register (SP_REGNUM, new_sp);
1262 flush_cached_frames ();
1264 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
1265 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1267 struct linked_proc_info *pi_ptr, *prev_ptr;
1269 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1271 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1273 if (&pi_ptr->info == proc_desc)
1278 error ("Can't locate dummy extra frame info\n");
1280 if (prev_ptr != NULL)
1281 prev_ptr->next = pi_ptr->next;
1283 linked_proc_desc_table = pi_ptr->next;
1289 /* To skip prologues, I use this predicate. Returns either PC itself
1290 if the code at PC does not look like a function prologue; otherwise
1291 returns an address that (if we're lucky) follows the prologue. If
1292 LENIENT, then we must skip everything which is involved in setting
1293 up the frame (it's OK to skip more, just so long as we don't skip
1294 anything which might clobber the registers which are being saved.
1295 Currently we must not skip more on the alpha, but we might need the
1296 lenient stuff some day. */
1299 alpha_skip_prologue_internal (CORE_ADDR pc, int lenient)
1303 CORE_ADDR post_prologue_pc;
1306 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1307 /* Silently return the unaltered pc upon memory errors.
1308 This could happen on OSF/1 if decode_line_1 tries to skip the
1309 prologue for quickstarted shared library functions when the
1310 shared library is not yet mapped in.
1311 Reading target memory is slow over serial lines, so we perform
1312 this check only if the target has shared libraries. */
1313 if (target_read_memory (pc, buf, 4))
1317 /* See if we can determine the end of the prologue via the symbol table.
1318 If so, then return either PC, or the PC after the prologue, whichever
1321 post_prologue_pc = after_prologue (pc, NULL);
1323 if (post_prologue_pc != 0)
1324 return max (pc, post_prologue_pc);
1326 /* Can't determine prologue from the symbol table, need to examine
1329 /* Skip the typical prologue instructions. These are the stack adjustment
1330 instruction and the instructions that save registers on the stack
1331 or in the gcc frame. */
1332 for (offset = 0; offset < 100; offset += 4)
1336 status = read_memory_nobpt (pc + offset, buf, 4);
1338 memory_error (status, pc + offset);
1339 inst = extract_unsigned_integer (buf, 4);
1341 /* The alpha has no delay slots. But let's keep the lenient stuff,
1342 we might need it for something else in the future. */
1346 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1348 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1350 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1352 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1355 if ((inst & 0xfc1f0000) == 0xb41e0000
1356 && (inst & 0xffff0000) != 0xb7fe0000)
1357 continue; /* stq reg,n($sp) */
1359 if ((inst & 0xfc1f0000) == 0x9c1e0000
1360 && (inst & 0xffff0000) != 0x9ffe0000)
1361 continue; /* stt reg,n($sp) */
1363 if (inst == 0x47de040f) /* bis sp,sp,fp */
1372 alpha_skip_prologue (CORE_ADDR addr)
1374 return (alpha_skip_prologue_internal (addr, 0));
1378 /* Is address PC in the prologue (loosely defined) for function at
1382 alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc)
1384 CORE_ADDR end_prologue = alpha_skip_prologue_internal (startaddr, 1);
1385 return pc >= startaddr && pc < end_prologue;
1389 /* The alpha needs a conversion between register and memory format if
1390 the register is a floating point register and
1391 memory format is float, as the register format must be double
1393 memory format is an integer with 4 bytes or less, as the representation
1394 of integers in floating point registers is different. */
1396 alpha_register_convert_to_virtual (int regnum, struct type *valtype,
1397 char *raw_buffer, char *virtual_buffer)
1399 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1401 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1405 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1407 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1408 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1410 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1413 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1414 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1415 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1418 error ("Cannot retrieve value from floating point register");
1422 alpha_register_convert_to_raw (struct type *valtype, int regnum,
1423 char *virtual_buffer, char *raw_buffer)
1425 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1427 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1431 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1433 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1434 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1436 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1439 if (TYPE_UNSIGNED (valtype))
1440 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1442 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1443 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1444 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1447 error ("Cannot store value in floating point register");
1450 /* Given a return value in `regbuf' with a type `valtype',
1451 extract and copy its value into `valbuf'. */
1454 alpha_extract_return_value (struct type *valtype,
1455 char regbuf[REGISTER_BYTES], char *valbuf)
1457 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1458 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1459 regbuf + REGISTER_BYTE (FP0_REGNUM),
1462 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1465 /* Given a return value in `regbuf' with a type `valtype',
1466 write its value into the appropriate register. */
1469 alpha_store_return_value (struct type *valtype, char *valbuf)
1471 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1472 int regnum = V0_REGNUM;
1473 int length = TYPE_LENGTH (valtype);
1475 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1477 regnum = FP0_REGNUM;
1478 length = REGISTER_RAW_SIZE (regnum);
1479 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1482 memcpy (raw_buffer, valbuf, length);
1484 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1487 /* Just like reinit_frame_cache, but with the right arguments to be
1488 callable as an sfunc. */
1491 reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
1493 reinit_frame_cache ();
1496 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1497 to find a convenient place in the text segment to stick a breakpoint to
1498 detect the completion of a target function call (ala call_function_by_hand).
1502 alpha_call_dummy_address (void)
1505 struct minimal_symbol *sym;
1507 entry = entry_point_address ();
1512 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1514 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1517 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1521 alpha_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1522 struct value **args, struct type *type, int gcc_p)
1524 CORE_ADDR bp_address = CALL_DUMMY_ADDRESS ();
1526 if (bp_address == 0)
1527 error ("no place to put call");
1528 write_register (RA_REGNUM, bp_address);
1529 write_register (T12_REGNUM, fun);
1532 /* On the Alpha, the call dummy code is nevery copied to user space
1533 (see alpha_fix_call_dummy() above). The contents of this do not
1535 LONGEST alpha_call_dummy_words[] = { 0 };
1538 alpha_use_struct_convention (int gcc_p, struct type *type)
1540 /* Structures are returned by ref in extra arg0. */
1545 alpha_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1547 /* Store the address of the place in which to copy the structure the
1548 subroutine will return. Handled by alpha_push_arguments. */
1552 alpha_extract_struct_value_address (char *regbuf)
1554 return (extract_address (regbuf + REGISTER_BYTE (V0_REGNUM),
1555 REGISTER_RAW_SIZE (V0_REGNUM)));
1558 /* alpha_software_single_step() is called just before we want to resume
1559 the inferior, if we want to single-step it but there is no hardware
1560 or kernel single-step support (NetBSD on Alpha, for example). We find
1561 the target of the coming instruction and breakpoint it.
1563 single_step is also called just after the inferior stops. If we had
1564 set up a simulated single-step, we undo our damage. */
1567 alpha_next_pc (CORE_ADDR pc)
1574 insn = read_memory_unsigned_integer (pc, sizeof (insn));
1576 /* Opcode is top 6 bits. */
1577 op = (insn >> 26) & 0x3f;
1581 /* Jump format: target PC is:
1583 return (read_register ((insn >> 16) & 0x1f) & ~3);
1586 if ((op & 0x30) == 0x30)
1588 /* Branch format: target PC is:
1589 (new PC) + (4 * sext(displacement)) */
1590 if (op == 0x30 || /* BR */
1591 op == 0x34) /* BSR */
1594 offset = (insn & 0x001fffff);
1595 if (offset & 0x00100000)
1596 offset |= 0xffe00000;
1598 return (pc + 4 + offset);
1601 /* Need to determine if branch is taken; read RA. */
1602 rav = (LONGEST) read_register ((insn >> 21) & 0x1f);
1605 case 0x38: /* BLBC */
1609 case 0x3c: /* BLBS */
1613 case 0x39: /* BEQ */
1617 case 0x3d: /* BNE */
1621 case 0x3a: /* BLT */
1625 case 0x3b: /* BLE */
1629 case 0x3f: /* BGT */
1633 case 0x3e: /* BGE */
1640 /* Not a branch or branch not taken; target PC is:
1646 alpha_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1648 static CORE_ADDR next_pc;
1649 typedef char binsn_quantum[BREAKPOINT_MAX];
1650 static binsn_quantum break_mem;
1653 if (insert_breakpoints_p)
1656 next_pc = alpha_next_pc (pc);
1658 target_insert_breakpoint (next_pc, break_mem);
1662 target_remove_breakpoint (next_pc, break_mem);
1668 _initialize_alpha_tdep (void)
1670 struct cmd_list_element *c;
1672 tm_print_insn = print_insn_alpha;
1674 /* Let the user set the fence post for heuristic_proc_start. */
1676 /* We really would like to have both "0" and "unlimited" work, but
1677 command.c doesn't deal with that. So make it a var_zinteger
1678 because the user can always use "999999" or some such for unlimited. */
1679 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1680 (char *) &heuristic_fence_post,
1682 Set the distance searched for the start of a function.\n\
1683 If you are debugging a stripped executable, GDB needs to search through the\n\
1684 program for the start of a function. This command sets the distance of the\n\
1685 search. The only need to set it is when debugging a stripped executable.",
1687 /* We need to throw away the frame cache when we set this, since it
1688 might change our ability to get backtraces. */
1689 c->function.sfunc = reinit_frame_cache_sfunc;
1690 add_show_from_set (c, &showlist);