@@ -35,6 +35,18 @@ void rt_hw_show_register(struct rt_hw_exp_stack *regs)
3535 rt_kprintf ("cpsr:0x%08x\n" , regs -> cpsr );
3636}
3737
38+ void (* rt_trap_hook )(struct rt_hw_exp_stack * regs , const char * ex , unsigned int exception_type );
39+
40+ /**
41+ * This function will set a hook function to trap handler.
42+ *
43+ * @param hook the hook function
44+ */
45+ void rt_hw_trap_set_hook (void (* hook )(struct rt_hw_exp_stack * regs , const char * ex , unsigned int exception_type ))
46+ {
47+ rt_trap_hook = hook ;
48+ }
49+
3850/**
3951 * When comes across an instruction which it cannot handle,
4052 * it takes the undefined instruction trap.
@@ -72,12 +84,20 @@ void rt_hw_trap_undef(struct rt_hw_exp_stack *regs)
7284 }
7385 }
7486#endif
75- rt_kprintf ("undefined instruction:\n" );
76- rt_hw_show_register (regs );
87+
88+ if (rt_trap_hook == RT_NULL )
89+ {
90+ rt_kprintf ("undefined instruction:\n" );
91+ rt_hw_show_register (regs );
7792#ifdef RT_USING_FINSH
78- list_thread ();
93+ list_thread ();
7994#endif
80- rt_hw_cpu_shutdown ();
95+ rt_hw_cpu_shutdown ();
96+ }
97+ else
98+ {
99+ rt_trap_hook (regs , "undefined instruction" , UND_EXCEPTION );
100+ }
81101}
82102
83103/**
@@ -91,12 +111,19 @@ void rt_hw_trap_undef(struct rt_hw_exp_stack *regs)
91111 */
92112void rt_hw_trap_swi (struct rt_hw_exp_stack * regs )
93113{
94- rt_kprintf ("software interrupt:\n" );
95- rt_hw_show_register (regs );
114+ if (rt_trap_hook == RT_NULL )
115+ {
116+ rt_kprintf ("software interrupt:\n" );
117+ rt_hw_show_register (regs );
96118#ifdef RT_USING_FINSH
97- list_thread ();
119+ list_thread ();
98120#endif
99- rt_hw_cpu_shutdown ();
121+ rt_hw_cpu_shutdown ();
122+ }
123+ else
124+ {
125+ rt_trap_hook (regs , "software instruction" , SWI_EXCEPTION );
126+ }
100127}
101128
102129/**
@@ -109,12 +136,19 @@ void rt_hw_trap_swi(struct rt_hw_exp_stack *regs)
109136 */
110137void rt_hw_trap_pabt (struct rt_hw_exp_stack * regs )
111138{
112- rt_kprintf ("prefetch abort:\n" );
113- rt_hw_show_register (regs );
139+ if (rt_trap_hook == RT_NULL )
140+ {
141+ rt_kprintf ("prefetch abort:\n" );
142+ rt_hw_show_register (regs );
114143#ifdef RT_USING_FINSH
115- list_thread ();
144+ list_thread ();
116145#endif
117- rt_hw_cpu_shutdown ();
146+ rt_hw_cpu_shutdown ();
147+ }
148+ else
149+ {
150+ rt_trap_hook (regs , "prefetch abort" , PABT_EXCEPTION );
151+ }
118152}
119153
120154/**
@@ -127,12 +161,19 @@ void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
127161 */
128162void rt_hw_trap_dabt (struct rt_hw_exp_stack * regs )
129163{
130- rt_kprintf ("data abort:" );
131- rt_hw_show_register (regs );
164+ if (rt_trap_hook == RT_NULL )
165+ {
166+ rt_kprintf ("data abort:" );
167+ rt_hw_show_register (regs );
132168#ifdef RT_USING_FINSH
133- list_thread ();
169+ list_thread ();
134170#endif
135- rt_hw_cpu_shutdown ();
171+ rt_hw_cpu_shutdown ();
172+ }
173+ else
174+ {
175+ rt_trap_hook (regs , "data abort" , DABT_EXCEPTION );
176+ }
136177}
137178
138179/**
@@ -144,23 +185,32 @@ void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
144185 */
145186void rt_hw_trap_resv (struct rt_hw_exp_stack * regs )
146187{
147- rt_kprintf ("reserved trap:\n" );
148- rt_hw_show_register (regs );
188+ if (rt_trap_hook == RT_NULL )
189+ {
190+ rt_kprintf ("reserved trap:\n" );
191+ rt_hw_show_register (regs );
149192#ifdef RT_USING_FINSH
150- list_thread ();
193+ list_thread ();
151194#endif
152- rt_hw_cpu_shutdown ();
195+ rt_hw_cpu_shutdown ();
196+ }
197+ else
198+ {
199+ rt_trap_hook (regs , "reserved trap" , RESV_EXCEPTION );
200+ }
153201}
154202
155203void rt_hw_trap_irq (void )
156204{
157205 void * param ;
206+ int int_ack ;
158207 int ir ;
159208 rt_isr_handler_t isr_func ;
160209 extern struct rt_irq_desc isr_table [];
161210
162- ir = rt_hw_interrupt_get_irq ();
211+ int_ack = rt_hw_interrupt_get_irq ();
163212
213+ ir = int_ack & GIC_ACK_INTID_MASK ;
164214 if (ir == 1023 )
165215 {
166216 /* Spurious interrupt */
@@ -181,7 +231,7 @@ void rt_hw_trap_irq(void)
181231 }
182232
183233 /* end of interrupt */
184- rt_hw_interrupt_ack (ir );
234+ rt_hw_interrupt_ack (int_ack );
185235}
186236
187237void rt_hw_trap_fiq (void )
0 commit comments