source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/asm/asm.h @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 8.9 KB
Line 
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#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;                       \
56symbol:         .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;                       \
66symbol:         .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;                         \
80symbol:
81
82/*
83 * FEXPORT - export definition of a function symbol
84 */
85#define FEXPORT(symbol)                                 \
86                .globl  symbol;                         \
87                .type   symbol,@function;               \
88symbol:
89
90/*
91 * ABS - export absolute symbol
92 */
93#define ABS(symbol,value)                               \
94                .globl  symbol;                         \
95symbol          =       value
96
97#define PANIC(msg)                                      \
98                .set    push;                           \
99                .set    reorder;                        \
100                PTR_LA  a0,8f;                          \
101                jal     panic;                          \
1029:              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;                     \
1198:              .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;                     \
1301:              .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;                            \
1719:
172#define MOVZ(rd,rs,rt)                                  \
173                .set    push;                           \
174                .set    reorder;                        \
175                bnez    rt,9f;                          \
176                move    rd,rs;                          \
177                .set    pop;                            \
1789:
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;                            \
1879:
188#define MOVZ(rd,rs,rt)                                  \
189                .set    push;                           \
190                .set    noreorder;                      \
191                beqzl   rt,9f;                          \
192                 move   rd,rs;                          \
193                .set    pop;                            \
1949:
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_SIM == _MIPS_SIM_ABI32)
208#define ALSZ    7
209#define ALMASK  ~7
210#endif
211#if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
212#define ALSZ    15
213#define ALMASK  ~15
214#endif
215
216/*
217 * Macros to handle different pointer/register sizes for 32/64-bit code
218 */
219
220/*
221 * Size of a register
222 */
223#ifdef __mips64
224#define SZREG   8
225#else
226#define SZREG   4
227#endif
228
229/*
230 * Use the following macros in assemblercode to load/store registers,
231 * pointers etc.
232 */
233#if (_MIPS_SIM == _MIPS_SIM_ABI32)
234#define REG_S           sw
235#define REG_L           lw
236#define REG_SUBU        subu
237#define REG_ADDU        addu
238#endif
239#if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
240#define REG_S           sd
241#define REG_L           ld
242#define REG_SUBU        dsubu
243#define REG_ADDU        daddu
244#endif
245
246/*
247 * How to add/sub/load/store/shift C int variables.
248 */
249#if (_MIPS_SZINT == 32)
250#define INT_ADD         add
251#define INT_ADDU        addu
252#define INT_ADDI        addi
253#define INT_ADDIU       addiu
254#define INT_SUB         sub
255#define INT_SUBU        subu
256#define INT_L           lw
257#define INT_S           sw
258#define INT_SLL         sll
259#define INT_SLLV        sllv
260#define INT_SRL         srl
261#define INT_SRLV        srlv
262#define INT_SRA         sra
263#define INT_SRAV        srav
264#endif
265
266#if (_MIPS_SZINT == 64)
267#define INT_ADD         dadd
268#define INT_ADDU        daddu
269#define INT_ADDI        daddi
270#define INT_ADDIU       daddiu
271#define INT_SUB         dsub
272#define INT_SUBU        dsubu
273#define INT_L           ld
274#define INT_S           sd
275#define INT_SLL         dsll
276#define INT_SLLV        dsllv
277#define INT_SRL         dsrl
278#define INT_SRLV        dsrlv
279#define INT_SRA         dsra
280#define INT_SRAV        dsrav
281#endif
282
283/*
284 * How to add/sub/load/store/shift C long variables.
285 */
286#if (_MIPS_SZLONG == 32)
287#define LONG_ADD        add
288#define LONG_ADDU       addu
289#define LONG_ADDI       addi
290#define LONG_ADDIU      addiu
291#define LONG_SUB        sub
292#define LONG_SUBU       subu
293#define LONG_L          lw
294#define LONG_S          sw
295#define LONG_SLL        sll
296#define LONG_SLLV       sllv
297#define LONG_SRL        srl
298#define LONG_SRLV       srlv
299#define LONG_SRA        sra
300#define LONG_SRAV       srav
301
302#define LONG            .word
303#define LONGSIZE        4
304#define LONGMASK        3
305#define LONGLOG         2
306#endif
307
308#if (_MIPS_SZLONG == 64)
309#define LONG_ADD        dadd
310#define LONG_ADDU       daddu
311#define LONG_ADDI       daddi
312#define LONG_ADDIU      daddiu
313#define LONG_SUB        dsub
314#define LONG_SUBU       dsubu
315#define LONG_L          ld
316#define LONG_S          sd
317#define LONG_SLL        dsll
318#define LONG_SLLV       dsllv
319#define LONG_SRL        dsrl
320#define LONG_SRLV       dsrlv
321#define LONG_SRA        dsra
322#define LONG_SRAV       dsrav
323
324#define LONG            .dword
325#define LONGSIZE        8
326#define LONGMASK        7
327#define LONGLOG         3
328#endif
329
330/*
331 * How to add/sub/load/store/shift pointers.
332 */
333#if (_MIPS_SZPTR == 32)
334#define PTR_ADD         add
335#define PTR_ADDU        addu
336#define PTR_ADDI        addi
337#define PTR_ADDIU       addiu
338#define PTR_SUB         sub
339#define PTR_SUBU        subu
340#define PTR_L           lw
341#define PTR_S           sw
342#define PTR_LA          la
343#define PTR_SLL         sll
344#define PTR_SLLV        sllv
345#define PTR_SRL         srl
346#define PTR_SRLV        srlv
347#define PTR_SRA         sra
348#define PTR_SRAV        srav
349
350#define PTR_SCALESHIFT  2
351
352#define PTR             .word
353#define PTRSIZE         4
354#define PTRLOG          2
355#endif
356
357#if (_MIPS_SZPTR == 64)
358#define PTR_ADD         dadd
359#define PTR_ADDU        daddu
360#define PTR_ADDI        daddi
361#define PTR_ADDIU       daddiu
362#define PTR_SUB         dsub
363#define PTR_SUBU        dsubu
364#define PTR_L           ld
365#define PTR_S           sd
366#define PTR_LA          dla
367#define PTR_SLL         dsll
368#define PTR_SLLV        dsllv
369#define PTR_SRL         dsrl
370#define PTR_SRLV        dsrlv
371#define PTR_SRA         dsra
372#define PTR_SRAV        dsrav
373
374#define PTR_SCALESHIFT  3
375
376#define PTR             .dword
377#define PTRSIZE         8
378#define PTRLOG          3
379#endif
380
381/*
382 * Some cp0 registers were extended to 64bit for MIPS III.
383 */
384#if (_MIPS_SIM == _MIPS_SIM_ABI32)
385#define MFC0            mfc0
386#define MTC0            mtc0
387#endif
388#if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
389#define MFC0            dmfc0
390#define MTC0            dmtc0
391#endif
392
393#define SSNOP           sll zero,zero,1
394
395#endif /* __ASM_ASM_H */
Note: See TracBrowser for help on using the repository browser.