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