initial commit
[glibc.git] / sysdeps / unix / sysv / linux / loongarch / sysdep.S
1 /* syscall error handlers
2 Copyright (C) 2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <sysdep.h>
20
21 #if IS_IN (libc)
22 # define errno __libc_errno
23 #endif
24
25 ENTRY (__syscall_error)
26 /* Fall through to __syscall_set_errno */
27 END (__syscall_error)
28
29 /* Non-standard calling convention: argument in a0, return address in t0,
30 and clobber only t1.
31 */
32 ENTRY (__syscall_set_errno)
33
34 /* We got here because a0 < 0, but only codes in the range [-4095, -1]
35 represent errors. Otherwise, just return the result normally.
36 */
37 li.d t1, -4096
38 bgeu t1, a0, L (out)
39 sub.w a0, zero, a0
40 #if RTLD_PRIVATE_ERRNO
41 la t1, rtld_errno
42 #elif defined(__PIC__)
43 la.tls.ie t1, errno
44 add.d t1, tp, t1
45 #else
46 la.tls.le t1, errno
47 add.d t1, tp, t1
48 #endif
49 st.w a0, t1, 0
50 li.d a0, -1
51 L (out):
52 ret
53 END (__syscall_set_errno)