branch update for HEAD-2003021201
[reactos.git] / ntoskrnl / ex / i386 / interlck.c
1 /* $Id$
2  *
3  * reactos/ntoskrnl/ex/i386/interlck.c
4  *
5  */
6 #include <ddk/ntddk.h>
7
8
9 INTERLOCKED_RESULT FASTCALL
10 Exfi386InterlockedIncrementLong(IN PLONG Addend);
11
12 __asm__("\n\t.global @Exfi386InterlockedIncrementLong@4\n\t"
13         "@Exfi386InterlockedIncrementLong@4:\n\t"
14         "addl $1,(%ecx)\n\t"
15         "lahf\n\t"
16         "andl $0xC000, %eax\n\t"
17         "ret\n\t");
18
19
20 INTERLOCKED_RESULT FASTCALL
21 Exfi386InterlockedDecrementLong(IN PLONG Addend);
22
23 __asm__("\n\t.global @Exfi386InterlockedDecrementLong@4\n\t"
24         "@Exfi386InterlockedDecrementLong@4:\n\t"
25         "subl $1,(%ecx)\n\t"
26         "lahf\n\t"
27         "andl $0xC000, %eax\n\t"
28         "ret\n\t");
29
30
31 ULONG FASTCALL
32 Exfi386InterlockedExchangeUlong(IN PULONG Target,
33                                 IN ULONG Value);
34
35 __asm__("\n\t.global @Exfi386InterlockedExchangeUlong@8\n\t"
36         "@Exfi386InterlockedExchangeUlong@8:\n\t"
37         "xchgl %edx,(%ecx)\n\t"
38         "movl  %edx,%eax\n\t"
39         "ret\n\t");
40
41
42
43 INTERLOCKED_RESULT STDCALL
44 Exi386InterlockedIncrementLong(IN PLONG Addend);
45
46 __asm__("\n\t.global _Exi386InterlockedIncrementLong@4\n\t"
47         "_Exi386InterlockedIncrementLong@4:\n\t"
48         "movl 4(%esp),%eax\n\t"
49         "addl $1,(%eax)\n\t"
50         "lahf\n\t"
51         "andl $0xC000, %eax\n\t"
52         "ret $4\n\t");
53
54
55 INTERLOCKED_RESULT STDCALL
56 Exi386InterlockedDecrementLong(IN PLONG Addend);
57
58 __asm__("\n\t.global _Exi386InterlockedDecrementLong@4\n\t"
59         "_Exi386InterlockedDecrementLong@4:\n\t"
60         "movl 4(%esp),%eax\n\t"
61         "subl $1,(%eax)\n\t"
62         "lahf\n\t"
63         "andl $0xC000, %eax\n\t"
64         "ret $4\n\t");
65
66
67 ULONG STDCALL
68 Exi386InterlockedExchangeUlong(IN PULONG Target,
69                                IN ULONG Value);
70
71 __asm__("\n\t.global _Exi386InterlockedExchangeUlong@8\n\t"
72         "_Exi386InterlockedExchangeUlong@8:\n\t"
73         "movl 4(%esp),%edx\n\t"
74         "movl 8(%esp),%eax\n\t"
75         "xchgl %eax,(%edx)\n\t"
76         "ret $8\n\t");
77
78
79 /**********************************************************************
80  * FASTCALL: @InterlockedIncrement@4
81  * STDCALL : _InterlockedIncrement@4
82  */
83 LONG FASTCALL
84 InterlockedIncrement(PLONG Addend);
85 /*
86  * FUNCTION: Increments a caller supplied variable of type LONG as an 
87  * atomic operation
88  * ARGUMENTS:
89  *     Addend = Points to a variable whose value is to be increment
90  * RETURNS: The incremented value
91  */
92
93 __asm__("\n\t.global @InterlockedIncrement@4\n\t"
94         "@InterlockedIncrement@4:\n\t"
95         "movl $1,%eax\n\t"
96         "xaddl %eax,(%ecx)\n\t"
97         "incl %eax\n\t"
98         "ret\n\t");
99
100
101 /**********************************************************************
102  * FASTCALL: @InterlockedDecrement@4
103  * STDCALL : _InterlockedDecrement@4
104  */
105 LONG FASTCALL
106 InterlockedDecrement(PLONG Addend);
107
108 __asm__("\n\t.global @InterlockedDecrement@4\n\t"
109         "@InterlockedDecrement@4:\n\t"
110         "movl $-1,%eax\n\t"
111         "xaddl %eax,(%ecx)\n\t"
112         "decl %eax\n\t"
113         "ret\n\t");
114
115
116 /**********************************************************************
117  * FASTCALL: @InterlockedExchange@8
118  * STDCALL : _InterlockedExchange@8
119  */
120
121 LONG FASTCALL
122 InterlockedExchange(PLONG Target,
123                     LONG Value);
124
125 __asm__("\n\t.global @InterlockedExchange@8\n\t"
126         "@InterlockedExchange@8:\n\t"
127         "xchgl %edx,(%ecx)\n\t"
128         "movl  %edx,%eax\n\t"
129         "ret\n\t");
130
131
132 /**********************************************************************
133  * FASTCALL: @InterlockedExchangeAdd@8
134  * STDCALL: _InterlockedExchangeAdd@8
135  */
136 LONG FASTCALL
137 InterlockedExchangeAdd(PLONG Addend,
138                        LONG Value);
139
140 __asm__("\n\t.global @InterlockedExchangeAdd@8\n\t"
141         "@InterlockedExchangeAdd@8:\n\t"
142         "xaddl %edx,(%ecx)\n\t"
143         "movl %edx,%eax\n\t"
144         "ret\n\t");
145
146
147 /**********************************************************************
148  * FASTCALL: @InterlockedCompareExchange@12
149  * STDCALL: _InterlockedCompareExchange@12
150  */
151 LONG FASTCALL
152 InterlockedCompareExchange(PLONG Destination,
153                            LONG Exchange,
154                            LONG Comperand);
155
156 __asm__("\n\t.global @InterlockedCompareExchange@12\n\t"
157         "@InterlockedCompareExchange@12:\n\t"
158         "movl 4(%esp),%eax\n\t"
159         "cmpxchg %edx,(%ecx)\n\t"
160         "ret $4\n\t");
161
162 /* EOF */