Merge git://git.denx.de/u-boot-mpc85xx
[platform/kernel/u-boot.git] / include / ppc_asm.tmpl
1 /*
2  * (C) Copyright 2000-2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /*
9  * This file contains all the macros and symbols which define
10  * a PowerPC assembly language environment.
11  */
12 #ifndef __PPC_ASM_TMPL__
13 #define __PPC_ASM_TMPL__
14
15 #include <config.h>
16
17 /***************************************************************************
18  *
19  * These definitions simplify the ugly declarations necessary for GOT
20  * definitions.
21  *
22  * Stolen from prepboot/bootldr.h, (C) 1998 Gabriel Paubert, paubert@iram.es
23  *
24  * Uses r12 to access the GOT
25  */
26
27 #define START_GOT                       \
28         .section        ".got2","aw";   \
29 .LCTOC1 = .+32768
30
31 #define END_GOT                         \
32         .text
33
34 #define GET_GOT                         \
35         bl      1f              ;       \
36         .text   2               ;       \
37 0:      .long   .LCTOC1-1f      ;       \
38         .text                   ;       \
39 1:      mflr    r12             ;       \
40         lwz     r0,0b-1b(r12)   ;       \
41         add     r12,r0,r12      ;
42
43 #define GOT_ENTRY(NAME)         .L_ ## NAME = . - .LCTOC1 ; .long NAME
44
45 #define GOT(NAME)               .L_ ## NAME (r12)
46
47
48 /***************************************************************************
49  * Register names
50  */
51 #define r0      0
52 #define r1      1
53 #define r2      2
54 #define r3      3
55 #define r4      4
56 #define r5      5
57 #define r6      6
58 #define r7      7
59 #define r8      8
60 #define r9      9
61 #define r10     10
62 #define r11     11
63 #define r12     12
64 #define r13     13
65 #define r14     14
66 #define r15     15
67 #define r16     16
68 #define r17     17
69 #define r18     18
70 #define r19     19
71 #define r20     20
72 #define r21     21
73 #define r22     22
74 #define r23     23
75 #define r24     24
76 #define r25     25
77 #define r26     26
78 #define r27     27
79 #define r28     28
80 #define r29     29
81 #define r30     30
82 #define r31     31
83
84 #if defined(CONFIG_MPC5xxx)
85
86 #define HID0_ICE_BITPOS 16
87 #define HID0_DCE_BITPOS 17
88
89 #endif
90
91 #define curptr r2
92
93 #define SYNC \
94         sync; \
95         isync
96
97 /*
98  * Macros for storing registers into and loading registers from
99  * exception frames.
100  */
101 #define SAVE_GPR(n, base)       stw     n,GPR0+4*(n)(base)
102 #define SAVE_2GPRS(n, base)     SAVE_GPR(n, base); SAVE_GPR(n+1, base)
103 #define SAVE_4GPRS(n, base)     SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
104 #define SAVE_8GPRS(n, base)     SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
105 #define SAVE_10GPRS(n, base)    SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
106 #define REST_GPR(n, base)       lwz     n,GPR0+4*(n)(base)
107 #define REST_2GPRS(n, base)     REST_GPR(n, base); REST_GPR(n+1, base)
108 #define REST_4GPRS(n, base)     REST_2GPRS(n, base); REST_2GPRS(n+2, base)
109 #define REST_8GPRS(n, base)     REST_4GPRS(n, base); REST_4GPRS(n+4, base)
110 #define REST_10GPRS(n, base)    REST_8GPRS(n, base); REST_2GPRS(n+8, base)
111
112 /*
113  * GCC sometimes accesses words at negative offsets from the stack
114  * pointer, although the SysV ABI says it shouldn't.  To cope with
115  * this, we leave this much untouched space on the stack on exception
116  * entry.
117  */
118 #define STACK_UNDERHEAD 64
119
120 /*
121  * Exception entry code.  This code runs with address translation
122  * turned off, i.e. using physical addresses.
123  * We assume sprg3 has the physical address of the current
124  * task's thread_struct.
125  */
126 #define EXCEPTION_PROLOG(reg1, reg2)    \
127         mtspr   SPRG0,r20;      \
128         mtspr   SPRG1,r21;      \
129         mfcr    r20;            \
130         subi    r21,r1,INT_FRAME_SIZE+STACK_UNDERHEAD;  /* alloc exc. frame */\
131         stw     r20,_CCR(r21);          /* save registers */ \
132         stw     r22,GPR22(r21); \
133         stw     r23,GPR23(r21); \
134         mfspr   r20,SPRG0;      \
135         stw     r20,GPR20(r21); \
136         mfspr   r22,SPRG1;      \
137         stw     r22,GPR21(r21); \
138         mflr    r20;            \
139         stw     r20,_LINK(r21); \
140         mfctr   r22;            \
141         stw     r22,_CTR(r21);  \
142         mfspr   r20,XER;        \
143         stw     r20,_XER(r21);  \
144         mfspr   r20, DAR_DEAR;  \
145         stw     r20,_DAR(r21);  \
146         mfspr   r22,reg1;       \
147         mfspr   r23,reg2;       \
148         stw     r0,GPR0(r21);   \
149         stw     r1,GPR1(r21);   \
150         stw     r2,GPR2(r21);   \
151         stw     r1,0(r21);      \
152         mr      r1,r21;                 /* set new kernel sp */ \
153         SAVE_4GPRS(3, r21);
154 /*
155  * Note: code which follows this uses cr0.eq (set if from kernel),
156  * r21, r22 (SRR0), and r23 (SRR1).
157  */
158
159 /*
160  * Exception vectors.
161  *
162  * The data words for `hdlr' and `int_return' are initialized with
163  * OFFSET values only; they must be relocated first before they can
164  * be used!
165  */
166 #define COPY_EE(d, s)           rlwimi d,s,0,16,16
167 #define NOCOPY(d, s)
168
169 #ifdef CONFIG_E500
170 #define EXC_XFER_TEMPLATE(n, label, hdlr, msr, copyee)  \
171         stw     r22,_NIP(r21);                          \
172         stw     r23,_MSR(r21);                          \
173         li      r23,n;                                  \
174         stw     r23,TRAP(r21);                          \
175         li      r20,msr;                                \
176         copyee(r20,r23);                                \
177         rlwimi  r20,r23,0,25,25;                        \
178         mtmsr   r20;                                    \
179         bl      1f;                                     \
180 1:      mflr    r23;                                    \
181         addis   r23,r23,(hdlr - 1b)@ha;                 \
182         addi    r23,r23,(hdlr - 1b)@l;                  \
183         b       transfer_to_handler
184
185 #define STD_EXCEPTION(n, label, hdlr)                           \
186 .align 4;                                                       \
187 label:                                                          \
188         EXCEPTION_PROLOG(SRR0, SRR1);                           \
189         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
190         EXC_XFER_TEMPLATE(n, label, hdlr, MSR_KERNEL, NOCOPY)   \
191
192 #define CRIT_EXCEPTION(n, label, hdlr)                          \
193 .align 4;                                                       \
194 label:                                                          \
195         EXCEPTION_PROLOG(CSRR0, CSRR1);                         \
196         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
197         EXC_XFER_TEMPLATE(n, label, hdlr,                       \
198         MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY)           \
199
200 #define MCK_EXCEPTION(n, label, hdlr)                           \
201 .align 4;                                                       \
202 label:                                                          \
203         EXCEPTION_PROLOG(MCSRR0, MCSRR1);                       \
204         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
205         EXC_XFER_TEMPLATE(n, label, hdlr,                       \
206         MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY)           \
207
208 #else   /* !E500 */
209
210 #define EXC_XFER_TEMPLATE(label, hdlr, msr, copyee)     \
211         bl      1f;                                     \
212 1:      mflr    r20;                                    \
213         lwz     r20,(.L_ ## label)-1b+8(r20);           \
214         mtlr    r20;                                    \
215         li      r20,msr;                                \
216         copyee(r20,r23);                                \
217         rlwimi  r20,r23,0,25,25;                        \
218         blrl;                                           \
219 .L_ ## label :                                          \
220         .long   hdlr - _start + _START_OFFSET;          \
221         .long   int_return - _start + _START_OFFSET;    \
222         .long   transfer_to_handler - _start + _START_OFFSET
223
224 #define STD_EXCEPTION(n, label, hdlr)                           \
225         . = n;                                                  \
226 label:                                                          \
227         EXCEPTION_PROLOG(SRR0, SRR1);                           \
228         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
229         EXC_XFER_TEMPLATE(label, hdlr, MSR_KERNEL, NOCOPY)      \
230
231 #define CRIT_EXCEPTION(n, label, hdlr)                          \
232         . = n;                                                  \
233 label:                                                          \
234         EXCEPTION_PROLOG(CSRR0, CSRR1);                         \
235         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
236         EXC_XFER_TEMPLATE(label, hdlr,                          \
237         MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY)           \
238
239 #define MCK_EXCEPTION(n, label, hdlr)                           \
240         . = n;                                                  \
241 label:                                                          \
242         EXCEPTION_PROLOG(MCSRR0, MCSRR1);                       \
243         addi    r3,r1,STACK_FRAME_OVERHEAD;                     \
244         EXC_XFER_TEMPLATE(label, hdlr,                          \
245         MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY)           \
246
247 #endif  /* !E500 */
248 #endif  /* __PPC_ASM_TMPL__ */