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.

164 lines
3.7 KiB

  1. title "Ldt Support 2 - Low Level"
  2. ;++
  3. ;
  4. ; Copyright (c) 1991 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; ldtsup2.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements procedures to load a new ldt and to flush
  13. ; segment descriptors.
  14. ;
  15. ; Author:
  16. ;
  17. ; Bryan M. Willman (bryanwi) 14-May-1991
  18. ;
  19. ; Environment:
  20. ;
  21. ; Kernel mode only.
  22. ;
  23. ; Revision History:
  24. ;
  25. ;--
  26. .386p
  27. .xlist
  28. include ks386.inc
  29. include i386\kimacro.inc
  30. include mac386.inc
  31. include callconv.inc
  32. .list
  33. _TEXT$00 SEGMENT DWORD PUBLIC 'CODE'
  34. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  35. ;++
  36. ;
  37. ; VOID
  38. ; KiLoadLdtr(
  39. ; VOID
  40. ; )
  41. ;
  42. ; Routine Description:
  43. ;
  44. ; This routine copies the Ldt descriptor image out of the currently
  45. ; executing process object into the Ldt descriptor, and reloads the
  46. ; the Ldt descriptor into the Ldtr. The effect of this is to provide
  47. ; a new Ldt.
  48. ;
  49. ; If the Ldt descriptor image has a base or limit of 0, then NULL will
  50. ; be loaded into the Ldtr, and no copy to the Gdt will be done.
  51. ;
  52. ; Arguments:
  53. ;
  54. ; None.
  55. ;
  56. ; Return Value:
  57. ;
  58. ; None.
  59. ;
  60. ;--
  61. cPublicProc _KiLoadLdtr, 0
  62. push esi
  63. push edi
  64. mov eax,fs:PcPrcbData+PbCurrentThread ; (eax)->CurrentThread
  65. mov eax,[eax]+(ThApcState+AsProcess) ; (eax)->CurrentProcess
  66. lea esi,[eax]+PrLdtDescriptor ; (esi)->Ldt value
  67. xor dx,dx ; assume null value
  68. cmp word ptr [esi],0 ; limit == 0?
  69. jz kill10 ; yes limit 0, go load null
  70. ;
  71. ; We have a non-null Ldt Descriptor, copy it into the Gdt
  72. ;
  73. mov edi,fs:PcGdt
  74. add edi,KGDT_LDT ; (edi)->Ldt descriptor
  75. movsd
  76. movsd ; descrip. now matches value
  77. mov dx,KGDT_LDT
  78. kill10: lldt dx
  79. pop edi
  80. pop esi
  81. stdCall _KiFlushDescriptors
  82. stdRET _KiLoadLdtr
  83. stdENDP _KiLoadLdtr
  84. ;++
  85. ;
  86. ; VOID
  87. ; KiFlushDescriptors(
  88. ; VOID
  89. ; )
  90. ;
  91. ; Routine Description:
  92. ;
  93. ; Flush the in-processor descriptor registers for the segment registers.
  94. ; We do this by reloading each segment register.
  95. ;
  96. ; N.B.
  97. ;
  98. ; This procedure is only intended to support Ldt operations.
  99. ; It does not support operations on the Gdt. In particular,
  100. ; neither it nor Ke386SetDescriptorProcess are appropriate for
  101. ; editing descriptors used by 16bit kernel code (i.e. ABIOS.)
  102. ;
  103. ; Since we are in kernel mode, we know that CS and SS do NOT
  104. ; contain Ldt selectors, any such selectors will be save/restored
  105. ; by the interrupt that brought us here from user space.
  106. ;
  107. ; Since we are in kernel mode, DS must contain a flat GDT descriptor,
  108. ; since all entry sequences would have forced a reference to it.
  109. ;
  110. ; Since we are in kernel mode, FS points to the PCR, since all
  111. ; entry sequences force it to.
  112. ;
  113. ; Therefore, only ES and GS need to be flushed.
  114. ;
  115. ; Since no inline kernel code ever uses GS, we know it will be
  116. ; restored from a frame of some caller, or nobody cares. Therefore,
  117. ; we load null into GS. (Fastest possible load.)
  118. ;
  119. ; ES is restored to KGDT_R3_DATA, because kernel exit will not restore
  120. ; it for us. If we do not put the correct value in ES, we may wind
  121. ; up with zero in ES in user mode.
  122. ;
  123. ; Arguments:
  124. ;
  125. ; None.
  126. ;
  127. ; Return Value:
  128. ;
  129. ; None.
  130. ;
  131. ;--
  132. cPublicProc _KiFlushDescriptors ,0
  133. xor ax,ax
  134. mov gs,ax
  135. push ds
  136. pop es
  137. stdRET _KiFlushDescriptors
  138. stdENDP _KiFlushDescriptors
  139. _TEXT$00 ends
  140. end
  141.