2 * Sparc register context support
4 * Copyright (C) 2000 Ulrich Weigand
13 #include <sys/types.h>
18 #ifdef HAVE_SYS_PTRACE_H
19 # include <sys/ptrace.h>
28 #if defined(__sun) || defined(__sun__)
30 /* retrieve a thread context */
31 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
33 int pid = thread->unix_pid;
34 if (flags & CONTEXT_FULL)
37 if (ptrace( PTRACE_GETREGS, pid, 0, (int) ®s ) == -1) goto error;
38 if (flags & CONTEXT_INTEGER)
41 context->g1 = regs.r_g1;
42 context->g2 = regs.r_g2;
43 context->g3 = regs.r_g3;
44 context->g4 = regs.r_g4;
45 context->g5 = regs.r_g5;
46 context->g6 = regs.r_g6;
47 context->g7 = regs.r_g7;
49 context->o0 = regs.r_o0;
50 context->o1 = regs.r_o1;
51 context->o2 = regs.r_o2;
52 context->o3 = regs.r_o3;
53 context->o4 = regs.r_o4;
54 context->o5 = regs.r_o5;
55 context->o6 = regs.r_o6;
56 context->o7 = regs.r_o7;
58 /* FIXME: local and in registers */
60 if (flags & CONTEXT_CONTROL)
62 context->psr = regs.r_psr;
63 context->pc = regs.r_pc;
64 context->npc = regs.r_npc;
65 context->y = regs.r_y;
66 context->wim = 0; /* FIXME */
67 context->tbr = 0; /* FIXME */
70 if (flags & CONTEXT_FLOATING_POINT)
80 /* set a thread context */
81 static void set_thread_context( struct thread *thread, unsigned int flags, const CONTEXT *context )
87 #error You must implement get/set_thread_context for your platform
91 /* copy a context structure according to the flags */
92 static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
94 if (flags & CONTEXT_CONTROL)
103 if (flags & CONTEXT_INTEGER)
138 if (flags & CONTEXT_FLOATING_POINT)
144 /* retrieve the current instruction pointer of a thread */
145 void *get_thread_ip( struct thread *thread )
149 if (suspend_for_ptrace( thread ))
151 get_thread_context( thread, CONTEXT_CONTROL, &context );
152 resume_thread( thread );
154 return (void *)context.pc;
157 /* determine if we should continue the thread in single-step mode */
158 int get_thread_single_step( struct thread *thread )
160 return 0; /* FIXME */
163 /* retrieve the current context of a thread */
164 DECL_HANDLER(get_thread_context)
166 struct thread *thread;
168 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
170 if (get_reply_max_size() < sizeof(CONTEXT))
172 set_error( STATUS_INVALID_PARAMETER );
175 if (!(thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT ))) return;
177 if ((data = set_reply_data_size( sizeof(CONTEXT) )))
179 if (thread->context) /* thread is inside an exception event */
181 copy_context( data, thread->context, flags );
184 if (flags && suspend_for_ptrace( thread ))
186 get_thread_context( thread, flags, data );
187 resume_thread( thread );
190 release_object( thread );
194 /* set the current context of a thread */
195 DECL_HANDLER(set_thread_context)
197 struct thread *thread;
198 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
200 if (get_req_data_size() < sizeof(CONTEXT))
202 set_error( STATUS_INVALID_PARAMETER );
205 if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
207 if (thread->context) /* thread is inside an exception event */
209 copy_context( thread->context, get_req_data(), flags );
212 if (flags && suspend_for_ptrace( thread ))
214 set_thread_context( thread, flags, get_req_data() );
215 resume_thread( thread );
217 release_object( thread );
221 #endif /* __sparc__ */