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