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.

199 lines
4.8 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // cpuvsn.cpp
  17. // Description:
  18. // This modules contains the functions needed to set the cpu version
  19. // variable. This was based on code found in CONTROLS.C and CPUVSN.ASM
  20. // in MRV.
  21. //
  22. // Routines:
  23. //
  24. // Data:
  25. // ProcessorVersionInitialized - if initialized
  26. // MMxVersion - true if running on an MMX system
  27. // P6Version - true if running on a P6
  28. //
  29. // $Author: KLILLEVO $
  30. // $Date: 31 Oct 1996 10:12:44 $
  31. // $Archive: S:\h26x\src\common\ccpuvsn.cpv $
  32. // $Header: S:\h26x\src\common\ccpuvsn.cpv 1.5 31 Oct 1996 10:12:44 KLILLEVO $
  33. // $Log: S:\h26x\src\common\ccpuvsn.cpv $
  34. //
  35. // Rev 1.5 31 Oct 1996 10:12:44 KLILLEVO
  36. // changed from DBOUT to DBgLog
  37. //
  38. // Rev 1.4 15 Oct 1996 12:47:40 KLILLEVO
  39. // save ebx
  40. //
  41. // Rev 1.3 10 Sep 1996 14:16:44 BNICKERS
  42. // Recognize when running on Pentium Pro processor.
  43. //
  44. // Rev 1.2 29 May 1996 14:06:16 RHAZRA
  45. // Enabled CPU sensing via CPUID instruction
  46. //
  47. // Rev 1.1 27 Dec 1995 14:11:22 RMCKENZX
  48. //
  49. // Added copyright notice
  50. //
  51. // Rev 1.0 31 Jul 1995 12:55:14 DBRUCKS
  52. // rename files
  53. //
  54. // Rev 1.1 28 Jul 1995 09:26:40 CZHU
  55. //
  56. // Include typedefs.h instead of datatype.h
  57. /////////////////////////////////////////////////////////////////////////////////
  58. #include "precomp.h"
  59. extern int ProcessorVersionInitialized = {FALSE};
  60. extern int P6Version = {FALSE};
  61. extern int MMxVersion = {FALSE};
  62. #define MMX_IS_ON(edxValue) ((edxValue >> 23)&0x1) /* bit 23 */
  63. /* Static Functions
  64. */
  65. static long CPUVersion(U32 uEAX);
  66. /*****************************************************************************
  67. *
  68. * InitializeProcessorVersion
  69. *
  70. * Determine the processor version - setting the global variables
  71. *
  72. * History: 06/13/95 -BRN-
  73. * 07/27/95 -DJB- Port to H26X and turn on MMx detection
  74. */
  75. void FAR InitializeProcessorVersion (
  76. int nOn486)
  77. {
  78. I32 iVersion;
  79. FX_ENTRY("InitializeProcessorVersion")
  80. if (ProcessorVersionInitialized) {
  81. DEBUGMSG (ZONE_INIT, ("%s: ProcessorVersion already initialized\r\n", _fx_));
  82. goto done;
  83. }
  84. if (!nOn486)
  85. {
  86. iVersion = CPUVersion (0);
  87. iVersion &= 0xffff; /* Top 16-bits is part of the vendor id string */
  88. if (iVersion < 1)
  89. {
  90. P6Version = FALSE;
  91. MMxVersion = FALSE;
  92. }
  93. else
  94. {
  95. iVersion = CPUVersion (1);
  96. P6Version = (int) ((iVersion & 0xF00L) == 0x600L);
  97. MMxVersion = (int) MMX_IS_ON(iVersion);
  98. }
  99. }
  100. ProcessorVersionInitialized = TRUE;
  101. done:
  102. return;
  103. } /* end InitializeProcessorVersion() */
  104. /*****************************************************************************
  105. *
  106. * SelectProcessor
  107. *
  108. * Control the processor choice from above
  109. *
  110. * Returns 0 if success and 1 if failure
  111. *
  112. * History: 06/13/95 -BRN-
  113. * 07/27/95 -DJB- Port to H26X
  114. */
  115. DWORD SelectProcessor (DWORD dwTarget)
  116. {
  117. if (! ProcessorVersionInitialized)
  118. {
  119. ProcessorVersionInitialized = TRUE;
  120. if (dwTarget == TARGET_PROCESSOR_PENTIUM)
  121. {
  122. P6Version = FALSE;
  123. MMxVersion = FALSE;
  124. }
  125. else if (dwTarget == TARGET_PROCESSOR_P6)
  126. {
  127. P6Version = TRUE;
  128. MMxVersion = FALSE;
  129. }
  130. else if (dwTarget == TARGET_PROCESSOR_PENTIUM_MMX)
  131. {
  132. P6Version = FALSE;
  133. MMxVersion = TRUE;
  134. }
  135. else if (dwTarget == TARGET_PROCESSOR_P6_MMX)
  136. {
  137. P6Version = TRUE;
  138. MMxVersion = TRUE;
  139. }
  140. return 0;
  141. }
  142. return 1;
  143. } /* end SelectProcessor() */
  144. /*****************************************************************************
  145. *
  146. * CPUVersion
  147. *
  148. * Accesss the CPUID information
  149. *
  150. * Returns: Upper 16-bits of EDX and Lower 16-bits of EAX
  151. *
  152. *
  153. * History: 06/15/95 -BRN-
  154. * 07/27/95 -DJB- Port from MRV's CPUVSN.ASM to H26X
  155. */
  156. static long CPUVersion(U32 uEAX)
  157. {
  158. long lResult;
  159. __asm {
  160. push ebx
  161. #ifdef WIN32
  162. mov eax,uEAX
  163. #else
  164. movzx eax,sp
  165. movzx eax,ss:PW [eax+4]
  166. #endif
  167. xor ebx,ebx
  168. xor ecx,ecx
  169. xor edx,edx
  170. _emit 00FH ; CPUID instruction
  171. _emit 0A2H
  172. and edx,0FFFF0000H
  173. and eax,00000FFFFH
  174. or eax,edx
  175. mov lResult,eax
  176. pop ebx
  177. }
  178. return lResult;
  179. } /* end CPUVersion() */