picorv32.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef PICORV32_H
  2. #define PICORV32_H
  3. #ifndef __ASSEMBLY__
  4. #include "compiler.h"
  5. static inline void p_retirq(void)
  6. {
  7. asm volatile(".insn r 0x0b, 0, 2, zero, zero, zero");
  8. __builtin_unreachable();
  9. }
  10. /*
  11. * hpa: the keepmask is a local addition.
  12. *
  13. * oldmask = irq_mask;
  14. * irq_mask = ((irq_mask & ~keepmask) ^ newmask) | MASKED
  15. *
  16. * ... where MASKED represents IRQs permanently masked
  17. * in the hardware.
  18. */
  19. static inline unsigned int
  20. p_maskirq(unsigned int newmask, unsigned int keepmask)
  21. {
  22. unsigned int oldmask;
  23. asm volatile(".insn r 0x0b, 0, 3, %0, %z1, %z2"
  24. : "=r" (oldmask)
  25. : "Jr" (newmask), "Jr" (keepmask));
  26. return oldmask;
  27. }
  28. static inline unsigned int
  29. p_waitirq(unsigned int andmask, unsigned int ormask)
  30. {
  31. unsigned int pending_mask;
  32. asm volatile(".insn r 0x0b, 0, 4, %0, %z1, %z2"
  33. : "=r" (pending_mask)
  34. : "Jr" (andmask), "Jr" (ormask));
  35. return pending_mask;
  36. }
  37. static inline unsigned int p_timer(unsigned int newval)
  38. {
  39. unsigned int oldval;
  40. asm volatile(".insn 0x0b, 0, 5, %0, %z1, %z2"
  41. : "=r" (oldval)
  42. : "Jr" (newval), "Jr" (0));
  43. }
  44. #else /* __ASSEMBLY__ */
  45. #define q0 x0
  46. #define q1 x1
  47. #define q2 x2
  48. #define q3 x3
  49. .macro addqxi qd, rs, imm
  50. .insn i 0x0b, 0x02, \qd, \rs, \imm
  51. .endm
  52. .macro addxqi rd, qs, imm
  53. .insn i 0x0b, 0x03, \rd, \qs, \imm
  54. .endm
  55. .macro retirq
  56. .insn r 0x0b, 0, 2, zero, zero, zero
  57. .endm
  58. .macro maskirq rd, rs1, rs2
  59. .insn r 0x0b, 0, 3, \rd, \rs1, \rs2
  60. .endm
  61. .macro waitirq rd, andmask, ormask
  62. .insn r 0x0b, 0, 4, \rd, \andmask, \ormask
  63. .endm
  64. .macro timer rd, rs
  65. .insn r 0x0b, 0, 5, \rd, \rs, zero
  66. .endm
  67. #endif /* __ASSEMBLY__ */
  68. #endif /* PICORV32_H */