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 |
|
---|
26 | DECLEXPORT(void) crUnpackSetReturnPointer( CRNetworkPointer *ptr );
|
---|
27 | DECLEXPORT(void) crUnpackSetWritebackPointer( CRNetworkPointer *ptr );
|
---|
28 | DECLEXPORT(void) crUnpack( const void *data, const void *opcodes, unsigned int num_opcodes, SPUDispatchTable *table );
|
---|
29 | DECLEXPORT(void) crUnpackPush(void);
|
---|
30 | DECLEXPORT(void) crUnpackPop(void);
|
---|
31 |
|
---|
32 | typedef enum
|
---|
33 | {
|
---|
34 | CR_UNPACK_BUFFER_TYPE_GENERIC = 0,
|
---|
35 | CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN,
|
---|
36 | CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END
|
---|
37 | } CR_UNPACK_BUFFER_TYPE;
|
---|
38 |
|
---|
39 | DECLINLINE(CR_UNPACK_BUFFER_TYPE) crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes)
|
---|
40 | {
|
---|
41 | const uint8_t *pu8Codes = (const uint8_t *)opcodes;
|
---|
42 |
|
---|
43 | CR_UNPACK_BUFFER_TYPE enmType;
|
---|
44 | uint8_t first;
|
---|
45 | uint8_t last;
|
---|
46 |
|
---|
47 | if (!num_opcodes)
|
---|
48 | return CR_UNPACK_BUFFER_TYPE_GENERIC;
|
---|
49 |
|
---|
50 | first = pu8Codes[0];
|
---|
51 | last = pu8Codes[1-(int)num_opcodes];
|
---|
52 |
|
---|
53 | enmType = (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
|
---|
54 |
|
---|
55 | if (last != CR_CMDBLOCKEND_OPCODE)
|
---|
56 | return enmType;
|
---|
57 |
|
---|
58 | /* last is CMDBLOCKEND*/
|
---|
59 | return (enmType == CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
|
---|
60 | }
|
---|
61 |
|
---|
62 | extern CRNetworkPointer * return_ptr;
|
---|
63 | extern CRNetworkPointer * writeback_ptr;
|
---|
64 |
|
---|
65 | #if defined(LINUX) || defined(WINDOWS)
|
---|
66 | #define CR_UNALIGNED_ACCESS_OKAY
|
---|
67 | #else
|
---|
68 | #undef CR_UNALIGNED_ACCESS_OKAY
|
---|
69 | #endif
|
---|
70 | DECLEXPORT(double) crReadUnalignedDouble( const void *buffer );
|
---|
71 |
|
---|
72 | #define READ_DATA( offset, type ) \
|
---|
73 | *( (const type *) (cr_unpackData + (offset)))
|
---|
74 |
|
---|
75 | #ifdef CR_UNALIGNED_ACCESS_OKAY
|
---|
76 | #define READ_DOUBLE( offset ) \
|
---|
77 | READ_DATA( offset, GLdouble )
|
---|
78 | #else
|
---|
79 | #define READ_DOUBLE( offset ) \
|
---|
80 | crReadUnalignedDouble( cr_unpackData + (offset) )
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | #define READ_NETWORK_POINTER( offset ) \
|
---|
84 | ( cr_unpackData + (offset) )
|
---|
85 |
|
---|
86 | /* XXX make this const */
|
---|
87 | #define DATA_POINTER( offset, type ) \
|
---|
88 | ( (type *) (cr_unpackData + (offset)) )
|
---|
89 |
|
---|
90 | #define INCR_DATA_PTR( delta ) \
|
---|
91 | cr_unpackData += (delta)
|
---|
92 |
|
---|
93 | #define INCR_DATA_PTR_NO_ARGS() \
|
---|
94 | INCR_DATA_PTR( 4 )
|
---|
95 |
|
---|
96 | #define INCR_VAR_PTR() \
|
---|
97 | INCR_DATA_PTR( *((int *) cr_unpackData ) )
|
---|
98 |
|
---|
99 | #define SET_RETURN_PTR( offset ) do { \
|
---|
100 | CRDBGPTR_CHECKZ(return_ptr); \
|
---|
101 | crMemcpy( return_ptr, cr_unpackData + (offset), sizeof( *return_ptr ) ); \
|
---|
102 | } while (0);
|
---|
103 |
|
---|
104 |
|
---|
105 | #define SET_WRITEBACK_PTR( offset ) do { \
|
---|
106 | CRDBGPTR_CHECKZ(writeback_ptr); \
|
---|
107 | crMemcpy( writeback_ptr, cr_unpackData + (offset), sizeof( *writeback_ptr ) ); \
|
---|
108 | } while (0);
|
---|
109 |
|
---|
110 | #ifdef __cplusplus
|
---|
111 | }
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | #endif /* CR_UNPACK_H */
|
---|