xref: /openbsd-src/lib/libc/arch/powerpc/sys/sbrk.S (revision 83762a71f74848f4d09174ce350838b4204957c5)
1*83762a71Sderaadt/* $OpenBSD: sbrk.S,v 1.18 2023/12/10 16:45:51 deraadt Exp $ */
22352eb10Sdrahn
32352eb10Sdrahn/*
42352eb10Sdrahn * Copyright (c) 1996 Dale Rahn
52352eb10Sdrahn *
62352eb10Sdrahn * Redistribution and use in source and binary forms, with or without
72352eb10Sdrahn * modification, are permitted provided that the following conditions
82352eb10Sdrahn * are met:
92352eb10Sdrahn * 1. Redistributions of source code must retain the above copyright
102352eb10Sdrahn *    notice, this list of conditions and the following disclaimer.
112352eb10Sdrahn * 2. Redistributions in binary form must reproduce the above copyright
122352eb10Sdrahn *    notice, this list of conditions and the following disclaimer in the
132352eb10Sdrahn *    documentation and/or other materials provided with the distribution.
142352eb10Sdrahn *
152352eb10Sdrahn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
162352eb10Sdrahn * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
172352eb10Sdrahn * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182352eb10Sdrahn * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
192352eb10Sdrahn * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202352eb10Sdrahn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212352eb10Sdrahn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222352eb10Sdrahn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232352eb10Sdrahn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242352eb10Sdrahn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252352eb10Sdrahn * SUCH DAMAGE.
262352eb10Sdrahn */
272352eb10Sdrahn
28a4afd6daSrahnds#include "SYS.h"
29a4afd6daSrahnds
30a4afd6daSrahnds	.data
31a4afd6daSrahnds	.globl _end
32b3b7ef2eSguenther	.globl __curbrk
33b3b7ef2eSguenther	.hidden __curbrk
34b3b7ef2eSguenther__curbrk:
3581621933Sguenther	.long _end
36aa797096Sguenther	END(__curbrk)
37aa797096Sguenther	.type	__curbrk,@object
38a4afd6daSrahnds
39a4afd6daSrahnds	.text
400be5e928SguentherENTRY_NB(sbrk)
41a4afd6daSrahnds
42feec8525Sdrahn	/* call break(__curbrk + size) */
4384f3c8deSderaadt#ifndef __PIC__
44b3b7ef2eSguenther	addis	6, 0, __curbrk@H
45b3b7ef2eSguenther	ori	6, 6, __curbrk@L	/* # 6 = &__curbrk */
4645330cbfSrahnds#else
4745330cbfSrahnds	mflr	10
48f14e32ddSkettenis	bcl	20, 31, 1f
49f14e32ddSkettenis1:	mflr	9
50f14e32ddSkettenis	addis	9, 9, _GLOBAL_OFFSET_TABLE_-1b@ha
51f14e32ddSkettenis	addi	9, 9, _GLOBAL_OFFSET_TABLE_-1b@l
5245330cbfSrahnds	mtlr	10
53b3b7ef2eSguenther	lwz	6,__curbrk@got(9)
5445330cbfSrahnds#endif
55a4afd6daSrahnds	lwz	5, 0(6)		/* # 5 = *6 (old_curbrk) */
56a4afd6daSrahnds	add	3, 5, 3		/* # 3 = new_curbrk */
57a4afd6daSrahnds	mr	7, 3
58a4afd6daSrahnds
59d2c5a474Sgkoehler	li	0, SYS_break
60*83762a71Sderaadt99:	sc
61*83762a71Sderaadt	PINSYSCALL(SYS_break, 99b)
62a4afd6daSrahnds
63a4afd6daSrahnds	/* check for error */
64a4afd6daSrahnds	cmpwi	0, 0
6545330cbfSrahnds	beq+	.L_sbrk_ok
665e1df623Sguenther	stw	0, R2_OFFSET_ERRNO(2)
675e1df623Sguenther	li	3, -1
685e1df623Sguenther	blr
69a4afd6daSrahnds
70feec8525Sdrahn	/* update, __curbrk and return */
7145330cbfSrahnds.L_sbrk_ok:
72feec8525Sdrahn	stw	7, 0(6)		/* # remember, 6=&__curbrk, 7=new_curbrk */
73a4afd6daSrahnds	mr	3, 5		/* # remember, 5=old_curbrk */
74a4afd6daSrahnds	blr
75aa797096SguentherEND(sbrk)
764e0d3631Sjca	.weak	sbrk
77