MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / include / asm-nios2nommu / asm-macros.h
blob9dda7cd95f8ebe7e87336e2e849e9c3aad0fe997
1 /*
2 * Macro used to simplify coding multi-line assembler.
3 * Some of the bit test macro can simplify down to one line
4 * depending on the mask value.
6 * Copyright (C) 2004 Microtronix Datacom Ltd.
8 * All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * ANDs reg2 with mask and places the result in reg1.
30 * You cannnot use the same register for reg1 & reg2.
33 .macro ANDI32 reg1,reg2,mask
34 .if \mask & 0xffff
35 .if \mask & 0xffff0000
36 movhi \reg1,%hi(\mask)
37 movui \reg1,%lo(\mask)
38 and \reg1,\reg1,\reg2
39 .else
40 andi \reg1,\reg2,%lo(\mask)
41 .endif
42 .else
43 andhi \reg1,\reg2,%hi(\mask)
44 .endif
45 .endm
48 * ORs reg2 with mask and places the result in reg1.
50 * It is safe to use the same register for reg1 & reg2.
53 .macro ORI32 reg1,reg2,mask
54 .if \mask & 0xffff
55 .if \mask & 0xffff0000
56 orhi \reg1,\reg2,%hi(\mask)
57 ori \reg1,\reg2,%lo(\mask)
58 .else
59 ori \reg1,\reg2,%lo(\mask)
60 .endif
61 .else
62 orhi \reg1,\reg2,%hi(\mask)
63 .endif
64 .endm
67 * XORs reg2 with mask and places the result in reg1.
69 * It is safe to use the same register for reg1 & reg2.
72 .macro XORI32 reg1,reg2,mask
73 .if \mask & 0xffff
74 .if \mask & 0xffff0000
75 xorhi \reg1,\reg2,%hi(\mask)
76 xori \reg1,\reg1,%lo(\mask)
77 .else
78 xori \reg1,\reg2,%lo(\mask)
79 .endif
80 .else
81 xorhi \reg1,\reg2,%hi(\mask)
82 .endif
83 .endm
86 * This is a support macro for BTBZ & BTBNZ. It checks
87 * the bit to make sure it is valid 32 value.
89 * It is safe to use the same register for reg1 & reg2.
92 .macro BT reg1,reg2,bit
93 .if \bit > 31
94 .err
95 .else
96 .if \bit < 16
97 andi \reg1,\reg2,(1 << \bit)
98 .else
99 andhi \reg1,\reg2,(1 << (\bit - 16))
100 .endif
101 .endif
102 .endm
105 * Tests the bit in reg2 and branches to label if the
106 * bit is zero. The result of the bit test is stored in reg1.
108 * It is safe to use the same register for reg1 & reg2.
111 .macro BTBZ reg1,reg2,bit,label
112 BT \reg1,\reg2,\bit
113 beq \reg1,r0,\label
114 .endm
117 * Tests the bit in reg2 and branches to label if the
118 * bit is non-zero. The result of the bit test is stored in reg1.
120 * It is safe to use the same register for reg1 & reg2.
123 .macro BTBNZ reg1,reg2,bit,label
124 BT \reg1,\reg2,\bit
125 bne \reg1,r0,\label
126 .endm
129 * Tests the bit in reg2 and then compliments the bit in reg2.
130 * The result of the bit test is stored in reg1.
132 * It is NOT safe to use the same register for reg1 & reg2.
135 .macro BTC reg1,reg2,bit
136 .if \bit > 31
137 .err
138 .else
139 .if \bit < 16
140 andi \reg1,\reg2,(1 << \bit)
141 xori \reg2,\reg2,(1 << \bit)
142 .else
143 andhi \reg1,\reg2,(1 << (\bit - 16))
144 xorhi \reg2,\reg2,(1 << (\bit - 16))
145 .endif
146 .endif
147 .endm
150 * Tests the bit in reg2 and then sets the bit in reg2.
151 * The result of the bit test is stored in reg1.
153 * It is NOT safe to use the same register for reg1 & reg2.
156 .macro BTS reg1,reg2,bit
157 .if \bit > 31
158 .err
159 .else
160 .if \bit < 16
161 andi \reg1,\reg2,(1 << \bit)
162 ori \reg2,\reg2,(1 << \bit)
163 .else
164 andhi \reg1,\reg2,(1 << (\bit - 16))
165 orhi \reg2,\reg2,(1 << (\bit - 16))
166 .endif
167 .endif
168 .endm
171 * Tests the bit in reg2 and then resets the bit in reg2.
172 * The result of the bit test is stored in reg1.
174 * It is NOT safe to use the same register for reg1 & reg2.
177 .macro BTR reg1,reg2,bit
178 .if \bit > 31
179 .err
180 .else
181 .if \bit < 16
182 andi \reg1,\reg2,(1 << \bit)
183 andi \reg2,\reg2,%lo(~(1 << \bit))
184 .else
185 andhi \reg1,\reg2,(1 << (\bit - 16))
186 andhi \reg2,\reg2,%lo(~(1 << (\bit - 16)))
187 .endif
188 .endif
189 .endm
192 * Tests the bit in reg2 and then compliments the bit in reg2.
193 * The result of the bit test is stored in reg1. If the
194 * original bit was zero it branches to label.
196 * It is NOT safe to use the same register for reg1 & reg2.
199 .macro BTCBZ reg1,reg2,bit,label
200 BTC \reg1,\reg2,\bit
201 beq \reg1,r0,\label
202 .endm
205 * Tests the bit in reg2 and then compliments the bit in reg2.
206 * The result of the bit test is stored in reg1. If the
207 * original bit was non-zero it branches to label.
209 * It is NOT safe to use the same register for reg1 & reg2.
212 .macro BTCBNZ reg1,reg2,bit,label
213 BTC \reg1,\reg2,\bit
214 bne \reg1,r0,\label
215 .endm
218 * Tests the bit in reg2 and then sets the bit in reg2.
219 * The result of the bit test is stored in reg1. If the
220 * original bit was zero it branches to label.
222 * It is NOT safe to use the same register for reg1 & reg2.
225 .macro BTSBZ reg1,reg2,bit,label
226 BTS \reg1,\reg2,\bit
227 beq \reg1,r0,\label
228 .endm
231 * Tests the bit in reg2 and then sets the bit in reg2.
232 * The result of the bit test is stored in reg1. If the
233 * original bit was non-zero it branches to label.
235 * It is NOT safe to use the same register for reg1 & reg2.
238 .macro BTSBNZ reg1,reg2,bit,label
239 BTS \reg1,\reg2,\bit
240 bne \reg1,r0,\label
241 .endm
244 * Tests the bit in reg2 and then resets the bit in reg2.
245 * The result of the bit test is stored in reg1. If the
246 * original bit was zero it branches to label.
248 * It is NOT safe to use the same register for reg1 & reg2.
251 .macro BTRBZ reg1,reg2,bit,label
252 BTR \reg1,\reg2,\bit
253 bne \reg1,r0,\label
254 .endm
257 * Tests the bit in reg2 and then resets the bit in reg2.
258 * The result of the bit test is stored in reg1. If the
259 * original bit was non-zero it branches to label.
261 * It is NOT safe to use the same register for reg1 & reg2.
264 .macro BTRBNZ reg1,reg2,bit,label
265 BTR \reg1,\reg2,\bit
266 bne \reg1,r0,\label
267 .endm
270 * Tests the bits in mask against reg2 stores the result in reg1.
271 * If the all the bits in the mask are zero it branches to label.
273 * It is safe to use the same register for reg1 & reg2.
276 .macro TSTBZ reg1,reg2,mask,label
277 ANDI32 \reg1,\reg2,\mask
278 beq \reg1,r0,\label
279 .endm
282 * Tests the bits in mask against reg2 stores the result in reg1.
283 * If the any of the bits in the mask are 1 it branches to label.
285 * It is safe to use the same register for reg1 & reg2.
288 .macro TSTBNZ reg1,reg2,mask,label
289 ANDI32 \reg1,\reg2,\mask
290 bne \reg1,r0,\label
291 .endm
294 * Pushes reg onto the stack.
297 .macro PUSH reg
298 addi sp,sp,-4
299 stw \reg,0(sp)
300 .endm
303 * Pops the top of the stack into reg.
306 .macro POP reg
307 ldw \reg,0(sp)
308 addi sp,sp,4
309 .endm
312 * Clears reg
315 .macro CLR reg
316 mov \reg,r0
317 .endm
320 * The preprocessor macro does not work for
321 * the nios2 compiler. Undefine ENTRY and define
322 * a real assembler macro.
324 #undef ENTRY
325 #define ENTRY(name) ASM_ENTRY name
327 .macro ASM_ENTRY name
328 .globl \name
329 __ALIGN
330 \name:
331 .endm