651cb03f14d36e580c420ee9b3df4faaeceda248
3 # (C) Copyright IBM Corporation 2004, 2005
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 # Ian Romanick <idr@us.ibm.com>
29 import gl_XML
, glX_XML
32 class PrintGenericStubs(gl_XML
.gl_print_base
):
35 gl_XML
.gl_print_base
.__init
__(self
)
37 self
.name
= "gl_x86_asm.py (from Mesa)"
38 self
.license
= license
.bsd_license_template
% ( \
39 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
40 (C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
44 def get_stack_size(self
, f
):
46 for p
in f
.parameterIterator():
47 size
+= p
.get_stack_size()
52 def printRealHeader(self
):
53 print '#include "assyntax.h"'
54 print '#include "glapi/glapioffsets.h"'
56 print '#if defined(STDCALL_API)'
57 print '# if defined(USE_MGL_NAMESPACE)'
58 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
60 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
63 print '# if defined(USE_MGL_NAMESPACE)'
64 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
65 print '# define _glapi_Dispatch _mglapi_Dispatch'
67 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
71 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
73 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
74 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
76 print '#define GLOBL_FN(x) GLOBL x'
79 print '#if defined(PTHREADS) || defined(USE_XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
80 print '# define THREADS'
83 print '#ifdef GLX_USE_TLS'
85 print '#ifdef GLX_X86_READONLY_TEXT'
86 print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)'
88 print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */'
91 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
92 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
93 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
94 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
95 print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
96 print '\tCTX_INSNS ; \\'
97 print '\tJMP(GL_OFFSET(off))'
99 print '#elif defined(PTHREADS)'
100 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
101 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
102 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
103 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
104 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
105 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
106 print '\tJE(1f) ;\t\t\t\t\t\\'
107 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
108 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
109 print '\tJMP(GL_OFFSET(off))'
110 print '#elif defined(THREADS)'
111 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
112 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
113 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
114 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
115 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
116 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
117 print '\tJE(1f) ;\t\t\t\t\t\\'
118 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
119 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
120 print '\tJMP(GL_OFFSET(off))'
121 print '#else /* Non-threaded version. */'
122 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
123 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
124 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
125 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
126 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
127 print '\tJMP(GL_OFFSET(off))'
130 print '#ifdef HAVE_ALIAS'
131 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
132 print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
133 print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
135 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
136 print ' GL_STUB(fn, off, fn_alt)'
141 print '#ifdef GLX_USE_TLS'
143 print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
144 print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
146 print 'GLNAME(_x86_get_dispatch):'
148 print '1:\tpopl %eax'
149 print '\taddl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
150 print '\tmovl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax'
153 print '#elif defined(PTHREADS)'
154 print 'EXTERN GLNAME(_glapi_Dispatch)'
155 print 'EXTERN GLNAME(_gl_DispatchTSD)'
156 print 'EXTERN GLNAME(pthread_getspecific)'
159 print 'GLNAME(_x86_get_dispatch):'
160 print '\tSUB_L(CONST(24), ESP)'
161 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
162 print '\tCALL(GLNAME(pthread_getspecific))'
163 print '\tADD_L(CONST(28), ESP)'
165 print '#elif defined(THREADS)'
166 print 'EXTERN GLNAME(_glapi_get_dispatch)'
170 print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )'
171 print '\t\t.section\twtext, "awx", @progbits'
172 print '#endif /* defined( GLX_USE_TLS ) */'
175 print '\t\tALIGNTEXT16'
176 print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
177 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
178 print 'GLNAME(gl_dispatch_functions_start):'
183 def printRealFooter(self
):
185 print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
186 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
187 print '\t\tALIGNTEXT16'
188 print 'GLNAME(gl_dispatch_functions_end):'
190 print '#if defined(GLX_USE_TLS) && defined(__linux__)'
191 print ' .section ".note.ABI-tag", "a"'
193 print ' .long 1f - 0f /* name length */'
194 print ' .long 3f - 2f /* data length */'
195 print ' .long 1 /* note length */'
196 print '0: .asciz "GNU" /* vendor name */'
197 print '1: .p2align 2'
198 print '2: .long 0 /* note data: the ABI tag */'
199 print ' .long 2,4,20 /* Minimum kernel version w/TLS */'
200 print '3: .p2align 2 /* pad out section */'
201 print '#endif /* GLX_USE_TLS */'
203 print '#if defined (__ELF__) && defined (__linux__)'
204 print ' .section .note.GNU-stack,"",%progbits'
209 def printBody(self
, api
):
210 for f
in api
.functionIterateByOffset():
211 name
= f
.dispatch_name()
212 stack
= self
.get_stack_size(f
)
213 alt
= "%s@%u" % (name
, stack
)
215 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (name
, f
.name
, alt
)
217 if not f
.is_static_entry_point(f
.name
):
218 print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name
, alt
)
221 for f
in api
.functionIterateByOffset():
222 name
= f
.dispatch_name()
223 stack
= self
.get_stack_size(f
)
224 alt
= "%s@%u" % (name
, stack
)
226 if f
.is_static_entry_point(f
.name
):
227 for n
in f
.entry_points
:
229 alt2
= "%s@%u" % (n
, stack
)
230 text
= '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % (n
, f
.name
, alt2
, f
.name
, alt
)
232 if f
.has_different_protocol(n
):
233 print '#ifndef GLX_INDIRECT_RENDERING'
242 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys
.argv
[0]
245 if __name__
== '__main__':
246 file_name
= "gl_API.xml"
250 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "m:f:")
254 for (arg
,val
) in args
:
260 if mode
== "generic":
261 printer
= PrintGenericStubs()
263 print "ERROR: Invalid mode \"%s\" specified." % mode
266 api
= gl_XML
.parse_GL_API(file_name
, glX_XML
.glx_item_factory())