2 * Sparc register context support
4 * Copyright (C) 2000 Ulrich Weigand
13 #include <sys/types.h>
18 #include <sys/ptrace.h>
27 #if defined(__sun) || defined(__sun__)
29 /* retrieve a thread context */
30 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
32 int pid = thread->unix_pid;
33 if (flags & CONTEXT_FULL)
36 if (ptrace( PTRACE_GETREGS, pid, 0, (int) ®s ) == -1) goto error;
37 if (flags & CONTEXT_INTEGER)
40 context->g1 = regs.r_g1;
41 context->g2 = regs.r_g2;
42 context->g3 = regs.r_g3;
43 context->g4 = regs.r_g4;
44 context->g5 = regs.r_g5;
45 context->g6 = regs.r_g6;
46 context->g7 = regs.r_g7;
48 context->o0 = regs.r_o0;
49 context->o1 = regs.r_o1;
50 context->o2 = regs.r_o2;
51 context->o3 = regs.r_o3;
52 context->o4 = regs.r_o4;
53 context->o5 = regs.r_o5;
54 context->o6 = regs.r_o6;
55 context->o7 = regs.r_o7;
57 /* FIXME: local and in registers */
59 if (flags & CONTEXT_CONTROL)
61 context->psr = regs.r_psr;
62 context->pc = regs.r_pc;
63 context->npc = regs.r_npc;
64 context->y = regs.r_y;
65 context->wim = 0; /* FIXME */
66 context->tbr = 0; /* FIXME */
69 if (flags & CONTEXT_FLOATING_POINT)
79 /* set a thread context */
80 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
86 #error You must implement get/set_thread_context for your platform
90 /* copy a context structure according to the flags */
91 static void copy_context( CONTEXT *to, CONTEXT *from, int flags )
93 if (flags & CONTEXT_CONTROL)
102 if (flags & CONTEXT_INTEGER)
137 if (flags & CONTEXT_FLOATING_POINT)
143 /* retrieve the current instruction pointer of a thread */
144 void *get_thread_ip( struct thread *thread )
148 if (suspend_for_ptrace( thread ))
150 get_thread_context( thread, CONTEXT_CONTROL, &context );
151 resume_thread( thread );
153 return (void *)context.pc;
156 /* retrieve the current context of a thread */
157 DECL_HANDLER(get_thread_context)
159 struct thread *thread;
160 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
162 if ((thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT )))
164 if (thread->context) /* thread is inside an exception event */
166 copy_context( &req->context, thread->context, flags );
169 if (flags && suspend_for_ptrace( thread ))
171 get_thread_context( thread, flags, &req->context );
172 resume_thread( thread );
174 release_object( thread );
179 /* set the current context of a thread */
180 DECL_HANDLER(set_thread_context)
182 struct thread *thread;
183 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
185 if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
187 if (thread->context) /* thread is inside an exception event */
189 copy_context( thread->context, &req->context, flags );
192 if (flags && suspend_for_ptrace( thread ))
194 set_thread_context( thread, flags, &req->context );
195 resume_thread( thread );
197 release_object( thread );
201 #endif /* __sparc__ */