memset.S 4.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1998, 1999, 2000 by Ralf Baechle
 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 9
 * Copyright (C) 2007 by Maciej W. Rozycki
 * Copyright (C) 2011, 2012 MIPS Technologies, Inc.
L
Linus Torvalds 已提交
10 11
 */
#include <asm/asm.h>
12
#include <asm/asm-offsets.h>
L
Linus Torvalds 已提交
13 14
#include <asm/regdef.h>

A
Atsushi Nemoto 已提交
15 16 17 18 19 20 21 22
#if LONGSIZE == 4
#define LONG_S_L swl
#define LONG_S_R swr
#else
#define LONG_S_L sdl
#define LONG_S_R sdr
#endif

23 24 25 26 27 28 29 30 31 32 33 34 35 36
#ifdef CONFIG_CPU_MICROMIPS
#define STORSIZE (LONGSIZE * 2)
#define STORMASK (STORSIZE - 1)
#define FILL64RG t8
#define FILLPTRG t7
#undef  LONG_S
#define LONG_S LONG_SP
#else
#define STORSIZE LONGSIZE
#define STORMASK LONGMASK
#define FILL64RG a1
#define FILLPTRG t0
#endif

L
Linus Torvalds 已提交
37 38
#define EX(insn,reg,addr,handler)			\
9:	insn	reg, addr;				\
R
Ralf Baechle 已提交
39 40
	.section __ex_table,"a";			\
	PTR	9b, handler;				\
L
Linus Torvalds 已提交
41 42 43
	.previous

	.macro	f_fill64 dst, offset, val, fixup
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
	EX(LONG_S, \val, (\offset +  0 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  1 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  2 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  3 * STORSIZE)(\dst), \fixup)
#if ((defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) || !defined(CONFIG_CPU_MICROMIPS))
	EX(LONG_S, \val, (\offset +  4 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  5 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  6 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  7 * STORSIZE)(\dst), \fixup)
#endif
#if (!defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4))
	EX(LONG_S, \val, (\offset +  8 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset +  9 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 10 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 11 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 12 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 13 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 14 * STORSIZE)(\dst), \fixup)
	EX(LONG_S, \val, (\offset + 15 * STORSIZE)(\dst), \fixup)
A
Atsushi Nemoto 已提交
63
#endif
L
Linus Torvalds 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	.endm

/*
 * memset(void *s, int c, size_t n)
 *
 * a0: start of area to clear
 * a1: char to fill with
 * a2: size of area to clear
 */
	.set	noreorder
	.align	5
LEAF(memset)
	beqz		a1, 1f
	 move		v0, a0			/* result */

	andi		a1, 0xff		/* spread fillword */
A
Atsushi Nemoto 已提交
80
	LONG_SLL		t1, a1, 8
L
Linus Torvalds 已提交
81
	or		a1, t1
A
Atsushi Nemoto 已提交
82 83 84 85 86
	LONG_SLL		t1, a1, 16
#if LONGSIZE == 8
	or		a1, t1
	LONG_SLL		t1, a1, 32
#endif
L
Linus Torvalds 已提交
87 88 89 90
	or		a1, t1
1:

FEXPORT(__bzero)
91
	sltiu		t0, a2, STORSIZE	/* very small region? */
92
	bnez		t0, .Lsmall_memset
93
	 andi		t0, a0, STORMASK	/* aligned? */
L
Linus Torvalds 已提交
94

95 96 97 98
#ifdef CONFIG_CPU_MICROMIPS
	move		t8, a1			/* used by 'swp' instruction */
	move		t9, a1
#endif
99
#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
L
Linus Torvalds 已提交
100
	beqz		t0, 1f
101
	 PTR_SUBU	t0, STORSIZE		/* alignment in bytes */
102 103
#else
	.set		noat
104
	li		AT, STORSIZE
105 106 107 108
	beqz		t0, 1f
	 PTR_SUBU	t0, AT			/* alignment in bytes */
	.set		at
#endif
L
Linus Torvalds 已提交
109

110
	R10KCBARRIER(0(ra))
L
Linus Torvalds 已提交
111
#ifdef __MIPSEB__
112
	EX(LONG_S_L, a1, (a0), .Lfirst_fixup)	/* make word/dword aligned */
L
Linus Torvalds 已提交
113 114
#endif
#ifdef __MIPSEL__
115
	EX(LONG_S_R, a1, (a0), .Lfirst_fixup)	/* make word/dword aligned */
L
Linus Torvalds 已提交
116 117 118 119 120 121
#endif
	PTR_SUBU	a0, t0			/* long align ptr */
	PTR_ADDU	a2, t0			/* correct size */

1:	ori		t1, a2, 0x3f		/* # of full blocks */
	xori		t1, 0x3f
122
	beqz		t1, .Lmemset_partial	/* no block to fill */
123
	 andi		t0, a2, 0x40-STORSIZE
L
Linus Torvalds 已提交
124 125 126 127

	PTR_ADDU	t1, a0			/* end address */
	.set		reorder
1:	PTR_ADDIU	a0, 64
128
	R10KCBARRIER(0(ra))
129
	f_fill64 a0, -64, FILL64RG, .Lfwd_fixup
L
Linus Torvalds 已提交
130 131 132
	bne		t1, a0, 1b
	.set		noreorder

133
.Lmemset_partial:
134
	R10KCBARRIER(0(ra))
L
Linus Torvalds 已提交
135
	PTR_LA		t1, 2f			/* where to start */
136 137 138
#ifdef CONFIG_CPU_MICROMIPS
	LONG_SRL	t7, t0, 1
#endif
A
Atsushi Nemoto 已提交
139
#if LONGSIZE == 4
140
	PTR_SUBU	t1, FILLPTRG
A
Atsushi Nemoto 已提交
141 142
#else
	.set		noat
143
	LONG_SRL	AT, FILLPTRG, 1
A
Atsushi Nemoto 已提交
144
	PTR_SUBU	t1, AT
145
	.set		at
A
Atsushi Nemoto 已提交
146
#endif
L
Linus Torvalds 已提交
147 148 149 150 151 152
	jr		t1
	 PTR_ADDU	a0, t0			/* dest ptr */

	.set		push
	.set		noreorder
	.set		nomacro
153
	f_fill64 a0, -64, FILL64RG, .Lpartial_fixup	/* ... but first do longs ... */
L
Linus Torvalds 已提交
154
2:	.set		pop
155
	andi		a2, STORMASK		/* At most one long to go */
L
Linus Torvalds 已提交
156 157 158

	beqz		a2, 1f
	 PTR_ADDU	a0, a2			/* What's left */
159
	R10KCBARRIER(0(ra))
L
Linus Torvalds 已提交
160
#ifdef __MIPSEB__
161
	EX(LONG_S_R, a1, -1(a0), .Llast_fixup)
L
Linus Torvalds 已提交
162 163
#endif
#ifdef __MIPSEL__
164
	EX(LONG_S_L, a1, -1(a0), .Llast_fixup)
L
Linus Torvalds 已提交
165 166 167 168
#endif
1:	jr		ra
	 move		a2, zero

169
.Lsmall_memset:
L
Linus Torvalds 已提交
170 171 172 173
	beqz		a2, 2f
	 PTR_ADDU	t1, a0, a2

1:	PTR_ADDIU	a0, 1			/* fill bytewise */
174
	R10KCBARRIER(0(ra))
L
Linus Torvalds 已提交
175 176 177 178 179 180 181
	bne		t1, a0, 1b
	 sb		a1, -1(a0)

2:	jr		ra			/* done */
	 move		a2, zero
	END(memset)

182
.Lfirst_fixup:
L
Linus Torvalds 已提交
183 184 185
	jr	ra
	 nop

186
.Lfwd_fixup:
L
Linus Torvalds 已提交
187 188
	PTR_L		t0, TI_TASK($28)
	andi		a2, 0x3f
189
	LONG_L		t0, THREAD_BUADDR(t0)
L
Linus Torvalds 已提交
190 191 192 193
	LONG_ADDU	a2, t1
	jr		ra
	 LONG_SUBU	a2, t0

194
.Lpartial_fixup:
L
Linus Torvalds 已提交
195
	PTR_L		t0, TI_TASK($28)
196
	andi		a2, STORMASK
197
	LONG_L		t0, THREAD_BUADDR(t0)
L
Linus Torvalds 已提交
198 199 200 201
	LONG_ADDU	a2, t1
	jr		ra
	 LONG_SUBU	a2, t0

202
.Llast_fixup:
L
Linus Torvalds 已提交
203
	jr		ra
204
	 andi		v1, a2, STORMASK