forked from 0ad/0ad
Replaces architecture-dependent cpuid function with inline GCC assembly. Should fix #670 by eliminating nasm dependency.
This was SVN commit r9891.
This commit is contained in:
parent
f9d7c1246d
commit
153357f640
@ -1,12 +0,0 @@
|
|||||||
%ifdef OS_UNIX
|
|
||||||
%define arg0 rdi
|
|
||||||
%define arg1 rsi
|
|
||||||
%define arg2 rdx
|
|
||||||
%define arg3 rcx
|
|
||||||
%else
|
|
||||||
%define arg0 rcx
|
|
||||||
%define arg1 rdx
|
|
||||||
%define arg2 r8
|
|
||||||
%define arg3 r9
|
|
||||||
%endif
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
; Copyright (c) 2010 Wildfire Games
|
|
||||||
;
|
|
||||||
; 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.
|
|
||||||
|
|
||||||
; For the sym() macro
|
|
||||||
%include "../ia32/ia32.inc"
|
|
||||||
; For arg0..3
|
|
||||||
%include "amd64_abi.inc"
|
|
||||||
|
|
||||||
BITS 64
|
|
||||||
|
|
||||||
; extern "C" void CALL_CONV amd64_asm_cpuid(x86_x64_CpuidRegs* reg);
|
|
||||||
; reference: http://softwarecommunity.intel.com/articles/eng/2669.htm
|
|
||||||
global sym(amd64_asm_cpuid)
|
|
||||||
ALIGN 8
|
|
||||||
sym(amd64_asm_cpuid):
|
|
||||||
push rbx ; rbx is the only caller-save register we clobber
|
|
||||||
|
|
||||||
mov r8, arg0
|
|
||||||
mov eax, DWORD [r8+0]
|
|
||||||
mov ecx, DWORD [r8+8]
|
|
||||||
cpuid
|
|
||||||
mov DWORD [r8+0], eax
|
|
||||||
mov DWORD [r8+4], ebx
|
|
||||||
mov DWORD [r8+8], ecx
|
|
||||||
mov DWORD [r8+12], edx
|
|
||||||
|
|
||||||
pop rbx
|
|
||||||
|
|
||||||
ret
|
|
||||||
ALIGN 8
|
|
@ -1,41 +0,0 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* interface to various AMD64 functions (written in asm)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INCLUDED_AMD64_ASM
|
|
||||||
#define INCLUDED_AMD64_ASM
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct x86_x64_CpuidRegs;
|
|
||||||
extern void CALL_CONV amd64_asm_cpuid(x86_x64_CpuidRegs* reg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef INCLUDED_AMD64_ASM
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
/* Copyright (c) 2011 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include "lib/sysdep/cpu.h"
|
#include "lib/sysdep/cpu.h"
|
||||||
#include "lib/sysdep/arch/ia32/ia32.h"
|
#include "lib/sysdep/arch/ia32/ia32.h"
|
||||||
#include "lib/sysdep/arch/ia32/ia32_asm.h"
|
|
||||||
|
|
||||||
#if MSC_VERSION
|
#if MSC_VERSION
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
; disable executable stack
|
|
||||||
%ifidn __OUTPUT_FORMAT__,elf
|
|
||||||
section .note.GNU-stack noalloc noexec nowrite progbits
|
|
||||||
%endif
|
|
||||||
%ifidn __OUTPUT_FORMAT__,elf64
|
|
||||||
section .note.GNU-stack noalloc noexec nowrite progbits
|
|
||||||
%endif
|
|
||||||
|
|
||||||
; set section attributes
|
|
||||||
; section .data data align=32 use32
|
|
||||||
; section .bss bss align=16 use32
|
|
||||||
; section .text code align=64 use32
|
|
||||||
; activate .text (needs to be separate because __SECT__ will otherwise
|
|
||||||
; complain that the above definition is redeclaring attributes)
|
|
||||||
section .text
|
|
||||||
|
|
||||||
; Usage:
|
|
||||||
; use sym(ia32_cap) instead of _ia32_cap - on relevant platforms, sym() will add
|
|
||||||
; the underlines automagically, on others it won't
|
|
||||||
%ifdef DONT_USE_UNDERLINE
|
|
||||||
%define sym(a) a
|
|
||||||
%else
|
|
||||||
%define sym(a) _ %+ a
|
|
||||||
%endif
|
|
@ -1,52 +0,0 @@
|
|||||||
; Copyright (c) 2010 Wildfire Games
|
|
||||||
;
|
|
||||||
; 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.
|
|
||||||
|
|
||||||
; assembly code for IA-32 (avoid inline assembly due to differing
|
|
||||||
; compiler support and/or syntax).
|
|
||||||
|
|
||||||
%include "ia32.inc"
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------
|
|
||||||
; CPUID support
|
|
||||||
;-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
; extern "C" void __cdecl ia32_asm_cpuid(x86_x64_CpuidRegs* regs);
|
|
||||||
global sym(ia32_asm_cpuid)
|
|
||||||
sym(ia32_asm_cpuid):
|
|
||||||
push ebx ; (clobbered by CPUID)
|
|
||||||
push edi ; (need a register other than eax..edx)
|
|
||||||
|
|
||||||
mov edi, [esp+8+4] ; -> regs
|
|
||||||
|
|
||||||
mov eax, [edi+0] ; eax (function)
|
|
||||||
mov ecx, [edi+8] ; ecx (count)
|
|
||||||
cpuid
|
|
||||||
stosd
|
|
||||||
xchg eax, ebx
|
|
||||||
stosd
|
|
||||||
xchg eax, ecx
|
|
||||||
stosd
|
|
||||||
xchg eax, edx
|
|
||||||
stosd
|
|
||||||
|
|
||||||
pop edi
|
|
||||||
pop ebx
|
|
||||||
ret
|
|
@ -1,33 +0,0 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* interface to various IA-32 functions (written in assembly language)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INCLUDED_IA32_ASM
|
|
||||||
#define INCLUDED_IA32_ASM
|
|
||||||
|
|
||||||
struct x86_x64_CpuidRegs;
|
|
||||||
EXTERN_C void CALL_CONV ia32_asm_cpuid(x86_x64_CpuidRegs* regs);
|
|
||||||
|
|
||||||
#endif // #ifndef INCLUDED_IA32_ASM
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2010 Wildfire Games
|
/* Copyright (c) 2011 Wildfire Games
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -44,16 +44,15 @@
|
|||||||
# include <intrin.h> // __rdtsc
|
# include <intrin.h> // __rdtsc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HAVE_CPUIDEX 0
|
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729
|
||||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // __cpuidex available on VC10+ and VC9 SP1 (allows setting ecx beforehand)
|
// VC10+ and VC9 SP1: __cpuidex is already available
|
||||||
# undef HAVE_CPUIDEX
|
#elif GCC_VERSION
|
||||||
# define HAVE_CPUIDEX 1
|
# define __cpuidex(regsArray, level, index)\
|
||||||
|
__asm__ __volatile__ ("cpuid"\
|
||||||
|
: "=a" ((regsArray)[0]), "=b" ((regsArray)[1]), "=c" ((regsArray)[2]), "=d" ((regsArray)[3])\
|
||||||
|
: "0" (level), "2" (index));
|
||||||
#else
|
#else
|
||||||
# if ARCH_AMD64
|
# error "compiler not supported"
|
||||||
# include "lib/sysdep/arch/amd64/amd64_asm.h"
|
|
||||||
# else
|
|
||||||
# include "lib/sysdep/arch/ia32/ia32_asm.h"
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -72,17 +71,9 @@
|
|||||||
|
|
||||||
static void cpuid(x86_x64_CpuidRegs* regs)
|
static void cpuid(x86_x64_CpuidRegs* regs)
|
||||||
{
|
{
|
||||||
#if HAVE_CPUIDEX
|
|
||||||
cassert(sizeof(regs->eax) == sizeof(int));
|
cassert(sizeof(regs->eax) == sizeof(int));
|
||||||
cassert(sizeof(*regs) == 4*sizeof(int));
|
cassert(sizeof(*regs) == 4*sizeof(int));
|
||||||
__cpuidex((int*)regs, regs->eax, regs->ecx);
|
__cpuidex((int*)regs, regs->eax, regs->ecx);
|
||||||
#else
|
|
||||||
# if ARCH_AMD64
|
|
||||||
amd64_asm_cpuid(regs);
|
|
||||||
# else
|
|
||||||
ia32_asm_cpuid(regs);
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 cpuid_maxFunction;
|
static u32 cpuid_maxFunction;
|
||||||
|
Loading…
Reference in New Issue
Block a user