trap.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * 2006-03-13 Bernard first version
  13. * 2006-05-27 Bernard add skyeye support
  14. * 2007-11-19 Yi.Qiu fix rt_hw_trap_irq function
  15. * 2013-03-29 aozima Modify the interrupt interface implementations.
  16. */
  17. #include <rtthread.h>
  18. #include <rthw.h>
  19. #include "s3c24x0.h"
  20. /**
  21. * @addtogroup S3C24X0
  22. */
  23. /*@{*/
  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_register *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 ARM7TDMI 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_udef(struct rt_hw_register *regs)
  52. {
  53. rt_hw_show_register(regs);
  54. rt_kprintf("undefined instruction\n");
  55. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  56. #ifdef RT_USING_FINSH
  57. list_thread();
  58. #endif
  59. rt_hw_cpu_shutdown();
  60. }
  61. /**
  62. * The software interrupt instruction (SWI) is used for entering
  63. * Supervisor mode, usually to request a particular supervisor
  64. * function.
  65. *
  66. * @param regs system registers
  67. *
  68. * @note never invoke this function in application
  69. */
  70. void rt_hw_trap_swi(struct rt_hw_register *regs)
  71. {
  72. rt_hw_show_register(regs);
  73. rt_kprintf("software interrupt\n");
  74. rt_hw_cpu_shutdown();
  75. }
  76. /**
  77. * An abort indicates that the current memory access cannot be completed,
  78. * which occurs during an instruction prefetch.
  79. *
  80. * @param regs system registers
  81. *
  82. * @note never invoke this function in application
  83. */
  84. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  85. {
  86. rt_hw_show_register(regs);
  87. rt_kprintf("prefetch abort\n");
  88. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  89. #ifdef RT_USING_FINSH
  90. list_thread();
  91. #endif
  92. rt_hw_cpu_shutdown();
  93. }
  94. /**
  95. * An abort indicates that the current memory access cannot be completed,
  96. * which occurs during a data access.
  97. *
  98. * @param regs system registers
  99. *
  100. * @note never invoke this function in application
  101. */
  102. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  103. {
  104. rt_hw_show_register(regs);
  105. rt_kprintf("data abort\n");
  106. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  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_register *regs)
  120. {
  121. rt_kprintf("not used\n");
  122. rt_hw_show_register(regs);
  123. rt_hw_cpu_shutdown();
  124. }
  125. extern struct rt_irq_desc isr_table[];
  126. void rt_hw_trap_irq(void)
  127. {
  128. unsigned long irq;
  129. rt_isr_handler_t isr_func;
  130. void *param;
  131. irq = INTOFFSET;
  132. if (irq == INTGLOBAL) return;
  133. /* get interrupt service routine */
  134. isr_func = isr_table[irq].handler;
  135. param = isr_table[irq].param;
  136. /* turn to interrupt service routine */
  137. isr_func(irq, param);
  138. /* clear pending register */
  139. /* note: must be the last, if not, may repeat*/
  140. ClearPending(1 << irq);
  141. #ifdef RT_USING_INTERRUPT_INFO
  142. isr_table[irq].counter++;
  143. #endif /* RT_USING_INTERRUPT_INFO */
  144. }
  145. void rt_hw_trap_fiq(void)
  146. {
  147. rt_kprintf("fast interrupt request\n");
  148. }
  149. /*@}*/