unpack.py revision 66c14dd42d5cc3f7cc1a06db62c37e87602bcac0
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Copyright (c) 2001, Stanford University
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# All rights reserved.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# See the file LICENSE.txt for information on redistributing this software.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncimport sys
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncimport apiutil
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncapiutil.CopyrightC()
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint """/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "unpacker.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_opcodes.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_error.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_mem.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_spu.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "unpack_extend.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include <stdio.h>
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include <memory.h>
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include <iprt/cdefs.h>
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncDECLEXPORT(const unsigned char *) cr_unpackData = NULL;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncSPUDispatchTable cr_unpackDispatch;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncstatic void crUnpackExtend(void);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncstatic void crUnpackExtendDbg(void);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync/*#define CR_UNPACK_DEBUG_OPCODES*/
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync/*#define CR_UNPACK_DEBUG_LAST_OPCODES*/
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync"""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncnodebug_opcodes = [
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_MULTITEXCOORD2FARB_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_VERTEX3F_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_NORMAL3F_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_COLOR4UB_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_LOADIDENTITY_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_MATRIXMODE_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_LOADMATRIXF_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_DISABLE_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_COLOR4F_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_ENABLE_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_BEGIN_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_END_OPCODE",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_SECONDARYCOLOR3FEXT_OPCODE"
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync]
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncnodebug_extopcodes = [
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Useful functions
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncdef ReadData( offset, arg_type ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync argument out of the buffer's operand area."""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if arg_type == "GLdouble" or arg_type == "GLclampd":
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync retval = "READ_DOUBLE( %d )" % offset
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync retval = "READ_DATA( %d, %s )" % (offset, arg_type)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync return retval
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncdef FindReturnPointer( return_type, params ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync """For GL functions that return values (either as the return value or
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync through a pointer parameter) emit a SET_RETURN_PTR call."""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync arg_len = apiutil.PacketLength( params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (return_type != 'void'):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\tSET_RETURN_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync paramList = [ ('foo', 'void *', 0) ]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\tSET_RETURN_PTR( %d );' % (arg_len + 8 - apiutil.PacketLength(paramList))
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncdef FindWritebackPointer( return_type, params ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync """Emit a SET_WRITEBACK_PTR call."""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync arg_len = apiutil.PacketLength( params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if return_type != 'void':
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync paramList = [ ('foo', 'void *', 0) ]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync arg_len += apiutil.PacketLength( paramList )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\tSET_WRITEBACK_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncdef MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync counter = counter_init
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync copy_of_params = params[:]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for i in range( 0, len(params) ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync (name, type, vecSize) = params[i]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if apiutil.IsPointer(copy_of_params[i][1]):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync params[i] = ('NULL', type, vecSize)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if not "get" in apiutil.Properties(func_name):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\tcrError( "%s needs to be special cased!" );' % func_name
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync counter += apiutil.sizeof(copy_of_params[i][1])
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if ("get" in apiutil.Properties(func_name)):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync FindReturnPointer( return_type, params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync FindWritebackPointer( return_type, params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if return_type != "void":
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\t(void)",
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\t",
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "cr_unpackDispatch.%s( %s );" % (func_name, apiutil.MakeCallString(params))
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncdef MakeVectorCall( return_type, func_name, arg_type ):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync """Convert a call like glVertex3f to glVertex3fv."""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync vec_func = apiutil.VectorFunction(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync params = apiutil.Parameters(vec_func)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync assert len(params) == 1
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync (arg_name, vecType, vecSize) = params[0]
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if arg_type == "GLdouble" or arg_type == "GLclampd":
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "#ifdef CR_UNALIGNED_ACCESS_OKAY"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "#else"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for index in range(0, vecSize):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tGLdouble v" + `index` + " = READ_DOUBLE(", `index * 8`, ");"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if return_type != "void":
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\t(void) cr_unpackDispatch.%s(" % func_name,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tcr_unpackDispatch.%s(" % func_name,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for index in range(0, vecSize):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "v" + `index`,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if index != vecSize - 1:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print ",",
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print ");"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "#endif"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynckeys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Generate unpack functions for all the simple functions.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncfor func_name in keys:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (not "pack" in apiutil.ChromiumProps(func_name) or
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync apiutil.FindSpecial( "unpacker", func_name )):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync continue
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync params = apiutil.Parameters(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync return_type = apiutil.ReturnType(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "static void crUnpack%s(void)" % func_name
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "{"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync vector_func = apiutil.VectorFunction(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync MakeVectorCall( return_type, func_name, params[0][1] )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync MakeNormalCall( return_type, func_name, params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync packet_length = apiutil.PacketLength( params )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if packet_length == 0:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tINCR_DATA_PTR_NO_ARGS( );"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync else:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "\tINCR_DATA_PTR( %d );" % packet_length
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print "}\n"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Emit some code
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint """
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynctypedef struct __dispatchNode {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync const unsigned char *unpackData;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync struct __dispatchNode *next;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync} DispatchNode;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncstatic DispatchNode *unpackStack = NULL;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncstatic SPUDispatchTable *cr_lastDispatch = NULL;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid crUnpackPush(void)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync DispatchNode *node = (DispatchNode*)crAlloc( sizeof( *node ) );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync node->next = unpackStack;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unpackStack = node;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync node->unpackData = cr_unpackData;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid crUnpackPop(void)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync DispatchNode *node = unpackStack;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (!node)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crError( "crUnpackPop called with an empty stack!" );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unpackStack = node->next;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_unpackData = node->unpackData;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crFree( node );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsyncCR_UNPACK_BUFFER_TYPE crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes)
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync{
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync const uint8_t *pu8Codes = (const uint8_t *)opcodes;
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync uint8_t first;
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync uint8_t last;
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync if (!num_opcodes)
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync return CR_UNPACK_BUFFER_TYPE_GENERIC;
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync first = pu8Codes[0];
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync last = pu8Codes[1-(int)num_opcodes];
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync switch (last)
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync {
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync case CR_CMDBLOCKFLUSH_OPCODE:
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync return CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH;
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync case CR_CMDBLOCKEND_OPCODE:
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync return (first == CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync default:
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync return (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync }
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync}
916fa1ce1597c87cd10eb4b8077fe31f9089f000vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid crUnpack( const void *data, const void *opcodes,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unsigned int num_opcodes, SPUDispatchTable *table )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unsigned int i;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync const unsigned char *unpack_opcodes;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (table != cr_lastDispatch)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crSPUCopyDispatchTable( &cr_unpackDispatch, table );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_lastDispatch = table;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unpack_opcodes = (const unsigned char *)opcodes;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync cr_unpackData = (const unsigned char *)data;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
ea0c46c4f46bda493e9e07b95b232c74167414bevboxsync#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crDebug("crUnpack: %d opcodes", num_opcodes);
0b118dfeb59a8bf4637e53cdcc7d963b83c7ea0dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for (i = 0 ; i < num_opcodes ; i++)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync {
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync CRDBGPTR_CHECKZ(writeback_ptr);
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync CRDBGPTR_CHECKZ(return_ptr);
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync /*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync switch( *unpack_opcodes )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync {"""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Emit switch cases for all unextended opcodes
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncfor func_name in keys:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if "pack" in apiutil.ChromiumProps(func_name):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\t\t\tcase %s:' % apiutil.OpcodeName( func_name )
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync print """
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (i==(num_opcodes-1))
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crDebug("Unpack: %s");
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif """ % apiutil.OpcodeName(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\t\t\t\tcrUnpack%s(); \n\t\t\t\tbreak;' % func_name
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint """
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case CR_EXTEND_OPCODE:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync #ifdef CR_UNPACK_DEBUG_OPCODES
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crUnpackExtendDbg();
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync #else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (i==(num_opcodes-1)) crUnpackExtendDbg();
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync # endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crUnpackExtend();
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync #endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
f3f69e0e8d6a713566e129aa3ab321b1e6b07fbcvboxsync case CR_CMDBLOCKBEGIN_OPCODE:
f3f69e0e8d6a713566e129aa3ab321b1e6b07fbcvboxsync case CR_CMDBLOCKEND_OPCODE:
66c14dd42d5cc3f7cc1a06db62c37e87602bcac0vboxsync case CR_CMDBLOCKFLUSH_OPCODE:
f3f69e0e8d6a713566e129aa3ab321b1e6b07fbcvboxsync case CR_NOP_OPCODE:
f3f69e0e8d6a713566e129aa3ab321b1e6b07fbcvboxsync INCR_DATA_PTR_NO_ARGS( );
f3f69e0e8d6a713566e129aa3ab321b1e6b07fbcvboxsync break;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync default:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crError( "Unknown opcode: %d", *unpack_opcodes );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync break;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync CRDBGPTR_CHECKZ(writeback_ptr);
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync CRDBGPTR_CHECKZ(return_ptr);
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync unpack_opcodes--;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}"""
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Emit unpack functions for extended opcodes, non-special functions only.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncfor func_name in keys:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if ("extpack" in apiutil.ChromiumProps(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync and not apiutil.FindSpecial("unpacker", func_name)):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync return_type = apiutil.ReturnType(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync params = apiutil.Parameters(func_name)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print 'static void crUnpackExtend%s(void)' % func_name
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '{'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync MakeNormalCall( return_type, func_name, params, 8 )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '}\n'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint 'static void crUnpackExtend(void)'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint '{'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint ''
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint '\tswitch( extend_opcode )'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint '\t{'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# Emit switch statement for extended opcodes
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncfor func_name in keys:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if "extpack" in apiutil.ChromiumProps(func_name):
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync# print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\t\t\tcrUnpackExtend%s( );' % func_name
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync print '\t\t\tbreak;'
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncprint """ default:
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crError( "Unknown extended opcode: %d", (int) extend_opcode );
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync break;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync INCR_VAR_PTR();
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}"""
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint 'static void crUnpackExtendDbg(void)'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint '{'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint ''
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint '\tswitch( extend_opcode )'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint '\t{'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync# Emit switch statement for extended opcodes
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncfor func_name in keys:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if "extpack" in apiutil.ChromiumProps(func_name):
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync print '\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync print '\t\t\tcrUnpackExtend%s( );' % func_name
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync print '\t\t\tbreak;'
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncprint """ default:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crError( "Unknown extended opcode: %d", (int) extend_opcode );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync INCR_VAR_PTR();
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync}"""