This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc / kernel / head_booke.h
1 #ifndef __HEAD_BOOKE_H__
2 #define __HEAD_BOOKE_H__
3
4 /*
5  * Macros used for common Book-e exception handling
6  */
7
8 #define SET_IVOR(vector_number, vector_label)           \
9                 li      r26,vector_label@l;             \
10                 mtspr   SPRN_IVOR##vector_number,r26;   \
11                 sync
12
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;                                              \
20         beq     1f;                                                          \
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     */\
25         tophys(r11,r1);                                                      \
26         stw     r10,_CCR(r11);          /* save various registers          */\
27         stw     r12,GPR12(r11);                                              \
28         stw     r9,GPR9(r11);                                                \
29         mfspr   r10,SPRG0;                                                   \
30         stw     r10,GPR10(r11);                                              \
31         mfspr   r12,SPRG1;                                                   \
32         stw     r12,GPR11(r11);                                              \
33         mflr    r10;                                                         \
34         stw     r10,_LINK(r11);                                              \
35         mfspr   r10,SPRG4R;                                                  \
36         mfspr   r12,SRR0;                                                    \
37         stw     r10,GPR1(r11);                                               \
38         mfspr   r9,SRR1;                                                     \
39         stw     r10,0(r11);                                                  \
40         rlwinm  r9,r9,0,14,12;          /* clear MSR_WE (necessary?)       */\
41         stw     r0,GPR0(r11);                                                \
42         SAVE_4GPRS(3, r11);                                                  \
43         SAVE_2GPRS(7, r11)
44
45 /*
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.
56  */
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);                                          \
62         mfspr   r10,SPRG0;                                                   \
63         stw     r10,crit_sprg0@l(r8);                                        \
64         mfspr   r10,SPRG1;                                                   \
65         stw     r10,crit_sprg1@l(r8);                                        \
66         mfspr   r10,SPRG4R;                                                  \
67         stw     r10,crit_sprg4@l(r8);                                        \
68         mfspr   r10,SPRG5R;                                                  \
69         stw     r10,crit_sprg5@l(r8);                                        \
70         mfspr   r10,SPRG7R;                                                  \
71         stw     r10,crit_sprg7@l(r8);                                        \
72         mfspr   r10,SPRN_PID;                                                \
73         stw     r10,crit_pid@l(r8);                                          \
74         mfspr   r10,SRR0;                                                    \
75         stw     r10,crit_srr0@l(r8);                                         \
76         mfspr   r10,SRR1;                                                    \
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;                                \
84         beq     1f;                                                          \
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          */\
91         stw     r12,GPR12(r11);                                              \
92         stw     r9,GPR9(r11);                                                \
93         mflr    r10;                                                         \
94         stw     r10,_LINK(r11);                                              \
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             */\
99         mfspr   r12,CSRR0;                                                   \
100         stw     r1,GPR1(r11);                                                \
101         mfspr   r9,CSRR1;                                                    \
102         stw     r1,0(r11);                                                   \
103         tovirt(r1,r11);                                                      \
104         rlwinm  r9,r9,0,14,12;          /* clear MSR_WE (necessary?)       */\
105         stw     r0,GPR0(r11);                                                \
106         SAVE_4GPRS(3, r11);                                                  \
107         SAVE_2GPRS(7, r11)
108
109 /*
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.
117  */
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);                                        \
123         mfspr   r10,SPRG0;                                                   \
124         stw     r10,mcheck_sprg0@l(r8);                                      \
125         mfspr   r10,SPRG1;                                                   \
126         stw     r10,mcheck_sprg1@l(r8);                                      \
127         mfspr   r10,SPRG4R;                                                  \
128         stw     r10,mcheck_sprg4@l(r8);                                      \
129         mfspr   r10,SPRG5R;                                                  \
130         stw     r10,mcheck_sprg5@l(r8);                                      \
131         mfspr   r10,SPRG7R;                                                  \
132         stw     r10,mcheck_sprg7@l(r8);                                      \
133         mfspr   r10,SPRN_PID;                                                \
134         stw     r10,mcheck_pid@l(r8);                                        \
135         mfspr   r10,SRR0;                                                    \
136         stw     r10,mcheck_srr0@l(r8);                                       \
137         mfspr   r10,SRR1;                                                    \
138         stw     r10,mcheck_srr1@l(r8);                                       \
139         mfspr   r10,CSRR0;                                                   \
140         stw     r10,mcheck_csrr0@l(r8);                                      \
141         mfspr   r10,CSRR1;                                                   \
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;                                  \
149         beq     1f;                                                          \
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);                                              \
157         stw     r9,GPR9(r11);                                                \
158         mflr    r10;                                                         \
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             */\
164         mfspr   r12,MCSRR0;                                                  \
165         stw     r1,GPR1(r11);                                                \
166         mfspr   r9,MCSRR1;                                                   \
167         stw     r1,0(r11);                                                   \
168         tovirt(r1,r11);                                                      \
169         rlwinm  r9,r9,0,14,12;          /* clear MSR_WE (necessary?)       */\
170         stw     r0,GPR0(r11);                                                \
171         SAVE_4GPRS(3, r11);                                                  \
172         SAVE_2GPRS(7, r11)
173
174 /*
175  * Exception vectors.
176  */
177 #define START_EXCEPTION(label)                                               \
178         .align 5;                                                            \
179 label:
180
181 #define FINISH_EXCEPTION(func)                                  \
182         bl      transfer_to_handler_full;                       \
183         .long   func;                                           \
184         .long   ret_from_except_full
185
186 #define EXCEPTION(n, label, hdlr, xfer)                         \
187         START_EXCEPTION(label);                                 \
188         NORMAL_EXCEPTION_PROLOG;                                \
189         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
190         xfer(n, hdlr)
191
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)
199
200 #define MCHECK_EXCEPTION(n, label, hdlr)                        \
201         START_EXCEPTION(label);                                 \
202         MCHECK_EXCEPTION_PROLOG;                                \
203         mfspr   r5,SPRN_ESR;                                    \
204         stw     r5,_ESR(r11);                                   \
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,   \
208                           ret_from_mcheck_exc)
209
210 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret)   \
211         li      r10,trap;                                       \
212         stw     r10,TRAP(r11);                                  \
213         lis     r10,msr@h;                                      \
214         ori     r10,r10,msr@l;                                  \
215         copyee(r10, r9);                                        \
216         bl      tfer;                                           \
217         .long   hdlr;                                           \
218         .long   ret
219
220 #define COPY_EE(d, s)           rlwimi d,s,0,16,16
221 #define NOCOPY(d, s)
222
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)
226
227 #define EXC_XFER_LITE(n, hdlr)          \
228         EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \
229                           ret_from_except)
230
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)
234
235 #define EXC_XFER_EE_LITE(n, hdlr)       \
236         EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \
237                           ret_from_except)
238
239
240 #endif /* __HEAD_BOOKE_H__ */