1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Mesa 3-D graphics library 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci/* 26bf215546Sopenharmony_ci * Check extended CPU capabilities. Now justs returns the raw CPUID 27bf215546Sopenharmony_ci * feature information, allowing the higher level code to interpret the 28bf215546Sopenharmony_ci * results. 29bf215546Sopenharmony_ci * 30bf215546Sopenharmony_ci * Written by Holger Waechtler <holger@akaflieg.extern.tu-berlin.de> 31bf215546Sopenharmony_ci * 32bf215546Sopenharmony_ci * Cleaned up and simplified by Gareth Hughes <gareth@valinux.com> 33bf215546Sopenharmony_ci * 34bf215546Sopenharmony_ci */ 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci/* 37bf215546Sopenharmony_ci * NOTE: Avoid using spaces in between '(' ')' and arguments, especially 38bf215546Sopenharmony_ci * with macros like CONST, LLBL that expand to CONCAT(...). Putting spaces 39bf215546Sopenharmony_ci * in there will break the build on some platforms. 40bf215546Sopenharmony_ci */ 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci#include "assyntax.h" 43bf215546Sopenharmony_ci#include "common_x86_features.h" 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci SEG_TEXT 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ciALIGNTEXT4 48bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_has_cpuid) 49bf215546Sopenharmony_ciHIDDEN(_mesa_x86_has_cpuid) 50bf215546Sopenharmony_ciGLNAME(_mesa_x86_has_cpuid): 51bf215546Sopenharmony_ci _CET_ENDBR 52bf215546Sopenharmony_ci /* Test for the CPUID command. If the ID Flag bit in EFLAGS 53bf215546Sopenharmony_ci * (bit 21) is writable, the CPUID command is present */ 54bf215546Sopenharmony_ci PUSHF_L 55bf215546Sopenharmony_ci POP_L (EAX) 56bf215546Sopenharmony_ci MOV_L (EAX, ECX) 57bf215546Sopenharmony_ci XOR_L (CONST(0x00200000), EAX) 58bf215546Sopenharmony_ci PUSH_L (EAX) 59bf215546Sopenharmony_ci POPF_L 60bf215546Sopenharmony_ci PUSHF_L 61bf215546Sopenharmony_ci POP_L (EAX) 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /* Verify the ID Flag bit has been written. */ 64bf215546Sopenharmony_ci CMP_L (ECX, EAX) 65bf215546Sopenharmony_ci SETNE (AL) 66bf215546Sopenharmony_ci XOR_L (CONST(0xff), EAX) 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci RET 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ciALIGNTEXT4 72bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_cpuid) 73bf215546Sopenharmony_ciHIDDEN(_mesa_x86_cpuid) 74bf215546Sopenharmony_ciGLNAME(_mesa_x86_cpuid): 75bf215546Sopenharmony_ci _CET_ENDBR 76bf215546Sopenharmony_ci MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */ 77bf215546Sopenharmony_ci PUSH_L (EDI) 78bf215546Sopenharmony_ci PUSH_L (EBX) 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci CPUID 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci MOV_L (REGOFF(16, ESP), EDI) /* *eax */ 83bf215546Sopenharmony_ci MOV_L (EAX, REGIND(EDI)) 84bf215546Sopenharmony_ci MOV_L (REGOFF(20, ESP), EDI) /* *ebx */ 85bf215546Sopenharmony_ci MOV_L (EBX, REGIND(EDI)) 86bf215546Sopenharmony_ci MOV_L (REGOFF(24, ESP), EDI) /* *ecx */ 87bf215546Sopenharmony_ci MOV_L (ECX, REGIND(EDI)) 88bf215546Sopenharmony_ci MOV_L (REGOFF(28, ESP), EDI) /* *edx */ 89bf215546Sopenharmony_ci MOV_L (EDX, REGIND(EDI)) 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci POP_L (EBX) 92bf215546Sopenharmony_ci POP_L (EDI) 93bf215546Sopenharmony_ci RET 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ciALIGNTEXT4 96bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_cpuid_eax) 97bf215546Sopenharmony_ciHIDDEN(_mesa_x86_cpuid_eax) 98bf215546Sopenharmony_ciGLNAME(_mesa_x86_cpuid_eax): 99bf215546Sopenharmony_ci _CET_ENDBR 100bf215546Sopenharmony_ci MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */ 101bf215546Sopenharmony_ci PUSH_L (EBX) 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci CPUID 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci POP_L (EBX) 106bf215546Sopenharmony_ci RET 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ciALIGNTEXT4 109bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_cpuid_ebx) 110bf215546Sopenharmony_ciHIDDEN(_mesa_x86_cpuid_ebx) 111bf215546Sopenharmony_ciGLNAME(_mesa_x86_cpuid_ebx): 112bf215546Sopenharmony_ci _CET_ENDBR 113bf215546Sopenharmony_ci MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */ 114bf215546Sopenharmony_ci PUSH_L (EBX) 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci CPUID 117bf215546Sopenharmony_ci MOV_L (EBX, EAX) /* return EBX */ 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci POP_L (EBX) 120bf215546Sopenharmony_ci RET 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ciALIGNTEXT4 123bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_cpuid_ecx) 124bf215546Sopenharmony_ciHIDDEN(_mesa_x86_cpuid_ecx) 125bf215546Sopenharmony_ciGLNAME(_mesa_x86_cpuid_ecx): 126bf215546Sopenharmony_ci _CET_ENDBR 127bf215546Sopenharmony_ci MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */ 128bf215546Sopenharmony_ci PUSH_L (EBX) 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci CPUID 131bf215546Sopenharmony_ci MOV_L (ECX, EAX) /* return ECX */ 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci POP_L (EBX) 134bf215546Sopenharmony_ci RET 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ciALIGNTEXT4 137bf215546Sopenharmony_ciGLOBL GLNAME(_mesa_x86_cpuid_edx) 138bf215546Sopenharmony_ciHIDDEN(_mesa_x86_cpuid_edx) 139bf215546Sopenharmony_ciGLNAME(_mesa_x86_cpuid_edx): 140bf215546Sopenharmony_ci _CET_ENDBR 141bf215546Sopenharmony_ci MOV_L (REGOFF(4, ESP), EAX) /* cpuid op */ 142bf215546Sopenharmony_ci PUSH_L (EBX) 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci CPUID 145bf215546Sopenharmony_ci MOV_L (EDX, EAX) /* return EDX */ 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci POP_L (EBX) 148bf215546Sopenharmony_ci RET 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci#ifdef USE_SSE_ASM 151bf215546Sopenharmony_ci/* Execute an SSE instruction to see if the operating system correctly 152bf215546Sopenharmony_ci * supports SSE. A signal handler for SIGILL should have been set 153bf215546Sopenharmony_ci * before calling this function, otherwise this could kill the client 154bf215546Sopenharmony_ci * application. 155bf215546Sopenharmony_ci * 156bf215546Sopenharmony_ci * -----> !!!! ATTENTION DEVELOPERS !!!! <----- 157bf215546Sopenharmony_ci * 158bf215546Sopenharmony_ci * If you're debugging with gdb and you get stopped in this function, 159bf215546Sopenharmony_ci * just type 'continue'! Execution will proceed normally. 160bf215546Sopenharmony_ci * See freedesktop.org bug #1709 for more info. 161bf215546Sopenharmony_ci */ 162bf215546Sopenharmony_ciALIGNTEXT4 163bf215546Sopenharmony_ciGLOBL GLNAME( _mesa_test_os_sse_support ) 164bf215546Sopenharmony_ciHIDDEN(_mesa_test_os_sse_support) 165bf215546Sopenharmony_ciGLNAME( _mesa_test_os_sse_support ): 166bf215546Sopenharmony_ci _CET_ENDBR 167bf215546Sopenharmony_ci XORPS ( XMM0, XMM0 ) 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci RET 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci/* Perform an SSE divide-by-zero to see if the operating system 173bf215546Sopenharmony_ci * correctly supports unmasked SIMD FPU exceptions. Signal handlers for 174bf215546Sopenharmony_ci * SIGILL and SIGFPE should have been set before calling this function, 175bf215546Sopenharmony_ci * otherwise this could kill the client application. 176bf215546Sopenharmony_ci */ 177bf215546Sopenharmony_ciALIGNTEXT4 178bf215546Sopenharmony_ciGLOBL GLNAME( _mesa_test_os_sse_exception_support ) 179bf215546Sopenharmony_ciHIDDEN(_mesa_test_os_sse_exception_support) 180bf215546Sopenharmony_ciGLNAME( _mesa_test_os_sse_exception_support ): 181bf215546Sopenharmony_ci _CET_ENDBR 182bf215546Sopenharmony_ci PUSH_L ( EBP ) 183bf215546Sopenharmony_ci MOV_L ( ESP, EBP ) 184bf215546Sopenharmony_ci SUB_L ( CONST( 8 ), ESP ) 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci /* Save the original MXCSR register value. 187bf215546Sopenharmony_ci */ 188bf215546Sopenharmony_ci STMXCSR ( REGOFF( -4, EBP ) ) 189bf215546Sopenharmony_ci 190bf215546Sopenharmony_ci /* Unmask the divide-by-zero exception and perform one. 191bf215546Sopenharmony_ci */ 192bf215546Sopenharmony_ci STMXCSR ( REGOFF( -8, EBP ) ) 193bf215546Sopenharmony_ci AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) ) 194bf215546Sopenharmony_ci LDMXCSR ( REGOFF( -8, EBP ) ) 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci XORPS ( XMM0, XMM0 ) 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci PUSH_L ( CONST( 0x3f800000 ) ) 199bf215546Sopenharmony_ci PUSH_L ( CONST( 0x3f800000 ) ) 200bf215546Sopenharmony_ci PUSH_L ( CONST( 0x3f800000 ) ) 201bf215546Sopenharmony_ci PUSH_L ( CONST( 0x3f800000 ) ) 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci MOVUPS ( REGIND( ESP ), XMM1 ) 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci DIVPS ( XMM0, XMM1 ) 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci /* Restore the original MXCSR register value. 208bf215546Sopenharmony_ci */ 209bf215546Sopenharmony_ci LDMXCSR ( REGOFF( -4, EBP ) ) 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ci LEAVE 212bf215546Sopenharmony_ci RET 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci#endif 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci#if defined (__ELF__) && defined (__linux__) 218bf215546Sopenharmony_ci .section .note.GNU-stack,"",%progbits 219bf215546Sopenharmony_ci#endif 220