1*4d12bfcdSjoerg/* $NetBSD: brk.S,v 1.16 2013/09/12 15:36:16 joerg Exp $ */ 21394f01bSchristos 30b9f5089Scgd/* 40b9f5089Scgd * Copyright (c) 1992, 1993 50b9f5089Scgd * The Regents of the University of California. All rights reserved. 60b9f5089Scgd * 70b9f5089Scgd * This software was developed by the Computer Systems Engineering group 80b9f5089Scgd * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 90b9f5089Scgd * contributed to Berkeley. 100b9f5089Scgd * 110b9f5089Scgd * Redistribution and use in source and binary forms, with or without 120b9f5089Scgd * modification, are permitted provided that the following conditions 130b9f5089Scgd * are met: 140b9f5089Scgd * 1. Redistributions of source code must retain the above copyright 150b9f5089Scgd * notice, this list of conditions and the following disclaimer. 160b9f5089Scgd * 2. Redistributions in binary form must reproduce the above copyright 170b9f5089Scgd * notice, this list of conditions and the following disclaimer in the 180b9f5089Scgd * documentation and/or other materials provided with the distribution. 19eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors 200b9f5089Scgd * may be used to endorse or promote products derived from this software 210b9f5089Scgd * without specific prior written permission. 220b9f5089Scgd * 230b9f5089Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 240b9f5089Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 250b9f5089Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 260b9f5089Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 270b9f5089Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 280b9f5089Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 290b9f5089Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 300b9f5089Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 310b9f5089Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 320b9f5089Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 330b9f5089Scgd * SUCH DAMAGE. 340b9f5089Scgd * 350b9f5089Scgd * from: Header: brk.s,v 1.3 92/06/25 12:56:05 mccanne Exp 360b9f5089Scgd */ 370b9f5089Scgd 381394f01bSchristos#include <machine/asm.h> 391394f01bSchristos#if defined(SYSLIBC_SCCS) && !defined(lint) 401394f01bSchristos#if 0 410b9f5089Scgd .asciz "@(#)brk.s 8.1 (Berkeley) 6/4/93" 421394f01bSchristos#else 43*4d12bfcdSjoerg RCSID("$NetBSD: brk.S,v 1.16 2013/09/12 15:36:16 joerg Exp $") 441394f01bSchristos#endif 451394f01bSchristos#endif /* SYSLIBC_SCCS and not lint */ 460b9f5089Scgd 470b9f5089Scgd#include "SYS.h" 480b9f5089Scgd 49dccf2a15Skleink .globl CURBRK 506348b7d5Skleink .globl _C_LABEL(__minbrk) 5115fb0e43Skleink .globl _end 520b9f5089Scgd 5303f996bdSkleink#ifdef WEAK_ALIAS 5403f996bdSkleinkWEAK_ALIAS(brk, _brk) 5503f996bdSkleink#endif 5603f996bdSkleink 570b9f5089Scgd .data 586348b7d5Skleink_C_LABEL(__minbrk): 5915fb0e43Skleink .long _end ! lower brk limit; also for gmon code 600b9f5089Scgd .text 610b9f5089Scgd 6203f996bdSkleinkENTRY(_brk) 63*4d12bfcdSjoerg#ifdef __PIC__ 64e0bf9676Spk PIC_PROLOGUE(%o5,%o4) 65a34b3f87Suwe set _C_LABEL(__minbrk), %o4 66a34b3f87Suwe ld [%o5 + %o4], %o4 67e0bf9676Spk ld [%o4], %o1 ! %o1 = minbrk 68e0bf9676Spk cmp %o1, %o0 ! if (minbrk > %o0) 69269c3e3dSmartin bgu,a 0f 70e0bf9676Spk mov %o1, %o0 ! %o0 = minbrk 71e0bf9676Spk0: 72e0bf9676Spk mov %o0, %o2 ! save argument to syscall 73e0bf9676Spk mov SYS_break, %g1 74e0bf9676Spk t ST_SYSCALL 75531d4686Snakayama set CURBRK, %o3 76e0bf9676Spk bcc,a 1f 77531d4686Snakayama ld [%o5 + %o3], %o4 78e0bf9676Spk ERROR() 79e0bf9676Spk1: 80e0bf9676Spk retl ! success, return 0 & record new break 81531d4686Snakayama st %o2, [%o4] 82e0bf9676Spk#else 836348b7d5Skleink sethi %hi(_C_LABEL(__minbrk)), %o1 ! %o1 = minbrk 846348b7d5Skleink ld [%o1 + %lo(_C_LABEL(__minbrk))], %o1 850b9f5089Scgd cmp %o1, %o0 ! if (minbrk > %o0) 86269c3e3dSmartin bgu,a 0f 870b9f5089Scgd mov %o1, %o0 ! %o0 = minbrk 880b9f5089Scgd0: 890b9f5089Scgd mov %o0, %o2 ! save argument to syscall 900b9f5089Scgd mov SYS_break, %g1 910b9f5089Scgd t ST_SYSCALL 920b9f5089Scgd bcc,a 1f 93dccf2a15Skleink sethi %hi(CURBRK), %g1 940b9f5089Scgd ERROR() 950b9f5089Scgd1: 960b9f5089Scgd retl ! success, return 0 & record new break 97dccf2a15Skleink st %o2, [%g1 + %lo(CURBRK)] 98e0bf9676Spk#endif 99