conio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the w64 mingw-runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER within this package.
  5. */
  6. #ifndef _INC_CONIO
  7. #define _INC_CONIO
  8. #include <_mingw.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. _CRTIMP char *_cgets(char *_Buffer);
  13. _CRTIMP int __cdecl _cprintf(const char *_Format,...);
  14. _CRTIMP int __cdecl _cputs(const char *_Str);
  15. _CRTIMP int __cdecl _cscanf(const char *_Format,...);
  16. _CRTIMP int __cdecl _cscanf_l(const char *_Format,_locale_t _Locale,...);
  17. _CRTIMP int __cdecl _getch(void);
  18. _CRTIMP int __cdecl _getche(void);
  19. _CRTIMP int __cdecl _vcprintf(const char *_Format,va_list _ArgList);
  20. _CRTIMP int __cdecl _cprintf_p(const char *_Format,...);
  21. _CRTIMP int __cdecl _vcprintf_p(const char *_Format,va_list _ArgList);
  22. _CRTIMP int __cdecl _cprintf_l(const char *_Format,_locale_t _Locale,...);
  23. _CRTIMP int __cdecl _vcprintf_l(const char *_Format,_locale_t _Locale,va_list _ArgList);
  24. _CRTIMP int __cdecl _cprintf_p_l(const char *_Format,_locale_t _Locale,...);
  25. _CRTIMP int __cdecl _vcprintf_p_l(const char *_Format,_locale_t _Locale,va_list _ArgList);
  26. _CRTIMP int __cdecl _kbhit(void);
  27. #if defined(_X86_) && !defined(__x86_64)
  28. int __cdecl _inp(unsigned short);
  29. unsigned short __cdecl _inpw(unsigned short);
  30. unsigned long __cdecl _inpd(unsigned short);
  31. int __cdecl _outp(unsigned short,int);
  32. unsigned short __cdecl _outpw(unsigned short,unsigned short);
  33. unsigned long __cdecl _outpd(unsigned short,unsigned long);
  34. #endif
  35. _CRTIMP int __cdecl _putch(int _Ch);
  36. _CRTIMP int __cdecl _ungetch(int _Ch);
  37. _CRTIMP int __cdecl _getch_nolock(void);
  38. _CRTIMP int __cdecl _getche_nolock(void);
  39. _CRTIMP int __cdecl _putch_nolock(int _Ch);
  40. _CRTIMP int __cdecl _ungetch_nolock(int _Ch);
  41. #ifndef _WCONIO_DEFINED
  42. #define _WCONIO_DEFINED
  43. #ifndef WEOF
  44. #define WEOF (wint_t)(0xFFFF)
  45. #endif
  46. _CRTIMP wchar_t *_cgetws(wchar_t *_Buffer);
  47. _CRTIMP wint_t __cdecl _getwch(void);
  48. _CRTIMP wint_t __cdecl _getwche(void);
  49. _CRTIMP wint_t __cdecl _putwch(wchar_t _WCh);
  50. _CRTIMP wint_t __cdecl _ungetwch(wint_t _WCh);
  51. _CRTIMP int __cdecl _cputws(const wchar_t *_String);
  52. _CRTIMP int __cdecl _cwprintf(const wchar_t *_Format,...);
  53. _CRTIMP int __cdecl _cwscanf(const wchar_t *_Format,...);
  54. _CRTIMP int __cdecl _cwscanf_l(const wchar_t *_Format,_locale_t _Locale,...);
  55. _CRTIMP int __cdecl _vcwprintf(const wchar_t *_Format,va_list _ArgList);
  56. _CRTIMP int __cdecl _cwprintf_p(const wchar_t *_Format,...);
  57. _CRTIMP int __cdecl _vcwprintf_p(const wchar_t *_Format,va_list _ArgList);
  58. _CRTIMP int __cdecl _cwprintf_l(const wchar_t *_Format,_locale_t _Locale,...);
  59. _CRTIMP int __cdecl _vcwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
  60. _CRTIMP int __cdecl _cwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,...);
  61. _CRTIMP int __cdecl _vcwprintf_p_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
  62. _CRTIMP wint_t __cdecl _putwch_nolock(wchar_t _WCh);
  63. _CRTIMP wint_t __cdecl _getwch_nolock(void);
  64. _CRTIMP wint_t __cdecl _getwche_nolock(void);
  65. _CRTIMP wint_t __cdecl _ungetwch_nolock(wint_t _WCh);
  66. #endif
  67. #ifndef NO_OLDNAMES
  68. char *__cdecl cgets(char *_Buffer);
  69. int __cdecl cprintf(const char *_Format,...);
  70. int __cdecl cputs(const char *_Str);
  71. int __cdecl cscanf(const char *_Format,...);
  72. int __cdecl getch(void);
  73. int __cdecl getche(void);
  74. int __cdecl kbhit(void);
  75. int __cdecl putch(int _Ch);
  76. int __cdecl ungetch(int _Ch);
  77. #if (defined(_X86_) && !defined(__x86_64))
  78. int __cdecl inp(unsigned short);
  79. unsigned short __cdecl inpw(unsigned short);
  80. int __cdecl outp(unsigned short,int);
  81. unsigned short __cdecl outpw(unsigned short,unsigned short);
  82. #endif
  83. /* I/O intrin functions. */
  84. __CRT_INLINE unsigned char __inbyte(unsigned short Port)
  85. {
  86. unsigned char value;
  87. __asm__ __volatile__ ("inb %w1,%b0"
  88. : "=a" (value)
  89. : "Nd" (Port));
  90. return value;
  91. }
  92. __CRT_INLINE unsigned short __inword(unsigned short Port)
  93. {
  94. unsigned short value;
  95. __asm__ __volatile__ ("inw %w1,%w0"
  96. : "=a" (value)
  97. : "Nd" (Port));
  98. return value;
  99. }
  100. __CRT_INLINE unsigned long __indword(unsigned short Port)
  101. {
  102. unsigned long value;
  103. __asm__ __volatile__ ("inl %w1,%0"
  104. : "=a" (value)
  105. : "Nd" (Port));
  106. return value;
  107. }
  108. __CRT_INLINE void __outbyte(unsigned short Port,unsigned char Data)
  109. {
  110. __asm__ __volatile__ ("outb %b0,%w1"
  111. :
  112. : "a" (Data), "Nd" (Port));
  113. }
  114. __CRT_INLINE void __outword(unsigned short Port,unsigned short Data)
  115. {
  116. __asm__ __volatile__ ("outw %w0,%w1"
  117. :
  118. : "a" (Data), "Nd" (Port));
  119. }
  120. __CRT_INLINE void __outdword(unsigned short Port,unsigned long Data)
  121. {
  122. __asm__ __volatile__ ("outl %0,%w1"
  123. :
  124. : "a" (Data), "Nd" (Port));
  125. }
  126. __CRT_INLINE void __inbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
  127. {
  128. __asm__ __volatile__ (
  129. "cld ; rep ; insb "
  130. : "=D" (Buffer), "=c" (Count)
  131. : "d"(Port), "0"(Buffer), "1" (Count)
  132. );
  133. }
  134. __CRT_INLINE void __inwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
  135. {
  136. __asm__ __volatile__ (
  137. "cld ; rep ; insw "
  138. : "=D" (Buffer), "=c" (Count)
  139. : "d"(Port), "0"(Buffer), "1" (Count)
  140. );
  141. }
  142. __CRT_INLINE void __indwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
  143. {
  144. __asm__ __volatile__ (
  145. "cld ; rep ; insl "
  146. : "=D" (Buffer), "=c" (Count)
  147. : "d"(Port), "0"(Buffer), "1" (Count)
  148. );
  149. }
  150. __CRT_INLINE void __outbytestring(unsigned short Port,unsigned char *Buffer,unsigned long Count)
  151. {
  152. __asm__ __volatile__ (
  153. "cld ; rep ; outsb "
  154. : "=S" (Buffer), "=c" (Count)
  155. : "d"(Port), "0"(Buffer), "1" (Count)
  156. );
  157. }
  158. __CRT_INLINE void __outwordstring(unsigned short Port,unsigned short *Buffer,unsigned long Count)
  159. {
  160. __asm__ __volatile__ (
  161. "cld ; rep ; outsw "
  162. : "=S" (Buffer), "=c" (Count)
  163. : "d"(Port), "0"(Buffer), "1" (Count)
  164. );
  165. }
  166. __CRT_INLINE void __outdwordstring(unsigned short Port,unsigned long *Buffer,unsigned long Count)
  167. {
  168. __asm__ __volatile__ (
  169. "cld ; rep ; outsl "
  170. : "=S" (Buffer), "=c" (Count)
  171. : "d"(Port), "0"(Buffer), "1" (Count)
  172. );
  173. }
  174. __CRT_INLINE unsigned __int64 __readcr0(void)
  175. {
  176. unsigned __int64 value;
  177. __asm__ __volatile__ (
  178. "mov %%cr0, %[value]"
  179. : [value] "=q" (value));
  180. return value;
  181. }
  182. /* Register sizes are different between 32/64 bit mode. So we have to do this for _WIN64 and _WIN32
  183. separately. */
  184. #ifdef _WIN64
  185. __CRT_INLINE void __writecr0(unsigned __int64 Data)
  186. {
  187. __asm__ __volatile__ (
  188. "mov %[Data], %%cr0"
  189. :
  190. : [Data] "q" (Data)
  191. : "memory");
  192. }
  193. __CRT_INLINE unsigned __int64 __readcr2(void)
  194. {
  195. unsigned __int64 value;
  196. __asm__ __volatile__ (
  197. "mov %%cr2, %[value]"
  198. : [value] "=q" (value));
  199. return value;
  200. }
  201. __CRT_INLINE void __writecr2(unsigned __int64 Data)
  202. {
  203. __asm__ __volatile__ (
  204. "mov %[Data], %%cr2"
  205. :
  206. : [Data] "q" (Data)
  207. : "memory");
  208. }
  209. __CRT_INLINE unsigned __int64 __readcr3(void)
  210. {
  211. unsigned __int64 value;
  212. __asm__ __volatile__ (
  213. "mov %%cr3, %[value]"
  214. : [value] "=q" (value));
  215. return value;
  216. }
  217. __CRT_INLINE void __writecr3(unsigned __int64 Data)
  218. {
  219. __asm__ __volatile__ (
  220. "mov %[Data], %%cr3"
  221. :
  222. : [Data] "q" (Data)
  223. : "memory");
  224. }
  225. __CRT_INLINE unsigned __int64 __readcr4(void)
  226. {
  227. unsigned __int64 value;
  228. __asm__ __volatile__ (
  229. "mov %%cr4, %[value]"
  230. : [value] "=q" (value));
  231. return value;
  232. }
  233. __CRT_INLINE void __writecr4(unsigned __int64 Data)
  234. {
  235. __asm__ __volatile__ (
  236. "mov %[Data], %%cr4"
  237. :
  238. : [Data] "q" (Data)
  239. : "memory");
  240. }
  241. __CRT_INLINE unsigned __int64 __readcr8(void)
  242. {
  243. unsigned __int64 value;
  244. __asm__ __volatile__ (
  245. "mov %%cr8, %[value]"
  246. : [value] "=q" (value));
  247. return value;
  248. }
  249. __CRT_INLINE void __writecr8(unsigned __int64 Data)
  250. {
  251. __asm__ __volatile__ (
  252. "mov %[Data], %%cr8"
  253. :
  254. : [Data] "q" (Data)
  255. : "memory");
  256. }
  257. #elif defined(_WIN32)
  258. __CRT_INLINE void __writecr0(unsigned Data)
  259. {
  260. __asm__ __volatile__ (
  261. "mov %[Data], %%cr0"
  262. :
  263. : [Data] "q" (Data)
  264. : "memory");
  265. }
  266. __CRT_INLINE unsigned long __readcr2(void)
  267. {
  268. unsigned long value;
  269. __asm__ __volatile__ (
  270. "mov %%cr2, %[value]"
  271. : [value] "=q" (value));
  272. return value;
  273. }
  274. __CRT_INLINE void __writecr2(unsigned Data)
  275. {
  276. __asm__ __volatile__ (
  277. "mov %[Data], %%cr2"
  278. :
  279. : [Data] "q" (Data)
  280. : "memory");
  281. }
  282. __CRT_INLINE unsigned long __readcr3(void)
  283. {
  284. unsigned long value;
  285. __asm__ __volatile__ (
  286. "mov %%cr3, %[value]"
  287. : [value] "=q" (value));
  288. return value;
  289. }
  290. __CRT_INLINE void __writecr3(unsigned Data)
  291. {
  292. __asm__ __volatile__ (
  293. "mov %[Data], %%cr3"
  294. :
  295. : [Data] "q" (Data)
  296. : "memory");
  297. }
  298. __CRT_INLINE unsigned long __readcr4(void)
  299. {
  300. unsigned long value;
  301. __asm__ __volatile__ (
  302. "mov %%cr4, %[value]"
  303. : [value] "=q" (value));
  304. return value;
  305. }
  306. __CRT_INLINE void __writecr4(unsigned Data)
  307. {
  308. __asm__ __volatile__ (
  309. "mov %[Data], %%cr4"
  310. :
  311. : [Data] "q" (Data)
  312. : "memory");
  313. }
  314. __CRT_INLINE unsigned long __readcr8(void)
  315. {
  316. unsigned long value; __asm__ __volatile__ (
  317. "mov %%cr8, %[value]"
  318. : [value] "=q" (value));
  319. return value;
  320. }
  321. __CRT_INLINE void __writecr8(unsigned Data)
  322. {
  323. __asm__ __volatile__ (
  324. "mov %[Data], %%cr8"
  325. :
  326. : [Data] "q" (Data)
  327. : "memory");
  328. }
  329. #endif
  330. __CRT_INLINE unsigned __int64 __readmsr(unsigned long msr)
  331. {
  332. unsigned __int64 val1, val2;
  333. __asm__ __volatile__(
  334. "rdmsr"
  335. : "=a" (val1), "=d" (val2)
  336. : "c" (msr));
  337. return val1 | (val2 << 32);
  338. }
  339. __CRT_INLINE void __writemsr (unsigned long msr, unsigned __int64 Value)
  340. {
  341. unsigned long val1 = Value, val2 = Value >> 32;
  342. __asm__ __volatile__ (
  343. "wrmsr"
  344. :
  345. : "c" (msr), "a" (val1), "d" (val2));
  346. }
  347. __CRT_INLINE unsigned __int64 __rdtsc(void)
  348. {
  349. unsigned __int64 val1, val2;
  350. __asm__ __volatile__ (
  351. "rdtsc"
  352. : "=a" (val1), "=d" (val2));
  353. return val1 | (val2 << 32);
  354. }
  355. __CRT_INLINE void __cpuid(int CPUInfo[4], int InfoType)
  356. {
  357. __asm__ __volatile__ (
  358. "cpuid"
  359. : "=a" (CPUInfo [0]), "=b" (CPUInfo [1]), "=c" (CPUInfo [2]), "=d" (CPUInfo [3])
  360. : "a" (InfoType));
  361. }
  362. #endif
  363. #ifdef __cplusplus
  364. }
  365. #endif
  366. #include <sec_api/conio_s.h>
  367. #endif