xref: /openbsd-src/sys/arch/mips64/include/trap.h (revision 99c437516b4902ed2464a9e29e4bfbab7c115116)
1*99c43751Svisa /*	$OpenBSD: trap.h,v 1.17 2022/01/28 16:20:09 visa Exp $	*/
2f58c7388Spefo 
3f58c7388Spefo /*
4f58c7388Spefo  * Copyright (c) 1988 University of Utah.
5f58c7388Spefo  * Copyright (c) 1992, 1993
6f58c7388Spefo  *	The Regents of the University of California.  All rights reserved.
7f58c7388Spefo  *
8f58c7388Spefo  * This code is derived from software contributed to Berkeley by
9f58c7388Spefo  * the Systems Programming Group of the University of Utah Computer
10f58c7388Spefo  * Science Department and Ralph Campbell.
11f58c7388Spefo  *
12f58c7388Spefo  * Redistribution and use in source and binary forms, with or without
13f58c7388Spefo  * modification, are permitted provided that the following conditions
14f58c7388Spefo  * are met:
15f58c7388Spefo  * 1. Redistributions of source code must retain the above copyright
16f58c7388Spefo  *    notice, this list of conditions and the following disclaimer.
17f58c7388Spefo  * 2. Redistributions in binary form must reproduce the above copyright
18f58c7388Spefo  *    notice, this list of conditions and the following disclaimer in the
19f58c7388Spefo  *    documentation and/or other materials provided with the distribution.
2053aa784aSmiod  * 3. Neither the name of the University nor the names of its contributors
21f58c7388Spefo  *    may be used to endorse or promote products derived from this software
22f58c7388Spefo  *    without specific prior written permission.
23f58c7388Spefo  *
24f58c7388Spefo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25f58c7388Spefo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26f58c7388Spefo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27f58c7388Spefo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28f58c7388Spefo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29f58c7388Spefo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30f58c7388Spefo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31f58c7388Spefo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32f58c7388Spefo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33f58c7388Spefo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34f58c7388Spefo  * SUCH DAMAGE.
35f58c7388Spefo  *
36f58c7388Spefo  *	from: Utah Hdr: trap.h 1.1 90/07/09
37f58c7388Spefo  *	from: @(#)trap.h	8.1 (Berkeley) 6/10/93
38f58c7388Spefo  */
39f58c7388Spefo 
402fa72412Spirofti #ifndef _MIPS64_TRAP_H_
412fa72412Spirofti #define _MIPS64_TRAP_H_
42f58c7388Spefo 
43f58c7388Spefo /*
44130f2570Smiod  * Trap codes (ExcCode in the cause register); also known in trap.c for
45130f2570Smiod  * name strings.
46f58c7388Spefo  */
47f58c7388Spefo 
48f58c7388Spefo #define T_INT			0	/* Interrupt pending */
49f58c7388Spefo #define T_TLB_MOD		1	/* TLB modified fault */
50f58c7388Spefo #define T_TLB_LD_MISS		2	/* TLB miss on load or ifetch */
51f58c7388Spefo #define T_TLB_ST_MISS		3	/* TLB miss on a store */
52f58c7388Spefo #define T_ADDR_ERR_LD		4	/* Address error on a load or ifetch */
53f58c7388Spefo #define T_ADDR_ERR_ST		5	/* Address error on a store */
54f58c7388Spefo #define T_BUS_ERR_IFETCH	6	/* Bus error on an ifetch */
55f58c7388Spefo #define T_BUS_ERR_LD_ST		7	/* Bus error on a load or store */
56f58c7388Spefo #define T_SYSCALL		8	/* System call */
57f58c7388Spefo #define T_BREAK			9	/* Breakpoint */
58f58c7388Spefo #define T_RES_INST		10	/* Reserved instruction exception */
59f58c7388Spefo #define T_COP_UNUSABLE		11	/* Coprocessor unusable */
60f58c7388Spefo #define T_OVFLOW		12	/* Arithmetic overflow */
61f58c7388Spefo #define	T_TRAP			13	/* Trap instruction */
62130f2570Smiod #define	T_VCEI			14	/* R4k Virtual coherency instruction */
63f58c7388Spefo #define	T_FPE			15	/* Floating point exception */
64130f2570Smiod #define	T_IWATCH		16	/* R4k Inst. Watch address reference */
65130f2570Smiod #define	T_C2E			18	/* R5k Coprocessor 2 exception */
66130f2570Smiod #define	T_MDMX			22	/* R5k MDMX unusable */
67f58c7388Spefo #define	T_DWATCH		23	/* Data Watch address reference */
68130f2570Smiod #define	T_MCHECK		24	/* Machine check */
69130f2570Smiod #define	T_CACHEERR		30	/* Cache error */
70130f2570Smiod #define T_VCED			31	/* R4k Virtual coherency data */
71f58c7388Spefo 
72f58c7388Spefo #define	T_USER			0x20	/* user-mode flag or'ed with type */
73f58c7388Spefo 
74f58c7388Spefo /*
755060888dSmiod  *  Defines for trap handler catching kernel accessing memory.
76f58c7388Spefo  */
777025e1b2Smiod #define	KT_COPYERR	1		/* User space copy error */
787025e1b2Smiod #define	KT_KCOPYERR	2		/* Kernel space copy error */
797025e1b2Smiod #define	KT_DDBERR	3		/* DDB access error */
80f58c7388Spefo 
81f58c7388Spefo #ifndef _LOCORE
82f58c7388Spefo 
83f58c7388Spefo #if defined(DDB) || defined(DEBUG)
84f58c7388Spefo 
85f58c7388Spefo struct trapdebug {			/* trap history buffer for debugging */
86a6ba7b46Smiod 	register_t status;
87a6ba7b46Smiod 	register_t cause;
882f072529Smiod 	register_t vadr;
892f072529Smiod 	register_t pc;
902f072529Smiod 	register_t ra;
912f072529Smiod 	register_t sp;
92f58c7388Spefo 	u_int	code;
9391b9a95cSmiod 	u_int	ipl;
94f58c7388Spefo };
95f58c7388Spefo 
962f072529Smiod #define	trapdebug_enter(ci, frame, cd)					\
972f072529Smiod do {									\
98a6ba7b46Smiod 	register_t sr = disableintr();					\
992f072529Smiod 	u_long cpuid = ci->ci_cpuid;					\
1002f072529Smiod 	struct trapdebug *t;						\
1012f072529Smiod 									\
1022f072529Smiod 	t = trapdebug + TRAPSIZE * cpuid + trppos[cpuid];		\
1032f072529Smiod 	t->status = frame->sr;						\
1042f072529Smiod 	t->cause = frame->cause;					\
1052f072529Smiod 	t->vadr = frame->badvaddr;					\
1062f072529Smiod 	t->pc = frame->pc;						\
1072f072529Smiod 	t->sp = frame->sp;						\
1082f072529Smiod 	t->ra = frame->ra;						\
1092f072529Smiod 	t->ipl = frame->ipl;						\
1102f072529Smiod 	t->code = cd;							\
1112f072529Smiod 	if (++trppos[cpuid] == TRAPSIZE)				\
1122f072529Smiod 		trppos[cpuid] = 0;					\
1132f072529Smiod 	setsr(sr);							\
1142f072529Smiod } while (0)
115f58c7388Spefo 
116f58c7388Spefo #define TRAPSIZE 10		/* Trap log buffer length */
1172f072529Smiod extern struct trapdebug trapdebug[MAXCPUS * TRAPSIZE];
1182f072529Smiod extern uint trppos[MAXCPUS];
119f58c7388Spefo 
120e4dd4815Smiod void trapDump(const char *, int (*)(const char *, ...));
121f58c7388Spefo 
122f58c7388Spefo #else
1232f072529Smiod #define	trapdebug_enter(ci, frame, code)
124f58c7388Spefo #endif
125f58c7388Spefo #endif /* _LOCORE */
126f58c7388Spefo 
1272fa72412Spirofti #endif /* !_MIPS64_TRAP_H_ */
128