1/* $OpenBSD: endian.h,v 1.7 2014/10/22 23:56:47 dlg Exp $ */
2
3#ifndef _MACHINE_ENDIAN_H_
4#define _MACHINE_ENDIAN_H_
5
6#define _BYTE_ORDER _BIG_ENDIAN
7
8#ifdef _KERNEL
9
10#define __ASI_P_L 0x88 /* == ASI_PRIMARY_LITTLE */
11
12static inline __uint16_t
13__mswap16(volatile const __uint16_t *m)
14{
15 __uint16_t v;
16
17 __asm("lduha [%1] %2, %0 ! %3"
18 : "=r" (v)
19 : "r" (m), "n" (__ASI_P_L), "m" (*m));
20
21 return (v);
22}
23
24static inline __uint32_t
25__mswap32(volatile const __uint32_t *m)
26{
27 __uint32_t v;
28
29 __asm("lduwa [%1] %2, %0 ! %3"
30 : "=r" (v)
31 : "r" (m), "n" (__ASI_P_L), "m" (*m));
32
33 return (v);
34}
35
36static inline __uint64_t
37__mswap64(volatile const __uint64_t *m)
38{
39 __uint64_t v;
40
41 __asm("ldxa [%1] %2, %0 ! %3"
42 : "=r" (v)
43 : "r" (m), "n" (__ASI_P_L), "m" (*m));
44
45 return (v);
46}
47
48static inline void
49__swapm16(volatile __uint16_t *m, __uint16_t v)
50{
51 __asm("stha %1, [%2] %3 ! %0"
52 : "=m" (*m)
53 : "r" (v), "r" (m), "n" (__ASI_P_L));
54}
55
56static inline void
57__swapm32(volatile __uint32_t *m, __uint32_t v)
58{
59 __asm("stwa %1, [%2] %3 ! %0"
60 : "=m" (*m)
61 : "r" (v), "r" (m), "n" (__ASI_P_L));
62}
63
64static inline void
65__swapm64(volatile __uint64_t *m, __uint64_t v)
66{
67 __asm("stxa %1, [%2] %3 ! %0"
68 : "=m" (*m)
69 : "r" (v), "r" (m), "n" (__ASI_P_L));
70}
71
72#undef __ASI_P_L
73
74#define __HAVE_MD_SWAPIO
75
76#endif /* _KERNEL */
77
78#define __STRICT_ALIGNMENT
79
80#ifndef __FROM_SYS__ENDIAN
81#include <sys/endian.h>
82#endif
83
84#endif /* _MACHINE_ENDIAN_H_ */