Update copyright notices with scripts/update-copyrights.
[glibc.git] / ports / sysdeps / unix / sysv / linux / aarch64 / getcontext.S
blobeea6867f9b5c06b9c6eba836934cf637216d2e6c
1 /* Save current context.
3    Copyright (C) 2009-2013 Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 2.1 of the
10    License, or (at your option) any later version.
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, see
19    <http://www.gnu.org/licenses/>.  */
21 #include <sysdep.h>
22 #include "ucontext_i.h"
23 #include "ucontext-internal.h"
25 /* int getcontext (ucontext_t *ucp)
27    Returns 0 on success -1 and errno on failure.
28  */
30         .text
32 ENTRY(__getcontext)
33         /* The saved context will return to the getcontext() call point
34            with a return value of 0 */
35         str     xzr,      [x0, oX0 +  0 * SZREG]
37         stp     x18, x19, [x0, oX0 + 18 * SZREG]
38         stp     x20, x21, [x0, oX0 + 20 * SZREG]
39         stp     x22, x23, [x0, oX0 + 22 * SZREG]
40         stp     x24, x25, [x0, oX0 + 24 * SZREG]
41         stp     x26, x27, [x0, oX0 + 26 * SZREG]
42         stp     x28, x29, [x0, oX0 + 28 * SZREG]
43         str     x30,      [x0, oX0 + 30 * SZREG]
45         /* Place LR into the saved PC, this will ensure that when
46            switching to this saved context with setcontext() control
47            will pass back to the caller of getcontext(), we have
48            already arrange to return the appropriate return value in x0
49            above.  */
50         str     x30, [x0, oPC]
52         /* Save the current SP */
53         mov     x2, sp
54         str     x2, [x0, oSP]
56         /* Figure out where to place the first context extension
57            block.  */
58         add     x2, x0, #oEXTENSION
60         /* Write the context extension fpsimd header.  */
61         mov     w3, #(FPSIMD_MAGIC & 0xffff)
62         movk    w3, #(FPSIMD_MAGIC >> 16), lsl #16
63         str     w3, [x2, #oHEAD + oMAGIC]
64         mov     w3, #FPSIMD_CONTEXT_SIZE
65         str     w3, [x2, #oHEAD + oSIZE]
67         /* Fill in the FP SIMD context.  */
68         add     x3, x2, #oV0 + 8 * SZVREG
69         stp      d8,  d9, [x3], # 2 * SZVREG
70         stp     d10, d11, [x3], # 2 * SZVREG
71         stp     d12, d13, [x3], # 2 * SZVREG
72         stp     d14, d15, [x3], # 2 * SZVREG
74         add     x3, x2, oFPSR
76         mrs     x4, fpsr
77         str     w4, [x3]
79         mrs     x4, fpcr
80         str     w4, [x3, oFPCR - oFPSR]
82         /* Write the termination context extension header.  */
83         add     x2, x2, #FPSIMD_CONTEXT_SIZE
85         str     xzr, [x2, #oHEAD + oMAGIC]
86         str     xzr, [x2, #oHEAD + oSIZE]
88         /* Grab the signal mask */
89         /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
90         add     x2, x0, #UCONTEXT_SIGMASK
91         mov     x0, SIG_BLOCK
92         mov     x1, 0
93         mov     x3, _NSIG8
94         mov     x8, SYS_ify (rt_sigprocmask)
95         svc     0
96         cbnz    x0, 1f
98         /* Return 0 for success */
99         mov     x0, 0
100         RET
102         b       C_SYMBOL_NAME(__syscall_error)
104         PSEUDO_END (__getcontext)
105 weak_alias (__getcontext, getcontext)