1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2013-03-16 Peng Fan Modifiled from sep4020
9 */
10
11 #include <rtthread.h>
12 #include <rthw.h>
13
14 #include <sep6200.h>
15
16 /**
17 * @addtogroup sep6200
18 */
19 /*@{*/
20
21 extern struct rt_thread *rt_current_thread;
22
23 /**
24 * this function will show registers of CPU
25 *
26 * @param regs the registers point
27 */
28
rt_hw_show_register(struct rt_hw_register * regs)29 void rt_hw_show_register (struct rt_hw_register *regs)
30 {
31 rt_kprintf("Execption:\n");
32 rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
33 rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
34 rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x r11:0x%08x\n", regs->r8, regs->r9, regs->r10,regs->r11);
35 rt_kprintf("r12:0x%08x r13:0x%08x r14:0x%08x r15:0x%08x\n", regs->r12,regs->r13,regs->r14,regs->r15);
36 rt_kprintf("r16:0x%08x r17:0x%08x r18:0x%08x r19:0x%08x\n", regs->r16,regs->r17,regs->r18,regs->r19);
37 rt_kprintf("r20:0x%08x r21:0x%08x r22:0x%08x r23:0x%08x\n", regs->r20,regs->r21,regs->r22,regs->r23);
38 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);
39 rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
40 rt_kprintf("asr:0x%08x bsr:0x%08x\n", regs->asr,regs->bsr);
41 }
42
43 /**
44 * When unicore comes across an instruction which it cannot handle,
45 * it takes the extn instruction trap.
46 *
47 * @param regs system registers
48 *
49 * @note never invoke this function in application
50 */
rt_hw_trap_extn(struct rt_hw_register * regs)51 void rt_hw_trap_extn(struct rt_hw_register *regs)
52 {
53 rt_hw_show_register(regs);
54
55 rt_kprintf("extn instruction\n");
56 rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);
57 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
58
59 rt_hw_cpu_shutdown();
60 }
61
62 /**
63 * The software interrupt instruction (SWI) is used for entering
64 * Supervisor mode, usually to request a particular supervisor
65 * function.
66 *
67 * @param regs system registers
68 *
69 * @note never invoke this function in application
70 */
rt_hw_trap_swi(struct rt_hw_register * regs)71 void rt_hw_trap_swi(struct rt_hw_register *regs)
72 {
73 rt_hw_show_register(regs);
74
75 rt_kprintf("software interrupt\n");
76 rt_hw_cpu_shutdown();
77 }
78
79 /**
80 * An abort indicates that the current memory access cannot be completed,
81 * which occurs during an instruction prefetch.
82 *
83 * @param regs system registers
84 *
85 * @note never invoke this function in application
86 */
rt_hw_trap_pabt(struct rt_hw_register * regs)87 void rt_hw_trap_pabt(struct rt_hw_register *regs)
88 {
89 rt_hw_show_register(regs);
90
91 rt_kprintf("prefetch abort\n");
92 rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);
93 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
94
95 rt_hw_cpu_shutdown();
96 }
97
98 /**
99 * An abort indicates that the current memory access cannot be completed,
100 * which occurs during a data access.
101 *
102 * @param regs system registers
103 *
104 * @note never invoke this function in application
105 */
rt_hw_trap_dabt(struct rt_hw_register * regs)106 void rt_hw_trap_dabt(struct rt_hw_register *regs)
107 {
108 rt_hw_show_register(regs);
109
110 rt_kprintf("data abort\n");
111 rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);
112 rt_hw_backtrace((rt_uint32_t *)regs->fp, (rt_uint32_t)rt_current_thread->entry);
113
114 rt_hw_cpu_shutdown();
115 }
116
117 /**
118 * Normally, system will never reach here
119 *
120 * @param regs system registers
121 *
122 * @note never invoke this function in application
123 */
rt_hw_trap_resv(struct rt_hw_register * regs)124 void rt_hw_trap_resv(struct rt_hw_register *regs)
125 {
126 rt_kprintf("not used\n");
127 rt_hw_show_register(regs);
128 rt_hw_cpu_shutdown();
129 }
130
131 extern struct rt_irq_desc isr_table[];
132
rt_hw_trap_irq(void)133 void rt_hw_trap_irq(void)
134 {
135 unsigned long intstat;
136 rt_uint32_t irq = 0;
137 rt_isr_handler_t isr_func;
138 void *param;
139
140 /* get the interrupt number */
141 irq = *(RP)(SEP6200_VIC_IRQ_VECTOR_NUM);
142
143 /* get interrupt service routine */
144 isr_func = isr_table[irq].handler;
145 param = isr_table[irq].param;
146
147 /* turn to interrupt service routine */
148 isr_func(irq, param);
149
150 #ifdef RT_USING_INTERRUPT_INFO
151 isr_table[irq].counter++;
152 #endif /* RT_USING_INTERRUPT_INFO */
153 }
154
rt_hw_trap_fiq()155 void rt_hw_trap_fiq()
156 {
157 rt_kprintf("fast interrupt request\n");
158 }
159
160 /*@}*/
161