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