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