xref: /nrf52832-nimble/rt-thread/libcpu/arm/cortex-r4/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  * 2008-12-11     XuXinming    first version
9  * 2013-05-24     Grissiom     port to RM48x50
10  */
11 
12 #include <rtthread.h>
13 #include <rthw.h>
14 
15 #include <sys_vim.h>
16 
17 #include "armv7.h"
18 
19 /**
20  * @addtogroup RM48x50
21  */
22 /*@{*/
23 
24 /**
25  * this function will show registers of CPU
26  *
27  * @param regs the registers point
28  */
rt_hw_show_register(struct rt_hw_exp_stack * regs)29 void rt_hw_show_register (struct rt_hw_exp_stack *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\n", regs->r8, regs->r9, regs->r10);
35 	rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
36 	rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
37 	rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
38 }
39 
40 /**
41  * When comes across an instruction which it cannot handle,
42  * it takes the undefined instruction trap.
43  *
44  * @param regs system registers
45  *
46  * @note never invoke this function in application
47  */
rt_hw_trap_udef(struct rt_hw_exp_stack * regs)48 void rt_hw_trap_udef(struct rt_hw_exp_stack *regs)
49 {
50     rt_kprintf("undefined instruction\n");
51     rt_hw_show_register(regs);
52 	if (rt_thread_self() != RT_NULL)
53 		rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
54     rt_hw_cpu_shutdown();
55 }
56 
57 /**
58  * The software interrupt instruction (SWI) is used for entering
59  * Supervisor mode, usually to request a particular supervisor
60  * function.
61  *
62  * @param regs system registers
63  *
64  * @note never invoke this function in application
65  */
rt_hw_trap_svc(struct rt_hw_exp_stack * regs)66 void rt_hw_trap_svc(struct rt_hw_exp_stack *regs)
67 {
68     rt_kprintf("software interrupt\n");
69     rt_hw_show_register(regs);
70 #ifdef RT_USING_FINSH
71 	list_thread();
72 #endif
73     rt_hw_cpu_shutdown();
74 }
75 
76 /**
77  * An abort indicates that the current memory access cannot be completed,
78  * which occurs during an instruction prefetch.
79  *
80  * @param regs system registers
81  *
82  * @note never invoke this function in application
83  */
rt_hw_trap_pabt(struct rt_hw_exp_stack * regs)84 void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
85 {
86     rt_kprintf("prefetch abort\n");
87     rt_hw_show_register(regs);
88 #ifdef RT_USING_FINSH
89 	list_thread();
90 #endif
91     rt_hw_cpu_shutdown();
92 }
93 
94 /**
95  * An abort indicates that the current memory access cannot be completed,
96  * which occurs during a data access.
97  *
98  * @param regs system registers
99  *
100  * @note never invoke this function in application
101  */
rt_hw_trap_dabt(struct rt_hw_exp_stack * regs)102 void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
103 {
104     rt_kprintf("Data Abort ");
105     rt_hw_show_register(regs);
106 #ifdef RT_USING_FINSH
107 	list_thread();
108 #endif
109     rt_hw_cpu_shutdown();
110 }
111 
112 /**
113  * Normally, system will never reach here
114  *
115  * @param regs system registers
116  *
117  * @note never invoke this function in application
118  */
rt_hw_trap_resv(struct rt_hw_exp_stack * regs)119 void rt_hw_trap_resv(struct rt_hw_exp_stack *regs)
120 {
121     rt_kprintf("Reserved trap\n");
122     rt_hw_show_register(regs);
123 #ifdef RT_USING_FINSH
124 	list_thread();
125 #endif
126     rt_hw_cpu_shutdown();
127 }
128 
129 extern rt_isr_handler_t isr_table[];
rt_hw_trap_irq(void)130 void rt_hw_trap_irq(void)
131 {
132 	int irqno;
133 	struct rt_irq_desc* irq;
134 	extern struct rt_irq_desc irq_desc[];
135 
136 	irq = (struct rt_irq_desc*) vimREG->IRQVECREG;
137 	irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
138 
139 	/* invoke isr */
140 	irq->handler(irqno, irq->param);
141 }
142 
rt_hw_trap_fiq(void)143 void rt_hw_trap_fiq(void)
144 {
145     rt_kprintf("fast interrupt request\n");
146 }
147 
148 /*@}*/
149