Fixed typo in HKEY_CURRENT_CONFIG name.
[wine] / server / context_sparc.c
1 /*
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
15 #include <sys/reg.h>
16 #endif
17 #include <unistd.h>
18 #include <sys/ptrace.h>
19 #include <sys/user.h>
20
21 #include "winbase.h"
22
23 #include "thread.h"
24 #include "request.h"
25
26
27 #if defined(__sun) || defined(__sun__)
28
29 /* retrieve a thread context */
30 static void get_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
31 {
32     int pid = thread->unix_pid;
33     if (flags & CONTEXT_FULL)
34     {
35         struct regs regs;
36         if (ptrace( PTRACE_GETREGS, pid, 0, (int) &regs ) == -1) goto error;
37         if (flags & CONTEXT_INTEGER)
38         {
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;
47
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;
56
57             /* FIXME: local and in registers */
58         }
59         if (flags & CONTEXT_CONTROL)
60         {
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 */
67         }
68     }
69     if (flags & CONTEXT_FLOATING_POINT)
70     {
71         /* FIXME */
72     }
73     return;
74  error:
75     file_set_error();
76 }
77
78
79 /* set a thread context */
80 static void set_thread_context( struct thread *thread, unsigned int flags, CONTEXT *context )
81 {
82     /* FIXME */
83 }
84
85 #else  /* __sun__ */
86 #error You must implement get/set_thread_context for your platform
87 #endif  /* __sun__ */
88
89
90 /* copy a context structure according to the flags */
91 static void copy_context( CONTEXT *to, CONTEXT *from, int flags )
92 {
93     if (flags & CONTEXT_CONTROL)
94     {
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;
101     }
102     if (flags & CONTEXT_INTEGER)
103     {
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;
136     }
137     if (flags & CONTEXT_FLOATING_POINT)
138     {
139         /* FIXME */
140     }
141 }
142
143 /* retrieve the current instruction pointer of a thread */
144 void *get_thread_ip( struct thread *thread )
145 {
146     CONTEXT context;
147     context.pc = 0;
148     if (suspend_for_ptrace( thread ))
149     {
150         get_thread_context( thread, CONTEXT_CONTROL, &context );
151         resume_thread( thread );
152     }
153     return (void *)context.pc;
154 }
155
156 /* retrieve the current context of a thread */
157 DECL_HANDLER(get_thread_context)
158 {
159     struct thread *thread;
160     int flags = req->flags & ~CONTEXT_SPARC;  /* get rid of CPU id */
161
162     if ((thread = get_thread_from_handle( req->handle, THREAD_GET_CONTEXT )))
163     {
164         if (thread->context)  /* thread is inside an exception event */
165         {
166             copy_context( &req->context, thread->context, flags );
167             flags = 0;
168         }
169         if (flags && suspend_for_ptrace( thread ))
170         {
171             get_thread_context( thread, flags, &req->context );
172             resume_thread( thread );
173         }
174         release_object( thread );
175     }
176 }
177
178
179 /* set the current context of a thread */
180 DECL_HANDLER(set_thread_context)
181 {
182     struct thread *thread;
183     int flags = req->flags & ~CONTEXT_SPARC;  /* get rid of CPU id */
184
185     if ((thread = get_thread_from_handle( req->handle, THREAD_SET_CONTEXT )))
186     {
187         if (thread->context)  /* thread is inside an exception event */
188         {
189             copy_context( thread->context, &req->context, flags );
190             flags = 0;
191         }
192         if (flags && suspend_for_ptrace( thread ))
193         {
194             set_thread_context( thread, flags, &req->context );
195             resume_thread( thread );
196         }
197         release_object( thread );
198     }
199 }
200
201 #endif  /* __sparc__ */