summaryrefslogtreecommitdiff
path: root/firmware/export
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/export')
-rw-r--r--firmware/export/system.h120
1 files changed, 1 insertions, 119 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h
index 5064fcd91d..4442eb96d7 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -133,24 +133,6 @@ int get_cpu_boost_counter(void);
133#define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x))) 133#define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x)))
134#define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x))) 134#define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x)))
135 135
136/* newer? SDL includes endian.h, So we ignore it */
137#if (CONFIG_PLATFORM & PLATFORM_HOSTED) || defined(__PCTOOL__)
138#undef letoh16
139#undef letoh32
140#undef htole16
141#undef htole32
142#undef betoh16
143#undef betoh32
144#undef htobe16
145#undef htobe32
146#endif
147
148/* Android NDK contains swap16 and swap32, ignore them */
149#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
150#undef swap16
151#undef swap32
152#endif
153
154/* Get the byte offset of a type's member */ 136/* Get the byte offset of a type's member */
155#ifndef offsetof 137#ifndef offsetof
156#define offsetof(type, member) __builtin_offsetof(type, member) 138#define offsetof(type, member) __builtin_offsetof(type, member)
@@ -206,111 +188,11 @@ enum {
206#include "system-target.h" 188#include "system-target.h"
207#elif defined(HAVE_SDL) /* SDL build */ 189#elif defined(HAVE_SDL) /* SDL build */
208#include "system-sdl.h" 190#include "system-sdl.h"
209#define NEED_GENERIC_BYTESWAPS
210#elif defined(__PCTOOL__) 191#elif defined(__PCTOOL__)
211#include "system-sdl.h" 192#include "system-sdl.h"
212#define NEED_GENERIC_BYTESWAPS
213#endif 193#endif
214#include "bitswap.h" 194#include "bitswap.h"
215 195#include "rbendian.h"
216#ifdef NEED_GENERIC_BYTESWAPS
217static inline uint16_t swap16_hw(uint16_t value)
218 /*
219 result[15..8] = value[ 7..0];
220 result[ 7..0] = value[15..8];
221 */
222{
223 return (value >> 8) | (value << 8);
224}
225
226static inline uint32_t swap32_hw(uint32_t value)
227 /*
228 result[31..24] = value[ 7.. 0];
229 result[23..16] = value[15.. 8];
230 result[15.. 8] = value[23..16];
231 result[ 7.. 0] = value[31..24];
232 */
233{
234 uint32_t hi = swap16_hw(value >> 16);
235 uint32_t lo = swap16_hw(value & 0xffff);
236 return (lo << 16) | hi;
237}
238
239static inline uint32_t swap_odd_even32_hw(uint32_t value)
240{
241 /*
242 result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
243 result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
244 */
245 uint32_t t = value & 0xff00ff00;
246 return (t >> 8) | ((t ^ value) << 8);
247}
248
249static inline uint32_t swaw32_hw(uint32_t value)
250{
251 /*
252 result[31..16] = value[15.. 0];
253 result[15.. 0] = value[31..16];
254 */
255 return (value >> 16) | (value << 16);
256}
257
258#endif /* NEED_GENERIC_BYTESWAPS */
259
260/* static endianness conversion */
261#define SWAP16_CONST(x) \
262 ((typeof(x))( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) ))
263
264#define SWAP32_CONST(x) \
265 ((typeof(x))( ((uint32_t)(x) >> 24) | \
266 (((uint32_t)(x) & 0xff0000) >> 8) | \
267 (((uint32_t)(x) & 0xff00) << 8) | \
268 ((uint32_t)(x) << 24) ))
269
270#define SWAP_ODD_EVEN32_CONST(x) \
271 ((typeof(x))( ((uint32_t)SWAP16_CONST((uint32_t)(x) >> 16) << 16) | \
272 SWAP16_CONST((uint32_t)(x))) )
273
274#define SWAW32_CONST(x) \
275 ((typeof(x))( ((uint32_t)(x) << 16) | ((uint32_t)(x) >> 16) ))
276
277/* Select best method based upon whether x is a constant expression */
278#define swap16(x) \
279 ( __builtin_constant_p(x) ? SWAP16_CONST(x) : (typeof(x))swap16_hw(x) )
280
281#define swap32(x) \
282 ( __builtin_constant_p(x) ? SWAP32_CONST(x) : (typeof(x))swap32_hw(x) )
283
284#define swap_odd_even32(x) \
285 ( __builtin_constant_p(x) ? SWAP_ODD_EVEN32_CONST(x) : (typeof(x))swap_odd_even32_hw(x) )
286
287#define swaw32(x) \
288 ( __builtin_constant_p(x) ? SWAW32_CONST(x) : (typeof(x))swaw32_hw(x) )
289
290
291#ifdef ROCKBOX_LITTLE_ENDIAN
292#define letoh16(x) (x)
293#define letoh32(x) (x)
294#define htole16(x) (x)
295#define htole32(x) (x)
296#define betoh16(x) swap16(x)
297#define betoh32(x) swap32(x)
298#define htobe16(x) swap16(x)
299#define htobe32(x) swap32(x)
300#define swap_odd_even_be32(x) (x)
301#define swap_odd_even_le32(x) swap_odd_even32(x)
302#else
303#define letoh16(x) swap16(x)
304#define letoh32(x) swap32(x)
305#define htole16(x) swap16(x)
306#define htole32(x) swap32(x)
307#define betoh16(x) (x)
308#define betoh32(x) (x)
309#define htobe16(x) (x)
310#define htobe32(x) (x)
311#define swap_odd_even_be32(x) swap_odd_even32(x)
312#define swap_odd_even_le32(x) (x)
313#endif
314 196
315#ifndef BIT_N 197#ifndef BIT_N
316#define BIT_N(n) (1U << (n)) 198#define BIT_N(n) (1U << (n))