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) 2016 Red Hat, 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
20 /* This is the entry point for making a system call. The calling
21 * convention here is that of a C varargs function with the
22 * first argument an 'int *' to the signal_pending flag, the
23 * second one the system call number (as a 'long'), and all further
24 * arguments being syscall arguments (also 'long').
29 .localentry safe_syscall_base,0
34 .quad .L.safe_syscall_base,.TOC.@tocbase,0
39 /* We enter with r3 == &signal_pending
40 * r4 == syscall number
41 * r5 ... r10 == syscall arguments
42 * and return the result in r3
43 * and the syscall instruction needs
44 * r0 == syscall number
45 * r3 ... r8 == syscall arguments
46 * and returns the result in r3
47 * Shuffle everything around appropriately.
49 std 14, 16(1) /* Preserve r14 in SP+16 */
51 mr 14, 3 /* signal_pending */
52 mr 0, 4 /* syscall number */
53 mr 3, 5 /* syscall arguments */
60 /* This next sequence of code works in conjunction with the
61 * rewind_if_safe_syscall_function(). If a signal is taken
62 * and the interrupted PC is anywhere between 'safe_syscall_start'
63 * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
64 * The code sequence must therefore be able to cope with this, and
65 * the syscall instruction must be the final one in the sequence.
68 /* if signal_pending is non-zero, don't do the call */
74 /* code path when we did execute the syscall */
75 ld 14, 16(1) /* restore r14 */
79 /* code path when we didn't execute the syscall */
80 2: ld 14, 16(1) /* restore r14 */
81 addi 3, 0, QEMU_ERESTARTSYS
83 /* code path setting errno */
84 1: b safe_syscall_set_errno_tail
85 nop /* per abi, for the linker to modify */
90 .size safe_syscall_base, .-safe_syscall_base
92 .size safe_syscall_base, .-.L.safe_syscall_base
93 .size .L.safe_syscall_base, .-.L.safe_syscall_base