home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v2.zip / DDKX86 / DBCSDD / INC / IODELAY.INC < prev    next >
Text File  |  1995-04-14  |  6KB  |  225 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Microsoft Corporation, 1989
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12. ;       SCCSID = @(#)iodelay.inc    6.1 90/11/16
  13. ;      SCCSID = @(#)iodelay..inc    1.0 90/09/17
  14. ; ****************************************************************************
  15. ; *                                         *
  16. ; *                                         *
  17. ; *                                         *
  18. ; ****************************************************************************
  19. ;
  20. ; This file provides the following macros
  21. ;
  22. ;    DevIODelay -    Device Driver IODelay (16 bit)
  23. ;    DevIODelay32 -    Device Driver IODelay (32 bit)
  24. ;    kIODelay -    Kernel IODelay (16 bit)
  25. ;    kIODelay32 -    Kernel IODelay (32 bit)
  26. ;    dhIODelay -    DosHlp IODelay (16 bit)
  27. ;    dhIODelay32 -    DosHlp IODelay (32 bit)
  28.  
  29.  
  30. ?REG_AX equ 0h
  31. ?REG_CX equ 1h
  32. ?REG_DX equ 2h
  33. ?REG_BX equ 3h
  34. ?REG_BP equ 5h
  35. ?REG_SI equ 6h
  36. ?REG_DI equ 7h
  37.  
  38. IO_DEC    equ 48h
  39.  
  40. ifndef    MI_MOV_REG_IMM
  41.     include mi.inc
  42. endif
  43.  
  44. ;***    DevIODelay - Delay at least 500ns with 16bit DEVICE options
  45.  
  46. DevIODelay macro scratch
  47.     IODelayWorker <scratch>,<DEVICE>,<16bit>
  48.     endm
  49.  
  50. ;***    DevIODelay32 - Delay at least 500ns with 32bit DEVICE options
  51.  
  52. DevIODelay32 macro scratch
  53.     IODelayWorker <scratch>,<DEVICE>,<32bit>
  54.     endm
  55.  
  56. ;***    kIODelay - Delay at least 500ns with 16bit KERNEL options
  57.  
  58. kIODelay macro scratch
  59.     IODelayWorker <scratch>,<KERNEL>,<16bit>
  60.     endm
  61.  
  62. ;***    kIODelay32 - Delay at least 500ns with 32bit KERNEL options
  63.  
  64. kIODelay32 macro scratch
  65.     IODelayWorker <scratch>,<KERNEL>,<32bit>
  66.     endm
  67.  
  68. ;***    dhIODelay - Delay at least 500ns with 16bit OS2LDR options
  69.  
  70. dhIODelay macro scratch
  71.     IODelayWorker <scratch>,<OS2LDR>,<16bit>
  72.     endm
  73.  
  74. ;***    dhIODelay32 - Delay at least 500ns with 32bit OS2LDR options
  75.  
  76. dhIODelay32 macro scratch
  77.     IODelayWorker <scratch>,<OS2LDR>,<32bit>
  78.     endm
  79.  
  80.  
  81. ;***    IODelayWorker - Delay at least 500ns to allow an IN/OUT
  82. ;          instruction to complete
  83. ;
  84. ;    Flushes the prefetch queue and waits until the AT bus catches up.
  85. ;    Primarily needed when back to back IO is performed on the same
  86. ;    hardware.
  87. ;
  88. ;    PARAMETERS:
  89. ;            scratch - register to use for count
  90. ;
  91. ;            type - type of code IODelayWorker is used
  92. ;
  93. ;                (OS2LDR)
  94. ;                (KERNEL)
  95. ;                (DEVICE)
  96. ;
  97. ;            codesize - size of code IODelayWorker is used in
  98. ;
  99. ;                (32BIT)
  100. ;                (16BIT)
  101. ;
  102. ;    NOTE:
  103. ;        The type of code determines the method used to obtain
  104. ;        the count value.  In the case of OS2LDR and KERNEL a
  105. ;        explicit fixup must be performed.  For the DEVICE case
  106. ;        the loader performs the fixup.    The code size is
  107. ;        also used to detemine how to code the register use.
  108. ;
  109. ;
  110.  
  111. IODelayWorker macro    scratch,type,codesize
  112. local a ,b
  113.     ifb    <type>
  114.         if2
  115.         %out "Must specify type and code size"
  116.         %out "Usage: IODelayWorker reg,type,code size"
  117.         .err
  118.         endif
  119.     elseifb <codesize>
  120.         if2
  121.         %out "Must specify code size"
  122.         %out "Usage: IODelayWorker reg,type,codesize"
  123.         .err
  124.         endif
  125.  
  126.     else
  127.  
  128.     ifidni    <codesize>,<16bit>
  129.         ifb     <scratch>
  130.         ?reg_scratch = ?REG_AX
  131.         else
  132.         ifidni    <scratch>,<ax>
  133.             ?reg_scratch = ?REG_AX
  134.         elseifidni    <scratch>,<bx>
  135.             ?reg_scratch = ?REG_BX
  136.         elseifidni    <scratch>,<cx>
  137.             ?reg_scratch = ?REG_CX
  138.         elseifidni    <scratch>,<dx>
  139.             ?reg_scratch = ?REG_DX
  140.         elseifidni    <scratch>,<bp>
  141.             ?reg_scratch = ?REG_BP
  142.         elseifidni    <scratch>,<si>
  143.             ?reg_scratch = ?REG_SI
  144.         elseifidni    <scratch>,<di>
  145.             ?reg_scratch = ?REG_DI
  146.         else
  147.            %out "Bad register argument:" &scratch
  148.            .err
  149.         endif
  150.         endif
  151.     elseifidni <codesize>,<32bit>
  152.         ifb     <scratch>
  153.         ?reg_scratch = ?REG_AX
  154.         else
  155.         ifidni    <scratch>,<eax>
  156.             ?reg_scratch = ?REG_AX
  157.         elseifidni    <scratch>,<ebx>
  158.             ?reg_scratch = ?REG_BX
  159.         elseifidni    <scratch>,<ecx>
  160.             ?reg_scratch = ?REG_CX
  161.         elseifidni    <scratch>,<edx>
  162.             ?reg_scratch = ?REG_DX
  163.         elseifidni    <scratch>,<ebp>
  164.             ?reg_scratch = ?REG_BP
  165.         elseifidni    <scratch>,<esi>
  166.             ?reg_scratch = ?REG_SI
  167.         elseifidni    <scratch>,<edi>
  168.             ?reg_scratch = ?REG_DI
  169.         else
  170.            %out "Bad register argument:" &scratch
  171.            .err
  172.         endif
  173.         endif
  174.     else
  175.         %out "Bad code size specified:" &codesize
  176.         .err
  177.     endif
  178.  
  179.     ; mov    ax,DELAYTIME
  180.     db    (MI_MOV_REG_IMM + ?reg_scratch)
  181.     b::
  182.     ifidni    <type>,<os2ldr>
  183.         ifidni  <codesize>,<16bit>
  184.         dw  0
  185.         else
  186.         dd  0
  187.         endif
  188.         IODELAYFIXUP segment
  189.  
  190.         ifidni    <codesize>,<16bit>
  191.             dw    offset DGROUP:b
  192.         else
  193.             ; only the first 16 bits will be significant
  194.             ; the second 16 bits specify 32-bit operand
  195.             ; and a padding character
  196.  
  197.             dd    offset DGROUP:b
  198.         endif
  199.  
  200.         ifidni    <codesize>,<16bit>
  201.             db    1        ; specify 16-bit operand
  202.             db    0        ;; pad
  203.         endif
  204.  
  205.         IODELAYFIXUP ends
  206.     else
  207.         ifndef DOSIODELAYCNT
  208.         EXTRN        DOSIODELAYCNT:ABS
  209.         endif
  210.         ifidni  <codesize>,<16bit>
  211.         dw  DOSIODELAYCNT
  212.         else
  213.         dd  DOSIODELAYCNT
  214.         endif
  215.     endif
  216.     ALIGN    4
  217.     a::
  218.     ;dec    ax
  219.     db    (IO_DEC + ?reg_scratch)
  220.     jnz    a
  221.  
  222.     endif
  223.  
  224.     endm
  225.