push/pop color table state (Eric Plante)
[mesa.git] / src / mesa / glapi / glsparcasm.py
1 #!/usr/bin/env python
2
3 # $Id: glsparcasm.py,v 1.7 2002/01/03 16:33:59 brianp Exp $
4
5 # Mesa 3-D graphics library
6 # Version: 4.1
7 #
8 # Copyright (C) 1999-2001 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 src/SPARC/glapi_sparc.S file.
29 #
30 # Usage:
31 # gloffsets.py >glapi_sparc.S
32 #
33 # Dependencies:
34 # The apispec file must be in the current directory.
35
36
37 import apiparser;
38
39
40 def PrintHead():
41 print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */'
42 print '#include "glapioffsets.h"'
43 print ''
44 print '/* The _glapi_Dispatch symbol addresses get relocated into the'
45 print ' * sethi/or instruction sequences below at library init time.'
46 print ' */'
47 print ''
48 print ''
49 print '.text'
50 print '.align 32'
51 print '.globl __glapi_sparc_icache_flush'
52 print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
53 print '\tflush\t%o0'
54 print '\tretl'
55 print '\tnop'
56 print ''
57 print '.data'
58 print '.align 64'
59 print ''
60 print '.globl _mesa_sparc_glapi_begin'
61 print '.type _mesa_sparc_glapi_begin,#function'
62 print '_mesa_sparc_glapi_begin:'
63 return
64 #endif
65
66 def PrintTail():
67 print '\t nop'
68 print ''
69 print '.globl _mesa_sparc_glapi_end'
70 print '.type _mesa_sparc_glapi_end,#function'
71 print '_mesa_sparc_glapi_end:'
72 print ''
73 #endif
74
75
76
77 records = []
78
79 def FindOffset(funcName):
80 for (name, alias, offset) in records:
81 if name == funcName:
82 return offset
83 #endif
84 #endfor
85 return -1
86 #enddef
87
88 def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset):
89 argList = apiparser.MakeArgList(argTypeList, argNameList)
90 if alias != '':
91 dispatchName = alias
92 else:
93 dispatchName = name
94 #endif
95
96 if offset < 0:
97 # try to find offset from alias name
98 assert dispatchName != ''
99 offset = FindOffset(dispatchName)
100 if offset == -1:
101 #print 'Cannot dispatch %s' % name
102 return
103 #endif
104 #endif
105
106 # save this info in case we need to look up an alias later
107 records.append((name, dispatchName, offset))
108
109 # print the assembly code
110 print ''
111 print '.globl gl%s' % (name)
112 print '.type gl%s,#function' % (name)
113 print 'gl%s:' % (name)
114 print '#ifdef __sparc_v9__'
115 print '\tsethi\t%hi(0x00000000), %g2'
116 print '\tsethi\t%hi(0x00000000), %g1'
117 print '\tor\t%g2, %lo(0x00000000), %g2'
118 print '\tor\t%g1, %lo(0x00000000), %g1'
119 print '\tsllx\t%g2, 32, %g2'
120 print '\tldx\t[%g1 + %g2], %g1'
121 print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (dispatchName)
122 print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (dispatchName)
123 print '\tldx\t[%g1 + %g2], %g3'
124 print '#else'
125 print '\tsethi\t%hi(0x00000000), %g1'
126 print '\tld\t[%g1 + %lo(0x00000000)], %g1'
127 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (dispatchName)
128 print '#endif'
129 print '\tjmpl\t%g3, %g0'
130 print '\tnop'
131 #enddef
132
133
134 PrintHead()
135 apiparser.ProcessSpecFile("APIspec", EmitFunction)
136 PrintTail()