Tizen 2.1 base
[sdk/emulator/qemu.git] / hw / yagl_marshal.h
1 #ifndef _QEMU_YAGL_MARSHAL_H
2 #define _QEMU_YAGL_MARSHAL_H
3
4 #include "yagl_types.h"
5 #include "exec-memory.h"
6
7 /*
8  * All marshalling/unmarshalling must be done with 8-byte alignment,
9  * since this is the maximum alignment possible. This way we can
10  * just do assignments without "memcpy" calls and can be sure that
11  * the code won't fail on architectures that don't support unaligned
12  * memory access.
13  */
14
15 /*
16  * Each marshalled value is aligned
17  * at 8-byte boundary and there may be maximum
18  * 2 values returned (status and return value)
19  */
20 #define YAGL_MARSHAL_MAX_RESPONSE (8 * 2)
21
22 /*
23  * Max marshal buffer size.
24  */
25 #define YAGL_MARSHAL_SIZE 0x8000
26
27 typedef enum
28 {
29     yagl_call_result_fail = 0,  /* Call failed, fatal error. */
30     yagl_call_result_retry = 1, /* Page fault on host, retry is required. */
31     yagl_call_result_ok = 2     /* Call is ok. */
32 } yagl_call_result;
33
34 static __inline int yagl_marshal_skip(uint8_t** buff)
35 {
36     *buff += 8;
37     return 0;
38 }
39
40 static __inline void yagl_marshal_put_uint8(uint8_t** buff, uint8_t value)
41 {
42     **buff = value;
43     *buff += 8;
44 }
45
46 static __inline uint8_t yagl_marshal_get_uint8(uint8_t** buff)
47 {
48     uint8_t tmp = **buff;
49     *buff += 8;
50     return tmp;
51 }
52
53 static __inline void yagl_marshal_put_uint32(uint8_t** buff, uint32_t value)
54 {
55     *(uint32_t*)(*buff) = cpu_to_le32(value);
56     *buff += 8;
57 }
58
59 static __inline uint32_t yagl_marshal_get_uint32(uint8_t** buff)
60 {
61     uint32_t tmp = le32_to_cpu(*(uint32_t*)*buff);
62     *buff += 8;
63     return tmp;
64 }
65
66 static __inline void yagl_marshal_put_float(uint8_t** buff, float value)
67 {
68     *(float*)(*buff) = value;
69     *buff += 8;
70 }
71
72 static __inline float yagl_marshal_get_float(uint8_t** buff)
73 {
74     float tmp = *(float*)*buff;
75     *buff += 8;
76     return tmp;
77 }
78
79 static __inline target_ulong yagl_marshal_get_ptr(uint8_t** buff)
80 {
81 #if TARGET_LONG_SIZE == 4
82     target_ulong tmp = le32_to_cpu(*(uint32_t*)*buff);
83 #else
84     target_ulong tmp = le64_to_cpu(*(uint64_t*)*buff);
85 #endif
86     *buff += 8;
87     return tmp;
88 }
89
90 static __inline void yagl_marshal_put_host_handle(uint8_t** buff, yagl_host_handle value)
91 {
92     *(uint32_t*)(*buff) = cpu_to_le32(value);
93     *buff += 8;
94 }
95
96 static __inline yagl_host_handle yagl_marshal_get_host_handle(uint8_t** buff)
97 {
98     yagl_host_handle tmp = le32_to_cpu(*(uint32_t*)*buff);
99     *buff += 8;
100     return tmp;
101 }
102
103 static __inline void yagl_marshal_put_call_result(uint8_t** buff, yagl_call_result value)
104 {
105     *(uint32_t*)(*buff) = cpu_to_le32(value);
106     *buff += 8;
107 }
108
109 #define yagl_marshal_put_int8(buff, value) yagl_marshal_put_uint8(buff, (uint8_t)(value))
110 #define yagl_marshal_get_int8(buff) ((int8_t)yagl_marshal_get_uint8(buff))
111 #define yagl_marshal_put_int32(buff, value) yagl_marshal_put_uint32(buff, (uint32_t)(value))
112 #define yagl_marshal_get_int32(buff) ((int32_t)yagl_marshal_get_uint32(buff))
113 #define yagl_marshal_put_uint32_t(buff, value) yagl_marshal_put_uint32(buff, value)
114 #define yagl_marshal_get_uint32_t(buff) yagl_marshal_get_uint32(buff)
115 #define yagl_marshal_put_int(buff, value) yagl_marshal_put_int32(buff, (value))
116 #define yagl_marshal_get_int(buff) yagl_marshal_get_int32(buff)
117 #define yagl_marshal_get_pid(buff) yagl_marshal_get_uint32(buff)
118 #define yagl_marshal_get_tid(buff) yagl_marshal_get_uint32(buff)
119 #define yagl_marshal_get_api_id(buff) yagl_marshal_get_uint32(buff)
120 #define yagl_marshal_get_func_id(buff) yagl_marshal_get_uint32(buff)
121
122 #endif