• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2006-2007 IBM
3    Contributed by
4      Corey Ashford <cjashfor@us.ibm.com>
5      Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
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 #ifndef ucontext_i_h
27 #define ucontext_i_h
28 
29 #include <ucontext.h>
30 
31 #if defined(__linux__)
32 /* These values were derived by reading
33    /usr/src/linux-2.6.18-1.8/arch/um/include/sysdep-ppc/ptrace.h and
34    /usr/src/linux-2.6.18-1.8/arch/powerpc/kernel/ppc32.h
35 */
36 
37 #define NIP_IDX         32
38 #define MSR_IDX         33
39 #define ORIG_GPR3_IDX   34
40 #define CTR_IDX         35
41 #define LINK_IDX        36
42 #define XER_IDX         37
43 #define CCR_IDX         38
44 #define SOFTE_IDX       39
45 #define TRAP_IDX        40
46 #define DAR_IDX         41
47 #define DSISR_IDX       42
48 #define RESULT_IDX      43
49 
50 #define VSCR_IDX        32
51 #define VRSAVE_IDX      33
52 
53 #define UC_MCONTEXT_V_REGS ( ((void *)&dmy_ctxt.uc_mcontext.v_regs - (void *)&dmy_ctxt) )
54 
55 #define _UC_MCONTEXT_GPR(x) ( ((void *)&dmy_ctxt.uc_mcontext.gp_regs[x] - (void *)&dmy_ctxt) )
56 #define _UC_MCONTEXT_FPR(x) ( ((void *)&dmy_ctxt.uc_mcontext.fp_regs[x] - (void *)&dmy_ctxt) )
57 #define _UC_MCONTEXT_VR(x)  ( ((void *)&dmy_vrregset.vrregs[x] - (void *)&dmy_vrregset) )
58 
59 /* These are dummy structures used only for obtaining the offsets of the
60    various structure members. */
61 static ucontext_t dmy_ctxt;
62 static vrregset_t dmy_vrregset;
63 
64 #elif defined(__FreeBSD__)
65 /* See /usr/src/sys/powerpc/include/ucontext.h.
66    FreeBSD uses a different structure than Linux.
67 */
68 
69 #define NIP_IDX         36
70 #define MSR_IDX         37
71 //#define ORIG_GPR3_IDX
72 #define CTR_IDX         35
73 #define LINK_IDX        32
74 #define XER_IDX         34
75 #define CCR_IDX         33
76 //#define SOFTE_IDX
77 //#define TRAP_IDX
78 #define DAR_IDX         39
79 #define DSISR_IDX       40
80 //#define RESULT_IDX
81 
82 #define UC_MCONTEXT_V_REGS (((void *)&dmy_ctxt.mc_avec - (void *)&dmy_ctxt))
83 
84 #define _UC_MCONTEXT_GPR(_x) ( ((void *)&dmy_ctxt.mc_gpr[_x] - (void *)&dmy_ctxt) )
85 #define _UC_MCONTEXT_FPR(_x) ( ((void *)&dmy_ctxt.mc_fpreg[_x] - (void *)&dmy_ctxt) )
86 #define _UC_MCONTEXT_VR(_x) ( ((void *)&dmy_ctxt.mc_avec[_x] - (void *)&dmy_ctxt.mc_avec) )
87 
88 /* These are dummy structures used only for obtaining the offsets of the
89    various structure members. */
90 static struct __mcontext dmy_ctxt;
91 
92 #else
93 #error "Not implemented!"
94 #endif
95 
96 #define UC_MCONTEXT_GREGS_R0 _UC_MCONTEXT_GPR(0)
97 #define UC_MCONTEXT_GREGS_R1 _UC_MCONTEXT_GPR(1)
98 #define UC_MCONTEXT_GREGS_R2 _UC_MCONTEXT_GPR(2)
99 #define UC_MCONTEXT_GREGS_R3 _UC_MCONTEXT_GPR(3)
100 #define UC_MCONTEXT_GREGS_R4 _UC_MCONTEXT_GPR(4)
101 #define UC_MCONTEXT_GREGS_R5 _UC_MCONTEXT_GPR(5)
102 #define UC_MCONTEXT_GREGS_R6 _UC_MCONTEXT_GPR(6)
103 #define UC_MCONTEXT_GREGS_R7 _UC_MCONTEXT_GPR(7)
104 #define UC_MCONTEXT_GREGS_R8 _UC_MCONTEXT_GPR(8)
105 #define UC_MCONTEXT_GREGS_R9 _UC_MCONTEXT_GPR(9)
106 #define UC_MCONTEXT_GREGS_R10 _UC_MCONTEXT_GPR(10)
107 #define UC_MCONTEXT_GREGS_R11 _UC_MCONTEXT_GPR(11)
108 #define UC_MCONTEXT_GREGS_R12 _UC_MCONTEXT_GPR(12)
109 #define UC_MCONTEXT_GREGS_R13 _UC_MCONTEXT_GPR(13)
110 #define UC_MCONTEXT_GREGS_R14 _UC_MCONTEXT_GPR(14)
111 #define UC_MCONTEXT_GREGS_R15 _UC_MCONTEXT_GPR(15)
112 #define UC_MCONTEXT_GREGS_R16 _UC_MCONTEXT_GPR(16)
113 #define UC_MCONTEXT_GREGS_R17 _UC_MCONTEXT_GPR(17)
114 #define UC_MCONTEXT_GREGS_R18 _UC_MCONTEXT_GPR(18)
115 #define UC_MCONTEXT_GREGS_R19 _UC_MCONTEXT_GPR(19)
116 #define UC_MCONTEXT_GREGS_R20 _UC_MCONTEXT_GPR(20)
117 #define UC_MCONTEXT_GREGS_R21 _UC_MCONTEXT_GPR(21)
118 #define UC_MCONTEXT_GREGS_R22 _UC_MCONTEXT_GPR(22)
119 #define UC_MCONTEXT_GREGS_R23 _UC_MCONTEXT_GPR(23)
120 #define UC_MCONTEXT_GREGS_R24 _UC_MCONTEXT_GPR(24)
121 #define UC_MCONTEXT_GREGS_R25 _UC_MCONTEXT_GPR(25)
122 #define UC_MCONTEXT_GREGS_R26 _UC_MCONTEXT_GPR(26)
123 #define UC_MCONTEXT_GREGS_R27 _UC_MCONTEXT_GPR(27)
124 #define UC_MCONTEXT_GREGS_R28 _UC_MCONTEXT_GPR(28)
125 #define UC_MCONTEXT_GREGS_R29 _UC_MCONTEXT_GPR(29)
126 #define UC_MCONTEXT_GREGS_R30 _UC_MCONTEXT_GPR(30)
127 #define UC_MCONTEXT_GREGS_R31 _UC_MCONTEXT_GPR(31)
128 #define UC_MCONTEXT_GREGS_NIP _UC_MCONTEXT_GPR(NIP_IDX)
129 #define UC_MCONTEXT_GREGS_MSR _UC_MCONTEXT_GPR(MSR_IDX)
130 #ifdef ORIG_GPR3_IDX
131 #define UC_MCONTEXT_GREGS_ORIG_GPR3 _UC_MCONTEXT_GPR(ORIG_GPR3_IDX)
132 #endif
133 #define UC_MCONTEXT_GREGS_CTR _UC_MCONTEXT_GPR(CTR_IDX)
134 #define UC_MCONTEXT_GREGS_LINK _UC_MCONTEXT_GPR(LINK_IDX)
135 #define UC_MCONTEXT_GREGS_XER _UC_MCONTEXT_GPR(XER_IDX)
136 #define UC_MCONTEXT_GREGS_CCR _UC_MCONTEXT_GPR(CCR_IDX)
137 #ifdef SOFTE_IDX
138 #define UC_MCONTEXT_GREGS_SOFTE _UC_MCONTEXT_GPR(SOFTE_IDX)
139 #endif
140 #ifdef TRAP_IDX
141 #define UC_MCONTEXT_GREGS_TRAP _UC_MCONTEXT_GPR(TRAP_IDX)
142 #endif
143 #define UC_MCONTEXT_GREGS_DAR _UC_MCONTEXT_GPR(DAR_IDX)
144 #define UC_MCONTEXT_GREGS_DSISR _UC_MCONTEXT_GPR(DSISR_IDX)
145 #ifdef RESULT_IDX
146 #define UC_MCONTEXT_GREGS_RESULT _UC_MCONTEXT_GPR(RESULT_IDX)
147 #endif
148 
149 #define UC_MCONTEXT_FREGS_R0 _UC_MCONTEXT_FPR(0)
150 #define UC_MCONTEXT_FREGS_R1 _UC_MCONTEXT_FPR(1)
151 #define UC_MCONTEXT_FREGS_R2 _UC_MCONTEXT_FPR(2)
152 #define UC_MCONTEXT_FREGS_R3 _UC_MCONTEXT_FPR(3)
153 #define UC_MCONTEXT_FREGS_R4 _UC_MCONTEXT_FPR(4)
154 #define UC_MCONTEXT_FREGS_R5 _UC_MCONTEXT_FPR(5)
155 #define UC_MCONTEXT_FREGS_R6 _UC_MCONTEXT_FPR(6)
156 #define UC_MCONTEXT_FREGS_R7 _UC_MCONTEXT_FPR(7)
157 #define UC_MCONTEXT_FREGS_R8 _UC_MCONTEXT_FPR(8)
158 #define UC_MCONTEXT_FREGS_R9 _UC_MCONTEXT_FPR(9)
159 #define UC_MCONTEXT_FREGS_R10 _UC_MCONTEXT_FPR(10)
160 #define UC_MCONTEXT_FREGS_R11 _UC_MCONTEXT_FPR(11)
161 #define UC_MCONTEXT_FREGS_R12 _UC_MCONTEXT_FPR(12)
162 #define UC_MCONTEXT_FREGS_R13 _UC_MCONTEXT_FPR(13)
163 #define UC_MCONTEXT_FREGS_R14 _UC_MCONTEXT_FPR(14)
164 #define UC_MCONTEXT_FREGS_R15 _UC_MCONTEXT_FPR(15)
165 #define UC_MCONTEXT_FREGS_R16 _UC_MCONTEXT_FPR(16)
166 #define UC_MCONTEXT_FREGS_R17 _UC_MCONTEXT_FPR(17)
167 #define UC_MCONTEXT_FREGS_R18 _UC_MCONTEXT_FPR(18)
168 #define UC_MCONTEXT_FREGS_R19 _UC_MCONTEXT_FPR(19)
169 #define UC_MCONTEXT_FREGS_R20 _UC_MCONTEXT_FPR(20)
170 #define UC_MCONTEXT_FREGS_R21 _UC_MCONTEXT_FPR(21)
171 #define UC_MCONTEXT_FREGS_R22 _UC_MCONTEXT_FPR(22)
172 #define UC_MCONTEXT_FREGS_R23 _UC_MCONTEXT_FPR(23)
173 #define UC_MCONTEXT_FREGS_R24 _UC_MCONTEXT_FPR(24)
174 #define UC_MCONTEXT_FREGS_R25 _UC_MCONTEXT_FPR(25)
175 #define UC_MCONTEXT_FREGS_R26 _UC_MCONTEXT_FPR(26)
176 #define UC_MCONTEXT_FREGS_R27 _UC_MCONTEXT_FPR(27)
177 #define UC_MCONTEXT_FREGS_R28 _UC_MCONTEXT_FPR(28)
178 #define UC_MCONTEXT_FREGS_R29 _UC_MCONTEXT_FPR(29)
179 #define UC_MCONTEXT_FREGS_R30 _UC_MCONTEXT_FPR(30)
180 #define UC_MCONTEXT_FREGS_R31 _UC_MCONTEXT_FPR(31)
181 #define UC_MCONTEXT_FREGS_FPSCR _UC_MCONTEXT_FPR(32)
182 
183 
184 #define UC_MCONTEXT_VREGS_R0 _UC_MCONTEXT_VR(0)
185 #define UC_MCONTEXT_VREGS_R1 _UC_MCONTEXT_VR(1)
186 #define UC_MCONTEXT_VREGS_R2 _UC_MCONTEXT_VR(2)
187 #define UC_MCONTEXT_VREGS_R3 _UC_MCONTEXT_VR(3)
188 #define UC_MCONTEXT_VREGS_R4 _UC_MCONTEXT_VR(4)
189 #define UC_MCONTEXT_VREGS_R5 _UC_MCONTEXT_VR(5)
190 #define UC_MCONTEXT_VREGS_R6 _UC_MCONTEXT_VR(6)
191 #define UC_MCONTEXT_VREGS_R7 _UC_MCONTEXT_VR(7)
192 #define UC_MCONTEXT_VREGS_R8 _UC_MCONTEXT_VR(8)
193 #define UC_MCONTEXT_VREGS_R9 _UC_MCONTEXT_VR(9)
194 #define UC_MCONTEXT_VREGS_R10 _UC_MCONTEXT_VR(10)
195 #define UC_MCONTEXT_VREGS_R11 _UC_MCONTEXT_VR(11)
196 #define UC_MCONTEXT_VREGS_R12 _UC_MCONTEXT_VR(12)
197 #define UC_MCONTEXT_VREGS_R13 _UC_MCONTEXT_VR(13)
198 #define UC_MCONTEXT_VREGS_R14 _UC_MCONTEXT_VR(14)
199 #define UC_MCONTEXT_VREGS_R15 _UC_MCONTEXT_VR(15)
200 #define UC_MCONTEXT_VREGS_R16 _UC_MCONTEXT_VR(16)
201 #define UC_MCONTEXT_VREGS_R17 _UC_MCONTEXT_VR(17)
202 #define UC_MCONTEXT_VREGS_R18 _UC_MCONTEXT_VR(18)
203 #define UC_MCONTEXT_VREGS_R19 _UC_MCONTEXT_VR(19)
204 #define UC_MCONTEXT_VREGS_R20 _UC_MCONTEXT_VR(20)
205 #define UC_MCONTEXT_VREGS_R21 _UC_MCONTEXT_VR(21)
206 #define UC_MCONTEXT_VREGS_R22 _UC_MCONTEXT_VR(22)
207 #define UC_MCONTEXT_VREGS_R23 _UC_MCONTEXT_VR(23)
208 #define UC_MCONTEXT_VREGS_R24 _UC_MCONTEXT_VR(24)
209 #define UC_MCONTEXT_VREGS_R25 _UC_MCONTEXT_VR(25)
210 #define UC_MCONTEXT_VREGS_R26 _UC_MCONTEXT_VR(26)
211 #define UC_MCONTEXT_VREGS_R27 _UC_MCONTEXT_VR(27)
212 #define UC_MCONTEXT_VREGS_R28 _UC_MCONTEXT_VR(28)
213 #define UC_MCONTEXT_VREGS_R29 _UC_MCONTEXT_VR(29)
214 #define UC_MCONTEXT_VREGS_R30 _UC_MCONTEXT_VR(30)
215 #define UC_MCONTEXT_VREGS_R31 _UC_MCONTEXT_VR(31)
216 #if defined(__linux__)
217 #define UC_MCONTEXT_VREGS_VSCR ((void *)&dmy_vrregset.vscr - (void *)&dmy_vrregset)
218 #define UC_MCONTEXT_VREGS_VRSAVE ((void *)&dmy_vrregset.vrsave - (void *)&dmy_vrregset)
219 #elif defined(__FreeBSD__)
220 #define UC_MCONTEXT_VREGS_VSCR ((void *)&dmy_ctxt.mc_av[0] - (void *)&dmy_ctxt)
221 #define UC_MCONTEXT_VREGS_VRSAVE ((void *)&dmy_ctxt.mc_av[1] - (void *)&dmy_ctxt)
222 #else
223 #error "Not implemented!"
224 #endif
225 
226 #endif
227