1 #ifndef __HEAD_BOOKE_H__
2 #define __HEAD_BOOKE_H__
5 * Macros used for common Book-e exception handling
8 #define SET_IVOR(vector_number, vector_label) \
9 li r26,vector_label@l; \
10 mtspr SPRN_IVOR##vector_number,r26; \
13 #define NORMAL_EXCEPTION_PROLOG \
14 mtspr SPRN_SPRG0,r10; /* save two registers to work with */\
15 mtspr SPRN_SPRG1,r11; \
16 mtspr SPRN_SPRG4W,r1; \
17 mfcr r10; /* save CR in r10 for now */\
18 mfspr r11,SPRN_SRR1; /* check whether user or kernel */\
19 andi. r11,r11,MSR_PR; \
21 mfspr r1,SPRG3; /* if from user, start at top of */\
22 lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\
23 addi r1,r1,THREAD_SIZE; \
24 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\
26 stw r10,_CCR(r11); /* save various registers */\
40 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
46 * Exception prolog for critical exceptions. This is a little different
47 * from the normal exception prolog above since a critical exception
48 * can potentially occur at any point during normal exception processing.
49 * Thus we cannot use the same SPRG registers as the normal prolog above.
50 * Instead we use a couple of words of memory at low physical addresses.
51 * This is OK since we don't support SMP on these processors. For Book E
52 * processors, we also have a reserved register (SPRG2) that is only used
53 * in critical exceptions so we can free up a GPR to use as the base for
54 * indirect access to the critical exception save area. This is necessary
55 * since the MMU is always on and the save area is offset from KERNELBASE.
57 #define CRITICAL_EXCEPTION_PROLOG \
58 mtspr SPRG2,r8; /* SPRG2 only used in criticals */ \
59 lis r8,crit_save@ha; \
60 stw r10,crit_r10@l(r8); \
61 stw r11,crit_r11@l(r8); \
63 stw r10,crit_sprg0@l(r8); \
65 stw r10,crit_sprg1@l(r8); \
67 stw r10,crit_sprg4@l(r8); \
69 stw r10,crit_sprg5@l(r8); \
71 stw r10,crit_sprg7@l(r8); \
73 stw r10,crit_pid@l(r8); \
75 stw r10,crit_srr0@l(r8); \
77 stw r10,crit_srr1@l(r8); \
78 mfspr r8,SPRG2; /* SPRG2 only used in criticals */ \
79 mfcr r10; /* save CR in r10 for now */\
80 mfspr r11,SPRN_CSRR1; /* check whether user or kernel */\
81 andi. r11,r11,MSR_PR; \
82 lis r11,critical_stack_top@h; \
83 ori r11,r11,critical_stack_top@l; \
85 /* COMING FROM USER MODE */ \
86 mfspr r11,SPRG3; /* if from user, start at top of */\
87 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
88 addi r11,r11,THREAD_SIZE; \
89 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
90 stw r10,_CCR(r11); /* save various registers */\
95 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
96 stw r12,_DEAR(r11); /* since they may have had stuff */\
97 mfspr r9,SPRN_ESR; /* in them at the point where the */\
98 stw r9,_ESR(r11); /* exception was taken */\
104 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
106 SAVE_4GPRS(3, r11); \
110 * Exception prolog for machine check exceptions. This is similar to
111 * the critical exception prolog, except that machine check exceptions
112 * have their own save area. For Book E processors, we also have a
113 * reserved register (SPRG6) that is only used in machine check exceptions
114 * so we can free up a GPR to use as the base for indirect access to the
115 * machine check exception save area. This is necessary since the MMU
116 * is always on and the save area is offset from KERNELBASE.
118 #define MCHECK_EXCEPTION_PROLOG \
119 mtspr SPRG6W,r8; /* SPRG6 used in machine checks */ \
120 lis r8,mcheck_save@ha; \
121 stw r10,mcheck_r10@l(r8); \
122 stw r11,mcheck_r11@l(r8); \
124 stw r10,mcheck_sprg0@l(r8); \
126 stw r10,mcheck_sprg1@l(r8); \
128 stw r10,mcheck_sprg4@l(r8); \
130 stw r10,mcheck_sprg5@l(r8); \
132 stw r10,mcheck_sprg7@l(r8); \
133 mfspr r10,SPRN_PID; \
134 stw r10,mcheck_pid@l(r8); \
136 stw r10,mcheck_srr0@l(r8); \
138 stw r10,mcheck_srr1@l(r8); \
140 stw r10,mcheck_csrr0@l(r8); \
142 stw r10,mcheck_csrr1@l(r8); \
143 mfspr r8,SPRG6R; /* SPRG6 used in machine checks */ \
144 mfcr r10; /* save CR in r10 for now */\
145 mfspr r11,SPRN_MCSRR1; /* check whether user or kernel */\
146 andi. r11,r11,MSR_PR; \
147 lis r11,mcheck_stack_top@h; \
148 ori r11,r11,mcheck_stack_top@l; \
150 /* COMING FROM USER MODE */ \
151 mfspr r11,SPRG3; /* if from user, start at top of */\
152 lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\
153 addi r11,r11,THREAD_SIZE; \
154 1: subi r11,r11,INT_FRAME_SIZE; /* Allocate an exception frame */\
155 stw r10,_CCR(r11); /* save various registers */\
156 stw r12,GPR12(r11); \
159 stw r10,_LINK(r11); \
160 mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\
161 stw r12,_DEAR(r11); /* since they may have had stuff */\
162 mfspr r9,SPRN_ESR; /* in them at the point where the */\
163 stw r9,_ESR(r11); /* exception was taken */\
169 rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\
171 SAVE_4GPRS(3, r11); \
177 #define START_EXCEPTION(label) \
181 #define FINISH_EXCEPTION(func) \
182 bl transfer_to_handler_full; \
184 .long ret_from_except_full
186 #define EXCEPTION(n, label, hdlr, xfer) \
187 START_EXCEPTION(label); \
188 NORMAL_EXCEPTION_PROLOG; \
189 addi r3,r1,STACK_FRAME_OVERHEAD; \
192 #define CRITICAL_EXCEPTION(n, label, hdlr) \
193 START_EXCEPTION(label); \
194 CRITICAL_EXCEPTION_PROLOG; \
195 addi r3,r1,STACK_FRAME_OVERHEAD; \
196 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
197 NOCOPY, transfer_to_handler_full, \
198 ret_from_except_full)
200 #define MCHECK_EXCEPTION(n, label, hdlr) \
201 START_EXCEPTION(label); \
202 MCHECK_EXCEPTION_PROLOG; \
205 addi r3,r1,STACK_FRAME_OVERHEAD; \
206 EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
207 NOCOPY, mcheck_transfer_to_handler, \
210 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \
220 #define COPY_EE(d, s) rlwimi d,s,0,16,16
223 #define EXC_XFER_STD(n, hdlr) \
224 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \
225 ret_from_except_full)
227 #define EXC_XFER_LITE(n, hdlr) \
228 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
231 #define EXC_XFER_EE(n, hdlr) \
232 EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \
233 ret_from_except_full)
235 #define EXC_XFER_EE_LITE(n, hdlr) \
236 EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
240 #endif /* __HEAD_BOOKE_H__ */