1*a546978dSmatt/* $NetBSD: byte_swap_2.S,v 1.6 2013/08/19 03:44:18 matt Exp $ */ 237c9f0a6Schristos 337c9f0a6Schristos/*- 437c9f0a6Schristos * Copyright (c) 1999 The NetBSD Foundation, Inc. 537c9f0a6Schristos * All rights reserved. 637c9f0a6Schristos * 737c9f0a6Schristos * This code is derived from software contributed to The NetBSD Foundation 837c9f0a6Schristos * by Charles M. Hannum. 937c9f0a6Schristos * 1037c9f0a6Schristos * Redistribution and use in source and binary forms, with or without 1137c9f0a6Schristos * modification, are permitted provided that the following conditions 1237c9f0a6Schristos * are met: 1337c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright 1437c9f0a6Schristos * notice, this list of conditions and the following disclaimer. 1537c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright 1637c9f0a6Schristos * notice, this list of conditions and the following disclaimer in the 1737c9f0a6Schristos * documentation and/or other materials provided with the distribution. 1837c9f0a6Schristos * 1937c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2037c9f0a6Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2137c9f0a6Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2237c9f0a6Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2337c9f0a6Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2437c9f0a6Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2537c9f0a6Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2637c9f0a6Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2737c9f0a6Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2837c9f0a6Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2937c9f0a6Schristos * POSSIBILITY OF SUCH DAMAGE. 3037c9f0a6Schristos */ 3137c9f0a6Schristos 3237c9f0a6Schristos#include <machine/asm.h> 3337c9f0a6Schristos 34c61d2c64Suwe#if defined(_KERNEL) || defined(_STANDALONE) 35*a546978dSmatt#define FUNC _C_LABEL(bswap16) 36c61d2c64Suwe#else 37*a546978dSmatt#define FUNC _C_LABEL(__bswap16) 38c61d2c64Suwe#endif 39*a546978dSmatt 40*a546978dSmattENTRY(FUNC) 41a96852fcSmatt#ifdef _ARM_ARCH_6 42a96852fcSmatt rev16 r0, r0 43*a546978dSmatt#elif !defined(__thumb__) 4437c9f0a6Schristos and r1, r0, #0xff 4537c9f0a6Schristos mov r0, r0, lsr #8 4637c9f0a6Schristos orr r0, r0, r1, lsl #8 47*a546978dSmatt#else 48*a546978dSmatt movs r2, #0xff 49*a546978dSmatt movs r1, r0 50*a546978dSmatt ands r1, r1, r2 51*a546978dSmatt lsls r1, r1, #8 52*a546978dSmatt lsrs r0, r0, #8 53*a546978dSmatt ands r0, r0, r2 54*a546978dSmatt orrs r0, r0, r1 55a96852fcSmatt#endif 5637c9f0a6Schristos RET 57*a546978dSmattEND(FUNC) 58*a546978dSmatt#if BYTE_ORDER == LITTLE_ENDIAN 59*a546978dSmattSTRONG_ALIAS(_C_LABEL(ntohs), FUNC) 60*a546978dSmattSTRONG_ALIAS(_C_LABEL(htons), FUNC) 61*a546978dSmatt#endif 62