2 * Sparc register context support
4 * Copyright (C) 2000 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sys/types.h>
33 #ifdef HAVE_SYS_PTRACE_H
34 # include <sys/ptrace.h>
44 #if defined(__sun) || defined(__sun__)
46 /* retrieve a thread context */
47 static void get_thread_context_ptrace( struct thread
*thread
, unsigned int flags
, CONTEXT
*context
)
49 int pid
= get_ptrace_pid(thread
);
50 if (flags
& CONTEXT_FULL
)
53 if (ptrace( PTRACE_GETREGS
, pid
, 0, (int) ®s
) == -1) goto error
;
54 if (flags
& CONTEXT_INTEGER
)
57 context
->g1
= regs
.r_g1
;
58 context
->g2
= regs
.r_g2
;
59 context
->g3
= regs
.r_g3
;
60 context
->g4
= regs
.r_g4
;
61 context
->g5
= regs
.r_g5
;
62 context
->g6
= regs
.r_g6
;
63 context
->g7
= regs
.r_g7
;
65 context
->o0
= regs
.r_o0
;
66 context
->o1
= regs
.r_o1
;
67 context
->o2
= regs
.r_o2
;
68 context
->o3
= regs
.r_o3
;
69 context
->o4
= regs
.r_o4
;
70 context
->o5
= regs
.r_o5
;
71 context
->o6
= regs
.r_o6
;
72 context
->o7
= regs
.r_o7
;
74 /* FIXME: local and in registers */
76 if (flags
& CONTEXT_CONTROL
)
78 context
->psr
= regs
.r_psr
;
79 context
->pc
= regs
.r_pc
;
80 context
->npc
= regs
.r_npc
;
81 context
->y
= regs
.r_y
;
82 context
->wim
= 0; /* FIXME */
83 context
->tbr
= 0; /* FIXME */
85 context
|= flags
& (CONTEXT_CONTROL
|CONTEXT_INTEGER
);
87 if (flags
& CONTEXT_FLOATING_POINT
)
97 /* set a thread context */
98 static void set_thread_context_ptrace( struct thread
*thread
, unsigned int flags
, const CONTEXT
*context
)
104 #error You must implement get/set_thread_context_ptrace for your platform
108 /* copy a context structure according to the flags */
109 static void copy_context( CONTEXT
*to
, const CONTEXT
*from
, unsigned int flags
)
111 if (flags
& CONTEXT_CONTROL
)
120 if (flags
& CONTEXT_INTEGER
)
155 if (flags
& CONTEXT_FLOATING_POINT
)
159 context
|= flags
& (CONTEXT_CONTROL
|CONTEXT_INTEGER
);
162 /* retrieve the current instruction pointer of a thread */
163 void *get_thread_ip( struct thread
*thread
)
167 if (suspend_for_ptrace( thread
))
169 get_thread_context_ptrace( thread
, CONTEXT_CONTROL
, &context
);
170 resume_after_ptrace( thread
);
172 return (void *)context
.pc
;
175 /* determine if we should continue the thread in single-step mode */
176 int get_thread_single_step( struct thread
*thread
)
178 return 0; /* FIXME */
181 /* send a signal to a specific thread */
182 int tkill( int pid
, int sig
)
184 /* FIXME: should do something here */
189 /* retrieve the thread context */
190 void get_thread_context( struct thread
*thread
, CONTEXT
*context
, unsigned int flags
)
192 context
->ContextFlags
|= CONTEXT_SPARC
;
193 flags
&= ~CONTEXT_SPARC
; /* get rid of CPU id */
195 if (thread
->context
) /* thread is inside an exception event or suspended */
197 copy_context( context
, thread
->context
, flags
);
199 else if (flags
&& suspend_for_ptrace( thread
))
201 get_thread_context_ptrace( thread
, flags
, context
);
202 resume_after_ptrace( thread
);
206 /* set the thread context */
207 void set_thread_context( struct thread
*thread
, const CONTEXT
*context
, unsigned int flags
)
209 flags
&= ~CONTEXT_SPARC
; /* get rid of CPU id */
211 if (thread
->context
) /* thread is inside an exception event or suspended */
213 copy_context( thread
->context
, context
, flags
);
215 else if (flags
&& suspend_for_ptrace( thread
))
217 set_thread_context_ptrace( thread
, flags
, context
);
218 resume_after_ptrace( thread
);
222 #endif /* __sparc__ */