init.h revision 5e34685f1847c7b616bee0055176231ef5012d37
1/* libunwind - a platform-independent unwind library
2   Copyright (C) 2002 Hewlett-Packard Co
3	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7libunwind is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12libunwind is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17As a special exception, if you link this library with other files to
18produce an executable, this library does not by itself cause the
19resulting executable to be covered by the GNU General Public License.
20This exception does not however invalidate any other reasons why the
21executable file might be covered by the GNU General Public
22License.  */
23
24#include "unwind_i.h"
25
26static inline
27common_init (struct ia64_cursor *c)
28{
29  int i, ret;
30
31  c->cfm_loc =		IA64_REG_LOC (c, UNW_IA64_CFM);
32  c->top_rnat_loc =	IA64_REG_LOC (c, UNW_IA64_AR_RNAT);
33  c->bsp_loc =		IA64_REG_LOC (c, UNW_IA64_AR_BSP);
34  c->bspstore_loc =	IA64_REG_LOC (c, UNW_IA64_AR_BSPSTORE);
35  c->pfs_loc =		IA64_REG_LOC (c, UNW_IA64_AR_PFS);
36  c->rnat_loc =		IA64_REG_LOC (c, UNW_IA64_AR_RNAT);
37  c->ip_loc =		IA64_REG_LOC (c, UNW_IA64_IP);
38  c->pri_unat_loc =	0;	/* no primary UNaT location */
39  c->unat_loc =		IA64_REG_LOC (c, UNW_IA64_AR_UNAT);
40  c->pr_loc =		IA64_REG_LOC (c, UNW_IA64_PR);
41  c->lc_loc =		IA64_REG_LOC (c, UNW_IA64_AR_LC);
42  c->fpsr_loc =		IA64_REG_LOC (c, UNW_IA64_AR_FPSR);
43
44  c->r4_loc = IA64_REG_LOC (c, UNW_IA64_GR + 4);
45  c->r5_loc = IA64_REG_LOC (c, UNW_IA64_GR + 5);
46  c->r6_loc = IA64_REG_LOC (c, UNW_IA64_GR + 6);
47  c->r7_loc = IA64_REG_LOC (c, UNW_IA64_GR + 7);
48
49  /* This says that each NaT bit is stored along with the
50     corresponding preserved register: */
51  c->nat4_loc = IA64_LOC (4, 0);
52  c->nat5_loc = IA64_LOC (5, 0);
53  c->nat6_loc = IA64_LOC (6, 0);
54  c->nat7_loc = IA64_LOC (7, 0);
55
56  c->b1_loc = IA64_REG_LOC (c, UNW_IA64_BR + 1);
57  c->b2_loc = IA64_REG_LOC (c, UNW_IA64_BR + 2);
58  c->b3_loc = IA64_REG_LOC (c, UNW_IA64_BR + 3);
59  c->b4_loc = IA64_REG_LOC (c, UNW_IA64_BR + 4);
60  c->b5_loc = IA64_REG_LOC (c, UNW_IA64_BR + 5);
61
62  c->f2_loc = IA64_FPREG_LOC (c, UNW_IA64_FR + 2);
63  c->f3_loc = IA64_FPREG_LOC (c, UNW_IA64_FR + 3);
64  c->f4_loc = IA64_FPREG_LOC (c, UNW_IA64_FR + 4);
65  c->f5_loc = IA64_FPREG_LOC (c, UNW_IA64_FR + 5);
66  for (i = 16; i <= 31; ++i)
67    c->fr_loc[i - 16] = IA64_FPREG_LOC (c, UNW_IA64_FR + i);
68
69  ret = ia64_get (c, c->pr_loc, &c->pr);
70  if (ret < 0)
71    return ret;
72
73  ret = ia64_get (c, c->ip_loc, &c->ip);
74  if (ret < 0)
75    return ret;
76
77  ret = ia64_get (c, IA64_REG_LOC (c, UNW_IA64_SP), &c->sp);
78  if (ret < 0)
79    return ret;
80
81  c->psp = c->sp;
82
83  ret = ia64_get (c, c->bsp_loc, &c->bsp);
84  if (ret < 0)
85    return ret;
86
87  c->rbs_top = c->bsp;
88  c->pi.flags = 0;
89
90#ifdef UNW_LOCAL_ONLY
91  c->eh_args[0] = c->eh_args[1] = c->eh_args[2] = c->eh_args[3] = 0;
92#else
93  for (i = 0; i < 4; ++i)
94    {
95      ret = ia64_get (c, IA64_REG_LOC (c, UNW_IA64_GR + 15 + i),
96		      &c->eh_args[i]);
97      if (ret < 0)
98	{
99	  if (ret == -UNW_EBADREG)
100	    c->eh_args[i] = 0;
101	  else
102	    return ret;
103	}
104    }
105#endif
106
107#ifdef IA64_UNW_SCRIPT_CACHE
108  c->hint = 0;
109  c->prev_script = 0;
110#endif
111  return ia64_get_proc_info (c);
112}
113