trap.h revision 178172
1120878Sphk/*	$OpenBSD: trap.h,v 1.3 1999/01/27 04:46:06 imp Exp $	*/
2120878Sphk
3120878Sphk/*-
4120878Sphk * Copyright (c) 1988 University of Utah.
5120878Sphk * Copyright (c) 1992, 1993
6120878Sphk *	The Regents of the University of California.  All rights reserved.
7120878Sphk *
8120878Sphk * This code is derived from software contributed to Berkeley by
9120878Sphk * the Systems Programming Group of the University of Utah Computer
10120878Sphk * Science Department and Ralph Campbell.
11120878Sphk *
12120878Sphk * Redistribution and use in source and binary forms, with or without
13120878Sphk * modification, are permitted provided that the following conditions
14120878Sphk * are met:
15120878Sphk * 1. Redistributions of source code must retain the above copyright
16120878Sphk *    notice, this list of conditions and the following disclaimer.
17120878Sphk * 2. Redistributions in binary form must reproduce the above copyright
18120878Sphk *    notice, this list of conditions and the following disclaimer in the
19120878Sphk *    documentation and/or other materials provided with the distribution.
20120878Sphk * 4. Neither the name of the University nor the names of its contributors
21120878Sphk *    may be used to endorse or promote products derived from this software
22120878Sphk *    without specific prior written permission.
23120878Sphk *
24120878Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25120878Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26120878Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27120878Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28120878Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29120878Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30120878Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31120878Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32120878Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33120878Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34120878Sphk * SUCH DAMAGE.
35120878Sphk *
36120878Sphk *	from: Utah Hdr: trap.h 1.1 90/07/09
37120878Sphk *	from: @(#)trap.h	8.1 (Berkeley) 6/10/93
38120878Sphk *	JNPR: trap.h,v 1.3 2006/12/02 09:53:41 katta
39120878Sphk * $FreeBSD: head/sys/mips/include/trap.h 178172 2008-04-13 07:27:37Z imp $
40120878Sphk */
41120878Sphk
42120878Sphk#ifndef _MACHINE_TRAP_H_
43120878Sphk#define	_MACHINE_TRAP_H_
44120878Sphk
45120878Sphk/*
46120878Sphk * Trap codes also known in trap.c for name strings.
47120878Sphk * Used for indexing so modify with care.
48120878Sphk */
49120878Sphk
50120878Sphk#define	T_INT			0	/* Interrupt pending */
51120878Sphk#define	T_TLB_MOD		1	/* TLB modified fault */
52120878Sphk#define	T_TLB_LD_MISS		2	/* TLB miss on load or ifetch */
53120878Sphk#define	T_TLB_ST_MISS		3	/* TLB miss on a store */
54120878Sphk#define	T_ADDR_ERR_LD		4	/* Address error on a load or ifetch */
55120878Sphk#define	T_ADDR_ERR_ST		5	/* Address error on a store */
56120878Sphk#define	T_BUS_ERR_IFETCH	6	/* Bus error on an ifetch */
57120878Sphk#define	T_BUS_ERR_LD_ST		7	/* Bus error on a load or store */
58120878Sphk#define	T_SYSCALL		8	/* System call */
59120878Sphk#define	T_BREAK			9	/* Breakpoint */
60120878Sphk#define	T_RES_INST		10	/* Reserved instruction exception */
61120878Sphk#define	T_COP_UNUSABLE		11	/* Coprocessor unusable */
62120878Sphk#define	T_OVFLOW		12	/* Arithmetic overflow */
63120878Sphk#define	T_TRAP			13	/* Trap instruction */
64120878Sphk#define	T_VCEI			14	/* Virtual coherency instruction */
65120878Sphk#define	T_FPE			15	/* Floating point exception */
66120878Sphk#define	T_IWATCH		16	/* Inst. Watch address reference */
67120878Sphk#define T_C2E                   18      /* Exception from coprocessor 2 */
68120878Sphk#define	T_DWATCH		23	/* Data Watch address reference */
69120878Sphk#define T_MCHECK                24      /* Received an MCHECK */
70120878Sphk#define	T_VCED			31	/* Virtual coherency data */
71120878Sphk
72120878Sphk#define	T_USER			0x20	/* user-mode flag or'ed with type */
73120878Sphk
74120878Sphk#if !defined(SMP) && (defined(DDB) || defined(DEBUG))
75120878Sphk
76120878Sphkstruct trapdebug {		/* trap history buffer for debugging */
77120878Sphk	u_int	status;
78120878Sphk	u_int	cause;
79120878Sphk	u_int	vadr;
80120878Sphk	u_int	pc;
81120878Sphk	u_int	ra;
82120878Sphk	u_int	sp;
83120878Sphk	u_int	code;
84120878Sphk};
85120878Sphk
86120878Sphk#define	trapdebug_enter(x, cd) {	\
87120878Sphk	intrmask_t s = disableintr();	\
88120878Sphk	trp->status = x->sr;		\
89120878Sphk	trp->cause = x->cause;		\
90120878Sphk	trp->vadr = x->badvaddr;	\
91120878Sphk	trp->pc = x->pc;		\
92120878Sphk	trp->sp = x->sp;		\
93120878Sphk	trp->ra = x->ra;		\
94120878Sphk	trp->code = cd;			\
95120878Sphk	if (++trp == &trapdebug[TRAPSIZE])	\
96120878Sphk		trp = trapdebug;	\
97120878Sphk	restoreintr(s);			\
98120878Sphk}
99120878Sphk
100120878Sphk#define	TRAPSIZE 10		/* Trap log buffer length */
101120878Sphkextern struct trapdebug trapdebug[TRAPSIZE], *trp;
102120878Sphk
103120878Sphkvoid trapDump(char *msg);
104120878Sphk
105120878Sphk#else
106120878Sphk
107120878Sphk#define	trapdebug_enter(x, cd)
108120878Sphk
109120878Sphk#endif
110120878Sphk
111120878Sphk#ifndef LOCORE /* XXX */
112120878Sphkint check_address(void *);
113120878Sphkvoid platform_trap_enter(void);
114120878Sphkvoid platform_trap_exit(void);
115120878Sphk#endif
116120878Sphk
117120878Sphk#endif /* !_MACHINE_TRAP_H_ */
118120878Sphk