1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1994-1998,2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/t_lock.h>
#include <sys/klwp.h>
#include <sys/ucontext.h>
#include <sys/procfs.h>
#include <sys/privregs.h>
#include <sys/cpuvar.h>
#include <sys/cmn_err.h>
#include <sys/systm.h>
#include <sys/archsystm.h>
#include <sys/machsystm.h>
#include <sys/fpu/fpusystm.h>
/*
* Association of extra register state with a struct ucontext is
* done by placing an xrs_t within the uc_mcontext filler area.
*
* The following routines provide an interface for this association.
*/
/*
* clear the struct ucontext extra register state pointer
*/
/* ARGSUSED */
void
xregs_clrptr(klwp_id_t lwp, ucontext_t *uc)
{
uc->uc_mcontext.xrs.xrs_id = 0;
uc->uc_mcontext.xrs.xrs_ptr = NULL;
}
/*
* indicate whether or not an extra register state
* pointer is associated with a struct ucontext
*/
/* ARGSUSED */
int
xregs_hasptr(klwp_id_t lwp, ucontext_t *uc)
{
return (uc->uc_mcontext.xrs.xrs_id == XRS_ID);
}
/*
* get the struct ucontext extra register state pointer field
*/
/* ARGSUSED */
caddr_t
xregs_getptr(klwp_id_t lwp, ucontext_t *uc)
{
if (uc->uc_mcontext.xrs.xrs_id == XRS_ID)
return (uc->uc_mcontext.xrs.xrs_ptr);
return (NULL);
}
/*
* set the struct ucontext extra register state pointer field
*/
/* ARGSUSED */
void
xregs_setptr(klwp_id_t lwp, ucontext_t *uc, caddr_t xrp)
{
uc->uc_mcontext.xrs.xrs_id = XRS_ID;
uc->uc_mcontext.xrs.xrs_ptr = xrp;
}
#ifdef _SYSCALL32_IMPL
/* ARGSUSED */
void
xregs_clrptr32(klwp_id_t lwp, ucontext32_t *uc)
{
uc->uc_mcontext.xrs.xrs_id = 0;
uc->uc_mcontext.xrs.xrs_ptr = 0;
}
/* ARGSUSED */
int
xregs_hasptr32(klwp_id_t lwp, ucontext32_t *uc)
{
return (uc->uc_mcontext.xrs.xrs_id == XRS_ID);
}
/* ARGSUSED */
caddr32_t
xregs_getptr32(klwp_id_t lwp, ucontext32_t *uc)
{
if (uc->uc_mcontext.xrs.xrs_id == XRS_ID)
return (uc->uc_mcontext.xrs.xrs_ptr);
return (0);
}
/* ARGSUSED */
void
xregs_setptr32(klwp_id_t lwp, ucontext32_t *uc, caddr32_t xrp)
{
uc->uc_mcontext.xrs.xrs_id = XRS_ID;
uc->uc_mcontext.xrs.xrs_ptr = xrp;
}
#endif /* _SYSCALL32_IMPL */
/*
* Extra register state manipulation routines.
* NOTE: 'lwp' might not correspond to 'curthread' in any of the
* functions below since they are called from code in /proc to get
* or set the extra registers of another lwp.
*/
int xregs_exists = 1;
#define GET_UPPER_32(all) (uint32_t)((uint64_t)(all) >> 32)
#define SET_ALL_64(upper, lower) \
(((uint64_t)(upper) << 32) | (uint32_t)(lower))
/*
* fill in the extra register state area specified with the
* specified lwp's non-floating-point extra register state
* information
*/
void
xregs_getgregs(klwp_id_t lwp, caddr_t xrp)
{
prxregset_t *xregs = (prxregset_t *)xrp;
struct regs *rp = lwptoregs(lwp);
if (xregs == NULL)
return;
xregs->pr_type = XR_TYPE_V8P;
xregs->pr_un.pr_v8p.pr_xg[XR_G0] = 0;
xregs->pr_un.pr_v8p.pr_xg[XR_G1] = GET_UPPER_32(rp->r_g1);
xregs->pr_un.pr_v8p.pr_xg[XR_G2] = GET_UPPER_32(rp->r_g2);
xregs->pr_un.pr_v8p.pr_xg[XR_G3] = GET_UPPER_32(rp->r_g3);
xregs->pr_un.pr_v8p.pr_xg[XR_G4] = GET_UPPER_32(rp->r_g4);
xregs->pr_un.pr_v8p.pr_xg[XR_G5] = GET_UPPER_32(rp->r_g5);
xregs->pr_un.pr_v8p.pr_xg[XR_G6] = GET_UPPER_32(rp->r_g6);
xregs->pr_un.pr_v8p.pr_xg[XR_G7] = GET_UPPER_32(rp->r_g7);
xregs->pr_un.pr_v8p.pr_xo[XR_O0] = GET_UPPER_32(rp->r_o0);
xregs->pr_un.pr_v8p.pr_xo[XR_O1] = GET_UPPER_32(rp->r_o1);
xregs->pr_un.pr_v8p.pr_xo[XR_O2] = GET_UPPER_32(rp->r_o2);
xregs->pr_un.pr_v8p.pr_xo[XR_O3] = GET_UPPER_32(rp->r_o3);
xregs->pr_un.pr_v8p.pr_xo[XR_O4] = GET_UPPER_32(rp->r_o4);
xregs->pr_un.pr_v8p.pr_xo[XR_O5] = GET_UPPER_32(rp->r_o5);
xregs->pr_un.pr_v8p.pr_xo[XR_O6] = GET_UPPER_32(rp->r_o6);
xregs->pr_un.pr_v8p.pr_xo[XR_O7] = GET_UPPER_32(rp->r_o7);
xregs->pr_un.pr_v8p.pr_tstate = rp->r_tstate;
xregs_getgfiller(lwp, xrp);
}
/*
* fill in the extra register state area specified with the
* specified lwp's floating-point extra register state information
*/
void
xregs_getfpregs(klwp_id_t lwp, caddr_t xrp)
{
prxregset_t *xregs = (prxregset_t *)xrp;
kfpu_t *fp = lwptofpu(lwp);
if (xregs == NULL)
return;
kpreempt_disable();
xregs->pr_type = XR_TYPE_V8P;
if (ttolwp(curthread) == lwp)
fp->fpu_fprs = _fp_read_fprs();
if ((fp->fpu_en) || (fp->fpu_fprs & FPRS_FEF)) {
/*
* If we have an fpu and the current thread owns the fp
* context, flush fp registers into the pcb.
*/
if (fpu_exists && (ttolwp(curthread) == lwp)) {
if ((fp->fpu_fprs & FPRS_FEF) != FPRS_FEF) {
uint32_t fprs = (FPRS_FEF|FPRS_DU|FPRS_DL);
_fp_write_fprs(fprs);
fp->fpu_fprs = fprs;
#ifdef DEBUG
if (fpdispr) {
cmn_err(CE_NOTE, "xregs_getfpregs "
"with fp disabled!");
}
#endif /* DEBUG */
}
fp_v8p_fksave(fp);
}
(void) kcopy(&fp->fpu_fr.fpu_dregs[16],
&xregs->pr_un.pr_v8p.pr_xfr,
sizeof (xregs->pr_un.pr_v8p.pr_xfr));
xregs->pr_un.pr_v8p.pr_xfsr = GET_UPPER_32(fp->fpu_fsr);
xregs->pr_un.pr_v8p.pr_fprs = fp->fpu_fprs;
xregs_getfpfiller(lwp, xrp);
} else {
int i;
for (i = 0; i < 32; i++) /* Nan */
xregs->pr_un.pr_v8p.pr_xfr.pr_regs[i] = (uint32_t)-1;
}
kpreempt_enable();
}
/*
* fill in the extra register state area specified with
* the specified lwp's extra register state information
*/
void
xregs_get(klwp_id_t lwp, caddr_t xrp)
{
if (xrp != NULL) {
bzero(xrp, sizeof (prxregset_t));
xregs_getgregs(lwp, xrp);
xregs_getfpregs(lwp, xrp);
}
}
/*
* set the specified lwp's non-floating-point extra
* register state based on the specified input
*/
void
xregs_setgregs(klwp_id_t lwp, caddr_t xrp)
{
prxregset_t *xregs = (prxregset_t *)xrp;
struct regs *rp = lwptoregs(lwp);
int current = (lwp == curthread->t_lwp);
if (xregs == NULL)
return;
#ifdef DEBUG
if (xregs->pr_type != XR_TYPE_V8P) {
cmn_err(CE_WARN,
"xregs_setgregs: pr_type is %d and should be %d",
xregs->pr_type, XR_TYPE_V8P);
}
#endif /* DEBUG */
if (current) {
/*
* copy the args from the regs first
*/
(void) save_syscall_args();
}
rp->r_g1 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G1], rp->r_g1);
rp->r_g2 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G2], rp->r_g2);
rp->r_g3 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G3], rp->r_g3);
rp->r_g4 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G4], rp->r_g4);
rp->r_g5 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G5], rp->r_g5);
rp->r_g6 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G6], rp->r_g6);
rp->r_g7 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xg[XR_G7], rp->r_g7);
rp->r_o0 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O0], rp->r_o0);
rp->r_o1 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O1], rp->r_o1);
rp->r_o2 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O2], rp->r_o2);
rp->r_o3 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O3], rp->r_o3);
rp->r_o4 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O4], rp->r_o4);
rp->r_o5 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O5], rp->r_o5);
rp->r_o6 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O6], rp->r_o6);
rp->r_o7 = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xo[XR_O7], rp->r_o7);
rp->r_tstate &= ~((uint64_t)CCR_XCC << TSTATE_CCR_SHIFT);
rp->r_tstate |= xregs->pr_un.pr_v8p.pr_tstate &
((uint64_t)CCR_XCC << TSTATE_CCR_SHIFT);
rp->r_tstate &= ~((uint64_t)TSTATE_ASI_MASK << TSTATE_ASI_SHIFT);
rp->r_tstate |= xregs->pr_un.pr_v8p.pr_tstate &
((uint64_t)TSTATE_ASI_MASK << TSTATE_ASI_SHIFT);
xregs_setgfiller(lwp, xrp);
if (current) {
/*
* This was called from a system call, but we
* do not want to return via the shared window;
* restoring the CPU context changes everything.
*/
lwp->lwp_eosys = JUSTRETURN;
curthread->t_post_sys = 1;
}
}
/*
* set the specified lwp's floating-point extra
* register state based on the specified input
*/
void
xregs_setfpregs(klwp_id_t lwp, caddr_t xrp)
{
prxregset_t *xregs = (prxregset_t *)xrp;
kfpu_t *fp = lwptofpu(lwp);
if (xregs == NULL)
return;
#ifdef DEBUG
if (xregs->pr_type != XR_TYPE_V8P) {
cmn_err(CE_WARN,
"xregs_setfpregs: pr_type is %d and should be %d",
xregs->pr_type, XR_TYPE_V8P);
}
#endif /* DEBUG */
if ((fp->fpu_en) || (xregs->pr_un.pr_v8p.pr_fprs & FPRS_FEF)) {
kpreempt_disable();
(void) kcopy(&xregs->pr_un.pr_v8p.pr_xfr,
&fp->fpu_fr.fpu_dregs[16],
sizeof (xregs->pr_un.pr_v8p.pr_xfr));
fp->fpu_fprs = xregs->pr_un.pr_v8p.pr_fprs;
fp->fpu_fsr = SET_ALL_64(xregs->pr_un.pr_v8p.pr_xfsr,
fp->fpu_fsr);
xregs_setfpfiller(lwp, xrp);
/*
* If not the current lwp then resume() will handle it
*/
if (lwp != ttolwp(curthread)) {
/* force resume to reload fp regs */
kpreempt_enable();
return;
}
if (fpu_exists) {
fp->fpu_fprs = _fp_read_fprs();
if ((fp->fpu_fprs & FPRS_FEF) != FPRS_FEF) {
uint32_t fprs = (FPRS_FEF|FPRS_DU|FPRS_DL);
_fp_write_fprs(fprs);
fp->fpu_fprs = (V9_FPU_FPRS_TYPE)fprs;
#ifdef DEBUG
if (fpdispr) {
cmn_err(CE_NOTE, "xregs_setfpregs "
"with fp disabled!");
}
#endif /* DEBUG */
}
fp_v8p_load(fp);
}
kpreempt_enable();
}
}
/*
* set the specified lwp's extra register
* state based on the specified input
*/
void
xregs_set(klwp_id_t lwp, caddr_t xrp)
{
if (xrp != NULL) {
xregs_setgregs(lwp, xrp);
xregs_setfpregs(lwp, xrp);
}
}
/*
* return the size of the extra register state
*/
int
xregs_getsize(proc_t *p)
{
if (!xregs_exists || p->p_model == DATAMODEL_LP64)
return (0);
return (sizeof (prxregset_t));
}
|