trap.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2013-03-16 Peng Fan Modifiled from sep4020
  23. */
  24. #include <rtthread.h>
  25. #include <rthw.h>
  26. #include <sep6200.h>
  27. /**
  28. * @addtogroup sep6200
  29. */
  30. /*@{*/
  31. extern struct rt_thread *rt_current_thread;
  32. /**
  33. * this function will show registers of CPU
  34. *
  35. * @param regs the registers point
  36. */
  37. void rt_hw_show_register (struct rt_hw_register *regs)
  38. {
  39. rt_kprintf("Execption:\n");
  40. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  41. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  42. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x r11:0x%08x\n", regs->r8, regs->r9, regs->r10,regs->r11);
  43. rt_kprintf("r12:0x%08x r13:0x%08x r14:0x%08x r15:0x%08x\n", regs->r12,regs->r13,regs->r14,regs->r15);
  44. rt_kprintf("r16:0x%08x r17:0x%08x r18:0x%08x r19:0x%08x\n", regs->r16,regs->r17,regs->r18,regs->r19);
  45. rt_kprintf("r20:0x%08x r21:0x%08x r22:0x%08x r23:0x%08x\n", regs->r20,regs->r21,regs->r22,regs->r23);
  46. rt_kprintf("r24:0x%08x sb:0x%08x sl:0x%08xfp :0x%08x ip :0x%08x\n",regs->r24,regs->sb,regs->sl,regs->fp,regs->ip);
  47. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  48. rt_kprintf("asr:0x%08x bsr:0x%08x\n", regs->asr,regs->bsr);
  49. }
  50. /**
  51. * When unicore comes across an instruction which it cannot handle,
  52. * it takes the extn instruction trap.
  53. *
  54. * @param regs system registers
  55. *
  56. * @note never invoke this function in application
  57. */
  58. void rt_hw_trap_extn(struct rt_hw_register *regs)
  59. {
  60. rt_hw_show_register(regs);
  61. rt_kprintf("extn instruction\n");
  62. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  63. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  64. rt_hw_cpu_shutdown();
  65. }
  66. /**
  67. * The software interrupt instruction (SWI) is used for entering
  68. * Supervisor mode, usually to request a particular supervisor
  69. * function.
  70. *
  71. * @param regs system registers
  72. *
  73. * @note never invoke this function in application
  74. */
  75. void rt_hw_trap_swi(struct rt_hw_register *regs)
  76. {
  77. rt_hw_show_register(regs);
  78. rt_kprintf("software interrupt\n");
  79. rt_hw_cpu_shutdown();
  80. }
  81. /**
  82. * An abort indicates that the current memory access cannot be completed,
  83. * which occurs during an instruction prefetch.
  84. *
  85. * @param regs system registers
  86. *
  87. * @note never invoke this function in application
  88. */
  89. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  90. {
  91. rt_hw_show_register(regs);
  92. rt_kprintf("prefetch abort\n");
  93. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  94. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  95. rt_hw_cpu_shutdown();
  96. }
  97. /**
  98. * An abort indicates that the current memory access cannot be completed,
  99. * which occurs during a data access.
  100. *
  101. * @param regs system registers
  102. *
  103. * @note never invoke this function in application
  104. */
  105. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  106. {
  107. rt_hw_show_register(regs);
  108. rt_kprintf("data abort\n");
  109. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  110. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  111. rt_hw_cpu_shutdown();
  112. }
  113. /**
  114. * Normally, system will never reach here
  115. *
  116. * @param regs system registers
  117. *
  118. * @note never invoke this function in application
  119. */
  120. void rt_hw_trap_resv(struct rt_hw_register *regs)
  121. {
  122. rt_kprintf("not used\n");
  123. rt_hw_show_register(regs);
  124. rt_hw_cpu_shutdown();
  125. }
  126. extern struct rt_irq_desc isr_table[];
  127. void rt_hw_trap_irq(void)
  128. {
  129. unsigned long intstat;
  130. rt_uint32_t irq = 0;
  131. rt_isr_handler_t isr_func;
  132. void *param;
  133. /* get the interrupt number */
  134. irq = *(RP)(SEP6200_VIC_IRQ_VECTOR_NUM);
  135. /* get interrupt service routine */
  136. isr_func = isr_table[irq].handler;
  137. param = isr_table[irq].param;
  138. /* turn to interrupt service routine */
  139. isr_func(irq, param);
  140. #ifdef RT_USING_INTERRUPT_INFO
  141. isr_table[irq].counter++;
  142. #endif /* RT_USING_INTERRUPT_INFO */
  143. }
  144. void rt_hw_trap_fiq()
  145. {
  146. rt_kprintf("fast interrupt request\n");
  147. }
  148. /*@}*/