1 /*
2 * File : exception.c
3 * COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Change Logs:
20 * Date Author Notes
21 * 2010-05-17 swkyer first version
22 */
23 #include <rtthread.h>
24 #include <rthw.h>
25 #include "../common/exception.h"
26 #include "../common/mipsregs.h"
27
28 /**
29 * @addtogroup Ingenic
30 */
31 /*@{*/
32
33 /**
34 * exception handle table
35 */
36 exception_func_t sys_exception_handlers[33];
37
38 /**
39 * setup the exception handle
40 */
rt_set_except_vector(int n,exception_func_t func)41 exception_func_t rt_set_except_vector(int n, exception_func_t func)
42 {
43 exception_func_t old_handler = sys_exception_handlers[n];
44
45 if ((n == 0) || (n > 32) || (!func))
46 {
47 return 0;
48 }
49
50 sys_exception_handlers[n] = func;
51
52 return old_handler;
53 }
54
tlb_refill_handler(void)55 void tlb_refill_handler(void)
56 {
57 rt_kprintf("tlb-miss happens, epc: 0x%08x\n", read_c0_epc());
58 rt_hw_cpu_shutdown();
59 }
60
cache_error_handler(void)61 void cache_error_handler(void)
62 {
63 rt_kprintf("cache exception happens, epc: 0x%08x\n", read_c0_epc());
64 rt_hw_cpu_shutdown();
65 }
66
unhandled_exception_handle(pt_regs_t * regs)67 static void unhandled_exception_handle(pt_regs_t *regs)
68 {
69 rt_kprintf("exception happens, epc: 0x%08x\n", regs->cp0_epc);
70 }
71
install_default_execpt_handle(void)72 void install_default_execpt_handle(void)
73 {
74 rt_int32_t i;
75
76 for (i=0; i<33; i++)
77 sys_exception_handlers[i] = (exception_func_t)unhandled_exception_handle;
78 }
79
80 /*@}*/
81
82