1*b6cbf720SGianluca Guida/* $NetBSD: byte_swap_2.S,v 1.3 2008/02/16 17:37:13 apb Exp $ */ 2*b6cbf720SGianluca Guida 3*b6cbf720SGianluca Guida/* 4*b6cbf720SGianluca Guida * Copyright (c) 1996 Carnegie-Mellon University. 5*b6cbf720SGianluca Guida * All rights reserved. 6*b6cbf720SGianluca Guida * 7*b6cbf720SGianluca Guida * Author: Chris G. Demetriou 8*b6cbf720SGianluca Guida * 9*b6cbf720SGianluca Guida * Permission to use, copy, modify and distribute this software and 10*b6cbf720SGianluca Guida * its documentation is hereby granted, provided that both the copyright 11*b6cbf720SGianluca Guida * notice and this permission notice appear in all copies of the 12*b6cbf720SGianluca Guida * software, derivative works or modified versions, and any portions 13*b6cbf720SGianluca Guida * thereof, and that both notices appear in supporting documentation. 14*b6cbf720SGianluca Guida * 15*b6cbf720SGianluca Guida * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16*b6cbf720SGianluca Guida * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17*b6cbf720SGianluca Guida * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18*b6cbf720SGianluca Guida * 19*b6cbf720SGianluca Guida * Carnegie Mellon requests users of this software to return to 20*b6cbf720SGianluca Guida * 21*b6cbf720SGianluca Guida * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22*b6cbf720SGianluca Guida * School of Computer Science 23*b6cbf720SGianluca Guida * Carnegie Mellon University 24*b6cbf720SGianluca Guida * Pittsburgh PA 15213-3890 25*b6cbf720SGianluca Guida * 26*b6cbf720SGianluca Guida * any improvements or extensions that they make and grant Carnegie the 27*b6cbf720SGianluca Guida * rights to redistribute these changes. 28*b6cbf720SGianluca Guida */ 29*b6cbf720SGianluca Guida 30*b6cbf720SGianluca Guida#include <machine/asm.h> 31*b6cbf720SGianluca Guida 32*b6cbf720SGianluca Guida/* 33*b6cbf720SGianluca Guida * Byte-swap a 2-byte quantity. (Convert 0x0123 to 0x2301.) 34*b6cbf720SGianluca Guida * 35*b6cbf720SGianluca Guida * Argument is an unsigned 2-byte integer (uint16_t). 36*b6cbf720SGianluca Guida */ 37*b6cbf720SGianluca Guida#if defined(_KERNEL) || defined(_STANDALONE) 38*b6cbf720SGianluca Guida#define BSWAP16 bswap16 39*b6cbf720SGianluca Guida#else /* defined(_KERNEL) || defined(_STANDALONE) */ 40*b6cbf720SGianluca Guida#define BSWAP16 __bswap16 41*b6cbf720SGianluca Guida#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 42*b6cbf720SGianluca GuidaLEAF(BSWAP16, 1) /* a0 contains 0x0123 */ 43*b6cbf720SGianluca GuidaXLEAF(htons, 1) 44*b6cbf720SGianluca GuidaXLEAF(ntohs, 1) 45*b6cbf720SGianluca Guida insbl a0, 1, t0 /* t0 = 0x23 */ 46*b6cbf720SGianluca Guida extbl a0, 1, t1 /* t1 = 0x 01 */ 47*b6cbf720SGianluca Guida or t0, t1, v0 /* v0 = 0x2301 */ 48*b6cbf720SGianluca Guida RET 49*b6cbf720SGianluca GuidaEND(BSWAP16) 50