1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2013
4 * David Feng <fenghua@phytium.com.cn>
5 */
6
7 #include <common.h>
8 #include <asm/global_data.h>
9 #include <asm/ptrace.h>
10 #include <irq_func.h>
11 #include <linux/compiler.h>
12 #include <efi_loader.h>
13
14 DECLARE_GLOBAL_DATA_PTR;
15
interrupt_init(void)16 int interrupt_init(void)
17 {
18 enable_interrupts();
19
20 return 0;
21 }
22
enable_interrupts(void)23 void enable_interrupts(void)
24 {
25 return;
26 }
27
disable_interrupts(void)28 int disable_interrupts(void)
29 {
30 return 0;
31 }
32
show_efi_loaded_images(struct pt_regs * regs)33 static void show_efi_loaded_images(struct pt_regs *regs)
34 {
35 efi_print_image_infos((void *)regs->elr);
36 }
37
dump_instr(struct pt_regs * regs)38 static void dump_instr(struct pt_regs *regs)
39 {
40 u32 *addr = (u32 *)(regs->elr & ~3UL);
41 int i;
42
43 printf("Code: ");
44 for (i = -4; i < 1; i++)
45 printf(i == 0 ? "(%08x) " : "%08x ", addr[i]);
46 printf("\n");
47 }
48
show_regs(struct pt_regs * regs)49 void show_regs(struct pt_regs *regs)
50 {
51 int i;
52
53 if (gd->flags & GD_FLG_RELOC)
54 printf("elr: %016lx lr : %016lx (reloc)\n",
55 regs->elr - gd->reloc_off,
56 regs->regs[30] - gd->reloc_off);
57 printf("elr: %016lx lr : %016lx\n", regs->elr, regs->regs[30]);
58
59 for (i = 0; i < 29; i += 2)
60 printf("x%-2d: %016lx x%-2d: %016lx\n",
61 i, regs->regs[i], i+1, regs->regs[i+1]);
62 printf("\n");
63 dump_instr(regs);
64 }
65
66 /*
67 * do_bad_sync handles the impossible case in the Synchronous Abort vector.
68 */
do_bad_sync(struct pt_regs * pt_regs,unsigned int esr)69 void do_bad_sync(struct pt_regs *pt_regs, unsigned int esr)
70 {
71 efi_restore_gd();
72 printf("Bad mode in \"Synchronous Abort\" handler, esr 0x%08x\n", esr);
73 show_regs(pt_regs);
74 show_efi_loaded_images(pt_regs);
75 panic("Resetting CPU ...\n");
76 }
77
78 /*
79 * do_bad_irq handles the impossible case in the Irq vector.
80 */
do_bad_irq(struct pt_regs * pt_regs,unsigned int esr)81 void do_bad_irq(struct pt_regs *pt_regs, unsigned int esr)
82 {
83 efi_restore_gd();
84 printf("Bad mode in \"Irq\" handler, esr 0x%08x\n", esr);
85 show_regs(pt_regs);
86 show_efi_loaded_images(pt_regs);
87 panic("Resetting CPU ...\n");
88 }
89
90 /*
91 * do_bad_fiq handles the impossible case in the Fiq vector.
92 */
do_bad_fiq(struct pt_regs * pt_regs,unsigned int esr)93 void do_bad_fiq(struct pt_regs *pt_regs, unsigned int esr)
94 {
95 efi_restore_gd();
96 printf("Bad mode in \"Fiq\" handler, esr 0x%08x\n", esr);
97 show_regs(pt_regs);
98 show_efi_loaded_images(pt_regs);
99 panic("Resetting CPU ...\n");
100 }
101
102 /*
103 * do_bad_error handles the impossible case in the Error vector.
104 */
do_bad_error(struct pt_regs * pt_regs,unsigned int esr)105 void do_bad_error(struct pt_regs *pt_regs, unsigned int esr)
106 {
107 efi_restore_gd();
108 printf("Bad mode in \"Error\" handler, esr 0x%08x\n", esr);
109 show_regs(pt_regs);
110 show_efi_loaded_images(pt_regs);
111 panic("Resetting CPU ...\n");
112 }
113
114 /*
115 * do_sync handles the Synchronous Abort exception.
116 */
do_sync(struct pt_regs * pt_regs,unsigned int esr)117 void do_sync(struct pt_regs *pt_regs, unsigned int esr)
118 {
119 efi_restore_gd();
120 printf("\"Synchronous Abort\" handler, esr 0x%08x\n", esr);
121 show_regs(pt_regs);
122 show_efi_loaded_images(pt_regs);
123 panic("Resetting CPU ...\n");
124 }
125
126 /*
127 * do_irq handles the Irq exception.
128 */
do_irq(struct pt_regs * pt_regs,unsigned int esr)129 void do_irq(struct pt_regs *pt_regs, unsigned int esr)
130 {
131 efi_restore_gd();
132 printf("\"Irq\" handler, esr 0x%08x\n", esr);
133 show_regs(pt_regs);
134 show_efi_loaded_images(pt_regs);
135 panic("Resetting CPU ...\n");
136 }
137
138 /*
139 * do_fiq handles the Fiq exception.
140 */
do_fiq(struct pt_regs * pt_regs,unsigned int esr)141 void do_fiq(struct pt_regs *pt_regs, unsigned int esr)
142 {
143 efi_restore_gd();
144 printf("\"Fiq\" handler, esr 0x%08x\n", esr);
145 show_regs(pt_regs);
146 show_efi_loaded_images(pt_regs);
147 panic("Resetting CPU ...\n");
148 }
149
150 /*
151 * do_error handles the Error exception.
152 * Errors are more likely to be processor specific,
153 * it is defined with weak attribute and can be redefined
154 * in processor specific code.
155 */
do_error(struct pt_regs * pt_regs,unsigned int esr)156 void __weak do_error(struct pt_regs *pt_regs, unsigned int esr)
157 {
158 efi_restore_gd();
159 printf("\"Error\" handler, esr 0x%08x\n", esr);
160 show_regs(pt_regs);
161 show_efi_loaded_images(pt_regs);
162 panic("Resetting CPU ...\n");
163 }
164