exception.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @addtogroup Ingenic
  29. */
  30. /*@{*/
  31. /**
  32. * exception handle table
  33. */
  34. exception_func_t sys_exception_handlers[33];
  35. /**
  36. * setup the exception handle
  37. */
  38. exception_func_t rt_set_except_vector(int n, exception_func_t func)
  39. {
  40. exception_func_t old_handler = sys_exception_handlers[n];
  41. if ((n == 0) || (n > 32) || (!func))
  42. {
  43. return 0;
  44. }
  45. sys_exception_handlers[n] = func;
  46. return old_handler;
  47. }
  48. void tlb_refill_handler(void)
  49. {
  50. rt_kprintf("tlb-miss happens, epc: 0x%08x\n", read_c0_epc());
  51. rt_hw_cpu_shutdown();
  52. }
  53. void cache_error_handler(void)
  54. {
  55. rt_kprintf("cache exception happens, epc: 0x%08x\n", read_c0_epc());
  56. rt_hw_cpu_shutdown();
  57. }
  58. static void unhandled_exception_handle(pt_regs_t *regs)
  59. {
  60. rt_kprintf("exception happens, epc: 0x%08x\n", regs->cp0_epc);
  61. }
  62. void install_default_execpt_handle(void)
  63. {
  64. rt_int32_t i;
  65. for (i=0; i<33; i++)
  66. sys_exception_handlers[i] = (exception_func_t)unhandled_exception_handle;
  67. }
  68. /*@}*/