atom.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * atomic memory operations and fences for rv32a
  3. *
  4. * assumes the standard A extension
  5. * LR/SC only work on cached regions
  6. */
  7. #define Amoadd 0
  8. #define Amoswap 1
  9. #define Amolr 2
  10. #define Amosc 3
  11. #define Amoxor 4
  12. #define Amoor 010
  13. #define Amoand 014
  14. #define Amomin 020
  15. #define Amomax 024
  16. #define Amominu 030
  17. #define Amomaxu 034
  18. /* AMO operand widths */
  19. #define Amow 2 /* long */
  20. #define AQ (1<<26) /* acquire */
  21. #define RL (1<<25) /* release */
  22. /* instructions unknown to the assembler */
  23. /* atomically (rd = (rs1); (rs1) = rd func rs2) */
  24. #define AMOW(func, opts, rs2, rs1, rd) \
  25. WORD $(((func)<<27)|((rs2)<<20)|((rs1)<<15)|(Amow<<12)|((rd)<<7)|057|(opts))
  26. #define LRW(rs1, rd) AMOW(Amolr, AQ, 0, rs1, rd)
  27. #define SCW(rs2, rs1, rd) AMOW(Amosc, AQ|RL, rs2, rs1, rd)
  28. #define FENCE WORD $(0xf | 0xff<<20) /* all i/o, mem ops before & after */
  29. #define PAUSE WORD $(0xf | 1<<24) /* FENCE pred=W, Zihintpause ext'n */
  30. #define FENCE_I WORD $(0xf | 1<<12)
  31. #define SFENCE_VMA(rs2, rs1) WORD $(011<<25|(rs2)<<20|(rs1)<<15|0<<7|SYSTEM)
  32. #define SEXT_W(r) ADDW R0, r