Imported Upstream version 1.3.1
[platform/upstream/libunwind.git] / src / tilegx / Gresume.c
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3    Copyright (C) 2014 Tilera Corp.
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
27 #include "unwind_i.h"
28 #include "offsets.h"
29 #include <ucontext.h>
30
31 #ifndef UNW_REMOTE_ONLY
32
33 HIDDEN inline int
34 tilegx_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
35 {
36   int i;
37   struct cursor *c = (struct cursor *) cursor;
38   ucontext_t *uc = c->dwarf.as_arg;
39
40   Debug (1, "(cursor=%p\n", c);
41
42   return setcontext(uc);
43 }
44
45 #endif /* !UNW_REMOTE_ONLY */
46
47 static inline void
48 establish_machine_state (struct cursor *c)
49 {
50   unw_addr_space_t as = c->dwarf.as;
51   void *arg = c->dwarf.as_arg;
52   unw_fpreg_t fpval;
53   unw_word_t val;
54   int reg;
55
56   Debug (8, "copying out cursor state\n");
57
58   for (reg = 0; reg <= UNW_REG_LAST; ++reg)
59     {
60       Debug (16, "copying %s %d\n", unw_regname (reg), reg);
61
62       if (unw_is_fpreg (reg))
63         {
64           Debug (1, "no fp!");
65           abort ();
66         }
67       else
68         {
69           if (tdep_access_reg (c, reg, &val, 0) >= 0)
70             as->acc.access_reg (as, reg, &val, 1, arg);
71         }
72     }
73 }
74
75 int
76 unw_resume (unw_cursor_t *cursor)
77 {
78   struct cursor *c = (struct cursor *) cursor;
79
80   Debug (1, "(cursor=%p) ip=0x%lx\n", c, c->dwarf.ip);
81
82   if (!c->dwarf.ip)
83     {
84       /* This can happen easily when the frame-chain gets truncated
85          due to bad or missing unwind-info.  */
86       Debug (1, "refusing to resume execution at address 0\n");
87       return -UNW_EINVAL;
88     }
89
90   establish_machine_state (c);
91
92   return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
93                                      c->dwarf.as_arg);
94 }