2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Check extended CPU capabilities. Now justs returns the raw CPUID
27 * feature information, allowing the higher level code to interpret the
30 * Written by Holger Waechtler <holger@akaflieg.extern.tu-berlin.de>
32 * Cleaned up and simplified by Gareth Hughes <gareth@valinux.com>
37 * NOTE: Avoid using spaces in between '(' ')' and arguments, especially
38 * with macros like CONST, LLBL that expand to CONCAT(...). Putting spaces
39 * in there will break the build on some platforms.
43 #include "common_x86_features.h"
48 GLOBL GLNAME(_mesa_x86_has_cpuid)
49 HIDDEN(_mesa_x86_has_cpuid)
50 GLNAME(_mesa_x86_has_cpuid):
52 /* Test for the CPUID command. If the ID Flag bit in EFLAGS
53 * (bit 21) is writable, the CPUID command is present */
57 XOR_L (CONST(0x00200000), EAX)
63 /* Verify the ID Flag bit has been written. */
66 XOR_L (CONST(0xff), EAX)
72 GLOBL GLNAME(_mesa_x86_cpuid)
73 HIDDEN(_mesa_x86_cpuid)
74 GLNAME(_mesa_x86_cpuid):
76 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
82 MOV_L (REGOFF(16, ESP), EDI) /* *eax */
83 MOV_L (EAX, REGIND(EDI))
84 MOV_L (REGOFF(20, ESP), EDI) /* *ebx */
85 MOV_L (EBX, REGIND(EDI))
86 MOV_L (REGOFF(24, ESP), EDI) /* *ecx */
87 MOV_L (ECX, REGIND(EDI))
88 MOV_L (REGOFF(28, ESP), EDI) /* *edx */
89 MOV_L (EDX, REGIND(EDI))
96 GLOBL GLNAME(_mesa_x86_cpuid_eax)
97 HIDDEN(_mesa_x86_cpuid_eax)
98 GLNAME(_mesa_x86_cpuid_eax):
100 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
109 GLOBL GLNAME(_mesa_x86_cpuid_ebx)
110 HIDDEN(_mesa_x86_cpuid_ebx)
111 GLNAME(_mesa_x86_cpuid_ebx):
113 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
117 MOV_L (EBX, EAX) /* return EBX */
123 GLOBL GLNAME(_mesa_x86_cpuid_ecx)
124 HIDDEN(_mesa_x86_cpuid_ecx)
125 GLNAME(_mesa_x86_cpuid_ecx):
127 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
131 MOV_L (ECX, EAX) /* return ECX */
137 GLOBL GLNAME(_mesa_x86_cpuid_edx)
138 HIDDEN(_mesa_x86_cpuid_edx)
139 GLNAME(_mesa_x86_cpuid_edx):
141 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
145 MOV_L (EDX, EAX) /* return EDX */
151 /* Execute an SSE instruction to see if the operating system correctly
152 * supports SSE. A signal handler for SIGILL should have been set
153 * before calling this function, otherwise this could kill the client
156 * -----> !!!! ATTENTION DEVELOPERS !!!! <-----
158 * If you're debugging with gdb and you get stopped in this function,
159 * just type 'continue'! Execution will proceed normally.
160 * See freedesktop.org bug #1709 for more info.
163 GLOBL GLNAME( _mesa_test_os_sse_support )
164 HIDDEN(_mesa_test_os_sse_support)
165 GLNAME( _mesa_test_os_sse_support ):
172 /* Perform an SSE divide-by-zero to see if the operating system
173 * correctly supports unmasked SIMD FPU exceptions. Signal handlers for
174 * SIGILL and SIGFPE should have been set before calling this function,
175 * otherwise this could kill the client application.
178 GLOBL GLNAME( _mesa_test_os_sse_exception_support )
179 HIDDEN(_mesa_test_os_sse_exception_support)
180 GLNAME( _mesa_test_os_sse_exception_support ):
184 SUB_L ( CONST( 8 ), ESP )
186 /* Save the original MXCSR register value.
188 STMXCSR ( REGOFF( -4, EBP ) )
190 /* Unmask the divide-by-zero exception and perform one.
192 STMXCSR ( REGOFF( -8, EBP ) )
193 AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) )
194 LDMXCSR ( REGOFF( -8, EBP ) )
198 PUSH_L ( CONST( 0x3f800000 ) )
199 PUSH_L ( CONST( 0x3f800000 ) )
200 PUSH_L ( CONST( 0x3f800000 ) )
201 PUSH_L ( CONST( 0x3f800000 ) )
203 MOVUPS ( REGIND( ESP ), XMM1 )
207 /* Restore the original MXCSR register value.
209 LDMXCSR ( REGOFF( -4, EBP ) )
217 #if defined (__ELF__) && defined (__linux__)
218 .section .note.GNU-stack,"",%progbits