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

4.104.114.84.95
Last change on this file since 98f3cfa was abd9401, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 14, 2000 at 3:38:08 PM

Functionality moved from directory above to accomodate building
shared source code.

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