|
Packit |
6c4009 |
/* Assembler macros for Nios II.
|
|
Packit |
6c4009 |
Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
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_NIOS2_SYSDEP_H
|
|
Packit |
6c4009 |
#define _LINUX_NIOS2_SYSDEP_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <asm/unistd.h>
|
|
Packit |
6c4009 |
#include <sysdeps/unix/sysdep.h>
|
|
Packit |
6c4009 |
#include <sysdeps/nios2/sysdep.h>
|
|
Packit |
6c4009 |
#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* For RTLD_PRIVATE_ERRNO. */
|
|
Packit |
6c4009 |
#include <dl-sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <tls.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* For Linux we can use the system call table in the header file
|
|
Packit |
6c4009 |
/usr/include/asm/unistd.h
|
|
Packit |
6c4009 |
of the kernel. But these symbols do not follow the SYS_* syntax
|
|
Packit |
6c4009 |
so we have to redefine the `SYS_ify' macro here. */
|
|
Packit |
6c4009 |
#undef SYS_ify
|
|
Packit |
6c4009 |
#define SYS_ify(syscall_name) __NR_##syscall_name
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __ASSEMBLER__
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define SYSCALL_ERROR_LABEL __local_syscall_error
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef PSEUDO
|
|
Packit |
6c4009 |
#define PSEUDO(name, syscall_name, args) \
|
|
Packit |
6c4009 |
ENTRY (name) \
|
|
Packit |
6c4009 |
DO_CALL (syscall_name, args) \
|
|
Packit |
6c4009 |
bne r7, zero, SYSCALL_ERROR_LABEL; \
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef PSEUDO_END
|
|
Packit |
6c4009 |
#define PSEUDO_END(name) \
|
|
Packit |
6c4009 |
SYSCALL_ERROR_HANDLER \
|
|
Packit |
6c4009 |
END (name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef PSEUDO_NOERRNO
|
|
Packit |
6c4009 |
#define PSEUDO_NOERRNO(name, syscall_name, args) \
|
|
Packit |
6c4009 |
ENTRY (name) \
|
|
Packit |
6c4009 |
DO_CALL (syscall_name, args)
|
|
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 |
#undef DO_CALL
|
|
Packit |
6c4009 |
#define DO_CALL(syscall_name, args) \
|
|
Packit |
6c4009 |
DOARGS_##args \
|
|
Packit |
6c4009 |
movi r2, SYS_ify(syscall_name); \
|
|
Packit |
6c4009 |
trap;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined(__PIC__) || defined(PIC)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# if RTLD_PRIVATE_ERRNO
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER \
|
|
Packit |
6c4009 |
SYSCALL_ERROR_LABEL: \
|
|
Packit |
6c4009 |
nextpc r3; \
|
|
Packit |
6c4009 |
1: \
|
|
Packit |
6c4009 |
movhi r8, %hiadj(rtld_errno - 1b); \
|
|
Packit |
6c4009 |
addi r8, r8, %lo(rtld_errno - 1b); \
|
|
Packit |
6c4009 |
add r3, r3, r8; \
|
|
Packit |
6c4009 |
stw r2, 0(r3); \
|
|
Packit |
6c4009 |
movi r2, -1; \
|
|
Packit |
6c4009 |
ret;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# if IS_IN (libc)
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_ERRNO __libc_errno
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_ERRNO errno
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
# define SYSCALL_ERROR_HANDLER \
|
|
Packit |
6c4009 |
SYSCALL_ERROR_LABEL: \
|
|
Packit |
6c4009 |
nextpc r3; \
|
|
Packit |
6c4009 |
1: \
|
|
Packit |
6c4009 |
movhi r8, %hiadj(_gp_got - 1b); \
|
|
Packit |
6c4009 |
addi r8, r8, %lo(_gp_got - 1b); \
|
|
Packit |
6c4009 |
add r3, r3, r8; \
|
|
Packit |
6c4009 |
ldw r3, %tls_ie(SYSCALL_ERROR_ERRNO)(r3); \
|
|
Packit |
6c4009 |
add r3, r23, r3; \
|
|
Packit |
6c4009 |
stw r2, 0(r3); \
|
|
Packit |
6c4009 |
movi r2, -1; \
|
|
Packit |
6c4009 |
ret;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We can use a single error handler in the static library. */
|
|
Packit |
6c4009 |
#define SYSCALL_ERROR_HANDLER \
|
|
Packit |
6c4009 |
SYSCALL_ERROR_LABEL: \
|
|
Packit |
6c4009 |
jmpi __syscall_error;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define DOARGS_0 /* nothing */
|
|
Packit |
6c4009 |
#define DOARGS_1 /* nothing */
|
|
Packit |
6c4009 |
#define DOARGS_2 /* nothing */
|
|
Packit |
6c4009 |
#define DOARGS_3 /* nothing */
|
|
Packit |
6c4009 |
#define DOARGS_4 /* nothing */
|
|
Packit |
6c4009 |
#define DOARGS_5 ldw r8, 0(sp);
|
|
Packit |
6c4009 |
#define DOARGS_6 ldw r9, 4(sp); ldw r8, 0(sp);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The function has to return the error code. */
|
|
Packit |
6c4009 |
#undef PSEUDO_ERRVAL
|
|
Packit |
6c4009 |
#define PSEUDO_ERRVAL(name, syscall_name, args) \
|
|
Packit |
6c4009 |
ENTRY (name) \
|
|
Packit |
6c4009 |
DO_CALL (syscall_name, args)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef PSEUDO_END_ERRVAL
|
|
Packit |
6c4009 |
#define PSEUDO_END_ERRVAL(name) \
|
|
Packit |
6c4009 |
END (name)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define ret_ERRVAL ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else /* __ASSEMBLER__ */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* In order to get __set_errno() definition in INLINE_SYSCALL. */
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Previously Nios2 used the generic version without the libc_hidden_def
|
|
Packit |
6c4009 |
which lead in a non existent __send symbol in libc.so. */
|
|
Packit |
6c4009 |
# undef HAVE_INTERNAL_SEND_SYMBOL
|
|
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 |
unsigned int result_var = INTERNAL_SYSCALL (name, err, nr, args); \
|
|
Packit |
6c4009 |
if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
__set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
|
|
Packit |
6c4009 |
result_var = -1L; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
(int) result_var; })
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL_DECL
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL_DECL(err) unsigned int err __attribute__((unused))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL_ERROR_P
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL_ERROR_P(val, err) ((void) (val), (unsigned int) (err))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL_ERRNO
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL_ERRNO(val, err) ((void) (err), val)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL_RAW
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
|
|
Packit |
6c4009 |
({ unsigned int _sys_result; \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
/* Load argument values in temporary variables
|
|
Packit |
6c4009 |
to perform side effects like function calls
|
|
Packit |
6c4009 |
before the call-used registers are set. */ \
|
|
Packit |
6c4009 |
LOAD_ARGS_##nr (args) \
|
|
Packit |
6c4009 |
LOAD_REGS_##nr \
|
|
Packit |
6c4009 |
register int _r2 asm ("r2") = (int)(name); \
|
|
Packit |
6c4009 |
register int _err asm ("r7"); \
|
|
Packit |
6c4009 |
asm volatile ("trap" \
|
|
Packit |
6c4009 |
: "+r" (_r2), "=r" (_err) \
|
|
Packit |
6c4009 |
: ASM_ARGS_##nr \
|
|
Packit |
6c4009 |
: __SYSCALL_CLOBBERS); \
|
|
Packit |
6c4009 |
_sys_result = _r2; \
|
|
Packit |
6c4009 |
err = _err; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
(int) _sys_result; })
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL(name, err, nr, args...) \
|
|
Packit |
6c4009 |
INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#undef INTERNAL_SYSCALL_NCS
|
|
Packit |
6c4009 |
#define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
|
|
Packit |
6c4009 |
INTERNAL_SYSCALL_RAW(number, err, nr, args)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define LOAD_ARGS_0()
|
|
Packit |
6c4009 |
#define LOAD_REGS_0
|
|
Packit |
6c4009 |
#define ASM_ARGS_0
|
|
Packit |
6c4009 |
#define LOAD_ARGS_1(a1) \
|
|
Packit |
6c4009 |
LOAD_ARGS_0 () \
|
|
Packit |
6c4009 |
int __arg1 = (int) (a1);
|
|
Packit |
6c4009 |
#define LOAD_REGS_1 \
|
|
Packit |
6c4009 |
register int _r4 asm ("r4") = __arg1; \
|
|
Packit |
6c4009 |
LOAD_REGS_0
|
|
Packit |
6c4009 |
#define ASM_ARGS_1 "r" (_r4)
|
|
Packit |
6c4009 |
#define LOAD_ARGS_2(a1, a2) \
|
|
Packit |
6c4009 |
LOAD_ARGS_1 (a1) \
|
|
Packit |
6c4009 |
int __arg2 = (int) (a2);
|
|
Packit |
6c4009 |
#define LOAD_REGS_2 \
|
|
Packit |
6c4009 |
register int _r5 asm ("r5") = __arg2; \
|
|
Packit |
6c4009 |
LOAD_REGS_1
|
|
Packit |
6c4009 |
#define ASM_ARGS_2 ASM_ARGS_1, "r" (_r5)
|
|
Packit |
6c4009 |
#define LOAD_ARGS_3(a1, a2, a3) \
|
|
Packit |
6c4009 |
LOAD_ARGS_2 (a1, a2) \
|
|
Packit |
6c4009 |
int __arg3 = (int) (a3);
|
|
Packit |
6c4009 |
#define LOAD_REGS_3 \
|
|
Packit |
6c4009 |
register int _r6 asm ("r6") = __arg3; \
|
|
Packit |
6c4009 |
LOAD_REGS_2
|
|
Packit |
6c4009 |
#define ASM_ARGS_3 ASM_ARGS_2, "r" (_r6)
|
|
Packit |
6c4009 |
#define LOAD_ARGS_4(a1, a2, a3, a4) \
|
|
Packit |
6c4009 |
LOAD_ARGS_3 (a1, a2, a3) \
|
|
Packit |
6c4009 |
int __arg4 = (int) (a4);
|
|
Packit |
6c4009 |
#define LOAD_REGS_4 \
|
|
Packit |
6c4009 |
register int _r7 asm ("r7") = __arg4; \
|
|
Packit |
6c4009 |
LOAD_REGS_3
|
|
Packit |
6c4009 |
#define ASM_ARGS_4 ASM_ARGS_3, "r" (_r7)
|
|
Packit |
6c4009 |
#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
|
|
Packit |
6c4009 |
LOAD_ARGS_4 (a1, a2, a3, a4) \
|
|
Packit |
6c4009 |
int __arg5 = (int) (a5);
|
|
Packit |
6c4009 |
#define LOAD_REGS_5 \
|
|
Packit |
6c4009 |
register int _r8 asm ("r8") = __arg5; \
|
|
Packit |
6c4009 |
LOAD_REGS_4
|
|
Packit |
6c4009 |
#define ASM_ARGS_5 ASM_ARGS_4, "r" (_r8)
|
|
Packit |
6c4009 |
#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
|
|
Packit |
6c4009 |
LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
|
|
Packit |
6c4009 |
int __arg6 = (int) (a6);
|
|
Packit |
6c4009 |
#define LOAD_REGS_6 \
|
|
Packit |
6c4009 |
register int _r9 asm ("r9") = __arg6; \
|
|
Packit |
6c4009 |
LOAD_REGS_5
|
|
Packit |
6c4009 |
#define ASM_ARGS_6 ASM_ARGS_5, "r" (_r9)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define __SYSCALL_CLOBBERS "memory"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* __ASSEMBLER__ */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Pointer mangling support. */
|
|
Packit |
6c4009 |
#if IS_IN (rtld)
|
|
Packit |
6c4009 |
/* We cannot use the thread descriptor because in ld.so we use setjmp
|
|
Packit |
6c4009 |
earlier than the descriptor is initialized. */
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# ifdef __ASSEMBLER__
|
|
Packit |
6c4009 |
# define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23)
|
|
Packit |
6c4009 |
# define PTR_MANGLE(dst, src, guard) xor dst, src, guard
|
|
Packit |
6c4009 |
# define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define PTR_MANGLE(var) \
|
|
Packit |
6c4009 |
(var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
|
|
Packit |
6c4009 |
# define PTR_DEMANGLE(var) PTR_MANGLE (var)
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* linux/nios2/sysdep.h */
|