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 /* retrieve the current context of a thread */
161 DECL_HANDLER(get_thread_context
)
163 struct thread
*thread
;
164 int flags
= req
->flags
& ~CONTEXT_SPARC
; /* get rid of CPU id */
166 if (get_req_data_size(req
) < sizeof(CONTEXT
))
168 set_error( STATUS_INVALID_PARAMETER
);
171 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_GET_CONTEXT
)))
173 if (thread
->context
) /* thread is inside an exception event */
175 copy_context( get_req_data(req
), thread
->context
, flags
);
178 if (flags
&& suspend_for_ptrace( thread
))
180 get_thread_context( thread
, flags
, get_req_data(req
) );
181 resume_thread( thread
);
183 release_object( thread
);
188 /* set the current context of a thread */
189 DECL_HANDLER(set_thread_context
)
191 struct thread
*thread
;
192 int flags
= req
->flags
& ~CONTEXT_SPARC
; /* get rid of CPU id */
194 if (get_req_data_size(req
) < sizeof(CONTEXT
))
196 set_error( STATUS_INVALID_PARAMETER
);
199 if ((thread
= get_thread_from_handle( req
->handle
, THREAD_SET_CONTEXT
)))
201 if (thread
->context
) /* thread is inside an exception event */
203 copy_context( thread
->context
, get_req_data(req
), flags
);
206 if (flags
&& suspend_for_ptrace( thread
))
208 set_thread_context( thread
, flags
, get_req_data(req
) );
209 resume_thread( thread
);
211 release_object( thread
);
215 #endif /* __sparc__ */