1
0

trap.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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-09-06 XuXinming first version
  13. * 2006-09-15 Bernard modify rt_hw_trap_irq for more effective
  14. */
  15. #include <rtthread.h>
  16. #include <rthw.h>
  17. #include "s3c44b0.h"
  18. extern unsigned char interrupt_bank0[256];
  19. extern unsigned char interrupt_bank1[256];
  20. extern unsigned char interrupt_bank2[256];
  21. extern unsigned char interrupt_bank3[256];
  22. extern struct rt_thread *rt_current_thread;
  23. /**
  24. * @addtogroup S3C44B0
  25. */
  26. /*@{*/
  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_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_kprintf("software interrupt\n");
  68. rt_hw_show_register(regs);
  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_hw_cpu_shutdown();
  84. }
  85. /**
  86. * An abort indicates that the current memory access cannot be completed,
  87. * which occurs during a data access.
  88. *
  89. * @param regs system registers
  90. *
  91. * @note never invoke this function in application
  92. */
  93. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  94. {
  95. rt_hw_show_register(regs);
  96. rt_kprintf("data abort\n");
  97. rt_hw_cpu_shutdown();
  98. }
  99. /**
  100. * Normally, system will never reach here
  101. *
  102. * @param regs system registers
  103. *
  104. * @note never invoke this function in application
  105. */
  106. void rt_hw_trap_resv(struct rt_hw_register *regs)
  107. {
  108. rt_kprintf("not used\n");
  109. rt_hw_show_register(regs);
  110. rt_hw_cpu_shutdown();
  111. }
  112. extern rt_isr_handler_t isr_table[];
  113. void rt_hw_trap_irq()
  114. {
  115. register unsigned long ispr, intstat;
  116. register rt_isr_handler_t isr_func;
  117. #ifdef BSP_INT_DEBUG
  118. rt_kprintf("irq coming, ");
  119. #endif
  120. intstat = I_ISPR & 0x7ffffff;
  121. #ifdef BSP_INT_DEBUG
  122. rt_kprintf("I_ISPR: %d\n", intstat);
  123. #endif
  124. ispr = intstat;
  125. /* to find interrupt */
  126. if ( intstat & 0xff ) /* lowest 8bits */
  127. {
  128. intstat = interrupt_bank0[intstat & 0xff];
  129. isr_func = (rt_isr_handler_t)isr_table[ intstat ];
  130. }
  131. else if ( intstat & 0xff00 ) /* low 8bits */
  132. {
  133. intstat = interrupt_bank1[(intstat & 0xff00) >> 8];
  134. isr_func = (rt_isr_handler_t)isr_table[ intstat ];
  135. }
  136. else if ( intstat & 0xff0000 ) /* high 8bits */
  137. {
  138. intstat = interrupt_bank2[(intstat & 0xff0000) >> 16];
  139. isr_func = (rt_isr_handler_t)isr_table[ intstat ];
  140. }
  141. else if ( intstat & 0xff000000 ) /* highest 8bits */
  142. {
  143. intstat = interrupt_bank3[(intstat & 0xff000000) >> 24];
  144. isr_func = (rt_isr_handler_t)isr_table[ intstat ];
  145. }
  146. else return;
  147. #ifdef BSP_INT_DEBUG
  148. rt_kprintf("irq: %d happen\n", intstat);
  149. #endif
  150. /* turn to interrupt service routine */
  151. isr_func(intstat);
  152. I_ISPC = ispr; /* clear interrupt */
  153. }
  154. void rt_hw_trap_fiq()
  155. {
  156. rt_kprintf("fast interrupt request\n");
  157. }
  158. /*@}*/