picorv32.h 1.6 KB

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