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.

270 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation. All Rights Reserved.
  3. Module Name:
  4. msr.h
  5. Abstract:
  6. This module contains private x86 processor model specific register defines, variables, inline
  7. functions and prototypes. The model specific registers supported are those related to
  8. the processor performance counters and local apic for Intel PII/PIII, AMD K7, and Intel P4
  9. processors.
  10. Author:
  11. Joseph Ballantyne
  12. Environment:
  13. Kernel Mode
  14. Revision History:
  15. --*/
  16. // Model Specific Register locations
  17. // This is the offset for the MSR which can be used to program the local APIC
  18. // base address, as well as for turning the local APIC on and off.
  19. #define APICBASE 0x1b
  20. // Performance counter Model Specific Register offsets (for the Intel Pentium II/III)
  21. #define INTELPERFORMANCECOUNTER0 0xc1
  22. #define INTELPERFORMANCECOUNTER1 0xc2
  23. #define INTELEVENTSELECT0 0x186
  24. #define INTELEVENTSELECT1 0x187
  25. // This is a bit mask which defines which bits can actually be read from
  26. // the performance counters. For Intel that is the bottom 40 bits.
  27. #define INTELPERFCOUNTMASK 0x000000ffffffffff
  28. // These are event codes used to make the performance counters count cycles
  29. // and instructions on Intel PII/PIII processors.
  30. #define INTELCOUNTCYCLES 0x79
  31. #define INTELCOUNTINSTRUCTIONS 0xc0
  32. #define INTELINTSDISABLED 0xc6
  33. #define INTELINTSDISABLEDWHILEPENDING 0xc7
  34. // These are values used to start and stop the Intel PII/PIII performance counters.
  35. // Note that we leave performance counter 1 enabled for counting on Intel
  36. // PII/PIII processors.
  37. #define STARTPERFCOUNTERS 0x00570000
  38. #define PERFCOUNTERENABLED 0x00400000
  39. // Performance counter Model Specific Register offsets for the Intel P4 Processor.
  40. // Note that this is NOT all of the locations, just those for the first 2 counters.
  41. // There are other additional counters but their locations are not yet defined here.
  42. // The structure and programming of the perf counters on the P4 is quite different
  43. // from earlier Intel processors.
  44. #define WILLAMETTEPERFCOUNTER0 0x300
  45. #define WILLAMETTEPERFCOUNTER1 0x301
  46. #define WILLAMETTEESCR0 0x3c8
  47. #define WILLAMETTEESCR1 0x3c9
  48. #define WILLAMETTECCR0 0x360
  49. #define WILLAMETTECCR1 0x361
  50. // These are event codes used to make the performance counters count cycles
  51. // and instructions on Intel P4 processors.
  52. #define WILLAMETTECOUNTCYCLES 0x04ffa000
  53. #define WILLAMETTECOUNTINSTRUCTIONS 0xc0
  54. // These are values used to start and stop the P4 performance counters.
  55. #define WILLAMETTESTOPPERFCOUNTER 0x80000000
  56. #define WILLAMETTESTARTPERFCOUNTERS 0x00001000
  57. // Performance counter Model Specific Register offsets (for the AMD K7)
  58. // AMD supports 4 different performance counters. All of the MSR locations
  59. // are defined here.
  60. #define AMDPERFORMANCECOUNTER0 0xc0010004
  61. #define AMDPERFORMANCECOUNTER1 0xc0010005
  62. #define AMDPERFORMANCECOUNTER2 0xc0010006
  63. #define AMDPERFORMANCECOUNTER3 0xc0010007
  64. #define AMDEVENTSELECT0 0xc0010000
  65. #define AMDEVENTSELECT1 0xc0010001
  66. #define AMDEVENTSELECT2 0xc0010002
  67. #define AMDEVENTSELECT3 0xc0010003
  68. // This is a bit mask which defines which bits can actually be read from
  69. // the performance counters. For AMD that is the bottom 48 bits.
  70. #define AMDPERFCOUNTMASK 0x0000ffffffffffff
  71. // These are event codes used to make the performance counters count cycles
  72. // and instructions on AMD processors.
  73. #define AMDCOUNTCYCLES 0x76
  74. #define AMDCOUNTINSTRUCTIONS 0xc0
  75. #define AMDINTSDISABLED 0xc6
  76. #define AMDINTSDISABLEDWHILEPENDING 0xc7
  77. // These are values used to start and stop the AMD K7 performance counters.
  78. #define AMDSTOPPERFCOUNTER 0
  79. #define AMDSTARTPERFCOUNTERS 0x00530000
  80. // The following defines have been mapped to variables, so that we can properly support
  81. // the different processors. The above MSR defined locations and programming values
  82. // are loaded into these variables at initialization according to the processor
  83. // type, and these defines are used from then on for programming the MSRs.
  84. #define PERFORMANCECOUNTER0 PerformanceCounter0
  85. #define PERFORMANCECOUNTER1 PerformanceCounter1
  86. #define EVENTSELECT0 EventSelect0
  87. #define EVENTSELECT1 EventSelect1
  88. #define PERFCOUNTMASK PerformanceCounterMask
  89. #define STOPPERFCOUNTERS StopCounter
  90. // Define inline assembly sequences that map to instruction opcodes the inline
  91. // assembler does not know about.
  92. #define rdmsr __asm _emit 0x0f __asm _emit 0x32
  93. #define wrmsr __asm _emit 0x0f __asm _emit 0x30
  94. #define rdprf __asm _emit 0x0f __asm _emit 0x33
  95. // Global variables used to support MSRs on different processor types.
  96. // These variables are loaded at initialization with values appropriate for
  97. // the processor the code is running on.
  98. extern ULONG PerformanceCounter0;
  99. extern ULONG PerformanceCounter1;
  100. extern ULONG EventSelect0;
  101. extern ULONG EventSelect1;
  102. extern ULONGLONG PerformanceCounterMask;
  103. extern ULONG StopCounter;
  104. extern ULONG StartCycleCounter;
  105. extern ULONG StartInstructionCounter;
  106. extern ULONG StartInterruptsDisabledCounter;
  107. extern ULONG EnablePerfCounters;
  108. // Function prototype for writing model specific registers.
  109. VOID
  110. __fastcall
  111. WriteIntelMSR (
  112. ULONG index,
  113. ULONGLONG value
  114. );
  115. #pragma LOCKED_CODE
  116. #pragma warning ( disable : 4035 )
  117. // __inline
  118. // ULONGLONG
  119. // ReadIntelMSR (
  120. // ULONG index
  121. // )
  122. //
  123. //*++
  124. //
  125. // Function Description:
  126. //
  127. // Reads processor model specific register (MSR) indicated by index, and returns the 64 bit
  128. // result.
  129. //
  130. // Arguments:
  131. //
  132. // index - Supplies an index which indicates which processor Model Specific Register (MSR)
  133. // should be read. Attempting to read an unsupported register location will result
  134. // in a general protection (GP) fault.
  135. //
  136. // Return Value:
  137. //
  138. // 64 bit contents of selected model specific register.
  139. //
  140. //*--
  141. __inline
  142. ULONGLONG
  143. ReadIntelMSR (
  144. ULONG index
  145. )
  146. {
  147. __asm {
  148. mov ecx,index
  149. rdmsr
  150. }
  151. }
  152. // __inline
  153. // ULONGLONG
  154. // ReadPerformanceCounter (
  155. // ULONG index
  156. // )
  157. //
  158. //*++
  159. //
  160. // Function Description:
  161. //
  162. // Reads processor performance counter indicated by index, and returns the 64 bit
  163. // result.
  164. //
  165. // Arguments:
  166. //
  167. // index - Supplies a zero based index which indicates which processor performance
  168. // counter should be read. For PII/PIII processors this index can be 0 or 1.
  169. // For AMD K7 processors this index can be 0 - 3.
  170. //
  171. // Return Value:
  172. //
  173. // 64 bit contents of selected performance counter.
  174. //
  175. //*--
  176. __inline
  177. ULONGLONG
  178. ReadPerformanceCounter (
  179. ULONG index
  180. )
  181. {
  182. __asm {
  183. mov ecx,index
  184. rdprf
  185. }
  186. }
  187. #pragma warning ( default : 4035 )
  188. #pragma PAGEABLE_CODE