home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / portio.zip / portio.asm < prev    next >
Assembly Source File  |  1993-05-03  |  5KB  |  139 lines

  1. ; ******************************************************************
  2. ;   <portio.asm> code file
  3. ;
  4. ;   Function definitions for port access routines
  5. ;        inp(port)   - read single byte from I/O port
  6. ;        inpw(port)  - read single word from I/O port pair
  7. ;        outp(port)  - write single byte to I/O port
  8. ;        outpw(port) - write single word to I/O port pair
  9. ;
  10. ;   For IBM C Set/2  Version 1.0
  11. ;
  12. ;  DISCLAIMER:
  13. ;  -------------------------
  14. ;  This code and the accompanying documentation is hereby placed in
  15. ;  the public domain.  It is not part of any standard product and
  16. ;  is provided solely as an example for your private and/or
  17. ;  commercial use.  You may freely use or distribute this code in
  18. ;  derived works as long as you do not attempt to prevent others
  19. ;  from doing likewise.  Neither the author, nor his employer,
  20. ;  shall be liable for any damages arising from your use of this
  21. ;  code; it is provided solely ASIS with no warranty whatsoever.
  22. ;
  23. ;  Author contact:   Michael Thompson
  24. ;                    tommy@msc.cornell.edu
  25. ; ******************************************************************
  26.  
  27. P@IOCODE        segment 'CODE'
  28.                 assume  cs:P@IOCODE
  29.  
  30. ;=============================================================================
  31. ; These routines must be declared as
  32. ;
  33. ;       unsigned short _Far16 _Fastcall inp(unsigned short port);
  34. ;       unsigned short _Far16 _Fastcall inpw(unsigned short port);
  35. ;       unsigned short _Far16 _Fastcall outp(unsigned short, unsigned short);
  36. ;       unsigned short _Far16 _Fastcall outpw(unsigned short, unsigned short);
  37. ;
  38. ; in the CSET/2 declarations.  The fastcall convention passes the values on
  39. ; the registers AX, DX as assumed below.  The short return allows use of AX
  40. ; only on exit.  This should be nearly at the limit of the 32->16 call 
  41. ; convention.
  42. ;
  43. ; Compiling and linkage requires these routines to be stored in a DLL so are
  44. ; 16 bit.  I could make them 32 bit IF I could get a true protected mode 32
  45. ; bit assembler.  Microsoft maybe there, but I refuse to buy their toys
  46. ; anymore.
  47. ;
  48. ; General make process:
  49. ;    masm /Mx portio;
  50. ;    link /map /noi /nod portio,portio.dll,,,portio.def
  51. ;    implib portio.lib portio.def
  52. ;
  53. ; portio.def must contain
  54. ;       LIBRARY PORTIO
  55. ;       DESCRIPTION 'Dynamically-linked Run-Time Library for Port Access'
  56. ;       PROTMODE
  57. ;       CODE PRELOAD EXECUTEONLY IOPL
  58. ;
  59. ;       EXPORTS
  60. ;       @inp
  61. ;       @outp
  62. ;       @inpw
  63. ;       @outpw
  64. ;
  65. ; The CODE IOPL is required - all CODE segments are give IOPL priveleges.
  66. ; For some reason, can't figure out how to override one MASM segment.
  67. ; @ indicates a fastcall routine apparently, /Mx preserves case.
  68. ;=============================================================================
  69.  
  70.  
  71.  
  72. ;=============================================================================
  73. ; Subroutine to output byte to specified port
  74. ;
  75. ; Usage:  unsigned short = outp (unsigned short port, unsigned short byte)
  76. ;         unsigned short = outpw(unsigned short port, unsigned short word)
  77. ;
  78. ; Inputs: AX - port
  79. ;         DX - contains value to be sent (low byte only for outp)
  80. ;
  81. ; Output: AX - byte value sent
  82. ;=============================================================================
  83. @outp           proc    far
  84.                 public  @outp
  85.                 assume  ds:nothing,es:nothing
  86. ;
  87.                 xchg    ax,dx                           ; Get port in DX
  88.                 out     dx,al                           ; And send one byte
  89.                 xor     ah,ah                           ; Say didn't send hi
  90.                 ret
  91. ;
  92. @outp           endp
  93.  
  94. @outpw          proc    far
  95.                 public  @outpw
  96.                 assume  ds:nothing,es:nothing
  97. ;
  98.                 xchg    ax,dx                           ; Get port in DX
  99.                 out     dx,ax                           ; And send one byte
  100.                 ret
  101. ;
  102. @outpw          endp
  103.  
  104.  
  105. ;=============================================================================
  106. ; Subroutine to read input from a specified port
  107. ;
  108. ; Usage:  unsigned short = inp (unsigned short port)
  109. ;         unsigned short = inpw(unsigned short port)
  110. ;
  111. ; Inputs: AX - port
  112. ;
  113. ; Output: AX - byte (word) value received
  114. ;=============================================================================
  115. @inp            proc    far
  116.                 public  @inp
  117.                 assume  ds:nothing,es:nothing
  118. ;
  119.                 mov     dx,ax                           ; Get port in DX
  120.                 in      al,dx                           ; Read the byte
  121.                 xor     ah,ah                           ; Clear AH
  122.                 ret
  123. ;
  124. @inp            endp
  125.  
  126. @inpw           proc    far
  127.                 public  @inpw
  128.                 assume  ds:nothing,es:nothing
  129. ;
  130.                 mov     dx,ax                           ; Get port in DX
  131.                 in      ax,dx                           ; Read the word
  132.                 ret
  133. ;
  134. @inpw           endp
  135.  
  136. P@IOCODE                ends
  137. ;
  138.                 end
  139.