trap.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 <sep4020.h>
  20. /**
  21. * @addtogroup S3C24X0
  22. */
  23. /*@{*/
  24. extern struct rt_thread *rt_current_thread;
  25. /**
  26. * this function will show registers of CPU
  27. *
  28. * @param regs the registers point
  29. */
  30. void rt_hw_show_register (struct rt_hw_register *regs)
  31. {
  32. rt_kprintf("Execption:\n");
  33. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  34. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  35. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  36. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  37. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  38. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  39. }
  40. /**
  41. * When ARM7TDMI comes across an instruction which it cannot handle,
  42. * it takes the undefined instruction trap.
  43. *
  44. * @param regs system registers
  45. *
  46. * @note never invoke this function in application
  47. */
  48. void rt_hw_trap_udef(struct rt_hw_register *regs)
  49. {
  50. rt_hw_show_register(regs);
  51. rt_kprintf("undefined instruction\n");
  52. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  53. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  54. rt_hw_cpu_shutdown();
  55. }
  56. /**
  57. * The software interrupt instruction (SWI) is used for entering
  58. * Supervisor mode, usually to request a particular supervisor
  59. * function.
  60. *
  61. * @param regs system registers
  62. *
  63. * @note never invoke this function in application
  64. */
  65. void rt_hw_trap_swi(struct rt_hw_register *regs)
  66. {
  67. rt_hw_show_register(regs);
  68. rt_kprintf("software interrupt\n");
  69. rt_hw_cpu_shutdown();
  70. }
  71. /**
  72. * An abort indicates that the current memory access cannot be completed,
  73. * which occurs during an instruction prefetch.
  74. *
  75. * @param regs system registers
  76. *
  77. * @note never invoke this function in application
  78. */
  79. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  80. {
  81. rt_hw_show_register(regs);
  82. rt_kprintf("prefetch abort\n");
  83. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  84. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  85. rt_hw_cpu_shutdown();
  86. }
  87. /**
  88. * An abort indicates that the current memory access cannot be completed,
  89. * which occurs during a data access.
  90. *
  91. * @param regs system registers
  92. *
  93. * @note never invoke this function in application
  94. */
  95. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  96. {
  97. rt_hw_show_register(regs);
  98. rt_kprintf("data abort\n");
  99. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  100. rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
  101. rt_hw_cpu_shutdown();
  102. }
  103. /**
  104. * Normally, system will never reach here
  105. *
  106. * @param regs system registers
  107. *
  108. * @note never invoke this function in application
  109. */
  110. void rt_hw_trap_resv(struct rt_hw_register *regs)
  111. {
  112. rt_kprintf("not used\n");
  113. rt_hw_show_register(regs);
  114. rt_hw_cpu_shutdown();
  115. }
  116. extern struct rt_irq_desc isr_table[];
  117. void rt_hw_trap_irq(void)
  118. {
  119. unsigned long intstat;
  120. rt_uint32_t irq = 0;
  121. rt_isr_handler_t isr_func;
  122. void *param;
  123. /*Get the final intrrupt source*/
  124. intstat = *(RP)(INTC_IFSR);;
  125. /*Shift to get the intrrupt number*/
  126. while(intstat != 1)
  127. {
  128. intstat = intstat >> 1;
  129. irq++;
  130. }
  131. /* get interrupt service routine */
  132. isr_func = isr_table[irq].handler;
  133. param = isr_table[irq].param;
  134. /* turn to interrupt service routine */
  135. isr_func(irq, param);
  136. #ifdef RT_USING_INTERRUPT_INFO
  137. isr_table[irq].counter++;
  138. #endif /* RT_USING_INTERRUPT_INFO */
  139. }
  140. void rt_hw_trap_fiq(void)
  141. {
  142. rt_kprintf("fast interrupt request\n");
  143. }
  144. /*@}*/