1 #ifndef _QEMU_YAGL_MARSHAL_H
2 #define _QEMU_YAGL_MARSHAL_H
4 #include "yagl_types.h"
5 #include "exec-memory.h"
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
16 * Each marshalled value is aligned
17 * at 8-byte boundary and there may be maximum
18 * 2 values returned (status and return value)
20 #define YAGL_MARSHAL_MAX_RESPONSE (8 * 2)
23 * Max marshal buffer size.
25 #define YAGL_MARSHAL_SIZE 0x8000
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. */
34 static __inline int yagl_marshal_skip(uint8_t** buff)
40 static __inline void yagl_marshal_put_uint8(uint8_t** buff, uint8_t value)
46 static __inline uint8_t yagl_marshal_get_uint8(uint8_t** buff)
53 static __inline void yagl_marshal_put_uint32(uint8_t** buff, uint32_t value)
55 *(uint32_t*)(*buff) = cpu_to_le32(value);
59 static __inline uint32_t yagl_marshal_get_uint32(uint8_t** buff)
61 uint32_t tmp = le32_to_cpu(*(uint32_t*)*buff);
66 static __inline void yagl_marshal_put_float(uint8_t** buff, float value)
68 *(float*)(*buff) = value;
72 static __inline float yagl_marshal_get_float(uint8_t** buff)
74 float tmp = *(float*)*buff;
79 static __inline target_ulong yagl_marshal_get_ptr(uint8_t** buff)
81 #if TARGET_LONG_SIZE == 4
82 target_ulong tmp = le32_to_cpu(*(uint32_t*)*buff);
84 target_ulong tmp = le64_to_cpu(*(uint64_t*)*buff);
90 static __inline void yagl_marshal_put_host_handle(uint8_t** buff, yagl_host_handle value)
92 *(uint32_t*)(*buff) = cpu_to_le32(value);
96 static __inline yagl_host_handle yagl_marshal_get_host_handle(uint8_t** buff)
98 yagl_host_handle tmp = le32_to_cpu(*(uint32_t*)*buff);
103 static __inline void yagl_marshal_put_call_result(uint8_t** buff, yagl_call_result value)
105 *(uint32_t*)(*buff) = cpu_to_le32(value);
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)