1*5918a2e0Snonaka/* $NetBSD: byte_swap_2.S,v 1.6 2006/04/14 09:23:01 nonaka Exp $ */ 265363da2Sitojun 365363da2Sitojun/*- 465363da2Sitojun * Copyright (C) 1999 SHIMIZU Ryo. All rights reserved. 565363da2Sitojun * 665363da2Sitojun * Redistribution and use in source and binary forms, with or without 765363da2Sitojun * modification, are permitted provided that the following conditions 865363da2Sitojun * are met: 965363da2Sitojun * 1. Redistributions of source code must retain the above copyright 1065363da2Sitojun * notice, this list of conditions and the following disclaimer. 1165363da2Sitojun * 2. Redistributions in binary form must reproduce the above copyright 1265363da2Sitojun * notice, this list of conditions and the following disclaimer in the 1365363da2Sitojun * documentation and/or other materials provided with the distribution. 1465363da2Sitojun * 3. The name of the author may not be used to endorse or promote products 1565363da2Sitojun * derived from this software without specific prior written permission. 1665363da2Sitojun * 1765363da2Sitojun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1865363da2Sitojun * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1965363da2Sitojun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2065363da2Sitojun * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2165363da2Sitojun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2265363da2Sitojun * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2365363da2Sitojun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2465363da2Sitojun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2565363da2Sitojun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2665363da2Sitojun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2765363da2Sitojun */ 2865363da2Sitojun 2965363da2Sitojun#include <machine/asm.h> 30*5918a2e0Snonaka 31*5918a2e0Snonaka#undef _LOCORE 32*5918a2e0Snonaka#define _LOCORE /* XXX not really, just assembly-code source */ 33116abff9Smsaitoh#include <machine/endian.h> 3465363da2Sitojun 3565363da2SitojunENTRY(bswap16) 36116abff9Smsaitoh#if BYTE_ORDER == LITTLE_ENDIAN 3765363da2SitojunALTENTRY(ntohs) 3865363da2SitojunALTENTRY(htons) 39116abff9Smsaitoh#endif 40e7b43156Suwe extu.w r4, r4 4165363da2Sitojun rts 4265363da2Sitojun swap.b r4, r0 4319d60bc0Suwe 44116abff9Smsaitoh#if BYTE_ORDER == BIG_ENDIAN 4519d60bc0SuweENTRY(ntohs) 46116abff9SmsaitohALTENTRY(htons) 47116abff9Smsaitoh rts 48e7b43156Suwe extu.w r4, r0 4919d60bc0Suwe#endif 50