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 10 #include <common.h> 11 #include <asm/ptrace.h> 12 #include <asm/system.h> 13 #include <asm/encoding.h> 14 15 static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs); 16 17 int interrupt_init(void) 18 { 19 return 0; 20 } 21 22 /* 23 * enable interrupts 24 */ 25 void enable_interrupts(void) 26 { 27 } 28 29 /* 30 * disable interrupts 31 */ 32 int disable_interrupts(void) 33 { 34 return 0; 35 } 36 37 ulong handle_trap(ulong mcause, ulong epc, struct pt_regs *regs) 38 { 39 ulong is_int; 40 41 is_int = (mcause & MCAUSE_INT); 42 if ((is_int) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT)) 43 external_interrupt(0); /* handle_m_ext_interrupt */ 44 else if ((is_int) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER)) 45 timer_interrupt(0); /* handle_m_timer_interrupt */ 46 else 47 _exit_trap(mcause, epc, regs); 48 49 return epc; 50 } 51 52 /* 53 *Entry Point for PLIC Interrupt Handler 54 */ 55 __attribute__((weak)) void external_interrupt(struct pt_regs *regs) 56 { 57 } 58 59 __attribute__((weak)) void timer_interrupt(struct pt_regs *regs) 60 { 61 } 62 63 static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs) 64 { 65 static const char * const exception_code[] = { 66 "Instruction address misaligned", 67 "Instruction access fault", 68 "Illegal instruction", 69 "Breakpoint", 70 "Load address misaligned", 71 "Load access fault", 72 "Store/AMO address misaligned", 73 "Store/AMO access fault", 74 "Environment call from U-mode", 75 "Environment call from S-mode", 76 "Reserved", 77 "Environment call from M-mode", 78 "Instruction page fault", 79 "Load page fault", 80 "Reserved", 81 "Store/AMO page fault", 82 }; 83 84 if (code < ARRAY_SIZE(exception_code)) { 85 printf("exception code: %ld , %s , epc %lx , ra %lx\n", 86 code, exception_code[code], epc, regs->ra); 87 } else { 88 printf("Reserved\n"); 89 } 90 91 hang(); 92 } 93