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.

344 lines
8.7 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. add esp,ExceptionRecordSize + NumParms*4
  94. ENDM
  95. ;
  96. ; Prefix Flags
  97. ;
  98. PREFIX_ES equ 00000100h
  99. PREFIX_CS equ 00000200h
  100. PREFIX_SS equ 00000400h
  101. PREFIX_DS equ 00000800h
  102. PREFIX_FS equ 00001000h
  103. PREFIX_GS equ 00002000h
  104. PREFIX_OPER32 equ 00004000h
  105. PREFIX_ADDR32 equ 00008000h
  106. PREFIX_LOCK equ 00010000h
  107. PREFIX_REPNE equ 00020000h
  108. PREFIX_REP equ 00040000h
  109. PREFIX_SEG_ALL equ 00003f00h
  110. NUM_OPCODE equ 255
  111. ;
  112. ; Reginfo structure
  113. ;
  114. RegInfo struc
  115. RiSegSs dd 0
  116. RiEsp dd 0
  117. RiEFlags dd 0
  118. RiSegCs dd 0
  119. RiEip dd 0
  120. RiTrapFrame dd 0
  121. RiCsLimit dd 0
  122. RiCsBase dd 0
  123. RiCsFlags dd 0
  124. RiSsLimit dd 0
  125. RiSsBase dd 0
  126. RiSsFlags dd 0
  127. RiPrefixFlags dd 0
  128. RiOperand dd 0
  129. RegInfo ends
  130. REGINFOSIZE EQU 56
  131. MAX_VDM_ADDR EQU 0FFFFFFH
  132. DR7_GLOBAL EQU 002AAH
  133. ;
  134. ;Fast Read/Write Defines
  135. ;
  136. SVC_DEMFASTREAD equ 42h
  137. SVC_DEMFASTWRITE equ 43h
  138. DOS_BOP equ 50h
  139. ;
  140. ;
  141. ; Size of Exception Record
  142. ;
  143. ExceptionRecordSize = (ErNumberParameters + 4 + 3) AND 0fffffffcH ;
  144. ;
  145. ; Magic value
  146. ;
  147. OPCODE_MAGIC equ 00f5ah
  148. ;++
  149. ; diBEGIN - BEGIN index table
  150. ;
  151. ; ENTRY name = name of di table
  152. ; badindex = local label for unspecified entries
  153. ;
  154. ; EXIT ?sindex = specific entry index
  155. ; ?badindex = default index for unspecified entries
  156. ;--
  157. diBEGIN macro name,badindex ;; Beginning of dispatch table
  158. ?sopc = 0
  159. ?badindex = badindex
  160. name label byte ;; Start of dispatch table
  161. endm
  162. ;++
  163. ; dtI - SPECIFIC index table entry
  164. ;
  165. ; ENTRY opc = opcode value
  166. ; index = INDEX_ value corresponding to opcode
  167. ; ?badindex = unspecified entry index
  168. ; ?sopc = specific entry index
  169. ;
  170. ; EXIT Unspecified entries prior to "index" filled in;
  171. ; Specified entry filled in.
  172. ; ?sopc = next index to fill in;
  173. ;--
  174. dtI macro opc,index ;; Specific entry in dispatch table
  175. if ?sopc gt opc
  176. %out dtI: opcode out of order
  177. .err
  178. else
  179. if ?sopc lt opc ;; Fill unspecified entries
  180. rept opc - ?sopc
  181. db ?badindex
  182. endm
  183. endif
  184. db index ;; Specified entry
  185. ?sopc = opc+1 ;; Set new start index
  186. endif
  187. endm
  188. ;++
  189. ; diEND - END index table
  190. ;
  191. ; ENTRY index = highest entry in table
  192. ; ?sopc = specific entry index
  193. ;
  194. ; EXIT rest of the table filled in
  195. ;--
  196. diEND macro index ;; End of dispatch table
  197. if ?sopc lt index ;; Fill in rest of table
  198. rept index - ?sopc
  199. db ?badindex
  200. endm
  201. db ?badindex ;; fill in last entry of table!
  202. endif
  203. endm
  204. ;++
  205. ; dtBEGIN - BEGIN dispatch table
  206. ;
  207. ; ENTRY name = name of dt table
  208. ; badaddr = local label for unspecified entries
  209. ;
  210. ; EXIT ?sindex = specific entry index
  211. ; ?badaddr = default handler for unspecified entries
  212. ;--
  213. dtBEGIN macro name,badaddr ;; Beginning of dispatch table
  214. ?sindex = 0
  215. ?badaddr = badaddr
  216. name label dword ;; Start of dispatch table
  217. endm
  218. ;++
  219. ; dtS - SPECIFIC dispatch table entry
  220. ;
  221. ; ENTRY index = index of entry
  222. ; addr = address of handler
  223. ; ?badaddr = unspecified entry handler
  224. ; ?sindex = specific entry index
  225. ;
  226. ; EXIT Unspecified entries prior to "index" filled in;
  227. ; Specified entry filled in.
  228. ; ?sindex = next index to fill in;
  229. ;--
  230. dtS macro index,addr ;; Specific entry in dispatch table
  231. if ?sindex gt index
  232. %out dtS: index out of order
  233. .err
  234. else
  235. if ?sindex lt index ;; Fill unspecified entries
  236. rept index - ?sindex
  237. dd offset FLAT:?badaddr
  238. endm
  239. endif
  240. dd offset FLAT:addr ;; Specified entry
  241. ?sindex = index+1 ;; Set new start index
  242. endif
  243. endm
  244. ;++
  245. ; dtEND - END dispatch table
  246. ;
  247. ; ENTRY index = highest entry in table
  248. ; ?sindex = specific entry index
  249. ;
  250. ; EXIT rest of the table filled in
  251. ;--
  252. dtEND macro index ;; End of dispatch table
  253. if ?sindex lt index ;; Fill in rest of table
  254. rept index - ?sindex
  255. dd offset FLAT:?badaddr
  256. endm
  257. dd offset FLAT:?badaddr ;; fill in last entry of table!
  258. endif
  259. endm
  260. ;++
  261. ; CsToLinearPM
  262. ;
  263. ;--
  264. CsToLinearPM macro sel, erraddr
  265. lea eax,[esi].RiCsLimit
  266. push eax
  267. lea eax,[esi].RiCsBase
  268. push eax
  269. lea eax,[esi].RiCsFlags
  270. push eax
  271. push sel
  272. call _Ki386GetSelectorParameters@16
  273. or al,al
  274. jz erraddr
  275. test [esi].RiCsFlags,SEL_TYPE_EXECUTE
  276. jz erraddr
  277. test [esi].RiCsFlags,SEL_TYPE_2GIG
  278. jz @f
  279. ; Correct limit value for granularity
  280. shl [esi].RiCsLimit,12
  281. or [esi].RiCsLimit,0FFFh
  282. @@:
  283. endm
  284. ;++
  285. ; CsToLinearV86
  286. ;
  287. ;--
  288. CsToLinearV86 macro
  289. movzx eax,word ptr [esi].RiSegCs
  290. shl eax,4
  291. mov [esi].RiCsBase,eax
  292. mov [esi].RiCsLimit,0FFFFh
  293. mov [esi].RiCsFlags,0
  294. endm