Fix some MSC intrinsics
[reactos.git] / reactos / include / crt / msc / intrin.h
1 #ifndef KJK_INTRIN_H_
2 #define KJK_INTRIN_H_
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 /*** Stack frame juggling ***/
9 void * _ReturnAddress(void);
10 #pragma intrinsic(_ReturnAddress)
11 void * _AddressOfReturnAddress(void);
12 #pragma intrinsic(_AddressOfReturnAddress)
13 unsigned int __getcallerseflags(void);
14 #pragma intrinsic(__getcallerseflags)
15
16 /*** Atomic operations ***/
17 void _ReadWriteBarrier(void);
18 #pragma intrinsic(_ReadWriteBarrier)
19 void _ReadBarrier(void);
20 #pragma intrinsic(_ReadBarrier)
21 void _WriteBarrier(void);
22 #pragma intrinsic(_WriteBarrier)
23
24 short _InterlockedCompareExchange16(volatile short * const Destination, const short Exchange, const short Comperand);
25 #pragma intrinsic(_InterlockedCompareExchange16)
26 long _InterlockedCompareExchange(volatile long * const Destination, const long Exchange, const long Comperand);
27 #pragma intrinsic(_InterlockedCompareExchange)
28 #if defined(_AMD64_) || defined(_IA64_)
29 void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand);
30 #pragma intrinsic(_InterlockedCompareExchangePointer)
31 void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value);
32 #pragma intrinsic(_InterlockedExchangePointer)
33 #else
34 #define _InterlockedCompareExchangePointer _InterlockedCompareExchange
35 #define _InterlockedExchangePointer _InterlockedExchange
36 #endif
37 long _InterlockedExchange(volatile long * const Target, const long Value);
38 #pragma intrinsic(_InterlockedExchange)
39
40 long _InterlockedExchangeAdd(volatile long * const Addend, const long Value);
41 #pragma intrinsic(_InterlockedExchangeAdd)
42 char _InterlockedAnd8(volatile char * const value, const char mask);
43 #pragma intrinsic(_InterlockedAnd8)
44 short _InterlockedAnd16(volatile short * const value, const short mask);
45 #pragma intrinsic(_InterlockedAnd16)
46 long _InterlockedAnd(volatile long * const value, const long mask);
47 #pragma intrinsic(_InterlockedAnd)
48 char _InterlockedOr8(volatile char * const value, const char mask);
49 #pragma intrinsic(_InterlockedOr8)
50 short _InterlockedOr16(volatile short * const value, const short mask);
51 #pragma intrinsic(_InterlockedOr16)
52 long _InterlockedOr(volatile long * const value, const long mask);
53 #pragma intrinsic(_InterlockedOr)
54 char _InterlockedXor8(volatile char * const value, const char mask);
55 #pragma intrinsic(_InterlockedXor8)
56 short _InterlockedXor16(volatile short * const value, const short mask);
57 #pragma intrinsic(_InterlockedXor16)
58 long _InterlockedXor(volatile long * const value, const long mask);
59 #pragma intrinsic(_InterlockedXor)
60 long _InterlockedAddLargeStatistic(volatile __int64 * const Addend, const long Value);
61 #pragma intrinsic(_InterlockedAddLargeStatistic)
62 long _InterlockedDecrement(volatile long * const lpAddend);
63 #pragma intrinsic(_InterlockedDecrement)
64 long _InterlockedIncrement(volatile long * const lpAddend);
65 #pragma intrinsic(_InterlockedIncrement)
66 short _InterlockedDecrement16(volatile short * const lpAddend);
67 #pragma intrinsic(_InterlockedDecrement16)
68 short _InterlockedIncrement16(volatile short * const lpAddend);
69 #pragma intrinsic(_InterlockedIncrement16)
70 unsigned char _interlockedbittestandreset(volatile long * a, const long b);
71 #pragma intrinsic(_interlockedbittestandreset)
72 unsigned char _interlockedbittestandset(volatile long * a, const long b);
73 #pragma intrinsic(_interlockedbittestandset)
74
75 #if defined(_M_AMD64)
76 __int64 _InterlockedExchange64(volatile __int64 * const Target, const __int64 Value);
77 #pragma intrinsic(_InterlockedExchange64)
78 __int64 _InterlockedExchangeAdd64(volatile __int64 * const Addend, const __int64 Value);
79 #pragma intrinsic(_InterlockedExchangeAdd64)
80 __int64 _InterlockedAnd64(volatile __int64 * const value, const __int64 mask);
81 #pragma intrinsic(_InterlockedAnd64)
82 long _InterlockedOr64(volatile __int64 * const value, const __int64 mask);
83 #pragma intrinsic(_InterlockedOr64)
84 __int64 _InterlockedCompareExchange64(volatile __int64 * const Destination, const __int64 Exchange, const __int64 Comperand);
85 #pragma intrinsic(_InterlockedCompareExchange64)
86 __int64 _InterlockedDecrement64(volatile __int64 * const lpAddend);
87 #pragma intrinsic(_InterlockedDecrement64)
88 __int64 _InterlockedIncrement64(volatile __int64 * const lpAddend);
89 #pragma intrinsic(_InterlockedIncrement64)
90 unsigned char _interlockedbittestandreset64(volatile __int64 * a, const __int64 b);
91 #pragma intrinsic(_interlockedbittestandreset64)
92 unsigned char _interlockedbittestandset64(volatile __int64 * a, const __int64 b);
93 #pragma intrinsic(_interlockedbittestandset64)
94 #endif
95
96 /*** String operations ***/
97 void __stosb(unsigned char * Dest, const unsigned char Data, size_t Count);
98 #pragma intrinsic(__stosb)
99 void __stosw(unsigned short * Dest, const unsigned short Data, size_t Count);
100 #pragma intrinsic(__stosw)
101 void __stosd(unsigned long * Dest, const unsigned long Data, size_t Count);
102 #pragma intrinsic(__stosd)
103 void __movsb(unsigned char * Destination, const unsigned char * Source, size_t Count);
104 #pragma intrinsic(__movsb)
105 void __movsw(unsigned short * Destination, const unsigned short * Source, size_t Count);
106 #pragma intrinsic(__movsw)
107 void __movsd(unsigned long * Destination, const unsigned long * Source, size_t Count);
108 #pragma intrinsic(__movsd)
109
110 #if defined(_M_AMD64)
111 /*** GS segment addressing ***/
112 void __writegsbyte(const unsigned long Offset, const unsigned char Data);
113 #pragma intrinsic(__writegsbyte)
114 void __writegsword(const unsigned long Offset, const unsigned short Data);
115 #pragma intrinsic(__writegsword)
116 void __writegsdword(const unsigned long Offset, const unsigned long Data);
117 #pragma intrinsic(__writegsdword)
118 void __writegsqword(const unsigned long Offset, const unsigned __int64 Data);
119 #pragma intrinsic(__writegsqword)
120 unsigned char __readgsbyte(const unsigned long Offset);
121 #pragma intrinsic(__readgsbyte)
122 unsigned short __readgsword(const unsigned long Offset);
123 #pragma intrinsic(__readgsword)
124 unsigned long __readgsdword(const unsigned long Offset);
125 #pragma intrinsic(__readgsdword)
126 unsigned __int64 __readgsqword(const unsigned long Offset);
127 #pragma intrinsic(__readgsqword)
128 void __incgsbyte(const unsigned long Offset);
129 #pragma intrinsic(__incgsbyte)
130 void __incgsword(const unsigned long Offset);
131 #pragma intrinsic(__incgsword)
132 void __incgsdword(const unsigned long Offset);
133 #pragma intrinsic(__incgsdword)
134 void __addgsbyte(const unsigned long Offset, const unsigned char Data);
135 #pragma intrinsic(__addgsbyte)
136 void __addgsword(const unsigned long Offset, const unsigned short Data);
137 #pragma intrinsic(__addgsword)
138 void __addgsdword(const unsigned long Offset, const unsigned int Data);
139 #pragma intrinsic(__addgsdword)
140 void __addgsqword(const unsigned long Offset, const unsigned __int64 Data);
141 #pragma intrinsic(__addgsqword)
142 #endif
143
144 //#if defined(_M_IX86)
145 /*** FS segment addressing ***/
146 void __writefsbyte(const unsigned long Offset, const unsigned char Data);
147 #pragma intrinsic(__writefsbyte)
148 void __writefsword(const unsigned long Offset, const unsigned short Data);
149 #pragma intrinsic(__writefsword)
150 void __writefsdword(const unsigned long Offset, const unsigned long Data);
151 #pragma intrinsic(__writefsdword)
152 unsigned char __readfsbyte(const unsigned long Offset);
153 #pragma intrinsic(__readfsbyte)
154 unsigned short __readfsword(const unsigned long Offset);
155 #pragma intrinsic(__readfsword)
156 unsigned long __readfsdword(const unsigned long Offset);
157 #pragma intrinsic(__readfsdword)
158 void __incfsbyte(const unsigned long Offset);
159 #pragma intrinsic(__incfsbyte)
160 void __incfsword(const unsigned long Offset);
161 #pragma intrinsic(__incfsword)
162 void __incfsdword(const unsigned long Offset);
163 #pragma intrinsic(__incfsdword)
164 void __addfsbyte(const unsigned long Offset, const unsigned char Data);
165 #pragma intrinsic(__addfsbyte)
166 void __addfsword(const unsigned long Offset, const unsigned short Data);
167 #pragma intrinsic(__addfsword)
168 void __addfsdword(const unsigned long Offset, const unsigned int Data);
169 #pragma intrinsic(__addfsdword)
170 //#endif
171
172
173 /*** Bit manipulation ***/
174 unsigned char _BitScanForward(unsigned long * const Index, const unsigned long Mask);
175 #pragma intrinsic(_BitScanForward)
176 unsigned char _BitScanReverse(unsigned long * const Index, const unsigned long Mask);
177 #pragma intrinsic(_BitScanReverse)
178 unsigned char _bittest(const long * const a, const long b);
179 #pragma intrinsic(_bittest)
180 unsigned char _bittestandcomplement(long * const a, const long b);
181 #pragma intrinsic(_bittestandcomplement)
182 unsigned char _bittestandreset(long * const a, const long b);
183 #pragma intrinsic(_bittestandreset)
184 unsigned char _bittestandset(long * const a, const long b);
185 #pragma intrinsic(_bittestandset)
186 unsigned char _rotl8(unsigned char value, unsigned char shift);
187 #pragma intrinsic(_rotl8)
188 unsigned short _rotl16(unsigned short value, unsigned char shift);
189 #pragma intrinsic(_rotl16)
190 unsigned int _rotl(unsigned int value, int shift);
191 #pragma intrinsic(_rotl)
192 unsigned int _rotr(unsigned int value, int shift);
193 #pragma intrinsic(_rotr)
194 unsigned char _rotr8(unsigned char value, unsigned char shift);
195 #pragma intrinsic(_rotr8)
196 unsigned short _rotr16(unsigned short value, unsigned char shift);
197 #pragma intrinsic(_rotr16)
198 unsigned __int64 __ll_lshift(const unsigned __int64 Mask, const int Bit);
199 #pragma intrinsic(__ll_lshift)
200 __int64 __ll_rshift(const __int64 Mask, const int Bit);
201 #pragma intrinsic(__ll_rshift)
202 unsigned __int64 __ull_rshift(const unsigned __int64 Mask, int Bit);
203 #pragma intrinsic(__ull_rshift)
204 unsigned short _byteswap_ushort(unsigned short value);
205 #pragma intrinsic(_byteswap_ushort)
206 unsigned long _byteswap_ulong(unsigned long value);
207 #pragma intrinsic(_byteswap_ulong)
208 unsigned __int64 _byteswap_uint64(unsigned __int64 value);
209 #pragma intrinsic(_byteswap_uint64)
210
211 /*** 64-bit math ***/
212 __int64 __emul(const int a, const int b);
213 #pragma intrinsic(__emul)
214 unsigned __int64 __emulu(const unsigned int a, const unsigned int b);
215 #pragma intrinsic(__emulu)
216
217 /*** Port I/O ***/
218 unsigned char __inbyte(const unsigned short Port);
219 #pragma intrinsic(__inbyte)
220 unsigned short __inword(const unsigned short Port);
221 #pragma intrinsic(__inword)
222 unsigned long __indword(const unsigned short Port);
223 #pragma intrinsic(__indword)
224 void __inbytestring(unsigned short Port, unsigned char * Buffer, unsigned long Count);
225 #pragma intrinsic(__inbytestring)
226 void __inwordstring(unsigned short Port, unsigned short * Buffer, unsigned long Count);
227 #pragma intrinsic(__inwordstring)
228 void __indwordstring(unsigned short Port, unsigned long * Buffer, unsigned long Count);
229 #pragma intrinsic(__indwordstring)
230 void __outbyte(unsigned short const Port, const unsigned char Data);
231 #pragma intrinsic(__outbyte)
232 void __outword(unsigned short const Port, const unsigned short Data);
233 #pragma intrinsic(__outword)
234 void __outdword(unsigned short const Port, const unsigned long Data);
235 #pragma intrinsic(__outdword)
236 void __outbytestring(unsigned short const Port, const unsigned char * const Buffer, const unsigned long Count);
237 #pragma intrinsic(__outbytestring)
238 void __outwordstring(unsigned short const Port, const unsigned short * const Buffer, const unsigned long Count);
239 #pragma intrinsic(__outwordstring)
240 void __outdwordstring(unsigned short const Port, const unsigned long * const Buffer, const unsigned long Count);
241 #pragma intrinsic(__outdwordstring)
242
243 /*** System information ***/
244 void __cpuid(int CPUInfo[], const int InfoType);
245 #pragma intrinsic(__cpuid)
246 unsigned __int64 __rdtsc(void);
247 #pragma intrinsic(__rdtsc)
248 void __writeeflags(uintptr_t Value);
249 #pragma intrinsic(__writeeflags)
250 uintptr_t __readeflags(void);
251 #pragma intrinsic(__readeflags)
252
253 /*** Interrupts ***/
254 void __debugbreak(void);
255 #pragma intrinsic(__debugbreak)
256 void __int2c(void);
257 #pragma intrinsic(__int2c)
258 void _disable(void);
259 #pragma intrinsic(_disable)
260 void _enable(void);
261 #pragma intrinsic(_enable)
262 void __halt(void);
263 #pragma intrinsic(__halt)
264
265 /*** Protected memory management ***/
266 void __writecr0(const unsigned __int64 Data);
267 #pragma intrinsic(__writecr0)
268 void __writecr3(const unsigned __int64 Data);
269 #pragma intrinsic(__writecr3)
270 void __writecr4(const unsigned __int64 Data);
271 #pragma intrinsic(__writecr4)
272
273 #ifdef _M_AMD64
274 void __writecr8(const unsigned __int64 Data);
275 #pragma intrinsic(__writecr8)
276 unsigned __int64 __readcr0(void);
277 #pragma intrinsic(__readcr0)
278 unsigned __int64 __readcr2(void);
279 #pragma intrinsic(__readcr2)
280 unsigned __int64 __readcr3(void);
281 #pragma intrinsic(__readcr3)
282 unsigned __int64 __readcr4(void);
283 #pragma intrinsic(__readcr4)
284 unsigned __int64 __readcr8(void);
285 #pragma intrinsic(__readcr8)
286 unsigned __int64 __readdr(unsigned int reg);
287 #pragma intrinsic(__readdr)
288 void __writedr(unsigned reg, unsigned __int64 value);
289 #pragma intrinsic(__writedr)
290 #else
291 unsigned long __readcr0(void);
292 unsigned long __readcr2(void);
293 unsigned long __readcr3(void);
294 unsigned long __readcr4(void);
295 unsigned int __readdr(unsigned int reg);
296 void __writedr(unsigned reg, unsigned int value);
297 #endif
298
299 void __invlpg(void * const Address);
300 #pragma intrinsic(__invlpg)
301
302 /*** System operations ***/
303 unsigned __int64 __readmsr(const int reg);
304 #pragma intrinsic(__readmsr)
305 void __writemsr(const unsigned long Register, const unsigned __int64 Value);
306 #pragma intrinsic(__writemsr)
307 unsigned __int64 __readpmc(const int counter);
308 #pragma intrinsic(__readpmc)
309 unsigned long __segmentlimit(const unsigned long a);
310 #pragma intrinsic(__segmentlimit)
311 void __wbinvd(void);
312 #pragma intrinsic(__wbinvd)
313 void __lidt(void *Source);
314 #pragma intrinsic(__lidt)
315 void __sidt(void *Destination);
316 #pragma intrinsic(__sidt)
317 void _mm_pause(void);
318 #pragma intrinsic(_mm_pause)
319
320 #ifdef __cplusplus
321 }
322 #endif
323
324 #endif /* KJK_INTRIN_H_ */
325
326 /* EOF */