1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#!/usr/bin/env python
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# (C) Copyright IBM Corporation 2004
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# All Rights Reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# Permission is hereby granted, free of charge, to any person obtaining a
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# copy of this software and associated documentation files (the "Software"),
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# to deal in the Software without restriction, including without limitation
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# on the rights to use, copy, modify, merge, publish, distribute, sub
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# license, and/or sell copies of the Software, and to permit persons to whom
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# the Software is furnished to do so, subject to the following conditions:
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# The above copyright notice and this permission notice (including the next
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# paragraph) shall be included in all copies or substantial portions of the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# Software.
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# IN THE SOFTWARE.
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# Authors:
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#    Ian Romanick <idr@us.ibm.com>
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport license
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport gl_XML, glX_XML
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport sys, getopt
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass PrintGenericStubs(gl_XML.gl_print_base):
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	def __init__(self):
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		gl_XML.gl_print_base.__init__(self)
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		self.name = "gl_SPARC_asm.py (from Mesa)"
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		self.license = license.bsd_license_template % ( \
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org"""Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	def printRealHeader(self):
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#ifdef __arch64__'
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_OFF(N)\t((N) * 8)'
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_LL\t\tldx'
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)'
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STACK_SIZE\t128'
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#else'
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_OFF(N)\t((N) * 4)'
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_LL\t\tld'
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)'
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STACK_SIZE\t64'
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#endif'
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GLOBL_FN(x) .globl x ; .type x, @function'
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define HIDDEN(x) .hidden x'
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.register %g2, #scratch'
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.register %g3, #scratch'
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.text'
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(__glapi_sparc_icache_flush)'
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(__glapi_sparc_icache_flush)'
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.type\t__glapi_sparc_icache_flush, @function'
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tflush\t%o0'
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tretl'
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.align\t32'
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.type\t__glapi_sparc_get_pc, @function'
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_get_pc:'
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tretl'
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t add\t%o7, %g2, %g2'
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc'
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#ifdef GLX_USE_TLS'
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(__glapi_sparc_get_dispatch)'
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(__glapi_sparc_get_dispatch)'
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_get_dispatch:'
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%o7, %g1'
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcall\t__glapi_sparc_get_pc'
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%g1, %o7'
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tretl'
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t mov\t%g2, %o0'
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.data'
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.align\t32'
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */'
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */'
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(__glapi_sparc_tls_stub)'
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(__glapi_sparc_tls_stub)'
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_tls_stub: /* Call offset in %g3 */'
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%o7, %g1'
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcall\t__glapi_sparc_get_pc'
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%g1, %o7'
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsrl\t%g3, 10, %g3'
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g7+%g2], %g1'
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g1 + %g3], %g1'
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tjmp\t%g1'
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub'
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STUB(fn, off)\t\t\t\t\\'
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(fn);\t\t\t\t\t\\'
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\'
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\'
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\tfn,.-fn;'
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#elif defined(HAVE_PTHREAD)'
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */'
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */'
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */'
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */'
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */'
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */'
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */'
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */'
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.data'
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.align\t32'
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(__glapi_sparc_pthread_stub)'
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(__glapi_sparc_pthread_stub)'
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */'
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%o7, %g1'
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcall\t__glapi_sparc_get_pc'
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%g1, %o7'
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_glapi_Dispatch), %g1'
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsrl\t%g3, 10, %g3'
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2+%g1], %g2'
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2], %g1'
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcmp\t%g1, 0'
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tbe\t2f'
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '1:\tGL_LL\t[%g1 + %g3], %g1'
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tjmp\t%g1'
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '2:\tsave\t%sp, GL_STACK_SIZE, %sp'
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%g3, %l0'
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcall\t_glapi_get_dispatch'
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%o0, %g1'
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%l0, %g3'
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tba\t1b'
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t restore %g0, %g0, %g0'
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub'
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STUB(fn, off)\t\t\t\\'
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(fn);\t\t\t\t\\'
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\'
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\tfn,.-fn;'
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#else /* Non-threaded version. */'
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.type	__glapi_sparc_nothread_stub, @function'
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */'
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%o7, %g1'
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tcall\t__glapi_sparc_get_pc'
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tmov\t%g1, %o7'
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsrl\t%g3, 10, %g3'
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tsethi\t%hi(_glapi_Dispatch), %g1'
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2+%g1], %g2'
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g2], %g1'
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGL_LL\t[%g1 + %g3], %g1'
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tjmp\t%g1'
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t nop'
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub'
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STUB(fn, off)\t\t\t\\'
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tGLOBL_FN(fn);\t\t\t\t\\'
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\'
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.size\tfn,.-fn;'
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#endif'
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '#define GL_STUB_ALIAS(fn, alias)		\\'
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '	.globl	fn;				\\'
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '	.set	fn, alias'
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.text'
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.align\t32'
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.globl\tgl_dispatch_functions_start'
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(gl_dispatch_functions_start)'
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print 'gl_dispatch_functions_start:'
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		return
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	def printRealFooter(self):
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print ''
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\t.globl\tgl_dispatch_functions_end'
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print '\tHIDDEN(gl_dispatch_functions_end)'
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print 'gl_dispatch_functions_end:'
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		return
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	def printBody(self, api):
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		for f in api.functionIterateByOffset():
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			name = f.dispatch_name()
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			print '\tGL_STUB(gl%s, %d)' % (name, f.offset)
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			if not f.is_static_entry_point(f.name):
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				print '\tHIDDEN(gl%s)' % (name)
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		for f in api.functionIterateByOffset():
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			name = f.dispatch_name()
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			if f.is_static_entry_point(f.name):
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				for n in f.entry_points:
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org					if n != f.name:
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org						text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name)
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org						if f.has_different_protocol(n):
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org							print '#ifndef GLX_INDIRECT_RENDERING'
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org							print text
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org							print '#endif'
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org						else:
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org							print text
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		return
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef show_usage():
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	sys.exit(1)
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgif __name__ == '__main__':
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	file_name = "gl_API.xml"
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	mode = "generic"
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	try:
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		(args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	except Exception,e:
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		show_usage()
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	for (arg,val) in args:
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		if arg == '-m':
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			mode = val
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		elif arg == "-f":
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			file_name = val
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	if mode == "generic":
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		printer = PrintGenericStubs()
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	else:
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		print "ERROR: Invalid mode \"%s\" specified." % mode
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		show_usage()
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	printer.Print(api)
274