sbrk.S revision 115279
1295263Sgjb/*- 2295263Sgjb * Copyright (c) 1990 The Regents of the University of California. 3295263Sgjb * All rights reserved. 4295263Sgjb * 5294509Sgjb * This code is derived from software contributed to Berkeley by 6294509Sgjb * William Jolitz. 7294509Sgjb * 8295262Sgjb * Redistribution and use in source and binary forms, with or without 9294509Sgjb * modification, are permitted provided that the following conditions 10294509Sgjb * are met: 11294509Sgjb * 1. Redistributions of source code must retain the above copyright 12294509Sgjb * notice, this list of conditions and the following disclaimer. 13294509Sgjb * 2. Redistributions in binary form must reproduce the above copyright 14294509Sgjb * notice, this list of conditions and the following disclaimer in the 15294509Sgjb * documentation and/or other materials provided with the distribution. 16294509Sgjb * 3. All advertising materials mentioning features or use of this software 17294509Sgjb * must display the following acknowledgement: 18295225Sgjb * This product includes software developed by the University of 19295262Sgjb * California, Berkeley and its contributors. 20295225Sgjb * 4. Neither the name of the University nor the names of its contributors 21295225Sgjb * may be used to endorse or promote products derived from this software 22295225Sgjb * without specific prior written permission. 23295225Sgjb * 24295225Sgjb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#if defined(SYSLIBC_SCCS) && !defined(lint) 38 .asciz "@(#)sbrk.s 5.1 (Berkeley) 4/23/90" 39#endif /* SYSLIBC_SCCS and not lint */ 40#include <machine/asm.h> 41__FBSDID("$FreeBSD: head/lib/libc/amd64/sys/sbrk.S 115279 2003-05-24 17:35:23Z peter $"); 42 43#include "SYS.h" 44 45 .globl CNAME(_end) 46 .globl HIDENAME(minbrk) 47 .globl HIDENAME(curbrk) 48 49 .data 50HIDENAME(minbrk): .quad CNAME(_end) 51HIDENAME(curbrk): .quad CNAME(_end) 52 .text 53 54ENTRY(sbrk) 55 pushq %rdi 56 movq %rdi,%rcx 57#ifdef PIC 58 movq PIC_GOT(HIDENAME(curbrk)),%rdx 59 movq (%rdx),%rax 60#else 61 movq HIDENAME(curbrk)(%rip),%rax 62#endif 63 testq %rcx,%rcx 64 jz back 65 addq %rax,%rdi 66 mov $SYS_break,%eax 67 KERNCALL 68 jb err 69#ifdef PIC 70 movq PIC_GOT(HIDENAME(curbrk)),%rdx 71 movq (%rdx),%rax 72#else 73 movq HIDENAME(curbrk)(%rip),%rax 74#endif 75 movq 0(%rsp), %rcx 76#ifdef PIC 77 addq %rcx,(%rdx) 78#else 79 addq %rcx,HIDENAME(curbrk)(%rip) 80#endif 81back: 82 addq $8, %rsp 83 ret 84err: 85 addq $8, %rsp 86#ifdef PIC 87 movq PIC_GOT(HIDENAME(cerror)),%rdx 88 jmp *%rdx 89#else 90 jmp HIDENAME(cerror) 91#endif 92