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