1
0

trap.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * COPYRIGHT (C) 2013-2014, Shanghai Real-Thread Technology Co., Ltd
  3. *
  4. * All rights reserved.
  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. #include <rtthread.h>
  21. #include <rthw.h>
  22. #include "zynq7000.h"
  23. #include "gic.h"
  24. extern struct rt_thread *rt_current_thread;
  25. #ifdef RT_USING_FINSH
  26. extern long list_thread(void);
  27. #endif
  28. /**
  29. * this function will show registers of CPU
  30. *
  31. * @param regs the registers point
  32. */
  33. void rt_hw_show_register (struct rt_hw_exp_stack *regs)
  34. {
  35. rt_kprintf("Execption:\n");
  36. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  37. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  38. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  39. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  40. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  41. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  42. }
  43. /**
  44. * When comes across an instruction which it cannot handle,
  45. * it takes the undefined instruction trap.
  46. *
  47. * @param regs system registers
  48. *
  49. * @note never invoke this function in application
  50. */
  51. void rt_hw_trap_undef(struct rt_hw_exp_stack *regs)
  52. {
  53. rt_kprintf("undefined instruction:\n");
  54. rt_hw_show_register(regs);
  55. #ifdef RT_USING_FINSH
  56. list_thread();
  57. #endif
  58. rt_hw_cpu_shutdown();
  59. }
  60. /**
  61. * The software interrupt instruction (SWI) is used for entering
  62. * Supervisor mode, usually to request a particular supervisor
  63. * function.
  64. *
  65. * @param regs system registers
  66. *
  67. * @note never invoke this function in application
  68. */
  69. void rt_hw_trap_swi(struct rt_hw_exp_stack *regs)
  70. {
  71. rt_kprintf("software interrupt:\n");
  72. rt_hw_show_register(regs);
  73. #ifdef RT_USING_FINSH
  74. list_thread();
  75. #endif
  76. rt_hw_cpu_shutdown();
  77. }
  78. /**
  79. * An abort indicates that the current memory access cannot be completed,
  80. * which occurs during an instruction prefetch.
  81. *
  82. * @param regs system registers
  83. *
  84. * @note never invoke this function in application
  85. */
  86. void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
  87. {
  88. rt_kprintf("prefetch abort:\n");
  89. rt_hw_show_register(regs);
  90. #ifdef RT_USING_FINSH
  91. list_thread();
  92. #endif
  93. rt_hw_cpu_shutdown();
  94. }
  95. /**
  96. * An abort indicates that the current memory access cannot be completed,
  97. * which occurs during a data access.
  98. *
  99. * @param regs system registers
  100. *
  101. * @note never invoke this function in application
  102. */
  103. void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
  104. {
  105. rt_kprintf("data abort:");
  106. rt_hw_show_register(regs);
  107. #ifdef RT_USING_FINSH
  108. list_thread();
  109. #endif
  110. rt_hw_cpu_shutdown();
  111. }
  112. /**
  113. * Normally, system will never reach here
  114. *
  115. * @param regs system registers
  116. *
  117. * @note never invoke this function in application
  118. */
  119. void rt_hw_trap_resv(struct rt_hw_exp_stack *regs)
  120. {
  121. rt_kprintf("reserved trap:\n");
  122. rt_hw_show_register(regs);
  123. #ifdef RT_USING_FINSH
  124. list_thread();
  125. #endif
  126. rt_hw_cpu_shutdown();
  127. }
  128. #define GIC_ACK_INTID_MASK 0x000003ff
  129. void rt_hw_trap_irq()
  130. {
  131. void *param;
  132. unsigned long ir;
  133. unsigned long fullir;
  134. rt_isr_handler_t isr_func;
  135. extern struct rt_irq_desc isr_table[];
  136. fullir = arm_gic_get_active_irq(0);
  137. ir = fullir & GIC_ACK_INTID_MASK;
  138. /* get interrupt service routine */
  139. isr_func = isr_table[ir].handler;
  140. if (isr_func)
  141. {
  142. param = isr_table[ir].param;
  143. /* turn to interrupt service routine */
  144. isr_func(ir, param);
  145. }
  146. /* end of interrupt */
  147. arm_gic_ack(0, fullir);
  148. }
  149. void rt_hw_trap_fiq()
  150. {
  151. void *param;
  152. unsigned long ir;
  153. unsigned long fullir;
  154. rt_isr_handler_t isr_func;
  155. extern struct rt_irq_desc isr_table[];
  156. fullir = arm_gic_get_active_irq(0);
  157. ir = fullir & GIC_ACK_INTID_MASK;
  158. /* get interrupt service routine */
  159. isr_func = isr_table[ir].handler;
  160. param = isr_table[ir].param;
  161. /* turn to interrupt service routine */
  162. isr_func(ir, param);
  163. /* end of interrupt */
  164. arm_gic_ack(0, fullir);
  165. }