summaryrefslogtreecommitdiff
path: root/arch/nds32/lib/interrupts.c
blob: ca8c227b05fe7192385863635519e151bff31bf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Alex Zuepke <azu@sysgo.de>
 *
 * Copyright (C) 2011 Andes Technology Corporation
 * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <asm/ptrace.h>
#include <asm/system.h>
#undef INTERRUPT_MODE

static int int_flag;

int irq_flags;		/* needed by asm-nds32/system.h */

int GIE_STATUS(void)
{
	int ret;

	__asm__ __volatile__ (
		"mfsr	$p0, $psw\n\t"
		"andi	%0, %0, 0x1\n\t"
		: "=r" (ret)
		:
		: "memory"
	);
	return ret;
}

#ifdef CONFIG_USE_INTERRUPT

/* enable interrupts */
void enable_interrupts(void)
{
	local_irq_restore(int_flag);
}

/*
 * disable interrupts
 * Return TRUE if GIE is enabled before we disable it.
 */
int disable_interrupts(void)
{

	int gie_ori_status;

	gie_ori_status = GIE_STATUS();

	local_irq_save(int_flag);

	return gie_ori_status;
}
#endif

void bad_mode(void)
{
	panic("Resetting CPU ...\n");
	reset_cpu(0);
}

void show_regs(struct pt_regs *regs)
{
	const char *processor_modes[] = {"USER", "SuperUser" , "HyperVisor"};

	printf("\n");
	printf("pc : [<%08lx>]	sp: [<%08lx>]\n"
		"lp : %08lx  gp : %08lx  fp : %08lx\n",
		regs->ipc, regs->sp, regs->lp, regs->gp, regs->fp);
	printf("D1H: %08lx  D1L: %08lx  D0H: %08lx  D0L: %08lx\n",
		regs->d1hi, regs->d1lo, regs->d0hi, regs->d0lo);
	printf("r27: %08lx  r26: %08lx  r25: %08lx  r24: %08lx\n",
		regs->p1, regs->p0, regs->r[25], regs->r[24]);
	printf("r23: %08lx  r22: %08lx  r21: %08lx  r20: %08lx\n",
		regs->r[23], regs->r[22], regs->r[21], regs->r[20]);
	printf("r19: %08lx  r18: %08lx  r17: %08lx  r16: %08lx\n",
		regs->r[19], regs->r[18], regs->r[17], regs->r[16]);
	printf("r15: %08lx  r14: %08lx  r13: %08lx  r12: %08lx\n",
		regs->r[15], regs->r[14], regs->r[13], regs->r[12]);
	printf("r11: %08lx  r10: %08lx  r9 : %08lx  r8 : %08lx\n",
		regs->r[11], regs->r[10], regs->r[9], regs->r[8]);
	printf("r7 : %08lx  r6 : %08lx  r5 : %08lx  r4 : %08lx\n",
		regs->r[7], regs->r[6], regs->r[5], regs->r[4]);
	printf("r3 : %08lx  r2 : %08lx  r1 : %08lx  r0 : %08lx\n",
		regs->r[3], regs->r[2], regs->r[1], regs->r[0]);
	printf("  Interrupts %s  Mode %s\n",
		interrupts_enabled(regs) ? "on" : "off",
		processor_modes[processor_mode(regs)]);
}

void do_interruption(struct pt_regs *pt_regs, int EVIC_num)
{
	const char *interruption_type[] = {
		"Reset",
		"TLB Fill",
		"TLB Not Present",
		"TLB Misc",
		"VLPT Miss",
		"Cache Parity Error",
		"Debug",
		"General Exception",
		"External Interrupt"
	};

	printf("%s\n", interruption_type[EVIC_num]);
	show_regs(pt_regs);
	bad_mode();
}