1/* $OpenBSD: sbrk.S,v 1.5 2012/08/22 17:19:34 pascal Exp $ */ 2/* $NetBSD: sbrk.S,v 1.7 2003/08/07 16:42:05 agc Exp $ */ 3 4/*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 33 */ 34 35#include "SYS.h" 36 37 .globl _C_LABEL(end) 38 39#ifdef WEAK_ALIAS 40WEAK_ALIAS(sbrk, _sbrk) 41#endif 42 43 .data 44 .align 0 45 .globl CURBRK 46 .type CURBRK,#object 47 .globl minbrk 48 .type minbrk,#object 49CURBRK: 50 .word _C_LABEL(end) 51_ASM_LABEL(minbrk): 52 .word _C_LABEL(end) 53 54/* 55 * Change the data segment size 56 */ 57SYSENTRY(_sbrk) 58#ifdef __PIC__ 59 /* Setup the GOT */ 60 ldr r3, .Lgot 61 ldr r2, .Lcurbrk 62.L1: 63 add r3, pc, r3 64 ldr r2, [r3, r2] 65#else 66 ldr r2, .Lcurbrk 67#endif 68 /* Get the current brk address */ 69 ldr r1, [r2] 70 71 /* Calculate new value */ 72 mov r3, r0 73 add r0, r0, r1 74 SYSTRAP(break) 75 bcs PIC_SYM(CERROR, PLT) 76 77 /* Store new curbrk value */ 78 ldr r0, [r2] 79 add r1, r0, r3 80 str r1, [r2] 81 82 /* Return old curbrk value */ 83 mov r15, r14 84 85 .align 0 86#ifdef __PIC__ 87.Lgot: 88 .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (.L1+8) 89#endif 90.Lcurbrk: 91 .word PIC_SYM(CURBRK, GOT) 92