|
Packit |
6c4009 |
/* Assembly macros for RISC-V.
|
|
Packit |
6c4009 |
Copyright (C) 2011-2018
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library. If not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _LINUX_RISCV_SYSDEP_H
|
|
Packit |
6c4009 |
#define _LINUX_RISCV_SYSDEP_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
|
|
Packit |
6c4009 |
#include <tls.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __ASSEMBLER__
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# include <sys/asm.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define ENTRY(name) LEAF(name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define L(label) .L ## label
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Performs a system call, handling errors by setting errno. Linux indicates
|
|
Packit |
6c4009 |
errors by setting a0 to a value between -1 and -4095. */
|
|
Packit |
6c4009 |
# undef PSEUDO
|
|
Packit |
6c4009 |
# define PSEUDO(name, syscall_name, args) \
|
|
Packit |
6c4009 |
.text; \
|
|
Packit |
6c4009 |
.align 2; \
|
|
Packit |
6c4009 |
ENTRY (name); \
|
|
Packit |
6c4009 |
li a7, SYS_ify (syscall_name); \
|
|
Packit |
6c4009 |
scall; \
|
|
Packit |
6c4009 |
li a7, -4096; \
|
|
Packit |
6c4009 |
bgtu a0, a7, .Lsyscall_error ## name;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef PSEUDO_END
|
|
Packit |
6c4009 |
# define PSEUDO_END(sym) \
|
|
Packit |
6c4009 |
SYSCALL_ERROR_HANDLER (sym) \
|
|
Packit |
6c4009 |
ret; \
|
|
Packit |
6c4009 |
END (sym)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# if !IS_IN (libc)
|
|
Packit |
6c4009 |
# if RTLD_PRIVATE_ERRNO
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER(name) \
|
|
Packit |
6c4009 |
.Lsyscall_error ## name: \
|
|
Packit |
6c4009 |
li t1, -4096; \
|
|
Packit |
6c4009 |
neg a0, a0; \
|
|
Packit |
6c4009 |
sw a0, rtld_errno, t1; \
|
|
Packit |
6c4009 |
li a0, -1;
|
|
Packit |
6c4009 |
# elif defined (__PIC__)
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER(name) \
|
|
Packit |
6c4009 |
.Lsyscall_error ## name: \
|
|
Packit |
6c4009 |
la.tls.ie t1, errno; \
|
|
Packit |
6c4009 |
add t1, t1, tp; \
|
|
Packit |
6c4009 |
neg a0, a0; \
|
|
Packit |
6c4009 |
sw a0, 0(t1); \
|
|
Packit |
6c4009 |
li a0, -1;
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER(name) \
|
|
Packit |
6c4009 |
.Lsyscall_error ## name: \
|
|
Packit |
6c4009 |
lui t1, %tprel_hi(errno); \
|
|
Packit |
6c4009 |
add t1, t1, tp, %tprel_add(errno); \
|
|
Packit |
6c4009 |
neg a0, a0; \
|
|
Packit |
6c4009 |
sw a0, %tprel_lo(errno)(t1); \
|
|
Packit |
6c4009 |
li a0, -1;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER(name) \
|
|
Packit |
6c4009 |
.Lsyscall_error ## name: \
|
|
Packit |
6c4009 |
j __syscall_error;
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Performs a system call, not setting errno. */
|
|
Packit |
6c4009 |
# undef PSEUDO_NEORRNO
|
|
Packit |
6c4009 |
# define PSEUDO_NOERRNO(name, syscall_name, args) \
|
|
Packit |
6c4009 |
.align 2; \
|
|
Packit |
6c4009 |
ENTRY (name); \
|
|
Packit |
6c4009 |
li a7, SYS_ify (syscall_name); \
|
|
Packit |
6c4009 |
scall;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef PSEUDO_END_NOERRNO
|
|
Packit |
6c4009 |
# define PSEUDO_END_NOERRNO(name) \
|
|
Packit |
6c4009 |
END (name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef ret_NOERRNO
|
|
Packit |
6c4009 |
# define ret_NOERRNO ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Perfroms a system call, returning the error code. */
|
|
Packit |
6c4009 |
# undef PSEUDO_ERRVAL
|
|
Packit |
6c4009 |
# define PSEUDO_ERRVAL(name, syscall_name, args) \
|
|
Packit |
6c4009 |
PSEUDO_NOERRNO (name, syscall_name, args) \
|
|
Packit |
6c4009 |
neg a0, a0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef PSEUDO_END_ERRVAL
|
|
Packit |
6c4009 |
# define PSEUDO_END_ERRVAL(name) \
|
|
Packit |
6c4009 |
END (name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef ret_ERRVAL
|
|
Packit |
6c4009 |
# define ret_ERRVAL ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* __ASSEMBLER__ */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* In order to get __set_errno() definition in INLINE_SYSCALL. */
|
|
Packit |
6c4009 |
#ifndef __ASSEMBLER__
|
|
Packit |
6c4009 |
# include <errno.h>
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdeps/unix/sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef SYS_ify
|
|
Packit |
6c4009 |
#define SYS_ify(syscall_name) __NR_##syscall_name
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef __ASSEMBLER__
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* List of system calls which are supported as vsyscalls. */
|
|
Packit |
6c4009 |
# define HAVE_CLOCK_GETRES_VSYSCALL 1
|
|
Packit |
6c4009 |
# define HAVE_CLOCK_GETTIME_VSYSCALL 1
|
|
Packit |
6c4009 |
# define HAVE_GETTIMEOFDAY_VSYSCALL 1
|
|
Packit |
6c4009 |
# define HAVE_GETCPU_VSYSCALL 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Define a macro which expands into the inline wrapper code for a system
|
|
Packit |
6c4009 |
call. */
|
|
Packit |
6c4009 |
# undef INLINE_SYSCALL
|
|
Packit |
6c4009 |
# define INLINE_SYSCALL(name, nr, args...) \
|
|
Packit |
6c4009 |
({ INTERNAL_SYSCALL_DECL (err); \
|
|
Packit |
6c4009 |
long int __sys_result = INTERNAL_SYSCALL (name, err, nr, args); \
|
|
Packit |
6c4009 |
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__sys_result, ))) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
__set_errno (INTERNAL_SYSCALL_ERRNO (__sys_result, )); \
|
|
Packit |
6c4009 |
__sys_result = (unsigned long) -1; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
__sys_result; })
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define INTERNAL_SYSCALL_DECL(err) do { } while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define INTERNAL_SYSCALL_ERROR_P(val, err) \
|
|
Packit |
6c4009 |
((unsigned long int) (val) > -4096UL)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define INTERNAL_SYSCALL_ERRNO(val, err) (-val)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define INTERNAL_SYSCALL(name, err, nr, args...) \
|
|
Packit |
6c4009 |
internal_syscall##nr (SYS_ify (name), err, args)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
|
|
Packit |
6c4009 |
internal_syscall##nr (number, err, args)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall0(number, err, dummy...) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0"); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "=r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall1(number, err, arg0) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall2(number, err, arg0, arg1) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r" (__a1) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall3(number, err, arg0, arg1, arg2) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
register long int __a2 asm ("a2") = (long int) (arg2); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r" (__a1), "r" (__a2) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall4(number, err, arg0, arg1, arg2, arg3) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
register long int __a2 asm ("a2") = (long int) (arg2); \
|
|
Packit |
6c4009 |
register long int __a3 asm ("a3") = (long int) (arg3); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r" (__a1), "r" (__a2), "r" (__a3) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall5(number, err, arg0, arg1, arg2, arg3, arg4) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
register long int __a2 asm ("a2") = (long int) (arg2); \
|
|
Packit |
6c4009 |
register long int __a3 asm ("a3") = (long int) (arg3); \
|
|
Packit |
6c4009 |
register long int __a4 asm ("a4") = (long int) (arg4); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r"(__a1), "r"(__a2), "r"(__a3), "r" (__a4) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall6(number, err, arg0, arg1, arg2, arg3, arg4, arg5) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
register long int __a2 asm ("a2") = (long int) (arg2); \
|
|
Packit |
6c4009 |
register long int __a3 asm ("a3") = (long int) (arg3); \
|
|
Packit |
6c4009 |
register long int __a4 asm ("a4") = (long int) (arg4); \
|
|
Packit |
6c4009 |
register long int __a5 asm ("a5") = (long int) (arg5); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r" (__a1), "r" (__a2), "r" (__a3), \
|
|
Packit |
6c4009 |
"r" (__a4), "r" (__a5) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define internal_syscall7(number, err, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
long int _sys_result; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
register long int __a7 asm ("a7") = number; \
|
|
Packit |
6c4009 |
register long int __a0 asm ("a0") = (long int) (arg0); \
|
|
Packit |
6c4009 |
register long int __a1 asm ("a1") = (long int) (arg1); \
|
|
Packit |
6c4009 |
register long int __a2 asm ("a2") = (long int) (arg2); \
|
|
Packit |
6c4009 |
register long int __a3 asm ("a3") = (long int) (arg3); \
|
|
Packit |
6c4009 |
register long int __a4 asm ("a4") = (long int) (arg4); \
|
|
Packit |
6c4009 |
register long int __a5 asm ("a5") = (long int) (arg5); \
|
|
Packit |
6c4009 |
register long int __a6 asm ("a6") = (long int) (arg6); \
|
|
Packit |
6c4009 |
__asm__ volatile ( \
|
|
Packit |
6c4009 |
"scall\n\t" \
|
|
Packit |
6c4009 |
: "+r" (__a0) \
|
|
Packit |
6c4009 |
: "r" (__a7), "r" (__a1), "r" (__a2), "r" (__a3), \
|
|
Packit |
6c4009 |
"r" (__a4), "r" (__a5), "r" (__a6) \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = __a0; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
_sys_result; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define __SYSCALL_CLOBBERS "memory"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
extern long int __syscall_error (long int neg_errno);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* ! __ASSEMBLER__ */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Pointer mangling is not supported. */
|
|
Packit |
6c4009 |
#define PTR_MANGLE(var) (void) (var)
|
|
Packit |
6c4009 |
#define PTR_DEMANGLE(var) (void) (var)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* linux/riscv/sysdep.h */
|