platformCPU.cc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #ifndef _PLATFORM_CPU_H_
  24. #include "platform/platformCPU.h"
  25. #endif
  26. #include "string/stringTable.h"
  27. TorqueSystemInfo PlatformSystemInfo;
  28. enum CPUFlags
  29. {
  30. BIT_FPU = BIT(0),
  31. BIT_RDTSC = BIT(4),
  32. BIT_MMX = BIT(23),
  33. BIT_SSE = BIT(25),
  34. BIT_3DNOW = BIT(31),
  35. };
  36. // fill the specified structure with information obtained from asm code
  37. void SetProcessorInfo(TorqueSystemInfo::Processor& pInfo,
  38. char* vendor, U32 processor, U32 properties)
  39. {
  40. PlatformSystemInfo.processor.properties |= (properties & BIT_FPU) ? CPU_PROP_FPU : 0;
  41. PlatformSystemInfo.processor.properties |= (properties & BIT_RDTSC) ? CPU_PROP_RDTSC : 0;
  42. PlatformSystemInfo.processor.properties |= (properties & BIT_MMX) ? CPU_PROP_MMX : 0;
  43. if (dStricmp(vendor, "GenuineIntel") == 0)
  44. {
  45. pInfo.properties |= (properties & BIT_SSE) ? CPU_PROP_SSE : 0;
  46. pInfo.type = CPU_Intel_Unknown;
  47. // switch on processor family code
  48. switch ((processor >> 8) & 0x0f)
  49. {
  50. case 4:
  51. pInfo.type = CPU_Intel_486;
  52. pInfo.name = StringTable->insert("Intel 486 class");
  53. break;
  54. // Pentium Family
  55. case 5:
  56. // switch on processor model code
  57. switch ((processor >> 4) & 0xf)
  58. {
  59. case 1:
  60. case 2:
  61. case 3:
  62. pInfo.type = CPU_Intel_Pentium;
  63. pInfo.name = StringTable->insert("Intel Pentium");
  64. break;
  65. case 4:
  66. pInfo.type = CPU_Intel_PentiumMMX;
  67. pInfo.name = StringTable->insert("Intel Pentium MMX");
  68. break;
  69. default:
  70. pInfo.type = CPU_Intel_Pentium;
  71. pInfo.name = StringTable->insert( "Intel (unknown, Pentium family)" );
  72. break;
  73. }
  74. break;
  75. // Pentium Pro/II/II family
  76. case 6:
  77. // switch on processor model code
  78. switch ((processor >> 4) & 0xf)
  79. {
  80. case 1:
  81. pInfo.type = CPU_Intel_PentiumPro;
  82. pInfo.name = StringTable->insert("Intel Pentium Pro");
  83. break;
  84. case 3:
  85. case 5:
  86. pInfo.type = CPU_Intel_PentiumII;
  87. pInfo.name = StringTable->insert("Intel Pentium II");
  88. break;
  89. case 6:
  90. pInfo.type = CPU_Intel_PentiumCeleron;
  91. pInfo.name = StringTable->insert("Intel Pentium Celeron");
  92. break;
  93. case 7:
  94. case 8:
  95. case 10:
  96. case 11:
  97. pInfo.type = CPU_Intel_PentiumIII;
  98. pInfo.name = StringTable->insert("Intel Pentium III");
  99. break;
  100. default:
  101. pInfo.type = CPU_Intel_PentiumPro;
  102. pInfo.name = StringTable->insert( "Intel (unknown, Pentium Pro/II/III family)" );
  103. break;
  104. }
  105. break;
  106. // Pentium4 Family
  107. case 0xf:
  108. pInfo.type = CPU_Intel_Pentium4;
  109. pInfo.name = StringTable->insert( "Intel Pentium 4" );
  110. break;
  111. default:
  112. pInfo.type = CPU_Intel_Unknown;
  113. pInfo.name = StringTable->insert( "Intel (unknown)" );
  114. break;
  115. }
  116. }
  117. //--------------------------------------
  118. else
  119. if (dStricmp(vendor, "AuthenticAMD") == 0)
  120. {
  121. // AthlonXP processors support SSE
  122. pInfo.properties |= (properties & BIT_SSE) ? CPU_PROP_SSE : 0;
  123. pInfo.properties |= (properties & BIT_3DNOW) ? CPU_PROP_3DNOW : 0;
  124. // switch on processor family code
  125. switch ((processor >> 8) & 0xf)
  126. {
  127. // K6 Family
  128. case 5:
  129. // switch on processor model code
  130. switch ((processor >> 4) & 0xf)
  131. {
  132. case 0:
  133. case 1:
  134. case 2:
  135. case 3:
  136. pInfo.type = CPU_AMD_K6_3;
  137. pInfo.name = StringTable->insert("AMD K5");
  138. break;
  139. case 4:
  140. case 5:
  141. case 6:
  142. case 7:
  143. pInfo.type = CPU_AMD_K6;
  144. pInfo.name = StringTable->insert("AMD K6");
  145. break;
  146. case 8:
  147. pInfo.type = CPU_AMD_K6_2;
  148. pInfo.name = StringTable->insert("AMD K6-2");
  149. break;
  150. case 9:
  151. case 10:
  152. case 11:
  153. case 12:
  154. case 13:
  155. case 14:
  156. case 15:
  157. pInfo.type = CPU_AMD_K6_3;
  158. pInfo.name = StringTable->insert("AMD K6-3");
  159. break;
  160. }
  161. break;
  162. // Athlon Family
  163. case 6:
  164. pInfo.type = CPU_AMD_Athlon;
  165. pInfo.name = StringTable->insert("AMD Athlon");
  166. break;
  167. default:
  168. pInfo.type = CPU_AMD_Unknown;
  169. pInfo.name = StringTable->insert("AMD (unknown)");
  170. break;
  171. }
  172. }
  173. //--------------------------------------
  174. else
  175. if (dStricmp(vendor, "CyrixInstead") == 0)
  176. {
  177. switch (processor)
  178. {
  179. case 0x520:
  180. pInfo.type = CPU_Cyrix_6x86;
  181. pInfo.name = StringTable->insert("Cyrix 6x86");
  182. break;
  183. case 0x440:
  184. pInfo.type = CPU_Cyrix_MediaGX;
  185. pInfo.name = StringTable->insert("Cyrix Media GX");
  186. break;
  187. case 0x600:
  188. pInfo.type = CPU_Cyrix_6x86MX;
  189. pInfo.name = StringTable->insert("Cyrix 6x86mx/MII");
  190. break;
  191. case 0x540:
  192. pInfo.type = CPU_Cyrix_GXm;
  193. pInfo.name = StringTable->insert("Cyrix GXm");
  194. break;
  195. default:
  196. pInfo.type = CPU_Cyrix_Unknown;
  197. pInfo.name = StringTable->insert("Cyrix (unknown)");
  198. break;
  199. }
  200. }
  201. }