1*0a6a1f1dSLionel Sambuc/* $NetBSD: bswap32.S,v 1.6 2014/03/18 18:20:35 riastradh Exp $ */ 2b6cbf720SGianluca Guida 3b6cbf720SGianluca Guida/* 4b6cbf720SGianluca Guida * Copyright (C) 1996 Scott Reynolds. All rights reserved. 5b6cbf720SGianluca Guida * 6b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without 7b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions 8b6cbf720SGianluca Guida * are met: 9b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright 10b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer. 11b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright 12b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer in the 13b6cbf720SGianluca Guida * documentation and/or other materials provided with the distribution. 14b6cbf720SGianluca Guida * 3. The name of the author may not be used to endorse or promote products 15b6cbf720SGianluca Guida * derived from this software without specific prior written permission 16b6cbf720SGianluca Guida * 17b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18b6cbf720SGianluca Guida * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19b6cbf720SGianluca Guida * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20b6cbf720SGianluca Guida * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21b6cbf720SGianluca Guida * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22b6cbf720SGianluca Guida * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23b6cbf720SGianluca Guida * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24b6cbf720SGianluca Guida * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25b6cbf720SGianluca Guida * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26b6cbf720SGianluca Guida * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27b6cbf720SGianluca Guida */ 28b6cbf720SGianluca Guida 29b6cbf720SGianluca Guida#include <machine/asm.h> 30b6cbf720SGianluca Guida 31b6cbf720SGianluca Guida#if defined(_KERNEL) || defined(_STANDALONE) 3284d9c625SLionel Sambuc#define BSWAP32 _C_LABEL(bswap32) 33b6cbf720SGianluca Guida#else /* defined(_KERNEL) || defined(_STANDALONE) */ 3484d9c625SLionel Sambuc#define BSWAP32 _C_LABEL(__bswap32) 35b6cbf720SGianluca Guida#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 3684d9c625SLionel Sambuc 3784d9c625SLionel Sambuc_ENTRY(BSWAP32) 3884d9c625SLionel Sambuc movl 4(%sp),%d0 3984d9c625SLionel Sambuc#ifdef __mcfisac__ 4084d9c625SLionel Sambuc byterev %d0 4184d9c625SLionel Sambuc#elif defined(__mcoldfire__) 4284d9c625SLionel Sambuc movl %d0,%d1 4384d9c625SLionel Sambuc lsrl #8,%d0 | ABCD -> 0ABC 4484d9c625SLionel Sambuc andl #0x00ff00ff,%d0 | 0ABC -> 0A0C 4584d9c625SLionel Sambuc andl #0x00ff00ff,%d1 | ABCD -> 0B0D 4684d9c625SLionel Sambuc lsll #8,%d1 | 0B0D -> B0D0 4784d9c625SLionel Sambuc orl %d1,%d0 | 0A0C | B0D0 -> BADC 4884d9c625SLionel Sambuc swap %d0 | BADC -> DCBA 4984d9c625SLionel Sambuc#else 50b6cbf720SGianluca Guida rolw #8,%d0 51b6cbf720SGianluca Guida swap %d0 52b6cbf720SGianluca Guida rolw #8,%d0 5384d9c625SLionel Sambuc#endif 54b6cbf720SGianluca Guida rts 5584d9c625SLionel SambucEND(BSWAP32) 56