1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
32 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
34 /* FIXME: Put this declaration in frame.h. */
35 extern struct obstack frame_cache_obstack;
38 /* Forward declarations. */
40 static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
42 static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
44 static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR,
46 struct frame_info *));
48 static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR,
49 struct frame_info *));
52 static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
55 static void reinit_frame_cache_sfunc PARAMS ((char *, int,
56 struct cmd_list_element *));
58 static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
59 alpha_extra_func_info_t proc_desc));
61 static int alpha_in_prologue PARAMS ((CORE_ADDR pc,
62 alpha_extra_func_info_t proc_desc));
64 /* Heuristic_proc_start may hunt through the text section for a long
65 time across a 2400 baud serial line. Allows the user to limit this
67 static unsigned int heuristic_fence_post = 0;
69 /* Layout of a stack frame on the alpha:
72 pdr members: | 7th ... nth arg, |
73 | `pushed' by caller. |
75 ----------------|-------------------------------|<-- old_sp == vfp
78 | |localoff | Copies of 1st .. 6th |
79 | | | | | argument if necessary. |
81 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
83 | | | | Locals and temporaries. |
85 | | | |-------------------------------|
87 |-fregoffset | Saved float registers. |
93 | | -------|-------------------------------|
95 | | | Saved registers. |
102 | ----------|-------------------------------|
104 frameoffset | Argument build area, gets |
105 | | 7th ... nth arg for any |
106 | | called procedure. |
108 -------------|-------------------------------|<-- sp
112 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
113 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
114 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
115 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
116 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
117 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
118 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
119 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
120 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
121 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
122 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
123 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
124 #define _PROC_MAGIC_ 0x0F0F0F0F
125 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
126 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
128 struct linked_proc_info
130 struct alpha_extra_func_info info;
131 struct linked_proc_info *next;
132 } *linked_proc_desc_table = NULL;
135 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
139 alpha_find_saved_regs (frame)
140 struct frame_info *frame;
143 CORE_ADDR reg_position;
145 alpha_extra_func_info_t proc_desc;
148 frame->saved_regs = (struct frame_saved_regs *)
149 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
150 memset (frame->saved_regs, 0, sizeof (struct frame_saved_regs));
152 /* If it is the frame for __sigtramp, the saved registers are located
153 in a sigcontext structure somewhere on the stack. __sigtramp
154 passes a pointer to the sigcontext structure on the stack.
155 If the stack layout for __sigtramp changes, or if sigcontext offsets
156 change, we might have to update this code. */
157 #ifndef SIGFRAME_PC_OFF
158 #define SIGFRAME_PC_OFF (2 * 8)
159 #define SIGFRAME_REGSAVE_OFF (4 * 8)
160 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
162 if (frame->signal_handler_caller)
164 CORE_ADDR sigcontext_pointer_addr;
165 CORE_ADDR sigcontext_addr;
168 sigcontext_pointer_addr = frame->next->frame;
170 sigcontext_pointer_addr = frame->frame;
171 sigcontext_addr = read_memory_integer(sigcontext_pointer_addr, 8);
172 for (ireg = 0; ireg < 32; ireg++)
174 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
175 frame->saved_regs->regs[ireg] = reg_position;
177 for (ireg = 0; ireg < 32; ireg++)
179 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
180 frame->saved_regs->regs[FP0_REGNUM + ireg] = reg_position;
182 frame->saved_regs->regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
186 proc_desc = frame->proc_desc;
187 if (proc_desc == NULL)
188 /* I'm not sure how/whether this can happen. Normally when we can't
189 find a proc_desc, we "synthesize" one using heuristic_proc_desc
190 and set the saved_regs right away. */
193 /* Fill in the offsets for the registers which gen_mask says
196 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
197 mask = PROC_REG_MASK (proc_desc);
199 returnreg = PROC_PC_REG (proc_desc);
201 /* Note that RA is always saved first, regardless of its actual
203 if (mask & (1 << returnreg))
205 frame->saved_regs->regs[returnreg] = reg_position;
207 mask &= ~(1 << returnreg); /* Clear bit for RA so we
208 don't save again later. */
211 for (ireg = 0; ireg <= 31 ; ++ireg)
212 if (mask & (1 << ireg))
214 frame->saved_regs->regs[ireg] = reg_position;
218 /* Fill in the offsets for the registers which float_mask says
221 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
222 mask = PROC_FREG_MASK (proc_desc);
224 for (ireg = 0; ireg <= 31 ; ++ireg)
225 if (mask & (1 << ireg))
227 frame->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
231 frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[returnreg];
235 read_next_frame_reg(fi, regno)
236 struct frame_info *fi;
239 for (; fi; fi = fi->next)
241 /* We have to get the saved sp from the sigcontext
242 if it is a signal handler frame. */
243 if (regno == SP_REGNUM && !fi->signal_handler_caller)
247 if (fi->saved_regs == NULL)
248 alpha_find_saved_regs (fi);
249 if (fi->saved_regs->regs[regno])
250 return read_memory_integer(fi->saved_regs->regs[regno], 8);
253 return read_register(regno);
257 alpha_frame_saved_pc(frame)
258 struct frame_info *frame;
260 alpha_extra_func_info_t proc_desc = frame->proc_desc;
261 /* We have to get the saved pc from the sigcontext
262 if it is a signal handler frame. */
263 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
265 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
266 return read_memory_integer(frame->frame - 8, 8);
268 return read_next_frame_reg(frame, pcreg);
272 alpha_saved_pc_after_call (frame)
273 struct frame_info *frame;
275 CORE_ADDR pc = frame->pc;
277 alpha_extra_func_info_t proc_desc;
280 /* Skip over shared library trampoline if necessary. */
281 tmp = SKIP_TRAMPOLINE_CODE (pc);
285 proc_desc = find_proc_desc (pc, frame->next);
286 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
288 return read_register (pcreg);
292 static struct alpha_extra_func_info temp_proc_desc;
293 static struct frame_saved_regs temp_saved_regs;
295 /* This fencepost looks highly suspicious to me. Removing it also
296 seems suspicious as it could affect remote debugging across serial
300 heuristic_proc_start(pc)
303 CORE_ADDR start_pc = pc;
304 CORE_ADDR fence = start_pc - heuristic_fence_post;
306 if (start_pc == 0) return 0;
308 if (heuristic_fence_post == UINT_MAX
309 || fence < VM_MIN_ADDRESS)
310 fence = VM_MIN_ADDRESS;
312 /* search back for previous return */
313 for (start_pc -= 4; ; start_pc -= 4)
314 if (start_pc < fence)
316 /* It's not clear to me why we reach this point when
317 stop_soon_quietly, but with this test, at least we
318 don't print out warnings for every child forked (eg, on
320 if (!stop_soon_quietly)
322 static int blurb_printed = 0;
324 if (fence == VM_MIN_ADDRESS)
325 warning("Hit beginning of text section without finding");
327 warning("Hit heuristic-fence-post without finding");
329 warning("enclosing function for address 0x%lx", pc);
333 This warning occurs if you are debugging a function without any symbols\n\
334 (for example, in a stripped executable). In that case, you may wish to\n\
335 increase the size of the search with the `set heuristic-fence-post' command.\n\
337 Otherwise, you told GDB there was a function where there isn't one, or\n\
338 (more likely) you have encountered a bug in GDB.\n");
345 else if (ABOUT_TO_RETURN(start_pc))
348 start_pc += 4; /* skip return */
352 static alpha_extra_func_info_t
353 heuristic_proc_desc(start_pc, limit_pc, next_frame)
354 CORE_ADDR start_pc, limit_pc;
355 struct frame_info *next_frame;
357 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
360 int has_frame_reg = 0;
361 unsigned long reg_mask = 0;
366 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
367 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
368 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
370 if (start_pc + 200 < limit_pc)
371 limit_pc = start_pc + 200;
373 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
379 status = read_memory_nobpt (cur_pc, buf, 4);
381 memory_error (status, cur_pc);
382 word = extract_unsigned_integer (buf, 4);
384 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
385 frame_size += (-word) & 0xffff;
386 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
387 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
389 int reg = (word & 0x03e00000) >> 21;
390 reg_mask |= 1 << reg;
391 temp_saved_regs.regs[reg] = sp + (short)word;
393 /* Starting with OSF/1-3.2C, the system libraries are shipped
394 without local symbols, but they still contain procedure
395 descriptors without a symbol reference. GDB is currently
396 unable to find these procedure descriptors and uses
397 heuristic_proc_desc instead.
398 As some low level compiler support routines (__div*, __add*)
399 use a non-standard return address register, we have to
400 add some heuristics to determine the return address register,
401 or stepping over these routines will fail.
402 Usually the return address register is the first register
403 saved on the stack, but assembler optimization might
404 rearrange the register saves.
405 So we recognize only a few registers (t7, t9, ra) within
406 the procedure prologue as valid return address registers.
408 FIXME: Rewriting GDB to access the procedure descriptors,
409 e.g. via the minimal symbol table, might obviate this hack. */
411 && cur_pc < (start_pc + 20)
412 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
415 else if (word == 0x47de040f) /* bis sp,sp fp */
420 /* If we haven't found a valid return address register yet,
421 keep searching in the procedure prologue. */
422 while (cur_pc < (limit_pc + 20) && cur_pc < (start_pc + 20))
428 status = read_memory_nobpt (cur_pc, buf, 4);
430 memory_error (status, cur_pc);
432 word = extract_unsigned_integer (buf, 4);
434 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
435 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
437 int reg = (word & 0x03e00000) >> 21;
438 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
448 PROC_FRAME_REG(&temp_proc_desc) = GCC_FP_REGNUM;
450 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
451 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
452 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
453 PROC_PC_REG(&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
454 PROC_LOCALOFF(&temp_proc_desc) = 0; /* XXX - bogus */
455 return &temp_proc_desc;
458 /* This returns the PC of the first inst after the prologue. If we can't
459 find the prologue, then return 0. */
462 after_prologue (pc, proc_desc)
464 alpha_extra_func_info_t proc_desc;
466 struct symtab_and_line sal;
467 CORE_ADDR func_addr, func_end;
470 proc_desc = find_proc_desc (pc, NULL);
474 /* If function is frameless, then we need to do it the hard way. I
475 strongly suspect that frameless always means prologueless... */
476 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
477 && PROC_FRAME_OFFSET (proc_desc) == 0)
481 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
482 return 0; /* Unknown */
484 sal = find_pc_line (func_addr, 0);
486 if (sal.end < func_end)
489 /* The line after the prologue is after the end of the function. In this
490 case, tell the caller to find the prologue the hard way. */
495 /* Return non-zero if we *might* be in a function prologue. Return zero if we
496 are definatly *not* in a function prologue. */
499 alpha_in_prologue (pc, proc_desc)
501 alpha_extra_func_info_t proc_desc;
503 CORE_ADDR after_prologue_pc;
505 after_prologue_pc = after_prologue (pc, proc_desc);
507 if (after_prologue_pc == 0
508 || pc < after_prologue_pc)
514 static alpha_extra_func_info_t
515 find_proc_desc (pc, next_frame)
517 struct frame_info *next_frame;
519 alpha_extra_func_info_t proc_desc;
524 /* Try to get the proc_desc from the linked call dummy proc_descs
525 if the pc is in the call dummy.
526 This is hairy. In the case of nested dummy calls we have to find the
527 right proc_desc, but we might not yet know the frame for the dummy
528 as it will be contained in the proc_desc we are searching for.
529 So we have to find the proc_desc whose frame is closest to the current
532 if (PC_IN_CALL_DUMMY (pc, 0, 0))
534 struct linked_proc_info *link;
535 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
536 alpha_extra_func_info_t found_proc_desc = NULL;
537 long min_distance = LONG_MAX;
539 for (link = linked_proc_desc_table; link; link = link->next)
541 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
542 if (distance > 0 && distance < min_distance)
544 min_distance = distance;
545 found_proc_desc = &link->info;
548 if (found_proc_desc != NULL)
549 return found_proc_desc;
552 b = block_for_pc(pc);
554 find_pc_partial_function (pc, NULL, &startaddr, NULL);
559 if (startaddr > BLOCK_START (b))
560 /* This is the "pathological" case referred to in a comment in
561 print_frame_info. It might be better to move this check into
565 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
569 /* If we never found a PDR for this function in symbol reading, then
570 examine prologues to find the information. */
571 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
576 /* IF this is the topmost frame AND
577 * (this proc does not have debugging information OR
578 * the PC is in the procedure prologue)
579 * THEN create a "heuristic" proc_desc (by analyzing
580 * the actual code) to replace the "official" proc_desc.
582 proc_desc = (alpha_extra_func_info_t)SYMBOL_VALUE(sym);
583 if (next_frame == NULL)
585 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
587 alpha_extra_func_info_t found_heuristic =
588 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
592 PROC_LOCALOFF (found_heuristic) =
593 PROC_LOCALOFF (proc_desc);
594 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
595 proc_desc = found_heuristic;
602 /* Is linked_proc_desc_table really necessary? It only seems to be used
603 by procedure call dummys. However, the procedures being called ought
604 to have their own proc_descs, and even if they don't,
605 heuristic_proc_desc knows how to create them! */
607 register struct linked_proc_info *link;
608 for (link = linked_proc_desc_table; link; link = link->next)
609 if (PROC_LOW_ADDR(&link->info) <= pc
610 && PROC_HIGH_ADDR(&link->info) > pc)
614 startaddr = heuristic_proc_start (pc);
617 heuristic_proc_desc (startaddr, pc, next_frame);
622 alpha_extra_func_info_t cached_proc_desc;
625 alpha_frame_chain(frame)
626 struct frame_info *frame;
628 alpha_extra_func_info_t proc_desc;
629 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
631 if (saved_pc == 0 || inside_entry_file (saved_pc))
634 proc_desc = find_proc_desc(saved_pc, frame);
638 cached_proc_desc = proc_desc;
640 /* Fetch the frame pointer for a dummy frame from the procedure
642 if (PROC_DESC_IS_DUMMY(proc_desc))
643 return (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
645 /* If no frame pointer and frame size is zero, we must be at end
646 of stack (or otherwise hosed). If we don't check frame size,
647 we loop forever if we see a zero size frame. */
648 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
649 && PROC_FRAME_OFFSET (proc_desc) == 0
650 /* The previous frame from a sigtramp frame might be frameless
651 and have frame size zero. */
652 && !frame->signal_handler_caller)
654 /* The alpha __sigtramp routine is frameless and has a frame size
655 of zero, but we are able to backtrace through it. */
657 find_pc_partial_function (saved_pc, &name,
658 (CORE_ADDR *)NULL, (CORE_ADDR *)NULL);
659 if (IN_SIGTRAMP (saved_pc, name))
665 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
666 + PROC_FRAME_OFFSET(proc_desc);
670 init_extra_frame_info (frame)
671 struct frame_info *frame;
673 /* Use proc_desc calculated in frame_chain */
674 alpha_extra_func_info_t proc_desc =
675 frame->next ? cached_proc_desc : find_proc_desc(frame->pc, frame->next);
677 frame->saved_regs = NULL;
679 frame->pc_reg = RA_REGNUM;
680 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
683 /* Get the locals offset and the saved pc register from the
684 procedure descriptor, they are valid even if we are in the
685 middle of the prologue. */
686 frame->localoff = PROC_LOCALOFF(proc_desc);
687 frame->pc_reg = PROC_PC_REG(proc_desc);
689 /* Fixup frame-pointer - only needed for top frame */
691 /* Fetch the frame pointer for a dummy frame from the procedure
693 if (PROC_DESC_IS_DUMMY(proc_desc))
694 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
696 /* This may not be quite right, if proc has a real frame register.
697 Get the value of the frame relative sp, procedure might have been
698 interrupted by a signal at it's very start. */
699 else if (frame->pc == PROC_LOW_ADDR (proc_desc) && !PROC_DESC_IS_DUMMY (proc_desc))
700 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
702 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
703 + PROC_FRAME_OFFSET (proc_desc);
705 if (proc_desc == &temp_proc_desc)
709 /* Do not set the saved registers for a sigtramp frame,
710 alpha_find_saved_registers will do that for us.
711 We can't use frame->signal_handler_caller, it is not yet set. */
712 find_pc_partial_function (frame->pc, &name,
713 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
714 if (!IN_SIGTRAMP (frame->pc, name))
716 frame->saved_regs = (struct frame_saved_regs*)
717 obstack_alloc (&frame_cache_obstack,
718 sizeof (struct frame_saved_regs));
719 *frame->saved_regs = temp_saved_regs;
720 frame->saved_regs->regs[PC_REGNUM]
721 = frame->saved_regs->regs[RA_REGNUM];
727 /* ALPHA stack frames are almost impenetrable. When execution stops,
728 we basically have to look at symbol information for the function
729 that we stopped in, which tells us *which* register (if any) is
730 the base of the frame pointer, and what offset from that register
731 the frame itself is at.
733 This presents a problem when trying to examine a stack in memory
734 (that isn't executing at the moment), using the "frame" command. We
735 don't have a PC, nor do we have any registers except SP.
737 This routine takes two arguments, SP and PC, and tries to make the
738 cached frames look as if these two arguments defined a frame on the
739 cache. This allows the rest of info frame to extract the important
740 arguments without difficulty. */
743 setup_arbitrary_frame (argc, argv)
748 error ("ALPHA frame specifications require two arguments: sp and pc");
750 return create_new_frame (argv[0], argv[1]);
753 /* The alpha passes the first six arguments in the registers, the rest on
754 the stack. The register arguments are eventually transferred to the
755 argument transfer area immediately below the stack by the called function
756 anyway. So we `push' at least six arguments on the stack, `reload' the
757 argument registers and then adjust the stack pointer to point past the
758 sixth argument. This algorithm simplifies the passing of a large struct
759 which extends from the registers to the stack.
760 If the called function is returning a structure, the address of the
761 structure to be returned is passed as a hidden first argument. */
764 alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
769 CORE_ADDR struct_addr;
772 int accumulate_size = struct_return ? 8 : 0;
773 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
774 struct alpha_arg { char *contents; int len; int offset; };
775 struct alpha_arg *alpha_args =
776 (struct alpha_arg*)alloca (nargs * sizeof (struct alpha_arg));
777 register struct alpha_arg *m_arg;
778 char raw_buffer[sizeof (CORE_ADDR)];
779 int required_arg_regs;
781 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
783 value_ptr arg = args[i];
784 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
785 /* Cast argument to long if necessary as the compiler does it too. */
786 switch (TYPE_CODE (arg_type))
791 case TYPE_CODE_RANGE:
793 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
795 arg_type = builtin_type_long;
796 arg = value_cast (arg_type, arg);
802 m_arg->len = TYPE_LENGTH (arg_type);
803 m_arg->offset = accumulate_size;
804 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
805 m_arg->contents = VALUE_CONTENTS(arg);
808 /* Determine required argument register loads, loading an argument register
809 is expensive as it uses three ptrace calls. */
810 required_arg_regs = accumulate_size / 8;
811 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
812 required_arg_regs = ALPHA_NUM_ARG_REGS;
814 /* Make room for the arguments on the stack. */
815 if (accumulate_size < arg_regs_size)
816 accumulate_size = arg_regs_size;
817 sp -= accumulate_size;
819 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
822 /* `Push' arguments on the stack. */
823 for (i = nargs; m_arg--, --i >= 0; )
824 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
827 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
828 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
831 /* Load the argument registers. */
832 for (i = 0; i < required_arg_regs; i++)
836 val = read_memory_integer (sp + i * 8, 8);
837 write_register (A0_REGNUM + i, val);
838 write_register (FPA0_REGNUM + i, val);
841 return sp + arg_regs_size;
845 alpha_push_dummy_frame()
848 struct linked_proc_info *link;
849 alpha_extra_func_info_t proc_desc;
850 CORE_ADDR sp = read_register (SP_REGNUM);
851 CORE_ADDR save_address;
852 char raw_buffer[MAX_REGISTER_RAW_SIZE];
855 link = (struct linked_proc_info *) xmalloc(sizeof (struct linked_proc_info));
856 link->next = linked_proc_desc_table;
857 linked_proc_desc_table = link;
859 proc_desc = &link->info;
862 * The registers we must save are all those not preserved across
864 * In addition, we must save the PC and RA.
866 * Dummy frame layout:
876 * Parameter build area
880 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
881 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
882 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
883 #define GEN_REG_SAVE_COUNT 24
884 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
885 #define FLOAT_REG_SAVE_COUNT 23
886 /* The special register is the PC as we have no bit for it in the save masks.
887 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
888 #define SPECIAL_REG_SAVE_COUNT 1
890 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
891 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
892 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
893 but keep SP aligned to a multiple of 16. */
894 PROC_REG_OFFSET(proc_desc) =
895 - ((8 * (SPECIAL_REG_SAVE_COUNT
897 + FLOAT_REG_SAVE_COUNT)
899 PROC_FREG_OFFSET(proc_desc) =
900 PROC_REG_OFFSET(proc_desc) + 8 * GEN_REG_SAVE_COUNT;
902 /* Save general registers.
903 The return address register is the first saved register, all other
904 registers follow in ascending order.
905 The PC is saved immediately below the SP. */
906 save_address = sp + PROC_REG_OFFSET(proc_desc);
907 store_address (raw_buffer, 8, read_register (RA_REGNUM));
908 write_memory (save_address, raw_buffer, 8);
910 mask = PROC_REG_MASK(proc_desc) & 0xffffffffL;
911 for (ireg = 0; mask; ireg++, mask >>= 1)
914 if (ireg == RA_REGNUM)
916 store_address (raw_buffer, 8, read_register (ireg));
917 write_memory (save_address, raw_buffer, 8);
921 store_address (raw_buffer, 8, read_register (PC_REGNUM));
922 write_memory (sp - 8, raw_buffer, 8);
924 /* Save floating point registers. */
925 save_address = sp + PROC_FREG_OFFSET(proc_desc);
926 mask = PROC_FREG_MASK(proc_desc) & 0xffffffffL;
927 for (ireg = 0; mask; ireg++, mask >>= 1)
930 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
931 write_memory (save_address, raw_buffer, 8);
935 /* Set and save the frame address for the dummy.
936 This is tricky. The only registers that are suitable for a frame save
937 are those that are preserved across procedure calls (s0-s6). But if
938 a read system call is interrupted and then a dummy call is made
939 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
940 is satisfied. Then it returns with the s0-s6 registers set to the values
941 on entry to the read system call and our dummy frame pointer would be
942 destroyed. So we save the dummy frame in the proc_desc and handle the
943 retrieval of the frame pointer of a dummy specifically. The frame register
944 is set to the virtual frame (pseudo) register, it's value will always
945 be read as zero and will help us to catch any errors in the dummy frame
947 PROC_DUMMY_FRAME(proc_desc) = sp;
948 PROC_FRAME_REG(proc_desc) = FP_REGNUM;
949 PROC_FRAME_OFFSET(proc_desc) = 0;
950 sp += PROC_REG_OFFSET(proc_desc);
951 write_register (SP_REGNUM, sp);
953 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS ();
954 PROC_HIGH_ADDR(proc_desc) = PROC_LOW_ADDR(proc_desc) + 4;
956 SET_PROC_DESC_IS_DUMMY(proc_desc);
957 PROC_PC_REG(proc_desc) = RA_REGNUM;
964 struct frame_info *frame = get_current_frame ();
965 CORE_ADDR new_sp = frame->frame;
967 alpha_extra_func_info_t proc_desc = frame->proc_desc;
969 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
970 if (frame->saved_regs == NULL)
971 alpha_find_saved_regs (frame);
974 for (regnum = 32; --regnum >= 0; )
975 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
976 write_register (regnum,
977 read_memory_integer (frame->saved_regs->regs[regnum],
979 for (regnum = 32; --regnum >= 0; )
980 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
981 write_register (regnum + FP0_REGNUM,
982 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 8));
984 write_register (SP_REGNUM, new_sp);
985 flush_cached_frames ();
987 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
989 struct linked_proc_info *pi_ptr, *prev_ptr;
991 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
993 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
995 if (&pi_ptr->info == proc_desc)
1000 error ("Can't locate dummy extra frame info\n");
1002 if (prev_ptr != NULL)
1003 prev_ptr->next = pi_ptr->next;
1005 linked_proc_desc_table = pi_ptr->next;
1011 /* To skip prologues, I use this predicate. Returns either PC itself
1012 if the code at PC does not look like a function prologue; otherwise
1013 returns an address that (if we're lucky) follows the prologue. If
1014 LENIENT, then we must skip everything which is involved in setting
1015 up the frame (it's OK to skip more, just so long as we don't skip
1016 anything which might clobber the registers which are being saved.
1017 Currently we must not skip more on the alpha, but we might the lenient
1021 alpha_skip_prologue (pc, lenient)
1027 CORE_ADDR post_prologue_pc;
1030 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1031 /* Silently return the unaltered pc upon memory errors.
1032 This could happen on OSF/1 if decode_line_1 tries to skip the
1033 prologue for quickstarted shared library functions when the
1034 shared library is not yet mapped in.
1035 Reading target memory is slow over serial lines, so we perform
1036 this check only if the target has shared libraries. */
1037 if (target_read_memory (pc, buf, 4))
1041 /* See if we can determine the end of the prologue via the symbol table.
1042 If so, then return either PC, or the PC after the prologue, whichever
1045 post_prologue_pc = after_prologue (pc, NULL);
1047 if (post_prologue_pc != 0)
1048 return max (pc, post_prologue_pc);
1050 /* Can't determine prologue from the symbol table, need to examine
1053 /* Skip the typical prologue instructions. These are the stack adjustment
1054 instruction and the instructions that save registers on the stack
1055 or in the gcc frame. */
1056 for (offset = 0; offset < 100; offset += 4)
1060 status = read_memory_nobpt (pc + offset, buf, 4);
1062 memory_error (status, pc + offset);
1063 inst = extract_unsigned_integer (buf, 4);
1065 /* The alpha has no delay slots. But let's keep the lenient stuff,
1066 we might need it for something else in the future. */
1070 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1072 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1074 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1076 else if ((inst & 0xfc1f0000) == 0xb41e0000
1077 && (inst & 0xffff0000) != 0xb7fe0000)
1078 continue; /* stq reg,n($sp) */
1080 else if ((inst & 0xfc1f0000) == 0x9c1e0000
1081 && (inst & 0xffff0000) != 0x9ffe0000)
1082 continue; /* stt reg,n($sp) */
1084 else if (inst == 0x47de040f) /* bis sp,sp,fp */
1093 /* Is address PC in the prologue (loosely defined) for function at
1097 alpha_in_lenient_prologue (startaddr, pc)
1098 CORE_ADDR startaddr;
1101 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1102 return pc >= startaddr && pc < end_prologue;
1106 /* The alpha needs a conversion between register and memory format if
1107 the register is a floating point register and
1108 memory format is float, as the register format must be double
1110 memory format is an integer with 4 bytes or less, as the representation
1111 of integers in floating point registers is different. */
1113 alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
1115 struct type *valtype;
1117 char *virtual_buffer;
1119 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1121 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1125 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1127 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1128 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1130 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1133 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1134 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1135 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1138 error ("Cannot retrieve value from floating point register");
1142 alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
1143 struct type *valtype;
1145 char *virtual_buffer;
1148 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1150 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1154 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1156 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1157 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1159 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1162 if (TYPE_UNSIGNED (valtype))
1163 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1165 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1166 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1167 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1170 error ("Cannot store value in floating point register");
1173 /* Given a return value in `regbuf' with a type `valtype',
1174 extract and copy its value into `valbuf'. */
1177 alpha_extract_return_value (valtype, regbuf, valbuf)
1178 struct type *valtype;
1179 char regbuf[REGISTER_BYTES];
1182 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1183 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1184 regbuf + REGISTER_BYTE (FP0_REGNUM),
1187 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1190 /* Given a return value in `regbuf' with a type `valtype',
1191 write its value into the appropriate register. */
1194 alpha_store_return_value (valtype, valbuf)
1195 struct type *valtype;
1198 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1199 int regnum = V0_REGNUM;
1200 int length = TYPE_LENGTH (valtype);
1202 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1204 regnum = FP0_REGNUM;
1205 length = REGISTER_RAW_SIZE (regnum);
1206 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1209 memcpy (raw_buffer, valbuf, length);
1211 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1214 /* Just like reinit_frame_cache, but with the right arguments to be
1215 callable as an sfunc. */
1218 reinit_frame_cache_sfunc (args, from_tty, c)
1221 struct cmd_list_element *c;
1223 reinit_frame_cache ();
1226 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1227 to find a convenient place in the text segment to stick a breakpoint to
1228 detect the completion of a target function call (ala call_function_by_hand).
1232 alpha_call_dummy_address ()
1235 struct minimal_symbol *sym;
1237 entry = entry_point_address ();
1242 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1244 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1247 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1251 _initialize_alpha_tdep ()
1253 struct cmd_list_element *c;
1255 tm_print_insn = print_insn_alpha;
1257 /* Let the user set the fence post for heuristic_proc_start. */
1259 /* We really would like to have both "0" and "unlimited" work, but
1260 command.c doesn't deal with that. So make it a var_zinteger
1261 because the user can always use "999999" or some such for unlimited. */
1262 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1263 (char *) &heuristic_fence_post,
1265 Set the distance searched for the start of a function.\n\
1266 If you are debugging a stripped executable, GDB needs to search through the\n\
1267 program for the start of a function. This command sets the distance of the\n\
1268 search. The only need to set it is when debugging a stripped executable.",
1270 /* We need to throw away the frame cache when we set this, since it
1271 might change our ability to get backtraces. */
1272 c->function.sfunc = reinit_frame_cache_sfunc;
1273 add_show_from_set (c, &showlist);