Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Daniel Borca | 79fa6b9 | 2003-10-23 13:28:05 +0000 | [diff] [blame^] | 3 | # $Id: glx86asm.py,v 1.9 2003/10/23 13:28:06 dborca 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__' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 46 | print '' |
| 47 | print '#if defined(STDCALL_API)' |
| 48 | print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))' |
| 49 | print '#elif defined(USE_MGL_NAMESPACE)' |
| 50 | print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 51 | print '#else' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 52 | print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 53 | print '#endif' |
| 54 | print '' |
| 55 | print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' |
| 56 | print '' |
Daniel Borca | 79fa6b9 | 2003-10-23 13:28:05 +0000 | [diff] [blame^] | 57 | print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 58 | print '#define GLOBL_FN(x) GLOBL x ; .type x,@function' |
| 59 | print '#else' |
| 60 | print '#define GLOBL_FN(x) GLOBL x' |
| 61 | print '#endif' |
| 62 | print '' |
Kendall Bennett | 9b77fb7 | 2003-10-14 23:47:21 +0000 | [diff] [blame] | 63 | print 'SEG_TEXT' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 64 | print '' |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 65 | print 'EXTERN GLNAME(_glapi_Dispatch)' |
| 66 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 67 | return |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 68 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | def PrintTail(): |
| 72 | print '' |
| 73 | print '#endif /* __WIN32__ */' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 74 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 75 | |
| 76 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 77 | |
| 78 | records = [] |
| 79 | |
| 80 | def FindOffset(funcName): |
| 81 | for (name, alias, offset) in records: |
| 82 | if name == funcName: |
| 83 | return offset |
| 84 | #endif |
| 85 | #endfor |
| 86 | return -1 |
| 87 | #enddef |
| 88 | |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 89 | # Find the size of the arguments on the stack for _stdcall name mangling |
| 90 | def FindStackSize(typeList): |
| 91 | result = 0 |
| 92 | for typ in typeList: |
| 93 | if typ == 'GLdouble' or typ == 'GLclampd': |
| 94 | result += 8; |
| 95 | else: |
| 96 | result += 4; |
| 97 | #endif |
| 98 | #endfor |
| 99 | return result |
| 100 | #enddef |
| 101 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 102 | def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset): |
| 103 | argList = apiparser.MakeArgList(argTypeList, argNameList) |
| 104 | if alias != '': |
| 105 | dispatchName = alias |
| 106 | else: |
| 107 | dispatchName = name |
| 108 | #endif |
| 109 | |
| 110 | if offset < 0: |
| 111 | # try to find offset from alias name |
| 112 | assert dispatchName != '' |
| 113 | offset = FindOffset(dispatchName) |
| 114 | if offset == -1: |
| 115 | #print 'Cannot dispatch %s' % name |
| 116 | return |
| 117 | #endif |
| 118 | #endif |
| 119 | |
| 120 | # save this info in case we need to look up an alias later |
| 121 | records.append((name, dispatchName, offset)) |
| 122 | |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 123 | # Find the argument stack size for _stdcall name mangling |
| 124 | stackSize = FindStackSize(argTypeList) |
| 125 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 126 | # print the assembly code |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 127 | print 'ALIGNTEXT16' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 128 | print "GLOBL_FN(GL_PREFIX(%s,%s@%s))" % (name, name, stackSize) |
| 129 | print "GL_PREFIX(%s,%s@%s):" % (name, name, stackSize) |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 130 | print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 131 | print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 132 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 133 | #enddef |
| 134 | |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 135 | PrintHead() |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 136 | apiparser.ProcessSpecFile("APIspec", EmitFunction) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 137 | PrintTail() |