blob: 0a0995a7af9d08479befecf50e0c8c564d5babe4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen6eedd922017-12-26 13:55:49 +08002/*
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>
Rick Chen6eedd922017-12-26 13:55:49 +08008 */
9
10#include <common.h>
11#include <asm/ptrace.h>
12#include <asm/system.h>
13#include <asm/encoding.h>
14
15static void _exit_trap(int code, uint epc, struct pt_regs *regs);
16
17int interrupt_init(void)
18{
19 return 0;
20}
21
22/*
23 * enable interrupts
24 */
25void enable_interrupts(void)
26{
27}
28
29/*
30 * disable interrupts
31 */
32int disable_interrupts(void)
33{
34 return 0;
35}
36
37uint handle_trap(uint mcause, uint epc, struct pt_regs *regs)
38{
39 uint 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
63static void _exit_trap(int code, uint epc, struct pt_regs *regs)
64{
Rick Chenf8e3a122018-02-12 11:24:43 +080065 static const char * const exception_code[] = {
Rick Chen6eedd922017-12-26 13:55:49 +080066 "Instruction address misaligned",
67 "Instruction access fault",
68 "Illegal instruction",
69 "Breakpoint",
70 "Load address misaligned"
71 };
72
73 printf("exception code: %d , %s , epc %08x , ra %08lx\n",
74 code, exception_code[code], epc, regs->ra);
75}