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.

353 lines
8.6 KiB

  1. ;++
  2. ;
  3. ; Copyright (c) 1989 Microsoft Corporation
  4. ;
  5. ; Module Name:
  6. ;
  7. ; vdm.inc
  8. ;
  9. ; Abstract:
  10. ;
  11. ; This module contains the structure and constant definitions for
  12. ; the vdm component
  13. ;
  14. ; Author:
  15. ;
  16. ; Dave Hastings (daveh) 20-Feb-1992
  17. ;
  18. ; Revision History
  19. ; Sudeepb (30-Nov-1992)
  20. ; Merged all the equates in one place
  21. ;
  22. ;--
  23. .386p
  24. TRUE equ 1
  25. FALSE equ 0
  26. ;
  27. ; Macro's to only do locked memory operations on MP systems
  28. ;
  29. IFDEF NT_UP
  30. MPLOCK equ <>
  31. ELSE
  32. MPLOCK equ <lock>
  33. ENDIF
  34. page , 132
  35. subttl "Macro to dispatch exception"
  36. ;++
  37. ;
  38. ; Macro Description:
  39. ;
  40. ; This macro allocates exception record on stack, sets up exception
  41. ; record using specified parameters and finally sets up arguments
  42. ; and calls _KiDispatchException.
  43. ;
  44. ; Arguments:
  45. ;
  46. ; ExcepCode - Exception code to put into exception record
  47. ; ExceptFlags - Exception flags to put into exception record
  48. ; ExceptRecord - Associated exception record
  49. ; ExceptAddress - Addr of instruction which the hardware exception occurs
  50. ; NumParms - Number of additional parameters
  51. ; ParameterList - the additional parameter list
  52. ;
  53. ; Return Value:
  54. ;
  55. ; None.
  56. ;
  57. ;--
  58. DISPATCH_EXCEPTION macro ExceptCode, ExceptFlags, ExceptRecord, ExceptAddress,\
  59. NumParms, ParameterList
  60. local de10, de20
  61. ; Set up exception record for raising exception
  62. ?i = 0
  63. sub esp, ExceptionRecordSize + NumParms * 4
  64. ; allocate exception record
  65. mov dword ptr [esp]+ErExceptionCode, ExceptCode
  66. ; set up exception code
  67. mov dword ptr [esp]+ErExceptionFlags, ExceptFlags
  68. ; set exception flags
  69. mov dword ptr [esp]+ErExceptionRecord, ExceptRecord
  70. ; set associated exception record
  71. mov dword ptr [esp]+ErExceptionAddress, ExceptAddress
  72. mov dword ptr [esp]+ErNumberParameters, NumParms
  73. ; set number of parameters
  74. IRP z, <ParameterList>
  75. mov dword ptr [esp]+(ErExceptionInformation+?i*4), z
  76. ?i = ?i + 1
  77. ENDM
  78. ; set up arguments and call _KiDispatchException
  79. mov ecx, esp ; (ecx)->exception record
  80. test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
  81. jz de10
  82. mov eax,0FFFFh
  83. jmp de20
  84. de10: mov eax,[ebp]+TsSegCs
  85. de20: and eax,MODE_MASK
  86. ; 1 - set first chance TRUE
  87. ; eax - PreviousMode
  88. ; ebp - trap frame addr
  89. ; 0 - Null exception frame
  90. ; ecx - exception record addr
  91. ; dispatchexception as appropriate
  92. stdCall _KiDispatchException, <ecx, 0, ebp, eax, 1>
  93. IFDEF STD_CALL
  94. add esp,ExceptionRecordSize + NumParms*4
  95. ELSE
  96. add esp,20 + ExceptionRecordSize + NumParms*4
  97. ENDIF
  98. ENDM
  99. ;
  100. ; Prefix Flags
  101. ;
  102. PREFIX_ES equ 00000100h
  103. PREFIX_CS equ 00000200h
  104. PREFIX_SS equ 00000400h
  105. PREFIX_DS equ 00000800h
  106. PREFIX_FS equ 00001000h
  107. PREFIX_GS equ 00002000h
  108. PREFIX_OPER32 equ 00004000h
  109. PREFIX_ADDR32 equ 00008000h
  110. PREFIX_LOCK equ 00010000h
  111. PREFIX_REPNE equ 00020000h
  112. PREFIX_REP equ 00040000h
  113. PREFIX_SEG_ALL equ 00003f00h
  114. NUM_OPCODE equ 255
  115. ;
  116. ; Reginfo structure
  117. ;
  118. RegInfo struc
  119. RiSegSs dd 0
  120. RiEsp dd 0
  121. RiEFlags dd 0
  122. RiSegCs dd 0
  123. RiEip dd 0
  124. RiTrapFrame dd 0
  125. RiCsLimit dd 0
  126. RiCsBase dd 0
  127. RiCsFlags dd 0
  128. RiSsLimit dd 0
  129. RiSsBase dd 0
  130. RiSsFlags dd 0
  131. RiPrefixFlags dd 0
  132. RiOperand dd 0
  133. RegInfo ends
  134. REGINFOSIZE EQU 56
  135. MAX_VDM_ADDR EQU 0FFFFFFH
  136. DR7_GLOBAL EQU 002AAH
  137. ;
  138. ;Fast Read/Write Defines
  139. ;
  140. SVC_DEMFASTREAD equ 42h
  141. SVC_DEMFASTWRITE equ 43h
  142. DOS_BOP equ 50h
  143. ;
  144. ;
  145. ; Size of Exception Record
  146. ;
  147. ExceptionRecordSize = (ErNumberParameters + 4 + 3) AND 0fffffffcH ;
  148. ;
  149. ; Magic value
  150. ;
  151. OPCODE_MAGIC equ 00f5ah
  152. ;++
  153. ; diBEGIN - BEGIN index table
  154. ;
  155. ; ENTRY name = name of di table
  156. ; badindex = local label for unspecified entries
  157. ;
  158. ; EXIT ?sindex = specific entry index
  159. ; ?badindex = default index for unspecified entries
  160. ;--
  161. diBEGIN macro name,badindex ;; Beginning of dispatch table
  162. ?sopc = 0
  163. ?badindex = badindex
  164. name label byte ;; Start of dispatch table
  165. endm
  166. ;++
  167. ; dtI - SPECIFIC index table entry
  168. ;
  169. ; ENTRY opc = opcode value
  170. ; index = INDEX_ value corresponding to opcode
  171. ; ?badindex = unspecified entry index
  172. ; ?sopc = specific entry index
  173. ;
  174. ; EXIT Unspecified entries prior to "index" filled in;
  175. ; Specified entry filled in.
  176. ; ?sopc = next index to fill in;
  177. ;--
  178. dtI macro opc,index ;; Specific entry in dispatch table
  179. if ?sopc gt opc
  180. %out dtI: opcode out of order
  181. .err
  182. else
  183. if ?sopc lt opc ;; Fill unspecified entries
  184. rept opc - ?sopc
  185. db ?badindex
  186. endm
  187. endif
  188. db index ;; Specified entry
  189. ?sopc = opc+1 ;; Set new start index
  190. endif
  191. endm
  192. ;++
  193. ; diEND - END index table
  194. ;
  195. ; ENTRY index = highest entry in table
  196. ; ?sopc = specific entry index
  197. ;
  198. ; EXIT rest of the table filled in
  199. ;--
  200. diEND macro index ;; End of dispatch table
  201. if ?sopc lt index ;; Fill in rest of table
  202. rept index - ?sopc
  203. db ?badindex
  204. endm
  205. db ?badindex ;; fill in last entry of table!
  206. endif
  207. endm
  208. ;++
  209. ; dtBEGIN - BEGIN dispatch table
  210. ;
  211. ; ENTRY name = name of dt table
  212. ; badaddr = local label for unspecified entries
  213. ;
  214. ; EXIT ?sindex = specific entry index
  215. ; ?badaddr = default handler for unspecified entries
  216. ;--
  217. dtBEGIN macro name,badaddr ;; Beginning of dispatch table
  218. ?sindex = 0
  219. ?badaddr = badaddr
  220. name label dword ;; Start of dispatch table
  221. endm
  222. ;++
  223. ; dtS - SPECIFIC dispatch table entry
  224. ;
  225. ; ENTRY index = index of entry
  226. ; addr = address of handler
  227. ; ?badaddr = unspecified entry handler
  228. ; ?sindex = specific entry index
  229. ;
  230. ; EXIT Unspecified entries prior to "index" filled in;
  231. ; Specified entry filled in.
  232. ; ?sindex = next index to fill in;
  233. ;--
  234. dtS macro index,addr ;; Specific entry in dispatch table
  235. if ?sindex gt index
  236. %out dtS: index out of order
  237. .err
  238. else
  239. if ?sindex lt index ;; Fill unspecified entries
  240. rept index - ?sindex
  241. dd offset FLAT:?badaddr
  242. endm
  243. endif
  244. dd offset FLAT:addr ;; Specified entry
  245. ?sindex = index+1 ;; Set new start index
  246. endif
  247. endm
  248. ;++
  249. ; dtEND - END dispatch table
  250. ;
  251. ; ENTRY index = highest entry in table
  252. ; ?sindex = specific entry index
  253. ;
  254. ; EXIT rest of the table filled in
  255. ;--
  256. dtEND macro index ;; End of dispatch table
  257. if ?sindex lt index ;; Fill in rest of table
  258. rept index - ?sindex
  259. dd offset FLAT:?badaddr
  260. endm
  261. dd offset FLAT:?badaddr ;; fill in last entry of table!
  262. endif
  263. endm
  264. ;++
  265. ; CsToLinearPM
  266. ;
  267. ;--
  268. CsToLinearPM macro sel, erraddr
  269. lea eax,[esi].RiCsLimit
  270. push eax
  271. lea eax,[esi].RiCsBase
  272. push eax
  273. lea eax,[esi].RiCsFlags
  274. push eax
  275. push sel
  276. IFDEF STD_CALL
  277. call _Ki386GetSelectorParameters@16
  278. ELSE
  279. call _Ki386GetSelectorParameters
  280. add esp,10h
  281. ENDIF
  282. or al,al
  283. jz erraddr
  284. test [esi].RiCsFlags,SEL_TYPE_EXECUTE
  285. jz erraddr
  286. test [esi].RiCsFlags,SEL_TYPE_2GIG
  287. jz @f
  288. ; Correct limit value for granularity
  289. shl [esi].RiCsLimit,12
  290. or [esi].RiCsLimit,0FFFh
  291. @@:
  292. endm
  293. ;++
  294. ; CsToLinearV86
  295. ;
  296. ;--
  297. CsToLinearV86 macro
  298. movzx eax,word ptr [esi].RiSegCs
  299. shl eax,4
  300. mov [esi].RiCsBase,eax
  301. mov [esi].RiCsLimit,0FFFFh
  302. mov [esi].RiCsFlags,0
  303. endm