1
0

trap.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. * 2013-07-20 Bernard first version
  9. */
  10. #include <rthw.h>
  11. #include <board.h>
  12. #include <rtthread.h>
  13. #include "armv7.h"
  14. extern struct rt_thread *rt_current_thread;
  15. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  16. extern long list_thread(void);
  17. #endif
  18. /**
  19. * this function will show registers of CPU
  20. *
  21. * @param regs the registers point
  22. */
  23. void rt_hw_show_register(struct rt_hw_exp_stack *regs)
  24. {
  25. rt_kprintf("Execption:\n");
  26. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  27. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  28. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  29. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  30. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  31. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  32. }
  33. /**
  34. * When comes across an instruction which it cannot handle,
  35. * it takes the undefined instruction trap.
  36. *
  37. * @param regs system registers
  38. *
  39. * @note never invoke this function in application
  40. */
  41. void rt_hw_trap_undef(struct rt_hw_exp_stack *regs)
  42. {
  43. rt_kprintf("undefined instruction:\n");
  44. rt_hw_show_register(regs);
  45. #if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
  46. list_thread();
  47. #endif
  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_swi(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. void rt_hw_trap_irq(void)
  119. {
  120. void *param;
  121. rt_isr_handler_t isr_func;
  122. extern struct rt_irq_desc isr_table[];
  123. uint32_t value = 0;
  124. // rt_kprintf("pend basic: 0x%08x\n", IRQ_PEND_BASIC);
  125. // rt_kprintf(" pend1: 0x%08x\n", IRQ_PEND1);
  126. // rt_kprintf(" pend2: 0x%08x\n", IRQ_PEND2);
  127. value = IRQ_PEND_BASIC & 0x3ff;
  128. if (value)
  129. {
  130. uint32_t irq;
  131. if (value & (1 << 8))
  132. {
  133. value = IRQ_PEND1;
  134. irq = __rt_ffs(value) - 1;
  135. }
  136. else if (value & (1 << 9))
  137. {
  138. value = IRQ_PEND2;
  139. irq = __rt_ffs(value) + 31;
  140. }
  141. else
  142. {
  143. value &= 0x0f;
  144. irq = __rt_ffs(value) - 1;
  145. }
  146. /* get interrupt service routine */
  147. isr_func = isr_table[irq].handler;
  148. #ifdef RT_USING_INTERRUPT_INFO
  149. isr_table[irq].counter++;
  150. #endif
  151. if (isr_func)
  152. {
  153. /* Interrupt for myself. */
  154. param = isr_table[irq].param;
  155. /* turn to interrupt service routine */
  156. isr_func(irq, param);
  157. }
  158. }
  159. }
  160. void rt_hw_trap_fiq(void)
  161. {
  162. /* TODO */
  163. }