home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / devddemo.zip / ASMUTILS.ASM next >
Assembly Source File  |  1991-01-31  |  8KB  |  213 lines

  1.               PAGE      60,131
  2.               TITLE     GENERIC Device Driver Assembler Level Utilities
  3. ;
  4.               .386P     ;    We amy want to use some 386 instructions
  5. ;
  6. ;┌───────────────────────────────────────────────────────────────────────────┐
  7. ;│                  CONSTANT DEFINITIONS                                     │
  8. ;└───────────────────────────────────────────────────────────────────────────┘
  9. ;
  10. TRUE          equ       1      ; Boolean values
  11. FALSE         equ       0
  12. REAL_TO_PROT  equ       02fh   ; This is the DevHlp cmd to go to PROTECT mode
  13. PROT_TO_REAL  equ       030h   ; This is the DevHlp cmd to go to REAL mode
  14. ;
  15.               PAGE
  16. ;
  17. ;
  18. ;┌───────────────────────────────────────────────────────────────────────────┐
  19. ;│                  CODE SEGMENT                                             │
  20. ;└───────────────────────────────────────────────────────────────────────────┘
  21. ;
  22. MAINSEG       SEGMENT   WORD PUBLIC 'CODE' USE16
  23. ;
  24.               ASSUME    CS:MAINSEG
  25.               public    _in_port
  26.               public    _out_port
  27.               public    _enable_irpt
  28.               public    _disable_irpt
  29.               public    _real_mode
  30.               public    _to_real_moda
  31.               public    _to_prot_moda
  32.               extrn     _dev_hlpCS:dword
  33. ;
  34. ;
  35. ;┌───────────────────────────────────────────────────────────────────────────┐
  36. ;│                                                                           │
  37. ;│  in_port - Get a byte from an input port                                  │
  38. ;│                                                                           │
  39. ;│  Syntax - word far in_port(word)                                          │
  40. ;│                                                                           │
  41. ;└───────────────────────────────────────────────────────────────────────────┘
  42. ;
  43. _in_port      proc      far
  44.               push      bp
  45.               mov       bp,sp
  46. ;
  47. ; Get the address of the port
  48. ;
  49.               mov       dx,[bp+4]
  50. ;
  51. ; Do the input
  52. ;
  53.               in        al,dx
  54. ;
  55. ; Clear the high half of the integer
  56. ;
  57.               xor       ah,ah
  58. ;
  59. ; and back we go, with the value in AX (MS integer return convention)
  60. ;
  61.               pop       bp
  62.               ret
  63. ;
  64. _in_port      endp
  65. ;
  66. ;┌───────────────────────────────────────────────────────────────────────────┐
  67. ;│                                                                           │
  68. ;│  out_port - Write a byte to an output port                                │
  69. ;│                                                                           │
  70. ;│  Syntax - void far out_port(word, word)                                   │
  71. ;│                             port  data                                    │
  72. ;│                                                                           │
  73. ;└───────────────────────────────────────────────────────────────────────────┘
  74. ;
  75. _out_port     proc      far
  76.               push      bp
  77.               mov       bp,sp
  78. ;
  79. ; Get the address of the port
  80. ;
  81.               mov       dx,[bp+4]
  82. ;
  83. ; and the data to output
  84. ;
  85.               mov       ax,[bp+6]
  86. ;
  87. ; Output it (surprise!)
  88. ;
  89.               out       dx,al
  90. ;
  91. ; All done
  92. ;
  93.               pop       bp
  94.               ret
  95. ;
  96. _out_port     endp
  97.               PAGE
  98. ;
  99. ;
  100. ;*****************************************************************************
  101. ;*                                                                           *
  102. ;*  enable_irpt() - Function to Enable CPU interrupts                        *
  103. ;*                                                                           *
  104. ;*  Syntax - void far enable_irpt(void)                                      *
  105. ;*                                                                           *
  106. ;*****************************************************************************
  107. ;
  108. _enable_irpt  proc      far
  109.               sti
  110.               ret
  111. ;
  112. _enable_irpt  endp
  113. ;
  114. ;
  115. ;*****************************************************************************
  116. ;*                                                                           *
  117. ;*  Disable_irpt() - Function to Disable CPU interrupts                      *
  118. ;*                                                                           *
  119. ;*  Syntax - void far enable_irpt(void)                                      *
  120. ;*                                                                           *
  121. ;*****************************************************************************
  122. ;
  123. _disable_irpt proc      far
  124.               cli
  125.               ret
  126. ;
  127. _disable_irpt endp
  128.               PAGE
  129. ;
  130. ;
  131. ;┌───────────────────────────────────────────────────────────────────────────┐
  132. ;│                                                                           │
  133. ;│  real_mode() Function to determine the CPU state                          │
  134. ;│                                                                           │
  135. ;│  Syntax - boolean far real_mode();                                        │
  136. ;│                                                                           │
  137. ;│  Returns TRUE if the CPU is in real mode, FALSE if in protect mode.       │
  138. ;│                                                                           │
  139. ;│  NOTE: Do not rewrite this function to use DevHlp RealToProt as this      │
  140. ;│        function is called before the devhlp entry point is stored.        │
  141. ;│        It would be OK to change this function to return the MSW and       │
  142. ;│        analyze it in C in to_prot_mode.  Just don't call devhlp to        │
  143. ;│        determine if the CPU is in real mode or not.                       │
  144. ;│                                                                           │
  145. ;└───────────────────────────────────────────────────────────────────────────┘
  146. ;
  147. _real_mode    proc      far
  148. ;
  149. ; Get the machine status word in AX
  150. ;
  151.               smsw      ax
  152. ;
  153. ; Low order bit is Protect Enable.  1 = Protect mode, 0 = Real mode.
  154. ;
  155.               and       ax,1
  156.               jz        rm0100
  157.               mov       ax,FALSE
  158.               jmp       rm0200
  159. rm0100:       mov       ax,TRUE
  160. ;
  161. ; Return to caller
  162. ;
  163. rm0200:
  164.               ret
  165. ;
  166. _real_mode    endp
  167.               PAGE
  168. ;
  169. ;
  170. ;┌───────────────────────────────────────────────────────────────────────────┐
  171. ;│                                                                           │
  172. ;│  to_real_moda - Go to real mode                                           │
  173. ;│                                                                           │
  174. ;│  Syntax - void far to_real_moda(void)                                     │
  175. ;│                                                                           │
  176. ;└───────────────────────────────────────────────────────────────────────────┘
  177. ;
  178. _to_real_moda proc      far
  179. ;
  180. ; Just load DL with the command and call dev_hlp.  This is because the return
  181. ; structure pointer is no longer valid after the mode switch.  But, that
  182. ; really doesn't matter because we don't care about the register values anyway.
  183. ;
  184.               mov       dl,PROT_TO_REAL
  185.               call      cs:_dev_hlpCS
  186.               ret
  187. ;
  188. _to_real_moda endp
  189. ;
  190. ;
  191. ;┌───────────────────────────────────────────────────────────────────────────┐
  192. ;│                                                                           │
  193. ;│  to_prot_moda - Go to protect mode                                        │
  194. ;│                                                                           │
  195. ;│  Syntax - void far to_prot_moda(void)                                     │
  196. ;│                                                                           │
  197. ;└───────────────────────────────────────────────────────────────────────────┘
  198. ;
  199. _to_prot_moda proc      far
  200. ;
  201. ; Same as above.  Just point and shoot.  Forget about the return register
  202. ; values.  We are not interested.
  203. ;
  204.               mov       dl,REAL_TO_PROT
  205.               call      cs:_dev_hlpCS
  206.               ret
  207. ;
  208. _to_prot_moda endp
  209.               PAGE
  210. MAINSEG       ENDS
  211. ;
  212.               END
  213.