instructions.h 1.4 KB

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