interrupts.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016-17 Microsemi Corporation.
  4. * Padmarao Begari, Microsemi Corporation <padmarao.begari@microsemi.com>
  5. *
  6. * Copyright (C) 2017 Andes Technology Corporation
  7. * Rick Chen, Andes Technology Corporation <rick@andestech.com>
  8. */
  9. #include <common.h>
  10. #include <irq_func.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/system.h>
  13. #include <asm/encoding.h>
  14. __attribute__((weak)) int plic_init(void)
  15. {
  16. return 0;
  17. }
  18. static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs)
  19. {
  20. static const char * const exception_code[] = {
  21. "Instruction address misaligned",
  22. "Instruction access fault",
  23. "Illegal instruction",
  24. "Breakpoint",
  25. "Load address misaligned",
  26. "Load access fault",
  27. "Store/AMO address misaligned",
  28. "Store/AMO access fault",
  29. "Environment call from U-mode",
  30. "Environment call from S-mode",
  31. "Reserved",
  32. "Environment call from M-mode",
  33. "Instruction page fault",
  34. "Load page fault",
  35. "Reserved",
  36. "Store/AMO page fault",
  37. };
  38. if (code < ARRAY_SIZE(exception_code)) {
  39. printf("exception code: %ld , %s , epc %lx , ra %lx\n",
  40. code, exception_code[code], epc, regs->ra);
  41. } else {
  42. printf("reserved exception code: %ld , epc %lx , ra %lx\n",
  43. code, epc, regs->ra);
  44. }
  45. hang();
  46. }
  47. int interrupt_init(void)
  48. {
  49. debug("[%s,%d]Initialize the plic\n", __func__, __LINE__);
  50. plic_init();
  51. return 0;
  52. }
  53. /*
  54. * enable interrupts
  55. */
  56. void enable_interrupts(void)
  57. {
  58. }
  59. /*
  60. * disable interrupts
  61. */
  62. int disable_interrupts(void)
  63. {
  64. return 0;
  65. }
  66. ulong handle_trap(ulong cause, ulong epc, struct pt_regs *regs)
  67. {
  68. ulong is_irq, irq;
  69. is_irq = (cause & MCAUSE_INT);
  70. irq = (cause & ~MCAUSE_INT);
  71. debug("[%s,%d]\n", __func__, __LINE__);
  72. if (is_irq) {
  73. switch (irq) {
  74. case IRQ_M_EXT:
  75. case IRQ_S_EXT:
  76. debug("[%s,%d]\n", __func__, __LINE__);
  77. external_interrupt(0); /* handle external interrupt */
  78. break;
  79. case IRQ_M_TIMER:
  80. case IRQ_S_TIMER:
  81. timer_interrupt(0); /* handle timer interrupt */
  82. break;
  83. default:
  84. _exit_trap(cause, epc, regs);
  85. break;
  86. };
  87. } else {
  88. _exit_trap(cause, epc, regs);
  89. }
  90. debug("[%s,%d]\n", __func__, __LINE__);
  91. return epc;
  92. }
  93. /*
  94. *Entry Point for PLIC Interrupt Handler
  95. */
  96. __attribute__((weak)) void external_interrupt(struct pt_regs *regs)
  97. {
  98. }
  99. __attribute__((weak)) void timer_interrupt(struct pt_regs *regs)
  100. {
  101. }