	.file	"mcount.s"
/*
 * $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.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	All Rights Reserved	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any	*/
/*	actual or intended publication of such source code.	*/

	.ident	"@(#)$Header: mcount.s 1.3 89/10/10 $"

/* count subroutine called during profiling */

/* struct counter {
 *	void	(*addr)();	address of calling routine
 *	long	count;		# of times called by caller
 */

/*
 * calling sequence:
 *		movl	$a_word,%edx
 *		call	_mcount
 *		.data
 *	a_word: .long	0
 */

	.text
	.globl	_mcount
	.globl	_countbase
	.align	4
/* clobbers %eax and %edx */
_mcount:
	movl	(%edx),%eax		/* %eax = pointer to counter */
	testl	%eax,%eax		/* if zero, must allocate a counter */
	jz	.alloc
	incl	(%eax)			/* increment counter */
.ret:
	ret

.alloc:
	movl	_countbase,%eax		/* get addr of next counter structure */
	testl	%eax,%eax		/* zero means counting is disabled */
	jz	.ret
	addl	$8,_countbase		/* move pointer to next structure */
	addl	$4,%eax			/* %eax = addr of count field */
	movl	%eax,(%edx)		/* update callers pointer */
	popl	%edx			/* %edx = return pc */
	movl	%edx,-4(%eax)		/* set proc address */
	incl	(%eax)			/* increment counter */
	jmp	*%edx
