flush out windows cpu detection.

This commit is contained in:
Jeff Hutchinson 2021-09-26 23:43:06 -04:00
parent ca0a5d41a7
commit 24e5db942b
5 changed files with 136 additions and 248 deletions

View file

@ -70,17 +70,16 @@ enum ProcessorProperties
CPU_PROP_MMX = (1<<2), ///< Supports MMX instruction set extension.
CPU_PROP_3DNOW = (1<<3), ///< Supports AMD 3dNow! instruction set extension.
CPU_PROP_SSE = (1<<4), ///< Supports SSE instruction set extension.
CPU_PROP_RDTSC = (1<<5), ///< Supports Read Time Stamp Counter op.
CPU_PROP_SSE2 = (1<<6), ///< Supports SSE2 instruction set extension.
CPU_PROP_SSE3 = (1<<7), ///< Supports SSE3 instruction set extension.
CPU_PROP_SSE3ex = (1<<8), ///< Supports extended SSE3 instruction set
CPU_PROP_SSE4_1 = (1<<9), ///< Supports SSE4_1 instruction set extension.
CPU_PROP_SSE4_2 = (1<<10), ///< Supports SSE4_2 instruction set extension.
CPU_PROP_AVX = (1<<11), ///< Supports AVX256 instruction set extension.
CPU_PROP_MP = (1<<12), ///< This is a multi-processor system.
CPU_PROP_LE = (1<<13), ///< This processor is LITTLE ENDIAN.
CPU_PROP_64bit = (1<<14), ///< This processor is 64-bit capable
CPU_PROP_NEON = (1<<15), ///< Supports the Arm Neon instruction set extension.
CPU_PROP_SSE2 = (1<<5), ///< Supports SSE2 instruction set extension.
CPU_PROP_SSE3 = (1<<6), ///< Supports SSE3 instruction set extension.
CPU_PROP_SSE3ex = (1<<7), ///< Supports Supplemental SSE3 instruction set
CPU_PROP_SSE4_1 = (1<<8), ///< Supports SSE4_1 instruction set extension.
CPU_PROP_SSE4_2 = (1<<9), ///< Supports SSE4_2 instruction set extension.
CPU_PROP_AVX = (1<<10), ///< Supports AVX256 instruction set extension.
CPU_PROP_MP = (1<<11), ///< This is a multi-processor system.
CPU_PROP_LE = (1<<12), ///< This processor is LITTLE ENDIAN.
CPU_PROP_64bit = (1<<13), ///< This processor is 64-bit capable
CPU_PROP_NEON = (1<<14), ///< Supports the Arm Neon instruction set extension.
};
/// Processor info manager.

View file

@ -1,128 +0,0 @@
;-----------------------------------------------------------------------------
; Copyright (c) 2012 GarageGames, LLC
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to
; deal in the Software without restriction, including without limitation the
; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
; sell copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
; IN THE SOFTWARE.
;-----------------------------------------------------------------------------
segment .text
; syntax: export_fn <function name>
%macro export_fn 1
%ifidn __OUTPUT_FORMAT__, elf
; No underscore needed for ELF object files
global %1
%1:
%else
global _%1
_%1:
%endif
%endmacro
; push registers
%macro pushreg 0
; pushad
push ebx
push ebp
push esi
push edi
%endmacro
; pop registers
%macro popreg 0
pop edi
pop esi
pop ebp
pop ebx
; popad
%endmacro
; void detectX86CPUInfo(char *vendor, U32 *processor, U32 *properties);
export_fn detectX86CPUInfo
push ebp
mov ebp, esp
pushreg
push edx
push ecx
pushfd
pushfd ; save EFLAGS to stack
pop eax ; move EFLAGS into EAX
mov ebx, eax
xor eax, 0x200000 ; flip bit 21
push eax
popfd ; restore EFLAGS
pushfd
pop eax
cmp eax, ebx
jz EXIT ; doesn't support CPUID instruction
;
; get vendor information using CPUID eax == 0
xor eax, eax
cpuid
; store the vendor tag (12 bytes in ebx, edx, ecx) in the first parameter,
; which should be a char[13]
push eax ; save eax
mov eax, [ebp+8] ; store the char* address in eax
mov [eax], ebx ; move ebx into the first 4 bytes
add eax, 4 ; advance the char* 4 bytes
mov [eax], edx ; move edx into the next 4 bytes
add eax, 4 ; advance the char* 4 bytes
mov [eax], ecx ; move ecx into the last 4 bytes
pop eax ; restore eax
; get generic extended CPUID info
mov eax, 1
cpuid ; eax=1, so cpuid queries feature information
and eax, 0x0fff3fff
push ecx
mov ecx, [ebp+12]
mov [ecx], eax ; just store the model bits in processor param
mov ecx, [ebp+16]
mov [ecx], edx ; set properties param
pop ecx
; want to check for 3DNow(tm).
; need to see if extended cpuid functions present.
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
jbe MAYBE_3DLATER
mov eax, 0x80000001
cpuid
; 3DNow if bit 31 set -> put bit in our properties
and edx, 0x80000000
push eax
mov eax, [ebp+16]
or [eax], edx
pop eax
MAYBE_3DLATER:
EXIT:
popfd
pop ecx
pop edx
popreg
pop ebp
ret