Fixed WM_GETTEXTLENGTH handling.
[wine/multimedia.git] / server / context_sparc.c
blobbd30922c8fefb61b1825893a33fa2ba57a565ee0
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
21 #ifdef HAVE_SYS_USER_H
22 # include <sys/user.h>
23 #endif
25 #include "winbase.h"
27 #include "thread.h"
28 #include "request.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)
39 struct regs regs;
40 if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
41 if (flags & CONTEXT_INTEGER)
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;
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)
75 /* FIXME */
77 return;
78 error:
79 file_set_error();
83 /* set a thread context */
84 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
86 /* FIXME */
89 #else /* __sun__ */
90 #error You must implement get/set_thread_context for your platform
91 #endif /* __sun__ */
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)
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;
106 if (flags & CONTEXT_INTEGER)
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;
141 if (flags & CONTEXT_FLOATING_POINT)
143 /* FIXME */
147 /* retrieve the current instruction pointer of a thread */
148 void *get_thread_ip( struct thread *thread )
150 CONTEXT context;
151 context.pc = 0;
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 );
169 return;
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 );
176 flags = 0;
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 );
197 return;
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 );
204 flags = 0;
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__ */