3 # (C) Copyright IBM Corporation 2004
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>
28 from xml
.sax
import saxutils
29 from xml
.sax
import make_parser
30 from xml
.sax
.handler
import feature_namespaces
36 class PrintGenericStubs(gl_XML
.FilterGLAPISpecBase
):
37 name
= "gl_x86_asm.py (from Mesa)"
40 gl_XML
.FilterGLAPISpecBase
.__init
__(self
)
41 self
.license
= license
.bsd_license_template
% ( \
42 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
43 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
46 def get_stack_size(self
, f
):
51 if p
.is_array() or t
.size
!= 8:
58 def printRealHeader(self
):
59 print '#include "assyntax.h"'
60 print '#include "glapioffsets.h"'
62 print '#ifndef __WIN32__'
64 print '#if defined(STDCALL_API)'
65 print '# if defined(USE_MGL_NAMESPACE)'
66 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
68 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
71 print '# if defined(USE_MGL_NAMESPACE)'
72 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
74 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
78 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
80 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
81 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
83 print '#define GLOBL_FN(x) GLOBL x'
86 print '#if defined(PTHREADS) || defined(XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
87 print '# define THREADS'
90 print '#if defined(PTHREADS)'
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 '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
96 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
97 print '\tJE(1f) ;\t\t\t\t\t\\'
98 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
99 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
100 print '\tJMP(GL_OFFSET(off))'
101 print '#elif defined(THREADS)'
102 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
103 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
104 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
105 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
106 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
107 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
108 print '\tJE(1f) ;\t\t\t\t\t\\'
109 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
110 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
111 print '\tJMP(GL_OFFSET(off))'
112 print '#else /* Non-threaded version. */'
113 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
114 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
115 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
116 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
117 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
118 print '\tJMP(GL_OFFSET(off))'
123 print '#ifdef PTHREADS'
124 print 'EXTERN GLNAME(_glapi_Dispatch)'
125 print 'EXTERN GLNAME(_gl_DispatchTSD)'
126 print 'EXTERN GLNAME(pthread_getspecific)'
129 print 'GLNAME(_x86_get_dispatch):'
130 print '\tSUB_L(CONST(24), ESP)'
131 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
132 print '\tCALL(GLNAME(pthread_getspecific))'
133 print '\tADD_L(CONST(28), ESP)'
135 print '#elif defined(THREADS)'
136 print 'EXTERN GLNAME(_glapi_get_dispatch)'
139 print '\t\tALIGNTEXT16 ; GLOBL GLNAME(gl_dispatch_functions_start)'
140 print 'GLNAME(gl_dispatch_functions_start):'
144 def printRealFooter(self
):
146 print '#endif /* __WIN32__ */'
149 def printFunction(self
, f
):
150 stack
= self
.get_stack_size(f
)
152 alt
= "%s@%u" % (f
.name
, stack
)
153 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (f
.name
, f
.real_name
, alt
)
157 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys
.argv
[0]
160 if __name__
== '__main__':
161 file_name
= "gl_API.xml"
165 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "m:f:")
169 for (arg
,val
) in args
:
175 if mode
== "generic":
176 dh
= PrintGenericStubs()
178 print "ERROR: Invalid mode \"%s\" specified." % mode
181 parser
= make_parser()
182 parser
.setFeature(feature_namespaces
, 0)
183 parser
.setContentHandler(dh
)