1bf215546Sopenharmony_ci 2bf215546Sopenharmony_ci# (C) Copyright IBM Corporation 2004 3bf215546Sopenharmony_ci# All Rights Reserved. 4bf215546Sopenharmony_ci# 5bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci# on the rights to use, copy, modify, merge, publish, distribute, sub 9bf215546Sopenharmony_ci# license, and/or sell copies of the Software, and to permit persons to whom 10bf215546Sopenharmony_ci# the Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci# 12bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci# Software. 15bf215546Sopenharmony_ci# 16bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22bf215546Sopenharmony_ci# IN THE SOFTWARE. 23bf215546Sopenharmony_ci# 24bf215546Sopenharmony_ci# Authors: 25bf215546Sopenharmony_ci# Ian Romanick <idr@us.ibm.com> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ciimport argparse 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ciimport license 30bf215546Sopenharmony_ciimport gl_XML, glX_XML 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ciclass PrintGenericStubs(gl_XML.gl_print_base): 33bf215546Sopenharmony_ci def __init__(self): 34bf215546Sopenharmony_ci gl_XML.gl_print_base.__init__(self) 35bf215546Sopenharmony_ci self.name = "gl_SPARC_asm.py (from Mesa)" 36bf215546Sopenharmony_ci self.license = license.bsd_license_template % ( \ 37bf215546Sopenharmony_ci"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 38bf215546Sopenharmony_ci(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci def printRealHeader(self): 42bf215546Sopenharmony_ci print('#ifdef __arch64__') 43bf215546Sopenharmony_ci print('#define GL_OFF(N)\t((N) * 8)') 44bf215546Sopenharmony_ci print('#define GL_LL\t\tldx') 45bf215546Sopenharmony_ci print('#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)') 46bf215546Sopenharmony_ci print('#define GL_STACK_SIZE\t128') 47bf215546Sopenharmony_ci print('#else') 48bf215546Sopenharmony_ci print('#define GL_OFF(N)\t((N) * 4)') 49bf215546Sopenharmony_ci print('#define GL_LL\t\tld') 50bf215546Sopenharmony_ci print('#define GL_TIE_LD(SYM)\t%tie_ld(SYM)') 51bf215546Sopenharmony_ci print('#define GL_STACK_SIZE\t64') 52bf215546Sopenharmony_ci print('#endif') 53bf215546Sopenharmony_ci print('') 54bf215546Sopenharmony_ci print('#define GLOBL_FN(x) .globl x ; .type x, @function') 55bf215546Sopenharmony_ci print('#define HIDDEN(x) .hidden x') 56bf215546Sopenharmony_ci print('') 57bf215546Sopenharmony_ci print('\t.register %g2, #scratch') 58bf215546Sopenharmony_ci print('\t.register %g3, #scratch') 59bf215546Sopenharmony_ci print('') 60bf215546Sopenharmony_ci print('\t.text') 61bf215546Sopenharmony_ci print('') 62bf215546Sopenharmony_ci print('\tGLOBL_FN(__glapi_sparc_icache_flush)') 63bf215546Sopenharmony_ci print('\tHIDDEN(__glapi_sparc_icache_flush)') 64bf215546Sopenharmony_ci print('\t.type\t__glapi_sparc_icache_flush, @function') 65bf215546Sopenharmony_ci print('__glapi_sparc_icache_flush: /* %o0 = insn_addr */') 66bf215546Sopenharmony_ci print('\tflush\t%o0') 67bf215546Sopenharmony_ci print('\tretl') 68bf215546Sopenharmony_ci print('\t nop') 69bf215546Sopenharmony_ci print('') 70bf215546Sopenharmony_ci print('\t.align\t32') 71bf215546Sopenharmony_ci print('') 72bf215546Sopenharmony_ci print('\t.type\t__glapi_sparc_get_pc, @function') 73bf215546Sopenharmony_ci print('__glapi_sparc_get_pc:') 74bf215546Sopenharmony_ci print('\tretl') 75bf215546Sopenharmony_ci print('\t add\t%o7, %g2, %g2') 76bf215546Sopenharmony_ci print('\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc') 77bf215546Sopenharmony_ci print('') 78bf215546Sopenharmony_ci print('') 79bf215546Sopenharmony_ci print('\tGLOBL_FN(__glapi_sparc_get_dispatch)') 80bf215546Sopenharmony_ci print('\tHIDDEN(__glapi_sparc_get_dispatch)') 81bf215546Sopenharmony_ci print('__glapi_sparc_get_dispatch:') 82bf215546Sopenharmony_ci print('\tmov\t%o7, %g1') 83bf215546Sopenharmony_ci print('\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2') 84bf215546Sopenharmony_ci print('\tcall\t__glapi_sparc_get_pc') 85bf215546Sopenharmony_ci print('\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2') 86bf215546Sopenharmony_ci print('\tmov\t%g1, %o7') 87bf215546Sopenharmony_ci print('\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1') 88bf215546Sopenharmony_ci print('\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1') 89bf215546Sopenharmony_ci print('\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)') 90bf215546Sopenharmony_ci print('\tretl') 91bf215546Sopenharmony_ci print('\t mov\t%g2, %o0') 92bf215546Sopenharmony_ci print('') 93bf215546Sopenharmony_ci print('\t.data') 94bf215546Sopenharmony_ci print('\t.align\t32') 95bf215546Sopenharmony_ci print('') 96bf215546Sopenharmony_ci print('\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */') 97bf215546Sopenharmony_ci print('\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */') 98bf215546Sopenharmony_ci print('\tGLOBL_FN(__glapi_sparc_tls_stub)') 99bf215546Sopenharmony_ci print('\tHIDDEN(__glapi_sparc_tls_stub)') 100bf215546Sopenharmony_ci print('__glapi_sparc_tls_stub: /* Call offset in %g3 */') 101bf215546Sopenharmony_ci print('\tmov\t%o7, %g1') 102bf215546Sopenharmony_ci print('\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2') 103bf215546Sopenharmony_ci print('\tcall\t__glapi_sparc_get_pc') 104bf215546Sopenharmony_ci print('\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2') 105bf215546Sopenharmony_ci print('\tmov\t%g1, %o7') 106bf215546Sopenharmony_ci print('\tsrl\t%g3, 10, %g3') 107bf215546Sopenharmony_ci print('\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1') 108bf215546Sopenharmony_ci print('\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1') 109bf215546Sopenharmony_ci print('\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)') 110bf215546Sopenharmony_ci print('\tGL_LL\t[%g7+%g2], %g1') 111bf215546Sopenharmony_ci print('\tGL_LL\t[%g1 + %g3], %g1') 112bf215546Sopenharmony_ci print('\tjmp\t%g1') 113bf215546Sopenharmony_ci print('\t nop') 114bf215546Sopenharmony_ci print('\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub') 115bf215546Sopenharmony_ci print('') 116bf215546Sopenharmony_ci print('#define GL_STUB(fn, off)\t\t\t\t\\') 117bf215546Sopenharmony_ci print('\tGLOBL_FN(fn);\t\t\t\t\t\\') 118bf215546Sopenharmony_ci print('fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\') 119bf215546Sopenharmony_ci print('\t sethi\tGL_OFF(off), %g3;\t\t\t\\') 120bf215546Sopenharmony_ci print('\t.size\tfn,.-fn;') 121bf215546Sopenharmony_ci print('') 122bf215546Sopenharmony_ci print('#define GL_STUB_ALIAS(fn, alias) \\') 123bf215546Sopenharmony_ci print(' .globl fn; \\') 124bf215546Sopenharmony_ci print(' .set fn, alias') 125bf215546Sopenharmony_ci print('') 126bf215546Sopenharmony_ci print('\t.text') 127bf215546Sopenharmony_ci print('\t.align\t32') 128bf215546Sopenharmony_ci print('') 129bf215546Sopenharmony_ci print('\t.globl\tgl_dispatch_functions_start') 130bf215546Sopenharmony_ci print('\tHIDDEN(gl_dispatch_functions_start)') 131bf215546Sopenharmony_ci print('gl_dispatch_functions_start:') 132bf215546Sopenharmony_ci print('') 133bf215546Sopenharmony_ci return 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci def printRealFooter(self): 136bf215546Sopenharmony_ci print('') 137bf215546Sopenharmony_ci print('\t.globl\tgl_dispatch_functions_end') 138bf215546Sopenharmony_ci print('\tHIDDEN(gl_dispatch_functions_end)') 139bf215546Sopenharmony_ci print('gl_dispatch_functions_end:') 140bf215546Sopenharmony_ci return 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci def printBody(self, api): 143bf215546Sopenharmony_ci for f in api.functionIterateByOffset(): 144bf215546Sopenharmony_ci name = f.dispatch_name() 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci print('\tGL_STUB(gl%s, %d)' % (name, f.offset)) 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci if not f.is_static_entry_point(f.name): 149bf215546Sopenharmony_ci print('\tHIDDEN(gl%s)' % (name)) 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_ci for f in api.functionIterateByOffset(): 152bf215546Sopenharmony_ci name = f.dispatch_name() 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci if f.is_static_entry_point(f.name): 155bf215546Sopenharmony_ci for n in f.entry_points: 156bf215546Sopenharmony_ci if n != f.name: 157bf215546Sopenharmony_ci text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name) 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci if f.has_different_protocol(n): 160bf215546Sopenharmony_ci print('#ifndef GLX_INDIRECT_RENDERING') 161bf215546Sopenharmony_ci print(text) 162bf215546Sopenharmony_ci print('#endif') 163bf215546Sopenharmony_ci else: 164bf215546Sopenharmony_ci print(text) 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci return 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_cidef _parser(): 170bf215546Sopenharmony_ci """Parse arguments and return a namespace.""" 171bf215546Sopenharmony_ci parser = argparse.ArgumentParser() 172bf215546Sopenharmony_ci parser.add_argument('-f', 173bf215546Sopenharmony_ci dest='filename', 174bf215546Sopenharmony_ci default='gl_API.xml', 175bf215546Sopenharmony_ci help='An XML description of an API.') 176bf215546Sopenharmony_ci return parser.parse_args() 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_cidef main(): 180bf215546Sopenharmony_ci """Main function.""" 181bf215546Sopenharmony_ci args = _parser() 182bf215546Sopenharmony_ci printer = PrintGenericStubs() 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_ci api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory()) 185bf215546Sopenharmony_ci printer.Print(api) 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ciif __name__ == '__main__': 189bf215546Sopenharmony_ci main() 190