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