xref: /linux/arch/sparc/lib/memset.S (revision df06c27ebd86af2b4c43f698c3d38b781dbc722d)
1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds/* linux/arch/sparc/lib/memset.S: Sparc optimized memset, bzero and clear_user code
31da177e4SLinus Torvalds * Copyright (C) 1991,1996 Free Software Foundation
41da177e4SLinus Torvalds * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
51da177e4SLinus Torvalds * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
61da177e4SLinus Torvalds *
774cad25cSAndreas Larsson * Calls to memset returns initial %o0. Calls to bzero returns 0, if ok, and
874cad25cSAndreas Larsson * number of bytes not yet set if exception occurs and we were called as
974cad25cSAndreas Larsson * clear_user.
101da177e4SLinus Torvalds */
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds#include <asm/ptrace.h>
13d3867f04SAl Viro#include <asm/export.h>
141da177e4SLinus Torvalds
151da177e4SLinus Torvalds/* Work around cpp -rob */
161da177e4SLinus Torvalds#define ALLOC #alloc
171da177e4SLinus Torvalds#define EXECINSTR #execinstr
181da177e4SLinus Torvalds#define EX(x,y,a,b) 				\
191da177e4SLinus Torvalds98: 	x,y;					\
201da177e4SLinus Torvalds	.section .fixup,ALLOC,EXECINSTR;	\
211da177e4SLinus Torvalds	.align	4;				\
22e51ea544SAl Viro99:	retl;					\
231da177e4SLinus Torvalds	 a, b, %o0;				\
241da177e4SLinus Torvalds	.section __ex_table,ALLOC;		\
251da177e4SLinus Torvalds	.align	4;				\
261da177e4SLinus Torvalds	.word	98b, 99b;			\
271da177e4SLinus Torvalds	.text;					\
281da177e4SLinus Torvalds	.align	4
291da177e4SLinus Torvalds
30*df06c27eSAl Viro#define STORE(source, base, offset, n)		\
31*df06c27eSAl Viro98: 	std source, [base + offset + n];	\
32*df06c27eSAl Viro	.section .fixup,ALLOC,EXECINSTR;	\
33*df06c27eSAl Viro	.align	4;				\
34*df06c27eSAl Viro99:	ba 30f;					\
35*df06c27eSAl Viro	 sub %o3, n - offset, %o3;		\
361da177e4SLinus Torvalds	.section __ex_table,ALLOC;		\
371da177e4SLinus Torvalds	.align	4;				\
38*df06c27eSAl Viro	.word	98b, 99b;			\
391da177e4SLinus Torvalds	.text;					\
40*df06c27eSAl Viro	.align	4;
41*df06c27eSAl Viro
42*df06c27eSAl Viro#define STORE_LAST(source, base, offset, n)	\
43*df06c27eSAl Viro	EX(std source, [base - offset - n],	\
44*df06c27eSAl Viro	   add %o1, offset + n);
451da177e4SLinus Torvalds
461da177e4SLinus Torvalds/* Please don't change these macros, unless you change the logic
471da177e4SLinus Torvalds * in the .fixup section below as well.
481da177e4SLinus Torvalds * Store 64 bytes at (BASE + OFFSET) using value SOURCE. */
491da177e4SLinus Torvalds#define ZERO_BIG_BLOCK(base, offset, source)	\
50*df06c27eSAl Viro	STORE(source, base, offset, 0x00);	\
51*df06c27eSAl Viro	STORE(source, base, offset, 0x08);	\
52*df06c27eSAl Viro	STORE(source, base, offset, 0x10);	\
53*df06c27eSAl Viro	STORE(source, base, offset, 0x18);	\
54*df06c27eSAl Viro	STORE(source, base, offset, 0x20);	\
55*df06c27eSAl Viro	STORE(source, base, offset, 0x28);	\
56*df06c27eSAl Viro	STORE(source, base, offset, 0x30);	\
57*df06c27eSAl Viro	STORE(source, base, offset, 0x38);
581da177e4SLinus Torvalds
591da177e4SLinus Torvalds#define ZERO_LAST_BLOCKS(base, offset, source)	\
60*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x38);	\
61*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x30); \
62*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x28);	\
63*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x20);	\
64*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x18);	\
65*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x10);	\
66*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x08);	\
67*df06c27eSAl Viro	STORE_LAST(source, base, offset, 0x00);
681da177e4SLinus Torvalds
691da177e4SLinus Torvalds	.text
701da177e4SLinus Torvalds	.align 4
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds        .globl  __bzero_begin
731da177e4SLinus Torvalds__bzero_begin:
741da177e4SLinus Torvalds
754d14a459SDavid S. Miller	.globl	__bzero
76f5a651f1SNagarathnam Muthusamy	.type	__bzero,#function
771da177e4SLinus Torvalds	.globl	memset
78d3867f04SAl Viro	EXPORT_SYMBOL(__bzero)
79d3867f04SAl Viro	EXPORT_SYMBOL(memset)
801da177e4SLinus Torvaldsmemset:
8174cad25cSAndreas Larsson	mov	%o0, %g1
8274cad25cSAndreas Larsson	mov	1, %g4
831da177e4SLinus Torvalds	and	%o1, 0xff, %g3
841da177e4SLinus Torvalds	sll	%g3, 8, %g2
851da177e4SLinus Torvalds	or	%g3, %g2, %g3
861da177e4SLinus Torvalds	sll	%g3, 16, %g2
871da177e4SLinus Torvalds	or	%g3, %g2, %g3
881da177e4SLinus Torvalds	b	1f
891da177e4SLinus Torvalds	 mov	%o2, %o1
901da177e4SLinus Torvalds3:
911da177e4SLinus Torvalds	cmp	%o2, 3
921da177e4SLinus Torvalds	be	2f
931da177e4SLinus Torvalds	 EX(stb	%g3, [%o0], sub %o1, 0)
941da177e4SLinus Torvalds
951da177e4SLinus Torvalds	cmp	%o2, 2
961da177e4SLinus Torvalds	be	2f
971da177e4SLinus Torvalds	 EX(stb	%g3, [%o0 + 0x01], sub %o1, 1)
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds	EX(stb	%g3, [%o0 + 0x02], sub %o1, 2)
1001da177e4SLinus Torvalds2:
1011da177e4SLinus Torvalds	sub	%o2, 4, %o2
1021da177e4SLinus Torvalds	add	%o1, %o2, %o1
1031da177e4SLinus Torvalds	b	4f
1041da177e4SLinus Torvalds	 sub	%o0, %o2, %o0
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds__bzero:
10774cad25cSAndreas Larsson	clr	%g4
1081da177e4SLinus Torvalds	mov	%g0, %g3
1091da177e4SLinus Torvalds1:
1101da177e4SLinus Torvalds	cmp	%o1, 7
1111da177e4SLinus Torvalds	bleu	7f
1121da177e4SLinus Torvalds	 andcc	%o0, 3, %o2
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds	bne	3b
1151da177e4SLinus Torvalds4:
1161da177e4SLinus Torvalds	 andcc	%o0, 4, %g0
1171da177e4SLinus Torvalds
1181da177e4SLinus Torvalds	be	2f
1191da177e4SLinus Torvalds	 mov	%g3, %g2
1201da177e4SLinus Torvalds
1211da177e4SLinus Torvalds	EX(st	%g3, [%o0], sub %o1, 0)
1221da177e4SLinus Torvalds	sub	%o1, 4, %o1
1231da177e4SLinus Torvalds	add	%o0, 4, %o0
1241da177e4SLinus Torvalds2:
1251da177e4SLinus Torvalds	andcc	%o1, 0xffffff80, %o3	! Now everything is 8 aligned and o1 is len to run
1261da177e4SLinus Torvalds	be	9f
1271da177e4SLinus Torvalds	 andcc	%o1, 0x78, %o2
1281da177e4SLinus Torvalds10:
1291da177e4SLinus Torvalds	ZERO_BIG_BLOCK(%o0, 0x00, %g2)
1301da177e4SLinus Torvalds	subcc	%o3, 128, %o3
1311da177e4SLinus Torvalds	ZERO_BIG_BLOCK(%o0, 0x40, %g2)
1321da177e4SLinus Torvalds	bne	10b
1331da177e4SLinus Torvalds	 add	%o0, 128, %o0
1341da177e4SLinus Torvalds
1351da177e4SLinus Torvalds	orcc	%o2, %g0, %g0
1361da177e4SLinus Torvalds9:
1371da177e4SLinus Torvalds	be	13f
1381da177e4SLinus Torvalds	 andcc	%o1, 7, %o1
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds	srl	%o2, 1, %o3
1411da177e4SLinus Torvalds	set	13f, %o4
1421da177e4SLinus Torvalds	sub	%o4, %o3, %o4
1431da177e4SLinus Torvalds	jmp	%o4
1441da177e4SLinus Torvalds	 add	%o0, %o2, %o0
1451da177e4SLinus Torvalds
1461da177e4SLinus Torvalds	ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
1471da177e4SLinus Torvalds	ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
1481da177e4SLinus Torvalds13:
1491da177e4SLinus Torvalds	be	8f
1501da177e4SLinus Torvalds	 andcc	%o1, 4, %g0
1511da177e4SLinus Torvalds
1521da177e4SLinus Torvalds	be	1f
1531da177e4SLinus Torvalds	 andcc	%o1, 2, %g0
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds	EX(st	%g3, [%o0], and %o1, 7)
1561da177e4SLinus Torvalds	add	%o0, 4, %o0
1571da177e4SLinus Torvalds1:
1581da177e4SLinus Torvalds	be	1f
1591da177e4SLinus Torvalds	 andcc	%o1, 1, %g0
1601da177e4SLinus Torvalds
1611da177e4SLinus Torvalds	EX(sth	%g3, [%o0], and %o1, 3)
1621da177e4SLinus Torvalds	add	%o0, 2, %o0
1631da177e4SLinus Torvalds1:
1641da177e4SLinus Torvalds	bne,a	8f
1651da177e4SLinus Torvalds	 EX(stb	%g3, [%o0], and %o1, 1)
1661da177e4SLinus Torvalds8:
16774cad25cSAndreas Larsson	b	0f
16874cad25cSAndreas Larsson	 nop
1691da177e4SLinus Torvalds7:
1701da177e4SLinus Torvalds	be	13b
1711da177e4SLinus Torvalds	 orcc	%o1, 0, %g0
1721da177e4SLinus Torvalds
1731da177e4SLinus Torvalds	be	0f
1741da177e4SLinus Torvalds8:
1751da177e4SLinus Torvalds	 add	%o0, 1, %o0
1761da177e4SLinus Torvalds	subcc	%o1, 1, %o1
177f61698e6SAlexander Shmelev	bne	8b
1781da177e4SLinus Torvalds	 EX(stb	%g3, [%o0 - 1], add %o1, 1)
1791da177e4SLinus Torvalds0:
18074cad25cSAndreas Larsson	andcc	%g4, 1, %g0
18174cad25cSAndreas Larsson	be	5f
18274cad25cSAndreas Larsson	 nop
18374cad25cSAndreas Larsson	retl
18474cad25cSAndreas Larsson	 mov	%g1, %o0
18574cad25cSAndreas Larsson5:
1861da177e4SLinus Torvalds	retl
1871da177e4SLinus Torvalds	 clr	%o0
1881da177e4SLinus Torvalds
1891da177e4SLinus Torvalds	.section .fixup,#alloc,#execinstr
1901da177e4SLinus Torvalds	.align	4
191*df06c27eSAl Viro30:
1921da177e4SLinus Torvalds	and	%o1, 0x7f, %o1
193*df06c27eSAl Viro	retl
1941da177e4SLinus Torvalds	 add	%o3, %o1, %o0
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds	.globl __bzero_end
1971da177e4SLinus Torvalds__bzero_end:
198