xref: /openbsd-src/sys/lib/libkern/arch/hppa/bcopy.m4 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1define(_rcsid,``$OpenBSD: bcopy.m4,v 1.6 2001/06/04 23:15:49 mickey Exp $'')dnl
2dnl
3dnl
4dnl  This is the source file for bcopy.S, spcopy.S
5dnl
6dnl
7define(`versionmacro',substr(_rcsid,1,eval(len(_rcsid)-2)))dnl
8dnl
9/* This is a generated file. DO NOT EDIT. */
10/*
11 * Generated from:
12 *
13 *	versionmacro
14 */
15/*
16 * Copyright (c) 1999 Michael Shalayeff
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 *    notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 *    notice, this list of conditions and the following disclaimer in the
26 *    documentation and/or other materials provided with the distribution.
27 * 3. All advertising materials mentioning features or use of this software
28 *    must display the following acknowledgement:
29 *      This product includes software developed by Michael Shalayeff.
30 * 4. The name of the author may not be used to endorse or promote products
31 *    derived from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
38 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 *
44 */
45
46dnl
47dnl    macro: L(`arg1',`arg2')
48dnl synopsis: creates an assembly label based on args resulting in $arg1.arg2
49dnl
50define(`L', `$$1.$2')dnl
51dnl
52dnl
53dnl
54define(`STWS',`ifelse($5, `u',dnl
55`ifelse($1, `1', `vshd	$4, t`$1', r31
56	stbys,B,m r31, F`'4($2, $3)',
57`0', `0', `vshd	t`'decr($1), t`$1', r31
58	stws,M	r31, F`'4($2, $3)')',dnl
59`0', `0',
60`ifelse($1, `1',
61`stbys,B`'ifelse(B, `b', `,m ', `0', `0', `	')`'t`$1', F`'4($2, $3)',
62`0', `0', `stws,M	t`$1', F`'4($2, $3)')')')dnl
63define(`STWSS', `ifelse(`$3', `1', `dnl',
64`0', `0', `STWSS($1, $2, eval($3 - 1), $4, $5)')
65	STWS($3, $1, $2, $4, $5)dnl
66')dnl
67define(`LDWSS', `ifelse(`$3', `1', `dnl',
68`0', `0', `LDWSS($1, $2, eval($3 - 1))')
69	ldws,M	F`'4($1, $2), t`'$3`'dnl
70')dnl
71dnl
72dnl copy data in 4-words blocks
73dnl
74define(`hppa_blcopy',`
75	addi	-16, $6, $6
76L($1, `loop16'`$7')
77dnl	cache hint may not work on some hardware
78dnl	ldw	F 32($2, $3), r0
79ifelse(F, `-', `dnl
80	addi	F`'4, $5, $5', `0', `0', `dnl')
81LDWSS($2, $3, 4)
82STWSS($4, $5, 3, `ret1', $7)
83ifelse($7, `u', `dnl
84	STWS(4, $4, $5, `ret1', $7)', $7, `a', `dnl')
85	addib,>= -16, $6, L($1, `loop16'`$7')
86ifelse($7, `a', `dnl
87	STWS(4, $4, $5, `ret1', $7)dnl
88', $7, `u', `dnl
89	copy	t4, ret1')')dnl
90dnl
91dnl copy in words
92dnl
93define(`STWL', `addib,<,n 12, $6, L($1, cleanup)
94ifelse($7, `u', `	copy	ret1, t1', $7, `a', `dnl')
95L($1, word)
96	ldws,M	F`'4($2, $3), t1
97	addib,>= -4, $6, L($1, word)
98	stws,M	t1, F`'4($4, $5)
99
100L($1, cleanup)
101	addib,=,n 4, $6, L($1, done)
102	ldws	0($2, $3), t1
103	add	$5, $6, $5
104	bv	r0(rp)
105	stbys,E	t1, 0($4, $5)
106')
107dnl
108dnl
109dnl parameters:
110dnl  $1	name
111dnl  $2	source space
112dnl  $3	source address
113dnl  $4	destination space
114dnl  $5	destination address
115dnl  $6	length
116dnl  $7	direction
117dnl
118define(hppa_copy,
119`dnl
120dnl
121dnl	if direction is `-' (backwards copy), adjust src, dst
122dnl
123ifelse($7,`-', `add	$3, $6, $3
124	add	$5, $6, $5
125define(`F', `-')dnl
126define(`R', `')dnl
127define(`M', `mb')dnl
128define(`B', `e')dnl
129define(`E', `b')dnl
130',dnl ifelse
131`0',`0',
132`define(`F', `')dnl
133define(`R', `-')dnl
134define(`M', `ma')dnl
135define(`B', `b')dnl
136define(`E', `e')dnl
137')dnl ifelse
138
139ifelse($7,`-', `', `0',`0',
140`	comib,>=,n 15, $6, L($1, byte)
141
142	extru	$3, 31, 2, t3
143	extru	$5, 31, 2, t4
144	add	$6, t4, $6
145	comb,<> t3, t4, L($1, unaligned)
146	dep	r0, 31, 2, $3
147	hppa_blcopy($1, $2, $3, $4, $5, $6, `a')
148
149	STWL($1, $2, $3, $4, $5, $6, `a')dnl
150
151L($1, unaligned)
152	sub,>=	t4, t3, t2
153	ldwm	F`'4($2, $3), ret1
154	zdep	t2, 28, 29, t1
155	mtsar	t1
156	hppa_blcopy($1, $2, $3, $4, $5, $6, `u')
157
158dnl	STWL($1, $2, $3, $4, $5, $6, `u')
159	addib,<,n 12, $6, L($1, cleanup_un)
160L($1, word_un)
161	ldws,M	F`'4($2, $3), t1
162	vshd	ret1, t1, t2
163	addib,<	-4, $6, L($1, cleanup1_un)
164	stws,M	t2, F`'4($4, $5)
165	ldws,M	F`'4($2, $3), ret1
166	vshd	t1, ret1, t2
167	addib,>= -4, $6, L($1, word_un)
168	stws,M	t2, F`'4($4, $5)
169
170L($1, cleanup_un)
171	addib,<=,n 4, $6, L($1, done)
172	mfctl	sar, t4
173	add	$5, $6, $5
174	extru	t4, 28, 2, t4
175	sub,<=	$6, t4, r0
176	ldws,M	F`'4($2, $3), t1
177	vshd	ret1, t1, t2
178	bv	r0(rp)
179	stbys,E	t2, 0($4, $5)
180
181L($1, cleanup1_un)
182	b	L($1, cleanup_un)
183	copy	t1, ret1
184')dnl ifelse
185
186L($1, byte)
187	comb,>=,n r0, $6, L($1, done)
188L($1, byte_loop)
189	ldbs,M	F`'1($2, $3), t1
190	addib,<> -1, $6, L($1, byte_loop)
191	stbs,M	t1, F`'1($4, $5)
192L($1, done)
193')dnl
194`
195#undef _LOCORE
196#define _LOCORE
197#include <machine/asm.h>
198#include <machine/frame.h>
199'
200ifelse(NAME, `bcopy',
201`
202#if defined(LIBC_SCCS)
203	.text
204	.asciz "versionmacro"
205	.align	4
206#endif
207
208LEAF_ENTRY(memcpy)
209ALTENTRY(memmove)
210	copy	arg0, t1
211	copy	arg1, arg0
212	copy	t1, arg1
213ALTENTRY(ovbcopy)
214ALTENTRY(bcopy)
215ALTENTRY(mycopy)
216	add	arg0, arg2, t1
217	comb,>,n t1, arg1, L(bcopy, reverse)
218	hppa_copy(bcopy_f, sr0, arg0, sr0, arg1, arg2, `+')
219	b,n	L(bcopy, ret)
220L(bcopy, reverse)
221	hppa_copy(bcopy_r, sr0, arg0, sr0, arg1, arg2, `-')
222L(bcopy, ret)
223	bv	0(rp)
224	nop
225EXIT(memcpy)
226')dnl
227dnl
228ifelse(NAME, `spcopy',
229`
230#ifdef _KERNEL
231#include <assym.h>
232
233/*
234 * int spcopy (pa_space_t ssp, const void *src, pa_space_t dsp, void *dst,
235 *              size_t size)
236 * do a space to space bcopy.
237 *
238 * assumed that spaces do not clash, otherwise we loose
239 */
240	.import	curproc, data
241	.import	copy_on_fault, code
242LEAF_ENTRY(spcopy)
243	ldw	HPPA_FRAME_ARG(4)(sp), ret1
244	comb,>=,n r0, ret1, L(spcopy, ret)
245`
246	/* setup fault handler */
247	ldil	L%curproc, r31
248	ldw	R%curproc(r31), r31
249	ldil	L%copy_on_fault, t2
250	ldw	p_addr(r31), r31
251	ldo	R%copy_on_fault(t2), t2
252	stw	t2, pcb_onfault+u_pcb(r31)
253'
254	mfsp	sr2, ret0	/* XXX need this?, sr1 is scratchable */
255	mtsp	arg0, sr1
256	mtsp	arg2, sr2
257	copy	ret1, arg0	/* ret1 is used in hppa`'_blcopy() */
258
259	hppa_copy(spcopy, sr1, arg1, sr2, arg3, ret1, `+')
260
261	/* reset fault handler */
262	stw	r0, pcb_onfault+u_pcb(r31)
263	mtsp	ret0, sr2
264L(spcopy, ret)
265	bv	0(rp)
266	copy	r0, ret0
267EXIT(spcopy)
268#endif
269')dnl
270
271	.end
272