1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 1993-2006
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
44 // disable warnings about "Inline asm assigning to FS:0 handler not registered as safe handler"
45 #pragma warning(disable:4733)
47 // Code from Intel that crashes a Cyrix CPU
48 #define CPUID _asm _emit 0x0F _asm _emit 0xA2
50 #define CPUID_SSE2_FLAG 0x04000000 //; Is IA SSE2 bit (Bit 26 of EDX) in feature flags set
51 static BOOL gP4OsSupport
= FALSE
;
54 EXCEPTION_DISPOSITION __cdecl
MyExceptionHandlerSSE2(struct _EXCEPTION_RECORD
* /*ExceptionRecord*/,
55 void * /*EstablisherFrame*/,
56 struct _CONTEXT
*ContextRecord
,
57 void * /*DispatcherContext*/)
59 // Turn off the P4 OS support flag.
62 // The offending P4 instruction is 3 bytes long. Skip it and continue.
63 ContextRecord
->Eip
+= 3;
64 return ExceptionContinueExecution
;
71 // we support all this stuff
74 long featureFlags
= 0;
78 // disable warnings about unreferenced _asm labels.
79 #pragma warning(disable:4102)
86 ; The AC bit
, bit
#18, is a new bit introduced in the EFLAGS
87 ; register on the i486 DX CPU to generate alignment faults
.
88 ; This bit can
not be set on the i386 CPU
.
92 pop eax
; get original EFLAGS
93 mov ecx
,eax
; save original EFLAGS
94 xor eax
,40000h
; flip AC bit in EFLAGS
95 push eax
; save
for EFLAGS
96 popfd
; copy to EFLAGS
98 pop eax
; get
new EFLAGS value
99 xor eax
,ecx
; can
't toggle AC bit, CPU=Intel386
100 je end_get_cpuid ; CPU is i386,
102 ; i486 DX CPU / i487 SX MCP and i486 SX CPU checking
104 ; Checking for ability to set/clear ID flag (Bit 21) in EFLAGS
105 ; which indicates the presence of a processor
106 ; with the ability to use the CPUID instruction.
109 pushfd ; push original EFLAGS
110 pop eax ; get original EFLAGS in eax
111 mov ecx,eax ; save original EFLAGS in ecx
112 xor eax,200000h ; flip ID bit in EFLAGS
113 push eax ; save for EFLAGS
114 popfd ; copy to EFLAGS
116 pop eax ; get new EFLAGS value
118 je end_get_cpuid ; CPU=486 without CPUID instruction functionality
120 ; Execute CPUID instruction to determine vendor, family,
121 ; model and stepping. The use of the CPUID instruction used
122 ; in this program can be used for B0 and later steppings
123 ; of the P5 processor.
126 // At this point we know we can do our CPUID instruction
127 // We need some special code here to handle Cyrix buggy processors
129 // Get our Vendors name out first
140 jmp non_cyrix_version
143 // EAX returns the highest value we can use as input into the
144 // CPUID instruction. If for some reason it returns 0, assume
145 // no MMX support. (Since we need to input 1 to query MMX)
149 cmp ebx, 0x69727943 // This is "iryC", "Cyri" in memory
150 jne non_cyrix_version
152 // EAX now contains the stepping, model and family information
153 and eax, 0x0FF0 // isolate model and family info
154 cmp eax, 0x0520 // We're a
6x86
, so there
's no MMX
159 mov eax, 1 // Our input flag for our CPUID instruction
161 mov featureFlags, edx ; save feature flags
168 BOOL bOsSupport = FALSE;
169 BOOL bHwSupport = (featureFlags & CPUID_SSE2_FLAG);
172 // Execute a KNI instruction and use Structured Exception Handling
173 // to catch the exception if the OS does not support KNI.
175 DWORD handler = (DWORD)MyExceptionHandlerSSE2;
179 __asm { // Build EXCEPTION_REGISTRATION record:
180 push handler // Address of handler function
181 push FS:[0] // Address of previous handler
182 mov FS:[0],ESP // Install new EXECEPTION_REGISTRATION
185 // If so, test a KNI instruction and make sure you don't get
186 // an exception (this tests OS support)
189 //orpd xmm1,xmm1; //Below are the op codes for this instruction
190 //emits will compile w/ MSVC 5.0 compiler
191 //You can comment these out and uncomment the
192 //orpd when using the Intel Compiler
200 __asm
{ // Remove our EXECEPTION_REGISTRATION record
201 mov eax
,[ESP
] // Get pointer to previous record
202 mov FS
:[0], EAX
// Install previous record
203 add esp
, 8 // Clean our EXECEPTION_REGISTRATION off stack
206 bOsSupport
= gP4OsSupport
;
209 return bHwSupport
&& bOsSupport
&& procType
;