blob: 35d90f13330c24236c4bd8a71fea7014881682ef [file] [log] [blame]
davem69ae144992001-06-05 04:30:03 +00001#!/usr/bin/env python
2
davem69ae144992001-06-05 04:30:03 +00003# Mesa 3-D graphics library
Brian Paul9a90cd42003-12-01 22:40:26 +00004# Version: 5.1
davem69ae144992001-06-05 04:30:03 +00005#
Brian Paul9a90cd42003-12-01 22:40:26 +00006# Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
davem69ae144992001-06-05 04:30:03 +00007#
8# Permission is hereby granted, free of charge, to any person obtaining a
9# copy of this software and associated documentation files (the "Software"),
10# to deal in the Software without restriction, including without limitation
11# the rights to use, copy, modify, merge, publish, distribute, sublicense,
12# and/or sell copies of the Software, and to permit persons to whom the
13# Software is furnished to do so, subject to the following conditions:
14#
15# The above copyright notice and this permission notice shall be included
16# in all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
Brian Paul6c0d72f2001-11-18 22:42:57 +000026# Generate the src/SPARC/glapi_sparc.S file.
davem69ae144992001-06-05 04:30:03 +000027#
28# Usage:
Brian Paul6c0d72f2001-11-18 22:42:57 +000029# gloffsets.py >glapi_sparc.S
davem69ae144992001-06-05 04:30:03 +000030#
31# Dependencies:
Brian Paul6c0d72f2001-11-18 22:42:57 +000032# The apispec file must be in the current directory.
davem69ae144992001-06-05 04:30:03 +000033
Brian Paul6c0d72f2001-11-18 22:42:57 +000034
35import apiparser;
davem69ae144992001-06-05 04:30:03 +000036
37
38def PrintHead():
39 print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */'
40 print '#include "glapioffsets.h"'
41 print ''
davem69ae144992001-06-05 04:30:03 +000042 print '/* The _glapi_Dispatch symbol addresses get relocated into the'
43 print ' * sethi/or instruction sequences below at library init time.'
44 print ' */'
45 print ''
davem694a497e62001-06-06 22:55:28 +000046 print ''
47 print '.text'
48 print '.align 32'
49 print '.globl __glapi_sparc_icache_flush'
50 print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
51 print '\tflush\t%o0'
52 print '\tretl'
Brian Paul6c0d72f2001-11-18 22:42:57 +000053 print '\tnop'
davem694a497e62001-06-06 22:55:28 +000054 print ''
davem69775355a2001-06-05 23:54:00 +000055 print '.data'
davem69ae144992001-06-05 04:30:03 +000056 print '.align 64'
57 print ''
davem69775355a2001-06-05 23:54:00 +000058 print '.globl _mesa_sparc_glapi_begin'
davem69636fb6c2001-08-03 13:16:31 +000059 print '.type _mesa_sparc_glapi_begin,#function'
davem69775355a2001-06-05 23:54:00 +000060 print '_mesa_sparc_glapi_begin:'
davem69ae144992001-06-05 04:30:03 +000061 return
62#endif
63
64def PrintTail():
65 print '\t nop'
66 print ''
davem69775355a2001-06-05 23:54:00 +000067 print '.globl _mesa_sparc_glapi_end'
davem69636fb6c2001-08-03 13:16:31 +000068 print '.type _mesa_sparc_glapi_end,#function'
davem69775355a2001-06-05 23:54:00 +000069 print '_mesa_sparc_glapi_end:'
70 print ''
davem69ae144992001-06-05 04:30:03 +000071#endif
72
73
Brian Paul6c0d72f2001-11-18 22:42:57 +000074
75records = []
76
77def FindOffset(funcName):
78 for (name, alias, offset) in records:
79 if name == funcName:
80 return offset
81 #endif
82 #endfor
83 return -1
84#enddef
85
86def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset):
87 argList = apiparser.MakeArgList(argTypeList, argNameList)
88 if alias != '':
89 dispatchName = alias
90 else:
91 dispatchName = name
92 #endif
93
94 if offset < 0:
95 # try to find offset from alias name
96 assert dispatchName != ''
97 offset = FindOffset(dispatchName)
98 if offset == -1:
99 #print 'Cannot dispatch %s' % name
100 return
101 #endif
102 #endif
103
104 # save this info in case we need to look up an alias later
105 records.append((name, dispatchName, offset))
106
107 # print the assembly code
davem69ae144992001-06-05 04:30:03 +0000108 print ''
Brian Paulefe2baa2002-01-03 16:33:59 +0000109 print '.globl gl%s' % (name)
110 print '.type gl%s,#function' % (name)
111 print 'gl%s:' % (name)
Brian Paul9a90cd42003-12-01 22:40:26 +0000112 print '#if defined(__sparc_v9__) && !defined(__linux__)'
davem69ae144992001-06-05 04:30:03 +0000113 print '\tsethi\t%hi(0x00000000), %g2'
114 print '\tsethi\t%hi(0x00000000), %g1'
115 print '\tor\t%g2, %lo(0x00000000), %g2'
116 print '\tor\t%g1, %lo(0x00000000), %g1'
117 print '\tsllx\t%g2, 32, %g2'
davem69775355a2001-06-05 23:54:00 +0000118 print '\tldx\t[%g1 + %g2], %g1'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000119 print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (dispatchName)
120 print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (dispatchName)
davem69ae144992001-06-05 04:30:03 +0000121 print '\tldx\t[%g1 + %g2], %g3'
122 print '#else'
123 print '\tsethi\t%hi(0x00000000), %g1'
davem69775355a2001-06-05 23:54:00 +0000124 print '\tld\t[%g1 + %lo(0x00000000)], %g1'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000125 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (dispatchName)
davem69ae144992001-06-05 04:30:03 +0000126 print '#endif'
127 print '\tjmpl\t%g3, %g0'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000128 print '\tnop'
davem69ae144992001-06-05 04:30:03 +0000129#enddef
130
131
davem69ae144992001-06-05 04:30:03 +0000132PrintHead()
Brian Paul6c0d72f2001-11-18 22:42:57 +0000133apiparser.ProcessSpecFile("APIspec", EmitFunction)
davem69ae144992001-06-05 04:30:03 +0000134PrintTail()