asm.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef __ASM_H
  2. #define __ASM_H
  3. #define REG_READ(name, offset) \
  4. .section .text.__read_ ## name; \
  5. .global __read_ ## name; \
  6. __read_ ## name: \
  7. csrrs a0, offset, x0; \
  8. ret
  9. #define REG_WRITE(name, offset) \
  10. .section .text.__write_ ## name; \
  11. .global __write_ ## name; \
  12. __write_ ## name: \
  13. csrrw x0, offset, a0; \
  14. ret
  15. #define REG_SET(name, offset) \
  16. .section .text.__set_ ## name; \
  17. .global __set_ ## name; \
  18. __set_ ## name: \
  19. csrrs x0, offset, a0; \
  20. ret
  21. #define REG_CLEAR(name, offset) \
  22. .section .text.__clear_ ## name; \
  23. .global __clear_ ## name; \
  24. __clear_ ## name: \
  25. csrrc x0, offset, a0; \
  26. ret
  27. #define REG_READ_WRITE(name, offset) REG_READ(name, offset); REG_WRITE(name, offset)
  28. #define REG_SET_CLEAR(name, offset) REG_SET(name, offset); REG_CLEAR(name, offset)
  29. #define RW(offset, name) REG_READ_WRITE(name, offset); REG_SET_CLEAR(name, offset)
  30. #define RO(offset, name) REG_READ(name, offset)
  31. #if __riscv_xlen == 32
  32. #define RW32(offset, name) RW(offset, name)
  33. #define RO32(offset, name) RO(offset, name)
  34. #else
  35. #define RW32(offset, name)
  36. #define RO32(offset, name)
  37. #endif
  38. #endif /* __ASM_H */