xref: /nrf52832-nimble/rt-thread/libcpu/arm/sep4020/trap.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2006-03-13     Bernard      first version
9  * 2006-05-27     Bernard      add skyeye support
10  * 2007-11-19     Yi.Qiu       fix rt_hw_trap_irq function
11  * 2013-03-29     aozima       Modify the interrupt interface implementations.
12  */
13 
14 #include <rtthread.h>
15 #include <rthw.h>
16 
17 #include <sep4020.h>
18 
19 /**
20  * @addtogroup S3C24X0
21  */
22 /*@{*/
23 
24 extern struct rt_thread *rt_current_thread;
25 
26 /**
27  * this function will show registers of CPU
28  *
29  * @param regs the registers point
30  */
31 
rt_hw_show_register(struct rt_hw_register * regs)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 /**
44  * When ARM7TDMI comes across an instruction which it cannot handle,
45  * it takes the undefined instruction trap.
46  *
47  * @param regs system registers
48  *
49  * @note never invoke this function in application
50  */
rt_hw_trap_udef(struct rt_hw_register * regs)51 void rt_hw_trap_udef(struct rt_hw_register *regs)
52 {
53 	rt_hw_show_register(regs);
54 
55 	rt_kprintf("undefined instruction\n");
56 	rt_kprintf("thread - %s stack:\n", rt_current_thread->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->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->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 final intrrupt source*/
141     intstat = *(RP)(INTC_IFSR);;
142 
143     /*Shift to get the intrrupt number*/
144     while(intstat != 1)
145     {
146         intstat = intstat >> 1;
147         irq++;
148     }
149 
150     /* get interrupt service routine */
151     isr_func = isr_table[irq].handler;
152     param = isr_table[irq].param;
153 
154     /* turn to interrupt service routine */
155     isr_func(irq, param);
156 
157 #ifdef RT_USING_INTERRUPT_INFO
158 	isr_table[irq].counter++;
159 #endif /* RT_USING_INTERRUPT_INFO */
160 }
161 
rt_hw_trap_fiq(void)162 void rt_hw_trap_fiq(void)
163 {
164 	rt_kprintf("fast interrupt request\n");
165 }
166 
167 /*@}*/
168