Print this page
XXX AVX procfs
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/fs/proc/prmachdep.c
+++ new/usr/src/uts/intel/fs/proc/prmachdep.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 #include <sys/types.h>
31 31 #include <sys/t_lock.h>
32 32 #include <sys/param.h>
33 33 #include <sys/cred.h>
34 34 #include <sys/debug.h>
35 35 #include <sys/inline.h>
36 36 #include <sys/kmem.h>
37 37 #include <sys/proc.h>
38 38 #include <sys/regset.h>
39 39 #include <sys/privregs.h>
40 40 #include <sys/sysmacros.h>
41 41 #include <sys/systm.h>
42 42 #include <sys/vfs.h>
43 43 #include <sys/vnode.h>
44 44 #include <sys/psw.h>
45 45 #include <sys/pcb.h>
46 46 #include <sys/buf.h>
47 47 #include <sys/signal.h>
48 48 #include <sys/user.h>
49 49 #include <sys/cpuvar.h>
50 50
51 51 #include <sys/fault.h>
52 52 #include <sys/syscall.h>
53 53 #include <sys/procfs.h>
54 54 #include <sys/cmn_err.h>
55 55 #include <sys/stack.h>
56 56 #include <sys/debugreg.h>
57 57 #include <sys/copyops.h>
58 58
59 59 #include <sys/vmem.h>
60 60 #include <sys/mman.h>
61 61 #include <sys/vmparam.h>
62 62 #include <sys/fp.h>
63 63 #include <sys/archsystm.h>
64 64 #include <sys/vmsystm.h>
65 65 #include <vm/hat.h>
66 66 #include <vm/as.h>
67 67 #include <vm/seg.h>
68 68 #include <vm/seg_kmem.h>
69 69 #include <vm/seg_kp.h>
70 70 #include <vm/page.h>
71 71
72 72 #include <sys/sysi86.h>
73 73
74 74 #include <fs/proc/prdata.h>
75 75
76 76 int prnwatch = 10000; /* maximum number of watched areas */
77 77
78 78 /*
79 79 * Force a thread into the kernel if it is not already there.
80 80 * This is a no-op on uniprocessors.
81 81 */
82 82 /* ARGSUSED */
83 83 void
84 84 prpokethread(kthread_t *t)
85 85 {
86 86 if (t->t_state == TS_ONPROC && t->t_cpu != CPU)
87 87 poke_cpu(t->t_cpu->cpu_id);
88 88 }
89 89
90 90 /*
91 91 * Return general registers.
92 92 */
93 93 void
94 94 prgetprregs(klwp_t *lwp, prgregset_t prp)
95 95 {
96 96 ASSERT(MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
97 97
98 98 getgregs(lwp, prp);
99 99 }
100 100
101 101 /*
102 102 * Set general registers.
103 103 * (Note: This can be an alias to setgregs().)
104 104 */
105 105 void
106 106 prsetprregs(klwp_t *lwp, prgregset_t prp, int initial)
107 107 {
108 108 if (initial) /* set initial values */
109 109 lwptoregs(lwp)->r_ps = PSL_USER;
110 110 (void) setgregs(lwp, prp);
111 111 }
112 112
113 113 #ifdef _SYSCALL32_IMPL
114 114
115 115 /*
116 116 * Convert prgregset32 to native prgregset
117 117 */
118 118 void
119 119 prgregset_32ton(klwp_t *lwp, prgregset32_t src, prgregset_t dst)
120 120 {
121 121 struct regs *rp = lwptoregs(lwp);
122 122
123 123 dst[REG_GSBASE] = lwp->lwp_pcb.pcb_gsbase;
124 124 dst[REG_FSBASE] = lwp->lwp_pcb.pcb_fsbase;
125 125
126 126 dst[REG_DS] = (uint16_t)src[DS];
127 127 dst[REG_ES] = (uint16_t)src[ES];
128 128
129 129 dst[REG_GS] = (uint16_t)src[GS];
130 130 dst[REG_FS] = (uint16_t)src[FS];
131 131 dst[REG_SS] = (uint16_t)src[SS];
132 132 dst[REG_RSP] = (uint32_t)src[UESP];
133 133 dst[REG_RFL] =
134 134 (rp->r_ps & ~PSL_USERMASK) | (src[EFL] & PSL_USERMASK);
135 135 dst[REG_CS] = (uint16_t)src[CS];
136 136 dst[REG_RIP] = (uint32_t)src[EIP];
137 137 dst[REG_ERR] = (uint32_t)src[ERR];
138 138 dst[REG_TRAPNO] = (uint32_t)src[TRAPNO];
139 139 dst[REG_RAX] = (uint32_t)src[EAX];
140 140 dst[REG_RCX] = (uint32_t)src[ECX];
141 141 dst[REG_RDX] = (uint32_t)src[EDX];
142 142 dst[REG_RBX] = (uint32_t)src[EBX];
143 143 dst[REG_RBP] = (uint32_t)src[EBP];
144 144 dst[REG_RSI] = (uint32_t)src[ESI];
145 145 dst[REG_RDI] = (uint32_t)src[EDI];
146 146 dst[REG_R8] = dst[REG_R9] = dst[REG_R10] = dst[REG_R11] =
147 147 dst[REG_R12] = dst[REG_R13] = dst[REG_R14] = dst[REG_R15] = 0;
148 148 }
149 149
150 150 /*
151 151 * Return 32-bit general registers
152 152 */
153 153 void
154 154 prgetprregs32(klwp_t *lwp, prgregset32_t prp)
155 155 {
156 156 ASSERT(MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
157 157 getgregs32(lwp, prp);
158 158 }
159 159
160 160 #endif /* _SYSCALL32_IMPL */
161 161
162 162 /*
163 163 * Get the syscall return values for the lwp.
164 164 */
165 165 int
166 166 prgetrvals(klwp_t *lwp, long *rval1, long *rval2)
167 167 {
168 168 struct regs *r = lwptoregs(lwp);
169 169
170 170 if (r->r_ps & PS_C)
171 171 return (r->r_r0);
172 172 if (lwp->lwp_eosys == JUSTRETURN) {
173 173 *rval1 = 0;
174 174 *rval2 = 0;
175 175 } else if (lwp_getdatamodel(lwp) != DATAMODEL_NATIVE) {
176 176 /*
177 177 * XX64 Not sure we -really- need to do this, because the
178 178 * syscall return already masks off the bottom values ..?
179 179 */
180 180 *rval1 = r->r_r0 & (uint32_t)0xffffffffu;
181 181 *rval2 = r->r_r1 & (uint32_t)0xffffffffu;
182 182 } else {
183 183 *rval1 = r->r_r0;
184 184 *rval2 = r->r_r1;
185 185 }
186 186 return (0);
187 187 }
188 188
189 189 /*
190 190 * Does the system support floating-point, either through hardware
191 191 * or by trapping and emulating floating-point machine instructions?
192 192 */
193 193 int
194 194 prhasfp(void)
195 195 {
196 196 extern int fp_kind;
197 197
198 198 return (fp_kind != FP_NO);
199 199 }
200 200
201 201 /*
202 202 * Get floating-point registers.
203 203 */
204 204 void
205 205 prgetprfpregs(klwp_t *lwp, prfpregset_t *pfp)
206 206 {
207 207 bzero(pfp, sizeof (prfpregset_t));
208 208 getfpregs(lwp, pfp);
209 209 }
210 210
211 211 #if defined(_SYSCALL32_IMPL)
212 212 void
213 213 prgetprfpregs32(klwp_t *lwp, prfpregset32_t *pfp)
214 214 {
215 215 bzero(pfp, sizeof (*pfp));
216 216 getfpregs32(lwp, pfp);
217 217 }
218 218 #endif /* _SYSCALL32_IMPL */
219 219
220 220 /*
221 221 * Set floating-point registers.
222 222 * (Note: This can be an alias to setfpregs().)
223 223 */
224 224 void
225 225 prsetprfpregs(klwp_t *lwp, prfpregset_t *pfp)
226 226 {
227 227 setfpregs(lwp, pfp);
228 228 }
229 229
230 230 #if defined(_SYSCALL32_IMPL)
↓ open down ↓ |
230 lines elided |
↑ open up ↑ |
231 231 void
232 232 prsetprfpregs32(klwp_t *lwp, prfpregset32_t *pfp)
233 233 {
234 234 setfpregs32(lwp, pfp);
235 235 }
236 236 #endif /* _SYSCALL32_IMPL */
237 237
238 238 /*
239 239 * Does the system support extra register state?
240 240 */
241 -/* ARGSUSED */
242 241 int
243 242 prhasx(proc_t *p)
244 243 {
245 - return (0);
244 + /* XXX */
245 + return (1);
246 246 }
247 247
248 248 /*
249 249 * Get the size of the extra registers.
250 250 */
251 -/* ARGSUSED */
252 251 int
253 252 prgetprxregsize(proc_t *p)
254 253 {
255 - return (0);
254 + return (xregs_getsize(p));
256 255 }
257 256
258 257 /*
259 258 * Get extra registers.
260 259 */
261 -/*ARGSUSED*/
262 260 void
263 261 prgetprxregs(klwp_t *lwp, caddr_t prx)
264 262 {
265 - /* no extra registers */
263 + extern void xregs_get(struct _klwp *, caddr_t);
264 +
265 + xregs_get(lwp, prx);
266 266 }
267 267
268 268 /*
269 269 * Set extra registers.
270 270 */
271 -/*ARGSUSED*/
272 271 void
273 272 prsetprxregs(klwp_t *lwp, caddr_t prx)
274 273 {
275 - /* no extra registers */
274 + extern void xregs_set(struct _klwp *, caddr_t);
275 +
276 + xregs_set(lwp, prx);
276 277 }
277 278
278 279 /*
279 280 * Return the base (lower limit) of the process stack.
280 281 */
281 282 caddr_t
282 283 prgetstackbase(proc_t *p)
283 284 {
284 285 return (p->p_usrstack - p->p_stksize);
285 286 }
286 287
287 288 /*
288 289 * Return the "addr" field for pr_addr in prpsinfo_t.
289 290 * This is a vestige of the past, so whatever we return is OK.
290 291 */
291 292 caddr_t
292 293 prgetpsaddr(proc_t *p)
293 294 {
294 295 return ((caddr_t)p);
295 296 }
296 297
297 298 /*
298 299 * Arrange to single-step the lwp.
299 300 */
300 301 void
301 302 prstep(klwp_t *lwp, int watchstep)
302 303 {
303 304 ASSERT(MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
304 305
305 306 /*
306 307 * flag LWP so that its r_efl trace bit (PS_T) will be set on
307 308 * next return to usermode.
308 309 */
309 310 lwp->lwp_pcb.pcb_flags |= REQUEST_STEP;
310 311 lwp->lwp_pcb.pcb_flags &= ~REQUEST_NOSTEP;
311 312
312 313 if (watchstep)
313 314 lwp->lwp_pcb.pcb_flags |= WATCH_STEP;
314 315 else
315 316 lwp->lwp_pcb.pcb_flags |= NORMAL_STEP;
316 317
317 318 aston(lwptot(lwp)); /* let trap() set PS_T in rp->r_efl */
318 319 }
319 320
320 321 /*
321 322 * Undo prstep().
322 323 */
323 324 void
324 325 prnostep(klwp_t *lwp)
325 326 {
326 327 ASSERT(ttolwp(curthread) == lwp ||
327 328 MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
328 329
329 330 /*
330 331 * flag LWP so that its r_efl trace bit (PS_T) will be cleared on
331 332 * next return to usermode.
332 333 */
333 334 lwp->lwp_pcb.pcb_flags |= REQUEST_NOSTEP;
334 335
335 336 lwp->lwp_pcb.pcb_flags &=
336 337 ~(REQUEST_STEP|NORMAL_STEP|WATCH_STEP|DEBUG_PENDING);
337 338
338 339 aston(lwptot(lwp)); /* let trap() clear PS_T in rp->r_efl */
339 340 }
340 341
341 342 /*
342 343 * Return non-zero if a single-step is in effect.
343 344 */
344 345 int
345 346 prisstep(klwp_t *lwp)
346 347 {
347 348 ASSERT(MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
348 349
349 350 return ((lwp->lwp_pcb.pcb_flags &
350 351 (NORMAL_STEP|WATCH_STEP|DEBUG_PENDING)) != 0);
351 352 }
352 353
353 354 /*
354 355 * Set the PC to the specified virtual address.
355 356 */
356 357 void
357 358 prsvaddr(klwp_t *lwp, caddr_t vaddr)
358 359 {
359 360 struct regs *r = lwptoregs(lwp);
360 361
361 362 ASSERT(MUTEX_NOT_HELD(&lwptoproc(lwp)->p_lock));
362 363
363 364 r->r_pc = (uintptr_t)vaddr;
364 365 }
365 366
366 367 /*
367 368 * Map address "addr" in address space "as" into a kernel virtual address.
368 369 * The memory is guaranteed to be resident and locked down.
369 370 */
370 371 caddr_t
371 372 prmapin(struct as *as, caddr_t addr, int writing)
372 373 {
373 374 page_t *pp;
374 375 caddr_t kaddr;
375 376 pfn_t pfnum;
376 377
377 378 /*
378 379 * XXX - Because of past mistakes, we have bits being returned
379 380 * by getpfnum that are actually the page type bits of the pte.
380 381 * When the object we are trying to map is a memory page with
381 382 * a page structure everything is ok and we can use the optimal
382 383 * method, ppmapin. Otherwise, we have to do something special.
383 384 */
384 385 pfnum = hat_getpfnum(as->a_hat, addr);
385 386 if (pf_is_memory(pfnum)) {
386 387 pp = page_numtopp_nolock(pfnum);
387 388 if (pp != NULL) {
388 389 ASSERT(PAGE_LOCKED(pp));
389 390 kaddr = ppmapin(pp, writing ?
390 391 (PROT_READ | PROT_WRITE) : PROT_READ, (caddr_t)-1);
391 392 return (kaddr + ((uintptr_t)addr & PAGEOFFSET));
392 393 }
393 394 }
394 395
395 396 /*
396 397 * Oh well, we didn't have a page struct for the object we were
397 398 * trying to map in; ppmapin doesn't handle devices, but allocating a
398 399 * heap address allows ppmapout to free virtual space when done.
399 400 */
400 401 kaddr = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP);
401 402
402 403 hat_devload(kas.a_hat, kaddr, MMU_PAGESIZE, pfnum,
403 404 writing ? (PROT_READ | PROT_WRITE) : PROT_READ, 0);
404 405
405 406 return (kaddr + ((uintptr_t)addr & PAGEOFFSET));
406 407 }
407 408
408 409 /*
409 410 * Unmap address "addr" in address space "as"; inverse of prmapin().
410 411 */
411 412 /* ARGSUSED */
412 413 void
413 414 prmapout(struct as *as, caddr_t addr, caddr_t vaddr, int writing)
414 415 {
415 416 extern void ppmapout(caddr_t);
416 417
417 418 vaddr = (caddr_t)((uintptr_t)vaddr & PAGEMASK);
418 419 ppmapout(vaddr);
419 420 }
420 421
421 422 /*
422 423 * Make sure the lwp is in an orderly state
423 424 * for inspection by a debugger through /proc.
424 425 *
425 426 * This needs to be called only once while the current thread remains in the
426 427 * kernel and needs to be called while holding no resources (mutex locks, etc).
427 428 *
428 429 * As a hedge against these conditions, if prstop() is called repeatedly
429 430 * before prunstop() is called, it does nothing and just returns.
430 431 *
431 432 * prunstop() must be called before the thread returns to user level.
432 433 */
433 434 /* ARGSUSED */
434 435 void
435 436 prstop(int why, int what)
436 437 {
437 438 klwp_t *lwp = ttolwp(curthread);
438 439 struct regs *r = lwptoregs(lwp);
439 440
440 441 if (lwp->lwp_pcb.pcb_flags & PRSTOP_CALLED)
441 442 return;
442 443
443 444 /*
444 445 * Make sure we don't deadlock on a recursive call
445 446 * to prstop(). stop() tests the lwp_nostop flag.
446 447 */
447 448 ASSERT(lwp->lwp_nostop == 0);
448 449 lwp->lwp_nostop = 1;
449 450
450 451 if (copyin_nowatch((caddr_t)r->r_pc, &lwp->lwp_pcb.pcb_instr,
451 452 sizeof (lwp->lwp_pcb.pcb_instr)) == 0)
452 453 lwp->lwp_pcb.pcb_flags |= INSTR_VALID;
453 454 else {
454 455 lwp->lwp_pcb.pcb_flags &= ~INSTR_VALID;
455 456 lwp->lwp_pcb.pcb_instr = 0;
456 457 }
457 458
458 459 (void) save_syscall_args();
459 460 ASSERT(lwp->lwp_nostop == 1);
460 461 lwp->lwp_nostop = 0;
461 462
462 463 lwp->lwp_pcb.pcb_flags |= PRSTOP_CALLED;
463 464 aston(curthread); /* so prunstop() will be called */
464 465 }
465 466
466 467 /*
467 468 * Inform prstop() that it should do its work again
468 469 * the next time it is called.
469 470 */
470 471 void
471 472 prunstop(void)
472 473 {
473 474 ttolwp(curthread)->lwp_pcb.pcb_flags &= ~PRSTOP_CALLED;
474 475 }
475 476
476 477 /*
477 478 * Fetch the user-level instruction on which the lwp is stopped.
478 479 * It was saved by the lwp itself, in prstop().
479 480 * Return non-zero if the instruction is valid.
480 481 */
481 482 int
482 483 prfetchinstr(klwp_t *lwp, ulong_t *ip)
483 484 {
484 485 *ip = (ulong_t)(instr_t)lwp->lwp_pcb.pcb_instr;
485 486 return (lwp->lwp_pcb.pcb_flags & INSTR_VALID);
486 487 }
487 488
488 489 /*
489 490 * Called from trap() when a load or store instruction
490 491 * falls in a watched page but is not a watchpoint.
491 492 * We emulate the instruction in the kernel.
492 493 */
493 494 /* ARGSUSED */
494 495 int
495 496 pr_watch_emul(struct regs *rp, caddr_t addr, enum seg_rw rw)
496 497 {
497 498 #ifdef SOMEDAY
498 499 int res;
499 500 proc_t *p = curproc;
500 501 char *badaddr = (caddr_t)(-1);
501 502 int mapped;
502 503
503 504 /* prevent recursive calls to pr_watch_emul() */
504 505 ASSERT(!(curthread->t_flag & T_WATCHPT));
505 506 curthread->t_flag |= T_WATCHPT;
506 507
507 508 watch_disable_addr(addr, 8, rw);
508 509 res = do_unaligned(rp, &badaddr);
509 510 watch_enable_addr(addr, 8, rw);
510 511
511 512 curthread->t_flag &= ~T_WATCHPT;
512 513 if (res == SIMU_SUCCESS) {
513 514 /* adjust the pc */
514 515 return (1);
515 516 }
516 517 #endif
517 518 return (0);
518 519 }
519 520
520 521 /*
521 522 * Return the number of active entries in the local descriptor table.
522 523 */
523 524 int
524 525 prnldt(proc_t *p)
525 526 {
526 527 int limit, i, n;
527 528 user_desc_t *udp;
528 529
529 530 ASSERT(MUTEX_HELD(&p->p_ldtlock));
530 531
531 532 /*
532 533 * Currently 64 bit processes cannot have private LDTs.
533 534 */
534 535 ASSERT(p->p_model != DATAMODEL_LP64 || p->p_ldt == NULL);
535 536
536 537 if (p->p_ldt == NULL)
537 538 return (0);
538 539 n = 0;
539 540 limit = p->p_ldtlimit;
540 541 ASSERT(limit >= 0 && limit < MAXNLDT);
541 542
542 543 /*
543 544 * Count all present user descriptors.
544 545 */
545 546 for (i = LDT_UDBASE, udp = &p->p_ldt[i]; i <= limit; i++, udp++)
546 547 if (udp->usd_type != 0 || udp->usd_dpl != 0 || udp->usd_p != 0)
547 548 n++;
548 549 return (n);
549 550 }
550 551
551 552 /*
552 553 * Fetch the active entries from the local descriptor table.
553 554 */
554 555 void
555 556 prgetldt(proc_t *p, struct ssd *ssd)
556 557 {
557 558 int i, limit;
558 559 user_desc_t *udp;
559 560
560 561 ASSERT(MUTEX_HELD(&p->p_ldtlock));
561 562
562 563 if (p->p_ldt == NULL)
563 564 return;
564 565
565 566 limit = p->p_ldtlimit;
566 567 ASSERT(limit >= 0 && limit < MAXNLDT);
567 568
568 569 /*
569 570 * All present user descriptors.
570 571 */
571 572 for (i = LDT_UDBASE, udp = &p->p_ldt[i]; i <= limit; i++, udp++)
572 573 if (udp->usd_type != 0 || udp->usd_dpl != 0 ||
573 574 udp->usd_p != 0)
574 575 usd_to_ssd(udp, ssd++, SEL_LDT(i));
575 576 }
↓ open down ↓ |
290 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX