aboutsummaryrefslogtreecommitdiff
path: root/arch/sparc/lib/rwsem_32.S
blob: 9675268e7fdeb37f700a8ed6c608b9a59583c95c (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Assembly part of rw semaphores.
 *
 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
 */

#include <asm/ptrace.h>
#include <asm/psr.h>

	.section .sched.text, "ax"
	.align	4

	.globl		___down_read
___down_read:
	rd		%psr, %g3
	nop
	nop
	nop
	or		%g3, PSR_PIL, %g7
	wr		%g7, 0, %psr
	nop
	nop
	nop
#ifdef CONFIG_SMP
1:	ldstub		[%g1 + 4], %g7
	tst		%g7
	bne		1b
	 ld		[%g1], %g7
	sub		%g7, 1, %g7
	st		%g7, [%g1]
	stb		%g0, [%g1 + 4]
#else
	ld		[%g1], %g7
	sub		%g7, 1, %g7
	st		%g7, [%g1]
#endif
	wr		%g3, 0, %psr
	add		%g7, 1, %g7
	nop
	nop
	subcc		%g7, 1, %g7
	bneg		3f
	 nop
2:	jmpl		%o7, %g0
	 mov		%g4, %o7
3:	save		%sp, -64, %sp
	mov		%g1, %l1
	mov		%g4, %l4
	bcs		4f
	 mov		%g5, %l5
	call		down_read_failed
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		___down_read
	 restore	%l5, %g0, %g5
4:	call		down_read_failed_biased
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		2b
	 restore	%l5, %g0, %g5

	.globl		___down_write
___down_write:
	rd		%psr, %g3
	nop
	nop
	nop
	or		%g3, PSR_PIL, %g7
	wr		%g7, 0, %psr
	sethi		%hi(0x01000000), %g2
	nop
	nop
#ifdef CONFIG_SMP
1:	ldstub		[%g1 + 4], %g7
	tst		%g7
	bne		1b
	 ld		[%g1], %g7
	sub		%g7, %g2, %g7
	st		%g7, [%g1]
	stb		%g0, [%g1 + 4]
#else
	ld		[%g1], %g7
	sub		%g7, %g2, %g7
	st		%g7, [%g1]
#endif
	wr		%g3, 0, %psr
	add		%g7, %g2, %g7
	nop
	nop
	subcc		%g7, %g2, %g7
	bne		3f
	 nop
2:	jmpl		%o7, %g0
	 mov		%g4, %o7
3:	save		%sp, -64, %sp
	mov		%g1, %l1
	mov		%g4, %l4
	bcs		4f
	 mov		%g5, %l5
	call		down_write_failed
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		___down_write
	 restore	%l5, %g0, %g5
4:	call		down_write_failed_biased
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		2b
	 restore	%l5, %g0, %g5

	.text
	.globl		___up_read
___up_read:
	rd		%psr, %g3
	nop
	nop
	nop
	or		%g3, PSR_PIL, %g7
	wr		%g7, 0, %psr
	nop
	nop
	nop
#ifdef CONFIG_SMP
1:	ldstub		[%g1 + 4], %g7
	tst		%g7
	bne		1b
	 ld		[%g1], %g7
	add		%g7, 1, %g7
	st		%g7, [%g1]
	stb		%g0, [%g1 + 4]
#else
	ld		[%g1], %g7
	add		%g7, 1, %g7
	st		%g7, [%g1]
#endif
	wr		%g3, 0, %psr
	nop
	nop
	nop
	cmp		%g7, 0
	be		3f
	 nop
2:	jmpl		%o7, %g0
	 mov		%g4, %o7
3:	save		%sp, -64, %sp
	mov		%g1, %l1
	mov		%g4, %l4
	mov		%g5, %l5
	clr		%o1
	call		__rwsem_wake
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		2b
	 restore	%l5, %g0, %g5

	.globl		___up_write
___up_write:
	rd		%psr, %g3
	nop
	nop
	nop
	or		%g3, PSR_PIL, %g7
	wr		%g7, 0, %psr
	sethi		%hi(0x01000000), %g2
	nop
	nop
#ifdef CONFIG_SMP
1:	ldstub		[%g1 + 4], %g7
	tst		%g7
	bne		1b
	 ld		[%g1], %g7
	add		%g7, %g2, %g7
	st		%g7, [%g1]
	stb		%g0, [%g1 + 4]
#else
	ld		[%g1], %g7
	add		%g7, %g2, %g7
	st		%g7, [%g1]
#endif
	wr		%g3, 0, %psr
	sub		%g7, %g2, %g7
	nop
	nop
	addcc		%g7, %g2, %g7
	bcs		3f
	 nop
2:	jmpl		%o7, %g0
	 mov		%g4, %o7
3:	save		%sp, -64, %sp
	mov		%g1, %l1
	mov		%g4, %l4
	mov		%g5, %l5
	mov		%g7, %o1
	call		__rwsem_wake
	 mov		%l1, %o0
	mov		%l1, %g1
	mov		%l4, %g4
	ba		2b
	 restore	%l5, %g0, %g5