blob: 903a1c4cd55766f7383b6c3eb93fff67c72ef652 [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
Lukas Auere429a1e2018-11-22 11:26:17 +010015static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs);
Rick Chen6eedd922017-12-26 13:55:49 +080016
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
Lukas Auere429a1e2018-11-22 11:26:17 +010037ulong handle_trap(ulong mcause, ulong epc, struct pt_regs *regs)
Rick Chen6eedd922017-12-26 13:55:49 +080038{
Lukas Auere429a1e2018-11-22 11:26:17 +010039 ulong is_int;
Rick Chen6eedd922017-12-26 13:55:49 +080040
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
Lukas Auere429a1e2018-11-22 11:26:17 +010063static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs)
Rick Chen6eedd922017-12-26 13:55:49 +080064{
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",
Lukas Auer40f7eb52018-11-22 11:26:20 +010070 "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",
Rick Chen6eedd922017-12-26 13:55:49 +080082 };
83
Lukas Auerae525d52018-11-22 11:26:21 +010084 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 }
Lukas Auer306b31d2018-11-22 11:26:22 +010090
91 hang();
Rick Chen6eedd922017-12-26 13:55:49 +080092}