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
27 #include <sys/types.h>
33 #ifdef HAVE_SYS_PTRACE_H
34 # include <sys/ptrace.h>
39 #if 0 /* no longer used */
41 #ifndef PTRACE_PEEKUSER
43 # define PTRACE_PEEKUSER PT_READ_D
45 #endif /* PTRACE_PEEKUSER */
47 #ifndef PTRACE_POKEUSER
49 # define PTRACE_POKEUSER PT_WRITE_D
51 #endif /* PTRACE_POKEUSER */
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);
73 context
->ContextFlags
|= CONTEXT_INTEGER
;
75 if (flags
& CONTEXT_CONTROL
)
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;
118 XREG((48+32*2),Fpscr
);
119 context
->ContextFlags
|= CONTEXT_FLOATING_POINT
;
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);
149 if (flags
& CONTEXT_CONTROL
)
157 if (flags
& CONTEXT_FLOATING_POINT
)
192 XREG((48+32*2),Fpscr
);
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
)
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);
226 to
->ContextFlags
|= CONTEXT_INTEGER
;
228 if (flags
& CONTEXT_FLOATING_POINT
)
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)
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__ */