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.

137 lines
3.9 KiB

  1. title "Asynchronous Procedure Call Interrupt"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; apcint.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the code necessary to process the Asynchronous
  13. ; Procedure Call interrupt request.
  14. ;
  15. ; Author:
  16. ;
  17. ; David N. Cutler (davec) 10-Nov-2000
  18. ;
  19. ; Environment:
  20. ;
  21. ; Kernel mode only.
  22. ;
  23. ;--
  24. extern KiDeliverApc:proc
  25. extern __imp_HalEndSystemInterrupt:qword
  26. include ksamd64.inc
  27. subttl "Asynchronous Procedure Call Interrupt"
  28. ;++
  29. ;
  30. ; VOID
  31. ; KiApcInterrupt (
  32. ; VOID
  33. ; )
  34. ;
  35. ; Routine Description:
  36. ;
  37. ; This routine is entered as the result of a software interrupt generated
  38. ; at APC_LEVEL. Its function is to save the machine state and call the APC
  39. ; delivery routine.
  40. ;
  41. ; N.B. This is a directly connected interrupt that does not use an interrupt
  42. ; object.
  43. ;
  44. ; N.B. APC interrupts are never requested for user mode APCs.
  45. ;
  46. ; Arguments:
  47. ;
  48. ; None.
  49. ;
  50. ; Return Value:
  51. ;
  52. ; None.
  53. ;
  54. ;--
  55. NESTED_ENTRY KiApcInterrupt, _TEXT$00
  56. .pushframe ; mark machine frame
  57. push_reg rbp ; push dummy vector
  58. push_reg rbp ; save nonvolatile register
  59. GENERATE_INTERRUPT_FRAME ; generate interrupt frame
  60. mov ecx, APC_LEVEL ; set new IRQL level
  61. ENTER_INTERRUPT ; raise IRQL, do EOI, enable interrupts
  62. mov cl, KernelMode ; set APC processor mode
  63. xor edx, edx ; set exception frame address
  64. lea r8, (-128)[rbp] ; set trap frame address
  65. call KiDeliverApc ; initiate APC execution
  66. EXIT_INTERRUPT <NoEOI> ; lower IRQL and restore state
  67. NESTED_END KiApcInterrupt, _TEXT$00
  68. subttl "Initiate User APC Execution"
  69. ;++
  70. ;
  71. ; Routine Description:
  72. ;
  73. ; This routine generates an exception frame and attempts to deliver a user
  74. ; APC.
  75. ;
  76. ; Arguments:
  77. ;
  78. ; rbp - Supplies the address of the trap frame.
  79. ;
  80. ; rsp - Supplies the address of the trap frame.
  81. ;
  82. ; Return value:
  83. ;
  84. ; None.
  85. ;
  86. ;--
  87. NESTED_ENTRY KiInitiateUserApc, _TEXT$00
  88. GENERATE_EXCEPTION_FRAME ; generate exception frame
  89. mov rbx, gs:[PcCurrentThread] ; get current thread address
  90. cmp byte ptr ThNpxState[rbx], LEGACY_STATE_SWITCH ; check if switched
  91. jne short KiIU10 ; if ne, legacy state not switched
  92. ;
  93. ; N.B. The legacy floating point state must be saved and restored since saving
  94. ; the state initializes some of the state.
  95. ;
  96. ; N.B. Interrupts must also be disabled during this sequence to ensure that a
  97. ; get context APC interrupt does not occur.
  98. ;
  99. lea rsi, (KTRAP_FRAME_LENGTH - 128)[rbp] ; get legacy save address
  100. cli ; disable interrupts
  101. fnsaved [rsi] ; save legacy floating state
  102. mov di, LfControlWord[rsi] ; save current control word
  103. mov word ptr LfControlWord[rsi], 03fh ; set to mask all exceptions
  104. frstord [rsi] ; restore legacy floating point state
  105. mov LfControlWord[rsi], di ; restore control word
  106. fldcw word ptr LfControlWord[rsi] ; load legacy control word
  107. sti ; enable interrupts
  108. KiIU10: mov cl, UserMode ; set APC processor mode
  109. mov rdx, rsp ; set exception frame address
  110. lea r8, (-128)[rbp] ; set trap frame address
  111. call KiDeliverApc ; deliver APC
  112. RESTORE_EXCEPTION_STATE ; restore exception state/deallocate
  113. ret ; return
  114. NESTED_END KiInitiateUserApc, _TEXT$00
  115. end