instructions.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H
  3. #define _SELFTESTS_POWERPC_INSTRUCTIONS_H
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. /* This defines the "copy" instruction from Power ISA 3.0 Book II, section 4.4. */
  7. #define __COPY(RA, RB, L) \
  8. (0x7c00060c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10))
  9. #define COPY(RA, RB, L) \
  10. .long __COPY((RA), (RB), (L))
  11. static inline void copy(void *i)
  12. {
  13. asm volatile(str(COPY(0, %0, 0))";"
  14. :
  15. : "b" (i)
  16. : "memory"
  17. );
  18. }
  19. static inline void copy_first(void *i)
  20. {
  21. asm volatile(str(COPY(0, %0, 1))";"
  22. :
  23. : "b" (i)
  24. : "memory"
  25. );
  26. }
  27. /* This defines the "paste" instruction from Power ISA 3.0 Book II, section 4.4. */
  28. #define __PASTE(RA, RB, L, RC) \
  29. (0x7c00070c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10) | (RC) << (31-31))
  30. #define PASTE(RA, RB, L, RC) \
  31. .long __PASTE((RA), (RB), (L), (RC))
  32. static inline int paste(void *i)
  33. {
  34. int cr;
  35. asm volatile(str(PASTE(0, %1, 0, 0))";"
  36. "mfcr %0;"
  37. : "=r" (cr)
  38. : "b" (i)
  39. : "memory"
  40. );
  41. return cr;
  42. }
  43. static inline int paste_last(void *i)
  44. {
  45. int cr;
  46. asm volatile(str(PASTE(0, %1, 1, 1))";"
  47. "mfcr %0;"
  48. : "=r" (cr)
  49. : "b" (i)
  50. : "memory"
  51. );
  52. return cr;
  53. }
  54. #define PPC_INST_COPY __COPY(0, 0, 0)
  55. #define PPC_INST_COPY_FIRST __COPY(0, 0, 1)
  56. #define PPC_INST_PASTE __PASTE(0, 0, 0, 0)
  57. #define PPC_INST_PASTE_LAST __PASTE(0, 0, 1, 1)
  58. #endif /* _SELFTESTS_POWERPC_INSTRUCTIONS_H */