xref: /linux/arch/sparc/lib/GENpage.S (revision 6c8c1406a6d6a3f2e61ac590f5c0994231bc6be7)
1/* SPDX-License-Identifier: GPL-2.0 */
2/* GENpage.S: Generic clear and copy page.
3 *
4 * Copyright (C) 2007 (davem@davemloft.net)
5 */
6#include <asm/page.h>
7
8	.text
9	.align	32
10
11GENcopy_user_page:
12	set	PAGE_SIZE, %g7
131:	ldx	[%o1 + 0x00], %o2
14	ldx	[%o1 + 0x08], %o3
15	ldx	[%o1 + 0x10], %o4
16	ldx	[%o1 + 0x18], %o5
17	stx	%o2, [%o0 + 0x00]
18	stx	%o3, [%o0 + 0x08]
19	stx	%o4, [%o0 + 0x10]
20	stx	%o5, [%o0 + 0x18]
21	ldx	[%o1 + 0x20], %o2
22	ldx	[%o1 + 0x28], %o3
23	ldx	[%o1 + 0x30], %o4
24	ldx	[%o1 + 0x38], %o5
25	stx	%o2, [%o0 + 0x20]
26	stx	%o3, [%o0 + 0x28]
27	stx	%o4, [%o0 + 0x30]
28	stx	%o5, [%o0 + 0x38]
29	subcc	%g7, 64, %g7
30	add	%o1, 64, %o1
31	bne,pt	%xcc, 1b
32	 add	%o0, 64, %o0
33	retl
34	 nop
35
36GENclear_page:
37GENclear_user_page:
38	set	PAGE_SIZE, %g7
391:	stx	%g0, [%o0 + 0x00]
40	stx	%g0, [%o0 + 0x08]
41	stx	%g0, [%o0 + 0x10]
42	stx	%g0, [%o0 + 0x18]
43	stx	%g0, [%o0 + 0x20]
44	stx	%g0, [%o0 + 0x28]
45	stx	%g0, [%o0 + 0x30]
46	stx	%g0, [%o0 + 0x38]
47	subcc	%g7, 64, %g7
48	bne,pt	%xcc, 1b
49	 add	%o0, 64, %o0
50
51#define BRANCH_ALWAYS	0x10680000
52#define NOP		0x01000000
53#define GEN_DO_PATCH(OLD, NEW)	\
54	sethi	%hi(NEW), %g1; \
55	or	%g1, %lo(NEW), %g1; \
56	sethi	%hi(OLD), %g2; \
57	or	%g2, %lo(OLD), %g2; \
58	sub	%g1, %g2, %g1; \
59	sethi	%hi(BRANCH_ALWAYS), %g3; \
60	sll	%g1, 11, %g1; \
61	srl	%g1, 11 + 2, %g1; \
62	or	%g3, %lo(BRANCH_ALWAYS), %g3; \
63	or	%g3, %g1, %g3; \
64	stw	%g3, [%g2]; \
65	sethi	%hi(NOP), %g3; \
66	or	%g3, %lo(NOP), %g3; \
67	stw	%g3, [%g2 + 0x4]; \
68	flush	%g2;
69
70	.globl	generic_patch_pageops
71	.type	generic_patch_pageops,#function
72generic_patch_pageops:
73	GEN_DO_PATCH(copy_user_page, GENcopy_user_page)
74	GEN_DO_PATCH(_clear_page, GENclear_page)
75	GEN_DO_PATCH(clear_user_page, GENclear_user_page)
76	retl
77	 nop
78	.size	generic_patch_pageops,.-generic_patch_pageops
79