10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55648Ssetje * Common Development and Distribution License (the "License").
65648Ssetje * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12967Sgavin.maltby@oracle.com * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
260Sstevel@tonic-gate /* All Rights Reserved */
270Sstevel@tonic-gate
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/vmparam.h>
320Sstevel@tonic-gate #include <sys/systm.h>
330Sstevel@tonic-gate #include <sys/sysmacros.h>
340Sstevel@tonic-gate #include <sys/signal.h>
350Sstevel@tonic-gate #include <sys/stack.h>
360Sstevel@tonic-gate #include <sys/frame.h>
370Sstevel@tonic-gate #include <sys/proc.h>
380Sstevel@tonic-gate #include <sys/ucontext.h>
390Sstevel@tonic-gate #include <sys/siginfo.h>
400Sstevel@tonic-gate #include <sys/cpuvar.h>
410Sstevel@tonic-gate #include <sys/asm_linkage.h>
420Sstevel@tonic-gate #include <sys/kmem.h>
430Sstevel@tonic-gate #include <sys/errno.h>
440Sstevel@tonic-gate #include <sys/bootconf.h>
450Sstevel@tonic-gate #include <sys/archsystm.h>
460Sstevel@tonic-gate #include <sys/fpu/fpusystm.h>
470Sstevel@tonic-gate #include <sys/auxv.h>
480Sstevel@tonic-gate #include <sys/debug.h>
490Sstevel@tonic-gate #include <sys/elf.h>
500Sstevel@tonic-gate #include <sys/elf_SPARC.h>
510Sstevel@tonic-gate #include <sys/cmn_err.h>
520Sstevel@tonic-gate #include <sys/spl.h>
530Sstevel@tonic-gate #include <sys/privregs.h>
540Sstevel@tonic-gate #include <sys/kobj.h>
550Sstevel@tonic-gate #include <sys/modctl.h>
560Sstevel@tonic-gate #include <sys/reboot.h>
570Sstevel@tonic-gate #include <sys/time.h>
580Sstevel@tonic-gate #include <sys/panic.h>
590Sstevel@tonic-gate #include <vm/seg_kmem.h>
600Sstevel@tonic-gate #include <vm/page.h>
610Sstevel@tonic-gate #include <sys/machpcb.h>
620Sstevel@tonic-gate
630Sstevel@tonic-gate extern struct bootops *bootops;
640Sstevel@tonic-gate
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate * Workaround for broken FDDI driver (remove when 4289172 is fixed)
670Sstevel@tonic-gate */
680Sstevel@tonic-gate short cputype = 0x80;
690Sstevel@tonic-gate
700Sstevel@tonic-gate extern int getpcstack_top(pc_t *pcstack, int limit, uintptr_t *lastfp,
710Sstevel@tonic-gate pc_t *lastpc);
720Sstevel@tonic-gate
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate * Get a pc-only stacktrace. Used for kmem_alloc() buffer ownership tracking.
750Sstevel@tonic-gate * Returns MIN(current stack depth, pcstack_limit).
760Sstevel@tonic-gate */
770Sstevel@tonic-gate int
getpcstack(pc_t * pcstack,int pcstack_limit)780Sstevel@tonic-gate getpcstack(pc_t *pcstack, int pcstack_limit)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate struct frame *fp, *minfp, *stacktop;
810Sstevel@tonic-gate uintptr_t nextfp;
820Sstevel@tonic-gate pc_t nextpc;
830Sstevel@tonic-gate int depth;
840Sstevel@tonic-gate int on_intr;
850Sstevel@tonic-gate pc_t pcswin[MAXWIN];
860Sstevel@tonic-gate int npcwin = MIN(MAXWIN, pcstack_limit);
870Sstevel@tonic-gate
880Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(CPU)) != 0)
890Sstevel@tonic-gate stacktop = (struct frame *)(CPU->cpu_intr_stack + SA(MINFRAME));
900Sstevel@tonic-gate else
910Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk;
920Sstevel@tonic-gate
930Sstevel@tonic-gate minfp = (struct frame *)((uintptr_t)getfp() + STACK_BIAS);
940Sstevel@tonic-gate
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate * getpcstack_top() processes the frames still in register windows,
970Sstevel@tonic-gate * fills nextfp and nextpc with our starting point, and returns
980Sstevel@tonic-gate * the number of frames it wrote into pcstack.
990Sstevel@tonic-gate *
1000Sstevel@tonic-gate * Since we cannot afford to take a relocation trap while we are
1010Sstevel@tonic-gate * messing with register windows, we pass getpcstack_top() a buffer
1020Sstevel@tonic-gate * on our stack and then copy the result out to the pcstack buffer
1030Sstevel@tonic-gate * provided by the caller. The size of this buffer is the maximum
1040Sstevel@tonic-gate * supported number of SPARC register windows; however we ASSERT
1050Sstevel@tonic-gate * that it returns fewer than that, since it will skip the current
1060Sstevel@tonic-gate * frame.
1070Sstevel@tonic-gate */
1080Sstevel@tonic-gate npcwin = getpcstack_top(pcswin, npcwin, &nextfp, &nextpc);
1090Sstevel@tonic-gate ASSERT(npcwin >= 0 && npcwin < MAXWIN && npcwin <= pcstack_limit);
1100Sstevel@tonic-gate for (depth = 0; depth < npcwin; depth++) {
1110Sstevel@tonic-gate pcstack[depth] = pcswin[depth];
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate fp = (struct frame *)(nextfp + STACK_BIAS);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate while (depth < pcstack_limit) {
1170Sstevel@tonic-gate if (fp <= minfp || fp >= stacktop) {
1180Sstevel@tonic-gate if (on_intr) {
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate * Hop from interrupt stack to thread stack.
1210Sstevel@tonic-gate */
1220Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk;
1230Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase;
1240Sstevel@tonic-gate on_intr = 0;
1250Sstevel@tonic-gate continue;
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate break;
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate pcstack[depth++] = nextpc;
1310Sstevel@tonic-gate minfp = fp;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate nextpc = (pc_t)fp->fr_savpc;
1340Sstevel@tonic-gate fp = (struct frame *)((uintptr_t)fp->fr_savfp + STACK_BIAS);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate return (depth);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate * The following ELF header fields are defined as processor-specific
1420Sstevel@tonic-gate * in the SPARC V8 ABI:
1430Sstevel@tonic-gate *
1440Sstevel@tonic-gate * e_ident[EI_DATA] encoding of the processor-specific
1450Sstevel@tonic-gate * data in the object file
1460Sstevel@tonic-gate * e_machine processor identification
1470Sstevel@tonic-gate * e_flags processor-specific flags associated
1480Sstevel@tonic-gate * with the file
1490Sstevel@tonic-gate */
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate * The value of at_flags reflects a platform's cpu module support.
1530Sstevel@tonic-gate * at_flags is used to check for allowing a binary to execute and
1540Sstevel@tonic-gate * is passed as the value of the AT_FLAGS auxiliary vector.
1550Sstevel@tonic-gate */
1560Sstevel@tonic-gate int at_flags = 0;
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate * Check the processor-specific fields of an ELF header.
1600Sstevel@tonic-gate *
1610Sstevel@tonic-gate * returns 1 if the fields are valid, 0 otherwise
1620Sstevel@tonic-gate */
1630Sstevel@tonic-gate int
elfheadcheck(unsigned char e_data,Elf32_Half e_machine,Elf32_Word e_flags)1640Sstevel@tonic-gate elfheadcheck(
1650Sstevel@tonic-gate unsigned char e_data,
1660Sstevel@tonic-gate Elf32_Half e_machine,
1670Sstevel@tonic-gate Elf32_Word e_flags)
1680Sstevel@tonic-gate {
1690Sstevel@tonic-gate Elf32_Word needed_flags;
1700Sstevel@tonic-gate int supported_flags;
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate if (e_data != ELFDATA2MSB)
1730Sstevel@tonic-gate return (0);
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate switch (e_machine) {
1760Sstevel@tonic-gate case EM_SPARC:
1770Sstevel@tonic-gate if (e_flags == 0)
1780Sstevel@tonic-gate return (1);
1790Sstevel@tonic-gate else
1800Sstevel@tonic-gate return (0);
1810Sstevel@tonic-gate case EM_SPARCV9:
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate * Check that ELF flags are set to supported SPARC V9 flags
1840Sstevel@tonic-gate */
1850Sstevel@tonic-gate needed_flags = e_flags & EF_SPARC_EXT_MASK;
1860Sstevel@tonic-gate supported_flags = at_flags & ~EF_SPARC_32PLUS;
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate if (needed_flags & ~supported_flags)
1890Sstevel@tonic-gate return (0);
1900Sstevel@tonic-gate else
1910Sstevel@tonic-gate return (1);
1920Sstevel@tonic-gate case EM_SPARC32PLUS:
1930Sstevel@tonic-gate if ((e_flags & EF_SPARC_32PLUS) != 0 &&
1940Sstevel@tonic-gate ((e_flags & ~at_flags) & EF_SPARC_32PLUS_MASK) == 0)
1950Sstevel@tonic-gate return (1);
1960Sstevel@tonic-gate else
1970Sstevel@tonic-gate return (0);
1980Sstevel@tonic-gate default:
1990Sstevel@tonic-gate return (0);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate uint_t auxv_hwcap_include = 0; /* patch to enable unrecognized features */
2040Sstevel@tonic-gate uint_t auxv_hwcap_exclude = 0; /* patch for broken cpus, debugging */
2050Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
2060Sstevel@tonic-gate uint_t auxv_hwcap32_include = 0; /* ditto for 32-bit apps */
2070Sstevel@tonic-gate uint_t auxv_hwcap32_exclude = 0; /* ditto for 32-bit apps */
2080Sstevel@tonic-gate #endif
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate uint_t cpu_hwcap_flags = 0; /* set by cpu-dependent code */
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate * Gather information about the processor and place it into auxv_hwcap
2140Sstevel@tonic-gate * so that it can be exported to the linker via the aux vector.
2150Sstevel@tonic-gate *
2160Sstevel@tonic-gate * We use this seemingly complicated mechanism so that we can ensure
2170Sstevel@tonic-gate * that /etc/system can be used to override what the system can or
2180Sstevel@tonic-gate * cannot discover for itself.
2190Sstevel@tonic-gate */
2200Sstevel@tonic-gate void
bind_hwcap(void)2210Sstevel@tonic-gate bind_hwcap(void)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate auxv_hwcap = (auxv_hwcap_include | cpu_hwcap_flags) &
2240Sstevel@tonic-gate ~auxv_hwcap_exclude;
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate if (auxv_hwcap_include || auxv_hwcap_exclude)
2270Sstevel@tonic-gate cmn_err(CE_CONT, "?user ABI extensions: %b\n",
2280Sstevel@tonic-gate auxv_hwcap, FMT_AV_SPARC);
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate * These are now a compatibility artifact; all supported SPARC CPUs
2330Sstevel@tonic-gate * are V9-capable (and thus support v8plus) and fully implement
2340Sstevel@tonic-gate * {s,u}mul and {s,u}div.
2350Sstevel@tonic-gate */
2360Sstevel@tonic-gate cpu_hwcap_flags |= AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS;
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate auxv_hwcap32 = (auxv_hwcap32_include | cpu_hwcap_flags) &
2390Sstevel@tonic-gate ~auxv_hwcap32_exclude;
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate if (auxv_hwcap32_include || auxv_hwcap32_exclude)
2420Sstevel@tonic-gate cmn_err(CE_CONT, "?32-bit user ABI extensions: %b\n",
2430Sstevel@tonic-gate auxv_hwcap32, FMT_AV_SPARC);
2440Sstevel@tonic-gate #endif
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate int
__ipltospl(int ipl)2480Sstevel@tonic-gate __ipltospl(int ipl)
2490Sstevel@tonic-gate {
2500Sstevel@tonic-gate return (ipltospl(ipl));
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate /*
2540Sstevel@tonic-gate * Print a stack backtrace using the specified stack pointer. We delay two
255*12967Sgavin.maltby@oracle.com * seconds before continuing, unless this is the panic traceback.
256*12967Sgavin.maltby@oracle.com * If we are in the process of panicking, we also attempt to write the
257*12967Sgavin.maltby@oracle.com * stack backtrace to a staticly assigned buffer, to allow the panic
258*12967Sgavin.maltby@oracle.com * code to find it and write it in to uncompressed pages within the
259*12967Sgavin.maltby@oracle.com * system crash dump.
260*12967Sgavin.maltby@oracle.com *
261*12967Sgavin.maltby@oracle.com * Note that the frame for the starting stack pointer value is omitted because
2620Sstevel@tonic-gate * the corresponding %pc is not known.
2630Sstevel@tonic-gate */
264*12967Sgavin.maltby@oracle.com
265*12967Sgavin.maltby@oracle.com extern char *dump_stack_scratch;
266*12967Sgavin.maltby@oracle.com
2670Sstevel@tonic-gate void
traceback(caddr_t sp)2680Sstevel@tonic-gate traceback(caddr_t sp)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate struct frame *fp = (struct frame *)(sp + STACK_BIAS);
2710Sstevel@tonic-gate struct frame *nextfp, *minfp, *stacktop;
2720Sstevel@tonic-gate int on_intr;
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate cpu_t *cpu;
2750Sstevel@tonic-gate
276*12967Sgavin.maltby@oracle.com uint_t offset = 0;
277*12967Sgavin.maltby@oracle.com uint_t next_offset = 0;
278*12967Sgavin.maltby@oracle.com char stack_buffer[2048];
279*12967Sgavin.maltby@oracle.com char local_buffer[1024];
280*12967Sgavin.maltby@oracle.com
2810Sstevel@tonic-gate flush_windows();
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate if (!panicstr)
2840Sstevel@tonic-gate printf("traceback: %%sp = %p\n", (void *)sp);
2850Sstevel@tonic-gate
286*12967Sgavin.maltby@oracle.com if (panicstr && !dump_stack_scratch) {
287*12967Sgavin.maltby@oracle.com printf("Warning - stack not written to the dumpbuf\n");
288*12967Sgavin.maltby@oracle.com }
289*12967Sgavin.maltby@oracle.com
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate * If we are panicking, the high-level interrupt information in
2920Sstevel@tonic-gate * CPU was overwritten. panic_cpu has the correct values.
2930Sstevel@tonic-gate */
2940Sstevel@tonic-gate kpreempt_disable(); /* prevent migration */
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate cpu = (panicstr && CPU->cpu_id == panic_cpu.cpu_id)? &panic_cpu : CPU;
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate if ((on_intr = CPU_ON_INTR(cpu)) != 0)
2990Sstevel@tonic-gate stacktop = (struct frame *)(cpu->cpu_intr_stack + SA(MINFRAME));
3000Sstevel@tonic-gate else
3010Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk;
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate kpreempt_enable();
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate minfp = fp;
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate while ((uintptr_t)fp >= KERNELBASE) {
3080Sstevel@tonic-gate uintptr_t pc = (uintptr_t)fp->fr_savpc;
3090Sstevel@tonic-gate ulong_t off;
3100Sstevel@tonic-gate char *sym;
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate nextfp = (struct frame *)((uintptr_t)fp->fr_savfp + STACK_BIAS);
3130Sstevel@tonic-gate if (nextfp <= minfp || nextfp >= stacktop) {
3140Sstevel@tonic-gate if (on_intr) {
3150Sstevel@tonic-gate /*
3160Sstevel@tonic-gate * Hop from interrupt stack to thread stack.
3170Sstevel@tonic-gate */
3180Sstevel@tonic-gate stacktop = (struct frame *)curthread->t_stk;
3190Sstevel@tonic-gate minfp = (struct frame *)curthread->t_stkbase;
3200Sstevel@tonic-gate on_intr = 0;
3210Sstevel@tonic-gate continue;
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate break; /* we're outside of the expected range */
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate if ((uintptr_t)nextfp & (STACK_ALIGN - 1)) {
3270Sstevel@tonic-gate printf(" >> mis-aligned %%fp = %p\n", (void *)nextfp);
3280Sstevel@tonic-gate break;
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate if ((sym = kobj_getsymname(pc, &off)) != NULL) {
3320Sstevel@tonic-gate printf("%016lx %s:%s+%lx "
3330Sstevel@tonic-gate "(%lx, %lx, %lx, %lx, %lx, %lx)\n", (ulong_t)nextfp,
3340Sstevel@tonic-gate mod_containing_pc((caddr_t)pc), sym, off,
3350Sstevel@tonic-gate nextfp->fr_arg[0], nextfp->fr_arg[1],
3360Sstevel@tonic-gate nextfp->fr_arg[2], nextfp->fr_arg[3],
3370Sstevel@tonic-gate nextfp->fr_arg[4], nextfp->fr_arg[5]);
338*12967Sgavin.maltby@oracle.com (void) snprintf(stack_buffer, sizeof (stack_buffer),
339*12967Sgavin.maltby@oracle.com "%s:%s+%lx "
340*12967Sgavin.maltby@oracle.com "(%lx, %lx, %lx, %lx, %lx, %lx) | ",
341*12967Sgavin.maltby@oracle.com mod_containing_pc((caddr_t)pc), sym, off,
342*12967Sgavin.maltby@oracle.com nextfp->fr_arg[0], nextfp->fr_arg[1],
343*12967Sgavin.maltby@oracle.com nextfp->fr_arg[2], nextfp->fr_arg[3],
344*12967Sgavin.maltby@oracle.com nextfp->fr_arg[4], nextfp->fr_arg[5]);
3450Sstevel@tonic-gate } else {
346*12967Sgavin.maltby@oracle.com (void) printf("%016lx %p (%lx, %lx, %lx, "
347*12967Sgavin.maltby@oracle.com "%lx, %lx, %lx)\n",
3480Sstevel@tonic-gate (ulong_t)nextfp, (void *)pc,
3490Sstevel@tonic-gate nextfp->fr_arg[0], nextfp->fr_arg[1],
3500Sstevel@tonic-gate nextfp->fr_arg[2], nextfp->fr_arg[3],
3510Sstevel@tonic-gate nextfp->fr_arg[4], nextfp->fr_arg[5]);
352*12967Sgavin.maltby@oracle.com (void) snprintf(stack_buffer, sizeof (stack_buffer),
353*12967Sgavin.maltby@oracle.com "%p (%lx, %lx, %lx, %lx, %lx, %lx) | ",
354*12967Sgavin.maltby@oracle.com (void *)pc,
355*12967Sgavin.maltby@oracle.com nextfp->fr_arg[0], nextfp->fr_arg[1],
356*12967Sgavin.maltby@oracle.com nextfp->fr_arg[2], nextfp->fr_arg[3],
357*12967Sgavin.maltby@oracle.com nextfp->fr_arg[4], nextfp->fr_arg[5]);
3580Sstevel@tonic-gate }
3590Sstevel@tonic-gate
360*12967Sgavin.maltby@oracle.com (void) snprintf(local_buffer, sizeof (local_buffer),
361*12967Sgavin.maltby@oracle.com " %%l0-3: %016lx %016lx %016lx %016lx\n"
3620Sstevel@tonic-gate " %%l4-7: %016lx %016lx %016lx %016lx\n",
3630Sstevel@tonic-gate nextfp->fr_local[0], nextfp->fr_local[1],
3640Sstevel@tonic-gate nextfp->fr_local[2], nextfp->fr_local[3],
3650Sstevel@tonic-gate nextfp->fr_local[4], nextfp->fr_local[5],
3660Sstevel@tonic-gate nextfp->fr_local[6], nextfp->fr_local[7]);
367*12967Sgavin.maltby@oracle.com if (panicstr && dump_stack_scratch) {
368*12967Sgavin.maltby@oracle.com next_offset = offset + strlen(stack_buffer);
369*12967Sgavin.maltby@oracle.com if (next_offset < STACK_BUF_SIZE) {
370*12967Sgavin.maltby@oracle.com bcopy(stack_buffer, dump_stack_scratch + offset,
371*12967Sgavin.maltby@oracle.com strlen(stack_buffer));
372*12967Sgavin.maltby@oracle.com offset = next_offset;
373*12967Sgavin.maltby@oracle.com } else {
374*12967Sgavin.maltby@oracle.com /*
375*12967Sgavin.maltby@oracle.com * In attempting to save the panic stack
376*12967Sgavin.maltby@oracle.com * to the dumpbuf we have overflowed that area.
377*12967Sgavin.maltby@oracle.com * Print a warning and continue to printf the
378*12967Sgavin.maltby@oracle.com * stack to the msgbuf
379*12967Sgavin.maltby@oracle.com */
380*12967Sgavin.maltby@oracle.com printf("Warning: stack in the dump buffer"
381*12967Sgavin.maltby@oracle.com " may be incomplete\n");
382*12967Sgavin.maltby@oracle.com }
383*12967Sgavin.maltby@oracle.com }
384*12967Sgavin.maltby@oracle.com printf("%s", local_buffer);
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate fp = nextfp;
3870Sstevel@tonic-gate minfp = fp;
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate if (!panicstr) {
3910Sstevel@tonic-gate printf("end of traceback\n");
3920Sstevel@tonic-gate DELAY(2 * MICROSEC);
393*12967Sgavin.maltby@oracle.com } else if (dump_stack_scratch) {
394*12967Sgavin.maltby@oracle.com dump_stack_scratch[offset] = '\0';
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate * Generate a stack backtrace from a saved register set.
4000Sstevel@tonic-gate */
4010Sstevel@tonic-gate void
traceregs(struct regs * rp)4020Sstevel@tonic-gate traceregs(struct regs *rp)
4030Sstevel@tonic-gate {
4040Sstevel@tonic-gate traceback((caddr_t)rp->r_sp);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate void
exec_set_sp(size_t stksize)4080Sstevel@tonic-gate exec_set_sp(size_t stksize)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread);
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate lwp->lwp_pcb.pcb_xregstat = XREGNONE;
4130Sstevel@tonic-gate if (curproc->p_model == DATAMODEL_NATIVE)
4140Sstevel@tonic-gate stksize += sizeof (struct rwindow) + STACK_BIAS;
4150Sstevel@tonic-gate else
4160Sstevel@tonic-gate stksize += sizeof (struct rwindow32);
4170Sstevel@tonic-gate lwptoregs(lwp)->r_sp = (uintptr_t)curproc->p_usrstack - stksize;
4180Sstevel@tonic-gate }
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate /*
4210Sstevel@tonic-gate * Allocate a region of virtual address space, unmapped.
4220Sstevel@tonic-gate *
4230Sstevel@tonic-gate * When a hard-redzone (firewall) is in effect, redzone violations are
4240Sstevel@tonic-gate * caught by the hardware the instant they happen because the first byte
4250Sstevel@tonic-gate * past the logical end of a firewalled buffer lies at the start of an
4260Sstevel@tonic-gate * unmapped page. This firewalling is accomplished by bumping up the
4270Sstevel@tonic-gate * requested address allocation, effectively removing an additional page
4280Sstevel@tonic-gate * beyond the original request from the available virtual memory arena.
4290Sstevel@tonic-gate * However, the size of the allocation passed to boot, in boot_alloc(),
4300Sstevel@tonic-gate * doesn't reflect this additional page and fragmentation of the OBP
4310Sstevel@tonic-gate * "virtual-memory" "available" lists property occurs. Calling
4320Sstevel@tonic-gate * prom_claim_virt() for the firewall page avoids this fragmentation.
4330Sstevel@tonic-gate */
4340Sstevel@tonic-gate void *
boot_virt_alloc(void * addr,size_t size)4350Sstevel@tonic-gate boot_virt_alloc(void *addr, size_t size)
4360Sstevel@tonic-gate {
4375648Ssetje return (BOP_ALLOC_VIRT((caddr_t)addr, size));
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /*ARGSUSED*/
4420Sstevel@tonic-gate int
xcopyin_nta(const void * uaddr,void * kaddr,size_t count,int dummy)4430Sstevel@tonic-gate xcopyin_nta(const void *uaddr, void *kaddr, size_t count, int dummy)
4440Sstevel@tonic-gate {
4450Sstevel@tonic-gate return (xcopyin(uaddr, kaddr, count));
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate /*ARGSUSED*/
4480Sstevel@tonic-gate int
xcopyout_nta(const void * kaddr,void * uaddr,size_t count,int dummy)4490Sstevel@tonic-gate xcopyout_nta(const void *kaddr, void *uaddr, size_t count, int dummy)
4500Sstevel@tonic-gate {
4510Sstevel@tonic-gate return (xcopyout(kaddr, uaddr, count));
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate /*ARGSUSED*/
4540Sstevel@tonic-gate int
kcopy_nta(const void * from,void * to,size_t count,int dummy)4550Sstevel@tonic-gate kcopy_nta(const void *from, void *to, size_t count, int dummy)
4560Sstevel@tonic-gate {
4570Sstevel@tonic-gate return (kcopy(from, to, count));
4580Sstevel@tonic-gate }
459