xref: /openbmc/qemu/common-user/host/ppc64/safe-syscall.inc.S (revision 2bf40d0841b942e7ba12953d515e62a436f0af84)
1*bbf15aafSRichard Henderson/*
2*bbf15aafSRichard Henderson * safe-syscall.inc.S : host-specific assembly fragment
3*bbf15aafSRichard Henderson * to handle signals occurring at the same time as system calls.
4*bbf15aafSRichard Henderson * This is intended to be included by common-user/safe-syscall.S
5*bbf15aafSRichard Henderson *
6*bbf15aafSRichard Henderson * Written by Richard Henderson <rth@twiddle.net>
7*bbf15aafSRichard Henderson * Copyright (C) 2016 Red Hat, Inc.
8*bbf15aafSRichard Henderson *
9*bbf15aafSRichard Henderson * This work is licensed under the terms of the GNU GPL, version 2 or later.
10*bbf15aafSRichard Henderson * See the COPYING file in the top-level directory.
11*bbf15aafSRichard Henderson */
12*bbf15aafSRichard Henderson
13*bbf15aafSRichard Henderson        .global safe_syscall_base
14*bbf15aafSRichard Henderson        .global safe_syscall_start
15*bbf15aafSRichard Henderson        .global safe_syscall_end
16*bbf15aafSRichard Henderson        .type   safe_syscall_base, @function
17*bbf15aafSRichard Henderson
18*bbf15aafSRichard Henderson        .text
19*bbf15aafSRichard Henderson
20*bbf15aafSRichard Henderson        /* This is the entry point for making a system call. The calling
21*bbf15aafSRichard Henderson         * convention here is that of a C varargs function with the
22*bbf15aafSRichard Henderson         * first argument an 'int *' to the signal_pending flag, the
23*bbf15aafSRichard Henderson         * second one the system call number (as a 'long'), and all further
24*bbf15aafSRichard Henderson         * arguments being syscall arguments (also 'long').
25*bbf15aafSRichard Henderson         */
26*bbf15aafSRichard Henderson#if _CALL_ELF == 2
27*bbf15aafSRichard Hendersonsafe_syscall_base:
28*bbf15aafSRichard Henderson        .cfi_startproc
29*bbf15aafSRichard Henderson        .localentry safe_syscall_base,0
30*bbf15aafSRichard Henderson#else
31*bbf15aafSRichard Henderson        .section ".opd","aw"
32*bbf15aafSRichard Henderson        .align  3
33*bbf15aafSRichard Hendersonsafe_syscall_base:
34*bbf15aafSRichard Henderson        .quad   .L.safe_syscall_base,.TOC.@tocbase,0
35*bbf15aafSRichard Henderson        .previous
36*bbf15aafSRichard Henderson.L.safe_syscall_base:
37*bbf15aafSRichard Henderson        .cfi_startproc
38*bbf15aafSRichard Henderson#endif
39*bbf15aafSRichard Henderson        /* We enter with r3 == &signal_pending
40*bbf15aafSRichard Henderson         *               r4 == syscall number
41*bbf15aafSRichard Henderson         *               r5 ... r10 == syscall arguments
42*bbf15aafSRichard Henderson         *               and return the result in r3
43*bbf15aafSRichard Henderson         * and the syscall instruction needs
44*bbf15aafSRichard Henderson         *               r0 == syscall number
45*bbf15aafSRichard Henderson         *               r3 ... r8 == syscall arguments
46*bbf15aafSRichard Henderson         *               and returns the result in r3
47*bbf15aafSRichard Henderson         * Shuffle everything around appropriately.
48*bbf15aafSRichard Henderson         */
49*bbf15aafSRichard Henderson        std     14, 16(1) /* Preserve r14 in SP+16 */
50*bbf15aafSRichard Henderson        .cfi_offset 14, 16
51*bbf15aafSRichard Henderson        mr      14, 3   /* signal_pending */
52*bbf15aafSRichard Henderson        mr      0, 4    /* syscall number */
53*bbf15aafSRichard Henderson        mr      3, 5    /* syscall arguments */
54*bbf15aafSRichard Henderson        mr      4, 6
55*bbf15aafSRichard Henderson        mr      5, 7
56*bbf15aafSRichard Henderson        mr      6, 8
57*bbf15aafSRichard Henderson        mr      7, 9
58*bbf15aafSRichard Henderson        mr      8, 10
59*bbf15aafSRichard Henderson
60*bbf15aafSRichard Henderson        /* This next sequence of code works in conjunction with the
61*bbf15aafSRichard Henderson         * rewind_if_safe_syscall_function(). If a signal is taken
62*bbf15aafSRichard Henderson         * and the interrupted PC is anywhere between 'safe_syscall_start'
63*bbf15aafSRichard Henderson         * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
64*bbf15aafSRichard Henderson         * The code sequence must therefore be able to cope with this, and
65*bbf15aafSRichard Henderson         * the syscall instruction must be the final one in the sequence.
66*bbf15aafSRichard Henderson         */
67*bbf15aafSRichard Hendersonsafe_syscall_start:
68*bbf15aafSRichard Henderson        /* if signal_pending is non-zero, don't do the call */
69*bbf15aafSRichard Henderson        lwz     12, 0(14)
70*bbf15aafSRichard Henderson        cmpwi   0, 12, 0
71*bbf15aafSRichard Henderson        bne-    2f
72*bbf15aafSRichard Henderson        sc
73*bbf15aafSRichard Hendersonsafe_syscall_end:
74*bbf15aafSRichard Henderson        /* code path when we did execute the syscall */
75*bbf15aafSRichard Henderson        ld      14, 16(1) /* restore r14 */
76*bbf15aafSRichard Henderson        bso-    1f
77*bbf15aafSRichard Henderson        blr
78*bbf15aafSRichard Henderson
79*bbf15aafSRichard Henderson        /* code path when we didn't execute the syscall */
80*bbf15aafSRichard Henderson2:      ld      14, 16(1) /* restore r14 */
81*bbf15aafSRichard Henderson        addi    3, 0, QEMU_ERESTARTSYS
82*bbf15aafSRichard Henderson
83*bbf15aafSRichard Henderson        /* code path setting errno */
84*bbf15aafSRichard Henderson1:      b       safe_syscall_set_errno_tail
85*bbf15aafSRichard Henderson        nop     /* per abi, for the linker to modify */
86*bbf15aafSRichard Henderson
87*bbf15aafSRichard Henderson        .cfi_endproc
88*bbf15aafSRichard Henderson
89*bbf15aafSRichard Henderson#if _CALL_ELF == 2
90*bbf15aafSRichard Henderson        .size   safe_syscall_base, .-safe_syscall_base
91*bbf15aafSRichard Henderson#else
92*bbf15aafSRichard Henderson        .size   safe_syscall_base, .-.L.safe_syscall_base
93*bbf15aafSRichard Henderson        .size   .L.safe_syscall_base, .-.L.safe_syscall_base
94*bbf15aafSRichard Henderson#endif
95