Gregs.c revision a766efd844260866e0d216f6eeef87f4593f60b2
1a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock/* libunwind - a platform-independent unwind library
2a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock   Copyright (c) 2002-2004 Hewlett-Packard Development Company, L.P.
3a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
5a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock   Modified for x86_64 by Max Asbock <masbock@us.ibm.com>
6a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
7a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockThis file is part of libunwind.
8a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
9a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockPermission is hereby granted, free of charge, to any person obtaining
10a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbocka copy of this software and associated documentation files (the
11a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock"Software"), to deal in the Software without restriction, including
12a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockwithout limitation the rights to use, copy, modify, merge, publish,
13a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockdistribute, sublicense, and/or sell copies of the Software, and to
14a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockpermit persons to whom the Software is furnished to do so, subject to
15a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockthe following conditions:
16a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
17a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockThe above copyright notice and this permission notice shall be
18a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockincluded in all copies or substantial portions of the Software.
19a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
20a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
28a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock#include "unwind_i.h"
29a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
30a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock#if 0
31a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockstatic inline dwarf_loc_t
32a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbocklinux_scratch_loc (struct cursor *c, unw_regnum_t reg)
33a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock{
34a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  unw_word_t addr = c->sigcontext_addr;
35a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
36a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  switch (c->sigcontext_format)
37a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    {
38a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case X86_64_SCF_NONE:
39a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      return DWARF_REG_LOC (&c->dwarf, reg);
40a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
41a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case X86_64_SCF_LINUX_RT_SIGFRAME:
42a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      addr += LINUX_UC_MCONTEXT_OFF;
43a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      break;
44a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    }
45a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
46a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  return DWARF_REG_LOC (&c->dwarf, reg);
47a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
48a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock}
49a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
50a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockHIDDEN dwarf_loc_t
51a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockx86_64_scratch_loc (struct cursor *c, unw_regnum_t reg)
52a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock{
53a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  if (c->sigcontext_addr)
54a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    return linux_scratch_loc (c, reg);
55a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  else
56a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    return DWARF_REG_LOC (&c->dwarf, reg);
57a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock}
58a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock#endif
59a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
60a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockHIDDEN int
61a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbocktdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp,
62a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock		 int write)
63a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock{
64a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  dwarf_loc_t loc = DWARF_NULL_LOC;
65a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
66a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  switch (reg)
67a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    {
68a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
69a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RIP:
70a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      if (write)
71a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock	c->dwarf.ip = *valp;		/* also update the RIP cache */
72a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      loc = c->dwarf.loc[RIP];
73a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      break;
74a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
75a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_CFA:
76a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      if (write)
77a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock	return -UNW_EREADONLYREG;
78a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      *valp = c->dwarf.cfa;
79a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      return 0;
80a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
81a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RAX: loc = c->dwarf.loc[RAX]; break;
82a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RCX: loc = c->dwarf.loc[RCX]; break;
83a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RDX: loc = c->dwarf.loc[RDX]; break;
84a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RBX: loc = c->dwarf.loc[RBX]; break;
85a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RSP: loc = c->dwarf.loc[RSP]; break;
86a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RBP: loc = c->dwarf.loc[RBP]; break;
87a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RSI: loc = c->dwarf.loc[RSI]; break;
88a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_RDI: loc = c->dwarf.loc[RDI]; break;
89a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R8: loc = c->dwarf.loc[R8]; break;
90a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R9: loc = c->dwarf.loc[R9]; break;
91a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R10: loc = c->dwarf.loc[R10]; break;
92a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R11: loc = c->dwarf.loc[R11]; break;
93a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R12: loc = c->dwarf.loc[R12]; break;
94a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R13: loc = c->dwarf.loc[R13]; break;
95a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R14: loc = c->dwarf.loc[R14]; break;
96a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    case UNW_X86_64_R15: loc = c->dwarf.loc[R15]; break;
97a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
98a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    default:
99a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      Debug (1, "bad register number %u\n", reg);
100a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      return -UNW_EBADREG;
101a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    }
102a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
103a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  if (write)
104a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    return dwarf_put (&c->dwarf, loc, *valp);
105a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock  else
106a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock    return dwarf_get (&c->dwarf, loc, valp);
107a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock}
108a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock
109a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbockHIDDEN int
110a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbocktdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp,
111a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock		   int write)
112a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock{
113a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock      return -UNW_EBADREG;
114a766efd844260866e0d216f6eeef87f4593f60b2ibm.com!masbock}
115