blob: 9675268e7fdeb37f700a8ed6c608b9a59583c95c [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Assembly part of rw semaphores.
3 *
4 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
5 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/ptrace.h>
8#include <asm/psr.h>
9
Sam Ravnborgc6d64c12008-01-28 21:06:23 -080010 .section .sched.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 .align 4
12
13 .globl ___down_read
14___down_read:
15 rd %psr, %g3
16 nop
17 nop
18 nop
19 or %g3, PSR_PIL, %g7
20 wr %g7, 0, %psr
21 nop
22 nop
23 nop
24#ifdef CONFIG_SMP
251: ldstub [%g1 + 4], %g7
26 tst %g7
27 bne 1b
28 ld [%g1], %g7
29 sub %g7, 1, %g7
30 st %g7, [%g1]
31 stb %g0, [%g1 + 4]
32#else
33 ld [%g1], %g7
34 sub %g7, 1, %g7
35 st %g7, [%g1]
36#endif
37 wr %g3, 0, %psr
38 add %g7, 1, %g7
39 nop
40 nop
41 subcc %g7, 1, %g7
42 bneg 3f
43 nop
442: jmpl %o7, %g0
45 mov %g4, %o7
463: save %sp, -64, %sp
47 mov %g1, %l1
48 mov %g4, %l4
49 bcs 4f
50 mov %g5, %l5
51 call down_read_failed
52 mov %l1, %o0
53 mov %l1, %g1
54 mov %l4, %g4
55 ba ___down_read
56 restore %l5, %g0, %g5
574: call down_read_failed_biased
58 mov %l1, %o0
59 mov %l1, %g1
60 mov %l4, %g4
61 ba 2b
62 restore %l5, %g0, %g5
63
64 .globl ___down_write
65___down_write:
66 rd %psr, %g3
67 nop
68 nop
69 nop
70 or %g3, PSR_PIL, %g7
71 wr %g7, 0, %psr
72 sethi %hi(0x01000000), %g2
73 nop
74 nop
75#ifdef CONFIG_SMP
761: ldstub [%g1 + 4], %g7
77 tst %g7
78 bne 1b
79 ld [%g1], %g7
80 sub %g7, %g2, %g7
81 st %g7, [%g1]
82 stb %g0, [%g1 + 4]
83#else
84 ld [%g1], %g7
85 sub %g7, %g2, %g7
86 st %g7, [%g1]
87#endif
88 wr %g3, 0, %psr
89 add %g7, %g2, %g7
90 nop
91 nop
92 subcc %g7, %g2, %g7
93 bne 3f
94 nop
952: jmpl %o7, %g0
96 mov %g4, %o7
973: save %sp, -64, %sp
98 mov %g1, %l1
99 mov %g4, %l4
100 bcs 4f
101 mov %g5, %l5
102 call down_write_failed
103 mov %l1, %o0
104 mov %l1, %g1
105 mov %l4, %g4
106 ba ___down_write
107 restore %l5, %g0, %g5
1084: call down_write_failed_biased
109 mov %l1, %o0
110 mov %l1, %g1
111 mov %l4, %g4
112 ba 2b
113 restore %l5, %g0, %g5
114
115 .text
116 .globl ___up_read
117___up_read:
118 rd %psr, %g3
119 nop
120 nop
121 nop
122 or %g3, PSR_PIL, %g7
123 wr %g7, 0, %psr
124 nop
125 nop
126 nop
127#ifdef CONFIG_SMP
1281: ldstub [%g1 + 4], %g7
129 tst %g7
130 bne 1b
131 ld [%g1], %g7
132 add %g7, 1, %g7
133 st %g7, [%g1]
134 stb %g0, [%g1 + 4]
135#else
136 ld [%g1], %g7
137 add %g7, 1, %g7
138 st %g7, [%g1]
139#endif
140 wr %g3, 0, %psr
141 nop
142 nop
143 nop
144 cmp %g7, 0
145 be 3f
146 nop
1472: jmpl %o7, %g0
148 mov %g4, %o7
1493: save %sp, -64, %sp
150 mov %g1, %l1
151 mov %g4, %l4
152 mov %g5, %l5
153 clr %o1
154 call __rwsem_wake
155 mov %l1, %o0
156 mov %l1, %g1
157 mov %l4, %g4
158 ba 2b
159 restore %l5, %g0, %g5
160
161 .globl ___up_write
162___up_write:
163 rd %psr, %g3
164 nop
165 nop
166 nop
167 or %g3, PSR_PIL, %g7
168 wr %g7, 0, %psr
169 sethi %hi(0x01000000), %g2
170 nop
171 nop
172#ifdef CONFIG_SMP
1731: ldstub [%g1 + 4], %g7
174 tst %g7
175 bne 1b
176 ld [%g1], %g7
177 add %g7, %g2, %g7
178 st %g7, [%g1]
179 stb %g0, [%g1 + 4]
180#else
181 ld [%g1], %g7
182 add %g7, %g2, %g7
183 st %g7, [%g1]
184#endif
185 wr %g3, 0, %psr
186 sub %g7, %g2, %g7
187 nop
188 nop
189 addcc %g7, %g2, %g7
190 bcs 3f
191 nop
1922: jmpl %o7, %g0
193 mov %g4, %o7
1943: save %sp, -64, %sp
195 mov %g1, %l1
196 mov %g4, %l4
197 mov %g5, %l5
198 mov %g7, %o1
199 call __rwsem_wake
200 mov %l1, %o0
201 mov %l1, %g1
202 mov %l4, %g4
203 ba 2b
204 restore %l5, %g0, %g5