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.

173 lines
3.6 KiB

  1. title "I386 PCR"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; i386pcr.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements routines for accessing and initing the pcr.
  13. ;
  14. ; Author:
  15. ;
  16. ; Bryan Willman (bryanwi) 20 Mar 90
  17. ;
  18. ; Environment:
  19. ;
  20. ; Kernel mode, early init of first processor.
  21. ;
  22. ; Revision History:
  23. ;
  24. ;--
  25. .386p
  26. .xlist
  27. include ks386.inc
  28. include callconv.inc ; calling convention macros
  29. .list
  30. ;
  31. ; NOTE - This definition of PCR gives us 2 instructions to get to some
  32. ; variables that need to be addressable in one instruction. Any
  33. ; such variable (such as current thread) must be accessed via its
  34. ; own access procedure (see below), NOT by KeGetPcr()->PbCurrentThread.
  35. ; (This is only an issue on MP machines.)
  36. ;
  37. _TEXT$00 SEGMENT DWORD PUBLIC 'CODE'
  38. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  39. ;++
  40. ;
  41. ; PKTHREAD
  42. ; KeGetCurrentThread()
  43. ;
  44. ; Return Value:
  45. ;
  46. ; Pointer to current Thread object.
  47. ;
  48. ;--
  49. cPublicProc ___KeGetCurrentThread ,0
  50. mov eax,PCR[PcPrcbData+PbCurrentThread]
  51. stdRET ___KeGetCurrentThread
  52. stdENDP ___KeGetCurrentThread
  53. ;++
  54. ;
  55. ; KPROCESSOR_MODE
  56. ; KeGetPreviousMode()
  57. ;
  58. ; Return Value:
  59. ;
  60. ; PreviousMode of current thread.
  61. ;
  62. ;--
  63. cPublicProc _KeGetPreviousMode
  64. mov eax,PCR[PcPrcbData+PbCurrentThread] ; (eax) -> Thread
  65. movzx eax,byte ptr [eax]+ThPreviousMode ; (eax) = PreviousMode
  66. stdRET _KeGetPreviousMode
  67. stdENDP _KeGetPreviousMode
  68. ;++
  69. ;
  70. ; BOOLEAN
  71. ; KeIsExecutingDpc(
  72. ; VOID
  73. ; );
  74. ;
  75. ; Return Value:
  76. ;
  77. ; Value of flag which indicates whether we're executing in DPC context
  78. ;
  79. ;--
  80. cPublicProc ___KeIsExecutingDpc ,0
  81. movzx eax, byte ptr PCR[PcPrcbData.PbDpcRoutineActive]
  82. stdRET ___KeIsExecutingDpc
  83. stdENDP ___KeIsExecutingDpc
  84. ;++
  85. ;
  86. ; VOID
  87. ; GetMachineBootPointers(
  88. ; )
  89. ;
  90. ; Routine Description:
  91. ;
  92. ; This routine is called at system startup to extract the address of
  93. ; the PCR and machine control values. It is useful only for the P0
  94. ; case where the boot loader must already init the machine before it
  95. ; turns on paging and calls us.
  96. ;
  97. ; Pcr address is extracted from the base of KGDT_R0_PCR.
  98. ;
  99. ; Gdt and Idt are extracted from the machine GDTR and IDTR.
  100. ;
  101. ; TSS is derived from the TSR and related descriptor.
  102. ;
  103. ; Arguments:
  104. ;
  105. ; None.
  106. ;
  107. ; Return Value:
  108. ;
  109. ;
  110. ; (edi) -> gdt
  111. ; (esi) -> pcr
  112. ; (edx) -> tss
  113. ; (eax) -> idt
  114. ;
  115. ;--
  116. cPublicProc GetMachineBootPointers
  117. push ebp
  118. mov ebp,esp
  119. sub esp,8
  120. sgdt fword ptr [ebp-8]
  121. mov edi,[ebp-6] ; (edi) = gdt address
  122. mov cx,fs
  123. and cx,(NOT RPL_MASK)
  124. movzx ecx,cx
  125. add ecx,edi ; (ecx) -> pcr descriptor
  126. mov dh,[ecx+KgdtBaseHi]
  127. mov dl,[ecx+KgdtBaseMid]
  128. shl edx,16
  129. mov dx,[ecx+KgdtBaseLow] ; (edx) -> pcr
  130. mov esi,edx ; (esi) -> pcr
  131. str cx
  132. movzx ecx,cx
  133. add ecx,edi ; (ecx) -> TSS descriptor
  134. mov dh,[ecx+KgdtBaseHi]
  135. mov dl,[ecx+KgdtBaseMid]
  136. shl edx,16
  137. mov dx,[ecx+KgdtBaseLow] ; (edx) -> TSS
  138. sidt fword ptr [ebp-8]
  139. mov eax,[ebp-6] ; (eax) -> Idt
  140. mov esp,ebp
  141. pop ebp
  142. stdRET GetMachineBootPointers
  143. stdENDP GetMachineBootPointers
  144. _TEXT$00 ENDS
  145. end