2 * safe-syscall.inc.S : host-specific assembly fragment
3 * to handle signals occurring at the same time as system calls.
4 * This is intended to be included by common-user/safe-syscall.S
6 * Written by Richard Henderson <rth@twiddle.net>
7 * Copyright (C) 2018 Linaro, Inc.
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 .global safe_syscall_base
14 .global safe_syscall_start
15 .global safe_syscall_end
16 .type safe_syscall_base, @function
17 .type safe_syscall_start, @function
18 .type safe_syscall_end, @function
21 * This is the entry point for making a system call. The calling
22 * convention here is that of a C varargs function with the
23 * first argument an 'int *' to the signal_pending flag, the
24 * second one the system call number (as a 'long'), and all further
25 * arguments being syscall arguments (also 'long').
30 * The syscall calling convention is nearly the same as C:
31 * we enter with a0 == &signal_pending
32 * a1 == syscall number
33 * a2 ... a7 == syscall arguments
34 * and return the result in a0
35 * and the syscall instruction needs
36 * a7 == syscall number
37 * a0 ... a5 == syscall arguments
38 * and returns the result in a0
39 * Shuffle everything around appropriately.
41 mv t0, a0 /* signal_pending pointer */
42 mv t1, a1 /* syscall number */
43 mv a0, a2 /* syscall arguments */
52 * This next sequence of code works in conjunction with the
53 * rewind_if_safe_syscall_function(). If a signal is taken
54 * and the interrupted PC is anywhere between 'safe_syscall_start'
55 * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
56 * The code sequence must therefore be able to cope with this, and
57 * the syscall instruction must be the final one in the sequence.
60 /* If signal_pending is non-zero, don't do the call */
65 /* code path for having successfully executed the syscall */
70 /* code path setting errno */
72 j safe_syscall_set_errno_tail
74 /* code path when we didn't execute the syscall */
75 2: li a0, QEMU_ERESTARTSYS
76 j safe_syscall_set_errno_tail
79 .size safe_syscall_base, .-safe_syscall_base