17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5843e198johnlev * Common Development and Distribution License (the "License").
6843e198johnlev * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
22f6e214cGavin Maltby * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
233f11de9Sara Hartse * Copyright (c) 2016 by Delphix. All rights reserved.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate#ifndef	_SYS_PANIC_H
277c478bdstevel@tonic-gate#define	_SYS_PANIC_H
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#if !defined(_ASM)
307c478bdstevel@tonic-gate#include <sys/types.h>
317c478bdstevel@tonic-gate#include <sys/thread.h>
327c478bdstevel@tonic-gate#include <sys/cpuvar.h>
337c478bdstevel@tonic-gate#endif	/* !_ASM */
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#ifdef	__cplusplus
367c478bdstevel@tonic-gateextern "C" {
377c478bdstevel@tonic-gate#endif
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gate#ifdef _LP64
407c478bdstevel@tonic-gate#define	PANICSTKSIZE	16384
417c478bdstevel@tonic-gate#else
427c478bdstevel@tonic-gate#define	PANICSTKSIZE	8192
437c478bdstevel@tonic-gate#endif
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gate#define	PANICBUFSIZE	8192
46f6e214cGavin Maltby#define	PANICBUFVERS	2
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate#define	PANICNVNAMELEN	16
497c478bdstevel@tonic-gate
50f6e214cGavin Maltby#define	STACK_BUF_SIZE	2048
51f6e214cGavin Maltby#define	SUMMARY_MAGIC	0xdead0d8a
52f6e214cGavin Maltby
537c478bdstevel@tonic-gate/*
547c478bdstevel@tonic-gate * Panicbuf Format:
557c478bdstevel@tonic-gate *
567c478bdstevel@tonic-gate * The kernel records the formatted panic message and an optional array of
577c478bdstevel@tonic-gate * name/value pairs into panicbuf[], a fixed-size buffer which is saved in
587c478bdstevel@tonic-gate * the crash dump and, on some platforms, is persistent across reboots.
597c478bdstevel@tonic-gate * The initial part of the buffer is a struct of type panic_data_t, which
607c478bdstevel@tonic-gate * includes a version number for identifying the format of subsequent data.
617c478bdstevel@tonic-gate *
627c478bdstevel@tonic-gate * The pd_msgoff word identifies the byte offset into panicbuf[] at which the
637c478bdstevel@tonic-gate * null-terminated panic message is located.  This is followed by an optional
647c478bdstevel@tonic-gate * variable-sized array of panic_nv_t items, which are used to record CPU
657c478bdstevel@tonic-gate * register values.  The number of items in pd_nvdata is computed as follows:
667c478bdstevel@tonic-gate *
677c478bdstevel@tonic-gate * (pd_msgoff - (sizeof (panic_data_t) - sizeof (panic_nv_t))) /
687c478bdstevel@tonic-gate * 	sizeof (panic_nv_t);
697c478bdstevel@tonic-gate *
707c478bdstevel@tonic-gate * In addition to panicbuf, debuggers can access the panic_* variables shown
717c478bdstevel@tonic-gate * below to determine more information about the initiator of the panic.
727c478bdstevel@tonic-gate */
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate#if !defined(_ASM)
757c478bdstevel@tonic-gate
767c478bdstevel@tonic-gatetypedef struct panic_nv {
777c478bdstevel@tonic-gate	char pnv_name[PANICNVNAMELEN];	/* String name */
787c478bdstevel@tonic-gate	uint64_t pnv_value;		/* Value */
797c478bdstevel@tonic-gate} panic_nv_t;
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gatetypedef struct panic_data {
827c478bdstevel@tonic-gate	uint32_t pd_version;		/* Version number of panic_data_t */
837c478bdstevel@tonic-gate	uint32_t pd_msgoff;		/* Message byte offset in panicbuf */
84f6e214cGavin Maltby	char pd_uuid[36 + 1];		/* image uuid */
857c478bdstevel@tonic-gate	panic_nv_t pd_nvdata[1];	/* Array of named data */
867c478bdstevel@tonic-gate} panic_data_t;
877c478bdstevel@tonic-gate
88f6e214cGavin Maltbytypedef struct summary_dump {
89f6e214cGavin Maltby	uint32_t sd_magic;		/* magic number */
90f6e214cGavin Maltby	uint32_t sd_ssum;		/* checsksum32(stack buffer) */
91f6e214cGavin Maltby	/*
92f6e214cGavin Maltby	 * stack buffer and other summary data follow here -- see
93f6e214cGavin Maltby	 * dump_summary()
94f6e214cGavin Maltby	 */
95f6e214cGavin Maltby} summary_dump_t;
96f6e214cGavin Maltby
977c478bdstevel@tonic-gate#if defined(_KERNEL)
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate/*
1007c478bdstevel@tonic-gate * Kernel macros for adding information to pd_nvdata[].  PANICNVGET() returns
1017c478bdstevel@tonic-gate * a panic_nv_t pointer (pnv) after the end of the existing data, PANICNVADD()
1027c478bdstevel@tonic-gate * modifies the current item and increments pnv, and PANICNVSET() rewrites
1037c478bdstevel@tonic-gate * pd_msgoff to indicate the end of pd_nvdata[].
1047c478bdstevel@tonic-gate */
1057c478bdstevel@tonic-gate#define	PANICNVGET(pdp)							\
1067c478bdstevel@tonic-gate	((pdp)->pd_nvdata + (((pdp)->pd_msgoff -			\
1077c478bdstevel@tonic-gate	(sizeof (panic_data_t) - sizeof (panic_nv_t))) / sizeof (panic_nv_t)))
1087c478bdstevel@tonic-gate
1097c478bdstevel@tonic-gate#define	PANICNVADD(pnv, n, v)						\
1107c478bdstevel@tonic-gate	{								\
1117c478bdstevel@tonic-gate		(void) strncpy((pnv)->pnv_name, (n), PANICNVNAMELEN);	\
1127c478bdstevel@tonic-gate		(pnv)->pnv_value = (uint64_t)(v); (pnv)++;		\
1137c478bdstevel@tonic-gate	}
1147c478bdstevel@tonic-gate
1157c478bdstevel@tonic-gate#define	PANICNVSET(pdp, pnv) \
1167c478bdstevel@tonic-gate	(pdp)->pd_msgoff = (uint32_t)((char *)(pnv) - (char *)(pdp));
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate/*
1197c478bdstevel@tonic-gate * Kernel panic data; preserved in crash dump for debuggers.
1207c478bdstevel@tonic-gate */
1217c478bdstevel@tonic-gate#pragma align 8(panicbuf)
1227c478bdstevel@tonic-gateextern char panicbuf[PANICBUFSIZE];
1237c478bdstevel@tonic-gateextern kthread_t *panic_thread;
1247c478bdstevel@tonic-gateextern cpu_t panic_cpu;
1257c478bdstevel@tonic-gateextern hrtime_t panic_hrtime;
1267c478bdstevel@tonic-gateextern timespec_t panic_hrestime;
1277c478bdstevel@tonic-gate
1287c478bdstevel@tonic-gate/*
129843e198johnlev * Forward declarations for types:
130843e198johnlev */
131843e198johnlevstruct panic_trap_info;
132843e198johnlevstruct regs;
133843e198johnlev
134843e198johnlev/*
1357c478bdstevel@tonic-gate * Miscellaneous state variables defined in or used by the panic code:
1367c478bdstevel@tonic-gate */
1377c478bdstevel@tonic-gateextern char *panic_bootstr;
1387c478bdstevel@tonic-gateextern int panic_bootfcn;
1397c478bdstevel@tonic-gateextern int panic_forced;
1407c478bdstevel@tonic-gateextern int halt_on_panic;
1417c478bdstevel@tonic-gateextern int nopanicdebug;
1427c478bdstevel@tonic-gateextern int do_polled_io;
1437c478bdstevel@tonic-gateextern int obpdebug;
1447c478bdstevel@tonic-gateextern int in_sync;
1457c478bdstevel@tonic-gateextern int panic_quiesce;
1467c478bdstevel@tonic-gateextern int panic_dump;
147843e198johnlevextern int64_t panic_lbolt64;
148843e198johnlevextern label_t panic_regs;
149843e198johnlevextern struct regs *panic_reg;
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gate/*
1527c478bdstevel@tonic-gate * Panic functions called from the common panic code which must be
1537c478bdstevel@tonic-gate * implemented by architecture or platform-specific code:
1547c478bdstevel@tonic-gate */
1557c478bdstevel@tonic-gateextern void panic_saveregs(panic_data_t *, struct regs *);
156843e198johnlevextern void panic_savetrap(panic_data_t *, struct panic_trap_info *);
157843e198johnlevextern void panic_showtrap(struct panic_trap_info *);
1587c478bdstevel@tonic-gateextern void panic_stopcpus(cpu_t *, kthread_t *, int);
1597c478bdstevel@tonic-gateextern void panic_enter_hw(int);
1607c478bdstevel@tonic-gateextern void panic_quiesce_hw(panic_data_t *);
1617c478bdstevel@tonic-gateextern void panic_dump_hw(int);
1627c478bdstevel@tonic-gateextern int panic_trigger(int *);
1637c478bdstevel@tonic-gate
1647c478bdstevel@tonic-gate#endif /* _KERNEL */
1657c478bdstevel@tonic-gate#endif /* !_ASM */
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gate#ifdef	__cplusplus
1687c478bdstevel@tonic-gate}
1697c478bdstevel@tonic-gate#endif
1707c478bdstevel@tonic-gate
1717c478bdstevel@tonic-gate#endif	/* _SYS_PANIC_H */
172