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