1#!/usr/bin/env python 2 3# (C) Copyright IBM Corporation 2004 4# All Rights Reserved. 5# 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: 12# 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 15# Software. 16# 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 23# IN THE SOFTWARE. 24# 25# Authors: 26# Ian Romanick <idr@us.ibm.com> 27 28import argparse 29 30import license 31import gl_XML, glX_XML 32 33class PrintGenericStubs(gl_XML.gl_print_base): 34 def __init__(self): 35 gl_XML.gl_print_base.__init__(self) 36 self.name = "gl_SPARC_asm.py (from Mesa)" 37 self.license = license.bsd_license_template % ( \ 38"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 39(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") 40 41 42 def printRealHeader(self): 43 print '#ifdef __arch64__' 44 print '#define GL_OFF(N)\t((N) * 8)' 45 print '#define GL_LL\t\tldx' 46 print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)' 47 print '#define GL_STACK_SIZE\t128' 48 print '#else' 49 print '#define GL_OFF(N)\t((N) * 4)' 50 print '#define GL_LL\t\tld' 51 print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)' 52 print '#define GL_STACK_SIZE\t64' 53 print '#endif' 54 print '' 55 print '#define GLOBL_FN(x) .globl x ; .type x, @function' 56 print '#define HIDDEN(x) .hidden x' 57 print '' 58 print '\t.register %g2, #scratch' 59 print '\t.register %g3, #scratch' 60 print '' 61 print '\t.text' 62 print '' 63 print '\tGLOBL_FN(__glapi_sparc_icache_flush)' 64 print '\tHIDDEN(__glapi_sparc_icache_flush)' 65 print '\t.type\t__glapi_sparc_icache_flush, @function' 66 print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */' 67 print '\tflush\t%o0' 68 print '\tretl' 69 print '\t nop' 70 print '' 71 print '\t.align\t32' 72 print '' 73 print '\t.type\t__glapi_sparc_get_pc, @function' 74 print '__glapi_sparc_get_pc:' 75 print '\tretl' 76 print '\t add\t%o7, %g2, %g2' 77 print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc' 78 print '' 79 print '#ifdef GLX_USE_TLS' 80 print '' 81 print '\tGLOBL_FN(__glapi_sparc_get_dispatch)' 82 print '\tHIDDEN(__glapi_sparc_get_dispatch)' 83 print '__glapi_sparc_get_dispatch:' 84 print '\tmov\t%o7, %g1' 85 print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' 86 print '\tcall\t__glapi_sparc_get_pc' 87 print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' 88 print '\tmov\t%g1, %o7' 89 print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' 90 print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' 91 print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' 92 print '\tretl' 93 print '\t mov\t%g2, %o0' 94 print '' 95 print '\t.data' 96 print '\t.align\t32' 97 print '' 98 print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */' 99 print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */' 100 print '\tGLOBL_FN(__glapi_sparc_tls_stub)' 101 print '\tHIDDEN(__glapi_sparc_tls_stub)' 102 print '__glapi_sparc_tls_stub: /* Call offset in %g3 */' 103 print '\tmov\t%o7, %g1' 104 print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' 105 print '\tcall\t__glapi_sparc_get_pc' 106 print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' 107 print '\tmov\t%g1, %o7' 108 print '\tsrl\t%g3, 10, %g3' 109 print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' 110 print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' 111 print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' 112 print '\tGL_LL\t[%g7+%g2], %g1' 113 print '\tGL_LL\t[%g1 + %g3], %g1' 114 print '\tjmp\t%g1' 115 print '\t nop' 116 print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub' 117 print '' 118 print '#define GL_STUB(fn, off)\t\t\t\t\\' 119 print '\tGLOBL_FN(fn);\t\t\t\t\t\\' 120 print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\' 121 print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\' 122 print '\t.size\tfn,.-fn;' 123 print '' 124 print '#elif defined(HAVE_PTHREAD)' 125 print '' 126 print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */' 127 print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */' 128 print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */' 129 print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */' 130 print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */' 131 print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */' 132 print '' 133 print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */' 134 print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */' 135 print '' 136 print '\t.data' 137 print '\t.align\t32' 138 print '' 139 print '\tGLOBL_FN(__glapi_sparc_pthread_stub)' 140 print '\tHIDDEN(__glapi_sparc_pthread_stub)' 141 print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */' 142 print '\tmov\t%o7, %g1' 143 print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' 144 print '\tcall\t__glapi_sparc_get_pc' 145 print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' 146 print '\tmov\t%g1, %o7' 147 print '\tsethi\t%hi(_glapi_Dispatch), %g1' 148 print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' 149 print '\tsrl\t%g3, 10, %g3' 150 print '\tGL_LL\t[%g2+%g1], %g2' 151 print '\tGL_LL\t[%g2], %g1' 152 print '\tcmp\t%g1, 0' 153 print '\tbe\t2f' 154 print '\t nop' 155 print '1:\tGL_LL\t[%g1 + %g3], %g1' 156 print '\tjmp\t%g1' 157 print '\t nop' 158 print '2:\tsave\t%sp, GL_STACK_SIZE, %sp' 159 print '\tmov\t%g3, %l0' 160 print '\tcall\t_glapi_get_dispatch' 161 print '\t nop' 162 print '\tmov\t%o0, %g1' 163 print '\tmov\t%l0, %g3' 164 print '\tba\t1b' 165 print '\t restore %g0, %g0, %g0' 166 print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub' 167 print '' 168 print '#define GL_STUB(fn, off)\t\t\t\\' 169 print '\tGLOBL_FN(fn);\t\t\t\t\\' 170 print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\' 171 print '\t sethi\tGL_OFF(off), %g3;\t\t\\' 172 print '\t.size\tfn,.-fn;' 173 print '' 174 print '#else /* Non-threaded version. */' 175 print '' 176 print '\t.type __glapi_sparc_nothread_stub, @function' 177 print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */' 178 print '\tmov\t%o7, %g1' 179 print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' 180 print '\tcall\t__glapi_sparc_get_pc' 181 print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' 182 print '\tmov\t%g1, %o7' 183 print '\tsrl\t%g3, 10, %g3' 184 print '\tsethi\t%hi(_glapi_Dispatch), %g1' 185 print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' 186 print '\tGL_LL\t[%g2+%g1], %g2' 187 print '\tGL_LL\t[%g2], %g1' 188 print '\tGL_LL\t[%g1 + %g3], %g1' 189 print '\tjmp\t%g1' 190 print '\t nop' 191 print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub' 192 print '' 193 print '#define GL_STUB(fn, off)\t\t\t\\' 194 print '\tGLOBL_FN(fn);\t\t\t\t\\' 195 print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\' 196 print '\t sethi\tGL_OFF(off), %g3;\t\t\\' 197 print '\t.size\tfn,.-fn;' 198 print '' 199 print '#endif' 200 print '' 201 print '#define GL_STUB_ALIAS(fn, alias) \\' 202 print ' .globl fn; \\' 203 print ' .set fn, alias' 204 print '' 205 print '\t.text' 206 print '\t.align\t32' 207 print '' 208 print '\t.globl\tgl_dispatch_functions_start' 209 print '\tHIDDEN(gl_dispatch_functions_start)' 210 print 'gl_dispatch_functions_start:' 211 print '' 212 return 213 214 def printRealFooter(self): 215 print '' 216 print '\t.globl\tgl_dispatch_functions_end' 217 print '\tHIDDEN(gl_dispatch_functions_end)' 218 print 'gl_dispatch_functions_end:' 219 return 220 221 def printBody(self, api): 222 for f in api.functionIterateByOffset(): 223 name = f.dispatch_name() 224 225 print '\tGL_STUB(gl%s, %d)' % (name, f.offset) 226 227 if not f.is_static_entry_point(f.name): 228 print '\tHIDDEN(gl%s)' % (name) 229 230 for f in api.functionIterateByOffset(): 231 name = f.dispatch_name() 232 233 if f.is_static_entry_point(f.name): 234 for n in f.entry_points: 235 if n != f.name: 236 text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name) 237 238 if f.has_different_protocol(n): 239 print '#ifndef GLX_INDIRECT_RENDERING' 240 print text 241 print '#endif' 242 else: 243 print text 244 245 return 246 247 248def _parser(): 249 """Parse arguments and return a namespace.""" 250 parser = argparse.ArgumentParser() 251 parser.add_argument('-f', 252 dest='filename', 253 default='gl_API.xml', 254 help='An XML description of an API.') 255 return parser.parse_args() 256 257 258def main(): 259 """Main function.""" 260 args = _parser() 261 printer = PrintGenericStubs() 262 263 api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory()) 264 printer.Print(api) 265 266 267if __name__ == '__main__': 268 main() 269