/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
/* $Header: sbrk.s,v 1.13.2.1 92/06/24 14:02:39 marker Exp $ */

#include <sys/regdef.h>
#include <sys/asm.h>
#include <sys.s>
#include "sys/syscall.h"


	.globl	_end
	.globl	_minbrk
	.globl	_curbrk

	.data
_minbrk:.word	_end
_curbrk:.word	_end
	.text

#ifdef	SYSTYPE_POSIX
LEAF(_sbrk)
#else	/* !SYSTYPE_POSIX */
LEAF(sbrk)
#endif	/* !SYSTYPE_POSIX */
	lw	v1,_curbrk
	beq	a0,zero,noincr
	addu	a0,v1
	li	v0,SYS_brk
	syscall
	bne	a3,zero,err
	sw	a0,_curbrk		# update to new curbrk
noincr:
	move	v0,v1			# return previous curbrk
#ifdef	SYSTYPE_POSIX
	RET(_sbrk)
#else	/* !SYSTYPE_POSIX */
	RET(sbrk)
#endif	/* !SYSTYPE_POSIX */

err:
	j	_cerror


#ifndef	SYSTYPE_POSIX
LEAF(brk)
	lw	v0,_minbrk
	bgeu	a0,v0,1f
	move	a0,v0
1:
	li	v0,SYS_brk
	syscall
	bne	a3,zero,err
	sw	a0,_curbrk
	move	v0,zero
	RET(brk)
#endif	/* !SYSTYPE_POSIX */
