brg_endian.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
  4. LICENSE TERMS
  5. The redistribution and use of this software (with or without changes)
  6. is allowed without the payment of fees or royalties provided that:
  7. 1. source code distributions include the above copyright notice, this
  8. list of conditions and the following disclaimer;
  9. 2. binary distributions include the above copyright notice, this list
  10. of conditions and the following disclaimer in their documentation;
  11. 3. the name of the copyright holder is not used to endorse products
  12. built using this software without specific written permission.
  13. DISCLAIMER
  14. This software is provided 'as is' with no explicit or implied warranties
  15. in respect of its properties, including, but not limited to, correctness
  16. and/or fitness for purpose.
  17. ---------------------------------------------------------------------------
  18. Issue Date: 20/12/2007
  19. Changes for ARM 9/9/2010
  20. */
  21. #ifndef _BRG_ENDIAN_H
  22. #define _BRG_ENDIAN_H
  23. #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
  24. #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
  25. #if 0
  26. /* Include files where endian defines and byteswap functions may reside */
  27. #if defined( __sun )
  28. # include <sys/isa_defs.h>
  29. #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
  30. # include <sys/endian.h>
  31. #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
  32. defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
  33. # include <machine/endian.h>
  34. #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
  35. # if !defined( __MINGW32__ ) && !defined( _AIX )
  36. # include <endian.h>
  37. # if !defined( __BEOS__ )
  38. # include <byteswap.h>
  39. # endif
  40. # endif
  41. #endif
  42. #endif
  43. /* Now attempt to set the define for platform byte order using any */
  44. /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */
  45. /* seem to encompass most endian symbol definitions */
  46. #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )
  47. # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN
  48. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  49. # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN
  50. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  51. # endif
  52. #elif defined( BIG_ENDIAN )
  53. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  54. #elif defined( LITTLE_ENDIAN )
  55. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  56. #endif
  57. #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )
  58. # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN
  59. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  60. # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN
  61. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  62. # endif
  63. #elif defined( _BIG_ENDIAN )
  64. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  65. #elif defined( _LITTLE_ENDIAN )
  66. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  67. #endif
  68. #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )
  69. # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN
  70. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  71. # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN
  72. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  73. # endif
  74. #elif defined( __BIG_ENDIAN )
  75. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  76. #elif defined( __LITTLE_ENDIAN )
  77. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  78. #endif
  79. #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )
  80. # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__
  81. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  82. # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__
  83. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  84. # endif
  85. #elif defined( __BIG_ENDIAN__ )
  86. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  87. #elif defined( __LITTLE_ENDIAN__ )
  88. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  89. #endif
  90. /* if the platform byte order could not be determined, then try to */
  91. /* set this define using common machine defines */
  92. #if !defined(PLATFORM_BYTE_ORDER)
  93. #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \
  94. defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
  95. defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
  96. defined( vax ) || defined( vms ) || defined( VMS ) || \
  97. defined( __VMS ) || defined( _M_X64 )
  98. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  99. #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
  100. defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
  101. defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
  102. defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
  103. defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
  104. defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
  105. defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX )
  106. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  107. #elif defined(__arm__)
  108. # ifdef __BIG_ENDIAN
  109. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  110. # else
  111. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  112. # endif
  113. #elif 1 /* **** EDIT HERE IF NECESSARY **** */
  114. # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
  115. #elif 0 /* **** EDIT HERE IF NECESSARY **** */
  116. # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
  117. #else
  118. # error Please edit lines 132 or 134 in brg_endian.h to set the platform byte order
  119. #endif
  120. #endif
  121. #endif