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