common: Move reset_cpu() to the CPU header
[oweals/u-boot.git] / arch / arm / lib / interrupts.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2003
4  * Texas Instruments <www.ti.com>
5  *
6  * (C) Copyright 2002
7  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8  * Marius Groeger <mgroeger@sysgo.de>
9  *
10  * (C) Copyright 2002
11  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12  * Alex Zuepke <azu@sysgo.de>
13  *
14  * (C) Copyright 2002-2004
15  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
16  *
17  * (C) Copyright 2004
18  * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
19  */
20
21 #include <common.h>
22 #include <cpu_func.h>
23 #include <efi_loader.h>
24 #include <irq_func.h>
25 #include <asm/proc-armv/ptrace.h>
26 #include <asm/u-boot-arm.h>
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 int interrupt_init(void)
31 {
32         /*
33          * setup up stacks if necessary
34          */
35         IRQ_STACK_START_IN = gd->irq_sp + 8;
36
37         return 0;
38 }
39
40 void enable_interrupts(void)
41 {
42         return;
43 }
44 int disable_interrupts(void)
45 {
46         return 0;
47 }
48
49 void bad_mode (void)
50 {
51         panic ("Resetting CPU ...\n");
52         reset_cpu(0);
53 }
54
55 static void show_efi_loaded_images(struct pt_regs *regs)
56 {
57         efi_print_image_infos((void *)instruction_pointer(regs));
58 }
59
60 static void dump_instr(struct pt_regs *regs)
61 {
62         unsigned long addr = instruction_pointer(regs);
63         const int thumb = thumb_mode(regs);
64         const int width = thumb ? 4 : 8;
65         int i;
66
67         if (thumb)
68                 addr &= ~1L;
69         else
70                 addr &= ~3L;
71         printf("Code: ");
72         for (i = -4; i < 1 + !!thumb; i++) {
73                 unsigned int val;
74
75                 if (thumb)
76                         val = ((u16 *)addr)[i];
77                 else
78                         val = ((u32 *)addr)[i];
79                 printf(i == 0 ? "(%0*x) " : "%0*x ", width, val);
80         }
81         printf("\n");
82 }
83
84 void show_regs (struct pt_regs *regs)
85 {
86         unsigned long __maybe_unused flags;
87         const char __maybe_unused *processor_modes[] = {
88         "USER_26",      "FIQ_26",       "IRQ_26",       "SVC_26",
89         "UK4_26",       "UK5_26",       "UK6_26",       "UK7_26",
90         "UK8_26",       "UK9_26",       "UK10_26",      "UK11_26",
91         "UK12_26",      "UK13_26",      "UK14_26",      "UK15_26",
92         "USER_32",      "FIQ_32",       "IRQ_32",       "SVC_32",
93         "UK4_32",       "UK5_32",       "UK6_32",       "ABT_32",
94         "UK8_32",       "UK9_32",       "HYP_32",       "UND_32",
95         "UK12_32",      "UK13_32",      "UK14_32",      "SYS_32",
96         };
97
98         flags = condition_codes (regs);
99
100         printf("pc : [<%08lx>]     lr : [<%08lx>]\n",
101                instruction_pointer(regs), regs->ARM_lr);
102         if (gd->flags & GD_FLG_RELOC) {
103                 printf("reloc pc : [<%08lx>]       lr : [<%08lx>]\n",
104                        instruction_pointer(regs) - gd->reloc_off,
105                        regs->ARM_lr - gd->reloc_off);
106         }
107         printf("sp : %08lx  ip : %08lx   fp : %08lx\n",
108                regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
109         printf ("r10: %08lx  r9 : %08lx  r8 : %08lx\n",
110                 regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
111         printf ("r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
112                 regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
113         printf ("r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
114                 regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
115         printf ("Flags: %c%c%c%c",
116                 flags & CC_N_BIT ? 'N' : 'n',
117                 flags & CC_Z_BIT ? 'Z' : 'z',
118                 flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
119         printf ("  IRQs %s  FIQs %s  Mode %s%s\n",
120                 interrupts_enabled (regs) ? "on" : "off",
121                 fast_interrupts_enabled (regs) ? "on" : "off",
122                 processor_modes[processor_mode (regs)],
123                 thumb_mode (regs) ? " (T)" : "");
124         dump_instr(regs);
125 }
126
127 /* fixup PC to point to the instruction leading to the exception */
128 static inline void fixup_pc(struct pt_regs *regs, int offset)
129 {
130         uint32_t pc = instruction_pointer(regs) + offset;
131         regs->ARM_pc = pc | (regs->ARM_pc & PCMASK);
132 }
133
134 void do_undefined_instruction (struct pt_regs *pt_regs)
135 {
136         efi_restore_gd();
137         printf ("undefined instruction\n");
138         fixup_pc(pt_regs, -4);
139         show_regs (pt_regs);
140         show_efi_loaded_images(pt_regs);
141         bad_mode ();
142 }
143
144 void do_software_interrupt (struct pt_regs *pt_regs)
145 {
146         efi_restore_gd();
147         printf ("software interrupt\n");
148         fixup_pc(pt_regs, -4);
149         show_regs (pt_regs);
150         show_efi_loaded_images(pt_regs);
151         bad_mode ();
152 }
153
154 void do_prefetch_abort (struct pt_regs *pt_regs)
155 {
156         efi_restore_gd();
157         printf ("prefetch abort\n");
158         fixup_pc(pt_regs, -8);
159         show_regs (pt_regs);
160         show_efi_loaded_images(pt_regs);
161         bad_mode ();
162 }
163
164 void do_data_abort (struct pt_regs *pt_regs)
165 {
166         efi_restore_gd();
167         printf ("data abort\n");
168         fixup_pc(pt_regs, -8);
169         show_regs (pt_regs);
170         show_efi_loaded_images(pt_regs);
171         bad_mode ();
172 }
173
174 void do_not_used (struct pt_regs *pt_regs)
175 {
176         efi_restore_gd();
177         printf ("not used\n");
178         fixup_pc(pt_regs, -8);
179         show_regs (pt_regs);
180         show_efi_loaded_images(pt_regs);
181         bad_mode ();
182 }
183
184 void do_fiq (struct pt_regs *pt_regs)
185 {
186         efi_restore_gd();
187         printf ("fast interrupt request\n");
188         fixup_pc(pt_regs, -8);
189         show_regs (pt_regs);
190         show_efi_loaded_images(pt_regs);
191         bad_mode ();
192 }
193
194 void do_irq (struct pt_regs *pt_regs)
195 {
196         efi_restore_gd();
197         printf ("interrupt request\n");
198         fixup_pc(pt_regs, -8);
199         show_regs (pt_regs);
200         show_efi_loaded_images(pt_regs);
201         bad_mode ();
202 }