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