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