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.

186 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. sel.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Ramon J San Andres (ramonsa) 5-Nov-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #include "i386.h"
  15. #pragma hdrstop
  16. DECLARE_API( sel )
  17. /*++
  18. Routine Description:
  19. Dumps a selector (or range of selectors) from the GDT or LDT and displays
  20. relevant information about that selector.
  21. Arguments:
  22. arg - Supplies the selector to examine. If this is NULL, it dumps a
  23. range of selectors.
  24. Return Value:
  25. None
  26. --*/
  27. {
  28. DESCRIPTOR_TABLE_ENTRY_X86 Entry;
  29. static ULONG StartSelector=8;
  30. static ULONG EndSelector;
  31. NTSTATUS Result;
  32. ULONG dwProcessor=0;
  33. if (!GetCurrentProcessor(Client, &dwProcessor, NULL)) {
  34. dwProcessor = 0;
  35. }
  36. if (*args != '\0') {
  37. Entry.Selector = (ULONG) GetExpression(args);
  38. StartSelector=EndSelector=Entry.Selector;
  39. } else {
  40. EndSelector=StartSelector+0x80;
  41. Entry.Selector=StartSelector;
  42. }
  43. do {
  44. Result=LookupSelector((USHORT)dwProcessor,&Entry);
  45. dprintf("%04x ",(USHORT)Entry.Selector);
  46. if (Result == STATUS_SUCCESS) {
  47. dprintf("Bas=%08lx ", (ULONG)Entry.Descriptor.BaseLow +
  48. ((ULONG)Entry.Descriptor.HighWord.Bytes.BaseMid << 16) +
  49. ((ULONG)Entry.Descriptor.HighWord.Bytes.BaseHi << 24) );
  50. dprintf("Lim=%08lx ", (ULONG)Entry.Descriptor.LimitLow +
  51. (ULONG)(Entry.Descriptor.HighWord.Bits.LimitHi << 16) );
  52. dprintf((Entry.Descriptor.HighWord.Bits.Granularity) ? "Pages" : "Bytes");
  53. dprintf(" DPL=%i ",Entry.Descriptor.HighWord.Bits.Dpl);
  54. dprintf((Entry.Descriptor.HighWord.Bits.Pres) ? " P " : "NP ");
  55. if (Entry.Descriptor.HighWord.Bits.Type & 0x10) {
  56. //
  57. // Code or Data segment descriptor
  58. //
  59. if (Entry.Descriptor.HighWord.Bits.Type & 0x8) {
  60. //
  61. // Code segment descriptor
  62. //
  63. dprintf("Code ");
  64. if (Entry.Descriptor.HighWord.Bits.Type & 0x2) {
  65. //
  66. // Read/Execute
  67. //
  68. dprintf("RE ");
  69. } else {
  70. dprintf("EO ");
  71. }
  72. } else {
  73. //
  74. // Data segment descriptor
  75. //
  76. dprintf("Data ");
  77. if (Entry.Descriptor.HighWord.Bits.Type & 0x2) {
  78. //
  79. // Read/Write
  80. //
  81. dprintf("RW ");
  82. } else {
  83. dprintf("RO ");
  84. }
  85. }
  86. if (Entry.Descriptor.HighWord.Bits.Type & 0x1) {
  87. //
  88. // Accessed
  89. //
  90. dprintf("A ");
  91. }
  92. } else {
  93. //
  94. // System Segment or Gate Descriptor
  95. //
  96. switch (Entry.Descriptor.HighWord.Bits.Type) {
  97. case 2:
  98. //
  99. // LDT
  100. //
  101. dprintf("LDT ");
  102. break;
  103. case 1:
  104. case 3:
  105. case 9:
  106. case 0xB:
  107. //
  108. // TSS
  109. //
  110. if (Entry.Descriptor.HighWord.Bits.Type & 0x8) {
  111. dprintf("TSS32 ");
  112. } else {
  113. dprintf("TSS16 ");
  114. }
  115. if (Entry.Descriptor.HighWord.Bits.Type & 0x2) {
  116. dprintf("B ");
  117. } else {
  118. dprintf("A ");
  119. }
  120. break;
  121. case 4:
  122. dprintf("C-GATE16 ");
  123. break;
  124. case 5:
  125. dprintf("TSK-GATE ");
  126. break;
  127. case 6:
  128. dprintf("I-GATE16 ");
  129. break;
  130. case 7:
  131. dprintf("TRP-GATE16 ");
  132. break;
  133. case 0xC:
  134. dprintf("C-GATE32 ");
  135. break;
  136. case 0xF:
  137. dprintf("T-GATE32 ");
  138. break;
  139. }
  140. }
  141. dprintf("\n");
  142. } else {
  143. if (Result == STATUS_UNSUCCESSFUL) {
  144. dprintf("LDT page is invalid\n");
  145. } else {
  146. dprintf("Selector is invalid\n");
  147. }
  148. }
  149. Entry.Selector += 8;
  150. } while ( Entry.Selector < EndSelector );
  151. StartSelector = EndSelector;
  152. return S_OK;
  153. }