home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Include / asm / io.h < prev    next >
C/C++ Source or Header  |  2002-04-26  |  3KB  |  119 lines

  1. /* $Id: io.h,v 1.2 2002/04/26 23:09:19 smilcke Exp $ */
  2.  
  3. #ifndef _ASM_IO_H
  4. #define _ASM_IO_H
  5.  
  6. /*
  7.  * This file contains the definitions for the x86 IO instructions
  8.  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  9.  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  10.  * versions of the single-IO instructions (inb_p/inw_p/..).
  11.  *
  12.  * This file is not meant to be obfuscating: it's just complicated
  13.  * to (a) handle it all in a way that makes gcc able to optimize it
  14.  * as well as possible and (b) trying to avoid writing the same thing
  15.  * over and over again with slight variations and possibly making a
  16.  * mistake somewhere.
  17.  */
  18.  
  19. /*
  20.  * Thanks to James van Artsdalen for a better timing-fix than
  21.  * the two short jumps: using outb's to a nonexistent port seems
  22.  * to guarantee better timings even on fast machines.
  23.  *
  24.  * On the other hand, I'd like to be sure of a non-existent port:
  25.  * I feel a bit unsafe about using 0x80 (should be safe, though)
  26.  *
  27.  *        Linus
  28.  */
  29.  
  30.  /*
  31.   *  Bit simplified and optimized by Jan Hubicka
  32.   *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
  33.   *
  34.   *  isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
  35.   *  isa_read[wl] and isa_write[wl] fixed
  36.   *  - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  37.   */
  38.  
  39. /*
  40.  * IO bus memory addresses are also 1:1 with the physical address
  41.  */
  42.  
  43. #define IO_SPACE_LIMIT 0xffff
  44.  
  45. #ifdef SLOW_IO_BY_JUMPING
  46. #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
  47. #else
  48. #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
  49. #endif
  50.  
  51. #ifdef REALLY_SLOW_IO
  52. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
  53. #else
  54. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
  55. #endif
  56.  
  57. #define __io_virt(x) ((void *)(x))
  58.  
  59. #define readb(addr) (*(volatile unsigned char *) __io_virt(addr))
  60. #define readw(addr) (*(volatile unsigned short *) __io_virt(addr))
  61. #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
  62. #define __raw_readb readb
  63. #define __raw_readw readw
  64. #define __raw_readl readl
  65.  
  66. #define writeb(b,addr) (*(volatile unsigned char *) __io_virt(addr)=(b))
  67. #define writew(b,addr) (*(volatile unsigned short *) __io_virt(addr)=(b))
  68. #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr)=(b))
  69. #define __raw_writeb writeb
  70. #define __raw_writew writew
  71. #define __raw_writel writel
  72.  
  73.  
  74. /*
  75.  * Talk about misusing macros..
  76.  */
  77. #define __OUT1(s,x) \
  78. extern inline void out##s(unsigned x value, unsigned short port) {
  79.  
  80.  
  81. #define __IN1(s) \
  82. extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
  83.  
  84.  
  85. void outb(unsigned char data, int port);
  86. #pragma aux outb =       \
  87.   "out dx, al"                  \
  88.   parm [al] [dx];
  89.  
  90. unsigned char inb(int port);
  91. #pragma aux inb =       \
  92.   "in al,dx"            \
  93.   parm [dx]             \
  94.   value [al];
  95.  
  96. void outw(unsigned short data, int port);
  97. #pragma aux outw =       \
  98.   "out dx, ax"                  \
  99.   parm [ax] [dx];
  100.  
  101. unsigned short inw(int port);
  102. #pragma aux inw =       \
  103.   "in ax,dx"            \
  104.   parm [dx]             \
  105.   value [ax];
  106.  
  107. void outl(unsigned long data, int port);
  108. #pragma aux outl =       \
  109.   "out dx, eax"                  \
  110.   parm [eax] [dx];
  111.  
  112. unsigned long inl(int port);
  113. #pragma aux inl =       \
  114.   "in eax,dx"            \
  115.   parm [dx]             \
  116.   value [eax];
  117.  
  118. #endif
  119.