2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / sh / makecontext.S
blob877d78d3969d012ad44c2a73b291d52fc3ca7596
1 /* Create new context.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
22 #include "ucontext_i.h"
24 /* void __makecontext (struct ucontext *ucp, void (*func)(), int argc, ...);
25   __makecontext sets up a stack and registers for context to run a given
26   function.  The registers are set up like this:
27     r4-r7: parameters 1 to 4
28     r8   : uc_link from ucontext structure
29     pc   : (*func) pointer
30     pr   : address of exitcode
31     r15  : stack pointer for func.  */
33         .text
34         .align  5
35 ENTRY(__makecontext)
36         mov     #4, r3
37         mov.l   @(oSS_SP,r4), r1
38         mov.l   @(oSS_SIZE,r4), r2
39         add     r1, r2
40         cmp/gt  r6, r3
41         bf/s    1f
42          shlr2  r2
43         sub     r6, r2
44         add     r3, r2
46         shll2   r2
47         mov     #oR15, r0
48         mov.l   @(oLINK,r4), r1
49         mov.l   r2, @(r0,r4)
50         mov.l   r1, @(oR8,r4)
51         mov     #oPC, r0
52         mov.l   r5, @(r0,r4)
54         cmp/pl  r6
55         bf/s    .L1
56          dt     r6
57         mov.l   r7, @(oR4,r4)
58         cmp/pl  r6
59         bf/s    .L1
60          dt     r6
61         mov.l   @(0,r15), r1
62         mov.l   r1, @(oR5,r4)
63         cmp/pl  r6
64         bf/s    .L1
65          dt     r6
66         mov.l   @(4,r15), r1
67         mov.l   r1, @(oR6,r4)
68         cmp/pl  r6
69         bf/s    .L1
70          dt     r6
71         mov.l   @(8,r15), r1
72         mov.l   r1, @(oR7,r4)
73         mov     #12,r0
74 .L0:
75         cmp/pl  r6
76         bf/s    .L1
77          dt     r6
78         mov.l   @(r0,r15), r1
79         mov.l   r1, @r2
80         add     #4, r0
81         bra     .L0
82          add    #4, r2
83 .L1:
84 #ifdef PIC
85         mova    .Lexitcode, r0
86 #else
87         mov.l   .L2, r0
88 #endif
89         add     #oPR, r4
90         rts
91          mov.l  r0, @r4
92 #ifndef PIC
93         .align  2
94 .L2:
95         .long   .Lexitcode
96 #endif
97         cfi_endproc
99         .align  5
100 .Lexitcode:
101         tst     r8, r8
102         bt/s    2f
103          mov    r8, r4
104 #ifdef PIC
105         mova    .Lgot, r0
106         mov.l   .Lgot, r12
107         add     r0, r12
108         mov.l   .L3, r1
109         bsrf    r1
110 .LPCS0:
111          nop
112 #else
113         mov.l   .L3, r1
114         jsr     @r1
115          nop
116 #endif
118         mov.l   .L4, r1
119 #ifdef PIC
120         add     r12, r1
121 #endif
122         jsr     @r1
123          mov    r0, r4
125         bra     0b
126          nop
128         .align  2
129 #ifdef PIC
130 .Lgot:
131         .long   _GLOBAL_OFFSET_TABLE_
132 .L3:
133         .long   __setcontext@PLT-(.LPCS0+2-(.))
134 .L4:
135         .long   HIDDEN_JUMPTARGET(exit)@GOTOFF
136 #else
137 .L3:
138         .long   __setcontext
139 .L4:
140         .long   HIDDEN_JUMPTARGET(exit)
141 #endif
142         cfi_startproc
143 PSEUDO_END(__makecontext)
145 weak_alias (__makecontext, makecontext)