1*267197ecSapb/* $NetBSD: byte_swap_2.S,v 1.3 2008/02/16 17:37:13 apb Exp $ */ 237c9f0a6Schristos 337c9f0a6Schristos/* 437c9f0a6Schristos * Copyright (c) 1996 Carnegie-Mellon University. 537c9f0a6Schristos * All rights reserved. 637c9f0a6Schristos * 737c9f0a6Schristos * Author: Chris G. Demetriou 837c9f0a6Schristos * 937c9f0a6Schristos * Permission to use, copy, modify and distribute this software and 1037c9f0a6Schristos * its documentation is hereby granted, provided that both the copyright 1137c9f0a6Schristos * notice and this permission notice appear in all copies of the 1237c9f0a6Schristos * software, derivative works or modified versions, and any portions 1337c9f0a6Schristos * thereof, and that both notices appear in supporting documentation. 1437c9f0a6Schristos * 1537c9f0a6Schristos * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 1637c9f0a6Schristos * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 1737c9f0a6Schristos * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 1837c9f0a6Schristos * 1937c9f0a6Schristos * Carnegie Mellon requests users of this software to return to 2037c9f0a6Schristos * 2137c9f0a6Schristos * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 2237c9f0a6Schristos * School of Computer Science 2337c9f0a6Schristos * Carnegie Mellon University 2437c9f0a6Schristos * Pittsburgh PA 15213-3890 2537c9f0a6Schristos * 2637c9f0a6Schristos * any improvements or extensions that they make and grant Carnegie the 2737c9f0a6Schristos * rights to redistribute these changes. 2837c9f0a6Schristos */ 2937c9f0a6Schristos 3037c9f0a6Schristos#include <machine/asm.h> 3137c9f0a6Schristos 3237c9f0a6Schristos/* 3337c9f0a6Schristos * Byte-swap a 2-byte quantity. (Convert 0x0123 to 0x2301.) 3437c9f0a6Schristos * 35*267197ecSapb * Argument is an unsigned 2-byte integer (uint16_t). 3637c9f0a6Schristos */ 37987ddf0aSyamt#if defined(_KERNEL) || defined(_STANDALONE) 38987ddf0aSyamt#define BSWAP16 bswap16 39987ddf0aSyamt#else /* defined(_KERNEL) || defined(_STANDALONE) */ 40987ddf0aSyamt#define BSWAP16 __bswap16 41987ddf0aSyamt#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 42987ddf0aSyamtLEAF(BSWAP16, 1) /* a0 contains 0x0123 */ 4337c9f0a6SchristosXLEAF(htons, 1) 4437c9f0a6SchristosXLEAF(ntohs, 1) 4537c9f0a6Schristos insbl a0, 1, t0 /* t0 = 0x23 */ 4637c9f0a6Schristos extbl a0, 1, t1 /* t1 = 0x 01 */ 4737c9f0a6Schristos or t0, t1, v0 /* v0 = 0x2301 */ 4837c9f0a6Schristos RET 49987ddf0aSyamtEND(BSWAP16) 50