blob: cd47e64487227f41ceac93ee8500260fe4a088c1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen8bbb2902017-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>
Sean Andersonfd1f6e92019-12-25 00:27:44 -05008 *
9 * Copyright (C) 2019 Sean Anderson <seanga2@gmail.com>
Rick Chen8bbb2902017-12-26 13:55:49 +080010 */
11
12#include <common.h>
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000013#include <efi_loader.h>
Simon Glassdb41d652019-12-28 10:45:07 -070014#include <hang.h>
Simon Glassc30b7ad2019-11-14 12:57:41 -070015#include <irq_func.h>
Rick Chen8bbb2902017-12-26 13:55:49 +080016#include <asm/ptrace.h>
17#include <asm/system.h>
18#include <asm/encoding.h>
19
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000020DECLARE_GLOBAL_DATA_PTR;
21
22static void show_efi_loaded_images(uintptr_t epc)
23{
24 efi_print_image_infos((void *)epc);
25}
26
Sean Andersonfd1f6e92019-12-25 00:27:44 -050027static void show_regs(struct pt_regs *regs)
28{
29#ifdef CONFIG_SHOW_REGS
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000030 printf("SP: " REG_FMT " GP: " REG_FMT " TP: " REG_FMT "\n",
31 regs->sp, regs->gp, regs->tp);
32 printf("T0: " REG_FMT " T1: " REG_FMT " T2: " REG_FMT "\n",
33 regs->t0, regs->t1, regs->t2);
34 printf("S0: " REG_FMT " S1: " REG_FMT " A0: " REG_FMT "\n",
35 regs->s0, regs->s1, regs->a0);
36 printf("A1: " REG_FMT " A2: " REG_FMT " A3: " REG_FMT "\n",
37 regs->a1, regs->a2, regs->a3);
38 printf("A4: " REG_FMT " A5: " REG_FMT " A6: " REG_FMT "\n",
39 regs->a4, regs->a5, regs->a6);
40 printf("A7: " REG_FMT " S2: " REG_FMT " S3: " REG_FMT "\n",
41 regs->a7, regs->s2, regs->s3);
42 printf("S4: " REG_FMT " S5: " REG_FMT " S6: " REG_FMT "\n",
43 regs->s4, regs->s5, regs->s6);
44 printf("S7: " REG_FMT " S8: " REG_FMT " S9: " REG_FMT "\n",
45 regs->s7, regs->s8, regs->s9);
46 printf("S10: " REG_FMT " S11: " REG_FMT " T3: " REG_FMT "\n",
47 regs->s10, regs->s11, regs->t3);
48 printf("T4: " REG_FMT " T5: " REG_FMT " T6: " REG_FMT "\n\n",
49 regs->t4, regs->t5, regs->t6);
Sean Andersonfd1f6e92019-12-25 00:27:44 -050050#endif
51}
52
53static void _exit_trap(ulong code, ulong epc, ulong tval, struct pt_regs *regs)
Bin Meng7f5d35a2018-12-12 06:12:44 -080054{
55 static const char * const exception_code[] = {
56 "Instruction address misaligned",
57 "Instruction access fault",
58 "Illegal instruction",
59 "Breakpoint",
60 "Load address misaligned",
61 "Load access fault",
62 "Store/AMO address misaligned",
63 "Store/AMO access fault",
64 "Environment call from U-mode",
65 "Environment call from S-mode",
66 "Reserved",
67 "Environment call from M-mode",
68 "Instruction page fault",
69 "Load page fault",
70 "Reserved",
71 "Store/AMO page fault",
72 };
73
Sean Andersonfd1f6e92019-12-25 00:27:44 -050074 if (code < ARRAY_SIZE(exception_code))
75 printf("Unhandled exception: %s\n", exception_code[code]);
76 else
77 printf("Unhandled exception code: %ld\n", code);
Bin Meng7f5d35a2018-12-12 06:12:44 -080078
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000079 printf("EPC: " REG_FMT " RA: " REG_FMT " TVAL: " REG_FMT "\n",
80 epc, regs->ra, tval);
81 if (gd->flags & GD_FLG_RELOC)
82 printf("EPC: " REG_FMT " RA: " REG_FMT " reloc adjusted\n\n",
83 epc - gd->reloc_off, regs->ra - gd->reloc_off);
84
Sean Andersonfd1f6e92019-12-25 00:27:44 -050085 show_regs(regs);
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000086 show_efi_loaded_images(epc);
Bin Meng7f5d35a2018-12-12 06:12:44 -080087 hang();
88}
Rick Chen8bbb2902017-12-26 13:55:49 +080089
90int interrupt_init(void)
91{
92 return 0;
93}
94
95/*
96 * enable interrupts
97 */
98void enable_interrupts(void)
99{
100}
101
102/*
103 * disable interrupts
104 */
105int disable_interrupts(void)
106{
107 return 0;
108}
109
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500110ulong handle_trap(ulong cause, ulong epc, ulong tval, struct pt_regs *regs)
Rick Chen8bbb2902017-12-26 13:55:49 +0800111{
Anup Pateld2db2a82018-12-03 10:57:40 +0530112 ulong is_irq, irq;
Rick Chen8bbb2902017-12-26 13:55:49 +0800113
Anup Pateld2db2a82018-12-03 10:57:40 +0530114 is_irq = (cause & MCAUSE_INT);
115 irq = (cause & ~MCAUSE_INT);
116
117 if (is_irq) {
118 switch (irq) {
119 case IRQ_M_EXT:
120 case IRQ_S_EXT:
121 external_interrupt(0); /* handle external interrupt */
122 break;
123 case IRQ_M_TIMER:
124 case IRQ_S_TIMER:
125 timer_interrupt(0); /* handle timer interrupt */
126 break;
127 default:
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500128 _exit_trap(cause, epc, tval, regs);
Anup Pateld2db2a82018-12-03 10:57:40 +0530129 break;
130 };
131 } else {
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500132 _exit_trap(cause, epc, tval, regs);
Anup Pateld2db2a82018-12-03 10:57:40 +0530133 }
Rick Chen8bbb2902017-12-26 13:55:49 +0800134
135 return epc;
136}
137
138/*
139 *Entry Point for PLIC Interrupt Handler
140 */
141__attribute__((weak)) void external_interrupt(struct pt_regs *regs)
142{
143}
144
145__attribute__((weak)) void timer_interrupt(struct pt_regs *regs)
146{
147}