1463d47f6SMacpaul Lin /*
2463d47f6SMacpaul Lin * (C) Copyright 2002
3463d47f6SMacpaul Lin * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4463d47f6SMacpaul Lin * Alex Zuepke <azu@sysgo.de>
5463d47f6SMacpaul Lin *
6463d47f6SMacpaul Lin * Copyright (C) 2011 Andes Technology Corporation
7463d47f6SMacpaul Lin * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
8463d47f6SMacpaul Lin * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
9463d47f6SMacpaul Lin *
101a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
11463d47f6SMacpaul Lin */
12463d47f6SMacpaul Lin
13463d47f6SMacpaul Lin #include <common.h>
14463d47f6SMacpaul Lin #include <asm/ptrace.h>
15463d47f6SMacpaul Lin #include <asm/system.h>
16463d47f6SMacpaul Lin #undef INTERRUPT_MODE
17463d47f6SMacpaul Lin
18463d47f6SMacpaul Lin static int int_flag;
19463d47f6SMacpaul Lin
20463d47f6SMacpaul Lin int irq_flags; /* needed by asm-nds32/system.h */
21463d47f6SMacpaul Lin
GIE_STATUS(void)22463d47f6SMacpaul Lin int GIE_STATUS(void)
23463d47f6SMacpaul Lin {
24463d47f6SMacpaul Lin int ret;
25463d47f6SMacpaul Lin
26463d47f6SMacpaul Lin __asm__ __volatile__ (
27463d47f6SMacpaul Lin "mfsr $p0, $psw\n\t"
28463d47f6SMacpaul Lin "andi %0, %0, 0x1\n\t"
29463d47f6SMacpaul Lin : "=r" (ret)
30463d47f6SMacpaul Lin :
31463d47f6SMacpaul Lin : "memory"
32463d47f6SMacpaul Lin );
33463d47f6SMacpaul Lin return ret;
34463d47f6SMacpaul Lin }
35463d47f6SMacpaul Lin
36463d47f6SMacpaul Lin #ifdef CONFIG_USE_INTERRUPT
37463d47f6SMacpaul Lin
interrupt_init(void)38*2e88bb28SKun-Hua Huang int interrupt_init(void)
39*2e88bb28SKun-Hua Huang {
40*2e88bb28SKun-Hua Huang return 0;
41*2e88bb28SKun-Hua Huang }
42463d47f6SMacpaul Lin /* enable interrupts */
enable_interrupts(void)43463d47f6SMacpaul Lin void enable_interrupts(void)
44463d47f6SMacpaul Lin {
45463d47f6SMacpaul Lin local_irq_restore(int_flag);
46463d47f6SMacpaul Lin }
47463d47f6SMacpaul Lin
48463d47f6SMacpaul Lin /*
49463d47f6SMacpaul Lin * disable interrupts
50472d5460SYork Sun * Return true if GIE is enabled before we disable it.
51463d47f6SMacpaul Lin */
disable_interrupts(void)52463d47f6SMacpaul Lin int disable_interrupts(void)
53463d47f6SMacpaul Lin {
54463d47f6SMacpaul Lin
55463d47f6SMacpaul Lin int gie_ori_status;
56463d47f6SMacpaul Lin
57463d47f6SMacpaul Lin gie_ori_status = GIE_STATUS();
58463d47f6SMacpaul Lin
59463d47f6SMacpaul Lin local_irq_save(int_flag);
60463d47f6SMacpaul Lin
61463d47f6SMacpaul Lin return gie_ori_status;
62463d47f6SMacpaul Lin }
63463d47f6SMacpaul Lin #endif
64463d47f6SMacpaul Lin
bad_mode(void)65463d47f6SMacpaul Lin void bad_mode(void)
66463d47f6SMacpaul Lin {
67463d47f6SMacpaul Lin panic("Resetting CPU ...\n");
68463d47f6SMacpaul Lin reset_cpu(0);
69463d47f6SMacpaul Lin }
70463d47f6SMacpaul Lin
show_regs(struct pt_regs * regs)71463d47f6SMacpaul Lin void show_regs(struct pt_regs *regs)
72463d47f6SMacpaul Lin {
73463d47f6SMacpaul Lin const char *processor_modes[] = {"USER", "SuperUser" , "HyperVisor"};
74463d47f6SMacpaul Lin
75463d47f6SMacpaul Lin printf("\n");
76463d47f6SMacpaul Lin printf("pc : [<%08lx>] sp: [<%08lx>]\n"
77463d47f6SMacpaul Lin "lp : %08lx gp : %08lx fp : %08lx\n",
78463d47f6SMacpaul Lin regs->ipc, regs->sp, regs->lp, regs->gp, regs->fp);
79463d47f6SMacpaul Lin printf("D1H: %08lx D1L: %08lx D0H: %08lx D0L: %08lx\n",
80463d47f6SMacpaul Lin regs->d1hi, regs->d1lo, regs->d0hi, regs->d0lo);
81463d47f6SMacpaul Lin printf("r27: %08lx r26: %08lx r25: %08lx r24: %08lx\n",
82b0c4fae4SMacpaul Lin regs->p1, regs->p0, regs->r[25], regs->r[24]);
83463d47f6SMacpaul Lin printf("r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n",
84463d47f6SMacpaul Lin regs->r[23], regs->r[22], regs->r[21], regs->r[20]);
85463d47f6SMacpaul Lin printf("r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n",
86463d47f6SMacpaul Lin regs->r[19], regs->r[18], regs->r[17], regs->r[16]);
87463d47f6SMacpaul Lin printf("r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n",
88463d47f6SMacpaul Lin regs->r[15], regs->r[14], regs->r[13], regs->r[12]);
89463d47f6SMacpaul Lin printf("r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n",
90463d47f6SMacpaul Lin regs->r[11], regs->r[10], regs->r[9], regs->r[8]);
91463d47f6SMacpaul Lin printf("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
92463d47f6SMacpaul Lin regs->r[7], regs->r[6], regs->r[5], regs->r[4]);
93463d47f6SMacpaul Lin printf("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
94463d47f6SMacpaul Lin regs->r[3], regs->r[2], regs->r[1], regs->r[0]);
95463d47f6SMacpaul Lin printf(" Interrupts %s Mode %s\n",
96463d47f6SMacpaul Lin interrupts_enabled(regs) ? "on" : "off",
97463d47f6SMacpaul Lin processor_modes[processor_mode(regs)]);
98463d47f6SMacpaul Lin }
99463d47f6SMacpaul Lin
do_interruption(struct pt_regs * pt_regs,int EVIC_num)100463d47f6SMacpaul Lin void do_interruption(struct pt_regs *pt_regs, int EVIC_num)
101463d47f6SMacpaul Lin {
102463d47f6SMacpaul Lin const char *interruption_type[] = {
103463d47f6SMacpaul Lin "Reset",
104463d47f6SMacpaul Lin "TLB Fill",
105463d47f6SMacpaul Lin "TLB Not Present",
106463d47f6SMacpaul Lin "TLB Misc",
107463d47f6SMacpaul Lin "VLPT Miss",
108463d47f6SMacpaul Lin "Cache Parity Error",
109463d47f6SMacpaul Lin "Debug",
110463d47f6SMacpaul Lin "General Exception",
111463d47f6SMacpaul Lin "External Interrupt"
112463d47f6SMacpaul Lin };
113463d47f6SMacpaul Lin
114463d47f6SMacpaul Lin printf("%s\n", interruption_type[EVIC_num]);
115463d47f6SMacpaul Lin show_regs(pt_regs);
116463d47f6SMacpaul Lin bad_mode();
117463d47f6SMacpaul Lin }
118