sbrk.S revision 22993
176195Sbrian/*-
276195Sbrian * Copyright (c) 1990 The Regents of the University of California.
376195Sbrian * All rights reserved.
476195Sbrian *
576195Sbrian * This code is derived from software contributed to Berkeley by
676195Sbrian * William Jolitz.
776195Sbrian *
876195Sbrian * Redistribution and use in source and binary forms, with or without
976195Sbrian * modification, are permitted provided that the following conditions
1076195Sbrian * are met:
1176195Sbrian * 1. Redistributions of source code must retain the above copyright
1276195Sbrian *    notice, this list of conditions and the following disclaimer.
1376195Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1476195Sbrian *    notice, this list of conditions and the following disclaimer in the
1576195Sbrian *    documentation and/or other materials provided with the distribution.
1676195Sbrian * 3. All advertising materials mentioning features or use of this software
1776195Sbrian *    must display the following acknowledgement:
1876195Sbrian *	This product includes software developed by the University of
1976195Sbrian *	California, Berkeley and its contributors.
2076195Sbrian * 4. Neither the name of the University nor the names of its contributors
2176195Sbrian *    may be used to endorse or promote products derived from this software
2276195Sbrian *    without specific prior written permission.
2376195Sbrian *
2476195Sbrian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2576195Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2676195Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2776195Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2876195Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2976195Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3076195Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3176195Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3276195Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3376195Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3476195Sbrian * SUCH DAMAGE.
3576195Sbrian *
3676195Sbrian *	$Id$
3776195Sbrian */
3876195Sbrian
3976195Sbrian#if defined(SYSLIBC_RCS) && !defined(lint)
4076196Sbrian	.text
4176195Sbrian	.asciz "$Id$"
4276196Sbrian#endif /* SYSLIBC_RCS and not lint */
4376195Sbrian
4476195Sbrian#include "SYS.h"
4576195Sbrian
4676195Sbrian	.globl	CNAME(end)
4776195Sbrian	.globl	HIDENAME(minbrk)
4876195Sbrian	.globl	HIDENAME(curbrk)
4976195Sbrian
5076195Sbrian	.data
5176195SbrianHIDENAME(minbrk):	.long	CNAME(end)
5276195SbrianHIDENAME(curbrk):	.long	CNAME(end)
5376195Sbrian	.text
5476195Sbrian
5576195SbrianENTRY(sbrk)
5676195Sbrian#ifdef PIC
5776195Sbrian	movl	4(%esp),%ecx
5876195Sbrian	PIC_PROLOGUE
5976195Sbrian	movl	PIC_GOT(HIDENAME(curbrk)),%edx
6076195Sbrian	movl	(%edx),%eax
6176195Sbrian	PIC_EPILOGUE
6276195Sbrian	testl	%ecx,%ecx
6376195Sbrian	jz	back
6476195Sbrian	addl	%eax,4(%esp)
6576195Sbrian	lea	SYS_break,%eax
6676195Sbrian	KERNCALL
6776195Sbrian	jb	err
6876195Sbrian	PIC_PROLOGUE
6976195Sbrian	movl	PIC_GOT(HIDENAME(curbrk)),%edx
7076195Sbrian	movl	(%edx),%eax
7176195Sbrian	addl	%ecx,(%edx)
7276195Sbrian	PIC_EPILOGUE
7376195Sbrianback:
7476195Sbrian	ret
7576195Sbrianerr:
7676195Sbrian	PIC_PROLOGUE
7776195Sbrian	jmp	PIC_PLT(HIDENAME(cerror))
7876195Sbrian
7976195Sbrian#else /* !PIC */
8076195Sbrian
8176195Sbrian	movl	4(%esp),%ecx
8276195Sbrian	movl	HIDENAME(curbrk),%eax
8376195Sbrian	testl	%ecx,%ecx
8476195Sbrian	jz	back
8576195Sbrian	addl	%eax,4(%esp)
8676195Sbrian	lea	SYS_break,%eax
8776195Sbrian	KERNCALL
8876195Sbrian	jb	err
8976195Sbrian	movl	HIDENAME(curbrk),%eax
9076195Sbrian	addl	%ecx,HIDENAME(curbrk)
9176195Sbrianback:
9276195Sbrian	ret
9376195Sbrianerr:
9476195Sbrian	jmp	HIDENAME(cerror)
9576195Sbrian#endif /* PIC */
9676195Sbrian