1 /* 2 * File : trap.c 3 * This file is part of RT-Thread RTOS 4 * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Change Logs: 21 * Date Author Notes 22 * 2013-03-16 Peng Fan Modifiled from sep4020 23 */ 24 25 #include <rtthread.h> 26 #include <rthw.h> 27 28 #include <sep6200.h> 29 30 /** 31 * @addtogroup sep6200 32 */ 33 /*@{*/ 34 35 extern struct rt_thread *rt_current_thread; 36 37 /** 38 * this function will show registers of CPU 39 * 40 * @param regs the registers point 41 */ 42 43 void rt_hw_show_register (struct rt_hw_register *regs) 44 { 45 rt_kprintf("Execption:\n"); 46 rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3); 47 rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7); 48 rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x r11:0x%08x\n", regs->r8, regs->r9, regs->r10,regs->r11); 49 rt_kprintf("r12:0x%08x r13:0x%08x r14:0x%08x r15:0x%08x\n", regs->r12,regs->r13,regs->r14,regs->r15); 50 rt_kprintf("r16:0x%08x r17:0x%08x r18:0x%08x r19:0x%08x\n", regs->r16,regs->r17,regs->r18,regs->r19); 51 rt_kprintf("r20:0x%08x r21:0x%08x r22:0x%08x r23:0x%08x\n", regs->r20,regs->r21,regs->r22,regs->r23); 52 rt_kprintf("r24:0x%08x sb:0x%08x sl:0x%08xfp :0x%08x ip :0x%08x\n",regs->r24,regs->sb,regs->sl,regs->fp,regs->ip); 53 rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc); 54 rt_kprintf("asr:0x%08x bsr:0x%08x\n", regs->asr,regs->bsr); 55 } 56 57 /** 58 * When unicore comes across an instruction which it cannot handle, 59 * it takes the extn instruction trap. 60 * 61 * @param regs system registers 62 * 63 * @note never invoke this function in application 64 */ 65 void rt_hw_trap_extn(struct rt_hw_register *regs) 66 { 67 rt_hw_show_register(regs); 68 69 rt_kprintf("extn instruction\n"); 70 rt_kprintf("thread - %s stack:\n", rt_current_thread->name); 71 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry); 72 73 rt_hw_cpu_shutdown(); 74 } 75 76 /** 77 * The software interrupt instruction (SWI) is used for entering 78 * Supervisor mode, usually to request a particular supervisor 79 * function. 80 * 81 * @param regs system registers 82 * 83 * @note never invoke this function in application 84 */ 85 void rt_hw_trap_swi(struct rt_hw_register *regs) 86 { 87 rt_hw_show_register(regs); 88 89 rt_kprintf("software interrupt\n"); 90 rt_hw_cpu_shutdown(); 91 } 92 93 /** 94 * An abort indicates that the current memory access cannot be completed, 95 * which occurs during an instruction prefetch. 96 * 97 * @param regs system registers 98 * 99 * @note never invoke this function in application 100 */ 101 void rt_hw_trap_pabt(struct rt_hw_register *regs) 102 { 103 rt_hw_show_register(regs); 104 105 rt_kprintf("prefetch abort\n"); 106 rt_kprintf("thread - %s stack:\n", rt_current_thread->name); 107 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry); 108 109 rt_hw_cpu_shutdown(); 110 } 111 112 /** 113 * An abort indicates that the current memory access cannot be completed, 114 * which occurs during a data access. 115 * 116 * @param regs system registers 117 * 118 * @note never invoke this function in application 119 */ 120 void rt_hw_trap_dabt(struct rt_hw_register *regs) 121 { 122 rt_hw_show_register(regs); 123 124 rt_kprintf("data abort\n"); 125 rt_kprintf("thread - %s stack:\n", rt_current_thread->name); 126 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry); 127 128 rt_hw_cpu_shutdown(); 129 } 130 131 /** 132 * Normally, system will never reach here 133 * 134 * @param regs system registers 135 * 136 * @note never invoke this function in application 137 */ 138 void rt_hw_trap_resv(struct rt_hw_register *regs) 139 { 140 rt_kprintf("not used\n"); 141 rt_hw_show_register(regs); 142 rt_hw_cpu_shutdown(); 143 } 144 145 extern struct rt_irq_desc isr_table[]; 146 147 void rt_hw_trap_irq(void) 148 { 149 unsigned long intstat; 150 rt_uint32_t irq = 0; 151 rt_isr_handler_t isr_func; 152 void *param; 153 154 /* get the interrupt number */ 155 irq = *(RP)(SEP6200_VIC_IRQ_VECTOR_NUM); 156 157 /* get interrupt service routine */ 158 isr_func = isr_table[irq].handler; 159 param = isr_table[irq].param; 160 161 /* turn to interrupt service routine */ 162 isr_func(irq, param); 163 164 #ifdef RT_USING_INTERRUPT_INFO 165 isr_table[irq].counter++; 166 #endif /* RT_USING_INTERRUPT_INFO */ 167 } 168 169 void rt_hw_trap_fiq() 170 { 171 rt_kprintf("fast interrupt request\n"); 172 } 173 174 /*@}*/ 175