sim-endian.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _SIM_ENDIAN_C_
  15. #define _SIM_ENDIAN_C_
  16. /* This must come before any other includes. */
  17. #include "defs.h"
  18. #include "basics.h"
  19. #include "symcat.h"
  20. #if !defined(_SWAP_1)
  21. #define _SWAP_1(SET,RAW) SET (RAW)
  22. #endif
  23. #if !defined(_SWAP_2) && (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE) && defined(htons)
  24. #define _SWAP_2(SET,RAW) SET htons (RAW)
  25. #endif
  26. #ifndef _SWAP_2
  27. #define _SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8))
  28. #endif
  29. #if !defined(_SWAP_4) && (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE) && defined(htonl)
  30. #define _SWAP_4(SET,RAW) SET htonl (RAW)
  31. #endif
  32. #ifndef _SWAP_4
  33. #define _SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24))
  34. #endif
  35. #ifndef _SWAP_8
  36. #define _SWAP_8(SET,RAW) \
  37. union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \
  38. in.dword = RAW; \
  39. _SWAP_4 (out.words[0] =, in.words[1]); \
  40. _SWAP_4 (out.words[1] =, in.words[0]); \
  41. SET out.dword;
  42. #endif
  43. #define N 1
  44. #include "sim-endian-n.h"
  45. #undef N
  46. #define N 2
  47. #include "sim-endian-n.h"
  48. #undef N
  49. #define N 4
  50. #include "sim-endian-n.h"
  51. #undef N
  52. #define N 8
  53. #include "sim-endian-n.h"
  54. #undef N
  55. #endif /* _SIM_ENDIAN_C_ */