trap.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2021, Shenzhen Academy of Aerospace Technology
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-11-16 Dystopia the first version
  9. */
  10. #ifndef __TRAP_H__
  11. #define __TRAP_H__
  12. #include "c66xx.h"
  13. /*
  14. * exception operation macro
  15. */
  16. #define disable_exception()
  17. #define get_except_type() EFR
  18. #define ack_exception(type) ECR = 1ul << (type)
  19. #define get_iexcept() IERR
  20. #define set_iexcept(mask) IERR = (mask)
  21. /*
  22. * exception types
  23. */
  24. #define EXCEPT_TYPE_NXF 31 /* NMI */
  25. #define EXCEPT_TYPE_EXC 30 /* external exception */
  26. #define EXCEPT_TYPE_IXF 1 /* internal exception */
  27. #define EXCEPT_TYPE_SXF 0 /* software exception */
  28. #define EXCEPT_CAUSE_LBX (1 << 7) /* loop buffer exception */
  29. #define EXCEPT_CAUSE_PRX (1 << 6) /* privilege exception */
  30. #define EXCEPT_CAUSE_RAX (1 << 5) /* resource access exception */
  31. #define EXCEPT_CAUSE_RCX (1 << 4) /* resource conflict exception */
  32. #define EXCEPT_CAUSE_OPX (1 << 3) /* opcode exception */
  33. #define EXCEPT_CAUSE_EPX (1 << 2) /* execute packet exception */
  34. #define EXCEPT_CAUSE_FPX (1 << 1) /* fetch packet exception */
  35. #define EXCEPT_CAUSE_IFX (1 << 0) /* instruction fetch exception */
  36. enum SYSTEM_TRAP_CODE
  37. {
  38. ABORT_BUS_ADDRERR = 0, // bus address error
  39. ABORT_BUS_ACCERR, // bus access permission error
  40. ABORT_OPCODE_ILL, // illegal opcode
  41. ABORT_PRVREG_ILL, // privilege register
  42. ABORT_PRVOPC_ILL, // privileged opcode
  43. ABORT_ILLTRP_ILL, // illegal trap
  44. ABORT_BRKPT_ILL, // handling breakpoints
  45. };
  46. /*
  47. * abort types
  48. */
  49. #define ABORT_TYPE_BUS 0 // bus access abnormal
  50. #define ABORT_TYPE_MAP 1 // page table mapping error
  51. #define ABORT_TYPE_UNDDEF 0xff // undefined exception
  52. #define ABORT_TYPE_FATAL 0xffffffff // fatal error
  53. struct rt_exception_info {
  54. char *kernel_str;
  55. int type;
  56. int code;
  57. };
  58. #define BKPT_OPCODE 0x56454314 /* illegal opcode */
  59. #define INTC_MEXPMASK __SYSREGA(0x018000e0, unsigned int)
  60. #define __ffs(a) (_lmbd(1, _bitr(a)))
  61. #define __fls(a) (!(a) ? 0 : (32 - _lmbd(1, (a))))
  62. extern void rt_trap_init(void);
  63. #endif /* __TRAP_H__ */