Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Kendall Bennett | 9b77fb7 | 2003-10-14 23:47:21 +0000 | [diff] [blame] | 3 | # $Id: glx86asm.py,v 1.7 2003/10/14 23:47:21 kendallb Exp $ |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 4 | |
| 5 | # Mesa 3-D graphics library |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 6 | # Version: 4.1 |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 7 | # |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 8 | # Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 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 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 28 | # Generate the src/X86/glapi_x86.S file. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 29 | # |
| 30 | # Usage: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 31 | # gloffsets.py >glapi_x86.S |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 32 | # |
| 33 | # Dependencies: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 34 | # The apispec file must be in the current directory. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 35 | |
| 36 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 37 | import apiparser |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def PrintHead(): |
| 41 | print '/* DO NOT EDIT - This file generated automatically with glx86asm.py script */' |
| 42 | print '#include "assyntax.h"' |
| 43 | print '#include "glapioffsets.h"' |
| 44 | print '' |
| 45 | print '#ifndef __WIN32__' |
| 46 | print '' |
| 47 | print '#if defined(USE_MGL_NAMESPACE)' |
Brian Paul | 37cfb3b | 2000-09-06 17:33:40 +0000 | [diff] [blame] | 48 | print '#define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 49 | print '#else' |
Brian Paul | 37cfb3b | 2000-09-06 17:33:40 +0000 | [diff] [blame] | 50 | print '#define GL_PREFIX(n) GLNAME(CONCAT(gl,n))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 51 | print '#endif' |
| 52 | print '' |
| 53 | print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' |
| 54 | print '' |
Brian Paul | f9e75c3 | 2002-04-02 16:18:20 +0000 | [diff] [blame] | 55 | print '#if defined(GNU_ASSEMBLER) && !defined(DJGPP)' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 56 | print '#define GLOBL_FN(x) GLOBL x ; .type x,@function' |
| 57 | print '#else' |
| 58 | print '#define GLOBL_FN(x) GLOBL x' |
| 59 | print '#endif' |
| 60 | print '' |
Kendall Bennett | 9b77fb7 | 2003-10-14 23:47:21 +0000 | [diff] [blame] | 61 | print 'SEG_TEXT' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 62 | print '' |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 63 | print 'EXTERN GLNAME(_glapi_Dispatch)' |
| 64 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 65 | return |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 66 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | def PrintTail(): |
| 70 | print '' |
| 71 | print '#endif /* __WIN32__ */' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 72 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 73 | |
| 74 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 75 | |
| 76 | records = [] |
| 77 | |
| 78 | def FindOffset(funcName): |
| 79 | for (name, alias, offset) in records: |
| 80 | if name == funcName: |
| 81 | return offset |
| 82 | #endif |
| 83 | #endfor |
| 84 | return -1 |
| 85 | #enddef |
| 86 | |
| 87 | def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset): |
| 88 | argList = apiparser.MakeArgList(argTypeList, argNameList) |
| 89 | if alias != '': |
| 90 | dispatchName = alias |
| 91 | else: |
| 92 | dispatchName = name |
| 93 | #endif |
| 94 | |
| 95 | if offset < 0: |
| 96 | # try to find offset from alias name |
| 97 | assert dispatchName != '' |
| 98 | offset = FindOffset(dispatchName) |
| 99 | if offset == -1: |
| 100 | #print 'Cannot dispatch %s' % name |
| 101 | return |
| 102 | #endif |
| 103 | #endif |
| 104 | |
| 105 | # save this info in case we need to look up an alias later |
| 106 | records.append((name, dispatchName, offset)) |
| 107 | |
| 108 | # print the assembly code |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 109 | print 'ALIGNTEXT16' |
| 110 | print "GLOBL_FN(GL_PREFIX(%s))" % (name) |
| 111 | print "GL_PREFIX(%s):" % (name) |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 112 | print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 113 | print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 114 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 115 | |
| 116 | #enddef |
| 117 | |
| 118 | |
| 119 | |
| 120 | PrintHead() |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 121 | apiparser.ProcessSpecFile("APIspec", EmitFunction) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 122 | PrintTail() |