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
, 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
, 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
;
167 int flags
= req
->flags
& ~CONTEXT_SPARC
; /* get rid of CPU id */
169 if (get_req_data_size(req
) < sizeof(CONTEXT
))
171 set_error( STATUS_INVALID_PARAMETER
);
174 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_GET_CONTEXT
)))
176 if (thread
->context
) /* thread is inside an exception event */
178 copy_context( get_req_data(req
), thread
->context
, flags
);
181 if (flags
&& suspend_for_ptrace( thread
))
183 get_thread_context( thread
, flags
, get_req_data(req
) );
184 resume_thread( thread
);
186 release_object( thread
);
191 /* set the current context of a thread */
192 DECL_HANDLER(set_thread_context
)
194 struct thread
*thread
;
195 int flags
= req
->flags
& ~CONTEXT_SPARC
; /* get rid of CPU id */
197 if (get_req_data_size(req
) < sizeof(CONTEXT
))
199 set_error( STATUS_INVALID_PARAMETER
);
202 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_SET_CONTEXT
)))
204 if (thread
->context
) /* thread is inside an exception event */
206 copy_context( thread
->context
, get_req_data(req
), flags
);
209 if (flags
&& suspend_for_ptrace( thread
))
211 set_thread_context( thread
, flags
, get_req_data(req
) );
212 resume_thread( thread
);
214 release_object( thread
);
218 #endif /* __sparc__ */