CPUID.ASM 5.5 KB

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