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