1178172Simp/*	$OpenBSD: trap.h,v 1.3 1999/01/27 04:46:06 imp Exp $	*/
2178172Simp
3178172Simp/*-
4178172Simp * Copyright (c) 1988 University of Utah.
5178172Simp * Copyright (c) 1992, 1993
6178172Simp *	The Regents of the University of California.  All rights reserved.
7178172Simp *
8178172Simp * This code is derived from software contributed to Berkeley by
9178172Simp * the Systems Programming Group of the University of Utah Computer
10178172Simp * Science Department and Ralph Campbell.
11178172Simp *
12178172Simp * Redistribution and use in source and binary forms, with or without
13178172Simp * modification, are permitted provided that the following conditions
14178172Simp * are met:
15178172Simp * 1. Redistributions of source code must retain the above copyright
16178172Simp *    notice, this list of conditions and the following disclaimer.
17178172Simp * 2. Redistributions in binary form must reproduce the above copyright
18178172Simp *    notice, this list of conditions and the following disclaimer in the
19178172Simp *    documentation and/or other materials provided with the distribution.
20178172Simp * 4. Neither the name of the University nor the names of its contributors
21178172Simp *    may be used to endorse or promote products derived from this software
22178172Simp *    without specific prior written permission.
23178172Simp *
24178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34178172Simp * SUCH DAMAGE.
35178172Simp *
36178172Simp *	from: Utah Hdr: trap.h 1.1 90/07/09
37178172Simp *	from: @(#)trap.h	8.1 (Berkeley) 6/10/93
38178172Simp *	JNPR: trap.h,v 1.3 2006/12/02 09:53:41 katta
39178172Simp * $FreeBSD$
40178172Simp */
41178172Simp
42178172Simp#ifndef _MACHINE_TRAP_H_
43178172Simp#define	_MACHINE_TRAP_H_
44178172Simp
45178172Simp/*
46178172Simp * Trap codes also known in trap.c for name strings.
47178172Simp * Used for indexing so modify with care.
48178172Simp */
49178172Simp
50178172Simp#define	T_INT			0	/* Interrupt pending */
51178172Simp#define	T_TLB_MOD		1	/* TLB modified fault */
52178172Simp#define	T_TLB_LD_MISS		2	/* TLB miss on load or ifetch */
53178172Simp#define	T_TLB_ST_MISS		3	/* TLB miss on a store */
54178172Simp#define	T_ADDR_ERR_LD		4	/* Address error on a load or ifetch */
55178172Simp#define	T_ADDR_ERR_ST		5	/* Address error on a store */
56178172Simp#define	T_BUS_ERR_IFETCH	6	/* Bus error on an ifetch */
57178172Simp#define	T_BUS_ERR_LD_ST		7	/* Bus error on a load or store */
58178172Simp#define	T_SYSCALL		8	/* System call */
59178172Simp#define	T_BREAK			9	/* Breakpoint */
60178172Simp#define	T_RES_INST		10	/* Reserved instruction exception */
61178172Simp#define	T_COP_UNUSABLE		11	/* Coprocessor unusable */
62178172Simp#define	T_OVFLOW		12	/* Arithmetic overflow */
63178172Simp#define	T_TRAP			13	/* Trap instruction */
64178172Simp#define	T_VCEI			14	/* Virtual coherency instruction */
65178172Simp#define	T_FPE			15	/* Floating point exception */
66178172Simp#define	T_IWATCH		16	/* Inst. Watch address reference */
67178172Simp#define T_C2E                   18      /* Exception from coprocessor 2 */
68178172Simp#define	T_DWATCH		23	/* Data Watch address reference */
69178172Simp#define T_MCHECK                24      /* Received an MCHECK */
70178172Simp#define	T_VCED			31	/* Virtual coherency data */
71178172Simp
72178172Simp#define	T_USER			0x20	/* user-mode flag or'ed with type */
73178172Simp
74178172Simp#if !defined(SMP) && (defined(DDB) || defined(DEBUG))
75178172Simp
76178172Simpstruct trapdebug {		/* trap history buffer for debugging */
77206717Sjmallett	register_t	status;
78206717Sjmallett	register_t	cause;
79206717Sjmallett	register_t	vadr;
80206717Sjmallett	register_t	pc;
81206717Sjmallett	register_t	ra;
82206717Sjmallett	register_t	sp;
83206717Sjmallett	register_t	code;
84178172Simp};
85178172Simp
86178172Simp#define	trapdebug_enter(x, cd) {	\
87206717Sjmallett	register_t s = intr_disable();	\
88178172Simp	trp->status = x->sr;		\
89178172Simp	trp->cause = x->cause;		\
90178172Simp	trp->vadr = x->badvaddr;	\
91178172Simp	trp->pc = x->pc;		\
92178172Simp	trp->sp = x->sp;		\
93178172Simp	trp->ra = x->ra;		\
94178172Simp	trp->code = cd;			\
95178172Simp	if (++trp == &trapdebug[TRAPSIZE])	\
96178172Simp		trp = trapdebug;	\
97206717Sjmallett	intr_restore(s);		\
98178172Simp}
99178172Simp
100178172Simp#define	TRAPSIZE 10		/* Trap log buffer length */
101178172Simpextern struct trapdebug trapdebug[TRAPSIZE], *trp;
102178172Simp
103178172Simpvoid trapDump(char *msg);
104178172Simp
105178172Simp#else
106178172Simp
107178172Simp#define	trapdebug_enter(x, cd)
108178172Simp
109178172Simp#endif
110178172Simp
111202031Simpvoid MipsFPTrap(u_int, u_int, u_int);
112202031Simpvoid MipsKernGenException(void);
113202031Simpvoid MipsKernIntr(void);
114205360Sneelvoid MipsTLBInvalidException(void);
115202031Simpvoid MipsTLBMissException(void);
116202031Simpvoid MipsUserGenException(void);
117202031Simpvoid MipsUserIntr(void);
118202031Simp
119206717Sjmallettregister_t trap(struct trapframe *);
120202031Simp
121178172Simp#endif /* !_MACHINE_TRAP_H_ */
122