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>
4
5 This file is part of libunwind.
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26 #include <stdlib.h>
27
28 #include "unwind_i.h"
29 #include "offsets.h"
30
31 /* This routine is responsible for copying the register values in
32 cursor C and establishing them as the current machine state. */
33
34 static inline int
establish_machine_state(struct cursor * c)35 establish_machine_state (struct cursor *c)
36 {
37 int (*access_reg) (unw_addr_space_t, unw_regnum_t, unw_word_t *,
38 int write, void *);
39 int (*access_fpreg) (unw_addr_space_t, unw_regnum_t, unw_fpreg_t *,
40 int write, void *);
41 unw_addr_space_t as = c->dwarf.as;
42 void *arg = c->dwarf.as_arg;
43 unw_fpreg_t fpval;
44 unw_word_t val;
45 int reg;
46
47 access_reg = as->acc.access_reg;
48 access_fpreg = as->acc.access_fpreg;
49
50 Debug (8, "copying out cursor state\n");
51
52 for (reg = 0; reg <= UNW_REG_LAST; ++reg)
53 {
54 Debug (16, "copying %s %d\n", unw_regname (reg), reg);
55 if (unw_is_fpreg (reg))
56 {
57 if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
58 (*access_fpreg) (as, reg, &fpval, 1, arg);
59 }
60 else
61 {
62 if (tdep_access_reg (c, reg, &val, 0) >= 0)
63 (*access_reg) (as, reg, &val, 1, arg);
64 }
65 }
66 return 0;
67 }
68
69 PROTECTED int
unw_resume(unw_cursor_t * cursor)70 unw_resume (unw_cursor_t *cursor)
71 {
72 struct cursor *c = (struct cursor *) cursor;
73 int ret;
74
75 Debug (1, "(cursor=%p)\n", c);
76
77 if ((ret = establish_machine_state (c)) < 0)
78 return ret;
79
80 return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
81 c->dwarf.as_arg);
82 }
83