5dc9afe13f0d0f1c30d0d65bcaa0788fa48a3534
[reactos.git] / reactos / ntoskrnl / rtl / interlck.c
1 /* $Id: interlck.c,v 1.6 1999/12/11 21:14:48 dwelch Exp $
2 *
3 * reactos/ntoskrnl/rtl/interlck.c
4 *
5 * FIXME: change decorated names when __fastcall will be available
6 * (for both egcs 1.1.2 and gcc 2.95 FASTCALL == STDCALL).
7 */
8 #include <reactos/config.h>
9 #include <ntos.h>
10 #include <internal/debug.h>
11
12 #if 0
13 LONG FASTCALL InterlockedIncrement(PLONG Addend)
14 {
15 LONG r;
16 (*Addend)++;
17 r = (*Addend);
18 return(r);
19 }
20
21 LONG FASTCALL InterlockedDecrement(PLONG Addend)
22 {
23 LONG r;
24 (*Addend)--;
25 r = (*Addend);
26 return(r);
27 }
28 #endif
29
30 /**********************************************************************
31 * FASTCALL: @InterlockedIncrement@0
32 * STDCALL : _InterlockedIncrement@4
33 */
34 #if 1
35 LONG FASTCALL InterlockedIncrement (PLONG Addend);
36 /*
37 * FUNCTION: Increments a caller supplied variable of type LONG as an
38 * atomic operation
39 * ARGUMENTS;
40 * Addend = Points to a variable whose value is to be increment
41 * RETURNS: The incremented value
42 */
43 __asm__("\n\t.global _InterlockedIncrement@4\n\t"
44 "_InterlockedIncrement@4:\n\t"
45 "pushl %ebp\n\t"
46 "movl %esp,%ebp\n\t"
47 "pushl %ebx\n\t"
48 "movl $1,%eax\n\t"
49 "movl 8(%ebp),%ebx\n\t"
50 "xaddl %eax,(%ebx)\n\t"
51 "incl %eax\n\t"
52 "popl %ebx\n\t"
53 "movl %ebp,%esp\n\t"
54 "popl %ebp\n\t"
55 "ret $4\n\t");
56 #endif
57
58 #if 0
59 /*
60 __asm__(
61 #ifndef CONFIG_USE_FASTCALL
62 ".global _InterlockedIncrement@4\n"
63 "\t_InterlockedIncrement@4:\n"
64 "\tmovl 4(%esp), %ecx\n"
65 #else
66 ".global @InterlockedIncrement@0\n"
67 "\t@InterlockedIncrement@0:\n"
68 #endif
69 "\tmov $1, %eax\n"
70 "\txadd %ecx, %eax\n"
71 "\tinc %eax\n\n"
72 #ifndef CONFIG_USE_FASTCALL
73 "\tret $4\n"
74 #endif
75 );
76 */
77 #endif
78
79 /**********************************************************************
80 * FASTCALL: @InterlockedDecrement@0
81 * STDCALL : _InterlockedDecrement@4
82 */
83 #if 1
84 LONG FASTCALL InterlockedDecrement(PLONG Addend);
85 __asm__("\n\t.global _InterlockedDecrement@4\n\t"
86 "_InterlockedDecrement@4:\n\t"
87 "pushl %ebp\n\t"
88 "movl %esp,%ebp\n\t"
89 "pushl %ebx\n\t"
90 "movl $-1,%eax\n\t"
91 "movl 8(%ebp),%ebx\n\t"
92 "xaddl %eax,(%ebx)\n\t"
93 "decl %eax\n\t"
94 "popl %ebx\n\t"
95 "movl %ebp,%esp\n\t"
96 "popl %ebp\n\t"
97 "ret $4\n\t");
98 #endif
99
100 /**********************************************************************
101 * FASTCALL: @InterlockedExchange@0
102 * STDCALL : _InterlockedExchange@8
103 */
104 LONG
105 FASTCALL
106 InterlockedExchange (
107 PLONG Target,
108 LONG Value
109 );
110 __asm__(
111 "\n\t.global _InterlockedExchange@8\n\t"
112 "_InterlockedExchange@8:\n\t"
113 "pushl %ebp\n\t"
114 "movl %esp,%ebp\n\t"
115 "pushl %ebx\n\t"
116 "movl 12(%ebp),%eax\n\t"
117 "movl 8(%ebp),%ebx\n\t"
118 "xchgl %eax,(%ebx)\n\t"
119 "popl %ebx\n\t"
120 "movl %ebp,%esp\n\t"
121 "popl %ebp\n\t"
122 "ret $8\n\t"
123 );
124 /*
125 __asm__(
126 #ifndef CONFIG_USE_FASTCALL
127 ".global _InterlockedExchange@8\n"
128 "_InterlockedExchange@8:\n"
129 "\tmovl 4(%esp), %ecx\n"
130 "\tmovl 8(%esp), %edx\n"
131 #else
132 ".global @InterlockedExchange@0\n"
133 "@InterlockedExchange@0:\n"
134 #endif
135 "\tmovl %ecx, %eax\n"
136 "__InterlockedExchange_Loop:\n"
137 "\tlock\n"
138 "\tcmpxchg %ecx, %edx\n"
139 "\tjne __InterlockedExchange_Loop\n"
140 #ifndef CONFIG_USE_FASTCALL
141 "\tmovl %ecx, 4(%esp)\n"
142 "\tret $8\n"
143 #else
144 "\tret\n"
145 #endif
146 );
147 */
148
149
150 /**********************************************************************
151 * FASTCALL: @InterlockedExchangeAdd@0
152 * STDCALL : _InterlockedExchangeAdd@8
153 */
154 LONG
155 FASTCALL
156 InterlockedExchangeAdd (
157 PLONG Addend,
158 LONG Value
159 );
160 __asm__(
161 "\n\t.global _InterlockedExchangeAdd@8\n\t"
162 "_InterlockedExchangeAdd@8:\n\t"
163 "movl 8(%esp),%eax\n\t"
164 "movl 4(%esp),%ebx\n\t"
165 "xaddl %eax,(%ebx)\n\t"
166 "ret $8\n\t"
167 );
168 /*
169 __asm__(
170 #ifndef CONFIG_USE_FASTCALL
171 ".global _InterlockedExchangeAdd@8\n"
172 "\t_InterlockedExchangeAdd@8:\n"
173 "\tmovl 4(%esp), %ecx\n"
174 "\tmovl 8(%esp), %edx\n"
175 #else
176 ".global @InterlockedExchangeAdd@0\n"
177 "\t@InterlockedExchangeAdd@0:\n"
178 #endif
179 "\txadd %edx, %ecx\n"
180 "\tmovl %edx, %eax\n"
181 #ifndef CONFIG_USE_FASTCALL
182 "\tret $8\n"
183 #else
184 "\tret\n"
185 #endif
186 );
187 */
188
189
190 /**********************************************************************
191 * FASTCALL: @InterlockedCompareExchange@4
192 * STDCALL : _InterlockedCompareExchange@12
193 */
194 PVOID
195 FASTCALL
196 InterlockedCompareExchange (
197 PVOID * Destination,
198 PVOID Exchange,
199 PVOID Comperand
200 );
201 __asm__(
202 "\n\t.global _InterlockedCompareExchange@12\n\t"
203 "_InterlockedCompareExchange@12:\n\t"
204 "movl 12(%esp),%eax\n\t"
205 "movl 8(%esp),%edx\n\t"
206 "movl 4(%esp),%ebx\n\t"
207 "cmpxchg %edx,(%ebx)\n\t"
208 "movl %edx,%eax\n\t"
209 "ret $12\n\t"
210 );
211 /*
212 __asm__(
213 #ifndef CONFIG_USE_FASTCALL
214 ".global _InterlockedCompareExchange@12\n"
215 "\t_InterlockedCompareExchange@12:\n"
216 "\tmovl 4(%esp), %ecx\n"
217 "\tmovl 8(%esp), %edx\n"
218 "\tmovl 12(%esp), %eax\n"
219 #else
220 ".global @InterlockedCompareExchange@4\n"
221 "\t@InterlockedCompareExchange@4:\n"
222 "\tmovl 4(%esp), %eax\n"
223 #endif
224 "\tcmpxchg %ecx, %edx\n"
225 #ifndef CONFIG_USE_FASTCALL
226 "\tret $12\n"
227 #else
228 "\tret $4\n"
229 #endif
230 */
231
232
233 /* EOF */