2 * Copyright (C) 2016-2017 Andes Technology, Inc.
3 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 #ifndef _LINUX_NDS32_SYSDEP_H
7 #define _LINUX_NDS32_SYSDEP_H 1
9 #include <common/sysdep.h>
12 /* Define an entry point visible from C. */
14 # define ENTRY(name) \
17 .globl C_SYMBOL_NAME(name); \
18 .func C_SYMBOL_NAME(name); \
19 .type C_SYMBOL_NAME(name), @function; \
20 C_SYMBOL_NAME(name): \
24 # define ENTRY(name) \
26 .globl C_SYMBOL_NAME(name); \
27 .func C_SYMBOL_NAME(name); \
28 .type C_SYMBOL_NAME(name), @function; \
29 C_SYMBOL_NAME(name): \
37 .size C_SYMBOL_NAME(name), .-C_SYMBOL_NAME(name)
39 /* If compiled for profiling, call `mcount' at the start of each function. */
42 #define NO_UNDERSCORES
45 # ifdef NO_UNDERSCORES
46 #define syscall_error __syscall_error
49 #define SYS_ify(syscall_name) (__NR_##syscall_name)
51 #define __do_syscall(syscall_name) \
52 syscall SYS_ify(syscall_name);
55 # define PSEUDO(name, syscall_name, args) \
58 99: mfusr $r15, $PC; \
59 sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_ + 4); \
60 ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_ + 8); \
62 sethi $r15, hi20(SYSCALL_ERROR@PLT); \
63 ori $r15, $r15, lo12(SYSCALL_ERROR@PLT); \
64 add $r15, $r15, $r1; \
68 __do_syscall(syscall_name); \
70 sltsi $r1, $r0, -4096; \
74 # define PSEUDO(name, syscall_name, args) \
76 99: j SYSCALL_ERROR; \
79 __do_syscall(syscall_name); \
81 sltsi $r1, $r0, -4096; \
87 #define PSEUDO_NOERRNO(name, syscall_name, args) \
89 __do_syscall(syscall_name);
92 #define PSEUDO_END(sym) \
93 SYSCALL_ERROR_HANDLER \
96 #undef PSEUDO_END_ERRVAL
97 #define PSEUDO_END_ERRVAL(sym) END(sym)
99 #define PSEUDO_ERRVAL(name, syscall_name, args) PSEUDO_NOERRNO(name, syscall_name, args)
101 #define ret_ERRVAL ret
103 #define ret_NOERRNO ret
104 #if defined NOT_IN_libc
105 #define SYSCALL_ERROR __local_syscall_error
107 #define SYSCALL_ERROR_HANDLER \
108 __local_syscall_error: \
110 cfi_adjust_cfa_offset(8) \
111 cfi_rel_offset(gp, 0) \
112 cfi_rel_offset(lp, 4) \
114 sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4); \
115 ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8); \
116 add $gp, $gp, $r15; \
119 cfi_adjust_cfa_offset(4) \
120 cfi_rel_offset(r0, 0) \
122 bal C_SYMBOL_NAME(__errno_location@PLT); \
125 cfi_adjust_cfa_offset(-4); \
130 cfi_adjust_cfa_offset(-8); \
135 #define SYSCALL_ERROR_HANDLER \
136 __local_syscall_error: \
138 cfi_adjust_cfa_offset(4) \
139 cfi_rel_offset(lp, 0) \
142 cfi_adjust_cfa_offset(4) \
143 cfi_rel_offset(r0, 0) \
145 bal C_SYMBOL_NAME(__errno_location); \
148 cfi_adjust_cfa_offset(-4); \
153 cfi_adjust_cfa_offset(-4); \
159 #define SYSCALL_ERROR_HANDLER
160 #define SYSCALL_ERROR __syscall_error
163 #endif /* __ASSEMBLER__ */
164 #endif //_LINUX_NDS32_SYSDEP_H