1*84d9c625SLionel Sambuc/* $NetBSD: byte_swap_2.S,v 1.6 2013/08/19 03:44:18 matt Exp $ */ 2b6cbf720SGianluca Guida 3b6cbf720SGianluca Guida/*- 4b6cbf720SGianluca Guida * Copyright (c) 1999 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 Charles M. Hannum. 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(bswap16) 36b6cbf720SGianluca Guida#else 37*84d9c625SLionel Sambuc#define FUNC _C_LABEL(__bswap16) 38b6cbf720SGianluca Guida#endif 39*84d9c625SLionel Sambuc 40*84d9c625SLionel SambucENTRY(FUNC) 41*84d9c625SLionel Sambuc#ifdef _ARM_ARCH_6 42*84d9c625SLionel Sambuc rev16 r0, r0 43*84d9c625SLionel Sambuc#elif !defined(__thumb__) 44b6cbf720SGianluca Guida and r1, r0, #0xff 45b6cbf720SGianluca Guida mov r0, r0, lsr #8 46b6cbf720SGianluca Guida orr r0, r0, r1, lsl #8 47*84d9c625SLionel Sambuc#else 48*84d9c625SLionel Sambuc movs r2, #0xff 49*84d9c625SLionel Sambuc movs r1, r0 50*84d9c625SLionel Sambuc ands r1, r1, r2 51*84d9c625SLionel Sambuc lsls r1, r1, #8 52*84d9c625SLionel Sambuc lsrs r0, r0, #8 53*84d9c625SLionel Sambuc ands r0, r0, r2 54*84d9c625SLionel Sambuc orrs r0, r0, r1 55*84d9c625SLionel Sambuc#endif 56b6cbf720SGianluca Guida RET 57*84d9c625SLionel SambucEND(FUNC) 58*84d9c625SLionel Sambuc#if BYTE_ORDER == LITTLE_ENDIAN 59*84d9c625SLionel SambucSTRONG_ALIAS(_C_LABEL(ntohs), FUNC) 60*84d9c625SLionel SambucSTRONG_ALIAS(_C_LABEL(htons), FUNC) 61*84d9c625SLionel Sambuc#endif 62