root/mtcp/syscall-aarch64.S
/* [<][>][^][v][top][bottom][index][help] */
1 /* Copyright (C) 2005-2014 Free Software Foundation, Inc.
2
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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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 <http://www.gnu.org/licenses/>. */
18
19 /* This file was modified from the original below.
20 *
21 /* This file was modified from the original below.
22 * ../glibc-2.19/ports/sysdeps/unix/sysv/linux/aarch64/syscall.S
23 */
24
25 // #include <sysdep.h>
26 // Macros copied or modifid from:
27 // ../glibc-2.19/ports/sysdeps/arm/sysdep.h
28 // ../glibc-2.19/sysdeps/generic/sysdep.h (USED?)
29
30 // Added for DMTCP
31 #define PSEUDO_END(name)
32 #define ENTRY(name) \
33 .globl name ; \
34 .type name,%function ;\
35 .align 4 ; \
36 name:
37
38 /* syscall (int nr, ...)
39
40 AArch64 system calls take between 0 and 7 arguments. On entry here nr
41 is in w0 and any other system call arguments are in register x1..x7.
42
43 For kernel entry we need to move the system call nr to x8 then
44 load the remaining arguments to register. */
45 /*
46 * When using MTCP_SYS_ERRNO_ON_STACK, mtcp_sys.h adds the address of
47 * mtcp_sys_errno as the second argument after the syscall number:
48 * mtcp_syscall(int nr, int *mtcp_sys_errno, x2, x3, x4, x5, x6, x7, x8)
49 * nr is in x0/w0, and &mtcp_sys_errno is in x1. The logic below converts
50 * this call to:
51 * syscall(x8, x0, x1, x2, x3, x4, x5, x6)
52 * and saves the &mtcp_sys_errno in x10.
53 * When returning from sycall, kernel puts the return value in x0.
54 */
55
56 ENTRY (mtcp_syscall)
57 #ifdef MTCP_SYS_ERRNO_ON_STACK
58 mov x9, x8 /* Save last argument here temporarily */
59 mov x10, x1 /* Save address of mtcp_sys_errno here */
60 uxtw x8, w0
61 mov x0, x2
62 mov x1, x3
63 mov x2, x4
64 mov x3, x5
65 mov x4, x6
66 mov x5, x7
67 mov x6, x9 /* last argument had been moved here */
68 #else
69 uxtw x8, w0
70 mov x0, x1
71 mov x1, x2
72 mov x2, x3
73 mov x3, x4
74 mov x4, x5
75 mov x5, x6
76 mov x6, x7
77 #endif
78 svc 0x0
79 cmn x0, #4095
80 b.cs 1f /* Branch on error */
81 RET /* assembler treats this as "ret" */
82 1:
83 #ifdef MTCP_SYS_ERRNO_ON_STACK
84 // x10 has &mtcp_sys_errno and x0 has encoded errno
85 neg x0, x0 /* If x0-4096 was negative, 4096-x0 is the errno. */
86 str x0, [x10, #0] /* Save the errno in mtcp_sys_errno */
87 mov x0, #-1 /* return -1 */
88 RET /* assembler treats this as "ret" */
89 #else
90 // This will call a DMTCP function in C that sets mtcp_sys_errno :
91 // b PLTJMP(syscall_error)
92 #endif
93 PSEUDO_END (syscall)