davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame^] | 3 | # $Id: glsparcasm.py,v 1.4 2001/08/03 13:16:31 davem69 Exp $ |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 4 | |
| 5 | # Mesa 3-D graphics library |
| 6 | # Version: 3.5 |
| 7 | # |
| 8 | # Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| 9 | # |
| 10 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | # copy of this software and associated documentation files (the "Software"), |
| 12 | # to deal in the Software without restriction, including without limitation |
| 13 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 | # and/or sell copies of the Software, and to permit persons to whom the |
| 15 | # Software is furnished to do so, subject to the following conditions: |
| 16 | # |
| 17 | # The above copyright notice and this permission notice shall be included |
| 18 | # in all copies or substantial portions of the Software. |
| 19 | # |
| 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 21 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 24 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | |
| 27 | |
| 28 | # Generate the glapi_sparc.S assembly language file. |
| 29 | # |
| 30 | # Usage: |
| 31 | # glsparcasm.py >glapi_sparc.S |
| 32 | # |
| 33 | # Dependencies: |
| 34 | # The gl.spec file from the SI must be in the current directory. |
| 35 | # |
| 36 | # Brian Paul 11 May 2000 |
| 37 | # David S. Miller 4 Jun 2001 |
| 38 | |
| 39 | import string |
| 40 | import re |
| 41 | |
| 42 | |
| 43 | def PrintHead(): |
| 44 | print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */' |
| 45 | print '#include "glapioffsets.h"' |
| 46 | print '' |
| 47 | print '#define GL_PREFIX(n) gl##n' |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame^] | 48 | print '#define GLOBL_FN(x) .globl x ; .type x,#function' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 49 | print '' |
| 50 | print '/* The _glapi_Dispatch symbol addresses get relocated into the' |
| 51 | print ' * sethi/or instruction sequences below at library init time.' |
| 52 | print ' */' |
| 53 | print '' |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 54 | print '' |
| 55 | print '.text' |
| 56 | print '.align 32' |
| 57 | print '.globl __glapi_sparc_icache_flush' |
| 58 | print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */' |
| 59 | print '\tflush\t%o0' |
| 60 | print '\tretl' |
| 61 | print '\t nop' |
| 62 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 63 | print '.data' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 64 | print '.align 64' |
| 65 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 66 | print '.globl _mesa_sparc_glapi_begin' |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame^] | 67 | print '.type _mesa_sparc_glapi_begin,#function' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 68 | print '_mesa_sparc_glapi_begin:' |
| 69 | print '' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 70 | return |
| 71 | #endif |
| 72 | |
| 73 | def PrintTail(): |
| 74 | print '\t nop' |
| 75 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 76 | print '.globl _mesa_sparc_glapi_end' |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame^] | 77 | print '.type _mesa_sparc_glapi_end,#function' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 78 | print '_mesa_sparc_glapi_end:' |
| 79 | print '' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | |
| 83 | def GenerateDispatchCode(name, offset): |
| 84 | print '' |
| 85 | print "GLOBL_FN(GL_PREFIX(%s))" % (name) |
| 86 | print "GL_PREFIX(%s):" % (name) |
| 87 | print '#ifdef __sparc_v9__' |
| 88 | print '\tsethi\t%hi(0x00000000), %g2' |
| 89 | print '\tsethi\t%hi(0x00000000), %g1' |
| 90 | print '\tor\t%g2, %lo(0x00000000), %g2' |
| 91 | print '\tor\t%g1, %lo(0x00000000), %g1' |
| 92 | print '\tsllx\t%g2, 32, %g2' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 93 | print '\tldx\t[%g1 + %g2], %g1' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 94 | print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (offset) |
| 95 | print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (offset) |
| 96 | print '\tldx\t[%g1 + %g2], %g3' |
| 97 | print '#else' |
| 98 | print '\tsethi\t%hi(0x00000000), %g1' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 99 | print '\tld\t[%g1 + %lo(0x00000000)], %g1' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 100 | print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (offset) |
| 101 | print '#endif' |
| 102 | print '\tjmpl\t%g3, %g0' |
| 103 | #enddef |
| 104 | |
| 105 | |
| 106 | def FindAlias(list, funcName): |
| 107 | for i in range(0, len(list)): |
| 108 | entry = list[i] |
| 109 | if entry[0] == funcName: |
| 110 | return entry[1] |
| 111 | #endif |
| 112 | #endfor |
| 113 | return '' |
| 114 | #enddef |
| 115 | |
| 116 | |
| 117 | |
| 118 | def PrintDefines(): |
| 119 | functionPattern = re.compile('^[a-zA-Z0-9]+\(') |
| 120 | functionNamePattern = re.compile('^[a-zA-Z0-9]+') |
| 121 | |
| 122 | funcName = '' |
| 123 | functions = [ ] |
| 124 | |
| 125 | f = open('gl.spec') |
| 126 | for line in f.readlines(): |
| 127 | |
| 128 | m = functionPattern.match(line) |
| 129 | if m: |
| 130 | # extract funcName |
| 131 | n = functionNamePattern.findall(line) |
| 132 | funcName = n[0] |
| 133 | |
| 134 | m = string.split(line) |
| 135 | if len(m) > 1: |
| 136 | if m[0] == 'param': |
| 137 | paramName = m[1] |
| 138 | if m[0] == 'offset': |
| 139 | if m[1] == '?': |
| 140 | #print 'WARNING skipping', funcName |
| 141 | noop = 0 |
| 142 | else: |
| 143 | entry = [ funcName, funcName ] |
| 144 | functions.append(entry) |
| 145 | #endif |
| 146 | elif m[0] == 'alias': |
| 147 | aliasedName = FindAlias(functions, m[1]) |
| 148 | if aliasedName: |
| 149 | entry = [ funcName, aliasedName ] |
| 150 | functions.append(entry) |
| 151 | else: |
| 152 | print 'WARNING: alias to unknown function:', aliasedName |
| 153 | #endif |
| 154 | #endif |
| 155 | #endif |
| 156 | #endfor |
| 157 | |
| 158 | # Now generate the assembly dispatch code |
| 159 | for i in range(0, len(functions)): |
| 160 | entry = functions[i] |
| 161 | GenerateDispatchCode( entry[0], entry[1] ) |
| 162 | |
| 163 | #enddef |
| 164 | |
| 165 | |
| 166 | |
| 167 | PrintHead() |
| 168 | PrintDefines() |
| 169 | PrintTail() |