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.

101 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation. All Rights Reserved.
  3. Module Name:
  4. msr.c
  5. Abstract:
  6. This module contains global variables used to access x86 processor model specific registers
  7. related to performance counters, as well as a function for writing to x86 model specific registers.
  8. Author:
  9. Joseph Ballantyne
  10. Environment:
  11. Kernel Mode
  12. Revision History:
  13. --*/
  14. #include "common.h"
  15. #include "msr.h"
  16. #pragma LOCKED_DATA
  17. // These variables are used when programming performance counter MSRs.
  18. // The default values are for Intel PII/PIII/Celeron processors.
  19. ULONG PerformanceCounter0=INTELPERFORMANCECOUNTER0;
  20. ULONG PerformanceCounter1=INTELPERFORMANCECOUNTER1;
  21. ULONG EventSelect0=INTELEVENTSELECT0;
  22. ULONG EventSelect1=INTELEVENTSELECT1;
  23. ULONGLONG PerformanceCounterMask=INTELPERFCOUNTMASK;
  24. ULONG StopCounter=PERFCOUNTERENABLED;
  25. ULONG StartCycleCounter=STARTPERFCOUNTERS|INTELCOUNTCYCLES;
  26. ULONG StartInstructionCounter=STARTPERFCOUNTERS|INTELCOUNTINSTRUCTIONS;
  27. ULONG StartInterruptsDisabledCounter=STARTPERFCOUNTERS|INTELINTSDISABLEDWHILEPENDING;
  28. ULONG EnablePerfCounters=0;
  29. #pragma PAGEABLE_DATA
  30. #pragma LOCKED_CODE
  31. // We disable stack frames so that our direct accessing of parameters based
  32. // off of the stack pointer works properly.
  33. #pragma optimize("y", on)
  34. VOID
  35. __fastcall
  36. WriteIntelMSR (
  37. ULONG index,
  38. ULONGLONG value
  39. )
  40. /*++
  41. Routine Description:
  42. Writes the 64 bit data in value to the processor model specific register selected
  43. by index.
  44. Arguments:
  45. index - Supplies the index of the model specific register (MSR) to be written.
  46. Note that writing to an unsupported MSR will cause a GP (general protection)
  47. fault.
  48. value - Supplies the 64 bit data to write into the specified MSR.
  49. Return Value:
  50. None.
  51. --*/
  52. {
  53. __asm {
  54. mov eax, [esp + 0x4]
  55. mov edx, [esp + 0x8]
  56. wrmsr
  57. }
  58. }
  59. #pragma optimize("", on)
  60. #pragma PAGEABLE_CODE