Only include 'sys/user.h' for Linux. Fixes a compilation error on
[wine.git] / server / context_sparc.c
blobd8d6b79787c0273a1b29e06539bec3a8732b2989
1 /*
2 * Sparc register context support
4 * Copyright (C) 2000 Ulrich Weigand
5 */
7 #include "config.h"
9 #ifdef __sparc__
11 #include <assert.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 #ifdef HAVE_SYS_REG_H
15 # include <sys/reg.h>
16 #endif
17 #include <unistd.h>
18 #ifdef HAVE_SYS_PTRACE_H
19 # include <sys/ptrace.h>
20 #endif
22 #include "winbase.h"
24 #include "thread.h"
25 #include "request.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)
36 struct regs regs;
37 if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
38 if (flags & CONTEXT_INTEGER)
40 context->g0 = 0;
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)
72 /* FIXME */
74 return;
75 error:
76 file_set_error();
80 /* set a thread context */
81 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
83 /* FIXME */
86 #else /* __sun__ */
87 #error You must implement get/set_thread_context for your platform
88 #endif /* __sun__ */
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)
96 to->psr = from->psr;
97 to->pc = from->pc;
98 to->npc = from->npc;
99 to->y = from->y;
100 to->wim = from->wim;
101 to->tbr = from->tbr;
103 if (flags & CONTEXT_INTEGER)
105 to->g0 = from->g0;
106 to->g1 = from->g1;
107 to->g2 = from->g2;
108 to->g3 = from->g3;
109 to->g4 = from->g4;
110 to->g5 = from->g5;
111 to->g6 = from->g6;
112 to->g7 = from->g7;
113 to->o0 = from->o0;
114 to->o1 = from->o1;
115 to->o2 = from->o2;
116 to->o3 = from->o3;
117 to->o4 = from->o4;
118 to->o5 = from->o5;
119 to->o6 = from->o6;
120 to->o7 = from->o7;
121 to->l0 = from->l0;
122 to->l1 = from->l1;
123 to->l2 = from->l2;
124 to->l3 = from->l3;
125 to->l4 = from->l4;
126 to->l5 = from->l5;
127 to->l6 = from->l6;
128 to->l7 = from->l7;
129 to->i0 = from->i0;
130 to->i1 = from->i1;
131 to->i2 = from->i2;
132 to->i3 = from->i3;
133 to->i4 = from->i4;
134 to->i5 = from->i5;
135 to->i6 = from->i6;
136 to->i7 = from->i7;
138 if (flags & CONTEXT_FLOATING_POINT)
140 /* FIXME */
144 /* retrieve the current instruction pointer of a thread */
145 void *get_thread_ip( struct thread *thread )
147 CONTEXT context;
148 context.pc = 0;
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 );
172 return;
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 );
179 flags = 0;
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 );
200 return;
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 );
207 flags = 0;
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__ */