xref: /nrf52832-nimble/rt-thread/libcpu/mips/common/exception.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * File      : cpu.c
3  * This file is part of RT-Thread RTOS
4  * COPYRIGHT (C) 2010, RT-Thread Development Team
5  *
6  * The license and distribution terms for this file may be
7  * found in the file LICENSE in this distribution or at
8  * http://www.rt-thread.org/license/LICENSE
9  *
10  * Change Logs:
11  * Date           Author       Notes
12  * 2010-05-17     swkyer       first version
13  */
14 #ifndef __EXCEPTION_H__
15 #define __EXCEPTION_H__
16 
17 
18 /*
19  * important register numbers
20  */
21 #define REG_EPC				37
22 #define REG_FP				72
23 #define REG_SP				29
24 
25 /*
26  * Stack layout for the GDB exception handler
27  * Derived from the stack layout described in asm-mips/stackframe.h
28  *
29  * The first PTRSIZE*6 bytes are argument save space for C subroutines.
30  */
31 #define NUMREGS				90
32 
33 #define GDB_FR_REG0			(PTRSIZE*6)			/* 0 */
34 #define GDB_FR_REG1			((GDB_FR_REG0) + LONGSIZE)	/* 1 */
35 #define GDB_FR_REG2			((GDB_FR_REG1) + LONGSIZE)	/* 2 */
36 #define GDB_FR_REG3			((GDB_FR_REG2) + LONGSIZE)	/* 3 */
37 #define GDB_FR_REG4			((GDB_FR_REG3) + LONGSIZE)	/* 4 */
38 #define GDB_FR_REG5			((GDB_FR_REG4) + LONGSIZE)	/* 5 */
39 #define GDB_FR_REG6			((GDB_FR_REG5) + LONGSIZE)	/* 6 */
40 #define GDB_FR_REG7			((GDB_FR_REG6) + LONGSIZE)	/* 7 */
41 #define GDB_FR_REG8			((GDB_FR_REG7) + LONGSIZE)	/* 8 */
42 #define GDB_FR_REG9	        ((GDB_FR_REG8) + LONGSIZE)	/* 9 */
43 #define GDB_FR_REG10		((GDB_FR_REG9) + LONGSIZE)	/* 10 */
44 #define GDB_FR_REG11		((GDB_FR_REG10) + LONGSIZE)	/* 11 */
45 #define GDB_FR_REG12		((GDB_FR_REG11) + LONGSIZE)	/* 12 */
46 #define GDB_FR_REG13		((GDB_FR_REG12) + LONGSIZE)	/* 13 */
47 #define GDB_FR_REG14		((GDB_FR_REG13) + LONGSIZE)	/* 14 */
48 #define GDB_FR_REG15		((GDB_FR_REG14) + LONGSIZE)	/* 15 */
49 #define GDB_FR_REG16		((GDB_FR_REG15) + LONGSIZE)	/* 16 */
50 #define GDB_FR_REG17		((GDB_FR_REG16) + LONGSIZE)	/* 17 */
51 #define GDB_FR_REG18		((GDB_FR_REG17) + LONGSIZE)	/* 18 */
52 #define GDB_FR_REG19		((GDB_FR_REG18) + LONGSIZE)	/* 19 */
53 #define GDB_FR_REG20		((GDB_FR_REG19) + LONGSIZE)	/* 20 */
54 #define GDB_FR_REG21		((GDB_FR_REG20) + LONGSIZE)	/* 21 */
55 #define GDB_FR_REG22		((GDB_FR_REG21) + LONGSIZE)	/* 22 */
56 #define GDB_FR_REG23		((GDB_FR_REG22) + LONGSIZE)	/* 23 */
57 #define GDB_FR_REG24		((GDB_FR_REG23) + LONGSIZE)	/* 24 */
58 #define GDB_FR_REG25		((GDB_FR_REG24) + LONGSIZE)	/* 25 */
59 #define GDB_FR_REG26		((GDB_FR_REG25) + LONGSIZE)	/* 26 */
60 #define GDB_FR_REG27		((GDB_FR_REG26) + LONGSIZE)	/* 27 */
61 #define GDB_FR_REG28		((GDB_FR_REG27) + LONGSIZE)	/* 28 */
62 #define GDB_FR_REG29		((GDB_FR_REG28) + LONGSIZE)	/* 29 */
63 #define GDB_FR_REG30		((GDB_FR_REG29) + LONGSIZE)	/* 30 */
64 #define GDB_FR_REG31		((GDB_FR_REG30) + LONGSIZE)	/* 31 */
65 
66 /*
67  * Saved special registers
68  */
69 #define GDB_FR_STATUS		((GDB_FR_REG31) + LONGSIZE)	/* 32 */
70 #define GDB_FR_LO			((GDB_FR_STATUS) + LONGSIZE)	/* 33 */
71 #define GDB_FR_HI			((GDB_FR_LO) + LONGSIZE)	/* 34 */
72 #define GDB_FR_BADVADDR		((GDB_FR_HI) + LONGSIZE)	/* 35 */
73 #define GDB_FR_CAUSE		((GDB_FR_BADVADDR) + LONGSIZE)	/* 36 */
74 #define GDB_FR_EPC			((GDB_FR_CAUSE) + LONGSIZE)	/* 37 */
75 
76 ///*
77 // * Saved floating point registers
78 // */
79 //#define GDB_FR_FPR0		((GDB_FR_EPC) + LONGSIZE)	/* 38 */
80 //#define GDB_FR_FPR1		((GDB_FR_FPR0) + LONGSIZE)	/* 39 */
81 //#define GDB_FR_FPR2		((GDB_FR_FPR1) + LONGSIZE)	/* 40 */
82 //#define GDB_FR_FPR3		((GDB_FR_FPR2) + LONGSIZE)	/* 41 */
83 //#define GDB_FR_FPR4		((GDB_FR_FPR3) + LONGSIZE)	/* 42 */
84 //#define GDB_FR_FPR5		((GDB_FR_FPR4) + LONGSIZE)	/* 43 */
85 //#define GDB_FR_FPR6		((GDB_FR_FPR5) + LONGSIZE)	/* 44 */
86 //#define GDB_FR_FPR7		((GDB_FR_FPR6) + LONGSIZE)	/* 45 */
87 //#define GDB_FR_FPR8		((GDB_FR_FPR7) + LONGSIZE)	/* 46 */
88 //#define GDB_FR_FPR9		((GDB_FR_FPR8) + LONGSIZE)	/* 47 */
89 //#define GDB_FR_FPR10		((GDB_FR_FPR9) + LONGSIZE)	/* 48 */
90 //#define GDB_FR_FPR11		((GDB_FR_FPR10) + LONGSIZE)	/* 49 */
91 //#define GDB_FR_FPR12		((GDB_FR_FPR11) + LONGSIZE)	/* 50 */
92 //#define GDB_FR_FPR13		((GDB_FR_FPR12) + LONGSIZE)	/* 51 */
93 //#define GDB_FR_FPR14		((GDB_FR_FPR13) + LONGSIZE)	/* 52 */
94 //#define GDB_FR_FPR15		((GDB_FR_FPR14) + LONGSIZE)	/* 53 */
95 //#define GDB_FR_FPR16		((GDB_FR_FPR15) + LONGSIZE)	/* 54 */
96 //#define GDB_FR_FPR17		((GDB_FR_FPR16) + LONGSIZE)	/* 55 */
97 //#define GDB_FR_FPR18		((GDB_FR_FPR17) + LONGSIZE)	/* 56 */
98 //#define GDB_FR_FPR19		((GDB_FR_FPR18) + LONGSIZE)	/* 57 */
99 //#define GDB_FR_FPR20		((GDB_FR_FPR19) + LONGSIZE)	/* 58 */
100 //#define GDB_FR_FPR21		((GDB_FR_FPR20) + LONGSIZE)	/* 59 */
101 //#define GDB_FR_FPR22		((GDB_FR_FPR21) + LONGSIZE)	/* 60 */
102 //#define GDB_FR_FPR23		((GDB_FR_FPR22) + LONGSIZE)	/* 61 */
103 //#define GDB_FR_FPR24		((GDB_FR_FPR23) + LONGSIZE)	/* 62 */
104 //#define GDB_FR_FPR25		((GDB_FR_FPR24) + LONGSIZE)	/* 63 */
105 //#define GDB_FR_FPR26		((GDB_FR_FPR25) + LONGSIZE)	/* 64 */
106 //#define GDB_FR_FPR27		((GDB_FR_FPR26) + LONGSIZE)	/* 65 */
107 //#define GDB_FR_FPR28		((GDB_FR_FPR27) + LONGSIZE)	/* 66 */
108 //#define GDB_FR_FPR29		((GDB_FR_FPR28) + LONGSIZE)	/* 67 */
109 //#define GDB_FR_FPR30		((GDB_FR_FPR29) + LONGSIZE)	/* 68 */
110 //#define GDB_FR_FPR31		((GDB_FR_FPR30) + LONGSIZE)	/* 69 */
111 //
112 //#define GDB_FR_FSR		((GDB_FR_FPR31) + LONGSIZE)	/* 70 */
113 //#define GDB_FR_FIR		((GDB_FR_FSR) + LONGSIZE)	/* 71 */
114 //#define GDB_FR_FRP		((GDB_FR_FIR) + LONGSIZE)	/* 72 */
115 //
116 //#define GDB_FR_DUMMY		((GDB_FR_FRP) + LONGSIZE)	/* 73, unused ??? */
117 //
118 ///*
119 // * Again, CP0 registers
120 // */
121 //#define GDB_FR_CP0_INDEX	((GDB_FR_DUMMY) + LONGSIZE)	/* 74 */
122 #define GDB_FR_FRP			((GDB_FR_EPC) + LONGSIZE)	/* 72 */
123 #define GDB_FR_CP0_INDEX	((GDB_FR_FRP) + LONGSIZE)	/* 74 */
124 
125 #define GDB_FR_CP0_RANDOM	((GDB_FR_CP0_INDEX) + LONGSIZE)	/* 75 */
126 #define GDB_FR_CP0_ENTRYLO0	((GDB_FR_CP0_RANDOM) + LONGSIZE)/* 76 */
127 #define GDB_FR_CP0_ENTRYLO1	((GDB_FR_CP0_ENTRYLO0) + LONGSIZE)/* 77 */
128 #define GDB_FR_CP0_CONTEXT	((GDB_FR_CP0_ENTRYLO1) + LONGSIZE)/* 78 */
129 #define GDB_FR_CP0_PAGEMASK	((GDB_FR_CP0_CONTEXT) + LONGSIZE)/* 79 */
130 #define GDB_FR_CP0_WIRED	((GDB_FR_CP0_PAGEMASK) + LONGSIZE)/* 80 */
131 #define GDB_FR_CP0_REG7		((GDB_FR_CP0_WIRED) + LONGSIZE)	/* 81 */
132 #define GDB_FR_CP0_REG8		((GDB_FR_CP0_REG7) + LONGSIZE)	/* 82 */
133 #define GDB_FR_CP0_REG9		((GDB_FR_CP0_REG8) + LONGSIZE)	/* 83 */
134 #define GDB_FR_CP0_ENTRYHI	((GDB_FR_CP0_REG9) + LONGSIZE)	/* 84 */
135 #define GDB_FR_CP0_REG11	((GDB_FR_CP0_ENTRYHI) + LONGSIZE)/* 85 */
136 #define GDB_FR_CP0_REG12	((GDB_FR_CP0_REG11) + LONGSIZE)	/* 86 */
137 #define GDB_FR_CP0_REG13	((GDB_FR_CP0_REG12) + LONGSIZE)	/* 87 */
138 #define GDB_FR_CP0_REG14	((GDB_FR_CP0_REG13) + LONGSIZE)	/* 88 */
139 #define GDB_FR_CP0_PRID		((GDB_FR_CP0_REG14) + LONGSIZE)	/* 89 */
140 
141 #define GDB_FR_SIZE			((((GDB_FR_CP0_PRID) + LONGSIZE) + (PTRSIZE-1)) & ~(PTRSIZE-1))
142 
143 /*
144  * This is the same as above, but for the high-level
145  * part of the INT stub.
146  */
147 typedef struct pt_regs_s
148 {
149 	/* Saved main processor registers. */
150 	rt_base_t regs[32];
151 	/* Saved special registers. */
152 	rt_base_t cp0_status;
153 	rt_base_t hi;
154 	rt_base_t lo;
155 	rt_base_t cp0_badvaddr;
156 	rt_base_t cp0_cause;
157 	rt_base_t cp0_epc;
158 } pt_regs_t;
159 
160 typedef void (* exception_func_t)(pt_regs_t *regs);
161 
162 extern exception_func_t sys_exception_handlers[];
163 exception_func_t rt_set_except_vector(int n, exception_func_t func);
164 void install_default_execpt_handle(void);
165 
166 #endif /* end of __EXCEPTION_H__ */
167