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.
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
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
35 .if \mask
& 0xffff0000
36 movhi
\reg
1,%hi(\mask
)
37 movui
\reg
1,%lo(\mask
)
40 andi
\reg
1,\reg
2,%lo(\mask
)
43 andhi
\reg
1,\reg
2,%hi(\mask
)
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
55 .if \mask
& 0xffff0000
56 orhi
\reg
1,\reg
2,%hi(\mask
)
57 ori
\reg
1,\reg
2,%lo(\mask
)
59 ori
\reg
1,\reg
2,%lo(\mask
)
62 orhi
\reg
1,\reg
2,%hi(\mask
)
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
74 .if \mask
& 0xffff0000
75 xorhi
\reg
1,\reg
2,%hi(\mask
)
76 xori
\reg
1,\reg
1,%lo(\mask
)
78 xori
\reg
1,\reg
2,%lo(\mask
)
81 xorhi
\reg
1,\reg
2,%hi(\mask
)
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
97 andi
\reg
1,\reg
2,(1 << \bit
)
99 andhi
\reg
1,\reg
2,(1 << (\bit
- 16))
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
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
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
140 andi
\reg
1,\reg
2,(1 << \bit
)
141 xori
\reg
2,\reg
2,(1 << \bit
)
143 andhi
\reg
1,\reg
2,(1 << (\bit
- 16))
144 xorhi
\reg
2,\reg
2,(1 << (\bit
- 16))
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
161 andi
\reg
1,\reg
2,(1 << \bit
)
162 ori
\reg
2,\reg
2,(1 << \bit
)
164 andhi
\reg
1,\reg
2,(1 << (\bit
- 16))
165 orhi
\reg
2,\reg
2,(1 << (\bit
- 16))
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
182 andi
\reg
1,\reg
2,(1 << \bit
)
183 andi
\reg
2,\reg
2,%lo(~(1 << \bit
))
185 andhi
\reg
1,\reg
2,(1 << (\bit
- 16))
186 andhi
\reg
2,\reg
2,%lo(~(1 << (\bit
- 16)))
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
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
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
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
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
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
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
\reg
1,\reg
2,\mask
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
\reg
1,\reg
2,\mask
294 * Pushes reg onto the stack.
303 * Pops the top of the stack into reg.
320 * The preprocessor macro does not work for
321 * the nios2 compiler. Undefine ENTRY and define
322 * a real assembler macro.
325 #define ENTRY(name) ASM_ENTRY name
327 .macro ASM_ENTRY name