Leaked source code of windows server 2003
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.

190 lines
5.0 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. #if defined(NEC_98)
  32. #define FIXED_NTVDMSTATE_SEGMENT 0x60
  33. #else // !NEC_98
  34. #define FIXED_NTVDMSTATE_SEGMENT 0x70
  35. #endif // !NEC_98
  36. #define FIXED_NTVDMSTATE_OFFSET 0x14
  37. #define FIXED_NTVDMSTATE_LINEAR ((FIXED_NTVDMSTATE_SEGMENT << 4) + FIXED_NTVDMSTATE_OFFSET)
  38. #if defined(NEC_98)
  39. #define FIXED_NTVDMSTATE_REL40 0x214
  40. #else // !NEC_98
  41. #define FIXED_NTVDMSTATE_REL40 0x314
  42. #endif // !NEC_98
  43. #define FIXED_NTVDMSTATE_SIZE 4
  44. #if defined(NEC_98)
  45. #define NTIO_LOAD_SEGMENT 0x60
  46. #else // !NEC_98
  47. #define NTIO_LOAD_SEGMENT 0x70
  48. #endif // !NEC_98
  49. #define NTIO_LOAD_OFFSET 0
  50. #define pNtVDMState ((PULONG)FIXED_NTVDMSTATE_LINEAR)
  51. #define VDM_TIMECHANGE 0x00400000
  52. /* ASM
  53. ; FCLI macro should be used in v86mode/16bit preotect mode code to replace
  54. ; costly cli's. Please note that this macro could destroy the Overflow
  55. ; bit in the flag.
  56. FCLI macro
  57. local a,b,c
  58. push ds
  59. push ax
  60. mov ax,40h
  61. mov ds,ax
  62. lahf
  63. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  64. jnz short b
  65. lock and word ptr ds:FIXED_NTVDMSTATE_REL40,NOT VIRTUAL_INTERRUPT_BIT
  66. a:
  67. sahf
  68. pop ax
  69. pop ds
  70. jmp short c
  71. b:
  72. cli
  73. jmp short a
  74. c:
  75. endm
  76. ;
  77. ; FSTI macro should be used in v86mode or 16bit protectmode code to replace
  78. ; costly sti's. Please note that this macro could destroy the Overflow bit
  79. ; in the flag.
  80. FSTI macro
  81. local a,b,c
  82. push ds
  83. push ax
  84. mov ax,40h
  85. mov ds,ax
  86. lahf
  87. test word ptr ds:FIXED_NTVDMSTATE_REL40, INTERRUPT_PENDING_BIT
  88. jnz short b
  89. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  90. jnz short b
  91. lock or word ptr ds:FIXED_NTVDMSTATE_REL40, VIRTUAL_INTERRUPT_BIT
  92. a:
  93. sahf
  94. pop ax
  95. pop ds
  96. jmp short c
  97. b:
  98. sti
  99. jmp short a
  100. c:
  101. endm
  102. FIRET MACRO
  103. local a,b,d,e,f,g,i,j,k
  104. push ds
  105. push ax
  106. ;; Do real IRET on MIPS or if interrupts are pending
  107. mov ax,40h
  108. mov ds,ax
  109. test word ptr ds:FIXED_NTVDMSTATE_REL40, MIPS_BIT_MASK OR RI_BIT_MASK
  110. jnz short b
  111. ;; running on x86 can assume 386 or above instructions
  112. push bp
  113. mov bp,sp
  114. mov ax,[bp+10] ; get flags
  115. pop bp
  116. test ax,100h ; test if trap flag is set
  117. jnz short b ; if so, do iret
  118. test ax,200h ; test if interrupt flag is set
  119. jz short i ; ZR -> flag image has IF not set
  120. lock or word ptr ds:FIXED_NTVDMSTATE_REL40, VIRTUAL_INTERRUPT_BIT
  121. test word ptr ds:FIXED_NTVDMSTATE_REL40, INTERRUPT_PENDING_BIT
  122. jnz short b
  123. j:
  124. xchg ah,al ; AH=low byte AL=high byte
  125. cld
  126. test al,4 ; check direction flag
  127. jnz short d ;
  128. e:
  129. test al,8 ; check overflow flag
  130. jnz short f ; go to f if flag image has OF set
  131. jo short k ; go to k to reset OF
  132. g:
  133. sahf ; set low byte of flags from ah
  134. pop ax
  135. pop ds
  136. retf 2 ; IRET and discard flags
  137. i:
  138. lock and word ptr ds:FIXED_NTVDMSTATE_REL40,NOT VIRTUAL_INTERRUPT_BIT
  139. jmp short j
  140. f:
  141. jo short g ; all OK if OF bit set in real flag
  142. ; set the overflow bit in real flag
  143. push ax
  144. mov al,127
  145. add al,2 ; will set OF
  146. pop ax
  147. jmp short g
  148. k:
  149. ; reset the OF
  150. push ax
  151. xor al,al ; will reset OF
  152. pop ax
  153. jmp short g
  154. d:
  155. std
  156. jmp short e
  157. b:
  158. pop ax
  159. pop ds
  160. iret
  161. endm
  162. */