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