home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / ARTLSRC.RAR / SYS / IO.ASM next >
Assembly Source File  |  2000-08-15  |  2KB  |  88 lines

  1.                 .386
  2.  
  3.                 EXTRN   DosFlatToSel:Proc
  4. FLAT        GROUP    CODE32
  5.  
  6. CODE32          SEGMENT DWORD PUBLIC USE32 'CODE'
  7.                 ASSUME  CS:FLAT,DS:FLAT
  8.  
  9. ; Performs Input/Output from/to hardware ports
  10.  
  11. ; EXPECTS:      ecx     = 0,4,8,12,16,20 => Type of IO operation
  12. ;               eax     = Value (Output only)
  13. ;               dx      = Port number
  14.  
  15. System@__IOPort PROC    Near
  16.                 PUBLIC  System@__IOPort
  17.                 push    ebp ebx esi
  18.                 mov     ebp,esp
  19.                 cmp     sp,4*1024
  20.                 jae     @@1
  21.                 xor     sp,sp
  22.               @@1:
  23.                 mov     ebx,eax
  24.         mov    esi,ecx
  25.                 push    ss
  26.                 mov     eax,esp                 ; Convert SS:ESP to
  27.                 Call    DosFlatToSel            ; SS:SP for a 0:32->16:16 thunk.
  28.                 push    eax
  29.                 lss     sp,[esp]                ; Here is the far (16:16) jump
  30.                 jmp     Far Ptr Thunk_16        ; to the function's 16 bit thunk.
  31. ALIGN 4
  32. Back_To_32:
  33.                 pop     ss
  34.                 mov     esp,ebp
  35.                 pop     esi ebx ebp
  36.                 ret
  37. System@__IOPort ENDP
  38.  
  39. CODE32          ENDS
  40.  
  41. ; Special IOPL segment. The following line should be included into
  42. ; module definition file:
  43. ; SEGMENTS IO16 IOPL
  44.  
  45. IO16            SEGMENT DWORD PUBLIC USE16 'CODE'
  46.                 ASSUME  CS:IO16
  47. InputByte:      in      al,dx
  48.                 retf
  49. ALIGN 4
  50. InputWord:      in      ax,dx
  51.                 retf
  52. ALIGN 4
  53. InputDWord:     in      eax,dx
  54.                 retf
  55. ALIGN 4
  56. OutputByte:     mov     eax,ebx
  57.                 out     dx,al
  58.                 retf
  59. ALIGN 4
  60. OutputWord:     mov     eax,ebx
  61.                 out     dx,ax
  62.                 retf
  63. ALIGN 4
  64. OutputDWord:    mov     eax,ebx
  65.                 out     dx,eax
  66.                 retf
  67.  
  68. IO16            ENDS
  69.  
  70. ; 16-bit segment containing thunk code
  71.  
  72. CODE16          SEGMENT DWORD PUBLIC USE16 'CODE'
  73.                 ASSUME  CS:CODE16
  74. Thunk_16:
  75.                 Call    DWord Ptr @@CallTable[si]
  76.                 jmp     Far Ptr Back_To_32
  77. ALIGN 4
  78. @@CallTable     dd      InputByte
  79.                 dd      InputWord
  80.                 dd      InputDWord
  81.                 dd      OutputByte
  82.                 dd      OutputWord
  83.                 dd      OutputDWord
  84.  
  85. CODE16          ENDS
  86.  
  87.                 END
  88.