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.

202 lines
5.0 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * OS information
  8. *
  9. * Abstract:
  10. *
  11. * Describes the OS that is running
  12. *
  13. * Revision History:
  14. *
  15. * 05/13/1999 davidx
  16. * Created it.
  17. * 09/08/1999 agodfrey
  18. * Moved to Runtime\OSInfo.cpp
  19. *
  20. \**************************************************************************/
  21. #include "precomp.hpp"
  22. namespace GpRuntime {
  23. DWORD OSInfo::VAllocChunk;
  24. DWORD OSInfo::PageSize;
  25. DWORD OSInfo::MajorVersion;
  26. DWORD OSInfo::MinorVersion;
  27. BOOL OSInfo::IsNT;
  28. BOOL OSInfo::HasMMX;
  29. BOOL DetectMMXProcessor();
  30. }
  31. #ifdef _X86_
  32. /**************************************************************************\
  33. *
  34. * Function Description:
  35. *
  36. * Detect whether the processor supports MMX
  37. *
  38. * Arguments:
  39. *
  40. * NONE
  41. *
  42. * Return Value:
  43. *
  44. * TRUE if the processor supports MMX
  45. * FALSE otherwise
  46. *
  47. \**************************************************************************/
  48. BOOL
  49. GpRuntime::DetectMMXProcessor()
  50. {
  51. // NT 4.0 and up provide an API to check for MMX support; this handles
  52. // floating-point emulation as well. We cannot implicitly reference this
  53. // function because it's not exported by Windows 95 or NT < 4.0, so we
  54. // must use GetProcAddress. Windows 98 and up do export the function, but
  55. // it's stubbed, so we must also do an OS version check:
  56. typedef BOOL (WINAPI *ISPROCESSORFEATUREPRESENTFUNCTION)(DWORD);
  57. ISPROCESSORFEATUREPRESENTFUNCTION IsProcessorFeaturePresentFunction = NULL;
  58. if ((OSInfo::IsNT) && (OSInfo::MajorVersion >= 4))
  59. {
  60. // LoadLibrary is not required since we're implicitly dependent on
  61. // kernel32.dll, so just use GetModuleHandle:
  62. HMODULE kernel32Handle = GetModuleHandle(TEXT("kernel32.dll"));
  63. if (kernel32Handle != NULL)
  64. {
  65. IsProcessorFeaturePresentFunction =
  66. (ISPROCESSORFEATUREPRESENTFUNCTION) GetProcAddress(
  67. kernel32Handle, "IsProcessorFeaturePresent");
  68. }
  69. }
  70. BOOL hasMMX;
  71. if (IsProcessorFeaturePresentFunction != NULL)
  72. {
  73. hasMMX =
  74. IsProcessorFeaturePresentFunction(PF_MMX_INSTRUCTIONS_AVAILABLE);
  75. }
  76. else
  77. {
  78. hasMMX = FALSE;
  79. // IsProcessorFeaturePresent is unsupported on this OS, so we'll use
  80. // CPUID to check for MMX support.
  81. //
  82. // If CPUID is unsupported on this processor, we'll take the
  83. // exception. This will happen on most processors < Pentium, however
  84. // some 486 processors support CPUID.
  85. WARNING(("Executing processor detection; "
  86. "benign first-change exception possible."));
  87. __try
  88. {
  89. DWORD features;
  90. // Get processor features using CPUID function 1:
  91. __asm
  92. {
  93. push eax
  94. push ebx
  95. push ecx
  96. push edx
  97. mov eax, 1
  98. cpuid
  99. mov features, edx
  100. pop edx
  101. pop ecx
  102. pop ebx
  103. pop eax
  104. }
  105. // If bit 23 is set, MMX technology is supported by this
  106. // processor, otherwise MMX is unsupported:
  107. if (features & (1 << 23))
  108. {
  109. // Try executing an MMX instruction to make sure
  110. // floating-point emulation is not on:
  111. __asm emms
  112. // If we made it this far, then MMX is available:
  113. hasMMX = TRUE;
  114. }
  115. }
  116. __except(EXCEPTION_EXECUTE_HANDLER)
  117. {
  118. // We should only be here if (1) the processor does not support
  119. // CPUID or (2) CPUID is supported, but floating-point emulation
  120. // is enabled.
  121. }
  122. }
  123. return hasMMX;
  124. }
  125. #else // !_X86_
  126. #define DetectMMXProcessor() FALSE
  127. #endif // !_X86_
  128. /**************************************************************************\
  129. *
  130. * Function Description:
  131. *
  132. * Static initialization function for OSInfo class.
  133. * Called by GpRuntime::Initialize()
  134. *
  135. * Arguments:
  136. *
  137. * NONE
  138. *
  139. * Return Value:
  140. *
  141. * NONE
  142. *
  143. \**************************************************************************/
  144. VOID
  145. GpRuntime::OSInfo::Initialize()
  146. {
  147. // Get VM information
  148. SYSTEM_INFO sysinfo;
  149. GetSystemInfo(&sysinfo);
  150. VAllocChunk = sysinfo.dwAllocationGranularity;
  151. PageSize = sysinfo.dwPageSize;
  152. // Get operating system version information
  153. OSVERSIONINFOA osver;
  154. osver.dwOSVersionInfoSize = sizeof(osver);
  155. if (GetVersionExA(&osver))
  156. {
  157. IsNT = (osver.dwPlatformId == VER_PLATFORM_WIN32_NT);
  158. MajorVersion = osver.dwMajorVersion;
  159. MinorVersion = osver.dwMinorVersion;
  160. }
  161. // Check to see if MMX is available
  162. HasMMX = DetectMMXProcessor();
  163. }