1296341Sdelphij/*-
296593Smarkm * Copyright (c) 2002 Peter Grehan.
396593Smarkm * All rights reserved.
4142429Snectar *
596593Smarkm * Redistribution and use in source and binary forms, with or without
696593Smarkm * modification, are permitted provided that the following conditions
796593Smarkm * are met:
896593Smarkm * 1. Redistributions of source code must retain the above copyright
996593Smarkm *    notice, this list of conditions and the following disclaimer.
1096593Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1196593Smarkm *    notice, this list of conditions and the following disclaimer in the
1296593Smarkm *    documentation and/or other materials provided with the distribution.
1396593Smarkm *
1496593Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1596593Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1696593Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1796593Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1896593Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1996593Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20215698Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21215698Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22215698Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23215698Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24215698Ssimon * SUCH DAMAGE.
2596593Smarkm */
2696593Smarkm/*      $NetBSD: sbrk.S,v 1.8 2000/06/26 06:25:44 kleink Exp $  */
2796593Smarkm
2896593Smarkm#include <machine/asm.h>
2996593Smarkm__FBSDID("$FreeBSD$");
3096593Smarkm
3196593Smarkm#include "SYS.h"
3296593Smarkm
3396593Smarkm	.globl	HIDENAME(curbrk)
3496593Smarkm	.globl	CNAME(_end)
3596593Smarkm
3696593Smarkm	.data
3796593Smarkm	.align 3
3896593SmarkmHIDENAME(curbrk):
3996593Smarkm	.llong	CNAME(_end)
4096593Smarkm
41279264Sdelphij	.text
42279264SdelphijENTRY(sbrk)
4396593Smarkm	addis	%r5,%r2,HIDENAME(curbrk)@toc@ha
4496593Smarkm	addi	%r5,%r5,HIDENAME(curbrk)@toc@l
45215698Ssimon	ld	%r6,0(%r5)			/* r6 = old break */
46215698Ssimon	cmpdi	%r3,0				/* sbrk(0) - return curbrk */
47215698Ssimon	beq	1f
48215698Ssimon	add	%r3,%r3,%r6
49142429Snectar	mr	%r7,%r3				/* r7 = new break */
50215698Ssimon	li	%r0,SYS_break
51142429Snectar	sc					/* break(new_break) */
52142429Snectar	bso	2f
53279264Sdelphij	std     %r7,0(%r5)
54279264Sdelphij1:
55279264Sdelphij	mr      %r3,%r6				/* set return value */
5696593Smarkm	blr
57279264Sdelphij2:
58279264Sdelphij	mflr	%r0
59279264Sdelphij	std	%r0,16(%r1)
60279264Sdelphij	stdu	%r1,-48(%r1)
61279264Sdelphij	bl	HIDENAME(cerror)
62279264Sdelphij	nop
63215698Ssimon	ld	%r1,0(%r1)
64279264Sdelphij	ld	%r0,16(%r1)
65279264Sdelphij	mtlr	%r0
66279264Sdelphij	blr
67279264Sdelphij
68279264Sdelphij	.section .note.GNU-stack,"",%progbits
69215698Ssimon