osdep.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef __OSDEP_H__
  2. #define __OSDEP_H__
  3. /*
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2, or (at
  7. * your option) any later version.
  8. */
  9. #define __LITTLE_ENDIAN /* x86 */
  10. /* Taken from /usr/include/linux/hfs_sysdep.h */
  11. #if defined(__BIG_ENDIAN)
  12. # if !defined(__constant_htonl)
  13. # define __constant_htonl(x) (x)
  14. # endif
  15. # if !defined(__constant_htons)
  16. # define __constant_htons(x) (x)
  17. # endif
  18. #elif defined(__LITTLE_ENDIAN)
  19. # if !defined(__constant_htonl)
  20. # define __constant_htonl(x) \
  21. ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
  22. (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
  23. (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
  24. (((unsigned long int)(x) & 0xff000000U) >> 24)))
  25. # endif
  26. # if !defined(__constant_htons)
  27. # define __constant_htons(x) \
  28. ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  29. (((unsigned short int)(x) & 0xff00) >> 8)))
  30. # endif
  31. #else
  32. # error "Don't know if bytes are big- or little-endian!"
  33. #endif
  34. #define ntohl(x) \
  35. (__builtin_constant_p(x) ? \
  36. __constant_htonl((x)) : \
  37. __swap32(x))
  38. #define htonl(x) \
  39. (__builtin_constant_p(x) ? \
  40. __constant_htonl((x)) : \
  41. __swap32(x))
  42. #define ntohs(x) \
  43. (__builtin_constant_p(x) ? \
  44. __constant_htons((x)) : \
  45. __swap16(x))
  46. #define htons(x) \
  47. (__builtin_constant_p(x) ? \
  48. __constant_htons((x)) : \
  49. __swap16(x))
  50. static inline unsigned long int __swap32(unsigned long int x)
  51. {
  52. __asm__("xchgb %b0,%h0\n\t"
  53. "rorl $16,%0\n\t"
  54. "xchgb %b0,%h0"
  55. : "=q" (x)
  56. : "0" (x));
  57. return x;
  58. }
  59. static inline unsigned short int __swap16(unsigned short int x)
  60. {
  61. __asm__("xchgb %b0,%h0"
  62. : "=q" (x)
  63. : "0" (x));
  64. return x;
  65. }
  66. /* Make routines available to all */
  67. #define swap32(x) __swap32(x)
  68. #define swap16(x) __swap16(x)
  69. #include "linux-asm-io.h"
  70. typedef unsigned long Address;
  71. /* ANSI prototyping macro */
  72. #ifdef __STDC__
  73. #define P(x) x
  74. #else
  75. #define P(x) ()
  76. #endif
  77. #endif
  78. /*
  79. * Local variables:
  80. * c-basic-offset: 8
  81. * End:
  82. */