blob: 6dbf03b00cd5c98ac0eeb61b2296cfe4a14e072a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk74f43042005-09-25 01:48:28 +02002/*
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
Detlev Zundel792a09e2009-05-13 10:54:10 +020015 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
Wolfgang Denk74f43042005-09-25 01:48:28 +020016 *
17 * (C) Copyright 2004
18 * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
Wolfgang Denk74f43042005-09-25 01:48:28 +020019 */
20
21#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -070022#include <cpu_func.h>
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +020023#include <efi_loader.h>
Simon Glassc30b7ad2019-11-14 12:57:41 -070024#include <irq_func.h>
Wolfgang Denk74f43042005-09-25 01:48:28 +020025#include <asm/proc-armv/ptrace.h>
Jeroen Hofstee49c4bc32014-10-08 22:57:59 +020026#include <asm/u-boot-arm.h>
Wolfgang Denk74f43042005-09-25 01:48:28 +020027
Jean-Christophe PLAGNIOL-VILLARDc358d9c32009-05-09 13:21:18 +020028DECLARE_GLOBAL_DATA_PTR;
29
Simon Glass9d3915b2019-11-14 12:57:40 -070030int interrupt_init(void)
Heiko Schocherf1d2b312010-09-17 13:10:39 +020031{
32 /*
33 * setup up stacks if necessary
34 */
35 IRQ_STACK_START_IN = gd->irq_sp + 8;
36
37 return 0;
38}
Heiko Schocherf1d2b312010-09-17 13:10:39 +020039
Simon Glass9d3915b2019-11-14 12:57:40 -070040void enable_interrupts(void)
Wolfgang Denk74f43042005-09-25 01:48:28 +020041{
42 return;
43}
Simon Glass9d3915b2019-11-14 12:57:40 -070044int disable_interrupts(void)
Wolfgang Denk74f43042005-09-25 01:48:28 +020045{
46 return 0;
47}
Wolfgang Denk74f43042005-09-25 01:48:28 +020048
49void bad_mode (void)
50{
51 panic ("Resetting CPU ...\n");
Simon Glass9a3b4ce2019-12-28 10:45:01 -070052 reset_cpu(0);
Wolfgang Denk74f43042005-09-25 01:48:28 +020053}
54
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +020055static void show_efi_loaded_images(struct pt_regs *regs)
56{
57 efi_print_image_infos((void *)instruction_pointer(regs));
58}
59
Heinrich Schuchardtbd2a13f2018-05-15 19:42:23 +020060static 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
Wolfgang Denk74f43042005-09-25 01:48:28 +020084void show_regs (struct pt_regs *regs)
85{
Heiko Schocher80402f32015-06-29 09:10:46 +020086 unsigned long __maybe_unused flags;
87 const char __maybe_unused *processor_modes[] = {
Wolfgang Denk74f43042005-09-25 01:48:28 +020088 "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",
Marc Zyngierb726d222014-07-12 14:24:01 +010094 "UK8_32", "UK9_32", "HYP_32", "UND_32",
Wolfgang Denk74f43042005-09-25 01:48:28 +020095 "UK12_32", "UK13_32", "UK14_32", "SYS_32",
96 };
97
98 flags = condition_codes (regs);
99
Simon Glass23d184d2015-01-30 12:04:56 -0700100 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);
Andreas Engel6d0943a2008-01-14 09:06:52 +0000109 printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
Wolfgang Denk74f43042005-09-25 01:48:28 +0200110 regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
Andreas Engel6d0943a2008-01-14 09:06:52 +0000111 printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
Wolfgang Denk74f43042005-09-25 01:48:28 +0200112 regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
Andreas Engel6d0943a2008-01-14 09:06:52 +0000113 printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
Wolfgang Denk74f43042005-09-25 01:48:28 +0200114 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)" : "");
Heinrich Schuchardtbd2a13f2018-05-15 19:42:23 +0200124 dump_instr(regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200125}
126
Lothar Waßmannc8882362017-06-08 09:52:33 +0200127/* fixup PC to point to the instruction leading to the exception */
128static 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
Wolfgang Denk74f43042005-09-25 01:48:28 +0200134void do_undefined_instruction (struct pt_regs *pt_regs)
135{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100136 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200137 printf ("undefined instruction\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200138 fixup_pc(pt_regs, -4);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200139 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200140 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200141 bad_mode ();
142}
143
144void do_software_interrupt (struct pt_regs *pt_regs)
145{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100146 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200147 printf ("software interrupt\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200148 fixup_pc(pt_regs, -4);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200149 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200150 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200151 bad_mode ();
152}
153
154void do_prefetch_abort (struct pt_regs *pt_regs)
155{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100156 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200157 printf ("prefetch abort\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200158 fixup_pc(pt_regs, -8);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200159 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200160 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200161 bad_mode ();
162}
163
164void do_data_abort (struct pt_regs *pt_regs)
165{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100166 efi_restore_gd();
Tom Rini1551df32014-02-25 10:27:01 -0500167 printf ("data abort\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200168 fixup_pc(pt_regs, -8);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200169 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200170 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200171 bad_mode ();
172}
173
174void do_not_used (struct pt_regs *pt_regs)
175{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100176 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200177 printf ("not used\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200178 fixup_pc(pt_regs, -8);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200179 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200180 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200181 bad_mode ();
182}
183
184void do_fiq (struct pt_regs *pt_regs)
185{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100186 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200187 printf ("fast interrupt request\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200188 fixup_pc(pt_regs, -8);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200189 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200190 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200191 bad_mode ();
192}
193
194void do_irq (struct pt_regs *pt_regs)
195{
Alexander Grafcc4a4742016-03-04 01:10:12 +0100196 efi_restore_gd();
Wolfgang Denk74f43042005-09-25 01:48:28 +0200197 printf ("interrupt request\n");
Lothar Waßmannc8882362017-06-08 09:52:33 +0200198 fixup_pc(pt_regs, -8);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200199 show_regs (pt_regs);
Heinrich Schuchardt99b8db72018-04-05 11:56:22 +0200200 show_efi_loaded_images(pt_regs);
Wolfgang Denk74f43042005-09-25 01:48:28 +0200201 bad_mode ();
202}