summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-02-11 18:14:57 -0800
committerDylan Baker <baker.dylan.c@gmail.com>2015-06-22 14:13:37 -0700
commitc89697294babd011e8a1eb8c95865e9d0e14a79b (patch)
tree534180c28e1e4a2b2393aff8e73fe936bb8f6fce
parent500ebf06df2daa49836e8c936cd309e377206942 (diff)
glapi: gl_x86_asm.py: Use mako
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--src/mapi/glapi/gen/Makefile.am2
-rw-r--r--src/mapi/glapi/gen/gl_x86_asm.py195
-rw-r--r--src/mapi/glapi/gen/templates/glapi_x86.S.mako190
3 files changed, 195 insertions, 192 deletions
diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
index 2b67dc65dd..6afe0de16d 100644
--- a/src/mapi/glapi/gen/Makefile.am
+++ b/src/mapi/glapi/gen/Makefile.am
@@ -259,7 +259,7 @@ $(MESA_GLAPI_DIR)/glapi_gentable.c: gl_gentable.py $(COMMON) templates/glapi_gen
######################################################################
-$(MESA_GLAPI_DIR)/glapi_x86.S: gl_x86_asm.py $(COMMON)
+$(MESA_GLAPI_DIR)/glapi_x86.S: gl_x86_asm.py $(COMMON) templates/glapi_x86.S.mako
$(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml > $@
$(MESA_GLAPI_DIR)/glapi_x86-64.S: gl_x86-64_asm.py $(COMMON)
diff --git a/src/mapi/glapi/gen/gl_x86_asm.py b/src/mapi/glapi/gen/gl_x86_asm.py
index c0c7941ce1..70189c4c19 100644
--- a/src/mapi/glapi/gen/gl_x86_asm.py
+++ b/src/mapi/glapi/gen/gl_x86_asm.py
@@ -27,196 +27,9 @@
import argparse
-import license
import gl_XML, glX_XML
+from python import templates
-class PrintGenericStubs(gl_XML.gl_print_base):
-
- def __init__(self):
- gl_XML.gl_print_base.__init__(self)
-
- self.name = "gl_x86_asm.py (from Mesa)"
- self.license = license.bsd_license_template % ( \
-"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
-(C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
- return
-
-
- def get_stack_size(self, f):
- size = 0
- for p in f.parameterIterator():
- if p.is_padding:
- continue
-
- size += p.get_stack_size()
-
- return size
-
-
- def printRealHeader(self):
- print '#include "x86/assyntax.h"'
- print ''
- print '#if defined(STDCALL_API)'
- print '# if defined(USE_MGL_NAMESPACE)'
- print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
- print '# else'
- print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
- print '# endif'
- print '#else'
- print '# if defined(USE_MGL_NAMESPACE)'
- print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
- print '# define _glapi_Dispatch _mglapi_Dispatch'
- print '# else'
- print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
- print '# endif'
- print '#endif'
- print ''
- print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
- print ''
- print '#if defined(GNU_ASSEMBLER) && !defined(__MINGW32__) && !defined(__APPLE__)'
- print '#define GLOBL_FN(x) GLOBL x ; .type x, @function'
- print '#else'
- print '#define GLOBL_FN(x) GLOBL x'
- print '#endif'
- print ''
- print ''
- print '#ifdef GLX_USE_TLS'
- print ''
- print '#ifdef GLX_X86_READONLY_TEXT'
- print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)'
- print '#else'
- print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */'
- print '#endif'
- print ''
- print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
- print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
- print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
- print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
- print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
- print '\tCTX_INSNS ; \\'
- print '\tJMP(GL_OFFSET(off))'
- print ''
- print '#elif defined(HAVE_PTHREAD)'
- print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
- print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
- print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
- print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
- print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
- print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
- print '\tJE(1f) ;\t\t\t\t\t\\'
- print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
- print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
- print '\tJMP(GL_OFFSET(off))'
- print '#else'
- print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
- print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
- print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
- print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
- print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
- print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
- print '\tJE(1f) ;\t\t\t\t\t\\'
- print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
- print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
- print '\tJMP(GL_OFFSET(off))'
- print '#endif'
- print ''
- print '#ifdef HAVE_ALIAS'
- print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
- print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
- print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
- print '#else'
- print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
- print ' GL_STUB(fn, off, fn_alt)'
- print '#endif'
- print ''
- print 'SEG_TEXT'
- print ''
- print '#ifdef GLX_USE_TLS'
- print ''
- print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
- print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
- print 'ALIGNTEXT16'
- print 'GLNAME(_x86_get_dispatch):'
- print '\tcall 1f'
- print '1:\tpopl %eax'
- print '\taddl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
- print '\tmovl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax'
- print '\tret'
- print ''
- print '#elif defined(HAVE_PTHREAD)'
- print 'EXTERN GLNAME(_glapi_Dispatch)'
- print 'EXTERN GLNAME(_gl_DispatchTSD)'
- print 'EXTERN GLNAME(pthread_getspecific)'
- print ''
- print 'ALIGNTEXT16'
- print 'GLNAME(_x86_get_dispatch):'
- print '\tSUB_L(CONST(24), ESP)'
- print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
- print '\tCALL(GLNAME(pthread_getspecific))'
- print '\tADD_L(CONST(28), ESP)'
- print '\tRET'
- print '#else'
- print 'EXTERN GLNAME(_glapi_get_dispatch)'
- print '#endif'
- print ''
-
- print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )'
- print '\t\t.section\twtext, "awx", @progbits'
- print '#endif /* defined( GLX_USE_TLS ) */'
-
- print ''
- print '\t\tALIGNTEXT16'
- print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
- print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
- print 'GLNAME(gl_dispatch_functions_start):'
- print ''
- return
-
-
- def printRealFooter(self):
- print ''
- print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
- print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
- print '\t\tALIGNTEXT16'
- print 'GLNAME(gl_dispatch_functions_end):'
- print ''
- print '#if defined (__ELF__) && defined (__linux__)'
- print ' .section .note.GNU-stack,"",%progbits'
- print '#endif'
- return
-
-
- def printBody(self, api):
- for f in api.functionIterateByOffset():
- name = f.dispatch_name()
- stack = self.get_stack_size(f)
- alt = "%s@%u" % (name, stack)
-
- print '\tGL_STUB(%s, %d, %s)' % (name, f.offset, alt)
-
- if not f.is_static_entry_point(f.name):
- print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt)
-
-
- for f in api.functionIterateByOffset():
- name = f.dispatch_name()
- stack = self.get_stack_size(f)
- alt = "%s@%u" % (name, stack)
-
- for n in f.entry_points:
- if f.is_static_entry_point(n):
- if n != f.name:
- alt2 = "%s@%u" % (n, stack)
- text = '\tGL_STUB_ALIAS(%s, %d, %s, %s, %s)' % (n, f.offset, alt2, name, alt)
-
- if f.has_different_protocol(n):
- print '#ifndef GLX_INDIRECT_RENDERING'
- print text
- print '#endif'
- else:
- print text
-
- return
def _parser():
parser = argparse.ArgumentParser()
@@ -229,10 +42,10 @@ def _parser():
def main():
args = _parser()
- printer = PrintGenericStubs()
-
api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory())
- printer.Print(api)
+ template = templates.LOOKUP.get_template('glapi_x86.S.mako')
+
+ print template.render(api=api)
if __name__ == '__main__':
diff --git a/src/mapi/glapi/gen/templates/glapi_x86.S.mako b/src/mapi/glapi/gen/templates/glapi_x86.S.mako
new file mode 100644
index 0000000000..947135ea3f
--- /dev/null
+++ b/src/mapi/glapi/gen/templates/glapi_x86.S.mako
@@ -0,0 +1,190 @@
+## Copyright (C) 2015 Intel Corporation
+##
+## 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.
+##
+## In case it isn't obvious, this ## commented copyright header will not be
+## rendered into the actual template, it applies to the template.
+##
+<%namespace name="utils" file="utils.mako"/>
+
+${utils.copyright(['1999-2001 Brian Paul', '2005 IBM Corporation'], 'gl_x86_asm.py (from Mesa)')}
+
+#include "x86/assyntax.h"
+
+#if defined(STDCALL_API)
+# if defined(USE_MGL_NAMESPACE)
+# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))
+# else
+# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))
+# endif
+#else
+# if defined(USE_MGL_NAMESPACE)
+# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))
+# define _glapi_Dispatch _mglapi_Dispatch
+# else
+# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))
+# endif
+#endif
+
+#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))
+
+#if defined(GNU_ASSEMBLER) && !defined(__MINGW32__) && !defined(__APPLE__)
+#define GLOBL_FN(x) GLOBL x ; .type x, @function
+#else
+#define GLOBL_FN(x) GLOBL x
+#endif
+
+#if defined(HAVE_PTHREAD) || defined(_WIN32)
+# define THREADS
+#endif
+
+#ifdef GLX_USE_TLS
+
+#ifdef GLX_X86_READONLY_TEXT
+# define CTX_INSNS MOV_L(GS:(EAX), EAX)
+#else
+# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */
+#endif
+
+# define GL_STUB(fn,off,fn_alt) ${'\\'}
+ALIGNTEXT16; ${'\\'}
+GLOBL_FN(GL_PREFIX(fn, fn_alt)); ${'\\'}
+GL_PREFIX(fn, fn_alt): ${'\\'}
+ CALL(_x86_get_dispatch) ; ${'\\'}
+ CTX_INSNS ; ${'\\'}
+ JMP(GL_OFFSET(off))
+
+#elif defined(HAVE_PTHREAD)
+# define GL_STUB(fn,off,fn_alt) ${'\\'}
+ALIGNTEXT16; ${'\\'}
+GLOBL_FN(GL_PREFIX(fn, fn_alt)); ${'\\'}
+GL_PREFIX(fn, fn_alt): ${'\\'}
+ MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; ${'\\'}
+ TEST_L(EAX, EAX) ; ${'\\'}
+ JE(1f) ; ${'\\'}
+ JMP(GL_OFFSET(off)) ; ${'\\'}
+1: CALL(_x86_get_dispatch) ; ${'\\'}
+ JMP(GL_OFFSET(off))
+#elif defined(THREADS)
+# define GL_STUB(fn,off,fn_alt) ${'\\'}
+ALIGNTEXT16; ${'\\'}
+GLOBL_FN(GL_PREFIX(fn, fn_alt)); ${'\\'}
+GL_PREFIX(fn, fn_alt): ${'\\'}
+ MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; ${'\\'}
+ TEST_L(EAX, EAX) ; ${'\\'}
+ JE(1f) ; ${'\\'}
+ JMP(GL_OFFSET(off)) ; ${'\\'}
+1: CALL(_glapi_get_dispatch) ; ${'\\'}
+ JMP(GL_OFFSET(off))
+#else /* Non-threaded version. */
+# define GL_STUB(fn,off,fn_alt) ${'\\'}
+ALIGNTEXT16; ${'\\'}
+GLOBL_FN(GL_PREFIX(fn, fn_alt)); ${'\\'}
+GL_PREFIX(fn, fn_alt): ${'\\'}
+ MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; ${'\\'}
+ JMP(GL_OFFSET(off))
+#endif
+
+#ifdef HAVE_ALIAS
+# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt) ${'\\'}
+ .globl GL_PREFIX(fn, fn_alt) ; ${'\\'}
+ .set GL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)
+#else
+# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt) ${'\\'}
+ GL_STUB(fn, off, fn_alt)
+#endif
+
+SEG_TEXT
+
+#ifdef GLX_USE_TLS
+
+ GLOBL GLNAME(_x86_get_dispatch)
+ HIDDEN(GLNAME(_x86_get_dispatch))
+ALIGNTEXT16
+GLNAME(_x86_get_dispatch):
+ call 1f
+1: popl %eax
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax
+ movl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax
+ ret
+
+#elif defined(HAVE_PTHREAD)
+EXTERN GLNAME(_glapi_Dispatch)
+EXTERN GLNAME(_gl_DispatchTSD)
+EXTERN GLNAME(pthread_getspecific)
+
+ALIGNTEXT16
+GLNAME(_x86_get_dispatch):
+ SUB_L(CONST(24), ESP)
+ PUSH_L(GLNAME(_gl_DispatchTSD))
+ CALL(GLNAME(pthread_getspecific))
+ ADD_L(CONST(28), ESP)
+ RET
+#elif defined(THREADS)
+EXTERN GLNAME(_glapi_get_dispatch)
+#endif
+
+
+#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )
+ .section wtext, "awx", @progbits
+#endif /* defined( GLX_USE_TLS ) */
+
+
+ ALIGNTEXT16
+ GLOBL GLNAME(gl_dispatch_functions_start)
+ HIDDEN(GLNAME(gl_dispatch_functions_start))
+GLNAME(gl_dispatch_functions_start):
+
+% for f in api.functionIterateByOffset():
+ <%
+ name = f.dispatch_name()
+ stack = sum(p.get_stack_size() for p in f.parameterIterator() if not p.is_padding)
+ %>\
+ GL_STUB(${name}, ${f.offset}, ${name} @ ${stack})
+ % if not f.is_static_entry_point(f.name):
+ HIDDEN(GL_PREFIX(${name}, ${name} @ ${stack}))
+ % endif
+% endfor
+
+% for f in api.functionIterateByOffset():
+ <%
+ name = f.dispatch_name()
+ stack = sum(p.get_stack_size() for p in f.parameterIterator() if not p.is_padding)
+ %>\
+ % for n in f.entry_points:
+ % if f.is_static_entry_point(n) and n != f.name:
+ % if f.has_different_protocol(n):
+ #ifndef GLX_INDIRECT_RENDERING
+ GL_STUB_ALIAS(${n}, ${f.offset}, ${n} @ ${stack}, ${name}, ${name} @ ${stack})
+ #endif
+ % else:
+ GL_STUB_ALIAS(${n}, ${f.offset}, ${n} @ ${stack}, ${name}, ${name} @ ${stack})
+ % endif
+ % endif
+ % endfor
+% endfor
+
+ GLOBL GLNAME(gl_dispatch_functions_end)
+ HIDDEN(GLNAME(gl_dispatch_functions_end))
+ ALIGNTEXT16
+GLNAME(gl_dispatch_functions_end):
+
+#if defined (__ELF__) && defined (__linux__)
+ .section .note.GNU-stack,"",%progbits
+#endif