OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [alpha-tdep.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.