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 12 static 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 24 static 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 36 static 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 48 static 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 56 static 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 64 static 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_ */ 85