Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
4.6 KiB

  1. /*++ BUILD Version: 0001
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. VINT.H
  5. Abstract:
  6. This module contains macro support for manipulating virtual
  7. interrupt bit from v86 mode and 16bit protect mode. FCLI/FST/FIRET
  8. result in exact behavior of these instructions on the chip without
  9. trapping.
  10. Author:
  11. Sudeepb 08-Dec-1992 Created
  12. Revision History:
  13. sudeepb 16-Mar-1993 added FIRET
  14. --*/
  15. /*
  16. See \nt\private\inc\vdm.h for a complete list
  17. of the NTVDM state flag bit definitions
  18. INTERRUPT_PENDING_BIT - set if interrupts pending
  19. VIRTUAL_INTERRUPT_BIT - This bit always correctly reflects the interrupt
  20. disbale/enable state of the vDM while in 16bit land.
  21. MIPS_BIT_MASK - tells whether VDM is running on x86/mips
  22. EXEC_BIT_MASK - tells if DOS is in int21/exec operation.
  23. */
  24. #define INTERRUPT_PENDING_BIT 0x0003
  25. #define VDM_INTS_HOOKED_IN_PM 0x0004
  26. #define VIRTUAL_INTERRUPT_BIT 0x0200
  27. #define MIPS_BIT_MASK 0x400
  28. #define EXEC_BIT_MASK 0x800
  29. #define RM_BIT_MASK 0x1000
  30. #define RI_BIT_MASK 0x2000
  31. #define FIXED_NTVDMSTATE_SEGMENT 0x70
  32. #define FIXED_NTVDMSTATE_OFFSET 0x14
  33. #define FIXED_NTVDMSTATE_LINEAR ((FIXED_NTVDMSTATE_SEGMENT << 4) + FIXED_NTVDMSTATE_OFFSET)
  34. #define FIXED_NTVDMSTATE_REL40 0x314
  35. #define FIXED_NTVDMSTATE_SIZE 4
  36. #define NTIO_LOAD_SEGMENT 0x70
  37. #define NTIO_LOAD_OFFSET 0
  38. #define pNtVDMState ((PULONG)FIXED_NTVDMSTATE_LINEAR)
  39. #define VDM_TIMECHANGE 0x00400000
  40. /* ASM
  41. ifdef WOW
  42. ; FCLI macro should be used in v86mode/16bit preotect mode code to replace
  43. ; costly cli's. Please note that this macro could destroy the Overflow
  44. ; bit in the flag.
  45. FCLI macro
  46. local a,b,c
  47. push ds
  48. push ax
  49. mov ax,40h
  50. mov ds,ax
  51. lahf
  52. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  53. jnz short b
  54. lock and word ptr ds:FIXED_NTVDMSTATE_REL40,NOT VIRTUAL_INTERRUPT_BIT
  55. a:
  56. sahf
  57. pop ax
  58. pop ds
  59. jmp short c
  60. b:
  61. cli
  62. jmp short a
  63. c:
  64. endm
  65. ;
  66. ; FSTI macro should be used in v86mode or 16bit protectmode code to replace
  67. ; costly sti's. Please note that this macro could destroy the Overflow bit
  68. ; in the flag.
  69. FSTI macro
  70. local a,b,c
  71. push ds
  72. push ax
  73. mov ax,40h
  74. mov ds,ax
  75. lahf
  76. test word ptr ds:FIXED_NTVDMSTATE_REL40, INTERRUPT_PENDING_BIT
  77. jnz short b
  78. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  79. jnz short b
  80. lock or word ptr ds:FIXED_NTVDMSTATE_REL40, VIRTUAL_INTERRUPT_BIT
  81. a:
  82. sahf
  83. pop ax
  84. pop ds
  85. jmp short c
  86. b:
  87. sti
  88. jmp short a
  89. c:
  90. endm
  91. FIRET MACRO
  92. local a,b,d,e,f,g,i,j,k
  93. push ds
  94. push ax
  95. ;; Do real IRET on MIPS or if interrupts are pending
  96. mov ax,40h
  97. mov ds,ax
  98. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  99. jnz short b
  100. ;; running on x86 can assume 386 or above instructions
  101. push bp
  102. mov bp,sp
  103. mov ax,[bp+10] ; get flags
  104. pop bp
  105. test ax,100h ; test if trap flag is set
  106. jnz short b ; if so, do iret
  107. test ax,200h ; test if interrupt flag is set
  108. jz short i ; ZR -> flag image has IF not set
  109. lock or word ptr ds:FIXED_NTVDMSTATE_REL40, VIRTUAL_INTERRUPT_BIT
  110. test word ptr ds:FIXED_NTVDMSTATE_REL40, INTERRUPT_PENDING_BIT
  111. jnz short b
  112. j:
  113. xchg ah,al ; AH=low byte AL=high byte
  114. cld
  115. test al,4 ; check direction flag
  116. jnz short d ;
  117. e:
  118. test al,8 ; check overflow flag
  119. jnz short f ; go to f if flag image has OF set
  120. jo short k ; go to k to reset OF
  121. g:
  122. sahf ; set low byte of flags from ah
  123. pop ax
  124. pop ds
  125. retf 2 ; IRET and discard flags
  126. i:
  127. lock and word ptr ds:FIXED_NTVDMSTATE_REL40,NOT VIRTUAL_INTERRUPT_BIT
  128. jmp short j
  129. f:
  130. jo short g ; all OK if OF bit set in real flag
  131. ; set the overflow bit in real flag
  132. push ax
  133. mov al,127
  134. add al,2 ; will set OF
  135. pop ax
  136. jmp short g
  137. k:
  138. ; reset the OF
  139. push ax
  140. xor al,al ; will reset OF
  141. pop ax
  142. jmp short g
  143. d:
  144. std
  145. jmp short e
  146. b:
  147. pop ax
  148. pop ds
  149. iret
  150. endm
  151. else ; WOW
  152. FCLI macro
  153. cli
  154. endm
  155. FSTI macro
  156. sti
  157. endm
  158. FIRET macro
  159. iret
  160. endm
  161. endif ; else WOW
  162. */