	.file	"sbrk.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.

/ C-library sbrk

/ oldend = sbrk(increment);

/ sbrk gets increment more core, and returns a pointer
/	to the beginning of the new core area

#include "sys.s"

ENTRY(sbrk)
	pushl	%esi		/ save register
	movl	_curbrk,%esi	/ save the current break value
	movl	4+SPARG0,R0	/ get incr
	testl	R0,R0		/ optimize for sbrk(0)
	jz	.nowork
	addl	_curbrk,R0	/ R0 = curbrk + incr
	pushl	R0
	call	brk		/ brk( curbrk + incr )
	popl	R1		/ clear stack
	cmpl	$-1,R0		/ just return if brk() failed
	je	.error
.nowork:
	movl	%esi,R0		/ success so return saved break value
.error:
	popl	%esi		/ restore register
	ret
	

/ brk(value)
/ as described in man2.
/ returns 0 for ok, -1 for error


SYSCALL(1,brk)
	movl	SPARG0,R2
	movl	R2,_curbrk
	ret

	.data
	.align	4
_curbrk:
	.long	end
