]>
Commit | Line | Data |
---|---|---|
1 | /* Copyright (C) 1992-2019 Free Software Foundation, Inc. | |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995. | |
4 | ARM changes by Philip Blundell, <pjb27@cam.ac.uk>, May 1997. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with the GNU C Library. If not, see | |
18 | <https://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef _LINUX_ARM_SYSDEP_H | |
21 | #define _LINUX_ARM_SYSDEP_H 1 | |
22 | ||
23 | /* There is some commonality. */ | |
24 | #include <sysdeps/unix/sysv/linux/sysdep.h> | |
25 | #include <sysdeps/unix/arm/sysdep.h> | |
26 | ||
27 | /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */ | |
28 | #include <dl-sysdep.h> | |
29 | ||
30 | #include <tls.h> | |
31 | ||
32 | /* In order to get __set_errno() definition in INLINE_SYSCALL. */ | |
33 | #ifndef __ASSEMBLER__ | |
34 | #include <errno.h> | |
35 | #endif | |
36 | ||
37 | /* For Linux we can use the system call table in the header file | |
38 | /usr/include/asm/unistd.h | |
39 | of the kernel. But these symbols do not follow the SYS_* syntax | |
40 | so we have to redefine the `SYS_ify' macro here. */ | |
41 | #undef SYS_ify | |
42 | #define SYS_ify(syscall_name) (__NR_##syscall_name) | |
43 | ||
44 | #include <bits/hwcap.h> | |
45 | ||
46 | #ifdef __ASSEMBLER__ | |
47 | ||
48 | #ifndef ARCH_HAS_HARD_TP | |
49 | /* Internal macro calling the linux kernel kuser_get_tls helper. | |
50 | Note that in thumb mode, a constant pool break is often out of range, so | |
51 | we always expand the constant inline. */ | |
52 | # ifdef __thumb2__ | |
53 | # define GET_TLS_BODY \ | |
54 | movw r0, #0x0fe0; \ | |
55 | movt r0, #0xffff; \ | |
56 | blx r0 | |
57 | # else | |
58 | # define GET_TLS_BODY \ | |
59 | mov r0, #0xffff0fff; /* Point to the high page. */ \ | |
60 | mov lr, pc; /* Save our return address. */ \ | |
61 | sub pc, r0, #31 /* Jump to the TLS entry. */ | |
62 | # endif | |
63 | ||
64 | /* Helper to get the TLS base pointer. Save LR in TMP, return in R0, | |
65 | and no other registers clobbered. TMP may be LR itself to indicate | |
66 | that no save is necessary. */ | |
67 | # undef GET_TLS | |
68 | # define GET_TLS(TMP) \ | |
69 | .ifnc TMP, lr; \ | |
70 | mov TMP, lr; \ | |
71 | cfi_register (lr, TMP); \ | |
72 | GET_TLS_BODY; \ | |
73 | mov lr, TMP; \ | |
74 | cfi_restore (lr); \ | |
75 | .else; \ | |
76 | GET_TLS_BODY; \ | |
77 | .endif | |
78 | #endif /* ARCH_HAS_HARD_TP */ | |
79 | ||
80 | /* Linux uses a negative return value to indicate syscall errors, | |
81 | unlike most Unices, which use the condition codes' carry flag. | |
82 | ||
83 | Since version 2.1 the return value of a system call might be | |
84 | negative even if the call succeeded. E.g., the `lseek' system call | |
85 | might return a large offset. Therefore we must not anymore test | |
86 | for < 0, but test for a real error by making sure the value in R0 | |
87 | is a real error number. Linus said he will make sure the no syscall | |
88 | returns a value in -1 .. -4095 as a valid result so we can safely | |
89 | test with -4095. */ | |
90 | ||
91 | #undef PSEUDO | |
92 | #define PSEUDO(name, syscall_name, args) \ | |
93 | .text; \ | |
94 | ENTRY (name); \ | |
95 | DO_CALL (syscall_name, args); \ | |
96 | cmn r0, $4096; | |
97 | ||
98 | #define PSEUDO_RET \ | |
99 | it cc; \ | |
100 | RETINSTR(cc, lr); \ | |
101 | b PLTJMP(SYSCALL_ERROR) | |
102 | #undef ret | |
103 | #define ret PSEUDO_RET | |
104 | ||
105 | #undef PSEUDO_END | |
106 | #define PSEUDO_END(name) \ | |
107 | SYSCALL_ERROR_HANDLER; \ | |
108 | END (name) | |
109 | ||
110 | #undef PSEUDO_NOERRNO | |
111 | #define PSEUDO_NOERRNO(name, syscall_name, args) \ | |
112 | .text; \ | |
113 | ENTRY (name); \ | |
114 | DO_CALL (syscall_name, args); | |
115 | ||
116 | #define PSEUDO_RET_NOERRNO \ | |
117 | DO_RET (lr); | |
118 | ||
119 | #undef ret_NOERRNO | |
120 | #define ret_NOERRNO PSEUDO_RET_NOERRNO | |
121 | ||
122 | #undef PSEUDO_END_NOERRNO | |
123 | #define PSEUDO_END_NOERRNO(name) \ | |
124 | END (name) | |
125 | ||
126 | /* The function has to return the error code. */ | |
127 | #undef PSEUDO_ERRVAL | |
128 | #define PSEUDO_ERRVAL(name, syscall_name, args) \ | |
129 | .text; \ | |
130 | ENTRY (name) \ | |
131 | DO_CALL (syscall_name, args); \ | |
132 | rsb r0, r0, #0 | |
133 | ||
134 | #undef PSEUDO_END_ERRVAL | |
135 | #define PSEUDO_END_ERRVAL(name) \ | |
136 | END (name) | |
137 | ||
138 | #define ret_ERRVAL PSEUDO_RET_NOERRNO | |
139 | ||
140 | #if !IS_IN (libc) | |
141 | # define SYSCALL_ERROR __local_syscall_error | |
142 | # if RTLD_PRIVATE_ERRNO | |
143 | # define SYSCALL_ERROR_HANDLER \ | |
144 | __local_syscall_error: \ | |
145 | rsb r0, r0, #0; \ | |
146 | LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \ | |
147 | mvn r0, #0; \ | |
148 | DO_RET(lr) | |
149 | # else | |
150 | # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__) | |
151 | # define POP_PC \ | |
152 | pop { lr }; \ | |
153 | cfi_adjust_cfa_offset (-4); \ | |
154 | cfi_restore (lr); \ | |
155 | bx lr | |
156 | # else | |
157 | # define POP_PC pop { pc } | |
158 | # endif | |
159 | # define SYSCALL_ERROR_HANDLER \ | |
160 | __local_syscall_error: \ | |
161 | push { lr }; \ | |
162 | cfi_adjust_cfa_offset (4); \ | |
163 | cfi_rel_offset (lr, 0); \ | |
164 | push { r0 }; \ | |
165 | cfi_adjust_cfa_offset (4); \ | |
166 | bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \ | |
167 | pop { r1 }; \ | |
168 | cfi_adjust_cfa_offset (-4); \ | |
169 | rsb r1, r1, #0; \ | |
170 | str r1, [r0]; \ | |
171 | mvn r0, #0; \ | |
172 | POP_PC; | |
173 | # endif | |
174 | #else | |
175 | # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */ | |
176 | # define SYSCALL_ERROR __syscall_error | |
177 | #endif | |
178 | ||
179 | /* The ARM EABI user interface passes the syscall number in r7, instead | |
180 | of in the swi. This is more efficient, because the kernel does not need | |
181 | to fetch the swi from memory to find out the number; which can be painful | |
182 | with separate I-cache and D-cache. Make sure to use 0 for the SWI | |
183 | argument; otherwise the (optional) compatibility code for APCS binaries | |
184 | may be invoked. */ | |
185 | ||
186 | /* Linux takes system call args in registers: | |
187 | arg 1 r0 | |
188 | arg 2 r1 | |
189 | arg 3 r2 | |
190 | arg 4 r3 | |
191 | arg 5 r4 (this is different from the APCS convention) | |
192 | arg 6 r5 | |
193 | arg 7 r6 | |
194 | ||
195 | The compiler is going to form a call by coming here, through PSEUDO, with | |
196 | arguments | |
197 | syscall number in the DO_CALL macro | |
198 | arg 1 r0 | |
199 | arg 2 r1 | |
200 | arg 3 r2 | |
201 | arg 4 r3 | |
202 | arg 5 [sp] | |
203 | arg 6 [sp+4] | |
204 | arg 7 [sp+8] | |
205 | ||
206 | We need to shuffle values between R4..R6 and the stack so that the | |
207 | caller's v1..v3 and stack frame are not corrupted, and the kernel | |
208 | sees the right arguments. | |
209 | ||
210 | */ | |
211 | ||
212 | /* We must save and restore r7 (call-saved) for the syscall number. | |
213 | We never make function calls from inside here (only potentially | |
214 | signal handlers), so we do not bother with doubleword alignment. | |
215 | ||
216 | Just like the APCS syscall convention, the EABI syscall convention uses | |
217 | r0 through r6 for up to seven syscall arguments. None are ever passed to | |
218 | the kernel on the stack, although incoming arguments are on the stack for | |
219 | syscalls with five or more arguments. | |
220 | ||
221 | The assembler will convert the literal pool load to a move for most | |
222 | syscalls. */ | |
223 | ||
224 | #undef DO_CALL | |
225 | #define DO_CALL(syscall_name, args) \ | |
226 | DOARGS_##args; \ | |
227 | ldr r7, =SYS_ify (syscall_name); \ | |
228 | swi 0x0; \ | |
229 | UNDOARGS_##args | |
230 | ||
231 | #undef DOARGS_0 | |
232 | #define DOARGS_0 \ | |
233 | .fnstart; \ | |
234 | push { r7 }; \ | |
235 | cfi_adjust_cfa_offset (4); \ | |
236 | cfi_rel_offset (r7, 0); \ | |
237 | .save { r7 } | |
238 | #undef DOARGS_1 | |
239 | #define DOARGS_1 DOARGS_0 | |
240 | #undef DOARGS_2 | |
241 | #define DOARGS_2 DOARGS_0 | |
242 | #undef DOARGS_3 | |
243 | #define DOARGS_3 DOARGS_0 | |
244 | #undef DOARGS_4 | |
245 | #define DOARGS_4 DOARGS_0 | |
246 | #undef DOARGS_5 | |
247 | #define DOARGS_5 \ | |
248 | .fnstart; \ | |
249 | push {r4, r7}; \ | |
250 | cfi_adjust_cfa_offset (8); \ | |
251 | cfi_rel_offset (r4, 0); \ | |
252 | cfi_rel_offset (r7, 4); \ | |
253 | .save { r4, r7 }; \ | |
254 | ldr r4, [sp, #8] | |
255 | #undef DOARGS_6 | |
256 | #define DOARGS_6 \ | |
257 | .fnstart; \ | |
258 | mov ip, sp; \ | |
259 | push {r4, r5, r7}; \ | |
260 | cfi_adjust_cfa_offset (12); \ | |
261 | cfi_rel_offset (r4, 0); \ | |
262 | cfi_rel_offset (r5, 4); \ | |
263 | cfi_rel_offset (r7, 8); \ | |
264 | .save { r4, r5, r7 }; \ | |
265 | ldmia ip, {r4, r5} | |
266 | #undef DOARGS_7 | |
267 | #define DOARGS_7 \ | |
268 | .fnstart; \ | |
269 | mov ip, sp; \ | |
270 | push {r4, r5, r6, r7}; \ | |
271 | cfi_adjust_cfa_offset (16); \ | |
272 | cfi_rel_offset (r4, 0); \ | |
273 | cfi_rel_offset (r5, 4); \ | |
274 | cfi_rel_offset (r6, 8); \ | |
275 | cfi_rel_offset (r7, 12); \ | |
276 | .save { r4, r5, r6, r7 }; \ | |
277 | ldmia ip, {r4, r5, r6} | |
278 | ||
279 | #undef UNDOARGS_0 | |
280 | #define UNDOARGS_0 \ | |
281 | pop {r7}; \ | |
282 | cfi_adjust_cfa_offset (-4); \ | |
283 | cfi_restore (r7); \ | |
284 | .fnend | |
285 | #undef UNDOARGS_1 | |
286 | #define UNDOARGS_1 UNDOARGS_0 | |
287 | #undef UNDOARGS_2 | |
288 | #define UNDOARGS_2 UNDOARGS_0 | |
289 | #undef UNDOARGS_3 | |
290 | #define UNDOARGS_3 UNDOARGS_0 | |
291 | #undef UNDOARGS_4 | |
292 | #define UNDOARGS_4 UNDOARGS_0 | |
293 | #undef UNDOARGS_5 | |
294 | #define UNDOARGS_5 \ | |
295 | pop {r4, r7}; \ | |
296 | cfi_adjust_cfa_offset (-8); \ | |
297 | cfi_restore (r4); \ | |
298 | cfi_restore (r7); \ | |
299 | .fnend | |
300 | #undef UNDOARGS_6 | |
301 | #define UNDOARGS_6 \ | |
302 | pop {r4, r5, r7}; \ | |
303 | cfi_adjust_cfa_offset (-12); \ | |
304 | cfi_restore (r4); \ | |
305 | cfi_restore (r5); \ | |
306 | cfi_restore (r7); \ | |
307 | .fnend | |
308 | #undef UNDOARGS_7 | |
309 | #define UNDOARGS_7 \ | |
310 | pop {r4, r5, r6, r7}; \ | |
311 | cfi_adjust_cfa_offset (-16); \ | |
312 | cfi_restore (r4); \ | |
313 | cfi_restore (r5); \ | |
314 | cfi_restore (r6); \ | |
315 | cfi_restore (r7); \ | |
316 | .fnend | |
317 | ||
318 | #else /* not __ASSEMBLER__ */ | |
319 | ||
320 | /* Define a macro which expands into the inline wrapper code for a system | |
321 | call. */ | |
322 | #undef INLINE_SYSCALL | |
323 | #define INLINE_SYSCALL(name, nr, args...) \ | |
324 | ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \ | |
325 | if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \ | |
326 | { \ | |
327 | __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \ | |
328 | _sys_result = (unsigned int) -1; \ | |
329 | } \ | |
330 | (int) _sys_result; }) | |
331 | ||
332 | #undef INTERNAL_SYSCALL_DECL | |
333 | #define INTERNAL_SYSCALL_DECL(err) do { } while (0) | |
334 | ||
335 | #if defined(__thumb__) | |
336 | /* We can not expose the use of r7 to the compiler. GCC (as | |
337 | of 4.5) uses r7 as the hard frame pointer for Thumb - although | |
338 | for Thumb-2 it isn't obviously a better choice than r11. | |
339 | And GCC does not support asms that conflict with the frame | |
340 | pointer. | |
341 | ||
342 | This would be easier if syscall numbers never exceeded 255, | |
343 | but they do. For the moment the LOAD_ARGS_7 is sacrificed. | |
344 | We can't use push/pop inside the asm because that breaks | |
345 | unwinding (i.e. thread cancellation) for this frame. We can't | |
346 | locally save and restore r7, because we do not know if this | |
347 | function uses r7 or if it is our caller's r7; if it is our caller's, | |
348 | then unwinding will fail higher up the stack. So we move the | |
349 | syscall out of line and provide its own unwind information. */ | |
350 | # undef INTERNAL_SYSCALL_RAW | |
351 | # define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \ | |
352 | ({ \ | |
353 | register int _a1 asm ("a1"); \ | |
354 | int _nametmp = name; \ | |
355 | LOAD_ARGS_##nr (args) \ | |
356 | register int _name asm ("ip") = _nametmp; \ | |
357 | asm volatile ("bl __libc_do_syscall" \ | |
358 | : "=r" (_a1) \ | |
359 | : "r" (_name) ASM_ARGS_##nr \ | |
360 | : "memory", "lr"); \ | |
361 | _a1; }) | |
362 | #else /* ARM */ | |
363 | # undef INTERNAL_SYSCALL_RAW | |
364 | # define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \ | |
365 | ({ \ | |
366 | register int _a1 asm ("r0"), _nr asm ("r7"); \ | |
367 | LOAD_ARGS_##nr (args) \ | |
368 | _nr = name; \ | |
369 | asm volatile ("swi 0x0 @ syscall " #name \ | |
370 | : "=r" (_a1) \ | |
371 | : "r" (_nr) ASM_ARGS_##nr \ | |
372 | : "memory"); \ | |
373 | _a1; }) | |
374 | #endif | |
375 | ||
376 | #undef INTERNAL_SYSCALL | |
377 | #define INTERNAL_SYSCALL(name, err, nr, args...) \ | |
378 | INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args) | |
379 | ||
380 | #undef INTERNAL_SYSCALL_ARM | |
381 | #define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \ | |
382 | INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args) | |
383 | ||
384 | #undef INTERNAL_SYSCALL_ERROR_P | |
385 | #define INTERNAL_SYSCALL_ERROR_P(val, err) \ | |
386 | ((unsigned int) (val) >= 0xfffff001u) | |
387 | ||
388 | #undef INTERNAL_SYSCALL_ERRNO | |
389 | #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) | |
390 | ||
391 | #define VDSO_NAME "LINUX_2.6" | |
392 | #define VDSO_HASH 61765110 | |
393 | ||
394 | /* List of system calls which are supported as vsyscalls. */ | |
395 | #define HAVE_CLOCK_GETTIME_VSYSCALL 1 | |
396 | #define HAVE_GETTIMEOFDAY_VSYSCALL 1 | |
397 | ||
398 | #define LOAD_ARGS_0() | |
399 | #define ASM_ARGS_0 | |
400 | #define LOAD_ARGS_1(a1) \ | |
401 | int _a1tmp = (int) (a1); \ | |
402 | LOAD_ARGS_0 () \ | |
403 | _a1 = _a1tmp; | |
404 | #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1) | |
405 | #define LOAD_ARGS_2(a1, a2) \ | |
406 | int _a2tmp = (int) (a2); \ | |
407 | LOAD_ARGS_1 (a1) \ | |
408 | register int _a2 asm ("a2") = _a2tmp; | |
409 | #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2) | |
410 | #define LOAD_ARGS_3(a1, a2, a3) \ | |
411 | int _a3tmp = (int) (a3); \ | |
412 | LOAD_ARGS_2 (a1, a2) \ | |
413 | register int _a3 asm ("a3") = _a3tmp; | |
414 | #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3) | |
415 | #define LOAD_ARGS_4(a1, a2, a3, a4) \ | |
416 | int _a4tmp = (int) (a4); \ | |
417 | LOAD_ARGS_3 (a1, a2, a3) \ | |
418 | register int _a4 asm ("a4") = _a4tmp; | |
419 | #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4) | |
420 | #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ | |
421 | int _v1tmp = (int) (a5); \ | |
422 | LOAD_ARGS_4 (a1, a2, a3, a4) \ | |
423 | register int _v1 asm ("v1") = _v1tmp; | |
424 | #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1) | |
425 | #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ | |
426 | int _v2tmp = (int) (a6); \ | |
427 | LOAD_ARGS_5 (a1, a2, a3, a4, a5) \ | |
428 | register int _v2 asm ("v2") = _v2tmp; | |
429 | #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2) | |
430 | #ifndef __thumb__ | |
431 | # define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \ | |
432 | int _v3tmp = (int) (a7); \ | |
433 | LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6) \ | |
434 | register int _v3 asm ("v3") = _v3tmp; | |
435 | # define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3) | |
436 | #endif | |
437 | ||
438 | /* For EABI, non-constant syscalls are actually pretty easy... */ | |
439 | #undef INTERNAL_SYSCALL_NCS | |
440 | #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \ | |
441 | INTERNAL_SYSCALL_RAW (number, err, nr, args) | |
442 | ||
443 | #define SINGLE_THREAD_BY_GLOBAL 1 | |
444 | ||
445 | #endif /* __ASSEMBLER__ */ | |
446 | ||
447 | #endif /* linux/arm/sysdep.h */ |