You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

byteswap.h 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (C) 2004 Tobias Lorenz
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef ETHERBOOT_BITS_BYTESWAP_H
  9. #define ETHERBOOT_BITS_BYTESWAP_H
  10. /* We do not have byte swap functions ... We are
  11. * RISC processor ...
  12. */
  13. static inline unsigned short __swap16(volatile unsigned short v)
  14. {
  15. return ((v << 8) | (v >> 8));
  16. }
  17. static inline unsigned int __swap32(volatile unsigned long v)
  18. {
  19. return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
  20. }
  21. #define __bswap_constant_16(x) \
  22. ((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
  23. (((uint16_t)(x) & 0xff00) >> 8)))
  24. #define __bswap_constant_32(x) \
  25. ((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
  26. (((uint32_t)(x) & 0x0000ff00U) << 8) | \
  27. (((uint32_t)(x) & 0x00ff0000U) >> 8) | \
  28. (((uint32_t)(x) & 0xff000000U) >> 24)))
  29. # define __bswap_16(x) \
  30. (__extension__ \
  31. ({ unsigned short int __bsx = (x); \
  32. ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); }))
  33. # define __bswap_32(x) \
  34. (__extension__ \
  35. ({ unsigned int __bsx = (x); \
  36. ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | \
  37. (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); }))
  38. #endif /* ETHERBOOT_BITS_BYTESWAP_H */