RTEMS 7.0-rc1
Loading...
Searching...
No Matches
byteorder.h
1/* SPDX-License-Identifier: GPL-2.0+-with-RTEMS-exception */
2
3/*
4 * byteorder.h
5 *
6 * This file contains inline implementation of function to
7 * deal with endian conversion.
8 *
9 * It is a stripped down version of linux ppc file...
10 *
11 * Copyright (C) 1999 Eric Valette (eric.valette@free.fr)
12 * Canon Centre Recherche France.
13 *
14 * The license and distribution terms for this file may be
15 * found in the file LICENSE in this distribution or at
16 * http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _LIBCPU_BYTEORDER_H
20#define _LIBCPU_BYTEORDER_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26static inline unsigned ld_le16(volatile uint16_t *addr)
27{
28 unsigned val;
29
30 __asm__ volatile ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
31 return val;
32}
33
34static inline void st_le16(volatile uint16_t *addr, unsigned val)
35{
36 __asm__ volatile ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
37}
38
39static inline unsigned ld_le32(volatile uint32_t *addr)
40{
41 unsigned val;
42
43 __asm__ volatile ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
44 return val;
45}
46
47static inline void st_le32(volatile uint32_t *addr, unsigned val)
48{
49 __asm__ volatile ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
50}
51
52#ifdef __cplusplus
53}
54#endif
55
56#endif /* _LIBCPU_BYTEORDER_H */