trap.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #include <rthw.h>
  27. #include <armv6.h>
  28. #include "fh_arch.h"
  29. #include "interrupt.h"
  30. #include "libraries/inc/fh_ictl.h"
  31. /**
  32. * @addtogroup FH81
  33. */
  34. /*@{*/
  35. extern struct rt_thread *rt_current_thread;
  36. #ifdef RT_USING_FINSH
  37. extern long list_thread(void);
  38. #endif
  39. /**
  40. * this function will show registers of CPU
  41. *
  42. * @param regs the registers point
  43. */
  44. void rt_hw_show_register (struct rt_hw_register *regs)
  45. {
  46. rt_kprintf("Execption:\n");
  47. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  48. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  49. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  50. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  51. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  52. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  53. }
  54. /**
  55. * When ARM7TDMI comes across an instruction which it cannot handle,
  56. * it takes the undefined instruction trap.
  57. *
  58. * @param regs system registers
  59. *
  60. * @note never invoke this function in application
  61. */
  62. void rt_hw_trap_udef(struct rt_hw_register *regs)
  63. {
  64. rt_hw_show_register(regs);
  65. rt_kprintf("undefined instruction\n");
  66. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  67. #ifdef RT_USING_FINSH
  68. list_thread();
  69. #endif
  70. rt_hw_cpu_shutdown();
  71. }
  72. /**
  73. * The software interrupt instruction (SWI) is used for entering
  74. * Supervisor mode, usually to request a particular supervisor
  75. * function.
  76. *
  77. * @param regs system registers
  78. *
  79. * @note never invoke this function in application
  80. */
  81. void rt_hw_trap_swi(struct rt_hw_register *regs)
  82. {
  83. rt_hw_show_register(regs);
  84. rt_kprintf("software interrupt\n");
  85. rt_hw_cpu_shutdown();
  86. }
  87. /**
  88. * An abort indicates that the current memory access cannot be completed,
  89. * which occurs during an instruction prefetch.
  90. *
  91. * @param regs system registers
  92. *
  93. * @note never invoke this function in application
  94. */
  95. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  96. {
  97. rt_hw_show_register(regs);
  98. rt_kprintf("prefetch abort\n");
  99. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  100. #ifdef RT_USING_FINSH
  101. list_thread();
  102. #endif
  103. rt_hw_cpu_shutdown();
  104. }
  105. /**
  106. * An abort indicates that the current memory access cannot be completed,
  107. * which occurs during a data access.
  108. *
  109. * @param regs system registers
  110. *
  111. * @note never invoke this function in application
  112. */
  113. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  114. {
  115. rt_hw_show_register(regs);
  116. rt_kprintf("data abort\n");
  117. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  118. #ifdef RT_USING_FINSH
  119. list_thread();
  120. #endif
  121. rt_hw_cpu_shutdown();
  122. }
  123. /**
  124. * Normally, system will never reach here
  125. *
  126. * @param regs system registers
  127. *
  128. * @note never invoke this function in application
  129. */
  130. void rt_hw_trap_resv(struct rt_hw_register *regs)
  131. {
  132. rt_kprintf("not used\n");
  133. rt_hw_show_register(regs);
  134. rt_hw_cpu_shutdown();
  135. }
  136. extern struct rt_irq_desc irq_desc[];
  137. void rt_hw_trap_irq()
  138. {
  139. rt_isr_handler_t isr_func;
  140. rt_uint32_t irqstat_l, irqstat_h, irq;
  141. void *param;
  142. fh_intc *p = (fh_intc *)INTC_REG_BASE;
  143. irqstat_l = p->IRQ_FINALSTATUS_L;
  144. irqstat_h = p->IRQ_FINALSTATUS_H;
  145. if (irqstat_l)
  146. {
  147. irq = __rt_ffs(irqstat_l) - 1;
  148. }
  149. else if(irqstat_h)
  150. {
  151. irq = __rt_ffs(irqstat_h) - 1 + 32;
  152. }
  153. else
  154. {
  155. rt_kprintf("No interrupt occur\n");
  156. return;
  157. }
  158. /* get interrupt service routine */
  159. isr_func = irq_desc[irq].handler;
  160. param = irq_desc[irq].param;
  161. /* turn to interrupt service routine */
  162. if(isr_func){
  163. isr_func(irq, param);
  164. }
  165. #ifdef RT_USING_INTERRUPT_INFO
  166. irq_desc[irq].counter ++;
  167. #endif
  168. }
  169. void rt_hw_trap_fiq()
  170. {
  171. rt_kprintf("fast interrupt request\n");
  172. }
  173. /*@}*/