blob: 1964c15eccd5cb091ad9a3b9171d03cd477cb189 [file] [log] [blame]
davem69ae144992001-06-05 04:30:03 +00001#!/usr/bin/env python
2
Brian Paul6c0d72f2001-11-18 22:42:57 +00003# $Id: glsparcasm.py,v 1.5 2001/11/18 22:42:57 brianp Exp $
davem69ae144992001-06-05 04:30:03 +00004
5# Mesa 3-D graphics library
Brian Paul6c0d72f2001-11-18 22:42:57 +00006# Version: 4.1
davem69ae144992001-06-05 04:30:03 +00007#
Brian Paul6c0d72f2001-11-18 22:42:57 +00008# Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
davem69ae144992001-06-05 04:30:03 +00009#
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
Brian Paul6c0d72f2001-11-18 22:42:57 +000028# Generate the src/SPARC/glapi_sparc.S file.
davem69ae144992001-06-05 04:30:03 +000029#
30# Usage:
Brian Paul6c0d72f2001-11-18 22:42:57 +000031# gloffsets.py >glapi_sparc.S
davem69ae144992001-06-05 04:30:03 +000032#
33# Dependencies:
Brian Paul6c0d72f2001-11-18 22:42:57 +000034# The apispec file must be in the current directory.
davem69ae144992001-06-05 04:30:03 +000035
Brian Paul6c0d72f2001-11-18 22:42:57 +000036
37import apiparser;
davem69ae144992001-06-05 04:30:03 +000038
39
40def PrintHead():
41 print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */'
42 print '#include "glapioffsets.h"'
43 print ''
44 print '#define GL_PREFIX(n) gl##n'
Brian Paul6c0d72f2001-11-18 22:42:57 +000045 print '#define GLOBL_FN(x) .globl x'
davem69ae144992001-06-05 04:30:03 +000046 print ''
47 print '/* The _glapi_Dispatch symbol addresses get relocated into the'
48 print ' * sethi/or instruction sequences below at library init time.'
49 print ' */'
50 print ''
davem694a497e62001-06-06 22:55:28 +000051 print ''
52 print '.text'
53 print '.align 32'
54 print '.globl __glapi_sparc_icache_flush'
55 print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
56 print '\tflush\t%o0'
57 print '\tretl'
Brian Paul6c0d72f2001-11-18 22:42:57 +000058 print '\tnop'
davem694a497e62001-06-06 22:55:28 +000059 print ''
davem69775355a2001-06-05 23:54:00 +000060 print '.data'
davem69ae144992001-06-05 04:30:03 +000061 print '.align 64'
62 print ''
davem69775355a2001-06-05 23:54:00 +000063 print '.globl _mesa_sparc_glapi_begin'
davem69636fb6c2001-08-03 13:16:31 +000064 print '.type _mesa_sparc_glapi_begin,#function'
davem69775355a2001-06-05 23:54:00 +000065 print '_mesa_sparc_glapi_begin:'
davem69ae144992001-06-05 04:30:03 +000066 return
67#endif
68
69def PrintTail():
70 print '\t nop'
71 print ''
davem69775355a2001-06-05 23:54:00 +000072 print '.globl _mesa_sparc_glapi_end'
davem69636fb6c2001-08-03 13:16:31 +000073 print '.type _mesa_sparc_glapi_end,#function'
davem69775355a2001-06-05 23:54:00 +000074 print '_mesa_sparc_glapi_end:'
75 print ''
davem69ae144992001-06-05 04:30:03 +000076#endif
77
78
Brian Paul6c0d72f2001-11-18 22:42:57 +000079
80records = []
81
82def FindOffset(funcName):
83 for (name, alias, offset) in records:
84 if name == funcName:
85 return offset
86 #endif
87 #endfor
88 return -1
89#enddef
90
91def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset):
92 argList = apiparser.MakeArgList(argTypeList, argNameList)
93 if alias != '':
94 dispatchName = alias
95 else:
96 dispatchName = name
97 #endif
98
99 if offset < 0:
100 # try to find offset from alias name
101 assert dispatchName != ''
102 offset = FindOffset(dispatchName)
103 if offset == -1:
104 #print 'Cannot dispatch %s' % name
105 return
106 #endif
107 #endif
108
109 # save this info in case we need to look up an alias later
110 records.append((name, dispatchName, offset))
111
112 # print the assembly code
davem69ae144992001-06-05 04:30:03 +0000113 print ''
114 print "GLOBL_FN(GL_PREFIX(%s))" % (name)
Brian Paul6c0d72f2001-11-18 22:42:57 +0000115 print '.type %s,#function' %(name)
davem69ae144992001-06-05 04:30:03 +0000116 print "GL_PREFIX(%s):" % (name)
117 print '#ifdef __sparc_v9__'
118 print '\tsethi\t%hi(0x00000000), %g2'
119 print '\tsethi\t%hi(0x00000000), %g1'
120 print '\tor\t%g2, %lo(0x00000000), %g2'
121 print '\tor\t%g1, %lo(0x00000000), %g1'
122 print '\tsllx\t%g2, 32, %g2'
davem69775355a2001-06-05 23:54:00 +0000123 print '\tldx\t[%g1 + %g2], %g1'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000124 print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (dispatchName)
125 print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (dispatchName)
davem69ae144992001-06-05 04:30:03 +0000126 print '\tldx\t[%g1 + %g2], %g3'
127 print '#else'
128 print '\tsethi\t%hi(0x00000000), %g1'
davem69775355a2001-06-05 23:54:00 +0000129 print '\tld\t[%g1 + %lo(0x00000000)], %g1'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000130 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (dispatchName)
davem69ae144992001-06-05 04:30:03 +0000131 print '#endif'
132 print '\tjmpl\t%g3, %g0'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000133 print '\tnop'
davem69ae144992001-06-05 04:30:03 +0000134#enddef
135
136
davem69ae144992001-06-05 04:30:03 +0000137PrintHead()
Brian Paul6c0d72f2001-11-18 22:42:57 +0000138apiparser.ProcessSpecFile("APIspec", EmitFunction)
davem69ae144992001-06-05 04:30:03 +0000139PrintTail()