core_v5.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef __CORE_V5_H__
  2. #define __CORE_V5_H__
  3. #define MSTATUS_UIE 0x00000001
  4. #define MSTATUS_SIE 0x00000002
  5. #define MSTATUS_HIE 0x00000004
  6. #define MSTATUS_MIE 0x00000008
  7. #define MSTATUS_UPIE 0x00000010
  8. #define MSTATUS_SPIE 0x00000020
  9. #define MSTATUS_HPIE 0x00000040
  10. #define MSTATUS_MPIE 0x00000080
  11. #define MSTATUS_SPP 0x00000100
  12. #define MSTATUS_HPP 0x00000600
  13. #define MSTATUS_MPP 0x00001800
  14. #define MSTATUS_FS 0x00006000
  15. #define MSTATUS_XS 0x00018000
  16. #define MSTATUS_MPRV 0x00020000
  17. #define MSTATUS_PUM 0x00040000
  18. #define MSTATUS_MXR 0x00080000
  19. #define MSTATUS_VM 0x1F000000
  20. #define MSTATUS32_SD 0x80000000
  21. #define MSTATUS64_SD 0x8000000000000000
  22. #if __riscv_xlen == 64
  23. #define MCAUSE_INT 0x8000000000000000UL
  24. #define MCAUSE_CAUSE 0x7FFFFFFFFFFFFFFFUL
  25. #else
  26. #define MCAUSE_INT 0x80000000UL
  27. #define MCAUSE_CAUSE 0x7FFFFFFFUL
  28. #endif
  29. #define IRQ_S_SOFT 1
  30. #define IRQ_H_SOFT 2
  31. #define IRQ_M_SOFT 3
  32. #define IRQ_S_TIMER 5
  33. #define IRQ_H_TIMER 6
  34. #define IRQ_M_TIMER 7
  35. #define IRQ_S_EXT 9
  36. #define IRQ_H_EXT 10
  37. #define IRQ_M_EXT 11
  38. #define IRQ_COP 12
  39. #define IRQ_HOST 13
  40. /* Machine mode MCAUSE */
  41. #define TRAP_M_I_ACC_FAULT 1 /* Instruction access fault */
  42. #define TRAP_M_L_ACC_FAULT 5 /* Data load access fault */
  43. #define TRAP_M_S_ACC_FAULT 7 /* Data store access fault */
  44. #define TRAP_U_ECALL 8
  45. #define TRAP_S_ECALL 9
  46. #define TRAP_H_ECALL 10
  47. #define TRAP_M_ECALL 11
  48. #define TRAP_M_I_PAGE_FAULT 12 /* Instruction page fault */
  49. #define TRAP_M_L_PAGE_FAULT 13 /* Data load page fault */
  50. #define TRAP_M_S_PAGE_FAULT 15 /* Data store page fault */
  51. #define TRAP_M_STACKOVF 32
  52. #define TRAP_M_STACKUDF 33
  53. /* Supervisor mode SCAUSE */
  54. #define TRAP_S_I_ACC_FAULT 1 /* Instruction access fault */
  55. #define TRAP_S_L_ACC_FAULT 5 /* Data load access fault */
  56. #define TRAP_S_S_ACC_FAULT 7 /* Data store access fault */
  57. #define TRAP_S_I_PAGE_FAULT 12 /* Instruction page fault */
  58. #define TRAP_S_L_PAGE_FAULT 13 /* Data load page fault */
  59. #define TRAP_S_S_PAGE_FAULT 15 /* Data store page fault */
  60. #define MIP_SSIP (1 << IRQ_S_SOFT)
  61. #define MIP_HSIP (1 << IRQ_H_SOFT)
  62. #define MIP_MSIP (1 << IRQ_M_SOFT)
  63. #define MIP_STIP (1 << IRQ_S_TIMER)
  64. #define MIP_HTIP (1 << IRQ_H_TIMER)
  65. #define MIP_MTIP (1 << IRQ_M_TIMER)
  66. #define MIP_SEIP (1 << IRQ_S_EXT)
  67. #define MIP_HEIP (1 << IRQ_H_EXT)
  68. #define MIP_MEIP (1 << IRQ_M_EXT)
  69. /* MILMB and MDLMB */
  70. #define MILMB_IEN (0x1UL)
  71. #define MDLMB_DEN (0x1UL)
  72. #if __riscv_xlen == 64
  73. # define SLL32 sllw
  74. # define STORE sd
  75. # define LOAD ld
  76. # define LWU lwu
  77. # define LOG_REGBYTES 3
  78. #else
  79. # define SLL32 sll
  80. # define STORE sw
  81. # define LOAD lw
  82. # define LWU lw
  83. # define LOG_REGBYTES 2
  84. #endif
  85. #define REGBYTES (1 << LOG_REGBYTES)
  86. #if __riscv_flen == 64
  87. # define FPSTORE fsd
  88. # define FPLOAD fld
  89. # define LOG_FPREGBYTES 3
  90. #else
  91. # define FPSTORE fsw
  92. # define FPLOAD flw
  93. # define LOG_FPREGBYTES 2
  94. #endif
  95. #define FPREGBYTES (1 << LOG_FPREGBYTES)
  96. #define STR(S) #S
  97. #define XSTR(S) STR(S)
  98. #define PUSH XSTR(STORE)
  99. #define POP XSTR(LOAD)
  100. #define REGSIZE XSTR(REGBYTES)
  101. #define FPPUSH XSTR(FPSTORE)
  102. #define FPPOP XSTR(FPLOAD)
  103. #define FPREGSIZE XSTR(FPREGBYTES)
  104. #ifndef __ASSEMBLER__
  105. #define read_csr(reg) __nds__csrr(reg)
  106. #define write_csr(reg, val) __nds__csrw(val, reg)
  107. #define swap_csr(reg, val) __nds__csrrw(val, reg)
  108. #define set_csr(reg, bit) __nds__csrrs(bit, reg)
  109. #define clear_csr(reg, bit) __nds__csrrc(bit, reg)
  110. #endif
  111. #endif // __CORE_V5_H__