blob: 98cbd477ef44dcfb3c71b6897c1bc19829b25e20 [file] [log] [blame]
davem69ae144992001-06-05 04:30:03 +00001#!/usr/bin/env python
2
davem69636fb6c2001-08-03 13:16:31 +00003# $Id: glsparcasm.py,v 1.4 2001/08/03 13:16:31 davem69 Exp $
davem69ae144992001-06-05 04:30:03 +00004
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
39import string
40import re
41
42
43def 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'
davem69636fb6c2001-08-03 13:16:31 +000048 print '#define GLOBL_FN(x) .globl x ; .type x,#function'
davem69ae144992001-06-05 04:30:03 +000049 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 ''
davem694a497e62001-06-06 22:55:28 +000054 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 ''
davem69775355a2001-06-05 23:54:00 +000063 print '.data'
davem69ae144992001-06-05 04:30:03 +000064 print '.align 64'
65 print ''
davem69775355a2001-06-05 23:54:00 +000066 print '.globl _mesa_sparc_glapi_begin'
davem69636fb6c2001-08-03 13:16:31 +000067 print '.type _mesa_sparc_glapi_begin,#function'
davem69775355a2001-06-05 23:54:00 +000068 print '_mesa_sparc_glapi_begin:'
69 print ''
davem69ae144992001-06-05 04:30:03 +000070 return
71#endif
72
73def PrintTail():
74 print '\t nop'
75 print ''
davem69775355a2001-06-05 23:54:00 +000076 print '.globl _mesa_sparc_glapi_end'
davem69636fb6c2001-08-03 13:16:31 +000077 print '.type _mesa_sparc_glapi_end,#function'
davem69775355a2001-06-05 23:54:00 +000078 print '_mesa_sparc_glapi_end:'
79 print ''
davem69ae144992001-06-05 04:30:03 +000080#endif
81
82
83def 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'
davem69775355a2001-06-05 23:54:00 +000093 print '\tldx\t[%g1 + %g2], %g1'
davem69ae144992001-06-05 04:30:03 +000094 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'
davem69775355a2001-06-05 23:54:00 +000099 print '\tld\t[%g1 + %lo(0x00000000)], %g1'
davem69ae144992001-06-05 04:30:03 +0000100 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (offset)
101 print '#endif'
102 print '\tjmpl\t%g3, %g0'
103#enddef
104
105
106def 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
118def 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
167PrintHead()
168PrintDefines()
169PrintTail()