make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-mips64 / asm.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1995, 1996, 1997, 1999, 2001 by Ralf Baechle
7  * Copyright (C) 1999 by Silicon Graphics, Inc.
8  * Copyright (C) 2001 MIPS Technologies, Inc.
9  * Copyright (C) 2002  Maciej W. Rozycki
10  *
11  * Some useful macros for MIPS assembler code
12  *
13  * Some of the routines below contain useless nops that will be optimized
14  * away by gas in -O mode. These nops are however required to fill delay
15  * slots in noreorder mode.
16  */
17 #ifndef __ASM_ASM_H
18 #define __ASM_ASM_H
19
20 #include <asm/sgidefs.h>
21
22 /*
23  * PIC specific declarations
24  * Not used for the kernel but here seems to be the right place.
25  */
26 #ifdef __PIC__
27 #define CPRESTORE(register)                             \
28                 .cprestore register
29 #define CPADD(register)                                 \
30                 .cpadd  register
31 #define CPLOAD(register)                                \
32                 .cpload register
33 #else
34 #define CPRESTORE(register)
35 #define CPADD(register)
36 #define CPLOAD(register)
37 #endif
38
39 /*
40  * LEAF - declare leaf routine
41  */
42 #define LEAF(symbol)                                    \
43                 .globl  symbol;                         \
44                 .align  2;                              \
45                 .type   symbol,@function;               \
46                 .ent    symbol,0;                       \
47 symbol:         .frame  sp,0,ra
48
49 /*
50  * NESTED - declare nested routine entry point
51  */
52 #define NESTED(symbol, framesize, rpc)                  \
53                 .globl  symbol;                         \
54                 .align  2;                              \
55                 .type   symbol,@function;               \
56                 .ent    symbol,0;                       \
57 symbol:         .frame  sp, framesize, rpc
58
59 /*
60  * END - mark end of function
61  */
62 #define END(function)                                   \
63                 .end    function;                       \
64                 .size   function,.-function
65
66 /*
67  * EXPORT - export definition of symbol
68  */
69 #define EXPORT(symbol)                                  \
70                 .globl  symbol;                         \
71 symbol:
72
73 /*
74  * FEXPORT - export definition of a function symbol
75  */
76 #define FEXPORT(symbol)                                 \
77                 .globl  symbol;                         \
78                 .type   symbol,@function;               \
79 symbol:
80
81 /*
82  * ABS - export absolute symbol
83  */
84 #define ABS(symbol,value)                               \
85                 .globl  symbol;                         \
86 symbol          =       value
87
88 #define PANIC(msg)                                      \
89                 .set    push;                           \
90                 .set    reorder;                        \
91                 PTR_LA  a0,8f;                          \
92                 jal     panic;                          \
93 9:              b       9b;                             \
94                 .set    pop;                            \
95                 TEXT(msg)
96
97 /*
98  * Print formatted string
99  */
100 #define PRINT(string)                                   \
101                 .set    push;                           \
102                 .set    reorder;                        \
103                 PTR_LA  a0,8f;                          \
104                 jal     printk;                         \
105                 .set    pop;                            \
106                 TEXT(string)
107
108 #define TEXT(msg)                                       \
109                 .pushsection .data;                     \
110 8:              .asciiz msg;                            \
111                 .popsection;
112
113 /*
114  * Build text tables
115  */
116 #define TTABLE(string)                                  \
117                 .pushsection .text;                     \
118                 .word   1f;                             \
119                 .popsection                             \
120                 .pushsection .data;                     \
121 1:              .asciiz string;                         \
122                 .popsection
123
124 /*
125  * MIPS IV pref instruction.
126  * Use with .set noreorder only!
127  *
128  * MIPS IV implementations are free to treat this as a nop.  The R5000
129  * is one of them.  So we should have an option not to use this instruction.
130  */
131 #if (_MIPS_ISA == _MIPS_ISA_MIPS4 ) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
132     (_MIPS_ISA == _MIPS_ISA_MIPS64)
133
134 #define PREF(hint,addr)                                 \
135                 .set    push;                           \
136                 .set    mips4;                          \
137                 pref    hint,addr;                      \
138                 .set    pop
139
140 #define PREFX(hint,addr)                                \
141                 .set    push;                           \
142                 .set    mips4;                          \
143                 prefx   hint,addr;                      \
144                 .set    pop
145
146 #else
147
148 #define PREF(hint,addr)
149 #define PREFX(hint,addr)
150
151 #endif
152
153 /*
154  * MIPS ISA IV/V movn/movz instructions and equivalents for older CPUs.
155  */
156 #if (_MIPS_ISA == _MIPS_ISA_MIPS1)
157 #define MOVN(rd,rs,rt)                                  \
158                 .set    push;                           \
159                 .set    reorder;                        \
160                 beqz    rt,9f;                          \
161                 move    rd,rs;                          \
162                 .set    pop;                            \
163 9:
164 #define MOVZ(rd,rs,rt)                                  \
165                 .set    push;                           \
166                 .set    reorder;                        \
167                 bnez    rt,9f;                          \
168                 move    rd,rs;                          \
169                 .set    pop;                            \
170 9:
171 #endif /* _MIPS_ISA == _MIPS_ISA_MIPS1 */
172 #if (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3)
173 #define MOVN(rd,rs,rt)                                  \
174                 .set    push;                           \
175                 .set    noreorder;                      \
176                 bnezl   rt,9f;                          \
177                  move   rd,rs;                          \
178                 .set    pop;                            \
179 9:
180 #define MOVZ(rd,rs,rt)                                  \
181                 .set    push;                           \
182                 .set    noreorder;                      \
183                 beqzl   rt,9f;                          \
184                  move   rd,rs;                          \
185                 .set    pop;                            \
186 9:
187 #endif /* (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3) */
188 #if (_MIPS_ISA == _MIPS_ISA_MIPS4 ) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
189     (_MIPS_ISA == _MIPS_ISA_MIPS32) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
190 #define MOVN(rd,rs,rt)                                  \
191                 movn    rd,rs,rt
192 #define MOVZ(rd,rs,rt)                                  \
193                 movz    rd,rs,rt
194 #endif /* MIPS IV, MIPS V, MIPS32 or MIPS64 */
195
196 /*
197  * Stack alignment
198  */
199 #if (_MIPS_ISA == _MIPS_ISA_MIPS1) || (_MIPS_ISA == _MIPS_ISA_MIPS2) || \
200     (_MIPS_ISA == _MIPS_ISA_MIPS32)
201 #define ALSZ    7
202 #define ALMASK  ~7
203 #endif
204 #if (_MIPS_ISA == _MIPS_ISA_MIPS3) || (_MIPS_ISA == _MIPS_ISA_MIPS4) || \
205     (_MIPS_ISA == _MIPS_ISA_MIPS5) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
206 #define ALSZ    15
207 #define ALMASK  ~15
208 #endif
209
210 /*
211  * Macros to handle different pointer/register sizes for 32/64-bit code
212  */
213
214 /*
215  * Size of a register
216  */
217 #ifdef __mips64
218 #define SZREG   8
219 #else
220 #define SZREG   4
221 #endif
222
223 /*
224  * Use the following macros in assemblercode to load/store registers,
225  * pointers etc.
226  */
227 #if (_MIPS_ISA == _MIPS_ISA_MIPS1) || (_MIPS_ISA == _MIPS_ISA_MIPS2) || \
228     (_MIPS_ISA == _MIPS_ISA_MIPS32)
229 #define REG_S           sw
230 #define REG_L           lw
231 #define REG_SUBU        subu
232 #define REG_ADDU        addu
233 #endif
234 #if (_MIPS_ISA == _MIPS_ISA_MIPS3) || (_MIPS_ISA == _MIPS_ISA_MIPS4) || \
235     (_MIPS_ISA == _MIPS_ISA_MIPS5) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
236 #define REG_S           sd
237 #define REG_L           ld
238 #define REG_SUBU        dsubu
239 #define REG_ADDU        daddu
240 #endif
241
242 /*
243  * How to add/sub/load/store/shift C int variables.
244  */
245 #if (_MIPS_SZINT == 32)
246 #define INT_ADD         add
247 #define INT_ADDU        addu
248 #define INT_ADDI        addi
249 #define INT_ADDIU       addiu
250 #define INT_SUB         sub
251 #define INT_SUBU        subu
252 #define INT_L           lw
253 #define INT_S           sw
254 #define INT_SLL         sll
255 #define INT_SLLV        sllv
256 #define INT_SRL         srl
257 #define INT_SRLV        srlv
258 #define INT_SRA         sra
259 #define INT_SRAV        srav
260 #endif
261
262 #if (_MIPS_SZINT == 64)
263 #define INT_ADD         dadd
264 #define INT_ADDU        daddu
265 #define INT_ADDI        daddi
266 #define INT_ADDIU       daddiu
267 #define INT_SUB         dsub
268 #define INT_SUBU        dsubu
269 #define INT_L           ld
270 #define INT_S           sd
271 #define INT_SLL         dsll
272 #define INT_SLLV        dsllv
273 #define INT_SRL         dsrl
274 #define INT_SRLV        dsrlv
275 #define INT_SRA         dsra
276 #define INT_SRAV        dsrav
277 #endif
278
279 /*
280  * How to add/sub/load/store/shift C long variables.
281  */
282 #if (_MIPS_SZLONG == 32)
283 #define LONG_ADD        add
284 #define LONG_ADDU       addu
285 #define LONG_ADDI       addi
286 #define LONG_ADDIU      addiu
287 #define LONG_SUB        sub
288 #define LONG_SUBU       subu
289 #define LONG_L          lw
290 #define LONG_S          sw
291 #define LONG_SLL        sll
292 #define LONG_SLLV       sllv
293 #define LONG_SRL        srl
294 #define LONG_SRLV       srlv
295 #define LONG_SRA        sra
296 #define LONG_SRAV       srav
297 #endif
298
299 #if (_MIPS_SZLONG == 64)
300 #define LONG_ADD        dadd
301 #define LONG_ADDU       daddu
302 #define LONG_ADDI       daddi
303 #define LONG_ADDIU      daddiu
304 #define LONG_SUB        dsub
305 #define LONG_SUBU       dsubu
306 #define LONG_L          ld
307 #define LONG_S          sd
308 #define LONG_SLL        dsll
309 #define LONG_SLLV       dsllv
310 #define LONG_SRL        dsrl
311 #define LONG_SRLV       dsrlv
312 #define LONG_SRA        dsra
313 #define LONG_SRAV       dsrav
314 #endif
315
316 /*
317  * How to add/sub/load/store/shift pointers.
318  */
319 #if (_MIPS_SZPTR == 32)
320 #define PTR_ADD         add
321 #define PTR_ADDU        addu
322 #define PTR_ADDI        addi
323 #define PTR_ADDIU       addiu
324 #define PTR_SUB         sub
325 #define PTR_SUBU        subu
326 #define PTR_L           lw
327 #define PTR_S           sw
328 #define PTR_LA          la
329 #define PTR_SLL         sll
330 #define PTR_SLLV        sllv
331 #define PTR_SRL         srl
332 #define PTR_SRLV        srlv
333 #define PTR_SRA         sra
334 #define PTR_SRAV        srav
335
336 #define PTR_SCALESHIFT  2
337
338 #define PTR             .word
339 #define PTRSIZE         4
340 #define PTRLOG          2
341 #endif
342
343 #if (_MIPS_SZPTR == 64)
344 #define PTR_ADD         dadd
345 #define PTR_ADDU        daddu
346 #define PTR_ADDI        daddi
347 #define PTR_ADDIU       daddiu
348 #define PTR_SUB         dsub
349 #define PTR_SUBU        dsubu
350 #define PTR_L           ld
351 #define PTR_S           sd
352 #define PTR_LA          dla
353 #define PTR_SLL         dsll
354 #define PTR_SLLV        dsllv
355 #define PTR_SRL         dsrl
356 #define PTR_SRLV        dsrlv
357 #define PTR_SRA         dsra
358 #define PTR_SRAV        dsrav
359
360 #define PTR_SCALESHIFT  3
361
362 #define PTR             .dword
363 #define PTRSIZE         8
364 #define PTRLOG          3
365 #endif
366
367 /*
368  * Some cp0 registers were extended to 64bit for MIPS III.
369  */
370 #if (_MIPS_ISA == _MIPS_ISA_MIPS1) || (_MIPS_ISA == _MIPS_ISA_MIPS2) || \
371     (_MIPS_ISA == _MIPS_ISA_MIPS32)
372 #define MFC0            mfc0
373 #define MTC0            mtc0
374 #endif
375 #if (_MIPS_ISA == _MIPS_ISA_MIPS3) || (_MIPS_ISA == _MIPS_ISA_MIPS4) || \
376     (_MIPS_ISA == _MIPS_ISA_MIPS5) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
377 #define MFC0            dmfc0
378 #define MTC0            dmtc0
379 #endif
380
381 #define SSNOP           sll zero,zero,1
382
383 #endif /* __ASM_ASM_H */