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., 675 Mass Ave, Cambridge, MA 02139, USA. */
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 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 fci->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 proc_desc = frame->proc_desc;
153 if (proc_desc == NULL)
154 /* I'm not sure how/whether this can happen. Normally when we can't
155 find a proc_desc, we "synthesize" one using heuristic_proc_desc
156 and set the saved_regs right away. */
159 /* Fill in the offsets for the registers which gen_mask says
162 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
163 mask = PROC_REG_MASK (proc_desc);
165 returnreg = PROC_PC_REG (proc_desc);
167 /* Note that RA is always saved first, regardless of it's actual
169 if (mask & (1 << returnreg))
171 frame->saved_regs->regs[returnreg] = reg_position;
173 mask &= ~(1 << returnreg); /* Clear bit for RA so we
174 don't save again later. */
177 for (ireg = 0; ireg <= 31 ; ++ireg)
178 if (mask & (1 << ireg))
180 frame->saved_regs->regs[ireg] = reg_position;
184 /* Fill in the offsets for the registers which float_mask says
187 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
188 mask = PROC_FREG_MASK (proc_desc);
190 for (ireg = 0; ireg <= 31 ; ++ireg)
191 if (mask & (1 << ireg))
193 frame->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
197 frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[returnreg];
201 read_next_frame_reg(fi, regno)
202 struct frame_info *fi;
205 /* If it is the frame for sigtramp we have a pointer to the sigcontext
207 If the stack layout for __sigtramp changes or if sigcontext offsets
208 change we might have to update this code. */
209 #ifndef SIGFRAME_PC_OFF
210 #define SIGFRAME_PC_OFF (2 * 8)
211 #define SIGFRAME_REGSAVE_OFF (4 * 8)
213 for (; fi; fi = fi->next)
215 if (fi->signal_handler_caller)
218 CORE_ADDR sigcontext_addr = read_memory_integer(fi->frame, 8);
220 if (regno == PC_REGNUM)
221 offset = SIGFRAME_PC_OFF;
223 offset = SIGFRAME_REGSAVE_OFF + regno * 8;
226 return read_memory_integer(sigcontext_addr + offset, 8);
228 else if (regno == SP_REGNUM)
232 if (fi->saved_regs == NULL)
233 alpha_find_saved_regs (fi);
234 if (fi->saved_regs->regs[regno])
235 return read_memory_integer(fi->saved_regs->regs[regno], 8);
238 return read_register(regno);
242 alpha_frame_saved_pc(frame)
243 struct frame_info *frame;
245 alpha_extra_func_info_t proc_desc = frame->proc_desc;
246 /* We have to get the saved pc from the sigcontext
247 if it is a signal handler frame. */
248 int pcreg = frame->signal_handler_caller ? PC_REGNUM
249 : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM);
251 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
252 return read_memory_integer(frame->frame - 8, 8);
254 return read_next_frame_reg(frame, pcreg);
258 alpha_saved_pc_after_call (frame)
259 struct frame_info *frame;
261 alpha_extra_func_info_t proc_desc = find_proc_desc (frame->pc, frame->next);
262 int pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
264 return read_register (pcreg);
268 static struct alpha_extra_func_info temp_proc_desc;
269 static struct frame_saved_regs temp_saved_regs;
271 /* This fencepost looks highly suspicious to me. Removing it also
272 seems suspicious as it could affect remote debugging across serial
276 heuristic_proc_start(pc)
279 CORE_ADDR start_pc = pc;
280 CORE_ADDR fence = start_pc - heuristic_fence_post;
282 if (start_pc == 0) return 0;
284 if (heuristic_fence_post == UINT_MAX
285 || fence < VM_MIN_ADDRESS)
286 fence = VM_MIN_ADDRESS;
288 /* search back for previous return */
289 for (start_pc -= 4; ; start_pc -= 4)
290 if (start_pc < fence)
292 /* It's not clear to me why we reach this point when
293 stop_soon_quietly, but with this test, at least we
294 don't print out warnings for every child forked (eg, on
296 if (!stop_soon_quietly)
298 static int blurb_printed = 0;
300 if (fence == VM_MIN_ADDRESS)
301 warning("Hit beginning of text section without finding");
303 warning("Hit heuristic-fence-post without finding");
305 warning("enclosing function for address 0x%lx", pc);
309 This warning occurs if you are debugging a function without any symbols\n\
310 (for example, in a stripped executable). In that case, you may wish to\n\
311 increase the size of the search with the `set heuristic-fence-post' command.\n\
313 Otherwise, you told GDB there was a function where there isn't one, or\n\
314 (more likely) you have encountered a bug in GDB.\n");
321 else if (ABOUT_TO_RETURN(start_pc))
324 start_pc += 4; /* skip return */
328 static alpha_extra_func_info_t
329 heuristic_proc_desc(start_pc, limit_pc, next_frame)
330 CORE_ADDR start_pc, limit_pc;
331 struct frame_info *next_frame;
333 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
336 int has_frame_reg = 0;
337 unsigned long reg_mask = 0;
341 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
342 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
343 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
345 if (start_pc + 200 < limit_pc)
346 limit_pc = start_pc + 200;
348 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
354 status = read_memory_nobpt (cur_pc, buf, 4);
356 memory_error (status, cur_pc);
357 word = extract_unsigned_integer (buf, 4);
359 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
360 frame_size += (-word) & 0xffff;
361 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
362 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
364 int reg = (word & 0x03e00000) >> 21;
365 reg_mask |= 1 << reg;
366 temp_saved_regs.regs[reg] = sp + (short)word;
368 else if (word == 0x47de040f) /* bis sp,sp fp */
372 PROC_FRAME_REG(&temp_proc_desc) = GCC_FP_REGNUM;
374 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
375 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
376 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
377 PROC_PC_REG(&temp_proc_desc) = RA_REGNUM;
378 PROC_LOCALOFF(&temp_proc_desc) = 0; /* XXX - bogus */
379 return &temp_proc_desc;
382 /* This returns the PC of the first inst after the prologue. If we can't
383 find the prologue, then return 0. */
386 after_prologue (pc, proc_desc)
388 alpha_extra_func_info_t proc_desc;
390 struct symtab_and_line sal;
391 CORE_ADDR func_addr, func_end;
394 proc_desc = find_proc_desc (pc, NULL);
398 /* If function is frameless, then we need to do it the hard way. I
399 strongly suspect that frameless always means prologueless... */
400 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
401 && PROC_FRAME_OFFSET (proc_desc) == 0)
405 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
406 return 0; /* Unknown */
408 sal = find_pc_line (func_addr, 0);
410 if (sal.end < func_end)
413 /* The line after the prologue is after the end of the function. In this
414 case, tell the caller to find the prologue the hard way. */
419 /* Return non-zero if we *might* be in a function prologue. Return zero if we
420 are definatly *not* in a function prologue. */
423 in_prologue (pc, proc_desc)
425 alpha_extra_func_info_t proc_desc;
427 CORE_ADDR after_prologue_pc;
429 after_prologue_pc = after_prologue (pc, proc_desc);
431 if (after_prologue_pc == 0
432 || pc < after_prologue_pc)
438 static alpha_extra_func_info_t
439 find_proc_desc (pc, next_frame)
441 struct frame_info *next_frame;
443 alpha_extra_func_info_t proc_desc;
448 /* Try to get the proc_desc from the linked call dummy proc_descs
449 if the pc is in the call dummy.
450 This is hairy. In the case of nested dummy calls we have to find the
451 right proc_desc, but we might not yet know the frame for the dummy
452 as it will be contained in the proc_desc we are searching for.
453 So we have to find the proc_desc whose frame is closest to the current
456 if (PC_IN_CALL_DUMMY (pc, 0, 0))
458 struct linked_proc_info *link;
459 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
460 alpha_extra_func_info_t found_proc_desc = NULL;
461 long min_distance = LONG_MAX;
463 for (link = linked_proc_desc_table; link; link = link->next)
465 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
466 if (distance > 0 && distance < min_distance)
468 min_distance = distance;
469 found_proc_desc = &link->info;
472 if (found_proc_desc != NULL)
473 return found_proc_desc;
476 b = block_for_pc(pc);
478 find_pc_partial_function (pc, NULL, &startaddr, NULL);
483 if (startaddr > BLOCK_START (b))
484 /* This is the "pathological" case referred to in a comment in
485 print_frame_info. It might be better to move this check into
489 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
493 /* If we never found a PDR for this function in symbol reading, then
494 examine prologues to find the information. */
495 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
500 /* IF this is the topmost frame AND
501 * (this proc does not have debugging information OR
502 * the PC is in the procedure prologue)
503 * THEN create a "heuristic" proc_desc (by analyzing
504 * the actual code) to replace the "official" proc_desc.
506 proc_desc = (alpha_extra_func_info_t)SYMBOL_VALUE(sym);
507 if (next_frame == NULL)
509 if (PROC_DESC_IS_DUMMY (proc_desc) || in_prologue (pc, proc_desc))
511 alpha_extra_func_info_t found_heuristic =
512 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
516 PROC_LOCALOFF (found_heuristic) =
517 PROC_LOCALOFF (proc_desc);
518 proc_desc = found_heuristic;
525 /* Is linked_proc_desc_table really necessary? It only seems to be used
526 by procedure call dummys. However, the procedures being called ought
527 to have their own proc_descs, and even if they don't,
528 heuristic_proc_desc knows how to create them! */
530 register struct linked_proc_info *link;
531 for (link = linked_proc_desc_table; link; link = link->next)
532 if (PROC_LOW_ADDR(&link->info) <= pc
533 && PROC_HIGH_ADDR(&link->info) > pc)
537 startaddr = heuristic_proc_start (pc);
540 heuristic_proc_desc (startaddr, pc, next_frame);
545 alpha_extra_func_info_t cached_proc_desc;
548 alpha_frame_chain(frame)
549 struct frame_info *frame;
551 alpha_extra_func_info_t proc_desc;
552 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
554 if (saved_pc == 0 || inside_entry_file (saved_pc))
557 proc_desc = find_proc_desc(saved_pc, frame);
561 cached_proc_desc = proc_desc;
563 /* Fetch the frame pointer for a dummy frame from the procedure
565 if (PROC_DESC_IS_DUMMY(proc_desc))
566 return (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
568 /* If no frame pointer and frame size is zero, we must be at end
569 of stack (or otherwise hosed). If we don't check frame size,
570 we loop forever if we see a zero size frame. */
571 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
572 && PROC_FRAME_OFFSET (proc_desc) == 0
573 /* The previous frame from a sigtramp frame might be frameless
574 and have frame size zero. */
575 && !frame->signal_handler_caller)
577 /* The alpha __sigtramp routine is frameless and has a frame size
578 of zero, but we are able to backtrace through it. */
580 find_pc_partial_function (saved_pc, &name,
581 (CORE_ADDR *)NULL, (CORE_ADDR *)NULL);
582 if (IN_SIGTRAMP (saved_pc, name))
588 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
589 + PROC_FRAME_OFFSET(proc_desc);
593 init_extra_frame_info (frame)
594 struct frame_info *frame;
596 /* Use proc_desc calculated in frame_chain */
597 alpha_extra_func_info_t proc_desc =
598 frame->next ? cached_proc_desc : find_proc_desc(frame->pc, frame->next);
600 frame->saved_regs = NULL;
602 proc_desc == &temp_proc_desc ? 0 : proc_desc;
605 /* Get the locals offset from the procedure descriptor, it is valid
606 even if we are in the middle of the prologue. */
607 frame->localoff = PROC_LOCALOFF(proc_desc);
609 /* Fixup frame-pointer - only needed for top frame */
611 /* Fetch the frame pointer for a dummy frame from the procedure
613 if (PROC_DESC_IS_DUMMY(proc_desc))
614 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
616 /* This may not be quite right, if proc has a real frame register.
617 Get the value of the frame relative sp, procedure might have been
618 interrupted by a signal at it's very start. */
619 else if (frame->pc == PROC_LOW_ADDR (proc_desc) && !PROC_DESC_IS_DUMMY (proc_desc))
620 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
622 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
623 + PROC_FRAME_OFFSET (proc_desc);
625 if (proc_desc == &temp_proc_desc)
627 frame->saved_regs = (struct frame_saved_regs*)
628 obstack_alloc (&frame_cache_obstack,
629 sizeof (struct frame_saved_regs));
630 *frame->saved_regs = temp_saved_regs;
631 frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[RA_REGNUM];
636 /* ALPHA stack frames are almost impenetrable. When execution stops,
637 we basically have to look at symbol information for the function
638 that we stopped in, which tells us *which* register (if any) is
639 the base of the frame pointer, and what offset from that register
640 the frame itself is at.
642 This presents a problem when trying to examine a stack in memory
643 (that isn't executing at the moment), using the "frame" command. We
644 don't have a PC, nor do we have any registers except SP.
646 This routine takes two arguments, SP and PC, and tries to make the
647 cached frames look as if these two arguments defined a frame on the
648 cache. This allows the rest of info frame to extract the important
649 arguments without difficulty. */
652 setup_arbitrary_frame (argc, argv)
657 error ("ALPHA frame specifications require two arguments: sp and pc");
659 return create_new_frame (argv[0], argv[1]);
662 /* The alpha passes the first six arguments in the registers, the rest on
663 the stack. The register arguments are eventually transferred to the
664 argument transfer area immediately below the stack by the called function
665 anyway. So we `push' at least six arguments on the stack, `reload' the
666 argument registers and then adjust the stack pointer to point past the
667 sixth argument. This algorithm simplifies the passing of a large struct
668 which extends from the registers to the stack.
669 If the called function is returning a structure, the address of the
670 structure to be returned is passed as a hidden first argument. */
673 alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
678 CORE_ADDR struct_addr;
681 int accumulate_size = struct_return ? 8 : 0;
682 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
683 struct alpha_arg { char *contents; int len; int offset; };
684 struct alpha_arg *alpha_args =
685 (struct alpha_arg*)alloca (nargs * sizeof (struct alpha_arg));
686 register struct alpha_arg *m_arg;
687 char raw_buffer[sizeof (CORE_ADDR)];
688 int required_arg_regs;
690 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
692 value_ptr arg = args[i];
693 /* Cast argument to long if necessary as the compiler does it too. */
694 if (TYPE_LENGTH (VALUE_TYPE (arg)) < TYPE_LENGTH (builtin_type_long))
695 arg = value_cast (builtin_type_long, arg);
696 m_arg->len = TYPE_LENGTH (VALUE_TYPE (arg));
697 m_arg->offset = accumulate_size;
698 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
699 m_arg->contents = VALUE_CONTENTS(arg);
702 /* Determine required argument register loads, loading an argument register
703 is expensive as it uses three ptrace calls. */
704 required_arg_regs = accumulate_size / 8;
705 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
706 required_arg_regs = ALPHA_NUM_ARG_REGS;
708 /* Make room for the arguments on the stack. */
709 if (accumulate_size < arg_regs_size)
710 accumulate_size = arg_regs_size;
711 sp -= accumulate_size;
713 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
716 /* `Push' arguments on the stack. */
717 for (i = nargs; m_arg--, --i >= 0; )
718 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
721 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
722 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
725 /* Load the argument registers. */
726 for (i = 0; i < required_arg_regs; i++)
730 val = read_memory_integer (sp + i * 8, 8);
731 write_register (A0_REGNUM + i, val);
732 write_register (FPA0_REGNUM + i, val);
735 return sp + arg_regs_size;
739 alpha_push_dummy_frame()
742 struct linked_proc_info *link;
743 alpha_extra_func_info_t proc_desc;
744 CORE_ADDR sp = read_register (SP_REGNUM);
745 CORE_ADDR save_address;
746 char raw_buffer[MAX_REGISTER_RAW_SIZE];
749 link = (struct linked_proc_info *) xmalloc(sizeof (struct linked_proc_info));
750 link->next = linked_proc_desc_table;
751 linked_proc_desc_table = link;
753 proc_desc = &link->info;
756 * The registers we must save are all those not preserved across
758 * In addition, we must save the PC and RA.
760 * Dummy frame layout:
770 * Parameter build area
774 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
775 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
776 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
777 #define GEN_REG_SAVE_COUNT 24
778 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
779 #define FLOAT_REG_SAVE_COUNT 23
780 /* The special register is the PC as we have no bit for it in the save masks.
781 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
782 #define SPECIAL_REG_SAVE_COUNT 1
784 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
785 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
786 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
787 but keep SP aligned to a multiple of 16. */
788 PROC_REG_OFFSET(proc_desc) =
789 - ((8 * (SPECIAL_REG_SAVE_COUNT
791 + FLOAT_REG_SAVE_COUNT)
793 PROC_FREG_OFFSET(proc_desc) =
794 PROC_REG_OFFSET(proc_desc) + 8 * GEN_REG_SAVE_COUNT;
796 /* Save general registers.
797 The return address register is the first saved register, all other
798 registers follow in ascending order.
799 The PC is saved immediately below the SP. */
800 save_address = sp + PROC_REG_OFFSET(proc_desc);
801 store_address (raw_buffer, 8, read_register (RA_REGNUM));
802 write_memory (save_address, raw_buffer, 8);
804 mask = PROC_REG_MASK(proc_desc) & 0xffffffffL;
805 for (ireg = 0; mask; ireg++, mask >>= 1)
808 if (ireg == RA_REGNUM)
810 store_address (raw_buffer, 8, read_register (ireg));
811 write_memory (save_address, raw_buffer, 8);
815 store_address (raw_buffer, 8, read_register (PC_REGNUM));
816 write_memory (sp - 8, raw_buffer, 8);
818 /* Save floating point registers. */
819 save_address = sp + PROC_FREG_OFFSET(proc_desc);
820 mask = PROC_FREG_MASK(proc_desc) & 0xffffffffL;
821 for (ireg = 0; mask; ireg++, mask >>= 1)
824 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
825 write_memory (save_address, raw_buffer, 8);
829 /* Set and save the frame address for the dummy.
830 This is tricky. The only registers that are suitable for a frame save
831 are those that are preserved across procedure calls (s0-s6). But if
832 a read system call is interrupted and then a dummy call is made
833 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
834 is satisfied. Then it returns with the s0-s6 registers set to the values
835 on entry to the read system call and our dummy frame pointer would be
836 destroyed. So we save the dummy frame in the proc_desc and handle the
837 retrieval of the frame pointer of a dummy specifically. The frame register
838 is set to the virtual frame (pseudo) register, it's value will always
839 be read as zero and will help us to catch any errors in the dummy frame
841 PROC_DUMMY_FRAME(proc_desc) = sp;
842 PROC_FRAME_REG(proc_desc) = FP_REGNUM;
843 PROC_FRAME_OFFSET(proc_desc) = 0;
844 sp += PROC_REG_OFFSET(proc_desc);
845 write_register (SP_REGNUM, sp);
847 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS ();
848 PROC_HIGH_ADDR(proc_desc) = PROC_LOW_ADDR(proc_desc) + 4;
850 SET_PROC_DESC_IS_DUMMY(proc_desc);
851 PROC_PC_REG(proc_desc) = RA_REGNUM;
858 struct frame_info *frame = get_current_frame ();
859 CORE_ADDR new_sp = frame->frame;
861 alpha_extra_func_info_t proc_desc = frame->proc_desc;
863 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
864 if (frame->saved_regs == NULL)
865 alpha_find_saved_regs (frame);
868 for (regnum = 32; --regnum >= 0; )
869 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
870 write_register (regnum,
871 read_memory_integer (frame->saved_regs->regs[regnum],
873 for (regnum = 32; --regnum >= 0; )
874 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
875 write_register (regnum + FP0_REGNUM,
876 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 8));
878 write_register (SP_REGNUM, new_sp);
879 flush_cached_frames ();
881 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
883 struct linked_proc_info *pi_ptr, *prev_ptr;
885 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
887 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
889 if (&pi_ptr->info == proc_desc)
894 error ("Can't locate dummy extra frame info\n");
896 if (prev_ptr != NULL)
897 prev_ptr->next = pi_ptr->next;
899 linked_proc_desc_table = pi_ptr->next;
905 /* To skip prologues, I use this predicate. Returns either PC itself
906 if the code at PC does not look like a function prologue; otherwise
907 returns an address that (if we're lucky) follows the prologue. If
908 LENIENT, then we must skip everything which is involved in setting
909 up the frame (it's OK to skip more, just so long as we don't skip
910 anything which might clobber the registers which are being saved.
911 Currently we must not skip more on the alpha, but we might the lenient
915 alpha_skip_prologue (pc, lenient)
921 CORE_ADDR post_prologue_pc;
924 #ifdef GDB_TARGET_HAS_SHARED_LIBS
925 /* Silently return the unaltered pc upon memory errors.
926 This could happen on OSF/1 if decode_line_1 tries to skip the
927 prologue for quickstarted shared library functions when the
928 shared library is not yet mapped in.
929 Reading target memory is slow over serial lines, so we perform
930 this check only if the target has shared libraries. */
931 if (target_read_memory (pc, buf, 4))
935 /* See if we can determine the end of the prologue via the symbol table.
936 If so, then return either PC, or the PC after the prologue, whichever
939 post_prologue_pc = after_prologue (pc, NULL);
941 if (post_prologue_pc != 0)
942 return max (pc, post_prologue_pc);
944 /* Can't determine prologue from the symbol table, need to examine
947 /* Skip the typical prologue instructions. These are the stack adjustment
948 instruction and the instructions that save registers on the stack
949 or in the gcc frame. */
950 for (offset = 0; offset < 100; offset += 4)
954 status = read_memory_nobpt (pc + offset, buf, 4);
956 memory_error (status, pc + offset);
957 inst = extract_unsigned_integer (buf, 4);
959 /* The alpha has no delay slots. But let's keep the lenient stuff,
960 we might need it for something else in the future. */
964 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
966 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
968 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
970 else if ((inst & 0xfc1f0000) == 0xb41e0000
971 && (inst & 0xffff0000) != 0xb7fe0000)
972 continue; /* stq reg,n($sp) */
974 else if ((inst & 0xfc1f0000) == 0x9c1e0000
975 && (inst & 0xffff0000) != 0x9ffe0000)
976 continue; /* stt reg,n($sp) */
978 else if (inst == 0x47de040f) /* bis sp,sp,fp */
987 /* Is address PC in the prologue (loosely defined) for function at
991 alpha_in_lenient_prologue (startaddr, pc)
995 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
996 return pc >= startaddr && pc < end_prologue;
1000 /* The alpha needs a conversion between register and memory format if
1001 the register is a floating point register and
1002 memory format is float, as the register format must be double
1004 memory format is an integer with 4 bytes or less, as the representation
1005 of integers in floating point registers is different. */
1007 alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
1009 struct type *valtype;
1011 char *virtual_buffer;
1013 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1015 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1019 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1021 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1022 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1024 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1027 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1028 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1029 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1032 error ("Cannot retrieve value from floating point register");
1036 alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
1037 struct type *valtype;
1039 char *virtual_buffer;
1042 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1044 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1048 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1050 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1051 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1053 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1056 if (TYPE_UNSIGNED (valtype))
1057 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1059 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1060 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1061 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1064 error ("Cannot store value in floating point register");
1067 /* Given a return value in `regbuf' with a type `valtype',
1068 extract and copy its value into `valbuf'. */
1071 alpha_extract_return_value (valtype, regbuf, valbuf)
1072 struct type *valtype;
1073 char regbuf[REGISTER_BYTES];
1078 regnum = TYPE_CODE (valtype) == TYPE_CODE_FLT ? FP0_REGNUM : V0_REGNUM;
1080 memcpy (valbuf, regbuf + REGISTER_BYTE (regnum), TYPE_LENGTH (valtype));
1083 /* Given a return value in `regbuf' with a type `valtype',
1084 write its value into the appropriate register. */
1087 alpha_store_return_value (valtype, valbuf)
1088 struct type *valtype;
1092 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1094 regnum = TYPE_CODE (valtype) == TYPE_CODE_FLT ? FP0_REGNUM : V0_REGNUM;
1095 memcpy(raw_buffer, valbuf, TYPE_LENGTH (valtype));
1097 write_register_bytes(REGISTER_BYTE (regnum), raw_buffer, TYPE_LENGTH (valtype));
1100 /* Just like reinit_frame_cache, but with the right arguments to be
1101 callable as an sfunc. */
1104 reinit_frame_cache_sfunc (args, from_tty, c)
1107 struct cmd_list_element *c;
1109 reinit_frame_cache ();
1112 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1113 to find a convenient place in the text segment to stick a breakpoint to
1114 detect the completion of a target function call (ala call_function_by_hand).
1118 alpha_call_dummy_address ()
1121 struct minimal_symbol *sym;
1123 entry = entry_point_address ();
1128 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1130 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1133 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1137 _initialize_alpha_tdep ()
1139 struct cmd_list_element *c;
1141 tm_print_insn = print_insn_alpha;
1143 /* Let the user set the fence post for heuristic_proc_start. */
1145 /* We really would like to have both "0" and "unlimited" work, but
1146 command.c doesn't deal with that. So make it a var_zinteger
1147 because the user can always use "999999" or some such for unlimited. */
1148 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1149 (char *) &heuristic_fence_post,
1151 Set the distance searched for the start of a function.\n\
1152 If you are debugging a stripped executable, GDB needs to search through the\n\
1153 program for the start of a function. This command sets the distance of the\n\
1154 search. The only need to set it is when debugging a stripped executable.",
1156 /* We need to throw away the frame cache when we set this, since it
1157 might change our ability to get backtraces. */
1158 c->function.sfunc = reinit_frame_cache_sfunc;
1159 add_show_from_set (c, &showlist);