summaryrefslogtreecommitdiff
path: root/src/ia64/unw_step.c
blob: 039a847795983db5608afffe8793cc98baa2cd5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* libunwind - a platform-independent unwind library
   Copyright (C) 2001-2002 Hewlett-Packard Co
	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>

This file is part of libunwind.

libunwind is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

libunwind is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public
License.  */

#include <signal.h>

#include "rse.h"
#include "unwind_i.h"

int
ia64_get_frame_state (struct ia64_cursor *c)
{
  unw_word_t prev_ip, prev_sp, prev_bsp, ip, pr, num_regs, cfm;
  int ret;

  prev_ip = c->ip;
  prev_sp = c->sp;
  prev_bsp = c->bsp;

  /* restore the ip */
  ret = ia64_get (c, c->rp_loc, &ip);
  if (ret < 0)
    return ret;
  c->ip = ip;

  if ((ip & 0xf) != 0)
    {
      /* don't let obviously bad addresses pollute the cache */
      debug (1, "%s: rejecting bad ip=0x%lx\n",  __FUNCTION__, c->ip);
      c->rp_loc = 0;
      return -UNW_EINVALIDIP;
    }

  /* restore the cfm: */
  c->cfm_loc = c->pfs_loc;

  /* restore the bsp: */
  pr = c->pr;
  num_regs = 0;
  if ((c->pi.flags & IA64_FLAG_SIGTRAMP))
    {
      unw_word_t sigcontext_addr, sigcontext_flags;

      ret = ia64_get (c, c->sp + 0x10, &sigcontext_addr);
      if (ret < 0)
	return ret;

      ret = ia64_get (c, (sigcontext_addr
			  + struct_offset (struct sigcontext, sc_flags)),
		      &sigcontext_flags);
      if (ret < 0)
	return ret;

      if ((sigcontext_flags & IA64_SC_FLAG_IN_SYSCALL_BIT) == 0)
	{
	  unw_word_t cfm;

	  ret = ia64_get (c, c->cfm_loc, &cfm);
	  if (ret < 0)
	    return ret;

	  num_regs = cfm & 0x7f;	/* size of frame */
	}
      c->pfs_loc = (c->sp + 0x10 + struct_offset (struct sigcontext,
						  sc_ar_pfs));
    }
  else
    {
      ret = ia64_get (c, c->cfm_loc, &cfm);
      if (ret < 0)
	return ret;
      num_regs = (cfm >> 7) & 0x7f;	/* size of locals */
    }
  c->bsp = (unsigned long) ia64_rse_skip_regs ((unsigned long *) c->bsp,
					       -num_regs);

  /* restore the sp: */
  c->sp = c->psp;

  if (c->ip == prev_ip && c->sp == prev_sp && c->bsp == prev_bsp)
    {
      dprintf ("%s: ip, sp, bsp remain unchanged; stopping here (ip=0x%lx)\n",
	       __FUNCTION__, ip);
      STAT(unw.stat.api.unwind_time += ia64_get_itc () - start);
      return -UNW_EBADFRAME;
    }

  /* as we unwind, the saved ar.unat becomes the primary unat: */
  c->pri_unat_loc = c->unat_loc;

  /* restore the predicates: */
  ret = ia64_get (c, c->pr_loc, &c->pr);
  if (ret < 0)
    return ret;

  return ia64_get_proc_info (c);
}


int
unw_step (unw_cursor_t *cursor)
{
  struct ia64_cursor *c = (struct ia64_cursor *) cursor;
  int ret;

  ret = ia64_find_save_locs (c);
  if (ret < 0)
    return ret;

  ret = ia64_get_frame_state (c);
  if (ret < 0)
    return ret;

  return (c->ip == 0) ? 0 : 1;
}