xref: /openbsd-src/lib/libc/arch/arm/sys/brk.S (revision 8162193374858e8d7dceca506657f13b21b8be44)
1*81621933Sguenther/*	$OpenBSD: brk.S,v 1.13 2022/12/08 01:25:43 guenther Exp $	*/
2fe62ce8dSdrahn/*	$NetBSD: brk.S,v 1.7 2003/12/26 11:23:44 martin Exp $	*/
3d987040fSdrahn
4d987040fSdrahn/*-
5d987040fSdrahn * Copyright (c) 1990 The Regents of the University of California.
6d987040fSdrahn * All rights reserved.
7d987040fSdrahn *
8d987040fSdrahn * Redistribution and use in source and binary forms, with or without
9d987040fSdrahn * modification, are permitted provided that the following conditions
10d987040fSdrahn * are met:
11d987040fSdrahn * 1. Redistributions of source code must retain the above copyright
12d987040fSdrahn *    notice, this list of conditions and the following disclaimer.
13d987040fSdrahn * 2. Redistributions in binary form must reproduce the above copyright
14d987040fSdrahn *    notice, this list of conditions and the following disclaimer in the
15d987040fSdrahn *    documentation and/or other materials provided with the distribution.
16d987040fSdrahn * 3. Neither the name of the University nor the names of its contributors
17d987040fSdrahn *    may be used to endorse or promote products derived from this software
18d987040fSdrahn *    without specific prior written permission.
19d987040fSdrahn *
20d987040fSdrahn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21d987040fSdrahn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22d987040fSdrahn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23d987040fSdrahn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24d987040fSdrahn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25d987040fSdrahn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26d987040fSdrahn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27d987040fSdrahn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28d987040fSdrahn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29d987040fSdrahn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30d987040fSdrahn * SUCH DAMAGE.
31d987040fSdrahn *
32d987040fSdrahn *	from: @(#)brk.s	5.2 (Berkeley) 12/17/90
33d987040fSdrahn */
34d987040fSdrahn
35d987040fSdrahn#include "SYS.h"
36d987040fSdrahn
37*81621933Sguenther	.globl	_end
38b3b7ef2eSguenther	.globl	__curbrk
39d987040fSdrahn
40d987040fSdrahn	.data
4171334cb4Skettenis	.align	2
42b3b7ef2eSguenther	.type	__minbrk,#object
43b3b7ef2eSguenther__minbrk:
44*81621933Sguenther	.word	_end
453f373d41Sguenther	END(__minbrk)
463f373d41Sguenther
47d987040fSdrahn/*
48d987040fSdrahn * Change the data segment size
49d987040fSdrahn */
5042d2c245SguentherENTRY_NB(brk)
5132b97dedSpascal#ifdef __PIC__
52d987040fSdrahn	/* Setup the GOT */
53d987040fSdrahn	ldr	r3, .Lgot
54d987040fSdrahn	ldr	r1, .Lminbrk
559e101d88Sdrahn.L1:
569e101d88Sdrahn	add	r3, pc, r3
57d987040fSdrahn	ldr	r1, [r3, r1]
58d987040fSdrahn#else
59d987040fSdrahn	ldr	r1, .Lminbrk
60d987040fSdrahn#endif
61d987040fSdrahn	/* Get the minimum allowable brk address */
62d987040fSdrahn	ldr	r1, [r1]
63d987040fSdrahn
64d987040fSdrahn	/*
65d987040fSdrahn	 * Valid the address specified and set to the minimum
66d987040fSdrahn	 * if the address is below minbrk.
67d987040fSdrahn	 */
68d987040fSdrahn	cmp	r0, r1
69fe62ce8dSdrahn	movcc	r0, r1
70d987040fSdrahn	mov	r2, r0
71d987040fSdrahn	SYSTRAP(break)
7238848718Sguenther	bcs	CERROR
73d987040fSdrahn
7432b97dedSpascal#ifdef __PIC__
75d987040fSdrahn	ldr	r1, .Lcurbrk
76d987040fSdrahn	ldr	r1, [r3, r1]
77d987040fSdrahn#else
78d987040fSdrahn	ldr	r1, .Lcurbrk
79d987040fSdrahn#endif
80d987040fSdrahn	/* Store the new address in curbrk */
81d987040fSdrahn	str	r2, [r1]
82d987040fSdrahn
83d987040fSdrahn	/* Return 0 for success */
84d987040fSdrahn	mov	r0, #0x00000000
85d987040fSdrahn	mov	r15, r14
86d987040fSdrahn
87d987040fSdrahn	.align	2
8832b97dedSpascal#ifdef __PIC__
89d987040fSdrahn.Lgot:
90*81621933Sguenther	.word	_GLOBAL_OFFSET_TABLE_ - (.L1+8)
91d987040fSdrahn#endif
92d987040fSdrahn.Lminbrk:
93b3b7ef2eSguenther	.word	PIC_SYM(__minbrk, GOT)
94d987040fSdrahn.Lcurbrk:
95b3b7ef2eSguenther	.word	PIC_SYM(__curbrk, GOT)
963f373d41SguentherEND(brk)
974e0d3631Sjca	.weak	brk
98