more clean-ups
[mesa.git] / src / mesa / x86 / common_x86_asm.S
1 /* $Id: common_x86_asm.S,v 1.5 2001/03/03 21:11:32 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.4
6 *
7 * Copyright (C) 1999-2000 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 /* $XFree86: xc/extras/Mesa/src/X86/common_x86_asm.S,v 1.5 2000/12/12 23:52:37 dawes Exp $ */
37
38 #include "assyntax.h"
39 #include "common_x86_features.h"
40
41
42 /* Intel vendor string
43 */
44 #define GENU 0x756e6547 /* "Genu" */
45 #define INEI 0x49656e69 /* "ineI" */
46 #define NTEL 0x6c65746e /* "ntel" */
47
48 /* AMD vendor string
49 */
50 #define AUTH 0x68747541 /* "Auth" */
51 #define ENTI 0x69746e65 /* "enti" */
52 #define CAMD 0x444d4163 /* "cAMD" */
53
54
55 SEG_DATA
56
57 /* We might want to print out some useful messages.
58 */
59 GLNAME( found_intel ): STRING( "Genuine Intel processor found\n\0" )
60 GLNAME( found_amd ): STRING( "Authentic AMD processor found\n\0" )
61
62 #ifdef USE_KATMAI_ASM
63 GLNAME( katmai_test_dummy ):
64 D_LONG 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000
65 #endif
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
76 /* Test for the CPUID command. If the ID Flag bit in EFLAGS
77 * (bit 21) is writable, the CPUID command is present.
78 */
79 PUSHF_L
80 POP_L ( EAX )
81 MOV_L ( EAX, ECX )
82 XOR_L ( CONST(0x00200000), EAX )
83 PUSH_L ( EAX )
84 POPF_L
85 PUSHF_L
86 POP_L ( EAX )
87
88 /* Verify the ID Flag bit has been written.
89 */
90 CMP_L ( ECX, EAX )
91 JZ ( LLBL ( cpuid_done ) )
92
93 /* Get the CPU vendor info.
94 */
95 XOR_L ( EAX, EAX )
96 CPUID
97
98 /* Test for Intel processors. We must look for the
99 * "GenuineIntel" string in EBX, ECX and EDX.
100 */
101 CMP_L ( CONST(GENU), EBX )
102 JNE ( LLBL( cpuid_amd ) )
103 CMP_L ( CONST(INEI), EDX )
104 JNE ( LLBL( cpuid_amd ) )
105 CMP_L ( CONST(NTEL), ECX )
106 JNE ( LLBL( cpuid_amd ) )
107
108 /* We have an Intel processor, so we can get the feature
109 * information with an CPUID input value of 1.
110 */
111 MOV_L ( CONST(0x1), EAX )
112 CPUID
113 MOV_L ( EDX, EAX )
114 JMP ( LLBL( cpuid_done ) )
115
116 LLBL( cpuid_amd ):
117
118 /* Test for AMD processors. We must look for the
119 * "AuthenticAMD" string in EBX, ECX and EDX.
120 */
121 CMP_L ( CONST(AUTH), EBX )
122 JNE ( LLBL( cpuid_other ) )
123 CMP_L ( CONST(ENTI), EDX )
124 JNE ( LLBL( cpuid_other ) )
125 CMP_L ( CONST(CAMD), ECX )
126 JNE ( LLBL( cpuid_other ) )
127
128 /* We have an AMD processor, so we can get the feature
129 * information after we verify that the extended functions are
130 * supported.
131 */
132 MOV_L ( CONST(0x80000000), EAX )
133 CPUID
134 TEST_L ( EAX, EAX )
135 JZ ( LLBL ( cpuid_failed ) )
136
137 MOV_L ( CONST(0x80000001), EAX )
138 CPUID
139 MOV_L ( EDX, EAX )
140 JMP ( LLBL ( cpuid_done ) )
141
142 LLBL( cpuid_other ):
143
144 /* Test for other processors here when required.
145 */
146
147 LLBL( cpuid_failed ):
148
149 /* If we can't determine the feature information, we must
150 * return zero to indicate that no platform-specific
151 * optimizations can be used.
152 */
153 MOV_L ( CONST(0), EAX )
154
155 LLBL ( cpuid_done ):
156
157 POP_L ( EBX )
158 RET
159
160
161 #ifdef USE_KATMAI_ASM
162 /* Execute an SSE instruction to see if the operating system correctly
163 * supports SSE. A signal handler for SIGILL should have been set
164 * before calling this function, otherwise this could kill the client
165 * application.
166 */
167 ALIGNTEXT4
168 GLOBL GLNAME( _mesa_test_os_katmai_support )
169 GLNAME( _mesa_test_os_katmai_support ):
170
171 XORPS ( XMM0, XMM0 )
172
173 RET
174
175
176 /* Perform an SSE divide-by-zero to see if the operating system
177 * correctly supports unmasked SIMD FPU exceptions. Signal handlers for
178 * SIGILL and SIGFPE should have been set before calling this function,
179 * otherwise this could kill the client application.
180 */
181 ALIGNTEXT4
182 GLOBL GLNAME( _mesa_test_os_katmai_exception_support )
183 GLNAME( _mesa_test_os_katmai_exception_support ):
184
185 PUSH_L ( EBP )
186 MOV_L ( ESP, EBP )
187 SUB_L ( CONST( 8 ), ESP )
188
189 /* Save the original MXCSR register value.
190 */
191 STMXCSR ( REGOFF( -4, EBP ) )
192
193 /* Unmask the divide-by-zero exception and perform one.
194 */
195 STMXCSR ( REGOFF( -8, EBP ) )
196 AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) )
197 LDMXCSR ( REGOFF( -8, EBP ) )
198
199 XORPS ( XMM0, XMM0 )
200 MOVUPS ( GLNAME( katmai_test_dummy ), XMM1 )
201
202 DIVPS ( XMM0, XMM1 )
203
204 /* Restore the original MXCSR register value.
205 */
206 LDMXCSR ( REGOFF( -4, EBP ) )
207
208 LEAVE
209 RET
210
211 #endif