4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
28 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
29 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/vmparam.h>
35 #include <sys/systm.h>
36 #include <sys/signal.h>
37 #include <sys/stack.h>
38 #include <sys/regset.h>
39 #include <sys/privregs.h>
40 #include <sys/frame.h>
43 #include <sys/siginfo.h>
44 #include <sys/cpuvar.h>
45 #include <sys/asm_linkage.h>
47 #include <sys/errno.h>
48 #include <sys/bootconf.h>
49 #include <sys/archsystm.h>
50 #include <sys/debug.h>
54 #include <sys/atomic.h>
55 #include <sys/sysmacros.h>
56 #include <sys/cmn_err.h>
57 #include <sys/modctl.h>
59 #include <sys/panic.h>
60 #include <sys/reboot.h>
63 #include <sys/x86_archext.h>
65 #include <sys/auxv_386.h>
66 #include <sys/dtrace.h>
67 #include <sys/brand.h>
68 #include <sys/machbrand.h>
69 #include <sys/cmn_err.h>
71 extern const struct fnsave_state x87_initial
;
72 extern const struct fxsave_state sse_initial
;
75 * Map an fnsave-formatted save area into an fxsave-formatted save area.
77 * Most fields are the same width, content and semantics. However
78 * the tag word is compressed.
81 fnsave_to_fxsave(const struct fnsave_state
*fn
, struct fxsave_state
*fx
)
85 fx
->fx_fcw
= fn
->f_fcw
;
86 fx
->fx_fsw
= fn
->f_fsw
;
89 * copy element by element (because of holes)
91 for (i
= 0; i
< 8; i
++)
92 bcopy(&fn
->f_st
[i
].fpr_16
[0], &fx
->fx_st
[i
].fpr_16
[0],
93 sizeof (fn
->f_st
[0].fpr_16
)); /* 80-bit x87-style floats */
96 * synthesize compressed tag bits
99 for (tagbits
= fn
->f_ftw
, i
= 0; i
< 8; i
++, tagbits
>>= 2)
100 if ((tagbits
& 3) != 3)
101 fx
->fx_fctw
|= (1 << i
);
103 fx
->fx_fop
= fn
->f_fop
;
106 fx
->fx_rip
= (uint64_t)fn
->f_eip
;
107 fx
->fx_rdp
= (uint64_t)fn
->f_dp
;
109 fx
->fx_eip
= fn
->f_eip
;
110 fx
->fx_cs
= fn
->f_cs
;
112 fx
->fx_dp
= fn
->f_dp
;
113 fx
->fx_ds
= fn
->f_ds
;
119 * Map from an fxsave-format save area to an fnsave-format save area.
122 fxsave_to_fnsave(const struct fxsave_state
*fx
, struct fnsave_state
*fn
)
124 uint_t i
, top
, tagbits
;
126 fn
->f_fcw
= fx
->fx_fcw
;
128 fn
->f_fsw
= fx
->fx_fsw
;
131 top
= (fx
->fx_fsw
& FPS_TOP
) >> 11;
134 * copy element by element (because of holes)
136 for (i
= 0; i
< 8; i
++)
137 bcopy(&fx
->fx_st
[i
].fpr_16
[0], &fn
->f_st
[i
].fpr_16
[0],
138 sizeof (fn
->f_st
[0].fpr_16
)); /* 80-bit x87-style floats */
141 * synthesize uncompressed tag bits
144 for (tagbits
= fx
->fx_fctw
, i
= 0; i
< 8; i
++, tagbits
>>= 1) {
147 static const uint16_t zero
[5] = { 0, 0, 0, 0, 0 };
149 if ((tagbits
& 1) == 0) {
150 fn
->f_ftw
|= 3 << (i
<< 1); /* empty */
155 * (tags refer to *physical* registers)
157 fpp
= &fx
->fx_st
[(i
- top
+ 8) & 7].fpr_16
[0];
159 expo
= fpp
[4] & 0x7fff;
161 if (ibit
&& expo
!= 0 && expo
!= 0x7fff)
162 continue; /* valid fp number */
164 if (bcmp(fpp
, &zero
, sizeof (zero
)))
165 fn
->f_ftw
|= 2 << (i
<< 1); /* NaN */
167 fn
->f_ftw
|= 1 << (i
<< 1); /* fp zero */
170 fn
->f_fop
= fx
->fx_fop
;
174 fn
->f_eip
= (uint32_t)fx
->fx_rip
;
175 fn
->f_cs
= U32CS_SEL
;
176 fn
->f_dp
= (uint32_t)fx
->fx_rdp
;
179 fn
->f_eip
= fx
->fx_eip
;
180 fn
->f_cs
= fx
->fx_cs
;
181 fn
->f_dp
= fx
->fx_dp
;
182 fn
->f_ds
= fx
->fx_ds
;
188 * Map from an fpregset_t into an fxsave-format save area
191 fpregset_to_fxsave(const fpregset_t
*fp
, struct fxsave_state
*fx
)
194 bcopy(fp
, fx
, sizeof (*fx
));
196 const struct _fpchip_state
*fc
= &fp
->fp_reg_set
.fpchip_state
;
198 fnsave_to_fxsave((const struct fnsave_state
*)fc
, fx
);
199 fx
->fx_mxcsr
= fc
->mxcsr
;
200 bcopy(&fc
->xmm
[0], &fx
->fx_xmm
[0], sizeof (fc
->xmm
));
203 * avoid useless #gp exceptions - mask reserved bits
205 fx
->fx_mxcsr
&= sse_mxcsr_mask
;
209 * Map from an fxsave-format save area into a fpregset_t
212 fxsave_to_fpregset(const struct fxsave_state
*fx
, fpregset_t
*fp
)
215 bcopy(fx
, fp
, sizeof (*fx
));
217 struct _fpchip_state
*fc
= &fp
->fp_reg_set
.fpchip_state
;
219 fxsave_to_fnsave(fx
, (struct fnsave_state
*)fc
);
220 fc
->mxcsr
= fx
->fx_mxcsr
;
221 bcopy(&fx
->fx_xmm
[0], &fc
->xmm
[0], sizeof (fc
->xmm
));
225 #if defined(_SYSCALL32_IMPL)
227 fpregset32_to_fxsave(const fpregset32_t
*fp
, struct fxsave_state
*fx
)
229 const struct fpchip32_state
*fc
= &fp
->fp_reg_set
.fpchip_state
;
231 fnsave_to_fxsave((const struct fnsave_state
*)fc
, fx
);
233 * avoid useless #gp exceptions - mask reserved bits
235 fx
->fx_mxcsr
= sse_mxcsr_mask
& fc
->mxcsr
;
236 bcopy(&fc
->xmm
[0], &fx
->fx_xmm
[0], sizeof (fc
->xmm
));
240 fxsave_to_fpregset32(const struct fxsave_state
*fx
, fpregset32_t
*fp
)
242 struct fpchip32_state
*fc
= &fp
->fp_reg_set
.fpchip_state
;
244 fxsave_to_fnsave(fx
, (struct fnsave_state
*)fc
);
245 fc
->mxcsr
= fx
->fx_mxcsr
;
246 bcopy(&fx
->fx_xmm
[0], &fc
->xmm
[0], sizeof (fc
->xmm
));
250 fpregset_nto32(const fpregset_t
*src
, fpregset32_t
*dst
)
252 fxsave_to_fpregset32((struct fxsave_state
*)src
, dst
);
253 dst
->fp_reg_set
.fpchip_state
.status
=
254 src
->fp_reg_set
.fpchip_state
.status
;
255 dst
->fp_reg_set
.fpchip_state
.xstatus
=
256 src
->fp_reg_set
.fpchip_state
.xstatus
;
260 fpregset_32ton(const fpregset32_t
*src
, fpregset_t
*dst
)
262 fpregset32_to_fxsave(src
, (struct fxsave_state
*)dst
);
263 dst
->fp_reg_set
.fpchip_state
.status
=
264 src
->fp_reg_set
.fpchip_state
.status
;
265 dst
->fp_reg_set
.fpchip_state
.xstatus
=
266 src
->fp_reg_set
.fpchip_state
.xstatus
;
271 * Set floating-point registers from a native fpregset_t.
274 setfpregs(klwp_t
*lwp
, fpregset_t
*fp
)
276 struct fpu_ctx
*fpu
= &lwp
->lwp_pcb
.pcb_fpu
;
278 if (fpu
->fpu_flags
& FPU_EN
) {
279 if (!(fpu
->fpu_flags
& FPU_VALID
)) {
281 * FPU context is still active, release the
288 * Else: if we are trying to change the FPU state of a thread which
289 * hasn't yet initialized floating point, store the state in
290 * the pcb and indicate that the state is valid. When the
291 * thread enables floating point, it will use this state instead
292 * of the default state.
295 switch (fp_save_mech
) {
298 bcopy(fp
, &fpu
->fpu_regs
.kfpu_u
.kfpu_fn
,
299 sizeof (fpu
->fpu_regs
.kfpu_u
.kfpu_fn
));
303 fpregset_to_fxsave(fp
, &fpu
->fpu_regs
.kfpu_u
.kfpu_fx
);
304 fpu
->fpu_regs
.kfpu_xstatus
=
305 fp
->fp_reg_set
.fpchip_state
.xstatus
;
309 fpregset_to_fxsave(fp
,
310 &fpu
->fpu_regs
.kfpu_u
.kfpu_xs
.xs_fxsave
);
311 fpu
->fpu_regs
.kfpu_xstatus
=
312 fp
->fp_reg_set
.fpchip_state
.xstatus
;
313 fpu
->fpu_regs
.kfpu_u
.kfpu_xs
.xs_xstate_bv
|=
314 (XFEATURE_LEGACY_FP
| XFEATURE_SSE
);
317 panic("Invalid fp_save_mech");
321 fpu
->fpu_regs
.kfpu_status
= fp
->fp_reg_set
.fpchip_state
.status
;
322 fpu
->fpu_flags
|= FPU_VALID
;
326 * Get floating-point registers into a native fpregset_t.
329 getfpregs(klwp_t
*lwp
, fpregset_t
*fp
)
331 struct fpu_ctx
*fpu
= &lwp
->lwp_pcb
.pcb_fpu
;
334 if (fpu
->fpu_flags
& FPU_EN
) {
336 * If we have FPU hw and the thread's pcb doesn't have
337 * a valid FPU state then get the state from the hw.
339 if (fpu_exists
&& ttolwp(curthread
) == lwp
&&
340 !(fpu
->fpu_flags
& FPU_VALID
))
341 fp_save(fpu
); /* get the current FPU state */
345 * There are 3 possible cases we have to be aware of here:
347 * 1. FPU is enabled. FPU state is stored in the current LWP.
349 * 2. FPU is not enabled, and there have been no intervening /proc
350 * modifications. Return initial FPU state.
352 * 3. FPU is not enabled, but a /proc consumer has modified FPU state.
353 * FPU state is stored in the current LWP.
355 if ((fpu
->fpu_flags
& FPU_EN
) || (fpu
->fpu_flags
& FPU_VALID
)) {
359 switch (fp_save_mech
) {
362 bcopy(&fpu
->fpu_regs
.kfpu_u
.kfpu_fn
, fp
,
363 sizeof (fpu
->fpu_regs
.kfpu_u
.kfpu_fn
));
367 fxsave_to_fpregset(&fpu
->fpu_regs
.kfpu_u
.kfpu_fx
, fp
);
368 fp
->fp_reg_set
.fpchip_state
.xstatus
=
369 fpu
->fpu_regs
.kfpu_xstatus
;
373 &fpu
->fpu_regs
.kfpu_u
.kfpu_xs
.xs_fxsave
, fp
);
374 fp
->fp_reg_set
.fpchip_state
.xstatus
=
375 fpu
->fpu_regs
.kfpu_xstatus
;
378 panic("Invalid fp_save_mech");
381 fp
->fp_reg_set
.fpchip_state
.status
= fpu
->fpu_regs
.kfpu_status
;
386 switch (fp_save_mech
) {
389 bcopy(&x87_initial
, fp
, sizeof (x87_initial
));
395 * For now, we don't have any AVX specific field in ABI.
396 * If we add any in the future, we need to initial them
399 fxsave_to_fpregset(&sse_initial
, fp
);
400 fp
->fp_reg_set
.fpchip_state
.xstatus
=
401 fpu
->fpu_regs
.kfpu_xstatus
;
404 panic("Invalid fp_save_mech");
407 fp
->fp_reg_set
.fpchip_state
.status
= fpu
->fpu_regs
.kfpu_status
;
412 #if defined(_SYSCALL32_IMPL)
415 * Set floating-point registers from an fpregset32_t.
418 setfpregs32(klwp_t
*lwp
, fpregset32_t
*fp
)
422 fpregset_32ton(fp
, &fpregs
);
423 setfpregs(lwp
, &fpregs
);
427 * Get floating-point registers into an fpregset32_t.
430 getfpregs32(klwp_t
*lwp
, fpregset32_t
*fp
)
434 getfpregs(lwp
, &fpregs
);
435 fpregset_nto32(&fpregs
, fp
);
438 #endif /* _SYSCALL32_IMPL */
441 * Return the general registers
444 getgregs(klwp_t
*lwp
, gregset_t grp
)
446 struct regs
*rp
= lwptoregs(lwp
);
448 struct pcb
*pcb
= &lwp
->lwp_pcb
;
449 int thisthread
= lwptot(lwp
) == curthread
;
451 grp
[REG_RDI
] = rp
->r_rdi
;
452 grp
[REG_RSI
] = rp
->r_rsi
;
453 grp
[REG_RDX
] = rp
->r_rdx
;
454 grp
[REG_RCX
] = rp
->r_rcx
;
455 grp
[REG_R8
] = rp
->r_r8
;
456 grp
[REG_R9
] = rp
->r_r9
;
457 grp
[REG_RAX
] = rp
->r_rax
;
458 grp
[REG_RBX
] = rp
->r_rbx
;
459 grp
[REG_RBP
] = rp
->r_rbp
;
460 grp
[REG_R10
] = rp
->r_r10
;
461 grp
[REG_R11
] = rp
->r_r11
;
462 grp
[REG_R12
] = rp
->r_r12
;
463 grp
[REG_R13
] = rp
->r_r13
;
464 grp
[REG_R14
] = rp
->r_r14
;
465 grp
[REG_R15
] = rp
->r_r15
;
466 grp
[REG_FSBASE
] = pcb
->pcb_fsbase
;
467 grp
[REG_GSBASE
] = pcb
->pcb_gsbase
;
470 if (pcb
->pcb_rupdate
== 1) {
471 grp
[REG_DS
] = pcb
->pcb_ds
;
472 grp
[REG_ES
] = pcb
->pcb_es
;
473 grp
[REG_FS
] = pcb
->pcb_fs
;
474 grp
[REG_GS
] = pcb
->pcb_gs
;
476 grp
[REG_DS
] = rp
->r_ds
;
477 grp
[REG_ES
] = rp
->r_es
;
478 grp
[REG_FS
] = rp
->r_fs
;
479 grp
[REG_GS
] = rp
->r_gs
;
483 grp
[REG_TRAPNO
] = rp
->r_trapno
;
484 grp
[REG_ERR
] = rp
->r_err
;
485 grp
[REG_RIP
] = rp
->r_rip
;
486 grp
[REG_CS
] = rp
->r_cs
;
487 grp
[REG_SS
] = rp
->r_ss
;
488 grp
[REG_RFL
] = rp
->r_rfl
;
489 grp
[REG_RSP
] = rp
->r_rsp
;
491 bcopy(&rp
->r_gs
, grp
, sizeof (gregset_t
));
495 #if defined(_SYSCALL32_IMPL)
498 getgregs32(klwp_t
*lwp
, gregset32_t grp
)
500 struct regs
*rp
= lwptoregs(lwp
);
501 struct pcb
*pcb
= &lwp
->lwp_pcb
;
502 int thisthread
= lwptot(lwp
) == curthread
;
506 if (pcb
->pcb_rupdate
== 1) {
507 grp
[GS
] = (uint16_t)pcb
->pcb_gs
;
508 grp
[FS
] = (uint16_t)pcb
->pcb_fs
;
509 grp
[DS
] = (uint16_t)pcb
->pcb_ds
;
510 grp
[ES
] = (uint16_t)pcb
->pcb_es
;
512 grp
[GS
] = (uint16_t)rp
->r_gs
;
513 grp
[FS
] = (uint16_t)rp
->r_fs
;
514 grp
[DS
] = (uint16_t)rp
->r_ds
;
515 grp
[ES
] = (uint16_t)rp
->r_es
;
519 grp
[EDI
] = (greg32_t
)rp
->r_rdi
;
520 grp
[ESI
] = (greg32_t
)rp
->r_rsi
;
521 grp
[EBP
] = (greg32_t
)rp
->r_rbp
;
523 grp
[EBX
] = (greg32_t
)rp
->r_rbx
;
524 grp
[EDX
] = (greg32_t
)rp
->r_rdx
;
525 grp
[ECX
] = (greg32_t
)rp
->r_rcx
;
526 grp
[EAX
] = (greg32_t
)rp
->r_rax
;
527 grp
[TRAPNO
] = (greg32_t
)rp
->r_trapno
;
528 grp
[ERR
] = (greg32_t
)rp
->r_err
;
529 grp
[EIP
] = (greg32_t
)rp
->r_rip
;
530 grp
[CS
] = (uint16_t)rp
->r_cs
;
531 grp
[EFL
] = (greg32_t
)rp
->r_rfl
;
532 grp
[UESP
] = (greg32_t
)rp
->r_rsp
;
533 grp
[SS
] = (uint16_t)rp
->r_ss
;
537 ucontext_32ton(const ucontext32_t
*src
, ucontext_t
*dst
)
539 mcontext_t
*dmc
= &dst
->uc_mcontext
;
540 const mcontext32_t
*smc
= &src
->uc_mcontext
;
542 bzero(dst
, sizeof (*dst
));
543 dst
->uc_flags
= src
->uc_flags
;
544 dst
->uc_link
= (ucontext_t
*)(uintptr_t)src
->uc_link
;
546 bcopy(&src
->uc_sigmask
, &dst
->uc_sigmask
, sizeof (dst
->uc_sigmask
));
548 dst
->uc_stack
.ss_sp
= (void *)(uintptr_t)src
->uc_stack
.ss_sp
;
549 dst
->uc_stack
.ss_size
= (size_t)src
->uc_stack
.ss_size
;
550 dst
->uc_stack
.ss_flags
= src
->uc_stack
.ss_flags
;
552 dmc
->gregs
[REG_GS
] = (greg_t
)(uint32_t)smc
->gregs
[GS
];
553 dmc
->gregs
[REG_FS
] = (greg_t
)(uint32_t)smc
->gregs
[FS
];
554 dmc
->gregs
[REG_ES
] = (greg_t
)(uint32_t)smc
->gregs
[ES
];
555 dmc
->gregs
[REG_DS
] = (greg_t
)(uint32_t)smc
->gregs
[DS
];
556 dmc
->gregs
[REG_RDI
] = (greg_t
)(uint32_t)smc
->gregs
[EDI
];
557 dmc
->gregs
[REG_RSI
] = (greg_t
)(uint32_t)smc
->gregs
[ESI
];
558 dmc
->gregs
[REG_RBP
] = (greg_t
)(uint32_t)smc
->gregs
[EBP
];
559 dmc
->gregs
[REG_RBX
] = (greg_t
)(uint32_t)smc
->gregs
[EBX
];
560 dmc
->gregs
[REG_RDX
] = (greg_t
)(uint32_t)smc
->gregs
[EDX
];
561 dmc
->gregs
[REG_RCX
] = (greg_t
)(uint32_t)smc
->gregs
[ECX
];
562 dmc
->gregs
[REG_RAX
] = (greg_t
)(uint32_t)smc
->gregs
[EAX
];
563 dmc
->gregs
[REG_TRAPNO
] = (greg_t
)(uint32_t)smc
->gregs
[TRAPNO
];
564 dmc
->gregs
[REG_ERR
] = (greg_t
)(uint32_t)smc
->gregs
[ERR
];
565 dmc
->gregs
[REG_RIP
] = (greg_t
)(uint32_t)smc
->gregs
[EIP
];
566 dmc
->gregs
[REG_CS
] = (greg_t
)(uint32_t)smc
->gregs
[CS
];
567 dmc
->gregs
[REG_RFL
] = (greg_t
)(uint32_t)smc
->gregs
[EFL
];
568 dmc
->gregs
[REG_RSP
] = (greg_t
)(uint32_t)smc
->gregs
[UESP
];
569 dmc
->gregs
[REG_SS
] = (greg_t
)(uint32_t)smc
->gregs
[SS
];
572 * A valid fpregs is only copied in if uc.uc_flags has UC_FPU set
573 * otherwise there is no guarantee that anything in fpregs is valid.
575 if (src
->uc_flags
& UC_FPU
)
576 fpregset_32ton(&src
->uc_mcontext
.fpregs
,
577 &dst
->uc_mcontext
.fpregs
);
580 #endif /* _SYSCALL32_IMPL */
583 * Return the user-level PC.
584 * If in a system call, return the address of the syscall trap.
589 greg_t upc
= lwptoregs(ttolwp(curthread
))->r_pc
;
592 if (curthread
->t_sysnum
== 0)
596 * We might've gotten here from sysenter (0xf 0x34),
597 * syscall (0xf 0x5) or lcall (0x9a 0 0 0 0 0x27 0).
599 * Go peek at the binary to figure it out..
601 if (fuword32((void *)(upc
- 2), &insn
) != -1 &&
602 (insn
& 0xffff) == 0x340f || (insn
& 0xffff) == 0x050f)
608 * Protect segment registers from non-user privilege levels and GDT selectors
609 * other than USER_CS, USER_DS and lwp FS and GS values. If the segment
610 * selector is non-null and not USER_CS/USER_DS, we make sure that the
611 * TI bit is set to point into the LDT and that the RPL is set to 3.
613 * Since struct regs stores each 16-bit segment register as a 32-bit greg_t, we
614 * also explicitly zero the top 16 bits since they may be coming from the
615 * user's address space via setcontext(2) or /proc.
617 * Note about null selector. When running on the hypervisor if we allow a
618 * process to set its %cs to null selector with RPL of 0 the hypervisor will
619 * crash the domain. If running on bare metal we would get a #gp fault and
620 * be able to kill the process and continue on. Therefore we make sure to
621 * force RPL to SEL_UPL even for null selector when setting %cs.
624 #if defined(IS_CS) || defined(IS_NOT_CS)
625 #error "IS_CS and IS_NOT_CS already defined"
633 fix_segreg(greg_t sr
, int iscs
, model_t datamodel
)
635 switch (sr
&= 0xffff) {
639 return (0 | SEL_UPL
);
645 * If lwp attempts to switch data model then force their
646 * code selector to be null selector.
649 if (datamodel
== DATAMODEL_NATIVE
)
650 return (0 | SEL_UPL
);
655 if (datamodel
== DATAMODEL_ILP32
)
656 return (0 | SEL_UPL
);
657 #elif defined(__i386)
671 * Force it into the LDT in ring 3 for 32-bit processes, which by
672 * default do not have an LDT, so that any attempt to use an invalid
673 * selector will reference the (non-existant) LDT, and cause a #gp
674 * fault for the process.
676 * 64-bit processes get the null gdt selector since they
677 * are not allowed to have a private LDT.
680 if (datamodel
== DATAMODEL_ILP32
) {
681 return (sr
| SEL_TI_LDT
| SEL_UPL
);
684 return (0 | SEL_UPL
);
689 #elif defined(__i386)
690 return (sr
| SEL_TI_LDT
| SEL_UPL
);
695 * Set general registers.
698 setgregs(klwp_t
*lwp
, gregset_t grp
)
700 struct regs
*rp
= lwptoregs(lwp
);
701 model_t datamodel
= lwp_getdatamodel(lwp
);
704 struct pcb
*pcb
= &lwp
->lwp_pcb
;
705 int thisthread
= lwptot(lwp
) == curthread
;
707 if (datamodel
== DATAMODEL_NATIVE
) {
710 (void) save_syscall_args(); /* copy the args */
712 rp
->r_rdi
= grp
[REG_RDI
];
713 rp
->r_rsi
= grp
[REG_RSI
];
714 rp
->r_rdx
= grp
[REG_RDX
];
715 rp
->r_rcx
= grp
[REG_RCX
];
716 rp
->r_r8
= grp
[REG_R8
];
717 rp
->r_r9
= grp
[REG_R9
];
718 rp
->r_rax
= grp
[REG_RAX
];
719 rp
->r_rbx
= grp
[REG_RBX
];
720 rp
->r_rbp
= grp
[REG_RBP
];
721 rp
->r_r10
= grp
[REG_R10
];
722 rp
->r_r11
= grp
[REG_R11
];
723 rp
->r_r12
= grp
[REG_R12
];
724 rp
->r_r13
= grp
[REG_R13
];
725 rp
->r_r14
= grp
[REG_R14
];
726 rp
->r_r15
= grp
[REG_R15
];
727 rp
->r_trapno
= grp
[REG_TRAPNO
];
728 rp
->r_err
= grp
[REG_ERR
];
729 rp
->r_rip
= grp
[REG_RIP
];
731 * Setting %cs or %ss to anything else is quietly but
732 * quite definitely forbidden!
736 rp
->r_rsp
= grp
[REG_RSP
];
741 pcb
->pcb_ds
= UDS_SEL
;
742 pcb
->pcb_es
= UDS_SEL
;
745 * 64-bit processes -are- allowed to set their fsbase/gsbase
746 * values directly, but only if they're using the segment
747 * selectors that allow that semantic.
749 * (32-bit processes must use lwp_set_private().)
751 pcb
->pcb_fsbase
= grp
[REG_FSBASE
];
752 pcb
->pcb_gsbase
= grp
[REG_GSBASE
];
753 pcb
->pcb_fs
= fix_segreg(grp
[REG_FS
], IS_NOT_CS
, datamodel
);
754 pcb
->pcb_gs
= fix_segreg(grp
[REG_GS
], IS_NOT_CS
, datamodel
);
757 * Ensure that we go out via update_sregs
759 pcb
->pcb_rupdate
= 1;
760 lwptot(lwp
)->t_post_sys
= 1;
763 #if defined(_SYSCALL32_IMPL)
765 rp
->r_rdi
= (uint32_t)grp
[REG_RDI
];
766 rp
->r_rsi
= (uint32_t)grp
[REG_RSI
];
767 rp
->r_rdx
= (uint32_t)grp
[REG_RDX
];
768 rp
->r_rcx
= (uint32_t)grp
[REG_RCX
];
769 rp
->r_rax
= (uint32_t)grp
[REG_RAX
];
770 rp
->r_rbx
= (uint32_t)grp
[REG_RBX
];
771 rp
->r_rbp
= (uint32_t)grp
[REG_RBP
];
772 rp
->r_trapno
= (uint32_t)grp
[REG_TRAPNO
];
773 rp
->r_err
= (uint32_t)grp
[REG_ERR
];
774 rp
->r_rip
= (uint32_t)grp
[REG_RIP
];
776 rp
->r_cs
= fix_segreg(grp
[REG_CS
], IS_CS
, datamodel
);
777 rp
->r_ss
= fix_segreg(grp
[REG_DS
], IS_NOT_CS
, datamodel
);
779 rp
->r_rsp
= (uint32_t)grp
[REG_RSP
];
784 pcb
->pcb_ds
= fix_segreg(grp
[REG_DS
], IS_NOT_CS
, datamodel
);
785 pcb
->pcb_es
= fix_segreg(grp
[REG_ES
], IS_NOT_CS
, datamodel
);
788 * (See fsbase/gsbase commentary above)
790 pcb
->pcb_fs
= fix_segreg(grp
[REG_FS
], IS_NOT_CS
, datamodel
);
791 pcb
->pcb_gs
= fix_segreg(grp
[REG_GS
], IS_NOT_CS
, datamodel
);
794 * Ensure that we go out via update_sregs
796 pcb
->pcb_rupdate
= 1;
797 lwptot(lwp
)->t_post_sys
= 1;
804 * Only certain bits of the flags register can be modified.
806 rp
->r_rfl
= (rp
->r_rfl
& ~PSL_USERMASK
) |
807 (grp
[REG_RFL
] & PSL_USERMASK
);
809 #elif defined(__i386)
812 * Only certain bits of the flags register can be modified.
814 grp
[EFL
] = (rp
->r_efl
& ~PSL_USERMASK
) | (grp
[EFL
] & PSL_USERMASK
);
817 * Copy saved registers from user stack.
819 bcopy(grp
, &rp
->r_gs
, sizeof (gregset_t
));
821 rp
->r_cs
= fix_segreg(rp
->r_cs
, IS_CS
, datamodel
);
822 rp
->r_ss
= fix_segreg(rp
->r_ss
, IS_NOT_CS
, datamodel
);
823 rp
->r_ds
= fix_segreg(rp
->r_ds
, IS_NOT_CS
, datamodel
);
824 rp
->r_es
= fix_segreg(rp
->r_es
, IS_NOT_CS
, datamodel
);
825 rp
->r_fs
= fix_segreg(rp
->r_fs
, IS_NOT_CS
, datamodel
);
826 rp
->r_gs
= fix_segreg(rp
->r_gs
, IS_NOT_CS
, datamodel
);
832 * Determine whether eip is likely to have an interrupt frame
833 * on the stack. We do this by comparing the address to the
834 * range of addresses spanned by several well-known routines.
836 extern void _interrupt();
837 extern void _allsyscalls();
838 extern void _cmntrap();
839 extern void fakesoftint();
841 extern size_t _interrupt_size
;
842 extern size_t _allsyscalls_size
;
843 extern size_t _cmntrap_size
;
844 extern size_t _fakesoftint_size
;
847 * Get a pc-only stacktrace. Used for kmem_alloc() buffer ownership tracking.
848 * Returns MIN(current stack depth, pcstack_limit).
851 getpcstack(pc_t
*pcstack
, int pcstack_limit
)
853 struct frame
*fp
= (struct frame
*)getfp();
854 struct frame
*nextfp
, *minfp
, *stacktop
;
859 if ((on_intr
= CPU_ON_INTR(CPU
)) != 0)
860 stacktop
= (struct frame
*)(CPU
->cpu_intr_stack
+ SA(MINFRAME
));
862 stacktop
= (struct frame
*)curthread
->t_stk
;
865 pc
= ((struct regs
*)fp
)->r_pc
;
867 while (depth
< pcstack_limit
) {
868 nextfp
= (struct frame
*)fp
->fr_savfp
;
870 if (nextfp
<= minfp
|| nextfp
>= stacktop
) {
873 * Hop from interrupt stack to thread stack.
875 stacktop
= (struct frame
*)curthread
->t_stk
;
876 minfp
= (struct frame
*)curthread
->t_stkbase
;
882 pcstack
[depth
++] = (pc_t
)pc
;
890 * The following ELF header fields are defined as processor-specific
893 * e_ident[EI_DATA] encoding of the processor-specific
894 * data in the object file
895 * e_machine processor identification
896 * e_flags processor-specific flags associated
901 * The value of at_flags reflects a platform's cpu module support.
902 * at_flags is used to check for allowing a binary to execute and
903 * is passed as the value of the AT_FLAGS auxiliary vector.
908 * Check the processor-specific fields of an ELF header.
910 * returns 1 if the fields are valid, 0 otherwise
915 unsigned char e_data
,
916 Elf32_Half e_machine
,
919 if (e_data
!= ELFDATA2LSB
)
922 if (e_machine
== EM_AMD64
)
925 return (e_machine
== EM_386
);
928 uint_t auxv_hwcap_include
= 0; /* patch to enable unrecognized features */
929 uint_t auxv_hwcap_include_2
= 0; /* second word */
930 uint_t auxv_hwcap_exclude
= 0; /* patch for broken cpus, debugging */
931 uint_t auxv_hwcap_exclude_2
= 0; /* second word */
932 #if defined(_SYSCALL32_IMPL)
933 uint_t auxv_hwcap32_include
= 0; /* ditto for 32-bit apps */
934 uint_t auxv_hwcap32_include_2
= 0; /* ditto for 32-bit apps */
935 uint_t auxv_hwcap32_exclude
= 0; /* ditto for 32-bit apps */
936 uint_t auxv_hwcap32_exclude_2
= 0; /* ditto for 32-bit apps */
940 * Gather information about the processor and place it into auxv_hwcap
941 * so that it can be exported to the linker via the aux vector.
943 * We use this seemingly complicated mechanism so that we can ensure
944 * that /etc/system can be used to override what the system can or
945 * cannot discover for itself.
950 uint_t cpu_hwcap_flags
[2];
951 cpuid_pass4(NULL
, cpu_hwcap_flags
);
953 auxv_hwcap
= (auxv_hwcap_include
| cpu_hwcap_flags
[0]) &
955 auxv_hwcap_2
= (auxv_hwcap_include_2
| cpu_hwcap_flags
[1]) &
956 ~auxv_hwcap_exclude_2
;
960 * On AMD processors, sysenter just doesn't work at all
961 * when the kernel is in long mode. On IA-32e processors
962 * it does, but there's no real point in all the alternate
963 * mechanism when syscall works on both.
965 * Besides, the kernel's sysenter handler is expecting a
968 auxv_hwcap
&= ~AV_386_SEP
;
971 * 32-bit processes can -always- use the lahf/sahf instructions
973 auxv_hwcap
|= AV_386_AHF
;
976 if (auxv_hwcap_include
|| auxv_hwcap_exclude
|| auxv_hwcap_include_2
||
977 auxv_hwcap_exclude_2
) {
979 * The below assignment is regrettably required to get lint
980 * to accept the validity of our format string. The format
981 * string is in fact valid, but whatever intelligence in lint
982 * understands the cmn_err()-specific %b appears to have an
983 * off-by-one error: it (mistakenly) complains about bit
984 * number 32 (even though this is explicitly permitted).
985 * Normally, one would will away such warnings with a "LINTED"
986 * directive, but for reasons unclear and unknown, lint
987 * refuses to be assuaged in this case. Fortunately, lint
988 * doesn't pretend to have solved the Halting Problem --
989 * and as soon as the format string is programmatic, it
990 * knows enough to shut up.
992 char *fmt
= "?user ABI extensions: %b\n";
993 cmn_err(CE_CONT
, fmt
, auxv_hwcap
, FMT_AV_386
);
994 fmt
= "?user ABI extensions (word 2): %b\n";
995 cmn_err(CE_CONT
, fmt
, auxv_hwcap_2
, FMT_AV_386_2
);
998 #if defined(_SYSCALL32_IMPL)
999 auxv_hwcap32
= (auxv_hwcap32_include
| cpu_hwcap_flags
[0]) &
1000 ~auxv_hwcap32_exclude
;
1001 auxv_hwcap32_2
= (auxv_hwcap32_include_2
| cpu_hwcap_flags
[1]) &
1002 ~auxv_hwcap32_exclude_2
;
1004 #if defined(__amd64)
1006 * If this is an amd64 architecture machine from Intel, then
1007 * syscall -doesn't- work in compatibility mode, only sysenter does.
1011 if (!cpuid_syscall32_insn(NULL
))
1012 auxv_hwcap32
&= ~AV_386_AMD_SYSC
;
1015 * 32-bit processes can -always- use the lahf/sahf instructions
1017 auxv_hwcap32
|= AV_386_AHF
;
1020 if (auxv_hwcap32_include
|| auxv_hwcap32_exclude
||
1021 auxv_hwcap32_include_2
|| auxv_hwcap32_exclude_2
) {
1023 * See the block comment in the cmn_err() of auxv_hwcap, above.
1025 char *fmt
= "?32-bit user ABI extensions: %b\n";
1026 cmn_err(CE_CONT
, fmt
, auxv_hwcap32
, FMT_AV_386
);
1027 fmt
= "?32-bit user ABI extensions (word 2): %b\n";
1028 cmn_err(CE_CONT
, fmt
, auxv_hwcap32_2
, FMT_AV_386_2
);
1034 * sync_icache() - this is called
1035 * in proc/fs/prusrio.c. x86 has an unified cache and therefore
1040 sync_icache(caddr_t addr
, uint_t len
)
1042 /* Do nothing for now */
1047 sync_data_memory(caddr_t va
, size_t len
)
1049 /* Not implemented for this platform */
1055 return (ipltospl(ipl
));
1059 * The panic code invokes panic_saveregs() to record the contents of a
1060 * regs structure into the specified panic_data structure for debuggers.
1063 panic_saveregs(panic_data_t
*pdp
, struct regs
*rp
)
1065 panic_nv_t
*pnv
= PANICNVGET(pdp
);
1071 #if defined(__amd64)
1072 PANICNVADD(pnv
, "rdi", rp
->r_rdi
);
1073 PANICNVADD(pnv
, "rsi", rp
->r_rsi
);
1074 PANICNVADD(pnv
, "rdx", rp
->r_rdx
);
1075 PANICNVADD(pnv
, "rcx", rp
->r_rcx
);
1076 PANICNVADD(pnv
, "r8", rp
->r_r8
);
1077 PANICNVADD(pnv
, "r9", rp
->r_r9
);
1078 PANICNVADD(pnv
, "rax", rp
->r_rax
);
1079 PANICNVADD(pnv
, "rbx", rp
->r_rbx
);
1080 PANICNVADD(pnv
, "rbp", rp
->r_rbp
);
1081 PANICNVADD(pnv
, "r10", rp
->r_r10
);
1082 PANICNVADD(pnv
, "r11", rp
->r_r11
);
1083 PANICNVADD(pnv
, "r12", rp
->r_r12
);
1084 PANICNVADD(pnv
, "r13", rp
->r_r13
);
1085 PANICNVADD(pnv
, "r14", rp
->r_r14
);
1086 PANICNVADD(pnv
, "r15", rp
->r_r15
);
1087 PANICNVADD(pnv
, "fsbase", rdmsr(MSR_AMD_FSBASE
));
1088 PANICNVADD(pnv
, "gsbase", rdmsr(MSR_AMD_GSBASE
));
1089 PANICNVADD(pnv
, "ds", rp
->r_ds
);
1090 PANICNVADD(pnv
, "es", rp
->r_es
);
1091 PANICNVADD(pnv
, "fs", rp
->r_fs
);
1092 PANICNVADD(pnv
, "gs", rp
->r_gs
);
1093 PANICNVADD(pnv
, "trapno", rp
->r_trapno
);
1094 PANICNVADD(pnv
, "err", rp
->r_err
);
1095 PANICNVADD(pnv
, "rip", rp
->r_rip
);
1096 PANICNVADD(pnv
, "cs", rp
->r_cs
);
1097 PANICNVADD(pnv
, "rflags", rp
->r_rfl
);
1098 PANICNVADD(pnv
, "rsp", rp
->r_rsp
);
1099 PANICNVADD(pnv
, "ss", rp
->r_ss
);
1100 PANICNVADD(pnv
, "gdt_hi", (uint64_t)(creg
.cr_gdt
._l
[3]));
1101 PANICNVADD(pnv
, "gdt_lo", (uint64_t)(creg
.cr_gdt
._l
[0]));
1102 PANICNVADD(pnv
, "idt_hi", (uint64_t)(creg
.cr_idt
._l
[3]));
1103 PANICNVADD(pnv
, "idt_lo", (uint64_t)(creg
.cr_idt
._l
[0]));
1104 #elif defined(__i386)
1105 PANICNVADD(pnv
, "gs", (uint32_t)rp
->r_gs
);
1106 PANICNVADD(pnv
, "fs", (uint32_t)rp
->r_fs
);
1107 PANICNVADD(pnv
, "es", (uint32_t)rp
->r_es
);
1108 PANICNVADD(pnv
, "ds", (uint32_t)rp
->r_ds
);
1109 PANICNVADD(pnv
, "edi", (uint32_t)rp
->r_edi
);
1110 PANICNVADD(pnv
, "esi", (uint32_t)rp
->r_esi
);
1111 PANICNVADD(pnv
, "ebp", (uint32_t)rp
->r_ebp
);
1112 PANICNVADD(pnv
, "esp", (uint32_t)rp
->r_esp
);
1113 PANICNVADD(pnv
, "ebx", (uint32_t)rp
->r_ebx
);
1114 PANICNVADD(pnv
, "edx", (uint32_t)rp
->r_edx
);
1115 PANICNVADD(pnv
, "ecx", (uint32_t)rp
->r_ecx
);
1116 PANICNVADD(pnv
, "eax", (uint32_t)rp
->r_eax
);
1117 PANICNVADD(pnv
, "trapno", (uint32_t)rp
->r_trapno
);
1118 PANICNVADD(pnv
, "err", (uint32_t)rp
->r_err
);
1119 PANICNVADD(pnv
, "eip", (uint32_t)rp
->r_eip
);
1120 PANICNVADD(pnv
, "cs", (uint32_t)rp
->r_cs
);
1121 PANICNVADD(pnv
, "eflags", (uint32_t)rp
->r_efl
);
1122 PANICNVADD(pnv
, "uesp", (uint32_t)rp
->r_uesp
);
1123 PANICNVADD(pnv
, "ss", (uint32_t)rp
->r_ss
);
1124 PANICNVADD(pnv
, "gdt", creg
.cr_gdt
);
1125 PANICNVADD(pnv
, "idt", creg
.cr_idt
);
1128 PANICNVADD(pnv
, "ldt", creg
.cr_ldt
);
1129 PANICNVADD(pnv
, "task", creg
.cr_task
);
1130 PANICNVADD(pnv
, "cr0", creg
.cr_cr0
);
1131 PANICNVADD(pnv
, "cr2", creg
.cr_cr2
);
1132 PANICNVADD(pnv
, "cr3", creg
.cr_cr3
);
1134 PANICNVADD(pnv
, "cr4", creg
.cr_cr4
);
1136 PANICNVSET(pdp
, pnv
);
1139 #define TR_ARG_MAX 6 /* Max args to print, same as SPARC */
1141 #if !defined(__amd64)
1144 * Given a return address (%eip), determine the likely number of arguments
1145 * that were pushed on the stack prior to its execution. We do this by
1146 * expecting that a typical call sequence consists of pushing arguments on
1147 * the stack, executing a call instruction, and then performing an add
1148 * on %esp to restore it to the value prior to pushing the arguments for
1149 * the call. We attempt to detect such an add, and divide the addend
1150 * by the size of a word to determine the number of pushed arguments.
1152 * If we do not find such an add, we punt and return TR_ARG_MAX. It is not
1153 * possible to reliably determine if a function took no arguments (i.e. was
1154 * void) because assembler routines do not reliably perform an add on %esp
1155 * immediately upon returning (eg. _sys_call()), so returning TR_ARG_MAX is
1156 * safer than returning 0.
1159 argcount(uintptr_t eip
)
1161 const uint8_t *ins
= (const uint8_t *)eip
;
1165 M_MODRM_ESP
= 0xc4, /* Mod/RM byte indicates %esp */
1166 M_ADD_IMM32
= 0x81, /* ADD imm32 to r/m32 */
1167 M_ADD_IMM8
= 0x83 /* ADD imm8 to r/m32 */
1170 if (eip
< KERNELBASE
|| ins
[1] != M_MODRM_ESP
)
1171 return (TR_ARG_MAX
);
1175 n
= ins
[2] + (ins
[3] << 8) + (ins
[4] << 16) + (ins
[5] << 24);
1183 return (TR_ARG_MAX
);
1187 return (MIN(n
, TR_ARG_MAX
));
1190 #endif /* !__amd64 */
1193 * Print a stack backtrace using the specified frame pointer. We delay two
1194 * seconds before continuing, unless this is the panic traceback.
1195 * If we are in the process of panicking, we also attempt to write the
1196 * stack backtrace to a staticly assigned buffer, to allow the panic
1197 * code to find it and write it in to uncompressed pages within the
1198 * system crash dump.
1199 * Note that the frame for the starting stack pointer value is omitted because
1200 * the corresponding %eip is not known.
1203 extern char *dump_stack_scratch
;
1205 #if defined(__amd64)
1208 traceback(caddr_t fpreg
)
1210 struct frame
*fp
= (struct frame
*)fpreg
;
1211 struct frame
*nextfp
;
1212 uintptr_t pc
, nextpc
;
1214 char args
[TR_ARG_MAX
* 2 + 16], *sym
;
1216 uint_t next_offset
= 0;
1217 char stack_buffer
[1024];
1220 printf("traceback: %%fp = %p\n", (void *)fp
);
1222 if (panicstr
&& !dump_stack_scratch
) {
1223 printf("Warning - stack not written to the dump buffer\n");
1226 fp
= (struct frame
*)plat_traceback(fpreg
);
1227 if ((uintptr_t)fp
< KERNELBASE
)
1231 fp
= (struct frame
*)fp
->fr_savfp
;
1233 while ((uintptr_t)fp
>= KERNELBASE
) {
1235 * XX64 Until port is complete tolerate 8-byte aligned
1236 * frame pointers but flag with a warning so they can
1239 if (((uintptr_t)fp
& (STACK_ALIGN
- 1)) != 0) {
1240 if (((uintptr_t)fp
& (8 - 1)) == 0) {
1241 printf(" >> warning! 8-byte"
1242 " aligned %%fp = %p\n", (void *)fp
);
1245 " >> mis-aligned %%fp = %p\n", (void *)fp
);
1251 nextpc
= (uintptr_t)fp
->fr_savpc
;
1252 nextfp
= (struct frame
*)fp
->fr_savfp
;
1253 if ((sym
= kobj_getsymname(pc
, &off
)) != NULL
) {
1254 printf("%016lx %s:%s+%lx (%s)\n", (uintptr_t)fp
,
1255 mod_containing_pc((caddr_t
)pc
), sym
, off
, args
);
1256 (void) snprintf(stack_buffer
, sizeof (stack_buffer
),
1257 "%s:%s+%lx (%s) | ",
1258 mod_containing_pc((caddr_t
)pc
), sym
, off
, args
);
1260 printf("%016lx %lx (%s)\n",
1261 (uintptr_t)fp
, pc
, args
);
1262 (void) snprintf(stack_buffer
, sizeof (stack_buffer
),
1263 "%lx (%s) | ", pc
, args
);
1266 if (panicstr
&& dump_stack_scratch
) {
1267 next_offset
= offset
+ strlen(stack_buffer
);
1268 if (next_offset
< STACK_BUF_SIZE
) {
1269 bcopy(stack_buffer
, dump_stack_scratch
+ offset
,
1270 strlen(stack_buffer
));
1271 offset
= next_offset
;
1274 * In attempting to save the panic stack
1275 * to the dumpbuf we have overflowed that area.
1276 * Print a warning and continue to printf the
1277 * stack to the msgbuf
1279 printf("Warning: stack in the dump buffer"
1280 " may be incomplete\n");
1281 offset
= next_offset
;
1290 printf("end of traceback\n");
1291 DELAY(2 * MICROSEC
);
1292 } else if (dump_stack_scratch
) {
1293 dump_stack_scratch
[offset
] = '\0';
1297 #elif defined(__i386)
1300 traceback(caddr_t fpreg
)
1302 struct frame
*fp
= (struct frame
*)fpreg
;
1303 struct frame
*nextfp
, *minfp
, *stacktop
;
1304 uintptr_t pc
, nextpc
;
1306 uint_t next_offset
= 0;
1307 char stack_buffer
[1024];
1312 * args[] holds TR_ARG_MAX hex long args, plus ", " or '\0'.
1314 char args
[TR_ARG_MAX
* 2 + 8], *p
;
1321 printf("traceback: %%fp = %p\n", (void *)fp
);
1323 if (panicstr
&& !dump_stack_scratch
) {
1324 printf("Warning - stack not written to the dumpbuf\n");
1328 * If we are panicking, all high-level interrupt information in
1329 * CPU was overwritten. panic_cpu has the correct values.
1331 kpreempt_disable(); /* prevent migration */
1333 cpu
= (panicstr
&& CPU
->cpu_id
== panic_cpu
.cpu_id
)? &panic_cpu
: CPU
;
1335 if ((on_intr
= CPU_ON_INTR(cpu
)) != 0)
1336 stacktop
= (struct frame
*)(cpu
->cpu_intr_stack
+ SA(MINFRAME
));
1338 stacktop
= (struct frame
*)curthread
->t_stk
;
1342 fp
= (struct frame
*)plat_traceback(fpreg
);
1343 if ((uintptr_t)fp
< KERNELBASE
)
1346 minfp
= fp
; /* Baseline minimum frame pointer */
1348 fp
= (struct frame
*)fp
->fr_savfp
;
1350 while ((uintptr_t)fp
>= KERNELBASE
) {
1354 if (fp
<= minfp
|| fp
>= stacktop
) {
1357 * Hop from interrupt stack to thread stack.
1359 stacktop
= (struct frame
*)curthread
->t_stk
;
1360 minfp
= (struct frame
*)curthread
->t_stkbase
;
1364 break; /* we're outside of the expected range */
1367 if ((uintptr_t)fp
& (STACK_ALIGN
- 1)) {
1368 printf(" >> mis-aligned %%fp = %p\n", (void *)fp
);
1372 nextpc
= fp
->fr_savpc
;
1373 nextfp
= (struct frame
*)fp
->fr_savfp
;
1374 argc
= argcount(nextpc
);
1375 argv
= (long *)((char *)fp
+ sizeof (struct frame
));
1379 while (argc
-- > 0 && argv
< (long *)stacktop
) {
1380 p
+= snprintf(p
, args
+ sizeof (args
) - p
,
1381 "%s%lx", (p
== args
) ? "" : ", ", *argv
++);
1384 if ((sym
= kobj_getsymname(pc
, &off
)) != NULL
) {
1385 printf("%08lx %s:%s+%lx (%s)\n", (uintptr_t)fp
,
1386 mod_containing_pc((caddr_t
)pc
), sym
, off
, args
);
1387 (void) snprintf(stack_buffer
, sizeof (stack_buffer
),
1388 "%s:%s+%lx (%s) | ",
1389 mod_containing_pc((caddr_t
)pc
), sym
, off
, args
);
1392 printf("%08lx %lx (%s)\n",
1393 (uintptr_t)fp
, pc
, args
);
1394 (void) snprintf(stack_buffer
, sizeof (stack_buffer
),
1395 "%lx (%s) | ", pc
, args
);
1399 if (panicstr
&& dump_stack_scratch
) {
1400 next_offset
= offset
+ strlen(stack_buffer
);
1401 if (next_offset
< STACK_BUF_SIZE
) {
1402 bcopy(stack_buffer
, dump_stack_scratch
+ offset
,
1403 strlen(stack_buffer
));
1404 offset
= next_offset
;
1407 * In attempting to save the panic stack
1408 * to the dumpbuf we have overflowed that area.
1409 * Print a warning and continue to printf the
1410 * stack to the msgbuf
1412 printf("Warning: stack in the dumpbuf"
1413 " may be incomplete\n");
1414 offset
= next_offset
;
1424 printf("end of traceback\n");
1425 DELAY(2 * MICROSEC
);
1426 } else if (dump_stack_scratch
) {
1427 dump_stack_scratch
[offset
] = '\0';
1435 * Generate a stack backtrace from a saved register set.
1438 traceregs(struct regs
*rp
)
1440 traceback((caddr_t
)rp
->r_fp
);
1444 exec_set_sp(size_t stksize
)
1446 klwp_t
*lwp
= ttolwp(curthread
);
1448 lwptoregs(lwp
)->r_sp
= (uintptr_t)curproc
->p_usrstack
- stksize
;
1452 gethrtime_waitfree(void)
1454 return (dtrace_gethrtime());
1460 return (gethrtimef());
1464 gethrtime_unscaled(void)
1466 return (gethrtimeunscaledf());
1470 scalehrtime(hrtime_t
*hrt
)
1476 unscalehrtime(hrtime_t nsecs
)
1478 return (unscalehrtimef(nsecs
));
1482 gethrestime(timespec_t
*tp
)
1487 #if defined(__amd64)
1489 * Part of the implementation of hres_tick(); this routine is
1490 * easier in C than assembler .. called with the hres_lock held.
1492 * XX64 Many of these timekeeping variables need to be extern'ed in a header
1495 #include <sys/time.h>
1496 #include <sys/machlock.h>
1499 extern int max_hres_adj
;
1502 __adj_hrestime(void)
1506 if (hrestime_adj
== 0)
1508 else if (hrestime_adj
> 0) {
1509 if (hrestime_adj
< max_hres_adj
)
1514 if (hrestime_adj
< -max_hres_adj
)
1515 adj
= -max_hres_adj
;
1521 hrestime_adj
= timedelta
;
1522 hrestime
.tv_nsec
+= adj
;
1524 while (hrestime
.tv_nsec
>= NANOSEC
) {
1527 hrestime
.tv_nsec
-= NANOSEC
;
1533 * Wrapper functions to maintain backwards compability
1536 xcopyin(const void *uaddr
, void *kaddr
, size_t count
)
1538 return (xcopyin_nta(uaddr
, kaddr
, count
, UIO_COPY_CACHED
));
1542 xcopyout(const void *kaddr
, void *uaddr
, size_t count
)
1544 return (xcopyout_nta(kaddr
, uaddr
, count
, UIO_COPY_CACHED
));