medeleg.rs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //! medeleg register
  2. /// medeleg register
  3. #[derive(Clone, Copy, Debug)]
  4. pub struct Medeleg {
  5. bits: usize,
  6. }
  7. impl Medeleg {
  8. /// Returns the contents of the register as raw bits
  9. #[inline]
  10. pub fn bits(&self) -> usize {
  11. self.bits
  12. }
  13. /// Instruction Address Misaligned Delegate
  14. #[inline]
  15. pub fn instruction_misaligned(&self) -> bool {
  16. self.bits & (1 << 0) != 0
  17. }
  18. /// Instruction Access Fault Delegate
  19. #[inline]
  20. pub fn instruction_fault(&self) -> bool {
  21. self.bits & (1 << 1) != 0
  22. }
  23. /// Illegal Instruction Delegate
  24. #[inline]
  25. pub fn illegal_instruction(&self) -> bool {
  26. self.bits & (1 << 2) != 0
  27. }
  28. /// Breakpoint Delegate
  29. #[inline]
  30. pub fn breakpoint(&self) -> bool {
  31. self.bits & (1 << 3) != 0
  32. }
  33. /// Load Address Misaligned Delegate
  34. #[inline]
  35. pub fn load_misaligned(&self) -> bool {
  36. self.bits & (1 << 4) != 0
  37. }
  38. /// Load Access Fault Delegate
  39. #[inline]
  40. pub fn load_fault(&self) -> bool {
  41. self.bits & (1 << 5) != 0
  42. }
  43. /// Store/AMO Address Misaligned Delegate
  44. #[inline]
  45. pub fn store_misaligned(&self) -> bool {
  46. self.bits & (1 << 6) != 0
  47. }
  48. /// Store/AMO Access Fault Delegate
  49. #[inline]
  50. pub fn store_fault(&self) -> bool {
  51. self.bits & (1 << 7) != 0
  52. }
  53. /// Environment Call from U-mode Delegate
  54. #[inline]
  55. pub fn user_env_call(&self) -> bool {
  56. self.bits & (1 << 8) != 0
  57. }
  58. /// Environment Call from S-mode Delegate
  59. #[inline]
  60. pub fn supervisor_env_call(&self) -> bool {
  61. self.bits & (1 << 9) != 0
  62. }
  63. /// Instruction Page Fault Delegate
  64. #[inline]
  65. pub fn instruction_page_fault(&self) -> bool {
  66. self.bits & (1 << 12) != 0
  67. }
  68. /// Load Page Fault Delegate
  69. #[inline]
  70. pub fn load_page_fault(&self) -> bool {
  71. self.bits & (1 << 13) != 0
  72. }
  73. /// Store/AMO Page Fault Delegate
  74. #[inline]
  75. pub fn store_page_fault(&self) -> bool {
  76. self.bits & (1 << 15) != 0
  77. }
  78. }
  79. read_csr_as!(Medeleg, 0x302);
  80. set!(0x302);
  81. clear!(0x302);
  82. set_clear_csr!(
  83. /// Instruction Address Misaligned Delegate
  84. , set_instruction_misaligned, clear_instruction_misaligned, 1 << 0);
  85. set_clear_csr!(
  86. /// Instruction Access Fault Delegate
  87. , set_instruction_fault, clear_instruction_fault, 1 << 1);
  88. set_clear_csr!(
  89. /// Illegal Instruction Delegate
  90. , set_illegal_instruction, clear_illegal_instruction, 1 << 2);
  91. set_clear_csr!(
  92. /// Breakpoint Delegate
  93. , set_breakpoint, clear_breakpoint, 1 << 3);
  94. set_clear_csr!(
  95. /// Load Address Misaligned Delegate
  96. , set_load_misaligned, clear_load_misaligned, 1 << 4);
  97. set_clear_csr!(
  98. /// Load Access Fault Delegate
  99. , set_load_fault, clear_load_fault, 1 << 5);
  100. set_clear_csr!(
  101. /// Store/AMO Address Misaligned Delegate
  102. , set_store_misaligned, clear_store_misaligned, 1 << 6);
  103. set_clear_csr!(
  104. /// Store/AMO Access fault
  105. , set_store_fault, clear_store_fault, 1 << 7);
  106. set_clear_csr!(
  107. /// Environment Call from U-mode Delegate
  108. , set_user_env_call, clear_user_env_call, 1 << 8);
  109. set_clear_csr!(
  110. /// Environment Call from S-mode Delegate
  111. , set_supervisor_env_call, clear_supervisor_env_call, 1 << 9);
  112. set_clear_csr!(
  113. /// Instruction Page Fault Delegate
  114. , set_instruction_page_fault, clear_instruction_page_fault, 1 << 12);
  115. set_clear_csr!(
  116. /// Load Page Fault Delegate
  117. , set_load_page_fault, clear_load_page_fault, 1 << 13);
  118. set_clear_csr!(
  119. /// Store/AMO Page Fault Delegate
  120. , set_store_page_fault, clear_store_page_fault, 1 << 15);