Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / tile / swapcontext.S
blobef24e39898cf4f016fb7ec82f476e995a24b05fc
1 /* Copyright (C) 2011-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21 #include "ucontext_i.h"
23 /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
25         .text
26 ENTRY (__swapcontext)
27         FEEDBACK_ENTER(__swapcontext)
28         /* Set up a frame and save r0 and r1.  */
29         {
30          ST sp, lr
31          ADDI_PTR r11, sp, -(3 * REGSIZE)
32          move r10, sp
33         }
34         ADDI_PTR sp, sp, -(4 * REGSIZE)
35         cfi_def_cfa_offset (4 * REGSIZE)
36         cfi_offset (lr, 0)
37         {
38          ST r11, r10
39          ADDI_PTR r10, sp, (2 * REGSIZE)
40         }
41         {
42          ST r10, r0
43          ADDI_PTR r10, sp, (3 * REGSIZE)
44         }
45         ST r10, r1
47         /* Save the current context.  */
48         jal __getcontext
50         /* Tear down the frame and restore r0, r1, and lr. */
51         {
52          BNEZ r0, .Lerror
53          ADDI_PTR r1, sp, 3 * REGSIZE
54         }
55         {
56          LD r1, r1
57          ADDI_PTR r0, sp, 2 * REGSIZE
58         }
59         {
60          LD r0, r0
61          ADDI_PTR sp, sp, 4 * REGSIZE
62         }
63         cfi_def_cfa_offset (0)
64         {
65          LD lr, sp
66          ADDLI_PTR r10, r0, UC_REG(54)
67         }
69         /* Update the stored sp and lr.  */
70         {
71          ST r10, sp
72          ADDLI_PTR r10, r0, UC_REG(55)
73         }
74         ST r10, lr
76         /* Tail-call setcontext to finish up.  */
77         {
78          move r0, r1
79          j __setcontext
80         }
82 .Lerror:
83         ADDI_PTR sp, sp, 4 * REGSIZE
84         cfi_def_cfa_offset (0)
85         LD lr, sp
86         jrp lr
87 END (__swapcontext)
89 weak_alias (__swapcontext, swapcontext)