blob: 5299489013760b72d2a2664d02a74783aed1e2c3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
David Feng0ae76532013-12-14 11:47:35 +08002/*
3 * (C) Copyright 2013
4 * David Feng <fenghua@phytium.com.cn>
David Feng0ae76532013-12-14 11:47:35 +08005 */
6
7#include <common.h>
Simon Glass25a58182020-05-10 11:40:06 -06008#include <asm/ptrace.h>
Simon Glassc30b7ad2019-11-14 12:57:41 -07009#include <irq_func.h>
David Feng0ae76532013-12-14 11:47:35 +080010#include <linux/compiler.h>
Alexander Graf64982912016-03-04 01:10:06 +010011#include <efi_loader.h>
David Feng0ae76532013-12-14 11:47:35 +080012
Peng Fan082693f2017-11-28 10:08:08 +080013DECLARE_GLOBAL_DATA_PTR;
David Feng0ae76532013-12-14 11:47:35 +080014
15int interrupt_init(void)
16{
Ovidiu Panait5cf9e3b2020-04-20 10:31:44 +030017 enable_interrupts();
18
David Feng0ae76532013-12-14 11:47:35 +080019 return 0;
20}
21
22void enable_interrupts(void)
23{
24 return;
25}
26
27int disable_interrupts(void)
28{
29 return 0;
30}
31
Heinrich Schuchardtbba81652019-04-04 22:06:25 +020032static void show_efi_loaded_images(struct pt_regs *regs)
33{
34 efi_print_image_infos((void *)regs->elr);
35}
36
Heinrich Schuchardt57bbf442019-09-12 19:09:26 +020037static void dump_instr(struct pt_regs *regs)
38{
39 u32 *addr = (u32 *)(regs->elr & ~3UL);
40 int i;
41
42 printf("Code: ");
43 for (i = -4; i < 1; i++)
44 printf(i == 0 ? "(%08x) " : "%08x ", addr[i]);
45 printf("\n");
46}
47
David Feng0ae76532013-12-14 11:47:35 +080048void show_regs(struct pt_regs *regs)
49{
50 int i;
51
Karl Beldanfa7b8ea2018-02-20 23:30:08 +000052 if (gd->flags & GD_FLG_RELOC)
53 printf("elr: %016lx lr : %016lx (reloc)\n",
54 regs->elr - gd->reloc_off,
55 regs->regs[30] - gd->reloc_off);
56 printf("elr: %016lx lr : %016lx\n", regs->elr, regs->regs[30]);
57
David Feng0ae76532013-12-14 11:47:35 +080058 for (i = 0; i < 29; i += 2)
59 printf("x%-2d: %016lx x%-2d: %016lx\n",
60 i, regs->regs[i], i+1, regs->regs[i+1]);
61 printf("\n");
Heinrich Schuchardt57bbf442019-09-12 19:09:26 +020062 dump_instr(regs);
David Feng0ae76532013-12-14 11:47:35 +080063}
64
65/*
66 * do_bad_sync handles the impossible case in the Synchronous Abort vector.
67 */
68void do_bad_sync(struct pt_regs *pt_regs, unsigned int esr)
69{
Alexander Graf64982912016-03-04 01:10:06 +010070 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +080071 printf("Bad mode in \"Synchronous Abort\" handler, esr 0x%08x\n", esr);
72 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +020073 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +080074 panic("Resetting CPU ...\n");
75}
76
77/*
78 * do_bad_irq handles the impossible case in the Irq vector.
79 */
80void do_bad_irq(struct pt_regs *pt_regs, unsigned int esr)
81{
Alexander Graf64982912016-03-04 01:10:06 +010082 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +080083 printf("Bad mode in \"Irq\" handler, esr 0x%08x\n", esr);
84 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +020085 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +080086 panic("Resetting CPU ...\n");
87}
88
89/*
90 * do_bad_fiq handles the impossible case in the Fiq vector.
91 */
92void do_bad_fiq(struct pt_regs *pt_regs, unsigned int esr)
93{
Alexander Graf64982912016-03-04 01:10:06 +010094 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +080095 printf("Bad mode in \"Fiq\" handler, esr 0x%08x\n", esr);
96 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +020097 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +080098 panic("Resetting CPU ...\n");
99}
100
101/*
102 * do_bad_error handles the impossible case in the Error vector.
103 */
104void do_bad_error(struct pt_regs *pt_regs, unsigned int esr)
105{
Alexander Graf64982912016-03-04 01:10:06 +0100106 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +0800107 printf("Bad mode in \"Error\" handler, esr 0x%08x\n", esr);
108 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +0200109 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +0800110 panic("Resetting CPU ...\n");
111}
112
113/*
114 * do_sync handles the Synchronous Abort exception.
115 */
116void do_sync(struct pt_regs *pt_regs, unsigned int esr)
117{
Alexander Graf64982912016-03-04 01:10:06 +0100118 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +0800119 printf("\"Synchronous Abort\" handler, esr 0x%08x\n", esr);
120 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +0200121 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +0800122 panic("Resetting CPU ...\n");
123}
124
125/*
126 * do_irq handles the Irq exception.
127 */
128void do_irq(struct pt_regs *pt_regs, unsigned int esr)
129{
Alexander Graf64982912016-03-04 01:10:06 +0100130 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +0800131 printf("\"Irq\" handler, esr 0x%08x\n", esr);
132 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +0200133 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +0800134 panic("Resetting CPU ...\n");
135}
136
137/*
138 * do_fiq handles the Fiq exception.
139 */
140void do_fiq(struct pt_regs *pt_regs, unsigned int esr)
141{
Alexander Graf64982912016-03-04 01:10:06 +0100142 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +0800143 printf("\"Fiq\" handler, esr 0x%08x\n", esr);
144 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +0200145 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +0800146 panic("Resetting CPU ...\n");
147}
148
149/*
150 * do_error handles the Error exception.
151 * Errors are more likely to be processor specific,
152 * it is defined with weak attribute and can be redefined
153 * in processor specific code.
154 */
155void __weak do_error(struct pt_regs *pt_regs, unsigned int esr)
156{
Alexander Graf64982912016-03-04 01:10:06 +0100157 efi_restore_gd();
David Feng0ae76532013-12-14 11:47:35 +0800158 printf("\"Error\" handler, esr 0x%08x\n", esr);
159 show_regs(pt_regs);
Heinrich Schuchardtbba81652019-04-04 22:06:25 +0200160 show_efi_loaded_images(pt_regs);
David Feng0ae76532013-12-14 11:47:35 +0800161 panic("Resetting CPU ...\n");
162}