Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / aarch64 / setcontext.S
blobd220c41f678b2515e623d3bf9ca596d23075eaa4
1 /* Set current context.
3    Copyright (C) 2009-2014 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 setcontext (const ucontext_t *ucp) */
27         .text
29 ENTRY(__setcontext)
31         /* Create a signal frame on the stack:
33                 fp
34                 lr
35                 ...
36            sp-> rt_sigframe
37          */
39         stp     x29, x30, [sp, -16]!
40         cfi_adjust_cfa_offset (16)
41         cfi_rel_offset (x29, 0)
42         cfi_rel_offset (x30, 8)
44         mov     x29, sp
45         cfi_def_cfa_register (x29)
47         /* Allocate space for the sigcontext.  */
48         mov     w3, #((RT_SIGFRAME_SIZE + SP_ALIGN_SIZE) & SP_ALIGN_MASK)
49         sub     sp, sp, x3
51         /* Compute the base address of the ucontext structure.  */
52         add     x1, sp, #RT_SIGFRAME_UCONTEXT
54         /* Only ucontext is required in the frame, *copy* it in.  */
56 #if UCONTEXT_SIZE % 16
57 #error The implementation of setcontext.S assumes sizeof(ucontext_t) % 16 == 0
58 #endif
60         mov     x2, #UCONTEXT_SIZE / 16
62         ldp     x3, x4, [x0], #16
63         stp     x3, x4, [x1], #16
64         sub     x2, x2, 1
65         cbnz    x2, 0b
67         /* rt_sigreturn () -- no arguments, sp points to struct rt_sigframe.  */
68         mov     x8, SYS_ify (rt_sigreturn)
69         svc     0
71         /* Ooops we failed.  Recover the stack */
73         mov     sp, x29
74         cfi_def_cfa_register (sp)
76         ldp     x29, x30, [sp], 16
77         cfi_adjust_cfa_offset (16)
78         cfi_restore (x29)
79         cfi_restore (x30)
80         b       C_SYMBOL_NAME(__syscall_error)
82 PSEUDO_END (__setcontext)
83 weak_alias (__setcontext, setcontext)
85 ENTRY(__startcontext)
86         mov     x0, x19
87         cbnz    x0, __setcontext
88 1:      b       HIDDEN_JUMPTARGET(_exit)
89 END(__startcontext)