xref: /openbmc/u-boot/arch/nds32/lib/interrupts.c (revision 9e336903)
1 /*
2  * (C) Copyright 2002
3  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4  * Alex Zuepke <azu@sysgo.de>
5  *
6  * Copyright (C) 2011 Andes Technology Corporation
7  * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
8  * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28 
29 #include <common.h>
30 #include <asm/ptrace.h>
31 #include <asm/system.h>
32 #undef INTERRUPT_MODE
33 
34 static int int_flag;
35 
36 int irq_flags;		/* needed by asm-nds32/system.h */
37 
38 int GIE_STATUS(void)
39 {
40 	int ret;
41 
42 	__asm__ __volatile__ (
43 		"mfsr	$p0, $psw\n\t"
44 		"andi	%0, %0, 0x1\n\t"
45 		: "=r" (ret)
46 		:
47 		: "memory"
48 	);
49 	return ret;
50 }
51 
52 #ifdef CONFIG_USE_INTERRUPT
53 
54 /* enable interrupts */
55 void enable_interrupts(void)
56 {
57 	local_irq_restore(int_flag);
58 }
59 
60 /*
61  * disable interrupts
62  * Return true if GIE is enabled before we disable it.
63  */
64 int disable_interrupts(void)
65 {
66 
67 	int gie_ori_status;
68 
69 	gie_ori_status = GIE_STATUS();
70 
71 	local_irq_save(int_flag);
72 
73 	return gie_ori_status;
74 }
75 #endif
76 
77 void bad_mode(void)
78 {
79 	panic("Resetting CPU ...\n");
80 	reset_cpu(0);
81 }
82 
83 void show_regs(struct pt_regs *regs)
84 {
85 	const char *processor_modes[] = {"USER", "SuperUser" , "HyperVisor"};
86 
87 	printf("\n");
88 	printf("pc : [<%08lx>]	sp: [<%08lx>]\n"
89 		"lp : %08lx  gp : %08lx  fp : %08lx\n",
90 		regs->ipc, regs->sp, regs->lp, regs->gp, regs->fp);
91 	printf("D1H: %08lx  D1L: %08lx  D0H: %08lx  D0L: %08lx\n",
92 		regs->d1hi, regs->d1lo, regs->d0hi, regs->d0lo);
93 	printf("r27: %08lx  r26: %08lx  r25: %08lx  r24: %08lx\n",
94 		regs->p1, regs->p0, regs->r[25], regs->r[24]);
95 	printf("r23: %08lx  r22: %08lx  r21: %08lx  r20: %08lx\n",
96 		regs->r[23], regs->r[22], regs->r[21], regs->r[20]);
97 	printf("r19: %08lx  r18: %08lx  r17: %08lx  r16: %08lx\n",
98 		regs->r[19], regs->r[18], regs->r[17], regs->r[16]);
99 	printf("r15: %08lx  r14: %08lx  r13: %08lx  r12: %08lx\n",
100 		regs->r[15], regs->r[14], regs->r[13], regs->r[12]);
101 	printf("r11: %08lx  r10: %08lx  r9 : %08lx  r8 : %08lx\n",
102 		regs->r[11], regs->r[10], regs->r[9], regs->r[8]);
103 	printf("r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
104 		regs->r[7], regs->r[6], regs->r[5], regs->r[4]);
105 	printf("r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
106 		regs->r[3], regs->r[2], regs->r[1], regs->r[0]);
107 	printf("  Interrupts %s  Mode %s\n",
108 		interrupts_enabled(regs) ? "on" : "off",
109 		processor_modes[processor_mode(regs)]);
110 }
111 
112 void do_interruption(struct pt_regs *pt_regs, int EVIC_num)
113 {
114 	const char *interruption_type[] = {
115 		"Reset",
116 		"TLB Fill",
117 		"TLB Not Present",
118 		"TLB Misc",
119 		"VLPT Miss",
120 		"Cache Parity Error",
121 		"Debug",
122 		"General Exception",
123 		"External Interrupt"
124 	};
125 
126 	printf("%s\n", interruption_type[EVIC_num]);
127 	show_regs(pt_regs);
128 	bad_mode();
129 }
130