source: rtems/c/src/lib/libcpu/powerpc/shared/include/byteorder.h @ d3d9ef37

4.104.114.84.95
Last change on this file since d3d9ef37 was a859df85, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/13/05 at 05:00:15

New header guards.

  • Property mode set to 100644
File size: 2.5 KB
Line 
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
24extern __inline__ unsigned ld_le16(volatile unsigned short *addr)
25{
26        unsigned val;
27
28        __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
29        return val;
30}
31
32extern __inline__ void st_le16(volatile unsigned short *addr, unsigned val)
33{
34        __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
35}
36
37extern __inline__ unsigned ld_le32(volatile unsigned *addr)
38{
39        unsigned val;
40
41        __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
42        return val;
43}
44
45extern __inline__ void st_le32(volatile unsigned *addr, unsigned val)
46{
47        __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
48}
49
50/* alas, egcs sounds like it has a bug in this code that doesn't use the
51   inline asm correctly, and can cause file corruption. Until I hear that
52   it's fixed, I can live without the extra speed. I hope. */
53#if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
54#if 0
55#  define __arch_swab16(x) ld_le16(&x)
56#  define __arch_swab32(x) ld_le32(&x)
57#else
58static __inline__ __const__ unsigned short ___arch__swab16(unsigned short value)
59{
60        unsigned int tmp;
61
62        __asm__("rlwimi %0,%0,8,0xff0000"
63            : "=r" (tmp)
64            : "0" (value));
65        return (tmp&0x00ffff00)>>8;
66}
67
68static __inline__ __const__ unsigned int ___arch__swab32(unsigned int value)
69{
70        unsigned int result;
71
72        __asm__("rotlwi %0,%1,24\n\t"
73            "rlwimi %0,%1,8,0xff\n\t"
74            "rlwimi %0,%1,8,0xff0000"
75            : "=&r" (result)
76            : "r" (value));
77        return result;
78}
79#define __arch__swab32(x) ___arch__swab32(x)
80#define __arch__swab16(x) ___arch__swab16(x)
81#endif /* 0 */
82
83#endif
84
85/* The same, but returns converted value from the location pointer by addr. */
86#define __arch__swab16p(addr) ld_le16(addr)
87#define __arch__swab32p(addr) ld_le32(addr)
88
89/* The same, but do the conversion in situ, ie. put the value back to addr. */
90#define __arch__swab16s(addr) st_le16(addr,*addr)
91#define __arch__swab32s(addr) st_le32(addr,*addr)
92
93#endif /* __GNUC__ */
94
95#endif /* _LIBCPU_BYTEORDER_H */
Note: See TracBrowser for help on using the repository browser.