Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 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> |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 2019 Sean Anderson <seanga2@gmail.com> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 13 | #include <efi_loader.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 14 | #include <hang.h> |
Simon Glass | c30b7ad | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 15 | #include <irq_func.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 16 | #include <asm/ptrace.h> |
| 17 | #include <asm/system.h> |
| 18 | #include <asm/encoding.h> |
| 19 | |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | static void show_efi_loaded_images(uintptr_t epc) |
| 23 | { |
| 24 | efi_print_image_infos((void *)epc); |
| 25 | } |
| 26 | |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 27 | static void show_regs(struct pt_regs *regs) |
| 28 | { |
| 29 | #ifdef CONFIG_SHOW_REGS |
Heinrich Schuchardt | c353f2b | 2020-12-02 14:36:26 +0100 | [diff] [blame] | 30 | printf("\nSP: " REG_FMT " GP: " REG_FMT " TP: " REG_FMT "\n", |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 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); |
Heinrich Schuchardt | c353f2b | 2020-12-02 14:36:26 +0100 | [diff] [blame] | 48 | printf("T4: " REG_FMT " T5: " REG_FMT " T6: " REG_FMT "\n", |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 49 | regs->t4, regs->t5, regs->t6); |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 50 | #endif |
| 51 | } |
| 52 | |
| 53 | static void _exit_trap(ulong code, ulong epc, ulong tval, struct pt_regs *regs) |
Bin Meng | 7f5d35a | 2018-12-12 06:12:44 -0800 | [diff] [blame] | 54 | { |
| 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 Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 74 | 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 Meng | 7f5d35a | 2018-12-12 06:12:44 -0800 | [diff] [blame] | 78 | |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 79 | printf("EPC: " REG_FMT " RA: " REG_FMT " TVAL: " REG_FMT "\n", |
| 80 | epc, regs->ra, tval); |
Sean Anderson | 8576813 | 2020-09-21 07:51:40 -0400 | [diff] [blame] | 81 | /* Print relocation adjustments, but only if gd is initialized */ |
| 82 | if (gd && gd->flags & GD_FLG_RELOC) |
Heinrich Schuchardt | c353f2b | 2020-12-02 14:36:26 +0100 | [diff] [blame] | 83 | printf("EPC: " REG_FMT " RA: " REG_FMT " reloc adjusted\n", |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 84 | epc - gd->reloc_off, regs->ra - gd->reloc_off); |
| 85 | |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 86 | show_regs(regs); |
Heinrich Schuchardt | 7c6ca03 | 2020-08-01 15:15:39 +0000 | [diff] [blame] | 87 | show_efi_loaded_images(epc); |
Heinrich Schuchardt | c353f2b | 2020-12-02 14:36:26 +0100 | [diff] [blame] | 88 | panic("\n"); |
Bin Meng | 7f5d35a | 2018-12-12 06:12:44 -0800 | [diff] [blame] | 89 | } |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 90 | |
| 91 | int interrupt_init(void) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * enable interrupts |
| 98 | */ |
| 99 | void enable_interrupts(void) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * disable interrupts |
| 105 | */ |
| 106 | int disable_interrupts(void) |
| 107 | { |
| 108 | return 0; |
| 109 | } |
| 110 | |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 111 | ulong handle_trap(ulong cause, ulong epc, ulong tval, struct pt_regs *regs) |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 112 | { |
Anup Patel | d2db2a8 | 2018-12-03 10:57:40 +0530 | [diff] [blame] | 113 | ulong is_irq, irq; |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 114 | |
Heinrich Schuchardt | c48e9f3 | 2020-09-26 07:50:36 +0200 | [diff] [blame] | 115 | /* An UEFI application may have changed gd. Restore U-Boot's gd. */ |
| 116 | efi_restore_gd(); |
| 117 | |
Anup Patel | d2db2a8 | 2018-12-03 10:57:40 +0530 | [diff] [blame] | 118 | 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 Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 132 | _exit_trap(cause, epc, tval, regs); |
Anup Patel | d2db2a8 | 2018-12-03 10:57:40 +0530 | [diff] [blame] | 133 | break; |
| 134 | }; |
| 135 | } else { |
Sean Anderson | fd1f6e9 | 2019-12-25 00:27:44 -0500 | [diff] [blame] | 136 | _exit_trap(cause, epc, tval, regs); |
Anup Patel | d2db2a8 | 2018-12-03 10:57:40 +0530 | [diff] [blame] | 137 | } |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 138 | |
| 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 | } |