xref: /dragonfly/lib/libc/x86_64/sys/fake_sbrk.S (revision 8618d94a)
1*8618d94aSMatthew Dillon/*-
2*8618d94aSMatthew Dillon * Copyright (c) 1990 The Regents of the University of California.
3*8618d94aSMatthew Dillon * All rights reserved.
4*8618d94aSMatthew Dillon *
5*8618d94aSMatthew Dillon * This code is derived from software contributed to Berkeley by
6*8618d94aSMatthew Dillon * William Jolitz.
7*8618d94aSMatthew Dillon *
8*8618d94aSMatthew Dillon * Redistribution and use in source and binary forms, with or without
9*8618d94aSMatthew Dillon * modification, are permitted provided that the following conditions
10*8618d94aSMatthew Dillon * are met:
11*8618d94aSMatthew Dillon * 1. Redistributions of source code must retain the above copyright
12*8618d94aSMatthew Dillon *    notice, this list of conditions and the following disclaimer.
13*8618d94aSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
14*8618d94aSMatthew Dillon *    notice, this list of conditions and the following disclaimer in the
15*8618d94aSMatthew Dillon *    documentation and/or other materials provided with the distribution.
16*8618d94aSMatthew Dillon * 3. Neither the name of the University nor the names of its contributors
17*8618d94aSMatthew Dillon *    may be used to endorse or promote products derived from this software
18*8618d94aSMatthew Dillon *    without specific prior written permission.
19*8618d94aSMatthew Dillon *
20*8618d94aSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21*8618d94aSMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*8618d94aSMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*8618d94aSMatthew Dillon * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24*8618d94aSMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*8618d94aSMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*8618d94aSMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*8618d94aSMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*8618d94aSMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*8618d94aSMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*8618d94aSMatthew Dillon * SUCH DAMAGE.
31*8618d94aSMatthew Dillon *
32*8618d94aSMatthew Dillon * @(#)sbrk.s	5.1 (Berkeley) 4/23/90
33*8618d94aSMatthew Dillon * $FreeBSD: src/lib/libc/amd64/sys/sbrk.S,v 1.15 2008/11/02 01:10:54 peter Exp $
34*8618d94aSMatthew Dillon */
35*8618d94aSMatthew Dillon
36*8618d94aSMatthew Dillon#include <machine/asm.h>
37*8618d94aSMatthew Dillon#include "SYS.h"
38*8618d94aSMatthew Dillon
39*8618d94aSMatthew Dillon	.globl	CNAME(_end)
40*8618d94aSMatthew Dillon	.globl	HIDENAME(minbrk)
41*8618d94aSMatthew Dillon	.globl	HIDENAME(curbrk)
42*8618d94aSMatthew Dillon
43*8618d94aSMatthew Dillon	.data
44*8618d94aSMatthew DillonHIDENAME(minbrk):	.quad	CNAME(_end)
45*8618d94aSMatthew DillonHIDENAME(curbrk):	.quad	CNAME(_end)
46*8618d94aSMatthew Dillon	.text
47*8618d94aSMatthew Dillon
48*8618d94aSMatthew DillonENTRY(fake_sbrk)
49*8618d94aSMatthew Dillon	pushq	%rdi
50*8618d94aSMatthew Dillon	movq	%rdi,%rcx
51*8618d94aSMatthew Dillon#ifdef PIC
52*8618d94aSMatthew Dillon	movq	PIC_GOT(HIDENAME(curbrk)),%rdx
53*8618d94aSMatthew Dillon	movq	(%rdx),%rax
54*8618d94aSMatthew Dillon#else
55*8618d94aSMatthew Dillon	movq	HIDENAME(curbrk)(%rip),%rax
56*8618d94aSMatthew Dillon#endif
57*8618d94aSMatthew Dillon	testq	%rcx,%rcx
58*8618d94aSMatthew Dillon	jz	back
59*8618d94aSMatthew Dillon	addq	%rax,%rdi
60*8618d94aSMatthew Dillon	mov	$SYS_break,%eax
61*8618d94aSMatthew Dillon	KERNCALL
62*8618d94aSMatthew Dillon	jb	err
63*8618d94aSMatthew Dillon#ifdef PIC
64*8618d94aSMatthew Dillon	movq	PIC_GOT(HIDENAME(curbrk)),%rdx
65*8618d94aSMatthew Dillon	movq	(%rdx),%rax
66*8618d94aSMatthew Dillon#else
67*8618d94aSMatthew Dillon	movq	HIDENAME(curbrk)(%rip),%rax
68*8618d94aSMatthew Dillon#endif
69*8618d94aSMatthew Dillon	movq	0(%rsp), %rcx
70*8618d94aSMatthew Dillon#ifdef PIC
71*8618d94aSMatthew Dillon	addq	%rcx,(%rdx)
72*8618d94aSMatthew Dillon#else
73*8618d94aSMatthew Dillon	addq	%rcx,HIDENAME(curbrk)(%rip)
74*8618d94aSMatthew Dillon#endif
75*8618d94aSMatthew Dillonback:
76*8618d94aSMatthew Dillon	addq	$8, %rsp
77*8618d94aSMatthew Dillon	ret
78*8618d94aSMatthew Dillonerr:
79*8618d94aSMatthew Dillon	addq	$8, %rsp
80*8618d94aSMatthew Dillon#ifdef PIC
81*8618d94aSMatthew Dillon	movq	PIC_GOT(HIDENAME(cerror)),%rdx
82*8618d94aSMatthew Dillon	jmp	*%rdx
83*8618d94aSMatthew Dillon#else
84*8618d94aSMatthew Dillon	jmp	HIDENAME(cerror)
85*8618d94aSMatthew Dillon#endif
86*8618d94aSMatthew DillonEND(fake_sbrk)
87*8618d94aSMatthew Dillon
88*8618d94aSMatthew Dillon	.section .note.GNU-stack,"",%progbits
89