trap.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2008-12-11 XuXinming first version
  13. * 2013-05-24 Grissiom port to RM48x50
  14. */
  15. #include <rtthread.h>
  16. #include <rthw.h>
  17. #include <sys_vim.h>
  18. #include "armv7.h"
  19. /**
  20. * @addtogroup RM48x50
  21. */
  22. /*@{*/
  23. /**
  24. * this function will show registers of CPU
  25. *
  26. * @param regs the registers point
  27. */
  28. void rt_hw_show_register (struct rt_hw_exp_stack *regs)
  29. {
  30. rt_kprintf("Execption:\n");
  31. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  32. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  33. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  34. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  35. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  36. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  37. }
  38. /**
  39. * When comes across an instruction which it cannot handle,
  40. * it takes the undefined instruction trap.
  41. *
  42. * @param regs system registers
  43. *
  44. * @note never invoke this function in application
  45. */
  46. void rt_hw_trap_udef(struct rt_hw_exp_stack *regs)
  47. {
  48. rt_kprintf("undefined instruction\n");
  49. rt_hw_show_register(regs);
  50. if (rt_thread_self() != RT_NULL)
  51. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  52. rt_hw_cpu_shutdown();
  53. }
  54. /**
  55. * The software interrupt instruction (SWI) is used for entering
  56. * Supervisor mode, usually to request a particular supervisor
  57. * function.
  58. *
  59. * @param regs system registers
  60. *
  61. * @note never invoke this function in application
  62. */
  63. void rt_hw_trap_svc(struct rt_hw_exp_stack *regs)
  64. {
  65. rt_kprintf("software interrupt\n");
  66. rt_hw_show_register(regs);
  67. #ifdef RT_USING_FINSH
  68. list_thread();
  69. #endif
  70. rt_hw_cpu_shutdown();
  71. }
  72. /**
  73. * An abort indicates that the current memory access cannot be completed,
  74. * which occurs during an instruction prefetch.
  75. *
  76. * @param regs system registers
  77. *
  78. * @note never invoke this function in application
  79. */
  80. void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
  81. {
  82. rt_kprintf("prefetch abort\n");
  83. rt_hw_show_register(regs);
  84. #ifdef RT_USING_FINSH
  85. list_thread();
  86. #endif
  87. rt_hw_cpu_shutdown();
  88. }
  89. /**
  90. * An abort indicates that the current memory access cannot be completed,
  91. * which occurs during a data access.
  92. *
  93. * @param regs system registers
  94. *
  95. * @note never invoke this function in application
  96. */
  97. void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
  98. {
  99. rt_kprintf("Data Abort ");
  100. rt_hw_show_register(regs);
  101. #ifdef RT_USING_FINSH
  102. list_thread();
  103. #endif
  104. rt_hw_cpu_shutdown();
  105. }
  106. /**
  107. * Normally, system will never reach here
  108. *
  109. * @param regs system registers
  110. *
  111. * @note never invoke this function in application
  112. */
  113. void rt_hw_trap_resv(struct rt_hw_exp_stack *regs)
  114. {
  115. rt_kprintf("Reserved trap\n");
  116. rt_hw_show_register(regs);
  117. #ifdef RT_USING_FINSH
  118. list_thread();
  119. #endif
  120. rt_hw_cpu_shutdown();
  121. }
  122. extern rt_isr_handler_t isr_table[];
  123. void rt_hw_trap_irq(void)
  124. {
  125. int irqno;
  126. struct rt_irq_desc* irq;
  127. extern struct rt_irq_desc irq_desc[];
  128. irq = (struct rt_irq_desc*) vimREG->IRQVECREG;
  129. irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
  130. /* invoke isr */
  131. irq->handler(irqno, irq->param);
  132. }
  133. void rt_hw_trap_fiq(void)
  134. {
  135. rt_kprintf("fast interrupt request\n");
  136. }
  137. /*@}*/