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 (get_req_data_size(req
) < sizeof(CONTEXT
))
164 set_error( STATUS_INVALID_PARAMETER
);
167 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_GET_CONTEXT
)))
169 if (thread
->context
) /* thread is inside an exception event */
171 copy_context( get_req_data(req
), thread
->context
, flags
);
174 if (flags
&& suspend_for_ptrace( thread
))
176 get_thread_context( thread
, flags
, get_req_data(req
) );
177 resume_thread( thread
);
179 release_object( thread
);
184 /* set the current context of a thread */
185 DECL_HANDLER(set_thread_context
)
187 struct thread
*thread
;
188 int flags
= req
->flags
& ~CONTEXT_SPARC
; /* get rid of CPU id */
190 if (get_req_data_size(req
) < sizeof(CONTEXT
))
192 set_error( STATUS_INVALID_PARAMETER
);
195 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_SET_CONTEXT
)))
197 if (thread
->context
) /* thread is inside an exception event */
199 copy_context( thread
->context
, get_req_data(req
), flags
);
202 if (flags
&& suspend_for_ptrace( thread
))
204 set_thread_context( thread
, flags
, get_req_data(req
) );
205 resume_thread( thread
);
207 release_object( thread
);
211 #endif /* __sparc__ */