diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-11-22 02:46:21 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-11-22 02:46:21 +0000 |
commit | ed6fe460c1a7f4ad512a2c386ceca3a0cd506072 (patch) | |
tree | 0a424c9518f4832470626d0cfbdc7c76645e25d7 /lib/mesa | |
parent | 73ca1c327417acc06ae584efee094eb8166b7f13 (diff) |
import Mesa 11.0.6
Diffstat (limited to 'lib/mesa')
-rw-r--r-- | lib/mesa/src/mapi/entry_x86-64_tls.h | 60 | ||||
-rw-r--r-- | lib/mesa/src/mapi/entry_x86_tls.h | 67 | ||||
-rw-r--r-- | lib/mesa/src/mapi/glapi/glapi.h | 55 | ||||
-rw-r--r-- | lib/mesa/src/mapi/glapi/glapi_entrypoint.c | 114 | ||||
-rw-r--r-- | lib/mesa/src/mapi/glapi/glapi_priv.h | 33 |
5 files changed, 213 insertions, 116 deletions
diff --git a/lib/mesa/src/mapi/entry_x86-64_tls.h b/lib/mesa/src/mapi/entry_x86-64_tls.h index f2fea5189..5c03b0456 100644 --- a/lib/mesa/src/mapi/entry_x86-64_tls.h +++ b/lib/mesa/src/mapi/entry_x86-64_tls.h @@ -25,17 +25,6 @@ * Chia-I Wu <olv@lunarg.com> */ -#ifdef __CET__ -#define ENDBR "endbr64\n\t" -#else -#define ENDBR -#endif - -#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY -#define HIDDEN __attribute__((visibility("hidden"))) -#else -#define HIDDEN -#endif __asm__(".text\n" ".balign 32\n" @@ -47,30 +36,23 @@ __asm__(".text\n" ".balign 32\n" \ func ":" -#ifndef __ILP32__ - #define STUB_ASM_CODE(slot) \ - ENDBR \ - "movq _glapi_tls_Dispatch@GOTTPOFF(%rip), %rax\n\t" \ + "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t" \ "movq %fs:(%rax), %r11\n\t" \ "jmp *(8 * " slot ")(%r11)" -#else - -#define STUB_ASM_CODE(slot) \ - ENDBR \ - "movq _glapi_tls_Dispatch@GOTTPOFF(%rip), %rax\n\t" \ - "movl %fs:(%rax), %r11d\n\t" \ - "movl 4*" slot "(%r11d), %r11d\n\t" \ - "jmp *%r11" - -#endif - #define MAPI_TMP_STUB_ASM_GCC #include "mapi_tmp.h" #ifndef MAPI_MODE_BRIDGE +__asm__("x86_64_current_tls:\n\t" + "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t" + "ret"); + +extern unsigned long +x86_64_current_tls(); + #include <string.h> #include "u_execmem.h" @@ -79,8 +61,8 @@ entry_patch_public(void) { } -extern char -x86_64_entry_start[] HIDDEN; +static char +x86_64_entry_start[]; mapi_func entry_get_public(int slot) @@ -92,37 +74,23 @@ void entry_patch(mapi_func entry, int slot) { char *code = (char *) entry; - int offset = 12; -#ifdef __ILP32__ - offset = 13; -#endif - *((unsigned int *) (code + offset)) = slot * sizeof(mapi_func); + *((unsigned int *) (code + 12)) = slot * sizeof(mapi_func); } mapi_func entry_generate(int slot) { - const char code_templ[] = { -#ifndef __ILP32__ + const char code_templ[16] = { /* movq %fs:0, %r11 */ 0x64, 0x4c, 0x8b, 0x1c, 0x25, 0x00, 0x00, 0x00, 0x00, /* jmp *0x1234(%r11) */ 0x41, 0xff, 0xa3, 0x34, 0x12, 0x00, 0x00, -#else - /* movl %fs:0, %r11d */ - 0x64, 0x44, 0x8b, 0x1c, 0x25, 0x00, 0x00, 0x00, 0x00, - /* movl 0x1234(%r11d), %r11d */ - 0x67, 0x45, 0x8b, 0x9b, 0x34, 0x12, 0x00, 0x00, - /* jmp *%r11 */ - 0x41, 0xff, 0xe3, -#endif }; - unsigned long long addr; + unsigned long addr; char *code; mapi_func entry; - __asm__("movq _glapi_tls_Dispatch@GOTTPOFF(%%rip), %0" - : "=r" (addr)); + addr = x86_64_current_tls(); if ((addr >> 32) != 0xffffffff) return NULL; addr &= 0xffffffff; diff --git a/lib/mesa/src/mapi/entry_x86_tls.h b/lib/mesa/src/mapi/entry_x86_tls.h index 9829968c0..46d2eced2 100644 --- a/lib/mesa/src/mapi/entry_x86_tls.h +++ b/lib/mesa/src/mapi/entry_x86_tls.h @@ -27,20 +27,6 @@ #include <string.h> -#ifdef __CET__ -#define ENDBR "endbr32\n\t" -#else -#define ENDBR -#endif - -#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY -#define HIDDEN __attribute__((visibility("hidden"))) -#else -#define HIDDEN -#endif - -#define X86_ENTRY_SIZE 32 - __asm__(".text"); __asm__("x86_current_tls:\n\t" @@ -48,7 +34,7 @@ __asm__("x86_current_tls:\n\t" "1:\n\t" "popl %eax\n\t" "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" - "movl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax\n\t" + "movl " ENTRY_CURRENT_TABLE "@GOTNTPOFF(%eax), %eax\n\t" "ret"); #ifndef GLX_X86_READONLY_TEXT @@ -64,14 +50,9 @@ __asm__(".balign 16\n" ".balign 16\n" \ func ":" -#define STUB_ASM_CODE(slot) \ - ENDBR \ - "call 1f\n" \ - "1:\n\t" \ - "popl %eax\n\t" \ - "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" \ - "movl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax\n\t" \ - "movl %gs:(%eax), %eax\n\t" \ +#define STUB_ASM_CODE(slot) \ + "call x86_current_tls\n\t" \ + "movl %gs:(%eax), %eax\n\t" \ "jmp *(4 * " slot ")(%eax)" #define MAPI_TMP_STUB_ASM_GCC @@ -90,28 +71,30 @@ __asm__(".text"); extern unsigned long x86_current_tls(); -extern char x86_entry_start[] HIDDEN; -extern char x86_entry_end[] HIDDEN; - -static inline mapi_func -entry_generate_or_patch(int, char *, size_t); +static char x86_entry_start[]; +static char x86_entry_end[]; void entry_patch_public(void) { #ifndef GLX_X86_READONLY_TEXT + char patch[8] = { + 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ + 0x90, 0x90 /* nop's */ + }; char *entry; - int slot = 0; - for (entry = x86_entry_start; entry < x86_entry_end; - entry += X86_ENTRY_SIZE, ++slot) - entry_generate_or_patch(slot, entry, X86_ENTRY_SIZE); + + *((unsigned long *) (patch + 2)) = x86_current_tls(); + + for (entry = x86_entry_start; entry < x86_entry_end; entry += 16) + memcpy(entry, patch, sizeof(patch)); #endif } mapi_func entry_get_public(int slot) { - return (mapi_func) (x86_entry_start + slot * X86_ENTRY_SIZE); + return (mapi_func) (x86_entry_start + slot * 16); } void @@ -121,21 +104,19 @@ entry_patch(mapi_func entry, int slot) *((unsigned long *) (code + 8)) = slot * sizeof(mapi_func); } -static inline mapi_func -entry_generate_or_patch(int slot, char *code, size_t size) +mapi_func +entry_generate(int slot) { const char code_templ[16] = { 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ 0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */ 0x90, 0x90, 0x90, 0x90 /* nop's */ }; + char *code; mapi_func entry; - if (code == NULL) { - size = sizeof(code_templ); - code = u_execmem_alloc(size); - } - if (!code || size < sizeof(code_templ)) + code = u_execmem_alloc(sizeof(code_templ)); + if (!code) return NULL; memcpy(code, code_templ, sizeof(code_templ)); @@ -147,10 +128,4 @@ entry_generate_or_patch(int slot, char *code, size_t size) return entry; } -mapi_func -entry_generate(int slot) -{ - return entry_generate_or_patch(slot, NULL, 0); -} - #endif /* MAPI_MODE_BRIDGE */ diff --git a/lib/mesa/src/mapi/glapi/glapi.h b/lib/mesa/src/mapi/glapi/glapi.h index d51ba0ff9..673295bca 100644 --- a/lib/mesa/src/mapi/glapi/glapi.h +++ b/lib/mesa/src/mapi/glapi/glapi.h @@ -45,8 +45,6 @@ #define _GLAPI_H #include "util/macros.h" -#include "util/u_thread.h" -#include "util/detect_os.h" #ifdef __cplusplus @@ -63,7 +61,7 @@ extern "C" { # else # define _GLAPI_EXPORT __declspec(dllimport) # endif -# elif defined(__GNUC__) +# elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define _GLAPI_EXPORT __attribute__((visibility("default"))) # else # define _GLAPI_EXPORT @@ -71,32 +69,52 @@ extern "C" { #endif /* _GLAPI_NO_EXPORTS */ +/* Is this needed? It is incomplete anyway. */ +#ifdef USE_MGL_NAMESPACE +#define _glapi_set_dispatch _mglapi_set_dispatch +#define _glapi_get_dispatch _mglapi_get_dispatch +#define _glapi_set_context _mglapi_set_context +#define _glapi_get_context _mglapi_get_context +#define _glapi_Dispatch _mglapi_Dispatch +#define _glapi_Context _mglapi_Context +#endif + typedef void (*_glapi_proc)(void); typedef void (*_glapi_nop_handler_proc)(const char *name); struct _glapi_table; -#if DETECT_OS_WINDOWS -extern __THREAD_INITIAL_EXEC struct _glapi_table * _glapi_tls_Dispatch; -extern __THREAD_INITIAL_EXEC void * _glapi_tls_Context; -#else -_GLAPI_EXPORT extern __THREAD_INITIAL_EXEC struct _glapi_table * _glapi_tls_Dispatch; -_GLAPI_EXPORT extern __THREAD_INITIAL_EXEC void * _glapi_tls_Context; -#endif + +#if defined (GLX_USE_TLS) + +_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch + __attribute__((tls_model("initial-exec"))); + +_GLAPI_EXPORT extern __thread void * _glapi_tls_Context + __attribute__((tls_model("initial-exec"))); _GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch; _GLAPI_EXPORT extern const void *_glapi_Context; -#if DETECT_OS_WINDOWS && !defined(MAPI_MODE_UTIL) && !defined(MAPI_MODE_GLAPI) -# define GET_DISPATCH() _glapi_get_dispatch() -# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_get_context() -#else # define GET_DISPATCH() _glapi_tls_Dispatch # define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_tls_Context -#endif -_GLAPI_EXPORT void +#else + +_GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch; +_GLAPI_EXPORT extern void *_glapi_Context; + +#define GET_DISPATCH() \ + (likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch()) + +#define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) \ + (likely(_glapi_Context) ? _glapi_Context : _glapi_get_context()) + +#endif /* defined (GLX_USE_TLS) */ + + +void _glapi_destroy_multithread(void); @@ -140,14 +158,9 @@ _GLAPI_EXPORT const char * _glapi_get_proc_name(unsigned int offset); -#if defined(GLX_USE_APPLEGL) || defined(GLX_USE_WINDOWSGL) _GLAPI_EXPORT struct _glapi_table * _glapi_create_table_from_handle(void *handle, const char *symbol_prefix); -_GLAPI_EXPORT void -_glapi_table_patch(struct _glapi_table *, const char *name, void *wrapper); -#endif - _GLAPI_EXPORT void _glapi_set_nop_handler(_glapi_nop_handler_proc func); diff --git a/lib/mesa/src/mapi/glapi/glapi_entrypoint.c b/lib/mesa/src/mapi/glapi/glapi_entrypoint.c index e2c4b997c..f1f7f5e59 100644 --- a/lib/mesa/src/mapi/glapi/glapi_entrypoint.c +++ b/lib/mesa/src/mapi/glapi/glapi_entrypoint.c @@ -38,8 +38,12 @@ #ifdef USE_X86_ASM +#if defined( GLX_USE_TLS ) extern GLubyte gl_dispatch_functions_start[]; extern GLubyte gl_dispatch_functions_end[]; +#else +extern const GLubyte gl_dispatch_functions_start[]; +#endif #endif /* USE_X86_ASM */ @@ -64,7 +68,7 @@ get_entrypoint_address(unsigned int functionOffset) static void init_glapi_relocs( void ) { -#if !defined(GLX_X86_READONLY_TEXT) +#if defined(GLX_USE_TLS) && !defined(GLX_X86_READONLY_TEXT) extern unsigned long _x86_get_dispatch(void); char run_time_patch[] = { 0x65, 0xa1, 0, 0, 0, 0 /* movl %gs:0,%eax */ @@ -117,7 +121,12 @@ fill_in_entrypoint_offset(_glapi_proc entrypoint, unsigned int offset) { GLubyte * const code = (GLubyte *) entrypoint; +#if defined(GLX_USE_TLS) *((unsigned int *)(code + 8)) = 4 * offset; +#else + *((unsigned int *)(code + 11)) = 4 * offset; + *((unsigned int *)(code + 22)) = 4 * offset; +#endif } @@ -128,7 +137,9 @@ extern void __glapi_sparc_icache_flush(unsigned int *); static void init_glapi_relocs( void ) { +#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) static const unsigned int template[] = { +#ifdef GLX_USE_TLS 0x05000000, /* sethi %hi(_glapi_tls_Dispatch), %g2 */ 0x8730e00a, /* srl %g3, 10, %g3 */ 0x8410a000, /* or %g2, %lo(_glapi_tls_Dispatch), %g2 */ @@ -141,12 +152,58 @@ init_glapi_relocs( void ) #endif 0x81c04000, /* jmp %g1 */ 0x01000000, /* nop */ +#else +#ifdef __arch64__ + 0x03000000, /* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */ + 0x05000000, /* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */ + 0x82106000, /* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */ + 0x8730e00a, /* 64-bit 0x0c --> srl %g3, 10, %g3 */ + 0x83287020, /* 64-bit 0x10 --> sllx %g1, 32, %g1 */ + 0x82004002, /* 64-bit 0x14 --> add %g1, %g2, %g1 */ + 0xc2586000, /* 64-bit 0x18 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */ +#else + 0x03000000, /* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */ + 0x8730e00a, /* 32-bit 0x04 --> srl %g3, 10, %g3 */ + 0xc2006000, /* 32-bit 0x08 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ +#endif + 0x80a06000, /* --> cmp %g1, 0 */ + 0x02800005, /* --> be +4*5 */ + 0x01000000, /* --> nop */ +#ifdef __arch64__ + 0xc2584003, /* 64-bit --> ldx [%g1 + %g3], %g1 */ +#else + 0xc2004003, /* 32-bit --> ld [%g1 + %g3], %g1 */ +#endif + 0x81c04000, /* --> jmp %g1 */ + 0x01000000, /* --> nop */ +#ifdef __arch64__ + 0x9de3bf80, /* 64-bit --> save %sp, -128, %sp */ +#else + 0x9de3bfc0, /* 32-bit --> save %sp, -64, %sp */ +#endif + 0xa0100003, /* --> mov %g3, %l0 */ + 0x40000000, /* --> call _glapi_get_dispatch */ + 0x01000000, /* --> nop */ + 0x82100008, /* --> mov %o0, %g1 */ + 0x86100010, /* --> mov %l0, %g3 */ + 0x10bffff7, /* --> ba -4*9 */ + 0x81e80000, /* --> restore */ +#endif }; +#ifdef GLX_USE_TLS extern unsigned int __glapi_sparc_tls_stub; extern unsigned long __glapi_sparc_get_dispatch(void); unsigned int *code = &__glapi_sparc_tls_stub; unsigned long dispatch = __glapi_sparc_get_dispatch(); +#else + extern unsigned int __glapi_sparc_pthread_stub; + unsigned int *code = &__glapi_sparc_pthread_stub; + unsigned long dispatch = (unsigned long) &_glapi_Dispatch; + unsigned long call_dest = (unsigned long ) &_glapi_get_dispatch; + int idx; +#endif +#ifdef GLX_USE_TLS code[0] = template[0] | (dispatch >> 10); code[1] = template[1]; __glapi_sparc_icache_flush(&code[0]); @@ -158,20 +215,72 @@ init_glapi_relocs( void ) __glapi_sparc_icache_flush(&code[4]); code[6] = template[6]; __glapi_sparc_icache_flush(&code[6]); +#else +#if defined(__arch64__) + code[0] = template[0] | (dispatch >> (32 + 10)); + code[1] = template[1] | ((dispatch & 0xffffffff) >> 10); + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | ((dispatch >> 32) & 0x3ff); + code[3] = template[3]; + __glapi_sparc_icache_flush(&code[2]); + code[4] = template[4]; + code[5] = template[5]; + __glapi_sparc_icache_flush(&code[4]); + code[6] = template[6] | (dispatch & 0x3ff); + idx = 7; +#else + code[0] = template[0] | (dispatch >> 10); + code[1] = template[1]; + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | (dispatch & 0x3ff); + idx = 3; +#endif + code[idx + 0] = template[idx + 0]; + __glapi_sparc_icache_flush(&code[idx - 1]); + code[idx + 1] = template[idx + 1]; + code[idx + 2] = template[idx + 2]; + __glapi_sparc_icache_flush(&code[idx + 1]); + code[idx + 3] = template[idx + 3]; + code[idx + 4] = template[idx + 4]; + __glapi_sparc_icache_flush(&code[idx + 3]); + code[idx + 5] = template[idx + 5]; + code[idx + 6] = template[idx + 6]; + __glapi_sparc_icache_flush(&code[idx + 5]); + code[idx + 7] = template[idx + 7]; + code[idx + 8] = template[idx + 8] | + (((call_dest - ((unsigned long) &code[idx + 8])) + >> 2) & 0x3fffffff); + __glapi_sparc_icache_flush(&code[idx + 7]); + code[idx + 9] = template[idx + 9]; + code[idx + 10] = template[idx + 10]; + __glapi_sparc_icache_flush(&code[idx + 9]); + code[idx + 11] = template[idx + 11]; + code[idx + 12] = template[idx + 12]; + __glapi_sparc_icache_flush(&code[idx + 11]); + code[idx + 13] = template[idx + 13]; + __glapi_sparc_icache_flush(&code[idx + 13]); +#endif +#endif } _glapi_proc generate_entrypoint(GLuint functionOffset) { +#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) static const unsigned int template[] = { 0x07000000, /* sethi %hi(0), %g3 */ 0x8210000f, /* mov %o7, %g1 */ 0x40000000, /* call */ 0x9e100001, /* mov %g1, %o7 */ }; +#ifdef GLX_USE_TLS extern unsigned int __glapi_sparc_tls_stub; unsigned long call_dest = (unsigned long ) &__glapi_sparc_tls_stub; +#else + extern unsigned int __glapi_sparc_pthread_stub; + unsigned long call_dest = (unsigned long ) &__glapi_sparc_pthread_stub; +#endif unsigned int *code = (unsigned int *) u_execmem_alloc(sizeof(template)); if (code) { code[0] = template[0] | (functionOffset & 0x3fffff); @@ -184,6 +293,7 @@ generate_entrypoint(GLuint functionOffset) __glapi_sparc_icache_flush(&code[2]); } return (_glapi_proc) code; +#endif } @@ -228,6 +338,8 @@ fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) void init_glapi_relocs_once( void ) { +#if defined(HAVE_PTHREAD) || defined(GLX_USE_TLS) static once_flag flag = ONCE_FLAG_INIT; call_once(&flag, init_glapi_relocs); +#endif } diff --git a/lib/mesa/src/mapi/glapi/glapi_priv.h b/lib/mesa/src/mapi/glapi/glapi_priv.h index 04d8fd0c2..337913acc 100644 --- a/lib/mesa/src/mapi/glapi/glapi_priv.h +++ b/lib/mesa/src/mapi/glapi/glapi_priv.h @@ -27,12 +27,25 @@ #define _GLAPI_PRIV_H +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#include "glapi/mesa.h" +#else /* HAVE_DIX_CONFIG_H */ #define GL_GLEXT_PROTOTYPES #include "GL/gl.h" #include "GL/glext.h" +#ifndef GL_OES_fixed_point +typedef int GLfixed; +#endif typedef int GLclampx; +#ifndef GL_OES_EGL_image +typedef void *GLeglImageOES; +#endif + +#endif /* HAVE_DIX_CONFIG_H */ + #include "glapi/glapi.h" @@ -40,6 +53,16 @@ typedef int GLclampx; extern "C" { #endif +/* getproc */ + +extern void +_glapi_check_table_not_null(const struct _glapi_table *table); + + +extern void +_glapi_check_table(const struct _glapi_table *table); + + /* entrypoint */ extern void @@ -62,11 +85,17 @@ get_entrypoint_address(unsigned int functionOffset); * Size (in bytes) of dispatch function (entrypoint). */ #if defined(USE_X86_ASM) -#define DISPATCH_FUNCTION_SIZE 16 +# if defined(GLX_USE_TLS) +# define DISPATCH_FUNCTION_SIZE 16 +# else +# define DISPATCH_FUNCTION_SIZE 32 +# endif #endif #if defined(USE_X64_64_ASM) -#define DISPATCH_FUNCTION_SIZE 16 +# if defined(GLX_USE_TLS) +# define DISPATCH_FUNCTION_SIZE 16 +# endif #endif |