trap.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-09-23 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "am33xx.h"
  17. #include "interrupt.h"
  18. #ifdef RT_USING_GDB
  19. #include "gdb_stub.h"
  20. #endif
  21. /**
  22. * @addtogroup AM33XX
  23. */
  24. /*@{*/
  25. extern struct rt_thread *rt_current_thread;
  26. #ifdef RT_USING_FINSH
  27. extern long list_thread(void);
  28. #endif
  29. /**
  30. * this function will show registers of CPU
  31. *
  32. * @param regs the registers point
  33. */
  34. void rt_hw_show_register (struct rt_hw_register *regs)
  35. {
  36. rt_kprintf("Execption:\n");
  37. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  38. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  39. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  40. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  41. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  42. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  43. }
  44. /**
  45. * When ARM7TDMI comes across an instruction which it cannot handle,
  46. * it takes the undefined instruction trap.
  47. *
  48. * @param regs system registers
  49. *
  50. * @note never invoke this function in application
  51. */
  52. void rt_hw_trap_udef(struct rt_hw_register *regs)
  53. {
  54. #ifdef RT_USING_GDB
  55. regs->pc -= 4; //lr in undef is pc + 4
  56. if (gdb_undef_hook(regs))
  57. return;
  58. #endif
  59. rt_hw_show_register(regs);
  60. rt_kprintf("undefined instruction\n");
  61. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  62. #ifdef RT_USING_FINSH
  63. list_thread();
  64. #endif
  65. rt_hw_cpu_shutdown();
  66. }
  67. /**
  68. * The software interrupt instruction (SWI) is used for entering
  69. * Supervisor mode, usually to request a particular supervisor
  70. * function.
  71. *
  72. * @param regs system registers
  73. *
  74. * @note never invoke this function in application
  75. */
  76. void rt_hw_trap_swi(struct rt_hw_register *regs)
  77. {
  78. rt_hw_show_register(regs);
  79. rt_kprintf("software interrupt\n");
  80. rt_hw_cpu_shutdown();
  81. }
  82. /**
  83. * An abort indicates that the current memory access cannot be completed,
  84. * which occurs during an instruction prefetch.
  85. *
  86. * @param regs system registers
  87. *
  88. * @note never invoke this function in application
  89. */
  90. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  91. {
  92. rt_hw_show_register(regs);
  93. rt_kprintf("prefetch abort\n");
  94. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  95. #ifdef RT_USING_FINSH
  96. list_thread();
  97. #endif
  98. rt_hw_cpu_shutdown();
  99. }
  100. /**
  101. * An abort indicates that the current memory access cannot be completed,
  102. * which occurs during a data access.
  103. *
  104. * @param regs system registers
  105. *
  106. * @note never invoke this function in application
  107. */
  108. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  109. {
  110. #ifdef RT_USING_GDB
  111. if (gdb_mem_fault_handler) {
  112. regs->pc = (unsigned long)gdb_mem_fault_handler;
  113. return;
  114. }
  115. #endif
  116. rt_hw_show_register(regs);
  117. rt_kprintf("data abort\n");
  118. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  119. #ifdef RT_USING_FINSH
  120. list_thread();
  121. #endif
  122. rt_hw_cpu_shutdown();
  123. }
  124. void rt_hw_trap_irq()
  125. {
  126. void *param;
  127. unsigned long ir;
  128. rt_isr_handler_t isr_func;
  129. extern struct rt_irq_desc isr_table[];
  130. ir = rt_hw_interrupt_get_active(INT_IRQ);
  131. if (ir == 127)
  132. {
  133. /* new IRQ generation */
  134. rt_hw_interrupt_ack(INT_IRQ);
  135. ir = rt_hw_interrupt_get_active(INT_IRQ);
  136. if (ir == 127)
  137. {
  138. /* still spurious interrupt, get out */
  139. /*rt_kprintf("still spurious interrupt\n");*/
  140. return;
  141. }
  142. /*rt_kprintf("new IRQ: %d\n", ir);*/
  143. }
  144. /* get interrupt service routine */
  145. isr_func = isr_table[ir].handler;
  146. param = isr_table[ir].param;
  147. /* turn to interrupt service routine */
  148. if (isr_func != RT_NULL)
  149. isr_func(ir, param);
  150. /* new IRQ generation */
  151. rt_hw_interrupt_ack(INT_IRQ);
  152. }
  153. void rt_hw_trap_fiq()
  154. {
  155. void *param;
  156. unsigned long ir;
  157. rt_isr_handler_t isr_func;
  158. extern struct rt_irq_desc isr_table[];
  159. ir = rt_hw_interrupt_get_active(INT_FIQ);
  160. /* get interrupt service routine */
  161. isr_func = isr_table[ir].handler;
  162. param = isr_table[ir].param;
  163. /* turn to interrupt service routine */
  164. isr_func(ir, param);
  165. /* new FIQ generation */
  166. rt_hw_interrupt_ack(INT_FIQ);
  167. }
  168. /*@}*/