trap.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. * 2010-11-13 weety first version
  23. */
  24. #include <rtthread.h>
  25. #include <rthw.h>
  26. #include "dm36x.h"
  27. /**
  28. * @addtogroup DM36X
  29. */
  30. /*@{*/
  31. extern struct rt_thread *rt_current_thread;
  32. #ifdef RT_USING_FINSH
  33. extern long list_thread(void);
  34. #endif
  35. /**
  36. * this function will show registers of CPU
  37. *
  38. * @param regs the registers point
  39. */
  40. void rt_hw_show_register (struct rt_hw_register *regs)
  41. {
  42. rt_kprintf("Execption:\n");
  43. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  44. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  45. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  46. rt_kprintf("fp :0x%08x ip :0x%08x\n", 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("cpsr:0x%08x\n", regs->cpsr);
  49. }
  50. /**
  51. * When ARM7TDMI comes across an instruction which it cannot handle,
  52. * it takes the undefined instruction trap.
  53. *
  54. * @param regs system registers
  55. *
  56. * @note never invoke this function in application
  57. */
  58. void rt_hw_trap_udef(struct rt_hw_register *regs)
  59. {
  60. rt_hw_show_register(regs);
  61. rt_kprintf("undefined instruction\n");
  62. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  63. #ifdef RT_USING_FINSH
  64. list_thread();
  65. #endif
  66. rt_hw_cpu_shutdown();
  67. }
  68. /**
  69. * The software interrupt instruction (SWI) is used for entering
  70. * Supervisor mode, usually to request a particular supervisor
  71. * function.
  72. *
  73. * @param regs system registers
  74. *
  75. * @note never invoke this function in application
  76. */
  77. void rt_hw_trap_swi(struct rt_hw_register *regs)
  78. {
  79. rt_hw_show_register(regs);
  80. rt_kprintf("software interrupt\n");
  81. rt_hw_cpu_shutdown();
  82. }
  83. /**
  84. * An abort indicates that the current memory access cannot be completed,
  85. * which occurs during an instruction prefetch.
  86. *
  87. * @param regs system registers
  88. *
  89. * @note never invoke this function in application
  90. */
  91. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  92. {
  93. rt_hw_show_register(regs);
  94. rt_kprintf("prefetch abort\n");
  95. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  96. #ifdef RT_USING_FINSH
  97. list_thread();
  98. #endif
  99. rt_hw_cpu_shutdown();
  100. }
  101. /**
  102. * An abort indicates that the current memory access cannot be completed,
  103. * which occurs during a data access.
  104. *
  105. * @param regs system registers
  106. *
  107. * @note never invoke this function in application
  108. */
  109. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  110. {
  111. rt_uint32_t fault_addr;
  112. rt_uint32_t fault_status;
  113. asm volatile ("mrc p15, 0, %0, c6, c0, 0"
  114. :
  115. :"r"(fault_addr)
  116. :"cc");
  117. rt_kprintf("unhandler access to 0x%08x\n", fault_addr);
  118. /* read DFSR */
  119. asm volatile ("MRC p15, 0, %0, c5, c0, 0"
  120. :
  121. :"r"(fault_status)
  122. :"cc");
  123. rt_kprintf("fault status 0x%08x\n", fault_status);
  124. rt_hw_show_register(regs);
  125. rt_kprintf("data abort\n");
  126. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  127. #ifdef RT_USING_FINSH
  128. list_thread();
  129. #endif
  130. rt_hw_cpu_shutdown();
  131. }
  132. /**
  133. * Normally, system will never reach here
  134. *
  135. * @param regs system registers
  136. *
  137. * @note never invoke this function in application
  138. */
  139. void rt_hw_trap_resv(struct rt_hw_register *regs)
  140. {
  141. rt_kprintf("not used\n");
  142. rt_hw_show_register(regs);
  143. rt_hw_cpu_shutdown();
  144. }
  145. extern struct rt_irq_desc irq_desc[];
  146. void rt_hw_trap_irq()
  147. {
  148. rt_isr_handler_t isr_func;
  149. rt_uint32_t val, irq, mask;
  150. void *param;
  151. /* get irq number */
  152. val = readl(DAVINCI_ARM_INTC_BASE+0x14) - readl(DAVINCI_ARM_INTC_BASE+0x24);
  153. irq = (val >> 2) - 1;
  154. /* clear pending register */
  155. mask = 1 << (irq & 0x1f);
  156. if (irq > 31)
  157. writel(mask, DAVINCI_ARM_INTC_BASE+0x0c); //IRQ1
  158. else
  159. writel(mask, DAVINCI_ARM_INTC_BASE+0x08); //IRQ0
  160. /* get interrupt service routine */
  161. isr_func = irq_desc[irq].handler;
  162. param = irq_desc[irq].param;
  163. /* turn to interrupt service routine */
  164. isr_func(irq, param);
  165. irq_desc[irq].counter++;
  166. }
  167. void rt_hw_trap_fiq()
  168. {
  169. rt_kprintf("fast interrupt request\n");
  170. }
  171. /*@}*/