1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2016-17 Microsemi Corporation.
4 * Padmarao Begari, Microsemi Corporation <padmarao.begari@microsemi.com>
6 * Copyright (C) 2017 Andes Technology Corporation
7 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
13 #include <asm/ptrace.h>
14 #include <asm/system.h>
15 #include <asm/encoding.h>
17 static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs)
19 static const char * const exception_code[] = {
20 "Instruction address misaligned",
21 "Instruction access fault",
22 "Illegal instruction",
24 "Load address misaligned",
26 "Store/AMO address misaligned",
27 "Store/AMO access fault",
28 "Environment call from U-mode",
29 "Environment call from S-mode",
31 "Environment call from M-mode",
32 "Instruction page fault",
35 "Store/AMO page fault",
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);
42 printf("reserved exception code: %ld , epc %lx , ra %lx\n",
49 int interrupt_init(void)
57 void enable_interrupts(void)
64 int disable_interrupts(void)
69 ulong handle_trap(ulong cause, ulong epc, struct pt_regs *regs)
73 is_irq = (cause & MCAUSE_INT);
74 irq = (cause & ~MCAUSE_INT);
80 external_interrupt(0); /* handle external interrupt */
84 timer_interrupt(0); /* handle timer interrupt */
87 _exit_trap(cause, epc, regs);
91 _exit_trap(cause, epc, regs);
98 *Entry Point for PLIC Interrupt Handler
100 __attribute__((weak)) void external_interrupt(struct pt_regs *regs)
104 __attribute__((weak)) void timer_interrupt(struct pt_regs *regs)