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.

136 lines
3.2 KiB

  1. title "CPUID support functions"
  2. ;++
  3. ;
  4. ; Copyright (c) 1999 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; cpuidsup.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; Implements functions to detect whether or not the CPUID instruction
  13. ; is supported on this processor and to provide a simple method to use
  14. ; CPUID from a C program.
  15. ;
  16. ; Author:
  17. ;
  18. ; Peter Johnston (peterj) July 14, 1999
  19. ;
  20. ; Environment:
  21. ;
  22. ; Any mode.
  23. ;
  24. ; Revision History:
  25. ;
  26. ;--
  27. .586p
  28. .xlist
  29. include ks386.inc
  30. include callconv.inc ; calling convention macros
  31. .list
  32. _TEXT$01 SEGMENT DWORD PUBLIC 'CODE'
  33. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  34. page
  35. subttl "IsCpuidPresent"
  36. ;++
  37. ;
  38. ; BOOLEAN
  39. ; IsCpuidPresent(
  40. ; VOID
  41. ; )
  42. ;
  43. ; Routine Description:
  44. ;
  45. ; If bit 21 of the EFLAGS register is writable, CPUID is supported on
  46. ; this processor. If not writable, CPUID is not supported.
  47. ;
  48. ; Note: It is expected that this routine is "locked" onto a single
  49. ; processor when run.
  50. ;
  51. ; Arguments:
  52. ;
  53. ; None.
  54. ;
  55. ; Return Value:
  56. ;
  57. ; TRUE if CPUID is supported,
  58. ; FALSE otherwise.
  59. ;
  60. ;--
  61. EFLAGS_ID equ 200000h ; bit 21
  62. cPublicProc _IsCpuidPresent ,0
  63. pushfd ; save EFLAGS
  64. pop ecx ; get current value
  65. xor ecx, EFLAGS_ID ; flip bit 21
  66. push ecx ; set flipped value in EFLAGS
  67. popfd
  68. pushfd ; read it back again
  69. pop eax
  70. xor eax, ecx ; if new value is what we set
  71. shr eax, 21 ; then these two are the same
  72. and eax, 1 ; isolate bit 21 (in bit 0)
  73. xor eax, 1 ; and flip it
  74. stdRET _IsCpuidPresent
  75. stdENDP _IsCpuidPresent
  76. page
  77. subttl "ExecuteCpuidFunction"
  78. ;++
  79. ;
  80. ; VOID
  81. ; ExecuteCpuidFunction(
  82. ; ULONG Function,
  83. ; PULONG Results
  84. ; )
  85. ;
  86. ; Routine Description:
  87. ;
  88. ; Execute the CPUID instruction, using the Function handed in and
  89. ; return the 4 DWORD result.
  90. ;
  91. ; Note: It is expected that this routine is "locked" onto a single
  92. ; processor when run.
  93. ;
  94. ; Arguments:
  95. ;
  96. ; Function Integer function number to be the input argument for
  97. ; the CPUID instruction.
  98. ; Results Pointer to the 4 DWORD array where the results are to
  99. ; be returned.
  100. ;
  101. ; Return Value:
  102. ;
  103. ; None.
  104. ;
  105. ;--
  106. cPublicProc _ExecuteCpuidFunction ,2
  107. mov eax, [esp+4] ; set CPUID function
  108. push esi ; save esi
  109. mov esi, [esp+12] ; get Results address
  110. push ebx ; save ebx
  111. cpuid ; execute
  112. mov [esi+0], eax ; eax -> Results[0]
  113. mov [esi+4], ebx ; ebx -> Results[1]
  114. mov [esi+8], ecx ; ecx -> Results[2]
  115. mov [esi+12], edx ; edx -> Results[3]
  116. pop ebx ; restore ebx, esi
  117. pop esi
  118. stdRET _ExecuteCpuidFunction
  119. stdENDP _ExecuteCpuidFunction
  120. _TEXT$01 ends
  121. end