xref: /netbsd-src/lib/libc/arch/mips/sys/brk.S (revision f3f411dad20d8ad598bae78ec1ee49d838e98af7)
1*f3f411daStsutsui/*	$NetBSD: brk.S,v 1.18 2010/12/12 09:00:37 tsutsui Exp $	*/
281b108b4Sjonathan
3ae1bfcddSglass/*-
4ae1bfcddSglass * Copyright (c) 1991, 1993
5ae1bfcddSglass *	The Regents of the University of California.  All rights reserved.
6ae1bfcddSglass *
7ae1bfcddSglass * This code is derived from software contributed to Berkeley by
8ae1bfcddSglass * Ralph Campbell.
9ae1bfcddSglass *
10ae1bfcddSglass * Redistribution and use in source and binary forms, with or without
11ae1bfcddSglass * modification, are permitted provided that the following conditions
12ae1bfcddSglass * are met:
13ae1bfcddSglass * 1. Redistributions of source code must retain the above copyright
14ae1bfcddSglass *    notice, this list of conditions and the following disclaimer.
15ae1bfcddSglass * 2. Redistributions in binary form must reproduce the above copyright
16ae1bfcddSglass *    notice, this list of conditions and the following disclaimer in the
17ae1bfcddSglass *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
19ae1bfcddSglass *    may be used to endorse or promote products derived from this software
20ae1bfcddSglass *    without specific prior written permission.
21ae1bfcddSglass *
22ae1bfcddSglass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23ae1bfcddSglass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ae1bfcddSglass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ae1bfcddSglass * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26ae1bfcddSglass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ae1bfcddSglass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ae1bfcddSglass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ae1bfcddSglass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ae1bfcddSglass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ae1bfcddSglass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ae1bfcddSglass * SUCH DAMAGE.
33ae1bfcddSglass */
34ae1bfcddSglass
35946af1bcSjonathan#include "SYS.h"
36946af1bcSjonathan
37ae1bfcddSglass#if defined(LIBC_SCCS) && !defined(lint)
3822882071Smatt#if 0
3922882071Smatt	RCSID("from: @(#)brk.s	8.1 (Berkeley) 6/4/93")
4022882071Smatt#else
41*f3f411daStsutsui	RCSID("$NetBSD: brk.S,v 1.18 2010/12/12 09:00:37 tsutsui Exp $")
4222882071Smatt#endif
43ae1bfcddSglass#endif /* LIBC_SCCS and not lint */
44ae1bfcddSglass
456348b7d5Skleink	.globl	_C_LABEL(__minbrk)
466348b7d5Skleink	.globl	_C_LABEL(__curbrk)
475af7e7a9Skleink	.globl	_C_LABEL(_end)
483b5d18b5Smycroft
4903f996bdSkleink#ifdef WEAK_ALIAS
5003f996bdSkleinkWEAK_ALIAS(brk, _brk)
5103f996bdSkleink#endif
5203f996bdSkleink
533b5d18b5Smycroft	.data
546348b7d5Skleink_C_LABEL(__minbrk):
5522882071Smatt	PTR_WORD	_C_LABEL(_end)
563b5d18b5Smycroft	.text
57ae1bfcddSglass
5803f996bdSkleinkLEAF(_brk)
5922882071Smatt	PIC_PROLOGUE(_brk)
6022882071Smatt	PTR_LA		t0, _C_LABEL(__minbrk)
6122882071Smatt	PTR_L		v0, 0(t0)
62de9e80b4Skleink	bgeu		a0, v0, 1f
63ae1bfcddSglass	move		a0, v0		# dont allow break < minbrk
64de9e80b4Skleink1:
653b5d18b5Smycroft	li		v0, SYS_break
66ae1bfcddSglass	syscall
67de9e80b4Skleink	bne		a3, zero, 2f
68*f3f411daStsutsui	PTR_LA		t0, _C_LABEL(__curbrk)
6922882071Smatt	PTR_S		a0, 0(t0)
70ae1bfcddSglass	move		v0, zero
7122882071Smatt	PIC_RETURN()
72de9e80b4Skleink2:
7322882071Smatt	PIC_TAILCALL(__cerror)
745d5afc14SsimonbEND(_brk)
75