1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003-2005 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4 Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
6 This file is part of libunwind.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27 #include "_UPT_internal.h"
31 # ifdef HAVE_ASM_PTRACE_OFFSETS_H
32 # include <asm/ptrace_offsets.h>
34 # include "tdep-ia64/rse.h"
37 #if HAVE_DECL_PTRACE_POKEUSER || HAVE_TTRACE
39 _UPT_access_reg (unw_addr_space_t as
, unw_regnum_t reg
, unw_word_t
*val
,
42 struct UPT_info
*ui
= arg
;
46 Debug(16, "using pokeuser: reg: %s [%u], val: %lx, write: %d\n", unw_regname(reg
), (unsigned) reg
, (long) val
, write
);
49 Debug (16, "%s <- %lx\n", unw_regname (reg
), (long) *val
);
53 if ((unsigned) reg
- UNW_IA64_NAT
< 32)
55 unsigned long nat_bits
, mask
;
57 /* The Linux ptrace represents the statc NaT bits as a single word. */
58 mask
= ((unw_word_t
) 1) << (reg
- UNW_IA64_NAT
);
61 # warning No support for ttrace() yet.
63 nat_bits
= ptrace (PTRACE_PEEKUSER
, pid
, PT_NAT_BITS
, 0);
75 # warning No support for ttrace() yet.
78 ptrace (PTRACE_POKEUSER
, pid
, PT_NAT_BITS
, nat_bits
);
96 unsigned long ip
, psr
;
98 /* distribute bundle-addr. & slot-number across PT_IIP & PT_IPSR. */
100 # warning No support for ttrace() yet.
103 psr
= ptrace (PTRACE_PEEKUSER
, pid
, PT_CR_IPSR
, 0);
110 psr
= (psr
& ~0x3UL
<< 41) | (*val
& 0x3);
112 # warning No support for ttrace() yet.
115 ptrace (PTRACE_POKEUSER
, pid
, PT_CR_IIP
, ip
);
116 ptrace (PTRACE_POKEUSER
, pid
, PT_CR_IPSR
, psr
);
124 # warning No support for ttrace() yet.
127 ip
= ptrace (PTRACE_PEEKUSER
, pid
, PT_CR_IIP
, 0);
131 *val
= ip
+ ((psr
>> 41) & 0x3);
136 case UNW_IA64_AR_BSPSTORE
:
137 reg
= UNW_IA64_AR_BSP
;
140 case UNW_IA64_AR_BSP
:
143 unsigned long sof
, cfm
, bsp
;
146 # warning No support for ttrace() yet.
148 /* Account for the fact that ptrace() expects bsp to point
149 _after_ the current register frame. */
151 cfm
= ptrace (PTRACE_PEEKUSER
, pid
, PT_CFM
, 0);
159 bsp
= rse_skip_regs (*val
, sof
);
161 # warning No support for ttrace() yet.
164 ptrace (PTRACE_POKEUSER
, pid
, PT_AR_BSP
, bsp
);
172 # warning No support for ttrace() yet.
175 bsp
= ptrace (PTRACE_PEEKUSER
, pid
, PT_AR_BSP
, 0);
179 *val
= rse_skip_regs (bsp
, -sof
);
185 /* If we change CFM, we need to adjust ptrace's notion of bsp
186 accordingly, so that the real bsp remains unchanged. */
189 unsigned long new_sof
, old_sof
, cfm
, bsp
;
192 # warning No support for ttrace() yet.
195 bsp
= ptrace (PTRACE_PEEKUSER
, pid
, PT_AR_BSP
, 0);
196 cfm
= ptrace (PTRACE_PEEKUSER
, pid
, PT_CFM
, 0);
200 old_sof
= (cfm
& 0x7f);
201 new_sof
= (*val
& 0x7f);
202 if (old_sof
!= new_sof
)
204 bsp
= rse_skip_regs (bsp
, -old_sof
+ new_sof
);
206 # warning No support for ttrace() yet.
209 ptrace (PTRACE_POKEUSER
, pid
, PT_AR_BSP
, 0);
215 # warning No support for ttrace() yet.
218 ptrace (PTRACE_POKEUSER
, pid
, PT_CFM
, *val
);
226 #endif /* End of IA64 */
228 if ((unsigned) reg
>= ARRAY_SIZE (_UPT_reg_offset
))
231 Debug(2, "register out of range: >= %zu / %zu\n", sizeof(_UPT_reg_offset
), sizeof(_UPT_reg_offset
[0]));
238 # warning No support for ttrace() yet.
242 ptrace (PTRACE_POKEUSER
, pid
, _UPT_reg_offset
[reg
], *val
);
245 Debug(16, "ptrace PEEKUSER pid: %lu , reg: %lu , offs: %lu\n", (unsigned long)pid
, (unsigned long)reg
,
246 (unsigned long)_UPT_reg_offset
[reg
]);
248 *val
= ptrace (PTRACE_PEEKUSER
, pid
, _UPT_reg_offset
[reg
], 0);
252 Debug(2, "ptrace failure\n");
258 #ifdef UNW_TARGET_IA64
263 Debug (16, "%s[%u] -> %lx\n", unw_regname (reg
), (unsigned) reg
, (long) *val
);
268 Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg
), reg
, strerror (errno
));
271 #elif HAVE_DECL_PT_GETREGS
273 _UPT_access_reg (unw_addr_space_t as
, unw_regnum_t reg
, unw_word_t
*val
,
274 int write
, void *arg
)
276 struct UPT_info
*ui
= arg
;
282 Debug(16, "using getregs: reg: %s [%u], val: %lx, write: %u\n", unw_regname(reg
), (unsigned) reg
, (long) val
, write
);
285 Debug (16, "%s [%u] <- %lx\n", unw_regname (reg
), (unsigned) reg
, (long) *val
);
287 if ((unsigned) reg
>= ARRAY_SIZE (_UPT_reg_offset
))
292 r
= (char *)®s
+ _UPT_reg_offset
[reg
];
293 if (ptrace(PT_GETREGS
, pid
, (caddr_t
)®s
, 0) == -1)
296 memcpy(r
, val
, sizeof(unw_word_t
));
297 if (ptrace(PT_SETREGS
, pid
, (caddr_t
)®s
, 0) == -1)
300 memcpy(val
, r
, sizeof(unw_word_t
));
304 Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg
), reg
, strerror (errno
));