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