Gresume.c revision 1e10c2931d970d0ae5426bba6ba9e1c2998c7451
1/* libunwind - a platform-independent unwind library
2   Copyright (C) 2008 CodeSourcery
3   Copyright 2011 Linaro Limited
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25
26#include "unwind_i.h"
27
28#ifndef UNW_REMOTE_ONLY
29
30HIDDEN inline int
31arm_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
32{
33#ifdef __linux__
34  struct cursor *c = (struct cursor *) cursor;
35  ucontext_t *uc = c->dwarf.as_arg;
36  unsigned long regs[10];
37
38  /* Copy the register contents to be restored.  */
39  regs[0] = uc->uc_mcontext.arm_r4;
40  regs[1] = uc->uc_mcontext.arm_r5;
41  regs[2] = uc->uc_mcontext.arm_r6;
42  regs[3] = uc->uc_mcontext.arm_r7;
43  regs[4] = uc->uc_mcontext.arm_r8;
44  regs[5] = uc->uc_mcontext.arm_r9;
45  regs[6] = uc->uc_mcontext.arm_r10;
46  regs[7] = uc->uc_mcontext.arm_fp;
47  regs[8] = uc->uc_mcontext.arm_sp;
48  regs[9] = uc->uc_mcontext.arm_lr;
49
50  /* Restore the registers.  */
51  asm __volatile__ (
52    "ldmia %0, {r4-r12, lr}\n"
53    "mov sp, r12\n"
54    "bx lr\n"
55    : : "r" (regs) :
56  );
57#else
58  printf ("%s: implement me\n", __FUNCTION__);
59#endif
60  return -UNW_EINVAL;
61}
62
63#endif /* !UNW_REMOTE_ONLY */
64
65static inline void
66establish_machine_state (struct cursor *c)
67{
68  unw_addr_space_t as = c->dwarf.as;
69  void *arg = c->dwarf.as_arg;
70  unw_fpreg_t fpval;
71  unw_word_t val;
72  int reg;
73
74  Debug (8, "copying out cursor state\n");
75
76  for (reg = 0; reg <= UNW_REG_LAST; ++reg)
77    {
78      Debug (16, "copying %s %d\n", unw_regname (reg), reg);
79      if (unw_is_fpreg (reg))
80	{
81	  if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
82	    as->acc.access_fpreg (as, reg, &fpval, 1, arg);
83	}
84      else
85	{
86	  if (tdep_access_reg (c, reg, &val, 0) >= 0)
87	    as->acc.access_reg (as, reg, &val, 1, arg);
88	}
89    }
90}
91
92PROTECTED int
93unw_resume (unw_cursor_t *cursor)
94{
95  struct cursor *c = (struct cursor *) cursor;
96
97  Debug (1, "(cursor=%p)\n", c);
98
99  if (!c->dwarf.ip)
100    {
101      /* This can happen easily when the frame-chain gets truncated
102	 due to bad or missing unwind-info.  */
103      Debug (1, "refusing to resume execution at address 0\n");
104      return -UNW_EINVAL;
105    }
106
107  establish_machine_state (c);
108
109  return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
110				     c->dwarf.as_arg);
111}
112