1*84d9c625SLionel Sambuc/* $NetBSD: byte_swap_4.S,v 1.7 2013/08/19 03:44:47 matt Exp $ */ 2b6cbf720SGianluca Guida 3b6cbf720SGianluca Guida/*- 4b6cbf720SGianluca Guida * Copyright (c) 1997 The NetBSD Foundation, Inc. 5b6cbf720SGianluca Guida * All rights reserved. 6b6cbf720SGianluca Guida * 7b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation 8b6cbf720SGianluca Guida * by Neil A. Carson 9b6cbf720SGianluca Guida * 10b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without 11b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions 12b6cbf720SGianluca Guida * are met: 13b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright 14b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer. 15b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright 16b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer in the 17b6cbf720SGianluca Guida * documentation and/or other materials provided with the distribution. 18b6cbf720SGianluca Guida * 19b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE. 30b6cbf720SGianluca Guida */ 31b6cbf720SGianluca Guida 32b6cbf720SGianluca Guida#include <machine/asm.h> 33b6cbf720SGianluca Guida 34b6cbf720SGianluca Guida#if defined(_KERNEL) || defined(_STANDALONE) 35*84d9c625SLionel Sambuc#define FUNC _C_LABEL(bswap32) 36b6cbf720SGianluca Guida#else 37*84d9c625SLionel Sambuc#define FUNC _C_LABEL(__bswap32) 38b6cbf720SGianluca Guida#endif 39*84d9c625SLionel SambucENTRY(FUNC) 40*84d9c625SLionel Sambuc#ifdef _ARM_ARCH_6 41*84d9c625SLionel Sambuc rev r0, r0 42*84d9c625SLionel Sambuc#elif !defined(__thumb__) 43*84d9c625SLionel Sambuc eor r1, r0, r0, ror #16 /* 4.3.2.1 -> 42.31.42.31 */ 44*84d9c625SLionel Sambuc bic r1, r1, #0x00FF0000 /* 42.31.42.31 -> 42.0.42.31 */ 45*84d9c625SLionel Sambuc mov r0, r0, ror #8 /* 4.3.2.1 -> 1.4.3.2 */ 46*84d9c625SLionel Sambuc eor r0, r0, r1, lsr #8 /* 1.4.3.2 ^ 0.42.0.42 -> 1.2.3.4 */ 47*84d9c625SLionel Sambuc#else 48*84d9c625SLionel Sambuc movs r3, #16 49*84d9c625SLionel Sambuc lsls r1, r0, #8 /* 4.3.2.1 -> 3.2.1.0 /* 50*84d9c625SLionel Sambuc lsrs r0, r0, #8 /* 4.3.2.1 -> 0.4.3.2 */ 51*84d9c625SLionel Sambuc rors r1, r3 /* 3.2.1.0 -> 1.0.3.2 */ 52*84d9c625SLionel Sambuc rors r0, r3 /* 0.4.3.2 -> 3.2.0.4 */ 53*84d9c625SLionel Sambuc lsrs r1, r1, #8 /* 1.0.3.2 -> 0.1.0.3 */ 54*84d9c625SLionel Sambuc lsls r1, r1, #8 /* 0.1.0.3 -> 1.0.3.0 */ 55*84d9c625SLionel Sambuc lsls r0, r0, #8 /* 3.2.0.4 -> 2.0.4.0 */ 56*84d9c625SLionel Sambuc lsrs r0, r0, #8 /* 2.0.4.0 -> 0.2.0.4 */ 57*84d9c625SLionel Sambuc orrs r0, r0, r1 /* 1.0.3.0 | 0.2.0.4 -> 1.2.3.4 */ 58b6cbf720SGianluca Guida#endif 59b6cbf720SGianluca Guida RET 60*84d9c625SLionel SambucEND(FUNC) 61*84d9c625SLionel Sambuc 62*84d9c625SLionel Sambuc#if BYTE_ORDER == LITTLE_ENDIAN 63*84d9c625SLionel SambucSTRONG_ALIAS(_C_LABEL(ntohl), FUNC) 64*84d9c625SLionel SambucSTRONG_ALIAS(_C_LABEL(htonl), FUNC) 65*84d9c625SLionel Sambuc#endif 66