1 | # Copyright (c) 2001, Stanford University
|
---|
2 | # All rights reserved.
|
---|
3 | #
|
---|
4 | # See the file LICENSE.txt for information on redistributing this software.
|
---|
5 |
|
---|
6 | from __future__ import print_function
|
---|
7 | import sys
|
---|
8 |
|
---|
9 | import apiutil
|
---|
10 |
|
---|
11 |
|
---|
12 | apiutil.CopyrightC()
|
---|
13 |
|
---|
14 | print("""/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
|
---|
15 |
|
---|
16 | #include "unpacker.h"
|
---|
17 | #include "cr_opcodes.h"
|
---|
18 | #include "cr_error.h"
|
---|
19 | #include "cr_mem.h"
|
---|
20 | #include "cr_spu.h"
|
---|
21 | #include "unpack_extend.h"
|
---|
22 | #include <stdio.h>
|
---|
23 | #include <memory.h>
|
---|
24 |
|
---|
25 | #include <iprt/cdefs.h>
|
---|
26 |
|
---|
27 | DECLEXPORT(const unsigned char *) cr_unpackData = NULL;
|
---|
28 | DECLEXPORT(const unsigned char *) cr_unpackDataEnd = NULL;
|
---|
29 |
|
---|
30 | static void crUnpackExtend(PCrUnpackerState pState);
|
---|
31 | static void crUnpackExtendDbg(PCrUnpackerState pState);
|
---|
32 |
|
---|
33 | #if 0 //def DEBUG_misha
|
---|
34 | //# define CR_UNPACK_DEBUG_OPCODES
|
---|
35 | # define CR_UNPACK_DEBUG_LAST_OPCODES
|
---|
36 | # define CR_UNPACK_DEBUG_PREV_OPCODES
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #ifdef CR_UNPACK_DEBUG_PREV_OPCODES
|
---|
40 | static GLenum g_VBoxDbgCrPrevOpcode = 0;
|
---|
41 | static GLenum g_VBoxDbgCrPrevExtendOpcode = 0;
|
---|
42 | #endif
|
---|
43 | """)
|
---|
44 |
|
---|
45 | nodebug_opcodes = [
|
---|
46 | "CR_MULTITEXCOORD2FARB_OPCODE",
|
---|
47 | "CR_VERTEX3F_OPCODE",
|
---|
48 | "CR_NORMAL3F_OPCODE",
|
---|
49 | "CR_COLOR4UB_OPCODE",
|
---|
50 | "CR_LOADIDENTITY_OPCODE",
|
---|
51 | "CR_MATRIXMODE_OPCODE",
|
---|
52 | "CR_LOADMATRIXF_OPCODE",
|
---|
53 | "CR_DISABLE_OPCODE",
|
---|
54 | "CR_COLOR4F_OPCODE",
|
---|
55 | "CR_ENABLE_OPCODE",
|
---|
56 | "CR_BEGIN_OPCODE",
|
---|
57 | "CR_END_OPCODE",
|
---|
58 | "CR_SECONDARYCOLOR3FEXT_OPCODE"
|
---|
59 | ]
|
---|
60 |
|
---|
61 | nodebug_extopcodes = [
|
---|
62 | "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
|
---|
63 | ]
|
---|
64 |
|
---|
65 | #
|
---|
66 | # Useful functions
|
---|
67 | #
|
---|
68 |
|
---|
69 | def ReadData( offset, arg_type ):
|
---|
70 | """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
|
---|
71 | argument out of the buffer's operand area."""
|
---|
72 | if arg_type == "GLdouble" or arg_type == "GLclampd":
|
---|
73 | retval = "READ_DOUBLE(pState, %d)" % offset
|
---|
74 | else:
|
---|
75 | retval = "READ_DATA(pState, %d, %s)" % (offset, arg_type)
|
---|
76 | return retval
|
---|
77 |
|
---|
78 |
|
---|
79 | def FindReturnPointer( return_type, params ):
|
---|
80 | """For GL functions that return values (either as the return value or
|
---|
81 | through a pointer parameter) emit a SET_RETURN_PTR call."""
|
---|
82 | arg_len = apiutil.PacketLength( params )
|
---|
83 | if (return_type != 'void'):
|
---|
84 | print('\tSET_RETURN_PTR(pState, %d);' % (arg_len + 8)) # extended opcode plus packet length
|
---|
85 | else:
|
---|
86 | paramList = [ ('foo', 'void *', 0) ]
|
---|
87 | print('\tSET_RETURN_PTR(pState, %d);' % (arg_len + 8 - apiutil.PacketLength(paramList)))
|
---|
88 |
|
---|
89 |
|
---|
90 | def getWritebackPointerOffset(return_type, params):
|
---|
91 | """Returns the offset of the writeback pointer"""
|
---|
92 | arg_len = apiutil.PacketLength( params )
|
---|
93 | if return_type != 'void':
|
---|
94 | paramList = [ ('foo', 'void *', 0) ]
|
---|
95 | arg_len += apiutil.PacketLength( paramList )
|
---|
96 |
|
---|
97 | return arg_len + 8 # extended opcode plus packet length
|
---|
98 |
|
---|
99 | def FindWritebackPointer( return_type, params ):
|
---|
100 | """Emit a SET_WRITEBACK_PTR call."""
|
---|
101 | print('\tSET_WRITEBACK_PTR(pState, %d);' % getWritebackPointerOffset(return_type, params))
|
---|
102 |
|
---|
103 |
|
---|
104 | def MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
|
---|
105 | counter = counter_init
|
---|
106 | copy_of_params = params[:]
|
---|
107 |
|
---|
108 | for i in range( 0, len(params) ):
|
---|
109 | (name, type, vecSize) = params[i]
|
---|
110 | if apiutil.IsPointer(copy_of_params[i][1]):
|
---|
111 | params[i] = ('NULL', type, vecSize)
|
---|
112 | copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
|
---|
113 | if not "get" in apiutil.Properties(func_name):
|
---|
114 | print('\tcrError( "%s needs to be special cased!" );' % func_name)
|
---|
115 | else:
|
---|
116 | print("\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) ))
|
---|
117 | counter += apiutil.sizeof(copy_of_params[i][1])
|
---|
118 |
|
---|
119 | if ("get" in apiutil.Properties(func_name)):
|
---|
120 | FindReturnPointer( return_type, params )
|
---|
121 | FindWritebackPointer( return_type, params )
|
---|
122 |
|
---|
123 | if return_type != "void":
|
---|
124 | print("\t(void)", end=" ")
|
---|
125 | else:
|
---|
126 | print("\t", end="")
|
---|
127 | print("pState->pDispatchTbl->%s(%s);" % (func_name, apiutil.MakeCallStringForDispatcher(params)))
|
---|
128 |
|
---|
129 |
|
---|
130 | def MakeVectorCall( return_type, func_name, arg_type ):
|
---|
131 | """Convert a call like glVertex3f to glVertex3fv."""
|
---|
132 | vec_func = apiutil.VectorFunction(func_name)
|
---|
133 | params = apiutil.Parameters(vec_func)
|
---|
134 | assert len(params) == 1
|
---|
135 | (arg_name, vecType, vecSize) = params[0]
|
---|
136 |
|
---|
137 | if arg_type == "GLdouble" or arg_type == "GLclampd":
|
---|
138 | print("#ifdef CR_UNALIGNED_ACCESS_OKAY")
|
---|
139 | print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" % (vec_func, vecType))
|
---|
140 | print("#else")
|
---|
141 | for index in range(0, vecSize):
|
---|
142 | print("\tGLdouble v" + repr(index) + " = READ_DOUBLE(pState, " + repr(index * 8) + ");")
|
---|
143 | if return_type != "void":
|
---|
144 | print("\t(void) pState->pDispatchTbl->%s(" % func_name, end="")
|
---|
145 | else:
|
---|
146 | print("\tpState->pDispatchTbl->%s(" % func_name, end="")
|
---|
147 | for index in range(0, vecSize):
|
---|
148 | print("v" + repr(index), end="")
|
---|
149 | if index != vecSize - 1:
|
---|
150 | print(",", end=" ")
|
---|
151 | print(");")
|
---|
152 | print("#endif")
|
---|
153 | else:
|
---|
154 | print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" % (vec_func, vecType))
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
159 |
|
---|
160 |
|
---|
161 | #
|
---|
162 | # Generate unpack functions for all the simple functions.
|
---|
163 | #
|
---|
164 | for func_name in keys:
|
---|
165 | if (not "pack" in apiutil.ChromiumProps(func_name) or
|
---|
166 | apiutil.FindSpecial( "unpacker", func_name )):
|
---|
167 | continue
|
---|
168 |
|
---|
169 | params = apiutil.Parameters(func_name)
|
---|
170 | return_type = apiutil.ReturnType(func_name)
|
---|
171 |
|
---|
172 | packet_length = apiutil.PacketLength( params )
|
---|
173 | print("static void crUnpack%s(PCrUnpackerState pState)" % func_name)
|
---|
174 | print("{")
|
---|
175 | if ("get" in apiutil.Properties(func_name)):
|
---|
176 | print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % getWritebackPointerOffset(return_type, params));
|
---|
177 | elif packet_length != 0:
|
---|
178 | print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % packet_length);
|
---|
179 |
|
---|
180 | vector_func = apiutil.VectorFunction(func_name)
|
---|
181 | if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
|
---|
182 | MakeVectorCall( return_type, func_name, params[0][1] )
|
---|
183 | else:
|
---|
184 | MakeNormalCall( return_type, func_name, params )
|
---|
185 | if packet_length == 0:
|
---|
186 | print("\tINCR_DATA_PTR_NO_ARGS(pState);")
|
---|
187 | else:
|
---|
188 | print("\tINCR_DATA_PTR(pState, %d);" % packet_length)
|
---|
189 | print("}\n")
|
---|
190 |
|
---|
191 |
|
---|
192 | #
|
---|
193 | # Emit some code
|
---|
194 | #
|
---|
195 | print("""
|
---|
196 | CR_UNPACK_BUFFER_TYPE crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes)
|
---|
197 | {
|
---|
198 | const uint8_t *pu8Codes = (const uint8_t *)opcodes;
|
---|
199 |
|
---|
200 | uint8_t first;
|
---|
201 | uint8_t last;
|
---|
202 |
|
---|
203 | if (!num_opcodes)
|
---|
204 | return CR_UNPACK_BUFFER_TYPE_GENERIC;
|
---|
205 |
|
---|
206 | first = pu8Codes[0];
|
---|
207 | last = pu8Codes[1-(int)num_opcodes];
|
---|
208 |
|
---|
209 | switch (last)
|
---|
210 | {
|
---|
211 | case CR_CMDBLOCKFLUSH_OPCODE:
|
---|
212 | return CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH;
|
---|
213 | case CR_CMDBLOCKEND_OPCODE:
|
---|
214 | return (first == CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
|
---|
215 | default:
|
---|
216 | return (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | void crUnpack(PCrUnpackerState pState)
|
---|
221 | {
|
---|
222 | unsigned int i;
|
---|
223 |
|
---|
224 | #if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
|
---|
225 | crDebug("crUnpack: %d opcodes", pState->cOpcodes);
|
---|
226 | #endif
|
---|
227 |
|
---|
228 | for (i = 0; i < pState->cOpcodes && RT_SUCCESS(pState->rcUnpack); i++)
|
---|
229 | {
|
---|
230 |
|
---|
231 | CRDBGPTR_CHECKZ(pState->pWritebackPtr);
|
---|
232 | CRDBGPTR_CHECKZ(pState->pReturnPtr);
|
---|
233 |
|
---|
234 | /*crDebug(\"Unpacking opcode \%d\", *pState->pbOpcodes);*/
|
---|
235 | #ifdef CR_UNPACK_DEBUG_PREV_OPCODES
|
---|
236 | g_VBoxDbgCrPrevOpcode = *pState->pbOpcodes;
|
---|
237 | #endif
|
---|
238 | switch( *pState->pbOpcodes )
|
---|
239 | {""")
|
---|
240 |
|
---|
241 | #
|
---|
242 | # Emit switch cases for all unextended opcodes
|
---|
243 | #
|
---|
244 | for func_name in keys:
|
---|
245 | if "pack" in apiutil.ChromiumProps(func_name):
|
---|
246 | print('\t\t\tcase %s:' % apiutil.OpcodeName( func_name ))
|
---|
247 | if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
|
---|
248 | print("""
|
---|
249 | #ifdef CR_UNPACK_DEBUG_LAST_OPCODES
|
---|
250 | if (i==(num_opcodes-1))
|
---|
251 | #endif
|
---|
252 | #if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
|
---|
253 | crDebug("Unpack: %s");
|
---|
254 | #endif """ % apiutil.OpcodeName(func_name))
|
---|
255 | print('\t\t\t\tcrUnpack%s(pState); \n\t\t\t\tbreak;' % func_name)
|
---|
256 |
|
---|
257 | print("""
|
---|
258 | case CR_EXTEND_OPCODE:
|
---|
259 | #ifdef CR_UNPACK_DEBUG_OPCODES
|
---|
260 | crUnpackExtendDbg(pState);
|
---|
261 | #else
|
---|
262 | # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
|
---|
263 | if (i==(num_opcodes-1)) crUnpackExtendDbg(pState);
|
---|
264 | else
|
---|
265 | # endif
|
---|
266 | crUnpackExtend(pState);
|
---|
267 | #endif
|
---|
268 | break;
|
---|
269 | case CR_CMDBLOCKBEGIN_OPCODE:
|
---|
270 | case CR_CMDBLOCKEND_OPCODE:
|
---|
271 | case CR_CMDBLOCKFLUSH_OPCODE:
|
---|
272 | case CR_NOP_OPCODE:
|
---|
273 | INCR_DATA_PTR_NO_ARGS(pState);
|
---|
274 | break;
|
---|
275 | default:
|
---|
276 | crError( "Unknown opcode: %d", *pState->pbOpcodes );
|
---|
277 | break;
|
---|
278 | }
|
---|
279 |
|
---|
280 | CRDBGPTR_CHECKZ(pState->pWritebackPtr);
|
---|
281 | CRDBGPTR_CHECKZ(pState->pReturnPtr);
|
---|
282 | pState->pbOpcodes--;
|
---|
283 | }
|
---|
284 | }""")
|
---|
285 |
|
---|
286 |
|
---|
287 | #
|
---|
288 | # Emit unpack functions for extended opcodes, non-special functions only.
|
---|
289 | #
|
---|
290 | for func_name in keys:
|
---|
291 | if ("extpack" in apiutil.ChromiumProps(func_name)
|
---|
292 | and not apiutil.FindSpecial("unpacker", func_name)):
|
---|
293 | return_type = apiutil.ReturnType(func_name)
|
---|
294 | params = apiutil.Parameters(func_name)
|
---|
295 | print('static void crUnpackExtend%s(PCrUnpackerState pState)' % func_name)
|
---|
296 | print('{')
|
---|
297 | if ("get" in apiutil.Properties(func_name)):
|
---|
298 | print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % (8 + getWritebackPointerOffset(return_type, params)));
|
---|
299 | else:
|
---|
300 | print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % (8 + apiutil.PacketLength( params )));
|
---|
301 | MakeNormalCall( return_type, func_name, params, 8 )
|
---|
302 | print('}\n')
|
---|
303 |
|
---|
304 | print('static void crUnpackExtend(PCrUnpackerState pState)')
|
---|
305 | print('{')
|
---|
306 | print('\tCHECK_BUFFER_SIZE_STATIC_LAST(pState, 4, GLenum);');
|
---|
307 | print('\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' ))
|
---|
308 | print('')
|
---|
309 | print('#ifdef CR_UNPACK_DEBUG_PREV_OPCODES')
|
---|
310 | print('\tg_VBoxDbgCrPrevExtendOpcode = extend_opcode;')
|
---|
311 | print('#endif')
|
---|
312 | print('')
|
---|
313 | print('\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/')
|
---|
314 | print('\tswitch( extend_opcode )')
|
---|
315 | print('\t{')
|
---|
316 |
|
---|
317 |
|
---|
318 | #
|
---|
319 | # Emit switch statement for extended opcodes
|
---|
320 | #
|
---|
321 | for func_name in keys:
|
---|
322 | if "extpack" in apiutil.ChromiumProps(func_name):
|
---|
323 | print('\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name ))
|
---|
324 | # print('\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )))
|
---|
325 | print('\t\t\tcrUnpackExtend%s(pState);' % func_name)
|
---|
326 | print('\t\t\tbreak;')
|
---|
327 |
|
---|
328 | print(""" default:
|
---|
329 | crError( "Unknown extended opcode: %d", (int) extend_opcode );
|
---|
330 | break;
|
---|
331 | }
|
---|
332 | INCR_VAR_PTR(pState);
|
---|
333 | }""")
|
---|
334 |
|
---|
335 | print('static void crUnpackExtendDbg(PCrUnpackerState pState)')
|
---|
336 | print('{')
|
---|
337 | print('\tCHECK_BUFFER_SIZE_STATIC_LAST(pState, 4, GLenum);');
|
---|
338 | print('\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' ))
|
---|
339 | print('')
|
---|
340 | print('#ifdef CR_UNPACK_DEBUG_PREV_OPCODES')
|
---|
341 | print('\tg_VBoxDbgCrPrevExtendOpcode = extend_opcode;')
|
---|
342 | print('#endif')
|
---|
343 | print('')
|
---|
344 | print('\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/')
|
---|
345 | print('\tswitch( extend_opcode )')
|
---|
346 | print('\t{')
|
---|
347 |
|
---|
348 |
|
---|
349 | #
|
---|
350 | # Emit switch statement for extended opcodes
|
---|
351 | #
|
---|
352 | for func_name in keys:
|
---|
353 | if "extpack" in apiutil.ChromiumProps(func_name):
|
---|
354 | print('\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name ))
|
---|
355 | if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
|
---|
356 | print('\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name ))
|
---|
357 | print('\t\t\tcrUnpackExtend%s(pState);' % func_name)
|
---|
358 | print('\t\t\tbreak;')
|
---|
359 |
|
---|
360 | print(""" default:
|
---|
361 | crError( "Unknown extended opcode: %d", (int) extend_opcode );
|
---|
362 | break;
|
---|
363 | }
|
---|
364 | INCR_VAR_PTR(pState);
|
---|
365 | }""")
|
---|