summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/sh/makecontext.S
blob: 0a9e0795459c8e6414cebce01a8a04d659906dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Create new context.
   Copyright (C) 2005 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <sysdep.h>

#include "ucontext_i.h"

/* void __makecontext (struct ucontext *ucp, void (*func)(), int argc, ...);
  __makecontext sets up a stack and registers for context to run a given
  function.  The registers are set up like this:
    r4-r7: parameters 1 to 4
    r8	 : uc_link from ucontext structure
    pc	 : (*func) pointer
    pr	 : address of exitcode
    r15	 : stack pointer for func.  */

	.text
	.align	5
ENTRY(__makecontext)
	mov	#4, r3
	mov.l	@(oSS_SP,r4), r1
	mov.l	@(oSS_SIZE,r4), r2
	add	r1, r2
	cmp/gt	r6, r3
	bf/s	1f
	 shlr2	r2
	sub	r6, r2
	add	r3, r2
1:
	shll2	r2
	mov	#oR15, r0
	mov.l	@(oLINK,r4), r1
	mov.l	r2, @(r0,r4)
	mov.l	r1, @(oR8,r4)
	mov	#oPC, r0
	mov.l	r5, @(r0,r4)

	cmp/pl	r6
	bf/s	.L1
	 dt	r6
	mov.l	r7, @(oR4,r4)
	cmp/pl	r6
	bf/s	.L1
	 dt	r6
	mov.l	@(0,r15), r1
	mov.l	r1, @(oR5,r4)
	cmp/pl	r6
	bf/s	.L1
	 dt	r6
	mov.l	@(4,r15), r1
	mov.l	r1, @(oR6,r4)
	cmp/pl	r6
	bf/s	.L1
	 dt	r6
	mov.l	@(8,r15), r1
	mov.l	r1, @(oR7,r4)
	mov	#12,r0
.L0:
	cmp/pl	r6
	bf/s	.L1
	 dt	r6
	mov.l	@(r0,r15), r1
	mov.l	r1, @r2
	add	#4, r0
	bra	.L0
	 add	#4, r2
.L1:
#ifdef PIC
	mova	.Lexitcode, r0
#else
	mov.l	.L2, r0
#endif
	add	#oPR, r4
	rts
	 mov.l	r0, @r4
#ifndef PIC
	.align	2
.L2:
	.long	.Lexitcode
#endif
	cfi_endproc

	.align	5
.Lexitcode:
	tst	r8, r8
	bt/s	2f
	 mov	r8, r4
#ifdef PIC
	mova	.Lgot, r0
	mov.l	.Lgot, r12
	add	r0, r12
	mov.l	.L3, r1
	bsrf	r1
.LPCS0:
	 nop
#else
	mov.l	.L3, r1
	jsr	@r1
	 nop
#endif
2:
	mov.l	.L4, r1
#ifdef PIC
	add	r12, r1
#endif
	jsr	@r1
	 mov	r0, r4
0:
	bra	0b
	 nop

	.align	2
#ifdef PIC
.Lgot:
	.long	_GLOBAL_OFFSET_TABLE_
.L3:
	.long	__setcontext@PLT-(.LPCS0+2-(.))
.L4:
	.long	HIDDEN_JUMPTARGET(exit)@GOTOFF
#else
.L3:
	.long	__setcontext
.L4:
	.long	HIDDEN_JUMPTARGET(exit)
#endif
	cfi_startproc
PSEUDO_END(__makecontext)

weak_alias (__makecontext, makecontext)