exceptions.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
  3. * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (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
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <stdio_dev.h>
  22. #include <asm/system.h>
  23. static const char * const excp_table[] = {
  24. "Unknown exception",
  25. "Reset",
  26. "Bus Error",
  27. "Data Page Fault",
  28. "Instruction Page Fault",
  29. "Tick Timer",
  30. "Alignment",
  31. "Illegal Instruction",
  32. "External Interrupt",
  33. "D-TLB Miss",
  34. "I-TLB Miss",
  35. "Range",
  36. "System Call",
  37. "Floating Point",
  38. "Trap",
  39. };
  40. static void (*handlers[32])(void);
  41. void exception_install_handler(int exception, void (*handler)(void))
  42. {
  43. if (exception < 0 || exception > 31)
  44. return;
  45. handlers[exception] = handler;
  46. }
  47. void exception_free_handler(int exception)
  48. {
  49. if (exception < 0 || exception > 31)
  50. return;
  51. handlers[exception] = 0;
  52. }
  53. static void exception_hang(int vect)
  54. {
  55. printf("Unhandled exception at 0x%x ", vect & 0xff00);
  56. vect = ((vect >> 8) & 0xff);
  57. if (vect < ARRAY_SIZE(excp_table))
  58. printf("(%s)\n", excp_table[vect]);
  59. else
  60. printf("(%s)\n", excp_table[0]);
  61. printf("EPCR: 0x%08lx\n", mfspr(SPR_EPCR_BASE));
  62. printf("EEAR: 0x%08lx\n", mfspr(SPR_EEAR_BASE));
  63. printf("ESR: 0x%08lx\n", mfspr(SPR_ESR_BASE));
  64. hang();
  65. }
  66. void exception_handler(int vect)
  67. {
  68. int exception = vect >> 8;
  69. if (handlers[exception])
  70. handlers[exception]();
  71. else
  72. exception_hang(vect);
  73. }