Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Common type definitions and macros widely used by Open
  28. *               Watcom tools.
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #ifndef _WATCOM_H_INCLUDED_
  34. #define _WATCOM_H_INCLUDED_
  35.  
  36. #include <errno.h>
  37. #ifndef __WATCOMC__
  38. #include "clibext.h"
  39. #endif
  40.  
  41. #if !defined(__sun__) && !defined(sun) && !defined(__sgi) && !defined(__hppa) && !defined(_AIX) && !defined(__alpha) && !defined(_TYPES_H_) && !defined(_SYS_TYPES_H)
  42.     typedef unsigned        uint;
  43. #endif
  44.  
  45. typedef unsigned char   uint_8;
  46. typedef unsigned short  uint_16;
  47. #if defined (LONG_IS_64BITS)
  48. typedef unsigned int    uint_32;
  49. #else
  50. typedef unsigned long   uint_32;
  51. #endif
  52. typedef unsigned char   unsigned_8;
  53. typedef unsigned short  unsigned_16;
  54. #if defined (LONG_IS_64BITS)
  55. typedef unsigned int    unsigned_32;
  56. #else
  57. typedef unsigned long   unsigned_32;
  58. #endif
  59.  
  60. typedef signed char     int_8;
  61. typedef signed short    int_16;
  62. #if defined (LONG_IS_64BITS)
  63. typedef signed int      int_32;
  64. #else
  65. typedef signed long     int_32;
  66. #endif
  67. typedef signed char     signed_8;
  68. typedef signed short    signed_16;
  69. #if defined (LONG_IS_64BITS)
  70. typedef signed int      signed_32;
  71. #else
  72. typedef signed long     signed_32;
  73. #endif
  74.  
  75. typedef struct {
  76.     union {
  77.         unsigned_32     _32[2];
  78.         unsigned_16     _16[4];
  79.         unsigned_8       _8[8];
  80.         struct {
  81. #if defined( __BIG_ENDIAN__ )
  82.             unsigned    v       : 1;
  83.             unsigned            : 15;
  84.             unsigned            : 16;
  85.             unsigned            : 16;
  86.             unsigned            : 16;
  87. #else
  88.             unsigned            : 16;
  89.             unsigned            : 16;
  90.             unsigned            : 16;
  91.             unsigned            : 15;
  92.             unsigned    v       : 1;
  93. #endif
  94.         }       sign;
  95. #if defined(__WATCOM_INT64__) || defined(__GNUC__)
  96.         unsigned long long   _64[1];
  97. #endif
  98.     } u;
  99. } unsigned_64;
  100. typedef unsigned_64     signed_64;
  101.  
  102. /* Macros for low/high end access on little and big endian machines */
  103.  
  104. #if defined( __BIG_ENDIAN__ )
  105.     #define I64LO32     1
  106.     #define I64HI32     0
  107.     #define I64LO16     3
  108.     #define I64HI16     0
  109.     #define I64LO8      7
  110.     #define I64HI8      0
  111. #else
  112.     #define I64LO32     0
  113.     #define I64HI32     1
  114.     #define I64LO16     0
  115.     #define I64HI16     3
  116.     #define I64LO8      0
  117.     #define I64HI8      7
  118. #endif
  119.  
  120. /* Define _crtn for prototypes for external C routines called from C++.
  121.  * Eg. extern _crtn void Foo();
  122.  */
  123. #if !defined( _crtn )
  124.     #if defined( __cplusplus )
  125.         #define _crtn   "C"
  126.     #else
  127.         #define _crtn
  128.     #endif
  129. #endif
  130.  
  131. /*  Macros for little/big endian conversion; These exist to simplify writing
  132.  *  code that handles both little and big endian data on either little or big
  133.  *  endian host platforms. Some of these macros could be implemented as inline
  134.  *  assembler where instructions to byte swap data in registers or read/write
  135.  *  memory access with byte swapping is available.
  136.  *
  137.  *  NOTE:   The SWAP_XX macros will swap data in place. If you only want to take a
  138.  *          a copy of the data and leave the original intact, then use the SWAPNC_XX
  139.  *          macros.
  140.  */
  141. #define SWAPNC_16(w)    (\
  142.                             (((w) & 0x000000FFUL) << 8) |\
  143.                             (((w) & 0x0000FF00UL) >> 8)\
  144.                         )
  145. #define SWAPNC_32(w)    (\
  146.                             (((w) & 0x000000FFUL) << 24) |\
  147.                             (((w) & 0x0000FF00UL) << 8) |\
  148.                             (((w) & 0x00FF0000UL) >> 8) |\
  149.                             (((w) & 0xFF000000UL) >> 24)\
  150.                         )
  151. #define SWAPNC_64(w)    (\
  152.                             (((w) & 0x00000000000000FFULL) << 56) |\
  153.                             (((w) & 0x000000000000FF00ULL) << 40) |\
  154.                             (((w) & 0x0000000000FF0000ULL) << 24) |\
  155.                             (((w) & 0x00000000FF000000ULL) << 8) |\
  156.                             (((w) & 0x000000FF00000000ULL) >> 8) |\
  157.                             (((w) & 0x0000FF0000000000ULL) >> 24) |\
  158.                             (((w) & 0x00FF000000000000ULL) >> 40) |\
  159.                             (((w) & 0xFF00000000000000ULL) >> 56)\
  160.                         )  
  161.  
  162. #if defined( __BIG_ENDIAN__ )
  163.     /* Macros to get little endian data */
  164.     #define GET_LE_16(w)    SWAPNC_16(w)
  165.     #define GET_LE_32(w)    SWAPNC_32(w)
  166.     #define GET_LE_64(w)    SWAPNC_64(w)
  167.     /* Macros to get big endian data */
  168.     #define GET_BE_16(w)    (w)
  169.     #define GET_BE_32(w)    (w)
  170.     #define GET_BE_64(w)    (w)
  171.     /* Macros to convert little endian data in place */
  172.     #define CONV_LE_16(w)   (w) = SWAPNC_16(w)
  173.     #define CONV_LE_32(w)   (w) = SWAPNC_32(w)
  174.     #define CONV_LE_64(w)   (w) = SWAPNC_64(w)
  175.     /* Macros to convert big endian data in place */
  176.     #define CONV_BE_16(w)
  177.     #define CONV_BE_32(w)
  178.     #define CONV_BE_64(w)
  179.     /* Macros to swap byte order */
  180.     #define SWAP_16     CONV_LE_16
  181.     #define SWAP_32     CONV_LE_32
  182.     #define SWAP_64     CONV_LE_64
  183. #else
  184.     /* Macros to get little endian data */
  185.     #define GET_LE_16(w)    (w)
  186.     #define GET_LE_32(w)    (w)
  187.     #define GET_LE_64(w)    (w)
  188.     /* Macros to get big endian data */
  189.     #define GET_BE_16(w)    SWAPNC_16(w)
  190.     #define GET_BE_32(w)    SWAPNC_32(w)
  191.     #define GET_BE_64(w)    SWAPNC_64(w)
  192.     /* Macros to convert little endian data in place */
  193.     #define CONV_LE_16(w)
  194.     #define CONV_LE_32(w)
  195.     #define CONV_LE_64(w)
  196.     /* Macros to convert big endian data in place */
  197.     #define CONV_BE_16(w)   (w) = SWAPNC_16(w)
  198.     #define CONV_BE_32(w)   (w) = SWAPNC_32(w)
  199.     #define CONV_BE_64(w)   (w) = SWAPNC_64(w)
  200.     /* Macros to swap byte order */
  201.     #define SWAP_16     CONV_BE_16
  202.     #define SWAP_32     CONV_BE_32
  203.     #define SWAP_64     CONV_BE_64
  204. #endif
  205.  
  206. #endif
  207.