blob: 0e12e7296f7fd28b70abe02d758d34352f1dbe6d [file] [log] [blame]
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +00001/*
2 * Sparc register context support
3 *
4 * Copyright (C) 2000 Ulrich Weigand
5 */
6
7#include "config.h"
8
9#ifdef __sparc__
10
11#include <assert.h>
12#include <errno.h>
13#include <sys/types.h>
14#ifdef HAVE_SYS_REG_H
Patrik Stridvall7a4e5992000-12-01 23:53:46 +000015# include <sys/reg.h>
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +000016#endif
17#include <unistd.h>
Patrik Stridvall7a4e5992000-12-01 23:53:46 +000018#ifdef HAVE_SYS_PTRACE_H
19# include <sys/ptrace.h>
20#endif
21#ifdef HAVE_SYS_USER_H
22# include <sys/user.h>
23#endif
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +000024
25#include "winbase.h"
26
27#include "thread.h"
28#include "request.h"
29
30
31#if defined(__sun) || defined(__sun__)
32
33/* retrieve a thread context */
34static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
35{
36 int pid = thread->unix_pid;
37 if (flags & CONTEXT_FULL)
38 {
39 struct regs regs;
40 if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
41 if (flags & CONTEXT_INTEGER)
42 {
43 context->g0 = 0;
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;
51
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;
60
61 /* FIXME: local and in registers */
62 }
63 if (flags & CONTEXT_CONTROL)
64 {
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 */
71 }
72 }
73 if (flags & CONTEXT_FLOATING_POINT)
74 {
75 /* FIXME */
76 }
77 return;
78 error:
79 file_set_error();
80}
81
82
83/* set a thread context */
84static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
85{
86 /* FIXME */
87}
88
89#else /* __sun__ */
90#error You must implement get/set_thread_context for your platform
91#endif /* __sun__ */
92
93
94/* copy a context structure according to the flags */
95static void copy_context( CONTEXT *to, CONTEXT *from, int flags )
96{
97 if (flags & CONTEXT_CONTROL)
98 {
99 to->psr = from->psr;
100 to->pc = from->pc;
101 to->npc = from->npc;
102 to->y = from->y;
103 to->wim = from->wim;
104 to->tbr = from->tbr;
105 }
106 if (flags & CONTEXT_INTEGER)
107 {
108 to->g0 = from->g0;
109 to->g1 = from->g1;
110 to->g2 = from->g2;
111 to->g3 = from->g3;
112 to->g4 = from->g4;
113 to->g5 = from->g5;
114 to->g6 = from->g6;
115 to->g7 = from->g7;
116 to->o0 = from->o0;
117 to->o1 = from->o1;
118 to->o2 = from->o2;
119 to->o3 = from->o3;
120 to->o4 = from->o4;
121 to->o5 = from->o5;
122 to->o6 = from->o6;
123 to->o7 = from->o7;
124 to->l0 = from->l0;
125 to->l1 = from->l1;
126 to->l2 = from->l2;
127 to->l3 = from->l3;
128 to->l4 = from->l4;
129 to->l5 = from->l5;
130 to->l6 = from->l6;
131 to->l7 = from->l7;
132 to->i0 = from->i0;
133 to->i1 = from->i1;
134 to->i2 = from->i2;
135 to->i3 = from->i3;
136 to->i4 = from->i4;
137 to->i5 = from->i5;
138 to->i6 = from->i6;
139 to->i7 = from->i7;
140 }
141 if (flags & CONTEXT_FLOATING_POINT)
142 {
143 /* FIXME */
144 }
145}
146
147/* retrieve the current instruction pointer of a thread */
148void *get_thread_ip( struct thread *thread )
149{
150 CONTEXT context;
151 context.pc = 0;
152 if (suspend_for_ptrace( thread ))
153 {
154 get_thread_context( thread, CONTEXT_CONTROL, &context );
155 resume_thread( thread );
156 }
157 return (void *)context.pc;
158}
159
Ove Kaavenada73832001-04-27 18:39:47 +0000160/* determine if we should continue the thread in single-step mode */
161int get_thread_single_step( struct thread *thread )
162{
163 return 0; /* FIXME */
164}
165
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000166/* retrieve the current context of a thread */
167DECL_HANDLER(get_thread_context)
168{
169 struct thread *thread;
170 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
171
Alexandre Julliard92643002000-08-31 01:59:51 +0000172 if (get_req_data_size(req) < sizeof(CONTEXT))
173 {
174 set_error( STATUS_INVALID_PARAMETER );
175 return;
176 }
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000177 if ((thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT )))
178 {
179 if (thread->context) /* thread is inside an exception event */
180 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000181 copy_context( get_req_data(req), thread->context, flags );
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000182 flags = 0;
183 }
184 if (flags && suspend_for_ptrace( thread ))
185 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000186 get_thread_context( thread, flags, get_req_data(req) );
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000187 resume_thread( thread );
188 }
189 release_object( thread );
190 }
191}
192
193
194/* set the current context of a thread */
195DECL_HANDLER(set_thread_context)
196{
197 struct thread *thread;
198 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
199
Alexandre Julliard92643002000-08-31 01:59:51 +0000200 if (get_req_data_size(req) < sizeof(CONTEXT))
201 {
202 set_error( STATUS_INVALID_PARAMETER );
203 return;
204 }
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000205 if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
206 {
207 if (thread->context) /* thread is inside an exception event */
208 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000209 copy_context( thread->context, get_req_data(req), flags );
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000210 flags = 0;
211 }
212 if (flags && suspend_for_ptrace( thread ))
213 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000214 set_thread_context( thread, flags, get_req_data(req) );
Ulrich Weigandafd6a4b2000-06-04 01:48:05 +0000215 resume_thread( thread );
216 }
217 release_object( thread );
218 }
219}
220
221#endif /* __sparc__ */