sparc64: add basic support
[uclibc-ng.git] / libc / sysdeps / linux / sparc64 / brk.S
blob2d857af6c37dc7c319e452512cb8bdc32627bb33
1 /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
2    Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
18 /* __brk is a special syscall under Linux since it never returns an
19    error.  Instead, the error condition is indicated by returning the old
20    break value (instead of the new, requested one).  */
22 #include <sysdep.h>
23 #define _ERRNO_H
24 #include <bits/errno.h>
26 #ifdef __PIC__
27 .section .bss
28         .align 8
29         .globl __curbrk
30 __curbrk: .skip 8
31         .type __curbrk,@object
32         .size __curbrk,8
33 #else
34 .common __curbrk, 8, 8
35 #endif
37         .text
38 ENTRY (__brk)
39         save    %sp, -192, %sp
40         cfi_def_cfa_register(%fp)
41         cfi_window_save
42         cfi_register(%o7, %i7)
43 #ifdef __PIC__
44         SETUP_PIC_REG(l7)
45 #endif
47         LOADSYSCALL(brk)
48         mov     %i0, %o0
50         ta      0x6d
52         /* All the ways we can fail... */
53         bcs,pn  %xcc, .Lerr1
54          nop
55         brz,pt  %i0, .Lok
56          subcc  %i0, %o0, %g0
57         bne,pn  %xcc, .Lerr0
58          nop
60         /* Update __curbrk and return cleanly.  */
61 .Lok:
62 #ifndef __PIC__
63         sethi   %hi(__curbrk), %g1
64         or      %g1, %lo(__curbrk), %g1
65 #else
66         sethi   %gdop_hix22(__curbrk), %g1
67         xor     %g1, %gdop_lox10(__curbrk), %g1
68         ldx     [%l7 + %g1], %g1, %gdop(__curbrk)
69 #endif
70         stx     %o0, [%g1]
71         mov     %g0, %i0
73         /* Don't use "ret" cause the preprocessor will eat it.  */
74         jmpl    %i7+8, %g0
75          restore
77         /* What a horrible way to die.  */
78 .Lerr0: set     ENOMEM, %o0
79 .Lerr1:
80 #ifndef _LIBC_REENTRANT
81 #ifndef __PIC__
82         sethi   %hi(errno), %g1
83         or      %g1, %lo(errno), %g1
84 #else
85         sethi   %gdop_hix22(errno), %g1
86         xor     %g1, %gdop_lox10(errno), %g1
87         ldx     [%l7 + %g1], %g1, %gdop(errno)
88 #endif
89         st      %o0, [%g1]
90 #else
91         call    HIDDEN_JUMPTARGET(__errno_location)
92          mov    %o0,%l1
93         st      %l1, [%o0]
94 #endif
95         sub     %g0, 1, %i0
96         jmpl    %i7+8, %g0
97          restore
98 END (__brk)
100 weak_alias (__brk, brk)
101 libc_hidden_def(brk)