xref: /netbsd-src/lib/libc/arch/i386/sys/brk.S (revision 0d34bfa26d596b4f9bcb49175a92020d91572850)
1*0d34bfa2Suebayasi/*	$NetBSD: brk.S,v 1.24 2014/05/23 02:34:19 uebayasi Exp $	*/
21394f01bSchristos
30b9f5089Scgd/*-
40b9f5089Scgd * Copyright (c) 1990 The Regents of the University of California.
50b9f5089Scgd * All rights reserved.
60b9f5089Scgd *
70b9f5089Scgd * This code is derived from software contributed to Berkeley by
80b9f5089Scgd * William Jolitz.
90b9f5089Scgd *
100b9f5089Scgd * Redistribution and use in source and binary forms, with or without
110b9f5089Scgd * modification, are permitted provided that the following conditions
120b9f5089Scgd * are met:
130b9f5089Scgd * 1. Redistributions of source code must retain the above copyright
140b9f5089Scgd *    notice, this list of conditions and the following disclaimer.
150b9f5089Scgd * 2. Redistributions in binary form must reproduce the above copyright
160b9f5089Scgd *    notice, this list of conditions and the following disclaimer in the
170b9f5089Scgd *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
190b9f5089Scgd *    may be used to endorse or promote products derived from this software
200b9f5089Scgd *    without specific prior written permission.
210b9f5089Scgd *
220b9f5089Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
230b9f5089Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
240b9f5089Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250b9f5089Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
260b9f5089Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
270b9f5089Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
280b9f5089Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
290b9f5089Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
300b9f5089Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
310b9f5089Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
320b9f5089Scgd * SUCH DAMAGE.
3344186168Sjtc *
3444186168Sjtc *	from: @(#)brk.s	5.2 (Berkeley) 12/17/90
350b9f5089Scgd */
360b9f5089Scgd
371394f01bSchristos#include <machine/asm.h>
380b9f5089Scgd#if defined(SYSLIBC_SCCS) && !defined(lint)
39*0d34bfa2Suebayasi	RCSID("$NetBSD: brk.S,v 1.24 2014/05/23 02:34:19 uebayasi Exp $")
400b9f5089Scgd#endif /* SYSLIBC_SCCS and not lint */
410b9f5089Scgd
420b9f5089Scgd#include "SYS.h"
430b9f5089Scgd
441fe07f18Smycroft	.globl	_end
456348b7d5Skleink	.globl	_C_LABEL(__minbrk)
466348b7d5Skleink	.globl	CURBRK
471fe07f18Smycroft
4815bc7ed3Skleink#ifdef WEAK_ALIAS
4915bc7ed3SkleinkWEAK_ALIAS(brk, _brk)
5015bc7ed3Skleink#endif
5115bc7ed3Skleink
521fe07f18Smycroft	.data
536348b7d5Skleink_C_LABEL(__minbrk):
546348b7d5Skleink	.long	_end
551fe07f18Smycroft	.text
560b9f5089Scgd
5703f996bdSkleinkENTRY(_brk)
584d12bfcdSjoerg#ifdef __PIC__
5922e614ceSmycroft	movl	4(%esp),%ecx
600b9f5089Scgd	PIC_PROLOGUE
616348b7d5Skleink	movl	PIC_GOT(_C_LABEL(__minbrk)),%edx
620b9f5089Scgd	PIC_EPILOGUE
6322e614ceSmycroft	cmpl	%ecx,(%edx)
64b25c2304Sross	jb	1f
6522e614ceSmycroft	movl	(%edx),%ecx
6622e614ceSmycroft	movl	%ecx,4(%esp)
6722e614ceSmycroft1:
683cac6dbbSad	OSYSTRAP(break)	/* don't clobber %ecx */
6922e614ceSmycroft	jc	err
7022e614ceSmycroft	PIC_PROLOGUE
716348b7d5Skleink	movl	PIC_GOT(CURBRK),%edx	# set up GOT addressing
7222e614ceSmycroft	PIC_EPILOGUE
7322e614ceSmycroft	movl	%ecx,(%edx)
7472e604e4Smycroft	xorl	%eax,%eax
750b9f5089Scgd	ret
760b9f5089Scgderr:
774e5324e2Sjoerg	jmp	CERROR
780b9f5089Scgd#else
7922e614ceSmycroft	movl	4(%esp),%ecx
806348b7d5Skleink	cmpl	%ecx,_C_LABEL(__minbrk)
81b25c2304Sross	jb	1f
826348b7d5Skleink	movl	_C_LABEL(__minbrk),%ecx
8322e614ceSmycroft	movl	%ecx,4(%esp)
8422e614ceSmycroft1:
853cac6dbbSad	OSYSTRAP(break)	/* don't clobber %ecx */
8622e614ceSmycroft	jc	err
876348b7d5Skleink	movl	%ecx,CURBRK
8872e604e4Smycroft	xorl	%eax,%eax
890b9f5089Scgd	ret
900b9f5089Scgderr:
916348b7d5Skleink	jmp	CERROR
920b9f5089Scgd#endif
93*0d34bfa2SuebayasiEND(_brk)
94