CPUID.ASM 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ;
  2. ; Copyright 2020 Electronic Arts Inc.
  3. ;
  4. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. ; software: you can redistribute it and/or modify it under the terms of
  6. ; the GNU General Public License as published by the Free Software Foundation,
  7. ; either version 3 of the License, or (at your option) any later version.
  8. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. ; in the hope that it will be useful, but with permitted additional restrictions
  10. ; under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. ; distributed with this program. You should have received a copy of the
  12. ; GNU General Public License along with permitted additional restrictions
  13. ; with this program. If not, see [https://github.com/electronicarts/CnC_Remastered_Collection]>.
  14. ; $Header: F:\projects\c&c0\vcs\code\cpuid.asv 5.0 11 Nov 1996 09:40:28 JOE_BOSTIC $
  15. ;***************************************************************************
  16. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S I N C **
  17. ;***************************************************************************
  18. ;* *
  19. ;* Project Name : Command & Conquer *
  20. ;* *
  21. ;* File Name : MMX.ASM *
  22. ;* *
  23. ;* Programmer : Steve Tall *
  24. ;* *
  25. ;* Start Date : May 19th, 1996 *
  26. ;* *
  27. ;* Last Update : May 19th 1996 [ST] *
  28. ;* *
  29. ;*-------------------------------------------------------------------------*
  30. ;* Functions: *
  31. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  32. .586
  33. .model flat
  34. ;
  35. ; Variables externs
  36. ;
  37. GLOBAL C CPUType:byte
  38. ;externdef C CPUType:byte
  39. GLOBAL C VendorID:byte
  40. ;externdef C VendorID:byte
  41. ;
  42. ; Function externs
  43. ;
  44. GLOBAL C Detect_MMX_Availability:near
  45. ;externdef C Detect_MMX_Availability:near
  46. .code
  47. ;*********************************************************************************************
  48. ;* Detect_MMX_Availability -- Detect the presence of MMX technology. *
  49. ;* *
  50. ;* *
  51. ;* INPUT: Nothing *
  52. ;* *
  53. ;* OUTPUT: True if MMX technology is available. *
  54. ;* *
  55. ;* Warnings: *
  56. ;* *
  57. ;* Note: Based in part on CPUID32.ASM by Intel *
  58. ;* *
  59. ;* HISTORY: *
  60. ;* 05/19/96 ST : Created. *
  61. ;*===========================================================================================*
  62. Detect_MMX_Availability proc C
  63. local idflag:byte
  64. local cputype:byte
  65. ;assume processor is at least 386
  66. ;
  67. ;check whether AC bit in eflags can be toggled.
  68. ;If not then processor is 386
  69. mov [idflag],0
  70. pushfd ;get Eflags in EAX
  71. pop eax
  72. mov ecx,eax ;save eflags
  73. xor eax,40000h ;toggle AC bit in eflags
  74. push eax ;new eflags on stack
  75. popfd ;move new value into eflags
  76. pushfd ;get new eflags back into eax
  77. pop eax
  78. xor eax,ecx ;if AC bit not toggled then CPU=386
  79. mov [cputype],3
  80. jz @@end_get_cpu ;cpu is 386
  81. push ecx
  82. popfd ;restore AC bit in eflags
  83. ;processor is at least 486
  84. ;
  85. ;Check for ability to set/clear ID flag in EFLAGS
  86. ;ID flag indicates ability of processor to execute the CPUID instruction.
  87. ;486 not guaranteed to have CPUID inst?
  88. ;
  89. mov [cputype],4
  90. mov eax,ecx ;original EFLAGS
  91. xor eax,200000h ;toggle ID bit
  92. push eax
  93. popfd
  94. pushfd
  95. pop eax
  96. xor eax,ecx ;check if still toggled
  97. jz @@end_get_cpu
  98. ; Execute CPUID instruction to determine vendor, family,
  99. ; model and stepping.
  100. ;
  101. mov [idflag],1 ;flag ID is available
  102. xor eax,eax
  103. cpuid
  104. mov dword ptr [VendorID],ebx
  105. mov dword ptr [VendorID+4],edx
  106. mov dword ptr [VendorID+8],ecx
  107. mov dword ptr [VendorID+12]," "
  108. cmp eax,1 ;check if 1 is valid
  109. jl @@end_get_cpu ;inp for cpuid inst.
  110. xor eax,eax
  111. inc eax
  112. cpuid ;get stepping, model and family
  113. and ax,0f00H
  114. shr ax,08H
  115. mov [cputype],al
  116. @@end_get_cpu: mov al,[cputype]
  117. mov [CPUType],al
  118. ;
  119. ; We have the CPU type in al now.
  120. ; If we arent on at least a pentium then we can assume there is no MMX
  121. ;
  122. cmp al,5
  123. jl @@no_mmx
  124. mov eax,1
  125. cpuid
  126. test edx,00800000h
  127. jz @@no_mmx
  128. ;
  129. ; MMX detected - return true
  130. ;
  131. mov eax,1
  132. ret
  133. @@no_mmx: xor eax,eax
  134. ret
  135. Detect_MMX_Availability endp
  136. .data
  137. CPUType db 0
  138. VendorID db "Not available",0,0,0,0,0,0
  139. end