xref: /openbmc/linux/arch/powerpc/lib/mem_64.S (revision 151f4e2b)
1/*
2 * String handling functions for PowerPC.
3 *
4 * Copyright (C) 1996 Paul Mackerras.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <asm/processor.h>
12#include <asm/errno.h>
13#include <asm/ppc_asm.h>
14#include <asm/export.h>
15#include <asm/kasan.h>
16
17#ifndef CONFIG_KASAN
18_GLOBAL(__memset16)
19	rlwimi	r4,r4,16,0,15
20	/* fall through */
21
22_GLOBAL(__memset32)
23	rldimi	r4,r4,32,0
24	/* fall through */
25
26_GLOBAL(__memset64)
27	neg	r0,r3
28	andi.	r0,r0,7
29	cmplw	cr1,r5,r0
30	b	.Lms
31EXPORT_SYMBOL(__memset16)
32EXPORT_SYMBOL(__memset32)
33EXPORT_SYMBOL(__memset64)
34#endif
35
36_GLOBAL_KASAN(memset)
37	neg	r0,r3
38	rlwimi	r4,r4,8,16,23
39	andi.	r0,r0,7			/* # bytes to be 8-byte aligned */
40	rlwimi	r4,r4,16,0,15
41	cmplw	cr1,r5,r0		/* do we get that far? */
42	rldimi	r4,r4,32,0
43.Lms:	PPC_MTOCRF(1,r0)
44	mr	r6,r3
45	blt	cr1,8f
46	beq	3f			/* if already 8-byte aligned */
47	subf	r5,r0,r5
48	bf	31,1f
49	stb	r4,0(r6)
50	addi	r6,r6,1
511:	bf	30,2f
52	sth	r4,0(r6)
53	addi	r6,r6,2
542:	bf	29,3f
55	stw	r4,0(r6)
56	addi	r6,r6,4
573:	srdi.	r0,r5,6
58	clrldi	r5,r5,58
59	mtctr	r0
60	beq	5f
61	.balign 16
624:	std	r4,0(r6)
63	std	r4,8(r6)
64	std	r4,16(r6)
65	std	r4,24(r6)
66	std	r4,32(r6)
67	std	r4,40(r6)
68	std	r4,48(r6)
69	std	r4,56(r6)
70	addi	r6,r6,64
71	bdnz	4b
725:	srwi.	r0,r5,3
73	clrlwi	r5,r5,29
74	PPC_MTOCRF(1,r0)
75	beq	8f
76	bf	29,6f
77	std	r4,0(r6)
78	std	r4,8(r6)
79	std	r4,16(r6)
80	std	r4,24(r6)
81	addi	r6,r6,32
826:	bf	30,7f
83	std	r4,0(r6)
84	std	r4,8(r6)
85	addi	r6,r6,16
867:	bf	31,8f
87	std	r4,0(r6)
88	addi	r6,r6,8
898:	cmpwi	r5,0
90	PPC_MTOCRF(1,r5)
91	beqlr
92	bf	29,9f
93	stw	r4,0(r6)
94	addi	r6,r6,4
959:	bf	30,10f
96	sth	r4,0(r6)
97	addi	r6,r6,2
9810:	bflr	31
99	stb	r4,0(r6)
100	blr
101EXPORT_SYMBOL(memset)
102EXPORT_SYMBOL_KASAN(memset)
103
104_GLOBAL_TOC_KASAN(memmove)
105	cmplw	0,r3,r4
106	bgt	backwards_memcpy
107	b	memcpy
108
109_GLOBAL(backwards_memcpy)
110	rlwinm.	r7,r5,32-3,3,31		/* r0 = r5 >> 3 */
111	add	r6,r3,r5
112	add	r4,r4,r5
113	beq	2f
114	andi.	r0,r6,3
115	mtctr	r7
116	bne	5f
117	.balign 16
1181:	lwz	r7,-4(r4)
119	lwzu	r8,-8(r4)
120	stw	r7,-4(r6)
121	stwu	r8,-8(r6)
122	bdnz	1b
123	andi.	r5,r5,7
1242:	cmplwi	0,r5,4
125	blt	3f
126	lwzu	r0,-4(r4)
127	subi	r5,r5,4
128	stwu	r0,-4(r6)
1293:	cmpwi	0,r5,0
130	beqlr
131	mtctr	r5
1324:	lbzu	r0,-1(r4)
133	stbu	r0,-1(r6)
134	bdnz	4b
135	blr
1365:	mtctr	r0
1376:	lbzu	r7,-1(r4)
138	stbu	r7,-1(r6)
139	bdnz	6b
140	subf	r5,r0,r5
141	rlwinm.	r7,r5,32-3,3,31
142	beq	2b
143	mtctr	r7
144	b	1b
145EXPORT_SYMBOL(memmove)
146EXPORT_SYMBOL_KASAN(memmove)
147