xref: /openbsd-src/lib/libc/arch/sh/sys/brk.S (revision fc31befaf105b97a112f7671f6f1ed3695619019)
1*fc31befaSmiod/*	$OpenBSD: brk.S,v 1.10 2024/03/27 20:03:29 miod Exp $	*/
2cf252584Smiod/*	$NetBSD: brk.S,v 1.10 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: @(#)brk.s	5.2 (Berkeley) 12/17/90
36cf252584Smiod */
37cf252584Smiod
38cf252584Smiod#include "SYS.h"
39cf252584Smiod
403f373d41Sguenther	.weak	brk
41cf252584Smiod
42cf252584Smiod	.data
43cf252584Smiod	.align	2
44b3b7ef2eSguenther__minbrk:
450ee2ce67Sguenther	.long	_end
463f373d41Sguenther	.size	__minbrk, . - __minbrk
473f373d41Sguenther	.type	__minbrk,@object
48cf252584Smiod
49cf252584Smiod	.text
50cf252584Smiod
513f373d41SguentherENTRY(brk)
5232b97dedSpascal#ifdef __PIC__
53cf252584Smiod	mova	L_GOT, r0
54cf252584Smiod	mov.l	L_GOT, r2
55cf252584Smiod	add	r0, r2
56cf252584Smiod	mov.l	Lminbrk, r0
57cf252584Smiod	mov.l	@(r0, r2), r0
58cf252584Smiod	mov.l	@r0, r0
59cf252584Smiod#else
60cf252584Smiod	mov.l	Lminbrk, r0
61cf252584Smiod	mov.l	@r0, r0
62cf252584Smiod#endif
63cf252584Smiod	cmp/hs	r4, r0
64cf252584Smiod	bf	1f
65cf252584Smiod	mov	r0, r4
66cf252584Smiod1:
67*fc31befaSmiod	systrap SYS_break
683f373d41Sguenther	bf	2f
6932b97dedSpascal#ifdef __PIC__
70cf252584Smiod	mov.l	Lcurbrk, r0
71cf252584Smiod	mov.l	@(r0, r2), r1
72cf252584Smiod	xor	r0, r0
73cf252584Smiod#else
74cf252584Smiod	xor	r0, r0
75cf252584Smiod	mov.l	Lcurbrk, r1
76cf252584Smiod#endif
77cf252584Smiod	rts
78cf252584Smiod	 mov.l	r4, @r1
793f373d41Sguenther2:
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_
86b3b7ef2eSguentherLminbrk:	.long	__minbrk@GOT
87b3b7ef2eSguentherLcurbrk:	.long	__curbrk@GOT
88cf252584Smiod#else
89b3b7ef2eSguentherLminbrk:	.long	__minbrk
90b3b7ef2eSguentherLcurbrk:	.long	__curbrk
91cf252584Smiod#endif
923f373d41Sguenther	SET_ENTRY_SIZE(brk)
93