davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 3 | # Mesa 3-D graphics library |
Brian Paul | 9a90cd4 | 2003-12-01 22:40:26 +0000 | [diff] [blame^] | 4 | # Version: 5.1 |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 5 | # |
Brian Paul | 9a90cd4 | 2003-12-01 22:40:26 +0000 | [diff] [blame^] | 6 | # Copyright (C) 1999-2003 Brian Paul All Rights Reserved. |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 7 | # |
| 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 Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 26 | # Generate the src/SPARC/glapi_sparc.S file. |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 27 | # |
| 28 | # Usage: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 29 | # gloffsets.py >glapi_sparc.S |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 30 | # |
| 31 | # Dependencies: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 32 | # The apispec file must be in the current directory. |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 33 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 34 | |
| 35 | import apiparser; |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | def PrintHead(): |
| 39 | print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */' |
| 40 | print '#include "glapioffsets.h"' |
| 41 | print '' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 42 | 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 '' |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 46 | 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 Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 53 | print '\tnop' |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 54 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 55 | print '.data' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 56 | print '.align 64' |
| 57 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 58 | print '.globl _mesa_sparc_glapi_begin' |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame] | 59 | print '.type _mesa_sparc_glapi_begin,#function' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 60 | print '_mesa_sparc_glapi_begin:' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 61 | return |
| 62 | #endif |
| 63 | |
| 64 | def PrintTail(): |
| 65 | print '\t nop' |
| 66 | print '' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 67 | print '.globl _mesa_sparc_glapi_end' |
davem69 | 636fb6c | 2001-08-03 13:16:31 +0000 | [diff] [blame] | 68 | print '.type _mesa_sparc_glapi_end,#function' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 69 | print '_mesa_sparc_glapi_end:' |
| 70 | print '' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 71 | #endif |
| 72 | |
| 73 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 74 | |
| 75 | records = [] |
| 76 | |
| 77 | def 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 | |
| 86 | def 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 |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 108 | print '' |
Brian Paul | efe2baa | 2002-01-03 16:33:59 +0000 | [diff] [blame] | 109 | print '.globl gl%s' % (name) |
| 110 | print '.type gl%s,#function' % (name) |
| 111 | print 'gl%s:' % (name) |
Brian Paul | 9a90cd4 | 2003-12-01 22:40:26 +0000 | [diff] [blame^] | 112 | print '#if defined(__sparc_v9__) && !defined(__linux__)' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 113 | 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' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 118 | print '\tldx\t[%g1 + %g2], %g1' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 119 | print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (dispatchName) |
| 120 | print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (dispatchName) |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 121 | print '\tldx\t[%g1 + %g2], %g3' |
| 122 | print '#else' |
| 123 | print '\tsethi\t%hi(0x00000000), %g1' |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 124 | print '\tld\t[%g1 + %lo(0x00000000)], %g1' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 125 | print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (dispatchName) |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 126 | print '#endif' |
| 127 | print '\tjmpl\t%g3, %g0' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 128 | print '\tnop' |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 129 | #enddef |
| 130 | |
| 131 | |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 132 | PrintHead() |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 133 | apiparser.ProcessSpecFile("APIspec", EmitFunction) |
davem69 | ae14499 | 2001-06-05 04:30:03 +0000 | [diff] [blame] | 134 | PrintTail() |