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