Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 /*
0002  * byteorder.h
0003  *
0004  *        This file contains inline implementation of function to
0005  *          deal with endian conversion.
0006  *
0007  * It is a stripped down version of linux ppc file...
0008  *
0009  * Copyright (C) 1999  Eric Valette (valette@crf.canon.fr)
0010  *                     Canon Centre Recherche France.
0011  *
0012  *  The license and distribution terms for this file may be
0013  *  found in the file LICENSE in this distribution or at
0014  *  http://www.rtems.org/license/LICENSE.
0015  */
0016 
0017 #ifndef _LIBCPU_BYTEORDER_H
0018 #define _LIBCPU_BYTEORDER_H
0019 
0020 #ifdef __cplusplus
0021 extern "C" {
0022 #endif
0023 
0024 static inline unsigned ld_le16(volatile uint16_t *addr)
0025 {
0026     unsigned val;
0027 
0028     __asm__ volatile ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
0029     return val;
0030 }
0031 
0032 static inline void st_le16(volatile uint16_t *addr, unsigned val)
0033 {
0034     __asm__ volatile ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
0035 }
0036 
0037 static inline unsigned ld_le32(volatile uint32_t *addr)
0038 {
0039     unsigned val;
0040 
0041     __asm__ volatile ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
0042     return val;
0043 }
0044 
0045 static inline void st_le32(volatile uint32_t *addr, unsigned val)
0046 {
0047     __asm__ volatile ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
0048 }
0049 
0050 #ifdef __cplusplus
0051 }
0052 #endif
0053 
0054 #endif /* _LIBCPU_BYTEORDER_H */