xref: /titanic_52/usr/src/uts/i86pc/os/machdep.c (revision d2117003c7d0588abeea5ed1b925b77f025e2c96)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/t_lock.h>
31 #include <sys/param.h>
32 #include <sys/sysmacros.h>
33 #include <sys/signal.h>
34 #include <sys/systm.h>
35 #include <sys/user.h>
36 #include <sys/mman.h>
37 #include <sys/vm.h>
38 
39 #include <sys/disp.h>
40 #include <sys/class.h>
41 
42 #include <sys/proc.h>
43 #include <sys/buf.h>
44 #include <sys/kmem.h>
45 
46 #include <sys/reboot.h>
47 #include <sys/uadmin.h>
48 #include <sys/callb.h>
49 
50 #include <sys/cred.h>
51 #include <sys/vnode.h>
52 #include <sys/file.h>
53 
54 #include <sys/procfs.h>
55 #include <sys/acct.h>
56 
57 #include <sys/vfs.h>
58 #include <sys/dnlc.h>
59 #include <sys/var.h>
60 #include <sys/cmn_err.h>
61 #include <sys/utsname.h>
62 #include <sys/debug.h>
63 #include <sys/kdi_impl.h>
64 
65 #include <sys/dumphdr.h>
66 #include <sys/bootconf.h>
67 #include <sys/varargs.h>
68 #include <sys/promif.h>
69 #include <sys/modctl.h>
70 
71 #include <sys/consdev.h>
72 #include <sys/frame.h>
73 
74 #include <sys/sunddi.h>
75 #include <sys/ddidmareq.h>
76 #include <sys/psw.h>
77 #include <sys/regset.h>
78 #include <sys/privregs.h>
79 #include <sys/clock.h>
80 #include <sys/tss.h>
81 #include <sys/cpu.h>
82 #include <sys/stack.h>
83 #include <sys/trap.h>
84 #include <sys/pic.h>
85 #include <sys/mmu.h>
86 #include <vm/hat.h>
87 #include <vm/anon.h>
88 #include <vm/as.h>
89 #include <vm/page.h>
90 #include <vm/seg.h>
91 #include <vm/seg_kmem.h>
92 #include <vm/seg_map.h>
93 #include <vm/seg_vn.h>
94 #include <vm/seg_kp.h>
95 #include <vm/hat_i86.h>
96 #include <sys/swap.h>
97 #include <sys/thread.h>
98 #include <sys/sysconf.h>
99 #include <sys/vm_machparam.h>
100 #include <sys/archsystm.h>
101 #include <sys/machsystm.h>
102 #include <sys/machlock.h>
103 #include <sys/x_call.h>
104 #include <sys/instance.h>
105 
106 #include <sys/time.h>
107 #include <sys/smp_impldefs.h>
108 #include <sys/psm_types.h>
109 #include <sys/atomic.h>
110 #include <sys/panic.h>
111 #include <sys/cpuvar.h>
112 #include <sys/dtrace.h>
113 #include <sys/bl.h>
114 #include <sys/nvpair.h>
115 #include <sys/x86_archext.h>
116 #include <sys/pool_pset.h>
117 #include <sys/autoconf.h>
118 #include <sys/kdi.h>
119 
120 #ifdef	TRAPTRACE
121 #include <sys/traptrace.h>
122 #endif	/* TRAPTRACE */
123 
124 #ifdef C2_AUDIT
125 extern void audit_enterprom(int);
126 extern void audit_exitprom(int);
127 #endif
128 
129 /*
130  * The panicbuf array is used to record messages and state:
131  */
132 char panicbuf[PANICBUFSIZE];
133 
134 /*
135  * maxphys - used during physio
136  * klustsize - used for klustering by swapfs and specfs
137  */
138 int maxphys = 56 * 1024;    /* XXX See vm_subr.c - max b_count in physio */
139 int klustsize = 56 * 1024;
140 
141 caddr_t	p0_va;		/* Virtual address for accessing physical page 0 */
142 int	pokefault = 0;
143 
144 /*
145  * defined here, though unused on x86,
146  * to make kstat_fr.c happy.
147  */
148 int vac;
149 
150 void stop_other_cpus();
151 void debug_enter(char *);
152 
153 int	procset = 1;
154 
155 /*
156  * Flags set by mdboot if we're panicking and we invoke mdboot on a CPU which
157  * is not the boot CPU.  When set, panic_idle() on the boot CPU will invoke
158  * mdboot with the corresponding arguments.
159  */
160 
161 #define	BOOT_WAIT	-1		/* Flag indicating we should idle */
162 
163 volatile int cpu_boot_cmd = BOOT_WAIT;
164 volatile int cpu_boot_fcn = BOOT_WAIT;
165 
166 extern void pm_cfb_check_and_powerup(void);
167 extern void pm_cfb_rele(void);
168 
169 /*
170  * Machine dependent code to reboot.
171  * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
172  * to a string to be used as the argument string when rebooting.
173  *
174  * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
175  * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
176  * we are in a normal shutdown sequence (interrupts are not blocked, the
177  * system is not panic'ing or being suspended).
178  */
179 /*ARGSUSED*/
180 void
181 mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)
182 {
183 	extern void mtrr_resync(void);
184 
185 	/*
186 	 * The PSMI guarantees the implementor of psm_shutdown that it will
187 	 * only be called on the boot CPU.  This was needed by Corollary
188 	 * because the hardware does not allow other CPUs to reset the
189 	 * boot CPU.  So before rebooting, we switch over to the boot CPU.
190 	 * If we are panicking, the other CPUs are at high spl spinning in
191 	 * panic_idle(), so we set the cpu_boot_* variables and wait for
192 	 * the boot CPU to re-invoke mdboot() for us.
193 	 */
194 	if (!panicstr) {
195 		kpreempt_disable();
196 		affinity_set(getbootcpuid());
197 	} else if (CPU->cpu_id != getbootcpuid()) {
198 		cpu_boot_cmd = cmd;
199 		cpu_boot_fcn = fcn;
200 		for (;;);
201 	}
202 
203 	/*
204 	 * XXX - rconsvp is set to NULL to ensure that output messages
205 	 * are sent to the underlying "hardware" device using the
206 	 * monitor's printf routine since we are in the process of
207 	 * either rebooting or halting the machine.
208 	 */
209 	rconsvp = NULL;
210 
211 	/*
212 	 * Print the reboot message now, before pausing other cpus.
213 	 * There is a race condition in the printing support that
214 	 * can deadlock multiprocessor machines.
215 	 */
216 	if (!(fcn == AD_HALT || fcn == AD_POWEROFF))
217 		prom_printf("rebooting...\n");
218 
219 	/*
220 	 * We can't bring up the console from above lock level, so do it now
221 	 */
222 	pm_cfb_check_and_powerup();
223 
224 	/* make sure there are no more changes to the device tree */
225 	devtree_freeze();
226 
227 	if (invoke_cb)
228 		(void) callb_execute_class(CB_CL_MDBOOT, NULL);
229 
230 	/*
231 	 * stop other cpus and raise our priority.  since there is only
232 	 * one active cpu after this, and our priority will be too high
233 	 * for us to be preempted, we're essentially single threaded
234 	 * from here on out.
235 	 */
236 	(void) spl6();
237 	if (!panicstr) {
238 		mutex_enter(&cpu_lock);
239 		pause_cpus(NULL);
240 		mutex_exit(&cpu_lock);
241 	}
242 
243 	/*
244 	 * try and reset leaf devices.  reset_leaves() should only
245 	 * be called when there are no other threads that could be
246 	 * accessing devices
247 	 */
248 	reset_leaves();
249 
250 	(void) spl8();
251 	(*psm_shutdownf)(cmd, fcn);
252 
253 	mtrr_resync();
254 
255 	if (fcn == AD_HALT || fcn == AD_POWEROFF)
256 		halt((char *)NULL);
257 	else
258 		prom_reboot("");
259 	/*NOTREACHED*/
260 }
261 
262 /* mdpreboot - may be called prior to mdboot while root fs still mounted */
263 /*ARGSUSED*/
264 void
265 mdpreboot(int cmd, int fcn, char *mdep)
266 {
267 	(*psm_preshutdownf)(cmd, fcn);
268 }
269 
270 void
271 idle_other_cpus()
272 {
273 	int cpuid = CPU->cpu_id;
274 	cpuset_t xcset;
275 
276 	ASSERT(cpuid < NCPU);
277 	CPUSET_ALL_BUT(xcset, cpuid);
278 	xc_capture_cpus(xcset);
279 }
280 
281 void
282 resume_other_cpus()
283 {
284 	ASSERT(CPU->cpu_id < NCPU);
285 
286 	xc_release_cpus();
287 }
288 
289 extern void	mp_halt(char *);
290 
291 void
292 stop_other_cpus()
293 {
294 	int cpuid = CPU->cpu_id;
295 	cpuset_t xcset;
296 
297 	ASSERT(cpuid < NCPU);
298 
299 	/*
300 	 * xc_trycall will attempt to make all other CPUs execute mp_halt,
301 	 * and will return immediately regardless of whether or not it was
302 	 * able to make them do it.
303 	 */
304 	CPUSET_ALL_BUT(xcset, cpuid);
305 	xc_trycall(NULL, NULL, NULL, xcset, (int (*)())mp_halt);
306 }
307 
308 /*
309  *	Machine dependent abort sequence handling
310  */
311 void
312 abort_sequence_enter(char *msg)
313 {
314 	if (abort_enable == 0) {
315 #ifdef C2_AUDIT
316 		if (audit_active)
317 			audit_enterprom(0);
318 #endif /* C2_AUDIT */
319 		return;
320 	}
321 #ifdef C2_AUDIT
322 	if (audit_active)
323 		audit_enterprom(1);
324 #endif /* C2_AUDIT */
325 	debug_enter(msg);
326 #ifdef C2_AUDIT
327 	if (audit_active)
328 		audit_exitprom(1);
329 #endif /* C2_AUDIT */
330 }
331 
332 /*
333  * Enter debugger.  Called when the user types ctrl-alt-d or whenever
334  * code wants to enter the debugger and possibly resume later.
335  */
336 void
337 debug_enter(
338 	char	*msg)		/* message to print, possibly NULL */
339 {
340 	if (dtrace_debugger_init != NULL)
341 		(*dtrace_debugger_init)();
342 
343 	if (msg)
344 		prom_printf("%s\n", msg);
345 
346 	if (boothowto & RB_DEBUG)
347 		kdi_dvec_enter();
348 
349 	if (dtrace_debugger_fini != NULL)
350 		(*dtrace_debugger_fini)();
351 }
352 
353 void
354 reset(void)
355 {
356 	ushort_t *bios_memchk;
357 
358 	/*
359 	 * Can't use psm_map_phys before the hat is initialized.
360 	 */
361 	if (khat_running) {
362 		bios_memchk = (ushort_t *)psm_map_phys(0x472,
363 		    sizeof (ushort_t), PROT_READ | PROT_WRITE);
364 		if (bios_memchk)
365 			*bios_memchk = 0x1234;	/* bios memory check disable */
366 	}
367 
368 	pc_reset();
369 	/*NOTREACHED*/
370 }
371 
372 /*
373  * Halt the machine and return to the monitor
374  */
375 void
376 halt(char *s)
377 {
378 	stop_other_cpus();	/* send stop signal to other CPUs */
379 	if (s)
380 		prom_printf("(%s) \n", s);
381 	prom_exit_to_mon();
382 	/*NOTREACHED*/
383 }
384 
385 /*
386  * Enter monitor.  Called via cross-call from stop_other_cpus().
387  */
388 void
389 mp_halt(char *msg)
390 {
391 	if (msg)
392 		prom_printf("%s\n", msg);
393 
394 	/*CONSTANTCONDITION*/
395 	while (1)
396 		;
397 }
398 
399 /*
400  * Initiate interrupt redistribution.
401  */
402 void
403 i_ddi_intr_redist_all_cpus()
404 {
405 }
406 
407 /*
408  * XXX These probably ought to live somewhere else
409  * XXX They are called from mem.c
410  */
411 
412 /*
413  * Convert page frame number to an OBMEM page frame number
414  * (i.e. put in the type bits -- zero for this implementation)
415  */
416 pfn_t
417 impl_obmem_pfnum(pfn_t pf)
418 {
419 	return (pf);
420 }
421 
422 #ifdef	NM_DEBUG
423 int nmi_test = 0;	/* checked in intentry.s during clock int */
424 int nmtest = -1;
425 nmfunc1(arg, rp)
426 int	arg;
427 struct regs *rp;
428 {
429 	printf("nmi called with arg = %x, regs = %x\n", arg, rp);
430 	nmtest += 50;
431 	if (arg == nmtest) {
432 		printf("ip = %x\n", rp->r_pc);
433 		return (1);
434 	}
435 	return (0);
436 }
437 
438 #endif
439 
440 #include <sys/bootsvcs.h>
441 
442 /* Hacked up initialization for initial kernel check out is HERE. */
443 /* The basic steps are: */
444 /*	kernel bootfuncs definition/initialization for KADB */
445 /*	kadb bootfuncs pointer initialization */
446 /*	putchar/getchar (interrupts disabled) */
447 
448 /* kadb bootfuncs pointer initialization */
449 
450 int
451 sysp_getchar()
452 {
453 	int i;
454 	int s;
455 
456 	if (cons_polledio == NULL) {
457 		/* Uh oh */
458 		prom_printf("getchar called with no console\n");
459 		for (;;)
460 			/* LOOP FOREVER */;
461 	}
462 
463 	s = clear_int_flag();
464 	i = cons_polledio->cons_polledio_getchar(
465 		cons_polledio->cons_polledio_argument);
466 	restore_int_flag(s);
467 	return (i);
468 }
469 
470 void
471 sysp_putchar(int c)
472 {
473 	int s;
474 
475 	/*
476 	 * We have no alternative but to drop the output on the floor.
477 	 */
478 	if (cons_polledio == NULL)
479 		return;
480 
481 	s = clear_int_flag();
482 	cons_polledio->cons_polledio_putchar(
483 		cons_polledio->cons_polledio_argument, c);
484 	restore_int_flag(s);
485 }
486 
487 int
488 sysp_ischar()
489 {
490 	int i;
491 	int s;
492 
493 	if (cons_polledio == NULL)
494 		return (0);
495 
496 	s = clear_int_flag();
497 	i = cons_polledio->cons_polledio_ischar(
498 		cons_polledio->cons_polledio_argument);
499 	restore_int_flag(s);
500 	return (i);
501 }
502 
503 int
504 goany(void)
505 {
506 	prom_printf("Type any key to continue ");
507 	(void) prom_getchar();
508 	prom_printf("\n");
509 	return (1);
510 }
511 
512 static struct boot_syscalls kern_sysp = {
513 	sysp_getchar,	/*	unchar	(*getchar)();	7  */
514 	sysp_putchar,	/*	int	(*putchar)();	8  */
515 	sysp_ischar,	/*	int	(*ischar)();	9  */
516 };
517 
518 void
519 kadb_uses_kernel()
520 {
521 	/*
522 	 * This routine is now totally misnamed, since it does not in fact
523 	 * control kadb's I/O; it only controls the kernel's prom_* I/O.
524 	 */
525 	sysp = &kern_sysp;
526 }
527 
528 /*
529  *	the interface to the outside world
530  */
531 
532 /*
533  * poll_port -- wait for a register to achieve a
534  *		specific state.  Arguments are a mask of bits we care about,
535  *		and two sub-masks.  To return normally, all the bits in the
536  *		first sub-mask must be ON, all the bits in the second sub-
537  *		mask must be OFF.  If about seconds pass without the register
538  *		achieving the desired bit configuration, we return 1, else
539  *		0.
540  */
541 int
542 poll_port(ushort_t port, ushort_t mask, ushort_t onbits, ushort_t offbits)
543 {
544 	int i;
545 	ushort_t maskval;
546 
547 	for (i = 500000; i; i--) {
548 		maskval = inb(port) & mask;
549 		if (((maskval & onbits) == onbits) &&
550 			((maskval & offbits) == 0))
551 			return (0);
552 		drv_usecwait(10);
553 	}
554 	return (1);
555 }
556 
557 /*
558  * set_idle_cpu is called from idle() when a CPU becomes idle.
559  */
560 /*LINTED: static unused */
561 static uint_t last_idle_cpu;
562 
563 /*ARGSUSED*/
564 void
565 set_idle_cpu(int cpun)
566 {
567 	last_idle_cpu = cpun;
568 	(*psm_set_idle_cpuf)(cpun);
569 }
570 
571 /*
572  * unset_idle_cpu is called from idle() when a CPU is no longer idle.
573  */
574 /*ARGSUSED*/
575 void
576 unset_idle_cpu(int cpun)
577 {
578 	(*psm_unset_idle_cpuf)(cpun);
579 }
580 
581 /*
582  * This routine is almost correct now, but not quite.  It still needs the
583  * equivalent concept of "hres_last_tick", just like on the sparc side.
584  * The idea is to take a snapshot of the hi-res timer while doing the
585  * hrestime_adj updates under hres_lock in locore, so that the small
586  * interval between interrupt assertion and interrupt processing is
587  * accounted for correctly.  Once we have this, the code below should
588  * be modified to subtract off hres_last_tick rather than hrtime_base.
589  *
590  * I'd have done this myself, but I don't have source to all of the
591  * vendor-specific hi-res timer routines (grrr...).  The generic hook I
592  * need is something like "gethrtime_unlocked()", which would be just like
593  * gethrtime() but would assume that you're already holding CLOCK_LOCK().
594  * This is what the GET_HRTIME() macro is for on sparc (although it also
595  * serves the function of making time available without a function call
596  * so you don't take a register window overflow while traps are disabled).
597  */
598 void
599 pc_gethrestime(timestruc_t *tp)
600 {
601 	int lock_prev;
602 	timestruc_t now;
603 	int nslt;		/* nsec since last tick */
604 	int adj;		/* amount of adjustment to apply */
605 
606 loop:
607 	lock_prev = hres_lock;
608 	now = hrestime;
609 	nslt = (int)(gethrtime() - hres_last_tick);
610 	if (nslt < 0) {
611 		/*
612 		 * nslt < 0 means a tick came between sampling
613 		 * gethrtime() and hres_last_tick; restart the loop
614 		 */
615 
616 		goto loop;
617 	}
618 	now.tv_nsec += nslt;
619 	if (hrestime_adj != 0) {
620 		if (hrestime_adj > 0) {
621 			adj = (nslt >> ADJ_SHIFT);
622 			if (adj > hrestime_adj)
623 				adj = (int)hrestime_adj;
624 		} else {
625 			adj = -(nslt >> ADJ_SHIFT);
626 			if (adj < hrestime_adj)
627 				adj = (int)hrestime_adj;
628 		}
629 		now.tv_nsec += adj;
630 	}
631 	while ((unsigned long)now.tv_nsec >= NANOSEC) {
632 
633 		/*
634 		 * We might have a large adjustment or have been in the
635 		 * debugger for a long time; take care of (at most) four
636 		 * of those missed seconds (tv_nsec is 32 bits, so
637 		 * anything >4s will be wrapping around).  However,
638 		 * anything more than 2 seconds out of sync will trigger
639 		 * timedelta from clock() to go correct the time anyway,
640 		 * so do what we can, and let the big crowbar do the
641 		 * rest.  A similar correction while loop exists inside
642 		 * hres_tick(); in all cases we'd like tv_nsec to
643 		 * satisfy 0 <= tv_nsec < NANOSEC to avoid confusing
644 		 * user processes, but if tv_sec's a little behind for a
645 		 * little while, that's OK; time still monotonically
646 		 * increases.
647 		 */
648 
649 		now.tv_nsec -= NANOSEC;
650 		now.tv_sec++;
651 	}
652 	if ((hres_lock & ~1) != lock_prev)
653 		goto loop;
654 
655 	*tp = now;
656 }
657 
658 void
659 gethrestime_lasttick(timespec_t *tp)
660 {
661 	int s;
662 
663 	s = hr_clock_lock();
664 	*tp = hrestime;
665 	hr_clock_unlock(s);
666 }
667 
668 time_t
669 gethrestime_sec(void)
670 {
671 	timestruc_t now;
672 
673 	gethrestime(&now);
674 	return (now.tv_sec);
675 }
676 
677 /*
678  * Initialize a kernel thread's stack
679  */
680 
681 caddr_t
682 thread_stk_init(caddr_t stk)
683 {
684 	ASSERT(((uintptr_t)stk & (STACK_ALIGN - 1)) == 0);
685 	return (stk - SA(MINFRAME));
686 }
687 
688 /*
689  * Initialize lwp's kernel stack.
690  */
691 
692 #ifdef TRAPTRACE
693 /*
694  * There's a tricky interdependency here between use of sysenter and
695  * TRAPTRACE which needs recording to avoid future confusion (this is
696  * about the third time I've re-figured this out ..)
697  *
698  * Here's how debugging lcall works with TRAPTRACE.
699  *
700  * 1 We're in userland with a breakpoint on the lcall instruction.
701  * 2 We execute the instruction - the instruction pushes the userland
702  *   %ss, %esp, %efl, %cs, %eip on the stack and zips into the kernel
703  *   via the call gate.
704  * 3 The hardware raises a debug trap in kernel mode, the hardware
705  *   pushes %efl, %cs, %eip and gets to dbgtrap via the idt.
706  * 4 dbgtrap pushes the error code and trapno and calls cmntrap
707  * 5 cmntrap finishes building a trap frame
708  * 6 The TRACE_REGS macros in cmntrap copy a REGSIZE worth chunk
709  *   off the stack into the traptrace buffer.
710  *
711  * This means that the traptrace buffer contains the wrong values in
712  * %esp and %ss, but everything else in there is correct.
713  *
714  * Here's how debugging sysenter works with TRAPTRACE.
715  *
716  * a We're in userland with a breakpoint on the sysenter instruction.
717  * b We execute the instruction - the instruction pushes -nothing-
718  *   on the stack, but sets %cs, %eip, %ss, %esp to prearranged
719  *   values to take us to sys_sysenter, at the top of the lwp's
720  *   stack.
721  * c goto 3
722  *
723  * At this point, because we got into the kernel without the requisite
724  * five pushes on the stack, if we didn't make extra room, we'd
725  * end up with the TRACE_REGS macro fetching the saved %ss and %esp
726  * values from negative (unmapped) stack addresses -- which really bites.
727  * That's why we do the '-= 8' below.
728  *
729  * XXX	Note that reading "up" lwp0's stack works because t0 is declared
730  *	right next to t0stack in locore.s
731  */
732 #endif
733 
734 caddr_t
735 lwp_stk_init(klwp_t *lwp, caddr_t stk)
736 {
737 	caddr_t oldstk;
738 	struct pcb *pcb = &lwp->lwp_pcb;
739 
740 	oldstk = stk;
741 	stk -= SA(sizeof (struct regs) + SA(MINFRAME));
742 #ifdef TRAPTRACE
743 	stk -= 2 * sizeof (greg_t); /* space for phony %ss:%sp (see above) */
744 #endif
745 	stk = (caddr_t)((uintptr_t)stk & ~(STACK_ALIGN - 1ul));
746 	bzero(stk, oldstk - stk);
747 	lwp->lwp_regs = (void *)(stk + SA(MINFRAME));
748 
749 	/*
750 	 * Arrange that the virtualized %fs and %gs GDT descriptors
751 	 * have a well-defined initial state (present, ring 3
752 	 * and of type data).
753 	 */
754 #if defined(__amd64)
755 	if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE)
756 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
757 	else
758 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_u32desc;
759 #elif defined(__i386)
760 	pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
761 #endif	/* __i386 */
762 	lwp_installctx(lwp);
763 	return (stk);
764 }
765 
766 /*ARGSUSED*/
767 void
768 lwp_stk_fini(klwp_t *lwp)
769 {}
770 
771 /*
772  * If we're not the panic CPU, we wait in panic_idle for reboot.  If we're
773  * the boot CPU, then we are responsible for actually doing the reboot, so
774  * we watch for cpu_boot_cmd to be set.
775  */
776 static void
777 panic_idle(void)
778 {
779 	splx(ipltospl(CLOCK_LEVEL));
780 	(void) setjmp(&curthread->t_pcb);
781 
782 	if (CPU->cpu_id == getbootcpuid()) {
783 		while (cpu_boot_cmd == BOOT_WAIT || cpu_boot_fcn == BOOT_WAIT)
784 			drv_usecwait(10);
785 
786 		mdboot(cpu_boot_cmd, cpu_boot_fcn, NULL, B_FALSE);
787 	}
788 
789 	for (;;);
790 }
791 
792 /*
793  * Stop the other CPUs by cross-calling them and forcing them to enter
794  * the panic_idle() loop above.
795  */
796 /*ARGSUSED*/
797 void
798 panic_stopcpus(cpu_t *cp, kthread_t *t, int spl)
799 {
800 	processorid_t i;
801 	cpuset_t xcset;
802 
803 	(void) splzs();
804 
805 	CPUSET_ALL_BUT(xcset, cp->cpu_id);
806 	xc_trycall(NULL, NULL, NULL, xcset, (int (*)())panic_idle);
807 
808 	for (i = 0; i < NCPU; i++) {
809 		if (i != cp->cpu_id && cpu[i] != NULL &&
810 		    (cpu[i]->cpu_flags & CPU_EXISTS))
811 			cpu[i]->cpu_flags |= CPU_QUIESCED;
812 	}
813 }
814 
815 /*
816  * Platform callback following each entry to panicsys().
817  */
818 /*ARGSUSED*/
819 void
820 panic_enter_hw(int spl)
821 {
822 	/* Nothing to do here */
823 }
824 
825 /*
826  * Platform-specific code to execute after panicstr is set: we invoke
827  * the PSM entry point to indicate that a panic has occurred.
828  */
829 /*ARGSUSED*/
830 void
831 panic_quiesce_hw(panic_data_t *pdp)
832 {
833 	psm_notifyf(PSM_PANIC_ENTER);
834 
835 #ifdef	TRAPTRACE
836 	/*
837 	 * Turn off TRAPTRACE
838 	 */
839 	TRAPTRACE_FREEZE;
840 #endif	/* TRAPTRACE */
841 }
842 
843 /*
844  * Platform callback prior to writing crash dump.
845  */
846 /*ARGSUSED*/
847 void
848 panic_dump_hw(int spl)
849 {
850 	/* Nothing to do here */
851 }
852 
853 /*ARGSUSED*/
854 void
855 plat_tod_fault(enum tod_fault_type tod_bad)
856 {
857 }
858 
859 /*ARGSUSED*/
860 int
861 blacklist(int cmd, const char *scheme, nvlist_t *fmri, const char *class)
862 {
863 	return (ENOTSUP);
864 }
865 
866 /*
867  * The underlying console output routines are protected by raising IPL in case
868  * we are still calling into the early boot services.  Once we start calling
869  * the kernel console emulator, it will disable interrupts completely during
870  * character rendering (see sysp_putchar, for example).  Refer to the comments
871  * and code in common/os/console.c for more information on these callbacks.
872  */
873 /*ARGSUSED*/
874 int
875 console_enter(int busy)
876 {
877 	return (splzs());
878 }
879 
880 /*ARGSUSED*/
881 void
882 console_exit(int busy, int spl)
883 {
884 	splx(spl);
885 }
886 
887 /*
888  * Allocate a region of virtual address space, unmapped.
889  * Stubbed out except on sparc, at least for now.
890  */
891 /*ARGSUSED*/
892 void *
893 boot_virt_alloc(void *addr, size_t size)
894 {
895 	return (addr);
896 }
897 
898 volatile unsigned long	tenmicrodata;
899 
900 void
901 tenmicrosec(void)
902 {
903 	extern int	tsc_gethrtime_initted;
904 	int		i;
905 
906 	if (tsc_gethrtime_initted) {
907 		hrtime_t start, end;
908 		start = end =  gethrtime();
909 		while ((end - start) < (10 * (NANOSEC / MICROSEC))) {
910 			SMT_PAUSE();
911 			end = gethrtime();
912 		}
913 	} else {
914 		/*
915 		 * Artificial loop to induce delay.
916 		 */
917 		for (i = 0; i < microdata; i++)
918 			tenmicrodata = microdata;
919 	}
920 }
921