xref: /openbsd-src/lib/libc/arch/powerpc64/sys/sbrk.S (revision 83762a71f74848f4d09174ce350838b4204957c5)
1*83762a71Sderaadt/* $OpenBSD: sbrk.S,v 1.5 2023/12/10 16:45:52 deraadt Exp $ */
29674f442Sdrahn
39674f442Sdrahn/*
49674f442Sdrahn * Copyright (c) 1996 Dale Rahn
59674f442Sdrahn *
69674f442Sdrahn * Redistribution and use in source and binary forms, with or without
79674f442Sdrahn * modification, are permitted provided that the following conditions
89674f442Sdrahn * are met:
99674f442Sdrahn * 1. Redistributions of source code must retain the above copyright
109674f442Sdrahn *    notice, this list of conditions and the following disclaimer.
119674f442Sdrahn * 2. Redistributions in binary form must reproduce the above copyright
129674f442Sdrahn *    notice, this list of conditions and the following disclaimer in the
139674f442Sdrahn *    documentation and/or other materials provided with the distribution.
149674f442Sdrahn *
159674f442Sdrahn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
169674f442Sdrahn * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
179674f442Sdrahn * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189674f442Sdrahn * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
199674f442Sdrahn * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209674f442Sdrahn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219674f442Sdrahn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229674f442Sdrahn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239674f442Sdrahn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249674f442Sdrahn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259674f442Sdrahn * SUCH DAMAGE.
269674f442Sdrahn */
279674f442Sdrahn
289674f442Sdrahn#include "SYS.h"
299674f442Sdrahn
309674f442Sdrahn	.data
31ccee21b1Sgkoehler	.globl _end
329674f442Sdrahn	.globl __curbrk
339674f442Sdrahn	.hidden __curbrk
349674f442Sdrahn__curbrk:
35ccee21b1Sgkoehler	.quad	_end
369674f442Sdrahn	END(__curbrk)
379674f442Sdrahn	.type	__curbrk,@object
389674f442Sdrahn
399674f442Sdrahn	.weak	sbrk
409674f442Sdrahn
419674f442Sdrahn	.text
421a8dbaacSderaadtSYSENTRY(sbrk)
431a8dbaacSderaadt	RETGUARD_SETUP(sbrk, %r11)
441a8dbaacSderaadt
459674f442Sdrahn	/* call break(__curbrk + size) */
469674f442Sdrahn	addis	%r6, %r2, __curbrk@toc@ha
479674f442Sdrahn	addi	%r6, %r6, __curbrk@toc@l	/* # %r6 = &__curbrk */
489674f442Sdrahn
49ccee21b1Sgkoehler	ld	%r5, 0(%r6)			/* # %r5 = *%r6 (old_curbrk) */
509674f442Sdrahn	add	%r3, %r5, %r3			/* # %r3 = new_curbrk */
519674f442Sdrahn	mr	%r7, %r3
529674f442Sdrahn
531a8dbaacSderaadt	li %r0, SYS_break
54*83762a71Sderaadt99:	sc
55*83762a71Sderaadt	PINSYSCALL(SYS_break, 99b)
569674f442Sdrahn
579674f442Sdrahn	/* check for error */
589674f442Sdrahn	cmpwi	%r0, 0
599674f442Sdrahn	beq+	.L_sbrk_ok
6043b3e2c9Skettenis	stw	%r0, R13_OFFSET_ERRNO(%r13)
619674f442Sdrahn	li	%r3, -1
621a8dbaacSderaadt	b	.L_done
639674f442Sdrahn
649674f442Sdrahn	/* update, __curbrk and return */
659674f442Sdrahn.L_sbrk_ok:
66ccee21b1Sgkoehler	std	%r7, 0(%r6)	/* # remember, %r6=&__curbrk, %r7=new_curbrk */
679674f442Sdrahn	mr	%r3, %r5	/* # remember, %r5=old_curbrk */
681a8dbaacSderaadt.L_done:
691a8dbaacSderaadt	RETGUARD_CHECK(sbrk, %r11);
709674f442Sdrahn	blr
719674f442Sdrahn END(sbrk)
72