sbrk.S revision 1.23
11.23Schristos/* $NetBSD: sbrk.S,v 1.23 2025/11/06 15:25:18 christos Exp $ */ 21.8Schristos 31.1Scgd/*- 41.1Scgd * Copyright (c) 1990 The Regents of the University of California. 51.1Scgd * All rights reserved. 61.1Scgd * 71.1Scgd * This code is derived from software contributed to Berkeley by 81.1Scgd * William Jolitz. 91.1Scgd * 101.1Scgd * Redistribution and use in source and binary forms, with or without 111.1Scgd * modification, are permitted provided that the following conditions 121.1Scgd * are met: 131.1Scgd * 1. Redistributions of source code must retain the above copyright 141.1Scgd * notice, this list of conditions and the following disclaimer. 151.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 161.1Scgd * notice, this list of conditions and the following disclaimer in the 171.1Scgd * documentation and/or other materials provided with the distribution. 181.17Sagc * 3. Neither the name of the University nor the names of its contributors 191.1Scgd * may be used to endorse or promote products derived from this software 201.1Scgd * without specific prior written permission. 211.1Scgd * 221.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Scgd * SUCH DAMAGE. 331.2Sjtc * 341.2Sjtc * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 351.1Scgd */ 361.1Scgd 371.8Schristos#include <machine/asm.h> 381.1Scgd#if defined(SYSLIBC_SCCS) && !defined(lint) 391.23Schristos RCSID("$NetBSD: sbrk.S,v 1.23 2025/11/06 15:25:18 christos Exp $") 401.1Scgd#endif /* SYSLIBC_SCCS and not lint */ 411.1Scgd 421.1Scgd#include "SYS.h" 431.1Scgd 441.1Scgd .globl _end 451.9Skleink .globl CURBRK 461.1Scgd 471.14Skleink#ifdef WEAK_ALIAS 481.14SkleinkWEAK_ALIAS(sbrk, _sbrk) 491.14Skleink#endif 501.14Skleink 511.1Scgd .data 521.9SkleinkCURBRK: .long _end 531.1Scgd .text 541.1Scgd 551.13SkleinkENTRY(_sbrk) 561.21Sjoerg#ifdef __PIC__ 571.1Scgd movl 4(%esp),%ecx 581.1Scgd PIC_PROLOGUE 591.9Skleink movl PIC_GOT(CURBRK),%edx 601.5Smycroft PIC_EPILOGUE 611.1Scgd movl (%edx),%eax 621.19Srmind test %ecx,%ecx 631.19Srmind jz out 641.12Smycroft addl %eax,%ecx 651.12Smycroft movl %ecx,4(%esp) 661.18Sad OSYSTRAP(break) /* don't clobber %ecx */ 671.5Smycroft jc err 681.1Scgd PIC_PROLOGUE 691.9Skleink movl PIC_GOT(CURBRK),%edx 701.5Smycroft PIC_EPILOGUE 711.1Scgd movl (%edx),%eax 721.12Smycroft movl %ecx,(%edx) 731.19Srmindout: 741.1Scgd ret 751.1Scgderr: 761.23Schristos _SYSCALL_ERR 771.1Scgd#else 781.1Scgd movl 4(%esp),%ecx 791.9Skleink movl CURBRK,%eax 801.19Srmind test %ecx,%ecx 811.19Srmind jz out 821.1Scgd addl %eax,4(%esp) 831.18Sad OSYSTRAP(break) /* don't clobber %ecx */ 841.5Smycroft jc err 851.9Skleink movl CURBRK,%eax 861.9Skleink addl %ecx,CURBRK 871.19Srmindout: 881.1Scgd ret 891.1Scgderr: 901.23Schristos _SYSCALL_ERR 911.1Scgd#endif 921.22SuebayasiEND(_sbrk) 93