2 * include/asm-xtensa/asmmacro.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2005 Tensilica Inc.
11 #ifndef _XTENSA_ASMMACRO_H
12 #define _XTENSA_ASMMACRO_H
14 #include <asm-generic/export.h>
18 * Some little helpers for loops. Use zero-overhead-loops
19 * where applicable and if supported by the processor.
21 * __loopi ar, at, size, inc
22 * ar register initialized with the start address
23 * at scratch register used by macro
24 * size size immediate value
27 * __loops ar, as, at, inc_log2[, mask_log2][, cond][, ncond]
28 * ar register initialized with the start address
29 * as register initialized with the size
30 * at scratch register use by macro
31 * inc_log2 increment [in log2]
32 * mask_log2 mask [in log2]
33 * cond true condition (used in loop'cond')
34 * ncond false condition (used in b'ncond')
37 * restart loop. 'as' register must not have been modified!
39 * __endla ar, as, incr
40 * ar start address (modified)
41 * as scratch register used by __loops/__loopi macros or
42 * end address used by __loopt macro
47 * loop for given size as immediate
50 .macro __loopi ar, at, size, incr
53 movi \at, ((\size + \incr - 1) / (\incr))
63 * loop for given size in register
66 .macro __loops ar, as, at, incr_log2, mask_log2, cond, ncond
70 addi \at, \as, (1 << \incr_log2) - 1
72 extui \at, \at, \incr_log2, \mask_log2
74 srli \at, \at, \incr_log2
80 extui \at, \as, \incr_log2, \mask_log2
83 srli \at, \as, \incr_log2
91 slli \at, \at, \incr_log2
105 .macro __loopt ar, as, at, incr_log2
110 addi \at, \at, (1 << \incr_log2) - 1
111 srli \at, \at, \incr_log2
121 * restart loop. registers must be unchanged
135 * end of loop with no increment of the address.
139 #if !XCHAL_HAVE_LOOPS
146 * end of loop with increment of the address.
149 .macro __endla ar, as, incr
154 /* Load or store instructions that may cause exceptions use the EX macro. */
156 #define EX(handler) \
157 .section __ex_table, "a"; \
158 .word 97f, handler; \
164 * Extract unaligned word that is split between two registers w0 and w1
165 * into r regardless of machine endianness. SAR must be loaded with the
166 * starting bit of the word (see __ssa8).
169 .macro __src_b r, w0, w1
178 * Load 2 lowest address bits of r into SAR for __src_b to extract unaligned
179 * word starting at r from two registers loaded from consecutive aligned
180 * addresses covering r regardless of machine endianness.
195 .macro do_nsau cnt, val, tmp, a
201 extui \tmp, \a, 16, 16
206 extui \tmp, \a, 24, 8
211 movi \tmp, __nsau_data
216 #endif /* !XCHAL_HAVE_NSA */
219 .macro do_abs dst, src, tmp
224 movgez \tmp, \src, \src
229 #if defined(__XTENSA_WINDOWED_ABI__)
231 /* Assembly instructions for windowed kernel ABI. */
233 /* Assembly instructions for call0 kernel ABI (will be ignored). */
236 #define XTENSA_FRAME_SIZE_RESERVE 16
237 #define XTENSA_SPILL_STACK_RESERVE 32
239 #define abi_entry(frame_size) \
240 entry sp, (XTENSA_FRAME_SIZE_RESERVE + \
241 (((frame_size) + XTENSA_STACK_ALIGNMENT - 1) & \
242 -XTENSA_STACK_ALIGNMENT))
243 #define abi_entry_default abi_entry(0)
245 #define abi_ret(frame_size) retw
246 #define abi_ret_default retw
249 #define abi_call call4
251 #define abi_callx callx4
252 /* outgoing call argument registers */
261 /* registers preserved across call */
262 #define abi_saved0 a2
263 #define abi_saved1 a3
265 /* none of the above */
269 #elif defined(__XTENSA_CALL0_ABI__)
271 /* Assembly instructions for windowed kernel ABI (will be ignored). */
273 /* Assembly instructions for call0 kernel ABI. */
276 #define XTENSA_SPILL_STACK_RESERVE 0
278 #define abi_entry(frame_size) __abi_entry (frame_size)
280 .macro __abi_entry frame_size
282 addi sp, sp, -(((\frame_size) + XTENSA_STACK_ALIGNMENT - 1) & \
283 -XTENSA_STACK_ALIGNMENT)
287 #define abi_entry_default
289 #define abi_ret(frame_size) __abi_ret (frame_size)
291 .macro __abi_ret frame_size
293 addi sp, sp, (((\frame_size) + XTENSA_STACK_ALIGNMENT - 1) & \
294 -XTENSA_STACK_ALIGNMENT)
299 #define abi_ret_default ret
302 #define abi_call call0
304 #define abi_callx callx0
305 /* outgoing call argument registers */
314 /* registers preserved across call */
315 #define abi_saved0 a12
316 #define abi_saved1 a13
318 /* none of the above */
323 #error Unsupported Xtensa ABI
326 #if defined(USER_SUPPORT_WINDOWED)
327 /* Assembly instructions for windowed user ABI. */
329 /* Assembly instructions for call0 user ABI (will be ignored). */
332 /* Assembly instructions for windowed user ABI (will be ignored). */
334 /* Assembly instructions for call0 user ABI. */
338 #define __XTENSA_HANDLER .section ".exception.text", "ax"
340 #endif /* _XTENSA_ASMMACRO_H */