xref: /nrf52832-nimble/rt-thread/libcpu/arm/s3c24x0/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 "s3c24x0.h"
18 
19 /**
20  * @addtogroup S3C24X0
21  */
22 /*@{*/
23 
24 extern struct rt_thread *rt_current_thread;
25 #ifdef RT_USING_FINSH
26 extern long list_thread(void);
27 #endif
28 
29 /**
30  * this function will show registers of CPU
31  *
32  * @param regs the registers point
33  */
34 
rt_hw_show_register(struct rt_hw_register * regs)35 void rt_hw_show_register (struct rt_hw_register *regs)
36 {
37 	rt_kprintf("Execption:\n");
38 	rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
39 	rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
40 	rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
41 	rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
42 	rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
43 	rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
44 }
45 
46 /**
47  * When ARM7TDMI comes across an instruction which it cannot handle,
48  * it takes the undefined instruction trap.
49  *
50  * @param regs system registers
51  *
52  * @note never invoke this function in application
53  */
rt_hw_trap_udef(struct rt_hw_register * regs)54 void rt_hw_trap_udef(struct rt_hw_register *regs)
55 {
56 	rt_hw_show_register(regs);
57 
58 	rt_kprintf("undefined instruction\n");
59 	rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
60 
61 #ifdef RT_USING_FINSH
62 	list_thread();
63 #endif
64 	rt_hw_cpu_shutdown();
65 }
66 
67 /**
68  * The software interrupt instruction (SWI) is used for entering
69  * Supervisor mode, usually to request a particular supervisor
70  * function.
71  *
72  * @param regs system registers
73  *
74  * @note never invoke this function in application
75  */
rt_hw_trap_swi(struct rt_hw_register * regs)76 void rt_hw_trap_swi(struct rt_hw_register *regs)
77 {
78 	rt_hw_show_register(regs);
79 
80 	rt_kprintf("software interrupt\n");
81 	rt_hw_cpu_shutdown();
82 }
83 
84 /**
85  * An abort indicates that the current memory access cannot be completed,
86  * which occurs during an instruction prefetch.
87  *
88  * @param regs system registers
89  *
90  * @note never invoke this function in application
91  */
rt_hw_trap_pabt(struct rt_hw_register * regs)92 void rt_hw_trap_pabt(struct rt_hw_register *regs)
93 {
94 	rt_hw_show_register(regs);
95 
96 	rt_kprintf("prefetch abort\n");
97 	rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
98 
99 #ifdef RT_USING_FINSH
100 	list_thread();
101 #endif
102 	rt_hw_cpu_shutdown();
103 }
104 
105 /**
106  * An abort indicates that the current memory access cannot be completed,
107  * which occurs during a data access.
108  *
109  * @param regs system registers
110  *
111  * @note never invoke this function in application
112  */
rt_hw_trap_dabt(struct rt_hw_register * regs)113 void rt_hw_trap_dabt(struct rt_hw_register *regs)
114 {
115 	rt_hw_show_register(regs);
116 
117 	rt_kprintf("data abort\n");
118 	rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
119 
120 #ifdef RT_USING_FINSH
121 	list_thread();
122 #endif
123 	rt_hw_cpu_shutdown();
124 }
125 
126 /**
127  * Normally, system will never reach here
128  *
129  * @param regs system registers
130  *
131  * @note never invoke this function in application
132  */
rt_hw_trap_resv(struct rt_hw_register * regs)133 void rt_hw_trap_resv(struct rt_hw_register *regs)
134 {
135 	rt_kprintf("not used\n");
136 	rt_hw_show_register(regs);
137 	rt_hw_cpu_shutdown();
138 }
139 
140 extern struct rt_irq_desc isr_table[];
141 
rt_hw_trap_irq(void)142 void rt_hw_trap_irq(void)
143 {
144     unsigned long irq;
145     rt_isr_handler_t isr_func;
146     void *param;
147 
148     irq = INTOFFSET;
149 
150     if (irq == INTGLOBAL) return;
151 
152     /* get interrupt service routine */
153     isr_func = isr_table[irq].handler;
154     param = isr_table[irq].param;
155 
156     /* turn to interrupt service routine */
157     isr_func(irq, param);
158 
159     /* clear pending register */
160     /* note: must be the last, if not, may repeat*/
161     ClearPending(1 << irq);
162 
163 #ifdef RT_USING_INTERRUPT_INFO
164 	isr_table[irq].counter++;
165 #endif /* RT_USING_INTERRUPT_INFO */
166 }
167 
rt_hw_trap_fiq(void)168 void rt_hw_trap_fiq(void)
169 {
170 	rt_kprintf("fast interrupt request\n");
171 }
172 
173 /*@}*/
174