xref: /openbsd-src/lib/libc/arch/powerpc/sys/brk.S (revision 83762a71f74848f4d09174ce350838b4204957c5)
1*83762a71Sderaadt/* $OpenBSD: brk.S,v 1.19 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
30b3b7ef2eSguenther	.extern __curbrk
3181621933Sguenther	.extern _end
32a4afd6daSrahnds
330be5e928SguentherENTRY_NB(brk)
34a4afd6daSrahnds
35a4afd6daSrahnds	/* check >= _end, if not make the call for _end */
3684f3c8deSderaadt#ifndef __PIC__
3781621933Sguenther	addis 5,0,_end@h
3881621933Sguenther	ori  5,5,_end@l				/* # 5 = &_end */
3945330cbfSrahnds#else
4045330cbfSrahnds	mflr	10
41f14e32ddSkettenis	bcl	20, 31, 1f
42f14e32ddSkettenis1:	mflr	9
43f14e32ddSkettenis	addis	9, 9, _GLOBAL_OFFSET_TABLE_-1b@ha
44f14e32ddSkettenis	addi	9, 9, _GLOBAL_OFFSET_TABLE_-1b@l
4545330cbfSrahnds	mtlr	10
4681621933Sguenther	lwz	5,_end@got(9)
4745330cbfSrahnds#endif
48471292dbStdeval	cmplw	3,5
4980a50934Srahnds	bge+	.L_brk_call
50a4afd6daSrahnds	mr	3, 5
51a4afd6daSrahnds
5280a50934Srahnds.L_brk_call:
53a4afd6daSrahnds	mr	7, 3
54a4afd6daSrahnds	/* call break(size) */
5584f3c8deSderaadt#ifndef __PIC__
56b3b7ef2eSguenther	addis	6, 0, __curbrk@H
57b3b7ef2eSguenther	ori	6, 6, __curbrk@L	/* # 6 = &__curbrk */
5845330cbfSrahnds#else
59b3b7ef2eSguenther	lwz	6,__curbrk@got(9)
6045330cbfSrahnds#endif
61a4afd6daSrahnds
62d2c5a474Sgkoehler	li	0, SYS_break
63*83762a71Sderaadt99:	sc
64*83762a71Sderaadt	PINSYSCALL(SYS_break, 99b)
65a4afd6daSrahnds
66a4afd6daSrahnds	/* check for error */
67a4afd6daSrahnds	cmpwi	0, 0
6880a50934Srahnds	beq+	.L_brk_ok	/* OK so this is stupid but I haven't read b */
695e1df623Sguenther	stw	0, R2_OFFSET_ERRNO(2)
705e1df623Sguenther	li	3, -1
715e1df623Sguenther	blr
72a4afd6daSrahnds
73feec8525Sdrahn	/* update, __curbrk and return */
7480a50934Srahnds.L_brk_ok:
75feec8525Sdrahn	stw	7, 0(6)		/* # remember, 6=&__curbrk, 3= new value */
76a4afd6daSrahnds	mr	3, 0		/* # return 0 */
77a4afd6daSrahnds	blr
78aa797096SguentherEND(brk)
794e0d3631Sjca	.weak	brk
80