trap.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2008-12-11 XuXinming first version
  9. * 2013-05-24 Grissiom port to RM48x50
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <sys_vim.h>
  14. #include "armv7.h"
  15. /**
  16. * @addtogroup RM48x50
  17. */
  18. /*@{*/
  19. /**
  20. * this function will show registers of CPU
  21. *
  22. * @param regs the registers point
  23. */
  24. void rt_hw_show_register (struct rt_hw_exp_stack *regs)
  25. {
  26. rt_kprintf("Execption:\n");
  27. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  28. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  29. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  30. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  31. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  32. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  33. }
  34. /**
  35. * When comes across an instruction which it cannot handle,
  36. * it takes the undefined instruction trap.
  37. *
  38. * @param regs system registers
  39. *
  40. * @note never invoke this function in application
  41. */
  42. void rt_hw_trap_udef(struct rt_hw_exp_stack *regs)
  43. {
  44. rt_kprintf("undefined instruction\n");
  45. rt_hw_show_register(regs);
  46. if (rt_thread_self() != RT_NULL)
  47. rt_kprintf("Current Thread: %s\n", rt_thread_self()->parent.name);
  48. rt_hw_cpu_shutdown();
  49. }
  50. /**
  51. * The software interrupt instruction (SWI) is used for entering
  52. * Supervisor mode, usually to request a particular supervisor
  53. * function.
  54. *
  55. * @param regs system registers
  56. *
  57. * @note never invoke this function in application
  58. */
  59. void rt_hw_trap_svc(struct rt_hw_exp_stack *regs)
  60. {
  61. rt_kprintf("software interrupt\n");
  62. rt_hw_show_register(regs);
  63. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  64. list_thread();
  65. #endif
  66. rt_hw_cpu_shutdown();
  67. }
  68. /**
  69. * An abort indicates that the current memory access cannot be completed,
  70. * which occurs during an instruction prefetch.
  71. *
  72. * @param regs system registers
  73. *
  74. * @note never invoke this function in application
  75. */
  76. void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
  77. {
  78. rt_kprintf("prefetch abort\n");
  79. rt_hw_show_register(regs);
  80. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  81. list_thread();
  82. #endif
  83. rt_hw_cpu_shutdown();
  84. }
  85. /**
  86. * An abort indicates that the current memory access cannot be completed,
  87. * which occurs during a data access.
  88. *
  89. * @param regs system registers
  90. *
  91. * @note never invoke this function in application
  92. */
  93. void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
  94. {
  95. rt_kprintf("Data Abort ");
  96. rt_hw_show_register(regs);
  97. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  98. list_thread();
  99. #endif
  100. rt_hw_cpu_shutdown();
  101. }
  102. /**
  103. * Normally, system will never reach here
  104. *
  105. * @param regs system registers
  106. *
  107. * @note never invoke this function in application
  108. */
  109. void rt_hw_trap_resv(struct rt_hw_exp_stack *regs)
  110. {
  111. rt_kprintf("Reserved trap\n");
  112. rt_hw_show_register(regs);
  113. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  114. list_thread();
  115. #endif
  116. rt_hw_cpu_shutdown();
  117. }
  118. extern rt_isr_handler_t isr_table[];
  119. void rt_hw_trap_irq(void)
  120. {
  121. int irqno;
  122. struct rt_irq_desc* irq;
  123. extern struct rt_irq_desc irq_desc[];
  124. irq = (struct rt_irq_desc*) vimREG->IRQVECREG;
  125. irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
  126. /* invoke isr */
  127. irq->handler(irqno, irq->param);
  128. }
  129. void rt_hw_trap_fiq(void)
  130. {
  131. rt_kprintf("fast interrupt request\n");
  132. }
  133. /*@}*/