xref: /netbsd-src/sys/arch/m68k/m68k/copypage.s (revision 4aa16837d6c5a854ea7598ac4deb33c3d4a4f074)
1/*	$NetBSD: copypage.s,v 1.17 2023/09/26 12:46:30 tsutsui Exp $	*/
2
3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by J.T. Conklin <jtc@NetBSD.org> and
9 * by Hiroshi Horitomo <horimoto@cs-aoi.cs.sist.ac.jp>
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * Optimized functions for copying/clearing a whole page.
35 */
36
37#include "opt_m68k_arch.h"
38
39#include <machine/asm.h>
40#include "assym.h"
41
42	.file	"copypage.s"
43	.text
44
45/*
46 * copypage040(fromaddr, toaddr)
47 *
48 * Optimized version of bcopy for a single page-aligned PAGE_SIZE byte copy,
49 * using instructions only available on the mc68040 and later.
50 */
51#if defined(M68040) || defined(M68060)
52ENTRY(copypage040)
53	movl	4(%sp),%a0		| source address
54	movl	8(%sp),%a1		| destiniation address
55	movw	#PAGE_SIZE/32-1,%d0	| number of 32 byte chunks - 1
56.Lm16loop:
57	.long	0xf6209000		| move16 (%a0)+,(%a1)+
58	.long	0xf6209000		| move16 (%a0)+,(%a1)+
59	dbf	%d0,.Lm16loop
60	rts
61#endif /* M68040 || M68060 */
62
63/*
64 * copypage(fromaddr, toaddr)
65 *
66 * Optimized version of bcopy for a single page-aligned PAGE_SIZE byte copy.
67 */
68ENTRY(copypage)
69	movl	4(%sp),%a0		| source address
70	movl	8(%sp),%a1		| destiniation address
71#ifndef	__mc68010__
72	movw	#PAGE_SIZE/32-1,%d0	| number of 32 byte chunks - 1
73.Lmlloop:
74	movl	(%a0)+,(%a1)+
75	movl	(%a0)+,(%a1)+
76	movl	(%a0)+,(%a1)+
77	movl	(%a0)+,(%a1)+
78	movl	(%a0)+,(%a1)+
79	movl	(%a0)+,(%a1)+
80	movl	(%a0)+,(%a1)+
81	movl	(%a0)+,(%a1)+
82	dbf	%d0,.Lmlloop
83#else	/* __mc68010__ */
84	movw	#PAGE_SIZE/4-1,%d0	| number of 4 byte chunks - 1
85.Lmlloop:
86	movl	(%a0)+,(%a1)+
87	dbf	%d0,.Lmlloop		| use the 68010 loop mode
88#endif	/* __mc68010__ */
89	rts
90
91/*
92 * zeropage(addr)
93 *
94 * Optimized version of bzero for a single page-aligned PAGE_SIZE byte zero.
95 */
96ENTRY(zeropage)
97	movl	4(%sp),%a0		| dest address
98#ifndef	__mc68010__
99	movql	#PAGE_SIZE/256-1,%d0	| number of 256 byte chunks - 1
100	movml	%d2-%d7,-(%sp)
101	movql	#0,%d1
102	movql	#0,%d2
103	movql	#0,%d3
104	movql	#0,%d4
105	movql	#0,%d5
106	movql	#0,%d6
107	movql	#0,%d7
108	movl	%d1,%a1
109	lea	PAGE_SIZE(%a0),%a0
110.Lzloop:
111	movml	%d1-%d7/%a1,-(%a0)
112	movml	%d1-%d7/%a1,-(%a0)
113	movml	%d1-%d7/%a1,-(%a0)
114	movml	%d1-%d7/%a1,-(%a0)
115	movml	%d1-%d7/%a1,-(%a0)
116	movml	%d1-%d7/%a1,-(%a0)
117	movml	%d1-%d7/%a1,-(%a0)
118	movml	%d1-%d7/%a1,-(%a0)
119	dbf	%d0,.Lzloop
120	movml	(%sp)+,%d2-%d7
121#else	/* __mc68010__ */
122	movw	#PAGE_SIZE/4-1,%d0	| number of 4 byte chunks - 1
123.Lzloop:
124	clrl	(%a0)+
125	dbf	%d0,.Lzloop		| use the 68010 loop mode
126#endif	/* __mc68010__ */
127	rts
128