Explicitly check for MSICONDITION_TRUE being returned from
[wine] / server / context_sparc.c
1 /*
2  * Sparc register context support
3  *
4  * Copyright (C) 2000 Ulrich Weigand
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #ifdef __sparc__
24
25 #include <assert.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_REG_H
29 # include <sys/reg.h>
30 #endif
31 #include <stdarg.h>
32 #include <unistd.h>
33 #ifdef HAVE_SYS_PTRACE_H
34 # include <sys/ptrace.h>
35 #endif
36
37 #include "windef.h"
38
39 #include "file.h"
40 #include "thread.h"
41 #include "request.h"
42
43
44 #if defined(__sun) || defined(__sun__)
45
46 /* retrieve a thread context */
47 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
48 {
49     int pid = get_ptrace_pid(thread);
50     if (flags & CONTEXT_FULL)
51     {
52         struct regs regs;
53         if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
54         if (flags & CONTEXT_INTEGER)
55         {
56             context->g0 = 0;
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;
64
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;
73
74             /* FIXME: local and in registers */
75         }
76         if (flags & CONTEXT_CONTROL)
77         {
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 */
84         }
85     }
86     if (flags & CONTEXT_FLOATING_POINT)
87     {
88         /* FIXME */
89     }
90     return;
91  error:
92     file_set_error();
93 }
94
95
96 /* set a thread context */
97 static void set_thread_context( struct thread *thread, unsigned int flags, const CONTEXT *context )
98 {
99     /* FIXME */
100 }
101
102 #else  /* __sun__ */
103 #error You must implement get/set_thread_context for your platform
104 #endif  /* __sun__ */
105
106
107 /* copy a context structure according to the flags */
108 static void copy_context( CONTEXT *to, const CONTEXT *from, int flags )
109 {
110     if (flags & CONTEXT_CONTROL)
111     {
112         to->psr    = from->psr;
113         to->pc     = from->pc;
114         to->npc    = from->npc;
115         to->y      = from->y;
116         to->wim    = from->wim;
117         to->tbr    = from->tbr;
118     }
119     if (flags & CONTEXT_INTEGER)
120     {
121         to->g0 = from->g0;
122         to->g1 = from->g1;
123         to->g2 = from->g2;
124         to->g3 = from->g3;
125         to->g4 = from->g4;
126         to->g5 = from->g5;
127         to->g6 = from->g6;
128         to->g7 = from->g7;
129         to->o0 = from->o0;
130         to->o1 = from->o1;
131         to->o2 = from->o2;
132         to->o3 = from->o3;
133         to->o4 = from->o4;
134         to->o5 = from->o5;
135         to->o6 = from->o6;
136         to->o7 = from->o7;
137         to->l0 = from->l0;
138         to->l1 = from->l1;
139         to->l2 = from->l2;
140         to->l3 = from->l3;
141         to->l4 = from->l4;
142         to->l5 = from->l5;
143         to->l6 = from->l6;
144         to->l7 = from->l7;
145         to->i0 = from->i0;
146         to->i1 = from->i1;
147         to->i2 = from->i2;
148         to->i3 = from->i3;
149         to->i4 = from->i4;
150         to->i5 = from->i5;
151         to->i6 = from->i6;
152         to->i7 = from->i7;
153     }
154     if (flags & CONTEXT_FLOATING_POINT)
155     {
156         /* FIXME */
157     }
158 }
159
160 /* retrieve the current instruction pointer of a thread */
161 void *get_thread_ip( struct thread *thread )
162 {
163     CONTEXT context;
164     context.pc = 0;
165     if (suspend_for_ptrace( thread ))
166     {
167         get_thread_context( thread, CONTEXT_CONTROL, &context );
168         resume_after_ptrace( thread );
169     }
170     return (void *)context.pc;
171 }
172
173 /* determine if we should continue the thread in single-step mode */
174 int get_thread_single_step( struct thread *thread )
175 {
176     return 0;  /* FIXME */
177 }
178
179 /* send a signal to a specific thread */
180 int tkill( int pid, int sig )
181 {
182     /* FIXME: should do something here */
183     errno = ENOSYS;
184     return -1;
185 }
186
187 /* retrieve the current context of a thread */
188 DECL_HANDLER(get_thread_context)
189 {
190     struct thread *thread;
191     void *data;
192     int flags = req->flags & ~CONTEXT_SPARC;  /* get rid of CPU id */
193
194     if (get_reply_max_size() < sizeof(CONTEXT))
195     {
196         set_error( STATUS_INVALID_PARAMETER );
197         return;
198     }
199     if (!(thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT ))) return;
200
201     if ((data = set_reply_data_size( sizeof(CONTEXT) )))
202     {
203         if (thread->context)  /* thread is inside an exception event */
204         {
205             copy_context( data, thread->context, flags );
206             flags = 0;
207         }
208         if (flags && suspend_for_ptrace( thread ))
209         {
210             get_thread_context( thread, flags, data );
211             resume_after_ptrace( thread );
212         }
213     }
214     release_object( thread );
215 }
216
217
218 /* set the current context of a thread */
219 DECL_HANDLER(set_thread_context)
220 {
221     struct thread *thread;
222     int flags = req->flags & ~CONTEXT_SPARC;  /* get rid of CPU id */
223
224     if (get_req_data_size() < sizeof(CONTEXT))
225     {
226         set_error( STATUS_INVALID_PARAMETER );
227         return;
228     }
229     if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
230     {
231         if (thread->context)  /* thread is inside an exception event */
232         {
233             copy_context( thread->context, get_req_data(), flags );
234             flags = 0;
235         }
236         if (flags && suspend_for_ptrace( thread ))
237         {
238             set_thread_context( thread, flags, get_req_data() );
239             resume_after_ptrace( thread );
240         }
241         release_object( thread );
242     }
243 }
244
245 #endif  /* __sparc__ */