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