diff options
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/alpha/include/endian.h | 161 | ||||
-rw-r--r-- | sys/arch/amiga/include/endian.h | 8 | ||||
-rw-r--r-- | sys/arch/arc/include/endian.h | 109 | ||||
-rw-r--r-- | sys/arch/arm32/include/endian.h | 86 | ||||
-rw-r--r-- | sys/arch/atari/include/endian.h | 8 | ||||
-rw-r--r-- | sys/arch/hp300/include/endian.h | 7 | ||||
-rw-r--r-- | sys/arch/i386/include/endian.h | 160 | ||||
-rw-r--r-- | sys/arch/kbus/include/endian.h | 93 | ||||
-rw-r--r-- | sys/arch/m68k/include/endian.h | 165 | ||||
-rw-r--r-- | sys/arch/mac68k/include/endian.h | 7 | ||||
-rw-r--r-- | sys/arch/mvme68k/include/endian.h | 7 | ||||
-rw-r--r-- | sys/arch/mvme88k/include/endian.h | 106 | ||||
-rw-r--r-- | sys/arch/pc532/include/endian.h | 136 | ||||
-rw-r--r-- | sys/arch/pmax/include/endian.h | 109 | ||||
-rw-r--r-- | sys/arch/powerpc/include/endian.h | 93 | ||||
-rw-r--r-- | sys/arch/sparc/include/endian.h | 100 | ||||
-rw-r--r-- | sys/arch/sun3/include/endian.h | 7 | ||||
-rw-r--r-- | sys/arch/vax/include/endian.h | 128 | ||||
-rw-r--r-- | sys/arch/wgrisc/include/endian.h | 109 |
19 files changed, 364 insertions, 1235 deletions
diff --git a/sys/arch/alpha/include/endian.h b/sys/arch/alpha/include/endian.h index da1d5250a08..2a7502d0a12 100644 --- a/sys/arch/alpha/include/endian.h +++ b/sys/arch/alpha/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.7 1997/08/08 18:27:17 niklas Exp $ */ -/* $NetBSD: endian.h,v 1.3 1996/10/13 19:57:59 cgd Exp $ */ +/* $OpenBSD: endian.h,v 1.8 1997/11/09 23:05:00 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,143 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 8.1 (Berkeley) 6/10/93 - */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -#if 0 -/* - * prototypes supplied for documentation purposes solely - */ -u_int32_t htobe32 __P((u_int32_t)); -u_int16_t htobe16 __P((u_int16_t)); -u_int32_t betoh32 __P((u_int32_t)); -u_int16_t betoh16 __P((u_int16_t)); - -u_int32_t htole32 __P((u_int32_t)); -u_int16_t htole16 __P((u_int16_t)); -u_int32_t letoh32 __P((u_int32_t)); -u_int16_t letoh16 __P((u_int16_t)); - -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -#endif -__END_DECLS - -#ifdef __GNUC__ - -/* XXX perhaps some __asm would be better here? */ -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __x = (x); \ - (((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | \ - (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24); }) - -#define __byte_swap_int16_variable(x) \ -({ register u_int16_t __x = (x); \ - (((__x) & 0xff00) >> 8) | (((__x) & 0x00ff) << 8); }) - -#ifdef __OPTIMIZE__ - -#define __byte_swap_int32_constant(x) \ - ((((x) & 0xff000000) >> 24) | \ - (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | \ - (((x) & 0x000000ff) << 24)) -#define __byte_swap_int16_constant(x) \ - ((((x) & 0xff00) >> 8) | \ - (((x) & 0x00ff) << 8)) -#define __byte_swap_int32(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int32_constant(x) : __byte_swap_int32_variable(x)) -#define __byte_swap_int16(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int16_constant(x) : __byte_swap_int16_variable(x)) - -#else /* __OPTIMIZE__ */ - -#define __byte_swap_int32(x) __byte_swap_int32_variable(x) -#define __byte_swap_int16(x) __byte_swap_int16_variable(x) - -#endif /* __OPTIMIZE__ */ -#endif /* __GNUC__ */ - -/* - * Macros for big/little endian to host and vice versa. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define betoh32(x) __byte_swap_int32(x) -#define betoh16(x) __byte_swap_int16(x) -#define htobe32(x) __byte_swap_int32(x) -#define htobe16(x) __byte_swap_int16(x) -#define letoh32(x) (x) -#define letoh16(x) (x) -#define htole32(x) (x) -#define htole16(x) (x) - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. - */ -#define ntohl(x) betoh32(x) -#define ntohs(x) betoh16(x) -#define htonl(x) htobe32(x) -#define htons(x) htobe16(x) +#ifndef _ALPHA_ENDIAN_H_ +#define _ALPHA_ENDIAN_H_ -#define NTOHL(x) (void)((x) = ntohl(x)) -#define NTOHS(x) (void)((x) = ntohs(x)) -#define HTONL(x) (void)((x) = htonl(x)) -#define HTONS(x) (void)((x) = htons(x)) +#define BYTE_ORDER 1234 +#include <sys/endian.h> -#endif /* !_POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ +#endif /* _ALPHA_ENDIAN_H_ */ diff --git a/sys/arch/amiga/include/endian.h b/sys/arch/amiga/include/endian.h index bfd856c0de2..0fd359c357b 100644 --- a/sys/arch/amiga/include/endian.h +++ b/sys/arch/amiga/include/endian.h @@ -1,9 +1,9 @@ -/* $OpenBSD: endian.h,v 1.2 1996/11/25 13:11:14 niklas Exp $ */ +/* $OpenBSD: endian.h,v 1.3 1997/11/09 23:05:01 niklas Exp $ */ /* $NetBSD: endian.h,v 1.7 1994/10/26 02:06:09 cgd Exp $ */ -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ +#ifndef _AMIGA_ENDIAN_H_ +#define _AMIGA_ENDIAN_H_ #include <m68k/endian.h> -#endif +#endif /* _AMIGA_ENDIAN_H */ diff --git a/sys/arch/arc/include/endian.h b/sys/arch/arc/include/endian.h index 2bae3bd2a1c..771c96526ff 100644 --- a/sys/arch/arc/include/endian.h +++ b/sys/arch/arc/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.5 1997/06/25 12:52:08 grr Exp $ */ -/* $NetBSD: endian.h,v 1.4 1994/10/26 21:09:38 cgd Exp $ */ +/* $OpenBSD: endian.h,v 1.6 1997/11/09 23:05:03 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,91 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 8.1 (Berkeley) 6/11/93 - */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* - * Define _NOQUAD if the compiler does NOT support 64-bit integers. - */ -/* #define _NOQUAD */ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER LITTLE_ENDIAN /* ``... Beautiful SPIIIIM!'' */ - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) -#define NTOHL(x) (void)(x) -#define NTOHS(x) (void)(x) -#define HTONL(x) (void)(x) -#define HTONS(x) (void)(x) +#ifndef _ARC_ENDIAN_H_ +#define _ARC_ENDIAN_H_ -#else +#define BYTE_ORDER 1234 +#include <sys/endian.h> -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) -#endif -#endif /* ! _POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ +#endif /* _ARC_ENDIAN_H_ */ diff --git a/sys/arch/arm32/include/endian.h b/sys/arch/arm32/include/endian.h index 3d47cfe3638..134ef9b04c6 100644 --- a/sys/arch/arm32/include/endian.h +++ b/sys/arch/arm32/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.3 1997/04/04 03:05:30 millert Exp $ */ -/* $NetBSD: endian.h,v 1.2 1996/03/14 23:11:10 mark Exp $ */ +/* $OpenBSD: endian.h,v 1.4 1997/11/09 23:05:04 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,68 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)endian.h 7.8 (Berkeley) 4/3/91 - */ - -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - */ -#define NTOHL(x) (x) = ntohl((u_int32_t)(x)) -#define NTOHS(x) (x) = ntohs((u_int16_t)(x)) -#define HTONL(x) (x) = htonl((u_int32_t)(x)) -#define HTONS(x) (x) = htons((u_int16_t)(x)) +#ifndef _ARM32_ENDIAN_H_ +#define _ARM32_ENDIAN_H_ -#endif /* _POSIX_SOURCE */ +#define BYTE_ORDER 1234 +#include <sys/endian.h> -#endif /* _MACHINE_ENDIAN_H_ */ +#endif /* _ARM32_ENDIAN_H_ */ diff --git a/sys/arch/atari/include/endian.h b/sys/arch/atari/include/endian.h index 8c0a134e452..3ec4f825ee7 100644 --- a/sys/arch/atari/include/endian.h +++ b/sys/arch/atari/include/endian.h @@ -1,9 +1,9 @@ -/* $OpenBSD: endian.h,v 1.2 1996/11/25 13:11:20 niklas Exp $ */ +/* $OpenBSD: endian.h,v 1.3 1997/11/09 23:05:05 niklas Exp $ */ /* $NetBSD: endian.h,v 1.1.1.1 1995/03/26 07:12:06 leo Exp $ */ -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ +#ifndef _ATARI_ENDIAN_H_ +#define _ATARI_ENDIAN_H_ #include <m68k/endian.h> -#endif +#endif /* _ATARI_ENDIAN_h_ */ diff --git a/sys/arch/hp300/include/endian.h b/sys/arch/hp300/include/endian.h index ffc96e65376..aadb88454d7 100644 --- a/sys/arch/hp300/include/endian.h +++ b/sys/arch/hp300/include/endian.h @@ -1,5 +1,10 @@ -/* $OpenBSD: endian.h,v 1.2 1996/11/25 13:11:22 niklas Exp $ */ +/* $OpenBSD: endian.h,v 1.3 1997/11/09 23:05:05 niklas Exp $ */ /* $NetBSD: endian.h,v 1.6 1994/10/26 07:26:22 cgd Exp $ */ +#ifndef _HP300_ENDIAN_H_ +#define _HP300_ENDIAN_H_ + /* Just use the common m68k definition */ #include <m68k/endian.h> + +#endif /* _HP300_ENDIAN_H_ */ diff --git a/sys/arch/i386/include/endian.h b/sys/arch/i386/include/endian.h index 37420cd889f..3c671f6cf96 100644 --- a/sys/arch/i386/include/endian.h +++ b/sys/arch/i386/include/endian.h @@ -1,10 +1,7 @@ -/* $OpenBSD: endian.h,v 1.6 1997/04/04 03:05:31 millert Exp $ */ -/* $NetBSD: endian.h,v 1.16 1995/06/01 17:19:18 mycroft Exp $ */ +/* $OpenBSD: endian.h,v 1.7 1997/11/09 23:05:06 niklas Exp $ */ -/* - * Copyright (c) 1995 Charles M. Hannum. All rights reserved. - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -16,126 +13,57 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _I386_ENDIAN_H_ -#define _I386_ENDIAN_H_ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - +#define _I386_ENDIAN_H_ #ifdef __GNUC__ #if defined(_KERNEL) && !defined(I386_CPU) -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __x = (x); \ - __asm ("bswap %1" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) +#define __swap32md(x) ({ \ + u_int32_t __x = (x); \ + \ + __asm ("bswap %1" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) #else -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __x = (x); \ - __asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) -#endif /* _KERNEL && ... */ - -#define __byte_swap_int16_variable(x) \ -({ register u_int16_t __x = (x); \ - __asm ("rorw $8, %w1" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) - -#ifdef __OPTIMIZE__ - -#define __byte_swap_int32_constant(x) \ - ((((x) & 0xff000000) >> 24) | \ - (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | \ - (((x) & 0x000000ff) << 24)) -#define __byte_swap_int16_constant(x) \ - ((((x) & 0xff00) >> 8) | \ - (((x) & 0x00ff) << 8)) -#define __byte_swap_int32(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int32_constant(x) : __byte_swap_int32_variable(x)) -#define __byte_swap_int16(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int16_constant(x) : __byte_swap_int16_variable(x)) - -#else /* __OPTIMIZE__ */ - -#define __byte_swap_int32(x) __byte_swap_int32_variable(x) -#define __byte_swap_int16(x) __byte_swap_int16_variable(x) - -#endif /* __OPTIMIZE__ */ - -#define ntohl(x) __byte_swap_int32(x) -#define ntohs(x) __byte_swap_int16(x) -#define htonl(x) __byte_swap_int32(x) -#define htons(x) __byte_swap_int16(x) +#define __swap32md(x) ({ \ + u_int32_t __x = (x); \ + \ + __asm ("rorw $8, %w1; rorl $16, %1; rorw $8, %w1" : \ + "=r" (__x) : "0" (__x)); \ + __x; \ +}) +#endif /* _KERNEL && !I386_CPU */ + +#define __swap16md(x) ({ \ + u_int16_t __x = (x); \ + \ + __asm ("rorw $8, %w1" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) + +/* Tell sys/endian.h we have MD variants of the swap macros. */ +#define MD_SWAP #endif /* __GNUC__ */ +#define BYTE_ORDER 1234 +#include <sys/endian.h> -/* - * Macros for network/external number representation conversion. - */ -#define NTOHL(x) (x) = ntohl((u_int32_t)(x)) -#define NTOHS(x) (x) = ntohs((u_int16_t)(x)) -#define HTONL(x) (x) = htonl((u_int32_t)(x)) -#define HTONS(x) (x) = htons((u_int16_t)(x)) - -#endif /* _POSIX_SOURCE */ - -#endif /* !_I386_ENDIAN_H_ */ +#endif /* _I386_ENDIAN_H_ */ diff --git a/sys/arch/kbus/include/endian.h b/sys/arch/kbus/include/endian.h index e353bbe855a..1eb417ab2f2 100644 --- a/sys/arch/kbus/include/endian.h +++ b/sys/arch/kbus/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.1 1997/10/14 07:25:30 gingold Exp $ */ -/* $NetBSD: endian.h,v 1.3 1996/02/13 17:04:58 christos Exp $ */ +/* $OpenBSD: endian.h,v 1.2 1997/11/09 23:05:07 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,75 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.7 (Berkeley) 4/3/91 - */ - -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ - -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER BIG_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) - -#define NTOHL(x) (void) (x) -#define NTOHS(x) (void) (x) -#define HTONL(x) (void) (x) -#define HTONS(x) (void) (x) -#else +#ifndef _KBUS_ENDIAN_H_ +#define _KBUS_ENDIAN_H_ -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) -#endif +#define BYTE_ORDER 4321 +#include <sys/endian.h> -#endif /* _MACHINE_ENDIAN_H_ */ +#endif /* _KBUS_ENDIAN_H_ */ diff --git a/sys/arch/m68k/include/endian.h b/sys/arch/m68k/include/endian.h index b9514134c68..c1963970b53 100644 --- a/sys/arch/m68k/include/endian.h +++ b/sys/arch/m68k/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.8 1997/06/25 12:52:09 grr Exp $ */ -/* $NetBSD: endian.h,v 1.10 1996/10/13 02:59:55 christos Exp $ */ +/* $OpenBSD: endian.h,v 1.9 1997/11/09 23:05:09 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,148 +13,45 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.7 (Berkeley) 4/3/91 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _M68K_ENDIAN_H_ #define _M68K_ENDIAN_H_ -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER BIG_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -#if 0 -/* - * prototypes supplied for documentation purposes solely - */ -u_int32_t htobe32 __P((u_int32_t)); -u_int16_t htobe16 __P((u_int16_t)); -u_int32_t betoh32 __P((u_int32_t)); -u_int16_t betoh16 __P((u_int16_t)); - -u_int32_t htole32 __P((u_int32_t)); -u_int16_t htole16 __P((u_int16_t)); -u_int32_t letoh32 __P((u_int32_t)); -u_int16_t letoh16 __P((u_int16_t)); - -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -#endif -__END_DECLS - #ifdef __GNUC__ -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __x = (x); \ - __asm ("rorw #8, %0; swap %0; rorw #8, %0" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) - -#define __byte_swap_int16_variable(x) \ -({ register u_int16_t __x = (x); \ - __asm ("rorw #8, %0" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) - -#ifdef __OPTIMIZE__ +#define __swap32md(x) ({ \ + register u_int32_t __x = (x); \ + __asm ("rorw #8, %0; swap %0; rorw #8, %0" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) -#define __byte_swap_int32_constant(x) \ - ((((x) & 0xff000000) >> 24) | \ - (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | \ - (((x) & 0x000000ff) << 24)) -#define __byte_swap_int16_constant(x) \ - ((((x) & 0xff00) >> 8) | \ - (((x) & 0x00ff) << 8)) -#define __byte_swap_int32(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int32_constant(x) : __byte_swap_int32_variable(x)) -#define __byte_swap_int16(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int16_constant(x) : __byte_swap_int16_variable(x)) +#define __swap16md(x) ({ \ + register u_int16_t __x = (x); \ + __asm ("rorw #8, %0" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) -#else /* __OPTIMIZE__ */ +/* Tell sys/endian.h we have MD variants of the swap macros. */ +#define MD_SWAP -#define __byte_swap_int32(x) __byte_swap_int32_variable(x) -#define __byte_swap_int16(x) __byte_swap_int16_variable(x) - -#endif /* __OPTIMIZE__ */ #endif /* __GNUC__ */ -/* - * Macros for big/little endian to host and vice versa. - */ -#define betoh32(x) (x) -#define betoh16(x) (x) -#define htobe32(x) (x) -#define htobe16(x) (x) - -#define letoh32(x) __byte_swap_int32(x) -#define letoh16(x) __byte_swap_int16(x) -#define htole32(x) __byte_swap_int32(x) -#define htole16(x) __byte_swap_int16(x) - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. - */ -#define ntohl(x) betoh32(x) -#define ntohs(x) betoh16(x) -#define htonl(x) htobe32(x) -#define htons(x) htobe16(x) - -#define NTOHL(x) (void)(x) -#define NTOHS(x) (void)(x) -#define HTONL(x) (void)(x) -#define HTONS(x) (void)(x) - -#endif /* _POSIX_SOURCE */ +#define BYTE_ORDER 4321 +#include <sys/endian.h> #endif /* _M68K_ENDIAN_H_ */ diff --git a/sys/arch/mac68k/include/endian.h b/sys/arch/mac68k/include/endian.h index 8a18b27e41c..1893ed3dbc7 100644 --- a/sys/arch/mac68k/include/endian.h +++ b/sys/arch/mac68k/include/endian.h @@ -1,4 +1,9 @@ -/* $OpenBSD: endian.h,v 1.2 1996/05/26 18:35:48 briggs Exp $ */ +/* $OpenBSD: endian.h,v 1.3 1997/11/09 23:05:09 niklas Exp $ */ /* $NetBSD: endian.h,v 1.5 1994/10/26 08:46:28 cgd Exp $ */ +#ifndef _MAC68K_ENDIAN_H_ +#define _MAC68K_ENDIAN_H_ + #include <m68k/endian.h> + +#endif /* _MAC68K_ENDIAN_H */ diff --git a/sys/arch/mvme68k/include/endian.h b/sys/arch/mvme68k/include/endian.h index 03eb53ac558..f30117c7c8a 100644 --- a/sys/arch/mvme68k/include/endian.h +++ b/sys/arch/mvme68k/include/endian.h @@ -1,4 +1,9 @@ -/* $OpenBSD: endian.h,v 1.3 1996/04/28 10:56:15 deraadt Exp $ */ +/* $OpenBSD: endian.h,v 1.4 1997/11/09 23:05:10 niklas Exp $ */ + +#ifndef _MVME68K_ENDIAN_H_ +#define _MVME68K_ENDIAN_H_ /* Just use the common m68k definition */ #include <m68k/endian.h> + +#endif /* _MVME68K_ENDIAN_H_ */ diff --git a/sys/arch/mvme88k/include/endian.h b/sys/arch/mvme88k/include/endian.h index 5fa99cefc7a..198cc050e2f 100644 --- a/sys/arch/mvme88k/include/endian.h +++ b/sys/arch/mvme88k/include/endian.h @@ -1,6 +1,7 @@ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. +/* $OpenBSD: endian.h,v 1.8 1997/11/09 23:05:11 niklas Exp $ */ + +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,89 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)endian.h 8.1 (Berkeley) 6/11/93 - * $Id: endian.h,v 1.7 1997/06/25 12:52:10 grr Exp $ - */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ - -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, 88000 ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER BIG_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) - -#define NTOHL(x) (void)(x) -#define NTOHS(x) (void)(x) -#define HTONL(x) (void)(x) -#define HTONS(x) (void)(x) -#else +#ifndef _MVME88K_ENDIAN_H_ +#define _MVME88K_ENDIAN_H_ -#define NTOHL(x) (x) = ntohl((u_long)x) -#define NTOHS(x) (x) = ntohs((u_short)x) -#define HTONL(x) (x) = htonl((u_long)x) -#define HTONS(x) (x) = htons((u_short)x) +#define BYTE_ORDER 4321 +#include <sys/endian.h> -#endif -#endif /* ! _POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ +#endif /* _MVME88K_ENDIAN_H_ */ diff --git a/sys/arch/pc532/include/endian.h b/sys/arch/pc532/include/endian.h index 388513c91f8..014e749daaf 100644 --- a/sys/arch/pc532/include/endian.h +++ b/sys/arch/pc532/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.3 1997/04/04 03:05:33 millert Exp $ */ -/* $NetBSD: endian.h,v 1.8 1995/06/18 07:13:46 phil Exp $ */ +/* $OpenBSD: endian.h,v 1.4 1997/11/09 23:05:12 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,117 +13,47 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _PC532_ENDIAN_H_ #define _PC532_ENDIAN_H_ -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, ns32000 */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - - #ifdef __GNUC__ -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __x = (x); \ - __asm ("rotw 8,%1; rotd 16,%1; rotw 8,%1" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) +#define __swap32md(x) ({ \ + register u_int32_t __x = (x); \ +\ + __asm ("rotw 8,%1; rotd 16,%1; rotw 8,%1" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) -#define __byte_swap_int16_variable(x) \ -({ register u_int16_t __x = (x); \ - __asm ("rotw 8,%1" \ - : "=r" (__x) \ - : "0" (__x)); \ - __x; }) +#define __swap16md(x) ({ \ + register u_int16_t __x = (x); \ +\ + __asm ("rotw 8,%1" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) - -#ifdef __OPTIMIZE__ - -#define __byte_swap_int32_constant(x) \ - ((((x) & 0xff000000) >> 24) | \ - (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | \ - (((x) & 0x000000ff) << 24)) -#define __byte_swap_int16__constant(x) \ - ((((x) & 0xff00) >> 8) | \ - (((x) & 0x00ff) << 8)) -#define __byte_swap_int32(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int32_constant(x) : __byte_swap_int32_variable(x)) -#define __byte_swap_int16(x) \ - (__builtin_constant_p((x)) ? \ - __byte_swap_int16_constant(x) : __byte_swap_int16_variable(x)) - -#else /* __OPTIMIZE__ */ - -#define __byte_swap_int32(x) __byte_swap_int32_variable(x) -#define __byte_swap_int16(x) __byte_swap_int16_variable(x) - -#endif /* __OPTIMIZE__ */ - -#define ntohl(x) __byte_swap_int32(x) -#define ntohs(x) __byte_swap_int16(x) -#define htonl(x) __byte_swap_int32(x) -#define htons(x) __byte_swap_int16(x) +/* Tell sys/endian.h we have MD variants of the swap macros. */ +#define MD_SWAP #endif /* __GNUC__ */ - -/* - * Macros for network/external number representation conversion. - */ -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) - -#endif /* _POSIX_SOURCE */ +#define BYTE_ORDER 1234 +#include <sys/endian.h> #endif /* _PC532_ENDIAN_H_ */ diff --git a/sys/arch/pmax/include/endian.h b/sys/arch/pmax/include/endian.h index 60cac2a0a72..dd5718af3eb 100644 --- a/sys/arch/pmax/include/endian.h +++ b/sys/arch/pmax/include/endian.h @@ -1,8 +1,7 @@ -/* $NetBSD: endian.h,v 1.8 1996/10/13 20:59:02 mhitch Exp $ */ +/* $OpenBSD: endian.h,v 1.11 1997/11/09 23:05:13 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -14,92 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 8.1 (Berkeley) 6/11/93 - */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* - * Define _NOQUAD if the compiler does NOT support 64-bit integers. - */ -/* #define _NOQUAD */ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> -#include <machine/types.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) -#define NTOHL(x) (void)(x) -#define NTOHS(x) (void)(x) -#define HTONL(x) (void)(x) -#define HTONS(x) (void)(x) +#ifndef _PMAX_ENDIAN_H_ +#define _PMAX_ENDIAN_H_ -#else +#define BYTE_ORDER 1234 +#include <sys/endian.h> -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) -#endif -#endif /* ! _POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ +#endif /* _PMAX_ENDIAN_H_ */ diff --git a/sys/arch/powerpc/include/endian.h b/sys/arch/powerpc/include/endian.h index 979a90f125d..12e3e5ca950 100644 --- a/sys/arch/powerpc/include/endian.h +++ b/sys/arch/powerpc/include/endian.h @@ -1,8 +1,8 @@ -/* $OpenBSD: endian.h,v 1.8 1997/10/13 10:53:43 pefo Exp $ */ +/* $OpenBSD: endian.h,v 1.9 1997/11/09 23:05:15 niklas Exp $ */ -/* - * Copyright (c) 1997 Per Fogelstrom - * +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -13,79 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed under OpenBSD by - * Per Fogelstrom, Opsycon AB, Sweden. + * This product includes software developed by Niklas Hallqvist. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ - -#ifndef _POSIX_SOURCE - -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -/* - * Byte order definition. Byte numbers given in increasing address order. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, NS32K */ -#define BIG_ENDIAN 4321 /* MSB first: M68K */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER BIG_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion where - * network/external is defined to be in BIG_ENDIAN byte order. - * - * *NOTE* That the macros are supposed to work on the arrgument (x) and - * thus should *NOT* be used in assignments such as 'foo=HTONS(bar)'. - */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) - -#define NTOHL(x) (void) (x) -#define NTOHS(x) (void) (x) -#define HTONL(x) (void) (x) -#define HTONS(x) (void) (x) -#else +#ifndef _POWERPC_ENDIAN_H_ +#define _POWERPC_ENDIAN_H_ -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) -#endif +#define BYTE_ORDER 4321 +#include <sys/endian.h> -#endif /* _POSIX_SOURCE */ -#endif /* _MACHINE_ENDIAN_H_ */ +#endif /* _POWERPC_ENDIAN_H_ */ diff --git a/sys/arch/sparc/include/endian.h b/sys/arch/sparc/include/endian.h index 302cc658d93..2a995812c47 100644 --- a/sys/arch/sparc/include/endian.h +++ b/sys/arch/sparc/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.7 1997/08/08 08:26:15 downsj Exp $ */ -/* $NetBSD: endian.h,v 1.6 1996/10/11 00:43:00 christos Exp $ */ +/* $OpenBSD: endian.h,v 1.8 1997/11/09 23:05:16 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,82 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.7 (Berkeley) 4/3/91 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _MACHINE_ENDIAN_H_ -#define _MACHINE_ENDIAN_H_ - -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 - -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER BIG_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. - */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) - -#define NTOHL(x) (void) (x) -#define NTOHS(x) (void) (x) -#define HTONL(x) (void) (x) -#define HTONS(x) (void) (x) - -#else +#ifndef _SPARC_ENDIAN_H_ +#define _SPARC_ENDIAN_H_ -#define NTOHL(x) (x) = ntohl((in_addr_t)x) -#define NTOHS(x) (x) = ntohs((in_port_t)x) -#define HTONL(x) (x) = htonl((in_addr_t)x) -#define HTONS(x) (x) = htons((in_port_t)x) -#endif +#define BYTE_ORDER 4321 +#include <sys/endian.h> -#endif /* _MACHINE_ENDIAN_H_ */ +#endif /* _SPARC_ENDIAN_H_ */ diff --git a/sys/arch/sun3/include/endian.h b/sys/arch/sun3/include/endian.h index 4725a83ab43..6fb98ea59ab 100644 --- a/sys/arch/sun3/include/endian.h +++ b/sys/arch/sun3/include/endian.h @@ -1,4 +1,9 @@ -/* $OpenBSD: endian.h,v 1.2 1996/11/25 13:11:37 niklas Exp $ */ +/* $OpenBSD: endian.h,v 1.3 1997/11/09 23:05:17 niklas Exp $ */ /* $NetBSD: endian.h,v 1.6 1994/11/21 21:33:37 gwr Exp $ */ +#ifndef _SUN3_ENDIAN_H_ +#define _SUN3_ENDIAN_H_ + #include <m68k/endian.h> + +#endif /* _SUN3_ENDIAN_H */ diff --git a/sys/arch/vax/include/endian.h b/sys/arch/vax/include/endian.h index 90707f9cec5..9be228a194e 100644 --- a/sys/arch/vax/include/endian.h +++ b/sys/arch/vax/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.6 1997/04/04 03:17:06 millert Exp $ */ -/* $NetBSD: endian.h,v 1.8 1996/10/13 03:28:00 christos Exp $ */ +/* $OpenBSD: endian.h,v 1.7 1997/11/09 23:05:18 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991 Regents of the University of California. - * All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,102 +13,50 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _VAX_ENDIAN_H_ #define _VAX_ENDIAN_H_ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE - -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ - -#define BYTE_ORDER LITTLE_ENDIAN - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - #ifdef __GNUC__ -#define __byte_swap_int32_variable(x) \ -({ register u_int32_t __y, __x = (x); \ - \ - __asm ("rotl $-8, %1, %0; \ - insv %0, $16, $8, %0; \ - rotl $8, %1, r1; \ - movb r1, %0" \ - : "&=r" (__y) \ - : "r" (__x) \ - : "r1", "cc" ); \ - __y; }) - -#define __byte_swap_int16_variable(x) \ -({ register u_int16_t __y, __x = (x); \ - \ - __asm ("rotl $8, %1, %0; \ - rotl $-8, %1, r1; \ - movb r1, %0; \ - movzwl %0, %0" \ - : "&=r" (__y) \ - : "r" (__x) \ - : "r1", "cc" ); \ - __y; }) - - -#define __byte_swap_int32(x) __byte_swap_int32_variable(x) -#define __byte_swap_int16(x) __byte_swap_int16_variable(x) - -#define ntohl(x) __byte_swap_int32(x) -#define ntohs(x) __byte_swap_int16(x) -#define htonl(x) __byte_swap_int32(x) -#define htons(x) __byte_swap_int16(x) +#define __swap32md(x) ({ \ + u_int32_t __y, __x = (x); \ + \ + __asm ("rotl $-8, %1, %0; insv %0, $16, $8, %0; " \ + "rotl $8, %1, r1; movb r1, %0" : \ + "&=r" (__y) : "r" (__x) : "r1", "cc"); \ + __y; \ +}) + +#define __swap16md(x) ({ \ + u_int16_t __y, __x = (x); \ + \ + __asm ("rotl $8, %1, %0; rotl $-8, %1, r1; movb r1, %0; " \ + "movzwl %0, %0" : "&=r" (__y) : "r" (__x) : "r1", "cc"); \ + __y; \ +}) + +/* Tell sys/endian.h we have MD variants of the swap macros. */ +#define MD_SWAP #endif /* __GNUC__ */ -/* - * Macros for network/external number representation conversion. - */ -#define NTOHL(x) (x) = ntohl((u_int32_t)(x)) -#define NTOHS(x) (x) = ntohs((u_int16_t)(x)) -#define HTONL(x) (x) = htonl((u_int32_t)(x)) -#define HTONS(x) (x) = htons((u_int16_t)(x)) - -#endif /* _POSIX_SOURCE */ +#define BYTE_ORDER 1234 +#include <sys/endian.h> #endif /* _VAX_ENDIAN_H_ */ diff --git a/sys/arch/wgrisc/include/endian.h b/sys/arch/wgrisc/include/endian.h index b8899c077cf..f4485789018 100644 --- a/sys/arch/wgrisc/include/endian.h +++ b/sys/arch/wgrisc/include/endian.h @@ -1,9 +1,7 @@ -/* $OpenBSD: endian.h,v 1.4 1997/06/25 12:52:11 grr Exp $ */ -/* $NetBSD: endian.h,v 1.4 1994/10/26 21:09:38 cgd Exp $ */ +/* $OpenBSD: endian.h,v 1.5 1997/11/09 23:05:19 niklas Exp $ */ -/* - * Copyright (c) 1987, 1991, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,91 +13,26 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This product includes software developed by Niklas Hallqvist. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)endian.h 8.1 (Berkeley) 6/11/93 - */ - -#ifndef _ENDIAN_H_ -#define _ENDIAN_H_ - -/* - * Define _NOQUAD if the compiler does NOT support 64-bit integers. - */ -/* #define _NOQUAD */ - -/* - * Define the order of 32-bit words in 64-bit words. - */ -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 - -#ifndef _POSIX_SOURCE -/* - * Definitions for byte order, according to byte significance from low - * address to high. - */ -#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ -#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ - -#define BYTE_ORDER LITTLE_ENDIAN /* ``... Beautiful SPIIIIM!'' */ - -#include <sys/cdefs.h> - -typedef u_int32_t in_addr_t; -typedef u_int16_t in_port_t; - -__BEGIN_DECLS -u_int32_t htonl __P((u_int32_t)); -u_int16_t htons __P((u_int16_t)); -u_int32_t ntohl __P((u_int32_t)); -u_int16_t ntohs __P((u_int16_t)); -__END_DECLS - -/* - * Macros for network/external number representation conversion. - * - * The way this works is that HTONS(x) modifies x and *can't* be used as - * and rvalue i.e. foo=HTONS(bar) is wrong. Likewise x=htons(x) should - * never be used where HTONS(x) will serve i.e. foo=htons(foo) is wrong. - * Failing to observe these rule will result in code that appears to work - * and probably does work, but generates gcc warnings on architectures - * where the macros are used to optimize away an unneeded conversion. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if BYTE_ORDER == BIG_ENDIAN && !defined(lint) -#define ntohl(x) (x) -#define ntohs(x) (x) -#define htonl(x) (x) -#define htons(x) (x) -#define NTOHL(x) (void)(x) -#define NTOHS(x) (void)(x) -#define HTONL(x) (void)(x) -#define HTONS(x) (void)(x) +#ifndef _WGRISC_ENDIAN_H_ +#define _WGRISC_ENDIAN_H_ -#else +#define BYTE_ORDER 1234 +#include <sys/endian.h> -#define NTOHL(x) (x) = ntohl((u_int32_t)x) -#define NTOHS(x) (x) = ntohs((u_int16_t)x) -#define HTONL(x) (x) = htonl((u_int32_t)x) -#define HTONS(x) (x) = htons((u_int16_t)x) -#endif -#endif /* ! _POSIX_SOURCE */ -#endif /* !_ENDIAN_H_ */ +#endif /* _WGRISC_ENDIAN_H_ */ |