xref: /rk3399_rockchip-uboot/arch/arm/lib/interrupts.c (revision 965eda410b8d28439dc1ba4f76061880d72978fd)
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 
27 DECLARE_GLOBAL_DATA_PTR;
28 
29 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_IRQ)
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 #endif
49 
50 void bad_mode (void)
51 {
52 	panic ("Resetting CPU ...\n");
53 	reset_cpu (0);
54 }
55 
56 void show_regs (struct pt_regs *regs)
57 {
58 	unsigned long __maybe_unused flags;
59 	const char __maybe_unused *processor_modes[] = {
60 	"USER_26",	"FIQ_26",	"IRQ_26",	"SVC_26",
61 	"UK4_26",	"UK5_26",	"UK6_26",	"UK7_26",
62 	"UK8_26",	"UK9_26",	"UK10_26",	"UK11_26",
63 	"UK12_26",	"UK13_26",	"UK14_26",	"UK15_26",
64 	"USER_32",	"FIQ_32",	"IRQ_32",	"SVC_32",
65 	"UK4_32",	"UK5_32",	"UK6_32",	"ABT_32",
66 	"UK8_32",	"UK9_32",	"HYP_32",	"UND_32",
67 	"UK12_32",	"UK13_32",	"UK14_32",	"SYS_32",
68 	};
69 
70 	flags = condition_codes (regs);
71 
72 	printf("pc : [<%08lx>]	   lr : [<%08lx>]\n",
73 	       instruction_pointer(regs), regs->ARM_lr);
74 	if (gd->flags & GD_FLG_RELOC) {
75 		printf("reloc pc : [<%08lx>]	   lr : [<%08lx>]\n",
76 		       instruction_pointer(regs) - gd->reloc_off,
77 		       regs->ARM_lr - gd->reloc_off);
78 	}
79 	printf("sp : %08lx  ip : %08lx	 fp : %08lx\n",
80 	       regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
81 	printf ("r10: %08lx  r9 : %08lx	 r8 : %08lx\n",
82 		regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
83 	printf ("r7 : %08lx  r6 : %08lx	 r5 : %08lx  r4 : %08lx\n",
84 		regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
85 	printf ("r3 : %08lx  r2 : %08lx	 r1 : %08lx  r0 : %08lx\n",
86 		regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
87 	printf ("Flags: %c%c%c%c",
88 		flags & CC_N_BIT ? 'N' : 'n',
89 		flags & CC_Z_BIT ? 'Z' : 'z',
90 		flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
91 	printf ("  IRQs %s  FIQs %s  Mode %s%s\n",
92 		interrupts_enabled (regs) ? "on" : "off",
93 		fast_interrupts_enabled (regs) ? "on" : "off",
94 		processor_modes[processor_mode (regs)],
95 		thumb_mode (regs) ? " (T)" : "");
96 }
97 
98 /* fixup PC to point to the instruction leading to the exception */
99 static inline void fixup_pc(struct pt_regs *regs, int offset)
100 {
101 	uint32_t pc = instruction_pointer(regs) + offset;
102 	regs->ARM_pc = pc | (regs->ARM_pc & PCMASK);
103 }
104 
105 void do_undefined_instruction (struct pt_regs *pt_regs)
106 {
107 	efi_restore_gd();
108 	printf ("undefined instruction\n");
109 	fixup_pc(pt_regs, -4);
110 	show_regs (pt_regs);
111 	bad_mode ();
112 }
113 
114 void do_software_interrupt (struct pt_regs *pt_regs)
115 {
116 	efi_restore_gd();
117 	printf ("software interrupt\n");
118 	fixup_pc(pt_regs, -4);
119 	show_regs (pt_regs);
120 	bad_mode ();
121 }
122 
123 void do_prefetch_abort (struct pt_regs *pt_regs)
124 {
125 	efi_restore_gd();
126 	printf ("prefetch abort\n");
127 	fixup_pc(pt_regs, -8);
128 	show_regs (pt_regs);
129 	bad_mode ();
130 }
131 
132 void do_data_abort (struct pt_regs *pt_regs)
133 {
134 	efi_restore_gd();
135 	printf ("data abort\n");
136 	fixup_pc(pt_regs, -8);
137 	show_regs (pt_regs);
138 	bad_mode ();
139 }
140 
141 void do_not_used (struct pt_regs *pt_regs)
142 {
143 	efi_restore_gd();
144 	printf ("not used\n");
145 	fixup_pc(pt_regs, -8);
146 	show_regs (pt_regs);
147 	bad_mode ();
148 }
149 
150 void do_fiq (struct pt_regs *pt_regs)
151 {
152 	efi_restore_gd();
153 	printf ("fast interrupt request\n");
154 	fixup_pc(pt_regs, -8);
155 	show_regs (pt_regs);
156 	bad_mode ();
157 }
158 
159 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_IRQ)
160 void do_irq (struct pt_regs *pt_regs)
161 {
162 	efi_restore_gd();
163 	printf ("interrupt request\n");
164 	fixup_pc(pt_regs, -8);
165 	show_regs (pt_regs);
166 	bad_mode ();
167 }
168 #endif
169