1 /* libunwind - a platform-independent unwind library
2 Copyright (c) 2002-2004 Hewlett-Packard Development Company, L.P.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 Modified for x86_64 by Max Asbock <masbock@us.ibm.com>
7 This file is part of libunwind.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
31 static inline dwarf_loc_t
32 linux_scratch_loc (struct cursor
*c
, unw_regnum_t reg
)
34 unw_word_t addr
= c
->sigcontext_addr
;
36 switch (c
->sigcontext_format
)
39 return DWARF_REG_LOC (&c
->dwarf
, reg
);
41 case X86_64_SCF_LINUX_RT_SIGFRAME
:
42 addr
+= LINUX_UC_MCONTEXT_OFF
;
45 case X86_64_SCF_FREEBSD_SIGFRAME
:
46 addr
+= FREEBSD_UC_MCONTEXT_OFF
;
50 return DWARF_REG_LOC (&c
->dwarf
, reg
);
55 x86_64_scratch_loc (struct cursor
*c
, unw_regnum_t reg
)
57 if (c
->sigcontext_addr
)
58 return linux_scratch_loc (c
, reg
);
60 return DWARF_REG_LOC (&c
->dwarf
, reg
);
65 tdep_access_reg (struct cursor
*c
, unw_regnum_t reg
, unw_word_t
*valp
,
68 dwarf_loc_t loc
= DWARF_NULL_LOC
;
77 c
->dwarf
.ip
= *valp
; /* also update the RIP cache */
78 loc
= c
->dwarf
.loc
[RIP
];
84 return -UNW_EREADONLYREG
;
90 arg_num
= reg
- UNW_X86_64_RAX
;
91 mask
= (1 << arg_num
);
94 c
->dwarf
.eh_args
[arg_num
] = *valp
;
95 c
->dwarf
.eh_valid_mask
|= mask
;
98 else if ((c
->dwarf
.eh_valid_mask
& mask
) != 0)
100 *valp
= c
->dwarf
.eh_args
[arg_num
];
104 loc
= c
->dwarf
.loc
[(reg
== UNW_X86_64_RAX
) ? RAX
: RDX
];
107 case UNW_X86_64_RCX
: loc
= c
->dwarf
.loc
[RCX
]; break;
108 case UNW_X86_64_RBX
: loc
= c
->dwarf
.loc
[RBX
]; break;
110 case UNW_X86_64_RBP
: loc
= c
->dwarf
.loc
[RBP
]; break;
111 case UNW_X86_64_RSI
: loc
= c
->dwarf
.loc
[RSI
]; break;
112 case UNW_X86_64_RDI
: loc
= c
->dwarf
.loc
[RDI
]; break;
113 case UNW_X86_64_R8
: loc
= c
->dwarf
.loc
[R8
]; break;
114 case UNW_X86_64_R9
: loc
= c
->dwarf
.loc
[R9
]; break;
115 case UNW_X86_64_R10
: loc
= c
->dwarf
.loc
[R10
]; break;
116 case UNW_X86_64_R11
: loc
= c
->dwarf
.loc
[R11
]; break;
117 case UNW_X86_64_R12
: loc
= c
->dwarf
.loc
[R12
]; break;
118 case UNW_X86_64_R13
: loc
= c
->dwarf
.loc
[R13
]; break;
119 case UNW_X86_64_R14
: loc
= c
->dwarf
.loc
[R14
]; break;
120 case UNW_X86_64_R15
: loc
= c
->dwarf
.loc
[R15
]; break;
123 Debug (1, "bad register number %u\n", reg
);
128 return dwarf_put (&c
->dwarf
, loc
, *valp
);
130 return dwarf_get (&c
->dwarf
, loc
, valp
);
134 tdep_access_fpreg (struct cursor
*c
, unw_regnum_t reg
, unw_fpreg_t
*valp
,