]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sh/makecontext.S
* sysdeps/unix/sysv/linux/sh/makecontext.S: New file.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sh / makecontext.S
1 /* Create new context.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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. */
19
20 #include <sysdep.h>
21
22 #include "ucontext_i.h"
23
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. */
32
33 .text
34 .align 5
35 cfi_startproc
36 ENTRY(__makecontext)
37 mov #4, r3
38 mov.l @(oSS_SP,r4), r1
39 mov.l @(oSS_SIZE,r4), r2
40 add r1, r2
41 cmp/gt r6, r3
42 bf/s 1f
43 shlr2 r2
44 sub r6, r2
45 add r3, r2
46 1:
47 shll2 r2
48 mov #oR15, r0
49 mov.l @(oLINK,r4), r1
50 mov.l r2, @(r0,r4)
51 mov.l r1, @(oR8,r4)
52 mov #oPC, r0
53 mov.l r5, @(r0,r4)
54
55 cmp/pl r6
56 bf/s .L1
57 dt r6
58 mov.l r7, @(oR4,r4)
59 cmp/pl r6
60 bf/s .L1
61 dt r6
62 mov.l @(0,r15), r1
63 mov.l r1, @(oR5,r4)
64 cmp/pl r6
65 bf/s .L1
66 dt r6
67 mov.l @(4,r15), r1
68 mov.l r1, @(oR6,r4)
69 cmp/pl r6
70 bf/s .L1
71 dt r6
72 mov.l @(8,r15), r1
73 mov.l r1, @(oR7,r4)
74 mov #12,r0
75 .L0:
76 cmp/pl r6
77 bf/s .L1
78 dt r6
79 mov.l @(r0,r15), r1
80 mov.l r1, @r2
81 add #4, r0
82 bra .L0
83 add #4, r2
84 .L1:
85 #ifdef PIC
86 mova .Lexitcode, r0
87 #else
88 mov.l .L2, r0
89 #endif
90 add #oPR, r4
91 rts
92 mov.l r0, @r4
93 #ifndef PIC
94 .align 2
95 .L2:
96 .long .Lexitcode
97 #endif
98 cfi_endproc
99
100 .align 5
101 .Lexitcode:
102 tst r8, r8
103 bt/s 2f
104 mov r8, r4
105 #ifdef PIC
106 mova .Lgot, r0
107 mov.l .Lgot, r12
108 add r0, r12
109 mov.l .L3, r1
110 bsrf r1
111 .LPCS0:
112 nop
113 #else
114 mov.l .L3, r1
115 jsr @r1
116 nop
117 #endif
118 2:
119 mov.l .L4, r1
120 #ifdef PIC
121 add r12, r1
122 #endif
123 jsr @r1
124 mov r0, r4
125 0:
126 bra 0b
127 nop
128
129 .align 2
130 #ifdef PIC
131 .Lgot:
132 .long _GLOBAL_OFFSET_TABLE_
133 .L3:
134 .long __setcontext@PLT-(.LPCS0+2-(.))
135 .L4:
136 .long HIDDEN_JUMPTARGET(exit)@GOTOFF
137 #else
138 .L3:
139 .long __setcontext
140 .L4:
141 .long HIDDEN_JUMPTARGET(exit)
142 #endif
143 PSEUDO_END(__makecontext)
144
145 weak_alias (__makecontext, makecontext)