trap.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. */
  23. #include <rtthread.h>
  24. #include <rthw.h>
  25. #include "gk7101.h"
  26. #include <gtypes.h>
  27. #include <gd_int.h>
  28. #include "rtos_lib.h"
  29. extern struct rt_thread *rt_current_thread;
  30. #ifdef RT_USING_FINSH
  31. extern long list_thread(void);
  32. #endif
  33. /**
  34. * this function will show registers of CPU
  35. *
  36. * @param regs the registers point
  37. */
  38. /* FIXME(Heyong): add for print the system infos when sys abort */
  39. static void _rtt_statistics()
  40. {
  41. rt_uint32_t total;
  42. rt_uint32_t used;
  43. rt_uint32_t max_used;
  44. struct rt_thread *thread;
  45. struct rt_list_node *node;
  46. rt_uint8_t *ptr;
  47. rt_base_t level;
  48. struct rt_object_information *information;
  49. information = rt_object_get_information(RT_Object_Class_Thread);
  50. RT_ASSERT(information != RT_NULL);
  51. struct rt_list_node *list = &(information->object_list);
  52. level = rt_hw_interrupt_disable();
  53. for (node = list->next; node != list; node = node->next)
  54. {
  55. thread = rt_list_entry(node, struct rt_thread, list);
  56. //if(thread) thread->total_tick = 0;
  57. }
  58. rt_hw_interrupt_enable(level);
  59. rt_memory_info(&total,&used,&max_used);
  60. rt_kprintf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  61. rt_kprintf("\n memory info size \n");
  62. rt_kprintf("------------------------- ------\n");
  63. rt_kprintf("total memory: (%dKB)\n", total/1024);
  64. rt_kprintf("used memory : (%dKB)\n", used/1024);
  65. rt_kprintf("maximum allocated memory: (%dKB)\n\n", max_used/1024);
  66. rt_kprintf(" thread pri status sp stack addr stack size max used \n");
  67. rt_kprintf("-------------------------------- --- ------- ---------- ---------- ---------- ---------- \n");
  68. for (node = list->next; node != list; node = node->next)
  69. {
  70. thread = rt_list_entry(node, struct rt_thread, list);
  71. #if 0
  72. rt_kprintf("%-32.*s 0x%02x", RT_NAME_MAX, thread->name, thread->current_priority);
  73. #else
  74. int priority = thread->current_priority;
  75. rt_kprintf("%-32.*s %03d", RT_NAME_MAX, thread->name, priority);
  76. #endif
  77. if (thread->stat == RT_THREAD_READY) rt_kprintf(" ready ");
  78. else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
  79. else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init ");
  80. else if (thread->stat == RT_THREAD_CLOSE) rt_kprintf(" close ");
  81. ptr = (rt_uint8_t*)thread->stack_addr;
  82. while (*ptr == '#')ptr++;
  83. rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x \n",
  84. thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
  85. thread->stack_addr,
  86. thread->stack_size,
  87. thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr)
  88. );
  89. }
  90. rt_kprintf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  91. }
  92. // FIXME(heyong): add for debug when sys abort.
  93. int g_eth_input = 0;
  94. int g_eth_output = 0;
  95. int g_wifi_input = 0;
  96. int g_wifi_output = 0;
  97. void rt_hw_show_register (struct rt_hw_register *regs)
  98. {
  99. rt_kprintf("Execption:\n");
  100. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  101. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  102. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  103. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  104. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  105. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  106. rt_kprintf("eth info : in = %d out = %d\n", g_eth_input, g_eth_output);
  107. rt_kprintf("wifi info: in = %d out = %d\n", g_wifi_input, g_wifi_output);
  108. _rtt_statistics();
  109. }
  110. /**
  111. * When ARM7TDMI comes across an instruction which it cannot handle,
  112. * it takes the undefined instruction trap.
  113. *
  114. * @param regs system registers
  115. *
  116. * @note never invoke this function in application
  117. */
  118. void rt_hw_trap_udef(struct rt_hw_register *regs)
  119. {
  120. rt_hw_show_register(regs);
  121. rt_kprintf("undefined instruction\n");
  122. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  123. #ifdef RT_USING_FINSH
  124. list_thread();
  125. #endif
  126. rt_hw_cpu_shutdown();
  127. }
  128. /**
  129. * The software interrupt instruction (SWI) is used for entering
  130. * Supervisor mode, usually to request a particular supervisor
  131. * function.
  132. *
  133. * @param regs system registers
  134. *
  135. * @note never invoke this function in application
  136. */
  137. void rt_hw_trap_swi(struct rt_hw_register *regs)
  138. {
  139. rt_hw_show_register(regs);
  140. rt_kprintf("software interrupt\n");
  141. rt_hw_cpu_shutdown();
  142. }
  143. /**
  144. * An abort indicates that the current memory access cannot be completed,
  145. * which occurs during an instruction prefetch.
  146. *
  147. * @param regs system registers
  148. *
  149. * @note never invoke this function in application
  150. */
  151. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  152. {
  153. rt_hw_show_register(regs);
  154. rt_kprintf("prefetch abort\n");
  155. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  156. #ifdef RT_USING_FINSH
  157. list_thread();
  158. #endif
  159. rt_hw_cpu_shutdown();
  160. }
  161. /**
  162. * An abort indicates that the current memory access cannot be completed,
  163. * which occurs during a data access.
  164. *
  165. * @param regs system registers
  166. *
  167. * @note never invoke this function in application
  168. */
  169. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  170. {
  171. rt_kprintf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  172. rt_kprintf("data abort\n");
  173. rt_kprintf("thread - [%s] stack:\n", rt_current_thread->name);
  174. rt_hw_show_register(regs);
  175. #ifdef RT_USING_FINSH
  176. list_thread();
  177. #endif
  178. rt_hw_cpu_shutdown();
  179. }
  180. /**
  181. * Normally, system will never reach here
  182. *
  183. * @param regs system registers
  184. *
  185. * @note never invoke this function in application
  186. */
  187. void rt_hw_trap_resv(struct rt_hw_register *regs)
  188. {
  189. rt_kprintf("not used\n");
  190. rt_hw_show_register(regs);
  191. rt_hw_cpu_shutdown();
  192. }
  193. extern struct rt_irq_desc irq_desc[];
  194. void rt_hw_trap_irq()
  195. {
  196. int index;
  197. //rt_kprintf("irq interrupt request\n");
  198. GD_IRQ_ISR();
  199. if(gkosHookData)
  200. {
  201. for( index=0; index < gkosHookData->timerFunctionCount; index++ )
  202. {
  203. if( gkosHookData->timerFunctionArray[index] )
  204. {
  205. (*gkosHookData->timerFunctionArray[index])(NULL);
  206. }
  207. }
  208. }
  209. }
  210. void rt_hw_trap_fiq()
  211. {
  212. //rt_kprintf("fast interrupt request\n");
  213. GD_FIQ_ISR();
  214. //rt_tick_increase();
  215. }
  216. /*@}*/