summaryrefslogtreecommitdiffstats
path: root/src/mapi
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-04-22 15:33:43 +0800
committerChia-I Wu <[email protected]>2010-05-07 10:41:12 +0800
commit56eb5d7e852ab04b45ba09831e2c8fbadcda8c40 (patch)
tree6d8363eb8b33f09a6fc0948106302d9ce37086f6 /src/mapi
parent75143ef05576ee9f25ee176bc28c3c4d03705bf5 (diff)
mapi: Add x86 dispatcher.
Diffstat (limited to 'src/mapi')
-rw-r--r--src/mapi/mapi/entry.c13
-rw-r--r--src/mapi/mapi/entry_x86_tls.h120
-rw-r--r--src/mapi/mapi/entry_x86_tsd.h89
-rw-r--r--src/mapi/mapi/mapi_tmp.h25
4 files changed, 246 insertions, 1 deletions
diff --git a/src/mapi/mapi/entry.c b/src/mapi/mapi/entry.c
index b38df073918..968aa445285 100644
--- a/src/mapi/mapi/entry.c
+++ b/src/mapi/mapi/entry.c
@@ -26,9 +26,18 @@
* Chia-I Wu <[email protected]>
*/
+#include "entry.h"
+
+#if defined(USE_X86_ASM) && defined(__GNUC__)
+# ifdef GLX_USE_TLS
+# include "entry_x86_tls.h"
+# else
+# include "entry_x86_tsd.h"
+# endif
+#else
+
#include <stdlib.h>
#include "u_current.h"
-#include "entry.h"
#include "table.h"
/* C version of the public entries */
@@ -50,3 +59,5 @@ void
entry_patch(mapi_func entry, int slot)
{
}
+
+#endif /* asm */
diff --git a/src/mapi/mapi/entry_x86_tls.h b/src/mapi/mapi/entry_x86_tls.h
new file mode 100644
index 00000000000..de0498181de
--- /dev/null
+++ b/src/mapi/mapi/entry_x86_tls.h
@@ -0,0 +1,120 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu <[email protected]>
+ */
+
+#include <string.h>
+#include "u_execmem.h"
+#include "u_macros.h"
+
+__asm__(".text");
+
+__asm__("x86_current_tls:\n\t"
+ "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"
+ "ret");
+
+#ifndef GLX_X86_READONLY_TEXT
+__asm__(".section wtext, \"awx\", @progbits\n"
+ ".balign 16\n"
+ "x86_entry_start:");
+#endif /* GLX_X86_READONLY_TEXT */
+
+#define STUB_ASM_ENTRY(func) \
+ ".globl " func "\n" \
+ ".type " func ", @function\n" \
+ ".balign 16\n" \
+ func ":"
+
+#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
+#include "mapi_tmp.h"
+
+#ifndef GLX_X86_READONLY_TEXT
+__asm__(".balign 16\n"
+ "x86_entry_end:");
+__asm__(".text");
+#endif /* GLX_X86_READONLY_TEXT */
+
+extern unsigned long
+x86_current_tls();
+
+void
+entry_patch_public(void)
+{
+#ifndef GLX_X86_READONLY_TEXT
+ extern char x86_entry_start[];
+ extern char x86_entry_end[];
+ char patch[8] = {
+ 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */
+ 0x90, 0x90 /* nop's */
+ };
+ char *entry;
+
+ *((unsigned long *) (patch + 2)) = x86_current_tls();
+
+ for (entry = x86_entry_start; entry < x86_entry_end; entry += 16)
+ memcpy(entry, patch, sizeof(patch));
+#endif
+}
+
+void
+entry_patch(mapi_func entry, int slot)
+{
+ void *code = (void *) entry;
+ *((unsigned long *) (code + 8)) = slot * sizeof(mapi_func);
+}
+
+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 */
+ };
+ void *code;
+ mapi_func entry;
+
+ code = u_execmem_alloc(sizeof(code_templ));
+ if (!code)
+ return NULL;
+
+ memcpy(code, code_templ, sizeof(code_templ));
+
+ *((unsigned long *) (code + 2)) = x86_current_tls();
+ entry = (mapi_func) code;
+ entry_patch(entry, slot);
+
+ return entry;
+}
diff --git a/src/mapi/mapi/entry_x86_tsd.h b/src/mapi/mapi/entry_x86_tsd.h
new file mode 100644
index 00000000000..d31e0676f07
--- /dev/null
+++ b/src/mapi/mapi/entry_x86_tsd.h
@@ -0,0 +1,89 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu <[email protected]>
+ */
+
+#include <string.h>
+#include "u_execmem.h"
+#include "u_macros.h"
+
+#define X86_ENTRY_SIZE 32
+
+__asm__(".text");
+
+#define STUB_ASM_ENTRY(func) \
+ ".globl " func "\n" \
+ ".type " func ", @function\n" \
+ ".balign 32\n" \
+ func ":"
+
+#define STUB_ASM_CODE(slot) \
+ "movl _glapi_Dispatch, %eax\n\t" \
+ "testl %eax, %eax\n\t" \
+ "je 1f\n\t" \
+ "jmp *(4 * " slot ")(%eax)\n" \
+ "1:\n\t" \
+ "call _glapi_get_dispatch\n\t" \
+ "jmp *(4 * " slot ")(%eax)"
+
+#define MAPI_TMP_STUB_ASM_GCC
+#include "mapi_tmp.h"
+
+__asm__(".balign 32\n"
+ "x86_entry_end:");
+
+void
+entry_patch_public(void)
+{
+}
+
+void
+entry_patch(mapi_func entry, int slot)
+{
+ void *code = (void *) entry;
+
+ *((unsigned long *) (code + 11)) = slot * sizeof(mapi_func);
+ *((unsigned long *) (code + 22)) = slot * sizeof(mapi_func);
+}
+
+mapi_func
+entry_generate(int slot)
+{
+ extern const char x86_entry_end[];
+ const char *code_templ = x86_entry_end - X86_ENTRY_SIZE;
+ void *code;
+ mapi_func entry;
+
+ code = u_execmem_alloc(X86_ENTRY_SIZE);
+ if (!code)
+ return NULL;
+
+ memcpy(code, code_templ, X86_ENTRY_SIZE);
+ entry = (mapi_func) code;
+ entry_patch(entry, slot);
+
+ return entry;
+}
diff --git a/src/mapi/mapi/mapi_tmp.h b/src/mapi/mapi/mapi_tmp.h
index da4e8ae54fa..79beca47d2a 100644
--- a/src/mapi/mapi/mapi_tmp.h
+++ b/src/mapi/mapi/mapi_tmp.h
@@ -184,3 +184,28 @@ const mapi_func table_noop_array[] = {
#endif /* DEBUG */
#undef MAPI_TMP_NOOP_ARRAY
#endif /* MAPI_TMP_NOOP_ARRAY */
+
+
+#ifdef MAPI_TMP_STUB_ASM_GCC
+# define STUB_ASM_ALIAS(func, to) \
+ ".globl " func "\n" \
+ ".set " func ", " to
+# define STUB_ASM_HIDE(func) \
+ ".hidden " func
+
+# define MAPI_ABI_ENTRY(ret, name, params) \
+ __asm__(STUB_ASM_ENTRY(U_CONCAT_STR(MAPI_ABI_PREFIX, name)));
+# define MAPI_ABI_CODE(ret, name, args) \
+ __asm__(STUB_ASM_CODE(U_STRINGIFY(MAPI_SLOT_ ## name)));
+# define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
+ __asm__(STUB_ASM_ALIAS(U_CONCAT_STR(MAPI_ABI_PREFIX, name), \
+ U_CONCAT_STR(MAPI_ABI_PREFIX, alias)));
+# define MAPI_ABI_ENTRY_HIDDEN(ret, name, params) \
+ __asm__(STUB_ASM_HIDE(U_CONCAT_STR(MAPI_ABI_PREFIX, name))); \
+ MAPI_ABI_ENTRY(ret, name, params);
+# define MAPI_ALIAS_ENTRY_HIDDEN(alias, ret, name, params) \
+ __asm__(STUB_ASM_HIDE(U_CONCAT_STR(MAPI_ABI_PREFIX, name))); \
+ MAPI_ALIAS_ENTRY(alias, ret, name, params);
+# include MAPI_ABI_HEADER
+#undef MAPI_TMP_STUB_ASM_GCC
+#endif /* MAPI_TMP_STUB_ASM_GCC */