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

4.104.114.84.95
Last change on this file since aaed235 was 21e1c44, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:53:10

2003-09-04 Joel Sherrill <joel@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/clock/c_clock.h, mpc6xx/exceptions/raw_exception.c, mpc6xx/exceptions/raw_exception.h, mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h, mpc6xx/mmu/mmuAsm.S, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/brg.c, mpc8260/exceptions/raw_exception.c, mpc8260/exceptions/raw_exception.h, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/exceptions/raw_exception.c, mpc8xx/exceptions/raw_exception.h, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c.polled, ppc403/timer/timer.c, rtems/powerpc/debugmod.h, shared/include/byteorder.h, shared/include/cpuIdent.c, shared/include/cpuIdent.h, shared/include/io.h, shared/include/mmu.h, shared/include/page.h, shared/include/pgtable.h, shared/include/spr.h: URL for license changed.
  • 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 _PPC_BYTEORDER_H
20#define _PPC_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 /* _PPC_BYTEORDER_H */
Note: See TracBrowser for help on using the repository browser.