Committing in .
[mesa.git] / src / mesa / x86 / common_x86_asm.S
1 /* $Id: common_x86_asm.S,v 1.12 2002/09/19 16:07:32 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.0.3
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 /*
28 * Check extended CPU capabilities. Now justs returns the raw CPUID
29 * feature information, allowing the higher level code to interpret the
30 * results.
31 *
32 * Written by Holger Waechtler <holger@akaflieg.extern.tu-berlin.de>
33 *
34 * Cleaned up and simplified by Gareth Hughes <gareth@valinux.com>
35 */
36
37 /*
38 * NOTE: Avoid using spaces in between '(' ')' and arguments, especially
39 * with macros like CONST, LLBL that expand to CONCAT(...). Putting spaces
40 * in there will break the build on some platforms.
41 */
42
43 #include "matypes.h"
44 #include "common_x86_features.h"
45
46
47 /* Intel vendor string
48 */
49 #define GENU 0x756e6547 /* "Genu" */
50 #define INEI 0x49656e69 /* "ineI" */
51 #define NTEL 0x6c65746e /* "ntel" */
52
53 /* AMD vendor string
54 */
55 #define AUTH 0x68747541 /* "Auth" */
56 #define ENTI 0x69746e65 /* "enti" */
57 #define CAMD 0x444d4163 /* "cAMD" */
58
59
60 SEG_DATA
61
62 /* We might want to print out some useful messages.
63 */
64 GLNAME( found_intel ): STRING( "Genuine Intel processor found\n\0" )
65 GLNAME( found_amd ): STRING( "Authentic AMD processor found\n\0" )
66
67
68 SEG_TEXT
69
70 ALIGNTEXT4
71 GLOBL GLNAME( _mesa_identify_x86_cpu_features )
72 GLNAME( _mesa_identify_x86_cpu_features ):
73
74 PUSH_L ( EBX )
75 PUSH_L ( ESI )
76
77 /* Test for the CPUID command. If the ID Flag bit in EFLAGS
78 * (bit 21) is writable, the CPUID command is present.
79 */
80 PUSHF_L
81 POP_L ( EAX )
82 MOV_L ( EAX, ECX )
83 XOR_L ( CONST(0x00200000), EAX )
84 PUSH_L ( EAX )
85 POPF_L
86 PUSHF_L
87 POP_L ( EAX )
88
89 /* Verify the ID Flag bit has been written.
90 */
91 CMP_L ( ECX, EAX )
92 JZ ( LLBL (cpuid_done) )
93
94 /* Get the CPU vendor info.
95 */
96 XOR_L ( EAX, EAX )
97 CPUID
98
99 /* Test for Intel processors. We must look for the
100 * "GenuineIntel" string in EBX, ECX and EDX.
101 */
102 CMP_L ( CONST(GENU), EBX )
103 JNE ( LLBL(cpuid_amd) )
104 CMP_L ( CONST(INEI), EDX )
105 JNE ( LLBL(cpuid_amd) )
106 CMP_L ( CONST(NTEL), ECX )
107 JNE ( LLBL(cpuid_amd) )
108
109 /* We have an Intel processor, so we can get the feature
110 * information with an CPUID input value of 1.
111 */
112 MOV_L ( CONST(0x1), EAX )
113 CPUID
114 MOV_L ( EDX, EAX )
115 JMP ( LLBL(cpuid_done) )
116
117 LLBL(cpuid_amd):
118
119 /* Test for AMD processors. We must look for the
120 * "AuthenticAMD" string in EBX, ECX and EDX.
121 */
122 CMP_L ( CONST(AUTH), EBX )
123 JNE ( LLBL(cpuid_other) )
124 CMP_L ( CONST(ENTI), EDX )
125 JNE ( LLBL(cpuid_other) )
126 CMP_L ( CONST(CAMD), ECX )
127 JNE ( LLBL(cpuid_other) )
128
129 /* We have an AMD processor, so we can get the feature
130 * information after we verify that the extended functions are
131 * supported.
132 */
133 /* The features we need are almost all in the extended set. The
134 * exception is SSE enable, which is in the standard set (0x1).
135 */
136 MOV_L ( CONST(0x1), EAX )
137 CPUID
138 TEST_L ( EAX, EAX )
139 JZ ( LLBL (cpuid_failed) )
140 MOV_L ( EDX, ESI )
141
142 MOV_L ( CONST(0x80000000), EAX )
143 CPUID
144 TEST_L ( EAX, EAX )
145 JZ ( LLBL (cpuid_failed) )
146
147 MOV_L ( CONST(0x80000001), EAX )
148 CPUID
149 MOV_L ( EDX, EAX )
150
151 AND_L ( CONST(0x02000000), ESI ) /* OR in the SSE bit */
152 OR_L ( ESI, EAX )
153
154 JMP ( LLBL (cpuid_done) )
155
156 LLBL(cpuid_other):
157
158 /* Test for other processors here when required.
159 */
160
161 LLBL(cpuid_failed):
162
163 /* If we can't determine the feature information, we must
164 * return zero to indicate that no platform-specific
165 * optimizations can be used.
166 */
167 MOV_L ( CONST(0), EAX )
168
169 LLBL (cpuid_done):
170
171 POP_L ( ESI )
172 POP_L ( EBX )
173 RET
174
175
176 #ifdef USE_SSE_ASM
177 /* Execute an SSE instruction to see if the operating system correctly
178 * supports SSE. A signal handler for SIGILL should have been set
179 * before calling this function, otherwise this could kill the client
180 * application.
181 */
182 ALIGNTEXT4
183 GLOBL GLNAME( _mesa_test_os_sse_support )
184 GLNAME( _mesa_test_os_sse_support ):
185
186 XORPS ( XMM0, XMM0 )
187
188 RET
189
190
191 /* Perform an SSE divide-by-zero to see if the operating system
192 * correctly supports unmasked SIMD FPU exceptions. Signal handlers for
193 * SIGILL and SIGFPE should have been set before calling this function,
194 * otherwise this could kill the client application.
195 */
196 ALIGNTEXT4
197 GLOBL GLNAME( _mesa_test_os_sse_exception_support )
198 GLNAME( _mesa_test_os_sse_exception_support ):
199
200 PUSH_L ( EBP )
201 MOV_L ( ESP, EBP )
202 SUB_L ( CONST( 8 ), ESP )
203
204 /* Save the original MXCSR register value.
205 */
206 STMXCSR ( REGOFF( -4, EBP ) )
207
208 /* Unmask the divide-by-zero exception and perform one.
209 */
210 STMXCSR ( REGOFF( -8, EBP ) )
211 AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) )
212 LDMXCSR ( REGOFF( -8, EBP ) )
213
214 XORPS ( XMM0, XMM0 )
215
216 PUSH_L ( CONST( 0x3f800000 ) )
217 PUSH_L ( CONST( 0x3f800000 ) )
218 PUSH_L ( CONST( 0x3f800000 ) )
219 PUSH_L ( CONST( 0x3f800000 ) )
220
221 MOVUPS ( REGIND( ESP ), XMM1 )
222
223 ADD_L ( CONST( 32 ), ESP )
224
225 DIVPS ( XMM0, XMM1 )
226
227 /* Restore the original MXCSR register value.
228 */
229 LDMXCSR ( REGOFF( -4, EBP ) )
230
231 LEAVE
232 RET
233
234 #endif