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.

1562 lines
40 KiB

  1. ;++
  2. ;
  3. ; Copyright (c) 1989 Microsoft Corporation
  4. ;
  5. ; Module Name:
  6. ;
  7. ; kimacro.inc
  8. ;
  9. ; Abstract:
  10. ;
  11. ; This module contains the macros used by kernel assembler code.
  12. ; It includes macros to manipulate interrupts, support system
  13. ; entry and exit for syscalls, faults, and interrupts, and
  14. ; manipulate floating point state.
  15. ;
  16. ; Author:
  17. ;
  18. ; Shie-Lin (shielint) 24-Jan-1990
  19. ;
  20. ; Revision History:
  21. ;
  22. ; BryanWi 17-Aug-90
  23. ; Replace GENERATE_MACHINE... and RESTORE... with ENTER_...
  24. ; and EXIT_ALL macros.
  25. ;
  26. ;--
  27. ;++
  28. ;
  29. ; These constants are used by the fpo directives in this file.
  30. ; This directive causes the assembler to output a .debug$f segment
  31. ; in the obj file. The segment will contain 1 fpo record for each
  32. ; directive present during assembly.
  33. ;
  34. ; Although the assembler will accept all valid values, the value of 7
  35. ; in the FPO_REGS field indicates to the debugger that a trap frame is
  36. ; generated by the function. The value of 7 can be used because the
  37. ; C/C++ compiler puts a maximum value of 3 in the field.
  38. ;
  39. FPO_LOCALS equ 0 ; 32 bits, size of locals in dwords
  40. FPO_PARAMS equ 0 ; 32 bits, size of parameters in dwords
  41. FPO_PROLOG equ 0 ; 12 bits, 0-4095, # of bytes in prolog
  42. FPO_REGS equ 0 ; 3 bits, 0-7, # regs saved in prolog
  43. FPO_USE_EBP equ 0 ; 1 bit, 0-1, is ebp used?
  44. FPO_TRAPFRAME equ 1 ; 2 bits, 0=fpo, 1=trap frame, 2=tss
  45. ;
  46. ;--
  47. ;++
  48. ;
  49. ; POLL_DEBUGGER
  50. ;
  51. ; Macro Description:
  52. ;
  53. ; Call the debugger so it can check for control-c. If it finds
  54. ; it, it will report our iret address as address of break-in.
  55. ;
  56. ; N.B. This macro should be used when all the caller's registers
  57. ; have been restored. (Otherwise, the kernel debugger register
  58. ; dump will not have correct state.) The only exception is
  59. ; fs. This is because Kd may need to access PCR or PRCB.
  60. ;
  61. ; Arguments:
  62. ;
  63. ; There MUST be an iret frame on the stack when this macro
  64. ; is invoked.
  65. ;
  66. ; Exit:
  67. ;
  68. ; Debugger will iret for us, so we don't usually return from
  69. ; this macro, but remember that it generates nothing for non-DEVL
  70. ; kernels.
  71. ;--
  72. POLL_DEBUGGER macro
  73. local a, b, c_
  74. if DEVL
  75. EXTRNP _DbgBreakPointWithStatus,1
  76. stdCall _KdPollBreakIn
  77. or al,al
  78. jz short c_
  79. stdCall _DbgBreakPointWithStatus,<DBG_STATUS_CONTROL_C>
  80. c_:
  81. endif ; DEVL
  82. endm
  83. ;++
  84. ;
  85. ; ASSERT_FS
  86. ;
  87. ; Try to catch funky condition wherein we get FS=r3 value while
  88. ; running in kernel mode.
  89. ;
  90. ;--
  91. ASSERT_FS macro
  92. local a,b
  93. if DBG
  94. EXTRNP _KeBugCheck,1
  95. mov bx,fs
  96. cmp bx,KGDT_R0_PCR
  97. jnz short a
  98. cmp dword ptr fs:[0], 0
  99. jne short b
  100. a:
  101. stdCall _KeBugCheck,<-1>
  102. align 4
  103. b:
  104. endif
  105. endm
  106. ;++
  107. ;
  108. ;
  109. ; Copy data from various places into base of TrapFrame, net effect
  110. ; is to allow dbg KB command to trace across trap frame, and to
  111. ; allow user to find arguments to system calls.
  112. ;
  113. ; USE ebx and edi.
  114. ;--
  115. SET_DEBUG_DATA macro
  116. ife FPO
  117. ;
  118. ; This macro is used by ENTER_SYSTEM_CALL, ENTER_TRAP and ENTER_INTERRUPT
  119. ; and is used at the end of above macros. It is safe to destroy ebx, edi.
  120. ;
  121. mov ebx,[ebp]+TsEbp
  122. mov edi,[ebp]+TsEip
  123. mov [ebp]+TsDbgArgPointer,edx
  124. mov [ebp]+TsDbgArgMark,0BADB0D00h
  125. mov [ebp]+TsDbgEbp,ebx
  126. mov [ebp]+TsDbgEip,edi
  127. endif
  128. endm
  129. ;++
  130. ;
  131. ; ENTER_DR_ASSIST EnterLabel, ExitLabel, NoAbiosAssist, NoV86Assist
  132. ;
  133. ; Macro Description:
  134. ;
  135. ; Jumped to by ENTER_ macros to deal with DR register work,
  136. ; abios work and v86 work. The main purpose of this macro is
  137. ; that interrupt/trap/systemCall EnterMacros can jump here to
  138. ; deal with some special cases such that most of the times the
  139. ; main ENTER_ execution flow can proceed without being branched.
  140. ;
  141. ; If (previousmode == usermode) {
  142. ; save DR* in trapframe
  143. ; load DR* from Prcb
  144. ; }
  145. ;
  146. ; Arguments:
  147. ; EnterLabel - label to emit
  148. ; ExitLabel - label to branch to when done
  149. ;
  150. ; Entry-conditions:
  151. ; Dr work:
  152. ; DebugActive == TRUE
  153. ; (esi)->Thread object
  154. ; (esp)->base of trap frame
  155. ; (ebp)->base of trap frame
  156. ;
  157. ; Abios work:
  158. ; v86 work:
  159. ;
  160. ; Exit-conditions:
  161. ; Dr work:
  162. ; Interrupts match input state (this routine doesn't change IEF)
  163. ; (esp)->base of trap frame
  164. ; (ebp)->base of trap frame
  165. ; Preserves entry eax, edx
  166. ; Abios work:
  167. ; v86 work:
  168. ;
  169. ;--
  170. ENTER_DR_ASSIST macro EnterLabel, ExitLabel, NoAbiosAssist, NoV86Assist, V86R
  171. local a,b
  172. public Dr_&EnterLabel
  173. align 4
  174. Dr_&EnterLabel:
  175. ;
  176. ; Test if we came from user-mode. If not, do nothing.
  177. ;
  178. test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
  179. jnz short a
  180. .errnz (MODE_MASK AND 0FFFFFF00h)
  181. test byte ptr [ebp]+TsSegCs,MODE_MASK
  182. jz Dr_&ExitLabel ; called from kmode, go continue
  183. ;
  184. ; Save user-mode Dr* regs in TrapFrame
  185. ;
  186. ; We are safe to destroy ebx, ecx, edi because in ENTER_INTERRUPT and
  187. ; ENTER_TRAP these registers are saved already. In ENTER_SYSTEMCALL
  188. ; ebx, edi is saved and ecx is don't-care.
  189. ;
  190. a: mov ebx,dr0
  191. mov ecx,dr1
  192. mov edi,dr2
  193. mov [ebp]+TsDr0,ebx
  194. mov [ebp]+TsDr1,ecx
  195. mov [ebp]+TsDr2,edi
  196. mov ebx,dr3
  197. mov ecx,dr6
  198. mov edi,dr7
  199. mov [ebp]+TsDr3,ebx
  200. mov [ebp]+TsDr6,ecx
  201. xor ebx,ebx
  202. mov [ebp]+TsDr7,edi
  203. ;
  204. ; Make Dr7 safe before loading junk from save area
  205. ;
  206. mov dr7,ebx
  207. ;
  208. ; Load KernelDr* into processor
  209. ;
  210. mov edi,dword ptr fs:[PcPrcb]
  211. mov ebx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr0
  212. mov ecx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr1
  213. mov dr0,ebx
  214. mov dr1,ecx
  215. mov ebx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr2
  216. mov ecx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr3
  217. mov dr2,ebx
  218. mov dr3,ecx
  219. mov ebx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr6
  220. mov ecx,[edi].PbProcessorState.PsSpecialRegisters.SrKernelDr7
  221. mov dr6,ebx
  222. mov dr7,ecx
  223. ifnb <V86R>
  224. test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
  225. jz short b
  226. jmp Dr_&V86R
  227. endif
  228. b:
  229. jmp Dr_&ExitLabel
  230. ifb <NoAbiosAssist>
  231. public Abios_&EnterLabel
  232. align 4
  233. Abios_&EnterLabel:
  234. ;
  235. ; INTERRUPT_STACK16_TO_STACK32
  236. ;
  237. ; This macro remaps current 32bit stack to 16bit stack at interrupt
  238. ; time.
  239. ;
  240. ; Arguments:
  241. ;
  242. ; (esp)->trap frame.
  243. ; (eax)->Entry Esp.
  244. ;
  245. mov eax, [esp].TsErrCode ; (eax) = Entry Esp
  246. mov ecx, KGDT_R0_DATA
  247. mov edx, fs:[PcPrcb] ; get current PRCB address
  248. mov edx, [edx]+PbCurrentThread ; get current thread
  249. mov edx, [edx]+ThStackLimit ; get thread stack base
  250. shl eax, 16
  251. add edx, esp
  252. mov [esp].TsErrCode, eax
  253. mov ss, cx
  254. mov esp, edx ; Interrupts are off
  255. mov ebp, edx
  256. jmp Abios_&ExitLabel
  257. endif ; NoAbiosAssist
  258. ifb <NoV86Assist>
  259. public V86_&EnterLabel
  260. align 4
  261. V86_&EnterLabel:
  262. ;
  263. ; Move the V86 segment registers to the correct place in the frame
  264. ;
  265. mov eax,dword ptr [ebp].TsV86Fs
  266. mov ebx,dword ptr [ebp].TsV86Gs
  267. mov ecx,dword ptr [ebp].TsV86Es
  268. mov edx,dword ptr [ebp].TsV86Ds
  269. mov [ebp].TsSegFs,ax
  270. mov [ebp].TsSegGs,bx
  271. mov [ebp].TsSegEs,cx
  272. mov [ebp].TsSegDs,dx
  273. jmp V86_&ExitLabel
  274. endif ; NoV86Assist
  275. endm
  276. ;++
  277. ;
  278. ; ENTER_SYSCALL AssistLabel, TagetLabel, NoFSLoad
  279. ;
  280. ; Macro Description:
  281. ;
  282. ; Build the frame and set registers needed by a system call.
  283. ;
  284. ; Save:
  285. ; Errorpad,
  286. ; Non-volatile regs,
  287. ; FS,
  288. ; ExceptionList,
  289. ; PreviousMode
  290. ;
  291. ; Don't Save:
  292. ; Volatile regs
  293. ; Seg regs
  294. ; Floating point state
  295. ;
  296. ; Set:
  297. ; FS,
  298. ; ExceptionList,
  299. ; PreviousMode,
  300. ; Direction
  301. ;
  302. ; Arguments:
  303. ; AssistLabel - label ENTER_ASSIST macro is at
  304. ; TargetLabel - label to emit for ENTER_ASSIST to jump to
  305. ; NoFSLoad - Don't set FS(it is already set to KGDT_R0_PCR at entry).
  306. ;
  307. ; Exit-conditions:
  308. ; Interrupts match input state (this routine doesn't change IEF)
  309. ; (esp)->base of trap frame
  310. ; (ebp)->base of trap frame
  311. ; Preserves entry eax, edx
  312. ;
  313. ; Note:
  314. ; The DS: reference to PreviousMode is *required* for correct
  315. ; functioning of lazy selector loads. If you remove this use
  316. ; of DS:, put a DS: override on something.
  317. ;
  318. ;--
  319. ENTER_SYSCALL macro AssistLabel, TargetLabel, NoFSLoad, RejectVdmLabel
  320. .FPO ( FPO_LOCALS, FPO_PARAMS, FPO_PROLOG, FPO_REGS, FPO_USE_EBP, FPO_TRAPFRAME )
  321. ifdef KERNELONLY
  322. ;
  323. ; Construct trap frame.
  324. ;
  325. ; N.B. The initial part of the trap frame is constructed by pushing values
  326. ; on the stack. If the format of the trap frame is changed, then the
  327. ; following code must alos be changed.
  328. ;
  329. push 0 ; put pad dword for error on stack
  330. push ebp ; save the non-volatile registers
  331. push ebx ;
  332. push esi ;
  333. push edi ;
  334. ifb <NoFSLoad>
  335. push fs ; save and set FS to PCR.
  336. mov ebx,KGDT_R0_PCR ; set PCR segment number
  337. mov fs,bx ;
  338. else
  339. ; FS already contains KGDT_R0_PCR(entry via PentiumPro fast system call)
  340. push KGDT_R3_TEB OR RPL_MASK
  341. endif ; NoFSLoad
  342. mov esi,PCR[PcPrcbData+PbCurrentThread] ; get current thread address
  343. ;
  344. ; Save the old exception list in trap frame and initialize a new empty
  345. ; exception list.
  346. ;
  347. push PCR[PcExceptionList] ; save old exception list
  348. mov PCR[PcExceptionList],EXCEPTION_CHAIN_END ; set new empty list
  349. ;
  350. ; Save the old previous mode in trap frame, allocate remainder of trap frame,
  351. ; and set the new previous mode.
  352. ;
  353. push [esi]+ThPreviousMode ; save old previous mode
  354. sub esp,TsPreviousPreviousMode ; allocate remainder of trap frame
  355. mov ebx,[esp+TsSegCS] ; compute new previous mode
  356. and ebx,MODE_MASK ;
  357. mov [esi]+ThPreviousMode,bl ; set new previous mode
  358. ;
  359. ; Save the old trap frame address and set the new trap frame address.
  360. ;
  361. mov ebp,esp ; set trap frame address
  362. mov ebx,[esi].ThTrapFrame ; save current trap frame address
  363. mov [ebp].TsEdx,ebx ;
  364. test [esi].ThDebugActive, 0ffh ; See if we need to save debug registers
  365. mov [esi].ThTrapFrame,ebp ; set new trap frame address
  366. cld ; make sure direction is forward
  367. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  368. mov byte ptr [ebp].TsDr7, 0
  369. jnz Dr_&AssistLabel ; if nz, debugging is active on thread
  370. Dr_&TargetLabel: ;
  371. SET_DEBUG_DATA ; Note this destroys edi
  372. sti ; enable interrupts
  373. else
  374. %out ENTER_SYSCAL outside of kernel
  375. .err
  376. endif
  377. endm
  378. ;++
  379. ;
  380. ; ENTER_INTERRUPT AssistLabel, TargetLabel
  381. ;
  382. ; Macro Description:
  383. ;
  384. ; Build the frame and set registers needed by an interrupt.
  385. ;
  386. ; Save:
  387. ; Errorpad,
  388. ; Non-volatile regs,
  389. ; FS,
  390. ; ExceptionList,
  391. ; PreviousMode
  392. ; Volatile regs
  393. ; Seg regs from V86 mode
  394. ; DS, ES, GS
  395. ;
  396. ; Don't Save:
  397. ; Floating point state
  398. ;
  399. ; Set:
  400. ; FS,
  401. ; ExceptionList,
  402. ; Direction,
  403. ; DS, ES
  404. ;
  405. ; Don't Set:
  406. ; PreviousMode
  407. ;
  408. ; Arguments:
  409. ; AssistLabel - label ENTER_ASSIST macro is at
  410. ; TargetLabel - label to emit for ENTER_ASSIST to jump to
  411. ;
  412. ; Exit-conditions:
  413. ; Interrupts match input state (this routine doesn't change IEF)
  414. ; (esp)->base of trap frame
  415. ; (ebp)->base of trap frame
  416. ; Preserves entry eax, ecx, edx
  417. ;
  418. ;--
  419. ENTER_INTERRUPT macro AssistLabel, TargetLabel, PassParm
  420. local b
  421. .FPO ( FPO_LOCALS+2, FPO_PARAMS, FPO_PROLOG, FPO_REGS, FPO_USE_EBP, FPO_TRAPFRAME )
  422. ;
  423. ; Fill in parts of frame we care about
  424. ;
  425. ifb <PassParm>
  426. push esp ; Use Error code field to save 16bit esp
  427. endif
  428. push ebp ; Save the non-volatile registers
  429. push ebx
  430. push esi
  431. push edi
  432. sub esp, TsEdi
  433. mov ebp,esp
  434. mov [esp]+TsEax, eax ; Save volatile registers
  435. mov [esp]+TsEcx, ecx
  436. mov [esp]+TsEdx, edx
  437. if DBG
  438. mov dword ptr [esp]+TsPreviousPreviousMode, -1 ; ThPreviousMode not pushed on interrupt
  439. endif
  440. test dword ptr [esp].TsEFlags,EFLAGS_V86_MASK
  441. jnz V86_&AssistLabel
  442. cmp word ptr [esp]+TsSegCs, KGDT_R0_CODE
  443. jz short @f
  444. mov [esp]+TsSegFs, fs ; Save and set FS to PCR.
  445. mov [esp]+TsSegDs, ds
  446. mov [esp]+TsSegEs, es
  447. mov [esp]+TsSegGs, gs
  448. V86_&TargetLabel:
  449. mov ebx,KGDT_R0_PCR
  450. mov eax,KGDT_R3_DATA OR RPL_MASK
  451. mov fs, bx
  452. mov ds, ax
  453. mov es, ax
  454. @@:
  455. mov ebx, fs:[PcExceptionList] ;Save, set ExceptionList
  456. mov fs:[PcExceptionList],EXCEPTION_CHAIN_END
  457. mov [esp]+TsExceptionList, ebx
  458. ifnb <PassParm>
  459. lea eax, [esp].TsErrCode
  460. lea ecx, [esp].TsEip ; Move eax to EIP field
  461. mov ebx, ss:[eax] ; (ebx) = parameter to pass
  462. mov ss:[eax], ecx ; save 16bit esp
  463. endif
  464. ;
  465. ; Remap ABIOS 16 bit stack to 32 bit stack, if necessary.
  466. ;
  467. cmp esp, 10000h
  468. jb Abios_&AssistLabel
  469. mov dword ptr [esp].TsErrCode, 0 ; Indicate no remapping.
  470. Abios_&TargetLabel:
  471. ;
  472. ; end of Abios stack checking
  473. ;
  474. ifdef PcPrcbData
  475. mov ecx,PCR[PcPrcbData+PbCurrentThread] ; get current thread address
  476. else
  477. mov ecx,PCR[PcPrcb]
  478. mov ecx,[ecx].PbCurrentThread ; get current thread address
  479. endif
  480. cld
  481. ifnb <PassParm>
  482. push ebx ; push parameter as argument
  483. endif
  484. test byte ptr [ecx].ThDebugActive, 0ffh ; See if debug registers need saving
  485. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  486. mov [ebp].TsDr7, 0
  487. jnz Dr_&AssistLabel
  488. Dr_&TargetLabel:
  489. SET_DEBUG_DATA
  490. endm
  491. ;++
  492. ;
  493. ; ENTER_INTERRUPT_FORCE_STATE AssistLabel, TargetLabel
  494. ;
  495. ; Macro Description:
  496. ;
  497. ; Build the frame and set registers needed by an interrupt.
  498. ;
  499. ; This macro is the same as ENTER_INTERRUPT except that it forces the
  500. ; needed state and does not save previous state.
  501. ;
  502. ; This macro is currently only used by HalpApicRebootService which does not
  503. ; return;
  504. ;
  505. ; Save:
  506. ; Errorpad,
  507. ; Non-volatile regs,
  508. ; ExceptionList,
  509. ; PreviousMode
  510. ; Volatile regs
  511. ; Seg regs from V86 mode
  512. ;
  513. ; Don't Save:
  514. ; FS,
  515. ; DS, ES, GS
  516. ; Floating point state
  517. ;
  518. ; Set:
  519. ; FS,
  520. ; ExceptionList,
  521. ; Direction,
  522. ; DS, ES
  523. ;
  524. ; Don't Set:
  525. ; PreviousMode
  526. ;
  527. ; Arguments:
  528. ; AssistLabel - label ENTER_ASSIST macro is at
  529. ; TargetLabel - label to emit for ENTER_ASSIST to jump to
  530. ;
  531. ; Exit-conditions:
  532. ; Interrupts match input state (this routine doesn't change IEF)
  533. ; (esp)->base of trap frame
  534. ; (ebp)->base of trap frame
  535. ; Preserves entry eax, ecx, edx
  536. ;
  537. ;--
  538. ENTER_INTERRUPT_FORCE_STATE macro AssistLabel, TargetLabel, PassParm
  539. local b
  540. .FPO ( FPO_LOCALS+2, FPO_PARAMS, FPO_PROLOG, FPO_REGS, FPO_USE_EBP, FPO_TRAPFRAME )
  541. ;
  542. ; Fill in parts of frame we care about
  543. ;
  544. ifb <PassParm>
  545. push esp ; Use Error code field to save 16bit esp
  546. endif
  547. push ebp ; Save the non-volatile registers
  548. push ebx
  549. push esi
  550. push edi
  551. sub esp, TsEdi
  552. mov ebp,esp
  553. mov [esp]+TsEax, eax ; Save volatile registers
  554. mov [esp]+TsEcx, ecx
  555. mov [esp]+TsEdx, edx
  556. if DBG
  557. mov dword ptr [esp]+TsPreviousPreviousMode, -1 ; ThPreviousMode not pushed on interrupt
  558. endif
  559. test dword ptr [esp].TsEflags,EFLAGS_V86_MASK
  560. jnz V86_&AssistLabel
  561. V86_&TargetLabel:
  562. mov ebx,KGDT_R0_PCR
  563. mov eax,KGDT_R3_DATA OR RPL_MASK
  564. mov fs, bx
  565. mov ds, ax
  566. mov es, ax
  567. @@:
  568. mov ebx, fs:[PcExceptionList] ;Save, set ExceptionList
  569. mov fs:[PcExceptionList],EXCEPTION_CHAIN_END
  570. mov [esp]+TsExceptionList, ebx
  571. ifnb <PassParm>
  572. lea eax, [esp].TsErrCode
  573. lea ecx, [esp].TsEip ; Move eax to EIP field
  574. mov ebx, ss:[eax] ; (ebx) = parameter to pass
  575. mov ss:[eax], ecx ; save 16bit esp
  576. endif
  577. ;
  578. ; Remap ABIOS 16 bit stack to 32 bit stack, if necessary.
  579. ;
  580. cmp esp, 10000h
  581. jb Abios_&AssistLabel
  582. mov dword ptr [esp].TsErrCode, 0 ; Indicate no remapping.
  583. Abios_&TargetLabel:
  584. ;
  585. ; end of Abios stack checking
  586. ;
  587. ifdef PcPrcbData
  588. mov ecx,PCR[PcPrcbData+PbCurrentThread] ; get current thread address
  589. else
  590. mov ecx,PCR[PcPrcb]
  591. mov ecx,[ecx].PbCurrentThread ; get current thread address
  592. endif
  593. cld
  594. ifnb <PassParm>
  595. push ebx ; push parameter as argument
  596. endif
  597. test byte ptr [ecx].ThDebugActive, 0ffh ; See if debug registers need saving
  598. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  599. mov [ebp].TsDr7, 0
  600. jnz Dr_&AssistLabel
  601. Dr_&TargetLabel:
  602. SET_DEBUG_DATA
  603. endm
  604. ;++
  605. ;
  606. ; ENTER_TRAP AssistLabel, TargetLabel
  607. ;
  608. ; Macro Description:
  609. ;
  610. ; Build the frame and set registers needed by a trap or exception.
  611. ;
  612. ; Save:
  613. ; Non-volatile regs,
  614. ; FS,
  615. ; ExceptionList,
  616. ; PreviousMode,
  617. ; Volatile regs
  618. ; Seg Regs from V86 mode
  619. ; DS, ES, GS
  620. ;
  621. ; Don't Save:
  622. ; Floating point state
  623. ;
  624. ; Set:
  625. ; FS,
  626. ; Direction,
  627. ; DS, ES
  628. ;
  629. ; Don't Set:
  630. ; PreviousMode,
  631. ; ExceptionList
  632. ;
  633. ; Arguments:
  634. ; AssistLabel - label ENTER_ASSIST macro is at
  635. ; TargetLabel - label to emit for ENTER_ASSIST to jump to
  636. ;
  637. ; Exit-conditions:
  638. ; Interrupts match input state (this routine doesn't change IEF)
  639. ; (esp)->base of trap frame
  640. ; (ebp)->base of trap frame
  641. ; Preserves entry eax
  642. ;
  643. ;--
  644. ENTER_TRAP macro AssistLabel, TargetLabel
  645. local b
  646. .FPO ( FPO_LOCALS, FPO_PARAMS, FPO_PROLOG, FPO_REGS, FPO_USE_EBP, FPO_TRAPFRAME )
  647. ;
  648. ; Fill in parts of frame we care about
  649. ;
  650. if DBG
  651. ifndef _Ki16BitStackException
  652. EXTRNP _Ki16BitStackException
  653. endif
  654. endif ; DBG
  655. mov word ptr [esp+2], 0 ; Clear upper word of ErrorCode
  656. push ebp ; Save the non-volatile registers
  657. push ebx
  658. push esi
  659. push edi
  660. push fs ; Save and set FS to PCR.
  661. mov ebx,KGDT_R0_PCR
  662. mov fs,bx
  663. mov ebx, fs:[PcExceptionList] ;Save ExceptionList
  664. push ebx
  665. if DBG
  666. push -1 ; Don't need to save ThPreviousMode from trap
  667. else
  668. sub esp, 4 ; pad dword
  669. endif
  670. push eax ; Save the volatile registers
  671. push ecx
  672. push edx
  673. push ds ; Save segments
  674. push es
  675. push gs
  676. ;
  677. ; Skip allocate reset of trap frame and Set up DS/ES, they may be trash
  678. ;
  679. mov ax,KGDT_R3_DATA OR RPL_MASK
  680. sub esp,TsSegGs
  681. mov ds,ax
  682. mov es,ax
  683. if DBG
  684. ;
  685. ; The code here check if the exception occurred in ring 0
  686. ; ABIOS code. If yes, this is a fatal condition. We will
  687. ; put out message and bugcheck.
  688. ;
  689. cmp esp, 10000h ; Is the trap in abios?
  690. jb _Ki16BitStackException ; if b, yes, switch stack and bugcheck.
  691. endif ; DBG
  692. mov ebp,esp
  693. test dword ptr [esp].TsEflags,EFLAGS_V86_MASK
  694. jnz V86_&AssistLabel
  695. V86_&TargetLabel:
  696. ifdef PcPrcbData
  697. mov ecx,PCR[PcPrcbData+PbCurrentThread] ; get current thread address
  698. else
  699. mov ecx,PCR[PcPrcb]
  700. mov ecx,[ecx].PbCurrentThread ; get current thread address
  701. endif
  702. cld
  703. test byte ptr [ecx].ThDebugActive, 0ffh ; See if debug registers need saving
  704. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  705. mov [ebp].TsDr7, 0
  706. jnz Dr_&AssistLabel
  707. Dr_&TargetLabel:
  708. SET_DEBUG_DATA
  709. endm
  710. ;++
  711. ;
  712. ; EXIT_ALL NoRestoreSegs, NoRestoreVolatiles, NoPreviousMode
  713. ;
  714. ; Macro Description:
  715. ;
  716. ; Load a syscall frame back into the machine.
  717. ;
  718. ; Restore:
  719. ; Volatile regs, IF NoRestoreVolatiles blank
  720. ; NoPreviousMode,
  721. ; ExceptionList,
  722. ; FS,
  723. ; Non-volatile regs
  724. ;
  725. ; If the frame is a kernel mode frame, AND esp has been edited,
  726. ; then TsSegCs will have a special value. Test for that value
  727. ; and execute special code for that case.
  728. ;
  729. ; N.B. This macro generates an IRET! (i.e. It exits!)
  730. ;
  731. ; Arguments:
  732. ;
  733. ; NoRestoreSegs - non-blank if DS, ES, GS are NOT to be restored
  734. ;
  735. ; NoRestoreVolatiles - non-blank if Volatile regs are NOT to be restored
  736. ;
  737. ; NoPreviousMode - if nb pop ThPreviousMode
  738. ;
  739. ; Entry-conditions:
  740. ;
  741. ; (esp)->base of trap frame
  742. ; (ebp)->Base of trap frame
  743. ;
  744. ; Exit-conditions:
  745. ;
  746. ; Does not exit, returns.
  747. ; Preserves eax, ecx, edx, IFF NoRestoreVolatiles is set
  748. ;
  749. ;--
  750. ?adjesp = 0
  751. ?RestoreAll = 1
  752. EXIT_ALL macro NoRestoreSegs, NoRestoreVolatiles, NoPreviousMode
  753. local a, b, f, x
  754. local Dr_ExitHelp, Dr_ExitHelp_Target
  755. local Db_NotATrapFrame, Db_A, Db_NotValidEntry, NonFlatPm_Target
  756. ;
  757. ; Sanity check some values and setup globals for macro
  758. ;
  759. ?adjesp = TsSegGs
  760. ?RestoreAll = 1
  761. ifnb <NoRestoreSegs>
  762. ?RestoreAll = 0
  763. ?adjesp = ?adjesp + 12
  764. endif
  765. ifnb <NoRestoreVolatiles>
  766. if ?RestoreAll eq 1
  767. %out "EXIT_ALL NoRestoreVolatiles requires NoRestoreSegs"
  768. .err
  769. endif
  770. ?adjesp = ?adjesp + 12
  771. endif
  772. ifb <NoPreviousMode>
  773. ifndef KERNELONLY
  774. %out EXIT_ALL can not restore previousmode outside kernel
  775. .err
  776. endif
  777. endif
  778. ; All callers are responsible for getting here with interrupts disabled.
  779. if DBG
  780. pushfd
  781. pop edx
  782. test edx, EFLAGS_INTERRUPT_MASK
  783. jnz Db_NotValidEntry
  784. cmp esp, ebp ; make sure esp = ebp
  785. jne Db_NotValidEntry
  786. ; Make sure BADB0D00 sig is present. If not this isn't a trap frame!
  787. Db_A: sub [esp]+TsDbgArgMark,0BADB0D00h
  788. jne Db_NotATrapFrame
  789. endif
  790. ASSERT_FS
  791. mov edx, [esp]+TsExceptionList
  792. if DBG
  793. or edx, edx
  794. jnz short @f
  795. int 3
  796. @@:
  797. endif
  798. mov fs:[PcExceptionList], edx ; Restore ExceptionList
  799. ifb <NoPreviousMode>
  800. mov ecx, [esp]+TsPreviousPreviousMode ; Restore PreviousMode
  801. if DBG
  802. cmp ecx, -1 ; temporary debugging code
  803. jne @f ; to make sure no one tries to pop ThPreviousMode
  804. int 3 ; when it wasn't saved
  805. @@:
  806. endif
  807. mov esi,fs:[PcPrcbData+PbCurrentThread]
  808. mov [esi]+ThPreviousMode,cl
  809. else
  810. if DBG
  811. mov ecx, [esp]+TsPreviousPreviousMode
  812. cmp ecx, -1 ; temporary debugging code
  813. je @f ; to make sure no one pushed ThPreviousMode and
  814. int 3 ; is now exiting without restoreing it
  815. @@:
  816. endif
  817. endif
  818. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  819. test byte ptr [esp].TsDr7, DR7_ACTIVE
  820. jnz Dr_ExitHelp
  821. Dr_ExitHelp_Target:
  822. test dword ptr [esp].TsEflags,EFLAGS_V86_MASK
  823. jnz V86ExitHelp
  824. test word ptr [esp]+TsSegCs,FRAME_EDITED
  825. jz b ; Edited frame pop out.
  826. if ?RestoreAll eq 0
  827. .errnz MODE_MASK-1
  828. cmp word ptr [esp]+TsSegCs,KGDT_R3_CODE OR RPL_MASK ; set/clear ZF
  829. bt word ptr [esp]+TsSegCs,0 ; test MODE_MASK set/clear CF
  830. cmc ; (CF=1 and ZF=0)
  831. ja f ; jmp if CF=0 and ZF=0
  832. endif
  833. ifb <NoRestoreVolatiles>
  834. mov edx, [esp]+TsEdx ; Restore volitales
  835. mov ecx, [esp]+TsEcx
  836. ; must restore eax before any
  837. mov eax, [esp].TsEax ; selectors! (see trap0e handler)
  838. endif
  839. cmp word ptr [ebp]+TsSegCs, KGDT_R0_CODE
  840. jz short @f
  841. ifb <NoRestoreSegs>
  842. lea esp, [ebp]+TsSegGs
  843. pop gs ; Restore Segs
  844. pop es
  845. pop ds
  846. endif
  847. NonFlatPm_Target:
  848. lea esp, [ebp]+TsSegFs
  849. pop fs
  850. @@:
  851. lea esp, [ebp]+TsEdi ; Skip PreMode, ExceptList and fs
  852. pop edi ; restore non-volatiles
  853. pop esi
  854. pop ebx
  855. pop ebp
  856. ;
  857. ; Esp MUST point to the Error Code on the stack. Because we use it to
  858. ; store the entering esp.
  859. ;
  860. cmp word ptr [esp+8], 80h ; check for abios code segment?
  861. ja AbiosExitHelp
  862. add esp, 4 ; remove error code from trap frame
  863. ifnb <NoRestoreVolatiles>
  864. public _KiSystemCallExitBranch
  865. public _KiSystemCallExit
  866. public _KiSystemCallExit2
  867. public _KiSystemCallExit3
  868. ; NoRestoreVolatiles is only used for return from System Service.
  869. ; If returning to Kernel mode, the processor state does not need
  870. ; to be altered (CS, CPL stays the same etc), so simply unwind the
  871. ; kernel frame and branch to the saved EIP.
  872. test dword ptr [esp+4], MODE_MASK
  873. ; If the following branch is taken, we are returning to usermode.
  874. ; If this processor supports the SYSEXIT instruction, the branch
  875. ; will be adjusted at boot time to use the appropriate code sequence.
  876. _KiSystemCallExitBranch:
  877. jnz short _KiSystemCallExit
  878. ; Exit to kernel mode from system call, faster than IRETD,
  879. ; unwind the frame and branch to return address.
  880. pop edx ; get eip
  881. pop ecx ; remove CS from stack
  882. popfd ; restore eflags
  883. jmp edx
  884. if 0
  885. ; one day we should test and see if the following is faster
  886. ; than the above (and still valid).
  887. sti ; reenable interrupts
  888. ret 8 ; return to @esp and pop CS and EFLAGs
  889. endif
  890. _KiSystemCallExit:
  891. iretd ; return
  892. _KiSystemCallExit2:
  893. test dword ptr [esp+8], EFLAGS_TF
  894. jne short _KiSystemCallExit
  895. pop edx ; pop EIP
  896. add esp, 4 ; Remove CS
  897. and dword ptr [esp], NOT EFLAGS_INTERRUPT_MASK ; Disable interrupts in the flags
  898. popfd
  899. pop ecx ; pop ESP
  900. sti ; sysexit does not reload flags
  901. iSYSEXIT
  902. _KiSystemCallExit3:
  903. ; AMD
  904. pop ecx ; pop EIP
  905. add esp, 8
  906. pop esp
  907. ; mov esp, [esp+8] ; remove CS & Eflags, get ESP
  908. iSYSRET
  909. endif ;; <NoRestoreVolatiles>
  910. iretd ; return
  911. if DBG
  912. Db_NotATrapFrame:
  913. add [esp]+TsDbgArgMark,0BADB0D00h ; put back the orig value
  914. Db_NotValidEntry:
  915. int 3
  916. jmp Db_A
  917. endif
  918. ;
  919. ; EXIT_HELPER
  920. ;
  921. ; if (PreviousMode == UserMode) {
  922. ; DR* regs = TF.Dr* regs
  923. ; }
  924. ;
  925. ; Entry-Conditions:
  926. ;
  927. ; DebugActive == TRUE
  928. ; (ebp)->TrapFrame
  929. ;
  930. ;--
  931. align dword
  932. Dr_ExitHelp:
  933. test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
  934. jnz short x
  935. test dword ptr [ebp]+TsSegCs,MODE_MASK
  936. jz Dr_ExitHelp_Target
  937. x: xor ebx,ebx
  938. mov esi,[ebp]+TsDr0
  939. mov edi,[ebp]+TsDr1
  940. mov dr7,ebx
  941. mov dr0,esi
  942. mov ebx,[ebp]+TsDr2
  943. mov dr1,edi
  944. mov dr2,ebx
  945. mov esi,[ebp]+TsDr3
  946. mov edi,[ebp]+TsDr6
  947. mov ebx,[ebp]+TsDr7
  948. mov dr3,esi
  949. mov dr6,edi
  950. mov dr7,ebx
  951. jmp Dr_ExitHelp_Target
  952. ;
  953. if ?RestoreAll eq 0
  954. ;
  955. ; Restore segs and volatiles for non-flat R3 PM (VDM in PM)
  956. ;
  957. f: mov eax,[esp].TsEax ; restore eax before any selectors
  958. ; (see trap0e handler)
  959. add esp,TsSegGs
  960. pop gs
  961. pop es
  962. pop ds
  963. pop edx
  964. pop ecx
  965. jmp NonFlatPm_Target
  966. endif ; not ?RestoreAll
  967. ;
  968. ; TsSegCs contains the special value that means the frame was edited
  969. ; in a way that affected esp, AND it's a kernel mode frame.
  970. ; (Special value is null selector except for RPL.)
  971. ;
  972. ; Put back the real CS.
  973. ; push eflags, eip onto target stack
  974. ; restore
  975. ; switch to target stack
  976. ; iret
  977. ;
  978. b: mov ebx,[esp]+TsTempSegCs
  979. mov [esp]+TsSegCs,ebx
  980. ;
  981. ; There is no instruction that will load esp with an arbitrary value
  982. ; (i.e. one out of a frame) and do a return, if no privledge transition
  983. ; is occuring. Therefore, if we are returning to kernel mode, and
  984. ; esp has been edited, we must "emulate" a kind of iretd.
  985. ;
  986. ; We do this by logically pushing the eip,cs,eflags onto the new
  987. ; logical stack, loading that stack, and doing an iretd. This
  988. ; requires that the new logical stack is at least 1 dword higher
  989. ; than the unedited esp would have been. (i.e. It is not legal
  990. ; to edit esp to have a new value < the old value.)
  991. ;
  992. ; KeContextToKframes enforces this rule.
  993. ;
  994. ;
  995. ; Compute new logical stack address
  996. ;
  997. mov ebx,[esp]+TsTempEsp
  998. sub ebx,12
  999. mov [esp]+TsErrCode,ebx
  1000. ;
  1001. ; Copy eip,cs,eflags to new stack. note we do this high to low
  1002. ;
  1003. mov esi,[esp]+TsEflags
  1004. mov [ebx+8],esi
  1005. mov esi,[esp]+TsSegCs
  1006. mov [ebx+4],esi
  1007. mov esi,[esp]+TsEip
  1008. mov [ebx],esi
  1009. ;
  1010. ; Do a standard restore sequence.
  1011. ;
  1012. ; Observe that RestoreVolatiles is honored. Editing a volatile
  1013. ; register has no effect when returning from a system call.
  1014. ;
  1015. ifb <NoRestoreVolatiles>
  1016. mov eax,[esp].TsEax
  1017. endif
  1018. ; add esp,TsSegGs
  1019. ;
  1020. ;ifb <NoRestoreSegs>
  1021. ; pop gs
  1022. ; pop es
  1023. ; pop ds
  1024. ;else
  1025. ; add esp,12
  1026. ;endif
  1027. ifb <NoRestoreVolatiles>
  1028. mov edx, [esp]+TsEdx
  1029. mov ecx, [esp]+TsEcx
  1030. endif
  1031. ;ifnb <NoPreviousMode>
  1032. ; add esp, 4 ; Skip previous mode
  1033. ;else
  1034. ; pop ebx ; Restore PreviousMode
  1035. ; mov esi,fs:[PcPrcbData+PbCurrentThread]
  1036. ; mov ss:[esi]+ThPreviousMode,bl
  1037. ;endif
  1038. ;
  1039. ; pop ebx
  1040. ;
  1041. ; mov fs:[PcExceptionList], ebx ;Restore ExceptionList
  1042. ; pop fs
  1043. add esp, TsEdi
  1044. pop edi ; restore non-volatiles
  1045. pop esi
  1046. pop ebx
  1047. pop ebp
  1048. ;
  1049. ; (esp)->TsErrCode, where we saved the new esp
  1050. ;
  1051. mov esp,[esp] ; Do move not push to avoid increment
  1052. iretd
  1053. endm
  1054. ;++
  1055. ;
  1056. ; INTERRUPT_EXIT
  1057. ;
  1058. ; Macro Description:
  1059. ;
  1060. ; This macro is executed on return from an interrupt vector service
  1061. ; service routine. Its function is to restore privileged processor
  1062. ; state, and continue thread execution. If control is returning to
  1063. ; user mode and there is a user APC pending, then APC level interupt
  1064. ; will be requested and control is transfered to the user APC delivery
  1065. ; routine, if no higher level interrupt pending.
  1066. ;
  1067. ; Arguments:
  1068. ;
  1069. ; (TOS) = previous irql
  1070. ; (TOS+4) = irq vector to eoi
  1071. ; (TOS+8 ...) = machine_state frame
  1072. ; (ebp)-> machine state frame (trap frame)
  1073. ;
  1074. ;--
  1075. INTERRUPT_EXIT macro DebugCheck
  1076. local a
  1077. ifnb <DebugCheck>
  1078. POLL_DEBUGGER
  1079. endif
  1080. if DBG ; save current eip for
  1081. a: mov esi, offset a ; debugging bad trap frames
  1082. endif
  1083. ifdef __imp_Kei386EoiHelper@0
  1084. cli
  1085. call _HalEndSystemInterrupt@8
  1086. jmp dword ptr [__imp_Kei386EoiHelper@0]
  1087. else
  1088. cli
  1089. call dword ptr [__imp__HalEndSystemInterrupt@8]
  1090. jmp Kei386EoiHelper@0
  1091. endif
  1092. endm
  1093. ;++
  1094. ;
  1095. ; SPURIOUS_INTERRUPT_EXIT
  1096. ;
  1097. ; Macro Description:
  1098. ;
  1099. ; To exit an interrupt without performing the EOI.
  1100. ;
  1101. ; Arguments:
  1102. ;
  1103. ; (TOS) = machine_state frame
  1104. ; (ebp)-> machine state frame (trap frame)
  1105. ;
  1106. ;--
  1107. SPURIOUS_INTERRUPT_EXIT macro
  1108. local a
  1109. if DBG ; save current eip for
  1110. a: mov esi, offset a ; debugging bad trap frames
  1111. endif
  1112. ifdef __imp_Kei386EoiHelper@0
  1113. jmp dword ptr [__imp_Kei386EoiHelper@0]
  1114. else
  1115. jmp Kei386EoiHelper@0
  1116. endif
  1117. endm
  1118. ;++
  1119. ;
  1120. ; ENTER_TRAPV86
  1121. ;
  1122. ; Macro Description:
  1123. ;
  1124. ; Construct trap frame for v86 mode traps.
  1125. ;
  1126. ;--
  1127. ENTER_TRAPV86 macro DRENTER,V86ENTER
  1128. sub esp, TsErrCode
  1129. mov word ptr [esp].TsErrCode + 2, 0
  1130. mov [esp].TsEbx, ebx
  1131. mov [esp].TsEax, eax
  1132. mov [esp].TsEbp, ebp
  1133. mov [esp].TsEsi, esi
  1134. mov [esp].TsEdi, edi
  1135. mov ebx, KGDT_R0_PCR
  1136. mov eax, KGDT_R3_DATA OR RPL_MASK
  1137. mov [esp].TsEcx, ecx
  1138. mov [esp].TsEdx, edx
  1139. if DBG
  1140. mov [esp].TsPreviousPreviousMode, -1
  1141. mov [esp].TsDbgArgMark, 0BADB0D00h
  1142. endif
  1143. mov fs, bx
  1144. mov ds, ax
  1145. mov es, ax
  1146. mov ebp, esp
  1147. mov eax, PCR[PcExceptionList]
  1148. mov [esp]+TsExceptionList, eax
  1149. mov eax, dr7
  1150. cld ; CHECKIT_SUDEEP ; do we really need it
  1151. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  1152. test al, DR7_ACTIVE
  1153. mov [esp].TsDr7, eax
  1154. jnz Dr_&DRENTER
  1155. Dr_&V86ENTER:
  1156. endm
  1157. ;
  1158. ; Taken from ntos\vdm\i386\vdmtb.inc
  1159. ;
  1160. FIXED_NTVDMSTATE_LINEAR_PC_AT equ 0714H
  1161. FIXED_NTVDMSTATE_LINEAR_PC_98 equ 0614H
  1162. MACHINE_TYPE_MASK equ 0ff00H
  1163. VDM_VIRTUAL_INTERRUPTS equ 0200H
  1164. ;++
  1165. ;
  1166. ; EXIT_TRAPV86
  1167. ;
  1168. ; Macro Description:
  1169. ;
  1170. ; if UserApc is pending deliver it
  1171. ; if User Context is v86 mode
  1172. ; Exit from kernel (does not return)
  1173. ; else
  1174. ; return (expected to execute EXIT_ALL)
  1175. ;--
  1176. EXIT_TRAPV86 macro
  1177. local w, x, y, z
  1178. z: mov ebx, PCR[PcPrcbData+PbCurrentThread]
  1179. mov byte ptr [ebx]+ThAlerted, 0
  1180. cmp byte ptr [ebx]+ThApcState.AsUserApcPending, 0
  1181. jne short w
  1182. ;
  1183. ; Kernel exit to V86 mode
  1184. ;
  1185. add esp,TsEdx
  1186. pop edx
  1187. pop ecx
  1188. pop eax
  1189. .errnz (DR7_ACTIVE AND 0FFFFFF00h)
  1190. test byte ptr [ebp].TsDr7, DR7_ACTIVE
  1191. jnz short x
  1192. y:
  1193. add esp,12 ; unused fields
  1194. pop edi
  1195. pop esi
  1196. pop ebx
  1197. pop ebp
  1198. add esp,4 ; clear error code
  1199. iretd
  1200. x: xor ebx, ebx
  1201. mov esi,[ebp]+TsDr0
  1202. mov edi,[ebp]+TsDr1
  1203. mov dr7, ebx ; Turn off debug exceptions while reloading
  1204. mov ebx,[ebp]+TsDr2
  1205. mov dr0,esi
  1206. mov dr1,edi
  1207. mov dr2,ebx
  1208. mov esi,[ebp]+TsDr3
  1209. mov edi,[ebp]+TsDr6
  1210. mov ebx,[ebp]+TsDr7
  1211. mov dr3,esi
  1212. mov dr6,edi
  1213. mov dr7,ebx
  1214. jmp short y
  1215. w:
  1216. ;
  1217. ; Dispatch user mode APC
  1218. ; The APC routine runs with interrupts on and at APC level
  1219. ;
  1220. RaiseIrql APC_LEVEL
  1221. push eax ; Save OldIrql
  1222. sti
  1223. stdCall _KiDeliverApc, <1, 0, ebp> ; ebp - Trap frame
  1224. ; 0 - Null exception frame
  1225. ; 1 - Previous mode
  1226. pop ecx ; (TOS) = OldIrql
  1227. LowerIrql ecx
  1228. cli
  1229. ;
  1230. ; UserApc may have changed to vdm Monitor context (user flat 32)
  1231. ; If it has cannot use the v86 only kernel exit
  1232. ;
  1233. test dword ptr [ebp]+TsEFlags,EFLAGS_V86_MASK
  1234. jnz z
  1235. ; Exit to do EXIT_ALL
  1236. endm
  1237. ;++
  1238. ;
  1239. ; KERNEL ICECAP PROBE MACROS
  1240. ;
  1241. ; Macro Description:
  1242. ;
  1243. ; Used to wrap selected calls in .asm routines with the same
  1244. ; probe calls inserted by the C compiler when /fastcap is used.
  1245. ; The X-suffix versions of the probe calls are used only in
  1246. ; KiSystemService and log additional information such as
  1247. ; Pid, Tid, image file name, etc.
  1248. ;
  1249. ; Arguments:
  1250. ;
  1251. ; Current Function
  1252. ; Called Function
  1253. ;
  1254. ;--
  1255. IFDEF _CAPKERN
  1256. extrn __CAP_Start_Profiling@8:PROC
  1257. extrn __CAP_End_Profiling@4:PROC
  1258. extrn _CAP_Log_NInt:PROC
  1259. CAPSTART macro ArgList
  1260. stdCall __CAP_Start_Profiling, <ArgList>
  1261. endm
  1262. CAPEND macro ArgList
  1263. stdCall __CAP_End_Profiling, <ArgList>
  1264. endm
  1265. CAPSTARTX macro ArgList
  1266. push eax
  1267. stdCall __CAP_ThreadID
  1268. pop eax
  1269. stdCall __CAP_Start_Profiling, <ArgList>
  1270. endm
  1271. CAPENDX macro ArgList
  1272. stdCall __CAP_End_Profiling, <ArgList>
  1273. push eax
  1274. stdCall __CAP_SetCPU
  1275. pop eax
  1276. endm
  1277. ELSE
  1278. CAPSTART macro ArgList
  1279. endm
  1280. CAPEND macro ArgList
  1281. endm
  1282. CAPSTARTX macro ArgList
  1283. endm
  1284. CAPENDX macro ArgList
  1285. endm
  1286. ENDIF
  1287. ;++
  1288. ;
  1289. ; PERF_GET_TIMESTAMP
  1290. ;
  1291. ; Macro Description:
  1292. ;
  1293. ;
  1294. ; Return a time stamp that for event tracing in EDX:EAX
  1295. ;
  1296. ; NOTE: This may trash ECX
  1297. ;
  1298. ; In retail, get the clock value from WmiGetCpuClock. Else if using
  1299. ; reserved memory for logging, get cycle counter.
  1300. ;
  1301. ;--
  1302. PERF_GET_TIMESTAMP macro
  1303. extrn _WmiGetCpuClock:DWORD
  1304. call [_WmiGetCpuClock]
  1305. endm