blob: fb3ce118c1778d700bd4712459ba3a4e4716682c [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 Schuchardtc353f2b2020-12-02 14:36:26 +010030 printf("\nSP: " REG_FMT " GP: " REG_FMT " TP: " REG_FMT "\n",
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000031 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);
Heinrich Schuchardtc353f2b2020-12-02 14:36:26 +010048 printf("T4: " REG_FMT " T5: " REG_FMT " T6: " REG_FMT "\n",
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000049 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);
Sean Anderson85768132020-09-21 07:51:40 -040081 /* Print relocation adjustments, but only if gd is initialized */
82 if (gd && gd->flags & GD_FLG_RELOC)
Heinrich Schuchardtc353f2b2020-12-02 14:36:26 +010083 printf("EPC: " REG_FMT " RA: " REG_FMT " reloc adjusted\n",
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000084 epc - gd->reloc_off, regs->ra - gd->reloc_off);
85
Sean Andersonfd1f6e92019-12-25 00:27:44 -050086 show_regs(regs);
Heinrich Schuchardt7c6ca032020-08-01 15:15:39 +000087 show_efi_loaded_images(epc);
Heinrich Schuchardtc353f2b2020-12-02 14:36:26 +010088 panic("\n");
Bin Meng7f5d35a2018-12-12 06:12:44 -080089}
Rick Chen8bbb2902017-12-26 13:55:49 +080090
91int interrupt_init(void)
92{
93 return 0;
94}
95
96/*
97 * enable interrupts
98 */
99void enable_interrupts(void)
100{
101}
102
103/*
104 * disable interrupts
105 */
106int disable_interrupts(void)
107{
108 return 0;
109}
110
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500111ulong handle_trap(ulong cause, ulong epc, ulong tval, struct pt_regs *regs)
Rick Chen8bbb2902017-12-26 13:55:49 +0800112{
Anup Pateld2db2a82018-12-03 10:57:40 +0530113 ulong is_irq, irq;
Rick Chen8bbb2902017-12-26 13:55:49 +0800114
Heinrich Schuchardtc48e9f32020-09-26 07:50:36 +0200115 /* An UEFI application may have changed gd. Restore U-Boot's gd. */
116 efi_restore_gd();
117
Anup Pateld2db2a82018-12-03 10:57:40 +0530118 is_irq = (cause & MCAUSE_INT);
119 irq = (cause & ~MCAUSE_INT);
120
121 if (is_irq) {
122 switch (irq) {
123 case IRQ_M_EXT:
124 case IRQ_S_EXT:
125 external_interrupt(0); /* handle external interrupt */
126 break;
127 case IRQ_M_TIMER:
128 case IRQ_S_TIMER:
129 timer_interrupt(0); /* handle timer interrupt */
130 break;
131 default:
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500132 _exit_trap(cause, epc, tval, regs);
Anup Pateld2db2a82018-12-03 10:57:40 +0530133 break;
134 };
135 } else {
Sean Andersonfd1f6e92019-12-25 00:27:44 -0500136 _exit_trap(cause, epc, tval, regs);
Anup Pateld2db2a82018-12-03 10:57:40 +0530137 }
Rick Chen8bbb2902017-12-26 13:55:49 +0800138
139 return epc;
140}
141
142/*
143 *Entry Point for PLIC Interrupt Handler
144 */
145__attribute__((weak)) void external_interrupt(struct pt_regs *regs)
146{
147}
148
149__attribute__((weak)) void timer_interrupt(struct pt_regs *regs)
150{
151}