byte_swap.h revision 1.1
11.1Sleo/*	$NetBSD: byte_swap.h,v 1.1 2001/03/30 20:00:05 leo Exp $	*/
21.1Sleo
31.1Sleo/*-
41.1Sleo * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Sleo * All rights reserved.
61.1Sleo *
71.1Sleo * This code is derived from software contributed to The NetBSD Foundation
81.1Sleo * by Leo Weppelman.
91.1Sleo *
101.1Sleo * Redistribution and use in source and binary forms, with or without
111.1Sleo * modification, are permitted provided that the following conditions
121.1Sleo * are met:
131.1Sleo * 1. Redistributions of source code must retain the above copyright
141.1Sleo *    notice, this list of conditions and the following disclaimer.
151.1Sleo * 2. Redistributions in binary form must reproduce the above copyright
161.1Sleo *    notice, this list of conditions and the following disclaimer in the
171.1Sleo *    documentation and/or other materials provided with the distribution.
181.1Sleo * 3. All advertising materials mentioning features or use of this software
191.1Sleo *    must display the following acknowledgement:
201.1Sleo *        This product includes software developed by the NetBSD
211.1Sleo *        Foundation, Inc. and its contributors.
221.1Sleo * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sleo *    contributors may be used to endorse or promote products derived
241.1Sleo *    from this software without specific prior written permission.
251.1Sleo *
261.1Sleo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sleo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sleo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sleo * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sleo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sleo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sleo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sleo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sleo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sleo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sleo * POSSIBILITY OF SUCH DAMAGE.
371.1Sleo */
381.1Sleo
391.1Sleo#ifndef	M68K_BYTE_SWAP_H_
401.1Sleo#define	M68K_BYTE_SWAP_H_
411.1Sleo
421.1Sleo#if defined(_KERNEL)
431.1Sleo
441.1Sleo#define __byte_swap_word(var)				\
451.1Sleo        ({ u_int16_t    __var = (var);  		\
461.1Sleo        	__asm__ __volatile ("rorw #8, %0"	\
471.1Sleo					: "=r" (__var)	\
481.1Sleo					: "0" (__var)); \
491.1Sleo            __var; })
501.1Sleo
511.1Sleo#define __byte_swap_long(var)    \
521.1Sleo        ({ u_int32_t    __var = (var);					\
531.1Sleo        	__asm__ __volatile ("rorw #8, %0; swap %0; rorw #8, %0"	\
541.1Sleo					: "=r" (__var) : "0" (__var));	\
551.1Sleo            __var; })
561.1Sleo
571.1Sleo#endif /* defined(_KERNEL) */
581.1Sleo
591.1Sleo#endif /* !M68K_BYTE_SWAP_H_ */
60