/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#include "assym.h"

	.ident	"$Header: ovbcopy.s 1.4 89/08/07 $"

/* $Log:	ovbcopy.s,v $
 */

/*
 * ovbcopy(from, to, size)
 *	char *from, *to;
 *	unsigned size;
 *
 * OVerlay bcopy.  Used in boot to move sections around.
 */

	.text
	.globl	ovbcopy
	.align	4
ovbcopy:
	movl	%edi, %eax	/ save registers
	movl	%esi, %edx
	movl	SPARG0, %esi	/ source
	movl	SPARG1, %edi	/ destination
	movl	SPARG2, %ecx	/ count
	cmpl	%edi, %esi	/ Source < Destination?
	jl	ovback		/ yes,  so copy backwards
	je	ovbret		/ if == strings, nothing to do.
	rep;	smovb		/ move the bytes
ovbret:	movl	%edx, %esi	/ restore registers
	movl	%eax, %edi
	RETURN
ovback:
	addl	%ecx, %esi	/ source += count...
	decl	%esi		/	... -1
	addl	%ecx, %edi	/ destination += count...
	decl	%edi		/	... -1
	std			/ set direction flag for backwards
	rep;	smovb		/ move the bytes (backwards)
	cld			/ re-set direction flag for forwards.
	movl	%edx, %esi	/ restore registers
	movl	%eax, %edi
	RETURN
