2
0

picorv32.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. return oldval;
  44. }
  45. static inline unsigned int
  46. p_pollirq(unsigned int mask, unsigned int already)
  47. {
  48. unsigned int irqs;
  49. asm volatile(".insn 0x0b, 0, 6, %0, %z1, %z2"
  50. : "=r" (irqs)
  51. : "Jr" (mask), "Jr" (already));
  52. return irqs;
  53. }
  54. #else /* __ASSEMBLY__ */
  55. #define q0 x0
  56. #define q1 x1
  57. #define q2 x2
  58. #define q3 x3
  59. .macro addqxi qd, rs, imm
  60. .insn i 0x0b, 0x02, \qd, \rs, \imm
  61. .endm
  62. .macro addxqi rd, qs, imm
  63. .insn i 0x0b, 0x03, \rd, \qs, \imm
  64. .endm
  65. .macro retirq
  66. .insn r 0x0b, 0, 2, zero, zero, zero
  67. .endm
  68. .macro maskirq rd, rs1, rs2
  69. .insn r 0x0b, 0, 3, \rd, \rs1, \rs2
  70. .endm
  71. .macro waitirq rd, andmask, ormask
  72. .insn r 0x0b, 0, 4, \rd, \andmask, \ormask
  73. .endm
  74. .macro timer rd, rs
  75. .insn r 0x0b, 0, 5, \rd, \rs, zero
  76. .endm
  77. .macro pollirq rd, mask, already
  78. .insn r 0x0b, 0, 6, \rd, \mask, \already
  79. .endm
  80. #endif /* __ASSEMBLY__ */
  81. #endif /* PICORV32_H */