trap.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. /**
  19. * @addtogroup AM33XX
  20. */
  21. /*@{*/
  22. extern struct rt_thread *rt_current_thread;
  23. #ifdef RT_USING_FINSH
  24. extern long list_thread(void);
  25. #endif
  26. /**
  27. * this function will show registers of CPU
  28. *
  29. * @param regs the registers point
  30. */
  31. void rt_hw_show_register (struct rt_hw_register *regs)
  32. {
  33. rt_kprintf("Execption:\n");
  34. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  35. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  36. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  37. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  38. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  39. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  40. }
  41. /**
  42. * When ARM7TDMI comes across an instruction which it cannot handle,
  43. * it takes the undefined instruction trap.
  44. *
  45. * @param regs system registers
  46. *
  47. * @note never invoke this function in application
  48. */
  49. void rt_hw_trap_udef(struct rt_hw_register *regs)
  50. {
  51. rt_hw_show_register(regs);
  52. rt_kprintf("undefined instruction\n");
  53. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  54. #ifdef RT_USING_FINSH
  55. list_thread();
  56. #endif
  57. rt_hw_cpu_shutdown();
  58. }
  59. /**
  60. * The software interrupt instruction (SWI) is used for entering
  61. * Supervisor mode, usually to request a particular supervisor
  62. * function.
  63. *
  64. * @param regs system registers
  65. *
  66. * @note never invoke this function in application
  67. */
  68. void rt_hw_trap_swi(struct rt_hw_register *regs)
  69. {
  70. rt_hw_show_register(regs);
  71. rt_kprintf("software interrupt\n");
  72. rt_hw_cpu_shutdown();
  73. }
  74. /**
  75. * An abort indicates that the current memory access cannot be completed,
  76. * which occurs during an instruction prefetch.
  77. *
  78. * @param regs system registers
  79. *
  80. * @note never invoke this function in application
  81. */
  82. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  83. {
  84. rt_hw_show_register(regs);
  85. rt_kprintf("prefetch abort\n");
  86. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  87. #ifdef RT_USING_FINSH
  88. list_thread();
  89. #endif
  90. rt_hw_cpu_shutdown();
  91. }
  92. /**
  93. * An abort indicates that the current memory access cannot be completed,
  94. * which occurs during a data access.
  95. *
  96. * @param regs system registers
  97. *
  98. * @note never invoke this function in application
  99. */
  100. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  101. {
  102. rt_hw_show_register(regs);
  103. rt_kprintf("data abort\n");
  104. rt_kprintf("thread %.*s stack:\n", RT_NAME_MAX, rt_current_thread->name);
  105. #ifdef RT_USING_FINSH
  106. list_thread();
  107. #endif
  108. rt_hw_cpu_shutdown();
  109. }
  110. void rt_hw_trap_irq()
  111. {
  112. void *param;
  113. unsigned long ir;
  114. rt_isr_handler_t isr_func;
  115. extern struct rt_irq_desc isr_table[];
  116. ir = rt_hw_interrupt_get_active(INT_IRQ);
  117. if (ir == 127)
  118. {
  119. /* new IRQ generation */
  120. rt_hw_interrupt_ack(INT_IRQ);
  121. ir = rt_hw_interrupt_get_active(INT_IRQ);
  122. if (ir == 127)
  123. {
  124. /* still spurious interrupt, get out */
  125. /*rt_kprintf("still spurious interrupt\n");*/
  126. return;
  127. }
  128. /*rt_kprintf("new IRQ: %d\n", ir);*/
  129. }
  130. /* get interrupt service routine */
  131. isr_func = isr_table[ir].handler;
  132. param = isr_table[ir].param;
  133. /* turn to interrupt service routine */
  134. if (isr_func != RT_NULL)
  135. isr_func(ir, param);
  136. /* new IRQ generation */
  137. rt_hw_interrupt_ack(INT_IRQ);
  138. }
  139. void rt_hw_trap_fiq()
  140. {
  141. void *param;
  142. unsigned long ir;
  143. rt_isr_handler_t isr_func;
  144. extern struct rt_irq_desc isr_table[];
  145. ir = rt_hw_interrupt_get_active(INT_FIQ);
  146. /* get interrupt service routine */
  147. isr_func = isr_table[ir].handler;
  148. param = isr_table[ir].param;
  149. /* turn to interrupt service routine */
  150. isr_func(ir, param);
  151. /* new FIQ generation */
  152. rt_hw_interrupt_ack(INT_FIQ);
  153. }
  154. /*@}*/