Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / x86 / common_x86_asm.S
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /*
26 * Check extended CPU capabilities. Now justs returns the raw CPUID
27 * feature information, allowing the higher level code to interpret the
28 * results.
29 *
30 * Written by Holger Waechtler <holger@akaflieg.extern.tu-berlin.de>
31 *
32 * Cleaned up and simplified by Gareth Hughes <gareth@valinux.com>
33 *
34 */
35
36 /*
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.
40 */
41
42 <<<<<<< HEAD:src/mesa/x86/common_x86_asm.S
43 =======
44 #include "matypes.h"
45 >>>>>>> master:src/mesa/x86/common_x86_asm.S
46 #include "assyntax.h"
47 #include "common_x86_features.h"
48
49 SEG_TEXT
50
51 ALIGNTEXT4
52 GLOBL GLNAME(_mesa_x86_has_cpuid)
53 HIDDEN(_mesa_x86_has_cpuid)
54 GLNAME(_mesa_x86_has_cpuid):
55
56 /* Test for the CPUID command. If the ID Flag bit in EFLAGS
57 * (bit 21) is writable, the CPUID command is present */
58 PUSHF_L
59 POP_L (EAX)
60 MOV_L (EAX, ECX)
61 XOR_L (CONST(0x00200000), EAX)
62 PUSH_L (EAX)
63 POPF_L
64 PUSHF_L
65 POP_L (EAX)
66
67 /* Verify the ID Flag bit has been written. */
68 CMP_L (ECX, EAX)
69 SETNE (AL)
70 XOR_L (CONST(0xff), EAX)
71
72 RET
73
74
75 ALIGNTEXT4
76 GLOBL GLNAME(_mesa_x86_cpuid)
77 HIDDEN(_mesa_x86_cpuid)
78 GLNAME(_mesa_x86_cpuid):
79
80 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
81 PUSH_L (EDI)
82 PUSH_L (EBX)
83
84 CPUID
85
86 MOV_L (REGOFF(16, ESP), EDI) /* *eax */
87 MOV_L (EAX, REGIND(EDI))
88 MOV_L (REGOFF(20, ESP), EDI) /* *ebx */
89 MOV_L (EBX, REGIND(EDI))
90 MOV_L (REGOFF(24, ESP), EDI) /* *ecx */
91 MOV_L (ECX, REGIND(EDI))
92 MOV_L (REGOFF(28, ESP), EDI) /* *edx */
93 MOV_L (EDX, REGIND(EDI))
94
95 POP_L (EBX)
96 POP_L (EDI)
97 RET
98
99 ALIGNTEXT4
100 GLOBL GLNAME(_mesa_x86_cpuid_eax)
101 HIDDEN(_mesa_x86_cpuid_eax)
102 GLNAME(_mesa_x86_cpuid_eax):
103
104 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
105 PUSH_L (EBX)
106
107 CPUID
108
109 POP_L (EBX)
110 RET
111
112 ALIGNTEXT4
113 GLOBL GLNAME(_mesa_x86_cpuid_ebx)
114 HIDDEN(_mesa_x86_cpuid_ebx)
115 GLNAME(_mesa_x86_cpuid_ebx):
116
117 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
118 PUSH_L (EBX)
119
120 CPUID
121 MOV_L (EBX, EAX) /* return EBX */
122
123 POP_L (EBX)
124 RET
125
126 ALIGNTEXT4
127 GLOBL GLNAME(_mesa_x86_cpuid_ecx)
128 HIDDEN(_mesa_x86_cpuid_ecx)
129 GLNAME(_mesa_x86_cpuid_ecx):
130
131 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
132 PUSH_L (EBX)
133
134 CPUID
135 MOV_L (ECX, EAX) /* return ECX */
136
137 POP_L (EBX)
138 RET
139
140 ALIGNTEXT4
141 GLOBL GLNAME(_mesa_x86_cpuid_edx)
142 HIDDEN(_mesa_x86_cpuid_edx)
143 GLNAME(_mesa_x86_cpuid_edx):
144
145 MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */
146 PUSH_L (EBX)
147
148 CPUID
149 MOV_L (EDX, EAX) /* return EDX */
150
151 POP_L (EBX)
152 RET
153
154 #ifdef USE_SSE_ASM
155 /* Execute an SSE instruction to see if the operating system correctly
156 * supports SSE. A signal handler for SIGILL should have been set
157 * before calling this function, otherwise this could kill the client
158 * application.
159 *
160 * -----> !!!! ATTENTION DEVELOPERS !!!! <-----
161 *
162 * If you're debugging with gdb and you get stopped in this function,
163 * just type 'continue'! Execution will proceed normally.
164 * See freedesktop.org bug #1709 for more info.
165 */
166 ALIGNTEXT4
167 GLOBL GLNAME( _mesa_test_os_sse_support )
168 HIDDEN(_mesa_test_os_sse_support)
169 GLNAME( _mesa_test_os_sse_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_sse_exception_support )
183 HIDDEN(_mesa_test_os_sse_exception_support)
184 GLNAME( _mesa_test_os_sse_exception_support ):
185
186 PUSH_L ( EBP )
187 MOV_L ( ESP, EBP )
188 SUB_L ( CONST( 8 ), ESP )
189
190 /* Save the original MXCSR register value.
191 */
192 STMXCSR ( REGOFF( -4, EBP ) )
193
194 /* Unmask the divide-by-zero exception and perform one.
195 */
196 STMXCSR ( REGOFF( -8, EBP ) )
197 AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) )
198 LDMXCSR ( REGOFF( -8, EBP ) )
199
200 XORPS ( XMM0, XMM0 )
201
202 PUSH_L ( CONST( 0x3f800000 ) )
203 PUSH_L ( CONST( 0x3f800000 ) )
204 PUSH_L ( CONST( 0x3f800000 ) )
205 PUSH_L ( CONST( 0x3f800000 ) )
206
207 MOVUPS ( REGIND( ESP ), XMM1 )
208
209 DIVPS ( XMM0, XMM1 )
210
211 /* Restore the original MXCSR register value.
212 */
213 LDMXCSR ( REGOFF( -4, EBP ) )
214
215 LEAVE
216 RET
217
218 #endif
219
220
221 #if defined (__ELF__) && defined (__linux__)
222 .section .note.GNU-stack,"",%progbits
223 #endif