154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis/* 254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Mesa 3-D graphics library 354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Version: 7.1 454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * 554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * 754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Permission is hereby granted, free of charge, to any person obtaining a 854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * copy of this software and associated documentation files (the "Software"), 954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * to deal in the Software without restriction, including without limitation 1054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * and/or sell copies of the Software, and to permit persons to whom the 1254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Software is furnished to do so, subject to the following conditions: 1354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * 1454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * The above copyright notice and this permission notice shall be included 1554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * in all copies or substantial portions of the Software. 1654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * 1754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis */ 2454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 2554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis/** 2654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * \file glapi_entrypoint.c 2754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * 2854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Arch-specific code for manipulating GL API entrypoints (dispatch stubs). 2954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis */ 3054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#include "glapi/glapi_priv.h" 33a73c6540d9a7f6e26d8568ba2fc522cb865f0a6cChia-I Wu#include "mapi/u_execmem.h" 3454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef USE_X86_ASM 3754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#if defined( GLX_USE_TLS ) 3954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzisextern GLubyte gl_dispatch_functions_start[]; 4054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzisextern GLubyte gl_dispatch_functions_end[]; 4154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 4254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzisextern const GLubyte gl_dispatch_functions_start[]; 4354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 4454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 4554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif /* USE_X86_ASM */ 4654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 4754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 4854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#if defined(DISPATCH_FUNCTION_SIZE) 4954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 5054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis_glapi_proc 5159e743b8d393f2bdf023e3a5ad8fe848a7459ec9Brian Paulget_entrypoint_address(unsigned int functionOffset) 5254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis{ 5354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis return (_glapi_proc) (gl_dispatch_functions_start 5454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis + (DISPATCH_FUNCTION_SIZE * functionOffset)); 5554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis} 5654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 5754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 5854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 5954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 606c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis#if defined(USE_X86_ASM) 6154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 6254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis/** 6354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis * Perform platform-specific GL API entry-point fixups. 6454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis */ 6554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzisstatic void 6654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzisinit_glapi_relocs( void ) 6754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis{ 686c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis#if defined(GLX_USE_TLS) && !defined(GLX_X86_READONLY_TEXT) 6954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned long _x86_get_dispatch(void); 7054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis char run_time_patch[] = { 7154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x65, 0xa1, 0, 0, 0, 0 /* movl %gs:0,%eax */ 7254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis }; 7354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis GLuint *offset = (GLuint *) &run_time_patch[2]; /* 32-bits for x86/32 */ 7454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis const GLubyte * const get_disp = (const GLubyte *) run_time_patch; 7554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis GLubyte * curr_func = (GLubyte *) gl_dispatch_functions_start; 7654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 7754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis *offset = _x86_get_dispatch(); 7854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis while ( curr_func != (GLubyte *) gl_dispatch_functions_end ) { 7954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis (void) memcpy( curr_func, get_disp, sizeof(run_time_patch)); 8054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis curr_func += DISPATCH_FUNCTION_SIZE; 8154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis } 8254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 836c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis} 846c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 850ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 860ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis/** 870ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * Generate a dispatch function (entrypoint) which jumps through 880ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * the given slot number (offset) in the current dispatch table. 890ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * We need assembly language in order to accomplish this. 900ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis */ 910ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis_glapi_proc 9259e743b8d393f2bdf023e3a5ad8fe848a7459ec9Brian Paulgenerate_entrypoint(unsigned int functionOffset) 930ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis{ 940ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis /* 32 is chosen as something of a magic offset. For x86, the dispatch 950ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * at offset 32 is the first one where the offset in the 960ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * "jmp OFFSET*4(%eax)" can't be encoded in a single byte. 970ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis */ 980ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis const GLubyte * const template_func = gl_dispatch_functions_start 990ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis + (DISPATCH_FUNCTION_SIZE * 32); 100a73c6540d9a7f6e26d8568ba2fc522cb865f0a6cChia-I Wu GLubyte * const code = (GLubyte *) u_execmem_alloc(DISPATCH_FUNCTION_SIZE); 1010ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1020ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1030ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis if ( code != NULL ) { 1040ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis (void) memcpy(code, template_func, DISPATCH_FUNCTION_SIZE); 1050ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis fill_in_entrypoint_offset( (_glapi_proc) code, functionOffset ); 1060ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis } 1070ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1080ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis return (_glapi_proc) code; 1090ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis} 1100ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1110ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1120ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis/** 1130ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * This function inserts a new dispatch offset into the assembly language 1140ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis * stub that was generated with the preceeding function. 1150ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis */ 1160ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisvoid 11759e743b8d393f2bdf023e3a5ad8fe848a7459ec9Brian Paulfill_in_entrypoint_offset(_glapi_proc entrypoint, unsigned int offset) 1180ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis{ 1190ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis GLubyte * const code = (GLubyte *) entrypoint; 1200ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1218fd7ee1815dd5880f94f13d88225d7be6f549ae6George Sapountzis#if defined(GLX_USE_TLS) 1228fd7ee1815dd5880f94f13d88225d7be6f549ae6George Sapountzis *((unsigned int *)(code + 8)) = 4 * offset; 1238fd7ee1815dd5880f94f13d88225d7be6f549ae6George Sapountzis#elif defined(THREADS) 1240ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis *((unsigned int *)(code + 11)) = 4 * offset; 1250ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis *((unsigned int *)(code + 22)) = 4 * offset; 1260ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis#else 1278fd7ee1815dd5880f94f13d88225d7be6f549ae6George Sapountzis *((unsigned int *)(code + 7)) = 4 * offset; 1280ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis#endif 1290ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis} 1300ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1310ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 1326c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis#elif defined(USE_SPARC_ASM) 1336c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 1346c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisextern void __glapi_sparc_icache_flush(unsigned int *); 1356c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 1366c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisstatic void 1376c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisinit_glapi_relocs( void ) 1386c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis{ 139a2f28ceea22254f09ee37039eec873ccdf689e6cMatt Turner#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) 14054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis static const unsigned int template[] = { 14154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef GLX_USE_TLS 14254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x05000000, /* sethi %hi(_glapi_tls_Dispatch), %g2 */ 14354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x8730e00a, /* srl %g3, 10, %g3 */ 14454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x8410a000, /* or %g2, %lo(_glapi_tls_Dispatch), %g2 */ 14554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef __arch64__ 14654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc259c002, /* ldx [%g7 + %g2], %g1 */ 14754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2584003, /* ldx [%g1 + %g3], %g1 */ 14854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 14954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc201c002, /* ld [%g7 + %g2], %g1 */ 15054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2004003, /* ld [%g1 + %g3], %g1 */ 15154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 15254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x81c04000, /* jmp %g1 */ 15354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x01000000, /* nop */ 15454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 15554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef __arch64__ 15654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x03000000, /* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */ 15754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x05000000, /* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */ 15854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x82106000, /* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */ 15954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x8730e00a, /* 64-bit 0x0c --> srl %g3, 10, %g3 */ 16054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x83287020, /* 64-bit 0x10 --> sllx %g1, 32, %g1 */ 16154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x82004002, /* 64-bit 0x14 --> add %g1, %g2, %g1 */ 16254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2586000, /* 64-bit 0x18 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */ 16354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 16454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x03000000, /* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */ 16554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x8730e00a, /* 32-bit 0x04 --> srl %g3, 10, %g3 */ 16654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2006000, /* 32-bit 0x08 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ 16754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 16854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x80a06000, /* --> cmp %g1, 0 */ 16954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x02800005, /* --> be +4*5 */ 17054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x01000000, /* --> nop */ 17154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef __arch64__ 17254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2584003, /* 64-bit --> ldx [%g1 + %g3], %g1 */ 17354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 17454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xc2004003, /* 32-bit --> ld [%g1 + %g3], %g1 */ 17554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 17654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x81c04000, /* --> jmp %g1 */ 17754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x01000000, /* --> nop */ 17854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef __arch64__ 17954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x9de3bf80, /* 64-bit --> save %sp, -128, %sp */ 18054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 18154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x9de3bfc0, /* 32-bit --> save %sp, -64, %sp */ 18254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 18354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0xa0100003, /* --> mov %g3, %l0 */ 18454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x40000000, /* --> call _glapi_get_dispatch */ 18554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x01000000, /* --> nop */ 18654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x82100008, /* --> mov %o0, %g1 */ 18754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x86100010, /* --> mov %l0, %g3 */ 18854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x10bffff7, /* --> ba -4*9 */ 18954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x81e80000, /* --> restore */ 19054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 19154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis }; 19254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef GLX_USE_TLS 19354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned int __glapi_sparc_tls_stub; 19454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned long __glapi_sparc_get_dispatch(void); 19554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned int *code = &__glapi_sparc_tls_stub; 19654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned long dispatch = __glapi_sparc_get_dispatch(); 19754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 19854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned int __glapi_sparc_pthread_stub; 19954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned int *code = &__glapi_sparc_pthread_stub; 20054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned long dispatch = (unsigned long) &_glapi_Dispatch; 20154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned long call_dest = (unsigned long ) &_glapi_get_dispatch; 20254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis int idx; 20354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 20454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 2056c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis#ifdef GLX_USE_TLS 20654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[0] = template[0] | (dispatch >> 10); 20754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[1] = template[1]; 20854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[0]); 20954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[2] = template[2] | (dispatch & 0x3ff); 21054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[3] = template[3]; 21154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[2]); 21254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[4] = template[4]; 21354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[5] = template[5]; 21454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[4]); 21554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[6] = template[6]; 21654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[6]); 21754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 21854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#if defined(__arch64__) 21954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[0] = template[0] | (dispatch >> (32 + 10)); 22054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[1] = template[1] | ((dispatch & 0xffffffff) >> 10); 22154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[0]); 22254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[2] = template[2] | ((dispatch >> 32) & 0x3ff); 22354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[3] = template[3]; 22454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[2]); 22554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[4] = template[4]; 22654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[5] = template[5]; 22754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[4]); 22854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[6] = template[6] | (dispatch & 0x3ff); 22954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis idx = 7; 23054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 23154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[0] = template[0] | (dispatch >> 10); 23254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[1] = template[1]; 23354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[0]); 23454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[2] = template[2] | (dispatch & 0x3ff); 23554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis idx = 3; 23654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 23754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 0] = template[idx + 0]; 23854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx - 1]); 23954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 1] = template[idx + 1]; 24054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 2] = template[idx + 2]; 24154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 1]); 24254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 3] = template[idx + 3]; 24354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 4] = template[idx + 4]; 24454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 3]); 24554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 5] = template[idx + 5]; 24654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 6] = template[idx + 6]; 24754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 5]); 24854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 7] = template[idx + 7]; 24954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 8] = template[idx + 8] | 25054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis (((call_dest - ((unsigned long) &code[idx + 8])) 25154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis >> 2) & 0x3fffffff); 25254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 7]); 25354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 9] = template[idx + 9]; 25454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 10] = template[idx + 10]; 25554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 9]); 25654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 11] = template[idx + 11]; 25754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 12] = template[idx + 12]; 25854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 11]); 25954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[idx + 13] = template[idx + 13]; 26054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[idx + 13]); 26154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 26254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 26354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis} 26454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 26554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 2666c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis_glapi_proc 2676c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisgenerate_entrypoint(GLuint functionOffset) 2686c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis{ 269a2f28ceea22254f09ee37039eec873ccdf689e6cMatt Turner#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) 27054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis static const unsigned int template[] = { 27154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x07000000, /* sethi %hi(0), %g3 */ 27254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x8210000f, /* mov %o7, %g1 */ 27354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x40000000, /* call */ 27454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 0x9e100001, /* mov %g1, %o7 */ 27554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis }; 27654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#ifdef GLX_USE_TLS 27754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned int __glapi_sparc_tls_stub; 27854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned long call_dest = (unsigned long ) &__glapi_sparc_tls_stub; 27954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#else 28054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis extern unsigned int __glapi_sparc_pthread_stub; 28154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis unsigned long call_dest = (unsigned long ) &__glapi_sparc_pthread_stub; 28254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 283a73c6540d9a7f6e26d8568ba2fc522cb865f0a6cChia-I Wu unsigned int *code = (unsigned int *) u_execmem_alloc(sizeof(template)); 28454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis if (code) { 28554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[0] = template[0] | (functionOffset & 0x3fffff); 28654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[1] = template[1]; 28754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[0]); 28854ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[2] = template[2] | 28954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis (((call_dest - ((unsigned long) &code[2])) 29054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis >> 2) & 0x3fffffff); 29154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis code[3] = template[3]; 29254ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis __glapi_sparc_icache_flush(&code[2]); 29354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis } 29454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis return (_glapi_proc) code; 29554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif 2966c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis} 29754ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 2986c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 2990ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisvoid 3000ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisfill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) 3016c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis{ 3020ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis unsigned int *code = (unsigned int *) entrypoint; 30354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3040ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis code[0] &= ~0x3fffff; 3050ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis code[0] |= (offset * sizeof(void *)) & 0x3fffff; 3060ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis __glapi_sparc_icache_flush(&code[0]); 3070ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis} 3086c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 3096c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 3100ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis#else /* USE_*_ASM */ 31154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3120ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisstatic void 3130ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisinit_glapi_relocs( void ) 31454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis{ 3156c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis} 31654ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3176c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 3180ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis_glapi_proc 3190ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisgenerate_entrypoint(GLuint functionOffset) 3206c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis{ 3210ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis (void) functionOffset; 3220ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis return NULL; 3236c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis} 3246c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis 32554ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 3266c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisvoid 3276c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzisfill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) 3286c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis{ 32954ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis /* an unimplemented architecture */ 33054ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis (void) entrypoint; 33154ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis (void) offset; 3326c8e5151f14bc642e3995a42ad0f90f407c04d5cGeorge Sapountzis} 33354ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis 33454ba95a4de749de1da73b3917aac99eb1d57d7faGeorge Sapountzis#endif /* USE_*_ASM */ 3350ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 3360ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis 3370ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisvoid 3380ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzisinit_glapi_relocs_once( void ) 3390ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis{ 340a2f28ceea22254f09ee37039eec873ccdf689e6cMatt Turner#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) 3410ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis static pthread_once_t once_control = PTHREAD_ONCE_INIT; 3420ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis pthread_once( & once_control, init_glapi_relocs ); 3430ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis#endif 3440ed0114de9f057e928124bada7289a4496a6d35fGeorge Sapountzis} 345