* alpha-tdep.c (alpha_register_name): New function.
[binutils-gdb.git] / gdb / alpha-tdep.c
1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "symtab.h"
26 #include "value.h"
27 #include "gdbcmd.h"
28 #include "gdbcore.h"
29 #include "dis-asm.h"
30 #include "symfile.h"
31 #include "objfiles.h"
32 #include "gdb_string.h"
33 #include "linespec.h"
34 #include "regcache.h"
35 #include "doublest.h"
36
37 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
38
39 /* Prototypes for local functions. */
40
41 static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
42
43 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
44
45 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
46
47 static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
48 CORE_ADDR,
49 struct frame_info *);
50
51 static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
52 struct frame_info *);
53
54 #if 0
55 static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
56 #endif
57
58 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
59
60 static CORE_ADDR after_prologue (CORE_ADDR pc,
61 alpha_extra_func_info_t proc_desc);
62
63 static int alpha_in_prologue (CORE_ADDR pc,
64 alpha_extra_func_info_t proc_desc);
65
66 static int alpha_about_to_return (CORE_ADDR pc);
67
68 void _initialize_alpha_tdep (void);
69
70 /* Heuristic_proc_start may hunt through the text section for a long
71 time across a 2400 baud serial line. Allows the user to limit this
72 search. */
73 static unsigned int heuristic_fence_post = 0;
74 /* *INDENT-OFF* */
75 /* Layout of a stack frame on the alpha:
76
77 | |
78 pdr members: | 7th ... nth arg, |
79 | `pushed' by caller. |
80 | |
81 ----------------|-------------------------------|<-- old_sp == vfp
82 ^ ^ ^ ^ | |
83 | | | | | |
84 | |localoff | Copies of 1st .. 6th |
85 | | | | | argument if necessary. |
86 | | | v | |
87 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
88 | | | | |
89 | | | | Locals and temporaries. |
90 | | | | |
91 | | | |-------------------------------|
92 | | | | |
93 |-fregoffset | Saved float registers. |
94 | | | | F9 |
95 | | | | . |
96 | | | | . |
97 | | | | F2 |
98 | | v | |
99 | | -------|-------------------------------|
100 | | | |
101 | | | Saved registers. |
102 | | | S6 |
103 |-regoffset | . |
104 | | | . |
105 | | | S0 |
106 | | | pdr.pcreg |
107 | v | |
108 | ----------|-------------------------------|
109 | | |
110 frameoffset | Argument build area, gets |
111 | | 7th ... nth arg for any |
112 | | called procedure. |
113 v | |
114 -------------|-------------------------------|<-- sp
115 | |
116 */
117 /* *INDENT-ON* */
118
119
120
121 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
122 /* These next two fields are kind of being hijacked. I wonder if
123 iline is too small for the values it needs to hold, if GDB is
124 running on a 32-bit host. */
125 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
126 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
127 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
128 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
129 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
130 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
131 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
132 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
133 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
134 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
135 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
136 #define _PROC_MAGIC_ 0x0F0F0F0F
137 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
138 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
139
140 struct linked_proc_info
141 {
142 struct alpha_extra_func_info info;
143 struct linked_proc_info *next;
144 }
145 *linked_proc_desc_table = NULL;
146 \f
147
148 /* Under GNU/Linux, signal handler invocations can be identified by the
149 designated code sequence that is used to return from a signal
150 handler. In particular, the return address of a signal handler
151 points to the following sequence (the first instruction is quadword
152 aligned):
153
154 bis $30,$30,$16
155 addq $31,0x67,$0
156 call_pal callsys
157
158 Each instruction has a unique encoding, so we simply attempt to
159 match the instruction the pc is pointing to with any of the above
160 instructions. If there is a hit, we know the offset to the start
161 of the designated sequence and can then check whether we really are
162 executing in a designated sequence. If not, -1 is returned,
163 otherwise the offset from the start of the desingated sequence is
164 returned.
165
166 There is a slight chance of false hits: code could jump into the
167 middle of the designated sequence, in which case there is no
168 guarantee that we are in the middle of a sigreturn syscall. Don't
169 think this will be a problem in praxis, though.
170 */
171
172 #ifndef TM_LINUXALPHA_H
173 /* HACK: Provide a prototype when compiling this file for non
174 linuxalpha targets. */
175 long alpha_linux_sigtramp_offset (CORE_ADDR pc);
176 #endif
177 long
178 alpha_linux_sigtramp_offset (CORE_ADDR pc)
179 {
180 unsigned int i[3], w;
181 long off;
182
183 if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
184 return -1;
185
186 off = -1;
187 switch (w)
188 {
189 case 0x47de0410:
190 off = 0;
191 break; /* bis $30,$30,$16 */
192 case 0x43ecf400:
193 off = 4;
194 break; /* addq $31,0x67,$0 */
195 case 0x00000083:
196 off = 8;
197 break; /* call_pal callsys */
198 default:
199 return -1;
200 }
201 pc -= off;
202 if (pc & 0x7)
203 {
204 /* designated sequence is not quadword aligned */
205 return -1;
206 }
207
208 if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
209 return -1;
210
211 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
212 return off;
213
214 return -1;
215 }
216 \f
217
218 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
219 size of zero, but we are able to backtrace through it. */
220 CORE_ADDR
221 alpha_osf_skip_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc)
222 {
223 char *name;
224 find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
225 if (IN_SIGTRAMP (pc, name))
226 return frame->frame;
227 else
228 return 0;
229 }
230 \f
231
232 /* Dynamically create a signal-handler caller procedure descriptor for
233 the signal-handler return code starting at address LOW_ADDR. The
234 descriptor is added to the linked_proc_desc_table. */
235
236 static alpha_extra_func_info_t
237 push_sigtramp_desc (CORE_ADDR low_addr)
238 {
239 struct linked_proc_info *link;
240 alpha_extra_func_info_t proc_desc;
241
242 link = (struct linked_proc_info *)
243 xmalloc (sizeof (struct linked_proc_info));
244 link->next = linked_proc_desc_table;
245 linked_proc_desc_table = link;
246
247 proc_desc = &link->info;
248
249 proc_desc->numargs = 0;
250 PROC_LOW_ADDR (proc_desc) = low_addr;
251 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
252 PROC_DUMMY_FRAME (proc_desc) = 0;
253 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
254 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
255 PROC_REG_MASK (proc_desc) = 0xffff;
256 PROC_FREG_MASK (proc_desc) = 0xffff;
257 PROC_PC_REG (proc_desc) = 26;
258 PROC_LOCALOFF (proc_desc) = 0;
259 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
260 return (proc_desc);
261 }
262 \f
263
264 char *
265 alpha_register_name (int regno)
266 {
267 static char *register_names[] =
268 {
269 "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
270 "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
271 "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
272 "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero",
273 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
274 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
275 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
276 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr",
277 "pc", "vfp",
278 };
279
280 if (regno < 0)
281 return (NULL);
282 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
283 return (NULL);
284 return (register_names[regno]);
285 }
286 \f
287
288 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
289 NULL). */
290
291 void
292 alpha_find_saved_regs (struct frame_info *frame)
293 {
294 int ireg;
295 CORE_ADDR reg_position;
296 unsigned long mask;
297 alpha_extra_func_info_t proc_desc;
298 int returnreg;
299
300 frame_saved_regs_zalloc (frame);
301
302 /* If it is the frame for __sigtramp, the saved registers are located
303 in a sigcontext structure somewhere on the stack. __sigtramp
304 passes a pointer to the sigcontext structure on the stack.
305 If the stack layout for __sigtramp changes, or if sigcontext offsets
306 change, we might have to update this code. */
307 #ifndef SIGFRAME_PC_OFF
308 #define SIGFRAME_PC_OFF (2 * 8)
309 #define SIGFRAME_REGSAVE_OFF (4 * 8)
310 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
311 #endif
312 if (frame->signal_handler_caller)
313 {
314 CORE_ADDR sigcontext_addr;
315
316 sigcontext_addr = SIGCONTEXT_ADDR (frame);
317 for (ireg = 0; ireg < 32; ireg++)
318 {
319 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
320 frame->saved_regs[ireg] = reg_position;
321 }
322 for (ireg = 0; ireg < 32; ireg++)
323 {
324 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
325 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
326 }
327 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
328 return;
329 }
330
331 proc_desc = frame->proc_desc;
332 if (proc_desc == NULL)
333 /* I'm not sure how/whether this can happen. Normally when we can't
334 find a proc_desc, we "synthesize" one using heuristic_proc_desc
335 and set the saved_regs right away. */
336 return;
337
338 /* Fill in the offsets for the registers which gen_mask says
339 were saved. */
340
341 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
342 mask = PROC_REG_MASK (proc_desc);
343
344 returnreg = PROC_PC_REG (proc_desc);
345
346 /* Note that RA is always saved first, regardless of its actual
347 register number. */
348 if (mask & (1 << returnreg))
349 {
350 frame->saved_regs[returnreg] = reg_position;
351 reg_position += 8;
352 mask &= ~(1 << returnreg); /* Clear bit for RA so we
353 don't save again later. */
354 }
355
356 for (ireg = 0; ireg <= 31; ++ireg)
357 if (mask & (1 << ireg))
358 {
359 frame->saved_regs[ireg] = reg_position;
360 reg_position += 8;
361 }
362
363 /* Fill in the offsets for the registers which float_mask says
364 were saved. */
365
366 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
367 mask = PROC_FREG_MASK (proc_desc);
368
369 for (ireg = 0; ireg <= 31; ++ireg)
370 if (mask & (1 << ireg))
371 {
372 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
373 reg_position += 8;
374 }
375
376 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
377 }
378
379 static CORE_ADDR
380 read_next_frame_reg (struct frame_info *fi, int regno)
381 {
382 for (; fi; fi = fi->next)
383 {
384 /* We have to get the saved sp from the sigcontext
385 if it is a signal handler frame. */
386 if (regno == SP_REGNUM && !fi->signal_handler_caller)
387 return fi->frame;
388 else
389 {
390 if (fi->saved_regs == NULL)
391 alpha_find_saved_regs (fi);
392 if (fi->saved_regs[regno])
393 return read_memory_integer (fi->saved_regs[regno], 8);
394 }
395 }
396 return read_register (regno);
397 }
398
399 CORE_ADDR
400 alpha_frame_saved_pc (struct frame_info *frame)
401 {
402 alpha_extra_func_info_t proc_desc = frame->proc_desc;
403 /* We have to get the saved pc from the sigcontext
404 if it is a signal handler frame. */
405 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
406
407 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
408 return read_memory_integer (frame->frame - 8, 8);
409
410 return read_next_frame_reg (frame, pcreg);
411 }
412
413 CORE_ADDR
414 alpha_saved_pc_after_call (struct frame_info *frame)
415 {
416 CORE_ADDR pc = frame->pc;
417 CORE_ADDR tmp;
418 alpha_extra_func_info_t proc_desc;
419 int pcreg;
420
421 /* Skip over shared library trampoline if necessary. */
422 tmp = SKIP_TRAMPOLINE_CODE (pc);
423 if (tmp != 0)
424 pc = tmp;
425
426 proc_desc = find_proc_desc (pc, frame->next);
427 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
428
429 if (frame->signal_handler_caller)
430 return alpha_frame_saved_pc (frame);
431 else
432 return read_register (pcreg);
433 }
434
435
436 static struct alpha_extra_func_info temp_proc_desc;
437 static struct frame_saved_regs temp_saved_regs;
438
439 /* Nonzero if instruction at PC is a return instruction. "ret
440 $zero,($ra),1" on alpha. */
441
442 static int
443 alpha_about_to_return (CORE_ADDR pc)
444 {
445 return read_memory_integer (pc, 4) == 0x6bfa8001;
446 }
447
448
449
450 /* This fencepost looks highly suspicious to me. Removing it also
451 seems suspicious as it could affect remote debugging across serial
452 lines. */
453
454 static CORE_ADDR
455 heuristic_proc_start (CORE_ADDR pc)
456 {
457 CORE_ADDR start_pc = pc;
458 CORE_ADDR fence = start_pc - heuristic_fence_post;
459
460 if (start_pc == 0)
461 return 0;
462
463 if (heuristic_fence_post == UINT_MAX
464 || fence < VM_MIN_ADDRESS)
465 fence = VM_MIN_ADDRESS;
466
467 /* search back for previous return */
468 for (start_pc -= 4;; start_pc -= 4)
469 if (start_pc < fence)
470 {
471 /* It's not clear to me why we reach this point when
472 stop_soon_quietly, but with this test, at least we
473 don't print out warnings for every child forked (eg, on
474 decstation). 22apr93 rich@cygnus.com. */
475 if (!stop_soon_quietly)
476 {
477 static int blurb_printed = 0;
478
479 if (fence == VM_MIN_ADDRESS)
480 warning ("Hit beginning of text section without finding");
481 else
482 warning ("Hit heuristic-fence-post without finding");
483
484 warning ("enclosing function for address 0x%s", paddr_nz (pc));
485 if (!blurb_printed)
486 {
487 printf_filtered ("\
488 This warning occurs if you are debugging a function without any symbols\n\
489 (for example, in a stripped executable). In that case, you may wish to\n\
490 increase the size of the search with the `set heuristic-fence-post' command.\n\
491 \n\
492 Otherwise, you told GDB there was a function where there isn't one, or\n\
493 (more likely) you have encountered a bug in GDB.\n");
494 blurb_printed = 1;
495 }
496 }
497
498 return 0;
499 }
500 else if (alpha_about_to_return (start_pc))
501 break;
502
503 start_pc += 4; /* skip return */
504 return start_pc;
505 }
506
507 static alpha_extra_func_info_t
508 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
509 struct frame_info *next_frame)
510 {
511 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
512 CORE_ADDR cur_pc;
513 int frame_size;
514 int has_frame_reg = 0;
515 unsigned long reg_mask = 0;
516 int pcreg = -1;
517
518 if (start_pc == 0)
519 return NULL;
520 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
521 memset (&temp_saved_regs, '\0', sizeof (struct frame_saved_regs));
522 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
523
524 if (start_pc + 200 < limit_pc)
525 limit_pc = start_pc + 200;
526 frame_size = 0;
527 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
528 {
529 char buf[4];
530 unsigned long word;
531 int status;
532
533 status = read_memory_nobpt (cur_pc, buf, 4);
534 if (status)
535 memory_error (status, cur_pc);
536 word = extract_unsigned_integer (buf, 4);
537
538 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
539 {
540 if (word & 0x8000)
541 frame_size += (-word) & 0xffff;
542 else
543 /* Exit loop if a positive stack adjustment is found, which
544 usually means that the stack cleanup code in the function
545 epilogue is reached. */
546 break;
547 }
548 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
549 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
550 {
551 int reg = (word & 0x03e00000) >> 21;
552 reg_mask |= 1 << reg;
553 temp_saved_regs.regs[reg] = sp + (short) word;
554
555 /* Starting with OSF/1-3.2C, the system libraries are shipped
556 without local symbols, but they still contain procedure
557 descriptors without a symbol reference. GDB is currently
558 unable to find these procedure descriptors and uses
559 heuristic_proc_desc instead.
560 As some low level compiler support routines (__div*, __add*)
561 use a non-standard return address register, we have to
562 add some heuristics to determine the return address register,
563 or stepping over these routines will fail.
564 Usually the return address register is the first register
565 saved on the stack, but assembler optimization might
566 rearrange the register saves.
567 So we recognize only a few registers (t7, t9, ra) within
568 the procedure prologue as valid return address registers.
569 If we encounter a return instruction, we extract the
570 the return address register from it.
571
572 FIXME: Rewriting GDB to access the procedure descriptors,
573 e.g. via the minimal symbol table, might obviate this hack. */
574 if (pcreg == -1
575 && cur_pc < (start_pc + 80)
576 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
577 pcreg = reg;
578 }
579 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
580 pcreg = (word >> 16) & 0x1f;
581 else if (word == 0x47de040f) /* bis sp,sp fp */
582 has_frame_reg = 1;
583 }
584 if (pcreg == -1)
585 {
586 /* If we haven't found a valid return address register yet,
587 keep searching in the procedure prologue. */
588 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
589 {
590 char buf[4];
591 unsigned long word;
592
593 if (read_memory_nobpt (cur_pc, buf, 4))
594 break;
595 cur_pc += 4;
596 word = extract_unsigned_integer (buf, 4);
597
598 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
599 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
600 {
601 int reg = (word & 0x03e00000) >> 21;
602 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
603 {
604 pcreg = reg;
605 break;
606 }
607 }
608 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
609 {
610 pcreg = (word >> 16) & 0x1f;
611 break;
612 }
613 }
614 }
615
616 if (has_frame_reg)
617 PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
618 else
619 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
620 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
621 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
622 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
623 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
624 return &temp_proc_desc;
625 }
626
627 /* This returns the PC of the first inst after the prologue. If we can't
628 find the prologue, then return 0. */
629
630 static CORE_ADDR
631 after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
632 {
633 struct symtab_and_line sal;
634 CORE_ADDR func_addr, func_end;
635
636 if (!proc_desc)
637 proc_desc = find_proc_desc (pc, NULL);
638
639 if (proc_desc)
640 {
641 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
642 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
643
644 /* If function is frameless, then we need to do it the hard way. I
645 strongly suspect that frameless always means prologueless... */
646 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
647 && PROC_FRAME_OFFSET (proc_desc) == 0)
648 return 0;
649 }
650
651 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
652 return 0; /* Unknown */
653
654 sal = find_pc_line (func_addr, 0);
655
656 if (sal.end < func_end)
657 return sal.end;
658
659 /* The line after the prologue is after the end of the function. In this
660 case, tell the caller to find the prologue the hard way. */
661
662 return 0;
663 }
664
665 /* Return non-zero if we *might* be in a function prologue. Return zero if we
666 are definitively *not* in a function prologue. */
667
668 static int
669 alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
670 {
671 CORE_ADDR after_prologue_pc;
672
673 after_prologue_pc = after_prologue (pc, proc_desc);
674
675 if (after_prologue_pc == 0
676 || pc < after_prologue_pc)
677 return 1;
678 else
679 return 0;
680 }
681
682 static alpha_extra_func_info_t
683 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame)
684 {
685 alpha_extra_func_info_t proc_desc;
686 struct block *b;
687 struct symbol *sym;
688 CORE_ADDR startaddr;
689
690 /* Try to get the proc_desc from the linked call dummy proc_descs
691 if the pc is in the call dummy.
692 This is hairy. In the case of nested dummy calls we have to find the
693 right proc_desc, but we might not yet know the frame for the dummy
694 as it will be contained in the proc_desc we are searching for.
695 So we have to find the proc_desc whose frame is closest to the current
696 stack pointer. */
697
698 if (PC_IN_CALL_DUMMY (pc, 0, 0))
699 {
700 struct linked_proc_info *link;
701 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
702 alpha_extra_func_info_t found_proc_desc = NULL;
703 long min_distance = LONG_MAX;
704
705 for (link = linked_proc_desc_table; link; link = link->next)
706 {
707 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
708 if (distance > 0 && distance < min_distance)
709 {
710 min_distance = distance;
711 found_proc_desc = &link->info;
712 }
713 }
714 if (found_proc_desc != NULL)
715 return found_proc_desc;
716 }
717
718 b = block_for_pc (pc);
719
720 find_pc_partial_function (pc, NULL, &startaddr, NULL);
721 if (b == NULL)
722 sym = NULL;
723 else
724 {
725 if (startaddr > BLOCK_START (b))
726 /* This is the "pathological" case referred to in a comment in
727 print_frame_info. It might be better to move this check into
728 symbol reading. */
729 sym = NULL;
730 else
731 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
732 0, NULL);
733 }
734
735 /* If we never found a PDR for this function in symbol reading, then
736 examine prologues to find the information. */
737 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
738 sym = NULL;
739
740 if (sym)
741 {
742 /* IF this is the topmost frame AND
743 * (this proc does not have debugging information OR
744 * the PC is in the procedure prologue)
745 * THEN create a "heuristic" proc_desc (by analyzing
746 * the actual code) to replace the "official" proc_desc.
747 */
748 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
749 if (next_frame == NULL)
750 {
751 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
752 {
753 alpha_extra_func_info_t found_heuristic =
754 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
755 pc, next_frame);
756 if (found_heuristic)
757 {
758 PROC_LOCALOFF (found_heuristic) =
759 PROC_LOCALOFF (proc_desc);
760 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
761 proc_desc = found_heuristic;
762 }
763 }
764 }
765 }
766 else
767 {
768 long offset;
769
770 /* Is linked_proc_desc_table really necessary? It only seems to be used
771 by procedure call dummys. However, the procedures being called ought
772 to have their own proc_descs, and even if they don't,
773 heuristic_proc_desc knows how to create them! */
774
775 register struct linked_proc_info *link;
776 for (link = linked_proc_desc_table; link; link = link->next)
777 if (PROC_LOW_ADDR (&link->info) <= pc
778 && PROC_HIGH_ADDR (&link->info) > pc)
779 return &link->info;
780
781 /* If PC is inside a dynamically generated sigtramp handler,
782 create and push a procedure descriptor for that code: */
783 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
784 if (offset >= 0)
785 return push_sigtramp_desc (pc - offset);
786
787 /* If heuristic_fence_post is non-zero, determine the procedure
788 start address by examining the instructions.
789 This allows us to find the start address of static functions which
790 have no symbolic information, as startaddr would have been set to
791 the preceding global function start address by the
792 find_pc_partial_function call above. */
793 if (startaddr == 0 || heuristic_fence_post != 0)
794 startaddr = heuristic_proc_start (pc);
795
796 proc_desc =
797 heuristic_proc_desc (startaddr, pc, next_frame);
798 }
799 return proc_desc;
800 }
801
802 alpha_extra_func_info_t cached_proc_desc;
803
804 CORE_ADDR
805 alpha_frame_chain (struct frame_info *frame)
806 {
807 alpha_extra_func_info_t proc_desc;
808 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
809
810 if (saved_pc == 0 || inside_entry_file (saved_pc))
811 return 0;
812
813 proc_desc = find_proc_desc (saved_pc, frame);
814 if (!proc_desc)
815 return 0;
816
817 cached_proc_desc = proc_desc;
818
819 /* Fetch the frame pointer for a dummy frame from the procedure
820 descriptor. */
821 if (PROC_DESC_IS_DUMMY (proc_desc))
822 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
823
824 /* If no frame pointer and frame size is zero, we must be at end
825 of stack (or otherwise hosed). If we don't check frame size,
826 we loop forever if we see a zero size frame. */
827 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
828 && PROC_FRAME_OFFSET (proc_desc) == 0
829 /* The previous frame from a sigtramp frame might be frameless
830 and have frame size zero. */
831 && !frame->signal_handler_caller)
832 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
833 else
834 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
835 + PROC_FRAME_OFFSET (proc_desc);
836 }
837
838 void
839 init_extra_frame_info (struct frame_info *frame)
840 {
841 /* Use proc_desc calculated in frame_chain */
842 alpha_extra_func_info_t proc_desc =
843 frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
844
845 frame->saved_regs = NULL;
846 frame->localoff = 0;
847 frame->pc_reg = RA_REGNUM;
848 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
849 if (proc_desc)
850 {
851 /* Get the locals offset and the saved pc register from the
852 procedure descriptor, they are valid even if we are in the
853 middle of the prologue. */
854 frame->localoff = PROC_LOCALOFF (proc_desc);
855 frame->pc_reg = PROC_PC_REG (proc_desc);
856
857 /* Fixup frame-pointer - only needed for top frame */
858
859 /* Fetch the frame pointer for a dummy frame from the procedure
860 descriptor. */
861 if (PROC_DESC_IS_DUMMY (proc_desc))
862 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
863
864 /* This may not be quite right, if proc has a real frame register.
865 Get the value of the frame relative sp, procedure might have been
866 interrupted by a signal at it's very start. */
867 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
868 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
869 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
870 else
871 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
872 + PROC_FRAME_OFFSET (proc_desc);
873
874 if (proc_desc == &temp_proc_desc)
875 {
876 char *name;
877
878 /* Do not set the saved registers for a sigtramp frame,
879 alpha_find_saved_registers will do that for us.
880 We can't use frame->signal_handler_caller, it is not yet set. */
881 find_pc_partial_function (frame->pc, &name,
882 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
883 if (!IN_SIGTRAMP (frame->pc, name))
884 {
885 frame->saved_regs = (CORE_ADDR *)
886 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
887 memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
888 frame->saved_regs[PC_REGNUM]
889 = frame->saved_regs[RA_REGNUM];
890 }
891 }
892 }
893 }
894
895 /* ALPHA stack frames are almost impenetrable. When execution stops,
896 we basically have to look at symbol information for the function
897 that we stopped in, which tells us *which* register (if any) is
898 the base of the frame pointer, and what offset from that register
899 the frame itself is at.
900
901 This presents a problem when trying to examine a stack in memory
902 (that isn't executing at the moment), using the "frame" command. We
903 don't have a PC, nor do we have any registers except SP.
904
905 This routine takes two arguments, SP and PC, and tries to make the
906 cached frames look as if these two arguments defined a frame on the
907 cache. This allows the rest of info frame to extract the important
908 arguments without difficulty. */
909
910 struct frame_info *
911 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
912 {
913 if (argc != 2)
914 error ("ALPHA frame specifications require two arguments: sp and pc");
915
916 return create_new_frame (argv[0], argv[1]);
917 }
918
919 /* The alpha passes the first six arguments in the registers, the rest on
920 the stack. The register arguments are eventually transferred to the
921 argument transfer area immediately below the stack by the called function
922 anyway. So we `push' at least six arguments on the stack, `reload' the
923 argument registers and then adjust the stack pointer to point past the
924 sixth argument. This algorithm simplifies the passing of a large struct
925 which extends from the registers to the stack.
926 If the called function is returning a structure, the address of the
927 structure to be returned is passed as a hidden first argument. */
928
929 CORE_ADDR
930 alpha_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
931 int struct_return, CORE_ADDR struct_addr)
932 {
933 int i;
934 int accumulate_size = struct_return ? 8 : 0;
935 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
936 struct alpha_arg
937 {
938 char *contents;
939 int len;
940 int offset;
941 };
942 struct alpha_arg *alpha_args =
943 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
944 register struct alpha_arg *m_arg;
945 char raw_buffer[sizeof (CORE_ADDR)];
946 int required_arg_regs;
947
948 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
949 {
950 struct value *arg = args[i];
951 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
952 /* Cast argument to long if necessary as the compiler does it too. */
953 switch (TYPE_CODE (arg_type))
954 {
955 case TYPE_CODE_INT:
956 case TYPE_CODE_BOOL:
957 case TYPE_CODE_CHAR:
958 case TYPE_CODE_RANGE:
959 case TYPE_CODE_ENUM:
960 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
961 {
962 arg_type = builtin_type_long;
963 arg = value_cast (arg_type, arg);
964 }
965 break;
966 default:
967 break;
968 }
969 m_arg->len = TYPE_LENGTH (arg_type);
970 m_arg->offset = accumulate_size;
971 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
972 m_arg->contents = VALUE_CONTENTS (arg);
973 }
974
975 /* Determine required argument register loads, loading an argument register
976 is expensive as it uses three ptrace calls. */
977 required_arg_regs = accumulate_size / 8;
978 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
979 required_arg_regs = ALPHA_NUM_ARG_REGS;
980
981 /* Make room for the arguments on the stack. */
982 if (accumulate_size < arg_regs_size)
983 accumulate_size = arg_regs_size;
984 sp -= accumulate_size;
985
986 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
987 sp &= ~15;
988
989 /* `Push' arguments on the stack. */
990 for (i = nargs; m_arg--, --i >= 0;)
991 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
992 if (struct_return)
993 {
994 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
995 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
996 }
997
998 /* Load the argument registers. */
999 for (i = 0; i < required_arg_regs; i++)
1000 {
1001 LONGEST val;
1002
1003 val = read_memory_integer (sp + i * 8, 8);
1004 write_register (A0_REGNUM + i, val);
1005 write_register (FPA0_REGNUM + i, val);
1006 }
1007
1008 return sp + arg_regs_size;
1009 }
1010
1011 void
1012 alpha_push_dummy_frame (void)
1013 {
1014 int ireg;
1015 struct linked_proc_info *link;
1016 alpha_extra_func_info_t proc_desc;
1017 CORE_ADDR sp = read_register (SP_REGNUM);
1018 CORE_ADDR save_address;
1019 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1020 unsigned long mask;
1021
1022 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
1023 link->next = linked_proc_desc_table;
1024 linked_proc_desc_table = link;
1025
1026 proc_desc = &link->info;
1027
1028 /*
1029 * The registers we must save are all those not preserved across
1030 * procedure calls.
1031 * In addition, we must save the PC and RA.
1032 *
1033 * Dummy frame layout:
1034 * (high memory)
1035 * Saved PC
1036 * Saved F30
1037 * ...
1038 * Saved F0
1039 * Saved R29
1040 * ...
1041 * Saved R0
1042 * Saved R26 (RA)
1043 * Parameter build area
1044 * (low memory)
1045 */
1046
1047 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1048 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1049 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1050 #define GEN_REG_SAVE_COUNT 24
1051 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1052 #define FLOAT_REG_SAVE_COUNT 23
1053 /* The special register is the PC as we have no bit for it in the save masks.
1054 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1055 #define SPECIAL_REG_SAVE_COUNT 1
1056
1057 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1058 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
1059 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1060 but keep SP aligned to a multiple of 16. */
1061 PROC_REG_OFFSET (proc_desc) =
1062 -((8 * (SPECIAL_REG_SAVE_COUNT
1063 + GEN_REG_SAVE_COUNT
1064 + FLOAT_REG_SAVE_COUNT)
1065 + 15) & ~15);
1066 PROC_FREG_OFFSET (proc_desc) =
1067 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1068
1069 /* Save general registers.
1070 The return address register is the first saved register, all other
1071 registers follow in ascending order.
1072 The PC is saved immediately below the SP. */
1073 save_address = sp + PROC_REG_OFFSET (proc_desc);
1074 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1075 write_memory (save_address, raw_buffer, 8);
1076 save_address += 8;
1077 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
1078 for (ireg = 0; mask; ireg++, mask >>= 1)
1079 if (mask & 1)
1080 {
1081 if (ireg == RA_REGNUM)
1082 continue;
1083 store_address (raw_buffer, 8, read_register (ireg));
1084 write_memory (save_address, raw_buffer, 8);
1085 save_address += 8;
1086 }
1087
1088 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1089 write_memory (sp - 8, raw_buffer, 8);
1090
1091 /* Save floating point registers. */
1092 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1093 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
1094 for (ireg = 0; mask; ireg++, mask >>= 1)
1095 if (mask & 1)
1096 {
1097 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1098 write_memory (save_address, raw_buffer, 8);
1099 save_address += 8;
1100 }
1101
1102 /* Set and save the frame address for the dummy.
1103 This is tricky. The only registers that are suitable for a frame save
1104 are those that are preserved across procedure calls (s0-s6). But if
1105 a read system call is interrupted and then a dummy call is made
1106 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1107 is satisfied. Then it returns with the s0-s6 registers set to the values
1108 on entry to the read system call and our dummy frame pointer would be
1109 destroyed. So we save the dummy frame in the proc_desc and handle the
1110 retrieval of the frame pointer of a dummy specifically. The frame register
1111 is set to the virtual frame (pseudo) register, it's value will always
1112 be read as zero and will help us to catch any errors in the dummy frame
1113 retrieval code. */
1114 PROC_DUMMY_FRAME (proc_desc) = sp;
1115 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1116 PROC_FRAME_OFFSET (proc_desc) = 0;
1117 sp += PROC_REG_OFFSET (proc_desc);
1118 write_register (SP_REGNUM, sp);
1119
1120 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1121 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
1122
1123 SET_PROC_DESC_IS_DUMMY (proc_desc);
1124 PROC_PC_REG (proc_desc) = RA_REGNUM;
1125 }
1126
1127 void
1128 alpha_pop_frame (void)
1129 {
1130 register int regnum;
1131 struct frame_info *frame = get_current_frame ();
1132 CORE_ADDR new_sp = frame->frame;
1133
1134 alpha_extra_func_info_t proc_desc = frame->proc_desc;
1135
1136 /* we need proc_desc to know how to restore the registers;
1137 if it is NULL, construct (a temporary) one */
1138 if (proc_desc == NULL)
1139 proc_desc = find_proc_desc (frame->pc, frame->next);
1140
1141 /* Question: should we copy this proc_desc and save it in
1142 frame->proc_desc? If we do, who will free it?
1143 For now, we don't save a copy... */
1144
1145 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1146 if (frame->saved_regs == NULL)
1147 alpha_find_saved_regs (frame);
1148 if (proc_desc)
1149 {
1150 for (regnum = 32; --regnum >= 0;)
1151 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
1152 write_register (regnum,
1153 read_memory_integer (frame->saved_regs[regnum],
1154 8));
1155 for (regnum = 32; --regnum >= 0;)
1156 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
1157 write_register (regnum + FP0_REGNUM,
1158 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1159 }
1160 write_register (SP_REGNUM, new_sp);
1161 flush_cached_frames ();
1162
1163 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
1164 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1165 {
1166 struct linked_proc_info *pi_ptr, *prev_ptr;
1167
1168 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1169 pi_ptr != NULL;
1170 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1171 {
1172 if (&pi_ptr->info == proc_desc)
1173 break;
1174 }
1175
1176 if (pi_ptr == NULL)
1177 error ("Can't locate dummy extra frame info\n");
1178
1179 if (prev_ptr != NULL)
1180 prev_ptr->next = pi_ptr->next;
1181 else
1182 linked_proc_desc_table = pi_ptr->next;
1183
1184 xfree (pi_ptr);
1185 }
1186 }
1187 \f
1188 /* To skip prologues, I use this predicate. Returns either PC itself
1189 if the code at PC does not look like a function prologue; otherwise
1190 returns an address that (if we're lucky) follows the prologue. If
1191 LENIENT, then we must skip everything which is involved in setting
1192 up the frame (it's OK to skip more, just so long as we don't skip
1193 anything which might clobber the registers which are being saved.
1194 Currently we must not skip more on the alpha, but we might need the
1195 lenient stuff some day. */
1196
1197 CORE_ADDR
1198 alpha_skip_prologue (CORE_ADDR pc, int lenient)
1199 {
1200 unsigned long inst;
1201 int offset;
1202 CORE_ADDR post_prologue_pc;
1203 char buf[4];
1204
1205 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1206 /* Silently return the unaltered pc upon memory errors.
1207 This could happen on OSF/1 if decode_line_1 tries to skip the
1208 prologue for quickstarted shared library functions when the
1209 shared library is not yet mapped in.
1210 Reading target memory is slow over serial lines, so we perform
1211 this check only if the target has shared libraries. */
1212 if (target_read_memory (pc, buf, 4))
1213 return pc;
1214 #endif
1215
1216 /* See if we can determine the end of the prologue via the symbol table.
1217 If so, then return either PC, or the PC after the prologue, whichever
1218 is greater. */
1219
1220 post_prologue_pc = after_prologue (pc, NULL);
1221
1222 if (post_prologue_pc != 0)
1223 return max (pc, post_prologue_pc);
1224
1225 /* Can't determine prologue from the symbol table, need to examine
1226 instructions. */
1227
1228 /* Skip the typical prologue instructions. These are the stack adjustment
1229 instruction and the instructions that save registers on the stack
1230 or in the gcc frame. */
1231 for (offset = 0; offset < 100; offset += 4)
1232 {
1233 int status;
1234
1235 status = read_memory_nobpt (pc + offset, buf, 4);
1236 if (status)
1237 memory_error (status, pc + offset);
1238 inst = extract_unsigned_integer (buf, 4);
1239
1240 /* The alpha has no delay slots. But let's keep the lenient stuff,
1241 we might need it for something else in the future. */
1242 if (lenient && 0)
1243 continue;
1244
1245 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1246 continue;
1247 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1248 continue;
1249 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1250 continue;
1251 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1252 continue;
1253
1254 if ((inst & 0xfc1f0000) == 0xb41e0000
1255 && (inst & 0xffff0000) != 0xb7fe0000)
1256 continue; /* stq reg,n($sp) */
1257 /* reg != $zero */
1258 if ((inst & 0xfc1f0000) == 0x9c1e0000
1259 && (inst & 0xffff0000) != 0x9ffe0000)
1260 continue; /* stt reg,n($sp) */
1261 /* reg != $zero */
1262 if (inst == 0x47de040f) /* bis sp,sp,fp */
1263 continue;
1264
1265 break;
1266 }
1267 return pc + offset;
1268 }
1269
1270 #if 0
1271 /* Is address PC in the prologue (loosely defined) for function at
1272 STARTADDR? */
1273
1274 static int
1275 alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc)
1276 {
1277 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1278 return pc >= startaddr && pc < end_prologue;
1279 }
1280 #endif
1281
1282 /* The alpha needs a conversion between register and memory format if
1283 the register is a floating point register and
1284 memory format is float, as the register format must be double
1285 or
1286 memory format is an integer with 4 bytes or less, as the representation
1287 of integers in floating point registers is different. */
1288 void
1289 alpha_register_convert_to_virtual (int regnum, struct type *valtype,
1290 char *raw_buffer, char *virtual_buffer)
1291 {
1292 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1293 {
1294 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1295 return;
1296 }
1297
1298 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1299 {
1300 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1301 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1302 }
1303 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1304 {
1305 ULONGEST l;
1306 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1307 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1308 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1309 }
1310 else
1311 error ("Cannot retrieve value from floating point register");
1312 }
1313
1314 void
1315 alpha_register_convert_to_raw (struct type *valtype, int regnum,
1316 char *virtual_buffer, char *raw_buffer)
1317 {
1318 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1319 {
1320 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1321 return;
1322 }
1323
1324 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1325 {
1326 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1327 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1328 }
1329 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1330 {
1331 ULONGEST l;
1332 if (TYPE_UNSIGNED (valtype))
1333 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1334 else
1335 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1336 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1337 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1338 }
1339 else
1340 error ("Cannot store value in floating point register");
1341 }
1342
1343 /* Given a return value in `regbuf' with a type `valtype',
1344 extract and copy its value into `valbuf'. */
1345
1346 void
1347 alpha_extract_return_value (struct type *valtype,
1348 char regbuf[REGISTER_BYTES], char *valbuf)
1349 {
1350 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1351 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1352 regbuf + REGISTER_BYTE (FP0_REGNUM),
1353 valbuf);
1354 else
1355 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1356 }
1357
1358 /* Given a return value in `regbuf' with a type `valtype',
1359 write its value into the appropriate register. */
1360
1361 void
1362 alpha_store_return_value (struct type *valtype, char *valbuf)
1363 {
1364 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1365 int regnum = V0_REGNUM;
1366 int length = TYPE_LENGTH (valtype);
1367
1368 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1369 {
1370 regnum = FP0_REGNUM;
1371 length = REGISTER_RAW_SIZE (regnum);
1372 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1373 }
1374 else
1375 memcpy (raw_buffer, valbuf, length);
1376
1377 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1378 }
1379
1380 /* Just like reinit_frame_cache, but with the right arguments to be
1381 callable as an sfunc. */
1382
1383 static void
1384 reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
1385 {
1386 reinit_frame_cache ();
1387 }
1388
1389 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1390 to find a convenient place in the text segment to stick a breakpoint to
1391 detect the completion of a target function call (ala call_function_by_hand).
1392 */
1393
1394 CORE_ADDR
1395 alpha_call_dummy_address (void)
1396 {
1397 CORE_ADDR entry;
1398 struct minimal_symbol *sym;
1399
1400 entry = entry_point_address ();
1401
1402 if (entry != 0)
1403 return entry;
1404
1405 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1406
1407 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1408 return 0;
1409 else
1410 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1411 }
1412
1413 /* alpha_software_single_step() is called just before we want to resume
1414 the inferior, if we want to single-step it but there is no hardware
1415 or kernel single-step support (NetBSD on Alpha, for example). We find
1416 the target of the coming instruction and breakpoint it.
1417
1418 single_step is also called just after the inferior stops. If we had
1419 set up a simulated single-step, we undo our damage. */
1420
1421 static CORE_ADDR
1422 alpha_next_pc (CORE_ADDR pc)
1423 {
1424 unsigned int insn;
1425 unsigned int op;
1426 int offset;
1427 LONGEST rav;
1428
1429 insn = read_memory_unsigned_integer (pc, sizeof (insn));
1430
1431 /* Opcode is top 6 bits. */
1432 op = (insn >> 26) & 0x3f;
1433
1434 if (op == 0x1a)
1435 {
1436 /* Jump format: target PC is:
1437 RB & ~3 */
1438 return (read_register ((insn >> 16) & 0x1f) & ~3);
1439 }
1440
1441 if ((op & 0x30) == 0x30)
1442 {
1443 /* Branch format: target PC is:
1444 (new PC) + (4 * sext(displacement)) */
1445 if (op == 0x30 || /* BR */
1446 op == 0x34) /* BSR */
1447 {
1448 branch_taken:
1449 offset = (insn & 0x001fffff);
1450 if (offset & 0x00100000)
1451 offset |= 0xffe00000;
1452 offset *= 4;
1453 return (pc + 4 + offset);
1454 }
1455
1456 /* Need to determine if branch is taken; read RA. */
1457 rav = (LONGEST) read_register ((insn >> 21) & 0x1f);
1458 switch (op)
1459 {
1460 case 0x38: /* BLBC */
1461 if ((rav & 1) == 0)
1462 goto branch_taken;
1463 break;
1464 case 0x3c: /* BLBS */
1465 if (rav & 1)
1466 goto branch_taken;
1467 break;
1468 case 0x39: /* BEQ */
1469 if (rav == 0)
1470 goto branch_taken;
1471 break;
1472 case 0x3d: /* BNE */
1473 if (rav != 0)
1474 goto branch_taken;
1475 break;
1476 case 0x3a: /* BLT */
1477 if (rav < 0)
1478 goto branch_taken;
1479 break;
1480 case 0x3b: /* BLE */
1481 if (rav <= 0)
1482 goto branch_taken;
1483 break;
1484 case 0x3f: /* BGT */
1485 if (rav > 0)
1486 goto branch_taken;
1487 break;
1488 case 0x3e: /* BGE */
1489 if (rav >= 0)
1490 goto branch_taken;
1491 break;
1492 }
1493 }
1494
1495 /* Not a branch or branch not taken; target PC is:
1496 pc + 4 */
1497 return (pc + 4);
1498 }
1499
1500 void
1501 alpha_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1502 {
1503 static CORE_ADDR next_pc;
1504 typedef char binsn_quantum[BREAKPOINT_MAX];
1505 static binsn_quantum break_mem;
1506 CORE_ADDR pc;
1507
1508 if (insert_breakpoints_p)
1509 {
1510 pc = read_pc ();
1511 next_pc = alpha_next_pc (pc);
1512
1513 target_insert_breakpoint (next_pc, break_mem);
1514 }
1515 else
1516 {
1517 target_remove_breakpoint (next_pc, break_mem);
1518 write_pc (next_pc);
1519 }
1520 }
1521
1522 void
1523 _initialize_alpha_tdep (void)
1524 {
1525 struct cmd_list_element *c;
1526
1527 tm_print_insn = print_insn_alpha;
1528
1529 /* Let the user set the fence post for heuristic_proc_start. */
1530
1531 /* We really would like to have both "0" and "unlimited" work, but
1532 command.c doesn't deal with that. So make it a var_zinteger
1533 because the user can always use "999999" or some such for unlimited. */
1534 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1535 (char *) &heuristic_fence_post,
1536 "\
1537 Set the distance searched for the start of a function.\n\
1538 If you are debugging a stripped executable, GDB needs to search through the\n\
1539 program for the start of a function. This command sets the distance of the\n\
1540 search. The only need to set it is when debugging a stripped executable.",
1541 &setlist);
1542 /* We need to throw away the frame cache when we set this, since it
1543 might change our ability to get backtraces. */
1544 c->function.sfunc = reinit_frame_cache_sfunc;
1545 add_show_from_set (c, &showlist);
1546 }