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 |
|
---|
7 | #ifndef CR_UNPACK_H
|
---|
8 | #define CR_UNPACK_H
|
---|
9 |
|
---|
10 | #include "cr_compiler.h"
|
---|
11 | #include "cr_spu.h"
|
---|
12 | #include "cr_protocol.h"
|
---|
13 | #include "cr_mem.h"
|
---|
14 | #include "cr_opcodes.h"
|
---|
15 |
|
---|
16 | #include <iprt/types.h>
|
---|
17 |
|
---|
18 | #ifdef __cplusplus
|
---|
19 | extern "C" {
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | extern SPUDispatchTable cr_unpackDispatch;
|
---|
23 | /*extern DLLDATA(const unsigned char *) cr_unpackData;*/
|
---|
24 | extern DECLEXPORT(const unsigned char *) cr_unpackData;
|
---|
25 | extern DECLEXPORT(const unsigned char *) cr_unpackDataEnd;
|
---|
26 |
|
---|
27 | DECLEXPORT(void) crUnpackSetReturnPointer( CRNetworkPointer *ptr );
|
---|
28 | DECLEXPORT(void) crUnpackSetWritebackPointer( CRNetworkPointer *ptr );
|
---|
29 | DECLEXPORT(void) crUnpack( const void *data, const void *data_end, const void *opcodes, unsigned int num_opcodes, SPUDispatchTable *table );
|
---|
30 | DECLEXPORT(void) crUnpackPush(void);
|
---|
31 | DECLEXPORT(void) crUnpackPop(void);
|
---|
32 |
|
---|
33 | typedef enum
|
---|
34 | {
|
---|
35 | CR_UNPACK_BUFFER_TYPE_GENERIC = 0,
|
---|
36 | CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN,
|
---|
37 | CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH,
|
---|
38 | CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END
|
---|
39 | } CR_UNPACK_BUFFER_TYPE;
|
---|
40 |
|
---|
41 | DECLEXPORT(CR_UNPACK_BUFFER_TYPE) crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes);
|
---|
42 |
|
---|
43 | extern CRNetworkPointer * return_ptr;
|
---|
44 | extern CRNetworkPointer * writeback_ptr;
|
---|
45 |
|
---|
46 | #if defined(LINUX) || defined(WINDOWS)
|
---|
47 | #define CR_UNALIGNED_ACCESS_OKAY
|
---|
48 | #else
|
---|
49 | #undef CR_UNALIGNED_ACCESS_OKAY
|
---|
50 | #endif
|
---|
51 | DECLEXPORT(double) crReadUnalignedDouble( const void *buffer );
|
---|
52 |
|
---|
53 | #define READ_DATA( offset, type ) \
|
---|
54 | *( (const type *) (cr_unpackData + (offset)))
|
---|
55 |
|
---|
56 | #ifdef CR_UNALIGNED_ACCESS_OKAY
|
---|
57 | #define READ_DOUBLE( offset ) \
|
---|
58 | READ_DATA( offset, GLdouble )
|
---|
59 | #else
|
---|
60 | #define READ_DOUBLE( offset ) \
|
---|
61 | crReadUnalignedDouble( cr_unpackData + (offset) )
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #define READ_NETWORK_POINTER( offset ) \
|
---|
65 | ( cr_unpackData + (offset) )
|
---|
66 |
|
---|
67 | /* XXX make this const */
|
---|
68 | #define DATA_POINTER( offset, type ) \
|
---|
69 | ( (type *) (cr_unpackData + (offset)) )
|
---|
70 |
|
---|
71 | #define DATA_POINTER_CHECK( offset ) \
|
---|
72 | ( (cr_unpackDataEnd ? cr_unpackData + (offset) < cr_unpackDataEnd : true) )
|
---|
73 |
|
---|
74 | #define INCR_DATA_PTR( delta ) \
|
---|
75 | cr_unpackData += (delta)
|
---|
76 |
|
---|
77 | #define INCR_DATA_PTR_NO_ARGS() \
|
---|
78 | INCR_DATA_PTR( 4 )
|
---|
79 |
|
---|
80 | #define INCR_VAR_PTR() \
|
---|
81 | INCR_DATA_PTR( *((int *) cr_unpackData ) )
|
---|
82 |
|
---|
83 | #define SET_RETURN_PTR( offset ) do { \
|
---|
84 | CRDBGPTR_CHECKZ(return_ptr); \
|
---|
85 | crMemcpy( return_ptr, cr_unpackData + (offset), sizeof( *return_ptr ) ); \
|
---|
86 | } while (0);
|
---|
87 |
|
---|
88 |
|
---|
89 | #define SET_WRITEBACK_PTR( offset ) do { \
|
---|
90 | CRDBGPTR_CHECKZ(writeback_ptr); \
|
---|
91 | crMemcpy( writeback_ptr, cr_unpackData + (offset), sizeof( *writeback_ptr ) ); \
|
---|
92 | } while (0);
|
---|
93 |
|
---|
94 | #ifdef __cplusplus
|
---|
95 | }
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | #endif /* CR_UNPACK_H */
|
---|