Ignore:
Timestamp:
May 18, 2003, 6:53:22 AM (22 years ago)
Author:
bird
Message:

Freebsd 5.0/4.8 kind of.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/386/endian.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r168 r169  
    3232 *
    3333 *      from: @(#)endian.h      7.8 (Berkeley) 4/3/91
    34  *      $Id: endian.h,v 1.9 1994/02/12 07:23:49 cgd Exp $
     34 * $FreeBSD: src/sys/i386/include/endian.h,v 1.35 2002/09/23 04:32:16 mike Exp $
     35 *
     36 * bird: this is a bit mixed up. with 1.18 too.
    3537 */
    3638
    3739#ifndef _MACHINE_ENDIAN_H_
    3840#define _MACHINE_ENDIAN_H_
     41
    3942
    4043/*
     
    4447#define _QUAD_LOWWORD 0
    4548
    46 
    47 #ifndef _POSIX_SOURCE
    4849/*
    4950 * Definitions for byte order, according to byte significance from low
    5051 * address to high.
    5152 */
    52 #define LITTLE_ENDIAN   1234    /* LSB first: i386, vax */
    53 #define BIG_ENDIAN      4321    /* MSB first: 68000, ibm, net */
    54 #define PDP_ENDIAN      3412    /* LSB first in word, MSW first in long */
     53#define _LITTLE_ENDIAN  1234    /* LSB first: i386, vax */
     54#define _BIG_ENDIAN     4321    /* MSB first: 68000, ibm, net */
     55#define _PDP_ENDIAN     3412    /* LSB first in word, MSW first in long */
    5556
    56 #define BYTE_ORDER      LITTLE_ENDIAN
     57#define _BYTE_ORDER     LITTLE_ENDIAN
    5758
    58 unsigned long   htonl(unsigned long);
    59 unsigned short  htons(unsigned short);
    60 unsigned long   ntohl(unsigned long);
    61 unsigned short  ntohs(unsigned short);
     59/*
     60 * Deprecated variants that don't have enough underscores to be useful in more
     61 * strict namespaces.
     62 */
     63#if __BSD_VISIBLE
     64#define LITTLE_ENDIAN   _LITTLE_ENDIAN
     65#define BIG_ENDIAN      _BIG_ENDIAN
     66#define PDP_ENDIAN      _PDP_ENDIAN
     67#define BYTE_ORDER      _BYTE_ORDER
     68#endif
    6269
    63 #ifndef __EMX__
     70#include <sys/cdefs.h>
     71
    6472
    6573#ifdef __GNUC__
    6674
    67 #if __GNUC__ >= 2
     75#define __word_swap_int(x) \
     76__extension__ ({ register __uint32_t __X = (x); \
     77   __asm ("rorl $16, %0" : "+r" (__X)); \
     78   __X; })
    6879
    69 #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
    70 #define __byte_swap_long(x) \
    71 ({ register unsigned long __x = (x); \
    72    asm ("bswap %1" \
    73         : "=q" (__x) \
    74         : "0" (__x)); \
    75    __x; })
     80#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
     81
     82#define __byte_swap_int(x) \
     83__extension__ ({ register __uint32_t __X = (x); \
     84   __asm ("bswap %0" : "+r" (__X)); \
     85   __X; })
    7686#else
    77 #define __byte_swap_long(x) \
    78 ({ register unsigned long __x = (x); \
    79    asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
    80         : "=q" (__x) \
    81         : "0" (__x)); \
    82    __x; })
    83 #endif  /* KERNEL && ... */
     87
     88#define __byte_swap_int(x) \
     89__extension__ ({ register __uint32_t __X = (x); \
     90   __asm ("xchgb %h0, %b0\n\trorl $16, %0\n\txchgb %h0, %b0" \
     91       : "+q" (__X)); \
     92   __X; })
     93#endif
     94
    8495#define __byte_swap_word(x) \
    85 ({ register unsigned short __x = (x); \
    86    asm ("xchgb %h1, %b1" \
    87         : "=q" (__x) \
    88         : "0" (__x)); \
    89    __x; })
     96__extension__ ({ register __uint16_t __X = (x); \
     97   __asm ("xchgb %h0, %b0" : "+q" (__X)); \
     98   __X; })
    9099
    91 #else   /* __GNUC__ >= 2 */
     100static __inline __uint64_t
     101__bswap64(__uint64_t _x)
     102{
     103        return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) |
     104            ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) |
     105            ((_x << 24) & ((__uint64_t)0xff << 40)) |
     106            ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)));
     107}
    92108
    93 #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
    94 #define __byte_swap_long(x) \
    95 ({ register unsigned long __x = (x); \
    96    asm ("bswap %1" \
    97         : "=r" (__x) \
    98         : "0" (__x)); \
    99    __x; })
    100 #else
    101 #define __byte_swap_long(x) \
    102 ({ register u_long __x = (x); \
    103    asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
    104         : "=r" (__x) \
    105         : "0" (__x)); \
    106    __x; })
    107 #endif  /* KERNEL && ... */
    108 #define __byte_swap_word(x) \
    109 ({ register u_short __x = (x); \
    110    asm ("rorw $8, %w1" \
    111         : "=r" (__x) \
    112         : "0" (__x)); \
    113    __x; })
     109static __inline __uint32_t
     110__bswap32(__uint32_t _x)
     111{
    114112
    115 #endif  /* __GNUC__ >= 2 */
     113        return (__byte_swap_int(_x));
     114}
    116115
    117 #define ntohl(x)        __byte_swap_long(x)
    118 #define ntohs(x)        __byte_swap_word(x)
    119 #define htonl(x)        __byte_swap_long(x)
    120 #define htons(x)        __byte_swap_word(x)
     116static __inline __uint16_t
     117__bswap16(__uint16_t _x)
     118{
    121119
    122 #endif  /* __GNUC__ */
     120        return (__byte_swap_word(_x));
     121}
    123122
    124 #endif /* not __EMX__ */
     123#define __htonl(x)      __bswap32(x)
     124#define __htons(x)      __bswap16(x)
     125#define __ntohl(x)      __bswap32(x)
     126#define __ntohs(x)      __bswap16(x)
     127
     128#else /* !__GNUC__ */
     129
     130/*
     131 * No optimizations are available for this compiler.  Fall back to
     132 * non-optimized functions by defining the constant usually used to prevent
     133 * redefinition.
     134 */
     135#define _BYTEORDER_FUNC_DEFINED
     136
     137#endif /* __GNUC__ */
     138
     139
     140/* For toolkit compatibility we must do this stuff here.
     141 * Not sure how correct this is now. And mixing 4 versions
     142 * of (Free)BSD doesn't help....
     143 */
     144#ifndef _POSIX_SOURCE
     145
     146#ifndef _KERNEL
     147#include <sys/cdefs.h>
     148#endif
     149
     150__BEGIN_DECLS
     151unsigned long  _System htonl __P((unsigned long));
     152unsigned short _System htons __P((unsigned short));
     153unsigned long  _System ntohl __P((unsigned long));
     154unsigned short _System ntohs __P((unsigned short));
     155__END_DECLS
     156
     157#ifndef _BYTEORDER_FUNC_DEFINED
     158#define _BYTEORDER_FUNC_DEFINED
     159#define htonl(x)   __htonl(x)
     160#define htons(x)   __htons(x)
     161#define ntohl(x)   __ntohl(x)
     162#define ntohs(x)   __ntohs(x)
     163#endif
    125164
    126165/*
    127166 * Macros for network/external number representation conversion.
    128167 */
    129 #define NTOHL(x)        (x) = ntohl((u_long)x)
    130 #define NTOHS(x)        (x) = ntohs((u_short)x)
    131 #define HTONL(x)        (x) = htonl((u_long)x)
    132 #define HTONS(x)        (x) = htons((u_short)x)
     168#define NTOHL(x)   ((x) = ntohl((u_long)(x)))
     169#define NTOHS(x)   ((x) = ntohs((u_short)(x)))
     170#define HTONL(x)   ((x) = htonl((u_long)(x)))
     171#define HTONS(x)   ((x) = htons((u_short)(x)))
    133172
    134 #endif /* _POSIX_SOURCE */
     173#endif /*!_POSIX_SOURCE*/
     174
    135175
    136176#endif /* _MACHINE_ENDIAN_H_ */
Note: See TracChangeset for help on using the changeset viewer.