trap.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-01-13 weety modified from mini2440
  9. * 2015-04-15 ArdaFu Split from AT91SAM9260 BSP
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #define INT_IRQ 0x00
  14. #define INT_FIQ 0x01
  15. extern struct rt_thread *rt_current_thread;
  16. #ifdef RT_USING_FINSH
  17. extern long list_thread(void);
  18. #endif
  19. struct rt_hw_register
  20. {
  21. rt_uint32_t r0;
  22. rt_uint32_t r1;
  23. rt_uint32_t r2;
  24. rt_uint32_t r3;
  25. rt_uint32_t r4;
  26. rt_uint32_t r5;
  27. rt_uint32_t r6;
  28. rt_uint32_t r7;
  29. rt_uint32_t r8;
  30. rt_uint32_t r9;
  31. rt_uint32_t r10;
  32. rt_uint32_t fp;
  33. rt_uint32_t ip;
  34. rt_uint32_t sp;
  35. rt_uint32_t lr;
  36. rt_uint32_t pc;
  37. rt_uint32_t cpsr;
  38. rt_uint32_t ORIG_r0;
  39. };
  40. /**
  41. * this function will show registers of CPU
  42. *
  43. * @param regs the registers point
  44. */
  45. void rt_hw_show_register (struct rt_hw_register *regs)
  46. {
  47. rt_kprintf("Execption:\n");
  48. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n",
  49. regs->r0, regs->r1, regs->r2, regs->r3);
  50. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n",
  51. regs->r4, regs->r5, regs->r6, regs->r7);
  52. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n",
  53. regs->r8, regs->r9, regs->r10);
  54. rt_kprintf("fp :0x%08x ip :0x%08x\n",
  55. regs->fp, regs->ip);
  56. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n",
  57. regs->sp, regs->lr, regs->pc);
  58. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  59. }
  60. /**
  61. * When ARM7TDMI comes across an instruction which it cannot handle,
  62. * it takes the undefined instruction trap.
  63. *
  64. * @param regs system registers
  65. *
  66. * @note never invoke this function in application
  67. */
  68. void rt_hw_trap_udef(struct rt_hw_register *regs)
  69. {
  70. rt_hw_show_register(regs);
  71. rt_kprintf("undefined instruction\n");
  72. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  73. #ifdef RT_USING_FINSH
  74. list_thread();
  75. #endif
  76. rt_hw_cpu_shutdown();
  77. }
  78. /**
  79. * The software interrupt instruction (SWI) is used for entering
  80. * Supervisor mode, usually to request a particular supervisor
  81. * function.
  82. *
  83. * @param regs system registers
  84. *
  85. * @note never invoke this function in application
  86. */
  87. void rt_hw_trap_swi(struct rt_hw_register *regs)
  88. {
  89. rt_hw_show_register(regs);
  90. rt_kprintf("software interrupt\n");
  91. rt_hw_cpu_shutdown();
  92. }
  93. /**
  94. * An abort indicates that the current memory access cannot be completed,
  95. * which occurs during an instruction prefetch.
  96. *
  97. * @param regs system registers
  98. *
  99. * @note never invoke this function in application
  100. */
  101. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  102. {
  103. rt_hw_show_register(regs);
  104. rt_kprintf("prefetch abort\n");
  105. rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  106. #ifdef RT_USING_FINSH
  107. list_thread();
  108. #endif
  109. rt_hw_cpu_shutdown();
  110. }
  111. /**
  112. * An abort indicates that the current memory access cannot be completed,
  113. * which occurs during a data access.
  114. *
  115. * @param regs system registers
  116. *
  117. * @note never invoke this function in application
  118. */
  119. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  120. {
  121. rt_hw_show_register(regs);
  122. rt_kprintf("data abort\n");
  123. rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  124. #ifdef RT_USING_FINSH
  125. list_thread();
  126. #endif
  127. rt_hw_cpu_shutdown();
  128. }
  129. /**
  130. * Normally, system will never reach here
  131. *
  132. * @param regs system registers
  133. *
  134. * @note never invoke this function in application
  135. */
  136. void rt_hw_trap_resv(struct rt_hw_register *regs)
  137. {
  138. rt_kprintf("not used\n");
  139. rt_hw_show_register(regs);
  140. rt_hw_cpu_shutdown();
  141. }
  142. extern struct rt_irq_desc irq_desc[];
  143. extern rt_uint32_t rt_hw_interrupt_get_active(rt_uint32_t fiq_irq);
  144. extern void rt_hw_interrupt_ack(rt_uint32_t fiq_irq, rt_uint32_t id);
  145. void rt_hw_trap_irq()
  146. {
  147. rt_isr_handler_t isr_func;
  148. rt_uint32_t irq;
  149. void *param;
  150. /* get irq number */
  151. irq = rt_hw_interrupt_get_active(INT_IRQ);
  152. /* get interrupt service routine */
  153. isr_func = irq_desc[irq].handler;
  154. param = irq_desc[irq].param;
  155. /* turn to interrupt service routine */
  156. isr_func(irq, param);
  157. rt_hw_interrupt_ack(INT_IRQ, irq);
  158. #ifdef RT_USING_INTERRUPT_INFO
  159. irq_desc[irq].counter ++;
  160. #endif
  161. }
  162. void rt_hw_trap_fiq()
  163. {
  164. rt_isr_handler_t isr_func;
  165. rt_uint32_t irq;
  166. void *param;
  167. /* get irq number */
  168. irq = rt_hw_interrupt_get_active(INT_FIQ);
  169. /* get interrupt service routine */
  170. isr_func = irq_desc[irq].handler;
  171. param = irq_desc[irq].param;
  172. /* turn to interrupt service routine */
  173. isr_func(irq, param);
  174. rt_hw_interrupt_ack(INT_FIQ, irq);
  175. #ifdef RT_USING_INTERRUPT_INFO
  176. irq_desc[irq].counter ++;
  177. #endif
  178. }