d3d9: Fix the type of three loop variables.
[wine/multimedia.git] / server / context_powerpc.c
blob5ce63648cd1c0a2e1d19a0e229daec440b4a088d
1 /*
2 * PowerPC register context support
4 * Copyright (C) 2002 Marcus Meissner, SuSE Linux AG.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #ifdef __powerpc__
25 #include <assert.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_REG_H
29 # include <sys/reg.h>
30 #endif
31 #include <stdarg.h>
32 #include <unistd.h>
33 #ifdef HAVE_SYS_PTRACE_H
34 # include <sys/ptrace.h>
35 #endif
37 #include "windef.h"
39 #if 0 /* no longer used */
41 #ifndef PTRACE_PEEKUSER
42 # ifdef PT_READ_D
43 # define PTRACE_PEEKUSER PT_READ_D
44 # endif
45 #endif /* PTRACE_PEEKUSER */
47 #ifndef PTRACE_POKEUSER
48 # ifdef PT_WRITE_D
49 # define PTRACE_POKEUSER PT_WRITE_D
50 # endif
51 #endif /* PTRACE_POKEUSER */
53 #include "file.h"
54 #include "thread.h"
55 #include "request.h"
57 /* retrieve a thread context */
58 static void get_thread_context_ptrace( struct thread *thread, unsigned int flags, CONTEXT *context )
60 int pid = get_ptrace_pid(thread);
61 if (flags & CONTEXT_INTEGER)
63 #define XREG(x,y) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->y) == -1) goto error;
64 #define IREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error;
65 IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
66 IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
67 IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
68 IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
69 IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
70 #undef IREG
71 XREG(37,Xer);
72 XREG(38,Cr);
73 context->ContextFlags |= CONTEXT_INTEGER;
75 if (flags & CONTEXT_CONTROL)
77 XREG(32,Iar);
78 XREG(33,Msr);
79 XREG(35,Ctr);
80 XREG(36,Lr); /* 36 is LNK ... probably Lr ? */
81 context->ContextFlags |= CONTEXT_CONTROL;
83 if (flags & CONTEXT_FLOATING_POINT)
85 #define FREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)((48+x*2)<<2), &context->Fpr##x) == -1) goto error;
86 FREG(0);
87 FREG(1);
88 FREG(2);
89 FREG(3);
90 FREG(4);
91 FREG(5);
92 FREG(6);
93 FREG(7);
94 FREG(8);
95 FREG(9);
96 FREG(10);
97 FREG(11);
98 FREG(12);
99 FREG(13);
100 FREG(14);
101 FREG(15);
102 FREG(16);
103 FREG(17);
104 FREG(18);
105 FREG(19);
106 FREG(20);
107 FREG(21);
108 FREG(22);
109 FREG(23);
110 FREG(24);
111 FREG(25);
112 FREG(26);
113 FREG(27);
114 FREG(28);
115 FREG(29);
116 FREG(30);
117 FREG(31);
118 XREG((48+32*2),Fpscr);
119 context->ContextFlags |= CONTEXT_FLOATING_POINT;
121 return;
122 error:
123 file_set_error();
125 #undef XREG
126 #undef IREG
127 #undef FREG
129 #define XREG(x,y) if (ptrace( PTRACE_POKEUSER, pid, (void*)(x<<2), &context->y) == -1) goto error;
130 #define IREG(x) if (ptrace( PTRACE_POKEUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error;
131 #define FREG(x) if (ptrace( PTRACE_POKEUSER, pid, (void*)((48+x*2)<<2), &context->Fpr##x) == -1) goto error;
132 /* set a thread context */
133 static void set_thread_context_ptrace( struct thread *thread, unsigned int flags, const CONTEXT *context )
135 int pid = get_ptrace_pid(thread);
136 if (flags & CONTEXT_FULL)
138 if (flags & CONTEXT_INTEGER)
140 IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
141 IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
142 IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
143 IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
144 IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
145 XREG(37,Xer);
146 XREG(38,Cr);
149 if (flags & CONTEXT_CONTROL)
151 XREG(32,Iar);
152 XREG(33,Msr);
153 XREG(35,Ctr);
154 XREG(36,Lr);
157 if (flags & CONTEXT_FLOATING_POINT)
159 FREG(0);
160 FREG(1);
161 FREG(2);
162 FREG(3);
163 FREG(4);
164 FREG(5);
165 FREG(6);
166 FREG(7);
167 FREG(8);
168 FREG(9);
169 FREG(10);
170 FREG(11);
171 FREG(12);
172 FREG(13);
173 FREG(14);
174 FREG(15);
175 FREG(16);
176 FREG(17);
177 FREG(18);
178 FREG(19);
179 FREG(20);
180 FREG(21);
181 FREG(22);
182 FREG(23);
183 FREG(24);
184 FREG(25);
185 FREG(26);
186 FREG(27);
187 FREG(28);
188 FREG(29);
189 FREG(30);
190 FREG(31);
191 #undef FREG
192 XREG((48+32*2),Fpscr);
194 return;
195 error:
196 file_set_error();
198 #undef XREG
199 #undef IREG
200 #undef FREG
202 #endif /* 0 */
204 #define IREG(x) to->Gpr##x = from->Gpr##x;
205 #define FREG(x) to->Fpr##x = from->Fpr##x;
206 #define CREG(x) to->x = from->x;
207 /* copy a context structure according to the flags */
208 void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
210 if (flags & CONTEXT_CONTROL)
212 CREG(Msr);
213 CREG(Ctr);
214 CREG(Iar);
215 to->ContextFlags |= CONTEXT_CONTROL;
217 if (flags & CONTEXT_INTEGER)
219 IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
220 IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
221 IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
222 IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
223 IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
224 CREG(Xer);
225 CREG(Cr);
226 to->ContextFlags |= CONTEXT_INTEGER;
228 if (flags & CONTEXT_FLOATING_POINT)
230 FREG(0);
231 FREG(1);
232 FREG(2);
233 FREG(3);
234 FREG(4);
235 FREG(5);
236 FREG(6);
237 FREG(7);
238 FREG(8);
239 FREG(9);
240 FREG(10);
241 FREG(11);
242 FREG(12);
243 FREG(13);
244 FREG(14);
245 FREG(15);
246 FREG(16);
247 FREG(17);
248 FREG(18);
249 FREG(19);
250 FREG(20);
251 FREG(21);
252 FREG(22);
253 FREG(23);
254 FREG(24);
255 FREG(25);
256 FREG(26);
257 FREG(27);
258 FREG(28);
259 FREG(29);
260 FREG(30);
261 FREG(31);
262 CREG(Fpscr);
263 to->ContextFlags |= CONTEXT_FLOATING_POINT;
267 /* retrieve the current instruction pointer of a context */
268 void *get_context_ip( const CONTEXT *context )
270 return (void *)context->Iar;
273 /* return the context flag that contains the CPU id */
274 unsigned int get_context_cpu_flag(void)
276 return 0;
279 /* return only the context flags that correspond to system regs */
280 /* (system regs are the ones we can't access on the client side) */
281 unsigned int get_context_system_regs( unsigned int flags )
283 return 0; /* FIXME: implement client-side handling */
286 #endif /* __powerpc__ */