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
6 * Copyright (C) 1998, 1999, 2000 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2007 by Maciej W. Rozycki
9 * Copyright (C) 2011, 2012 MIPS Technologies, Inc.
12 #include <asm/asm-offsets.h>
13 #include <asm/export.h>
14 #include <asm/regdef.h>
24 #ifdef CONFIG_CPU_MICROMIPS
25 #define STORSIZE (LONGSIZE * 2)
26 #define STORMASK (STORSIZE - 1)
30 #define LONG_S LONG_SP
32 #define STORSIZE LONGSIZE
33 #define STORMASK LONGMASK
42 * No need to protect it with EVA #ifdefery. The generated block of code
43 * will never be assembled if EVA is not enabled.
45 #define __EVAFY(insn, reg, addr) __BUILD_EVA_INSN(insn##e, reg, addr)
46 #define ___BUILD_EVA_INSN(insn, reg, addr) __EVAFY(insn, reg, addr)
48 #define EX(insn,reg,addr,handler) \
49 .if \mode == LEGACY_MODE; \
52 9: ___BUILD_EVA_INSN(insn, reg, addr); \
54 .section __ex_table,"a"; \
58 .macro f_fill64 dst, offset, val, fixup, mode
59 EX(LONG_S, \val, (\offset + 0 * STORSIZE)(\dst), \fixup)
60 EX(LONG_S, \val, (\offset + 1 * STORSIZE)(\dst), \fixup)
61 EX(LONG_S, \val, (\offset + 2 * STORSIZE)(\dst), \fixup)
62 EX(LONG_S, \val, (\offset + 3 * STORSIZE)(\dst), \fixup)
63 #if ((defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) || !defined(CONFIG_CPU_MICROMIPS))
64 EX(LONG_S, \val, (\offset + 4 * STORSIZE)(\dst), \fixup)
65 EX(LONG_S, \val, (\offset + 5 * STORSIZE)(\dst), \fixup)
66 EX(LONG_S, \val, (\offset + 6 * STORSIZE)(\dst), \fixup)
67 EX(LONG_S, \val, (\offset + 7 * STORSIZE)(\dst), \fixup)
69 #if (!defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4))
70 EX(LONG_S, \val, (\offset + 8 * STORSIZE)(\dst), \fixup)
71 EX(LONG_S, \val, (\offset + 9 * STORSIZE)(\dst), \fixup)
72 EX(LONG_S, \val, (\offset + 10 * STORSIZE)(\dst), \fixup)
73 EX(LONG_S, \val, (\offset + 11 * STORSIZE)(\dst), \fixup)
74 EX(LONG_S, \val, (\offset + 12 * STORSIZE)(\dst), \fixup)
75 EX(LONG_S, \val, (\offset + 13 * STORSIZE)(\dst), \fixup)
76 EX(LONG_S, \val, (\offset + 14 * STORSIZE)(\dst), \fixup)
77 EX(LONG_S, \val, (\offset + 15 * STORSIZE)(\dst), \fixup)
85 * Macro to generate the __bzero{,_user} symbol
87 * mode: LEGACY_MODE or EVA_MODE
89 .macro __BUILD_BZERO mode
90 /* Initialize __memset if this is the first time we call this macro */
93 .hidden __memset /* Make sure it does not leak */
96 sltiu t0, a2, STORSIZE /* very small region? */
97 bnez t0, .Lsmall_memset\@
98 andi t0, a0, STORMASK /* aligned? */
100 #ifdef CONFIG_CPU_MICROMIPS
101 move t8, a1 /* used by 'swp' instruction */
104 #ifndef CONFIG_CPU_DADDI_WORKAROUNDS
106 PTR_SUBU t0, STORSIZE /* alignment in bytes */
111 PTR_SUBU t0, AT /* alignment in bytes */
115 #ifndef CONFIG_CPU_MIPSR6
118 EX(LONG_S_L, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
120 EX(LONG_S_R, a1, (a0), .Lfirst_fixup\@) /* make word/dword aligned */
122 PTR_SUBU a0, t0 /* long align ptr */
123 PTR_ADDU a2, t0 /* correct size */
125 #else /* CONFIG_CPU_MIPSR6 */
126 #define STORE_BYTE(N) \
127 EX(sb, a1, N(a0), .Lbyte_fixup\@); \
131 PTR_ADDU a2, t0 /* correct size */
136 EX(sb, a1, 2(a0), .Lbyte_fixup\@)
142 EX(sb, a1, 6(a0), .Lbyte_fixup\@)
147 PTR_ADDIU a0, STORSIZE
148 #endif /* CONFIG_CPU_MIPSR6 */
149 1: ori t1, a2, 0x3f /* # of full blocks */
151 beqz t1, .Lmemset_partial\@ /* no block to fill */
152 andi t0, a2, 0x40-STORSIZE
154 PTR_ADDU t1, a0 /* end address */
158 f_fill64 a0, -64, FILL64RG, .Lfwd_fixup\@, \mode
164 PTR_LA t1, 2f /* where to start */
165 #ifdef CONFIG_CPU_MICROMIPS
169 PTR_SUBU t1, FILLPTRG
172 LONG_SRL AT, FILLPTRG, 1
177 PTR_ADDU a0, t0 /* dest ptr */
182 /* ... but first do longs ... */
183 f_fill64 a0, -64, FILL64RG, .Lpartial_fixup\@, \mode
185 andi a2, STORMASK /* At most one long to go */
188 #ifndef CONFIG_CPU_MIPSR6
189 PTR_ADDU a0, a2 /* What's left */
192 EX(LONG_S_R, a1, -1(a0), .Llast_fixup\@)
194 EX(LONG_S_L, a1, -1(a0), .Llast_fixup\@)
202 EX(sb, a1, 2(a0), .Lbyte_fixup\@)
208 EX(sb, a1, 6(a0), .Lbyte_fixup\@)
219 1: PTR_ADDIU a0, 1 /* fill bytewise */
232 #ifdef CONFIG_CPU_MIPSR6
237 #endif /* CONFIG_CPU_MIPSR6 */
244 PTR_L t0, TI_TASK($28)
246 LONG_L t0, THREAD_BUADDR(t0)
252 PTR_L t0, TI_TASK($28)
254 LONG_L t0, THREAD_BUADDR(t0)
261 andi v1, a2, STORMASK
266 * memset(void *s, int c, size_t n)
268 * a0: start of area to clear
269 * a1: char to fill with
270 * a2: size of area to clear
274 EXPORT_SYMBOL(memset)
276 move v0, a0 /* result */
278 andi a1, 0xff /* spread fillword */
290 EXPORT_SYMBOL(__bzero)
292 FEXPORT(__bzero_kernel)
293 EXPORT_SYMBOL(__bzero_kernel)
295 __BUILD_BZERO LEGACY_MODE
299 EXPORT_SYMBOL(__bzero)
300 __BUILD_BZERO EVA_MODE