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>
21 #ifdef HAVE_SYS_USER_H
22 # include <sys/user.h>
31 #if defined(__sun) || defined(__sun__)
33 /* retrieve a thread context */
34 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
36 int pid = thread->unix_pid;
37 if (flags & CONTEXT_FULL)
40 if (ptrace( PTRACE_GETREGS, pid, 0, (int) ®s ) == -1) goto error;
41 if (flags & CONTEXT_INTEGER)
44 context->g1 = regs.r_g1;
45 context->g2 = regs.r_g2;
46 context->g3 = regs.r_g3;
47 context->g4 = regs.r_g4;
48 context->g5 = regs.r_g5;
49 context->g6 = regs.r_g6;
50 context->g7 = regs.r_g7;
52 context->o0 = regs.r_o0;
53 context->o1 = regs.r_o1;
54 context->o2 = regs.r_o2;
55 context->o3 = regs.r_o3;
56 context->o4 = regs.r_o4;
57 context->o5 = regs.r_o5;
58 context->o6 = regs.r_o6;
59 context->o7 = regs.r_o7;
61 /* FIXME: local and in registers */
63 if (flags & CONTEXT_CONTROL)
65 context->psr = regs.r_psr;
66 context->pc = regs.r_pc;
67 context->npc = regs.r_npc;
68 context->y = regs.r_y;
69 context->wim = 0; /* FIXME */
70 context->tbr = 0; /* FIXME */
73 if (flags & CONTEXT_FLOATING_POINT)
83 /* set a thread context */
84 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
90 #error You must implement get/set_thread_context for your platform
94 /* copy a context structure according to the flags */
95 static void copy_context( CONTEXT *to, CONTEXT *from, int flags )
97 if (flags & CONTEXT_CONTROL)
106 if (flags & CONTEXT_INTEGER)
141 if (flags & CONTEXT_FLOATING_POINT)
147 /* retrieve the current instruction pointer of a thread */
148 void *get_thread_ip( struct thread *thread )
152 if (suspend_for_ptrace( thread ))
154 get_thread_context( thread, CONTEXT_CONTROL, &context );
155 resume_thread( thread );
157 return (void *)context.pc;
160 /* determine if we should continue the thread in single-step mode */
161 int get_thread_single_step( struct thread *thread )
163 return 0; /* FIXME */
166 /* retrieve the current context of a thread */
167 DECL_HANDLER(get_thread_context)
169 struct thread *thread;
170 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
172 if (get_req_data_size(req) < sizeof(CONTEXT))
174 set_error( STATUS_INVALID_PARAMETER );
177 if ((thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT )))
179 if (thread->context) /* thread is inside an exception event */
181 copy_context( get_req_data(req), thread->context, flags );
184 if (flags && suspend_for_ptrace( thread ))
186 get_thread_context( thread, flags, get_req_data(req) );
187 resume_thread( thread );
189 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(req) < 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(req), flags );
212 if (flags && suspend_for_ptrace( thread ))
214 set_thread_context( thread, flags, get_req_data(req) );
215 resume_thread( thread );
217 release_object( thread );
221 #endif /* __sparc__ */