trap.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * 2008-12-11 XuXinming first version
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "LPC24xx.h"
  17. //#define BSP_INT_DEBUG
  18. /**
  19. * @addtogroup LPC2478
  20. */
  21. /*@{*/
  22. /**
  23. * this function will show registers of CPU
  24. *
  25. * @param regs the registers point
  26. */
  27. void rt_hw_show_register (struct rt_hw_register *regs)
  28. {
  29. rt_kprintf("Execption:\n");
  30. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  31. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  32. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  33. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  34. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  35. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  36. }
  37. /**
  38. * When ARM7TDMI comes across an instruction which it cannot handle,
  39. * it takes the undefined instruction trap.
  40. *
  41. * @param regs system registers
  42. *
  43. * @note never invoke this function in application
  44. */
  45. void rt_hw_trap_udef(struct rt_hw_register *regs)
  46. {
  47. rt_kprintf("undefined instruction\n");
  48. rt_hw_show_register(regs);
  49. if (rt_thread_self() != RT_NULL)
  50. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  51. rt_hw_cpu_shutdown();
  52. }
  53. /**
  54. * The software interrupt instruction (SWI) is used for entering
  55. * Supervisor mode, usually to request a particular supervisor
  56. * function.
  57. *
  58. * @param regs system registers
  59. *
  60. * @note never invoke this function in application
  61. */
  62. void rt_hw_trap_swi(struct rt_hw_register *regs)
  63. {
  64. rt_kprintf("software interrupt\n");
  65. rt_hw_show_register(regs);
  66. if (rt_thread_self() != RT_NULL)
  67. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  68. rt_hw_cpu_shutdown();
  69. }
  70. /**
  71. * An abort indicates that the current memory access cannot be completed,
  72. * which occurs during an instruction prefetch.
  73. *
  74. * @param regs system registers
  75. *
  76. * @note never invoke this function in application
  77. */
  78. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  79. {
  80. rt_kprintf("prefetch abort\n");
  81. rt_hw_show_register(regs);
  82. if (rt_thread_self() != RT_NULL)
  83. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  84. rt_hw_cpu_shutdown();
  85. }
  86. /**
  87. * An abort indicates that the current memory access cannot be completed,
  88. * which occurs during a data access.
  89. *
  90. * @param regs system registers
  91. *
  92. * @note never invoke this function in application
  93. */
  94. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  95. {
  96. rt_kprintf("Data Abort ");
  97. rt_hw_show_register(regs);
  98. if (rt_thread_self() != RT_NULL)
  99. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  100. rt_hw_cpu_shutdown();
  101. }
  102. /**
  103. * Normally, system will never reach here
  104. *
  105. * @param regs system registers
  106. *
  107. * @note never invoke this function in application
  108. */
  109. void rt_hw_trap_resv(struct rt_hw_register *regs)
  110. {
  111. rt_kprintf("not used\n");
  112. rt_hw_show_register(regs);
  113. if (rt_thread_self() != RT_NULL)
  114. rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
  115. rt_hw_cpu_shutdown();
  116. }
  117. extern rt_isr_handler_t isr_table[];
  118. void rt_hw_trap_irq(void)
  119. {
  120. int irqno;
  121. struct rt_irq_desc* irq;
  122. extern struct rt_irq_desc irq_desc[];
  123. irq = (struct rt_irq_desc*) VICVectAddr;
  124. irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
  125. /* invoke isr */
  126. irq->handler(irqno, irq->param);
  127. }
  128. void rt_hw_trap_fiq(void)
  129. {
  130. rt_kprintf("fast interrupt request\n");
  131. }
  132. /*@}*/