exceptions.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
  3. * (C) Copyright 2011, Julius Baxter <julius@opencores.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <stdio_dev.h>
  9. #include <asm/system.h>
  10. static const char * const excp_table[] = {
  11. "Unknown exception",
  12. "Reset",
  13. "Bus Error",
  14. "Data Page Fault",
  15. "Instruction Page Fault",
  16. "Tick Timer",
  17. "Alignment",
  18. "Illegal Instruction",
  19. "External Interrupt",
  20. "D-TLB Miss",
  21. "I-TLB Miss",
  22. "Range",
  23. "System Call",
  24. "Floating Point",
  25. "Trap",
  26. };
  27. static void (*handlers[32])(void);
  28. void exception_install_handler(int exception, void (*handler)(void))
  29. {
  30. if (exception < 0 || exception > 31)
  31. return;
  32. handlers[exception] = handler;
  33. }
  34. void exception_free_handler(int exception)
  35. {
  36. if (exception < 0 || exception > 31)
  37. return;
  38. handlers[exception] = 0;
  39. }
  40. static void exception_hang(int vect)
  41. {
  42. printf("Unhandled exception at 0x%x ", vect & 0xff00);
  43. vect = ((vect >> 8) & 0xff);
  44. if (vect < ARRAY_SIZE(excp_table))
  45. printf("(%s)\n", excp_table[vect]);
  46. else
  47. printf("(%s)\n", excp_table[0]);
  48. printf("EPCR: 0x%08lx\n", mfspr(SPR_EPCR_BASE));
  49. printf("EEAR: 0x%08lx\n", mfspr(SPR_EEAR_BASE));
  50. printf("ESR: 0x%08lx\n", mfspr(SPR_ESR_BASE));
  51. hang();
  52. }
  53. void exception_handler(int vect)
  54. {
  55. int exception = vect >> 8;
  56. if (handlers[exception])
  57. handlers[exception]();
  58. else
  59. exception_hang(vect);
  60. }