Prepare switching to unicode of builtin widgets.
[wine.git] / server / context_sparc.c
blob0a63c12ec52e2b15abdd1b1f43754ce68c4bd6fd
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 #include <sys/ptrace.h>
19 #include <sys/user.h>
21 #include "winbase.h"
23 #include "thread.h"
24 #include "request.h"
27 #if defined(__sun) || defined(__sun__)
29 /* retrieve a thread context */
30 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
32 int pid = thread->unix_pid;
33 if (flags & CONTEXT_FULL)
35 struct regs regs;
36 if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
37 if (flags & CONTEXT_INTEGER)
39 context->g0 = 0;
40 context->g1 = regs.r_g1;
41 context->g2 = regs.r_g2;
42 context->g3 = regs.r_g3;
43 context->g4 = regs.r_g4;
44 context->g5 = regs.r_g5;
45 context->g6 = regs.r_g6;
46 context->g7 = regs.r_g7;
48 context->o0 = regs.r_o0;
49 context->o1 = regs.r_o1;
50 context->o2 = regs.r_o2;
51 context->o3 = regs.r_o3;
52 context->o4 = regs.r_o4;
53 context->o5 = regs.r_o5;
54 context->o6 = regs.r_o6;
55 context->o7 = regs.r_o7;
57 /* FIXME: local and in registers */
59 if (flags & CONTEXT_CONTROL)
61 context->psr = regs.r_psr;
62 context->pc = regs.r_pc;
63 context->npc = regs.r_npc;
64 context->y = regs.r_y;
65 context->wim = 0; /* FIXME */
66 context->tbr = 0; /* FIXME */
69 if (flags & CONTEXT_FLOATING_POINT)
71 /* FIXME */
73 return;
74 error:
75 file_set_error();
79 /* set a thread context */
80 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
82 /* FIXME */
85 #else /* __sun__ */
86 #error You must implement get/set_thread_context for your platform
87 #endif /* __sun__ */
90 /* copy a context structure according to the flags */
91 static void copy_context( CONTEXT *to, CONTEXT *from, int flags )
93 if (flags & CONTEXT_CONTROL)
95 to->psr = from->psr;
96 to->pc = from->pc;
97 to->npc = from->npc;
98 to->y = from->y;
99 to->wim = from->wim;
100 to->tbr = from->tbr;
102 if (flags & CONTEXT_INTEGER)
104 to->g0 = from->g0;
105 to->g1 = from->g1;
106 to->g2 = from->g2;
107 to->g3 = from->g3;
108 to->g4 = from->g4;
109 to->g5 = from->g5;
110 to->g6 = from->g6;
111 to->g7 = from->g7;
112 to->o0 = from->o0;
113 to->o1 = from->o1;
114 to->o2 = from->o2;
115 to->o3 = from->o3;
116 to->o4 = from->o4;
117 to->o5 = from->o5;
118 to->o6 = from->o6;
119 to->o7 = from->o7;
120 to->l0 = from->l0;
121 to->l1 = from->l1;
122 to->l2 = from->l2;
123 to->l3 = from->l3;
124 to->l4 = from->l4;
125 to->l5 = from->l5;
126 to->l6 = from->l6;
127 to->l7 = from->l7;
128 to->i0 = from->i0;
129 to->i1 = from->i1;
130 to->i2 = from->i2;
131 to->i3 = from->i3;
132 to->i4 = from->i4;
133 to->i5 = from->i5;
134 to->i6 = from->i6;
135 to->i7 = from->i7;
137 if (flags & CONTEXT_FLOATING_POINT)
139 /* FIXME */
143 /* retrieve the current instruction pointer of a thread */
144 void *get_thread_ip( struct thread *thread )
146 CONTEXT context;
147 context.pc = 0;
148 if (suspend_for_ptrace( thread ))
150 get_thread_context( thread, CONTEXT_CONTROL, &context );
151 resume_thread( thread );
153 return (void *)context.pc;
156 /* retrieve the current context of a thread */
157 DECL_HANDLER(get_thread_context)
159 struct thread *thread;
160 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
162 if (get_req_data_size(req) < sizeof(CONTEXT))
164 set_error( STATUS_INVALID_PARAMETER );
165 return;
167 if ((thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT )))
169 if (thread->context) /* thread is inside an exception event */
171 copy_context( get_req_data(req), thread->context, flags );
172 flags = 0;
174 if (flags && suspend_for_ptrace( thread ))
176 get_thread_context( thread, flags, get_req_data(req) );
177 resume_thread( thread );
179 release_object( thread );
184 /* set the current context of a thread */
185 DECL_HANDLER(set_thread_context)
187 struct thread *thread;
188 int flags = req->flags & ~CONTEXT_SPARC; /* get rid of CPU id */
190 if (get_req_data_size(req) < sizeof(CONTEXT))
192 set_error( STATUS_INVALID_PARAMETER );
193 return;
195 if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
197 if (thread->context) /* thread is inside an exception event */
199 copy_context( thread->context, get_req_data(req), flags );
200 flags = 0;
202 if (flags && suspend_for_ptrace( thread ))
204 set_thread_context( thread, flags, get_req_data(req) );
205 resume_thread( thread );
207 release_object( thread );
211 #endif /* __sparc__ */