xref: /openbsd-src/lib/libc/arch/sh/sys/sbrk.S (revision fc31befaf105b97a112f7671f6f1ed3695619019)
1*fc31befaSmiod/*	$OpenBSD: sbrk.S,v 1.10 2024/03/27 20:03:29 miod Exp $	*/
2cf252584Smiod/*	$NetBSD: sbrk.S,v 1.9 2006/01/06 03:58:31 uwe Exp $	*/
3cf252584Smiod
4cf252584Smiod/*-
5cf252584Smiod * Copyright (c) 1990 The Regents of the University of California.
6cf252584Smiod * All rights reserved.
7cf252584Smiod *
8cf252584Smiod * This code is derived from software contributed to Berkeley by
9cf252584Smiod * William Jolitz.
10cf252584Smiod *
11cf252584Smiod * Redistribution and use in source and binary forms, with or without
12cf252584Smiod * modification, are permitted provided that the following conditions
13cf252584Smiod * are met:
14cf252584Smiod * 1. Redistributions of source code must retain the above copyright
15cf252584Smiod *    notice, this list of conditions and the following disclaimer.
16cf252584Smiod * 2. Redistributions in binary form must reproduce the above copyright
17cf252584Smiod *    notice, this list of conditions and the following disclaimer in the
18cf252584Smiod *    documentation and/or other materials provided with the distribution.
19cf252584Smiod * 3. Neither the name of the University nor the names of its contributors
20cf252584Smiod *    may be used to endorse or promote products derived from this software
21cf252584Smiod *    without specific prior written permission.
22cf252584Smiod *
23cf252584Smiod * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24cf252584Smiod * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25cf252584Smiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26cf252584Smiod * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27cf252584Smiod * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28cf252584Smiod * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29cf252584Smiod * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30cf252584Smiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31cf252584Smiod * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32cf252584Smiod * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33cf252584Smiod * SUCH DAMAGE.
34cf252584Smiod *
35cf252584Smiod *	from: @(#)sbrk.s	5.1 (Berkeley) 4/23/90
36cf252584Smiod */
37cf252584Smiod
38cf252584Smiod#include "SYS.h"
39cf252584Smiod
400ee2ce67Sguenther	.globl	_end
41b3b7ef2eSguenther	.globl	__curbrk
42b3b7ef2eSguenther	.hidden	__curbrk
43cf252584Smiod
443f373d41Sguenther	.weak	sbrk
45cf252584Smiod
46cf252584Smiod	.data
47b3b7ef2eSguenther__curbrk:
480ee2ce67Sguenther	.long	_end
493f373d41Sguenther	.size	__curbrk, . - __curbrk
503f373d41Sguenther	.type	__curbrk,@object
513f373d41Sguenther
52cf252584Smiod	.text
53cf252584Smiod
543f373d41SguentherENTRY(sbrk)
55cf252584Smiod	mov	r4, r2
5632b97dedSpascal#ifdef __PIC__
57cf252584Smiod	mova	L_GOT, r0
58cf252584Smiod	mov.l	L_GOT, r3
59cf252584Smiod	add	r0, r3
60cf252584Smiod	mov.l	Lcurbrk, r0
61cf252584Smiod	mov.l	@(r0, r3), r0
62cf252584Smiod#else
63cf252584Smiod	mov.l	Lcurbrk, r0
64cf252584Smiod#endif
65cf252584Smiod	mov.l	@r0, r0
66cf252584Smiod	add	r0, r4
67*fc31befaSmiod	systrap SYS_break
683f373d41Sguenther	bf	1f
6932b97dedSpascal#ifdef __PIC__
70cf252584Smiod	mov.l	Lcurbrk, r0
71cf252584Smiod	mov.l	@(r0, r3), r1
72cf252584Smiod#else
73cf252584Smiod	mov.l	Lcurbrk, r1
74cf252584Smiod#endif
75cf252584Smiod	mov.l	@r1, r0
76cf252584Smiod	add	r0, r2
77cf252584Smiod	rts
78cf252584Smiod	 mov.l	r2, @r1
793f373d41Sguenther1:
80*fc31befaSmiod	SET_ERRNO_AND_RETURN(break)
81cf252584Smiod
82cf252584Smiod	.align	2
83*fc31befaSmiod	systrap_data SYS_break
8432b97dedSpascal#ifdef __PIC__
85cf252584SmiodL_GOT:		.long	_GLOBAL_OFFSET_TABLE_
86b3b7ef2eSguentherLcurbrk:	.long	__curbrk@GOT
87cf252584Smiod#else
88b3b7ef2eSguentherLcurbrk:	.long	__curbrk
89cf252584Smiod#endif
903f373d41Sguenther	SET_ENTRY_SIZE(sbrk)
91