OSDN Git Service

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