trap.c 3.8 KB

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