01f80b5c45d2fde74444b1be34b39016e7310e8f
[pandora-kernel.git] / arch / i386 / lib / semaphore.S
1 /*
2  * i386 semaphore implementation.
3  *
4  * (C) Copyright 1999 Linus Torvalds
5  *
6  * Portions Copyright 1999 Red Hat, Inc.
7  *
8  *      This program is free software; you can redistribute it and/or
9  *      modify it under the terms of the GNU General Public License
10  *      as published by the Free Software Foundation; either version
11  *      2 of the License, or (at your option) any later version.
12  *
13  * rw semaphores implemented November 1999 by Benjamin LaHaise <bcrl@kvack.org>
14  */
15
16 #include <linux/config.h>
17 #include <linux/linkage.h>
18 #include <asm/rwlock.h>
19 #include <asm/alternative-asm.i>
20 #include <asm/frame.i>
21 #include <asm/dwarf2.h>
22
23 /*
24  * The semaphore operations have a special calling sequence that
25  * allow us to do a simpler in-line version of them. These routines
26  * need to convert that sequence back into the C sequence when
27  * there is contention on the semaphore.
28  *
29  * %eax contains the semaphore pointer on entry. Save the C-clobbered
30  * registers (%eax, %edx and %ecx) except %eax whish is either a return
31  * value or just clobbered..
32  */
33         .section .sched.text
34 ENTRY(__down_failed)
35         CFI_STARTPROC
36         FRAME
37         pushl %edx
38         CFI_ADJUST_CFA_OFFSET 4
39         CFI_REL_OFFSET edx,0
40         pushl %ecx
41         CFI_ADJUST_CFA_OFFSET 4
42         CFI_REL_OFFSET ecx,0
43         call __down
44         popl %ecx
45         CFI_ADJUST_CFA_OFFSET -4
46         CFI_RESTORE ecx
47         popl %edx
48         CFI_ADJUST_CFA_OFFSET -4
49         CFI_RESTORE edx
50         ENDFRAME
51         ret
52         CFI_ENDPROC
53         END(__down_failed)
54
55 ENTRY(__down_failed_interruptible)
56         CFI_STARTPROC
57         FRAME
58         pushl %edx
59         CFI_ADJUST_CFA_OFFSET 4
60         CFI_REL_OFFSET edx,0
61         pushl %ecx
62         CFI_ADJUST_CFA_OFFSET 4
63         CFI_REL_OFFSET ecx,0
64         call __down_interruptible
65         popl %ecx
66         CFI_ADJUST_CFA_OFFSET -4
67         CFI_RESTORE ecx
68         popl %edx
69         CFI_ADJUST_CFA_OFFSET -4
70         CFI_RESTORE edx
71         ENDFRAME
72         ret
73         CFI_ENDPROC
74         END(__down_failed_interruptible)
75
76 ENTRY(__down_failed_trylock)
77         CFI_STARTPROC
78         FRAME
79         pushl %edx
80         CFI_ADJUST_CFA_OFFSET 4
81         CFI_REL_OFFSET edx,0
82         pushl %ecx
83         CFI_ADJUST_CFA_OFFSET 4
84         CFI_REL_OFFSET ecx,0
85         call __down_trylock
86         popl %ecx
87         CFI_ADJUST_CFA_OFFSET -4
88         CFI_RESTORE ecx
89         popl %edx
90         CFI_ADJUST_CFA_OFFSET -4
91         CFI_RESTORE edx
92         ENDFRAME
93         ret
94         CFI_ENDPROC
95         END(__down_failed_trylock)
96
97 ENTRY(__up_wakeup)
98         CFI_STARTPROC
99         FRAME
100         pushl %edx
101         CFI_ADJUST_CFA_OFFSET 4
102         CFI_REL_OFFSET edx,0
103         pushl %ecx
104         CFI_ADJUST_CFA_OFFSET 4
105         CFI_REL_OFFSET ecx,0
106         call __up
107         popl %ecx
108         CFI_ADJUST_CFA_OFFSET -4
109         CFI_RESTORE ecx
110         popl %edx
111         CFI_ADJUST_CFA_OFFSET -4
112         CFI_RESTORE edx
113         ENDFRAME
114         ret
115         CFI_ENDPROC
116         END(__up_wakeup)
117
118 /*
119  * rw spinlock fallbacks
120  */
121 #ifdef CONFIG_SMP
122 ENTRY(__write_lock_failed)
123         CFI_STARTPROC simple
124         FRAME
125 2:      LOCK_PREFIX
126         addl    $ RW_LOCK_BIAS,(%eax)
127 1:      rep; nop
128         cmpl    $ RW_LOCK_BIAS,(%eax)
129         jne     1b
130         LOCK_PREFIX
131         subl    $ RW_LOCK_BIAS,(%eax)
132         jnz     2b
133         ENDFRAME
134         ret
135         CFI_ENDPROC
136         END(__write_lock_failed)
137
138 ENTRY(__read_lock_failed)
139         CFI_STARTPROC
140         FRAME
141 2:      LOCK_PREFIX
142         incl    (%eax)
143 1:      rep; nop
144         cmpl    $1,(%eax)
145         js      1b
146         LOCK_PREFIX
147         decl    (%eax)
148         js      2b
149         ENDFRAME
150         ret
151         CFI_ENDPROC
152         END(__read_lock_failed)
153
154 #endif
155
156 /* Fix up special calling conventions */
157 ENTRY(call_rwsem_down_read_failed)
158         CFI_STARTPROC
159         push %ecx
160         CFI_ADJUST_CFA_OFFSET 4
161         CFI_REL_OFFSET ecx,0
162         push %edx
163         CFI_ADJUST_CFA_OFFSET 4
164         CFI_REL_OFFSET edx,0
165         call rwsem_down_read_failed
166         pop %edx
167         CFI_ADJUST_CFA_OFFSET -4
168         pop %ecx
169         CFI_ADJUST_CFA_OFFSET -4
170         ret
171         CFI_ENDPROC
172         END(call_rwsem_down_read_failed)
173
174 ENTRY(call_rwsem_down_write_failed)
175         CFI_STARTPROC
176         push %ecx
177         CFI_ADJUST_CFA_OFFSET 4
178         CFI_REL_OFFSET ecx,0
179         calll rwsem_down_write_failed
180         pop %ecx
181         CFI_ADJUST_CFA_OFFSET -4
182         ret
183         CFI_ENDPROC
184         END(call_rwsem_down_write_failed)
185
186 ENTRY(call_rwsem_wake)
187         CFI_STARTPROC
188         decw %dx    /* do nothing if still outstanding active readers */
189         jnz 1f
190         push %ecx
191         CFI_ADJUST_CFA_OFFSET 4
192         CFI_REL_OFFSET ecx,0
193         call rwsem_wake
194         pop %ecx
195         CFI_ADJUST_CFA_OFFSET -4
196 1:      ret
197         CFI_ENDPROC
198         END(call_rwsem_wake)
199
200 /* Fix up special calling conventions */
201 ENTRY(call_rwsem_downgrade_wake)
202         CFI_STARTPROC
203         push %ecx
204         CFI_ADJUST_CFA_OFFSET 4
205         CFI_REL_OFFSET ecx,0
206         push %edx
207         CFI_ADJUST_CFA_OFFSET 4
208         CFI_REL_OFFSET edx,0
209         call rwsem_downgrade_wake
210         pop %edx
211         CFI_ADJUST_CFA_OFFSET -4
212         pop %ecx
213         CFI_ADJUST_CFA_OFFSET -4
214         ret
215         CFI_ENDPROC
216         END(call_rwsem_downgrade_wake)
217