interrupt.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* Enable kernel-mode log API */
  16. #include <stdint.h>
  17. #include <stdlib.h>
  18. #include "dump.h"
  19. #include "interrupt.h"
  20. #include "syscalls.h"
  21. #include "syslog.h"
  22. uintptr_t __attribute__((weak))
  23. handle_irq_dummy(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32])
  24. {
  25. dump_core("unhandled interrupt", cause, epc, regs, fregs);
  26. sys_exit(1337);
  27. return epc;
  28. }
  29. uintptr_t __attribute__((weak, alias("handle_irq_dummy")))
  30. handle_irq_m_soft(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32]);
  31. uintptr_t __attribute__((weak, alias("handle_irq_dummy")))
  32. handle_irq_m_timer(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32]);
  33. extern uintptr_t
  34. handle_irq_m_ext(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32]);
  35. uintptr_t __attribute__((weak))
  36. handle_irq(uintptr_t cause, uintptr_t epc, uintptr_t regs[32], uintptr_t fregs[32])
  37. {
  38. #if defined(__GNUC__)
  39. #pragma GCC diagnostic ignored "-Woverride-init"
  40. #endif
  41. /* clang-format off */
  42. static uintptr_t (* const irq_table[])(
  43. uintptr_t cause,
  44. uintptr_t epc,
  45. uintptr_t regs[32],
  46. uintptr_t fregs[32]) =
  47. {
  48. [0 ... 14] = handle_irq_dummy,
  49. [IRQ_M_SOFT] = handle_irq_m_soft,
  50. [IRQ_M_TIMER] = handle_irq_m_timer,
  51. [IRQ_M_EXT] = handle_irq_m_ext,
  52. };
  53. /* clang-format on */
  54. #if defined(__GNUC__)
  55. #pragma GCC diagnostic warning "-Woverride-init"
  56. #endif
  57. return irq_table[cause & CAUSE_MACHINE_IRQ_REASON_MASK](cause, epc, regs, fregs);
  58. }