trap.c 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "encoding.h"
  2. #include "uart.h"
  3. #include "comdef.h"
  4. #if __riscv_xlen == 32
  5. #define MCAUSE_INT 0x80000000UL
  6. #define MCAUSE_CAUSE 0x000003FFUL
  7. #else
  8. #define MCAUSE_INT 0x8000000000000000UL
  9. #define MCAUSE_CAUSE 0x00000000000003FFUL
  10. #endif
  11. uintptr_t handle_trap(uintptr_t mcause, uintptr_t epc)
  12. {
  13. #if 0
  14. if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT)) {
  15. rlSendString("extern interrupt.\n");
  16. } else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER)){
  17. rlSendString("timer interrupt.\n");
  18. } else if (mcause & MCAUSE_INT) {
  19. rlSendString("local interrupt.\n");
  20. }
  21. else {
  22. rlSendString("unhandle trap.\n");
  23. }
  24. #endif
  25. printk("trap mcause:0x%x epc:0x%x\n",mcause,epc);
  26. return epc;
  27. }
  28. void trap_entry(void)
  29. {
  30. unsigned long mcause = read_csr(mcause);
  31. unsigned long mepc = read_csr(mepc);
  32. handle_trap(mcause, mepc);
  33. }